diff --git a/binaries/data/mods/public/simulation/ai/petra/attackManager.js b/binaries/data/mods/public/simulation/ai/petra/attackManager.js index efa92d4fa6..3acf2704cf 100644 --- a/binaries/data/mods/public/simulation/ai/petra/attackManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/attackManager.js @@ -27,19 +27,19 @@ m.AttackManager.prototype.init = function(gameState) this.outOfPlan.registerUpdates(); }; -m.AttackManager.prototype.setRushes = function() +m.AttackManager.prototype.setRushes = function(allowed) { - if (this.Config.personality.aggressive > 0.8) + if (this.Config.personality.aggressive > 0.8 && allowed > 2) { this.maxRushes = 3 this.rushSize = [ 16, 22, 28 ]; } - else if (this.Config.personality.aggressive > 0.6) + else if (this.Config.personality.aggressive > 0.6 && allowed > 1) { this.maxRushes = 2; this.rushSize = [ 18, 28 ]; } - else if (this.Config.personality.aggressive > 0.3) + else if (this.Config.personality.aggressive > 0.3 && allowed > 0) { this.maxRushes = 1; this.rushSize = [ 24 ]; @@ -83,6 +83,7 @@ m.AttackManager.prototype.checkEvents = function(gameState, events) continue; } attack.targetPos = attack.target.position(); + attack.resetPath(gameState); } if (attack.targetPlayer && attack.targetPlayer === targetPlayer) available += attack.unitCollection.length; diff --git a/binaries/data/mods/public/simulation/ai/petra/attackPlan.js b/binaries/data/mods/public/simulation/ai/petra/attackPlan.js index 1fa62df587..840b3f7276 100644 --- a/binaries/data/mods/public/simulation/ai/petra/attackPlan.js +++ b/binaries/data/mods/public/simulation/ai/petra/attackPlan.js @@ -402,13 +402,7 @@ m.AttackPlan.prototype.updatePreparation = function(gameState) } } // reset the path so that we recompute it for this new target - this.path = undefined; - if (!this.pathFinder) - { - this.pathFinder = new API3.aStarPath(gameState, false, false, this.targetPlayer); - this.pathWidth = 6; - this.pathSampling = 2; - } + this.resetPath(gameState); } // when we have a target, we path to it. @@ -1703,6 +1697,18 @@ m.AttackPlan.prototype.removeUnit = function(ent, update) this.unitCollection.updateEnt(ent); }; +// Reset the path so that it can be recomputed for a new target +m.AttackPlan.prototype.resetPath = function(gameState) +{ + this.path = undefined; + if (!this.pathFinder) + { + this.pathFinder = new API3.aStarPath(gameState, false, false, this.targetPlayer); + this.pathWidth = 6; + this.pathSampling = 2; + } +}; + m.AttackPlan.prototype.checkEvents = function(gameState, events) { let renameEvents = events["EntityRenamed"]; diff --git a/binaries/data/mods/public/simulation/ai/petra/defenseManager.js b/binaries/data/mods/public/simulation/ai/petra/defenseManager.js index bb9d263ea7..48eec8423a 100644 --- a/binaries/data/mods/public/simulation/ai/petra/defenseManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/defenseManager.js @@ -312,11 +312,10 @@ m.DefenseManager.prototype.assignDefenders = function(gameState) aMin = a; distMin = dist; } - if (aMin === undefined) - { - for (var a = 0; a < armiesNeeding.length; ++a) - API3.warn(" defense/armiesNeeding " + uneval(armiesNeeding[a]["need"])); - } + + // if outside our territory (helping an ally or attacking a cc foundation), keep some troops in backup + if (i < 12 && this.territoryMap.getOwner(armiesNeeding[aMin]["army"].foePosition) !== PlayerID) + continue; var str = m.getMaxStrength(ent); armiesNeeding[aMin]["need"] -= str; diff --git a/binaries/data/mods/public/simulation/ai/petra/headquarters.js b/binaries/data/mods/public/simulation/ai/petra/headquarters.js index e8ae746d27..4c7fe53b52 100644 --- a/binaries/data/mods/public/simulation/ai/petra/headquarters.js +++ b/binaries/data/mods/public/simulation/ai/petra/headquarters.js @@ -248,7 +248,7 @@ m.HQ.prototype.checkEvents = function (gameState, events, queues) m.getBestBase(ent, gameState).assignEntity(gameState, ent); if (ent.hasTerritoryInfluence()) this.updateTerritories(gameState); - if (ent.decaying && ent.isGarrisonHolder()) + if (ent.decaying() && ent.isGarrisonHolder()) this.garrisonManager.addDecayingStructure(gameState, evt.entity); } } diff --git a/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js b/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js index dd60f08a55..0a7c322798 100644 --- a/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js +++ b/binaries/data/mods/public/simulation/ai/petra/startingStrategy.js @@ -439,11 +439,14 @@ m.HQ.prototype.configFirstBase = function(gameState) } } if (this.Config.debug > 1) - API3.warn("startingWood: " + startingWood + "(cut at 8500 for no rush and 6000 for saveResources)"); + API3.warn("startingWood: " + startingWood + " (cut at 8500 for no rush and 6000 for saveResources)"); if (startingWood < 6000) this.saveResources = true; if (startingWood > 8500 && this.canBuildUnits) - this.attackManager.setRushes(); + { + let allowed = Math.ceil((startingWood - 8500) / 3000); + this.attackManager.setRushes(allowed); + } // immediatly build a wood dropsite if possible. var template = gameState.applyCiv("structures/{civ}_storehouse");