Convert IFacing.Facing and TurnSpeed to WAngle.
This commit is contained in:
@@ -209,13 +209,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
IOverrideAircraftLanding overrideAircraftLanding;
|
||||
|
||||
[Sync]
|
||||
public WAngle Facing;
|
||||
|
||||
int IFacing.Facing
|
||||
{
|
||||
get { return Facing.Facing; }
|
||||
set { Facing = WAngle.FromFacing(value); }
|
||||
}
|
||||
public WAngle Facing { get; set; }
|
||||
|
||||
[Sync]
|
||||
public WPos CenterPosition { get; private set; }
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!base.CanAttack(self, target))
|
||||
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;
|
||||
|
||||
facingTarget = TargetInFiringArc(self, target, info.FacingTolerance);
|
||||
facingTarget = TargetInFiringArc(self, target, 4 * info.FacingTolerance);
|
||||
|
||||
foreach (var a in Armaments)
|
||||
{
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (delta.HorizontalLengthSquared == 0)
|
||||
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)
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var armaments = ChooseArmamentsForTarget(target, forceAttack);
|
||||
foreach (var a in armaments)
|
||||
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 false;
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!base.CanAttack(self, target))
|
||||
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)
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
FirePort SelectFirePort(Actor self, WAngle targetYaw)
|
||||
{
|
||||
// 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);
|
||||
foreach (var i in indices)
|
||||
{
|
||||
@@ -161,8 +161,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (port == null)
|
||||
return;
|
||||
|
||||
var muzzleFacing = targetYaw.Facing;
|
||||
paxFacing[a.Actor].Facing = muzzleFacing;
|
||||
paxFacing[a.Actor].Facing = targetYaw;
|
||||
paxPos[a.Actor].SetVisualPosition(a.Actor, pos + PortOffset(self, port));
|
||||
|
||||
var barrel = a.CheckFire(a.Actor, facing, target);
|
||||
|
||||
@@ -415,7 +415,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!armaments.Any())
|
||||
continue;
|
||||
|
||||
if (!allowTurn && !ab.TargetInFiringArc(self, target, ab.Info.FacingTolerance))
|
||||
if (!allowTurn && !ab.TargetInFiringArc(self, target, 4 * ab.Info.FacingTolerance))
|
||||
continue;
|
||||
|
||||
// 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 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
|
||||
var aircraftInfo = self.World.Map.Rules.Actors[deliveringActorName.ToLowerInvariant()].TraitInfoOrDefault<AircraftInfo>();
|
||||
@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
new LocationInit(location),
|
||||
new CenterPositionInit(spawn),
|
||||
new OwnerInit(self.Owner),
|
||||
new FacingInit(initialFacing)
|
||||
new FacingInit(initialFacing.Facing)
|
||||
});
|
||||
|
||||
// Create delivered actor
|
||||
|
||||
@@ -370,10 +370,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var passengerFacing = passenger.TraitOrDefault<IFacing>();
|
||||
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>())
|
||||
t.TurretFacing = facing.Value.Facing + Info.PassengerFacing;
|
||||
t.TurretFacing = facing.Value.Facing.Facing + Info.PassengerFacing;
|
||||
}
|
||||
|
||||
public void Load(Actor self, Actor a)
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public Actor Carryable { get; private set; }
|
||||
public CarryallState State { get; private set; }
|
||||
|
||||
int cachedFacing;
|
||||
WAngle cachedFacing;
|
||||
IActorPreview[] carryablePreview;
|
||||
HashSet<string> landableTerrainTypes;
|
||||
|
||||
@@ -225,7 +225,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var carryableInits = new TypeDictionary()
|
||||
{
|
||||
new OwnerInit(Carryable.Owner),
|
||||
new DynamicFacingInit(() => facing.Facing),
|
||||
new DynamicFacingInit(() => facing.Facing.Facing),
|
||||
};
|
||||
|
||||
foreach (var api in Carryable.TraitsImplementing<IActorPreviewInitModifier>())
|
||||
|
||||
@@ -126,19 +126,19 @@ namespace OpenRA.Mods.Common.Traits
|
||||
break;
|
||||
case DeployState.Deploying:
|
||||
if (canTurn)
|
||||
self.Trait<IFacing>().Facing = Info.Facing;
|
||||
self.Trait<IFacing>().Facing = WAngle.FromFacing(Info.Facing);
|
||||
|
||||
Deploy(true);
|
||||
break;
|
||||
case DeployState.Deployed:
|
||||
if (canTurn)
|
||||
self.Trait<IFacing>().Facing = Info.Facing;
|
||||
self.Trait<IFacing>().Facing = WAngle.FromFacing(Info.Facing);
|
||||
|
||||
OnDeployCompleted();
|
||||
break;
|
||||
case DeployState.Undeploying:
|
||||
if (canTurn)
|
||||
self.Trait<IFacing>().Facing = Info.Facing;
|
||||
self.Trait<IFacing>().Facing = WAngle.FromFacing(Info.Facing);
|
||||
|
||||
Undeploy(true);
|
||||
break;
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public WPos CenterPosition { get; private set; }
|
||||
|
||||
[Sync]
|
||||
public int Facing { get; set; }
|
||||
public WAngle Facing { get; set; }
|
||||
|
||||
public int TurnSpeed { get { return 0; } }
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
TopLeft = init.GetValue<LocationInit, CPos>(info);
|
||||
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);
|
||||
finalPosition = init.World.Map.CenterOfCell(TopLeft);
|
||||
@@ -163,7 +163,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
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
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
#endregion
|
||||
|
||||
int oldFacing, facing;
|
||||
WAngle oldFacing, facing;
|
||||
WPos oldPos;
|
||||
CPos fromCell, toCell;
|
||||
public SubCell FromSubCell, ToSubCell;
|
||||
@@ -216,13 +216,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
#region IFacing
|
||||
[Sync]
|
||||
public int Facing
|
||||
public WAngle Facing
|
||||
{
|
||||
get { return facing; }
|
||||
set { facing = value; }
|
||||
}
|
||||
|
||||
public int TurnSpeed { get { return Info.TurnSpeed; } }
|
||||
public int TurnSpeed { get { return 4 * Info.TurnSpeed; } }
|
||||
#endregion
|
||||
|
||||
[Sync]
|
||||
@@ -281,7 +281,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
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
|
||||
// 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 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);
|
||||
}
|
||||
@@ -857,12 +857,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits)
|
||||
{
|
||||
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)
|
||||
{
|
||||
init.Add(new FacingInit(facing));
|
||||
init.Add(new FacingInit(facing.Facing));
|
||||
|
||||
// Allows the husk to drag to its final position
|
||||
if (CanEnterCell(self.Location, self, BlockedByActor.Stationary))
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (aircraftInfo != null)
|
||||
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 =>
|
||||
{
|
||||
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
td.Add(new LocationInit(location.Value));
|
||||
td.Add(new CenterPositionInit(pos));
|
||||
td.Add(new FacingInit(initialFacing));
|
||||
td.Add(new FacingInit(initialFacing.Facing));
|
||||
|
||||
var newUnit = self.World.CreateActor(producee.Name, td);
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
{
|
||||
BodyOrientation body;
|
||||
IFacing facing;
|
||||
int cachedFacing;
|
||||
WAngle cachedFacing;
|
||||
int cachedInterval;
|
||||
|
||||
public LeavesTrails(Actor self, LeavesTrailsInfo info)
|
||||
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
{
|
||||
body = self.Trait<BodyOrientation>();
|
||||
facing = self.TraitOrDefault<IFacing>();
|
||||
cachedFacing = facing != null ? facing.Facing : 0;
|
||||
cachedFacing = facing != null ? facing.Facing : WAngle.Zero;
|
||||
cachedPosition = self.CenterPosition;
|
||||
|
||||
base.Created(self);
|
||||
@@ -125,14 +125,14 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
var pos = Info.Type == TrailType.CenterPosition ? spawnPosition + body.LocalToWorld(offsetRotation) :
|
||||
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))
|
||||
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, self.World, Info.Image,
|
||||
Info.Sequences.Random(Game.CosmeticRandom), Info.Palette, Info.VisibleThroughFog, spawnFacing)));
|
||||
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, spawnFacing, self.World, Info.Image,
|
||||
Info.Sequences.Random(Game.CosmeticRandom), Info.Palette, Info.VisibleThroughFog)));
|
||||
|
||||
cachedPosition = self.CenterPosition;
|
||||
cachedFacing = facing != null ? facing.Facing : 0;
|
||||
cachedFacing = facing != null ? facing.Facing : WAngle.Zero;
|
||||
ticks = 0;
|
||||
|
||||
cachedInterval = isMoving ? Info.MovingInterval : Info.StationaryInterval;
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
if (facing == null)
|
||||
return () => WAngle.Zero;
|
||||
|
||||
return () => WAngle.FromFacing(facing.Facing);
|
||||
return () => facing.Facing;
|
||||
}
|
||||
|
||||
public RenderSprites(ActorInitializer init, RenderSpritesInfo info)
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
if (turreted != null)
|
||||
getFacing = () => WAngle.FromFacing(turreted.TurretFacing);
|
||||
else if (facing != null)
|
||||
getFacing = () => WAngle.FromFacing(facing.Facing);
|
||||
getFacing = () => facing.Facing;
|
||||
else
|
||||
getFacing = () => WAngle.Zero;
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return new Transform(self, Info.IntoActor)
|
||||
{
|
||||
Offset = Info.Offset,
|
||||
Facing = Info.Facing,
|
||||
Facing = WAngle.FromFacing(Info.Facing),
|
||||
Sounds = Info.TransformSounds,
|
||||
Notification = Info.TransformNotification,
|
||||
Faction = faction
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
class TurnOnIdle : ConditionalTrait<TurnOnIdleInfo>, INotifyIdle
|
||||
{
|
||||
int currentDelay;
|
||||
int targetFacing;
|
||||
WAngle targetFacing;
|
||||
readonly Mobile mobile;
|
||||
|
||||
public TurnOnIdle(ActorInitializer init, TurnOnIdleInfo info)
|
||||
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
inits.Add(facings);
|
||||
}
|
||||
|
||||
Func<int> bodyFacing = () => facing.Facing;
|
||||
Func<int> bodyFacing = () => facing.Facing.Facing;
|
||||
var dynamicFacing = inits.GetOrDefault<DynamicFacingInit>();
|
||||
var staticFacing = inits.GetOrDefault<FacingInit>();
|
||||
if (dynamicFacing != null)
|
||||
|
||||
Reference in New Issue
Block a user