Allow turrets to have a different facing count to the actor body.
This commit is contained in:
@@ -22,8 +22,7 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
|
|
||||||
class RenderBuildingTurreted : RenderBuilding
|
class RenderBuildingTurreted : RenderBuilding
|
||||||
{
|
{
|
||||||
public RenderBuildingTurreted( ActorInitializer init, RenderBuildingInfo info )
|
Turreted t;
|
||||||
: base(init, info, MakeTurretFacingFunc(init.self)) { }
|
|
||||||
|
|
||||||
static Func<int> MakeTurretFacingFunc(Actor self)
|
static Func<int> MakeTurretFacingFunc(Actor self)
|
||||||
{
|
{
|
||||||
@@ -31,5 +30,18 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
var turreted = self.TraitsImplementing<Turreted>().FirstOrDefault();
|
var turreted = self.TraitsImplementing<Turreted>().FirstOrDefault();
|
||||||
return () => turreted.turretFacing;
|
return () => turreted.turretFacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RenderBuildingTurreted(ActorInitializer init, RenderBuildingInfo info)
|
||||||
|
: base(init, info, MakeTurretFacingFunc(init.self))
|
||||||
|
{
|
||||||
|
t = init.self.TraitsImplementing<Turreted>().FirstOrDefault();
|
||||||
|
t.QuantizedFacings = anim.CurrentSequence.Facings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DamageStateChanged(Actor self, AttackInfo e)
|
||||||
|
{
|
||||||
|
base.DamageStateChanged(self, e);
|
||||||
|
t.QuantizedFacings = anim.CurrentSequence.Facings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
anim.Play(info.Sequence);
|
anim.Play(info.Sequence);
|
||||||
rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset(
|
rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset(
|
||||||
anim, () => TurretOffset(self), null, p => ZOffsetFromCenter(self, p, 1)));
|
anim, () => TurretOffset(self), null, p => ZOffsetFromCenter(self, p, 1)));
|
||||||
|
|
||||||
|
// Restrict turret facings to match the sprite
|
||||||
|
t.QuantizedFacings = anim.CurrentSequence.Facings;
|
||||||
}
|
}
|
||||||
|
|
||||||
WVec TurretOffset(Actor self)
|
WVec TurretOffset(Actor self)
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public class Turreted : ITick, ISync, IResolveOrder
|
public class Turreted : ITick, ISync, IResolveOrder
|
||||||
{
|
{
|
||||||
|
[Sync] public int QuantizedFacings = -1;
|
||||||
[Sync] public int turretFacing = 0;
|
[Sync] public int turretFacing = 0;
|
||||||
public int? desiredFacing;
|
public int? desiredFacing;
|
||||||
TurretedInfo info;
|
TurretedInfo info;
|
||||||
@@ -91,8 +92,17 @@ namespace OpenRA.Mods.RA
|
|||||||
// Orientation in unit-space
|
// Orientation in unit-space
|
||||||
public WRot LocalOrientation(Actor self)
|
public WRot LocalOrientation(Actor self)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Hack: turretFacing is relative to the world, so subtract the body yaw
|
// Hack: turretFacing is relative to the world, so subtract the body yaw
|
||||||
return WRot.FromYaw(WAngle.FromFacing(turretFacing) - self.Orientation.Yaw);
|
var local = WRot.FromYaw(WAngle.FromFacing(turretFacing) - self.Orientation.Yaw);
|
||||||
|
|
||||||
|
if (QuantizedFacings == -1)
|
||||||
|
return local;
|
||||||
|
|
||||||
|
// Quantize orientation to match a rendered sprite
|
||||||
|
// Implies no pitch or yaw
|
||||||
|
var facing = Traits.Util.QuantizeFacing(local.Yaw.Angle / 4, QuantizedFacings) * (256 / QuantizedFacings);
|
||||||
|
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user