Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/headquarters.js
var PETRA = function(m) | (function(m) | ||||
{ | { | ||||
/** | /** | ||||
* Headquarters | * Headquarters | ||||
* Deal with high level logic for the AI. Most of the interesting stuff gets done here. | * Deal with high level logic for the AI. Most of the interesting stuff gets done here. | ||||
* Some tasks: | * Some tasks: | ||||
* -defining RESS needs | * -defining RESS needs | ||||
* -BO decisions. | * -BO decisions. | ||||
▲ Show 20 Lines • Show All 1,077 Lines • ▼ Show 20 Lines | if (this.borderMap.map[j] & m.fullBorder_Mask) // disfavor the borders of the map | ||||
norm *= 0.5; | norm *= 0.5; | ||||
let val = 2*gameState.sharedScript.ccResourceMaps[resource].map[j]; | let val = 2*gameState.sharedScript.ccResourceMaps[resource].map[j]; | ||||
for (let res in gameState.sharedScript.resourceMaps) | for (let res in gameState.sharedScript.resourceMaps) | ||||
if (res != "food") | if (res != "food") | ||||
val += gameState.sharedScript.ccResourceMaps[res].map[j]; | val += gameState.sharedScript.ccResourceMaps[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; | ||||
if (this.isDangerousLocation(gameState, pos, halfSize)) | if (this.isDangerousLocation(gameState, pos, halfSize)) | ||||
continue; | continue; | ||||
bestVal = val; | bestVal = val; | ||||
▲ Show 20 Lines • Show All 1,574 Lines • ▼ Show 20 Lines | if (this.currentPhase != gameState.currentPhase()) | ||||
this.currentPhase = gameState.currentPhase(); | this.currentPhase = gameState.currentPhase(); | ||||
// In principle, this.phasing should be already reset to 0 when starting the research | // In principle, this.phasing should be already reset to 0 when starting the research | ||||
// but this does not work in case of an autoResearch tech | // but this does not work in case of an autoResearch tech | ||||
if (this.phasing) | if (this.phasing) | ||||
this.phasing = 0; | this.phasing = 0; | ||||
} | } | ||||
/* if (this.Config.debug > 1) | /* | ||||
if (this.Config.debug > 1) | |||||
{ | { | ||||
gameState.getOwnUnits().forEach (function (ent) { | gameState.getOwnUnits().forEach (function (ent) { | ||||
if (!ent.position()) | if (!ent.position()) | ||||
return; | return; | ||||
m.dumpEntity(ent); | m.dumpEntity(ent); | ||||
}); | }); | ||||
} */ | } | ||||
*/ | |||||
this.checkEvents(gameState, events); | this.checkEvents(gameState, events); | ||||
this.navalManager.checkEvents(gameState, queues, events); | this.navalManager.checkEvents(gameState, queues, events); | ||||
if (this.phasing) | if (this.phasing) | ||||
this.checkPhaseRequirements(gameState, queues); | this.checkPhaseRequirements(gameState, queues); | ||||
else | else | ||||
this.researchManager.checkPhase(gameState, queues); | this.researchManager.checkPhase(gameState, queues); | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | m.HQ.prototype.update = function(gameState, queues, events) | ||||
this.assignGatherers(); | this.assignGatherers(); | ||||
let nbBases = this.baseManagers.length; | let nbBases = this.baseManagers.length; | ||||
let activeBase; // We will loop only on 1 active base per turn | let activeBase; // We will loop only on 1 active base per turn | ||||
do | do | ||||
{ | { | ||||
this.currentBase %= this.baseManagers.length; | this.currentBase %= this.baseManagers.length; | ||||
activeBase = this.baseManagers[this.currentBase++].update(gameState, queues, events); | activeBase = this.baseManagers[this.currentBase++].update(gameState, queues, events); | ||||
--nbBases; | --nbBases; | ||||
// TODO what to do with this.reassignTerritories(this.baseManagers[this.currentBase]); | // TODO what to do with this.reassignTerritories(this.baseManagers[this.currentBase]); | ||||
} | } | ||||
while (!activeBase && nbBases != 0); | while (!activeBase && nbBases != 0); | ||||
this.navalManager.update(gameState, queues, events); | this.navalManager.update(gameState, queues, events); | ||||
if (this.Config.difficulty > 0 && (this.numActiveBases() > 0 || !this.canBuildUnits)) | if (this.Config.difficulty > 0 && (this.numActiveBases() > 0 || !this.canBuildUnits)) | ||||
this.attackManager.update(gameState, queues, events); | this.attackManager.update(gameState, queues, events); | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | m.HQ.prototype.Deserialize = function(gameState, data) | ||||
this.garrisonManager = new m.GarrisonManager(this.Config); | this.garrisonManager = new m.GarrisonManager(this.Config); | ||||
this.garrisonManager.Deserialize(data.garrisonManager); | this.garrisonManager.Deserialize(data.garrisonManager); | ||||
this.victoryManager = new m.VictoryManager(this.Config); | this.victoryManager = new m.VictoryManager(this.Config); | ||||
this.victoryManager.Deserialize(data.victoryManager); | this.victoryManager.Deserialize(data.victoryManager); | ||||
}; | }; | ||||
return m; | }(PETRA)); | ||||
}(PETRA); |
Wildfire Games · Phabricator