From 865d8d77e081b094c5202f23c4bd63ab0be5fd12 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 7 Sep 2019 14:43:44 +0100 Subject: [PATCH] Expire invalid instances from the SupportPowerBotModule cache. --- .../Traits/BotModules/SupportPowerBotModule.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs index 1b6a75262f..ae217c882f 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/SupportPowerBotModule.cs @@ -40,9 +40,10 @@ namespace OpenRA.Mods.Common.Traits { readonly World world; readonly Player player; + readonly Dictionary waitingPowers = new Dictionary(); + readonly Dictionary powerDecisions = new Dictionary(); + readonly List stalePowers = new List(); SupportPowerManager supportPowerManager; - Dictionary waitingPowers = new Dictionary(); - Dictionary powerDecisions = new Dictionary(); public SupportPowerBotModule(Actor self, SupportPowerBotModuleInfo info) : base(info) @@ -108,6 +109,13 @@ namespace OpenRA.Mods.Common.Traits bot.QueueOrder(new Order(sp.Key, supportPowerManager.Self, Target.FromCell(world, attackLocation.Value), false) { SuppressVisualFeedback = true }); } } + + // Remove stale powers + stalePowers.AddRange(waitingPowers.Keys.Where(wp => !supportPowerManager.Powers.ContainsKey(wp.Key))); + foreach (var p in stalePowers) + waitingPowers.Remove(p); + + stalePowers.Clear(); } /// Scans the map in chunks, evaluating all actors in each.