Use WRange for Mobile.MoveWithinRange.

This commit is contained in:
Paul Chote
2013-07-10 19:59:03 +12:00
parent ae987b3c10
commit 91698678a2
6 changed files with 10 additions and 9 deletions

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA.Activities
nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread, nextPathTime = self.World.SharedRandom.Next(delayBetweenPathingAttempts - delaySpread,
delayBetweenPathingAttempts + delaySpread); delayBetweenPathingAttempts + delaySpread);
return (AllowMovement) ? Util.SequenceActivities(self.Trait<Mobile>().MoveWithinRange(Target, Range.Range / 1024), this) : NextActivity; return (AllowMovement) ? Util.SequenceActivities(self.Trait<Mobile>().MoveWithinRange(Target, Range), this) : NextActivity;
} }
var desiredFacing = Util.GetFacing(Target.CenterPosition - self.CenterPosition, 0); var desiredFacing = Util.GetFacing(Target.CenterPosition - self.CenterPosition, 0);

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA.Activities
delayBetweenPathingAttempts + delaySpread); delayBetweenPathingAttempts + delaySpread);
var mobile = self.Trait<Mobile>(); var mobile = self.Trait<Mobile>();
return Util.SequenceActivities( mobile.MoveWithinRange( Target, Range ), this ); return Util.SequenceActivities( mobile.MoveWithinRange( Target, new WRange(1024*Range) ), this );
} }
} }
} }

View File

@@ -191,14 +191,14 @@ namespace OpenRA.Mods.RA.Missions
if (einstein != null) if (einstein != null)
{ {
if (einstein.IsInWorld) if (einstein.IsInWorld)
innerActivity = new Move.Move(Target.FromActor(einstein), 3); innerActivity = new Move.Move(Target.FromActor(einstein), WRange.FromCells(3));
else else
{ {
var container = world.UnitContaining(einstein); var container = world.UnitContaining(einstein);
if (container != null && !container.HasTrait<Aircraft>() && container.HasTrait<Mobile>()) if (container != null && !container.HasTrait<Aircraft>() && container.HasTrait<Mobile>())
innerActivity = new Move.Move(Target.FromActor(container), 3); innerActivity = new Move.Move(Target.FromActor(container), WRange.FromCells(3));
else else
innerActivity = new Move.Move(extractionLZ.Location, 3); innerActivity = new Move.Move(extractionLZ.Location, 3);

View File

@@ -516,7 +516,7 @@ namespace OpenRA.Mods.RA.Move
public Activity ScriptedMove(CPos cell) { return new Move(cell); } public Activity ScriptedMove(CPos cell) { return new Move(cell); }
public Activity MoveTo(CPos cell, int nearEnough) { return new Move(cell, nearEnough); } public Activity MoveTo(CPos cell, int nearEnough) { return new Move(cell, nearEnough); }
public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Move(cell, ignoredActor); } public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Move(cell, ignoredActor); }
public Activity MoveWithinRange(Target target, int range) { return new Move(target, range); } public Activity MoveWithinRange(Target target, WRange range) { return new Move(target, range); }
public Activity MoveTo(Func<List<CPos>> pathFunc) { return new Move(pathFunc); } public Activity MoveTo(Func<List<CPos>> pathFunc) { return new Move(pathFunc); }
} }
} }

View File

@@ -59,19 +59,20 @@ namespace OpenRA.Mods.RA.Move
} }
static readonly List<CPos> NoPath = new List<CPos>(); static readonly List<CPos> NoPath = new List<CPos>();
public Move(Target target, int range) public Move(Target target, WRange range)
{ {
this.getPath = (self, mobile) => this.getPath = (self, mobile) =>
{ {
if (!target.IsValid) if (!target.IsValid)
return NoPath; return NoPath;
// TODO: Adjust range to account for target center position
return self.World.WorldActor.Trait<PathFinder>().FindUnitPathToRange( return self.World.WorldActor.Trait<PathFinder>().FindUnitPathToRange(
mobile.toCell, target.CenterPosition.ToCPos(), range, self); mobile.toCell, target.CenterPosition.ToCPos(), range.Range / 1024, self);
}; };
this.destination = null; this.destination = null;
this.nearEnough = range; this.nearEnough = range.Range / 1024;
} }
public Move(Func<List<CPos>> getPath) public Move(Func<List<CPos>> getPath)

View File

@@ -69,7 +69,7 @@ namespace OpenRA.Mods.RA
var target = Target.FromOrder(order); var target = Target.FromOrder(order);
self.CancelActivity(); self.CancelActivity();
self.QueueActivity(mobile.MoveWithinRange(target, info.CloseEnough)); self.QueueActivity(mobile.MoveWithinRange(target, new WRange(1024*info.CloseEnough)));
self.QueueActivity(new Repair(order.TargetActor)); self.QueueActivity(new Repair(order.TargetActor));
self.SetTargetLine(target, Color.Green, false); self.SetTargetLine(target, Color.Green, false);