Fix turret facings for GTWR etc. Fixes #3610.

This commit is contained in:
Paul Chote
2013-08-03 11:47:25 +12:00
parent deb03e7a02
commit 03e09e25bb
7 changed files with 24 additions and 14 deletions

View File

@@ -18,6 +18,9 @@ namespace OpenRA.Traits
{
public class BodyOrientationInfo : ITraitInfo, IBodyOrientationInfo
{
[Desc("Number of facings for gameplay calculations. -1 indiciates auto-detection from sequence")]
public readonly int QuantizedFacings = -1;
[Desc("Camera pitch for rotation calculations")]
public readonly WAngle CameraPitch = WAngle.FromDegrees(40);
public object Create(ActorInitializer init) { return new BodyOrientation(init.self, this); }
@@ -25,21 +28,23 @@ namespace OpenRA.Traits
public class BodyOrientation : IBodyOrientation
{
[Sync] public int QuantizedFacings { get; set; }
BodyOrientationInfo Info;
[Sync] public int QuantizedFacings { get; private set; }
BodyOrientationInfo info;
public BodyOrientation(Actor self, BodyOrientationInfo info)
{
Info = info;
this.info = info;
if (info.QuantizedFacings > 0)
QuantizedFacings = info.QuantizedFacings;
}
public WAngle CameraPitch { get { return Info.CameraPitch; } }
public WAngle CameraPitch { get { return info.CameraPitch; } }
public WVec LocalToWorld(WVec vec)
{
// RA's 2d perspective doesn't correspond to an orthonormal 3D
// coordinate system, so fudge the y axis to make things look good
return new WVec(vec.Y, -Info.CameraPitch.Sin()*vec.X/1024, vec.Z);
return new WVec(vec.Y, -info.CameraPitch.Sin()*vec.X/1024, vec.Z);
}
public WRot QuantizeOrientation(Actor self, WRot orientation)
@@ -54,5 +59,11 @@ namespace OpenRA.Traits
// Roll and pitch are always zero if yaw is quantized
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
}
public void SetAutodetectedFacings(int facings)
{
if (info.QuantizedFacings < 0)
QuantizedFacings = facings;
}
}
}

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Traits
: this(self, MakeFacingFunc(self))
{
anim.PlayRepeating("idle");
self.Trait<IBodyOrientation>().QuantizedFacings = anim.CurrentSequence.Facings;
self.Trait<IBodyOrientation>().SetAutodetectedFacings(anim.CurrentSequence.Facings);
}
public int2 SelectionSize(Actor self)

View File

@@ -191,9 +191,10 @@ namespace OpenRA.Traits
public interface IBodyOrientation
{
WAngle CameraPitch { get; }
int QuantizedFacings { get; set; }
int QuantizedFacings { get; }
WVec LocalToWorld(WVec vec);
WRot QuantizeOrientation(Actor self, WRot orientation);
void SetAutodetectedFacings(int facings);
}
public interface IBodyOrientationInfo {}

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA.Render
rightWake.Play("wake-right");
anims.Add("wake-right", new AnimationWithOffset(rightWake, null, () => facing.Facing <= 128, -87));
self.Trait<IBodyOrientation>().QuantizedFacings = 2;
self.Trait<IBodyOrientation>().SetAutodetectedFacings(2);
}
public void DamageStateChanged(Actor self, AttackInfo e)

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA.Render
// Work around a bogus crash
anim.PlayRepeating( NormalizeSequence(self, "idle") );
self.Trait<IBodyOrientation>().QuantizedFacings = anim.CurrentSequence.Facings;
self.Trait<IBodyOrientation>().SetAutodetectedFacings(anim.CurrentSequence.Facings);
// Can't call Complete() directly from ctor because other traits haven't been inited yet
if (self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation && !init.Contains<SkipMakeAnimsInit>())

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA.Render
State = AnimationState.Waiting;
mobile = self.Trait<Mobile>();
self.Trait<IBodyOrientation>().QuantizedFacings = anim.CurrentSequence.Facings;
self.Trait<IBodyOrientation>().SetAutodetectedFacings(anim.CurrentSequence.Facings);
}
public void Attacking(Actor self, Target target)

View File

@@ -605,8 +605,6 @@ OBLI:
Turreted:
ROT:255
AutoTarget:
RenderBuilding:
QuantizedFacings: 8
-RenderBuilding:
RenderRangeCircle:
-EmitInfantryOnSell:
@@ -638,7 +636,7 @@ GTWR:
Weapon: HighV
LocalOffset: 256,0,256
AttackTurreted:
RenderBuilding:
BodyOrientation:
QuantizedFacings: 8
AutoTarget:
DetectCloaked:
@@ -682,7 +680,7 @@ ATWR:
LocalYaw: -100,100
AttackTurreted:
AutoTarget:
RenderBuilding:
BodyOrientation:
QuantizedFacings: 8
RenderDetectionCircle:
DetectCloaked: