Simplify IDockHost interface
This commit is contained in:
@@ -41,7 +41,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
bool dockInitiated = false;
|
bool dockInitiated = false;
|
||||||
|
|
||||||
public GenericDockSequence(Actor self, DockClientManager client, Actor hostActor, IDockHost host)
|
public GenericDockSequence(Actor self, DockClientManager client, Actor hostActor, IDockHost host,
|
||||||
|
int dockWait, bool isDragRequired, WVec dragOffset, int dragLength)
|
||||||
{
|
{
|
||||||
dockingState = DockingState.Drag;
|
dockingState = DockingState.Drag;
|
||||||
|
|
||||||
@@ -54,17 +55,12 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
DockHostSpriteOverlay = hostActor.TraitOrDefault<WithDockingOverlay>();
|
DockHostSpriteOverlay = hostActor.TraitOrDefault<WithDockingOverlay>();
|
||||||
notifyDockHosts = hostActor.TraitsImplementing<INotifyDockHost>().ToArray();
|
notifyDockHosts = hostActor.TraitsImplementing<INotifyDockHost>().ToArray();
|
||||||
|
|
||||||
if (host is IDockHostDrag sequence)
|
IsDragRequired = isDragRequired;
|
||||||
{
|
DragLength = dragLength;
|
||||||
IsDragRequired = sequence.IsDragRequired;
|
StartDrag = self.CenterPosition;
|
||||||
DragLength = sequence.DragLength;
|
EndDrag = hostActor.CenterPosition + dragOffset;
|
||||||
StartDrag = self.CenterPosition;
|
|
||||||
EndDrag = hostActor.CenterPosition + sequence.DragOffset;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
IsDragRequired = false;
|
|
||||||
|
|
||||||
QueueChild(new Wait(host.DockWait));
|
QueueChild(new Wait(dockWait));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Tick(Actor self)
|
public override bool Tick(Actor self)
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class DockHost : ConditionalTrait<DockHostInfo>,
|
public class DockHost : ConditionalTrait<DockHostInfo>,
|
||||||
IDockHost, IDockHostDrag, ITick, INotifySold, INotifyCapture, INotifyOwnerChanged, ISync, INotifyKilled, INotifyActorDisposing
|
IDockHost, ITick, INotifySold, INotifyCapture, INotifyOwnerChanged, ISync, INotifyKilled, INotifyActorDisposing
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
|
|
||||||
@@ -60,12 +60,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
protected readonly List<DockClientManager> ReservedDockClients = new();
|
protected readonly List<DockClientManager> ReservedDockClients = new();
|
||||||
|
|
||||||
public WPos DockPosition => self.CenterPosition + Info.DockOffset;
|
public WPos DockPosition => self.CenterPosition + Info.DockOffset;
|
||||||
public int DockWait => Info.DockWait;
|
|
||||||
public WAngle DockAngle => Info.DockAngle;
|
|
||||||
|
|
||||||
bool IDockHostDrag.IsDragRequired => Info.IsDragRequired;
|
|
||||||
WVec IDockHostDrag.DragOffset => Info.DragOffset;
|
|
||||||
int IDockHostDrag.DragLength => Info.DragLength;
|
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
bool preventDock = false;
|
bool preventDock = false;
|
||||||
@@ -141,10 +135,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
// Make sure the actor is at dock, at correct facing, and aircraft are landed.
|
// Make sure the actor is at dock, at correct facing, and aircraft are landed.
|
||||||
// Mobile cannot freely move in WPos, so when we calculate close enough we convert to CPos.
|
// Mobile cannot freely move in WPos, so when we calculate close enough we convert to CPos.
|
||||||
if ((move is Mobile ? clientActor.Location != clientActor.World.Map.CellContaining(DockPosition) : clientActor.CenterPosition != DockPosition)
|
if ((move is Mobile ? clientActor.Location != clientActor.World.Map.CellContaining(DockPosition) : clientActor.CenterPosition != DockPosition)
|
||||||
|| move is not IFacing facing || facing.Facing != DockAngle)
|
|| move is not IFacing facing || facing.Facing != Info.DockAngle)
|
||||||
{
|
{
|
||||||
moveCooldownHelper.NotifyMoveQueued();
|
moveCooldownHelper.NotifyMoveQueued();
|
||||||
moveToDockActivity.QueueChild(move.MoveOntoTarget(clientActor, Target.FromActor(self), DockPosition - self.CenterPosition, DockAngle));
|
moveToDockActivity.QueueChild(move.MoveOntoTarget(clientActor, Target.FromActor(self), DockPosition - self.CenterPosition, Info.DockAngle));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +147,15 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public virtual void QueueDockActivity(Activity moveToDockActivity, Actor self, Actor clientActor, DockClientManager client)
|
public virtual void QueueDockActivity(Activity moveToDockActivity, Actor self, Actor clientActor, DockClientManager client)
|
||||||
{
|
{
|
||||||
moveToDockActivity.QueueChild(new GenericDockSequence(clientActor, client, self, this));
|
moveToDockActivity.QueueChild(new GenericDockSequence(
|
||||||
|
clientActor,
|
||||||
|
client,
|
||||||
|
self,
|
||||||
|
this,
|
||||||
|
Info.DockWait,
|
||||||
|
Info.IsDragRequired,
|
||||||
|
Info.DragOffset,
|
||||||
|
Info.DragLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void TraitDisabled(Actor self) { UnreserveAll(); }
|
protected override void TraitDisabled(Actor self) { UnreserveAll(); }
|
||||||
|
|||||||
@@ -246,8 +246,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
int ReservationCount { get; }
|
int ReservationCount { get; }
|
||||||
bool CanBeReserved { get; }
|
bool CanBeReserved { get; }
|
||||||
WPos DockPosition { get; }
|
WPos DockPosition { get; }
|
||||||
int DockWait { get; }
|
|
||||||
WAngle DockAngle { get; }
|
|
||||||
|
|
||||||
/// <summary>Can this <paramref name="client"/> dock at this <see cref="IDockHost"/>.</summary>
|
/// <summary>Can this <paramref name="client"/> dock at this <see cref="IDockHost"/>.</summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
@@ -269,13 +267,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
void QueueDockActivity(Activity moveToDockActivity, Actor self, Actor clientActor, DockClientManager client);
|
void QueueDockActivity(Activity moveToDockActivity, Actor self, Actor clientActor, DockClientManager client);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IDockHostDrag
|
|
||||||
{
|
|
||||||
bool IsDragRequired { get; }
|
|
||||||
WVec DragOffset { get; }
|
|
||||||
int DragLength { get; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IDockClientManagerInfo : ITraitInfoInterface { }
|
public interface IDockClientManagerInfo : ITraitInfoInterface { }
|
||||||
|
|
||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
|
|||||||
Reference in New Issue
Block a user