1
0
forked from mirrors/0ad

Fix typo in "Headquaters" introduced in 4da78788c8

Fixes: #8291
This commit is contained in:
phosit
2025-08-22 20:28:49 +02:00
committed by Phosit
parent 2413d13483
commit 835f59a604
3 changed files with 61 additions and 61 deletions
@@ -1,7 +1,7 @@
import { BaseAI } from "simulation/ai/common-api/baseAI.js"; import { BaseAI } from "simulation/ai/common-api/baseAI.js";
import { Entity } from "simulation/ai/common-api/entity.js"; import { Entity } from "simulation/ai/common-api/entity.js";
import { Config } from "simulation/ai/petra/config.js"; import { Config } from "simulation/ai/petra/config.js";
import { Headquather } from "simulation/ai/petra/headquarters.js"; import { Headquarters } from "simulation/ai/petra/headquarters.js";
import { Queue } from "simulation/ai/petra/queue.js"; import { Queue } from "simulation/ai/petra/queue.js";
import { QueueManager } from "simulation/ai/petra/queueManager.js"; import { QueueManager } from "simulation/ai/petra/queueManager.js";
@@ -80,7 +80,7 @@ PetraBot.prototype.CustomInit = function(gameState)
this.queueManager = new QueueManager(this.Config, this.queues); this.queueManager = new QueueManager(this.Config, this.queues);
this.HQ = new Headquather(this.Config); this.HQ = new Headquarters(this.Config);
this.HQ.init(gameState, this.queues); this.HQ.init(gameState, this.queues);
@@ -39,7 +39,7 @@ import { Worker } from "simulation/ai/petra/worker.js";
* -picking new CC locations. * -picking new CC locations.
*/ */
export function Headquather(config) export function Headquarters(config)
{ {
this.Config = config; this.Config = config;
this.phasing = 0; // existing values: 0 means no, i > 0 means phasing towards phase i this.phasing = 0; // existing values: 0 means no, i > 0 means phasing towards phase i
@@ -79,7 +79,7 @@ export function Headquather(config)
} }
/** More initialisation for stuff that needs the gameState */ /** More initialisation for stuff that needs the gameState */
Headquather.prototype.init = function(gameState, queues) Headquarters.prototype.init = function(gameState, queues)
{ {
this.territoryMap = createTerritoryMap(gameState); this.territoryMap = createTerritoryMap(gameState);
// create borderMap: flag cells on the border of the map // create borderMap: flag cells on the border of the map
@@ -101,7 +101,7 @@ Headquather.prototype.init = function(gameState, queues)
/** /**
* initialization needed after deserialization (only called when deserialization) * initialization needed after deserialization (only called when deserialization)
*/ */
Headquather.prototype.postinit = function(gameState) Headquarters.prototype.postinit = function(gameState)
{ {
this.basesManager.postinit(gameState); this.basesManager.postinit(gameState);
this.updateTerritories(gameState); this.updateTerritories(gameState);
@@ -112,7 +112,7 @@ Headquather.prototype.postinit = function(gameState)
* otherwise return undefined * otherwise return undefined
* for the moment, only the case land-sea-land is supported * for the moment, only the case land-sea-land is supported
*/ */
Headquather.prototype.getSeaBetweenIndices = function(gameState, index1, index2) Headquarters.prototype.getSeaBetweenIndices = function(gameState, index1, index2)
{ {
const path = gameState.ai.accessibility.getTrajectToIndex(index1, index2); const path = gameState.ai.accessibility.getTrajectToIndex(index1, index2);
if (path && path.length == 3 && gameState.ai.accessibility.regionType[path[1]] == "water") if (path && path.length == 3 && gameState.ai.accessibility.regionType[path[1]] == "water")
@@ -127,7 +127,7 @@ Headquather.prototype.getSeaBetweenIndices = function(gameState, index1, index2)
return undefined; return undefined;
}; };
Headquather.prototype.checkEvents = function(gameState, events) Headquarters.prototype.checkEvents = function(gameState, events)
{ {
this.buildManager.checkEvents(gameState, events); this.buildManager.checkEvents(gameState, events);
@@ -302,7 +302,7 @@ Headquather.prototype.checkEvents = function(gameState, events)
} }
}; };
Headquather.prototype.handleNewBase = function(gameState) Headquarters.prototype.handleNewBase = function(gameState)
{ {
if (!this.firstBaseConfig) if (!this.firstBaseConfig)
// This is our first base, let us configure our starting resources. // This is our first base, let us configure our starting resources.
@@ -317,7 +317,7 @@ Headquather.prototype.handleNewBase = function(gameState)
}; };
/** Ensure that all requirements are met when phasing up*/ /** Ensure that all requirements are met when phasing up*/
Headquather.prototype.checkPhaseRequirements = function(gameState, queues) Headquarters.prototype.checkPhaseRequirements = function(gameState, queues)
{ {
if (gameState.getNumberOfPhases() == this.currentPhase) if (gameState.getNumberOfPhases() == this.currentPhase)
return; return;
@@ -392,12 +392,12 @@ Headquather.prototype.checkPhaseRequirements = function(gameState, queues)
}; };
/** Called by any "phase" research plan once it's started */ /** Called by any "phase" research plan once it's started */
Headquather.prototype.OnPhaseUp = function(gameState, phase) Headquarters.prototype.OnPhaseUp = function(gameState, phase)
{ {
}; };
/** This code trains citizen workers, trying to keep close to a ratio of worker/soldiers */ /** This code trains citizen workers, trying to keep close to a ratio of worker/soldiers */
Headquather.prototype.trainMoreWorkers = function(gameState, queues) Headquarters.prototype.trainMoreWorkers = function(gameState, queues)
{ {
// default template // default template
const requirementsDef = [ ["costsResource", 1, "food"] ]; const requirementsDef = [ ["costsResource", 1, "food"] ];
@@ -506,7 +506,7 @@ Headquather.prototype.trainMoreWorkers = function(gameState, queues)
}; };
/** picks the best template based on parameters and classes */ /** picks the best template based on parameters and classes */
Headquather.prototype.findBestTrainableUnit = function(gameState, classes, requirements) Headquarters.prototype.findBestTrainableUnit = function(gameState, classes, requirements)
{ {
let units; let units;
if (classes.indexOf("Hero") != -1) if (classes.indexOf("Hero") != -1)
@@ -591,12 +591,12 @@ Headquather.prototype.findBestTrainableUnit = function(gameState, classes, requi
* returns an entity collection of workers through BaseManager.pickBuilders * returns an entity collection of workers through BaseManager.pickBuilders
* TODO: when same accessIndex, sort by distance * TODO: when same accessIndex, sort by distance
*/ */
Headquather.prototype.bulkPickWorkers = function(gameState, baseRef, number) Headquarters.prototype.bulkPickWorkers = function(gameState, baseRef, number)
{ {
return this.basesManager.bulkPickWorkers(gameState, baseRef, number); return this.basesManager.bulkPickWorkers(gameState, baseRef, number);
}; };
Headquather.prototype.getTotalResourceLevel = function(gameState, resources, proximity) Headquarters.prototype.getTotalResourceLevel = function(gameState, resources, proximity)
{ {
return this.basesManager.getTotalResourceLevel(gameState, resources, proximity); return this.basesManager.getTotalResourceLevel(gameState, resources, proximity);
}; };
@@ -605,7 +605,7 @@ Headquather.prototype.getTotalResourceLevel = function(gameState, resources, pro
* Returns the current gather rate * Returns the current gather rate
* This is not per-se exact, it performs a few adjustments ad-hoc to account for travel distance, stuffs like that. * This is not per-se exact, it performs a few adjustments ad-hoc to account for travel distance, stuffs like that.
*/ */
Headquather.prototype.GetCurrentGatherRates = function(gameState) Headquarters.prototype.GetCurrentGatherRates = function(gameState)
{ {
return this.basesManager.GetCurrentGatherRates(gameState); return this.basesManager.GetCurrentGatherRates(gameState);
}; };
@@ -613,7 +613,7 @@ Headquather.prototype.GetCurrentGatherRates = function(gameState)
/** /**
* Returns the wanted gather rate. * Returns the wanted gather rate.
*/ */
Headquather.prototype.GetWantedGatherRates = function(gameState) Headquarters.prototype.GetWantedGatherRates = function(gameState)
{ {
if (!this.turnCache.wantedRates) if (!this.turnCache.wantedRates)
this.turnCache.wantedRates = gameState.ai.queueManager.wantedGatherRates(gameState); this.turnCache.wantedRates = gameState.ai.queueManager.wantedGatherRates(gameState);
@@ -629,7 +629,7 @@ Headquather.prototype.GetWantedGatherRates = function(gameState)
* We compare; we pick the one where the discrepancy is highest. * We compare; we pick the one where the discrepancy is highest.
* Need to balance long-term needs and possible short-term needs. * Need to balance long-term needs and possible short-term needs.
*/ */
Headquather.prototype.pickMostNeededResources = function(gameState, allowedResources = []) Headquarters.prototype.pickMostNeededResources = function(gameState, allowedResources = [])
{ {
const wantedRates = this.GetWantedGatherRates(gameState); const wantedRates = this.GetWantedGatherRates(gameState);
const currentRates = this.GetCurrentGatherRates(gameState); const currentRates = this.GetCurrentGatherRates(gameState);
@@ -664,7 +664,7 @@ Headquather.prototype.pickMostNeededResources = function(gameState, allowedResou
* Returns the best position to build a new Civil Center * Returns the best position to build a new Civil Center
* Whose primary function would be to reach new resources of type "resource". * Whose primary function would be to reach new resources of type "resource".
*/ */
Headquather.prototype.findEconomicCCLocation = function(gameState, template, resource, proximity, fromStrategic) Headquarters.prototype.findEconomicCCLocation = function(gameState, template, resource, proximity, fromStrategic)
{ {
// This builds a map. The procedure is fairly simple. It adds the resource maps // This builds a map. The procedure is fairly simple. It adds the resource maps
// (which are dynamically updated and are made so that they will facilitate DP placement) // (which are dynamically updated and are made so that they will facilitate DP placement)
@@ -865,7 +865,7 @@ Headquather.prototype.findEconomicCCLocation = function(gameState, template, res
* Returns the best position to build a new Civil Center * Returns the best position to build a new Civil Center
* Whose primary function would be to assure territorial continuity with our allies * Whose primary function would be to assure territorial continuity with our allies
*/ */
Headquather.prototype.findStrategicCCLocation = function(gameState, template) Headquarters.prototype.findStrategicCCLocation = function(gameState, template)
{ {
// This builds a map. The procedure is fairly simple. // This builds a map. The procedure is fairly simple.
// We minimize the Sum((dist - 300)^2) where the sum is on the three nearest allied CC // We minimize the Sum((dist - 300)^2) where the sum is on the three nearest allied CC
@@ -1011,7 +1011,7 @@ Headquather.prototype.findStrategicCCLocation = function(gameState, template)
* To do so, we suppose that the gain/distance is an increasing function of distance and look for the max distance * To do so, we suppose that the gain/distance is an increasing function of distance and look for the max distance
* for performance reasons. * for performance reasons.
*/ */
Headquather.prototype.findMarketLocation = function(gameState, template) Headquarters.prototype.findMarketLocation = function(gameState, template)
{ {
let markets = gameState.updatingCollection("diplo-ExclusiveAllyMarkets", filters.byClass("Trade"), let markets = gameState.updatingCollection("diplo-ExclusiveAllyMarkets", filters.byClass("Trade"),
gameState.getExclusiveAllyEntities()).toEntityArray(); gameState.getExclusiveAllyEntities()).toEntityArray();
@@ -1132,7 +1132,7 @@ Headquather.prototype.findMarketLocation = function(gameState, template)
* Returns the best position to build defensive buildings (fortress and towers) * Returns the best position to build defensive buildings (fortress and towers)
* Whose primary function is to defend our borders * Whose primary function is to defend our borders
*/ */
Headquather.prototype.findDefensiveLocation = function(gameState, template) Headquarters.prototype.findDefensiveLocation = function(gameState, template)
{ {
// We take the point in our territory which is the nearest to any enemy cc // We take the point in our territory which is the nearest to any enemy cc
// but requiring a minimal distance with our other defensive structures // but requiring a minimal distance with our other defensive structures
@@ -1270,7 +1270,7 @@ Headquather.prototype.findDefensiveLocation = function(gameState, template)
return [x, z, this.baseAtIndex(bestJdx)]; return [x, z, this.baseAtIndex(bestJdx)];
}; };
Headquather.prototype.buildTemple = function(gameState, queues) Headquarters.prototype.buildTemple = function(gameState, queues)
{ {
// at least one market (which have the same queue) should be build before any temple // at least one market (which have the same queue) should be build before any temple
if (queues.economicBuilding.hasQueuedUnits() || if (queues.economicBuilding.hasQueuedUnits() ||
@@ -1289,7 +1289,7 @@ Headquather.prototype.buildTemple = function(gameState, queues)
queues.economicBuilding.addPlan(new ConstructionPlan(gameState, templateName)); queues.economicBuilding.addPlan(new ConstructionPlan(gameState, templateName));
}; };
Headquather.prototype.buildMarket = function(gameState, queues) Headquarters.prototype.buildMarket = function(gameState, queues)
{ {
if (gameState.getOwnEntitiesByClass("Market", true).hasEntities() || if (gameState.getOwnEntitiesByClass("Market", true).hasEntities() ||
!this.canBuild(gameState, "structures/{civ}/market")) !this.canBuild(gameState, "structures/{civ}/market"))
@@ -1325,7 +1325,7 @@ Headquather.prototype.buildMarket = function(gameState, queues)
}; };
/** Build a farmstead */ /** Build a farmstead */
Headquather.prototype.buildFarmstead = function(gameState, queues) Headquarters.prototype.buildFarmstead = function(gameState, queues)
{ {
// Only build one farmstead for the time being ("DropsiteFood" does not refer to CCs) // Only build one farmstead for the time being ("DropsiteFood" does not refer to CCs)
if (gameState.getOwnEntitiesByClass("Farmstead", true).hasEntities()) if (gameState.getOwnEntitiesByClass("Farmstead", true).hasEntities())
@@ -1347,7 +1347,7 @@ Headquather.prototype.buildFarmstead = function(gameState, queues)
* Try to build a wonder when required * Try to build a wonder when required
* force = true when called from the victoryManager in case of Wonder victory condition. * force = true when called from the victoryManager in case of Wonder victory condition.
*/ */
Headquather.prototype.buildWonder = function(gameState, queues, force = false) Headquarters.prototype.buildWonder = function(gameState, queues, force = false)
{ {
if (queues.wonder && queues.wonder.hasQueuedUnits() || if (queues.wonder && queues.wonder.hasQueuedUnits() ||
gameState.getOwnEntitiesByClass("Wonder", true).hasEntities() || gameState.getOwnEntitiesByClass("Wonder", true).hasEntities() ||
@@ -1377,7 +1377,7 @@ Headquather.prototype.buildWonder = function(gameState, queues, force = false)
}; };
/** Build a corral, and train animals there */ /** Build a corral, and train animals there */
Headquather.prototype.manageCorral = function(gameState, queues) Headquarters.prototype.manageCorral = function(gameState, queues)
{ {
if (queues.corral.hasQueuedUnits()) if (queues.corral.hasQueuedUnits())
return; return;
@@ -1424,7 +1424,7 @@ Headquather.prototype.manageCorral = function(gameState, queues)
* build more houses if needed. * build more houses if needed.
* kinda ugly, lots of special cases to both build enough houses but not tooo many… * kinda ugly, lots of special cases to both build enough houses but not tooo many…
*/ */
Headquather.prototype.buildMoreHouses = function(gameState, queues) Headquarters.prototype.buildMoreHouses = function(gameState, queues)
{ {
let houseTemplateString = "structures/{civ}/apartment"; let houseTemplateString = "structures/{civ}/apartment";
if (!gameState.isTemplateAvailable(gameState.applyCiv(houseTemplateString)) || if (!gameState.isTemplateAvailable(gameState.applyCiv(houseTemplateString)) ||
@@ -1518,7 +1518,7 @@ Headquather.prototype.buildMoreHouses = function(gameState, queues)
}; };
/** Checks the status of the territory expansion. If no new economic bases created, build some strategic ones. */ /** Checks the status of the territory expansion. If no new economic bases created, build some strategic ones. */
Headquather.prototype.checkBaseExpansion = function(gameState, queues) Headquarters.prototype.checkBaseExpansion = function(gameState, queues)
{ {
if (queues.civilCentre.hasQueuedUnits()) if (queues.civilCentre.hasQueuedUnits())
return; return;
@@ -1554,7 +1554,7 @@ Headquather.prototype.checkBaseExpansion = function(gameState, queues)
} }
}; };
Headquather.prototype.buildNewBase = function(gameState, queues, resource) Headquarters.prototype.buildNewBase = function(gameState, queues, resource)
{ {
if (this.hasPotentialBase() && this.currentPhase == 1 && !gameState.isResearching(gameState.getPhaseName(2))) if (this.hasPotentialBase() && this.currentPhase == 1 && !gameState.isResearching(gameState.getPhaseName(2)))
return false; return false;
@@ -1588,7 +1588,7 @@ Headquather.prototype.buildNewBase = function(gameState, queues, resource)
}; };
/** Deals with building fortresses and towers along our border with enemies. */ /** Deals with building fortresses and towers along our border with enemies. */
Headquather.prototype.buildDefenses = function(gameState, queues) Headquarters.prototype.buildDefenses = function(gameState, queues)
{ {
if (this.saveResources && !this.canBarter || queues.defenseBuilding.hasQueuedUnits()) if (this.saveResources && !this.canBarter || queues.defenseBuilding.hasQueuedUnits())
return; return;
@@ -1647,7 +1647,7 @@ Headquather.prototype.buildDefenses = function(gameState, queues)
} }
}; };
Headquather.prototype.buildForge = function(gameState, queues) Headquarters.prototype.buildForge = function(gameState, queues)
{ {
if (this.getAccountedPopulation(gameState) < this.Config.Military.popForForge || if (this.getAccountedPopulation(gameState) < this.Config.Military.popForForge ||
queues.militaryBuilding.hasQueuedUnits() || gameState.getOwnEntitiesByClass("Forge", true).length) queues.militaryBuilding.hasQueuedUnits() || gameState.getOwnEntitiesByClass("Forge", true).length)
@@ -1664,7 +1664,7 @@ Headquather.prototype.buildForge = function(gameState, queues)
* Deals with constructing military buildings (e.g. barracks, stable). * 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.
*/ */
Headquather.prototype.constructTrainingBuildings = function(gameState, queues) Headquarters.prototype.constructTrainingBuildings = function(gameState, queues)
{ {
if (this.saveResources && !this.canBarter || queues.militaryBuilding.hasQueuedUnits()) if (this.saveResources && !this.canBarter || queues.militaryBuilding.hasQueuedUnits())
return; return;
@@ -1779,7 +1779,7 @@ Headquather.prototype.constructTrainingBuildings = function(gameState, queues)
/** /**
* Find base nearest to ennemies for military buildings. * Find base nearest to ennemies for military buildings.
*/ */
Headquather.prototype.findBestBaseForMilitary = function(gameState) Headquarters.prototype.findBestBaseForMilitary = function(gameState)
{ {
const ccEnts = gameState.updatingGlobalCollection("allCCs", filters.byClass("CivCentre")).toEntityArray(); const ccEnts = gameState.updatingGlobalCollection("allCCs", filters.byClass("CivCentre")).toEntityArray();
let bestBase; let bestBase;
@@ -1815,7 +1815,7 @@ Headquather.prototype.findBestBaseForMilitary = function(gameState)
* train with highest priority ranged infantry in the nearest civil center from a given set of positions * train with highest priority ranged infantry in the nearest civil center from a given set of positions
* and garrison them there for defense * and garrison them there for defense
*/ */
Headquather.prototype.trainEmergencyUnits = function(gameState, positions) Headquarters.prototype.trainEmergencyUnits = function(gameState, positions)
{ {
if (gameState.ai.queues.emergency.hasQueuedUnits()) if (gameState.ai.queues.emergency.hasQueuedUnits())
return false; return false;
@@ -1920,7 +1920,7 @@ Headquather.prototype.trainEmergencyUnits = function(gameState, positions)
return true; return true;
}; };
Headquather.prototype.canBuild = function(gameState, structure) Headquarters.prototype.canBuild = function(gameState, structure)
{ {
const type = gameState.applyCiv(structure); const type = gameState.applyCiv(structure);
if (this.buildManager.isUnbuildable(gameState, type)) if (this.buildManager.isUnbuildable(gameState, type))
@@ -1974,7 +1974,7 @@ Headquather.prototype.canBuild = function(gameState, structure)
return true; return true;
}; };
Headquather.prototype.updateTerritories = function(gameState) Headquarters.prototype.updateTerritories = function(gameState)
{ {
const around = [ [-0.7, 0.7], [0, 1], [0.7, 0.7], [1, 0], [0.7, -0.7], [0, -1], [-0.7, -0.7], [-1, 0] ]; const around = [ [-0.7, 0.7], [0, 1], [0.7, 0.7], [1, 0], [0.7, -0.7], [0, -1], [-0.7, -0.7], [-1, 0] ];
const alliedVictory = gameState.getAlliedVictory(); const alliedVictory = gameState.getAlliedVictory();
@@ -2049,7 +2049,7 @@ Headquather.prototype.updateTerritories = function(gameState)
/** /**
* returns the base corresponding to baseID * returns the base corresponding to baseID
*/ */
Headquather.prototype.getBaseByID = function(baseID) Headquarters.prototype.getBaseByID = function(baseID)
{ {
return this.basesManager.getBaseByID(baseID); return this.basesManager.getBaseByID(baseID);
}; };
@@ -2059,33 +2059,33 @@ Headquather.prototype.getBaseByID = function(baseID)
* ActiveBases includes only those with a built cc * ActiveBases includes only those with a built cc
* PotentialBases includes also those with a cc in construction * PotentialBases includes also those with a cc in construction
*/ */
Headquather.prototype.numActiveBases = function() Headquarters.prototype.numActiveBases = function()
{ {
return this.basesManager.numActiveBases(); return this.basesManager.numActiveBases();
}; };
Headquather.prototype.hasActiveBase = function() Headquarters.prototype.hasActiveBase = function()
{ {
return this.basesManager.hasActiveBase(); return this.basesManager.hasActiveBase();
}; };
Headquather.prototype.numPotentialBases = function() Headquarters.prototype.numPotentialBases = function()
{ {
return this.basesManager.numPotentialBases(); return this.basesManager.numPotentialBases();
}; };
Headquather.prototype.hasPotentialBase = function() Headquarters.prototype.hasPotentialBase = function()
{ {
return this.basesManager.hasPotentialBase(); return this.basesManager.hasPotentialBase();
}; };
Headquather.prototype.isDangerousLocation = function(gameState, pos, radius) Headquarters.prototype.isDangerousLocation = function(gameState, pos, radius)
{ {
return this.isNearInvadingArmy(pos) || this.isUnderEnemyFire(gameState, pos, radius); return this.isNearInvadingArmy(pos) || this.isUnderEnemyFire(gameState, pos, radius);
}; };
/** Check that the chosen position is not too near from an invading army */ /** Check that the chosen position is not too near from an invading army */
Headquather.prototype.isNearInvadingArmy = function(pos) Headquarters.prototype.isNearInvadingArmy = function(pos)
{ {
for (const army of this.defenseManager.armies) for (const army of this.defenseManager.armies)
if (army.foePosition && SquareVectorDistance(army.foePosition, pos) < 12000) if (army.foePosition && SquareVectorDistance(army.foePosition, pos) < 12000)
@@ -2093,7 +2093,7 @@ Headquather.prototype.isNearInvadingArmy = function(pos)
return false; return false;
}; };
Headquather.prototype.isUnderEnemyFire = function(gameState, pos, radius = 0) Headquarters.prototype.isUnderEnemyFire = function(gameState, pos, radius = 0)
{ {
if (!this.turnCache.firingStructures) if (!this.turnCache.firingStructures)
{ {
@@ -2110,7 +2110,7 @@ Headquather.prototype.isUnderEnemyFire = function(gameState, pos, radius = 0)
}; };
/** Compute the capture strength of all units attacking a capturable target */ /** Compute the capture strength of all units attacking a capturable target */
Headquather.prototype.updateCaptureStrength = function(gameState) Headquarters.prototype.updateCaptureStrength = function(gameState)
{ {
this.capturableTargets.clear(); this.capturableTargets.clear();
for (const ent of gameState.getOwnUnits().values()) for (const ent of gameState.getOwnUnits().values())
@@ -2163,7 +2163,7 @@ Headquather.prototype.updateCaptureStrength = function(gameState)
/** /**
* Check if a structure in blinking territory should/can be defended (currently if it has some attacking armies around) * Check if a structure in blinking territory should/can be defended (currently if it has some attacking armies around)
*/ */
Headquather.prototype.isDefendable = function(ent) Headquarters.prototype.isDefendable = function(ent)
{ {
if (!this.turnCache.numAround) if (!this.turnCache.numAround)
this.turnCache.numAround = {}; this.turnCache.numAround = {};
@@ -2175,7 +2175,7 @@ Headquather.prototype.isDefendable = function(ent)
/** /**
* Get the number of population already accounted for * Get the number of population already accounted for
*/ */
Headquather.prototype.getAccountedPopulation = function(gameState) Headquarters.prototype.getAccountedPopulation = function(gameState)
{ {
if (this.turnCache.accountedPopulation == undefined) if (this.turnCache.accountedPopulation == undefined)
{ {
@@ -2199,7 +2199,7 @@ Headquather.prototype.getAccountedPopulation = function(gameState)
/** /**
* Get the number of workers already accounted for * Get the number of workers already accounted for
*/ */
Headquather.prototype.getAccountedWorkers = function(gameState) Headquarters.prototype.getAccountedWorkers = function(gameState)
{ {
if (this.turnCache.accountedWorkers == undefined) if (this.turnCache.accountedWorkers == undefined)
{ {
@@ -2218,7 +2218,7 @@ Headquather.prototype.getAccountedWorkers = function(gameState)
return this.turnCache.accountedWorkers; return this.turnCache.accountedWorkers;
}; };
Headquather.prototype.baseManagers = function() Headquarters.prototype.baseManagers = function()
{ {
return this.basesManager.baseManagers; return this.basesManager.baseManagers;
}; };
@@ -2227,7 +2227,7 @@ Headquather.prototype.baseManagers = function()
* @param {number} territoryIndex - The index to get the map for. * @param {number} territoryIndex - The index to get the map for.
* @return {number} - The ID of the base at the given territory index. * @return {number} - The ID of the base at the given territory index.
*/ */
Headquather.prototype.baseAtIndex = function(territoryIndex) Headquarters.prototype.baseAtIndex = function(territoryIndex)
{ {
return this.basesManager.baseAtIndex(territoryIndex); return this.basesManager.baseAtIndex(territoryIndex);
}; };
@@ -2236,7 +2236,7 @@ Headquather.prototype.baseAtIndex = function(territoryIndex)
* Some functions are run every turn * Some functions are run every turn
* Others once in a while * Others once in a while
*/ */
Headquather.prototype.update = function(gameState, queues, events) Headquarters.prototype.update = function(gameState, queues, events)
{ {
Engine.ProfileStart("Headquarters update"); Engine.ProfileStart("Headquarters update");
this.emergencyManager.update(gameState); this.emergencyManager.update(gameState);
@@ -2346,7 +2346,7 @@ Headquather.prototype.update = function(gameState, queues, events)
Engine.ProfileStop(); Engine.ProfileStop();
}; };
Headquather.prototype.Serialize = function() Headquarters.prototype.Serialize = function()
{ {
const properties = { const properties = {
"phasing": this.phasing, "phasing": this.phasing,
@@ -2408,7 +2408,7 @@ Headquather.prototype.Serialize = function()
}; };
}; };
Headquather.prototype.Deserialize = function(gameState, data) Headquarters.prototype.Deserialize = function(gameState, data)
{ {
for (const key in data.properties) for (const key in data.properties)
this[key] = data.properties[key]; this[key] = data.properties[key];
@@ -4,7 +4,7 @@ import { SquareVectorDistance, warn as aiWarn } from "simulation/ai/common-api/u
import { Config } from "simulation/ai/petra/config.js"; import { Config } from "simulation/ai/petra/config.js";
import * as difficulty from "simulation/ai/petra/difficultyLevel.js"; import * as difficulty from "simulation/ai/petra/difficultyLevel.js";
import { gatherTreasure, getLandAccess, isFastMoving } from "simulation/ai/petra/entityExtend.js"; import { gatherTreasure, getLandAccess, isFastMoving } from "simulation/ai/petra/entityExtend.js";
import { Headquather } from "simulation/ai/petra/headquarters.js"; import { Headquarters } from "simulation/ai/petra/headquarters.js";
import { ConstructionPlan } from "simulation/ai/petra/queueplanBuilding.js"; import { ConstructionPlan } from "simulation/ai/petra/queueplanBuilding.js";
/** /**
@@ -12,7 +12,7 @@ import { ConstructionPlan } from "simulation/ai/petra/queueplanBuilding.js";
* depending on the initial conditions * depending on the initial conditions
*/ */
Headquather.prototype.gameAnalysis = function(gameState) Headquarters.prototype.gameAnalysis = function(gameState)
{ {
// Analysis of the terrain and the different access regions // Analysis of the terrain and the different access regions
if (!this.regionAnalysis(gameState)) if (!this.regionAnalysis(gameState))
@@ -61,7 +61,7 @@ Headquather.prototype.gameAnalysis = function(gameState)
/** /**
* Assign the starting entities to the different bases * Assign the starting entities to the different bases
*/ */
Headquather.prototype.assignStartingEntities = function(gameState) Headquarters.prototype.assignStartingEntities = function(gameState)
{ {
for (const ent of gameState.getOwnEntities().values()) for (const ent of gameState.getOwnEntities().values())
{ {
@@ -108,7 +108,7 @@ Headquather.prototype.assignStartingEntities = function(gameState)
* determine the main land Index (or water index if none) * determine the main land Index (or water index if none)
* as well as the list of allowed (land andf water) regions * as well as the list of allowed (land andf water) regions
*/ */
Headquather.prototype.regionAnalysis = function(gameState) Headquarters.prototype.regionAnalysis = function(gameState)
{ {
const accessibility = gameState.ai.accessibility; const accessibility = gameState.ai.accessibility;
let landIndex; let landIndex;
@@ -205,7 +205,7 @@ Headquather.prototype.regionAnalysis = function(gameState)
* load units and buildings from the config files * load units and buildings from the config files
* TODO: change that to something dynamic * TODO: change that to something dynamic
*/ */
Headquather.prototype.structureAnalysis = function(gameState) Headquarters.prototype.structureAnalysis = function(gameState)
{ {
const civref = gameState.playerData.civ; const civref = gameState.playerData.civ;
const civ = civref in this.Config.buildings ? civref : 'default'; const civ = civref in this.Config.buildings ? civref : 'default';
@@ -219,7 +219,7 @@ Headquather.prototype.structureAnalysis = function(gameState)
* build our first base * build our first base
* if not enough resource, try first to do a dock * if not enough resource, try first to do a dock
*/ */
Headquather.prototype.buildFirstBase = function(gameState) Headquarters.prototype.buildFirstBase = function(gameState)
{ {
if (gameState.ai.queues.civilCentre.hasQueuedUnits()) if (gameState.ai.queues.civilCentre.hasQueuedUnits())
return; return;
@@ -336,7 +336,7 @@ Headquather.prototype.buildFirstBase = function(gameState)
* - if one of our allies has a cc, affect a small fraction of our army for his defense, the rest will attack * - if one of our allies has a cc, affect a small fraction of our army for his defense, the rest will attack
* - otherwise all units will attack * - otherwise all units will attack
*/ */
Headquather.prototype.dispatchUnits = function(gameState) Headquarters.prototype.dispatchUnits = function(gameState)
{ {
const allycc = gameState.getExclusiveAllyEntities().filter(filters.byClass("CivCentre")) const allycc = gameState.getExclusiveAllyEntities().filter(filters.byClass("CivCentre"))
.toEntityArray(); .toEntityArray();
@@ -416,7 +416,7 @@ Headquather.prototype.dispatchUnits = function(gameState)
* - if on a small island, favor fishing * - if on a small island, favor fishing
* - count the available wood resource, and allow rushes only if enough (we should otherwise favor expansion) * - count the available wood resource, and allow rushes only if enough (we should otherwise favor expansion)
*/ */
Headquather.prototype.configFirstBase = function(gameState) Headquarters.prototype.configFirstBase = function(gameState)
{ {
if (!this.hasPotentialBase()) if (!this.hasPotentialBase())
return; return;