Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
Show First 20 Lines • Show All 1,484 Lines • ▼ Show 20 Lines | m.HQ.prototype.checkBaseExpansion = function(gameState, queues) | ||||
// first build one cc if all have been destroyed | // first build one cc if all have been destroyed | ||||
let activeBases = this.numActiveBase(); | let activeBases = this.numActiveBase(); | ||||
if (activeBases === 0) | if (activeBases === 0) | ||||
{ | { | ||||
this.buildFirstBase(gameState); | this.buildFirstBase(gameState); | ||||
return; | return; | ||||
} | } | ||||
// then expand if we have not enough room available for buildings | // then expand if we have not enough room available for buildings | ||||
if (this.stopBuilding.size > 1) | let nstopped = 0; | ||||
for (let stopTime of this.stopBuilding.values()) | |||||
{ | { | ||||
if (stopTime === Infinity || stopTime < gameState.ai.elapsedTime || ++nstopped < 2) | |||||
continue; | |||||
if (this.Config.debug > 2) | if (this.Config.debug > 2) | ||||
API3.warn("try to build a new base because not enough room to build " + uneval(this.stopBuilding)); | API3.warn("try to build a new base because not enough room to build " + uneval(this.stopBuilding)); | ||||
this.buildNewBase(gameState, queues); | this.buildNewBase(gameState, queues); | ||||
return; | return; | ||||
} | } | ||||
// then expand if we have lots of units (threshold depending on the aggressivity value) | // then expand if we have lots of units (threshold depending on the aggressivity value) | ||||
let numUnits = gameState.getOwnUnits().length; | let numUnits = gameState.getOwnUnits().length; | ||||
let numvar = 10 * (1 - this.Config.personality.aggressive); | let numvar = 10 * (1 - this.Config.personality.aggressive); | ||||
if (numUnits > activeBases * (65 + numvar + (10 + numvar)*(activeBases-1)) || (this.saveResources && numUnits > 50)) | if (numUnits > activeBases * (65 + numvar + (10 + numvar)*(activeBases-1)) || (this.saveResources && numUnits > 50)) | ||||
{ | { | ||||
if (this.Config.debug > 2) | if (this.Config.debug > 2) | ||||
API3.warn("try to build a new base because of population " + numUnits + " for " + activeBases + " CCs"); | API3.warn("try to build a new base because of population " + numUnits + " for " + activeBases + " CCs"); | ||||
this.buildNewBase(gameState, queues); | this.buildNewBase(gameState, queues); | ||||
} | } | ||||
}; | }; | ||||
m.HQ.prototype.buildNewBase = function(gameState, queues, resource) | m.HQ.prototype.buildNewBase = function(gameState, queues, resource) | ||||
{ | { | ||||
if (this.numActiveBase() > 0 && gameState.currentPhase() == 1 && !gameState.isResearching(gameState.townPhase())) | if (this.numActiveBase() > 0 && gameState.currentPhase() == 1 && !gameState.isResearching(gameState.townPhase())) | ||||
return false; | return false; | ||||
if (gameState.getOwnFoundations().filter(API3.Filters.byClass("CivCentre")).hasEntities() || queues.civilCentre.hasQueuedUnits()) | if (gameState.getOwnFoundations().filter(API3.Filters.byClass("CivCentre")).hasEntities() || queues.civilCentre.hasQueuedUnits()) | ||||
return false; | return false; | ||||
let template = this.numActiveBase() > 0 ? this.bBase[0] : gameState.applyCiv("structures/{civ}_civil_centre"); | |||||
if (!this.canBuild(gameState, template)) | let template; | ||||
// We require at least one of this civ civCentre as they may allow specific units or techs | |||||
let hasOwnCC = false; | |||||
for (let ent of gameState.updatingGlobalCollection("allCCs", API3.Filters.byClass("CivCentre")).values()) | |||||
{ | |||||
if (ent.owner() !== PlayerID || ent.templateName() !== gameState.applyCiv("structures/{civ}_civil_centre")) | |||||
continue; | |||||
hasOwnCC = true; | |||||
break; | |||||
} | |||||
if (hasOwnCC && this.canBuild(gameState, "structures/{civ}_military_colony")) | |||||
template = "structures/{civ}_military_colony"; | |||||
else if (this.canBuild(gameState, "structures/{civ}_civil_centre")) | |||||
template = "structures/{civ}_civil_centre"; | |||||
else if (!hasOwnCC && this.canBuild(gameState, "structures/{civ}_military_colony")) | |||||
template = "structures/{civ}_military_colony"; | |||||
else | |||||
return false; | return false; | ||||
// base "-1" means new base. | // base "-1" means new base. | ||||
if (this.Config.debug > 1) | if (this.Config.debug > 1) | ||||
API3.warn("new base planned with resource " + resource); | API3.warn("new base " + gameState.applyCiv(template) + " planned with resource " + resource); | ||||
queues.civilCentre.addPlan(new m.ConstructionPlan(gameState, template, { "base": -1, "resource": resource })); | queues.civilCentre.addPlan(new m.ConstructionPlan(gameState, template, { "base": -1, "resource": resource })); | ||||
return true; | return true; | ||||
}; | }; | ||||
/** Deals with building fortresses and towers along our border with enemies. */ | /** Deals with building fortresses and towers along our border with enemies. */ | ||||
m.HQ.prototype.buildDefenses = function(gameState, queues) | m.HQ.prototype.buildDefenses = function(gameState, queues) | ||||
{ | { | ||||
if ((this.saveResources && !this.canBarter) || queues.defenseBuilding.hasQueuedUnits()) | if ((this.saveResources && !this.canBarter) || queues.defenseBuilding.hasQueuedUnits()) | ||||
▲ Show 20 Lines • Show All 292 Lines • ▼ Show 20 Lines | m.HQ.prototype.canBuild = function(gameState, structure) | ||||
if (gameState.isTemplateDisabled(type)) | if (gameState.isTemplateDisabled(type)) | ||||
{ | { | ||||
this.stopBuilding.set(type, Infinity); | this.stopBuilding.set(type, Infinity); | ||||
return false; | return false; | ||||
} | } | ||||
let template = gameState.getTemplate(type); | let template = gameState.getTemplate(type); | ||||
if (!template) | if (!template) | ||||
{ | |||||
this.stopBuilding.set(type, Infinity); | this.stopBuilding.set(type, Infinity); | ||||
if (this.Config.debug > 0) | |||||
API3.warn("Petra error: trying to build " + structure + " for civ " + | |||||
gameState.getPlayerCiv() + " but no template found."); | |||||
} | |||||
if (!template || !template.available(gameState)) | if (!template || !template.available(gameState)) | ||||
return false; | return false; | ||||
if (!gameState.findBuilder(type)) | if (!gameState.findBuilder(type)) | ||||
{ | { | ||||
this.stopBuild(gameState, type, 120); | this.stopBuild(gameState, type, 120); | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | else | ||||
this.basesMap.map[j] = baseID; | this.basesMap.map[j] = baseID; | ||||
expansion++; | expansion++; | ||||
} | } | ||||
} | } | ||||
if (!expansion) | if (!expansion) | ||||
return; | return; | ||||
// We've increased our territory, so we may have some new room to build | // We've increased our territory, so we may have some new room to build | ||||
this.stopBuilding.clear(); | for (let [type, stopTime] of this.stopBuilding) | ||||
if (stopTime !== Infinity) | |||||
this.stopBuilding.delete(type); | |||||
// And if sufficient expansion, check if building a new market would improve our present trade routes | // And if sufficient expansion, check if building a new market would improve our present trade routes | ||||
let cellArea = this.territoryMap.cellSize * this.territoryMap.cellSize; | let cellArea = this.territoryMap.cellSize * this.territoryMap.cellSize; | ||||
if (expansion * cellArea > 960) | if (expansion * cellArea > 960) | ||||
this.tradeManager.routeProspection = true; | this.tradeManager.routeProspection = true; | ||||
}; | }; | ||||
/** | /** | ||||
* returns the base corresponding to baseID | * returns the base corresponding to baseID | ||||
▲ Show 20 Lines • Show All 285 Lines • ▼ Show 20 Lines | let properties = { | ||||
"currentRates": this.currentRates, | "currentRates": this.currentRates, | ||||
"lastFailedGather": this.lastFailedGather, | "lastFailedGather": this.lastFailedGather, | ||||
"supportRatio": this.supportRatio, | "supportRatio": this.supportRatio, | ||||
"targetNumWorkers": this.targetNumWorkers, | "targetNumWorkers": this.targetNumWorkers, | ||||
"stopBuilding": this.stopBuilding, | "stopBuilding": this.stopBuilding, | ||||
"fortStartTime": this.fortStartTime, | "fortStartTime": this.fortStartTime, | ||||
"towerStartTime": this.towerStartTime, | "towerStartTime": this.towerStartTime, | ||||
"fortressStartTime": this.fortressStartTime, | "fortressStartTime": this.fortressStartTime, | ||||
"bBase": this.bBase, | |||||
"bAdvanced": this.bAdvanced, | "bAdvanced": this.bAdvanced, | ||||
"saveResources": this.saveResources, | "saveResources": this.saveResources, | ||||
"saveSpace": this.saveSpace, | "saveSpace": this.saveSpace, | ||||
"needCorral": this.needCorral, | "needCorral": this.needCorral, | ||||
"needFarm": this.needFarm, | "needFarm": this.needFarm, | ||||
"needFish": this.needFish, | "needFish": this.needFish, | ||||
"canBuildUnits": this.canBuildUnits, | "canBuildUnits": this.canBuildUnits, | ||||
"navalMap": this.navalMap, | "navalMap": this.navalMap, | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator