From ac6431acf8e23d2d4aa943f66134f7b59ac1252e Mon Sep 17 00:00:00 2001 From: tovl Date: Sat, 31 Aug 2019 16:47:12 +0200 Subject: [PATCH] Clean up usage of CancelActivity. --- OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs | 7 ++----- .../Traits/Infiltration/InfiltrateForTransform.cs | 3 +-- OpenRA.Mods.Cnc/Traits/Infiltration/Infiltrates.cs | 5 +---- OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 8 ++------ OpenRA.Mods.Common/Traits/AttackMove.cs | 5 +---- OpenRA.Mods.Common/Traits/Captures.cs | 5 +---- OpenRA.Mods.Common/Traits/Cargo.cs | 5 +---- OpenRA.Mods.Common/Traits/Carryall.cs | 3 --- OpenRA.Mods.Common/Traits/DeliversCash.cs | 5 +---- OpenRA.Mods.Common/Traits/DeliversExperience.cs | 5 +---- OpenRA.Mods.Common/Traits/Demolition.cs | 5 +---- OpenRA.Mods.Common/Traits/EngineerRepair.cs | 5 +---- OpenRA.Mods.Common/Traits/EntersTunnels.cs | 5 +---- OpenRA.Mods.Common/Traits/Guard.cs | 5 +---- OpenRA.Mods.Common/Traits/Mobile.cs | 9 ++------- OpenRA.Mods.Common/Traits/Passenger.cs | 5 +---- OpenRA.Mods.Common/Traits/RepairableNear.cs | 5 +---- OpenRA.Mods.Common/Traits/RepairsBridges.cs | 5 +---- OpenRA.Mods.Common/Traits/TransformCrusherOnCrush.cs | 3 +-- OpenRA.Mods.Common/Traits/TransformOnCapture.cs | 3 +-- OpenRA.Mods.Common/Traits/World/CrateSpawner.cs | 3 +-- OpenRA.Mods.D2k/Traits/AttackSwallow.cs | 3 +-- 22 files changed, 24 insertions(+), 83 deletions(-) diff --git a/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs b/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs index ef68a729d6..7d88b9f59d 100644 --- a/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs +++ b/OpenRA.Mods.Cnc/Traits/Chronoshiftable.cs @@ -80,8 +80,6 @@ namespace OpenRA.Mods.Cnc.Traits // Return to original location if (--ReturnTicks == 0) { - self.CancelActivity(); - // The Move activity is not immediately cancelled, which, combined // with Activity.Cancel discarding NextActivity without checking the // IsInterruptable flag, means that a well timed order can cancel the @@ -95,7 +93,7 @@ namespace OpenRA.Mods.Cnc.Traits typeof(Actor).GetProperty("CurrentActivity").SetValue(self, null); // The actor is killed using Info.DamageTypes if the teleport fails - self.QueueActivity(new Teleport(chronosphere, Origin, null, true, killCargo, Info.ChronoshiftSound, + self.QueueActivity(false, new Teleport(chronosphere, Origin, null, true, killCargo, Info.ChronoshiftSound, false, true, Info.DamageTypes)); } } @@ -144,8 +142,7 @@ namespace OpenRA.Mods.Cnc.Traits this.killCargo = killCargo; // Set up the teleport - self.CancelActivity(); - self.QueueActivity(new Teleport(chronosphere, targetLocation, null, killCargo, true, Info.ChronoshiftSound)); + self.QueueActivity(false, new Teleport(chronosphere, targetLocation, null, killCargo, true, Info.ChronoshiftSound)); return true; } diff --git a/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForTransform.cs b/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForTransform.cs index 1222dd49fd..b26f34f17b 100644 --- a/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForTransform.cs +++ b/OpenRA.Mods.Cnc/Traits/Infiltration/InfiltrateForTransform.cs @@ -61,8 +61,7 @@ namespace OpenRA.Mods.Cnc.Traits if (facing != null) transform.Facing = facing.Facing; - self.CancelActivity(); - self.QueueActivity(transform); + self.QueueActivity(false, transform); } } } diff --git a/OpenRA.Mods.Cnc/Traits/Infiltration/Infiltrates.cs b/OpenRA.Mods.Cnc/Traits/Infiltration/Infiltrates.cs index 36e43f7acb..e947046ff4 100644 --- a/OpenRA.Mods.Cnc/Traits/Infiltration/Infiltrates.cs +++ b/OpenRA.Mods.Cnc/Traits/Infiltration/Infiltrates.cs @@ -114,10 +114,7 @@ namespace OpenRA.Mods.Cnc.Traits if (!CanInfiltrateTarget(self, order.Target)) return; - if (!order.Queued) - self.CancelActivity(); - - self.QueueActivity(new Infiltrate(self, order.Target, this)); + self.QueueActivity(order.Queued, new Infiltrate(self, order.Target, this)); self.ShowTargetLines(); } } diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 8efc2f8786..1ec7f7f1b4 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -354,8 +354,7 @@ namespace OpenRA.Mods.Common.Traits if (!ForceLanding && landNow.HasValue && landNow.Value && airborne && CanLand(self.Location) && !((self.CurrentActivity is Land) || self.CurrentActivity is Turn)) { - self.CancelActivity(); - self.QueueActivity(new Land(self)); + self.QueueActivity(false, new Land(self)); ForceLanding = true; } @@ -365,10 +364,7 @@ namespace OpenRA.Mods.Common.Traits ForceLanding = false; if (Info.IdleBehavior != IdleBehaviorType.Land) - { - self.CancelActivity(); - self.QueueActivity(new TakeOff(self)); - } + self.QueueActivity(false, new TakeOff(self)); } var oldCachedFacing = cachedFacing; diff --git a/OpenRA.Mods.Common/Traits/AttackMove.cs b/OpenRA.Mods.Common/Traits/AttackMove.cs index f5afc53f1c..549c6c8fe2 100644 --- a/OpenRA.Mods.Common/Traits/AttackMove.cs +++ b/OpenRA.Mods.Common/Traits/AttackMove.cs @@ -69,9 +69,6 @@ namespace OpenRA.Mods.Common.Traits { if (order.OrderString == "AttackMove" || order.OrderString == "AssaultMove") { - if (!order.Queued) - self.CancelActivity(); - var cell = self.World.Map.Clamp(self.World.Map.CellContaining(order.Target.CenterPosition)); if (!Info.MoveIntoShroud && !self.Owner.Shroud.IsExplored(cell)) return; @@ -80,7 +77,7 @@ namespace OpenRA.Mods.Common.Traits var assaultMoving = order.OrderString == "AssaultMove"; // TODO: this should scale with unit selection group size. - self.QueueActivity(new AttackMoveActivity(self, () => move.MoveTo(targetLocation, 8, targetLineColor: Color.OrangeRed), assaultMoving)); + self.QueueActivity(order.Queued, new AttackMoveActivity(self, () => move.MoveTo(targetLocation, 8, targetLineColor: Color.OrangeRed), assaultMoving)); self.ShowTargetLines(); } } diff --git a/OpenRA.Mods.Common/Traits/Captures.cs b/OpenRA.Mods.Common/Traits/Captures.cs index 6a74e4eeeb..25cc6a838a 100644 --- a/OpenRA.Mods.Common/Traits/Captures.cs +++ b/OpenRA.Mods.Common/Traits/Captures.cs @@ -95,10 +95,7 @@ namespace OpenRA.Mods.Common.Traits if (order.OrderString != "CaptureActor" || IsTraitDisabled) return; - if (!order.Queued) - self.CancelActivity(); - - self.QueueActivity(new CaptureActor(self, order.Target)); + self.QueueActivity(order.Queued, new CaptureActor(self, order.Target)); self.ShowTargetLines(); } diff --git a/OpenRA.Mods.Common/Traits/Cargo.cs b/OpenRA.Mods.Common/Traits/Cargo.cs index f08a9ca859..8cfdbff5b0 100644 --- a/OpenRA.Mods.Common/Traits/Cargo.cs +++ b/OpenRA.Mods.Common/Traits/Cargo.cs @@ -206,10 +206,7 @@ namespace OpenRA.Mods.Common.Traits if (!order.Queued && !CanUnload()) return; - if (!order.Queued) - self.CancelActivity(); - - self.QueueActivity(new UnloadCargo(self, Info.LoadRange)); + self.QueueActivity(order.Queued, new UnloadCargo(self, Info.LoadRange)); } } diff --git a/OpenRA.Mods.Common/Traits/Carryall.cs b/OpenRA.Mods.Common/Traits/Carryall.cs index df3217a832..166c989015 100644 --- a/OpenRA.Mods.Common/Traits/Carryall.cs +++ b/OpenRA.Mods.Common/Traits/Carryall.cs @@ -313,9 +313,6 @@ namespace OpenRA.Mods.Common.Traits if (order.Target.Type != TargetType.Actor) return; - if (!order.Queued) - self.CancelActivity(); - self.QueueActivity(order.Queued, new PickupUnit(self, order.Target.Actor, Info.BeforeLoadDelay)); self.ShowTargetLines(); } diff --git a/OpenRA.Mods.Common/Traits/DeliversCash.cs b/OpenRA.Mods.Common/Traits/DeliversCash.cs index f2326ab7ea..1502c44265 100644 --- a/OpenRA.Mods.Common/Traits/DeliversCash.cs +++ b/OpenRA.Mods.Common/Traits/DeliversCash.cs @@ -73,10 +73,7 @@ namespace OpenRA.Mods.Common.Traits if (order.OrderString != "DeliverCash") return; - if (!order.Queued) - self.CancelActivity(); - - self.QueueActivity(new DonateCash(self, order.Target, info.Payload, info.PlayerExperience)); + self.QueueActivity(order.Queued, new DonateCash(self, order.Target, info.Payload, info.PlayerExperience)); self.ShowTargetLines(); } diff --git a/OpenRA.Mods.Common/Traits/DeliversExperience.cs b/OpenRA.Mods.Common/Traits/DeliversExperience.cs index 8a3c3bffd9..ca95a74212 100644 --- a/OpenRA.Mods.Common/Traits/DeliversExperience.cs +++ b/OpenRA.Mods.Common/Traits/DeliversExperience.cs @@ -84,10 +84,7 @@ namespace OpenRA.Mods.Common.Traits else if (order.Target.Type != TargetType.FrozenActor) return; - if (!order.Queued) - self.CancelActivity(); - - self.QueueActivity(new DonateExperience(self, order.Target, gainsExperience.Level, info.PlayerExperience)); + self.QueueActivity(order.Queued, new DonateExperience(self, order.Target, gainsExperience.Level, info.PlayerExperience)); self.ShowTargetLines(); } diff --git a/OpenRA.Mods.Common/Traits/Demolition.cs b/OpenRA.Mods.Common/Traits/Demolition.cs index 686db69f02..a809abaf53 100644 --- a/OpenRA.Mods.Common/Traits/Demolition.cs +++ b/OpenRA.Mods.Common/Traits/Demolition.cs @@ -83,10 +83,7 @@ namespace OpenRA.Mods.Common.Traits return; } - if (!order.Queued) - self.CancelActivity(); - - self.QueueActivity(new Demolish(self, order.Target, info.EnterBehaviour, info.DetonationDelay, + self.QueueActivity(order.Queued, new Demolish(self, order.Target, info.EnterBehaviour, info.DetonationDelay, info.Flashes, info.FlashesDelay, info.FlashInterval)); self.ShowTargetLines(); diff --git a/OpenRA.Mods.Common/Traits/EngineerRepair.cs b/OpenRA.Mods.Common/Traits/EngineerRepair.cs index 2feff2e71f..db88d6116a 100644 --- a/OpenRA.Mods.Common/Traits/EngineerRepair.cs +++ b/OpenRA.Mods.Common/Traits/EngineerRepair.cs @@ -92,10 +92,7 @@ namespace OpenRA.Mods.Common.Traits if (order.OrderString != "EngineerRepair" || !IsValidOrder(self, order)) return; - if (!order.Queued) - self.CancelActivity(); - - self.QueueActivity(new RepairBuilding(self, order.Target, Info)); + self.QueueActivity(order.Queued, new RepairBuilding(self, order.Target, Info)); self.ShowTargetLines(); } diff --git a/OpenRA.Mods.Common/Traits/EntersTunnels.cs b/OpenRA.Mods.Common/Traits/EntersTunnels.cs index 2feea6dd59..87e708b181 100644 --- a/OpenRA.Mods.Common/Traits/EntersTunnels.cs +++ b/OpenRA.Mods.Common/Traits/EntersTunnels.cs @@ -82,10 +82,7 @@ namespace OpenRA.Mods.Common.Traits if (tunnel == null || !tunnel.Exit.HasValue) return; - if (!order.Queued) - self.CancelActivity(); - - self.QueueActivity(move.MoveTo(tunnel.Entrance, tunnel.NearEnough, targetLineColor: Color.Green)); + self.QueueActivity(order.Queued, move.MoveTo(tunnel.Entrance, tunnel.NearEnough, targetLineColor: Color.Green)); self.QueueActivity(move.MoveTo(tunnel.Exit.Value, tunnel.NearEnough, targetLineColor: Color.Green)); self.ShowTargetLines(); } diff --git a/OpenRA.Mods.Common/Traits/Guard.cs b/OpenRA.Mods.Common/Traits/Guard.cs index e36292e353..4af627875f 100644 --- a/OpenRA.Mods.Common/Traits/Guard.cs +++ b/OpenRA.Mods.Common/Traits/Guard.cs @@ -47,14 +47,11 @@ namespace OpenRA.Mods.Common.Traits public void GuardTarget(Actor self, Target target, bool queued = false) { - if (!queued) - self.CancelActivity(); - if (target.Type != TargetType.Actor) return; var range = target.Actor.Info.TraitInfo().Range; - self.QueueActivity(new AttackMoveActivity(self, () => move.MoveFollow(self, target, WDist.Zero, range, targetLineColor: Color.OrangeRed))); + self.QueueActivity(queued, new AttackMoveActivity(self, () => move.MoveFollow(self, target, WDist.Zero, range, targetLineColor: Color.OrangeRed))); self.ShowTargetLines(); } diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 6c4eb8c3d4..86204e2d31 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -318,8 +318,7 @@ namespace OpenRA.Mods.Common.Traits if (moveTo.HasValue) { - self.CancelActivity(); - self.QueueActivity(new Move(self, moveTo.Value, WDist.Zero)); + self.QueueActivity(false, new Move(self, moveTo.Value, WDist.Zero)); self.ShowTargetLines(); Log.Write("debug", "OnNudge #{0} from {1} to {2}", @@ -335,8 +334,7 @@ namespace OpenRA.Mods.Common.Traits if (cellInfo != null) { - self.CancelActivity(); - self.QueueActivity(new CallFunc(() => self.NotifyBlocker(cellInfo.Cell))); + self.QueueActivity(false, new CallFunc(() => self.NotifyBlocker(cellInfo.Cell))); self.QueueActivity(new WaitFor(() => CanEnterCell(cellInfo.Cell))); self.QueueActivity(new Move(self, cellInfo.Cell)); @@ -863,9 +861,6 @@ namespace OpenRA.Mods.Common.Traits if (!Info.LocomotorInfo.MoveIntoShroud && !self.Owner.Shroud.IsExplored(cell)) return; - if (!order.Queued) - self.CancelActivity(); - self.QueueActivity(order.Queued, WrapMove(new Move(self, cell, WDist.FromCells(8), null, true, Color.Green))); self.ShowTargetLines(); } diff --git a/OpenRA.Mods.Common/Traits/Passenger.cs b/OpenRA.Mods.Common/Traits/Passenger.cs index 3c6484015d..1ca8ae6666 100644 --- a/OpenRA.Mods.Common/Traits/Passenger.cs +++ b/OpenRA.Mods.Common/Traits/Passenger.cs @@ -159,10 +159,7 @@ namespace OpenRA.Mods.Common.Traits if (!IsCorrectCargoType(targetActor)) return; - if (!order.Queued) - self.CancelActivity(); - - self.QueueActivity(new RideTransport(self, order.Target)); + self.QueueActivity(order.Queued, new RideTransport(self, order.Target)); self.ShowTargetLines(); } diff --git a/OpenRA.Mods.Common/Traits/RepairableNear.cs b/OpenRA.Mods.Common/Traits/RepairableNear.cs index d377c2575c..2d3b8ac791 100644 --- a/OpenRA.Mods.Common/Traits/RepairableNear.cs +++ b/OpenRA.Mods.Common/Traits/RepairableNear.cs @@ -99,10 +99,7 @@ namespace OpenRA.Mods.Common.Traits if (!CanRepairAt(order.Target.Actor) || !ShouldRepair()) return; - if (!order.Queued) - self.CancelActivity(); - - self.QueueActivity(new Resupply(self, order.Target.Actor, Info.CloseEnough)); + self.QueueActivity(order.Queued, new Resupply(self, order.Target.Actor, Info.CloseEnough)); self.ShowTargetLines(); } diff --git a/OpenRA.Mods.Common/Traits/RepairsBridges.cs b/OpenRA.Mods.Common/Traits/RepairsBridges.cs index 9e97039314..1e13902c58 100644 --- a/OpenRA.Mods.Common/Traits/RepairsBridges.cs +++ b/OpenRA.Mods.Common/Traits/RepairsBridges.cs @@ -102,10 +102,7 @@ namespace OpenRA.Mods.Common.Traits else return; - if (!order.Queued) - self.CancelActivity(); - - self.QueueActivity(new RepairBridge(self, order.Target, info.EnterBehaviour, info.RepairNotification)); + self.QueueActivity(order.Queued, new RepairBridge(self, order.Target, info.EnterBehaviour, info.RepairNotification)); self.ShowTargetLines(); } } diff --git a/OpenRA.Mods.Common/Traits/TransformCrusherOnCrush.cs b/OpenRA.Mods.Common/Traits/TransformCrusherOnCrush.cs index 91f1839008..b3148de25a 100644 --- a/OpenRA.Mods.Common/Traits/TransformCrusherOnCrush.cs +++ b/OpenRA.Mods.Common/Traits/TransformCrusherOnCrush.cs @@ -53,8 +53,7 @@ namespace OpenRA.Mods.Common.Traits transform.Facing = facing.Facing; transform.SkipMakeAnims = info.SkipMakeAnims; - crusher.CancelActivity(); - crusher.QueueActivity(transform); + crusher.QueueActivity(false, transform); } } } diff --git a/OpenRA.Mods.Common/Traits/TransformOnCapture.cs b/OpenRA.Mods.Common/Traits/TransformOnCapture.cs index da0ddec1cd..729428119b 100644 --- a/OpenRA.Mods.Common/Traits/TransformOnCapture.cs +++ b/OpenRA.Mods.Common/Traits/TransformOnCapture.cs @@ -52,8 +52,7 @@ namespace OpenRA.Mods.Common.Traits var transform = new Transform(self, info.IntoActor) { ForceHealthPercentage = info.ForceHealthPercentage, Faction = faction }; if (facing != null) transform.Facing = facing.Facing; transform.SkipMakeAnims = info.SkipMakeAnims; - self.CancelActivity(); - self.QueueActivity(transform); + self.QueueActivity(false, transform); } } } diff --git a/OpenRA.Mods.Common/Traits/World/CrateSpawner.cs b/OpenRA.Mods.Common/Traits/World/CrateSpawner.cs index f95ee0b6e8..2b229d2b75 100644 --- a/OpenRA.Mods.Common/Traits/World/CrateSpawner.cs +++ b/OpenRA.Mods.Common/Traits/World/CrateSpawner.cs @@ -160,8 +160,7 @@ namespace OpenRA.Mods.Common.Traits drop.SetLZ(p, true); plane.Trait().Load(plane, crate); - plane.CancelActivity(); - plane.QueueActivity(new Fly(plane, Target.FromPos(finishEdge))); + plane.QueueActivity(false, new Fly(plane, Target.FromPos(finishEdge))); plane.QueueActivity(new RemoveSelf()); } else diff --git a/OpenRA.Mods.D2k/Traits/AttackSwallow.cs b/OpenRA.Mods.D2k/Traits/AttackSwallow.cs index 54e7575e3d..7131b99dd2 100644 --- a/OpenRA.Mods.D2k/Traits/AttackSwallow.cs +++ b/OpenRA.Mods.D2k/Traits/AttackSwallow.cs @@ -67,8 +67,7 @@ namespace OpenRA.Mods.D2k.Traits if (!target.IsInRange(self.CenterPosition, a.MaxRange())) return; - self.CancelActivity(); - self.QueueActivity(new SwallowActor(self, target, a, facing)); + self.QueueActivity(false, new SwallowActor(self, target, a, facing)); } public override Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor)