Convert yaml-exposed facings to WAngle.

This commit is contained in:
Paul Chote
2020-07-09 22:08:38 +01:00
committed by reaperrr
parent 6d12301f88
commit ac975f4139
80 changed files with 477 additions and 370 deletions

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Activities
this.info = info;
IsInterruptible = false;
aircraft = self.Trait<Aircraft>();
if (info.MaximumSpinSpeed != 0)
if (!info.MaximumSpinSpeed.HasValue || info.MaximumSpinSpeed.Value != WAngle.Zero)
acceleration = self.World.SharedRandom.Next(2) * 2 - 1;
}
@@ -49,14 +49,13 @@ namespace OpenRA.Mods.Common.Activities
return true;
}
if (info.MaximumSpinSpeed != 0)
if (acceleration != 0)
{
if (info.MaximumSpinSpeed < 0 || Math.Abs(spin) < info.MaximumSpinSpeed)
spin += acceleration; // TODO: Possibly unhardcode this
if (!info.MaximumSpinSpeed.HasValue || Math.Abs(spin) < info.MaximumSpinSpeed.Value.Angle)
spin += 4 * acceleration; // TODO: Possibly unhardcode this
// Allow for negative spin values and convert from facing to angle units
// TODO: Remember to convert this when removing WAngle.FromFacing
aircraft.Facing = new WAngle(aircraft.Facing.Angle + 4 * spin);
aircraft.Facing = new WAngle(aircraft.Facing.Angle + spin);
}
var move = info.Moves ? aircraft.FlyStep(aircraft.Facing) : WVec.Zero;

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Activities
// NOTE: desiredFacing = -1 means we should not prefer any particular facing and instead just
// use whatever facing gives us the most direct path to the landing site.
if (!facing.HasValue && aircraft.Info.TurnToLand)
desiredFacing = WAngle.FromFacing(aircraft.Info.InitialFacing);
desiredFacing = aircraft.Info.InitialFacing;
else
desiredFacing = facing;
}

View File

@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Activities
var exit = dest.FirstExitOrDefault();
var offset = exit != null ? exit.Info.SpawnOffset : WVec.Zero;
if (aircraft.Info.TurnToDock || !aircraft.Info.VTOL)
facing = WAngle.FromFacing(aircraft.Info.InitialFacing);
facing = aircraft.Info.InitialFacing;
aircraft.MakeReservation(dest);
QueueChild(new Land(self, Target.FromActor(dest), offset, facing, Color.Green));

View File

@@ -31,8 +31,8 @@ namespace OpenRA.Mods.Common.Activities
protected override void OnFirstRun(Actor self)
{
// Turn to the required facing.
if (deploy.DeployState == DeployState.Undeployed && deploy.Info.Facing != -1 && canTurn && !moving)
QueueChild(new Turn(self, WAngle.FromFacing(deploy.Info.Facing)));
if (deploy.DeployState == DeployState.Undeployed && deploy.Info.Facing.HasValue && canTurn && !moving)
QueueChild(new Turn(self, deploy.Info.Facing.Value));
}
public override bool Tick(Actor self)

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Activities
protected readonly Actor Refinery;
protected readonly Harvester Harv;
protected readonly int DockAngle;
protected readonly WAngle DockAngle;
protected readonly bool IsDragRequired;
protected readonly WVec DragOffset;
protected readonly int DragLength;
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Activities
protected DockingState dockingState;
public HarvesterDockSequence(Actor self, Actor refinery, int dockAngle, bool isDragRequired, WVec dragOffset, int dragLength)
public HarvesterDockSequence(Actor self, Actor refinery, WAngle dockAngle, bool isDragRequired, WVec dragOffset, int dragLength)
{
dockingState = DockingState.Turn;
Refinery = refinery;
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Activities
case DockingState.Turn:
dockingState = DockingState.Dock;
QueueChild(new Turn(self, WAngle.FromFacing(DockAngle)));
QueueChild(new Turn(self, DockAngle));
if (IsDragRequired)
QueueChild(new Drag(self, StartDrag, EndDrag, DragLength));
return false;

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Activities
readonly WithSpriteBody wsb;
readonly WithDockingAnimationInfo wda;
public SpriteHarvesterDockSequence(Actor self, Actor refinery, int dockAngle, bool isDragRequired, WVec dragOffset, int dragLength)
public SpriteHarvesterDockSequence(Actor self, Actor refinery, WAngle dockAngle, bool isDragRequired, WVec dragOffset, int dragLength)
: base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength)
{
wsb = self.Trait<WithSpriteBody>();

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Activities
{
public readonly string ToActor;
public CVec Offset = CVec.Zero;
public WAngle Facing = WAngle.FromFacing(96);
public WAngle Facing = new WAngle(384);
public string[] Sounds = { };
public string Notification = null;
public int ForceHealthPercentage = 0;

View File

@@ -84,10 +84,10 @@ namespace OpenRA.Mods.Common.Projectiles
public readonly int LockOnProbability = 100;
[Desc("Horizontal rate of turn.")]
public readonly int HorizontalRateOfTurn = 5;
public readonly WAngle HorizontalRateOfTurn = new WAngle(20);
[Desc("Vertical rate of turn.")]
public readonly int VerticalRateOfTurn = 6;
public readonly WAngle VerticalRateOfTurn = new WAngle(24);
[Desc("Gravity applied while in free fall.")]
public readonly int Gravity = 10;
@@ -288,7 +288,7 @@ namespace OpenRA.Mods.Common.Projectiles
// to hit the target without passing it by (and thus having to do horizontal loops)
var minSpeed = ((System.Math.Min(predClfDist * 1024 / (1024 - WAngle.FromFacing(vFacing).Sin()),
(relTarHorDist + predClfDist) * 1024 / (2 * (2048 - WAngle.FromFacing(vFacing).Sin())))
* info.VerticalRateOfTurn * 157) / 6400).Clamp(minLaunchSpeed, maxLaunchSpeed);
* info.VerticalRateOfTurn.Facing * 157) / 6400).Clamp(minLaunchSpeed, maxLaunchSpeed);
if ((sbyte)vFacing < 0)
speed = minSpeed;
@@ -300,7 +300,7 @@ namespace OpenRA.Mods.Common.Projectiles
var vFac = vFacing;
speed = BisectionSearch(minSpeed, maxLaunchSpeed, spd =>
{
var lpRds = LoopRadius(spd, info.VerticalRateOfTurn);
var lpRds = LoopRadius(spd, info.VerticalRateOfTurn.Facing);
return WillClimbWithinDistance(vFac, lpRds, predClfDist, diffClfMslHgt)
|| WillClimbAroundInclineTop(vFac, lpRds, predClfDist, diffClfMslHgt, spd);
});
@@ -320,7 +320,7 @@ namespace OpenRA.Mods.Common.Projectiles
void DetermineLaunchSpeedAndAngle(World world, out int speed, out int vFacing)
{
speed = maxLaunchSpeed;
loopRadius = LoopRadius(speed, info.VerticalRateOfTurn);
loopRadius = LoopRadius(speed, info.VerticalRateOfTurn.Facing);
// Compute current distance from target position
var tarDistVec = targetPosition + offset - pos;
@@ -440,7 +440,7 @@ namespace OpenRA.Mods.Common.Projectiles
speed = (speed + sign * info.Acceleration.Length).Clamp(0, maxSpeed);
// Compute the vertical loop radius
loopRadius = LoopRadius(speed, info.VerticalRateOfTurn);
loopRadius = LoopRadius(speed, info.VerticalRateOfTurn.Facing);
}
WVec FreefallTick()
@@ -509,7 +509,7 @@ namespace OpenRA.Mods.Common.Projectiles
// If missile is below incline top height and facing downwards, bring back
// its vertical facing above zero as soon as possible
if ((sbyte)vFacing < 0)
desiredVFacing = info.VerticalRateOfTurn;
desiredVFacing = info.VerticalRateOfTurn.Facing;
// Missile will climb around incline top if bringing vertical facing
// down to zero on an arc of radius loopRadius
@@ -525,7 +525,7 @@ namespace OpenRA.Mods.Common.Projectiles
// for which the missile will be able to climb terrAltDiff w-units
// within hHeightChange w-units all the while ending the ascent
// with vertical facing 0
for (var vFac = System.Math.Min(vFacing + info.VerticalRateOfTurn - 1, 63); vFac >= vFacing; vFac--)
for (var vFac = System.Math.Min(vFacing + info.VerticalRateOfTurn.Facing - 1, 63); vFac >= vFacing; vFac--)
if (!WillClimbWithinDistance(vFac, loopRadius, predClfDist, diffClfMslHgt)
&& !(predClfDist <= loopRadius * (1024 - WAngle.FromFacing(vFac).Sin()) / 1024
&& WillClimbAroundInclineTop(vFac, loopRadius, predClfDist, diffClfMslHgt, speed)))
@@ -600,7 +600,7 @@ namespace OpenRA.Mods.Common.Projectiles
// and thus needs smaller vertical facings so as not
// to hit the ground prematurely
if (targetPassedBy)
desiredVFacing = desiredVFacing.Clamp(-info.VerticalRateOfTurn, info.VerticalRateOfTurn);
desiredVFacing = desiredVFacing.Clamp(-info.VerticalRateOfTurn.Facing, info.VerticalRateOfTurn.Facing);
else if (lastHt == 0)
{ // Before the target is passed by, missile speed should be changed
// Target's height above loop's center
@@ -662,7 +662,7 @@ namespace OpenRA.Mods.Common.Projectiles
if (info.TerrainHeightAware && edgeVector.Length > loopRadius && lastHt > targetPosition.Z)
{
int vFac;
for (vFac = vFacing + 1; vFac <= vFacing + info.VerticalRateOfTurn - 1; vFac++)
for (vFac = vFacing + 1; vFac <= vFacing + info.VerticalRateOfTurn.Facing - 1; vFac++)
{
// Vector from missile's current position pointing to the loop's center
radius = new WVec(loopRadius, 0, 0)
@@ -681,7 +681,7 @@ namespace OpenRA.Mods.Common.Projectiles
// Aim for the target
var vDist = new WVec(-relTarHgt, -relTarHorDist, 0);
desiredVFacing = (sbyte)vDist.HorizontalLengthSquared != 0 ? vDist.Yaw.Facing : vFacing;
if (desiredVFacing < 0 && info.VerticalRateOfTurn < (sbyte)vFacing)
if (desiredVFacing < 0 && info.VerticalRateOfTurn.Facing < (sbyte)vFacing)
desiredVFacing = 0;
}
}
@@ -691,7 +691,7 @@ namespace OpenRA.Mods.Common.Projectiles
// Aim for the target
var vDist = new WVec(-relTarHgt, relTarHorDist, 0);
desiredVFacing = (sbyte)vDist.HorizontalLengthSquared != 0 ? vDist.Yaw.Facing : vFacing;
if (desiredVFacing < 0 && info.VerticalRateOfTurn < (sbyte)vFacing)
if (desiredVFacing < 0 && info.VerticalRateOfTurn.Facing < (sbyte)vFacing)
desiredVFacing = 0;
}
}
@@ -706,7 +706,7 @@ namespace OpenRA.Mods.Common.Projectiles
if (-diffClfMslHgt > info.CruiseAltitude.Length)
desiredVFacing = -desiredVFacing;
desiredVFacing = desiredVFacing.Clamp(-info.VerticalRateOfTurn, info.VerticalRateOfTurn);
desiredVFacing = desiredVFacing.Clamp(-info.VerticalRateOfTurn.Facing, info.VerticalRateOfTurn.Facing);
ChangeSpeed();
}
@@ -722,7 +722,7 @@ namespace OpenRA.Mods.Common.Projectiles
if (-diffClfMslHgt > info.CruiseAltitude.Length)
desiredVFacing = -desiredVFacing;
desiredVFacing = desiredVFacing.Clamp(-info.VerticalRateOfTurn, info.VerticalRateOfTurn);
desiredVFacing = desiredVFacing.Clamp(-info.VerticalRateOfTurn.Facing, info.VerticalRateOfTurn.Facing);
ChangeSpeed();
}
@@ -780,8 +780,8 @@ namespace OpenRA.Mods.Common.Projectiles
desiredHFacing = hFacing;
// Compute new direction the projectile will be facing
hFacing = Util.TickFacing(hFacing, desiredHFacing, info.HorizontalRateOfTurn);
vFacing = Util.TickFacing(vFacing, desiredVFacing, info.VerticalRateOfTurn);
hFacing = Util.TickFacing(hFacing, desiredHFacing, info.HorizontalRateOfTurn.Facing);
vFacing = Util.TickFacing(vFacing, desiredVFacing, info.VerticalRateOfTurn.Facing);
// Compute the projectile's guided displacement
return new WVec(0, -1024 * speed, 0)
@@ -803,7 +803,7 @@ namespace OpenRA.Mods.Common.Projectiles
speed = velocity.Length;
// Compute the vertical loop radius
loopRadius = LoopRadius(speed, info.VerticalRateOfTurn);
loopRadius = LoopRadius(speed, info.VerticalRateOfTurn.Facing);
}
// Switch from homing mode to freefall mode

