Introduce world offsets for turrets & armaments.
This commit is contained in:
@@ -37,19 +37,32 @@ namespace OpenRA.Mods.RA.Render
|
||||
anim.Play("turret");
|
||||
|
||||
anims.Add("turret_{0}".F(i++), new AnimationWithOffset(anim,
|
||||
() => turret.PxPosition(self, facing).ToFloat2() + RecoilOffset(self, turret), null));
|
||||
() => TurretPosition(self, turret, facing), null));
|
||||
}
|
||||
}
|
||||
|
||||
float2 RecoilOffset(Actor self, Turreted t)
|
||||
float2 TurretPosition(Actor self, Turreted t, IFacing facing)
|
||||
{
|
||||
var a = self.TraitsImplementing<Armament>()
|
||||
.OrderByDescending(w => w.Recoil)
|
||||
.FirstOrDefault(w => w.Info.Turret == t.info.Turret);
|
||||
if (a == null)
|
||||
return float2.Zero;
|
||||
if (t.CoordinateModel == CoordinateModel.Legacy)
|
||||
{
|
||||
var recoil = self.TraitsImplementing<Armament>()
|
||||
.Where(w => w.Info.Turret == t.Name)
|
||||
.Sum(w => w.LegacyRecoil);
|
||||
return t.PxPosition(self, facing).ToFloat2() + Traits.Util.RotateVectorByFacing(new float2(0, recoil), t.turretFacing, .7f);
|
||||
}
|
||||
else
|
||||
{
|
||||
var recoil = self.TraitsImplementing<Armament>()
|
||||
.Where(w => w.Info.Turret == t.Name)
|
||||
.Aggregate(WRange.Zero, (a,b) => a + b.Recoil);
|
||||
|
||||
return a.RecoilPxOffset(self, t.turretFacing).ToFloat2();
|
||||
var localOffset = new WVec(-recoil, WRange.Zero, WRange.Zero);
|
||||
var bodyOrientation = QuantizeOrientation(self, self.Orientation);
|
||||
var turretOrientation = QuantizeOrientation(self, t.LocalOrientation(self));
|
||||
var worldPos = WPos.Zero + t.Position(self) + LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation));
|
||||
|
||||
return PPos.FromWPosHackZ(worldPos).ToFloat2();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
var barrel = b;
|
||||
var turreted = self.TraitsImplementing<Turreted>()
|
||||
.FirstOrDefault(t => t.info.Turret == a.Info.Turret);
|
||||
.FirstOrDefault(t => t.Name == a.Info.Turret);
|
||||
var getFacing = turreted != null ? () => turreted.turretFacing :
|
||||
facing != null ? (Func<int>)(() => facing.Facing) : () => 0;
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count), new AnimationWithOffset(
|
||||
muzzleFlash,
|
||||
() => a.MuzzlePxPosition(self, facing, barrel).ToFloat2(),
|
||||
() => a.MuzzlePxOffset(self, facing, barrel).ToFloat2(),
|
||||
() => !isShowing));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user