From 2aebb05cd031eac1e9b0367ee545b062e44f805b Mon Sep 17 00:00:00 2001 From: Mustafa Alperen Seki Date: Mon, 21 Jan 2019 14:41:03 +0300 Subject: [PATCH] Implement Building/UnitDelays --- .../Traits/BotModules/BaseBuilderBotModule.cs | 3 +++ .../BotModules/BotModuleLogic/BaseBuilderQueueManager.cs | 6 ++++++ .../Traits/BotModules/UnitBuilderBotModule.cs | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs index 5f37666722..a0fae122f4 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs @@ -119,6 +119,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("What buildings should the AI have a maximum limit to build.")] public readonly Dictionary BuildingLimits = null; + [Desc("When should the AI start building specific buildings.")] + public readonly Dictionary BuildingDelays = null; + public override object Create(ActorInitializer init) { return new BaseBuilderBotModule(init.Self, this); } } diff --git a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs index a9bc36853b..edd5a475cd 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs @@ -292,6 +292,12 @@ namespace OpenRA.Mods.Common.Traits { var name = frac.Key; + // Does this building have initial delay, if so have we passed it? + if (baseBuilder.Info.BuildingDelays != null && + baseBuilder.Info.BuildingDelays.ContainsKey(name) && + baseBuilder.Info.BuildingDelays[name] > world.WorldTick) + continue; + // Can we build this structure? if (!buildableThings.Any(b => b.Name == name)) continue; diff --git a/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs index aee57b5622..b9a715d45a 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/UnitBuilderBotModule.cs @@ -33,6 +33,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("What units should the AI have a maximum limit to train.")] public readonly Dictionary UnitLimits = null; + [Desc("When should the AI start train specific units.")] + public readonly Dictionary UnitDelays = null; + public override object Create(ActorInitializer init) { return new UnitBuilderBotModule(init.Self, this); } } @@ -118,6 +121,11 @@ namespace OpenRA.Mods.Common.Traits if (Info.UnitsToBuild != null && !Info.UnitsToBuild.ContainsKey(name)) return; + if (Info.UnitDelays != null && + Info.UnitDelays.ContainsKey(name) && + Info.UnitDelays[name] > world.WorldTick) + return; + if (Info.UnitLimits != null && Info.UnitLimits.ContainsKey(name) && world.Actors.Count(a => a.Owner == player && a.Info.Name == name) >= Info.UnitLimits[name])