From 67e3c74d315391cae307076656b2bd66fd41a573 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 27 Sep 2014 08:17:26 +1200 Subject: [PATCH] Allow armaments to be enabled/disabled by upgrades. --- OpenRA.Mods.RA/Armament.cs | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.RA/Armament.cs b/OpenRA.Mods.RA/Armament.cs index 6276044cc4..9f37a30d61 100644 --- a/OpenRA.Mods.RA/Armament.cs +++ b/OpenRA.Mods.RA/Armament.cs @@ -53,10 +53,16 @@ namespace OpenRA.Mods.RA [Desc("Use multiple muzzle images if non-zero")] public readonly int MuzzleSplitFacings = 0; + [Desc("Enable only if this upgrade is enabled.")] + public readonly string RequiresUpgrade = null; + + [Desc("Disable if this upgrade is enabled.")] + public readonly string RestrictedByUpgrade = null; + public object Create(ActorInitializer init) { return new Armament(init.self, this); } } - public class Armament : ITick, IExplodeModifier + public class Armament : ITick, IExplodeModifier, IUpgradable { public readonly ArmamentInfo Info; public readonly WeaponInfo Weapon; @@ -72,6 +78,9 @@ namespace OpenRA.Mods.RA public int FireDelay { get; private set; } public int Burst { get; private set; } + bool requiresUpgrade; + bool restrictedByUpgrade; + public Armament(Actor self, ArmamentInfo info) { this.self = self; @@ -99,12 +108,32 @@ namespace OpenRA.Mods.RA barrels.Add(new Barrel { Offset = WVec.Zero, Yaw = WAngle.Zero }); Barrels = barrels.ToArray(); + + // Disable if an upgrade is required + requiresUpgrade = info.RequiresUpgrade != null; + } + + public bool AcceptsUpgrade(string type) + { + return type == Info.RequiresUpgrade || type == Info.RestrictedByUpgrade; + } + + public void UpgradeAvailable(Actor self, string type, bool available) + { + if (type == Info.RequiresUpgrade) + requiresUpgrade = !available; + else if (type == Info.RestrictedByUpgrade) + restrictedByUpgrade = available; } public void Tick(Actor self) { + if (requiresUpgrade || restrictedByUpgrade) + return; + if (FireDelay > 0) --FireDelay; + Recoil = new WRange(Math.Max(0, Recoil.Range - Info.RecoilRecovery.Range)); for (var i = 0; i < delayedActions.Count; i++) @@ -130,7 +159,7 @@ namespace OpenRA.Mods.RA // The world coordinate model uses Actor.Orientation public Barrel CheckFire(Actor self, IFacing facing, Target target) { - if (FireDelay > 0) + if (IsReloading) return null; if (limitedAmmo.Value != null && !limitedAmmo.Value.HasAmmo()) @@ -197,7 +226,7 @@ namespace OpenRA.Mods.RA return barrel; } - public bool IsReloading { get { return FireDelay > 0; } } + public bool IsReloading { get { return FireDelay > 0 || requiresUpgrade || restrictedByUpgrade; } } public bool ShouldExplode(Actor self) { return !IsReloading; } public WVec MuzzleOffset(Actor self, Barrel b)