From 0503ed711944200c3022797845e8d1f03f7c2634 Mon Sep 17 00:00:00 2001 From: Squiggles211 Date: Sat, 17 May 2014 02:54:50 -0500 Subject: [PATCH] Fixes inconsistency in reload times for Cnc Aircraft Fixes reload time inconsistency caused by always running the reload counter even when not needing to reload. Also adds the ability to specify that the reload counter restarts when firing a shot. --- AUTHORS | 1 + OpenRA.Mods.RA/LimitedAmmo.cs | 2 ++ OpenRA.Mods.RA/Reloads.cs | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index e405bda155..c7b9a9fd81 100644 --- a/AUTHORS +++ b/AUTHORS @@ -61,6 +61,7 @@ Also thanks to: * Pavlos Touboulidis (pav) * Pizzaoverhead * Psydev + * Raymond Bedrossian (Squiggles211) * Raymond Martineau (mart0258) * Reaperrr * Riderr3 diff --git a/OpenRA.Mods.RA/LimitedAmmo.cs b/OpenRA.Mods.RA/LimitedAmmo.cs index aad0afcf4f..079063deb0 100644 --- a/OpenRA.Mods.RA/LimitedAmmo.cs +++ b/OpenRA.Mods.RA/LimitedAmmo.cs @@ -58,6 +58,8 @@ namespace OpenRA.Mods.RA public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { TakeAmmo(); } + public int GetAmmoCount() { return ammo; } + public IEnumerable GetPips(Actor self) { var pips = Info.PipCount != 0 ? Info.PipCount : Info.Ammo; diff --git a/OpenRA.Mods.RA/Reloads.cs b/OpenRA.Mods.RA/Reloads.cs index 124567da2f..482fa6a6cc 100644 --- a/OpenRA.Mods.RA/Reloads.cs +++ b/OpenRA.Mods.RA/Reloads.cs @@ -20,6 +20,8 @@ namespace OpenRA.Mods.RA public readonly int Count = 0; [Desc("How long it takes to do so.")] public readonly int Period = 50; + [Desc("Whether or not reload counter should be reset when ammo has been fired.")] + public readonly bool ResetOnFire = false; public object Create(ActorInitializer init) { return new Reloads(init.self, this); } } @@ -29,21 +31,33 @@ namespace OpenRA.Mods.RA [Sync] int remainingTicks; ReloadsInfo Info; LimitedAmmo la; + int previousAmmo; public Reloads(Actor self, ReloadsInfo info) { Info = info; remainingTicks = info.Period; la = self.Trait(); + previousAmmo = la.GetAmmoCount(); } public void Tick(Actor self) { - if (--remainingTicks == 0) + if (!la.FullAmmo() && --remainingTicks == 0) { remainingTicks = Info.Period; + for (var i = 0; i < Info.Count; i++) la.GiveAmmo(); + + previousAmmo = la.GetAmmoCount(); + } + + // Resets the tick counter if ammo was fired. + if (Info.ResetOnFire && la.GetAmmoCount() < previousAmmo) + { + remainingTicks = Info.Period; + previousAmmo = la.GetAmmoCount(); } } }