2025-08-03 04:30:17 -07:00
|
|
|
globalThis.PlayerID = -1;
|
2013-12-09 06:23:56 -08:00
|
|
|
|
2025-08-03 04:30:17 -07:00
|
|
|
export function BaseAI(settings)
|
2013-12-09 06:23:56 -08:00
|
|
|
{
|
|
|
|
|
if (!settings)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this.player = settings.player;
|
2025-08-03 04:30:17 -07:00
|
|
|
}
|
2013-12-09 06:23:56 -08:00
|
|
|
|
2016-06-09 12:25:40 -07:00
|
|
|
/** Return a simple object (using no classes etc) that will be serialized into saved games */
|
2025-08-03 04:30:17 -07:00
|
|
|
BaseAI.prototype.Serialize = function()
|
2013-12-09 06:23:56 -08:00
|
|
|
{
|
|
|
|
|
return {};
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-09 12:25:40 -07:00
|
|
|
/**
|
|
|
|
|
* Called after the constructor when loading a saved game, with 'data' being
|
|
|
|
|
* whatever Serialize() returned
|
|
|
|
|
*/
|
2025-08-03 04:30:17 -07:00
|
|
|
BaseAI.prototype.Deserialize = function(data, sharedScript)
|
2013-12-09 06:23:56 -08:00
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
2025-08-03 04:30:17 -07:00
|
|
|
BaseAI.prototype.Init = function(state, playerID, sharedAI)
|
2013-12-09 06:23:56 -08:00
|
|
|
{
|
2013-12-30 02:04:59 -08:00
|
|
|
PlayerID = playerID;
|
2017-06-07 11:26:15 -07:00
|
|
|
|
2013-12-09 06:23:56 -08:00
|
|
|
this.territoryMap = sharedAI.territoryMap;
|
|
|
|
|
this.accessibility = sharedAI.accessibility;
|
2016-06-09 12:25:40 -07:00
|
|
|
|
2013-12-30 02:04:59 -08:00
|
|
|
this.gameState = sharedAI.gameState[this.player];
|
2013-12-09 06:23:56 -08:00
|
|
|
this.gameState.ai = this;
|
2016-06-09 12:25:40 -07:00
|
|
|
|
2013-12-09 06:23:56 -08:00
|
|
|
this.timeElapsed = sharedAI.timeElapsed;
|
|
|
|
|
|
2017-06-07 11:26:15 -07:00
|
|
|
this.CustomInit(this.gameState);
|
2015-09-19 05:41:21 -07:00
|
|
|
};
|
2013-12-09 06:23:56 -08:00
|
|
|
|
2016-06-09 12:25:40 -07:00
|
|
|
/** AIs override this function */
|
2025-08-03 04:30:17 -07:00
|
|
|
BaseAI.prototype.CustomInit = function()
|
2016-06-09 12:25:40 -07:00
|
|
|
{
|
2013-12-09 06:23:56 -08:00
|
|
|
};
|
|
|
|
|
|
2025-08-03 04:30:17 -07:00
|
|
|
BaseAI.prototype.HandleMessage = function(state, playerID, sharedAI)
|
2013-12-09 06:23:56 -08:00
|
|
|
{
|
2013-12-30 02:04:59 -08:00
|
|
|
PlayerID = playerID;
|
2014-01-09 17:46:27 -08:00
|
|
|
this.territoryMap = sharedAI.territoryMap;
|
2013-12-09 06:23:56 -08:00
|
|
|
this.OnUpdate(sharedAI);
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-09 12:25:40 -07:00
|
|
|
/** AIs override this function */
|
2025-08-03 04:30:17 -07:00
|
|
|
BaseAI.prototype.OnUpdate = function()
|
2016-06-09 12:25:40 -07:00
|
|
|
{
|
2013-12-09 06:23:56 -08:00
|
|
|
};
|
|
|
|
|
|
2025-08-03 04:30:17 -07:00
|
|
|
BaseAI.prototype.chat = function(message)
|
2013-12-09 06:23:56 -08:00
|
|
|
{
|
2018-03-06 10:34:33 -08:00
|
|
|
Engine.PostCommand(PlayerID, { "type": "aichat", "message": message });
|
2013-12-09 06:23:56 -08:00
|
|
|
};
|