0ad/binaries/data/mods/public/simulation/ai/common-api/baseAI.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

globalThis.PlayerID = -1;
export function BaseAI(settings)
{
if (!settings)
return;
this.player = settings.player;
}
2016-06-09 12:25:40 -07:00
/** Return a simple object (using no classes etc) that will be serialized into saved games */
BaseAI.prototype.Serialize = function()
{
return {};
};
2016-06-09 12:25:40 -07:00
/**
* Called after the constructor when loading a saved game, with 'data' being
* whatever Serialize() returned
*/
BaseAI.prototype.Deserialize = function(data, sharedScript)
{
};
BaseAI.prototype.Init = function(state, playerID, sharedAI)
{
PlayerID = playerID;
this.territoryMap = sharedAI.territoryMap;
this.accessibility = sharedAI.accessibility;
2016-06-09 12:25:40 -07:00
this.gameState = sharedAI.gameState[this.player];
this.gameState.ai = this;
2016-06-09 12:25:40 -07:00
this.timeElapsed = sharedAI.timeElapsed;
this.CustomInit(this.gameState);
};
2016-06-09 12:25:40 -07:00
/** AIs override this function */
BaseAI.prototype.CustomInit = function()
2016-06-09 12:25:40 -07:00
{
};
BaseAI.prototype.HandleMessage = function(state, playerID, sharedAI)
{
PlayerID = playerID;
this.territoryMap = sharedAI.territoryMap;
this.OnUpdate(sharedAI);
};
2016-06-09 12:25:40 -07:00
/** AIs override this function */
BaseAI.prototype.OnUpdate = function()
2016-06-09 12:25:40 -07:00
{
};
BaseAI.prototype.chat = function(message)
{
Engine.PostCommand(PlayerID, { "type": "aichat", "message": message });
};