From e0b77a85178ae4e7a68d2c1858f820ae6f313a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 24 Apr 2016 19:35:17 +0200 Subject: [PATCH] Add configurable DamageState/Type filters to WithSmoke. --- OpenRA.Mods.Common/Traits/Render/WithSmoke.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Render/WithSmoke.cs b/OpenRA.Mods.Common/Traits/Render/WithSmoke.cs index 94323f4fe1..3ad2cfd0a6 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithSmoke.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithSmoke.cs @@ -9,20 +9,30 @@ */ #endregion +using System.Collections.Generic; using OpenRA.Graphics; +using OpenRA.Mods.Common.Warheads; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits.Render { [Desc("Renders an overlay when the actor is taking heavy damage.")] - public class WithSmokeInfo : ITraitInfo, Requires + public class WithSmokeInfo : ITraitInfo, Requires // TODO: rename to WithDamageOverlay { - public readonly string Sequence = "smoke_m"; + public readonly string Sequence = "smoke_m"; // TODO: rename to image [SequenceReference("Sequence")] public readonly string IdleSequence = "idle"; [SequenceReference("Sequence")] public readonly string LoopSequence = "loop"; [SequenceReference("Sequence")] public readonly string EndSequence = "end"; + [Desc("Damage types that this should be used for (defined on the warheads).", + "Leave empty to disable all filtering.")] + public readonly HashSet DamageTypes = new HashSet(); + + [Desc("Trigger when Undamaged, Light, Medium, Heavy, Critical or Dead.")] + public readonly DamageState MinimumDamageState = DamageState.Heavy; + public readonly DamageState MaximumDamageState = DamageState.Dead; + public object Create(ActorInitializer init) { return new WithSmoke(init.Self, this); } } @@ -45,9 +55,14 @@ namespace OpenRA.Mods.Common.Traits.Render public void Damaged(Actor self, AttackInfo e) { + var warhead = e.Warhead as DamageWarhead; + if (info.DamageTypes.Count > 0 && (warhead != null && !warhead.DamageTypes.Overlaps(info.DamageTypes))) + return; + if (isSmoking) return; if (e.Damage < 0) return; /* getting healed */ - if (e.DamageState < DamageState.Heavy) return; + if (e.DamageState < info.MinimumDamageState) return; + if (e.DamageState > info.MaximumDamageState) return; isSmoking = true; anim.PlayThen(info.IdleSequence,