diff --git a/binaries/data/mods/public/simulation/ai/petra/attackManager.js b/binaries/data/mods/public/simulation/ai/petra/attackManager.js index 482e2eeb4d..5797768a01 100644 --- a/binaries/data/mods/public/simulation/ai/petra/attackManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/attackManager.js @@ -202,7 +202,7 @@ m.AttackManager.prototype.update = function(gameState, queues, events) if (!attackPlan.failed) { if (this.Config.debug > 1) - API3.warn("Headquarters: Rushing plan " + this.totalNumber + " with maxRushes " + this.maxRushes); + API3.warn("Military Manager: Rushing plan " + this.totalNumber + " with maxRushes " + this.maxRushes); this.totalNumber++; attackPlan.init(gameState); this.upcomingAttacks.Rush.push(attackPlan); @@ -458,7 +458,7 @@ m.AttackManager.prototype.getEnemyPlayer = function(gameState, attack) } if (enemyCivCentre) enemyCount += 500; - if (enemyCount < max) + if (!enemyCount || enemyCount < max) continue; max = enemyCount; enemyPlayer = i; @@ -495,7 +495,7 @@ m.AttackManager.prototype.raidTargetEntity = function(gameState, ent) if (!attackPlan.failed) { if (this.Config.debug > 1) - API3.warn("Headquarters: Raiding plan " + this.totalNumber); + API3.warn("Military Manager: Raiding plan " + this.totalNumber); this.totalNumber++; attackPlan.init(gameState); this.upcomingAttacks.Raid.push(attackPlan); diff --git a/binaries/data/mods/public/simulation/ai/petra/config.js b/binaries/data/mods/public/simulation/ai/petra/config.js index 305a3598a8..6b203b118c 100644 --- a/binaries/data/mods/public/simulation/ai/petra/config.js +++ b/binaries/data/mods/public/simulation/ai/petra/config.js @@ -139,14 +139,12 @@ m.Config.prototype.setConfig = function(gameState) // changing settings based on difficulty or personality if (this.difficulty < 2) { - this.Economy.cityPhase = 240000; this.Economy.supportRatio = 0.5; this.Economy.provisionFields = 1; this.Military.numSentryTowers = this.personality.defensive > 0.66 ? 1 : 0; } else if (this.difficulty < 3) { - this.Economy.cityPhase = 1800; this.Economy.supportRatio = 0.4; this.Economy.provisionFields = 1; this.Military.numSentryTowers = this.personality.defensive > 0.66 ? 1 : 0; @@ -205,6 +203,8 @@ m.Config.prototype.setConfig = function(gameState) this.Economy.targetNumWorkers = Math.max(this.Economy.targetNumWorkers, this.Economy.popPhase2); this.Economy.workPhase3 = Math.min(this.Economy.workPhase3, this.Economy.targetNumWorkers); this.Economy.workPhase4 = Math.min(this.Economy.workPhase4, this.Economy.targetNumWorkers); + if (this.difficulty < 2) + this.Economy.workPhase3 = Infinity; // prevent the phasing to city phase if (this.debug < 2) return; diff --git a/binaries/data/mods/public/simulation/ai/petra/garrisonManager.js b/binaries/data/mods/public/simulation/ai/petra/garrisonManager.js index 327a825639..b2d608182b 100644 --- a/binaries/data/mods/public/simulation/ai/petra/garrisonManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/garrisonManager.js @@ -113,18 +113,21 @@ m.GarrisonManager.prototype.update = function(gameState, events) let around = { "defenseStructure": false, "meleeSiege": false, "rangeSiege": false, "unit": false }; for (let ent of gameState.getEnemyEntities().values()) { - if (!ent.position()) + if (ent.hasClass("Structure")) + if (!ent.attackRange("Ranged")) + continue; + else if (ent.hasClass("Unit")) + if (ent.owner() == 0 && (!ent.unitAIState() || ent.unitAIState().split(".")[1] != "COMBAT")) + continue; + else continue; - if (ent.owner() === 0 && (!ent.unitAIState() || ent.unitAIState().split(".")[1] !== "COMBAT")) + if (!ent.position()) continue; let dist = API3.SquareVectorDistance(ent.position(), holder.position()); if (dist > range*range) continue; if (ent.hasClass("Structure")) - { - if (ent.attackRange("Ranged")) // TODO units on wall are not taken into account - around.defenseStructure = true; - } + around.defenseStructure = true; else if (m.isSiegeUnit(ent)) { if (ent.attackTypes().indexOf("Melee") !== -1) @@ -262,6 +265,9 @@ m.GarrisonManager.prototype.keepGarrisoned = function(ent, holder, around) case 'protection': // hurt unit for healing or infantry for defense if (holder.buffHeal() && ent.isHealable() && ent.healthLevel() < this.Config.garrisonHealthLevel.high) return true; + let capture = ent.capturePoints(); + if (capture && capture[PlayerID] / capture.reduce((a, b) => a + b) < 0.8) + return true; if (MatchesClassList(ent.classes(), holder.getGarrisonArrowClasses())) { if (around.unit || around.defenseStructure) diff --git a/binaries/data/mods/public/simulation/ai/petra/headquarters.js b/binaries/data/mods/public/simulation/ai/petra/headquarters.js index e0e57aa033..1fc8131c5b 100644 --- a/binaries/data/mods/public/simulation/ai/petra/headquarters.js +++ b/binaries/data/mods/public/simulation/ai/petra/headquarters.js @@ -786,8 +786,7 @@ m.HQ.prototype.findEconomicCCLocation = function(gameState, template, resource, { // This builds a map. The procedure is fairly simple. It adds the resource maps // (which are dynamically updated and are made so that they will facilitate DP placement) - // Then checks for a good spot in the territory. If none, and town/city phase, checks outside - // The AI will currently not build a CC if it wouldn't connect with an existing CC. + // Then look for a good spot. Engine.ProfileStart("findEconomicCCLocation");