From 1bb988512f9bb82b3087c464b75010afadff12b0 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Tue, 25 Jun 2019 02:50:34 +0200 Subject: [PATCH] Move AmmoPool RemainingTicks reset to Rearmable This is a better place to do this than the Resupply activity. --- OpenRA.Mods.Common/Activities/Resupply.cs | 7 ------- OpenRA.Mods.Common/Traits/Rearmable.cs | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/OpenRA.Mods.Common/Activities/Resupply.cs b/OpenRA.Mods.Common/Activities/Resupply.cs index e2e3ee83f7..154690a21b 100644 --- a/OpenRA.Mods.Common/Activities/Resupply.cs +++ b/OpenRA.Mods.Common/Activities/Resupply.cs @@ -135,13 +135,6 @@ namespace OpenRA.Mods.Common.Activities actualResupplyStarted = true; foreach (var notifyResupply in notifyResupplies) notifyResupply.BeforeResupply(host.Actor, self, activeResupplyTypes); - - // Reset the ReloadDelay to avoid any issues with early cancellation - // from previous reload attempts (explicit order, host building died, etc). - // HACK: this really shouldn't be managed from here - if (activeResupplyTypes.HasFlag(ResupplyType.Rearm)) - foreach (var pool in rearmable.RearmableAmmoPools) - pool.RemainingTicks = pool.Info.ReloadDelay; } if (activeResupplyTypes.HasFlag(ResupplyType.Repair)) diff --git a/OpenRA.Mods.Common/Traits/Rearmable.cs b/OpenRA.Mods.Common/Traits/Rearmable.cs index 16affa6624..c78fdc3fae 100644 --- a/OpenRA.Mods.Common/Traits/Rearmable.cs +++ b/OpenRA.Mods.Common/Traits/Rearmable.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits public object Create(ActorInitializer init) { return new Rearmable(this); } } - public class Rearmable : INotifyCreated + public class Rearmable : INotifyCreated, INotifyResupply { public readonly RearmableInfo Info; @@ -43,5 +43,18 @@ namespace OpenRA.Mods.Common.Traits { RearmableAmmoPools = self.TraitsImplementing().Where(p => Info.AmmoPools.Contains(p.Info.Name)).ToArray(); } + + void INotifyResupply.BeforeResupply(Actor self, Actor target, ResupplyType types) + { + if (!types.HasFlag(ResupplyType.Rearm)) + return; + + // Reset the ReloadDelay to avoid any issues with early cancellation + // from previous reload attempts (explicit order, host building died, etc). + foreach (var pool in RearmableAmmoPools) + pool.RemainingTicks = pool.Info.ReloadDelay; + } + + void INotifyResupply.ResupplyTick(Actor self, Actor target, ResupplyType types) { } } }