Convert Drag to world coords.
This commit is contained in:
@@ -35,9 +35,9 @@ namespace OpenRA.Mods.RA.Activities
|
||||
|
||||
// Move to the middle of the target, ignoring impassable tiles
|
||||
var mobile = self.Trait<Mobile>();
|
||||
var to = target.CenterLocation;
|
||||
var from = self.CenterLocation;
|
||||
var speed = mobile.MovementSpeedForCell(self, self.Location);
|
||||
var to = target.CenterPosition;
|
||||
var from = self.CenterPosition;
|
||||
var speed = mobile.WorldMovementSpeedForCell(self, self.Location);
|
||||
var length = speed > 0 ? (int)((to - from).Length * 3 / speed) : 0;
|
||||
|
||||
return Util.SequenceActivities(
|
||||
|
||||
@@ -79,23 +79,24 @@ namespace OpenRA.Mods.RA.Activities
|
||||
return this;
|
||||
|
||||
var actor = cargo.Unload(self);
|
||||
var exitPx = Util.CenterOfCell(exitTile.Value);
|
||||
var currentPx = Util.CenterOfCell(self.Location);
|
||||
var exit = exitTile.Value.CenterPosition;
|
||||
var current = self.Location.CenterPosition;
|
||||
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
if (actor.Destroyed) return;
|
||||
if (actor.Destroyed)
|
||||
return;
|
||||
|
||||
var mobile = actor.Trait<Mobile>();
|
||||
mobile.Facing = Util.GetFacing( (exitPx - currentPx).ToInt2(), mobile.Facing );
|
||||
mobile.Facing = Util.GetFacing(exit - current, mobile.Facing );
|
||||
mobile.SetPosition(actor, exitTile.Value);
|
||||
mobile.AdjustPxPosition(actor, currentPx);
|
||||
var speed = mobile.MovementSpeedForCell(actor, exitTile.Value);
|
||||
var length = speed > 0 ? ((int)(exitPx - currentPx).Length * 3 / speed) : 0;
|
||||
mobile.AdjustPxPosition(actor, PPos.FromWPos(current));
|
||||
var speed = mobile.WorldMovementSpeedForCell(actor, exitTile.Value);
|
||||
var length = speed > 0 ? ((int)(exit - current).Length * 3 / speed) : 0;
|
||||
|
||||
w.Add(actor);
|
||||
actor.CancelActivity();
|
||||
actor.QueueActivity(new Drag(currentPx, exitPx, length));
|
||||
actor.QueueActivity(new Drag(current, exit, length));
|
||||
actor.QueueActivity(mobile.MoveTo(exitTile.Value, 0));
|
||||
|
||||
var rallyPoint = ChooseRallyPoint(actor).Value;
|
||||
|
||||
@@ -15,25 +15,25 @@ namespace OpenRA.Mods.RA.Move
|
||||
{
|
||||
public class Drag : Activity
|
||||
{
|
||||
PPos endLocation;
|
||||
PPos startLocation;
|
||||
WPos start, end;
|
||||
int length;
|
||||
int ticks = 0;
|
||||
|
||||
public Drag(PPos start, PPos end, int length)
|
||||
public Drag(WPos start, WPos end, int length)
|
||||
{
|
||||
startLocation = start;
|
||||
endLocation = end;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public override Activity Tick( Actor self )
|
||||
{
|
||||
var mobile = self.Trait<Mobile>();
|
||||
mobile.PxPosition = length > 1
|
||||
? PPos.Lerp(startLocation, endLocation, ticks, length - 1)
|
||||
: endLocation;
|
||||
var pos = length > 1
|
||||
? WPos.Lerp(start, end, ticks, length - 1)
|
||||
: end;
|
||||
|
||||
mobile.PxPosition = PPos.FromWPos(pos);
|
||||
if (++ticks >= length)
|
||||
{
|
||||
mobile.IsMoving = false;
|
||||
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Move
|
||||
|
||||
public override IEnumerable<Target> GetTargets( Actor self )
|
||||
{
|
||||
yield return Target.FromPos(endLocation);
|
||||
yield return Target.FromPos(PPos.FromWPos(end));
|
||||
}
|
||||
|
||||
// Cannot be cancelled
|
||||
|
||||
@@ -420,6 +420,11 @@ namespace OpenRA.Mods.RA.Move
|
||||
return (int)(speed / 100);
|
||||
}
|
||||
|
||||
public int WorldMovementSpeedForCell(Actor self, CPos cell)
|
||||
{
|
||||
return MovementSpeedForCell(self, cell) * 1024 / Game.CellSize;
|
||||
}
|
||||
|
||||
public void AddInfluence()
|
||||
{
|
||||
if (self.IsInWorld)
|
||||
|
||||
@@ -50,8 +50,8 @@ namespace OpenRA.Mods.RA
|
||||
public void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo)
|
||||
{
|
||||
var exit = self.Location + exitinfo.ExitCellVector;
|
||||
var spawn = self.Trait<IHasLocation>().PxPosition + exitinfo.SpawnOffsetVector;
|
||||
var to = Util.CenterOfCell(exit);
|
||||
var spawn = (self.Trait<IHasLocation>().PxPosition + exitinfo.SpawnOffsetVector).ToWPos(0);
|
||||
var to = exit.CenterPosition;
|
||||
|
||||
var fi = producee.Traits.Get<IFacingInfo>();
|
||||
var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi.GetInitialFacing()) : exitinfo.Facing;
|
||||
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.RA
|
||||
// TODO: Move this into an *Init
|
||||
// TODO: We should be adjusting the actual position for aircraft, not just visuals.
|
||||
var teleportable = newUnit.Trait<ITeleportable>();
|
||||
teleportable.AdjustPxPosition(newUnit, spawn);
|
||||
teleportable.AdjustPxPosition(newUnit, PPos.FromWPos(spawn));
|
||||
|
||||
// TODO: Generalize this for non-mobile (e.g. aircraft) too
|
||||
// Remember to update the Enter activity too
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA
|
||||
if (mobile != null)
|
||||
{
|
||||
// Animate the spawn -> exit transition
|
||||
var speed = mobile.MovementSpeedForCell(newUnit, exit);
|
||||
var speed = mobile.WorldMovementSpeedForCell(newUnit, exit);
|
||||
var length = speed > 0 ? (int)((to - spawn).Length * 3 / speed) : 0;
|
||||
newUnit.QueueActivity(new Drag(spawn, to, length));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user