Make Tick return bool

This commit is contained in:
tovl
2019-05-14 21:13:25 +02:00
committed by teinarss
parent 09c1611239
commit 3790169db9
49 changed files with 328 additions and 318 deletions

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Activities
token = conditionManager.GrantCondition(self, attackMove.Info.AssaultMoveCondition);
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
// We are not currently attacking a target, so scan for new targets.
if (!IsCanceling && ChildActivity != null && ChildActivity.NextActivity == null && autoTarget != null)
@@ -74,13 +74,9 @@ namespace OpenRA.Mods.Common.Activities
}
}
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
// The last queued childactivity is guaranteed to be the inner move, so if we get here it means
// we have reached our destination and there are no more enemies on our path.
return NextActivity;
// The last queued childactivity is guaranteed to be the inner move, so if the childactivity
// queue is empty it means we have reached our destination and there are no more enemies on our path.
return TickChild(self);
}
protected override void OnLastRun(Actor self)

View File

@@ -34,10 +34,10 @@ namespace OpenRA.Mods.Common.Activities
IsInterruptible = false;
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
if (disableable != null && disableable.IsTraitDisabled)
return this;
return false;
var pos = length > 1
? WPos.Lerp(start, end, ticks, length - 1)
@@ -45,9 +45,9 @@ namespace OpenRA.Mods.Common.Activities
positionable.SetVisualPosition(self, pos);
if (++ticks >= length)
return NextActivity;
return true;
return this;
return false;
}
public override IEnumerable<Target> GetTargets(Actor self)

View File

@@ -45,10 +45,10 @@ namespace OpenRA.Mods.Common.Activities
lastVisibleTarget = Target.FromPos(initialTargetPosition.Value);
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
if (IsCanceling)
return NextActivity;
return true;
bool targetIsHiddenActor;
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Activities
// If we are ticking again after previously sequencing a MoveWithRange then that move must have completed
// Either we are in range and can see the target, or we've lost track of it and should give up
if (wasMovingWithinRange && targetIsHiddenActor)
return NextActivity;
return true;
wasMovingWithinRange = false;
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Activities
// Target is hidden or dead, and we don't have a fallback position to move towards
if (useLastVisibleTarget && !lastVisibleTarget.IsValidFor(self))
return NextActivity;
return true;
var pos = self.CenterPosition;
var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target;
@@ -79,12 +79,12 @@ namespace OpenRA.Mods.Common.Activities
// We've reached the required range - if the target is visible and valid then we wait
// otherwise if it is hidden or dead we give up
if (checkTarget.IsInRange(pos, maxRange) && !checkTarget.IsInRange(pos, minRange))
return useLastVisibleTarget ? NextActivity : this;
return useLastVisibleTarget;
// Move into range
wasMovingWithinRange = true;
QueueChild(move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, targetLineColor));
return this;
return false;
}
}
}

View File

@@ -144,18 +144,18 @@ namespace OpenRA.Mods.Common.Activities
}
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
// If the actor is inside a tunnel then we must let them move
// all the way through before moving to the next activity
if (IsCanceling && self.Location.Layer != CustomMovementLayerType.Tunnel)
return NextActivity;
return true;
if (mobile.IsTraitDisabled || mobile.IsTraitPaused)
return this;
return false;
if (destination == mobile.ToCell)
return NextActivity;
return true;
if (path == null)
path = EvalPath();
@@ -163,22 +163,21 @@ namespace OpenRA.Mods.Common.Activities
if (path.Count == 0)
{
destination = mobile.ToCell;
return this;
return false;
}
destination = path[0];
var nextCell = PopPath(self);
if (nextCell == null)
return this;
return false;
var firstFacing = self.World.Map.FacingBetween(mobile.FromCell, nextCell.Value.First, mobile.Facing);
if (firstFacing != mobile.Facing)
{
path.Add(nextCell.Value.First);
QueueChild(new Turn(self, firstFacing));
return this;
return false;
}
mobile.SetLocation(mobile.FromCell, mobile.FromSubCell, nextCell.Value.First, nextCell.Value.Second);
@@ -192,7 +191,7 @@ namespace OpenRA.Mods.Common.Activities
(map.Grid.OffsetOfSubCell(mobile.FromSubCell) + map.Grid.OffsetOfSubCell(mobile.ToSubCell)) / 2;
QueueChild(new MoveFirstHalf(this, from, to, mobile.Facing, mobile.Facing, 0));
return this;
return false;
}
Pair<CPos, SubCell>? PopPath(Actor self)
@@ -309,10 +308,10 @@ namespace OpenRA.Mods.Common.Activities
}
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
if (Move.mobile.IsTraitDisabled)
return this;
return false;
var ret = InnerTick(self, Move.mobile);
@@ -322,10 +321,10 @@ namespace OpenRA.Mods.Common.Activities
UpdateCenterLocation(self, Move.mobile);
if (ret == this)
return ret;
return false;
Queue(ret);
return NextActivity;
return true;
}
Activity InnerTick(Actor self, Mobile mobile)

View File

@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Activities
QueueChild(Mobile.MoveTo(() => CalculatePathToTarget(self)));
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
bool targetIsHiddenActor;
var oldTargetLocation = lastVisibleTargetLocation;
@@ -119,11 +119,9 @@ namespace OpenRA.Mods.Common.Activities
if (!IsCanceling && shouldRepath)
QueueChild(Mobile.MoveTo(() => CalculatePathToTarget(self)));
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
return NextActivity;
// The last queued childactivity is guaranteed to be the inner move, so if the childactivity
// queue is empty it means we have reached our destination.
return TickChild(self);
}
List<CPos> CalculatePathToTarget(Actor self)

View File

@@ -35,31 +35,28 @@ namespace OpenRA.Mods.Common.Activities
targetStartPos = target.Positions.PositionClosestTo(self.CenterPosition);
}
public override Activity Tick(Actor self)
public override bool Tick(Actor self)
{
if (IsCanceling || target.Type == TargetType.Invalid)
return NextActivity;
return true;
if (mobile.IsTraitDisabled || mobile.IsTraitPaused)
return this;
return false;
var currentPos = self.CenterPosition;
var targetPos = target.Positions.PositionClosestTo(currentPos);
// Give up if the target has moved too far
if (targetMovementThreshold > WDist.Zero && (targetPos - targetStartPos).LengthSquared > targetMovementThreshold.LengthSquared)
return NextActivity;
return true;
// Turn if required
var delta = targetPos - currentPos;
var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : mobile.Facing;
if (facing != mobile.Facing)
{
var turn = ActivityUtils.RunActivity(self, new Turn(self, facing));
if (turn != null)
QueueChild(turn);
return this;
QueueChild(new Turn(self, facing));
return false;
}
// Can complete the move in this step
@@ -67,13 +64,12 @@ namespace OpenRA.Mods.Common.Activities
if (delta.LengthSquared <= speed * speed)
{
mobile.SetVisualPosition(self, targetPos);
return NextActivity;
return true;
}
// Move towards the target
mobile.SetVisualPosition(self, currentPos + delta * speed / delta.Length);
return this;
return false;
}
public override IEnumerable<Target> GetTargets(Actor self)