LCOV - code coverage report
Current view: top level - simulation/ai/common-api - baseAI.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 33 0.0 %
Date: 2023-04-02 12:52:40 Functions: 0 9 0.0 %

          Line data    Source code
       1           0 : var PlayerID = -1;
       2             : 
       3           0 : var API3 = (function() {
       4             : 
       5           0 : var m = {};
       6             : 
       7           0 : m.BaseAI = function(settings)
       8             : {
       9           0 :         if (!settings)
      10           0 :                 return;
      11             : 
      12           0 :         this.player = settings.player;
      13             : 
      14             :         // played turn, in case you don't want the AI to play every turn.
      15           0 :         this.turn = 0;
      16             : };
      17             : 
      18             : /** Return a simple object (using no classes etc) that will be serialized into saved games */
      19           0 : m.BaseAI.prototype.Serialize = function()
      20             : {
      21           0 :         return {};
      22             : };
      23             : 
      24             : /**
      25             :  * Called after the constructor when loading a saved game, with 'data' being
      26             :  * whatever Serialize() returned
      27             :  */
      28           0 : m.BaseAI.prototype.Deserialize = function(data, sharedScript)
      29             : {
      30           0 :         this.isDeserialized = true;
      31             : };
      32             : 
      33           0 : m.BaseAI.prototype.Init = function(state, playerID, sharedAI)
      34             : {
      35           0 :         PlayerID = playerID;
      36             : 
      37           0 :         this.territoryMap = sharedAI.territoryMap;
      38           0 :         this.accessibility = sharedAI.accessibility;
      39             : 
      40           0 :         this.gameState = sharedAI.gameState[this.player];
      41           0 :         this.gameState.ai = this;
      42             : 
      43           0 :         this.timeElapsed = sharedAI.timeElapsed;
      44             : 
      45           0 :         this.CustomInit(this.gameState);
      46             : };
      47             : 
      48             : /** AIs override this function */
      49           0 : m.BaseAI.prototype.CustomInit = function()
      50             : {
      51             : };
      52             : 
      53           0 : m.BaseAI.prototype.HandleMessage = function(state, playerID, sharedAI)
      54             : {
      55           0 :         PlayerID = playerID;
      56           0 :         this.events = sharedAI.events;
      57           0 :         this.territoryMap = sharedAI.territoryMap;
      58             : 
      59           0 :         if (this.isDeserialized)
      60             :         {
      61           0 :                 this.Init(state, playerID, sharedAI);
      62           0 :                 this.isDeserialized = false;
      63             :         }
      64           0 :         this.OnUpdate(sharedAI);
      65             : };
      66             : 
      67             : /** AIs override this function */
      68           0 : m.BaseAI.prototype.OnUpdate = function()
      69             : {
      70             : };
      71             : 
      72           0 : m.BaseAI.prototype.chat = function(message)
      73             : {
      74           0 :         Engine.PostCommand(PlayerID, { "type": "aichat", "message": message });
      75             : };
      76             : 
      77           0 : return m;
      78             : 
      79             : }());
      80             : 

Generated by: LCOV version 1.14