Index: binaries/data/mods/public/simulation/ai/petra/config.js =================================================================== --- binaries/data/mods/public/simulation/ai/petra/config.js +++ binaries/data/mods/public/simulation/ai/petra/config.js @@ -63,11 +63,6 @@ "rome": [ "structures/{civ}_army_camp" ], "sele": [ "structures/{civ}_library" ], "spart": [ "structures/{civ}_syssiton", "structures/{civ}_theatron" ] - }, - "naval": { - "default": [], -// "brit": [ "structures/{civ}_crannog" ], - "cart": [ "structures/{civ}_super_dock" ] } }; Index: binaries/data/mods/public/simulation/ai/petra/navalManager.js =================================================================== --- binaries/data/mods/public/simulation/ai/petra/navalManager.js +++ binaries/data/mods/public/simulation/ai/petra/navalManager.js @@ -38,9 +38,8 @@ /** More initialisation for stuff that needs the gameState */ m.NavalManager.prototype.init = function(gameState, deserializing) { - // finished docks - this.docks = gameState.getOwnStructures().filter(API3.Filters.and(API3.Filters.byClassesOr(["Dock", "Shipyard"]), - API3.Filters.not(API3.Filters.isFoundation()))); + // docks + this.docks = gameState.getOwnStructures().filter(API3.Filters.byClassesOr(["Dock", "Shipyard"])); this.docks.registerUpdates(); this.ships = gameState.getOwnUnits().filter(API3.Filters.and(API3.Filters.byClass("Ship"), API3.Filters.not(API3.Filters.byMetadata(PlayerID, "role", "trader")))); @@ -104,16 +103,6 @@ } } - // load units and buildings from the config files - let civ = gameState.getPlayerCiv(); - if (civ in this.Config.buildings.naval) - this.bNaval = this.Config.buildings.naval[civ]; - else - this.bNaval = this.Config.buildings.naval['default']; - - for (let i in this.bNaval) - this.bNaval[i] = gameState.applyCiv(this.bNaval[i]); - if (deserializing) return; @@ -267,9 +256,8 @@ m.NavalManager.prototype.getUnconnectedSeas = function(gameState, region) { let seas = gameState.ai.accessibility.regionLinks[region].slice(); - let docks = gameState.getOwnStructures().filter(API3.Filters.byClass("Dock")); - docks.forEach(function (dock) { - if (dock.getMetadata(PlayerID, "access") !== region) + this.docks.forEach(function (dock) { + if (!dock.hasClass("Dock") || dock.getMetadata(PlayerID, "access") !== region) return; let i = seas.indexOf(dock.getMetadata(PlayerID, "sea")); if (i !== -1) @@ -319,8 +307,8 @@ { // just reset the units onBoard metadata and wait for a new ship to be assigned to this plan plan.units.forEach(function (ent) { - if ((ent.getMetadata(PlayerID, "onBoard") === "onBoard" && ent.position()) || - ent.getMetadata(PlayerID, "onBoard") === shipId) + if (ent.getMetadata(PlayerID, "onBoard") === "onBoard" && ent.position() || + ent.getMetadata(PlayerID, "onBoard") === shipId) ent.setMetadata(PlayerID, "onBoard", undefined); }); plan.needTransportShips = !plan.transportShips.hasEntities(); @@ -511,8 +499,7 @@ { if (queues.ships.hasQueuedUnits()) return; - if (!gameState.getOwnEntitiesByClass("Dock", true).filter(API3.Filters.isBuilt()).hasEntities() && - !gameState.getOwnEntitiesByClass("Shipyard", true).filter(API3.Filters.isBuilt()).hasEntities()) + if (!this.docks.filter(API3.Filters.isBuilt()).hasEntities()) return; // check if we have enough transport ships per region. for (let sea = 0; sea < this.seaShips.length; ++sea) @@ -640,31 +627,24 @@ } if (gameState.currentPhase() < 2 || gameState.getPopulation() < this.Config.Economy.popForTown + 15 || - queues.militaryBuilding.hasQueuedUnits() || this.bNaval.length === 0) + queues.militaryBuilding.hasQueuedUnits()) return; - let docks = gameState.getOwnStructures().filter(API3.Filters.byClass("Dock")); - if (!docks.hasEntities()) + if (!this.docks.filter(API3.Filters.byClass("Dock")).hasEntities() || + this.docks.filter(API3.Filters.byClass("Shipyard")).hasEntities()) return; - let nNaval = 0; - for (let naval of this.bNaval) - nNaval += gameState.countEntitiesAndQueuedByType(naval, true); - - if (nNaval === 0 || (nNaval < this.bNaval.length && gameState.getPopulation() > 120)) - { - for (let naval of this.bNaval) - { - if (gameState.countEntitiesAndQueuedByType(naval, true) < 1 && gameState.ai.HQ.canBuild(gameState, naval)) - { - let wantedLand = {}; - for (let base of gameState.ai.HQ.baseManagers) - if (base.anchor) - wantedLand[base.accessIndex] = true; - let sea = docks.toEntityArray()[0].getMetadata(PlayerID, "sea"); - queues.militaryBuilding.addPlan(new m.ConstructionPlan(gameState, naval, { "land": wantedLand, "sea": sea })); - break; - } - } - } + let template; + if (gameState.ai.HQ.canBuild(gameState, "structures/{civ}_super_dock")) + template = "structures/{civ}_super_dock"; + else if (gameState.ai.HQ.canBuild(gameState, "structures/{civ}_shipyard")) + template = "structures/{civ}_shipyard"; + else + return; + let wantedLand = {}; + for (let base of gameState.ai.HQ.baseManagers) + if (base.anchor) + wantedLand[base.accessIndex] = true; + let sea = this.docks.toEntityArray()[0].getMetadata(PlayerID, "sea"); + queues.militaryBuilding.addPlan(new m.ConstructionPlan(gameState, template, { "land": wantedLand, "sea": sea })); }; /** goal can be either attack (choose ship with best arrowCount) or transport (choose ship with best capacity) */ Index: binaries/data/mods/public/simulation/ai/petra/transportPlan.js =================================================================== --- binaries/data/mods/public/simulation/ai/petra/transportPlan.js +++ binaries/data/mods/public/simulation/ai/petra/transportPlan.js @@ -213,9 +213,7 @@ } if (!base.anchor || !base.anchor.position()) return false; - this.units.forEach(function (ent) { - ent.setMetadata(PlayerID, "base", base.ID); - }); + this.units.forEach(unit => { unit.setMetadata(PlayerID, "base", base.ID); }); } this.endIndex = this.startIndex; this.endPos = base.anchor.position();