From a9eca2cf545fc3f957ec8cf2e21f24670d991b57 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Mon, 21 Oct 2019 19:32:08 +0200 Subject: [PATCH] Add support for enabling prone state permanently Negative ProneTime now activates prone state permanently as soon as the trait is enabled. --- .../Traits/Infantry/TakeCover.cs | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs b/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs index 784bb091aa..0af1bb351c 100644 --- a/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs +++ b/OpenRA.Mods.Common/Traits/Infantry/TakeCover.cs @@ -19,14 +19,15 @@ namespace OpenRA.Mods.Common.Traits [Desc("Make the unit go prone when under attack, in an attempt to reduce damage.")] public class TakeCoverInfo : TurretedInfo { - [Desc("How long (in ticks) the actor remains prone.")] + [Desc("How long (in ticks) the actor remains prone.", + "Negative values mean actor remains prone permanently.")] public readonly int Duration = 100; [Desc("Prone movement speed as a percentage of the normal speed.")] public readonly int SpeedModifier = 50; - [FieldLoader.Require] - [Desc("Damage types that trigger prone state. Defined on the warheads.")] + [Desc("Damage types that trigger prone state. Defined on the warheads.", + "If Duration is negative (permanent), you can leave this empty to trigger prone state immediately.")] public readonly BitSet DamageTriggers = default(BitSet); [Desc("Damage modifiers for each damage type (defined on the warheads) while the unit is prone.")] @@ -40,6 +41,14 @@ namespace OpenRA.Mods.Common.Traits public readonly string ProneSequencePrefix = "prone-"; public override object Create(ActorInitializer init) { return new TakeCover(init, this); } + + public override void RulesetLoaded(Ruleset rules, ActorInfo ai) + { + if (Duration > -1 && DamageTriggers.IsEmpty) + throw new YamlException("TakeCover: If Duration isn't negative (permanent), DamageTriggers is required."); + + base.RulesetLoaded(rules, ai); + } } public class TakeCover : Turreted, INotifyDamage, IDamageModifier, ISpeedModifier, ISync, IRenderInfantrySequenceModifier @@ -49,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits [Sync] int remainingDuration = 0; - bool IsProne { get { return !IsTraitDisabled && remainingDuration > 0; } } + bool IsProne { get { return !IsTraitDisabled && remainingDuration != 0; } } bool IRenderInfantrySequenceModifier.IsModifyingSequence { get { return IsProne; } } string IRenderInfantrySequenceModifier.SequencePrefix { get { return info.ProneSequencePrefix; } } @@ -58,6 +67,8 @@ namespace OpenRA.Mods.Common.Traits : base(init, info) { this.info = info; + if (info.Duration < 0 && info.DamageTriggers.IsEmpty) + remainingDuration = info.Duration; } void INotifyDamage.Damaged(Actor self, AttackInfo e) @@ -111,5 +122,14 @@ namespace OpenRA.Mods.Common.Traits { remainingDuration = 0; } + + protected override void TraitEnabled(Actor self) + { + if (info.Duration < 0 && info.DamageTriggers.IsEmpty) + { + remainingDuration = info.Duration; + localOffset = info.ProneOffset; + } + } } }