Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/petra/headquarters.js
Show All 38 Lines | PETRA.HQ = function(Config) | ||||||||
this.buildManager = new PETRA.BuildManager(); | this.buildManager = new PETRA.BuildManager(); | ||||||||
this.defenseManager = new PETRA.DefenseManager(this.Config); | this.defenseManager = new PETRA.DefenseManager(this.Config); | ||||||||
this.tradeManager = new PETRA.TradeManager(this.Config); | this.tradeManager = new PETRA.TradeManager(this.Config); | ||||||||
this.navalManager = new PETRA.NavalManager(this.Config); | this.navalManager = new PETRA.NavalManager(this.Config); | ||||||||
this.researchManager = new PETRA.ResearchManager(this.Config); | this.researchManager = new PETRA.ResearchManager(this.Config); | ||||||||
this.diplomacyManager = new PETRA.DiplomacyManager(this.Config); | this.diplomacyManager = new PETRA.DiplomacyManager(this.Config); | ||||||||
this.garrisonManager = new PETRA.GarrisonManager(this.Config); | this.garrisonManager = new PETRA.GarrisonManager(this.Config); | ||||||||
this.victoryManager = new PETRA.VictoryManager(this.Config); | this.victoryManager = new PETRA.VictoryManager(this.Config); | ||||||||
this.emergencyManager = new PETRA.EmergencyManager(this.Config); | |||||||||
this.capturableTargets = new Map(); | this.capturableTargets = new Map(); | ||||||||
this.capturableTargetsTime = 0; | this.capturableTargetsTime = 0; | ||||||||
}; | }; | ||||||||
/** More initialisation for stuff that needs the gameState */ | /** More initialisation for stuff that needs the gameState */ | ||||||||
PETRA.HQ.prototype.init = function(gameState, queues) | PETRA.HQ.prototype.init = function(gameState, queues) | ||||||||
{ | { | ||||||||
this.territoryMap = PETRA.createTerritoryMap(gameState); | this.territoryMap = PETRA.createTerritoryMap(gameState); | ||||||||
// create borderMap: flag cells on the border of the map | // create borderMap: flag cells on the border of the map | ||||||||
// then this map will be completed with our frontier in updateTerritories | // then this map will be completed with our frontier in updateTerritories | ||||||||
this.borderMap = PETRA.createBorderMap(gameState); | this.borderMap = PETRA.createBorderMap(gameState); | ||||||||
// list of allowed regions | // list of allowed regions | ||||||||
this.landRegions = {}; | this.landRegions = {}; | ||||||||
// try to determine if we have a water map | // try to determine if we have a water map | ||||||||
this.navalMap = false; | this.navalMap = false; | ||||||||
this.navalRegions = {}; | this.navalRegions = {}; | ||||||||
this.treasures = gameState.getEntities().filter(ent => ent.isTreasure()); | this.treasures = gameState.getEntities().filter(ent => ent.isTreasure()); | ||||||||
this.treasures.registerUpdates(); | this.treasures.registerUpdates(); | ||||||||
this.currentPhase = gameState.currentPhase(); | this.currentPhase = gameState.currentPhase(); | ||||||||
this.decayingStructures = new Set(); | this.decayingStructures = new Set(); | ||||||||
this.emergencyManager.initPhases(gameState); | |||||||||
}; | }; | ||||||||
/** | /** | ||||||||
* initialization needed after deserialization (only called when deserialization) | * initialization needed after deserialization (only called when deserialization) | ||||||||
*/ | */ | ||||||||
PETRA.HQ.prototype.postinit = function(gameState) | PETRA.HQ.prototype.postinit = function(gameState) | ||||||||
{ | { | ||||||||
this.basesManager.postinit(gameState); | this.basesManager.postinit(gameState); | ||||||||
▲ Show 20 Lines • Show All 2,108 Lines • ▼ Show 20 Lines | |||||||||
/** | /** | ||||||||
* Some functions are run every turn | * Some functions are run every turn | ||||||||
* Others once in a while | * Others once in a while | ||||||||
*/ | */ | ||||||||
PETRA.HQ.prototype.update = function(gameState, queues, events) | PETRA.HQ.prototype.update = function(gameState, queues, events) | ||||||||
{ | { | ||||||||
Engine.ProfileStart("Headquarters update"); | Engine.ProfileStart("Headquarters update"); | ||||||||
this.emergencyManager.update(gameState); | |||||||||
FreagarachUnsubmitted Done Inline Actions
Freagarach: | |||||||||
this.turnCache = {}; | this.turnCache = {}; | ||||||||
this.territoryMap = PETRA.createTerritoryMap(gameState); | this.territoryMap = PETRA.createTerritoryMap(gameState); | ||||||||
this.canBarter = gameState.getOwnEntitiesByClass("Market", true).filter(API3.Filters.isBuilt()).hasEntities(); | this.canBarter = gameState.getOwnEntitiesByClass("Market", true).filter(API3.Filters.isBuilt()).hasEntities(); | ||||||||
// TODO find a better way to update | // TODO find a better way to update | ||||||||
if (this.currentPhase != gameState.currentPhase()) | if (this.currentPhase != gameState.currentPhase()) | ||||||||
{ | { | ||||||||
if (this.Config.debug > 0) | if (this.Config.debug > 0) | ||||||||
API3.warn(" civ " + gameState.getPlayerCiv() + " has phasedUp from " + this.currentPhase + | API3.warn(" civ " + gameState.getPlayerCiv() + " has phasedUp from " + this.currentPhase + | ||||||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | if (this.Config.debug == -100) | ||||||||
API3.warn(" buildManager " + uneval(this.buildManager.Serialize())); | API3.warn(" buildManager " + uneval(this.buildManager.Serialize())); | ||||||||
API3.warn(" defenseManager " + uneval(this.defenseManager.Serialize())); | API3.warn(" defenseManager " + uneval(this.defenseManager.Serialize())); | ||||||||
API3.warn(" tradeManager " + uneval(this.tradeManager.Serialize())); | API3.warn(" tradeManager " + uneval(this.tradeManager.Serialize())); | ||||||||
API3.warn(" navalManager " + uneval(this.navalManager.Serialize())); | API3.warn(" navalManager " + uneval(this.navalManager.Serialize())); | ||||||||
API3.warn(" researchManager " + uneval(this.researchManager.Serialize())); | API3.warn(" researchManager " + uneval(this.researchManager.Serialize())); | ||||||||
API3.warn(" diplomacyManager " + uneval(this.diplomacyManager.Serialize())); | API3.warn(" diplomacyManager " + uneval(this.diplomacyManager.Serialize())); | ||||||||
API3.warn(" garrisonManager " + uneval(this.garrisonManager.Serialize())); | API3.warn(" garrisonManager " + uneval(this.garrisonManager.Serialize())); | ||||||||
API3.warn(" victoryManager " + uneval(this.victoryManager.Serialize())); | API3.warn(" victoryManager " + uneval(this.victoryManager.Serialize())); | ||||||||
API3.warn(" emergencyManager " + uneval(this.emergencyManager.Serialize())); | |||||||||
} | } | ||||||||
return { | return { | ||||||||
"properties": properties, | "properties": properties, | ||||||||
"basesManager": this.basesManager.Serialize(), | "basesManager": this.basesManager.Serialize(), | ||||||||
"attackManager": this.attackManager.Serialize(), | "attackManager": this.attackManager.Serialize(), | ||||||||
"buildManager": this.buildManager.Serialize(), | "buildManager": this.buildManager.Serialize(), | ||||||||
"defenseManager": this.defenseManager.Serialize(), | "defenseManager": this.defenseManager.Serialize(), | ||||||||
"tradeManager": this.tradeManager.Serialize(), | "tradeManager": this.tradeManager.Serialize(), | ||||||||
"navalManager": this.navalManager.Serialize(), | "navalManager": this.navalManager.Serialize(), | ||||||||
"researchManager": this.researchManager.Serialize(), | "researchManager": this.researchManager.Serialize(), | ||||||||
"diplomacyManager": this.diplomacyManager.Serialize(), | "diplomacyManager": this.diplomacyManager.Serialize(), | ||||||||
"garrisonManager": this.garrisonManager.Serialize(), | "garrisonManager": this.garrisonManager.Serialize(), | ||||||||
"victoryManager": this.victoryManager.Serialize(), | "victoryManager": this.victoryManager.Serialize(), | ||||||||
"emergencyManager": this.emergencyManager.Serialize(), | |||||||||
}; | }; | ||||||||
}; | }; | ||||||||
PETRA.HQ.prototype.Deserialize = function(gameState, data) | PETRA.HQ.prototype.Deserialize = function(gameState, data) | ||||||||
{ | { | ||||||||
for (let key in data.properties) | for (let key in data.properties) | ||||||||
this[key] = data.properties[key]; | this[key] = data.properties[key]; | ||||||||
Show All 27 Lines | PETRA.HQ.prototype.Deserialize = function(gameState, data) | ||||||||
this.diplomacyManager = new PETRA.DiplomacyManager(this.Config); | this.diplomacyManager = new PETRA.DiplomacyManager(this.Config); | ||||||||
this.diplomacyManager.Deserialize(data.diplomacyManager); | this.diplomacyManager.Deserialize(data.diplomacyManager); | ||||||||
this.garrisonManager = new PETRA.GarrisonManager(this.Config); | this.garrisonManager = new PETRA.GarrisonManager(this.Config); | ||||||||
this.garrisonManager.Deserialize(data.garrisonManager); | this.garrisonManager.Deserialize(data.garrisonManager); | ||||||||
this.victoryManager = new PETRA.VictoryManager(this.Config); | this.victoryManager = new PETRA.VictoryManager(this.Config); | ||||||||
this.victoryManager.Deserialize(data.victoryManager); | this.victoryManager.Deserialize(data.victoryManager); | ||||||||
this.emergencyManager = new PETRA.EmergencyManager(this.Config); | |||||||||
this.emergencyManager.Deserialize(data.emergencyManager); | |||||||||
}; | }; |
Wildfire Games · Phabricator