fixes #88
This commit is contained in:
@@ -63,6 +63,7 @@ namespace OpenRa.Game
|
||||
Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 9, 5 ), Game.players[ 0 ] ) );
|
||||
Game.world.Add( new Actor( "jeep", Game.map.Offset + new int2( 9, 14 ), Game.players[ 1 ] ) );
|
||||
Game.world.Add( new Actor( "3tnk", Game.map.Offset + new int2( 12, 7 ), Game.players[ 1 ] ) );
|
||||
Game.world.Add(new Actor("apc", Game.map.Offset + new int2(13, 7), Game.players[1]));
|
||||
Game.world.Add(new Actor("ca", Game.map.Offset + new int2(40, 7), Game.players[1]));
|
||||
Game.world.Add(new Actor("e1", Game.map.Offset + new int2(9, 13), Game.players[1]));
|
||||
Game.world.Add(new Actor("arty", Game.map.Offset + new int2(10, 13), Game.players[1]));
|
||||
|
||||
@@ -153,6 +153,7 @@
|
||||
<Compile Include="Traits\RenderBuildingWarFactory.cs" />
|
||||
<Compile Include="Traits\RenderSimple.cs" />
|
||||
<Compile Include="Traits\RenderUnit.cs" />
|
||||
<Compile Include="Traits\RenderUnitMuzzleFlash.cs" />
|
||||
<Compile Include="Traits\RenderUnitRotor.cs" />
|
||||
<Compile Include="Traits\RenderUnitTurreted.cs" />
|
||||
<Compile Include="Traits\TraitsInterfaces.cs" />
|
||||
|
||||
@@ -13,6 +13,8 @@ namespace OpenRa.Game.Traits
|
||||
protected int primaryFireDelay = 0;
|
||||
protected int secondaryFireDelay = 0;
|
||||
|
||||
public float primaryRecoil = 0.0f, secondaryRecoil = 0.0f;
|
||||
|
||||
public AttackBase(Actor self) { }
|
||||
|
||||
protected bool CanAttack( Actor self )
|
||||
@@ -25,6 +27,9 @@ namespace OpenRa.Game.Traits
|
||||
if (primaryFireDelay > 0) --primaryFireDelay;
|
||||
if (secondaryFireDelay > 0) --secondaryFireDelay;
|
||||
|
||||
primaryRecoil = Math.Max(0f, primaryRecoil - .2f);
|
||||
secondaryRecoil = Math.Max(0f, secondaryRecoil - .2f);
|
||||
|
||||
if (target != null && target.IsDead) target = null; /* he's dead, jim. */
|
||||
}
|
||||
|
||||
@@ -36,20 +41,15 @@ namespace OpenRa.Game.Traits
|
||||
self.unitInfo.PrimaryOffset ) )
|
||||
{
|
||||
secondaryFireDelay = Math.Max( 4, secondaryFireDelay );
|
||||
if (rut != null) rut.primaryRecoil = 1;
|
||||
primaryRecoil = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.unitInfo.Secondary != null && CheckFire(self, self.unitInfo.Secondary, ref secondaryFireDelay,
|
||||
self.unitInfo.SecondaryOffset ?? self.unitInfo.PrimaryOffset))
|
||||
{
|
||||
if (rut != null)
|
||||
{
|
||||
if (self.unitInfo.SecondaryOffset != null)
|
||||
rut.secondaryRecoil = 1;
|
||||
else
|
||||
rut.primaryRecoil = 1;
|
||||
}
|
||||
if (self.unitInfo.SecondaryOffset != null) secondaryRecoil = 1;
|
||||
else primaryRecoil = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
47
OpenRa.Game/Traits/RenderUnitMuzzleFlash.cs
Normal file
47
OpenRa.Game/Traits/RenderUnitMuzzleFlash.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Game.Graphics;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
class RenderUnitMuzzleFlash : RenderUnit
|
||||
{
|
||||
Animation muzzleFlash;
|
||||
|
||||
public RenderUnitMuzzleFlash(Actor self)
|
||||
: base(self)
|
||||
{
|
||||
if (!self.unitInfo.MuzzleFlash) throw new InvalidOperationException("wtf??");
|
||||
|
||||
muzzleFlash = new Animation(self.unitInfo.Name);
|
||||
muzzleFlash.PlayFetchIndex("muzzle",
|
||||
() =>
|
||||
{
|
||||
var attack = self.traits.WithInterface<AttackBase>().First();
|
||||
var mobile = self.traits.WithInterface<Mobile>().First();
|
||||
return (Util.QuantizeFacing(
|
||||
mobile.facing, 8)) * 6 + (int)(attack.primaryRecoil * 5.9f);
|
||||
});
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self);
|
||||
muzzleFlash.Tick();
|
||||
}
|
||||
|
||||
public override IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self)
|
||||
{
|
||||
var attack = self.traits.WithInterface<AttackBase>().First();
|
||||
if (attack.primaryRecoil > 0)
|
||||
return base.Render(self).Concat(new[] {Util.Centered(self,
|
||||
muzzleFlash.Image, self.CenterLocation + new float2(
|
||||
self.unitInfo.PrimaryOffset.ElementAtOrDefault(2),
|
||||
self.unitInfo.PrimaryOffset.ElementAtOrDefault(3)))});
|
||||
else
|
||||
return base.Render(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ namespace OpenRa.Game.Traits
|
||||
{
|
||||
public Animation turretAnim;
|
||||
public Animation muzzleFlash;
|
||||
public float primaryRecoil = 0.0f, secondaryRecoil = 0.0f;
|
||||
|
||||
public RenderUnitTurreted(Actor self)
|
||||
: base(self)
|
||||
@@ -21,9 +20,11 @@ namespace OpenRa.Game.Traits
|
||||
{
|
||||
if (self.unitInfo.MuzzleFlash)
|
||||
{
|
||||
var attack = self.traits.WithInterface<AttackBase>().First();
|
||||
muzzleFlash = new Animation(self.unitInfo.Name);
|
||||
muzzleFlash.PlayFetchIndex("muzzle",
|
||||
() => (Util.QuantizeFacing(self.traits.Get<Turreted>().turretFacing,8)) * 6 + (int)(primaryRecoil * 6));
|
||||
() => (Util.QuantizeFacing(self.traits.Get<Turreted>().turretFacing,8)) * 6 + (int)(attack.primaryRecoil * 5.9f));
|
||||
/* hack: recoil can be 1.0f, but don't overflow into next anim */
|
||||
}
|
||||
|
||||
turretAnim.PlayFetchIndex("turret",
|
||||
@@ -36,25 +37,24 @@ namespace OpenRa.Game.Traits
|
||||
public override IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self)
|
||||
{
|
||||
var mobile = self.traits.Get<Mobile>();
|
||||
var attack = self.traits.WithInterface<AttackBase>().FirstOrDefault();
|
||||
|
||||
yield return Util.Centered(self, anim.Image, self.CenterLocation);
|
||||
yield return Util.Centered(self, turretAnim.Image, self.CenterLocation
|
||||
+ Util.GetTurretPosition(self, self.unitInfo.PrimaryOffset, primaryRecoil));
|
||||
+ Util.GetTurretPosition(self, self.unitInfo.PrimaryOffset, attack.primaryRecoil));
|
||||
if (self.unitInfo.SecondaryOffset != null)
|
||||
yield return Util.Centered(self, turretAnim.Image, self.CenterLocation
|
||||
+ Util.GetTurretPosition(self, self.unitInfo.SecondaryOffset, secondaryRecoil));
|
||||
+ Util.GetTurretPosition(self, self.unitInfo.SecondaryOffset, attack.secondaryRecoil));
|
||||
|
||||
if (muzzleFlash != null && primaryRecoil > 0)
|
||||
if (muzzleFlash != null && attack.primaryRecoil > 0)
|
||||
yield return Util.Centered(self, muzzleFlash.Image, self.CenterLocation
|
||||
+ Util.GetTurretPosition(self, self.unitInfo.PrimaryOffset, primaryRecoil));
|
||||
+ Util.GetTurretPosition(self, self.unitInfo.PrimaryOffset, attack.primaryRecoil));
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
{
|
||||
base.Tick(self);
|
||||
turretAnim.Tick();
|
||||
primaryRecoil = Math.Max(0f, primaryRecoil - .2f);
|
||||
secondaryRecoil = Math.Max(0f, secondaryRecoil - .2f);
|
||||
if (muzzleFlash != null)
|
||||
muzzleFlash.Tick();
|
||||
}
|
||||
|
||||
@@ -275,6 +275,7 @@
|
||||
<!-- apc -->
|
||||
<unit name="apc">
|
||||
<sequence name="idle" start="0" length="32" />
|
||||
<sequence name="muzzle" start="0" length="48" src="minigun" />
|
||||
</unit>
|
||||
<!-- mine layer -->
|
||||
<unit name="mnly">
|
||||
|
||||
@@ -55,7 +55,9 @@ PrimaryOffset=0,0,0,-2
|
||||
MuzzleFlash=yes
|
||||
[APC]
|
||||
Description=Armored Personnel Carrier
|
||||
Traits=Mobile, RenderUnit, AttackBase
|
||||
Traits=Mobile, AttackBase, RenderUnitMuzzleFlash
|
||||
PrimaryOffset=0,0,0,-4
|
||||
MuzzleFlash=yes
|
||||
[MNLY]
|
||||
Description=Minelayer
|
||||
Traits=Mobile, RenderUnit
|
||||
|
||||
Reference in New Issue
Block a user