From 372d03c320224debc747fc62797af30b39b4dde6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 26 Sep 2014 22:20:41 +1200 Subject: [PATCH] Convert SelfHealing to upgrades. --- .../UtilityCommands/UpgradeRules.cs | 12 ++++ OpenRA.Mods.RA/SelfHealing.cs | 70 +++++++++---------- mods/cnc/rules/defaults.yaml | 5 +- mods/cnc/rules/player.yaml | 4 +- mods/cnc/rules/tech.yaml | 2 - mods/ra/rules/civilian.yaml | 2 - mods/ra/rules/defaults.yaml | 5 +- mods/ra/rules/player.yaml | 3 +- 8 files changed, 59 insertions(+), 44 deletions(-) diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs index 7113c037d3..3296d68e50 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeRules.cs @@ -563,6 +563,18 @@ namespace OpenRA.Mods.Common.UtilityCommands } } + if (engineVersion < 20140927) + { + if (depth == 0) + node.Value.Nodes.RemoveAll(n => n.Key == "SelfHealingTech"); + + if (depth == 2 && node.Key == "RequiresTech" && parentKey.StartsWith("SelfHealing")) + { + node.Key = "RequiresUpgrade"; + node.Value.Value = "selfhealing-needs-reconfiguration"; + } + } + UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); } } diff --git a/OpenRA.Mods.RA/SelfHealing.cs b/OpenRA.Mods.RA/SelfHealing.cs index 6a97d0e9f8..88b5c7da33 100644 --- a/OpenRA.Mods.RA/SelfHealing.cs +++ b/OpenRA.Mods.RA/SelfHealing.cs @@ -21,31 +21,49 @@ namespace OpenRA.Mods.RA public readonly float HealIfBelow = .5f; public readonly int DamageCooldown = 0; - [Desc("The Type defined by SelfHealingTech required to enable this.")] - public readonly string RequiresTech = null; + [Desc("Enable only if this upgrade is enabled.")] + public readonly string RequiresUpgrade = null; - public virtual object Create(ActorInitializer init) { return new SelfHealing(this); } + public virtual object Create(ActorInitializer init) { return new SelfHealing(init.self, this); } } - class SelfHealing : ITick, ISync, INotifyDamage + class SelfHealing : ITick, ISync, INotifyDamage, IUpgradable { + readonly SelfHealingInfo info; + readonly Health health; + [Sync] int ticks; [Sync] int damageTicks; - SelfHealingInfo Info; + [Sync] bool disabled; - public SelfHealing(SelfHealingInfo info) { Info = info; } + + public SelfHealing(Actor self, SelfHealingInfo info) + { + this.info = info; + + health = self.Trait(); + + // Disable if an upgrade is required + disabled = info.RequiresUpgrade != null; + } + + public bool AcceptsUpgrade(string type) + { + return type == info.RequiresUpgrade; + } + + public void UpgradeAvailable(Actor self, string type, bool available) + { + if (type == info.RequiresUpgrade) + disabled = !available; + } public void Tick(Actor self) { - if (self.IsDead()) + if (self.IsDead() || disabled) return; - if (Info.RequiresTech != null && !self.World.ActorsWithTrait() - .Any(a => !a.Actor.IsDead() && a.Actor.Owner.IsAlliedWith(self.Owner) && Info.RequiresTech == a.Trait.Type)) - return; - - var health = self.Trait(); - if (health.HP >= Info.HealIfBelow*health.MaxHP) + if (health.HP >= info.HealIfBelow * health.MaxHP) return; if (damageTicks > 0) @@ -56,35 +74,15 @@ namespace OpenRA.Mods.RA if (--ticks <= 0) { - ticks = Info.Ticks; - self.InflictDamage(self, -Info.Step, null); + ticks = info.Ticks; + self.InflictDamage(self, -info.Step, null); } } public void Damaged(Actor self, AttackInfo e) { if (e.Damage > 0) - damageTicks = Info.DamageCooldown; - } - } - - [Desc("Attach this to an actor required as prerequisite for all owned units to regenerate health.")] - class SelfHealingTechInfo : ITraitInfo - { - public readonly string Type = null; - - public object Create(ActorInitializer init) { return new SelfHealingTech(this); } - } - - class SelfHealingTech - { - public string Type { get { return info.Type; } } - - readonly SelfHealingTechInfo info; - - public SelfHealingTech(SelfHealingTechInfo info) - { - this.info = info; + damageTicks = info.DamageCooldown; } } } diff --git a/mods/cnc/rules/defaults.yaml b/mods/cnc/rules/defaults.yaml index bb1ae62efd..4c95ed6a63 100644 --- a/mods/cnc/rules/defaults.yaml +++ b/mods/cnc/rules/defaults.yaml @@ -177,7 +177,10 @@ Ticks: 100 HealIfBelow: 1 DamageCooldown: 125 - RequiresTech: InfantryHealing + RequiresUpgrade: hospitalheal + GlobalUpgradable: + Upgrades: hospitalheal + Prerequisites: hosp UpdatesPlayerStatistics: Huntable: LuaScriptEvents: diff --git a/mods/cnc/rules/player.yaml b/mods/cnc/rules/player.yaml index f177d84ce9..cafc6c2c1a 100644 --- a/mods/cnc/rules/player.yaml +++ b/mods/cnc/rules/player.yaml @@ -30,4 +30,6 @@ Player: Prerequisites: techlevel.low, techlevel.medium, techlevel.high ProvidesTechPrerequisite@all: Name: Unrestricted - Prerequisites: techlevel.low, techlevel.medium, techlevel.high, techlevel.superweapons \ No newline at end of file + Prerequisites: techlevel.low, techlevel.medium, techlevel.high, techlevel.superweapons + GlobalUpgradeManager: + diff --git a/mods/cnc/rules/tech.yaml b/mods/cnc/rules/tech.yaml index 40a3843308..903a86ead1 100644 --- a/mods/cnc/rules/tech.yaml +++ b/mods/cnc/rules/tech.yaml @@ -27,8 +27,6 @@ HOSP: Dimensions: 2,2 Health: HP: 1000 - SelfHealingTech: - Type: InfantryHealing Tooltip: Name: Hospital LeavesHusk: diff --git a/mods/ra/rules/civilian.yaml b/mods/ra/rules/civilian.yaml index 29caa4118a..8f9fba2d45 100644 --- a/mods/ra/rules/civilian.yaml +++ b/mods/ra/rules/civilian.yaml @@ -83,8 +83,6 @@ HOSP: ExternalCapturable: ExternalCapturableBar: EngineerRepairable: - SelfHealingTech: - Type: InfantryHealing Tooltip: Name: Hospital RevealsShroud: diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index 7cb47ff0ab..af8fe35eab 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -166,7 +166,10 @@ Ticks: 100 HealIfBelow: 1 DamageCooldown: 125 - RequiresTech: InfantryHealing + RequiresUpgrade: hospitalheal + GlobalUpgradable: + Upgrades: hospitalheal + Prerequisites: hosp Huntable: LuaScriptEvents: ScriptTriggers: diff --git a/mods/ra/rules/player.yaml b/mods/ra/rules/player.yaml index fdf86884bc..de6c0616b3 100644 --- a/mods/ra/rules/player.yaml +++ b/mods/ra/rules/player.yaml @@ -71,4 +71,5 @@ Player: Prerequisites: techlevel.infonly, techlevel.low, techlevel.medium ProvidesTechPrerequisite@unrestricted: Name: Unrestricted - Prerequisites: techlevel.infonly, techlevel.low, techlevel.medium, techlevel.unrestricted \ No newline at end of file + Prerequisites: techlevel.infonly, techlevel.low, techlevel.medium, techlevel.unrestricted + GlobalUpgradeManager: