Class: HQ

HQ()

Headquarters Deal with high level logic for the AI. Most of the interesting stuff gets done here. Some tasks: -defining RESS needs -BO decisions. > training workers > building stuff (though we'll send that to bases) -picking strategy (specific manager?) -diplomacy -> diplomacyManager -planning attacks -> attackManager -picking new CC locations.

Constructor

new HQ()

Source:

Classes

gameAnalysis

Methods

assignStartingEntities()

Assign the starting entities to the different bases
Source:

baseAtIndex(territoryIndex) → {number}

Parameters:
Name Type Description
territoryIndex number The index to get the map for.
Source:
Returns:
- The ID of the base at the given territory index.
Type
number

buildDefenses()

Deals with building fortresses and towers along our border with enemies.
Source:

buildFarmstead()

Build a farmstead
Source:

buildFirstBase()

build our first base if not enough resource, try first to do a dock
Source:

buildMoreHouses()

build more houses if needed. kinda ugly, lots of special cases to both build enough houses but not tooo many…
Source:

buildWonder()

Try to build a wonder when required force = true when called from the victoryManager in case of Wonder victory condition.
Source:

bulkPickWorkers()

returns an entity collection of workers through BaseManager.pickBuilders TODO: when same accessIndex, sort by distance
Source:

checkBaseExpansion()

Checks the status of the territory expansion. If no new economic bases created, build some strategic ones.
Source:

checkPhaseRequirements()

Ensure that all requirements are met when phasing up
Source:

configFirstBase()

configure our first base expansion - if on a small island, favor fishing - count the available wood resource, and allow rushes only if enough (we should otherwise favor expansion)
Source:

constructTrainingBuildings()

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.
Source:

dispatchUnits()

set strategy if game without construction: - 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
Source:

findBestBaseForMilitary()

Find base nearest to ennemies for military buildings.
Source:

findBestTrainableUnit()

picks the best template based on parameters and classes
Source:

findDefensiveLocation()

Returns the best position to build defensive buildings (fortress and towers) Whose primary function is to defend our borders
Source:

findEconomicCCLocation()

Returns the best position to build a new Civil Center Whose primary function would be to reach new resources of type "resource".
Source:

findMarketLocation()

Returns the best position to build a new market: if the allies already have a market, build it as far as possible from it, although not in our border to be able to defend it easily. If no allied market, our second market will follow the same logic. To do so, we suppose that the gain/distance is an increasing function of distance and look for the max distance for performance reasons.
Source:

findStrategicCCLocation()

Returns the best position to build a new Civil Center Whose primary function would be to assure territorial continuity with our allies
Source:

getAccountedPopulation()

Get the number of population already accounted for
Source:

getAccountedWorkers()

Get the number of workers already accounted for
Source:

getBaseByID()

returns the base corresponding to baseID
Source:

GetCurrentGatherRates()

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.
Source:

getSeaBetweenIndices()

returns the sea index linking regions 1 and region 2 (supposed to be different land region) otherwise return undefined for the moment, only the case land-sea-land is supported
Source:

GetWantedGatherRates()

Returns the wanted gather rate.
Source:

init()

More initialisation for stuff that needs the gameState
Source:

isDefendable()

Check if a structure in blinking territory should/can be defended (currently if it has some attacking armies around)
Source:

isNearInvadingArmy()

Check that the chosen position is not too near from an invading army
Source:

manageCorral()

Build a corral, and train animals there
Source:

numActiveBases()

returns the number of bases with a cc ActiveBases includes only those with a built cc PotentialBases includes also those with a cc in construction
Source:

OnPhaseUp()

Called by any "phase" research plan once it's started
Source:

pickMostNeededResources()

Pick the resource which most needs another worker How this works: We get the rates we would want to have to be able to deal with our plans We get our current rates We compare; we pick the one where the discrepancy is highest. Need to balance long-term needs and possible short-term needs.
Source:

postinit()

initialization needed after deserialization (only called when deserialization)
Source:

regionAnalysis()

determine the main land Index (or water index if none) as well as the list of allowed (land andf water) regions
Source:

structureAnalysis()

load units and buildings from the config files TODO: change that to something dynamic
Source:

trainEmergencyUnits()

train with highest priority ranged infantry in the nearest civil center from a given set of positions and garrison them there for defense
Source:

trainMoreWorkers()

This code trains citizen workers, trying to keep close to a ratio of worker/soldiers
Source:

update()

Some functions are run every turn Others once in a while
Source:

updateCaptureStrength()

Compute the capture strength of all units attacking a capturable target
Source: