Convert IFacing.Facing and TurnSpeed to WAngle.
This commit is contained in:
@@ -69,8 +69,8 @@ namespace OpenRA
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO: Support non-zero pitch/roll in IFacing (IOrientation?)
|
// TODO: Support non-zero pitch/roll in IFacing (IOrientation?)
|
||||||
var facingValue = facing != null ? facing.Facing : 0;
|
var facingValue = facing != null ? facing.Facing : WAngle.Zero;
|
||||||
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facingValue));
|
return new WRot(WAngle.Zero, WAngle.Zero, facingValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -941,13 +941,13 @@ namespace OpenRA
|
|||||||
return projectedHeight[(MPos)puv];
|
return projectedHeight[(MPos)puv];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int FacingBetween(CPos cell, CPos towards, int fallbackfacing)
|
public WAngle FacingBetween(CPos cell, CPos towards, WAngle fallbackfacing)
|
||||||
{
|
{
|
||||||
var delta = CenterOfCell(towards) - CenterOfCell(cell);
|
var delta = CenterOfCell(towards) - CenterOfCell(cell);
|
||||||
if (delta.HorizontalLengthSquared == 0)
|
if (delta.HorizontalLengthSquared == 0)
|
||||||
return fallbackfacing;
|
return fallbackfacing;
|
||||||
|
|
||||||
return delta.Yaw.Facing;
|
return delta.Yaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Resize(int width, int height)
|
public void Resize(int width, int height)
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ namespace OpenRA.Traits
|
|||||||
public interface IFacing
|
public interface IFacing
|
||||||
{
|
{
|
||||||
int TurnSpeed { get; }
|
int TurnSpeed { get; }
|
||||||
int Facing { get; set; }
|
WAngle Facing { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IFacingInfo : ITraitInfoInterface { int GetInitialFacing(); }
|
public interface IFacingInfo : ITraitInfoInterface { int GetInitialFacing(); }
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ namespace OpenRA.Mods.Cnc.Activities
|
|||||||
|
|
||||||
var destination = self.World.Map.CenterOfSubCell(target.Actor.Location, targetSubcell);
|
var destination = self.World.Map.CenterOfSubCell(target.Actor.Location, targetSubcell);
|
||||||
var origin = self.World.Map.CenterOfSubCell(self.Location, mobile.FromSubCell);
|
var origin = self.World.Map.CenterOfSubCell(self.Location, mobile.FromSubCell);
|
||||||
var desiredFacing = (destination - origin).Yaw.Facing;
|
var desiredFacing = (destination - origin).Yaw;
|
||||||
if (mobile.Facing != desiredFacing)
|
if (mobile.Facing != desiredFacing)
|
||||||
{
|
{
|
||||||
QueueChild(new Turn(self, desiredFacing));
|
QueueChild(new Turn(self, desiredFacing));
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
|||||||
readonly Cargo cargo;
|
readonly Cargo cargo;
|
||||||
readonly BodyOrientation body;
|
readonly BodyOrientation body;
|
||||||
readonly IFacing facing;
|
readonly IFacing facing;
|
||||||
int cachedFacing;
|
WAngle cachedFacing;
|
||||||
|
|
||||||
Dictionary<Actor, IActorPreview[]> previews = new Dictionary<Actor, IActorPreview[]>();
|
Dictionary<Actor, IActorPreview[]> previews = new Dictionary<Actor, IActorPreview[]>();
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
|||||||
var passengerInits = new TypeDictionary()
|
var passengerInits = new TypeDictionary()
|
||||||
{
|
{
|
||||||
new OwnerInit(p.Owner),
|
new OwnerInit(p.Owner),
|
||||||
new DynamicFacingInit(() => body.QuantizeFacing(WAngle.FromFacing(facing.Facing)).Facing),
|
new DynamicFacingInit(() => body.QuantizeFacing(facing.Facing).Facing),
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var api in p.TraitsImplementing<IActorPreviewInitModifier>())
|
foreach (var api in p.TraitsImplementing<IActorPreviewInitModifier>())
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
|||||||
|
|
||||||
void ITick.Tick(Actor self)
|
void ITick.Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (facing.Facing <= 128)
|
if (facing.Facing.Angle <= 512)
|
||||||
{
|
{
|
||||||
var left = NormalizeSequence(self, info.LeftSequence);
|
var left = NormalizeSequence(self, info.LeftSequence);
|
||||||
if (DefaultAnimation.CurrentSequence.Name != left)
|
if (DefaultAnimation.CurrentSequence.Name != left)
|
||||||
|
|||||||
@@ -58,12 +58,14 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
{
|
{
|
||||||
public readonly TDGunboatInfo Info;
|
public readonly TDGunboatInfo Info;
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
|
static readonly WAngle Left = new WAngle(256);
|
||||||
|
static readonly WAngle Right = new WAngle(768);
|
||||||
|
|
||||||
IEnumerable<int> speedModifiers;
|
IEnumerable<int> speedModifiers;
|
||||||
INotifyVisualPositionChanged[] notifyVisualPositionChanged;
|
INotifyVisualPositionChanged[] notifyVisualPositionChanged;
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
public int Facing { get; set; }
|
public WAngle Facing { get; set; }
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
public WPos CenterPosition { get; private set; }
|
public WPos CenterPosition { get; private set; }
|
||||||
@@ -88,11 +90,11 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
if (centerPositionInit != null)
|
if (centerPositionInit != null)
|
||||||
SetPosition(self, centerPositionInit.Value);
|
SetPosition(self, centerPositionInit.Value);
|
||||||
|
|
||||||
Facing = init.GetValue<FacingInit, int>(info, Info.GetInitialFacing());
|
Facing = WAngle.FromFacing(init.GetValue<FacingInit, int>(info, Info.GetInitialFacing()));
|
||||||
|
|
||||||
// Prevent mappers from setting bogus facings
|
// Prevent mappers from setting bogus facings
|
||||||
if (Facing != 64 && Facing != 192)
|
if (Facing != Left && Facing != Right)
|
||||||
Facing = Facing > 127 ? 192 : 64;
|
Facing = Facing.Angle > 511 ? Right : Left;
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
@@ -128,10 +130,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
void Turn()
|
void Turn()
|
||||||
{
|
{
|
||||||
if (Facing == 64)
|
Facing = Facing == Left ? Right : Left;
|
||||||
Facing = 192;
|
|
||||||
else
|
|
||||||
Facing = 64;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int MovementSpeed
|
int MovementSpeed
|
||||||
@@ -141,20 +140,20 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
public Pair<CPos, SubCell>[] OccupiedCells() { return new[] { Pair.New(TopLeft, SubCell.FullCell) }; }
|
public Pair<CPos, SubCell>[] OccupiedCells() { return new[] { Pair.New(TopLeft, SubCell.FullCell) }; }
|
||||||
|
|
||||||
WVec MoveStep(int facing)
|
WVec MoveStep(WAngle facing)
|
||||||
{
|
{
|
||||||
return MoveStep(MovementSpeed, facing);
|
return MoveStep(MovementSpeed, facing);
|
||||||
}
|
}
|
||||||
|
|
||||||
WVec MoveStep(int speed, int facing)
|
WVec MoveStep(int speed, WAngle facing)
|
||||||
{
|
{
|
||||||
var dir = new WVec(0, -1024, 0).Rotate(WRot.FromFacing(facing));
|
var dir = new WVec(0, -1024, 0).Rotate(WRot.FromYaw(facing));
|
||||||
return speed * dir / 1024;
|
return speed * dir / 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDeathActorInitModifier.ModifyDeathActorInit(Actor self, TypeDictionary init)
|
void IDeathActorInitModifier.ModifyDeathActorInit(Actor self, TypeDictionary init)
|
||||||
{
|
{
|
||||||
init.Add(new FacingInit(Facing));
|
init.Add(new FacingInit(Facing.Facing));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanExistInCell(CPos cell) { return true; }
|
public bool CanExistInCell(CPos cell) { return true; }
|
||||||
@@ -225,7 +224,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits)
|
void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits)
|
||||||
{
|
{
|
||||||
if (!inits.Contains<DynamicFacingInit>() && !inits.Contains<FacingInit>())
|
if (!inits.Contains<DynamicFacingInit>() && !inits.Contains<FacingInit>())
|
||||||
inits.Add(new DynamicFacingInit(() => Facing));
|
inits.Add(new DynamicFacingInit(() => Facing.Facing));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
QueueChild(new FlyAttackRun(self, target, lastVisibleMaximumRange));
|
QueueChild(new FlyAttackRun(self, target, lastVisibleMaximumRange));
|
||||||
|
|
||||||
// Turn to face the target if required.
|
// 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);
|
aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.TurnSpeed);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
if (desiredFacing.HasValue && desiredFacing.Value != aircraft.Facing)
|
if (desiredFacing.HasValue && desiredFacing.Value != aircraft.Facing)
|
||||||
{
|
{
|
||||||
QueueChild(new Turn(self, desiredFacing.Value.Facing));
|
QueueChild(new Turn(self, desiredFacing.Value));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,9 +198,9 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return AttackStatus.NeedsToMove;
|
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;
|
attackStatus |= AttackStatus.NeedsToTurn;
|
||||||
QueueChild(new Turn(self, desiredFacing));
|
QueueChild(new Turn(self, desiredFacing));
|
||||||
return AttackStatus.NeedsToTurn;
|
return AttackStatus.NeedsToTurn;
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
var carryableFacing = carryall.Carryable.Trait<IFacing>();
|
var carryableFacing = carryall.Carryable.Trait<IFacing>();
|
||||||
var facingDelta = facing.Facing - carryableFacing.Facing;
|
var facingDelta = facing.Facing - carryableFacing.Facing;
|
||||||
foreach (var t in carryall.Carryable.TraitsImplementing<Turreted>())
|
foreach (var t in carryall.Carryable.TraitsImplementing<Turreted>())
|
||||||
t.TurretFacing += facingDelta;
|
t.TurretFacing += facingDelta.Facing;
|
||||||
|
|
||||||
carryableFacing.Facing = facing.Facing;
|
carryableFacing.Facing = facing.Facing;
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
// Turn to the required facing.
|
// Turn to the required facing.
|
||||||
if (deploy.DeployState == DeployState.Undeployed && deploy.Info.Facing != -1 && canTurn && !moving)
|
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)
|
public override bool Tick(Actor self)
|
||||||
|
|||||||
@@ -72,11 +72,11 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
// Turn to one of the harvestable facings
|
// Turn to one of the harvestable facings
|
||||||
if (harvInfo.HarvestFacings != 0)
|
if (harvInfo.HarvestFacings != 0)
|
||||||
{
|
{
|
||||||
var current = WAngle.FromFacing(facing.Facing);
|
var current = facing.Facing;
|
||||||
var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
|
var desired = body.QuantizeFacing(current, harvInfo.HarvestFacings);
|
||||||
if (desired != current)
|
if (desired != current)
|
||||||
{
|
{
|
||||||
QueueChild(new Turn(self, desired.Facing));
|
QueueChild(new Turn(self, desired));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
case DockingState.Turn:
|
case DockingState.Turn:
|
||||||
dockingState = DockingState.Dock;
|
dockingState = DockingState.Dock;
|
||||||
QueueChild(new Turn(self, DockAngle));
|
QueueChild(new Turn(self, WAngle.FromFacing(DockAngle)));
|
||||||
if (IsDragRequired)
|
if (IsDragRequired)
|
||||||
QueueChild(new Drag(self, StartDrag, EndDrag, DragLength));
|
QueueChild(new Drag(self, StartDrag, EndDrag, DragLength));
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
WPos start, end;
|
WPos start, end;
|
||||||
int length;
|
int length;
|
||||||
int ticks = 0;
|
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>();
|
positionable = self.Trait<IPositionable>();
|
||||||
disableable = self.TraitOrDefault<IMove>() as IDisabledTrait;
|
disableable = self.TraitOrDefault<IMove>() as IDisabledTrait;
|
||||||
@@ -39,8 +39,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
protected override void OnFirstRun(Actor self)
|
protected override void OnFirstRun(Actor self)
|
||||||
{
|
{
|
||||||
if (desiredFacing != -1)
|
if (desiredFacing.HasValue)
|
||||||
QueueChild(new Turn(self, desiredFacing));
|
QueueChild(new Turn(self, desiredFacing.Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Tick(Actor self)
|
public override bool Tick(Actor self)
|
||||||
|
|||||||
@@ -385,7 +385,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
protected readonly Move Move;
|
protected readonly Move Move;
|
||||||
protected readonly WPos From, To;
|
protected readonly WPos From, To;
|
||||||
protected readonly int FromFacing, ToFacing;
|
protected readonly WAngle FromFacing, ToFacing;
|
||||||
protected readonly bool EnableArc;
|
protected readonly bool EnableArc;
|
||||||
protected readonly WPos ArcCenter;
|
protected readonly WPos ArcCenter;
|
||||||
protected readonly int ArcFromLength;
|
protected readonly int ArcFromLength;
|
||||||
@@ -396,7 +396,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
protected readonly int MoveFractionTotal;
|
protected readonly int MoveFractionTotal;
|
||||||
protected int moveFraction;
|
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;
|
Move = move;
|
||||||
From = from;
|
From = from;
|
||||||
@@ -408,12 +408,12 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
IsInterruptible = false; // See comments in Move.Cancel()
|
IsInterruptible = false; // See comments in Move.Cancel()
|
||||||
|
|
||||||
// Calculate an elliptical arc that joins from and to
|
// Calculate an elliptical arc that joins from and to
|
||||||
var delta = Util.NormalizeFacing(fromFacing - toFacing);
|
var delta = (fromFacing - toFacing).Angle;
|
||||||
if (delta != 0 && delta != 128)
|
if (delta != 0 && delta != 512)
|
||||||
{
|
{
|
||||||
// The center of rotation is where the normal vectors cross
|
// The center of rotation is where the normal vectors cross
|
||||||
var u = new WVec(1024, 0, 0).Rotate(WRot.FromFacing(fromFacing));
|
var u = new WVec(1024, 0, 0).Rotate(WRot.FromYaw(fromFacing));
|
||||||
var v = new WVec(1024, 0, 0).Rotate(WRot.FromFacing(toFacing));
|
var v = new WVec(1024, 0, 0).Rotate(WRot.FromYaw(toFacing));
|
||||||
var w = from - to;
|
var w = from - to;
|
||||||
var s = (v.Y * w.X - v.X * w.Y) * 1024 / (v.X * u.Y - v.Y * u.X);
|
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;
|
var x = from.X + s * u.X / 1024;
|
||||||
@@ -476,9 +476,9 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
mobile.SetVisualPosition(self, To);
|
mobile.SetVisualPosition(self, To);
|
||||||
|
|
||||||
if (moveFraction >= MoveFractionTotal)
|
if (moveFraction >= MoveFractionTotal)
|
||||||
mobile.Facing = ToFacing & 0xFF;
|
mobile.Facing = ToFacing;
|
||||||
else
|
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);
|
protected abstract MovePart OnComplete(Actor self, Mobile mobile, Move parent);
|
||||||
@@ -491,7 +491,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
class MoveFirstHalf : MovePart
|
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) { }
|
: base(move, from, to, fromFacing, toFacing, startingFraction) { }
|
||||||
|
|
||||||
static bool IsTurn(Mobile mobile, CPos nextCell, Map map)
|
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.
|
// Tight U-turns should be done in place instead of making silly looking loops.
|
||||||
var nextFacing = map.FacingBetween(nextCell, mobile.ToCell, mobile.Facing);
|
var nextFacing = map.FacingBetween(nextCell, mobile.ToCell, mobile.Facing);
|
||||||
var currentFacing = map.FacingBetween(mobile.ToCell, mobile.FromCell, mobile.Facing);
|
var currentFacing = map.FacingBetween(mobile.ToCell, mobile.FromCell, mobile.Facing);
|
||||||
var delta = Util.NormalizeFacing(nextFacing - currentFacing);
|
var delta = (nextFacing - currentFacing).Angle;
|
||||||
return delta != 0 && (delta < 96 || delta > 160);
|
return delta != 0 && (delta < 384 || delta > 640);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override MovePart OnComplete(Actor self, Mobile mobile, Move parent)
|
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.FromCell, mobile.ToCell) + (fromSubcellOffset + toSubcellOffset) / 2,
|
||||||
Util.BetweenCells(self.World, mobile.ToCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
|
Util.BetweenCells(self.World, mobile.ToCell, nextCell.Value.First) + (toSubcellOffset + nextSubcellOffset) / 2,
|
||||||
mobile.Facing,
|
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);
|
moveFraction - MoveFractionTotal);
|
||||||
|
|
||||||
mobile.FinishedMoving(self);
|
mobile.FinishedMoving(self);
|
||||||
@@ -550,7 +550,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
class MoveSecondHalf : MovePart
|
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) { }
|
: 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)
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
// Turn if required
|
// Turn if required
|
||||||
var delta = targetPos - currentPos;
|
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)
|
if (facing != mobile.Facing)
|
||||||
{
|
{
|
||||||
mobile.Facing = Util.TickFacing(mobile.Facing, facing, mobile.TurnSpeed);
|
mobile.Facing = Util.TickFacing(mobile.Facing, facing, mobile.TurnSpeed);
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
ChildActivity.Cancel(self);
|
ChildActivity.Cancel(self);
|
||||||
|
|
||||||
var localOffset = carryall.OffsetForCarryable(self, cargo).Rotate(carryableBody.QuantizeOrientation(self, cargo.Orientation));
|
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
|
// Pause briefly before attachment for visual effect
|
||||||
if (delay > 0)
|
if (delay > 0)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
public readonly string ToActor;
|
public readonly string ToActor;
|
||||||
public CVec Offset = CVec.Zero;
|
public CVec Offset = CVec.Zero;
|
||||||
public int Facing = 96;
|
public WAngle Facing = WAngle.FromFacing(96);
|
||||||
public string[] Sounds = { };
|
public string[] Sounds = { };
|
||||||
public string Notification = null;
|
public string Notification = null;
|
||||||
public int ForceHealthPercentage = 0;
|
public int ForceHealthPercentage = 0;
|
||||||
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
new LocationInit(self.Location + Offset),
|
new LocationInit(self.Location + Offset),
|
||||||
new OwnerInit(self.Owner),
|
new OwnerInit(self.Owner),
|
||||||
new FacingInit(Facing),
|
new FacingInit(Facing.Facing),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (SkipMakeAnims)
|
if (SkipMakeAnims)
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
{
|
{
|
||||||
readonly Mobile mobile;
|
readonly Mobile mobile;
|
||||||
readonly IFacing facing;
|
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>();
|
mobile = self.TraitOrDefault<Mobile>();
|
||||||
facing = self.Trait<IFacing>();
|
facing = self.Trait<IFacing>();
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (entryLocation.HasValue && nextLocation.HasValue)
|
if (entryLocation.HasValue && nextLocation.HasValue)
|
||||||
initDict.Add(new FacingInit(Context.World.Map.FacingBetween(CPos.Zero, CPos.Zero + (nextLocation.Value - entryLocation.Value), 0)));
|
initDict.Add(new FacingInit(Context.World.Map.FacingBetween(CPos.Zero, CPos.Zero + (nextLocation.Value - entryLocation.Value), WAngle.Zero).Facing));
|
||||||
|
|
||||||
var actor = Context.World.CreateActor(addToWorld, actorType, initDict);
|
var actor = Context.World.CreateActor(addToWorld, actorType, initDict);
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
if (facing == null)
|
if (facing == null)
|
||||||
throw new LuaException("Actor '{0}' doesn't define a facing".F(Self));
|
throw new LuaException("Actor '{0}' doesn't define a facing".F(Self));
|
||||||
|
|
||||||
return facing.Facing;
|
return facing.Facing.Facing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -209,13 +209,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
IOverrideAircraftLanding overrideAircraftLanding;
|
IOverrideAircraftLanding overrideAircraftLanding;
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
public WAngle Facing;
|
public WAngle Facing { get; set; }
|
||||||
|
|
||||||
int IFacing.Facing
|
|
||||||
{
|
|
||||||
get { return Facing.Facing; }
|
|
||||||
set { Facing = WAngle.FromFacing(value); }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
public WPos CenterPosition { get; private set; }
|
public WPos CenterPosition { get; private set; }
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!base.CanAttack(self, target))
|
if (!base.CanAttack(self, target))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return TargetInFiringArc(self, target, base.Info.FacingTolerance);
|
return TargetInFiringArc(self, target, 4 * base.Info.FacingTolerance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
inAttackRange = false;
|
inAttackRange = false;
|
||||||
|
|
||||||
facingTarget = TargetInFiringArc(self, target, info.FacingTolerance);
|
facingTarget = TargetInFiringArc(self, target, 4 * info.FacingTolerance);
|
||||||
|
|
||||||
foreach (var a in Armaments)
|
foreach (var a in Armaments)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (delta.HorizontalLengthSquared == 0)
|
if (delta.HorizontalLengthSquared == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return Util.FacingWithinTolerance(facing.Facing, delta.Yaw.Facing, facingTolerance);
|
return Util.FacingWithinTolerance(facing.Facing, delta.Yaw, facingTolerance);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual bool CanAttack(Actor self, Target target)
|
protected virtual bool CanAttack(Actor self, Target target)
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var armaments = ChooseArmamentsForTarget(target, forceAttack);
|
var armaments = ChooseArmamentsForTarget(target, forceAttack);
|
||||||
foreach (var a in armaments)
|
foreach (var a in armaments)
|
||||||
if (target.IsInRange(pos, a.MaxRange()) && (a.Weapon.MinRange == WDist.Zero || !target.IsInRange(pos, a.Weapon.MinRange)))
|
if (target.IsInRange(pos, a.MaxRange()) && (a.Weapon.MinRange == WDist.Zero || !target.IsInRange(pos, a.Weapon.MinRange)))
|
||||||
if (TargetInFiringArc(self, target, Info.FacingTolerance))
|
if (TargetInFiringArc(self, target, 4 * Info.FacingTolerance))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!base.CanAttack(self, target))
|
if (!base.CanAttack(self, target))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return TargetInFiringArc(self, target, Info.FacingTolerance);
|
return TargetInFiringArc(self, target, 4 * Info.FacingTolerance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
|
public override Activity GetAttackActivity(Actor self, AttackSource source, Target newTarget, bool allowMove, bool forceAttack, Color? targetLineColor = null)
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
FirePort SelectFirePort(Actor self, WAngle targetYaw)
|
FirePort SelectFirePort(Actor self, WAngle targetYaw)
|
||||||
{
|
{
|
||||||
// Pick a random port that faces the target
|
// Pick a random port that faces the target
|
||||||
var bodyYaw = facing != null ? WAngle.FromFacing(facing.Facing) : WAngle.Zero;
|
var bodyYaw = facing != null ? facing.Facing : WAngle.Zero;
|
||||||
var indices = Enumerable.Range(0, Info.Ports.Length).Shuffle(self.World.SharedRandom);
|
var indices = Enumerable.Range(0, Info.Ports.Length).Shuffle(self.World.SharedRandom);
|
||||||
foreach (var i in indices)
|
foreach (var i in indices)
|
||||||
{
|
{
|
||||||
@@ -161,8 +161,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (port == null)
|
if (port == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var muzzleFacing = targetYaw.Facing;
|
paxFacing[a.Actor].Facing = targetYaw;
|
||||||
paxFacing[a.Actor].Facing = muzzleFacing;
|
|
||||||
paxPos[a.Actor].SetVisualPosition(a.Actor, pos + PortOffset(self, port));
|
paxPos[a.Actor].SetVisualPosition(a.Actor, pos + PortOffset(self, port));
|
||||||
|
|
||||||
var barrel = a.CheckFire(a.Actor, facing, target);
|
var barrel = a.CheckFire(a.Actor, facing, target);
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!armaments.Any())
|
if (!armaments.Any())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!allowTurn && !ab.TargetInFiringArc(self, target, ab.Info.FacingTolerance))
|
if (!allowTurn && !ab.TargetInFiringArc(self, target, 4 * ab.Info.FacingTolerance))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Evaluate whether we want to target this actor
|
// Evaluate whether we want to target this actor
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
var spawn = self.World.Map.CenterOfCell(location);
|
var spawn = self.World.Map.CenterOfCell(location);
|
||||||
|
|
||||||
var initialFacing = self.World.Map.FacingBetween(location, self.Location, 0);
|
var initialFacing = self.World.Map.FacingBetween(location, self.Location, WAngle.Zero);
|
||||||
|
|
||||||
// If aircraft, spawn at cruise altitude
|
// If aircraft, spawn at cruise altitude
|
||||||
var aircraftInfo = self.World.Map.Rules.Actors[deliveringActorName.ToLowerInvariant()].TraitInfoOrDefault<AircraftInfo>();
|
var aircraftInfo = self.World.Map.Rules.Actors[deliveringActorName.ToLowerInvariant()].TraitInfoOrDefault<AircraftInfo>();
|
||||||
@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
new LocationInit(location),
|
new LocationInit(location),
|
||||||
new CenterPositionInit(spawn),
|
new CenterPositionInit(spawn),
|
||||||
new OwnerInit(self.Owner),
|
new OwnerInit(self.Owner),
|
||||||
new FacingInit(initialFacing)
|
new FacingInit(initialFacing.Facing)
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create delivered actor
|
// Create delivered actor
|
||||||
|
|||||||
@@ -370,10 +370,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
var passengerFacing = passenger.TraitOrDefault<IFacing>();
|
var passengerFacing = passenger.TraitOrDefault<IFacing>();
|
||||||
if (passengerFacing != null)
|
if (passengerFacing != null)
|
||||||
passengerFacing.Facing = facing.Value.Facing + Info.PassengerFacing;
|
passengerFacing.Facing = facing.Value.Facing + WAngle.FromFacing(Info.PassengerFacing);
|
||||||
|
|
||||||
foreach (var t in passenger.TraitsImplementing<Turreted>())
|
foreach (var t in passenger.TraitsImplementing<Turreted>())
|
||||||
t.TurretFacing = facing.Value.Facing + Info.PassengerFacing;
|
t.TurretFacing = facing.Value.Facing.Facing + Info.PassengerFacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Load(Actor self, Actor a)
|
public void Load(Actor self, Actor a)
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public Actor Carryable { get; private set; }
|
public Actor Carryable { get; private set; }
|
||||||
public CarryallState State { get; private set; }
|
public CarryallState State { get; private set; }
|
||||||
|
|
||||||
int cachedFacing;
|
WAngle cachedFacing;
|
||||||
IActorPreview[] carryablePreview;
|
IActorPreview[] carryablePreview;
|
||||||
HashSet<string> landableTerrainTypes;
|
HashSet<string> landableTerrainTypes;
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var carryableInits = new TypeDictionary()
|
var carryableInits = new TypeDictionary()
|
||||||
{
|
{
|
||||||
new OwnerInit(Carryable.Owner),
|
new OwnerInit(Carryable.Owner),
|
||||||
new DynamicFacingInit(() => facing.Facing),
|
new DynamicFacingInit(() => facing.Facing.Facing),
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var api in Carryable.TraitsImplementing<IActorPreviewInitModifier>())
|
foreach (var api in Carryable.TraitsImplementing<IActorPreviewInitModifier>())
|
||||||
|
|||||||
@@ -126,19 +126,19 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
break;
|
break;
|
||||||
case DeployState.Deploying:
|
case DeployState.Deploying:
|
||||||
if (canTurn)
|
if (canTurn)
|
||||||
self.Trait<IFacing>().Facing = Info.Facing;
|
self.Trait<IFacing>().Facing = WAngle.FromFacing(Info.Facing);
|
||||||
|
|
||||||
Deploy(true);
|
Deploy(true);
|
||||||
break;
|
break;
|
||||||
case DeployState.Deployed:
|
case DeployState.Deployed:
|
||||||
if (canTurn)
|
if (canTurn)
|
||||||
self.Trait<IFacing>().Facing = Info.Facing;
|
self.Trait<IFacing>().Facing = WAngle.FromFacing(Info.Facing);
|
||||||
|
|
||||||
OnDeployCompleted();
|
OnDeployCompleted();
|
||||||
break;
|
break;
|
||||||
case DeployState.Undeploying:
|
case DeployState.Undeploying:
|
||||||
if (canTurn)
|
if (canTurn)
|
||||||
self.Trait<IFacing>().Facing = Info.Facing;
|
self.Trait<IFacing>().Facing = WAngle.FromFacing(Info.Facing);
|
||||||
|
|
||||||
Undeploy(true);
|
Undeploy(true);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public WPos CenterPosition { get; private set; }
|
public WPos CenterPosition { get; private set; }
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
public int Facing { get; set; }
|
public WAngle Facing { get; set; }
|
||||||
|
|
||||||
public int TurnSpeed { get { return 0; } }
|
public int TurnSpeed { get { return 0; } }
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
TopLeft = init.GetValue<LocationInit, CPos>(info);
|
TopLeft = init.GetValue<LocationInit, CPos>(info);
|
||||||
CenterPosition = init.GetValue<CenterPositionInit, WPos>(info, init.World.Map.CenterOfCell(TopLeft));
|
CenterPosition = init.GetValue<CenterPositionInit, WPos>(info, init.World.Map.CenterOfCell(TopLeft));
|
||||||
Facing = init.GetValue<FacingInit, int>(info, 128);
|
Facing = WAngle.FromFacing(init.GetValue<FacingInit, int>(info, 128));
|
||||||
|
|
||||||
dragSpeed = init.GetValue<HuskSpeedInit, int>(info, 0);
|
dragSpeed = init.GetValue<HuskSpeedInit, int>(info, 0);
|
||||||
finalPosition = init.World.Map.CenterOfCell(TopLeft);
|
finalPosition = init.World.Map.CenterOfCell(TopLeft);
|
||||||
@@ -163,7 +163,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void IDeathActorInitModifier.ModifyDeathActorInit(Actor self, TypeDictionary init)
|
void IDeathActorInitModifier.ModifyDeathActorInit(Actor self, TypeDictionary init)
|
||||||
{
|
{
|
||||||
init.Add(new FacingInit(Facing));
|
init.Add(new FacingInit(Facing.Facing));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We return self.Owner if there's no effective owner
|
// We return self.Owner if there's no effective owner
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
int oldFacing, facing;
|
WAngle oldFacing, facing;
|
||||||
WPos oldPos;
|
WPos oldPos;
|
||||||
CPos fromCell, toCell;
|
CPos fromCell, toCell;
|
||||||
public SubCell FromSubCell, ToSubCell;
|
public SubCell FromSubCell, ToSubCell;
|
||||||
@@ -216,13 +216,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
#region IFacing
|
#region IFacing
|
||||||
[Sync]
|
[Sync]
|
||||||
public int Facing
|
public WAngle Facing
|
||||||
{
|
{
|
||||||
get { return facing; }
|
get { return facing; }
|
||||||
set { facing = value; }
|
set { facing = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public int TurnSpeed { get { return Info.TurnSpeed; } }
|
public int TurnSpeed { get { return 4 * Info.TurnSpeed; } }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
@@ -281,7 +281,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
SetVisualPosition(self, init.World.Map.CenterOfSubCell(FromCell, FromSubCell));
|
SetVisualPosition(self, init.World.Map.CenterOfSubCell(FromCell, FromSubCell));
|
||||||
}
|
}
|
||||||
|
|
||||||
Facing = oldFacing = init.GetValue<FacingInit, int>(info, info.InitialFacing);
|
Facing = oldFacing = WAngle.FromFacing(init.GetValue<FacingInit, int>(info, info.InitialFacing));
|
||||||
|
|
||||||
// Sets the initial visual position
|
// Sets the initial visual position
|
||||||
// Unit will move into the cell grid (defined by LocationInit) as its initial activity
|
// Unit will move into the cell grid (defined by LocationInit) as its initial activity
|
||||||
@@ -828,7 +828,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var length = speed > 0 ? (toPos - fromPos).Length / speed : 0;
|
var length = speed > 0 ? (toPos - fromPos).Length / speed : 0;
|
||||||
|
|
||||||
var delta = toPos - fromPos;
|
var delta = toPos - fromPos;
|
||||||
var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : Facing;
|
var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw : Facing;
|
||||||
|
|
||||||
return new Drag(self, fromPos, toPos, length, facing);
|
return new Drag(self, fromPos, toPos, length, facing);
|
||||||
}
|
}
|
||||||
@@ -857,12 +857,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits)
|
void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits)
|
||||||
{
|
{
|
||||||
if (!inits.Contains<DynamicFacingInit>() && !inits.Contains<FacingInit>())
|
if (!inits.Contains<DynamicFacingInit>() && !inits.Contains<FacingInit>())
|
||||||
inits.Add(new DynamicFacingInit(() => facing));
|
inits.Add(new DynamicFacingInit(() => facing.Facing));
|
||||||
}
|
}
|
||||||
|
|
||||||
void IDeathActorInitModifier.ModifyDeathActorInit(Actor self, TypeDictionary init)
|
void IDeathActorInitModifier.ModifyDeathActorInit(Actor self, TypeDictionary init)
|
||||||
{
|
{
|
||||||
init.Add(new FacingInit(facing));
|
init.Add(new FacingInit(facing.Facing));
|
||||||
|
|
||||||
// Allows the husk to drag to its final position
|
// Allows the husk to drag to its final position
|
||||||
if (CanEnterCell(self.Location, self, BlockedByActor.Stationary))
|
if (CanEnterCell(self.Location, self, BlockedByActor.Stationary))
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (aircraftInfo != null)
|
if (aircraftInfo != null)
|
||||||
pos += new WVec(0, 0, aircraftInfo.CruiseAltitude.Length);
|
pos += new WVec(0, 0, aircraftInfo.CruiseAltitude.Length);
|
||||||
|
|
||||||
var initialFacing = self.World.Map.FacingBetween(location.Value, destinations[0], 0);
|
var initialFacing = self.World.Map.FacingBetween(location.Value, destinations[0], WAngle.Zero);
|
||||||
|
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
td.Add(new LocationInit(location.Value));
|
td.Add(new LocationInit(location.Value));
|
||||||
td.Add(new CenterPositionInit(pos));
|
td.Add(new CenterPositionInit(pos));
|
||||||
td.Add(new FacingInit(initialFacing));
|
td.Add(new FacingInit(initialFacing.Facing));
|
||||||
|
|
||||||
var newUnit = self.World.CreateActor(producee.Name, td);
|
var newUnit = self.World.CreateActor(producee.Name, td);
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
{
|
{
|
||||||
BodyOrientation body;
|
BodyOrientation body;
|
||||||
IFacing facing;
|
IFacing facing;
|
||||||
int cachedFacing;
|
WAngle cachedFacing;
|
||||||
int cachedInterval;
|
int cachedInterval;
|
||||||
|
|
||||||
public LeavesTrails(Actor self, LeavesTrailsInfo info)
|
public LeavesTrails(Actor self, LeavesTrailsInfo info)
|
||||||
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
{
|
{
|
||||||
body = self.Trait<BodyOrientation>();
|
body = self.Trait<BodyOrientation>();
|
||||||
facing = self.TraitOrDefault<IFacing>();
|
facing = self.TraitOrDefault<IFacing>();
|
||||||
cachedFacing = facing != null ? facing.Facing : 0;
|
cachedFacing = facing != null ? facing.Facing : WAngle.Zero;
|
||||||
cachedPosition = self.CenterPosition;
|
cachedPosition = self.CenterPosition;
|
||||||
|
|
||||||
base.Created(self);
|
base.Created(self);
|
||||||
@@ -125,14 +125,14 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
var pos = Info.Type == TrailType.CenterPosition ? spawnPosition + body.LocalToWorld(offsetRotation) :
|
var pos = Info.Type == TrailType.CenterPosition ? spawnPosition + body.LocalToWorld(offsetRotation) :
|
||||||
self.World.Map.CenterOfCell(spawnCell);
|
self.World.Map.CenterOfCell(spawnCell);
|
||||||
|
|
||||||
var spawnFacing = Info.SpawnAtLastPosition ? cachedFacing : (facing != null ? facing.Facing : 0);
|
var spawnFacing = Info.SpawnAtLastPosition ? cachedFacing : (facing != null ? facing.Facing : WAngle.Zero);
|
||||||
|
|
||||||
if ((Info.TerrainTypes.Count == 0 || Info.TerrainTypes.Contains(type)) && !string.IsNullOrEmpty(Info.Image))
|
if ((Info.TerrainTypes.Count == 0 || Info.TerrainTypes.Contains(type)) && !string.IsNullOrEmpty(Info.Image))
|
||||||
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, self.World, Info.Image,
|
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, spawnFacing, self.World, Info.Image,
|
||||||
Info.Sequences.Random(Game.CosmeticRandom), Info.Palette, Info.VisibleThroughFog, spawnFacing)));
|
Info.Sequences.Random(Game.CosmeticRandom), Info.Palette, Info.VisibleThroughFog)));
|
||||||
|
|
||||||
cachedPosition = self.CenterPosition;
|
cachedPosition = self.CenterPosition;
|
||||||
cachedFacing = facing != null ? facing.Facing : 0;
|
cachedFacing = facing != null ? facing.Facing : WAngle.Zero;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
|
|
||||||
cachedInterval = isMoving ? Info.MovingInterval : Info.StationaryInterval;
|
cachedInterval = isMoving ? Info.MovingInterval : Info.StationaryInterval;
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
if (facing == null)
|
if (facing == null)
|
||||||
return () => WAngle.Zero;
|
return () => WAngle.Zero;
|
||||||
|
|
||||||
return () => WAngle.FromFacing(facing.Facing);
|
return () => facing.Facing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RenderSprites(ActorInitializer init, RenderSpritesInfo info)
|
public RenderSprites(ActorInitializer init, RenderSpritesInfo info)
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
if (turreted != null)
|
if (turreted != null)
|
||||||
getFacing = () => WAngle.FromFacing(turreted.TurretFacing);
|
getFacing = () => WAngle.FromFacing(turreted.TurretFacing);
|
||||||
else if (facing != null)
|
else if (facing != null)
|
||||||
getFacing = () => WAngle.FromFacing(facing.Facing);
|
getFacing = () => facing.Facing;
|
||||||
else
|
else
|
||||||
getFacing = () => WAngle.Zero;
|
getFacing = () => WAngle.Zero;
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return new Transform(self, Info.IntoActor)
|
return new Transform(self, Info.IntoActor)
|
||||||
{
|
{
|
||||||
Offset = Info.Offset,
|
Offset = Info.Offset,
|
||||||
Facing = Info.Facing,
|
Facing = WAngle.FromFacing(Info.Facing),
|
||||||
Sounds = Info.TransformSounds,
|
Sounds = Info.TransformSounds,
|
||||||
Notification = Info.TransformNotification,
|
Notification = Info.TransformNotification,
|
||||||
Faction = faction
|
Faction = faction
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
class TurnOnIdle : ConditionalTrait<TurnOnIdleInfo>, INotifyIdle
|
class TurnOnIdle : ConditionalTrait<TurnOnIdleInfo>, INotifyIdle
|
||||||
{
|
{
|
||||||
int currentDelay;
|
int currentDelay;
|
||||||
int targetFacing;
|
WAngle targetFacing;
|
||||||
readonly Mobile mobile;
|
readonly Mobile mobile;
|
||||||
|
|
||||||
public TurnOnIdle(ActorInitializer init, TurnOnIdleInfo info)
|
public TurnOnIdle(ActorInitializer init, TurnOnIdleInfo info)
|
||||||
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
if (targetFacing == mobile.Facing)
|
if (targetFacing == mobile.Facing)
|
||||||
{
|
{
|
||||||
targetFacing = self.World.SharedRandom.Next(256);
|
targetFacing = new WAngle(self.World.SharedRandom.Next(1024));
|
||||||
currentDelay = self.World.SharedRandom.Next(Info.MinDelay, Info.MaxDelay);
|
currentDelay = self.World.SharedRandom.Next(Info.MinDelay, Info.MaxDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
void MoveTurret()
|
void MoveTurret()
|
||||||
{
|
{
|
||||||
var df = DesiredFacing ?? (facing != null ? facing.Facing : TurretFacing);
|
var df = DesiredFacing ?? (facing != null ? facing.Facing.Facing : TurretFacing);
|
||||||
TurretFacing = Util.TickFacing(TurretFacing, df, Info.TurnSpeed);
|
TurretFacing = Util.TickFacing(TurretFacing, df, Info.TurnSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,7 +249,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
inits.Add(facings);
|
inits.Add(facings);
|
||||||
}
|
}
|
||||||
|
|
||||||
Func<int> bodyFacing = () => facing.Facing;
|
Func<int> bodyFacing = () => facing.Facing.Facing;
|
||||||
var dynamicFacing = inits.GetOrDefault<DynamicFacingInit>();
|
var dynamicFacing = inits.GetOrDefault<DynamicFacingInit>();
|
||||||
var staticFacing = inits.GetOrDefault<FacingInit>();
|
var staticFacing = inits.GetOrDefault<FacingInit>();
|
||||||
if (dynamicFacing != null)
|
if (dynamicFacing != null)
|
||||||
|
|||||||
@@ -35,17 +35,6 @@ namespace OpenRA.Mods.Common
|
|||||||
return (facing - rot) & 0xFF;
|
return (facing - rot) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetNearestFacing(int facing, int desiredFacing)
|
|
||||||
{
|
|
||||||
var turn = desiredFacing - facing;
|
|
||||||
if (turn > 128)
|
|
||||||
turn -= 256;
|
|
||||||
if (turn < -128)
|
|
||||||
turn += 256;
|
|
||||||
|
|
||||||
return facing + turn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds step angle units to facing in the direction that takes it closer to desiredFacing.
|
/// Adds step angle units to facing in the direction that takes it closer to desiredFacing.
|
||||||
/// If facing is already within step of desiredFacing then desiredFacing is returned.
|
/// If facing is already within step of desiredFacing then desiredFacing is returned.
|
||||||
@@ -97,13 +86,13 @@ namespace OpenRA.Mods.Common
|
|||||||
return negative == 0 ? 0 : 256 - negative;
|
return negative == 0 ? 0 : 256 - negative;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool FacingWithinTolerance(int facing, int desiredFacing, int facingTolerance)
|
public static bool FacingWithinTolerance(WAngle facing, WAngle desiredFacing, int facingTolerance)
|
||||||
{
|
{
|
||||||
if (facingTolerance == 0 && facing == desiredFacing)
|
if (facingTolerance == 0 && facing == desiredFacing)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
var delta = Util.NormalizeFacing(desiredFacing - facing);
|
var delta = (desiredFacing - facing).Angle;
|
||||||
return delta <= facingTolerance || delta >= 256 - facingTolerance;
|
return delta <= facingTolerance || delta >= 1024 - facingTolerance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WPos BetweenCells(World w, CPos from, CPos to)
|
public static WPos BetweenCells(World w, CPos from, CPos to)
|
||||||
|
|||||||
Reference in New Issue
Block a user