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
{
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;