Differential D3343 Diff 16470 ps/trunk/binaries/data/mods/public/simulation/ai/petra/headquarters.js
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,907 Lines • ▼ Show 20 Lines | PETRA.HQ.prototype.buildForge = function(gameState, queues) | ||||
if (!gameState.getOwnEntitiesByClass("Market", true).hasEntities()) | if (!gameState.getOwnEntitiesByClass("Market", true).hasEntities()) | ||||
return; | return; | ||||
if (this.canBuild(gameState, "structures/{civ}/forge")) | if (this.canBuild(gameState, "structures/{civ}/forge")) | ||||
queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, "structures/{civ}/forge")); | queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, "structures/{civ}/forge")); | ||||
}; | }; | ||||
/** | /** | ||||
* Deals with constructing military buildings (barracks, stables…) | * Deals with constructing military buildings (e.g. barracks, stable). | ||||
* They are mostly defined by Config.js. This is unreliable since changes could be done easily. | * They are mostly defined by Config.js. This is unreliable since changes could be done easily. | ||||
*/ | */ | ||||
PETRA.HQ.prototype.constructTrainingBuildings = function(gameState, queues) | PETRA.HQ.prototype.constructTrainingBuildings = function(gameState, queues) | ||||
{ | { | ||||
if (this.saveResources && !this.canBarter || queues.militaryBuilding.hasQueuedUnits()) | if (this.saveResources && !this.canBarter || queues.militaryBuilding.hasQueuedUnits()) | ||||
return; | return; | ||||
let numBarracks = gameState.getOwnEntitiesByClass("Barracks", true).length; | let numBarracks = gameState.getOwnEntitiesByClass("Barracks", true).length; | ||||
if (this.saveResources && numBarracks != 0) | if (this.saveResources && numBarracks != 0) | ||||
return; | return; | ||||
let barracksTemplate = this.canBuild(gameState, "structures/{civ}/barracks") ? "structures/{civ}/barracks" : undefined; | let barracksTemplate = this.canBuild(gameState, "structures/{civ}/barracks") ? "structures/{civ}/barracks" : undefined; | ||||
let rangeTemplate = this.canBuild(gameState, "structures/{civ}/range") ? "structures/{civ}/range" : undefined; | let rangeTemplate = this.canBuild(gameState, "structures/{civ}/range") ? "structures/{civ}/range" : undefined; | ||||
let numRanges = gameState.getOwnEntitiesByClass("Range", true).length; | let numRanges = gameState.getOwnEntitiesByClass("Range", true).length; | ||||
let stableTemplate = this.canBuild(gameState, "structures/{civ}/stable") ? "structures/{civ}/stable" : undefined; | let stableTemplate = this.canBuild(gameState, "structures/{civ}/stable") ? "structures/{civ}/stable" : undefined; | ||||
let numStables = gameState.getOwnEntitiesByClass("Stable", true).length; | let numStables = gameState.getOwnEntitiesByClass("Stable", true).length; | ||||
if (this.getAccountedPopulation(gameState) > this.Config.Military.popForBarracks1 || | if (this.getAccountedPopulation(gameState) > this.Config.Military.popForBarracks1 || | ||||
this.phasing == 2 && gameState.getOwnStructures().filter(API3.Filters.byClass("Village")).length < 5) | this.phasing == 2 && gameState.getOwnStructures().filter(API3.Filters.byClass("Village")).length < 5) | ||||
{ | { | ||||
// first barracks/range and stables. | // First barracks/range and stable. | ||||
if (numBarracks + numRanges == 0) | if (numBarracks + numRanges == 0) | ||||
{ | { | ||||
let template = barracksTemplate || rangeTemplate; | let template = barracksTemplate || rangeTemplate; | ||||
if (template) | if (template) | ||||
{ | { | ||||
gameState.ai.queueManager.changePriority("militaryBuilding", 2 * this.Config.priorities.militaryBuilding); | gameState.ai.queueManager.changePriority("militaryBuilding", 2 * this.Config.priorities.militaryBuilding); | ||||
let plan = new PETRA.ConstructionPlan(gameState, template, { "militaryBase": true }); | let plan = new PETRA.ConstructionPlan(gameState, template, { "militaryBase": true }); | ||||
plan.queueToReset = "militaryBuilding"; | plan.queueToReset = "militaryBuilding"; | ||||
queues.militaryBuilding.addPlan(plan); | queues.militaryBuilding.addPlan(plan); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
if (numStables == 0 && stableTemplate) | if (numStables == 0 && stableTemplate) | ||||
{ | { | ||||
queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, stableTemplate, { "militaryBase": true })); | queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, stableTemplate, { "militaryBase": true })); | ||||
return; | return; | ||||
} | } | ||||
// Second range/barracks and stables | // Second barracks/range and stable. | ||||
if (numBarracks + numRanges == 1 && this.getAccountedPopulation(gameState) > this.Config.Military.popForBarracks2) | if (numBarracks + numRanges == 1 && this.getAccountedPopulation(gameState) > this.Config.Military.popForBarracks2) | ||||
{ | { | ||||
let template = numBarracks == 0 ? (barracksTemplate || rangeTemplate) : (rangeTemplate || barracksTemplate); | let template = numBarracks == 0 ? (barracksTemplate || rangeTemplate) : (rangeTemplate || barracksTemplate); | ||||
if (template) | if (template) | ||||
{ | { | ||||
queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, template, { "militaryBase": true })); | queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, template, { "militaryBase": true })); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
if (numStables == 1 && stableTemplate && this.getAccountedPopulation(gameState) > this.Config.Military.popForBarracks2) | if (numStables == 1 && stableTemplate && this.getAccountedPopulation(gameState) > this.Config.Military.popForBarracks2) | ||||
{ | { | ||||
queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, stableTemplate, { "militaryBase": true })); | queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, stableTemplate, { "militaryBase": true })); | ||||
return; | return; | ||||
} | } | ||||
// Then 3rd barracks/range/stables if needed | // Third barracks/range and stable, if needed. | ||||
if (numBarracks + numRanges + numStables == 2 && this.getAccountedPopulation(gameState) > this.Config.Military.popForBarracks2 + 30) | if (numBarracks + numRanges + numStables == 2 && this.getAccountedPopulation(gameState) > this.Config.Military.popForBarracks2 + 30) | ||||
{ | { | ||||
let template = barracksTemplate || stableTemplate || rangeTemplate; | let template = barracksTemplate || stableTemplate || rangeTemplate; | ||||
if (template) | if (template) | ||||
{ | { | ||||
queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, template, { "militaryBase": true })); | queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, template, { "militaryBase": true })); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (this.saveResources) | if (this.saveResources) | ||||
return; | return; | ||||
if (this.currentPhase < 3) | if (this.currentPhase < 3) | ||||
return; | return; | ||||
if (this.canBuild(gameState, "structures/{civ}/elephant_stables") && !gameState.getOwnEntitiesByClass("ElephantStable", true).hasEntities()) | if (this.canBuild(gameState, "structures/{civ}/elephant_stable") && !gameState.getOwnEntitiesByClass("ElephantStable", true).hasEntities()) | ||||
{ | { | ||||
queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, "structures/{civ}/elephant_stables", { "militaryBase": true })); | queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, "structures/{civ}/elephant_stable", { "militaryBase": true })); | ||||
return; | return; | ||||
} | } | ||||
if (this.canBuild(gameState, "structures/{civ}/arsenal") && !gameState.getOwnEntitiesByClass("Arsenal", true).hasEntities()) | if (this.canBuild(gameState, "structures/{civ}/arsenal") && !gameState.getOwnEntitiesByClass("Arsenal", true).hasEntities()) | ||||
{ | { | ||||
queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, "structures/{civ}/arsenal", { "militaryBase": true })); | queues.militaryBuilding.addPlan(new PETRA.ConstructionPlan(gameState, "structures/{civ}/arsenal", { "militaryBase": true })); | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 898 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator