Index: ps/trunk/binaries/data/mods/public/simulation/ai/common-api/entity.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/ai/common-api/entity.js +++ ps/trunk/binaries/data/mods/public/simulation/ai/common-api/entity.js @@ -709,7 +709,7 @@ return undefined; if (this.unitAIOrderData().length && - (this.unitAIState().split(".")[1] == "GATHER" || this.unitAIState().split(".")[1] == "RETURNRESOURCE")) + this.unitAIState().split(".")[1] == "GATHER") { let res; // this is an abuse of "_ai" but it works. Index: ps/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js +++ ps/trunk/binaries/data/mods/public/simulation/ai/petra/baseManager.js @@ -430,7 +430,7 @@ { if (ent.unitAIState() == "INDIVIDUAL.GATHER.GATHERING") ++this.gatherers[type].used; - else if (ent.unitAIState() == "INDIVIDUAL.RETURNRESOURCE.APPROACHING") + else if (ent.unitAIState() == "INDIVIDUAL.GATHER.RETURNINGRESOURCE.APPROACHING") ++this.gatherers[type].lost; } // TODO add also a test on remaining resources. Index: ps/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js +++ ps/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js @@ -2448,7 +2448,7 @@ { for (let worker of base.workers.values()) { - if (worker.unitAIState().split(".")[1] != "RETURNRESOURCE") + if (worker.unitAIState().split(".").indexOf("RETURNRESOURCE") === -1) continue; let orders = worker.unitAIOrderData(); if (orders.length < 2 || !orders[1].target || orders[1].target != worker.getMetadata(PlayerID, "supply")) Index: ps/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js +++ ps/trunk/binaries/data/mods/public/simulation/ai/petra/navalManager.js @@ -560,7 +560,7 @@ let unitAIState = ship.unitAIState(); if (ship.getMetadata(PlayerID, "transporter") !== undefined || unitAIState == "INDIVIDUAL.GATHER.APPROACHING" || - unitAIState == "INDIVIDUAL.RETURNRESOURCE.APPROACHING") + unitAIState == "INDIVIDUAL.GATHER.RETURNINGRESOURCE.APPROACHING") { let previousPosition = ship.getMetadata(PlayerID, "previousPosition"); if (!previousPosition || previousPosition[0] != shipPosition[0] || @@ -675,7 +675,7 @@ let unitAIState = blockingShip.unitAIState(); if (blockingShip.getMetadata(PlayerID, "transporter") === undefined && unitAIState != "INDIVIDUAL.GATHER.APPROACHING" && - unitAIState != "INDIVIDUAL.RETURNRESOURCE.APPROACHING") + unitAIState != "INDIVIDUAL.GATHER.RETURNINGRESOURCE.APPROACHING") { if (distSquare < 1600) blockingShip.moveToRange(shipPosition[0], shipPosition[1], 40, 45); Index: ps/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js +++ ps/trunk/binaries/data/mods/public/simulation/ai/petra/tradeManager.js @@ -110,7 +110,7 @@ PETRA.TradeManager.prototype.updateTrader = function(gameState, ent) { if (ent.hasClass("Ship") && gameState.ai.playedTurn % 5 == 0 && - !ent.unitAIState().startsWith("INDIVIDUAL.GATHER") && + !ent.unitAIState().startsWith("INDIVIDUAL.COLLECTTREASURE") && PETRA.gatherTreasure(gameState, ent, true)) return; Index: ps/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js +++ ps/trunk/binaries/data/mods/public/simulation/ai/petra/worker.js @@ -253,37 +253,37 @@ } } } - } - else if (unitAIState == "INDIVIDUAL.RETURNRESOURCE.APPROACHING") - { - if (gameState.ai.playedTurn % 10 == 0) + if (unitAIState == "INDIVIDUAL.GATHER.RETURNINGRESOURCE.APPROACHING") { - // Check from time to time that UnitAI does not send us to an inaccessible dropsite - let dropsite = gameState.getEntityById(ent.unitAIOrderData()[0].target); - if (dropsite && dropsite.position() && this.entAccess != PETRA.getLandAccess(gameState, dropsite)) - PETRA.returnResources(gameState, this.ent); - } + if (gameState.ai.playedTurn % 10 == 0) + { + // Check from time to time that UnitAI does not send us to an inaccessible dropsite + let dropsite = gameState.getEntityById(ent.unitAIOrderData()[0].target); + if (dropsite && dropsite.position() && this.entAccess != PETRA.getLandAccess(gameState, dropsite)) + PETRA.returnResources(gameState, this.ent); + } - // If gathering a sparse resource, we may have been sent to a faraway resource if the one nearby was full. - // Let's check if it is still the case. If so, we reset its metadata supplyId so that the unit will be - // reordered to gather after having returned the resources (when comparing its supplyId with the UnitAI one). - let gatherType = ent.getMetadata(PlayerID, "gather-type"); - let influenceGroup = Resources.GetResource(gatherType).aiAnalysisInfluenceGroup; - if (influenceGroup && influenceGroup == "sparse") - { - let supplyId = ent.getMetadata(PlayerID, "supply"); - if (supplyId) + // If gathering a sparse resource, we may have been sent to a faraway resource if the one nearby was full. + // Let's check if it is still the case. If so, we reset its metadata supplyId so that the unit will be + // reordered to gather after having returned the resources (when comparing its supplyId with the UnitAI one). + let gatherType = ent.getMetadata(PlayerID, "gather-type"); + let influenceGroup = Resources.GetResource(gatherType).aiAnalysisInfluenceGroup; + if (influenceGroup && influenceGroup == "sparse") { - let nearby = this.base.dropsiteSupplies[gatherType].nearby; - if (!nearby.some(sup => sup.id == supplyId)) + let supplyId = ent.getMetadata(PlayerID, "supply"); + if (supplyId) { - if (nearby.length) - ent.setMetadata(PlayerID, "supply", undefined); - else + let nearby = this.base.dropsiteSupplies[gatherType].nearby; + if (!nearby.some(sup => sup.id == supplyId)) { - let medium = this.base.dropsiteSupplies[gatherType].medium; - if (!medium.some(sup => sup.id == supplyId) && medium.length) + if (nearby.length) ent.setMetadata(PlayerID, "supply", undefined); + else + { + let medium = this.base.dropsiteSupplies[gatherType].medium; + if (!medium.some(sup => sup.id == supplyId) && medium.length) + ent.setMetadata(PlayerID, "supply", undefined); + } } } } @@ -379,13 +379,13 @@ } else // Perform some sanity checks { - if (unitAIStateOrder == "GATHER" || unitAIStateOrder == "RETURNRESOURCE") + if (unitAIStateOrder == "GATHER") { // we may have drifted towards ennemy territory during the hunt, if yes go home let territoryOwner = gameState.ai.HQ.territoryMap.getOwner(ent.position()); if (territoryOwner != 0 && !gameState.isPlayerAlly(territoryOwner)) // player is its own ally this.startHunting(gameState); - else if (unitAIState == "INDIVIDUAL.RETURNRESOURCE.APPROACHING") + else if (unitAIState == "INDIVIDUAL.GATHER.RETURNINGRESOURCE.APPROACHING") { // Check that UnitAI does not send us to an inaccessible dropsite let dropsite = gameState.getEntityById(ent.unitAIOrderData()[0].target);