From 780982dbe2c30f88d638e5fac3c2eb457b2fb2a0 Mon Sep 17 00:00:00 2001 From: blackhand1001 Date: Tue, 15 Oct 2019 20:17:44 -0400 Subject: [PATCH] Add PlaceDefenseTowardsEnemyChance trait to basebuilderbotmodule Add PlaceDefenseTowardsEnemyChance trait to basebuilderbotmodule. This defeaults to 100 which is the current behavior. This change now allows you to set the chance that bots will place defenses evenly around the base like the AI in stock red alert and Tiberian sun did. --- OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs | 3 +++ .../BotModules/BotModuleLogic/BaseBuilderQueueManager.cs | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs index 6114bd801e..7af6b28bb4 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BaseBuilderBotModule.cs @@ -93,6 +93,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Delay (in ticks) until rechecking for new BaseProviders.")] public readonly int CheckForNewBasesDelay = 1500; + [Desc("Chance that the AI will place the defenses in the direction of the closest enemy building.")] + public readonly int PlaceDefenseTowardsEnemyChance = 100; + [Desc("Minimum range at which to build defensive structures near a combat hotspot.")] public readonly int MinimumDefenseRadius = 5; diff --git a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs index edd5a475cd..dcdb4863fc 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs @@ -134,7 +134,9 @@ namespace OpenRA.Mods.Common.Traits // HACK: HACK HACK HACK // TODO: Derive this from BuildingCommonNames instead var type = BuildingType.Building; - if (world.Map.Rules.Actors[currentBuilding.Item].HasTraitInfo()) + + // Check if Building is a defense and if we should place it towards the enemy or not. + if (world.Map.Rules.Actors[currentBuilding.Item].HasTraitInfo() && world.LocalRandom.Next(100) < baseBuilder.Info.PlaceDefenseTowardsEnemyChance) type = BuildingType.Defense; else if (baseBuilder.Info.RefineryTypes.Contains(world.Map.Rules.Actors[currentBuilding.Item].Name)) type = BuildingType.Refinery;