Add more configurability to AI MinimumExcessPower logic
Allows to scale the targeted minimum excess with building count as well as define a maximum cap to avoid overproducing powerplants.
This commit is contained in:
@@ -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<Building>().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<PowerInfo>().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<PowerInfo>().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<PowerInfo>().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<PowerInfo>().Where(i => i.EnabledByDefault).Sum(pi => pi.Amount) > 0)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user