diff --git a/OpenRA.Mods.Common/AI/HackyAI.cs b/OpenRA.Mods.Common/AI/HackyAI.cs index f2cd1f8f396d..a051504d5ed8 100644 --- a/OpenRA.Mods.Common/AI/HackyAI.cs +++ b/OpenRA.Mods.Common/AI/HackyAI.cs @@ -225,6 +225,9 @@ public class BuildingCategories [Desc("What units should the AI have a maximum limit to train.")] public readonly Dictionary UnitLimits = null; + [Desc("Tells AI to don't train from this queue more than specified time at the same time.")] + public readonly Dictionary QueueLimits = null; + [Desc("What buildings to the AI should build.", "What % of the total base must be this type of building.")] public readonly Dictionary BuildingFractions = null; @@ -1402,6 +1405,25 @@ internal IEnumerable FindQueues(string category) .Select(a => a.Trait); } + internal ProductionQueue FindQueue(string category) + { + var queues = FindQueues(category); + + var usedQueues = queues.Where(q => q.CurrentItem() != null); + if (Info.QueueLimits != null && + Info.QueueLimits.ContainsKey(category) && + usedQueues.Count() >= Info.QueueLimits[category]) + return null; + + var freeQueues = queues.Where(q => q.CurrentItem() == null); + if (!freeQueues.Any()) + return null; + + var queue = freeQueues.Shuffle(Random).FirstOrDefault(); + + return queue; + } + void ProductionUnits(Actor self) { // Stop building until economy is restored @@ -1425,7 +1447,7 @@ void ProductionUnits(Actor self) void BuildUnit(string category, bool buildRandom) { // Pick a free queue - var queue = FindQueues(category).FirstOrDefault(q => q.CurrentItem() == null); + var queue = FindQueue(category); if (queue == null) return; @@ -1455,7 +1477,7 @@ void BuildUnit(string category, bool buildRandom) void BuildUnit(string category, string name) { - var queue = FindQueues(category).FirstOrDefault(q => q.CurrentItem() == null); + var queue = FindQueue(category); if (queue == null) return; @@ -1527,7 +1549,7 @@ void Send(UdpClient udp, string msg) void QueryPipe(string category, IEnumerable unit) { // Pick a free queue - var queue = FindQueues(category).FirstOrDefault(q => q.CurrentItem() == null); + var queue = FindQueue(category); if (queue == null) return;