Simplify IDockHost interface
This commit is contained in:
@@ -41,7 +41,8 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
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;
|
||||
|
||||
@@ -54,17 +55,12 @@ namespace OpenRA.Mods.Common.Activities
|
||||
DockHostSpriteOverlay = hostActor.TraitOrDefault<WithDockingOverlay>();
|
||||
notifyDockHosts = hostActor.TraitsImplementing<INotifyDockHost>().ToArray();
|
||||
|
||||
if (host is IDockHostDrag sequence)
|
||||
{
|
||||
IsDragRequired = sequence.IsDragRequired;
|
||||
DragLength = sequence.DragLength;
|
||||
StartDrag = self.CenterPosition;
|
||||
EndDrag = hostActor.CenterPosition + sequence.DragOffset;
|
||||
}
|
||||
else
|
||||
IsDragRequired = false;
|
||||
IsDragRequired = isDragRequired;
|
||||
DragLength = dragLength;
|
||||
StartDrag = self.CenterPosition;
|
||||
EndDrag = hostActor.CenterPosition + dragOffset;
|
||||
|
||||
QueueChild(new Wait(host.DockWait));
|
||||
QueueChild(new Wait(dockWait));
|
||||
}
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -60,12 +60,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
protected readonly List<DockClientManager> ReservedDockClients = new();
|
||||
|
||||
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]
|
||||
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.
|
||||
// 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)
|
||||
|| move is not IFacing facing || facing.Facing != DockAngle)
|
||||
|| move is not IFacing facing || facing.Facing != Info.DockAngle)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -153,7 +147,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
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(); }
|
||||
|
||||
@@ -246,8 +246,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
int ReservationCount { get; }
|
||||
bool CanBeReserved { get; }
|
||||
WPos DockPosition { get; }
|
||||
int DockWait { get; }
|
||||
WAngle DockAngle { get; }
|
||||
|
||||
/// <summary>Can this <paramref name="client"/> dock at this <see cref="IDockHost"/>.</summary>
|
||||
/// <remarks>
|
||||
@@ -269,13 +267,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
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 { }
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
|
||||
Reference in New Issue
Block a user