Remove Util.GetFacing.
This commit is contained in:
@@ -31,18 +31,6 @@ namespace OpenRA.Traits
|
|||||||
return (facing - rot) & 0xFF;
|
return (facing - rot) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetFacing(WVec d, int currentFacing)
|
|
||||||
{
|
|
||||||
if (d.LengthSquared == 0)
|
|
||||||
return currentFacing;
|
|
||||||
|
|
||||||
// OpenRA defines north as -y, so invert
|
|
||||||
var angle = WAngle.ArcTan(-d.Y, d.X, 4).Angle;
|
|
||||||
|
|
||||||
// Convert back to a facing
|
|
||||||
return (angle / 4 - 0x40) & 0xFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int GetNearestFacing(int facing, int desiredFacing)
|
public static int GetNearestFacing(int facing, int desiredFacing)
|
||||||
{
|
{
|
||||||
var turn = desiredFacing - facing;
|
var turn = desiredFacing - facing;
|
||||||
|
|||||||
@@ -70,9 +70,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (d.HorizontalLengthSquared < 91022)
|
if (d.HorizontalLengthSquared < 91022)
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
|
|
||||||
var desiredFacing = Util.GetFacing(d, plane.Facing);
|
|
||||||
|
|
||||||
// Don't turn until we've reached the cruise altitude
|
// Don't turn until we've reached the cruise altitude
|
||||||
|
var desiredFacing = d.Yaw.Facing;
|
||||||
var targetAltitude = plane.CenterPosition.Z + plane.Info.CruiseAltitude.Length - self.World.Map.DistanceAboveTerrain(plane.CenterPosition).Length;
|
var targetAltitude = plane.CenterPosition.Z + plane.Info.CruiseAltitude.Length - self.World.Map.DistanceAboveTerrain(plane.CenterPosition).Length;
|
||||||
if (plane.CenterPosition.Z < targetAltitude)
|
if (plane.CenterPosition.Z < targetAltitude)
|
||||||
desiredFacing = plane.Facing;
|
desiredFacing = plane.Facing;
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
var dist = target.CenterPosition - self.CenterPosition;
|
var dist = target.CenterPosition - self.CenterPosition;
|
||||||
|
|
||||||
// Can rotate facing while ascending
|
// Can rotate facing while ascending
|
||||||
var desiredFacing = Util.GetFacing(dist, helicopter.Facing);
|
var desiredFacing = dist.HorizontalLengthSquared != 0 ? dist.Yaw.Facing : helicopter.Facing;
|
||||||
helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.ROT);
|
helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.ROT);
|
||||||
|
|
||||||
if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude))
|
if (HeliFly.AdjustAltitude(self, helicopter, helicopter.Info.CruiseAltitude))
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
// Rotate towards the target
|
// Rotate towards the target
|
||||||
var dist = pos - self.CenterPosition;
|
var dist = pos - self.CenterPosition;
|
||||||
var desiredFacing = Util.GetFacing(dist, helicopter.Facing);
|
var desiredFacing = dist.HorizontalLengthSquared != 0 ? dist.Yaw.Facing : helicopter.Facing;
|
||||||
helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.ROT);
|
helicopter.Facing = Util.TickFacing(helicopter.Facing, desiredFacing, helicopter.ROT);
|
||||||
var move = helicopter.FlyStep(desiredFacing);
|
var move = helicopter.FlyStep(desiredFacing);
|
||||||
|
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
var desiredFacing = Util.GetFacing(d, plane.Facing);
|
Fly.FlyToward(self, plane, d.Yaw.Facing, WDist.Zero);
|
||||||
Fly.FlyToward(self, plane, desiredFacing, WDist.Zero);
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (move != null && (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange)))
|
if (move != null && (!Target.IsInRange(self.CenterPosition, maxRange) || Target.IsInRange(self.CenterPosition, minRange)))
|
||||||
return Util.SequenceActivities(move.MoveWithinRange(Target, minRange, maxRange), this);
|
return Util.SequenceActivities(move.MoveWithinRange(Target, minRange, maxRange), this);
|
||||||
|
|
||||||
var desiredFacing = Util.GetFacing(Target.CenterPosition - self.CenterPosition, 0);
|
var desiredFacing = (Target.CenterPosition - self.CenterPosition).Yaw.Facing;
|
||||||
if (facing.Facing != desiredFacing)
|
if (facing.Facing != desiredFacing)
|
||||||
return Util.SequenceActivities(new Turn(self, desiredFacing), this);
|
return Util.SequenceActivities(new Turn(self, desiredFacing), this);
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
|
target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
towardsTargetFacing = OpenRA.Traits.Util.GetFacing(target - headPos, 0);
|
towardsTargetFacing = (target - headPos).Yaw.Facing;
|
||||||
|
|
||||||
// Update the target position with the range we shoot beyond the target by
|
// Update the target position with the range we shoot beyond the target by
|
||||||
// I.e. we can deliberately overshoot, so aim for that position
|
// I.e. we can deliberately overshoot, so aim for that position
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
|
target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
facing = OpenRA.Traits.Util.GetFacing(target - pos, 0);
|
facing = (target - pos).Yaw.Facing;
|
||||||
length = Math.Max((target - pos).Length / speed.Length, 1);
|
length = Math.Max((target - pos).Length / speed.Length, 1);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.Image))
|
if (!string.IsNullOrEmpty(info.Image))
|
||||||
|
|||||||
@@ -169,13 +169,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public void Repulse()
|
public void Repulse()
|
||||||
{
|
{
|
||||||
var repulsionForce = GetRepulsionForce();
|
var repulsionForce = GetRepulsionForce();
|
||||||
|
if (repulsionForce.HorizontalLengthSquared == 0)
|
||||||
var repulsionFacing = Util.GetFacing(repulsionForce, -1);
|
|
||||||
if (repulsionFacing == -1)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var speed = Info.RepulsionSpeed != -1 ? Info.RepulsionSpeed : MovementSpeed;
|
var speed = Info.RepulsionSpeed != -1 ? Info.RepulsionSpeed : MovementSpeed;
|
||||||
SetPosition(self, CenterPosition + FlyStep(speed, repulsionFacing));
|
SetPosition(self, CenterPosition + FlyStep(speed, repulsionForce.Yaw.Facing));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual WVec GetRepulsionForce()
|
public virtual WVec GetRepulsionForce()
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
inAttackRange = false;
|
inAttackRange = false;
|
||||||
|
|
||||||
var f = facing.Value.Facing;
|
var f = facing.Value.Facing;
|
||||||
var facingToTarget = Util.GetFacing(target.CenterPosition - self.CenterPosition, f);
|
var delta = target.CenterPosition - self.CenterPosition;
|
||||||
|
var facingToTarget = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : f;
|
||||||
facingTarget = Math.Abs(facingToTarget - f) % 256 <= info.FacingTolerance;
|
facingTarget = Math.Abs(facingToTarget - f) % 256 <= info.FacingTolerance;
|
||||||
|
|
||||||
// Bombs drop anywhere in range
|
// Bombs drop anywhere in range
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
var f = facing.Value.Facing;
|
var f = facing.Value.Facing;
|
||||||
var facingToTarget = Util.GetFacing(target.CenterPosition - self.CenterPosition, f);
|
var delta = target.CenterPosition - self.CenterPosition;
|
||||||
|
var facingToTarget = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : f;
|
||||||
|
|
||||||
if (Math.Abs(facingToTarget - f) % 256 > info.FacingTolerance)
|
if (Math.Abs(facingToTarget - f) % 256 > info.FacingTolerance)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var pos = self.CenterPosition;
|
var pos = self.CenterPosition;
|
||||||
var targetYaw = WAngle.FromFacing(OpenRA.Traits.Util.GetFacing(target.CenterPosition - self.CenterPosition, 0));
|
var targetYaw = (target.CenterPosition - self.CenterPosition).Yaw;
|
||||||
|
|
||||||
foreach (var a in Armaments)
|
foreach (var a in Armaments)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -796,7 +796,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var speed = MovementSpeedForCell(self, cell);
|
var speed = MovementSpeedForCell(self, cell);
|
||||||
var length = speed > 0 ? (toPos - fromPos).Length / speed : 0;
|
var length = speed > 0 ? (toPos - fromPos).Length / speed : 0;
|
||||||
|
|
||||||
var facing = Util.GetFacing(toPos - fromPos, Facing);
|
var delta = toPos - fromPos;
|
||||||
|
var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : Facing;
|
||||||
return Util.SequenceActivities(new Turn(self, facing), new Drag(self, fromPos, toPos, length));
|
return Util.SequenceActivities(new Turn(self, facing), new Drag(self, fromPos, toPos, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +63,18 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var spawn = self.CenterPosition + exitinfo.SpawnOffset;
|
var spawn = self.CenterPosition + exitinfo.SpawnOffset;
|
||||||
var to = self.World.Map.CenterOfCell(exit);
|
var to = self.World.Map.CenterOfCell(exit);
|
||||||
|
|
||||||
var fi = producee.TraitInfoOrDefault<IFacingInfo>();
|
var initialFacing = exitinfo.Facing;
|
||||||
var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi == null ? 0 : fi.GetInitialFacing()) : exitinfo.Facing;
|
if (exitinfo.Facing < 0)
|
||||||
|
{
|
||||||
|
var delta = to - spawn;
|
||||||
|
if (delta.HorizontalLengthSquared == 0)
|
||||||
|
{
|
||||||
|
var fi = producee.TraitInfoOrDefault<IFacingInfo>();
|
||||||
|
initialFacing = fi != null ? fi.GetInitialFacing() : 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
initialFacing = delta.Yaw.Facing;
|
||||||
|
}
|
||||||
|
|
||||||
exitLocation = rp.Value != null ? rp.Value.Location : exit;
|
exitLocation = rp.Value != null ? rp.Value.Location : exit;
|
||||||
target = Target.FromCell(self.World, exitLocation);
|
target = Target.FromCell(self.World, exitLocation);
|
||||||
|
|||||||
@@ -110,7 +110,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public bool FaceTarget(Actor self, Target target)
|
public bool FaceTarget(Actor self, Target target)
|
||||||
{
|
{
|
||||||
DesiredFacing = Util.GetFacing(target.CenterPosition - self.CenterPosition, TurretFacing);
|
var delta = target.CenterPosition - self.CenterPosition;
|
||||||
|
DesiredFacing = delta.HorizontalLengthSquared != 0 ? delta.Yaw.Facing : TurretFacing;
|
||||||
MoveTurret();
|
MoveTurret();
|
||||||
return TurretFacing == DesiredFacing.Value;
|
return TurretFacing == DesiredFacing.Value;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user