Move ChildActivity handling into base Activity class.

This commit is contained in:
tovl
2019-04-30 22:45:02 +02:00
committed by teinarss
parent 37379daf3c
commit b9c302a73a
43 changed files with 139 additions and 342 deletions

View File

@@ -102,13 +102,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
Cancel(self);
@@ -125,7 +118,7 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft.Info.CanHover && !skipHeightAdjustment && dat != aircraft.Info.CruiseAltitude)
{
if (dat <= aircraft.LandAltitude)
QueueChild(self, new TakeOff(self, target), true);
QueueChild(new TakeOff(self, target));
else
VerticalTakeOffOrLandTick(self, aircraft, aircraft.Facing, aircraft.Info.CruiseAltitude);
@@ -136,7 +129,7 @@ namespace OpenRA.Mods.Common.Activities
}
else if (dat <= aircraft.LandAltitude)
{
QueueChild(self, new TakeOff(self, target), true);
QueueChild(new TakeOff(self, target));
return this;
}

View File

@@ -65,13 +65,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
Cancel(self);
@@ -121,7 +114,7 @@ namespace OpenRA.Mods.Common.Activities
// If all valid weapons have depleted their ammo and Rearmable trait exists, return to RearmActor to reload and then resume the activity
if (rearmable != null && !useLastVisibleTarget && attackAircraft.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self)))
{
QueueChild(self, new ReturnToBase(self, aircraft.Info.AbortOnResupply), true);
QueueChild(new ReturnToBase(self, aircraft.Info.AbortOnResupply));
return this;
}
@@ -139,7 +132,7 @@ namespace OpenRA.Mods.Common.Activities
}
// Fly towards the last known position
QueueChild(self, new Fly(self, target, WDist.Zero, lastVisibleMaximumRange, checkTarget.CenterPosition, Color.Red), true);
QueueChild(new Fly(self, target, WDist.Zero, lastVisibleMaximumRange, checkTarget.CenterPosition, Color.Red));
return this;
}
@@ -148,21 +141,21 @@ namespace OpenRA.Mods.Common.Activities
var isAirborne = self.World.Map.DistanceAboveTerrain(pos).Length >= aircraft.Info.MinAirborneAltitude;
if (!isAirborne)
QueueChild(self, new TakeOff(self), true);
QueueChild(new TakeOff(self));
if (attackAircraft.Info.AttackType == AirAttackType.Strafe)
{
if (target.IsInRange(pos, attackAircraft.GetMinimumRange()))
QueueChild(self, new FlyTimed(ticksUntilTurn, self), true);
QueueChild(new FlyTimed(ticksUntilTurn, self));
QueueChild(self, new Fly(self, target, target.CenterPosition, Color.Red), true);
QueueChild(self, new FlyTimed(ticksUntilTurn, self));
QueueChild(new Fly(self, target, target.CenterPosition, Color.Red));
QueueChild(new FlyTimed(ticksUntilTurn, self));
}
else
{
var minimumRange = attackAircraft.GetMinimumRangeVersusTarget(target);
if (!target.IsInRange(pos, lastVisibleMaximumRange) || target.IsInRange(pos, minimumRange))
QueueChild(self, new Fly(self, target, minimumRange, lastVisibleMaximumRange, target.CenterPosition, Color.Red), true);
QueueChild(new Fly(self, target, minimumRange, lastVisibleMaximumRange, target.CenterPosition, Color.Red));
else if (isAirborne) // Don't use 'else' to avoid conflict with TakeOff
Fly.VerticalTakeOffOrLandTick(self, aircraft, desiredFacing, aircraft.Info.CruiseAltitude);
}

View File

@@ -47,13 +47,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
Cancel(self);
@@ -96,7 +89,7 @@ namespace OpenRA.Mods.Common.Activities
}
wasMovingWithinRange = true;
QueueChild(self, aircraft.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, targetLineColor), true);
QueueChild(aircraft.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, targetLineColor));
return this;
}
}

View File

