Replaced Canceled state with Canceling state.

This commit is contained in:
tovl
2019-03-03 01:57:17 +01:00
committed by Paul Chote
parent 8191a6566b
commit a17cd0fa06
43 changed files with 74 additions and 108 deletions

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Activities
{
public enum ActivityState { Queued, Active, Done, Canceled }
public enum ActivityState { Queued, Active, Canceling, Done }
/*
* Activities are actions carried out by actors during each tick.
@@ -99,7 +99,7 @@ namespace OpenRA.Activities
{
get
{
return childActivity != null && childActivity.State != ActivityState.Done ? childActivity : null;
return childActivity != null && childActivity.State < ActivityState.Done ? childActivity : null;
}
set
@@ -153,7 +153,7 @@ namespace OpenRA.Activities
}
public bool IsInterruptible { get; protected set; }
public bool IsCanceled { get { return State == ActivityState.Canceled; } }
public bool IsCanceling { get { return State == ActivityState.Canceling; } }
public Activity()
{
@@ -179,8 +179,7 @@ namespace OpenRA.Activities
if (ParentActivity != null && ParentActivity != ret)
ParentActivity.ChildActivity = ret;
if (State != ActivityState.Canceled)
State = ActivityState.Done;
State = ActivityState.Done;
OnLastRun(self);
}
@@ -220,16 +219,16 @@ namespace OpenRA.Activities
public virtual bool Cancel(Actor self, bool keepQueue = false)
{
if (!keepQueue)
NextInQueue = null;
if (!IsInterruptible)
return false;
if (ChildActivity != null && !ChildActivity.Cancel(self))
return false;
if (ChildActivity != null)
ChildActivity.Cancel(self);
if (!keepQueue)
NextActivity = null;
State = ActivityState.Canceled;
State = ActivityState.Canceling;
return true;
}

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Cnc.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled)
if (IsCanceling)
return NextActivity;
if (rearmableInfo != null && ammoPools.Any(p => p.Info.Name == info.AmmoPoolName && !p.HasAmmo()))

View File

@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Cnc.Activities
return this;
}
if (IsCanceled)
if (IsCanceling)
return NextActivity;
bool targetIsHiddenActor;

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Cnc.Traits
public override Activity Tick(Actor self)
{
if (IsCanceled || !target.IsValidFor(self))
if (IsCanceling || !target.IsValidFor(self))
return NextActivity;
if (attack.IsTraitDisabled)

View File

@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Cnc.Traits
public override Activity Tick(Actor self)
{
if (IsCanceled || !attack.CanAttack(self, target))
if (IsCanceling || !attack.CanAttack(self, target))
return NextActivity;
if (attack.charges == 0)
@@ -120,7 +120,7 @@ namespace OpenRA.Mods.Cnc.Traits
public override Activity Tick(Actor self)
{
if (IsCanceled || !attack.CanAttack(self, target))
if (IsCanceling || !attack.CanAttack(self, target))
return NextActivity;
if (attack.charges == 0)

View File

@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.ForceLanding)
Cancel(self);
if (IsCanceled)
if (IsCanceling)
return NextActivity;
bool targetIsHiddenActor;

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.ForceLanding)
Cancel(self);
if (IsCanceled)
if (IsCanceling)
return NextActivity;
bool targetIsHiddenActor;

View File

@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Activities
return NextActivity;
}
if (IsCanceled)
if (IsCanceling)
return NextActivity;
if (remainingTicks > 0)

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.ForceLanding)
Cancel(self);
if (IsCanceled)
if (IsCanceling)
return NextActivity;
bool targetIsHiddenActor;

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Activities
return NextActivity;
}
if (IsCanceled || !self.World.Map.Contains(self.Location))
if (IsCanceling || !self.World.Map.Contains(self.Location))
return NextActivity;
Fly.FlyToward(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Activities
return NextActivity;
}
if (IsCanceled || remainingTicks-- == 0)
if (IsCanceling || remainingTicks-- == 0)
return NextActivity;
Fly.FlyToward(self, aircraft, aircraft.Facing, cruiseAltitude);

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.ForceLanding)
Cancel(self);
if (IsCanceled)
if (IsCanceling)
return NextActivity;
bool targetIsHiddenActor;

View File

@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.ForceLanding)
Cancel(self);
if (IsCanceled)
if (IsCanceling)
return NextActivity;
bool targetIsHiddenActor;
@@ -156,7 +156,7 @@ namespace OpenRA.Mods.Common.Activities
{
var activity = base.Tick(self);
if (activity == null && !IsCanceled && info.LandWhenIdle)
if (activity == null && !IsCanceling && info.LandWhenIdle)
{
if (info.TurnToLand)
self.QueueActivity(new Turn(self, info.InitialFacing));

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Activities
return NextActivity;
}
if (IsCanceled)
if (IsCanceling)
return NextActivity;
if (HeliFly.AdjustAltitude(self, aircraft, aircraft.Info.CruiseAltitude))

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled)
if (IsCanceling)
return NextActivity;
if (requireSpace && !aircraft.CanLand(self.Location))

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.ForceLanding)
return NextActivity;
if (IsCanceled)
if (IsCanceling)
return NextActivity;
if (dest == null || dest.IsDead || !Reservable.IsAvailableFor(dest, self))

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Activities
if (!target.IsValidFor(self))
Cancel(self);
if (IsCanceled)
if (IsCanceling)
return NextActivity;
if (!soundPlayed && aircraft.Info.LandingSounds.Length > 0 && !self.IsAtGroundLevel())

View File

@@ -51,11 +51,8 @@ namespace OpenRA.Mods.Common.Activities
}
// Conditional fixes being able to stop aircraft from resupplying.
if (IsCanceled && NextInQueue == null)
{
OnFirstRun(self);
return this;
}
if (IsCanceling && NextInQueue == null)
return new ResupplyAircraft(self);
return NextActivity;
}

View File

@@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.ForceLanding)
return NextActivity;
if (IsCanceled || self.IsDead)
if (IsCanceling || self.IsDead)
return NextActivity;
if (!isCalculated)

View File

@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled)
if (IsCanceling)
return NextActivity;
bool targetIsHiddenActor;
@@ -145,7 +145,7 @@ namespace OpenRA.Mods.Common.Activities
protected virtual AttackStatus TickAttack(Actor self, AttackFrontal attack)
{
if (IsCanceled)
if (IsCanceling)
return AttackStatus.UnableToAttack;
if (!target.IsValidFor(self))

View File

@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Activities
return this;
}
if (IsCanceled)
if (IsCanceling)
return NextActivity;
if ((carryall.State == Carryall.CarryallState.Idle || carryall.Carryable.IsDead) && state != DeliveryState.TakeOff)
@@ -208,8 +208,8 @@ namespace OpenRA.Mods.Common.Activities
public override bool Cancel(Actor self, bool keepQueue = false)
{
if (!IsCanceled && innerActivity != null && !innerActivity.Cancel(self))
return false;
if (!IsCanceling && innerActivity != null)
innerActivity.Cancel(self);
return base.Cancel(self);
}

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Activities
}
// Without this, turn for facing deploy angle will be canceled and immediately deploy!
if (IsCanceled)
if (IsCanceling)
return NextActivity;
if (IsInterruptible)

View File

@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Activities
useLastVisibleTarget = targetIsHiddenActor || !target.IsValidFor(self);
// Cancel immediately if the target died while we were entering it
if (!IsCanceled && useLastVisibleTarget && lastState == EnterState.Entering)
if (!IsCanceling && useLastVisibleTarget && lastState == EnterState.Entering)
Cancel(self, true);
TickInner(self, target, useLastVisibleTarget);
@@ -101,7 +101,7 @@ namespace OpenRA.Mods.Common.Activities
{
// NOTE: We can safely cancel in this case because we know the
// actor has finished any in-progress move activities
if (IsCanceled)
if (IsCanceling)
return NextActivity;
// Lost track of the target
@@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.Activities
// Subclasses can cancel the activity during TryStartEnter
// Return immediately to avoid an extra tick's delay
if (IsCanceled)
if (IsCanceling)
return NextActivity;
lastState = EnterState.Waiting;
@@ -145,7 +145,7 @@ namespace OpenRA.Mods.Common.Activities
{
// Check that we reached the requested position
var targetPos = target.Positions.PositionClosestTo(self.CenterPosition);
if (!IsCanceled && self.CenterPosition == targetPos && target.Type == TargetType.Actor)
if (!IsCanceling && self.CenterPosition == targetPos && target.Type == TargetType.Actor)
OnEnterComplete(self, target.Actor);
lastState = EnterState.Exiting;
@@ -164,8 +164,8 @@ namespace OpenRA.Mods.Common.Activities
{
OnCancel(self);
if (!IsCanceled && moveActivity != null && !moveActivity.Cancel(self))
return false;
if (!IsCanceling && moveActivity != null)
moveActivity.Cancel(self);
return base.Cancel(self, keepQueue);
}

View File

@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Activities
}
// Try and find a new transport nearby
if (IsCanceled || string.IsNullOrEmpty(type))
if (IsCanceling || string.IsNullOrEmpty(type))
return NextActivity;
Func<Actor, bool> isValidTransport = a =>
@@ -135,8 +135,8 @@ namespace OpenRA.Mods.Common.Activities
public override bool Cancel(Actor self, bool keepQueue = false)
{
if (!IsCanceled && enterTransport != null && !enterTransport.Cancel(self))
return false;
if (!IsCanceling && enterTransport != null)
enterTransport.Cancel(self);
return base.Cancel(self, keepQueue);
}

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled)
if (IsCanceling)
return NextActivity;
if (harv.IsFull)

View File

@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled)
if (IsCanceling)
{
claimLayer.RemoveClaim(self);
return NextActivity;

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled)
if (IsCanceling)
return NextActivity;
var target = targets.ClosestTo(self);

View File

@@ -48,8 +48,8 @@ namespace OpenRA.Mods.Common.Activities
public override bool Cancel(Actor self, bool keepQueue = false)
{
if (!IsCanceled && inner != null && !inner.Cancel(self))
return false;
if (!IsCanceling && inner != null)
inner.Cancel(self);
return base.Cancel(self, keepQueue);
}

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled)
if (IsCanceling)
return NextActivity;
bool targetIsHiddenActor;

View File

@@ -144,37 +144,9 @@ namespace OpenRA.Mods.Common.Activities
}
}
public override bool Cancel(Actor self, bool keepQueue = false)
{
if (ChildActivity == null)
return base.Cancel(self, keepQueue);
// Although MoveFirstHalf and MoveSecondHalf can't be interrupted,
// we prevent them from moving forever by removing the path.
if (path != null)
path.Clear();
// Remove queued activities
if (!keepQueue && NextInQueue != null)
NextInQueue = null;
// In current implementation, ChildActivity can be Turn, MoveFirstHalf and MoveSecondHalf.
// Turn may be interrupted freely while they are turning.
// Unlike Turn, MoveFirstHalf and MoveSecondHalf are not Interruptable, but clearing the
// path guarantees that they will return as soon as possible, once the actor is back in a
// valid position.
// This means that it is safe to unconditionally return true, which avoids breaking parent
// activities that rely on cancellation succeeding (but not necessarily immediately)
ChildActivity.Cancel(self, false);
return true;
}
public override Activity Tick(Actor self)
{
// ChildActivity is the top priority, unlike other activities.
// Even if this activity is canceled, we must let the child be run so that units
// will not end up in an odd place.
// Let the child be run so that units will not end up in an odd place.
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
@@ -187,7 +159,7 @@ namespace OpenRA.Mods.Common.Activities
// If the actor is inside a tunnel then we must let them move
// all the way through before moving to the next activity
if (IsCanceled && self.Location.Layer != CustomMovementLayerType.Tunnel)
if (IsCanceling && self.Location.Layer != CustomMovementLayerType.Tunnel)
return NextActivity;
if (mobile.IsTraitDisabled || mobile.IsTraitPaused)
@@ -440,7 +412,7 @@ namespace OpenRA.Mods.Common.Activities
var fromSubcellOffset = map.Grid.OffsetOfSubCell(mobile.FromSubCell);
var toSubcellOffset = map.Grid.OffsetOfSubCell(mobile.ToSubCell);
if (!IsCanceled || self.Location.Layer == CustomMovementLayerType.Tunnel)
if (!IsCanceling || self.Location.Layer == CustomMovementLayerType.Tunnel)
{
var nextCell = parent.PopPath(self);
if (nextCell != null)

View File

@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Activities
{
// We are done here if the order was cancelled for any
// reason except the target moving.
if (IsCanceled || !repath || !targetIsValid)
if (IsCanceling || !repath || !targetIsValid)
return NextActivity;
// Target has moved, and MoveAdjacentTo is still valid.
@@ -169,8 +169,8 @@ namespace OpenRA.Mods.Common.Activities
public override bool Cancel(Actor self, bool keepQueue = false)
{
if (!IsCanceled && inner != null && !inner.Cancel(self))
return false;
if (!IsCanceling && inner != null)
inner.Cancel(self);
return base.Cancel(self);
}

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Activities
return this;
}
if (IsCanceled || target.Type == TargetType.Invalid)
if (IsCanceling || target.Type == TargetType.Invalid)
return NextActivity;
if (mobile.IsTraitDisabled || mobile.IsTraitPaused)

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Activities
if (cargo != carryall.Carryable)
return NextActivity;
if (cargo.IsDead || IsCanceled || carryable.IsTraitDisabled || !cargo.AppearsFriendlyTo(self))
if (cargo.IsDead || IsCanceling || carryable.IsTraitDisabled || !cargo.AppearsFriendlyTo(self))
{
carryall.UnreserveCarryable(self);
return NextActivity;
@@ -161,8 +161,8 @@ namespace OpenRA.Mods.Common.Activities
public override bool Cancel(Actor self, bool keepQueue = false)
{
if (!IsCanceled && innerActivity != null && !innerActivity.Cancel(self))
return false;
if (!IsCanceling && innerActivity != null)
innerActivity.Cancel(self);
return base.Cancel(self, keepQueue);
}

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled)
if (IsCanceling)
return NextActivity;
if (host.Type == TargetType.Invalid)

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Mods.Common.Activities
{
public override Activity Tick(Actor self)
{
if (IsCanceled) return NextActivity;
if (IsCanceling) return NextActivity;
self.Dispose();
return null;
}

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled)
if (IsCanceling)
{
if (remainingTicks-- == 0)
return NextActivity;

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled)
if (IsCanceling)
return NextActivity;
if (ChildActivity != null)
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Activities
protected override void OnLastRun(Actor self)
{
if (!IsCanceled)
if (!IsCanceling)
DoTransform(self);
}

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (IsInterruptible && IsCanceled)
if (IsInterruptible && IsCanceling)
return NextActivity;
if (disablable != null && disablable.IsTraitDisabled)

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
cargo.Unloading = false;
if (IsCanceled || cargo.IsEmpty(self))
if (IsCanceling || cargo.IsEmpty(self))
return NextActivity;
foreach (var inu in notifiers)

View File

@@ -43,8 +43,8 @@ namespace OpenRA.Mods.Common.Activities
public override bool Cancel(Actor self, bool keepQueue = false)
{
if (!IsCanceled && inner != null && !inner.Cancel(self))
return false;
if (!IsCanceling && inner != null)
inner.Cancel(self);
return base.Cancel(self, keepQueue);
}

View File

@@ -45,9 +45,7 @@ namespace OpenRA.Mods.Common.Activities
public override bool Cancel(Actor self, bool keepQueue = false)
{
if (!base.Cancel(self, keepQueue))
return false;
base.Cancel(self, keepQueue);
Dispose();
return true;
}

View File

@@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Traits
public override Activity Tick(Actor self)
{
if (IsCanceled)
if (IsCanceling)
{
// Cancel the requested target, but keep firing on it while in range
attack.opportunityTarget = attack.requestedTarget;

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
// This activity can't move to reacquire hidden targets, so use the
// Recalculate overload that invalidates hidden targets.
target = target.RecalculateInvalidatingHiddenTargets(self.Owner);
if (IsCanceled || !target.IsValidFor(self) || !attack.IsReachableTarget(target, allowMove))
if (IsCanceling || !target.IsValidFor(self) || !attack.IsReachableTarget(target, allowMove))
return NextActivity;
attack.DoAttack(self, target);