Convert Move and related plumbing to world coordinates.
This commit is contained in:
@@ -81,14 +81,14 @@ namespace OpenRA.Mods.RA.Move
|
||||
return passability.ToBits();
|
||||
}
|
||||
|
||||
public static readonly Dictionary<SubCell, PVecInt> SubCellOffsets = new Dictionary<SubCell, PVecInt>()
|
||||
public static readonly Dictionary<SubCell, WVec> SubCellOffsets = new Dictionary<SubCell, WVec>()
|
||||
{
|
||||
{SubCell.TopLeft, new PVecInt(-7,-6)},
|
||||
{SubCell.TopRight, new PVecInt(6,-6)},
|
||||
{SubCell.Center, new PVecInt(0,0)},
|
||||
{SubCell.BottomLeft, new PVecInt(-7,6)},
|
||||
{SubCell.BottomRight, new PVecInt(6,6)},
|
||||
{SubCell.FullCell, new PVecInt(0,0)},
|
||||
{SubCell.TopLeft, new WVec(-299, -256, 0)},
|
||||
{SubCell.TopRight, new WVec(256, -256, 0)},
|
||||
{SubCell.Center, new WVec(0, 0, 0)},
|
||||
{SubCell.BottomLeft, new WVec(-299, 256, 0)},
|
||||
{SubCell.BottomRight, new WVec(256, 256, 0)},
|
||||
{SubCell.FullCell, new WVec(0, 0, 0)},
|
||||
};
|
||||
|
||||
static bool IsMovingInMyDirection(Actor self, Actor other)
|
||||
@@ -204,7 +204,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
if (init.Contains<LocationInit>())
|
||||
{
|
||||
this.__fromCell = this.__toCell = init.Get<LocationInit, CPos>();
|
||||
this.PxPosition = Util.CenterOfCell(fromCell) + MobileInfo.SubCellOffsets[fromSubCell];
|
||||
this.PxPosition = PPos.FromWPos(fromCell.CenterPosition + MobileInfo.SubCellOffsets[fromSubCell]);
|
||||
}
|
||||
|
||||
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing;
|
||||
@@ -214,7 +214,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
public void SetPosition(Actor self, CPos cell)
|
||||
{
|
||||
SetLocation(cell,fromSubCell, cell,fromSubCell);
|
||||
PxPosition = Util.CenterOfCell(fromCell) + MobileInfo.SubCellOffsets[fromSubCell];
|
||||
PxPosition = PPos.FromWPos(fromCell.CenterPosition + MobileInfo.SubCellOffsets[fromSubCell]);
|
||||
FinishedMoving(self);
|
||||
}
|
||||
|
||||
@@ -422,12 +422,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
decimal speed = Info.Speed * Info.TerrainSpeeds[type].Speed;
|
||||
foreach (var t in self.TraitsImplementing<ISpeedModifier>())
|
||||
speed *= t.GetSpeedModifier();
|
||||
return (int)(speed / 100);
|
||||
}
|
||||
|
||||
public int WorldMovementSpeedForCell(Actor self, CPos cell)
|
||||
{
|
||||
return MovementSpeedForCell(self, cell) * 1024 / Game.CellSize;
|
||||
return (int)(speed / 100) * 1024 / (3 * Game.CellSize);
|
||||
}
|
||||
|
||||
public void AddInfluence()
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, nextCell.Value.First, nextCell.Value.Second);
|
||||
var move = new MoveFirstHalf(
|
||||
this,
|
||||
Util.CenterOfCell(mobile.fromCell) + MobileInfo.SubCellOffsets[mobile.fromSubCell],
|
||||
mobile.fromCell.CenterPosition + MobileInfo.SubCellOffsets[mobile.fromSubCell],
|
||||
Util.BetweenCells(mobile.fromCell, mobile.toCell) + (MobileInfo.SubCellOffsets[mobile.fromSubCell] + MobileInfo.SubCellOffsets[mobile.toSubCell]) / 2,
|
||||
mobile.Facing,
|
||||
mobile.Facing,
|
||||
@@ -273,12 +273,12 @@ namespace OpenRA.Mods.RA.Move
|
||||
abstract class MovePart : Activity
|
||||
{
|
||||
protected readonly Move move;
|
||||
protected readonly PPos from, to;
|
||||
protected readonly WPos from, to;
|
||||
protected readonly int fromFacing, toFacing;
|
||||
protected readonly int moveFractionTotal;
|
||||
protected int moveFraction;
|
||||
|
||||
public MovePart(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction)
|
||||
public MovePart(Move move, WPos from, WPos to, int fromFacing, int toFacing, int startingFraction)
|
||||
{
|
||||
this.move = move;
|
||||
this.from = from;
|
||||
@@ -286,7 +286,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
this.fromFacing = fromFacing;
|
||||
this.toFacing = toFacing;
|
||||
this.moveFraction = startingFraction;
|
||||
this.moveFractionTotal = 3 * (to - from).Length;
|
||||
this.moveFractionTotal = (to - from).Length;
|
||||
}
|
||||
|
||||
public override void Cancel(Actor self)
|
||||
@@ -328,7 +328,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
|
||||
void UpdateCenterLocation(Actor self, Mobile mobile)
|
||||
{
|
||||
mobile.PxPosition = PPos.Lerp(from, to, moveFraction, moveFractionTotal);
|
||||
mobile.PxPosition = PPos.FromWPos(WPos.Lerp(from, to, moveFraction, moveFractionTotal));
|
||||
|
||||
if (moveFraction >= moveFractionTotal)
|
||||
mobile.Facing = toFacing & 0xFF;
|
||||
@@ -346,7 +346,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
|
||||
class MoveFirstHalf : MovePart
|
||||
{
|
||||
public MoveFirstHalf(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction)
|
||||
public MoveFirstHalf(Move move, WPos from, WPos to, int fromFacing, int toFacing, int startingFraction)
|
||||
: base(move, from, to, fromFacing, toFacing, startingFraction) { }
|
||||
|
||||
static bool IsTurn(Mobile mobile, CPos nextCell)
|
||||
@@ -384,7 +384,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
var ret2 = new MoveSecondHalf(
|
||||
move,
|
||||
Util.BetweenCells(mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||
Util.CenterOfCell(mobile.toCell) + toSubcellOffset,
|
||||
mobile.toCell.CenterPosition + toSubcellOffset,
|
||||
mobile.Facing,
|
||||
mobile.Facing,
|
||||
moveFraction - moveFractionTotal);
|
||||
@@ -397,7 +397,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
|
||||
class MoveSecondHalf : MovePart
|
||||
{
|
||||
public MoveSecondHalf(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction)
|
||||
public MoveSecondHalf(Move move, WPos from, WPos to, int fromFacing, int toFacing, int startingFraction)
|
||||
: base(move, from, to, fromFacing, toFacing, startingFraction) { }
|
||||
|
||||
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
||||
|
||||
@@ -88,8 +88,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
var rangeSquared = range.Range*range.Range;
|
||||
|
||||
// Correct for SubCell offset
|
||||
var so = MobileInfo.SubCellOffsets[srcSub];
|
||||
target -= new WVec(so.X * 1024 / Game.CellSize, so.Y * 1024 / Game.CellSize, 0);
|
||||
target -= MobileInfo.SubCellOffsets[srcSub];
|
||||
|
||||
// Select only the tiles that are within range from the requested SubCell
|
||||
// This assumes that the SubCell does not change during the path traversal
|
||||
|
||||
Reference in New Issue
Block a user