diff --git a/binaries/data/mods/public/simulation/ai/petra/baseManager.js b/binaries/data/mods/public/simulation/ai/petra/baseManager.js index b372b1e857..0f599ce027 100644 --- a/binaries/data/mods/public/simulation/ai/petra/baseManager.js +++ b/binaries/data/mods/public/simulation/ai/petra/baseManager.js @@ -48,10 +48,12 @@ m.BaseManager.prototype.init = function(gameState, state) this.units = gameState.getOwnUnits().filter(API3.Filters.byMetadata(PlayerID, "base", this.ID)); this.workers = this.units.filter(API3.Filters.byMetadata(PlayerID, "role", "worker")); this.buildings = gameState.getOwnStructures().filter(API3.Filters.byMetadata(PlayerID, "base", this.ID)); + this.mobileDropsites = this.units.filter(API3.Filters.isDropsite()); this.units.registerUpdates(); this.workers.registerUpdates(); this.buildings.registerUpdates(); + this.mobileDropsites.registerUpdates(); // array of entity IDs, with each being this.dropsites = {}; @@ -983,6 +985,8 @@ m.BaseManager.prototype.update = function(gameState, queues, events) this.reassignIdleWorkers(gameState); for (let ent of this.workers.values()) this.workerObject.update(gameState, ent); + for (let ent of this.mobileDropsites.values()) + this.workerObject.moveToGatherer(gameState, ent, false); } return false; } @@ -1031,6 +1035,8 @@ m.BaseManager.prototype.update = function(gameState, queues, events) this.reassignIdleWorkers(gameState); for (let ent of this.workers.values()) this.workerObject.update(gameState, ent); + for (let ent of this.mobileDropsites.values()) + this.workerObject.moveToGatherer(gameState, ent, false); return true; } @@ -1070,6 +1076,8 @@ m.BaseManager.prototype.update = function(gameState, queues, events) // check if workers can find something useful to do for (let ent of this.workers.values()) this.workerObject.update(gameState, ent); + for (let ent of this.mobileDropsites.values()) + this.workerObject.moveToGatherer(gameState, ent, false); Engine.ProfileStop(); return true; diff --git a/binaries/data/mods/public/simulation/ai/petra/headquarters.js b/binaries/data/mods/public/simulation/ai/petra/headquarters.js index 3302226222..60a49dad12 100644 --- a/binaries/data/mods/public/simulation/ai/petra/headquarters.js +++ b/binaries/data/mods/public/simulation/ai/petra/headquarters.js @@ -1926,7 +1926,7 @@ m.HQ.prototype.constructTrainingBuildings = function(gameState, queues) numBarracks -= numRanges; let stableTemplate = this.canBuild(gameState, "structures/{civ}_stables") ? "structures/{civ}_stables" : - this.canBuild(gameState, "structures/{civ}_stable") ? "structures/{civ}_stable" : undefined; + this.canBuild(gameState, "structures/{civ}_stable") ? "structures/{civ}_stable" : undefined; let numStables = gameState.getOwnEntitiesByClass("Stables", true).length; if (this.getAccountedPopulation(gameState) > this.Config.Military.popForBarracks1 || diff --git a/binaries/data/mods/public/simulation/ai/petra/worker.js b/binaries/data/mods/public/simulation/ai/petra/worker.js index 4d2f6ec129..bb4e2b5131 100644 --- a/binaries/data/mods/public/simulation/ai/petra/worker.js +++ b/binaries/data/mods/public/simulation/ai/petra/worker.js @@ -337,7 +337,7 @@ m.Worker.prototype.update = function(gameState, ent) ent.setMetadata(PlayerID, "target-foundation", undefined); // If worker elephant, move away to avoid being trapped in between constructions if (ent.hasClass("Elephant")) - this.moveAway(gameState); + this.moveToGatherer(gameState, ent, true); else if (this.baseID != gameState.ai.HQ.baseManagers[0].ID) { // reassign it to something useful @@ -1003,20 +1003,29 @@ m.Worker.prototype.buildAnyField = function(gameState, baseID) }; /** - * Workers elephant should move away from the buildings they've built to avoid being trapped in between constructions - * For the time being, we move towards the nearest gatherer (providing him a dropsite) + * Workers elephant should move away from the buildings they've built to avoid being trapped in between constructions. + * For the time being, we move towards the nearest gatherer (providing him a dropsite). + * BaseManager does also use that function to deal with its mobile dropsites. */ -m.Worker.prototype.moveAway = function(gameState) +m.Worker.prototype.moveToGatherer = function(gameState, ent, forced) { + let pos = ent.position(); + if (!pos || ent.getMetadata(PlayerID, "target-foundation") !== undefined) + return; + if (!forced && gameState.ai.elapsedTime < (ent.getMetadata(PlayerID, "nextMoveToGatherer") || 5)) + return; let gatherers = this.base.workersBySubrole(gameState, "gatherer"); - let pos = this.ent.position(); let dist = Math.min(); - let destination = pos; + let destination; + let access = m.getLandAccess(gameState, ent); + let types = ent.resourceDropsiteTypes(); for (let gatherer of gatherers.values()) { - if (!gatherer.position() || gatherer.getMetadata(PlayerID, "transport") !== undefined) + let gathererType = gatherer.getMetadata(PlayerID, "gather-type"); + if (!gathererType || types.indexOf(gathererType) == -1) continue; - if (gatherer.isIdle()) + if (!gatherer.position() || gatherer.getMetadata(PlayerID, "transport") !== undefined || + m.getLandAccess(gameState, gatherer) != access || gatherer.isIdle()) continue; let distance = API3.SquareVectorDistance(pos, gatherer.position()); if (distance > dist) @@ -1024,7 +1033,9 @@ m.Worker.prototype.moveAway = function(gameState) dist = distance; destination = gatherer.position(); } - this.ent.move(destination[0], destination[1]); + ent.setMetadata(PlayerID, "nextMoveToGatherer", gameState.ai.elapsedTime + (destination ? 12 : 5)); + if (destination && dist > 10) + ent.move(destination[0], destination[1]); }; /**