Rename existing activity states

This commit is contained in:
Oliver Brakmann
2016-12-06 22:24:39 +01:00
parent bd3639e81d
commit 683d3e747b
6 changed files with 94 additions and 94 deletions

View File

@@ -27,9 +27,9 @@ namespace OpenRA.Mods.Common.Activities
readonly IFacing carryallFacing; readonly IFacing carryallFacing;
readonly CPos destination; 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; Activity innerActivity;
public DeliverUnit(Actor self, CPos destination) public DeliverUnit(Actor self, CPos destination)
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Activities
carryable = carryall.Carryable.Trait<Carryable>(); carryable = carryall.Carryable.Trait<Carryable>();
positionable = carryall.Carryable.Trait<IPositionable>(); positionable = carryall.Carryable.Trait<IPositionable>();
carryableFacing = carryall.Carryable.Trait<IFacing>(); carryableFacing = carryall.Carryable.Trait<IFacing>();
state = State.Transport; state = DeliveryState.Transport;
} }
CPos? FindDropLocation(CPos targetCell, WDist maxSearchDistance) CPos? FindDropLocation(CPos targetCell, WDist maxSearchDistance)
@@ -87,12 +87,12 @@ namespace OpenRA.Mods.Common.Activities
if (IsCanceled) if (IsCanceled)
return NextActivity; return NextActivity;
if ((carryall.State == Carryall.CarryallState.Idle || carryall.Carryable.IsDead) && state != State.TakeOff) if ((carryall.State == Carryall.CarryallState.Idle || carryall.Carryable.IsDead) && state != DeliveryState.TakeOff)
state = State.Aborted; state = DeliveryState.Aborted;
switch (state) switch (state)
{ {
case State.Transport: case DeliveryState.Transport:
{ {
var targetLocation = FindDropLocation(destination, carryall.Info.DropRange); var targetLocation = FindDropLocation(destination, carryall.Info.DropRange);
@@ -129,15 +129,15 @@ namespace OpenRA.Mods.Common.Activities
return this; return this;
} }
state = State.Land; state = DeliveryState.Land;
return this; return this;
} }
case State.Land: case DeliveryState.Land:
{ {
if (!CanDropHere()) if (!CanDropHere())
{ {
state = State.Transport; state = DeliveryState.Transport;
return this; return this;
} }
@@ -150,30 +150,30 @@ namespace OpenRA.Mods.Common.Activities
return this; return this;
} }
state = carryall.Info.UnloadingDelay > 0 ? State.Wait : State.Release; state = carryall.Info.UnloadingDelay > 0 ? DeliveryState.Wait : DeliveryState.Release;
return this; return this;
} }
case State.Wait: case DeliveryState.Wait:
state = State.Release; state = DeliveryState.Release;
innerActivity = new Wait(carryall.Info.UnloadingDelay, false); innerActivity = new Wait(carryall.Info.UnloadingDelay, false);
return this; return this;
case State.Release: case DeliveryState.Release:
if (!CanDropHere()) if (!CanDropHere())
{ {
state = State.Transport; state = DeliveryState.Transport;
return this; return this;
} }
Release(); Release();
state = State.TakeOff; state = DeliveryState.TakeOff;
return this; return this;
case State.TakeOff: case DeliveryState.TakeOff:
return ActivityUtils.SequenceActivities(new HeliFly(self, Target.FromPos(self.CenterPosition)), NextActivity); return ActivityUtils.SequenceActivities(new HeliFly(self, Target.FromPos(self.CenterPosition)), NextActivity);
case State.Aborted: case DeliveryState.Aborted:
carryall.UnreserveCarryable(self); carryall.UnreserveCarryable(self);
break; break;
} }

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Activities
public abstract class Enter : Activity public abstract class Enter : Activity
{ {
public enum ReserveStatus { None, TooFar, Pending, Ready } public enum ReserveStatus { None, TooFar, Pending, Ready }
enum State { ApproachingOrEntering, Inside, Exiting, Done } enum EnterState { ApproachingOrEntering, Inside, Exiting, Done }
readonly IMove move; readonly IMove move;
readonly int maxTries = 0; readonly int maxTries = 0;
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Activities
public Target Target { get { return target; } } public Target Target { get { return target; } }
Target 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 bool isEnteringOrInside = false; // Used to know if exiting should be used
WPos savedPos; // Position just before entering WPos savedPos; // Position just before entering
Activity inner; Activity inner;
@@ -89,9 +89,9 @@ namespace OpenRA.Mods.Common.Activities
// Abort entering and/or leave if necessary // Abort entering and/or leave if necessary
protected virtual void AbortOrExit(Actor self) protected virtual void AbortOrExit(Actor self)
{ {
if (nextState == State.Done) if (nextState == EnterState.Done)
return; return;
nextState = isEnteringOrInside ? State.Exiting : State.Done; nextState = isEnteringOrInside ? EnterState.Exiting : EnterState.Done;
if (inner == this) if (inner == this)
inner = null; inner = null;
else if (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 // Cancel inner activity and mark as done unless already leaving or done
protected void Done(Actor self) protected void Done(Actor self)
{ {
if (nextState == State.Done) if (nextState == EnterState.Done)
return; return;
nextState = State.Done; nextState = EnterState.Done;
if (inner == this) if (inner == this)
inner = null; inner = null;
else if (inner != null) else if (inner != null)
@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Activities
public override bool Cancel(Actor self) public override bool Cancel(Actor self)
{ {
AbortOrExit(self); AbortOrExit(self);
if (nextState < State.Exiting) if (nextState < EnterState.Exiting)
return base.Cancel(self); return base.Cancel(self);
else else
NextActivity = null; NextActivity = null;
@@ -156,23 +156,23 @@ namespace OpenRA.Mods.Common.Activities
} }
} }
State FindAndTransitionToNextState(Actor self) EnterState FindAndTransitionToNextState(Actor self)
{ {
switch (nextState) switch (nextState)
{ {
case State.ApproachingOrEntering: case EnterState.ApproachingOrEntering:
// Reserve to enter or approach // Reserve to enter or approach
isEnteringOrInside = false; isEnteringOrInside = false;
switch (TryReserveElseTryAlternateReserve(self)) switch (TryReserveElseTryAlternateReserve(self))
{ {
case ReserveStatus.None: 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: case ReserveStatus.TooFar:
inner = move.MoveToTarget(self, targetCenter ? Target.FromPos(target.CenterPosition) : target); // Approach inner = move.MoveToTarget(self, targetCenter ? Target.FromPos(target.CenterPosition) : target); // Approach
return State.ApproachingOrEntering; return EnterState.ApproachingOrEntering;
case ReserveStatus.Pending: case ReserveStatus.Pending:
return State.ApproachingOrEntering; // Retry next tick return EnterState.ApproachingOrEntering; // Retry next tick
case ReserveStatus.Ready: case ReserveStatus.Ready:
break; // Reserved target -> start entering target break; // Reserved target -> start entering target
} }
@@ -185,38 +185,38 @@ namespace OpenRA.Mods.Common.Activities
if (inner != null) if (inner != null)
{ {
nextState = State.Inside; // Should be inside once inner activity is null nextState = EnterState.Inside; // Should be inside once inner activity is null
return State.ApproachingOrEntering; return EnterState.ApproachingOrEntering;
} }
// Can enter but there is no activity for it, so go inside without one // 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 // Might as well teleport into target if there is no MoveIntoTarget activity
if (nextState == State.ApproachingOrEntering) if (nextState == EnterState.ApproachingOrEntering)
nextState = State.Inside; nextState = EnterState.Inside;
// Otherwise, try to recover from moving target // Otherwise, try to recover from moving target
else if (target.CenterPosition != self.CenterPosition) else if (target.CenterPosition != self.CenterPosition)
{ {
nextState = State.ApproachingOrEntering; nextState = EnterState.ApproachingOrEntering;
Unreserve(self, false); Unreserve(self, false);
if (Reserve(self) == ReserveStatus.Ready) if (Reserve(self) == ReserveStatus.Ready)
{ {
inner = move.MoveIntoTarget(self, target); // Enter inner = move.MoveIntoTarget(self, target); // Enter
if (inner != null) if (inner != null)
return State.ApproachingOrEntering; return EnterState.ApproachingOrEntering;
nextState = State.ApproachingOrEntering; nextState = EnterState.ApproachingOrEntering;
goto case State.ApproachingOrEntering; goto case EnterState.ApproachingOrEntering;
} }
nextState = State.ApproachingOrEntering; nextState = EnterState.ApproachingOrEntering;
isEnteringOrInside = false; isEnteringOrInside = false;
inner = move.MoveIntoWorld(self, self.World.Map.CellContaining(savedPos)); inner = move.MoveIntoWorld(self, self.World.Map.CellContaining(savedPos));
return State.ApproachingOrEntering; return EnterState.ApproachingOrEntering;
} }
OnInside(self); OnInside(self);
@@ -227,29 +227,29 @@ namespace OpenRA.Mods.Common.Activities
self.Dispose(); self.Dispose();
// Return if Abort(Actor) or Done(self) was called from OnInside. // Return if Abort(Actor) or Done(self) was called from OnInside.
if (nextState >= State.Exiting) if (nextState >= EnterState.Exiting)
return State.Inside; return EnterState.Inside;
inner = this; // Start inside activity inner = this; // Start inside activity
nextState = State.Exiting; // Exit once inner activity is null (unless Done(self) is called) nextState = EnterState.Exiting; // Exit once inner activity is null (unless Done(self) is called)
return State.Inside; return EnterState.Inside;
// TODO: Handle target moved while inside or always call done for movable targets and use a separate exit activity // 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)); inner = move.MoveIntoWorld(self, self.World.Map.CellContaining(savedPos));
// If not successfully exiting, retry on next tick // If not successfully exiting, retry on next tick
if (inner == null) if (inner == null)
return State.Exiting; return EnterState.Exiting;
isEnteringOrInside = false; isEnteringOrInside = false;
nextState = State.Done; nextState = EnterState.Done;
return State.Exiting; return EnterState.Exiting;
case State.Done: case EnterState.Done:
return State.Done; return EnterState.Done;
} }
return State.Done; // dummy to quiet dumb compiler return EnterState.Done; // dummy to quiet dumb compiler
} }
Activity CanceledTick(Actor self) Activity CanceledTick(Actor self)
@@ -267,18 +267,18 @@ namespace OpenRA.Mods.Common.Activities
return CanceledTick(self); return CanceledTick(self);
// Check target validity if not exiting or done // 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); AbortOrExit(self);
// If no current activity, tick next activity // If no current activity, tick next activity
if (inner == null && FindAndTransitionToNextState(self) == State.Done) if (inner == null && FindAndTransitionToNextState(self) == EnterState.Done)
return CanceledTick(self); return CanceledTick(self);
// Run inner activity/InsideTick // Run inner activity/InsideTick
inner = inner == this ? InsideTick(self) : ActivityUtils.RunActivity(self, inner); inner = inner == this ? InsideTick(self) : ActivityUtils.RunActivity(self, inner);
// If we are finished, move on to next activity // If we are finished, move on to next activity
if (inner == null && nextState == State.Done) if (inner == null && nextState == EnterState.Done)
return NextActivity; return NextActivity;
return this; return this;

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Activities
{ {
public abstract class HarvesterDockSequence : Activity 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 Actor Refinery;
protected readonly Harvester Harv; protected readonly Harvester Harv;
@@ -30,11 +30,11 @@ namespace OpenRA.Mods.Common.Activities
protected readonly WPos StartDrag; protected readonly WPos StartDrag;
protected readonly WPos EndDrag; protected readonly WPos EndDrag;
protected State dockingState; protected DockingState dockingState;
public HarvesterDockSequence(Actor self, Actor refinery, int dockAngle, bool isDragRequired, WVec dragOffset, int dragLength) public HarvesterDockSequence(Actor self, Actor refinery, int dockAngle, bool isDragRequired, WVec dragOffset, int dragLength)
{ {
dockingState = State.Turn; dockingState = DockingState.Turn;
Refinery = refinery; Refinery = refinery;
DockAngle = dockAngle; DockAngle = dockAngle;
IsDragRequired = isDragRequired; IsDragRequired = isDragRequired;
@@ -49,25 +49,25 @@ namespace OpenRA.Mods.Common.Activities
{ {
switch (dockingState) switch (dockingState)
{ {
case State.Wait: case DockingState.Wait:
return this; return this;
case State.Turn: case DockingState.Turn:
dockingState = State.Dock; dockingState = DockingState.Dock;
if (IsDragRequired) if (IsDragRequired)
return ActivityUtils.SequenceActivities(new Turn(self, DockAngle), new Drag(self, StartDrag, EndDrag, DragLength), this); return ActivityUtils.SequenceActivities(new Turn(self, DockAngle), new Drag(self, StartDrag, EndDrag, DragLength), this);
return ActivityUtils.SequenceActivities(new Turn(self, DockAngle), this); return ActivityUtils.SequenceActivities(new Turn(self, DockAngle), this);
case State.Dock: case DockingState.Dock:
if (Refinery.IsInWorld && !Refinery.IsDead) if (Refinery.IsInWorld && !Refinery.IsDead)
foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>()) foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>())
nd.Docked(Refinery, self); nd.Docked(Refinery, self);
return OnStateDock(self); return OnStateDock(self);
case State.Loop: case DockingState.Loop:
if (!Refinery.IsInWorld || Refinery.IsDead || Harv.TickUnload(self, Refinery)) if (!Refinery.IsInWorld || Refinery.IsDead || Harv.TickUnload(self, Refinery))
dockingState = State.Undock; dockingState = DockingState.Undock;
return this; return this;
case State.Undock: case DockingState.Undock:
return OnStateUndock(self); return OnStateUndock(self);
case State.Complete: case DockingState.Complete:
if (Refinery.IsInWorld && !Refinery.IsDead) if (Refinery.IsInWorld && !Refinery.IsDead)
foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>()) foreach (var nd in Refinery.TraitsImplementing<INotifyDocking>())
nd.Undocked(Refinery, self); nd.Undocked(Refinery, self);
@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Activities
public override bool Cancel(Actor self) public override bool Cancel(Actor self)
{ {
dockingState = State.Undock; dockingState = DockingState.Undock;
return base.Cancel(self); return base.Cancel(self);
} }

View File

@@ -29,9 +29,9 @@ namespace OpenRA.Mods.Common.Activities
readonly int delay; 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; Activity innerActivity;
public PickupUnit(Actor self, Actor cargo, int delay) public PickupUnit(Actor self, Actor cargo, int delay)
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Activities
carryall = self.Trait<Carryall>(); carryall = self.Trait<Carryall>();
carryallFacing = self.Trait<IFacing>(); carryallFacing = self.Trait<IFacing>();
state = State.Intercept; state = PickupState.Intercept;
} }
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
@@ -71,18 +71,18 @@ namespace OpenRA.Mods.Common.Activities
switch (state) switch (state)
{ {
case State.Intercept: case PickupState.Intercept:
innerActivity = movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4)); innerActivity = movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4));
state = State.LockCarryable; state = PickupState.LockCarryable;
return this; return this;
case State.LockCarryable: case PickupState.LockCarryable:
state = State.MoveToCarryable; state = PickupState.MoveToCarryable;
if (!carryable.LockForPickup(cargo, self)) if (!carryable.LockForPickup(cargo, self))
state = State.Aborted; state = PickupState.Aborted;
return this; return this;
case State.MoveToCarryable: case PickupState.MoveToCarryable:
{ {
// Line up with the attachment point // Line up with the attachment point
var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation)); var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
@@ -94,27 +94,27 @@ namespace OpenRA.Mods.Common.Activities
return this; return this;
} }
state = State.Turn; state = PickupState.Turn;
return this; return this;
} }
case State.Turn: case PickupState.Turn:
if (carryallFacing.Facing != carryableFacing.Facing) if (carryallFacing.Facing != carryableFacing.Facing)
{ {
innerActivity = new Turn(self, carryableFacing.Facing); innerActivity = new Turn(self, carryableFacing.Facing);
return this; return this;
} }
state = State.Land; state = PickupState.Land;
return this; return this;
case State.Land: case PickupState.Land:
{ {
var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation)); var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
var targetPosition = cargo.CenterPosition - carryableBody.LocalToWorld(localOffset); var targetPosition = cargo.CenterPosition - carryableBody.LocalToWorld(localOffset);
if ((self.CenterPosition - targetPosition).HorizontalLengthSquared != 0 || carryallFacing.Facing != carryableFacing.Facing) if ((self.CenterPosition - targetPosition).HorizontalLengthSquared != 0 || carryallFacing.Facing != carryableFacing.Facing)
{ {
state = State.MoveToCarryable; state = PickupState.MoveToCarryable;
return this; return this;
} }
@@ -124,21 +124,21 @@ namespace OpenRA.Mods.Common.Activities
return this; return this;
} }
state = delay > 0 ? State.Wait : State.Pickup; state = delay > 0 ? PickupState.Wait : PickupState.Pickup;
return this; return this;
} }
case State.Wait: case PickupState.Wait:
state = State.Pickup; state = PickupState.Pickup;
innerActivity = new Wait(delay, false); innerActivity = new Wait(delay, false);
return this; return this;
case State.Pickup: case PickupState.Pickup:
// Remove our carryable from world // Remove our carryable from world
Attach(self); Attach(self);
return NextActivity; return NextActivity;
case State.Aborted: case PickupState.Aborted:
// We got cancelled // We got cancelled
carryall.UnreserveCarryable(self); carryall.UnreserveCarryable(self);
break; break;

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Activities
trait.Docked(); trait.Docked();
wsb.PlayCustomAnimation(self, wda.DockSequence, () => wsb.PlayCustomAnimationRepeating(self, wda.DockLoopSequence)); wsb.PlayCustomAnimation(self, wda.DockSequence, () => wsb.PlayCustomAnimationRepeating(self, wda.DockLoopSequence));
dockingState = State.Loop; dockingState = DockingState.Loop;
return this; return this;
} }
@@ -42,11 +42,11 @@ namespace OpenRA.Mods.Common.Activities
wsb.PlayCustomAnimationBackwards(self, wda.DockSequence, wsb.PlayCustomAnimationBackwards(self, wda.DockSequence,
() => () =>
{ {
dockingState = State.Complete; dockingState = DockingState.Complete;
foreach (var trait in self.TraitsImplementing<INotifyHarvesterAction>()) foreach (var trait in self.TraitsImplementing<INotifyHarvesterAction>())
trait.Undocked(); trait.Undocked();
}); });
dockingState = State.Wait; dockingState = DockingState.Wait;
return this; return this;
} }

