0ad/binaries/data/mods/public/simulation/ai/common-api/baseAI.js
phosit 2f2cbb96bf
Some checks are pending
checkrefs / lfscheck (push) Waiting to run
checkrefs / checkrefs (push) Waiting to run
lint / cppcheck (push) Waiting to run
lint / copyright (push) Waiting to run
lint / jenkinsfiles (push) Waiting to run
pre-commit / build (push) Waiting to run
Remove this.isDeserialized from BaseAI
`this.isDeserialized` is only required for AIs which `Deserialize`
function depends on the game state.
2026-06-14 17:52:54 +02:00

60 lines
1.2 KiB
JavaScript

globalThis.PlayerID = -1;
export function BaseAI(settings)
{
if (!settings)
return;
this.player = settings.player;
}
/** Return a simple object (using no classes etc) that will be serialized into saved games */
BaseAI.prototype.Serialize = function()
{
return {};
};
/**
* 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;
this.gameState = sharedAI.gameState[this.player];
this.gameState.ai = this;
this.timeElapsed = sharedAI.timeElapsed;
this.CustomInit(this.gameState);
};
/** AIs override this function */
BaseAI.prototype.CustomInit = function()
{
};
BaseAI.prototype.HandleMessage = function(state, playerID, sharedAI)
{
PlayerID = playerID;
this.territoryMap = sharedAI.territoryMap;
this.OnUpdate(sharedAI);
};
/** AIs override this function */
BaseAI.prototype.OnUpdate = function()
{
};
BaseAI.prototype.chat = function(message)
{
Engine.PostCommand(PlayerID, { "type": "aichat", "message": message });
};