From f5d788f4fc39a4c8fff360de6c91db0774a685f6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 31 Dec 2018 21:23:12 +0000 Subject: [PATCH] Prevent unit requests from stacking during production. --- .../Traits/BotModules/McvManagerBotModule.cs | 3 ++- .../Traits/BotModules/UnitBuilderBotModule.cs | 7 +++++-- OpenRA.Mods.Common/TraitsInterfaces.cs | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs index c035738730..372c906def 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/McvManagerBotModule.cs @@ -118,7 +118,8 @@ namespace OpenRA.Mods.Common.Traits if (unitBuilder != null) { var mcvInfo = AIUtils.GetInfoByCommonName(Info.McvTypes, player); - unitBuilder.RequestUnitProduction(bot, mcvInfo.Name); + if (unitBuilder.RequestedProductionCount(bot, mcvInfo.Name) == 0) + unitBuilder.RequestUnitProduction(bot, mcvInfo.Name); } } } diff --git a/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs index ca9bf31fdf..eb5137d195 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs @@ -9,8 +9,6 @@ */ #endregion -using System; -using System.Collections; using System.Collections.Generic; using System.Linq; using OpenRA.Traits; @@ -96,6 +94,11 @@ namespace OpenRA.Mods.Common.Traits queuedBuildRequests.Add(requestedActor); } + int IBotRequestUnitProduction.RequestedProductionCount(IBot bot, string requestedActor) + { + return queuedBuildRequests.Count(r => r == requestedActor); + } + void BuildUnit(IBot bot, string category, bool buildRandom) { // Pick a free queue diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 6a4df6063f..63bc6ee49b 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -472,6 +472,7 @@ namespace OpenRA.Mods.Common.Traits public interface IBotRequestUnitProduction { void RequestUnitProduction(IBot bot, string requestedActor); + int RequestedProductionCount(IBot bot, string requestedActor); } [RequireExplicitImplementation]