Allow turrets to have a different facing count to the actor body.

This commit is contained in:
Paul Chote
2013-05-25 16:12:51 +12:00
parent 13f8d944d2
commit 1d5f67cb6a
3 changed files with 28 additions and 3 deletions

View File

@@ -22,8 +22,7 @@ namespace OpenRA.Mods.RA.Render
class RenderBuildingTurreted : RenderBuilding
{
public RenderBuildingTurreted( ActorInitializer init, RenderBuildingInfo info )
: base(init, info, MakeTurretFacingFunc(init.self)) { }
Turreted t;
static Func<int> MakeTurretFacingFunc(Actor self)
{
@@ -31,5 +30,18 @@ namespace OpenRA.Mods.RA.Render
var turreted = self.TraitsImplementing<Turreted>().FirstOrDefault();
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;
}
}
}

View File

@@ -54,6 +54,9 @@ namespace OpenRA.Mods.RA.Render
anim.Play(info.Sequence);
rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset(
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)

View File

@@ -33,6 +33,7 @@ namespace OpenRA.Mods.RA
public class Turreted : ITick, ISync, IResolveOrder
{
[Sync] public int QuantizedFacings = -1;
[Sync] public int turretFacing = 0;
public int? desiredFacing;
TurretedInfo info;
@@ -91,8 +92,17 @@ namespace OpenRA.Mods.RA
// Orientation in unit-space
public WRot LocalOrientation(Actor self)
{
// 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));
}
}
}