Fix Follow formatting.

This commit is contained in:
Paul Chote
2013-07-10 20:01:04 +12:00
parent 91698678a2
commit ee188ededd

View File

@@ -15,8 +15,8 @@ namespace OpenRA.Mods.RA.Activities
{ {
public class Follow : Activity public class Follow : Activity
{ {
Target Target; Target target;
int Range; int range;
int nextPathTime; int nextPathTime;
const int delayBetweenPathingAttempts = 20; const int delayBetweenPathingAttempts = 20;
@@ -24,25 +24,25 @@ namespace OpenRA.Mods.RA.Activities
public Follow(Target target, int range) public Follow(Target target, int range)
{ {
Target = target; this.target = target;
Range = range; this.range = range;
} }
public override Activity Tick( Actor self ) public override Activity Tick(Actor self)
{ {
if (IsCanceled) return NextActivity; if (IsCanceled || !target.IsValid)
if (!Target.IsValid) return NextActivity; return NextActivity;
var inRange = ( Target.CenterPosition.ToCPos() - self.Location ).LengthSquared < Range * Range; var inRange = (target.CenterPosition.ToCPos() - self.Location).LengthSquared < range * range;
if( inRange ) return this; if (inRange || --nextPathTime > 0)
if (--nextPathTime > 0) return this; return this;
nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread, nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread,
delayBetweenPathingAttempts + delaySpread); delayBetweenPathingAttempts + delaySpread);
var mobile = self.Trait<Mobile>(); var mobile = self.Trait<Mobile>();
return Util.SequenceActivities( mobile.MoveWithinRange( Target, new WRange(1024*Range) ), this ); return Util.SequenceActivities(mobile.MoveWithinRange(target, new WRange(1024*range)), this);
} }
} }
} }