Rename existing activity states
This commit is contained in:
@@ -27,9 +27,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
readonly IFacing carryallFacing;
|
||||
readonly CPos destination;
|
||||
|
||||
enum State { Transport, Land, Wait, Release, TakeOff, Aborted }
|
||||
enum DeliveryState { Transport, Land, Wait, Release, TakeOff, Aborted }
|
||||
|
||||
State state;
|
||||
DeliveryState state;
|
||||
Activity innerActivity;
|
||||
|
||||
public DeliverUnit(Actor self, CPos destination)
|
||||
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
carryable = carryall.Carryable.Trait<Carryable>();
|
||||
positionable = carryall.Carryable.Trait<IPositionable>();
|
||||
carryableFacing = carryall.Carryable.Trait<IFacing>();
|
||||
state = State.Transport;
|
||||
state = DeliveryState.Transport;
|
||||
}
|
||||
|
||||
CPos? FindDropLocation(CPos targetCell, WDist maxSearchDistance)
|
||||
@@ -87,12 +87,12 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (IsCanceled)
|
||||
return NextActivity;
|
||||
|
||||
if ((carryall.State == Carryall.CarryallState.Idle || carryall.Carryable.IsDead) && state != State.TakeOff)
|
||||
state = State.Aborted;
|
||||
if ((carryall.State == Carryall.CarryallState.Idle || carryall.Carryable.IsDead) && state != DeliveryState.TakeOff)
|
||||
state = DeliveryState.Aborted;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case State.Transport:
|
||||
case DeliveryState.Transport:
|
||||
{
|
||||
var targetLocation = FindDropLocation(destination, carryall.Info.DropRange);
|
||||
|
||||
@@ -129,15 +129,15 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return this;
|
||||
}
|
||||
|
||||
state = State.Land;
|
||||
state = DeliveryState.Land;
|
||||
return this;
|
||||
}
|
||||
|
||||
case State.Land:
|
||||
case DeliveryState.Land:
|
||||
{
|
||||
if (!CanDropHere())
|
||||
{
|
||||
state = State.Transport;
|
||||
state = DeliveryState.Transport;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -150,30 +150,30 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return this;
|
||||
}
|
||||
|
||||
state = carryall.Info.UnloadingDelay > 0 ? State.Wait : State.Release;
|
||||
state = carryall.Info.UnloadingDelay > 0 ? DeliveryState.Wait : DeliveryState.Release;
|
||||
return this;
|
||||
}
|
||||
|
||||
case State.Wait:
|
||||
state = State.Release;
|
||||
case DeliveryState.Wait:
|
||||
state = DeliveryState.Release;
|
||||
innerActivity = new Wait(carryall.Info.UnloadingDelay, false);
|
||||
return this;
|
||||
|
||||
case State.Release:
|
||||
case DeliveryState.Release:
|
||||
if (!CanDropHere())
|
||||
{
|
||||
state = State.Transport;
|
||||
state = DeliveryState.Transport;
|
||||
return this;
|
||||
}
|
||||
|
||||
Release();
|
||||
state = State.TakeOff;
|
||||
state = DeliveryState.TakeOff;
|
||||
return this;
|
||||
|
||||
case State.TakeOff:
|
||||
case DeliveryState.TakeOff:
|
||||
return ActivityUtils.SequenceActivities(new HeliFly(self, Target.FromPos(self.CenterPosition)), NextActivity);
|
||||
|
||||
case State.Aborted:
|
||||
case DeliveryState.Aborted:
|
||||
carryall.UnreserveCarryable(self);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public abstract class Enter : Activity
|
||||
{
|
||||
public enum ReserveStatus { None, TooFar, Pending, Ready }
|
||||
enum State { ApproachingOrEntering, Inside, Exiting, Done }
|
||||
enum EnterState { ApproachingOrEntering, Inside, Exiting, Done }
|
||||
|
||||
readonly IMove move;
|
||||
readonly int maxTries = 0;
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public Target Target { get { return target; } }
|
||||
Target target;
|
||||
State nextState = State.ApproachingOrEntering; // Hint/starting point for next state
|
||||
EnterState nextState = EnterState.ApproachingOrEntering; // Hint/starting point for next state
|
||||
bool isEnteringOrInside = false; // Used to know if exiting should be used
|
||||
WPos savedPos; // Position just before entering
|
||||
Activity inner;
|
||||
@@ -89,9 +89,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
// Abort entering and/or leave if necessary
|
||||
protected virtual void AbortOrExit(Actor self)
|
||||
{
|
||||
if (nextState == State.Done)
|
||||
if (nextState == EnterState.Done)
|
||||
return;
|
||||
nextState = isEnteringOrInside ? State.Exiting : State.Done;
|
||||
nextState = isEnteringOrInside ? EnterState.Exiting : EnterState.Done;
|
||||
if (inner == this)
|
||||
inner = null;
|
||||
else if (inner != null)
|
||||
@@ -103,9 +103,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
// Cancel inner activity and mark as done unless already leaving or done
|
||||
protected void Done(Actor self)
|
||||
{
|
||||
if (nextState == State.Done)
|
||||
if (nextState == EnterState.Done)
|
||||
return;
|
||||
nextState = State.Done;
|
||||
nextState = EnterState.Done;
|
||||
if (inner == this)
|
||||
inner = null;
|
||||
else if (inner != null)
|
||||
@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public override bool Cancel(Actor self)
|
||||
{
|
||||
AbortOrExit(self);
|
||||
if (nextState < State.Exiting)
|
||||
if (nextState < EnterState.Exiting)
|
||||
return base.Cancel(self);
|
||||
else
|
||||
NextActivity = null;
|
||||
@@ -156,23 +156,23 @@ namespace OpenRA.Mods.Common.Activities
|
||||
}
|
||||
}
|
||||
|
||||
State FindAndTransitionToNextState(Actor self)
|
||||
EnterState FindAndTransitionToNextState(Actor self)
|
||||
{
|
||||
switch (nextState)
|
||||
{
|
||||
case State.ApproachingOrEntering:
|
||||
case EnterState.ApproachingOrEntering:
|
||||
|
||||
// Reserve to enter or approach
|
||||
isEnteringOrInside = false;
|
||||
switch (TryReserveElseTryAlternateReserve(self))
|
||||
{
|
||||
case ReserveStatus.None:
|
||||
return State.Done; // No available target -> abort to next activity
|
||||
return EnterState.Done; // No available target -> abort to next activity
|
||||
case ReserveStatus.TooFar:
|
||||
inner = move.MoveToTarget(self, targetCenter ? Target.FromPos(target.CenterPosition) : target); // Approach
|
||||
return State.ApproachingOrEntering;
|
||||
return EnterState.ApproachingOrEntering;
|
||||
case ReserveStatus.Pending:
|
||||
return State.ApproachingOrEntering; // Retry next tick
|
||||
return EnterState.ApproachingOrEntering; // Retry next tick
|
||||
case ReserveStatus.Ready:
|
||||
break; // Reserved target -> start entering target
|
||||
}
|
||||
@@ -185,38 +185,38 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
if (inner != null)
|
||||
{
|
||||
nextState = State.Inside; // Should be inside once inner activity is null
|
||||
return State.ApproachingOrEntering;
|
||||
nextState = EnterState.Inside; // Should be inside once inner activity is null
|
||||
return EnterState.ApproachingOrEntering;
|
||||
}
|
||||
|
||||
// Can enter but there is no activity for it, so go inside without one
|
||||
goto case State.Inside;
|
||||
goto case EnterState.Inside;
|
||||
|
||||
case State.Inside:
|
||||
case EnterState.Inside:
|
||||
// Might as well teleport into target if there is no MoveIntoTarget activity
|
||||
if (nextState == State.ApproachingOrEntering)
|
||||
nextState = State.Inside;
|
||||
if (nextState == EnterState.ApproachingOrEntering)
|
||||
nextState = EnterState.Inside;
|
||||
|
||||
// Otherwise, try to recover from moving target
|
||||
else if (target.CenterPosition != self.CenterPosition)
|
||||
{
|
||||
nextState = State.ApproachingOrEntering;
|
||||
nextState = EnterState.ApproachingOrEntering;
|
||||
Unreserve(self, false);
|
||||
if (Reserve(self) == ReserveStatus.Ready)
|
||||
{
|
||||
inner = move.MoveIntoTarget(self, target); // Enter
|
||||
if (inner != null)
|
||||
return State.ApproachingOrEntering;
|
||||
return EnterState.ApproachingOrEntering;
|
||||
|
||||
nextState = State.ApproachingOrEntering;
|
||||
goto case State.ApproachingOrEntering;
|
||||
nextState = EnterState.ApproachingOrEntering;
|
||||
goto case EnterState.ApproachingOrEntering;
|
||||
}
|
||||
|
||||
nextState = State.ApproachingOrEntering;
|
||||
nextState = EnterState.ApproachingOrEntering;
|
||||
isEnteringOrInside = false;
|
||||
inner = move.MoveIntoWorld(self, self.World.Map.CellContaining(savedPos));
|
||||
|
||||
return State.ApproachingOrEntering;
|
||||
return EnterState.ApproachingOrEntering;
|
||||
}
|
||||
|
||||
OnInside(self);
|
||||
@@ -227,29 +227,29 @@ namespace OpenRA.Mods.Common.Activities
|
||||
self.Dispose();
|
||||
|
||||
// Return if Abort(Actor) or Done(self) was called from OnInside.
|
||||
if (nextState >= State.Exiting)
|
||||
return State.Inside;
|
||||
if (nextState >= EnterState.Exiting)
|
||||
return EnterState.Inside;
|
||||
|
||||
inner = this; // Start inside activity
|
||||
nextState = State.Exiting; // Exit once inner activity is null (unless Done(self) is called)
|
||||
return State.Inside;
|
||||
nextState = EnterState.Exiting; // Exit once inner activity is null (unless Done(self) is called)
|
||||
return EnterState.Inside;
|
||||
|
||||
// TODO: Handle target moved while inside or always call done for movable targets and use a separate exit activity
|
||||
case State.Exiting:
|
||||
case EnterState.Exiting:
|
||||
inner = move.MoveIntoWorld(self, self.World.Map.CellContaining(savedPos));
|
||||
|
||||
// If not successfully exiting, retry on next tick
|
||||
if (inner == null)
|
||||
return State.Exiting;
|
||||
return EnterState.Exiting;
|
||||
isEnteringOrInside = false;
|
||||
nextState = State.Done;
|
||||
return State.Exiting;
|
||||
nextState = EnterState.Done;
|
||||
return EnterState.Exiting;
|
||||
|
||||
case State.Done:
|
||||
return State.Done;
|
||||
case EnterState.Done:
|
||||
return EnterState.Done;
|
||||
}
|
||||
|
||||
return State.Done; // dummy to quiet dumb compiler
|
||||
return EnterState.Done; // dummy to quiet dumb compiler
|
||||
}
|
||||
|
||||
Activity CanceledTick(Actor self)
|
||||
@@ -267,18 +267,18 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return CanceledTick(self);
|
||||
|
||||
// Check target validity if not exiting or done
|
||||
if (nextState != State.Done && (target.Type != TargetType.Actor || !target.IsValidFor(self)))
|
||||
if (nextState != EnterState.Done && (target.Type != TargetType.Actor || !target.IsValidFor(self)))
|
||||
AbortOrExit(self);
|
||||
|
||||
// If no current activity, tick next activity
|
||||
if (inner == null && FindAndTransitionToNextState(self) == State.Done)
|
||||
if (inner == null && FindAndTransitionToNextState(self) == EnterState.Done)
|
||||
return CanceledTick(self);
|
||||
|
||||
// Run inner activity/InsideTick
|
||||
inner = inner == this ? InsideTick(self) : ActivityUtils.RunActivity(self, inner);
|
||||
|
||||
// If we are finished, move on to next activity
|
||||
if (inner == null && nextState == State.Done)
|
||||
if (inner == null && nextState == EnterState.Done)
|
||||
return NextActivity;
|
||||
|
||||
return this;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public abstract class HarvesterDockSequence : Activity
|
||||
{
|
||||
protected enum State { Wait, Turn, Dock, Loop, Undock, Complete }
|
||||
protected enum DockingState { Wait, Turn, Dock, Loop, Undock, Complete }
|
||||
|
||||
protected readonly Actor Refinery;
|
||||
protected readonly Harvester Harv;
|
||||
@@ -30,11 +30,11 @@ namespace OpenRA.Mods.Common.Activities
|
||||
protected readonly WPos StartDrag;
|
||||
protected readonly WPos EndDrag;
|
||||
|
||||
protected State dockingState;
|
||||
protected DockingState dockingState;
|
||||
|
||||
public HarvesterDockSequence(Actor self, Actor refinery, int dockAngle, bool isDragRequired, WVec dragOffset, int dragLength)
|
||||
{
|
||||
dockingState = State.Turn;
|
||||
dockingState = DockingState.Turn;
|
||||
Refinery = refinery;
|
||||
DockAngle = dockAngle;
|
||||
IsDragRequired = isDragRequired;
|
||||
@@ -49,25 +49,25 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
switch (dockingState)
|
||||
{
|
||||
case State.Wait:
|
||||
case DockingState.Wait:
|
||||
return this;
|
||||
case State.Turn:
|
||||
dockingState = State.Dock;
|
||||
case DockingState.Turn:
|
||||
dockingState = DockingState.Dock;
|
||||
if (IsDragRequired)
|
||||
return ActivityUtils.SequenceActivities(new Turn(self, DockAngle), new Drag(self, StartDrag, EndDrag, DragLength), this);
|
||||
return ActivityUtils.SequenceActivities(new Turn(self, DockAngle), this);
|
||||
case State.Dock:
|
||||
case DockingState.Dock:
|
||||
if (Refinery.IsInWorld && !Refinery.IsDead)
|
||||
foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>())
|
||||
nd.Docked(Refinery, self);
|
||||
return OnStateDock(self);
|
||||
case State.Loop:
|
||||
case DockingState.Loop:
|
||||
if (!Refinery.IsInWorld || Refinery.IsDead || Harv.TickUnload(self, Refinery))
|
||||
dockingState = State.Undock;
|
||||
dockingState = DockingState.Undock;
|
||||
return this;
|
||||
case State.Undock:
|
||||
case DockingState.Undock:
|
||||
return OnStateUndock(self);
|
||||
case State.Complete:
|
||||
case DockingState.Complete:
|
||||
if (Refinery.IsInWorld && !Refinery.IsDead)
|
||||
foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>())
|
||||
nd.Undocked(Refinery, self);
|
||||
@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override bool Cancel(Actor self)
|
||||
{
|
||||
dockingState = State.Undock;
|
||||
dockingState = DockingState.Undock;
|
||||
return base.Cancel(self);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
readonly int delay;
|
||||
|
||||
enum State { Intercept, LockCarryable, MoveToCarryable, Turn, Land, Wait, Pickup, Aborted }
|
||||
enum PickupState { Intercept, LockCarryable, MoveToCarryable, Turn, Land, Wait, Pickup, Aborted }
|
||||
|
||||
State state;
|
||||
PickupState state;
|
||||
Activity innerActivity;
|
||||
|
||||
public PickupUnit(Actor self, Actor cargo, int delay)
|
||||
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
carryall = self.Trait<Carryall>();
|
||||
carryallFacing = self.Trait<IFacing>();
|
||||
|
||||
state = State.Intercept;
|
||||
state = PickupState.Intercept;
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
@@ -71,18 +71,18 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case State.Intercept:
|
||||
case PickupState.Intercept:
|
||||
innerActivity = movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4));
|
||||
state = State.LockCarryable;
|
||||
state = PickupState.LockCarryable;
|
||||
return this;
|
||||
|
||||
case State.LockCarryable:
|
||||
state = State.MoveToCarryable;
|
||||
case PickupState.LockCarryable:
|
||||
state = PickupState.MoveToCarryable;
|
||||
if (!carryable.LockForPickup(cargo, self))
|
||||
state = State.Aborted;
|
||||
state = PickupState.Aborted;
|
||||
return this;
|
||||
|
||||
case State.MoveToCarryable:
|
||||
case PickupState.MoveToCarryable:
|
||||
{
|
||||
// Line up with the attachment point
|
||||
var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
|
||||
@@ -94,27 +94,27 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return this;
|
||||
}
|
||||
|
||||
state = State.Turn;
|
||||
state = PickupState.Turn;
|
||||
return this;
|
||||
}
|
||||
|
||||
case State.Turn:
|
||||
case PickupState.Turn:
|
||||
if (carryallFacing.Facing != carryableFacing.Facing)
|
||||
{
|
||||
innerActivity = new Turn(self, carryableFacing.Facing);
|
||||
return this;
|
||||
}
|
||||
|
||||
state = State.Land;
|
||||
state = PickupState.Land;
|
||||
return this;
|
||||
|
||||
case State.Land:
|
||||
case PickupState.Land:
|
||||
{
|
||||
var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
|
||||
var targetPosition = cargo.CenterPosition - carryableBody.LocalToWorld(localOffset);
|
||||
if ((self.CenterPosition - targetPosition).HorizontalLengthSquared != 0 || carryallFacing.Facing != carryableFacing.Facing)
|
||||
{
|
||||
state = State.MoveToCarryable;
|
||||
state = PickupState.MoveToCarryable;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -124,21 +124,21 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return this;
|
||||
}
|
||||
|
||||
state = delay > 0 ? State.Wait : State.Pickup;
|
||||
state = delay > 0 ? PickupState.Wait : PickupState.Pickup;
|
||||
return this;
|
||||
}
|
||||
|
||||
case State.Wait:
|
||||
state = State.Pickup;
|
||||
case PickupState.Wait:
|
||||
state = PickupState.Pickup;
|
||||
innerActivity = new Wait(delay, false);
|
||||
return this;
|
||||
|
||||
case State.Pickup:
|
||||
case PickupState.Pickup:
|
||||
// Remove our carryable from world
|
||||
Attach(self);
|
||||
return NextActivity;
|
||||
|
||||
case State.Aborted:
|
||||
case PickupState.Aborted:
|
||||
// We got cancelled
|
||||
carryall.UnreserveCarryable(self);
|
||||
break;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
trait.Docked();
|
||||
|
||||
wsb.PlayCustomAnimation(self, wda.DockSequence, () => wsb.PlayCustomAnimationRepeating(self, wda.DockLoopSequence));
|
||||
dockingState = State.Loop;
|
||||
dockingState = DockingState.Loop;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -42,11 +42,11 @@ namespace OpenRA.Mods.Common.Activities
|
||||
wsb.PlayCustomAnimationBackwards(self, wda.DockSequence,
|
||||
() =>
|
||||
{
|
||||
dockingState = State.Complete;
|
||||
dockingState = DockingState.Complete;
|
||||
foreach (var trait in self.TraitsImplementing<INotifyHarvesterAction>())
|
||||
trait.Undocked();
|
||||
});
|
||||
dockingState = State.Wait;
|
||||
dockingState = DockingState.Wait;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -35,32 +35,32 @@ namespace OpenRA.Mods.TS.Activities
|
||||
{
|
||||
spriteOverlay.Visible = true;
|
||||
spriteOverlay.WithOffset.Animation.PlayThen(spriteOverlay.Info.Sequence, () => {
|
||||
dockingState = State.Loop;
|
||||
dockingState = DockingState.Loop;
|
||||
spriteOverlay.Visible = false;
|
||||
});
|
||||
}
|
||||
else
|
||||
dockingState = State.Loop;
|
||||
dockingState = DockingState.Loop;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public override Activity OnStateUndock(Actor self)
|
||||
{
|
||||
dockingState = State.Wait;
|
||||
dockingState = DockingState.Wait;
|
||||
|
||||
if (spriteOverlay != null && !spriteOverlay.Visible)
|
||||
{
|
||||
spriteOverlay.Visible = true;
|
||||
spriteOverlay.WithOffset.Animation.PlayBackwardsThen(spriteOverlay.Info.Sequence, () => {
|
||||
dockingState = State.Complete;
|
||||
dockingState = DockingState.Complete;
|
||||
body.Docked = false;
|
||||
spriteOverlay.Visible = false;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
dockingState = State.Complete;
|
||||
dockingState = DockingState.Complete;
|
||||
body.Docked = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user