From b9c302a73adde722d0f963335220407ed724865c Mon Sep 17 00:00:00 2001 From: tovl Date: Tue, 30 Apr 2019 22:45:02 +0200 Subject: [PATCH] Move ChildActivity handling into base Activity class. --- OpenRA.Game/Activities/Activity.cs | 34 ++++++++++--------- OpenRA.Game/Actor.cs | 2 +- OpenRA.Game/Traits/ActivityUtils.cs | 4 +-- OpenRA.Mods.Cnc/Activities/LayMines.cs | 16 +++------ OpenRA.Mods.Cnc/Activities/Leap.cs | 17 ++-------- OpenRA.Mods.Cnc/Activities/LeapAttack.cs | 13 ++----- OpenRA.Mods.Cnc/Traits/Attack/AttackTesla.cs | 20 ++--------- OpenRA.Mods.Common/Activities/Air/Fly.cs | 11 ++---- .../Activities/Air/FlyAttack.cs | 21 ++++-------- .../Activities/Air/FlyFollow.cs | 9 +---- OpenRA.Mods.Common/Activities/Air/Land.cs | 25 +++++--------- .../Activities/Air/ReturnToBase.cs | 22 ++++-------- OpenRA.Mods.Common/Activities/Air/TakeOff.cs | 9 +---- OpenRA.Mods.Common/Activities/Attack.cs | 14 +++----- .../Activities/DeliverResources.cs | 13 ++----- OpenRA.Mods.Common/Activities/DeliverUnit.cs | 14 +++----- .../Activities/DeployForGrantedCondition.cs | 11 ++---- OpenRA.Mods.Common/Activities/Enter.cs | 14 ++++---- .../Activities/FindAndDeliverResources.cs | 19 ++++------- .../Activities/HarvestResource.cs | 13 ++----- .../Activities/HarvesterDockSequence.cs | 13 ++----- OpenRA.Mods.Common/Activities/Hunt.cs | 11 ++---- .../Activities/Move/AttackMoveActivity.cs | 14 ++++---- OpenRA.Mods.Common/Activities/Move/Follow.cs | 9 +---- OpenRA.Mods.Common/Activities/Move/Move.cs | 17 ++-------- .../Activities/Move/MoveAdjacentTo.cs | 5 +-- .../Activities/Move/VisualMoveIntoTarget.cs | 9 +---- OpenRA.Mods.Common/Activities/PickupUnit.cs | 17 +++------- OpenRA.Mods.Common/Activities/Resupply.cs | 9 +---- OpenRA.Mods.Common/Activities/Transform.cs | 12 ++----- OpenRA.Mods.Common/Activities/UnloadCargo.cs | 19 ++++------- .../Activities/WaitForTransport.cs | 10 +----- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 2 +- .../Traits/Attack/AttackFollow.cs | 9 +---- .../Traits/Buildings/Refinery.cs | 6 ++-- .../Buildings/TransformsIntoAircraft.cs | 2 +- .../Buildings/TransformsIntoEntersTunnels.cs | 2 +- .../Traits/Buildings/TransformsIntoMobile.cs | 2 +- .../Buildings/TransformsIntoPassenger.cs | 2 +- .../Buildings/TransformsIntoRepairable.cs | 2 +- .../Conditions/GrantConditionOnDeploy.cs | 2 +- OpenRA.Mods.Common/Traits/Mobile.cs | 4 +-- OpenRA.Mods.Common/Traits/Repairable.cs | 2 +- 43 files changed, 139 insertions(+), 342 deletions(-) diff --git a/OpenRA.Game/Activities/Activity.cs b/OpenRA.Game/Activities/Activity.cs index 4debd90555..d9aa2a149e 100644 --- a/OpenRA.Game/Activities/Activity.cs +++ b/OpenRA.Game/Activities/Activity.cs @@ -41,11 +41,13 @@ namespace OpenRA.Activities public Activity NextActivity { get; protected set; } public bool IsInterruptible { get; protected set; } + public bool ChildHasPriority { get; protected set; } public bool IsCanceling { get { return State == ActivityState.Canceling; } } public Activity() { IsInterruptible = true; + ChildHasPriority = true; } public Activity TickOuter(Actor self) @@ -59,7 +61,18 @@ namespace OpenRA.Activities State = ActivityState.Active; } + if (ChildHasPriority) + { + ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); + if (ChildActivity != null) + return this; + } + var ret = Tick(self); + + if (ChildActivity != null && ChildActivity.State == ActivityState.Queued) + ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); + if (ret != this) { State = ActivityState.Done; @@ -113,20 +126,20 @@ namespace OpenRA.Activities State = ActivityState.Canceling; } - public virtual void Queue(Actor self, Activity activity) + public void Queue(Activity activity) { if (NextActivity != null) - NextActivity.Queue(self, activity); + NextActivity.Queue(activity); else NextActivity = activity; } - public virtual void QueueChild(Actor self, Activity activity, bool pretick = false) + public void QueueChild(Activity activity) { if (ChildActivity != null) - ChildActivity.Queue(self, activity); + ChildActivity.Queue(activity); else - ChildActivity = pretick ? ActivityUtils.RunActivity(self, activity) : activity; + ChildActivity = activity; } /// @@ -187,15 +200,4 @@ namespace OpenRA.Activities yield return a; } } - - public static class ActivityExts - { - public static IEnumerable GetTargetQueue(this Actor self) - { - return self.CurrentActivity - .Iterate(u => u.NextActivity) - .TakeWhile(u => u != null) - .SelectMany(u => u.GetTargets(self)); - } - } } diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index d32329164d..1cce51b4fc 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -222,7 +222,7 @@ namespace OpenRA if (CurrentActivity == null) CurrentActivity = nextActivity; else - CurrentActivity.Queue(this, nextActivity); + CurrentActivity.Queue(nextActivity); } public void CancelActivity() diff --git a/OpenRA.Game/Traits/ActivityUtils.cs b/OpenRA.Game/Traits/ActivityUtils.cs index f78c3ec24d..00896ab499 100644 --- a/OpenRA.Game/Traits/ActivityUtils.cs +++ b/OpenRA.Game/Traits/ActivityUtils.cs @@ -51,10 +51,10 @@ namespace OpenRA.Traits return act; } - public static Activity SequenceActivities(Actor self, params Activity[] acts) + public static Activity SequenceActivities(params Activity[] acts) { return acts.Reverse().Aggregate( - (next, a) => { a.Queue(self, next); return a; }); + (next, a) => { a.Queue(next); return a; }); } } } diff --git a/OpenRA.Mods.Cnc/Activities/LayMines.cs b/OpenRA.Mods.Cnc/Activities/LayMines.cs index 222bae8604..a891945c26 100644 --- a/OpenRA.Mods.Cnc/Activities/LayMines.cs +++ b/OpenRA.Mods.Cnc/Activities/LayMines.cs @@ -39,12 +39,6 @@ namespace OpenRA.Mods.Cnc.Activities public override Activity Tick(Actor self) { - if (ChildActivity != null) - { - ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); - return this; - } - if (IsCanceling) return NextActivity; @@ -59,16 +53,16 @@ namespace OpenRA.Mods.Cnc.Activities return NextActivity; // Add a CloseEnough range of 512 to the Rearm/Repair activities in order to ensure that we're at the host actor - QueueChild(self, new MoveAdjacentTo(self, Target.FromActor(rearmTarget)), true); - QueueChild(self, movement.MoveTo(self.World.Map.CellContaining(rearmTarget.CenterPosition), rearmTarget)); - QueueChild(self, new Resupply(self, rearmTarget, new WDist(512))); + QueueChild(new MoveAdjacentTo(self, Target.FromActor(rearmTarget))); + QueueChild(movement.MoveTo(self.World.Map.CellContaining(rearmTarget.CenterPosition), rearmTarget)); + QueueChild(new Resupply(self, rearmTarget, new WDist(512))); return this; } if ((minefield == null || minefield.Contains(self.Location)) && ShouldLayMine(self, self.Location)) { LayMine(self); - QueueChild(self, new Wait(20), true); // A little wait after placing each mine, for show + QueueChild(new Wait(20)); // A little wait after placing each mine, for show return this; } @@ -80,7 +74,7 @@ namespace OpenRA.Mods.Cnc.Activities var p = minefield.Random(self.World.SharedRandom); if (ShouldLayMine(self, p)) { - QueueChild(self, movement.MoveTo(p, 0), true); + QueueChild(movement.MoveTo(p, 0)); return this; } } diff --git a/OpenRA.Mods.Cnc/Activities/Leap.cs b/OpenRA.Mods.Cnc/Activities/Leap.cs index ff5220c25b..765fdd02a3 100644 --- a/OpenRA.Mods.Cnc/Activities/Leap.cs +++ b/OpenRA.Mods.Cnc/Activities/Leap.cs @@ -72,18 +72,9 @@ namespace OpenRA.Mods.Cnc.Activities public override Activity Tick(Actor self) { - if (canceled) - return NextActivity; - // Correct the visual position after we jumped - if (jumpComplete) - { - if (ChildActivity == null) - return NextActivity; - - ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); - return this; - } + if (canceled || jumpComplete) + return NextActivity; if (target.Type != TargetType.Invalid) targetPosition = target.CenterPosition; @@ -106,9 +97,7 @@ namespace OpenRA.Mods.Cnc.Activities attack.DoAttack(self, target); jumpComplete = true; - QueueChild(self, mobile.VisualMove(self, position, self.World.Map.CenterOfSubCell(destinationCell, destinationSubCell)), true); - - return this; + QueueChild(mobile.VisualMove(self, position, self.World.Map.CenterOfSubCell(destinationCell, destinationSubCell))); } return this; diff --git a/OpenRA.Mods.Cnc/Activities/LeapAttack.cs b/OpenRA.Mods.Cnc/Activities/LeapAttack.cs index 761f413acf..b9a4d158ea 100644 --- a/OpenRA.Mods.Cnc/Activities/LeapAttack.cs +++ b/OpenRA.Mods.Cnc/Activities/LeapAttack.cs @@ -74,13 +74,6 @@ namespace OpenRA.Mods.Cnc.Activities public override Activity Tick(Actor self) { - // Run this even if the target became invalid to avoid visual glitches - if (ChildActivity != null) - { - ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); - return this; - } - if (IsCanceling) return NextActivity; @@ -114,7 +107,7 @@ namespace OpenRA.Mods.Cnc.Activities if (!allowMovement || lastVisibleMaxRange == WDist.Zero || lastVisibleMaxRange < lastVisibleMinRange) return NextActivity; - QueueChild(self, mobile.MoveWithinRange(target, lastVisibleMinRange, lastVisibleMaxRange, checkTarget.CenterPosition, Color.Red), true); + QueueChild(mobile.MoveWithinRange(target, lastVisibleMinRange, lastVisibleMaxRange, checkTarget.CenterPosition, Color.Red)); return this; } @@ -144,11 +137,11 @@ namespace OpenRA.Mods.Cnc.Activities var desiredFacing = (destination - origin).Yaw.Facing; if (mobile.Facing != desiredFacing) { - QueueChild(self, new Turn(self, desiredFacing), true); + QueueChild(new Turn(self, desiredFacing)); return this; } - QueueChild(self, new Leap(self, target, mobile, targetMobile, info.Speed.Length, attack, edible), true); + QueueChild(new Leap(self, target, mobile, targetMobile, info.Speed.Length, attack, edible)); // Re-queue the child activities to kill the target if it didn't die in one go return this; diff --git a/OpenRA.Mods.Cnc/Traits/Attack/AttackTesla.cs b/OpenRA.Mods.Cnc/Traits/Attack/AttackTesla.cs index dc956fdd8c..cde97d8cb3 100644 --- a/OpenRA.Mods.Cnc/Traits/Attack/AttackTesla.cs +++ b/OpenRA.Mods.Cnc/Traits/Attack/AttackTesla.cs @@ -96,13 +96,6 @@ namespace OpenRA.Mods.Cnc.Traits public override Activity Tick(Actor self) { - if (ChildActivity != null) - { - ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); - if (ChildActivity != null) - return this; - } - if (IsCanceling || !attack.CanAttack(self, target)) return NextActivity; @@ -115,8 +108,8 @@ namespace OpenRA.Mods.Cnc.Traits if (!string.IsNullOrEmpty(attack.info.ChargeAudio)) Game.Sound.Play(SoundType.World, attack.info.ChargeAudio, self.CenterPosition); - QueueChild(self, new Wait(attack.info.InitialChargeDelay), true); - QueueChild(self, new ChargeFire(attack, target)); + QueueChild(new Wait(attack.info.InitialChargeDelay)); + QueueChild(new ChargeFire(attack, target)); return this; } @@ -154,13 +147,6 @@ namespace OpenRA.Mods.Cnc.Traits public override Activity Tick(Actor self) { - if (ChildActivity != null) - { - ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); - if (ChildActivity != null) - return this; - } - if (IsCanceling || !attack.CanAttack(self, target)) return NextActivity; @@ -169,7 +155,7 @@ namespace OpenRA.Mods.Cnc.Traits attack.DoAttack(self, target); - QueueChild(self, new Wait(attack.info.ChargeDelay), true); + QueueChild(new Wait(attack.info.ChargeDelay)); return this; } } diff --git a/OpenRA.Mods.Common/Activities/Air/Fly.cs b/OpenRA.Mods.Common/Activities/Air/Fly.cs index f2eb231bb7..61c56659c3 100644 --- a/OpenRA.Mods.Common/Activities/Air/Fly.cs +++ b/OpenRA.Mods.Common/Activities/Air/Fly.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs b/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs index 47ca76a614..a794fc9a2d 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyAttack.cs @@ -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); } diff --git a/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs b/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs index b1ab5c0570..0037af50d7 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyFollow.cs @@ -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; } } diff --git a/OpenRA.Mods.Common/Activities/Air/Land.cs b/OpenRA.Mods.Common/Activities/Air/Land.cs index d26164fce2..bd1f7ad365 100644 --- a/OpenRA.Mods.Common/Activities/Air/Land.cs +++ b/OpenRA.Mods.Common/Activities/Air/Land.cs @@ -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; diff --git a/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs b/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs index 7492ed0f90..17f16dbbe8 100644 --- a/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs +++ b/OpenRA.Mods.Common/Activities/Air/ReturnToBase.cs @@ -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; diff --git a/OpenRA.Mods.Common/Activities/Air/TakeOff.cs b/OpenRA.Mods.Common/Activities/Air/TakeOff.cs index 3ddbac0ebf..faaabcc95e 100644 --- a/OpenRA.Mods.Common/Activities/Air/TakeOff.cs +++ b/OpenRA.Mods.Common/Activities/Air/TakeOff.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Activities/Attack.cs b/OpenRA.Mods.Common/Activities/Attack.cs index de2a3f5182..c6743aaf73 100644 --- a/OpenRA.Mods.Common/Activities/Attack.cs +++ b/OpenRA.Mods.Common/Activities/Attack.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Activities/DeliverResources.cs b/OpenRA.Mods.Common/Activities/DeliverResources.cs index c7b9f61d34..57482fd06a 100644 --- a/OpenRA.Mods.Common/Activities/DeliverResources.cs +++ b/OpenRA.Mods.Common/Activities/DeliverResources.cs @@ -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()) 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; diff --git a/OpenRA.Mods.Common/Activities/DeliverUnit.cs b/OpenRA.Mods.Common/Activities/DeliverUnit.cs index 7325098974..f4e3caa315 100644 --- a/OpenRA.Mods.Common/Activities/DeliverUnit.cs +++ b/OpenRA.Mods.Common/Activities/DeliverUnit.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Activities/DeployForGrantedCondition.cs b/OpenRA.Mods.Common/Activities/DeployForGrantedCondition.cs index 8ad4c1da42..3f657a2b75 100644 --- a/OpenRA.Mods.Common/Activities/DeployForGrantedCondition.cs +++ b/OpenRA.Mods.Common/Activities/DeployForGrantedCondition.cs @@ -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; diff --git a/OpenRA.Mods.Common/Activities/Enter.cs b/OpenRA.Mods.Common/Activities/Enter.cs index a8f26db520..f88aa24592 100644 --- a/OpenRA.Mods.Common/Activities/Enter.cs +++ b/OpenRA.Mods.Common/Activities/Enter.cs @@ -35,6 +35,7 @@ namespace OpenRA.Mods.Common.Activities move = self.Trait(); this.target = target; this.targetLineColor = targetLineColor; + ChildHasPriority = false; } /// @@ -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; } diff --git a/OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs b/OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs index 114436d4db..35a63e44b7 100644 --- a/OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs +++ b/OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs @@ -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; diff --git a/OpenRA.Mods.Common/Activities/HarvestResource.cs b/OpenRA.Mods.Common/Activities/HarvestResource.cs index 4fb9e1f775..4beca9a3d4 100644 --- a/OpenRA.Mods.Common/Activities/HarvestResource.cs +++ b/OpenRA.Mods.Common/Activities/HarvestResource.cs @@ -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()) t.Harvested(self, resource); - QueueChild(self, new Wait(harvInfo.BaleLoadDelay), true); + QueueChild(new Wait(harvInfo.BaleLoadDelay)); return this; } diff --git a/OpenRA.Mods.Common/Activities/HarvesterDockSequence.cs b/OpenRA.Mods.Common/Activities/HarvesterDockSequence.cs index 1f29cb3cf6..069a9f27f4 100644 --- a/OpenRA.Mods.Common/Activities/HarvesterDockSequence.cs +++ b/OpenRA.Mods.Common/Activities/HarvesterDockSequence.cs @@ -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; diff --git a/OpenRA.Mods.Common/Activities/Hunt.cs b/OpenRA.Mods.Common/Activities/Hunt.cs index df1e66ec86..a1d1cba72e 100644 --- a/OpenRA.Mods.Common/Activities/Hunt.cs +++ b/OpenRA.Mods.Common/Activities/Hunt.cs @@ -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; } } diff --git a/OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs b/OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs index 7ad572ae3e..95c08986a0 100644 --- a/OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs +++ b/OpenRA.Mods.Common/Activities/Move/AttackMoveActivity.cs @@ -33,12 +33,13 @@ namespace OpenRA.Mods.Common.Activities conditionManager = self.TraitOrDefault(); attackMove = self.TraitOrDefault(); 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. diff --git a/OpenRA.Mods.Common/Activities/Move/Follow.cs b/OpenRA.Mods.Common/Activities/Move/Follow.cs index 37c440c61d..ad173b7998 100644 --- a/OpenRA.Mods.Common/Activities/Move/Follow.cs +++ b/OpenRA.Mods.Common/Activities/Move/Follow.cs @@ -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; } } diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index 0d5ff56858..6cfe4918a4 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs index d3dd27cd12..293dbc195b 100644 --- a/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs +++ b/OpenRA.Mods.Common/Activities/Move/MoveAdjacentTo.cs @@ -48,6 +48,7 @@ namespace OpenRA.Mods.Common.Activities Mobile = self.Trait(); pathFinder = self.World.WorldActor.Trait(); domainIndex = self.World.WorldActor.Trait(); + 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) diff --git a/OpenRA.Mods.Common/Activities/Move/VisualMoveIntoTarget.cs b/OpenRA.Mods.Common/Activities/Move/VisualMoveIntoTarget.cs index 443b791d4d..4855c5801c 100644 --- a/OpenRA.Mods.Common/Activities/Move/VisualMoveIntoTarget.cs +++ b/OpenRA.Mods.Common/Activities/Move/VisualMoveIntoTarget.cs @@ -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; } diff --git a/OpenRA.Mods.Common/Activities/PickupUnit.cs b/OpenRA.Mods.Common/Activities/PickupUnit.cs index c037b68174..ea93a7d54a 100644 --- a/OpenRA.Mods.Common/Activities/PickupUnit.cs +++ b/OpenRA.Mods.Common/Activities/PickupUnit.cs @@ -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; } } diff --git a/OpenRA.Mods.Common/Activities/Resupply.cs b/OpenRA.Mods.Common/Activities/Resupply.cs index e6b274821c..eb301142dc 100644 --- a/OpenRA.Mods.Common/Activities/Resupply.cs +++ b/OpenRA.Mods.Common/Activities/Resupply.cs @@ -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().MoveToTarget(self, host), true); + QueueChild(self.Trait().MoveToTarget(self, host)); foreach (var notifyResupply in notifyResupplies) notifyResupply.ResupplyTick(host.Actor, self, ResupplyType.None); diff --git a/OpenRA.Mods.Common/Activities/Transform.cs b/OpenRA.Mods.Common/Activities/Transform.cs index f26e30b3bf..99849bfcd0 100644 --- a/OpenRA.Mods.Common/Activities/Transform.cs +++ b/OpenRA.Mods.Common/Activities/Transform.cs @@ -37,10 +37,10 @@ namespace OpenRA.Mods.Common.Activities protected override void OnFirstRun(Actor self) { if (self.Info.HasTraitInfo()) - QueueChild(self, new Turn(self, Facing)); + QueueChild(new Turn(self, Facing)); if (self.Info.HasTraitInfo()) - 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(); 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; } diff --git a/OpenRA.Mods.Common/Activities/UnloadCargo.cs b/OpenRA.Mods.Common/Activities/UnloadCargo.cs index de08b4f667..28fff9d569 100644 --- a/OpenRA.Mods.Common/Activities/UnloadCargo.cs +++ b/OpenRA.Mods.Common/Activities/UnloadCargo.cs @@ -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; diff --git a/OpenRA.Mods.Common/Activities/WaitForTransport.cs b/OpenRA.Mods.Common/Activities/WaitForTransport.cs index f1e72cb9fd..43f44e7179 100644 --- a/OpenRA.Mods.Common/Activities/WaitForTransport.cs +++ b/OpenRA.Mods.Common/Activities/WaitForTransport.cs @@ -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); diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 272835d24b..33f70540a7 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -861,7 +861,7 @@ namespace OpenRA.Mods.Common.Traits public Activity VisualMove(Actor self, WPos fromPos, WPos toPos) { // TODO: Ignore repulsion when moving - return ActivityUtils.SequenceActivities(self, + return ActivityUtils.SequenceActivities( new CallFunc(() => SetVisualPosition(self, fromPos)), new Fly(self, Target.FromPos(toPos))); } diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs index 4a7b9c039d..65aa6a3acc 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackFollow.cs @@ -257,13 +257,6 @@ namespace OpenRA.Mods.Common.Traits public override Activity Tick(Actor self) { - if (ChildActivity != null) - { - ChildActivity = ActivityUtils.RunActivity(self, ChildActivity); - if (ChildActivity != null) - return this; - } - if (IsCanceling) { // Cancel the requested target, but keep firing on it while in range @@ -362,7 +355,7 @@ namespace OpenRA.Mods.Common.Traits } wasMovingWithinRange = true; - QueueChild(self, move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, Color.Red), true); + QueueChild(move.MoveWithinRange(target, minRange, maxRange, checkTarget.CenterPosition, Color.Red)); return this; } diff --git a/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs b/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs index 03c4cc1f7c..161590c9f7 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Refinery.cs @@ -164,9 +164,9 @@ namespace OpenRA.Mods.Common.Traits { if (!preventDock) { - dockOrder.QueueChild(self, new CallFunc(() => dockedHarv = harv, false)); - dockOrder.QueueChild(self, DockSequence(harv, self)); - dockOrder.QueueChild(self, new CallFunc(() => dockedHarv = null, false)); + dockOrder.QueueChild(new CallFunc(() => dockedHarv = harv, false)); + dockOrder.QueueChild(DockSequence(harv, self)); + dockOrder.QueueChild(new CallFunc(() => dockedHarv = null, false)); } } diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs index 68c35a9074..e46f971bd5 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoAircraft.cs @@ -130,7 +130,7 @@ namespace OpenRA.Mods.Common.Traits if (!order.Queued && activity.NextActivity != null) activity.NextActivity.Cancel(self); - activity.Queue(self, new IssueOrderAfterTransform(order.OrderString, order.Target)); + activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target)); if (currentTransform == null) self.QueueActivity(order.Queued, activity); diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs index 1a2d15d5e2..5d951d653d 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoEntersTunnels.cs @@ -100,7 +100,7 @@ namespace OpenRA.Mods.Common.Traits if (!order.Queued && activity.NextActivity != null) activity.NextActivity.Cancel(self); - activity.Queue(self, new IssueOrderAfterTransform(order.OrderString, order.Target)); + activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target)); if (currentTransform == null) self.QueueActivity(order.Queued, activity); diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs index a948906d82..20d635ed37 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoMobile.cs @@ -111,7 +111,7 @@ namespace OpenRA.Mods.Common.Traits if (!order.Queued && activity.NextActivity != null) activity.NextActivity.Cancel(self); - activity.Queue(self, new IssueOrderAfterTransform("Move", order.Target)); + activity.Queue(new IssueOrderAfterTransform("Move", order.Target)); if (currentTransform == null) self.QueueActivity(order.Queued, activity); diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs index cc77a4e414..7913aa6a72 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoPassenger.cs @@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Traits if (!order.Queued && activity.NextActivity != null) activity.NextActivity.Cancel(self); - activity.Queue(self, new IssueOrderAfterTransform(order.OrderString, order.Target)); + activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target)); if (currentTransform == null) self.QueueActivity(order.Queued, activity); diff --git a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs index c8a358fbf8..cb0a64b19e 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/TransformsIntoRepairable.cs @@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Traits if (!order.Queued && activity.NextActivity != null) activity.NextActivity.Cancel(self); - activity.Queue(self, new IssueOrderAfterTransform(order.OrderString, order.Target)); + activity.Queue(new IssueOrderAfterTransform(order.OrderString, order.Target)); if (currentTransform == null) self.QueueActivity(order.Queued, activity); diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs index b827c23184..7779e2d38a 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnDeploy.cs @@ -132,7 +132,7 @@ namespace OpenRA.Mods.Common.Traits return moveInner; var activity = new DeployForGrantedCondition(self, this, true); - activity.Queue(self, moveInner); + activity.Queue(moveInner); return activity; } diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 790c424fa5..fd30b17e7c 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -322,7 +322,7 @@ namespace OpenRA.Mods.Common.Traits var notifyBlocking = new CallFunc(() => self.NotifyBlocker(cellInfo.Cell)); var waitFor = new WaitFor(() => CanEnterCell(cellInfo.Cell)); var move = new Move(self, cellInfo.Cell); - self.QueueActivity(ActivityUtils.SequenceActivities(self, notifyBlocking, waitFor, move)); + self.QueueActivity(ActivityUtils.SequenceActivities(notifyBlocking, waitFor, move)); Log.Write("debug", "OnNudge (notify next blocking actor, wait and move) #{0} from {1} to {2}", self.ActorID, self.Location, cellInfo.Cell); @@ -691,7 +691,7 @@ namespace OpenRA.Mods.Common.Traits var delta = toPos - fromPos; var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : Facing; - return ActivityUtils.SequenceActivities(self, new Turn(self, facing), new Drag(self, fromPos, toPos, length)); + return ActivityUtils.SequenceActivities(new Turn(self, facing), new Drag(self, fromPos, toPos, length)); } CPos? ClosestGroundCell() diff --git a/OpenRA.Mods.Common/Traits/Repairable.cs b/OpenRA.Mods.Common/Traits/Repairable.cs index 3b69337d8b..e399dd4e08 100644 --- a/OpenRA.Mods.Common/Traits/Repairable.cs +++ b/OpenRA.Mods.Common/Traits/Repairable.cs @@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Traits self.CancelActivity(); self.SetTargetLine(order.Target, Color.Green); - var activities = ActivityUtils.SequenceActivities(self, + var activities = ActivityUtils.SequenceActivities( movement.MoveToTarget(self, order.Target, targetLineColor: Color.Green), new CallFunc(() => AfterReachActivities(self, order, movement)));