split unit smoke out into WithSmoke trait; remove duplication
This commit is contained in:
@@ -19,10 +19,9 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
public override object Create(ActorInitializer init) { return new RenderGunboat(init.self); }
|
public override object Create(ActorInitializer init) { return new RenderGunboat(init.self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class RenderGunboat : RenderSimple, INotifyDamage, INotifyDamageStateChanged
|
class RenderGunboat : RenderSimple, INotifyDamageStateChanged
|
||||||
{
|
{
|
||||||
IFacing facing;
|
IFacing facing;
|
||||||
bool isSmoking = false;
|
|
||||||
|
|
||||||
public RenderGunboat(Actor self)
|
public RenderGunboat(Actor self)
|
||||||
: base(self, () => self.HasTrait<Turreted>() ? self.Trait<Turreted>().turretFacing : 0)
|
: base(self, () => self.HasTrait<Turreted>() ? self.Trait<Turreted>().turretFacing : 0)
|
||||||
@@ -34,7 +33,6 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
wake.Play("left-wake");
|
wake.Play("left-wake");
|
||||||
Func<float2> offset = () => new float2(((anims["wake"].Animation.CurrentSequence.Name == "left-wake") ? 1 : -1),2);
|
Func<float2> offset = () => new float2(((anims["wake"].Animation.CurrentSequence.Name == "left-wake") ? 1 : -1),2);
|
||||||
anims.Add( "wake", new AnimationWithOffset( wake, offset, () => false ) { ZOffset = -2 } );
|
anims.Add( "wake", new AnimationWithOffset( wake, offset, () => false ) { ZOffset = -2 } );
|
||||||
anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string lastDir = "left";
|
string lastDir = "left";
|
||||||
@@ -61,19 +59,5 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
lastDamage = "";
|
lastDamage = "";
|
||||||
anim.ReplaceAnim(lastDir+lastDamage);
|
anim.ReplaceAnim(lastDir+lastDamage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Damaged(Actor self, AttackInfo e)
|
|
||||||
{
|
|
||||||
// Smoking
|
|
||||||
if (e.DamageState < DamageState.Heavy) return;
|
|
||||||
if (isSmoking) return;
|
|
||||||
|
|
||||||
isSmoking = true;
|
|
||||||
var smoke = anims[ "smoke" ].Animation;
|
|
||||||
smoke.PlayThen( "idle",
|
|
||||||
() => smoke.PlayThen( "loop",
|
|
||||||
() => smoke.PlayBackwardsThen( "end",
|
|
||||||
() => isSmoking = false ) ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -353,6 +353,7 @@
|
|||||||
<Compile Include="Reloads.cs" />
|
<Compile Include="Reloads.cs" />
|
||||||
<Compile Include="AnnounceOnKill.cs" />
|
<Compile Include="AnnounceOnKill.cs" />
|
||||||
<Compile Include="CrushableInfantry.cs" />
|
<Compile Include="CrushableInfantry.cs" />
|
||||||
|
<Compile Include="Render\WithSmoke.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -16,21 +16,15 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
{
|
{
|
||||||
public class RenderUnitInfo : RenderSimpleInfo
|
public class RenderUnitInfo : RenderSimpleInfo
|
||||||
{
|
{
|
||||||
public readonly bool Smokes = true;
|
|
||||||
public override object Create(ActorInitializer init) { return new RenderUnit(init.self); }
|
public override object Create(ActorInitializer init) { return new RenderUnit(init.self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RenderUnit : RenderSimple, INotifyDamage
|
public class RenderUnit : RenderSimple
|
||||||
{
|
{
|
||||||
public RenderUnit(Actor self)
|
public RenderUnit(Actor self)
|
||||||
: base(self, () => self.HasTrait<IFacing>() ? self.Trait<IFacing>().Facing : 0)
|
: base(self, () => self.HasTrait<IFacing>() ? self.Trait<IFacing>().Facing : 0)
|
||||||
{
|
{
|
||||||
canSmoke = self.Info.Traits.Get<RenderUnitInfo>().Smokes;
|
|
||||||
|
|
||||||
anim.PlayRepeating("idle");
|
anim.PlayRepeating("idle");
|
||||||
|
|
||||||
if (canSmoke)
|
|
||||||
anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlayCustomAnimation(Actor self, string newAnim, Action after)
|
public void PlayCustomAnimation(Actor self, string newAnim, Action after)
|
||||||
@@ -49,21 +43,5 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
anim.PlayBackwardsThen(name,
|
anim.PlayBackwardsThen(name,
|
||||||
() => { anim.PlayRepeating("idle"); a(); });
|
() => { anim.PlayRepeating("idle"); a(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSmoking;
|
|
||||||
bool canSmoke;
|
|
||||||
|
|
||||||
public void Damaged(Actor self, AttackInfo e)
|
|
||||||
{
|
|
||||||
if (e.DamageState < DamageState.Heavy) return;
|
|
||||||
if (isSmoking || !canSmoke) return;
|
|
||||||
|
|
||||||
isSmoking = true;
|
|
||||||
var smoke = anims[ "smoke" ].Animation;
|
|
||||||
smoke.PlayThen( "idle",
|
|
||||||
() => smoke.PlayThen( "loop",
|
|
||||||
() => smoke.PlayBackwardsThen( "end",
|
|
||||||
() => isSmoking = false ) ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
47
OpenRA.Mods.RA/Render/WithSmoke.cs
Normal file
47
OpenRA.Mods.RA/Render/WithSmoke.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||||
|
* 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
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA.Render
|
||||||
|
{
|
||||||
|
public class WithSmokeInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||||
|
{
|
||||||
|
public object Create(ActorInitializer init) { return new WithSmoke(init.self); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WithSmoke : INotifyDamage
|
||||||
|
{
|
||||||
|
bool isSmoking;
|
||||||
|
Animation anim;
|
||||||
|
|
||||||
|
public WithSmoke(Actor self)
|
||||||
|
{
|
||||||
|
var rs = self.Trait<RenderSimple>();
|
||||||
|
|
||||||
|
anim = new Animation("smoke_m");
|
||||||
|
rs.anims.Add("smoke", new RenderSimple.AnimationWithOffset(
|
||||||
|
anim, null, () => !isSmoking));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Damaged(Actor self, AttackInfo e)
|
||||||
|
{
|
||||||
|
if (isSmoking) return;
|
||||||
|
if (e.DamageState < DamageState.Heavy) return;
|
||||||
|
|
||||||
|
isSmoking = true;
|
||||||
|
anim.PlayThen( "idle",
|
||||||
|
() => anim.PlayThen( "loop",
|
||||||
|
() => anim.PlayBackwardsThen( "end",
|
||||||
|
() => isSmoking = false ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -283,5 +283,4 @@ VICE:
|
|||||||
PrimaryWeapon: Chemspray
|
PrimaryWeapon: Chemspray
|
||||||
AttackWander:
|
AttackWander:
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Smokes: False
|
|
||||||
WithMuzzleFlash:
|
WithMuzzleFlash:
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
Notification: unitlost.aud
|
Notification: unitlost.aud
|
||||||
AttackMove:
|
AttackMove:
|
||||||
AcceptsCloakCrate:
|
AcceptsCloakCrate:
|
||||||
|
WithSmoke:
|
||||||
|
|
||||||
^Tank:
|
^Tank:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -61,6 +62,7 @@
|
|||||||
Notification: unitlost.aud
|
Notification: unitlost.aud
|
||||||
AttackMove:
|
AttackMove:
|
||||||
AcceptsCloakCrate:
|
AcceptsCloakCrate:
|
||||||
|
WithSmoke:
|
||||||
|
|
||||||
^Helicopter:
|
^Helicopter:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ BOAT:
|
|||||||
RenderGunboat:
|
RenderGunboat:
|
||||||
AutoTarget:
|
AutoTarget:
|
||||||
AllowMovement: false
|
AllowMovement: false
|
||||||
|
WithSmoke:
|
||||||
|
|
||||||
LST:
|
LST:
|
||||||
Inherits: ^Ship
|
Inherits: ^Ship
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ BADR:
|
|||||||
ROT: 5
|
ROT: 5
|
||||||
Speed: 16
|
Speed: 16
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Smokes: no
|
|
||||||
WithShadow:
|
WithShadow:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
Cargo:
|
Cargo:
|
||||||
@@ -53,7 +52,6 @@ BADR.bomber:
|
|||||||
Ammo: 7
|
Ammo: 7
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Image: badr
|
Image: badr
|
||||||
Smokes: no
|
|
||||||
WithShadow:
|
WithShadow:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
-Selectable:
|
-Selectable:
|
||||||
@@ -108,7 +106,6 @@ MIG:
|
|||||||
Speed: 20
|
Speed: 20
|
||||||
RearmBuildings: afld
|
RearmBuildings: afld
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Smokes: no
|
|
||||||
WithShadow:
|
WithShadow:
|
||||||
LimitedAmmo:
|
LimitedAmmo:
|
||||||
Ammo: 8
|
Ammo: 8
|
||||||
@@ -159,7 +156,6 @@ YAK:
|
|||||||
ROT: 5
|
ROT: 5
|
||||||
Speed: 16
|
Speed: 16
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Smokes: no
|
|
||||||
WithShadow:
|
WithShadow:
|
||||||
LimitedAmmo:
|
LimitedAmmo:
|
||||||
Ammo: 18
|
Ammo: 18
|
||||||
@@ -251,7 +247,6 @@ HELI:
|
|||||||
ROT: 4
|
ROT: 4
|
||||||
Speed: 16
|
Speed: 16
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Smokes: no
|
|
||||||
WithRotor:
|
WithRotor:
|
||||||
Offset: 0,0,0,-2
|
Offset: 0,0,0,-2
|
||||||
WithShadow:
|
WithShadow:
|
||||||
@@ -295,7 +290,6 @@ HIND:
|
|||||||
ROT: 4
|
ROT: 4
|
||||||
Speed: 12
|
Speed: 12
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Smokes: no
|
|
||||||
WithRotor:
|
WithRotor:
|
||||||
WithShadow:
|
WithShadow:
|
||||||
LimitedAmmo:
|
LimitedAmmo:
|
||||||
@@ -321,7 +315,6 @@ U2:
|
|||||||
ROT: 7
|
ROT: 7
|
||||||
Speed: 40
|
Speed: 40
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Smokes: no
|
|
||||||
WithShadow:
|
WithShadow:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
-Selectable:
|
-Selectable:
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
GivesBounty:
|
GivesBounty:
|
||||||
GpsDot:
|
GpsDot:
|
||||||
String:Vehicle
|
String:Vehicle
|
||||||
|
WithSmoke:
|
||||||
|
|
||||||
^Tank:
|
^Tank:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -63,6 +64,7 @@
|
|||||||
GivesBounty:
|
GivesBounty:
|
||||||
GpsDot:
|
GpsDot:
|
||||||
String:Vehicle
|
String:Vehicle
|
||||||
|
WithSmoke:
|
||||||
|
|
||||||
^Infantry:
|
^Infantry:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
@@ -129,6 +131,7 @@
|
|||||||
GivesBounty:
|
GivesBounty:
|
||||||
GpsDot:
|
GpsDot:
|
||||||
String:Ship
|
String:Ship
|
||||||
|
WithSmoke:
|
||||||
|
|
||||||
^Plane:
|
^Plane:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
|
|||||||
Reference in New Issue
Block a user