View File

@@ -157,7 +157,7 @@ namespace OpenRA.Mods.Common.Scripting
// Scripted cargo aircraft must turn to default position before unloading.
// TODO: pass facing through UnloadCargo instead.
if (aircraft != null)
transport.QueueActivity(new Land(transport, Target.FromCell(transport.World, entryPath.Last()), WDist.FromCells(dropRange), WAngle.FromFacing(aircraft.Info.InitialFacing)));
transport.QueueActivity(new Land(transport, Target.FromCell(transport.World, entryPath.Last()), WDist.FromCells(dropRange), aircraft.Info.InitialFacing));
if (cargo != null)
transport.QueueActivity(new UnloadCargo(transport, WDist.FromCells(dropRange)));

View File

@@ -47,12 +47,13 @@ namespace OpenRA.Mods.Common.Traits
[Desc("The speed at which the aircraft is repulsed from other aircraft. Specify -1 for normal movement speed.")]
public readonly int RepulsionSpeed = -1;
public readonly int InitialFacing = 0;
public readonly WAngle InitialFacing = WAngle.Zero;
public readonly int TurnSpeed = 255;
[Desc("Speed at which the actor turns.")]
public readonly WAngle TurnSpeed = new WAngle(512);
[Desc("Turn speed to apply when aircraft flies in circles while idle. Defaults to TurnSpeed if negative.")]
public readonly int IdleTurnSpeed = -1;
[Desc("Turn speed to apply when aircraft flies in circles while idle. Defaults to TurnSpeed if undefined.")]
public readonly WAngle? IdleTurnSpeed = null;
public readonly int Speed = 1;
@@ -145,7 +146,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int NumberOfTicksToVerifyAvailableAirport = 150;
[Desc("Facing to use for actor previews (map editor, color picker, etc)")]
public readonly int PreviewFacing = 96;
public readonly WAngle PreviewFacing = new WAngle(384);
[Desc("Display order for the facing slider in the map editor")]
public readonly int EditorFacingDisplayOrder = 3;
@@ -160,14 +161,14 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Cursor to display when unable to land at target building.")]
public readonly string EnterBlockedCursor = "enter-blocked";
public WAngle GetInitialFacing() { return WAngle.FromFacing(InitialFacing); }
public WAngle GetInitialFacing() { return InitialFacing; }
public WDist GetCruiseAltitude() { return CruiseAltitude; }
public override object Create(ActorInitializer init) { return new Aircraft(init, this); }
IEnumerable<ActorInit> IActorPreviewInitInfo.ActorPreviewInits(ActorInfo ai, ActorPreviewType type)
{
yield return new FacingInit(WAngle.FromFacing(PreviewFacing));
yield return new FacingInit(PreviewFacing);
}
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return new ReadOnlyDictionary<CPos, SubCell>(); }
@@ -200,7 +201,7 @@ namespace OpenRA.Mods.Common.Traits
actor =>
{
var init = actor.GetInitOrDefault<FacingInit>(this);
return (init != null ? init.Value : WAngle.FromFacing(InitialFacing)).Angle;
return (init != null ? init.Value : InitialFacing).Angle;
},
(actor, value) => actor.ReplaceInit(new FacingInit(new WAngle((int)value))));
}
@@ -250,8 +251,8 @@ namespace OpenRA.Mods.Common.Traits
public WPos CenterPosition { get; private set; }
public CPos TopLeft { get { return self.World.Map.CellContaining(CenterPosition); } }
public WAngle TurnSpeed { get { return !IsTraitDisabled && !IsTraitPaused ? new WAngle(4 * Info.TurnSpeed) : WAngle.Zero; } }
public WAngle? IdleTurnSpeed { get { return Info.IdleTurnSpeed != -1 ? new WAngle(4 * Info.IdleTurnSpeed) : (WAngle?)null; } }
public WAngle TurnSpeed { get { return !IsTraitDisabled && !IsTraitPaused ? Info.TurnSpeed : WAngle.Zero; } }
public WAngle? IdleTurnSpeed { get { return Info.IdleTurnSpeed; } }
public Actor ReservedActor { get; private set; }
public bool MayYieldReservation { get; private set; }
@@ -292,7 +293,7 @@ namespace OpenRA.Mods.Common.Traits
if (centerPositionInit != null)
SetPosition(self, centerPositionInit.Value);
Facing = init.GetValue<FacingInit, WAngle>(WAngle.FromFacing(Info.InitialFacing));
Facing = init.GetValue<FacingInit, WAngle>(Info.InitialFacing);
creationActivityDelay = init.GetValue<CreationActivityDelayInit, int>(0);
}

View File

@@ -22,9 +22,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Explosion weapon that triggers when hitting ground.")]
public readonly string Explosion = "UnitExplode";
[Desc("Limit the maximum spin (in facing units per tick) that can be achieved while crashing.",
"0 disables spinning. Negative values imply no limit.")]
public readonly int MaximumSpinSpeed = -1;
[Desc("Limit the maximum spin (in angle units per tick) that can be achieved while crashing.",
"0 disables spinning. Leave undefined for no limit.")]
public readonly WAngle? MaximumSpinSpeed = null;
[Desc("Does the aircraft (husk) move forward at aircraft speed?")]
public readonly bool Moves = false;

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Cell offset where the exiting actor enters the ActorMap relative to the topleft cell of the producing actor.")]
public readonly CVec ExitCell = CVec.Zero;
public readonly int Facing = -1;
public readonly WAngle? Facing = null;
[Desc("Type tags on this exit.")]
public readonly HashSet<string> ProductionTypes = new HashSet<string>();

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly CVec SpawnOffset = CVec.Zero;
[Desc("Which direction the unit should face.")]
public readonly int Facing = 0;
public readonly WAngle Facing = WAngle.Zero;
[Desc("Whether another actor should spawn upon re-enabling the trait.")]
public readonly bool AllowRespawn = false;
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits
new ParentActorInit(self),
new LocationInit(self.Location + Info.SpawnOffset),
new OwnerInit(self.Owner),
new FacingInit(WAngle.FromFacing(Info.Facing)),
new FacingInit(Info.Facing),
});
});
}

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly bool BaselineSpawn = false;
[Desc("Direction the aircraft should face to land.")]
public readonly int Facing = 64;
public readonly WAngle Facing = new WAngle(256);
public override object Create(ActorInitializer init) { return new ProductionAirdrop(init, this); }
}
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Traits
var loc = self.Location.ToMPos(map);
startPos = new MPos(loc.U + map.Bounds.Width, loc.V).ToCPos(map);
endPos = new MPos(map.Bounds.Left, loc.V).ToCPos(map);
spawnFacing = WAngle.FromFacing(info.Facing);
spawnFacing = info.Facing;
}
// Assume a single exit point for simplicity
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Traits
});
var exitCell = self.Location + exit.ExitCell;
actor.QueueActivity(new Land(actor, Target.FromActor(self), WDist.Zero, WVec.Zero, WAngle.FromFacing(info.Facing), clearCells: new CPos[1] { exitCell }));
actor.QueueActivity(new Land(actor, Target.FromActor(self), WDist.Zero, WVec.Zero, info.Facing, clearCells: new CPos[1] { exitCell }));
actor.QueueActivity(new CallFunc(() =>
{
if (!self.IsInWorld || self.IsDead)

View File

@@ -23,8 +23,8 @@ namespace OpenRA.Mods.Common.Traits
{
public class RefineryInfo : TraitInfo, Requires<WithSpriteBodyInfo>, IAcceptResourcesInfo
{
[Desc("Actual harvester facing when docking, 0-255 counter-clock-wise.")]
public readonly int DockAngle = 0;
[Desc("Actual harvester facing when docking.")]
public readonly WAngle DockAngle = WAngle.Zero;
[Desc("Docking cell relative to top-left cell.")]
public readonly CVec DockOffset = CVec.Zero;
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits
public bool AllowDocking { get { return !preventDock; } }
public CVec DeliveryOffset { get { return info.DockOffset; } }
public int DeliveryAngle { get { return info.DockAngle; } }
public WAngle DeliveryAngle { get { return info.DockAngle; } }
public bool IsDragRequired { get { return info.IsDragRequired; } }
public WVec DragOffset { get { return info.DragOffset; } }
public int DragLength { get { return info.DragLength; } }

View File

@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly WDist LoadRange = WDist.FromCells(5);
[Desc("Which direction the passenger will face (relative to the transport) when unloading.")]
public readonly int PassengerFacing = 128;
public readonly WAngle PassengerFacing = new WAngle(512);
[Desc("Delay (in ticks) before continuing after loading a passenger.")]
public readonly int AfterLoadDelay = 8;
@@ -370,10 +370,10 @@ namespace OpenRA.Mods.Common.Traits
var passengerFacing = passenger.TraitOrDefault<IFacing>();
if (passengerFacing != null)
passengerFacing.Facing = facing.Value.Facing + WAngle.FromFacing(Info.PassengerFacing);
passengerFacing.Facing = facing.Value.Facing + Info.PassengerFacing;
foreach (var t in passenger.TraitsImplementing<Turreted>())
t.TurretFacing = facing.Value.Facing.Facing + Info.PassengerFacing;
t.TurretFacing = (facing.Value.Facing + Info.PassengerFacing).Facing;
}
public void Load(Actor self, Actor a)

View File

@@ -43,8 +43,8 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Cursor to display when unable to (un)deploy the actor.")]
public readonly string DeployBlockedCursor = "deploy-blocked";
[Desc("Facing that the actor must face before deploying. Set to -1 to deploy regardless of facing.")]
public readonly int Facing = -1;
[Desc("Facing that the actor must face before deploying. Leave undefined to deploy regardless of facing.")]
public readonly WAngle? Facing = null;
[Desc("Play a randomly selected sound from this list when deploying.")]
public readonly string[] DeploySounds = null;
@@ -94,8 +94,6 @@ namespace OpenRA.Mods.Common.Traits
{
readonly Actor self;
readonly bool checkTerrainType;
readonly bool canTurn;
readonly IMove move;
DeployState deployState;
INotifyDeployTriggered[] notify;
@@ -109,8 +107,6 @@ namespace OpenRA.Mods.Common.Traits
{
self = init.Self;
checkTerrainType = info.AllowedTerrainTypes.Count > 0;
canTurn = self.Info.HasTraitInfo<IFacingInfo>();
move = self.TraitOrDefault<IMove>();
deployState = init.GetValue<DeployStateInit, DeployState>(DeployState.Undeployed);
}
@@ -119,27 +115,25 @@ namespace OpenRA.Mods.Common.Traits
notify = self.TraitsImplementing<INotifyDeployTriggered>().ToArray();
base.Created(self);
if (Info.Facing.HasValue && deployState != DeployState.Undeployed)
{
var facing = self.TraitOrDefault<IFacing>();
if (facing != null)
facing.Facing = Info.Facing.Value;
}
switch (deployState)
{
case DeployState.Undeployed:
OnUndeployCompleted();
break;
case DeployState.Deploying:
if (canTurn)
self.Trait<IFacing>().Facing = WAngle.FromFacing(Info.Facing);
Deploy(true);
break;
case DeployState.Deployed:
if (canTurn)
self.Trait<IFacing>().Facing = WAngle.FromFacing(Info.Facing);
OnDeployCompleted();
break;
case DeployState.Undeploying:
if (canTurn)
self.Trait<IFacing>().Facing = WAngle.FromFacing(Info.Facing);
Undeploy(true);
break;
}

View File

@@ -23,16 +23,16 @@ namespace OpenRA.Mods.Common.Traits
public readonly HashSet<string> AllowedTerrain = new HashSet<string>();
[Desc("Facing to use for actor previews (map editor, color picker, etc)")]
public readonly int PreviewFacing = 96;
public readonly WAngle PreviewFacing = new WAngle(384);
IEnumerable<ActorInit> IActorPreviewInitInfo.ActorPreviewInits(ActorInfo ai, ActorPreviewType type)
{
yield return new FacingInit(WAngle.FromFacing(PreviewFacing));
yield return new FacingInit(PreviewFacing);
}
public override object Create(ActorInitializer init) { return new Husk(init, this); }
public WAngle GetInitialFacing() { return WAngle.FromFacing(128); }
public WAngle GetInitialFacing() { return new WAngle(512); }
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
{

View File

@@ -30,10 +30,10 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Which Locomotor does this trait use. Must be defined on the World actor.")]
public readonly string Locomotor = null;
public readonly int InitialFacing = 0;
public readonly WAngle InitialFacing = WAngle.Zero;
[Desc("Speed at which the actor turns.")]
public readonly int TurnSpeed = 255;
public readonly WAngle TurnSpeed = new WAngle(512);
public readonly int Speed = 1;
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly string Voice = "Action";
[Desc("Facing to use for actor previews (map editor, color picker, etc)")]
public readonly int PreviewFacing = 96;
public readonly WAngle PreviewFacing = new WAngle(384);
[Desc("Display order for the facing slider in the map editor")]
public readonly int EditorFacingDisplayOrder = 3;
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
IEnumerable<ActorInit> IActorPreviewInitInfo.ActorPreviewInits(ActorInfo ai, ActorPreviewType type)
{
yield return new FacingInit(WAngle.FromFacing(PreviewFacing));
yield return new FacingInit(PreviewFacing);
}
public override object Create(ActorInitializer init) { return new Mobile(init, this); }
@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Traits
base.RulesetLoaded(rules, ai);
}
public WAngle GetInitialFacing() { return WAngle.FromFacing(InitialFacing); }
public WAngle GetInitialFacing() { return InitialFacing; }
// initialized and used by CanEnterCell
Locomotor locomotor;
@@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.Traits
actor =>
{
var init = actor.GetInitOrDefault<FacingInit>(this);
return (init != null ? init.Value : WAngle.FromFacing(InitialFacing)).Angle;
return (init != null ? init.Value : InitialFacing).Angle;
},
(actor, value) => actor.ReplaceInit(new FacingInit(new WAngle((int)value))));
}
@@ -206,7 +206,7 @@ namespace OpenRA.Mods.Common.Traits
public WRot Orientation { get { return orientation; } }
public WAngle TurnSpeed { get { return new WAngle(4 * Info.TurnSpeed); } }
public WAngle TurnSpeed { get { return Info.TurnSpeed; } }
#endregion
[Sync]
@@ -265,7 +265,7 @@ namespace OpenRA.Mods.Common.Traits
SetVisualPosition(self, init.World.Map.CenterOfSubCell(FromCell, FromSubCell));
}
Facing = oldFacing = init.GetValue<FacingInit, WAngle>(WAngle.FromFacing(info.InitialFacing));
Facing = oldFacing = init.GetValue<FacingInit, WAngle>(info.InitialFacing);
// Sets the initial visual position
// Unit will move into the cell grid (defined by LocationInit) as its initial activity

View File

@@ -56,8 +56,8 @@ namespace OpenRA.Mods.Common.Traits
var spawn = self.CenterPosition + exitinfo.SpawnOffset;
var to = self.World.Map.CenterOfCell(exit);
var initialFacing = WAngle.FromFacing(exitinfo.Facing);
if (exitinfo.Facing < 0)
WAngle initialFacing;
if (!exitinfo.Facing.HasValue)
{
var delta = to - spawn;
if (delta.HorizontalLengthSquared == 0)
@@ -68,6 +68,8 @@ namespace OpenRA.Mods.Common.Traits
else
initialFacing = delta.Yaw;
}
else
initialFacing = exitinfo.Facing.Value;
exitLocations = rp.Value != null && rp.Value.Path.Count > 0 ? rp.Value.Path : new List<CPos> { exit };

View File

@@ -124,7 +124,7 @@ namespace OpenRA.Mods.Common.Traits
var spawn = self.World.Map.CenterOfCell(exit) + new WVec(WDist.Zero, WDist.Zero, altitude);
var to = self.World.Map.CenterOfCell(exit);
var initialFacing = exitinfo == null || exitinfo.Facing < 0 ? (to - spawn).Yaw : WAngle.FromFacing(exitinfo.Facing);
var initialFacing = (exitinfo != null && exitinfo.Facing.HasValue) ? exitinfo.Facing.Value : (to - spawn).Yaw;
exitLocations = rp.Value != null && rp.Value.Path.Count > 0 ? rp.Value.Path : new List<CPos> { exit };

View File

@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Traits
{
var aircraft = new List<Actor>();
if (!facing.HasValue)
facing = WAngle.FromFacing(256 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings);
facing = new WAngle(1024 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings);
var altitude = self.World.Map.Rules.Actors[info.UnitType].TraitInfo<AircraftInfo>().CruiseAltitude.Length;
var attackRotation = WRot.FromYaw(facing.Value);

View File

@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Traits
var info = Info as ParatroopersPowerInfo;
if (!facing.HasValue)
facing = WAngle.FromFacing(256 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings);
facing = new WAngle(1024 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings);
var utLower = info.UnitType.ToLowerInvariant();
ActorInfo unitType;

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly int Velocity = 75;
[Desc("Speed at which the particle turns.")]
public readonly int TurnSpeed = 15;
public readonly WAngle TurnSpeed = new WAngle(60);
public override object Create(ActorInitializer init) { return new ThrowsParticle(init, this); }
}
@@ -80,9 +80,9 @@ namespace OpenRA.Mods.Common.Traits
length = (finalPos - initialPos).Length / info.Velocity;
// WAngle requires positive inputs, so track the speed and direction separately
var rotationSpeed = WDist.FromPDF(Game.CosmeticRandom, 2).Length * info.TurnSpeed / 1024;
var rotationSpeed = WDist.FromPDF(Game.CosmeticRandom, 2).Length * info.TurnSpeed.Angle / 1024;
direction = rotationSpeed < 0 ? -1 : 1;
rotation = WAngle.FromFacing(Math.Abs(rotationSpeed));
rotation = new WAngle(Math.Abs(rotationSpeed));
var anim = new Animation(init.World, rs.GetImage(self), () => facing);
anim.PlayRepeating(info.Anim);

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
public readonly CVec Offset = CVec.Zero;
[Desc("Facing that the actor must face before transforming.")]
public readonly int Facing = 96;
public readonly WAngle Facing = new WAngle(384);
[Desc("Sounds to play when transforming.")]
public readonly string[] TransformSounds = { };
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
return new Transform(self, Info.IntoActor)
{
Offset = Info.Offset,
Facing = WAngle.FromFacing(Info.Facing),
Facing = Info.Facing,
Sounds = Info.TransformSounds,
Notification = Info.TransformNotification,
Faction = faction

View File

@@ -20,9 +20,11 @@ namespace OpenRA.Mods.Common.Traits
public class TurretedInfo : PausableConditionalTraitInfo, Requires<BodyOrientationInfo>, IActorPreviewInitInfo, IEditorActorOptions
{
public readonly string Turret = "primary";
[Desc("Speed at which the turret turns.")]
public readonly int TurnSpeed = 255;
public readonly int InitialFacing = 0;
public readonly WAngle TurnSpeed = new WAngle(512);
public readonly WAngle InitialFacing = WAngle.Zero;
[Desc("Number of ticks before turret is realigned. (-1 turns off realignment)")]
public readonly int RealignDelay = 40;
@@ -35,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
IEnumerable<ActorInit> IActorPreviewInitInfo.ActorPreviewInits(ActorInfo ai, ActorPreviewType type)
{
yield return new TurretFacingInit(this, WAngle.FromFacing(InitialFacing));
yield return new TurretFacingInit(this, InitialFacing);
}
IEnumerable<EditorActorOption> IEditorActorOptions.ActorOptions(ActorInfo ai, World world)
@@ -47,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
if (init != null)
return init.Value.Angle;
return WAngle.FromFacing(InitialFacing).Angle;
return InitialFacing.Angle;
},
(actor, value) => actor.ReplaceInit(new TurretFacingInit(this, new WAngle((int)value)), this));
}
@@ -78,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
public static Func<WAngle> TurretFacingFromInit(IActorInitializer init, TurretedInfo info)
{
return TurretFacingFromInit(init, info, WAngle.FromFacing(info.InitialFacing));
return TurretFacingFromInit(init, info, info.InitialFacing);
}
public static Func<WAngle> TurretFacingFromInit(IActorInitializer init, TraitInfo info, WAngle defaultFacing)
@@ -155,7 +157,7 @@ namespace OpenRA.Mods.Common.Traits
void MoveTurret()
{
var df = DesiredFacing ?? (facing != null ? facing.Facing.Facing : TurretFacing);
TurretFacing = Util.TickFacing(TurretFacing, df, Info.TurnSpeed);
TurretFacing = Util.TickFacing(TurretFacing, df, Info.TurnSpeed.Facing);
}
public bool FaceTarget(Actor self, Target target)

View File

@@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Traits
if (info.DeliveryAircraft != null)
{
var crate = w.CreateActor(false, crateActor, new TypeDictionary { new OwnerInit(w.WorldActor.Owner) });
var dropFacing = WAngle.FromFacing(256 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings);
var dropFacing = new WAngle(1024 * self.World.SharedRandom.Next(info.QuantizedFacings) / info.QuantizedFacings);
var delta = new WVec(0, -1024, 0).Rotate(WRot.FromYaw(dropFacing));
var altitude = self.World.Map.Rules.Actors[info.DeliveryAircraft].TraitInfo<AircraftInfo>().CruiseAltitude.Length;

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Required for the map editor to work. Attach this to the world actor.")]
public class EditorCursorLayerInfo : TraitInfo, Requires<EditorActorLayerInfo>
{
public readonly int PreviewFacing = 96;
public readonly WAngle PreviewFacing = new WAngle(384);
public override object Create(ActorInitializer init) { return new EditorCursorLayer(init.Self, this); }
}
@@ -194,7 +194,7 @@ namespace OpenRA.Mods.Common.Traits
}
if (actor.HasTraitInfo<IFacingInfo>())
reference.Add(new FacingInit(WAngle.FromFacing(info.PreviewFacing)));
reference.Add(new FacingInit(info.PreviewFacing));
Type = EditorCursorType.Actor;
Actor = new EditorActorPreview(wr, null, reference, owner);

View File

@@ -43,11 +43,11 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Outer radius for spawning support actors")]
public readonly int OuterSupportRadius = 4;
[Desc("Initial facing of BaseActor. -1 means random.")]
public readonly int BaseActorFacing = 128;
[Desc("Initial facing of BaseActor. Leave undefined for random facings.")]
public readonly WAngle? BaseActorFacing = new WAngle(512);
[Desc("Initial facing of SupportActors. -1 means random.")]
public readonly int SupportActorsFacing = -1;
[Desc("Initial facing of SupportActors. Leave undefined for random facings.")]
public readonly WAngle? SupportActorsFacing = null;
}
public class MPStartUnits { }

