Calculate Leap state on first run instead of construct.

This commit is contained in:
Paul Chote
2019-01-05 18:37:41 +00:00
committed by abcdefg30
parent 6b9a2a3c29
commit 0c7158efcd

View File

@@ -22,14 +22,16 @@ namespace OpenRA.Mods.Cnc.Activities
public class Leap : Activity public class Leap : Activity
{ {
readonly Mobile mobile; readonly Mobile mobile;
readonly WPos destination, origin; readonly Mobile targetMobile;
readonly CPos destinationCell; readonly int speed;
readonly SubCell destinationSubCell = SubCell.Any;
readonly int length;
readonly AttackLeap attack; readonly AttackLeap attack;
readonly EdibleByLeap edible; readonly EdibleByLeap edible;
readonly Target target; readonly Target target;
CPos destinationCell;
SubCell destinationSubCell = SubCell.Any;
WPos destination, origin;
int length;
bool canceled = false; bool canceled = false;
bool jumpComplete = false; bool jumpComplete = false;
int ticks = 0; 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) public Leap(Actor self, Target target, Mobile mobile, Mobile targetMobile, int speed, AttackLeap attack, EdibleByLeap edible)
{ {
this.mobile = mobile; this.mobile = mobile;
this.targetMobile = targetMobile;
this.attack = attack; this.attack = attack;
this.target = target; this.target = target;
this.edible = edible; this.edible = edible;
this.speed = speed;
}
protected override void OnFirstRun(Actor self)
{
destinationCell = target.Actor.Location; destinationCell = target.Actor.Location;
if (targetMobile != null) if (targetMobile != null)
destinationSubCell = targetMobile.ToSubCell; destinationSubCell = targetMobile.ToSubCell;
@@ -48,10 +55,7 @@ namespace OpenRA.Mods.Cnc.Activities
origin = self.World.Map.CenterOfSubCell(self.Location, mobile.FromSubCell); origin = self.World.Map.CenterOfSubCell(self.Location, mobile.FromSubCell);
destination = self.World.Map.CenterOfSubCell(destinationCell, destinationSubCell); destination = self.World.Map.CenterOfSubCell(destinationCell, destinationSubCell);
length = Math.Max((origin - destination).Length / speed, 1); length = Math.Max((origin - destination).Length / speed, 1);
}
protected override void OnFirstRun(Actor self)
{
// First check if we are still allowed to leap // First check if we are still allowed to leap
// We need an extra boolean as using Cancel() in OnFirstRun doesn't work // We need an extra boolean as using Cancel() in OnFirstRun doesn't work
canceled = !edible.GetLeapAtBy(self) || target.Type != TargetType.Actor; canceled = !edible.GetLeapAtBy(self) || target.Type != TargetType.Actor;