Convert IFacing.Facing and TurnSpeed to WAngle.
This commit is contained in:
@@ -170,7 +170,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
QueueChild(new FlyAttackRun(self, target, lastVisibleMaximumRange));
|
||||
|
||||
// Turn to face the target if required.
|
||||
else if (!attackAircraft.TargetInFiringArc(self, target, attackAircraft.Info.FacingTolerance))
|
||||
else if (!attackAircraft.TargetInFiringArc(self, target, 4 * attackAircraft.Info.FacingTolerance))
|
||||
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.TurnSpeed);
|
||||
|
||||
return false;
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
if (desiredFacing.HasValue && desiredFacing.Value != aircraft.Facing)
|
||||
{
|
||||
QueueChild(new Turn(self, desiredFacing.Value.Facing));
|
||||
QueueChild(new Turn(self, desiredFacing.Value));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,9 +198,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
return AttackStatus.NeedsToMove;
|
||||
}
|
||||
|
||||
if (!attack.TargetInFiringArc(self, target, attack.Info.FacingTolerance))
|
||||
if (!attack.TargetInFiringArc(self, target, 4 * attack.Info.FacingTolerance))
|
||||
{
|
||||
var desiredFacing = (attack.GetTargetPosition(pos, target) - pos).Yaw.Facing;
|
||||
var desiredFacing = (attack.GetTargetPosition(pos, target) - pos).Yaw;
|
||||
attackStatus |= AttackStatus.NeedsToTurn;
|
||||
QueueChild(new Turn(self, desiredFacing));
|
||||
return AttackStatus.NeedsToTurn;
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
var carryableFacing = carryall.Carryable.Trait<IFacing>();
|
||||
var facingDelta = facing.Facing - carryableFacing.Facing;
|
||||
foreach (var t in carryall.Carryable.TraitsImplementing<Turreted>())
|
||||
t.TurretFacing += facingDelta;
|
||||
t.TurretFacing += facingDelta.Facing;
|
||||
|
||||
carryableFacing.Facing = facing.Facing;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
// Turn to the required facing.
|
||||
if (deploy.DeployState == DeployState.Undeployed && deploy.Info.Facing != -1 && canTurn && !moving)
|
||||
QueueChild(new Turn(self, deploy.Info.Facing));
|
||||
QueueChild(new Turn(self, WAngle.FromFacing(deploy.Info.Facing)));
|
||||
}
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
|
||||
@@ -72,11 +72,11 @@ namespace OpenRA.Mods.Common.Activities
|
||||
// Turn to one of the harvestable facings
|
||||
if (harvInfo.HarvestFacings != 0)
|
||||
{
|
||||
var current = WAngle.FromFacing(facing.Facing);
|
||||
var current = facing.Facing;
|
||||
var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
|
||||
if (desired != current)
|
||||
{
|
||||
QueueChild(new Turn(self, desired.Facing));
|
||||
QueueChild(new Turn(self, desired));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
case DockingState.Turn:
|
||||
dockingState = DockingState.Dock;
|
||||
QueueChild(new Turn(self, DockAngle));
|
||||
QueueChild(new Turn(self, WAngle.FromFacing(DockAngle)));
|
||||
if (IsDragRequired)
|
||||
QueueChild(new Drag(self, StartDrag, EndDrag, DragLength));
|
||||
return false;
|
||||
|
||||
@@ -24,9 +24,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
WPos start, end;
|
||||
int length;
|
||||
int ticks = 0;
|
||||
int desiredFacing;
|
||||
WAngle? desiredFacing;
|
||||
|
||||
public Drag(Actor self, WPos start, WPos end, int length, int facing = -1)
|
||||
public Drag(Actor self, WPos start, WPos end, int length, WAngle? facing = null)
|
||||
{
|
||||
positionable = self.Trait<IPositionable>();
|
||||
disableable = self.TraitOrDefault<IMove>() as IDisabledTrait;
|
||||
@@ -39,8 +39,8 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
protected override void OnFirstRun(Actor self)
|
||||
{
|
||||
if (desiredFacing != -1)
|
||||
QueueChild(new Turn(self, desiredFacing));
|
||||
if (desiredFacing.HasValue)
|
||||
QueueChild(new Turn(self, desiredFacing.Value));
|
||||
}
|
||||
|
||||
public override bool Tick(Actor self)
|
||||
|
||||
@@ -385,7 +385,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
protected readonly Move Move;
|
||||
protected readonly WPos From, To;
|
||||
protected readonly int FromFacing, ToFacing;
|
||||
protected readonly WAngle FromFacing, ToFacing;
|
||||
protected readonly bool EnableArc;
|
||||
protected readonly WPos ArcCenter;
|
||||
protected readonly int ArcFromLength;
|
||||
@@ -396,7 +396,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
protected readonly int MoveFractionTotal;
|
||||
protected int moveFraction;
|
||||
|
||||
public MovePart(Move move, WPos from, WPos to, int fromFacing, int toFacing, int startingFraction)
|
||||
public MovePart(Move move, WPos from, WPos to, WAngle fromFacing, WAngle toFacing, int startingFraction)
|
||||
{
|
||||
Move = move;
|
||||
From = from;
|
||||
@@ -408,12 +408,12 @@ namespace OpenRA.Mods.Common.Activities
|
||||
IsInterruptible = false; // See comments in Move.Cancel()
|
||||
|
||||
// Calculate an elliptical arc that joins from and to
|
||||
var delta = Util.NormalizeFacing(fromFacing - toFacing);
|
||||
if (delta != 0 && delta != 128)
|
||||
var delta = (fromFacing - toFacing).Angle;
|
||||
if (delta != 0 && delta != 512)
|
||||
{
|
||||
// The center of rotation is where the normal vectors cross
|
||||
var u = new WVec(1024, 0, 0).Rotate(WRot.FromFacing(fromFacing));
|
||||
var v = new WVec(1024, 0, 0).Rotate(WRot.FromFacing(toFacing));
|
||||
var u = new WVec(1024, 0, 0).Rotate(WRot.FromYaw(fromFacing));
|
||||
var v = new WVec(1024, 0, 0).Rotate(WRot.FromYaw(toFacing));
|
||||
var w = from - to;
|
||||
var s = (v.Y * w.X - v.X * w.Y) * 1024 / (v.X * u.Y - v.Y * u.X);
|
||||
var x = from.X + s * u.X / 1024;
|
||||
@@ -476,9 +476,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
mobile.SetVisualPosition(self, To);
|
||||
|
||||
if (moveFraction >= MoveFractionTotal)
|
||||
mobile.Facing = ToFacing & 0xFF;
|
||||
mobile.Facing = ToFacing;
|
||||
else
|
||||
mobile.Facing = int2.Lerp(FromFacing, ToFacing, moveFraction, MoveFractionTotal) & 0xFF;
|
||||
mobile.Facing = WAngle.Lerp(FromFacing, ToFacing, moveFraction, MoveFractionTotal);
|
||||
}
|
||||
|
||||
protected abstract MovePart OnComplete(Actor self, Mobile mobile, Move parent);
|
||||
@@ -491,7 +491,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
class MoveFirstHalf : MovePart
|
||||
{
|
||||
public MoveFirstHalf(Move move, WPos from, WPos to, int fromFacing, int toFacing, int startingFraction)
|
||||
public MoveFirstHalf(Move move, WPos from, WPos to, WAngle fromFacing, WAngle toFacing, int startingFraction)
|
||||
: base(move, from, to, fromFacing, toFacing, startingFraction) { }
|
||||
|
||||
static bool IsTurn(Mobile mobile, CPos nextCell, Map map)
|
||||
@@ -499,8 +499,8 @@ namespace OpenRA.Mods.Common.Activities
|
||||
// Tight U-turns should be done in place instead of making silly looking loops.
|
||||
var nextFacing = map.FacingBetween(nextCell, mobile.ToCell, mobile.Facing);
|
||||
var currentFacing = map.FacingBetween(mobile.ToCell, mobile.FromCell, mobile.Facing);
|
||||
var delta = Util.NormalizeFacing(nextFacing - currentFacing);
|
||||
return delta != 0 && (delta < 96 || delta > 160);
|
||||
var delta = (nextFacing - currentFacing).Angle;
|
||||
return delta != 0 && (delta < 384 || delta > 640);
|
||||
}
|
||||
|
||||
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
||||
@@ -520,7 +520,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
Util.BetweenCells(self.World, mobile.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||
Util.BetweenCells(self.World, mobile.ToCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
|
||||
mobile.Facing,
|
||||
Util.GetNearestFacing(mobile.Facing, map.FacingBetween(mobile.ToCell, nextCell.Value.First, mobile.Facing)),
|
||||
map.FacingBetween(mobile.ToCell, nextCell.Value.First, mobile.Facing),
|
||||
moveFraction - MoveFractionTotal);
|
||||
|
||||
mobile.FinishedMoving(self);
|
||||
@@ -550,7 +550,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
class MoveSecondHalf : MovePart
|
||||
{
|
||||
public MoveSecondHalf(Move move, WPos from, WPos to, int fromFacing, int toFacing, int startingFraction)
|
||||
public MoveSecondHalf(Move move, WPos from, WPos to, WAngle fromFacing, WAngle toFacing, int startingFraction)
|
||||
: base(move, from, to, fromFacing, toFacing, startingFraction) { }
|
||||
|
||||
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
// Turn if required
|
||||
var delta = targetPos - currentPos;
|
||||
var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : mobile.Facing;
|
||||
var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw : mobile.Facing;
|
||||
if (facing != mobile.Facing)
|
||||
{
|
||||
mobile.Facing = Util.TickFacing(mobile.Facing, facing, mobile.TurnSpeed);
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
ChildActivity.Cancel(self);
|
||||
|
||||
var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
|
||||
QueueChild(new Land(self, Target.FromActor(cargo), -carryableBody.LocalToWorld(localOffset), WAngle.FromFacing(carryableFacing.Facing)));
|
||||
QueueChild(new Land(self, Target.FromActor(cargo), -carryableBody.LocalToWorld(localOffset), carryableFacing.Facing));
|
||||
|
||||
// Pause briefly before attachment for visual effect
|
||||
if (delay > 0)
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public readonly string ToActor;
|
||||
public CVec Offset = CVec.Zero;
|
||||
public int Facing = 96;
|
||||
public WAngle Facing = WAngle.FromFacing(96);
|
||||
public string[] Sounds = { };
|
||||
public string Notification = null;
|
||||
public int ForceHealthPercentage = 0;
|
||||
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
new LocationInit(self.Location + Offset),
|
||||
new OwnerInit(self.Owner),
|
||||
new FacingInit(Facing),
|
||||
new FacingInit(Facing.Facing),
|
||||
};
|
||||
|
||||
if (SkipMakeAnims)
|
||||
|
||||
@@ -19,9 +19,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
readonly Mobile mobile;
|
||||
readonly IFacing facing;
|
||||
readonly int desiredFacing;
|
||||
readonly WAngle desiredFacing;
|
||||
|
||||
public Turn(Actor self, int desiredFacing)
|
||||
public Turn(Actor self, WAngle desiredFacing)
|
||||
{
|
||||
mobile = self.TraitOrDefault<Mobile>();
|
||||
facing = self.Trait<IFacing>();
|
||||
|
||||
Reference in New Issue
Block a user