diff --git a/OpenRA.Mods.Common/AI/BaseBuilder.cs b/OpenRA.Mods.Common/AI/BaseBuilder.cs index 84bac838d3..aa17421c22 100644 --- a/OpenRA.Mods.Common/AI/BaseBuilder.cs +++ b/OpenRA.Mods.Common/AI/BaseBuilder.cs @@ -35,6 +35,7 @@ namespace OpenRA.Mods.Common.AI int checkForBasesTicks; int cachedBases; int cachedBuildings; + int minimumExcessPower; enum Water { @@ -54,6 +55,7 @@ namespace OpenRA.Mods.Common.AI playerResources = pr; this.category = category; failRetryTicks = ai.Info.StructureProductionResumeDelay; + minimumExcessPower = ai.Info.MinimumExcessPower; } public void Tick() @@ -100,6 +102,8 @@ namespace OpenRA.Mods.Common.AI return; playerBuildings = world.ActorsHavingTrait().Where(a => a.Owner == player).ToArray(); + var excessPowerBonus = ai.Info.ExcessPowerIncrement * (playerBuildings.Count() / ai.Info.ExcessPowerIncreaseThreshold.Clamp(1, int.MaxValue)); + minimumExcessPower = (ai.Info.MinimumExcessPower + excessPowerBonus).Clamp(ai.Info.MinimumExcessPower, ai.Info.MaximumExcessPower); var active = false; foreach (var queue in ai.FindQueues(category)) @@ -197,7 +201,7 @@ namespace OpenRA.Mods.Common.AI bool HasSufficientPowerForActor(ActorInfo actorInfo) { return (actorInfo.TraitInfos().Where(i => i.EnabledByDefault) - .Sum(p => p.Amount) + playerPower.ExcessPower) >= ai.Info.MinimumExcessPower; + .Sum(p => p.Amount) + playerPower.ExcessPower) >= minimumExcessPower; } ActorInfo ChooseBuildingToBuild(ProductionQueue queue) @@ -209,7 +213,7 @@ namespace OpenRA.Mods.Common.AI a => a.TraitInfos().Where(i => i.EnabledByDefault).Sum(p => p.Amount)); // First priority is to get out of a low power situation - if (playerPower.ExcessPower < ai.Info.MinimumExcessPower) + if (playerPower.ExcessPower < minimumExcessPower) { if (power != null && power.TraitInfos().Where(i => i.EnabledByDefault).Sum(p => p.Amount) > 0) { @@ -314,7 +318,7 @@ namespace OpenRA.Mods.Common.AI // Will this put us into low power? var actor = world.Map.Rules.Actors[name]; - if (playerPower.ExcessPower < ai.Info.MinimumExcessPower || !HasSufficientPowerForActor(actor)) + if (playerPower.ExcessPower < minimumExcessPower || !HasSufficientPowerForActor(actor)) { // Try building a power plant instead if (power != null && power.TraitInfos().Where(i => i.EnabledByDefault).Sum(pi => pi.Amount) > 0) diff --git a/OpenRA.Mods.Common/AI/HackyAI.cs b/OpenRA.Mods.Common/AI/HackyAI.cs index 649441977d..136be68b1f 100644 --- a/OpenRA.Mods.Common/AI/HackyAI.cs +++ b/OpenRA.Mods.Common/AI/HackyAI.cs @@ -96,6 +96,15 @@ namespace OpenRA.Mods.Common.AI [Desc("Minimum excess power the AI should try to maintain.")] public readonly int MinimumExcessPower = 0; + [Desc("Increase maintained excess power by this amount for every ExcessPowerIncreaseThreshold of base buildings.")] + public readonly int ExcessPowerIncrement = 0; + + [Desc("Increase maintained excess power by ExcessPowerIncrement for every N base buildings.")] + public readonly int ExcessPowerIncreaseThreshold = 1; + + [Desc("The targeted excess power the AI tries to maintain cannot rise above this.")] + public readonly int MaximumExcessPower = 0; + [Desc("Additional delay (in ticks) between structure production checks when there is no active production.", "StructureProductionRandomBonusDelay is added to this.")] public readonly int StructureProductionInactiveDelay = 125; @@ -193,7 +202,7 @@ namespace OpenRA.Mods.Common.AI public readonly UnitCategories UnitsCommonNames; [Desc("Tells the AI what building types fall under the same common name.", - "Possible keys are ConstructionYard, Power, Refinery, Silo , Barracks, Production, VehiclesFactory, NavalProduction.")] + "Possible keys are ConstructionYard, Power, Refinery, Silo, Barracks, Production, VehiclesFactory, NavalProduction.")] [FieldLoader.LoadUsing("LoadBuildingCategories", true)] public readonly BuildingCategories BuildingCommonNames;