Remove legacy turret/muzzle positioning code.
This commit is contained in:
@@ -18,16 +18,8 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
public enum CoordinateModel { Legacy, World };
|
||||
|
||||
public class Barrel
|
||||
{
|
||||
// Legacy coordinates
|
||||
public PVecInt TurretSpaceOffset; // position in turret space
|
||||
public PVecInt ScreenSpaceOffset; // screen-space hack to make things line up good.
|
||||
public int Facing; // deviation from turret facing
|
||||
|
||||
// World coordinates
|
||||
public WVec Offset;
|
||||
public WAngle Yaw;
|
||||
}
|
||||
@@ -44,10 +36,6 @@ namespace OpenRA.Mods.RA
|
||||
[Desc("Time (in frames) until the weapon can fire again.")]
|
||||
public readonly int FireDelay = 0;
|
||||
|
||||
public readonly float LegacyRecoilRecovery = 0.2f;
|
||||
public readonly int[] LegacyLocalOffset = { };
|
||||
|
||||
public CoordinateModel OffsetModel = CoordinateModel.Legacy;
|
||||
[Desc("Muzzle position relative to turret or body. (forward, right, up) triples")]
|
||||
public readonly WRange[] LocalOffset = {};
|
||||
[Desc("Muzzle yaw relative to turret or body.")]
|
||||
@@ -57,14 +45,7 @@ namespace OpenRA.Mods.RA
|
||||
[Desc("Recoil recovery per-frame")]
|
||||
public readonly WRange RecoilRecovery = new WRange(9);
|
||||
|
||||
public object Create(ActorInitializer init)
|
||||
{
|
||||
// Auto-detect coordinate type
|
||||
if (LocalOffset.Length > 0 && OffsetModel == CoordinateModel.Legacy)
|
||||
OffsetModel = CoordinateModel.World;
|
||||
|
||||
return new Armament(init.self, this);
|
||||
}
|
||||
public object Create(ActorInitializer init) { return new Armament(init.self, this); }
|
||||
}
|
||||
|
||||
public class Armament : ITick
|
||||
@@ -76,7 +57,6 @@ namespace OpenRA.Mods.RA
|
||||
Lazy<ILocalCoordinatesModel> Coords;
|
||||
|
||||
public WRange Recoil;
|
||||
public float LegacyRecoil { get; private set; }
|
||||
public int FireDelay { get; private set; }
|
||||
public int Burst { get; private set; }
|
||||
|
||||
@@ -91,38 +71,22 @@ namespace OpenRA.Mods.RA
|
||||
Weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()];
|
||||
Burst = Weapon.Burst;
|
||||
|
||||
if (info.LocalOffset.Length % 3 != 0)
|
||||
throw new InvalidOperationException("Invalid LocalOffset array length");
|
||||
|
||||
var barrels = new List<Barrel>();
|
||||
|
||||
if (Info.OffsetModel == CoordinateModel.Legacy)
|
||||
for (var i = 0; i < info.LocalOffset.Length / 3; i++)
|
||||
{
|
||||
for (var i = 0; i < info.LocalOffset.Length / 5; i++)
|
||||
barrels.Add(new Barrel
|
||||
{
|
||||
TurretSpaceOffset = new PVecInt(info.LegacyLocalOffset[5 * i], info.LegacyLocalOffset[5 * i + 1]),
|
||||
ScreenSpaceOffset = new PVecInt(info.LegacyLocalOffset[5 * i + 2], info.LegacyLocalOffset[5 * i + 3]),
|
||||
Facing = info.LegacyLocalOffset[5 * i + 4],
|
||||
});
|
||||
|
||||
// if no barrels specified, the default is "turret position; turret facing".
|
||||
if (barrels.Count == 0)
|
||||
barrels.Add(new Barrel { TurretSpaceOffset = PVecInt.Zero, ScreenSpaceOffset = PVecInt.Zero, Facing = 0 });
|
||||
}
|
||||
else
|
||||
{
|
||||
if (info.LocalOffset.Length % 3 != 0)
|
||||
throw new InvalidOperationException("Invalid LocalOffset array length");
|
||||
|
||||
for (var i = 0; i < info.LocalOffset.Length / 3; i++)
|
||||
barrels.Add(new Barrel
|
||||
{
|
||||
barrels.Add(new Barrel
|
||||
{
|
||||
Offset = new WVec(info.LocalOffset[3*i], info.LocalOffset[3*i + 1], info.LocalOffset[3*i + 2]),
|
||||
Yaw = info.LocalYaw.Length > i ? info.LocalYaw[i] : WAngle.Zero
|
||||
});
|
||||
}
|
||||
if (barrels.Count == 0)
|
||||
barrels.Add(new Barrel { Offset = WVec.Zero, Yaw = WAngle.Zero });
|
||||
Offset = new WVec(info.LocalOffset[3*i], info.LocalOffset[3*i + 1], info.LocalOffset[3*i + 2]),
|
||||
Yaw = info.LocalYaw.Length > i ? info.LocalYaw[i] : WAngle.Zero
|
||||
});
|
||||
}
|
||||
|
||||
if (barrels.Count == 0)
|
||||
barrels.Add(new Barrel { Offset = WVec.Zero, Yaw = WAngle.Zero });
|
||||
|
||||
Barrels = barrels.ToArray();
|
||||
}
|
||||
|
||||
@@ -130,7 +94,6 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
if (FireDelay > 0)
|
||||
--FireDelay;
|
||||
LegacyRecoil = Math.Max(0f, LegacyRecoil - Info.LegacyRecoilRecovery);
|
||||
Recoil = new WRange(Math.Max(0, Recoil.Range - Info.RecoilRecovery.Range));
|
||||
}
|
||||
|
||||
@@ -151,19 +114,10 @@ namespace OpenRA.Mods.RA
|
||||
var barrel = Barrels[Burst % Barrels.Length];
|
||||
var destMove = target.IsActor ? target.Actor.TraitOrDefault<IMove>() : null;
|
||||
|
||||
var legacyMuzzlePosition = self.CenterLocation + (PVecInt)MuzzlePxOffset(self, facing, barrel).ToInt2();
|
||||
var legacyMuzzleAltitude = move != null ? move.Altitude : 0;
|
||||
var legacyFacing = barrel.Facing + (Turret.Value != null ? Turret.Value.turretFacing :
|
||||
facing != null ? facing.Facing : Util.GetFacing(target.CenterLocation - self.CenterLocation, 0));
|
||||
|
||||
if (Info.OffsetModel == CoordinateModel.World)
|
||||
{
|
||||
var muzzlePosition = self.CenterPosition + MuzzleOffset(self, barrel);
|
||||
legacyMuzzlePosition = PPos.FromWPos(muzzlePosition);
|
||||
legacyMuzzleAltitude = Game.CellSize*muzzlePosition.Z/1024;
|
||||
|
||||
legacyFacing = MuzzleOrientation(self, barrel).Yaw.Angle / 4;
|
||||
}
|
||||
var muzzlePosition = self.CenterPosition + MuzzleOffset(self, barrel);
|
||||
var legacyMuzzlePosition = PPos.FromWPos(muzzlePosition);
|
||||
var legacyMuzzleAltitude = Game.CellSize*muzzlePosition.Z/1024;
|
||||
var legacyFacing = MuzzleOrientation(self, barrel).Yaw.Angle / 4;
|
||||
|
||||
var args = new ProjectileArgs
|
||||
{
|
||||
@@ -199,7 +153,6 @@ namespace OpenRA.Mods.RA
|
||||
foreach (var na in self.TraitsImplementing<INotifyAttack>())
|
||||
na.Attacking(self, target);
|
||||
|
||||
LegacyRecoil = Info.LegacyRecoil;
|
||||
Recoil = Info.Recoil;
|
||||
|
||||
if (--Burst > 0)
|
||||
@@ -221,48 +174,8 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public bool IsReloading { get { return FireDelay > 0; } }
|
||||
|
||||
PVecFloat GetUnitspaceBarrelOffset(Actor self, IFacing facing, Barrel b)
|
||||
{
|
||||
if (Turret.Value == null && facing == null)
|
||||
return PVecFloat.Zero;
|
||||
|
||||
var turretFacing = Turret.Value != null ? Turret.Value.turretFacing : facing.Facing;
|
||||
return (PVecFloat)Util.RotateVectorByFacing(b.TurretSpaceOffset.ToFloat2(), turretFacing, .7f);
|
||||
}
|
||||
|
||||
// Note: facing is only used by the legacy positioning code
|
||||
public PVecFloat MuzzlePxOffset(Actor self, IFacing facing, Barrel b)
|
||||
{
|
||||
// Hack for external code unaware of world coordinates
|
||||
if (Info.OffsetModel == CoordinateModel.World)
|
||||
return (PVecFloat)PPos.FromWPosHackZ(WPos.Zero + MuzzleOffset(self, b)).ToFloat2();
|
||||
|
||||
PVecFloat pos = b.ScreenSpaceOffset;
|
||||
|
||||
// local facing offset doesn't make sense for actors that don't rotate
|
||||
if (Turret.Value == null && facing == null)
|
||||
return pos;
|
||||
|
||||
if (Turret.Value != null)
|
||||
pos += Turret.Value.PxPosition(self, facing);
|
||||
|
||||
// Add local unitspace/turretspace offset
|
||||
var f = Turret.Value != null ? Turret.Value.turretFacing : facing.Facing;
|
||||
|
||||
// This is going away, so no point adding unnecessary usings
|
||||
var ru = self.TraitOrDefault<RenderUnit>();
|
||||
var numDirs = (ru != null) ? ru.anim.CurrentSequence.Facings : 8;
|
||||
var quantizedFacing = Util.QuantizeFacing(f, numDirs) * (256 / numDirs);
|
||||
|
||||
pos += (PVecFloat)Util.RotateVectorByFacing(b.TurretSpaceOffset.ToFloat2(), quantizedFacing, .7f);
|
||||
return pos;
|
||||
}
|
||||
|
||||
public WVec MuzzleOffset(Actor self, Barrel b)
|
||||
{
|
||||
if (Info.OffsetModel != CoordinateModel.World)
|
||||
throw new InvalidOperationException("Armament.MuzzlePosition requires a world coordinate offset");
|
||||
|
||||
var bodyOrientation = Coords.Value.QuantizeOrientation(self, self.Orientation);
|
||||
var localOffset = b.Offset + new WVec(-Recoil, WRange.Zero, WRange.Zero);
|
||||
if (Turret.Value != null)
|
||||
|
||||
Reference in New Issue
Block a user