Skip to content

Commit

Permalink
Rename fraction to distance/progress in MovePart
Browse files Browse the repository at this point in the history
  • Loading branch information
reaperrr authored and teinarss committed Apr 15, 2021
1 parent 646495f commit 4c7e3d8
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions OpenRA.Mods.Common/Activities/Move/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,18 @@ abstract class MovePart : Activity
protected readonly int ArcToLength;
protected readonly WAngle ArcToAngle;

protected readonly int MoveFractionTotal;
protected int moveFraction;
protected readonly int Distance;
protected int progress;

public MovePart(Move move, WPos from, WPos to, WAngle fromFacing, WAngle toFacing, int startingFraction)
public MovePart(Move move, WPos from, WPos to, WAngle fromFacing, WAngle toFacing, int carryoverProgress)
{
Move = move;
From = from;
To = to;
FromFacing = fromFacing;
ToFacing = toFacing;
moveFraction = startingFraction;
MoveFractionTotal = (to - from).Length;
progress = carryoverProgress;
Distance = (to - from).Length;
IsInterruptible = false; // See comments in Move.Cancel()

// Calculate an elliptical arc that joins from and to
Expand Down Expand Up @@ -436,11 +436,11 @@ public MovePart(Move move, WPos from, WPos to, WAngle fromFacing, WAngle toFacin
public override bool Tick(Actor self)
{
var mobile = Move.mobile;
moveFraction += mobile.MovementSpeedForCell(self, mobile.ToCell);
progress += mobile.MovementSpeedForCell(self, mobile.ToCell);

if (moveFraction >= MoveFractionTotal)
if (progress >= Distance)
{
moveFraction = MoveFractionTotal;
progress = Distance;
mobile.SetCenterPosition(self, To);
mobile.Facing = ToFacing;

Expand All @@ -451,19 +451,19 @@ public override bool Tick(Actor self)
WPos pos;
if (EnableArc)
{
var angle = WAngle.Lerp(ArcFromAngle, ArcToAngle, moveFraction, MoveFractionTotal);
var length = int2.Lerp(ArcFromLength, ArcToLength, moveFraction, MoveFractionTotal);
var height = int2.Lerp(From.Z, To.Z, moveFraction, MoveFractionTotal);
var angle = WAngle.Lerp(ArcFromAngle, ArcToAngle, progress, Distance);
var length = int2.Lerp(ArcFromLength, ArcToLength, progress, Distance);
var height = int2.Lerp(From.Z, To.Z, progress, Distance);
pos = ArcCenter + new WVec(0, length, height).Rotate(WRot.FromYaw(angle));
}
else
pos = WPos.Lerp(From, To, moveFraction, MoveFractionTotal);
pos = WPos.Lerp(From, To, progress, Distance);

if (self.Location.Layer == 0)
pos -= new WVec(WDist.Zero, WDist.Zero, self.World.Map.DistanceAboveTerrain(pos));

mobile.SetCenterPosition(self, pos);
mobile.Facing = WAngle.Lerp(FromFacing, ToFacing, moveFraction, MoveFractionTotal);
mobile.Facing = WAngle.Lerp(FromFacing, ToFacing, progress, Distance);
return false;
}

Expand All @@ -477,8 +477,8 @@ public override IEnumerable<Target> GetTargets(Actor self)

class MoveFirstHalf : MovePart
{
public MoveFirstHalf(Move move, WPos from, WPos to, WAngle fromFacing, WAngle toFacing, int startingFraction)
: base(move, from, to, fromFacing, toFacing, startingFraction) { }
public MoveFirstHalf(Move move, WPos from, WPos to, WAngle fromFacing, WAngle toFacing, int carryoverProgress)
: base(move, from, to, fromFacing, toFacing, carryoverProgress) { }

static bool IsTurn(Mobile mobile, CPos nextCell, Map map)
{
Expand Down Expand Up @@ -511,7 +511,7 @@ protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
Util.BetweenCells(self.World, mobile.ToCell, nextCell.Value.Cell) + (toSubcellOffset + nextSubcellOffset) / 2,
mobile.Facing,
map.FacingBetween(mobile.ToCell, nextCell.Value.Cell, mobile.Facing),
moveFraction - MoveFractionTotal);
progress - Distance);

mobile.FinishedMoving(self);
mobile.SetLocation(mobile.ToCell, mobile.ToSubCell, nextCell.Value.Cell, nextCell.Value.SubCell);
Expand All @@ -530,7 +530,7 @@ protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
toPos + toSubcellOffset,
mobile.Facing,
mobile.Facing,
moveFraction - MoveFractionTotal);
progress - Distance);

mobile.EnteringCell(self);
mobile.SetLocation(mobile.ToCell, mobile.ToSubCell, mobile.ToCell, mobile.ToSubCell);
Expand All @@ -540,8 +540,8 @@ protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)

class MoveSecondHalf : MovePart
{
public MoveSecondHalf(Move move, WPos from, WPos to, WAngle fromFacing, WAngle toFacing, int startingFraction)
: base(move, from, to, fromFacing, toFacing, startingFraction) { }
public MoveSecondHalf(Move move, WPos from, WPos to, WAngle fromFacing, WAngle toFacing, int carryoverProgress)
: base(move, from, to, fromFacing, toFacing, carryoverProgress) { }

protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
{
Expand Down

0 comments on commit 4c7e3d8

Please sign in to comment.