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 checkForBasesTicks;
|
||||||
int cachedBases;
|
int cachedBases;
|
||||||
int cachedBuildings;
|
int cachedBuildings;
|
||||||
|
int minimumExcessPower;
|
||||||
|
|
||||||
enum Water
|
enum Water
|
||||||
{
|
{
|
||||||
@@ -54,6 +55,7 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
playerResources = pr;
|
playerResources = pr;
|
||||||
this.category = category;
|
this.category = category;
|
||||||
failRetryTicks = ai.Info.StructureProductionResumeDelay;
|
failRetryTicks = ai.Info.StructureProductionResumeDelay;
|
||||||
|
minimumExcessPower = ai.Info.MinimumExcessPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick()
|
public void Tick()
|
||||||
@@ -100,6 +102,8 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
playerBuildings = world.ActorsHavingTrait<Building>().Where(a => a.Owner == player).ToArray();
|
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;
|
var active = false;
|
||||||
foreach (var queue in ai.FindQueues(category))
|
foreach (var queue in ai.FindQueues(category))
|
||||||
@@ -197,7 +201,7 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
bool HasSufficientPowerForActor(ActorInfo actorInfo)
|
bool HasSufficientPowerForActor(ActorInfo actorInfo)
|
||||||
{
|
{
|
||||||
return (actorInfo.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault)
|
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)
|
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));
|
a => a.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault).Sum(p => p.Amount));
|
||||||
|
|
||||||
// First priority is to get out of a low power situation
|
// 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)
|
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?
|
// Will this put us into low power?
|
||||||
var actor = world.Map.Rules.Actors[name];
|
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
|
// Try building a power plant instead
|
||||||
if (power != null && power.TraitInfos<PowerInfo>().Where(i => i.EnabledByDefault).Sum(pi => pi.Amount) > 0)
|
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.")]
|
[Desc("Minimum excess power the AI should try to maintain.")]
|
||||||
public readonly int MinimumExcessPower = 0;
|
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.",
|
[Desc("Additional delay (in ticks) between structure production checks when there is no active production.",
|
||||||
"StructureProductionRandomBonusDelay is added to this.")]
|
"StructureProductionRandomBonusDelay is added to this.")]
|
||||||
public readonly int StructureProductionInactiveDelay = 125;
|
public readonly int StructureProductionInactiveDelay = 125;
|
||||||
|
|||||||
Reference in New Issue
Block a user