@@ -73,13 +73,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (IsCanceling || target.Type == TargetType.Invalid)
{
if (landingInitiated)
@@ -94,7 +87,7 @@ namespace OpenRA.Mods.Common.Activities
var dat = self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition);
if (dat > aircraft.LandAltitude && dat < aircraft.Info.CruiseAltitude)
{
QueueChild(self, new TakeOff(self), true);
QueueChild(new TakeOff(self));
return this;
}
@@ -125,7 +118,7 @@ namespace OpenRA.Mods.Common.Activities
if (!newLocation.HasValue)
{
Cancel(self, true);
QueueChild(self, aircraft.MoveTo(landingCell, 0), true);
QueueChild(aircraft.MoveTo(landingCell, 0));
return this;
}
@@ -140,10 +133,10 @@ namespace OpenRA.Mods.Common.Activities
// Move towards landing location
if (aircraft.Info.VTOL && (pos - targetPosition).HorizontalLengthSquared != 0)
{
QueueChild(self, new Fly(self, Target.FromPos(targetPosition)), true);
QueueChild(new Fly(self, Target.FromPos(targetPosition)));
if (desiredFacing != -1)
QueueChild(self, new Turn(self, desiredFacing));
QueueChild(new Turn(self, desiredFacing));
return this;
}
@@ -199,11 +192,11 @@ namespace OpenRA.Mods.Common.Activities
turnRadius = Fly.CalculateTurnRadius(aircraft.Info.Speed, aircraft.Info.TurnSpeed);
// Move along approach trajectory.
QueueChild(self, new Fly(self, Target.FromPos(w1), WDist.Zero, new WDist(turnRadius * 3)), true);
QueueChild(self, new Fly(self, Target.FromPos(w2)), true);
QueueChild(new Fly(self, Target.FromPos(w1), WDist.Zero, new WDist(turnRadius * 3)));
QueueChild(new Fly(self, Target.FromPos(w2)));
// Fix a problem when the airplane is sent to land near the landing cell
QueueChild(self, new Fly(self, Target.FromPos(w3), WDist.Zero, new WDist(turnRadius / 2)), true);
QueueChild(new Fly(self, Target.FromPos(w3), WDist.Zero, new WDist(turnRadius / 2)));
finishedApproach = true;
return this;
}
@@ -216,9 +209,9 @@ namespace OpenRA.Mods.Common.Activities
{
// Maintain holding pattern.
if (aircraft.Info.CanHover)
QueueChild(self, new Wait(25), true);
QueueChild(new Wait(25));
else
QueueChild(self, new FlyCircle(self, 25), true);
QueueChild(new FlyCircle(self, 25));
self.NotifyBlocker(blockingCells);
finishedApproach = false;

View File

@@ -68,13 +68,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
// Refuse to take off if it would land immediately again.
// Special case: Don't kill other deploy hotkey activities.
if (aircraft.ForceLanding)
@@ -113,15 +106,14 @@ namespace OpenRA.Mods.Common.Activities
var randomPosition = WVec.FromPDF(self.World.SharedRandom, 2) * distanceLength / 1024;
var target = Target.FromPos(nearestResupplier.CenterPosition + randomPosition);
QueueChild(self, new Fly(self, target, WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green), true);
QueueChild(new Fly(self, target, WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green));
}
return this;
}
QueueChild(self, new Fly(self, Target.FromActor(nearestResupplier), WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green),
true);
QueueChild(self, new FlyCircle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport), true);
QueueChild(new Fly(self, Target.FromActor(nearestResupplier), WDist.Zero, aircraft.Info.WaitDistanceFromResupplyBase, targetLineColor: Color.Green));
QueueChild(new FlyCircle(self, aircraft.Info.NumberOfTicksToVerifyAvailableAirport));
return this;
}
@@ -140,13 +132,13 @@ namespace OpenRA.Mods.Common.Activities
facing = 192;
aircraft.MakeReservation(dest);
QueueChild(self, new Land(self, Target.FromActor(dest), offset, facing), true);
QueueChild(self, new Resupply(self, dest, WDist.Zero), true);
QueueChild(new Land(self, Target.FromActor(dest), offset, facing));
QueueChild(new Resupply(self, dest, WDist.Zero));
if (aircraft.Info.TakeOffOnResupply && !alwaysLand)
QueueChild(self, new TakeOff(self));
QueueChild(new TakeOff(self));
}
else
QueueChild(self, new Fly(self, Target.FromActor(dest)), true);
QueueChild(new Fly(self, Target.FromActor(dest)));
resupplied = true;
return this;

