diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj
index 242b6af3e0..c1d5b9637b 100644
--- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj
+++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj
@@ -507,7 +507,7 @@
-
+
diff --git a/OpenRA.Mods.Common/Traits/Upgrades/UpgradeOnDamage.cs b/OpenRA.Mods.Common/Traits/Upgrades/UpgradeOnDamageState.cs
similarity index 64%
rename from OpenRA.Mods.Common/Traits/Upgrades/UpgradeOnDamage.cs
rename to OpenRA.Mods.Common/Traits/Upgrades/UpgradeOnDamageState.cs
index c171a49af8..0fd2711631 100644
--- a/OpenRA.Mods.Common/Traits/Upgrades/UpgradeOnDamage.cs
+++ b/OpenRA.Mods.Common/Traits/Upgrades/UpgradeOnDamageState.cs
@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Applies an upgrade to the actor at specified damage states.")]
- public class UpgradeOnDamageInfo : ITraitInfo, Requires
+ public class UpgradeOnDamageStateInfo : ITraitInfo, Requires, Requires
{
[UpgradeGrantedReference, FieldLoader.Require]
[Desc("The upgrades to grant.")]
@@ -32,41 +32,52 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Are upgrades irrevocable once the conditions have been met?")]
public readonly bool GrantPermanently = false;
- public object Create(ActorInitializer init) { return new UpgradeOnDamage(init.Self, this); }
+ public object Create(ActorInitializer init) { return new UpgradeOnDamageState(init.Self, this); }
}
- public class UpgradeOnDamage : INotifyDamageStateChanged
+ public class UpgradeOnDamageState : INotifyDamageStateChanged, INotifyCreated
{
- readonly UpgradeOnDamageInfo info;
+ readonly UpgradeOnDamageStateInfo info;
readonly UpgradeManager um;
+ readonly Health health;
bool granted;
- public UpgradeOnDamage(Actor self, UpgradeOnDamageInfo info)
+ public UpgradeOnDamageState(Actor self, UpgradeOnDamageStateInfo info)
{
this.info = info;
- um = self.TraitOrDefault();
+ um = self.Trait();
+ health = self.Trait();
+ }
+
+ void INotifyCreated.Created(Actor self)
+ {
+ GrantUpgradeOnValidDamageState(self, health.DamageState);
+ }
+
+ void GrantUpgradeOnValidDamageState(Actor self, DamageState state)
+ {
+ if (!info.ValidDamageStates.HasFlag(state))
+ return;
+
+ granted = true;
+ var rand = Game.CosmeticRandom;
+ var sound = info.EnabledSounds.RandomOrDefault(rand);
+ Game.Sound.Play(sound, self.CenterPosition);
+ foreach (var u in info.Upgrades)
+ um.GrantUpgrade(self, u, this);
}
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
{
- if (um == null)
- return;
-
if (granted && info.GrantPermanently)
return;
- var rand = Game.CosmeticRandom;
- if (!granted && info.ValidDamageStates.HasFlag(e.DamageState) && !info.ValidDamageStates.HasFlag(e.PreviousDamageState))
- {
- granted = true;
- var sound = info.EnabledSounds.RandomOrDefault(rand);
- Game.Sound.Play(sound, self.CenterPosition);
- foreach (var u in info.Upgrades)
- um.GrantUpgrade(self, u, this);
- }
+ if (!granted && !info.ValidDamageStates.HasFlag(e.PreviousDamageState))
+ GrantUpgradeOnValidDamageState(self, health.DamageState);
else if (granted && !info.ValidDamageStates.HasFlag(e.DamageState) && info.ValidDamageStates.HasFlag(e.PreviousDamageState))
{
granted = false;
+ var rand = Game.CosmeticRandom;
var sound = info.DisabledSounds.RandomOrDefault(rand);
Game.Sound.Play(sound, self.CenterPosition);
foreach (var u in info.Upgrades)
diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs
index ecc4c7973f..7a1c039647 100644
--- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs
+++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs
@@ -280,6 +280,17 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
}
+ if (engineVersion < 20160818)
+ {
+ if (depth == 1 && node.Key.StartsWith("UpgradeOnDamage"))
+ {
+ var parts = node.Key.Split('@');
+ node.Key = "UpgradeOnDamageState";
+ if (parts.Length > 1)
+ node.Key += "@" + parts[1];
+ }
+ }
+
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
}
diff --git a/mods/ts/rules/defaults.yaml b/mods/ts/rules/defaults.yaml
index 7cb6c4bc73..eaceb33810 100644
--- a/mods/ts/rules/defaults.yaml
+++ b/mods/ts/rules/defaults.yaml
@@ -397,7 +397,7 @@
WithInfantryBody:
AttackSequence: attack
IdleSequences: idle1,idle2
- UpgradeOnDamage@CRITICAL:
+ UpgradeOnDamageState@CRITICAL:
Upgrades: criticalspeed
ValidDamageStates: Critical
GrantPermanently: true
@@ -476,10 +476,10 @@
Weapons: SmallDebris
Pieces: 3, 7
Range: 2c0, 5c0
- UpgradeOnDamage@DAMAGED:
+ UpgradeOnDamageState@DAMAGED:
Upgrades: damagedspeed
ValidDamageStates: Heavy
- UpgradeOnDamage@CRITICAL:
+ UpgradeOnDamageState@CRITICAL:
Upgrades: criticalspeed
ValidDamageStates: Critical
SpeedMultiplier@DAMAGED: