Avoid unnecessary Mobile lookups in Follow.

This commit is contained in:
Paul Chote
2013-08-18 16:10:12 +12:00
parent 9bbeb63989
commit 8fd4243861
3 changed files with 5 additions and 4 deletions

View File

@@ -16,15 +16,17 @@ namespace OpenRA.Mods.RA.Activities
public class Follow : Activity public class Follow : Activity
{ {
Target target; Target target;
Mobile mobile;
WRange range; WRange range;
int nextPathTime; int nextPathTime;
const int delayBetweenPathingAttempts = 20; const int delayBetweenPathingAttempts = 20;
const int delaySpread = 5; const int delaySpread = 5;
public Follow(Target target, WRange range) public Follow(Actor self, Target target, WRange range)
{ {
this.target = target; this.target = target;
mobile = self.Trait<Mobile>();
this.range = range; this.range = range;
} }
@@ -39,7 +41,6 @@ namespace OpenRA.Mods.RA.Activities
nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread, nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread,
delayBetweenPathingAttempts + delaySpread); delayBetweenPathingAttempts + delaySpread);
var mobile = self.Trait<Mobile>();
return Util.SequenceActivities(mobile.MoveWithinRange(target, range), this); return Util.SequenceActivities(mobile.MoveWithinRange(target, range), this);
} }
} }

View File

@@ -98,7 +98,7 @@ namespace OpenRA.Mods.RA
attack.Target = target; attack.Target = target;
if (allowMove && self.HasTrait<Mobile>() && !self.Info.Traits.Get<MobileInfo>().OnRails) if (allowMove && self.HasTrait<Mobile>() && !self.Info.Traits.Get<MobileInfo>().OnRails)
return Util.SequenceActivities(new Follow(target, range), this); return Util.SequenceActivities(new Follow(self, target, range), this);
} }
return NextActivity; return NextActivity;

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA
var range = WRange.FromCells(target.Actor.Info.Traits.Get<GuardableInfo>().Range); var range = WRange.FromCells(target.Actor.Info.Traits.Get<GuardableInfo>().Range);
self.QueueActivity(false, new AttackMove.AttackMoveActivity(self, self.QueueActivity(false, new AttackMove.AttackMoveActivity(self,
new Follow(target, range))); new Follow(self, target, range)));
} }
} }