Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/headquarters.js
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | PETRA.HQ = function(Config) | ||||
this.garrisonManager = new PETRA.GarrisonManager(this.Config); | this.garrisonManager = new PETRA.GarrisonManager(this.Config); | ||||
this.victoryManager = new PETRA.VictoryManager(this.Config); | this.victoryManager = new PETRA.VictoryManager(this.Config); | ||||
this.emergencyManager = new PETRA.EmergencyManager(this.Config); | this.emergencyManager = new PETRA.EmergencyManager(this.Config); | ||||
this.capturableTargets = new Map(); | this.capturableTargets = new Map(); | ||||
this.capturableTargetsTime = 0; | this.capturableTargetsTime = 0; | ||||
}; | }; | ||||
/** | |||||
* The identifier string to use when making and requesting a resource map. | |||||
*/ | |||||
PETRA.HQ.RESOURCE_MAP_IDENTIFIER = "PetraAI" | |||||
/** More initialisation for stuff that needs the gameState */ | /** More initialisation for stuff that needs the gameState */ | ||||
PETRA.HQ.prototype.init = function(gameState, queues) | PETRA.HQ.prototype.init = function(gameState, queues) | ||||
{ | { | ||||
this.territoryMap = PETRA.createTerritoryMap(gameState); | this.territoryMap = PETRA.createTerritoryMap(gameState); | ||||
// create borderMap: flag cells on the border of the map | // create borderMap: flag cells on the border of the map | ||||
// then this map will be completed with our frontier in updateTerritories | // then this map will be completed with our frontier in updateTerritories | ||||
this.borderMap = PETRA.createBorderMap(gameState); | this.borderMap = PETRA.createBorderMap(gameState); | ||||
// list of allowed regions | // list of allowed regions | ||||
this.landRegions = {}; | this.landRegions = {}; | ||||
// try to determine if we have a water map | // try to determine if we have a water map | ||||
this.navalMap = false; | this.navalMap = false; | ||||
this.navalRegions = {}; | this.navalRegions = {}; | ||||
gameState.sharedScript.createResourceMaps(this.Config.resources, PETRA.HQ.RESOURCE_MAP_IDENTIFIER); | |||||
this.treasures = gameState.getEntities().filter(ent => ent.isTreasure()); | this.treasures = gameState.getEntities().filter(ent => ent.isTreasure()); | ||||
this.treasures.registerUpdates(); | this.treasures.registerUpdates(); | ||||
this.currentPhase = gameState.currentPhase(); | this.currentPhase = gameState.currentPhase(); | ||||
this.decayingStructures = new Set(); | this.decayingStructures = new Set(); | ||||
this.emergencyManager.init(gameState); | this.emergencyManager.init(gameState); | ||||
}; | }; | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 705 Lines • ▼ Show 20 Lines | else | ||||
} | } | ||||
if (norm == 0) | if (norm == 0) | ||||
continue; | continue; | ||||
} | } | ||||
if (this.borderMap.map[j] & PETRA.fullBorder_Mask) // disfavor the borders of the map | if (this.borderMap.map[j] & PETRA.fullBorder_Mask) // disfavor the borders of the map | ||||
norm *= 0.5; | norm *= 0.5; | ||||
let val = 2 * gameState.sharedScript.ccResourceMaps[resource].map[j]; | const ccResourcesMaps = gameState.sharedScript.getCCResourcesMaps(PETRA.HQ.RESOURCE_MAP_IDENTIFIER); | ||||
for (let res in gameState.sharedScript.resourceMaps) | let val = 2 * ccResourcesMaps[resource].map[j]; | ||||
for (let res in gameState.sharedScript.getResourcesMaps(PETRA.HQ.RESOURCE_MAP_IDENTIFIER)) | |||||
if (res != "food") | if (res != "food") | ||||
val += gameState.sharedScript.ccResourceMaps[res].map[j]; | val += ccResourcesMaps[res].map[j]; | ||||
val *= norm; | val *= norm; | ||||
// If oversea, be just above threshold to be accepted if nothing else | // If oversea, be just above threshold to be accepted if nothing else | ||||
if (oversea) | if (oversea) | ||||
val = Math.max(val, cut + 0.1); | val = Math.max(val, cut + 0.1); | ||||
if (bestVal !== undefined && val < bestVal) | if (bestVal !== undefined && val < bestVal) | ||||
continue; | continue; | ||||
▲ Show 20 Lines • Show All 1,608 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator