Convert Move and related plumbing to world coordinates.
This commit is contained in:
@@ -100,9 +100,9 @@ namespace OpenRA.Traits
|
|||||||
return loc.ToPPos() + new PVecInt(Game.CellSize / 2, Game.CellSize / 2);
|
return loc.ToPPos() + new PVecInt(Game.CellSize / 2, Game.CellSize / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PPos BetweenCells(CPos from, CPos to)
|
public static WPos BetweenCells(CPos from, CPos to)
|
||||||
{
|
{
|
||||||
return PPos.Lerp(CenterOfCell(from), CenterOfCell(to), 1, 2);
|
return WPos.Lerp(from.CenterPosition, to.CenterPosition, 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int2 AsInt2(this int[] xs) { return new int2(xs[0], xs[1]); }
|
public static int2 AsInt2(this int[] xs) { return new int2(xs[0], xs[1]); }
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
var mobile = self.Trait<Mobile>();
|
var mobile = self.Trait<Mobile>();
|
||||||
var to = target.CenterPosition;
|
var to = target.CenterPosition;
|
||||||
var from = self.CenterPosition;
|
var from = self.CenterPosition;
|
||||||
var speed = mobile.WorldMovementSpeedForCell(self, self.Location);
|
var speed = mobile.MovementSpeedForCell(self, self.Location);
|
||||||
var length = speed > 0 ? (int)((to - from).Length * 3 / speed) : 0;
|
var length = speed > 0 ? (to - from).Length / speed : 0;
|
||||||
|
|
||||||
return Util.SequenceActivities(
|
return Util.SequenceActivities(
|
||||||
new Turn(Util.GetFacing(to - from, mobile.Facing)),
|
new Turn(Util.GetFacing(to - from, mobile.Facing)),
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
mobile.IsMoving = true;
|
mobile.IsMoving = true;
|
||||||
|
|
||||||
from = self.CenterPosition;
|
from = self.CenterPosition;
|
||||||
var offset = MobileInfo.SubCellOffsets[targetMobile.fromSubCell];
|
to = targetMobile.fromCell.CenterPosition + MobileInfo.SubCellOffsets[targetMobile.fromSubCell];
|
||||||
to = targetMobile.fromCell.CenterPosition + new WVec(offset.X * 1024 / Game.CellSize, offset.Y * 1024 / Game.CellSize, 0);
|
|
||||||
length = Math.Max((to - from).Length / speed.Range, 1);
|
length = Math.Max((to - from).Length / speed.Range, 1);
|
||||||
|
|
||||||
self.Trait<RenderInfantry>().Attacking(self, Target.FromActor(target));
|
self.Trait<RenderInfantry>().Attacking(self, Target.FromActor(target));
|
||||||
|
|||||||
@@ -91,8 +91,8 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
mobile.Facing = Util.GetFacing(exit - current, mobile.Facing );
|
mobile.Facing = Util.GetFacing(exit - current, mobile.Facing );
|
||||||
mobile.SetPosition(actor, exitTile.Value);
|
mobile.SetPosition(actor, exitTile.Value);
|
||||||
mobile.AdjustPxPosition(actor, PPos.FromWPos(current));
|
mobile.AdjustPxPosition(actor, PPos.FromWPos(current));
|
||||||
var speed = mobile.WorldMovementSpeedForCell(actor, exitTile.Value);
|
var speed = mobile.MovementSpeedForCell(actor, exitTile.Value);
|
||||||
var length = speed > 0 ? ((int)(exit - current).Length * 3 / speed) : 0;
|
var length = speed > 0 ? (exit - current).Length / speed : 0;
|
||||||
|
|
||||||
w.Add(actor);
|
w.Add(actor);
|
||||||
actor.CancelActivity();
|
actor.CancelActivity();
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (mobile != null)
|
if (mobile != null)
|
||||||
{
|
{
|
||||||
if (!mobile.CanEnterCell(self.Location, self, false)) return;
|
if (!mobile.CanEnterCell(self.Location, self, false)) return;
|
||||||
td.Add(new HuskSpeedInit(mobile.MovementSpeedForCell(self, self.Location)));
|
td.Add(new HuskSpeedInit(mobile.MovementSpeedForCell(self, self.Location) * 3 * Game.CellSize / 1024));
|
||||||
}
|
}
|
||||||
|
|
||||||
var aircraft = self.TraitOrDefault<Aircraft>();
|
var aircraft = self.TraitOrDefault<Aircraft>();
|
||||||
|
|||||||
@@ -81,14 +81,14 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
return passability.ToBits();
|
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.TopLeft, new WVec(-299, -256, 0)},
|
||||||
{SubCell.TopRight, new PVecInt(6,-6)},
|
{SubCell.TopRight, new WVec(256, -256, 0)},
|
||||||
{SubCell.Center, new PVecInt(0,0)},
|
{SubCell.Center, new WVec(0, 0, 0)},
|
||||||
{SubCell.BottomLeft, new PVecInt(-7,6)},
|
{SubCell.BottomLeft, new WVec(-299, 256, 0)},
|
||||||
{SubCell.BottomRight, new PVecInt(6,6)},
|
{SubCell.BottomRight, new WVec(256, 256, 0)},
|
||||||
{SubCell.FullCell, new PVecInt(0,0)},
|
{SubCell.FullCell, new WVec(0, 0, 0)},
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool IsMovingInMyDirection(Actor self, Actor other)
|
static bool IsMovingInMyDirection(Actor self, Actor other)
|
||||||
@@ -204,7 +204,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
if (init.Contains<LocationInit>())
|
if (init.Contains<LocationInit>())
|
||||||
{
|
{
|
||||||
this.__fromCell = this.__toCell = init.Get<LocationInit, CPos>();
|
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;
|
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)
|
public void SetPosition(Actor self, CPos cell)
|
||||||
{
|
{
|
||||||
SetLocation(cell,fromSubCell, cell,fromSubCell);
|
SetLocation(cell,fromSubCell, cell,fromSubCell);
|
||||||
PxPosition = Util.CenterOfCell(fromCell) + MobileInfo.SubCellOffsets[fromSubCell];
|
PxPosition = PPos.FromWPos(fromCell.CenterPosition + MobileInfo.SubCellOffsets[fromSubCell]);
|
||||||
FinishedMoving(self);
|
FinishedMoving(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,12 +422,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
decimal speed = Info.Speed * Info.TerrainSpeeds[type].Speed;
|
decimal speed = Info.Speed * Info.TerrainSpeeds[type].Speed;
|
||||||
foreach (var t in self.TraitsImplementing<ISpeedModifier>())
|
foreach (var t in self.TraitsImplementing<ISpeedModifier>())
|
||||||
speed *= t.GetSpeedModifier();
|
speed *= t.GetSpeedModifier();
|
||||||
return (int)(speed / 100);
|
return (int)(speed / 100) * 1024 / (3 * Game.CellSize);
|
||||||
}
|
|
||||||
|
|
||||||
public int WorldMovementSpeedForCell(Actor self, CPos cell)
|
|
||||||
{
|
|
||||||
return MovementSpeedForCell(self, cell) * 1024 / Game.CellSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddInfluence()
|
public void AddInfluence()
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, nextCell.Value.First, nextCell.Value.Second);
|
mobile.SetLocation(mobile.fromCell, mobile.fromSubCell, nextCell.Value.First, nextCell.Value.Second);
|
||||||
var move = new MoveFirstHalf(
|
var move = new MoveFirstHalf(
|
||||||
this,
|
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,
|
Util.BetweenCells(mobile.fromCell, mobile.toCell) + (MobileInfo.SubCellOffsets[mobile.fromSubCell] + MobileInfo.SubCellOffsets[mobile.toSubCell]) / 2,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
@@ -273,12 +273,12 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
abstract class MovePart : Activity
|
abstract class MovePart : Activity
|
||||||
{
|
{
|
||||||
protected readonly Move move;
|
protected readonly Move move;
|
||||||
protected readonly PPos from, to;
|
protected readonly WPos from, to;
|
||||||
protected readonly int fromFacing, toFacing;
|
protected readonly int fromFacing, toFacing;
|
||||||
protected readonly int moveFractionTotal;
|
protected readonly int moveFractionTotal;
|
||||||
protected int moveFraction;
|
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.move = move;
|
||||||
this.from = from;
|
this.from = from;
|
||||||
@@ -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 = (to - from).Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Cancel(Actor self)
|
public override void Cancel(Actor self)
|
||||||
@@ -328,7 +328,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
|
|
||||||
void UpdateCenterLocation(Actor self, Mobile mobile)
|
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)
|
if (moveFraction >= moveFractionTotal)
|
||||||
mobile.Facing = toFacing & 0xFF;
|
mobile.Facing = toFacing & 0xFF;
|
||||||
@@ -346,7 +346,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
|
|
||||||
class MoveFirstHalf : MovePart
|
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) { }
|
: base(move, from, to, fromFacing, toFacing, startingFraction) { }
|
||||||
|
|
||||||
static bool IsTurn(Mobile mobile, CPos nextCell)
|
static bool IsTurn(Mobile mobile, CPos nextCell)
|
||||||
@@ -384,7 +384,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
var ret2 = new MoveSecondHalf(
|
var ret2 = new MoveSecondHalf(
|
||||||
move,
|
move,
|
||||||
Util.BetweenCells(mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
Util.BetweenCells(mobile.fromCell, mobile.toCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||||
Util.CenterOfCell(mobile.toCell) + toSubcellOffset,
|
mobile.toCell.CenterPosition + toSubcellOffset,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
mobile.Facing,
|
mobile.Facing,
|
||||||
moveFraction - moveFractionTotal);
|
moveFraction - moveFractionTotal);
|
||||||
@@ -397,7 +397,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, WPos from, WPos 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)
|
||||||
|
|||||||
@@ -88,8 +88,7 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
var rangeSquared = range.Range*range.Range;
|
var rangeSquared = range.Range*range.Range;
|
||||||
|
|
||||||
// Correct for SubCell offset
|
// Correct for SubCell offset
|
||||||
var so = MobileInfo.SubCellOffsets[srcSub];
|
target -= MobileInfo.SubCellOffsets[srcSub];
|
||||||
target -= new WVec(so.X * 1024 / Game.CellSize, so.Y * 1024 / Game.CellSize, 0);
|
|
||||||
|
|
||||||
// Select only the tiles that are within range from the requested SubCell
|
// Select only the tiles that are within range from the requested SubCell
|
||||||
// This assumes that the SubCell does not change during the path traversal
|
// This assumes that the SubCell does not change during the path traversal
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ namespace OpenRA.Mods.RA
|
|||||||
if (mobile != null)
|
if (mobile != null)
|
||||||
{
|
{
|
||||||
// Animate the spawn -> exit transition
|
// Animate the spawn -> exit transition
|
||||||
var speed = mobile.WorldMovementSpeedForCell(newUnit, exit);
|
var speed = mobile.MovementSpeedForCell(newUnit, exit);
|
||||||
var length = speed > 0 ? (int)((to - spawn).Length * 3 / speed) : 0;
|
var length = speed > 0 ? (to - spawn).Length / speed : 0;
|
||||||
newUnit.QueueActivity(new Drag(spawn, to, length));
|
newUnit.QueueActivity(new Drag(spawn, to, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user