Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/baseManager.js
Show First 20 Lines • Show All 335 Lines • ▼ Show 20 Lines | PETRA.BaseManager.prototype.findBestDropsiteLocation = function(gameState, resource, templateName) | ||||
const droppableResources = template.resourceDropsiteTypes(); | const droppableResources = template.resourceDropsiteTypes(); | ||||
for (let j of this.territoryIndices) | for (let j of this.territoryIndices) | ||||
{ | { | ||||
let i = territoryMap.getNonObstructedTile(j, radius, obstructions); | let i = territoryMap.getNonObstructedTile(j, radius, obstructions); | ||||
if (i < 0) // no room around | if (i < 0) // no room around | ||||
continue; | continue; | ||||
const resourcesMaps = gameState.sharedScript.getResourcesMaps(PETRA.HQ.RESOURCE_MAP_IDENTIFIER); | |||||
// We add 3 times the needed resource and once others that can be dropped here. | // We add 3 times the needed resource and once others that can be dropped here. | ||||
let total = 2 * gameState.sharedScript.resourceMaps[resource].map[j]; | let total = 2 * resourcesMaps[resource].map[j]; | ||||
for (const res in gameState.sharedScript.resourceMaps) | for (const res in resourcesMaps) | ||||
if (droppableResources.indexOf(res) != -1) | if (droppableResources.indexOf(res) != -1) | ||||
total += gameState.sharedScript.resourceMaps[res].map[j]; | total += resourcesMaps[res].map[j]; | ||||
total *= 0.7; // Just a normalisation factor as the locateMap is limited to 255 | total *= 0.7; // Just a normalisation factor as the locateMap is limited to 255 | ||||
if (total <= bestVal) | if (total <= bestVal) | ||||
continue; | continue; | ||||
let pos = [cellSize * (j%width+0.5), cellSize * (Math.floor(j/width)+0.5)]; | let pos = [cellSize * (j%width+0.5), cellSize * (Math.floor(j/width)+0.5)]; | ||||
for (let dp of dpEnts) | for (let dp of dpEnts) | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | if (type == "food") | ||||
{ | { | ||||
queues.corral.addPlan(new PETRA.ConstructionPlan(gameState, "structures/{civ}/corral", { "favoredBase": this.ID })); | queues.corral.addPlan(new PETRA.ConstructionPlan(gameState, "structures/{civ}/corral", { "favoredBase": this.ID })); | ||||
gameState.ai.HQ.needCorral = true; | gameState.ai.HQ.needCorral = true; | ||||
} | } | ||||
} | } | ||||
continue; | continue; | ||||
} | } | ||||
// Non food stuff | // Non food stuff | ||||
if (!gameState.sharedScript.resourceMaps[type] || queues.dropsites.hasQueuedUnits() || | if (!gameState.sharedScript.getResourcesMaps(PETRA.HQ.RESOURCE_MAP_IDENTIFIER)[type] || queues.dropsites.hasQueuedUnits() || | ||||
gameState.getOwnFoundations().filter(API3.Filters.byClass("Storehouse")).hasEntities()) | gameState.getOwnFoundations().filter(API3.Filters.byClass("Storehouse")).hasEntities()) | ||||
{ | { | ||||
this.gatherers[type].nextCheck = gameState.ai.playedTurn; | this.gatherers[type].nextCheck = gameState.ai.playedTurn; | ||||
this.gatherers[type].used = 0; | this.gatherers[type].used = 0; | ||||
this.gatherers[type].lost = 0; | this.gatherers[type].lost = 0; | ||||
continue; | continue; | ||||
} | } | ||||
if (gameState.ai.playedTurn < this.gatherers[type].nextCheck) | if (gameState.ai.playedTurn < this.gatherers[type].nextCheck) | ||||
▲ Show 20 Lines • Show All 690 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator