More style fixes for Move.
This commit is contained in:
@@ -20,11 +20,13 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
{
|
{
|
||||||
class Move : Activity
|
class Move : Activity
|
||||||
{
|
{
|
||||||
|
static readonly List<CPos> NoPath = new List<CPos>();
|
||||||
|
|
||||||
CPos? destination;
|
CPos? destination;
|
||||||
WRange nearEnough;
|
WRange nearEnough;
|
||||||
public List<CPos> path;
|
List<CPos> path;
|
||||||
Func<Actor, Mobile, List<CPos>> getPath;
|
Func<Actor, Mobile, List<CPos>> getPath;
|
||||||
public Actor ignoreBuilding;
|
Actor ignoreBuilding;
|
||||||
|
|
||||||
// For dealing with blockers
|
// For dealing with blockers
|
||||||
bool hasWaited;
|
bool hasWaited;
|
||||||
@@ -35,9 +37,9 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
// Ignores lane bias and nearby units
|
// Ignores lane bias and nearby units
|
||||||
public Move(CPos destination)
|
public Move(CPos destination)
|
||||||
{
|
{
|
||||||
this.getPath = (self,mobile) =>
|
this.getPath = (self, mobile) =>
|
||||||
self.World.WorldActor.Trait<PathFinder>().FindPath(
|
self.World.WorldActor.Trait<PathFinder>().FindPath(
|
||||||
PathSearch.FromPoint( self.World, mobile.Info, self, mobile.toCell, destination, false )
|
PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, destination, false)
|
||||||
.WithoutLaneBias());
|
.WithoutLaneBias());
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.nearEnough = WRange.Zero;
|
this.nearEnough = WRange.Zero;
|
||||||
@@ -45,29 +47,28 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
|
|
||||||
// Hack for legacy code
|
// Hack for legacy code
|
||||||
public Move(CPos destination, int nearEnough)
|
public Move(CPos destination, int nearEnough)
|
||||||
: this(destination, WRange.FromCells(nearEnough)) {}
|
: this(destination, WRange.FromCells(nearEnough)) { }
|
||||||
|
|
||||||
public Move(CPos destination, WRange nearEnough)
|
public Move(CPos destination, WRange nearEnough)
|
||||||
{
|
{
|
||||||
this.getPath = (self,mobile) => self.World.WorldActor.Trait<PathFinder>().FindUnitPath( mobile.toCell, destination, self );
|
this.getPath = (self, mobile) => self.World.WorldActor.Trait<PathFinder>()
|
||||||
|
.FindUnitPath(mobile.toCell, destination, self);
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.nearEnough = nearEnough;
|
this.nearEnough = nearEnough;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Move(CPos destination, Actor ignoreBuilding)
|
public Move(CPos destination, Actor ignoreBuilding)
|
||||||
{
|
{
|
||||||
this.getPath = (self,mobile) =>
|
this.getPath = (self, mobile) =>
|
||||||
self.World.WorldActor.Trait<PathFinder>().FindPath(
|
self.World.WorldActor.Trait<PathFinder>().FindPath(
|
||||||
PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, destination, false)
|
PathSearch.FromPoint(self.World, mobile.Info, self, mobile.toCell, destination, false)
|
||||||
.WithIgnoredBuilding(ignoreBuilding)
|
.WithIgnoredBuilding(ignoreBuilding));
|
||||||
);
|
|
||||||
|
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
this.nearEnough = WRange.Zero;
|
this.nearEnough = WRange.Zero;
|
||||||
this.ignoreBuilding = ignoreBuilding;
|
this.ignoreBuilding = ignoreBuilding;
|
||||||
}
|
}
|
||||||
|
|
||||||
static readonly List<CPos> NoPath = new List<CPos>();
|
|
||||||
public Move(Target target, WRange range)
|
public Move(Target target, WRange range)
|
||||||
{
|
{
|
||||||
this.getPath = (self, mobile) =>
|
this.getPath = (self, mobile) =>
|
||||||
@@ -85,7 +86,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
|
|
||||||
public Move(Func<List<CPos>> getPath)
|
public Move(Func<List<CPos>> getPath)
|
||||||
{
|
{
|
||||||
this.getPath = (_1,_2) => getPath();
|
this.getPath = (_1, _2) => getPath();
|
||||||
this.destination = null;
|
this.destination = null;
|
||||||
this.nearEnough = WRange.Zero;
|
this.nearEnough = WRange.Zero;
|
||||||
}
|
}
|
||||||
@@ -132,7 +133,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
}
|
}
|
||||||
|
|
||||||
path = EvalPath(self, mobile);
|
path = EvalPath(self, mobile);
|
||||||
SanityCheckPath( mobile );
|
SanityCheckPath(mobile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path.Count == 0)
|
if (path.Count == 0)
|
||||||
@@ -151,7 +152,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
var firstFacing = Util.GetFacing(dir, mobile.Facing);
|
var firstFacing = Util.GetFacing(dir, mobile.Facing);
|
||||||
if (firstFacing != mobile.Facing)
|
if (firstFacing != mobile.Facing)
|
||||||
{
|
{
|
||||||
path.Add( nextCell.Value.First );
|
path.Add(nextCell.Value.First);
|
||||||
return Util.SequenceActivities(new Turn(firstFacing), this);
|
return Util.SequenceActivities(new Turn(firstFacing), this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -163,8 +164,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
Util.BetweenCells(mobile.fromCell, mobile.toCell) + (MobileInfo.SubCellOffsets[mobile.fromSubCell] + MobileInfo.SubCellOffsets[mobile.toSubCell]) / 2,
|
Util.BetweenCells(mobile.fromCell, mobile.toCell) + (MobileInfo.SubCellOffsets[mobile.fromSubCell] + MobileInfo.SubCellOffsets[mobile.toSubCell]) / 2,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
0
|
0);
|
||||||
);
|
|
||||||
|
|
||||||
return move;
|
return move;
|
||||||
}
|
}
|
||||||
@@ -206,7 +206,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
{
|
{
|
||||||
// Are we close enough?
|
// Are we close enough?
|
||||||
var cellRange = nearEnough.Range / 1024;
|
var cellRange = nearEnough.Range / 1024;
|
||||||
if ((mobile.toCell - destination.Value).LengthSquared <= cellRange*cellRange)
|
if ((mobile.toCell - destination.Value).LengthSquared <= cellRange * cellRange)
|
||||||
{
|
{
|
||||||
path.Clear();
|
path.Clear();
|
||||||
return null;
|
return null;
|
||||||
@@ -255,9 +255,9 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
return Pair.New(nextCell, subCell);
|
return Pair.New(nextCell, subCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Cancel( Actor self )
|
public override void Cancel(Actor self)
|
||||||
{
|
{
|
||||||
path = new List<CPos>(0);
|
path = NoPath;
|
||||||
base.Cancel(self);
|
base.Cancel(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,11 +272,11 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
|
|
||||||
abstract class MovePart : Activity
|
abstract class MovePart : Activity
|
||||||
{
|
{
|
||||||
public readonly Move move;
|
protected readonly Move move;
|
||||||
public readonly PPos from, to;
|
protected readonly PPos from, to;
|
||||||
public readonly int fromFacing, toFacing;
|
protected readonly int fromFacing, toFacing;
|
||||||
public int moveFraction;
|
protected readonly int moveFractionTotal;
|
||||||
public readonly int moveFractionTotal;
|
protected int moveFraction;
|
||||||
|
|
||||||
public MovePart(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction)
|
public MovePart(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction)
|
||||||
{
|
{
|
||||||
@@ -286,7 +286,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
this.fromFacing = fromFacing;
|
this.fromFacing = fromFacing;
|
||||||
this.toFacing = toFacing;
|
this.toFacing = toFacing;
|
||||||
this.moveFraction = startingFraction;
|
this.moveFraction = startingFraction;
|
||||||
this.moveFractionTotal = 3*(to - from).Length;
|
this.moveFractionTotal = 3 * (to - from).Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Cancel(Actor self)
|
public override void Cancel(Actor self)
|
||||||
@@ -304,7 +304,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
{
|
{
|
||||||
var mobile = self.Trait<Mobile>();
|
var mobile = self.Trait<Mobile>();
|
||||||
var ret = InnerTick(self, mobile);
|
var ret = InnerTick(self, mobile);
|
||||||
mobile.IsMoving = (ret is MovePart);
|
mobile.IsMoving = ret is MovePart;
|
||||||
|
|
||||||
if (moveFraction > moveFractionTotal)
|
if (moveFraction > moveFractionTotal)
|
||||||
moveFraction = moveFractionTotal;
|
moveFraction = moveFractionTotal;
|
||||||
@@ -372,8 +372,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
Util.BetweenCells(mobile.toCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
|
Util.BetweenCells(mobile.toCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
Util.GetNearestFacing(mobile.Facing, Util.GetFacing(nextCell.Value.First - mobile.toCell, mobile.Facing)),
|
Util.GetNearestFacing(mobile.Facing, Util.GetFacing(nextCell.Value.First - mobile.toCell, mobile.Facing)),
|
||||||
moveFraction - moveFractionTotal
|
moveFraction - moveFractionTotal);
|
||||||
);
|
|
||||||
|
|
||||||
mobile.SetLocation(mobile.toCell, mobile.toSubCell, nextCell.Value.First, nextCell.Value.Second);
|
mobile.SetLocation(mobile.toCell, mobile.toSubCell, nextCell.Value.First, nextCell.Value.Second);
|
||||||
return ret;
|
return ret;
|
||||||
@@ -388,8 +387,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
Util.CenterOfCell(mobile.toCell) + toSubcellOffset,
|
Util.CenterOfCell(mobile.toCell) + toSubcellOffset,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
moveFraction - moveFractionTotal
|
moveFraction - moveFractionTotal);
|
||||||
);
|
|
||||||
|
|
||||||
mobile.EnteringCell(self);
|
mobile.EnteringCell(self);
|
||||||
mobile.SetLocation(mobile.toCell, mobile.toSubCell, mobile.toCell, mobile.toSubCell);
|
mobile.SetLocation(mobile.toCell, mobile.toSubCell, mobile.toCell, mobile.toSubCell);
|
||||||
@@ -400,7 +398,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
class MoveSecondHalf : MovePart
|
class MoveSecondHalf : MovePart
|
||||||
{
|
{
|
||||||
public MoveSecondHalf(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction)
|
public MoveSecondHalf(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction)
|
||||||
: base(move, from, to, fromFacing, toFacing, startingFraction) {}
|
: base(move, from, to, fromFacing, toFacing, startingFraction) { }
|
||||||
|
|
||||||
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
||||||
{
|
{
|
||||||
@@ -416,12 +414,10 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
{
|
{
|
||||||
public static bool IsMoving(this Actor self)
|
public static bool IsMoving(this Actor self)
|
||||||
{
|
{
|
||||||
if (self.IsIdle)
|
var a = self.GetCurrentActivity();
|
||||||
|
if (a == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Activity a = self.GetCurrentActivity();
|
|
||||||
Debug.Assert(a != null);
|
|
||||||
|
|
||||||
// Dirty, but it suffices until we do something better:
|
// Dirty, but it suffices until we do something better:
|
||||||
if (a.GetType() == typeof(Move)) return true;
|
if (a.GetType() == typeof(Move)) return true;
|
||||||
if (a.GetType() == typeof(MoveAdjacentTo)) return true;
|
if (a.GetType() == typeof(MoveAdjacentTo)) return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user