New types for cell and pixel coordinate position/vectors.

This commit is contained in:
James Dunne
2012-06-20 23:22:27 -05:00
parent 0b98a8ce5e
commit 9c49143534
162 changed files with 1291 additions and 865 deletions

View File

@@ -20,15 +20,15 @@ namespace OpenRA.Mods.RA.Move
{
class Move : Activity
{
int2? destination;
CPos? destination;
int nearEnough;
public List<int2> path;
Func<Actor, Mobile, List<int2>> getPath;
public List<CPos> path;
Func<Actor, Mobile, List<CPos>> getPath;
public Actor ignoreBuilding;
// Scriptable move order
// Ignores lane bias and nearby units
public Move( int2 destination )
public Move(CPos destination)
{
this.getPath = (self,mobile) =>
self.World.WorldActor.Trait<PathFinder>().FindPath(
@@ -38,14 +38,14 @@ namespace OpenRA.Mods.RA.Move
this.nearEnough = 0;
}
public Move( int2 destination, int nearEnough )
public Move(CPos destination, int nearEnough)
{
this.getPath = (self,mobile) => self.World.WorldActor.Trait<PathFinder>().FindUnitPath( mobile.toCell, destination, self );
this.destination = destination;
this.nearEnough = nearEnough;
}
public Move(int2 destination, Actor ignoreBuilding)
public Move(CPos destination, Actor ignoreBuilding)
{
this.getPath = (self,mobile) =>
self.World.WorldActor.Trait<PathFinder>().FindPath(
@@ -60,13 +60,13 @@ namespace OpenRA.Mods.RA.Move
public Move(Target target, int range)
{
this.getPath = (self,mobile) => self.World.WorldActor.Trait<PathFinder>().FindUnitPathToRange(
mobile.toCell, Util.CellContaining(target.CenterLocation),
mobile.toCell, target.CenterLocation.ToCPos(),
range, self);
this.destination = null;
this.nearEnough = range;
}
public Move(Func<List<int2>> getPath)
public Move(Func<List<CPos>> getPath)
{
this.getPath = (_1,_2) => getPath();
this.destination = null;
@@ -83,7 +83,7 @@ namespace OpenRA.Mods.RA.Move
return hash;
}
List<int2> EvalPath( Actor self, Mobile mobile )
List<CPos> EvalPath(Actor self, Mobile mobile)
{
var path = getPath(self, mobile).TakeWhile(a => a != mobile.toCell).ToList();
mobile.PathHash = HashList(path);
@@ -131,7 +131,7 @@ namespace OpenRA.Mods.RA.Move
if( nextCell == null )
return this;
int2 dir = nextCell.Value.First - mobile.fromCell;
var dir = nextCell.Value.First - mobile.fromCell;
var firstFacing = Util.GetFacing( dir, mobile.Facing );
if( firstFacing != mobile.Facing )
{
@@ -167,7 +167,7 @@ namespace OpenRA.Mods.RA.Move
bool hasNudged;
int waitTicksRemaining;
void NudgeBlocker(Actor self, int2 nextCell)
void NudgeBlocker(Actor self, CPos nextCell)
{
var blocker = self.World.ActorMap.GetUnitsAt(nextCell).FirstOrDefault();
if (blocker == null) return;
@@ -180,7 +180,7 @@ namespace OpenRA.Mods.RA.Move
nudge.OnNudge(blocker, self, false);
}
Pair<int2, SubCell>? PopPath( Actor self, Mobile mobile )
Pair<CPos, SubCell>? PopPath(Actor self, Mobile mobile)
{
if( path.Count == 0 ) return null;
var nextCell = path[ path.Count - 1 ];
@@ -233,7 +233,7 @@ namespace OpenRA.Mods.RA.Move
public override void Cancel( Actor self )
{
path = new List<int2>();
path = new List<CPos>();
base.Cancel(self);
}
@@ -242,19 +242,19 @@ namespace OpenRA.Mods.RA.Move
if( path != null )
return Enumerable.Reverse(path).Select( c => Target.FromCell(c) );
if( destination != null )
return new Target[] { Target.FromPos(destination.Value) };
return new Target[] { Target.FromCell(destination.Value) };
return Target.NoTargets;
}
abstract class MovePart : Activity
{
public readonly Move move;
public readonly int2 from, to;
public readonly PPos from, to;
public readonly int fromFacing, toFacing;
public int moveFraction;
public readonly int moveFractionTotal;
public MovePart( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction )
public MovePart(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction)
{
this.move = move;
this.from = from;
@@ -304,7 +304,7 @@ namespace OpenRA.Mods.RA.Move
void UpdateCenterLocation( Actor self, Mobile mobile )
{
mobile.PxPosition = int2.Lerp( from, to, moveFraction, moveFractionTotal );
mobile.PxPosition = PPos.Lerp(from, to, moveFraction, moveFractionTotal);
if( moveFraction >= moveFractionTotal )
mobile.Facing = toFacing & 0xFF;
@@ -322,10 +322,10 @@ namespace OpenRA.Mods.RA.Move
class MoveFirstHalf : MovePart
{
public MoveFirstHalf( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction )
public MoveFirstHalf(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction)
: base( move, from, to, fromFacing, toFacing, startingFraction ) { }
static bool IsTurn( Mobile mobile, int2 nextCell )
static bool IsTurn( Mobile mobile, CPos nextCell )
{
return nextCell - mobile.toCell !=
mobile.toCell - mobile.fromCell;
@@ -373,7 +373,7 @@ namespace OpenRA.Mods.RA.Move
class MoveSecondHalf : MovePart
{
public MoveSecondHalf( Move move, int2 from, int2 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 )
{
}