View File

@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits
if (unitGroup.BaseActor != null)
{
var facing = unitGroup.BaseActorFacing < 0 ? new WAngle(w.SharedRandom.Next(1024)) : WAngle.FromFacing(unitGroup.BaseActorFacing);
var facing = unitGroup.BaseActorFacing.HasValue ? unitGroup.BaseActorFacing.Value : new WAngle(w.SharedRandom.Next(1024));
w.CreateActor(unitGroup.BaseActor.ToLowerInvariant(), new TypeDictionary
{
new LocationInit(sp + unitGroup.BaseActorOffset),
@@ -113,7 +113,7 @@ namespace OpenRA.Mods.Common.Traits
}
var subCell = ip.SharesCell ? w.ActorMap.FreeSubCell(validCell) : 0;
var facing = unitGroup.SupportActorsFacing < 0 ? new WAngle(w.SharedRandom.Next(1024)) : WAngle.FromFacing(unitGroup.SupportActorsFacing);
var facing = unitGroup.SupportActorsFacing.HasValue ? unitGroup.SupportActorsFacing.Value : new WAngle(w.SharedRandom.Next(1024));
w.CreateActor(s.ToLowerInvariant(), new TypeDictionary
{

View File

@@ -0,0 +1,105 @@
#region Copyright & License Information
/*
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
class ReplaceFacingAngles : UpdateRule
{
static readonly Dictionary<string, string[]> TraitFields = new Dictionary<string, string[]>()
{
{ "Aircraft", new[] { "InitialFacing", "PreviewFacing", "TurnSpeed", "IdleTurnSpeed" } },
{ "Mobile", new[] { "InitialFacing", "PreviewFacing", "TurnSpeed" } },
{ "Husk", new[] { "PreviewFacing" } },
{ "Turreted", new[] { "InitialFacing", "TurnSpeed" } },
{ "GrantConditionOnDeploy", new[] { "Facing" } },
{ "FreeActor", new[] { "Facing" } },
{ "ProductionAirdrop", new[] { "Facing" } },
{ "EditorCursorLayer", new[] { "PreviewFacing" } },
{ "MPStartUnits", new[] { "BaseActorFacing", "SupportActorsFacing" } },
{ "Refinery", new[] { "DockAngle" } },
{ "Cargo", new[] { "PassengerFacing" } },
{ "Exit", new[] { "Facing" } },
{ "ThrowsParticle", new[] { "TurnSpeed" } },
{ "Transforms", new[] { "Facing" } },
{ "FallsToEarth", new[] { "MaximumSpinSpeed" } },
{ "ConyardChronoReturn", new[] { "Facing" } },
{ "TDGunboat", new[] { "InitialFacing", "PreviewFacing" } },
{ "AttackPopupTurreted", new[] { "DefaultFacing" } },
{ "DropPodsPower", new[] { "PodFacing" } },
{ "TiberianSunRefinery", new[] { "DockAngle" } },
};
static readonly Dictionary<string, string[]> ProjectileFields = new Dictionary<string, string[]>()
{
{ "Missile", new[] { "HorizontalRateOfTurn", "VerticalRateOfTurn" } }
};
public override string Name { get { return "Increase facing angle resolution"; } }
public override string Description
{
get
{
return "Trait fields that defined facings (0-255) have been replaced with higher resolution angles (0-1023).\n" +
"Values for the following trait fields should be multiplied by 4, or if undefined (-1) replaced by an empty definition:\n" +
UpdateUtils.FormatMessageList(TraitFields.Select(t => t.Key + "\n" + UpdateUtils.FormatMessageList(t.Value))) + "\n" +
"Values for the following projectile files should be multiplied by 4:\n" +
UpdateUtils.FormatMessageList(ProjectileFields.Select(t => t.Key + "\n" + UpdateUtils.FormatMessageList(t.Value)));
}
}
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
{
foreach (var kv in TraitFields)
{
foreach (var traitNode in actorNode.ChildrenMatching(kv.Key))
{
foreach (var fieldName in kv.Value)
{
foreach (var fieldNode in traitNode.ChildrenMatching(fieldName))
{
var value = fieldNode.NodeValue<int>();
fieldNode.Value.Value = value != -1 ? FieldSaver.FormatValue(value != 255 ? 4 * value : 1023) : "";
}
}
}
}
yield break;
}
public override IEnumerable<string> UpdateWeaponNode(ModData modData, MiniYamlNode weaponNode)
{
foreach (var projectileNode in weaponNode.ChildrenMatching("Projectile"))
{
if (projectileNode.Value.Value == null)
continue;
string[] fieldNames;
if (ProjectileFields.TryGetValue(projectileNode.Value.Value, out fieldNames))
{
foreach (var fieldName in fieldNames)
{
foreach (var fieldNode in projectileNode.ChildrenMatching(fieldName))
{
var value = fieldNode.NodeValue<int>();
fieldNode.Value.Value = FieldSaver.FormatValue(value != 255 ? 4 * value : 1023);
}
}
}
}
yield break;
}
}
}

View File

@@ -69,6 +69,7 @@ namespace OpenRA.Mods.Common.UpdateRules
new UpdateMapInits(),
new CreateFlashPaletteEffectWarhead(),
new ChangeTargetLineDelayToMilliseconds(),
new ReplaceFacingAngles(),
})
};