Support custom helicopter rotors. Fixes #4072.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
* available to you under the terms of the GNU General Public License
|
* available to you under the terms of the GNU General Public License
|
||||||
* as published by the Free Software Foundation. For more information,
|
* as published by the Free Software Foundation. For more information,
|
||||||
@@ -16,23 +16,33 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
{
|
{
|
||||||
public class WithRotorInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
|
public class WithRotorInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
|
||||||
{
|
{
|
||||||
|
[Desc("Sequence name to use when flying")]
|
||||||
|
public readonly string Sequence = "rotor";
|
||||||
|
|
||||||
|
[Desc("Sequence name to use when landed")]
|
||||||
|
public readonly string GroundSequence = "slow-rotor";
|
||||||
|
|
||||||
[Desc("Position relative to body")]
|
[Desc("Position relative to body")]
|
||||||
public readonly WVec Offset = WVec.Zero;
|
public readonly WVec Offset = WVec.Zero;
|
||||||
|
|
||||||
public readonly string Id = "rotor";
|
public readonly string Id = "rotor";
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new WithRotor(init.self, this); }
|
public object Create(ActorInitializer init) { return new WithRotor(init.self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WithRotor : ITick
|
public class WithRotor : ITick
|
||||||
{
|
{
|
||||||
public Animation rotorAnim;
|
WithRotorInfo info;
|
||||||
|
Animation rotorAnim;
|
||||||
|
|
||||||
public WithRotor(Actor self, WithRotorInfo info)
|
public WithRotor(Actor self, WithRotorInfo info)
|
||||||
{
|
{
|
||||||
|
this.info = info;
|
||||||
var rs = self.Trait<RenderSprites>();
|
var rs = self.Trait<RenderSprites>();
|
||||||
var body = self.Trait<IBodyOrientation>();
|
var body = self.Trait<IBodyOrientation>();
|
||||||
|
|
||||||
rotorAnim = new Animation(rs.GetImage(self));
|
rotorAnim = new Animation(rs.GetImage(self));
|
||||||
rotorAnim.PlayRepeating("rotor");
|
rotorAnim.PlayRepeating(info.Sequence);
|
||||||
rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim,
|
rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim,
|
||||||
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
|
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
|
||||||
null, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
|
null, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
|
||||||
@@ -41,10 +51,10 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
var isFlying = self.CenterPosition.Z > 0 && !self.IsDead();
|
var isFlying = self.CenterPosition.Z > 0 && !self.IsDead();
|
||||||
if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor"))
|
if (isFlying ^ (rotorAnim.CurrentSequence.Name != info.Sequence))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rotorAnim.ReplaceAnim(isFlying ? "rotor" : "slow-rotor");
|
rotorAnim.ReplaceAnim(isFlying ? info.Sequence : info.GroundSequence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user