View File

@@ -64,13 +64,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
// Refuse to take off if it would land immediately again.
if (aircraft.ForceLanding)
{
@@ -100,7 +93,7 @@ namespace OpenRA.Mods.Common.Activities
if (!aircraft.Info.VTOL && assignTargetOnFirstRun)
return NextActivity;
QueueChild(self, new AttackMoveActivity(self, () => move.MoveToTarget(self, target)), true);
QueueChild(new AttackMoveActivity(self, () => move.MoveToTarget(self, target)));
moveToRallyPoint = false;
return this;
}

View File

@@ -85,12 +85,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
return this;
}
if (IsCanceling)
return NextActivity;
@@ -135,7 +129,7 @@ namespace OpenRA.Mods.Common.Activities
// Move towards the last known position
wasMovingWithinRange = true;
QueueChild(self, move.MoveWithinRange(target, WDist.Zero, lastVisibleMaximumRange, checkTarget.CenterPosition, Color.Red), true);
QueueChild(move.MoveWithinRange(target, WDist.Zero, lastVisibleMaximumRange, checkTarget.CenterPosition, Color.Red));
return this;
}
@@ -178,7 +172,7 @@ namespace OpenRA.Mods.Common.Activities
var sightRange = rs != null ? rs.Range : WDist.FromCells(2);
attackStatus |= AttackStatus.NeedsToMove;
QueueChild(self, move.MoveWithinRange(target, sightRange, target.CenterPosition, Color.Red), true);
QueueChild(move.MoveWithinRange(target, sightRange, target.CenterPosition, Color.Red));
return AttackStatus.NeedsToMove;
}
@@ -203,7 +197,7 @@ namespace OpenRA.Mods.Common.Activities
attackStatus |= AttackStatus.NeedsToMove;
var checkTarget = useLastVisibleTarget ? lastVisibleTarget : target;
QueueChild(self, move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, Color.Red), true);
QueueChild(move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, Color.Red));
return AttackStatus.NeedsToMove;
}
@@ -211,7 +205,7 @@ namespace OpenRA.Mods.Common.Activities
{
var desiredFacing = (attack.GetTargetPosition(pos, target) - pos).Yaw.Facing;
attackStatus |= AttackStatus.NeedsToTurn;
QueueChild(self, new Turn(self, desiredFacing), true);
QueueChild(new Turn(self, desiredFacing));
return AttackStatus.NeedsToTurn;
}

View File

@@ -39,13 +39,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (IsCanceling || isDocking)
return NextActivity;
@@ -56,7 +49,7 @@ namespace OpenRA.Mods.Common.Activities
// No refineries exist; check again after delay defined in Harvester.
if (harv.LinkedProc == null)
{
QueueChild(self, new Wait(harv.Info.SearchForDeliveryBuildingDelay), true);
QueueChild(new Wait(harv.Info.SearchForDeliveryBuildingDelay));
return this;
}
@@ -69,13 +62,13 @@ namespace OpenRA.Mods.Common.Activities
foreach (var n in self.TraitsImplementing<INotifyHarvesterAction>())
n.MovingToRefinery(self, proc, new FindAndDeliverResources(self));
QueueChild(self, movement.MoveTo(proc.Location + iao.DeliveryOffset, 0), true);
QueueChild(movement.MoveTo(proc.Location + iao.DeliveryOffset, 0));
return this;
}
if (!isDocking)
{
QueueChild(self, new Wait(10), true);
QueueChild(new Wait(10));
isDocking = true;
iao.OnDock(self, this);
return this;

View File

@@ -44,20 +44,14 @@ namespace OpenRA.Mods.Common.Activities
if (assignTargetOnFirstRun)
destination = Target.FromCell(self.World, self.Location);
QueueChild(self, new Land(self, destination, deliverRange), true);
QueueChild(self, new Wait(carryall.Info.BeforeUnloadDelay, false), true);
QueueChild(self, new ReleaseUnit(self));
QueueChild(self, new TakeOff(self));
QueueChild(new Land(self, destination, deliverRange));
QueueChild(new Wait(carryall.Info.BeforeUnloadDelay, false));
QueueChild(new ReleaseUnit(self));
QueueChild(new TakeOff(self));
}
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
return NextActivity;
}

View File

@@ -33,22 +33,15 @@ namespace OpenRA.Mods.Common.Activities
{
// Turn to the required facing.
if (deploy.DeployState == DeployState.Undeployed && deploy.Info.Facing != -1 && canTurn && !moving)
QueueChild(self, new Turn(self, deploy.Info.Facing));
QueueChild(new Turn(self, deploy.Info.Facing));
}
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (IsCanceling || initiated || (deploy.DeployState != DeployState.Deployed && moving))
return NextActivity;
QueueChild(self, new DeployInner(self, deploy), true);
QueueChild(new DeployInner(self, deploy));
initiated = true;
return this;

View File

@@ -35,6 +35,7 @@ namespace OpenRA.Mods.Common.Activities
move = self.Trait<IMove>();
this.target = target;
this.targetLineColor = targetLineColor;
ChildHasPriority = false;
}
/// <summary>
@@ -80,12 +81,9 @@ namespace OpenRA.Mods.Common.Activities
// We need to wait for movement to finish before transitioning to
// the next state or next activity
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
return this;
// Note that lastState refers to what we have just *finished* doing
switch (lastState)
@@ -106,7 +104,7 @@ namespace OpenRA.Mods.Common.Activities
{
// Target lines are managed by this trait, so we do not pass targetLineColor
var initialTargetPosition = (useLastVisibleTarget ? lastVisibleTarget : target).CenterPosition;
QueueChild(self, move.MoveToTarget(self, target, initialTargetPosition), true);
QueueChild(move.MoveToTarget(self, target, initialTargetPosition));
return this;
}
@@ -119,7 +117,7 @@ namespace OpenRA.Mods.Common.Activities
if (TryStartEnter(self, target.Actor))
{
lastState = EnterState.Entering;
QueueChild(self, move.MoveIntoTarget(self, target), true);
QueueChild(move.MoveIntoTarget(self, target));
return this;
}
@@ -139,7 +137,7 @@ namespace OpenRA.Mods.Common.Activities
OnEnterComplete(self, target.Actor);
lastState = EnterState.Exiting;
QueueChild(self, move.MoveIntoWorld(self, self.Location), true);
QueueChild(move.MoveIntoWorld(self, self.Location));
return this;
}

View File

@@ -65,26 +65,19 @@ namespace OpenRA.Mods.Common.Activities
// We have to make sure the actual "harvest" order is not skipped if a third order is queued,
// so we keep deliveredLoad false.
if (harv.IsFull)
QueueChild(self, new DeliverResources(self), true);
QueueChild(new DeliverResources(self));
}
// If an explicit "deliver" order is given, the harvester goes immediately to the refinery.
if (deliverActor != null)
{
QueueChild(self, new DeliverResources(self, deliverActor), true);
QueueChild(new DeliverResources(self, deliverActor));
hasDeliveredLoad = true;
}
}
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (IsCanceling)
return NextActivity;
@@ -102,7 +95,7 @@ namespace OpenRA.Mods.Common.Activities
// Are we full or have nothing more to gather? Deliver resources.
if (harv.IsFull || (!harv.IsEmpty && harv.LastSearchFailed))
{
QueueChild(self, new DeliverResources(self), true);
QueueChild(new DeliverResources(self));
hasDeliveredLoad = true;
return this;
}
@@ -110,7 +103,7 @@ namespace OpenRA.Mods.Common.Activities
// After a failed search, wait and sit still for a bit before searching again.
if (harv.LastSearchFailed && !hasWaited)
{
QueueChild(self, new Wait(harv.Info.WaitDuration), true);
QueueChild(new Wait(harv.Info.WaitDuration));
hasWaited = true;
return this;
}
@@ -147,7 +140,7 @@ namespace OpenRA.Mods.Common.Activities
var unblockCell = deliveryLoc + harv.Info.UnblockCell;
var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5);
self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Green, false);
QueueChild(self, mobile.MoveTo(moveTo, 1), true);
QueueChild(mobile.MoveTo(moveTo, 1));
}
}
@@ -155,7 +148,7 @@ namespace OpenRA.Mods.Common.Activities
}
// If we get here, our search for resources was successful. Commence harvesting.
QueueChild(self, new HarvestResource(self, closestHarvestableCell.Value), true);
QueueChild(new HarvestResource(self, closestHarvestableCell.Value));
lastHarvestedCell = closestHarvestableCell.Value;
hasHarvestedCell = true;
return this;

View File

@@ -49,13 +49,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (IsCanceling || harv.IsFull)
return NextActivity;
@@ -66,7 +59,7 @@ namespace OpenRA.Mods.Common.Activities
n.MovingToResources(self, targetCell, new FindAndDeliverResources(self));
self.SetTargetLine(Target.FromCell(self.World, targetCell), Color.Red, false);
QueueChild(self, move.MoveTo(targetCell, 2), true);
QueueChild(move.MoveTo(targetCell, 2));
return this;
}
@@ -80,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities
var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
if (desired != current)
{
QueueChild(self, new Turn(self, desired), true);
QueueChild(new Turn(self, desired));
return this;
}
}
@@ -94,7 +87,7 @@ namespace OpenRA.Mods.Common.Activities
foreach (var t in self.TraitsImplementing<INotifyHarvesterAction>())
t.Harvested(self, resource);
QueueChild(self, new Wait(harvInfo.BaleLoadDelay), true);
QueueChild(new Wait(harvInfo.BaleLoadDelay));
return this;
}

View File

@@ -47,13 +47,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
switch (dockingState)
{
case DockingState.Wait:
@@ -61,9 +54,9 @@ namespace OpenRA.Mods.Common.Activities
case DockingState.Turn:
dockingState = DockingState.Dock;
QueueChild(self, new Turn(self, DockAngle), true);
QueueChild(new Turn(self, DockAngle));
if (IsDragRequired)
QueueChild(self, new Drag(self, StartDrag, EndDrag, DragLength));
QueueChild(new Drag(self, StartDrag, EndDrag, DragLength));
return this;
case DockingState.Dock:
@@ -90,7 +83,7 @@ namespace OpenRA.Mods.Common.Activities
Harv.LastLinkedProc = Harv.LinkedProc;
Harv.LinkProc(self, null);
if (IsDragRequired)
QueueChild(self, new Drag(self, EndDrag, StartDrag, DragLength), true);
QueueChild(new Drag(self, EndDrag, StartDrag, DragLength));
dockingState = DockingState.Finished;
return this;

View File

@@ -33,13 +33,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (IsCanceling)
return NextActivity;
@@ -47,8 +40,8 @@ namespace OpenRA.Mods.Common.Activities
if (target == null)
return this;
QueueChild(self, new AttackMoveActivity(self, () => move.MoveTo(target.Location, 2)), true);
QueueChild(self, new Wait(25));
QueueChild(new AttackMoveActivity(self, () => move.MoveTo(target.Location, 2)));
QueueChild(new Wait(25));
return this;
}
}

View File

@@ -33,12 +33,13 @@ namespace OpenRA.Mods.Common.Activities
conditionManager = self.TraitOrDefault<ConditionManager>();
attackMove = self.TraitOrDefault<AttackMove>();
isAssaultMove = assaultMoving;
ChildHasPriority = false;
}
protected override void OnFirstRun(Actor self)
{
// Start moving.
QueueChild(self, getInner());
QueueChild(getInner());
if (conditionManager == null || attackMove == null)
return;
@@ -64,21 +65,18 @@ namespace OpenRA.Mods.Common.Activities
foreach (var ab in attackBases)
{
var activity = ab.GetAttackActivity(self, target, true, false);
QueueChild(self, activity);
QueueChild(activity);
ab.OnQueueAttackActivity(self, activity, target, true, false);
}
// Make sure to continue moving when the attack activities have finished.
QueueChild(self, getInner());
QueueChild(getInner());
}
}
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
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.

View File

