From 0c7158efcd84ead40c3659516c476f979a976f55 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 5 Jan 2019 18:37:41 +0000 Subject: [PATCH] Calculate Leap state on first run instead of construct. --- OpenRA.Mods.Cnc/Activities/Leap.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/OpenRA.Mods.Cnc/Activities/Leap.cs b/OpenRA.Mods.Cnc/Activities/Leap.cs index 08c452b014..1d936d495e 100644 --- a/OpenRA.Mods.Cnc/Activities/Leap.cs +++ b/OpenRA.Mods.Cnc/Activities/Leap.cs @@ -22,14 +22,16 @@ namespace OpenRA.Mods.Cnc.Activities public class Leap : Activity { readonly Mobile mobile; - readonly WPos destination, origin; - readonly CPos destinationCell; - readonly SubCell destinationSubCell = SubCell.Any; - readonly int length; + readonly Mobile targetMobile; + readonly int speed; readonly AttackLeap attack; readonly EdibleByLeap edible; readonly Target target; + CPos destinationCell; + SubCell destinationSubCell = SubCell.Any; + WPos destination, origin; + int length; bool canceled = false; bool jumpComplete = false; int ticks = 0; @@ -37,10 +39,15 @@ namespace OpenRA.Mods.Cnc.Activities public Leap(Actor self, Target target, Mobile mobile, Mobile targetMobile, int speed, AttackLeap attack, EdibleByLeap edible) { this.mobile = mobile; + this.targetMobile = targetMobile; this.attack = attack; this.target = target; this.edible = edible; + this.speed = speed; + } + protected override void OnFirstRun(Actor self) + { destinationCell = target.Actor.Location; if (targetMobile != null) destinationSubCell = targetMobile.ToSubCell; @@ -48,10 +55,7 @@ namespace OpenRA.Mods.Cnc.Activities origin = self.World.Map.CenterOfSubCell(self.Location, mobile.FromSubCell); destination = self.World.Map.CenterOfSubCell(destinationCell, destinationSubCell); length = Math.Max((origin - destination).Length / speed, 1); - } - protected override void OnFirstRun(Actor self) - { // First check if we are still allowed to leap // We need an extra boolean as using Cancel() in OnFirstRun doesn't work canceled = !edible.GetLeapAtBy(self) || target.Type != TargetType.Actor;