View File

@@ -35,32 +35,32 @@ namespace OpenRA.Mods.TS.Activities
{ {
spriteOverlay.Visible = true; spriteOverlay.Visible = true;
spriteOverlay.WithOffset.Animation.PlayThen(spriteOverlay.Info.Sequence, () => { spriteOverlay.WithOffset.Animation.PlayThen(spriteOverlay.Info.Sequence, () => {
dockingState = State.Loop; dockingState = DockingState.Loop;
spriteOverlay.Visible = false; spriteOverlay.Visible = false;
}); });
} }
else else
dockingState = State.Loop; dockingState = DockingState.Loop;
return this; return this;
} }
public override Activity OnStateUndock(Actor self) public override Activity OnStateUndock(Actor self)
{ {
dockingState = State.Wait; dockingState = DockingState.Wait;
if (spriteOverlay != null && !spriteOverlay.Visible) if (spriteOverlay != null && !spriteOverlay.Visible)
{ {
spriteOverlay.Visible = true; spriteOverlay.Visible = true;
spriteOverlay.WithOffset.Animation.PlayBackwardsThen(spriteOverlay.Info.Sequence, () => { spriteOverlay.WithOffset.Animation.PlayBackwardsThen(spriteOverlay.Info.Sequence, () => {
dockingState = State.Complete; dockingState = DockingState.Complete;
body.Docked = false; body.Docked = false;
spriteOverlay.Visible = false; spriteOverlay.Visible = false;
}); });
} }
else else
{ {
dockingState = State.Complete; dockingState = DockingState.Complete;
body.Docked = false; body.Docked = false;
} }