Use WRange for Follow.

This commit is contained in:
Paul Chote
2013-07-10 20:03:53 +12:00
parent ee188ededd
commit 0326d2bbd0
3 changed files with 10 additions and 11 deletions

View File

@@ -16,13 +16,13 @@ namespace OpenRA.Mods.RA.Activities
public class Follow : Activity public class Follow : Activity
{ {
Target target; Target target;
int 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, int range) public Follow(Target target, WRange range)
{ {
this.target = target; this.target = target;
this.range = range; this.range = range;
@@ -33,16 +33,14 @@ namespace OpenRA.Mods.RA.Activities
if (IsCanceled || !target.IsValid) if (IsCanceled || !target.IsValid)
return NextActivity; return NextActivity;
var inRange = (target.CenterPosition.ToCPos() - self.Location).LengthSquared < range * range; if (target.IsInRange(self.CenterPosition, range) || --nextPathTime > 0)
if (inRange || --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, range), this);
} }
} }
} }

View File

@@ -95,12 +95,11 @@ namespace OpenRA.Mods.RA
if (weapon != null) if (weapon != null)
{ {
attack.target = target; var range = WRange.FromCells(Math.Max(0, (int)weapon.Weapon.Range - RangeTolerance));
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( return Util.SequenceActivities(new Follow(target, range), this);
new Follow( target, Math.Max( 0, (int)weapon.Weapon.Range - RangeTolerance ) ),
this );
} }
return NextActivity; return NextActivity;

View File

@@ -28,8 +28,10 @@ namespace OpenRA.Mods.RA
{ {
var target = Target.FromActor(order.TargetActor); var target = Target.FromActor(order.TargetActor);
self.SetTargetLine(target, Color.Yellow); self.SetTargetLine(target, Color.Yellow);
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, target.Actor.Info.Traits.Get<GuardableInfo>().Range))); new Follow(target, range)));
} }
} }