Slight de-obfuscation of the AI code.

This was SVN commit r14317.
This commit is contained in:
wraitii 2013-12-09 14:20:11 +00:00
parent 9339e658a5
commit f9bee5d3ec
4 changed files with 15 additions and 17 deletions

View File

@ -34,7 +34,7 @@ function AegisBot(settings) {
AegisBot.prototype = new BaseAI();
AegisBot.prototype.InitShared = function(gameState, sharedScript) {
AegisBot.prototype.CustomInit = function(gameState, sharedScript) {
this.HQ.init(gameState,sharedScript.events,this.queues);
debug ("Initialized with the difficulty " + Config.difficulty);

View File

@ -678,6 +678,7 @@ HQ.prototype.buildMarket = function(gameState, queues){
// Build a farmstead to go to town phase faster and prepare for research. Only really active on higher diff mode.
HQ.prototype.buildFarmstead = function(gameState, queues){
if (gameState.getPopulation() > Config.Economy.popForFarmstead) {
// achtung: "DropsiteFood" does not refer to CCs.
if (queues.economicBuilding.countQueuedUnitsWithClass("DropsiteFood") === 0 &&
gameState.countEntitiesAndQueuedByType(gameState.applyCiv("structures/{civ}_farmstead")) === 0){
//only ever build one storehouse/CC/market at a time

View File

@ -165,10 +165,10 @@ SharedScript.prototype.GetTemplate = function(name)
return null;
};
// initialize the shared component using a given gamestate (the initial gamestate after map creation, usually)
// this is called right at the end of map generation, before you actually reach the map.
SharedScript.prototype.initWithState = function(state) {
this.events = state.events;
// Initialize the shared component.
// We need to now the initial state of the game for this, as we will use it.
// This is called right at the end of the map generation.
SharedScript.prototype.init = function(state) {
this.passabilityClasses = state.passabilityClasses;
this.passabilityMap = state.passabilityMap;
this.players = this._players;
@ -180,11 +180,9 @@ SharedScript.prototype.initWithState = function(state) {
this._techModifications[o] = state.players[o].techModifications;
this._entities = {};
for (var id in state.entities)
{
this._entities[id] = new Entity(this, state.entities[id]);
}
// entity collection updated on create/destroy event.
this.entities = new EntityCollection(this, this._entities);
@ -203,21 +201,21 @@ SharedScript.prototype.initWithState = function(state) {
this.gameState[this._players[i]] = new GameState();
this.gameState[this._players[i]].init(this,state,this._players[i]);
}
};
// General update of the shared script, before each AI's update
// applies entity deltas, and each gamestate.
SharedScript.prototype.onUpdate = function(state)
{
// deals with updating based on create and destroy messages.
this.ApplyEntitiesDelta(state);
Engine.ProfileStart("onUpdate");
// those are dynamic and need to be reset as the "state" object moves in memory.
this.events = state.events;
this.passabilityClasses = state.passabilityClasses;
this.passabilityMap = state.passabilityMap;
this.players = this._players;
this.playersData = state.players;
this.territoryMap = state.territoryMap;
this.timeElapsed = state.timeElapsed;
@ -228,11 +226,10 @@ SharedScript.prototype.onUpdate = function(state)
for (var i in this.gameState)
this.gameState[i].update(this,state);
// TODO: merge those two with "ApplyEntitiesDelta" since after all they do the same.
this.updateResourceMaps(this, this.events);
this.terrainAnalyzer.updateMapWithEvents(this);
//this.OnUpdate();
this.turn++;
Engine.ProfileStop();

View File

@ -282,10 +282,10 @@ private:
m_Commands.clear();
m_ScriptInterface.CallFunctionVoid(m_Obj.get(), "HandleMessage", state, SharedAI);
}
void InitWithSharedScript(CScriptVal state, CScriptValRooted SharedAI)
void InitAI(CScriptVal state, CScriptValRooted SharedAI)
{
m_Commands.clear();
m_ScriptInterface.CallFunctionVoid(m_Obj.get(), "InitWithSharedScript", state, SharedAI);
m_ScriptInterface.CallFunctionVoid(m_Obj.get(), "Init", state, SharedAI);
}
CAIWorker& m_Worker;
@ -523,13 +523,13 @@ public:
m_ScriptInterface.SetProperty(state.get(), "passabilityMap", m_PassabilityMapVal, true);
m_ScriptInterface.SetProperty(state.get(), "territoryMap", m_TerritoryMapVal, true);
m_ScriptInterface.CallFunctionVoid(m_SharedAIObj.get(), "initWithState", state);
m_ScriptInterface.CallFunctionVoid(m_SharedAIObj.get(), "init", state);
m_ScriptInterface.MaybeGC();
for (size_t i = 0; i < m_Players.size(); ++i)
{
if (m_HasSharedComponent && m_Players[i]->m_UseSharedComponent)
m_Players[i]->InitWithSharedScript(state,m_SharedAIObj);
m_Players[i]->InitAI(state,m_SharedAIObj);
}
}