Merge pull request #3627 from pchote/muzzleflash
Improved Muzzleflash support
This commit is contained in:
@@ -124,7 +124,6 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface INotifyAttack { void Attacking(Actor self, Target target); }
|
|
||||||
public interface IRenderModifier { IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r); }
|
public interface IRenderModifier { IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r); }
|
||||||
public interface IDamageModifier { float GetDamageModifier(Actor attacker, WarheadInfo warhead); }
|
public interface IDamageModifier { float GetDamageModifier(Actor attacker, WarheadInfo warhead); }
|
||||||
public interface ISpeedModifier { decimal GetSpeedModifier(); }
|
public interface ISpeedModifier { decimal GetSpeedModifier(); }
|
||||||
|
|||||||
@@ -74,7 +74,8 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
void LayMine(Actor self)
|
void LayMine(Actor self)
|
||||||
{
|
{
|
||||||
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
|
var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
|
||||||
if (limitedAmmo != null) limitedAmmo.Attacking(self, Target.FromCell(self.Location));
|
if (limitedAmmo != null)
|
||||||
|
limitedAmmo.TakeAmmo();
|
||||||
|
|
||||||
self.World.AddFrameEndTask(
|
self.World.AddFrameEndTask(
|
||||||
w => w.CreateActor(self.Info.Traits.Get<MinelayerInfo>().Mine, new TypeDictionary
|
w => w.CreateActor(self.Info.Traits.Get<MinelayerInfo>().Mine, new TypeDictionary
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ namespace OpenRA.Mods.RA
|
|||||||
});
|
});
|
||||||
|
|
||||||
foreach (var na in self.TraitsImplementing<INotifyAttack>())
|
foreach (var na in self.TraitsImplementing<INotifyAttack>())
|
||||||
na.Attacking(self, target);
|
na.Attacking(self, target, this, barrel);
|
||||||
|
|
||||||
Recoil = Info.Recoil;
|
Recoil = Info.Recoil;
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA
|
|||||||
base.Tick( self );
|
base.Tick( self );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Attacking(Actor self, Target target)
|
public void Attacking(Actor self, Target target, Armament a, Barrel barrel)
|
||||||
{
|
{
|
||||||
--charges;
|
--charges;
|
||||||
timeToRecharge = self.Info.Traits.Get<AttackTeslaInfo>().ReloadTime;
|
timeToRecharge = self.Info.Traits.Get<AttackTeslaInfo>().ReloadTime;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA
|
|||||||
remainingTime = Math.Max(remainingTime, time);
|
remainingTime = Math.Max(remainingTime, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Attacking(Actor self, Target target) { Uncloak(); }
|
public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { Uncloak(); }
|
||||||
|
|
||||||
public bool Cloaked { get { return remainingTime <= 0; } }
|
public bool Cloaked { get { return remainingTime <= 0; } }
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ namespace OpenRA.Mods.RA
|
|||||||
++ammo;
|
++ammo;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TakeAmmo()
|
public bool TakeAmmo()
|
||||||
{
|
{
|
||||||
if (ammo <= 0) return false;
|
if (ammo <= 0) return false;
|
||||||
@@ -53,7 +54,7 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public int ReloadTimePerAmmo() { return Info.ReloadTicks; }
|
public int ReloadTimePerAmmo() { return Info.ReloadTicks; }
|
||||||
|
|
||||||
public void Attacking(Actor self, Target target) { TakeAmmo(); }
|
public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { TakeAmmo(); }
|
||||||
|
|
||||||
public IEnumerable<PipType> GetPips(Actor self)
|
public IEnumerable<PipType> GetPips(Actor self)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
anim.PlayThen(NormalizeInfantrySequence(self, "heal"), () => State = AnimationState.Idle);
|
anim.PlayThen(NormalizeInfantrySequence(self, "heal"), () => State = AnimationState.Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Attacking(Actor self, Target target, Armament a, Barrel barrel)
|
||||||
|
{
|
||||||
|
Attacking(self, target);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Tick(Actor self)
|
public override void Tick(Actor self)
|
||||||
{
|
{
|
||||||
base.Tick(self);
|
base.Tick(self);
|
||||||
|
|||||||
@@ -11,69 +11,84 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Mods.RA;
|
using OpenRA.Mods.RA;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Render
|
namespace OpenRA.Mods.RA.Render
|
||||||
{
|
{
|
||||||
class WithMuzzleFlashInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<AttackBaseInfo>
|
class WithMuzzleFlashInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<AttackBaseInfo>, Requires<ArmamentInfo>
|
||||||
{
|
{
|
||||||
public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.self); }
|
[Desc("Sequence name to use")]
|
||||||
|
public readonly string Sequence = "muzzle";
|
||||||
|
|
||||||
|
[Desc("Armament name")]
|
||||||
|
public readonly string Armament = "primary";
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class WithMuzzleFlash : INotifyAttack, IRender, ITick
|
class WithMuzzleFlash : INotifyAttack, IRender, ITick
|
||||||
{
|
{
|
||||||
Dictionary<string, AnimationWithOffset> muzzleFlashes = new Dictionary<string, AnimationWithOffset>();
|
readonly WithMuzzleFlashInfo info;
|
||||||
bool isShowing;
|
Dictionary<Barrel, bool> visible = new Dictionary<Barrel, bool>();
|
||||||
|
Dictionary<Barrel, AnimationWithOffset> anims = new Dictionary<Barrel, AnimationWithOffset>();
|
||||||
|
|
||||||
public WithMuzzleFlash(Actor self)
|
public WithMuzzleFlash(Actor self, WithMuzzleFlashInfo info)
|
||||||
{
|
{
|
||||||
|
this.info = info;
|
||||||
var render = self.Trait<RenderSprites>();
|
var render = self.Trait<RenderSprites>();
|
||||||
var facing = self.TraitOrDefault<IFacing>();
|
var facing = self.TraitOrDefault<IFacing>();
|
||||||
|
|
||||||
var arms = self.TraitsImplementing<Armament>();
|
var arm = self.TraitsImplementing<Armament>()
|
||||||
foreach (var a in arms)
|
.Single(a => a.Info.Name == info.Armament);
|
||||||
foreach(var b in a.Barrels)
|
|
||||||
{
|
|
||||||
var barrel = b;
|
|
||||||
var turreted = self.TraitsImplementing<Turreted>()
|
|
||||||
.FirstOrDefault(t => t.Name == a.Info.Turret);
|
|
||||||
var getFacing = turreted != null ? () => turreted.turretFacing :
|
|
||||||
facing != null ? (Func<int>)(() => facing.Facing) : () => 0;
|
|
||||||
|
|
||||||
var muzzleFlash = new Animation(render.GetImage(self), getFacing);
|
foreach (var b in arm.Barrels)
|
||||||
muzzleFlash.Play("muzzle");
|
{
|
||||||
|
var barrel = b;
|
||||||
|
var turreted = self.TraitsImplementing<Turreted>()
|
||||||
|
.FirstOrDefault(t => t.Name == arm.Info.Turret);
|
||||||
|
|
||||||
muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count),
|
var getFacing = turreted != null ? () => turreted.turretFacing :
|
||||||
new AnimationWithOffset(muzzleFlash,
|
facing != null ? (Func<int>)(() => facing.Facing) : () => 0;
|
||||||
() => a.MuzzleOffset(self, barrel),
|
|
||||||
() => !isShowing));
|
var muzzleFlash = new Animation(render.GetImage(self), getFacing);
|
||||||
}
|
visible.Add(barrel, false);
|
||||||
|
anims.Add(barrel,
|
||||||
|
new AnimationWithOffset(muzzleFlash,
|
||||||
|
() => arm.MuzzleOffset(self, barrel),
|
||||||
|
() => !visible[barrel]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Attacking(Actor self, Target target)
|
public void Attacking(Actor self, Target target, Armament a, Barrel barrel)
|
||||||
{
|
{
|
||||||
isShowing = true;
|
if (a.Info.Name != info.Armament)
|
||||||
foreach( var mf in muzzleFlashes.Values )
|
return;
|
||||||
mf.Animation.PlayThen("muzzle", () => isShowing = false);
|
|
||||||
|
visible[barrel] = true;
|
||||||
|
anims[barrel].Animation.PlayThen(info.Sequence, () => visible[barrel] = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr)
|
public IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr)
|
||||||
{
|
{
|
||||||
foreach (var a in muzzleFlashes.Values)
|
foreach (var kv in anims)
|
||||||
{
|
{
|
||||||
if (a.DisableFunc != null && a.DisableFunc())
|
if (!visible[kv.Key])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
foreach (var r in a.Render(self, wr, wr.Palette("effect"), 1f))
|
if (kv.Value.DisableFunc != null && kv.Value.DisableFunc())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var r in kv.Value.Render(self, wr, wr.Palette("effect"), 1f))
|
||||||
yield return r;
|
yield return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
foreach (var a in muzzleFlashes.Values)
|
foreach (var a in anims.Values)
|
||||||
a.Animation.Tick();
|
a.Animation.Tick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.RA
|
|||||||
Panic();
|
Panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Attacking(Actor self, Target target)
|
public void Attacking(Actor self, Target target, Armament a, Barrel barrel)
|
||||||
{
|
{
|
||||||
if (self.World.SharedRandom.Next(100 / Info.AttackPanicChance) == 0)
|
if (self.World.SharedRandom.Next(100 / Info.AttackPanicChance) == 0)
|
||||||
Panic();
|
Panic();
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ namespace OpenRA.Mods.RA
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* lose our disguise if we attack anything */
|
/* lose our disguise if we attack anything */
|
||||||
public void Attacking(Actor self, Target target) { DropDisguise(); }
|
public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { DropDisguise(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class IgnoresDisguiseInfo : TraitInfo<IgnoresDisguise> {}
|
class IgnoresDisguiseInfo : TraitInfo<IgnoresDisguise> {}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Mods.RA.Activities;
|
using OpenRA.Mods.RA.Activities;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
@@ -46,4 +47,5 @@ namespace OpenRA.Mods.RA
|
|||||||
public interface INotifyParachuteLanded { void OnLanded(); }
|
public interface INotifyParachuteLanded { void OnLanded(); }
|
||||||
public interface INotifyTransform { void OnTransform(Actor self); }
|
public interface INotifyTransform { void OnTransform(Actor self); }
|
||||||
public interface INotifyTransformed { void OnTransformed(Actor toActor); }
|
public interface INotifyTransformed { void OnTransformed(Actor toActor); }
|
||||||
|
public interface INotifyAttack { void Attacking(Actor self, Target target, Armament a, Barrel barrel); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ HELI:
|
|||||||
Weapon: HeliAGGun
|
Weapon: HeliAGGun
|
||||||
LocalOffset: 128,-213,-85, 128,213,-85
|
LocalOffset: 128,-213,-85, 128,213,-85
|
||||||
Armament@SECONDARY:
|
Armament@SECONDARY:
|
||||||
|
Name: secondary
|
||||||
Weapon: HeliAAGun
|
Weapon: HeliAAGun
|
||||||
LocalOffset: 128,-213,-85, 128,213,-85
|
LocalOffset: 128,-213,-85, 128,213,-85
|
||||||
AttackHeli:
|
AttackHeli:
|
||||||
@@ -82,7 +83,9 @@ HELI:
|
|||||||
RenderUnit:
|
RenderUnit:
|
||||||
WithRotor:
|
WithRotor:
|
||||||
Offset: 0,0,85
|
Offset: 0,0,85
|
||||||
WithMuzzleFlash:
|
WithMuzzleFlash@PRIMARY:
|
||||||
|
WithMuzzleFlash@SECONDARY:
|
||||||
|
Armament: secondary
|
||||||
WithShadow:
|
WithShadow:
|
||||||
LeavesHusk:
|
LeavesHusk:
|
||||||
HuskActor: HELI.Husk
|
HuskActor: HELI.Husk
|
||||||
|
|||||||
@@ -106,12 +106,15 @@ APC:
|
|||||||
RecoilRecovery: 18
|
RecoilRecovery: 18
|
||||||
LocalOffset: 85,85,299, 85,-85,299
|
LocalOffset: 85,85,299, 85,-85,299
|
||||||
Armament@SECONDARY:
|
Armament@SECONDARY:
|
||||||
|
Name: secondary
|
||||||
Weapon: APCGun.AA
|
Weapon: APCGun.AA
|
||||||
Recoil: 96
|
Recoil: 96
|
||||||
RecoilRecovery: 18
|
RecoilRecovery: 18
|
||||||
LocalOffset: 85,85,299, 85,-85,299
|
LocalOffset: 85,85,299, 85,-85,299
|
||||||
AttackTurreted:
|
AttackTurreted:
|
||||||
WithMuzzleFlash:
|
WithMuzzleFlash@PRIMARY:
|
||||||
|
WithMuzzleFlash@SECONDARY:
|
||||||
|
Armament: secondary
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
WithTurret:
|
WithTurret:
|
||||||
AutoTarget:
|
AutoTarget:
|
||||||
@@ -404,6 +407,7 @@ HTNK:
|
|||||||
Recoil: 170
|
Recoil: 170
|
||||||
RecoilRecovery: 42
|
RecoilRecovery: 42
|
||||||
Armament@SECONDARY:
|
Armament@SECONDARY:
|
||||||
|
Name: secondary
|
||||||
Weapon: MammothMissiles
|
Weapon: MammothMissiles
|
||||||
LocalOffset: -85, 384, 340, -85, -384, 340
|
LocalOffset: -85, 384, 340, -85, -384, 340
|
||||||
LocalYaw: -100, 100
|
LocalYaw: -100, 100
|
||||||
|
|||||||
@@ -248,9 +248,12 @@ Rules:
|
|||||||
Armament@PRIMARY:
|
Armament@PRIMARY:
|
||||||
Weapon:M60mg
|
Weapon:M60mg
|
||||||
Armament@SECONDARY:
|
Armament@SECONDARY:
|
||||||
|
Name: secondary
|
||||||
Weapon:M60mg
|
Weapon:M60mg
|
||||||
AttackFrontal:
|
AttackFrontal:
|
||||||
WithMuzzleFlash:
|
WithMuzzleFlash@PRIMARY:
|
||||||
|
WithMuzzleFlash@SECONDARY:
|
||||||
|
Armament: secondary
|
||||||
MustBeDestroyed:
|
MustBeDestroyed:
|
||||||
-GivesBounty:
|
-GivesBounty:
|
||||||
PT:
|
PT:
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ YAK:
|
|||||||
Weapon: ChainGun.Yak
|
Weapon: ChainGun.Yak
|
||||||
LocalOffset: 256,-213,0
|
LocalOffset: 256,-213,0
|
||||||
Armament@SECONDARY:
|
Armament@SECONDARY:
|
||||||
|
Name: secondary
|
||||||
Weapon: ChainGun.Yak
|
Weapon: ChainGun.Yak
|
||||||
LocalOffset: 256,213,0
|
LocalOffset: 256,213,0
|
||||||
AttackPlane:
|
AttackPlane:
|
||||||
@@ -163,7 +164,9 @@ YAK:
|
|||||||
ReloadTicks: 11
|
ReloadTicks: 11
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
ReturnOnIdle:
|
ReturnOnIdle:
|
||||||
WithMuzzleFlash:
|
WithMuzzleFlash@PRIMARY:
|
||||||
|
WithMuzzleFlash@SECONDARY:
|
||||||
|
Armament: secondary
|
||||||
Contrail:
|
Contrail:
|
||||||
Offset: -853,0,0
|
Offset: -853,0,0
|
||||||
LeavesHusk:
|
LeavesHusk:
|
||||||
@@ -294,6 +297,7 @@ HIND:
|
|||||||
Weapon: ChainGun
|
Weapon: ChainGun
|
||||||
LocalOffset: 85,-213,-85
|
LocalOffset: 85,-213,-85
|
||||||
Armament@SECONDARY:
|
Armament@SECONDARY:
|
||||||
|
Name: secondary
|
||||||
Weapon: ChainGun
|
Weapon: ChainGun
|
||||||
LocalOffset: 85,213,-85
|
LocalOffset: 85,213,-85
|
||||||
AttackHeli:
|
AttackHeli:
|
||||||
@@ -314,7 +318,9 @@ HIND:
|
|||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
Selectable:
|
Selectable:
|
||||||
Bounds: 38,32,0,0
|
Bounds: 38,32,0,0
|
||||||
WithMuzzleFlash:
|
WithMuzzleFlash@PRIMARY:
|
||||||
|
WithMuzzleFlash@SECONDARY:
|
||||||
|
Armament: secondary
|
||||||
LeavesHusk:
|
LeavesHusk:
|
||||||
HuskActor: HIND.Husk
|
HuskActor: HIND.Husk
|
||||||
SmokeTrailWhenDamaged:
|
SmokeTrailWhenDamaged:
|
||||||
|
|||||||
Reference in New Issue
Block a user