@@ -47,13 +47,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (IsCanceling)
return NextActivity;
@@ -90,7 +83,7 @@ namespace OpenRA.Mods.Common.Activities
// Move into range
wasMovingWithinRange = true;
QueueChild(self, move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, targetLineColor), true);
QueueChild(move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, targetLineColor));
return this;
}
}

View File

@@ -146,17 +146,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
// Let the child be run so that units will not end up in an odd place.
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
// Child activities such as Turn might have finished.
// If we "return this" in this situation, the unit loses one tick and pauses movement briefly.
if (ChildActivity != null)
return this;
}
// 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)
@@ -188,7 +177,7 @@ namespace OpenRA.Mods.Common.Activities
{
path.Add(nextCell.Value.First);
QueueChild(self, new Turn(self, firstFacing), true);
QueueChild(new Turn(self, firstFacing));
return this;
}
@@ -202,7 +191,7 @@ namespace OpenRA.Mods.Common.Activities
var to = Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) +
(map.Grid.OffsetOfSubCell(mobile.FromSubCell) + map.Grid.OffsetOfSubCell(mobile.ToSubCell)) / 2;
QueueChild(self, new MoveFirstHalf(this, from, to, mobile.Facing, mobile.Facing, 0), true);
QueueChild(new MoveFirstHalf(this, from, to, mobile.Facing, mobile.Facing, 0));
return this;
}
@@ -335,7 +324,7 @@ namespace OpenRA.Mods.Common.Activities
if (ret == this)
return ret;
Queue(self, ret);
Queue(ret);
return NextActivity;
}

View File

@@ -48,6 +48,7 @@ namespace OpenRA.Mods.Common.Activities
Mobile = self.Trait<Mobile>();
pathFinder = self.World.WorldActor.Trait<IPathFinder>();
domainIndex = self.World.WorldActor.Trait<DomainIndex>();
ChildHasPriority = false;
// The target may become hidden between the initial order request and the first tick (e.g. if queued)
// Moving to any position (even if quite stale) is still better than immediately giving up
@@ -81,7 +82,7 @@ namespace OpenRA.Mods.Common.Activities
protected override void OnFirstRun(Actor self)
{
QueueChild(self, Mobile.MoveTo(() => CalculatePathToTarget(self)));
QueueChild(Mobile.MoveTo(() => CalculatePathToTarget(self)));
}
public override Activity Tick(Actor self)
@@ -116,7 +117,7 @@ namespace OpenRA.Mods.Common.Activities
// Target has moved, and MoveAdjacentTo is still valid.
if (!IsCanceling && shouldRepath)
QueueChild(self, Mobile.MoveTo(() => CalculatePathToTarget(self)));
QueueChild(Mobile.MoveTo(() => CalculatePathToTarget(self)));
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)

View File

@@ -37,13 +37,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (IsCanceling || target.Type == TargetType.Invalid)
return NextActivity;
@@ -64,7 +57,7 @@ namespace OpenRA.Mods.Common.Activities
{
var turn = ActivityUtils.RunActivity(self, new Turn(self, facing));
if (turn != null)
QueueChild(self, turn);
QueueChild(turn);
return this;
}

View File

@@ -56,13 +56,6 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (cargo != carryall.Carryable)
return NextActivity;
@@ -86,7 +79,7 @@ namespace OpenRA.Mods.Common.Activities
switch (state)
{
case PickupState.Intercept:
QueueChild(self, movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4), targetLineColor: Color.Yellow), true);
QueueChild(movement.MoveWithinRange(Target.FromActor(cargo), WDist.FromCells(4), targetLineColor: Color.Yellow));
state = PickupState.LockCarryable;
return this;
@@ -101,15 +94,15 @@ namespace OpenRA.Mods.Common.Activities
{
// Land at the target location
var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
QueueChild(self, new Land(self, Target.FromActor(cargo), -carryableBody.LocalToWorld(localOffset), carryableFacing.Facing), true);
QueueChild(new Land(self, Target.FromActor(cargo), -carryableBody.LocalToWorld(localOffset), carryableFacing.Facing));
// Pause briefly before attachment for visual effect
if (delay > 0)
QueueChild(self, new Wait(delay, false));
QueueChild(new Wait(delay, false));
// Remove our carryable from world
QueueChild(self, new CallFunc(() => Attach(self)));
QueueChild(self, new TakeOff(self));
QueueChild(new CallFunc(() => Attach(self)));
QueueChild(new TakeOff(self));
return this;
}
}

View File

@@ -75,19 +75,12 @@ namespace OpenRA.Mods.Common.Activities
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
// HACK: If the activity is cancelled while we're already resupplying (or about to start resupplying),
// move actor outside the resupplier footprint
// TODO: This check is nowhere near robust enough, and should be rewritten
if (IsCanceling && host.IsInRange(self.CenterPosition, closeEnough))
{
QueueChild(self, self.Trait<IMove>().MoveToTarget(self, host), true);
QueueChild(self.Trait<IMove>().MoveToTarget(self, host));
foreach (var notifyResupply in notifyResupplies)
notifyResupply.ResupplyTick(host.Actor, self, ResupplyType.None);

View File

@@ -37,10 +37,10 @@ namespace OpenRA.Mods.Common.Activities
protected override void OnFirstRun(Actor self)
{
if (self.Info.HasTraitInfo<IFacingInfo>())
QueueChild(self, new Turn(self, Facing));
QueueChild(new Turn(self, Facing));
if (self.Info.HasTraitInfo<AircraftInfo>())
QueueChild(self, new Land(self));
QueueChild(new Land(self));
}
public override Activity Tick(Actor self)
@@ -48,12 +48,6 @@ namespace OpenRA.Mods.Common.Activities
if (IsCanceling)
return NextActivity;
if (ChildActivity != null)
{
ActivityUtils.RunActivity(self, ChildActivity);
return this;
}
// Prevent deployment in bogus locations
var transforms = self.TraitOrDefault<Transforms>();
if (transforms != null && !transforms.CanDeploy())
@@ -72,7 +66,7 @@ namespace OpenRA.Mods.Common.Activities
IsInterruptible = false;
// Wait forever
QueueChild(self, new WaitFor(() => false));
QueueChild(new WaitFor(() => false));
makeAnimation.Reverse(self, () => DoTransform(self));
return this;
}

View File

@@ -77,27 +77,20 @@ namespace OpenRA.Mods.Common.Activities
if (aircraft != null)
{
// Queue the activity even if already landed in case self.Location != destination
QueueChild(self, new Land(self, destination, unloadRange));
QueueChild(new Land(self, destination, unloadRange));
takeOffAfterUnload = !aircraft.AtLandAltitude;
}
else
{
var cell = self.World.Map.Clamp(this.self.World.Map.CellContaining(destination.CenterPosition));
QueueChild(self, new Move(self, cell, unloadRange));
QueueChild(new Move(self, cell, unloadRange));
}
QueueChild(self, new Wait(cargo.Info.BeforeUnloadDelay));
QueueChild(new Wait(cargo.Info.BeforeUnloadDelay));
}
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (IsCanceling || cargo.IsEmpty(self))
return NextActivity;
@@ -113,7 +106,7 @@ namespace OpenRA.Mods.Common.Activities
if (exitSubCell == null)
{
self.NotifyBlocker(BlockedExitCells(actor));
QueueChild(self, new Wait(10), true);
QueueChild(new Wait(10));
return this;
}
@@ -138,10 +131,10 @@ namespace OpenRA.Mods.Common.Activities
{
Cancel(self, true);
if (cargo.Info.AfterUnloadDelay > 0)
QueueChild(self, new Wait(cargo.Info.AfterUnloadDelay, false), true);
QueueChild(new Wait(cargo.Info.AfterUnloadDelay, false));
if (takeOffAfterUnload)
QueueChild(self, new TakeOff(self), true);
QueueChild(new TakeOff(self));
}
return this;

View File

@@ -11,7 +11,6 @@
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities
{
@@ -28,18 +27,11 @@ namespace OpenRA.Mods.Common.Activities
protected override void OnFirstRun(Actor self)
{
QueueChild(self, inner);
QueueChild(inner);
}
public override Activity Tick(Actor self)
{
if (ChildActivity != null)
{
ChildActivity = ActivityUtils.RunActivity(self, ChildActivity);
if (ChildActivity != null)
return this;
}
if (transportable != null)
transportable.MovementCancelled(self);