Differential D3303 Diff 16247 ps/trunk/binaries/data/mods/public/simulation/ai/petra/entityExtend.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/entityExtend.js
Show First 20 Lines • Show All 376 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
PETRA.gatherTreasure = function(gameState, ent, water = false) | PETRA.gatherTreasure = function(gameState, ent, water = false) | ||||
{ | { | ||||
if (!gameState.ai.HQ.treasures.hasEntities()) | if (!gameState.ai.HQ.treasures.hasEntities()) | ||||
return false; | return false; | ||||
if (!ent || !ent.position()) | if (!ent || !ent.position()) | ||||
return false; | return false; | ||||
let rates = ent.resourceGatherRates(); | if (!ent.isTreasureCollecter) | ||||
if (!rates || !rates.treasure || rates.treasure <= 0) | |||||
return false; | return false; | ||||
let treasureFound; | let treasureFound; | ||||
let distmin = Math.min(); | let distmin = Math.min(); | ||||
let access = water ? PETRA.getSeaAccess(gameState, ent) : PETRA.getLandAccess(gameState, ent); | let access = water ? PETRA.getSeaAccess(gameState, ent) : PETRA.getLandAccess(gameState, ent); | ||||
for (let treasure of gameState.ai.HQ.treasures.values()) | for (let treasure of gameState.ai.HQ.treasures.values()) | ||||
{ | { | ||||
if (PETRA.IsSupplyFull(gameState, treasure)) | |||||
continue; | |||||
// let some time for the previous gatherer to reach the treasure before trying again | // let some time for the previous gatherer to reach the treasure before trying again | ||||
let lastGathered = treasure.getMetadata(PlayerID, "lastGathered"); | let lastGathered = treasure.getMetadata(PlayerID, "lastGathered"); | ||||
if (lastGathered && gameState.ai.elapsedTime - lastGathered < 20) | if (lastGathered && gameState.ai.elapsedTime - lastGathered < 20) | ||||
continue; | continue; | ||||
if (!water && access != PETRA.getLandAccess(gameState, treasure)) | if (!water && access != PETRA.getLandAccess(gameState, treasure)) | ||||
continue; | continue; | ||||
if (water && access != PETRA.getSeaAccess(gameState, treasure)) | if (water && access != PETRA.getSeaAccess(gameState, treasure)) | ||||
continue; | continue; | ||||
let territoryOwner = gameState.ai.HQ.territoryMap.getOwner(treasure.position()); | let territoryOwner = gameState.ai.HQ.territoryMap.getOwner(treasure.position()); | ||||
if (territoryOwner != 0 && !gameState.isPlayerAlly(territoryOwner)) | if (territoryOwner != 0 && !gameState.isPlayerAlly(territoryOwner)) | ||||
continue; | continue; | ||||
let dist = API3.SquareVectorDistance(ent.position(), treasure.position()); | let dist = API3.SquareVectorDistance(ent.position(), treasure.position()); | ||||
if (dist > 120000 || territoryOwner != PlayerID && dist > 14000) // AI has no LOS, so restrict it a bit | if (dist > 120000 || territoryOwner != PlayerID && dist > 14000) // AI has no LOS, so restrict it a bit | ||||
continue; | continue; | ||||
if (dist > distmin) | if (dist > distmin) | ||||
continue; | continue; | ||||
distmin = dist; | distmin = dist; | ||||
treasureFound = treasure; | treasureFound = treasure; | ||||
} | } | ||||
if (!treasureFound) | if (!treasureFound) | ||||
return false; | return false; | ||||
treasureFound.setMetadata(PlayerID, "lastGathered", gameState.ai.elapsedTime); | treasureFound.setMetadata(PlayerID, "lastGathered", gameState.ai.elapsedTime); | ||||
ent.gather(treasureFound); | ent.collectTreasure(treasureFound); | ||||
gameState.ai.HQ.AddTCGatherer(treasureFound.id()); | ent.setMetadata(PlayerID, "treasure", treasureFound.id()); | ||||
ent.setMetadata(PlayerID, "supply", treasureFound.id()); | |||||
return true; | return true; | ||||
}; | }; | ||||
PETRA.dumpEntity = function(ent) | PETRA.dumpEntity = function(ent) | ||||
{ | { | ||||
if (!ent) | if (!ent) | ||||
return; | return; | ||||
API3.warn(" >>> id " + ent.id() + " name " + ent.genericName() + " pos " + ent.position() + | API3.warn(" >>> id " + ent.id() + " name " + ent.genericName() + " pos " + ent.position() + | ||||
Show All 13 Lines |
Wildfire Games · Phabricator