LCOV - code coverage report
Current view: top level - simulation/helpers - InitGame.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 35 0.0 %
Date: 2023-04-02 12:52:40 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /**
       2             :  * Called when the map has been loaded, but before the simulation has started.
       3             :  * Only called when a new game is started, not when loading a saved game.
       4             :  */
       5             : function PreInitGame()
       6             : {
       7             :         // We need to replace skirmish "default" entities with real ones.
       8             :         // This needs to happen before AI initialization (in InitGame).
       9             :         // And we need to flush destroyed entities otherwise the AI gets the wrong game state in
      10             :         // the beginning and a bunch of "destroy" messages on turn 0, which just shouldn't happen.
      11           0 :         Engine.BroadcastMessage(MT_SkirmishReplace, {});
      12           0 :         Engine.FlushDestroyedEntities();
      13             : 
      14           0 :         let numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers();
      15           0 :         for (let i = 1; i < numPlayers; ++i) // ignore gaia
      16             :         {
      17           0 :                 let cmpTechnologyManager = QueryPlayerIDInterface(i, IID_TechnologyManager);
      18           0 :                 if (cmpTechnologyManager)
      19           0 :                         cmpTechnologyManager.UpdateAutoResearch();
      20             :         }
      21             : 
      22             :         // Explore the map inside the players' territory borders
      23           0 :         let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
      24           0 :         cmpRangeManager.ExploreTerritories();
      25             : }
      26             : 
      27             : function InitGame(settings)
      28             : {
      29             :         // No settings when loading a map in Atlas, so do nothing
      30           0 :         if (!settings)
      31             :         {
      32             :                 // Map dependent initialisations of components (i.e. garrisoned units)
      33           0 :                 Engine.BroadcastMessage(MT_InitGame, {});
      34           0 :                 return;
      35             :         }
      36             : 
      37           0 :         if (settings.ExploreMap)
      38             :         {
      39           0 :                 let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
      40           0 :                 for (let i = 1; i < settings.PlayerData.length; ++i)
      41           0 :                         cmpRangeManager.ExploreMap(i);
      42             :         }
      43             : 
      44           0 :         const cmpAIManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_AIManager);
      45           0 :         for (let i = 0; i < settings.PlayerData.length; ++i)
      46             :         {
      47           0 :                 const cmpPlayer = QueryPlayerIDInterface(i);
      48           0 :                 cmpPlayer.SetCheatsEnabled(!!settings.CheatsEnabled);
      49             : 
      50           0 :                 if (settings.PlayerData[i] && !!settings.PlayerData[i].AI)
      51             :                 {
      52           0 :                         cmpAIManager.AddPlayer(settings.PlayerData[i].AI, i, +settings.PlayerData[i].AIDiff, settings.PlayerData[i].AIBehavior || "random");
      53           0 :                         cmpPlayer.SetAI(true);
      54             :                 }
      55             : 
      56           0 :                 if (settings.PopulationCap)
      57           0 :                         cmpPlayer.SetMaxPopulation(settings.PopulationCap);
      58             : 
      59           0 :                 if (settings.AllyView)
      60           0 :                         Engine.QueryInterface(cmpPlayer.entity, IID_TechnologyManager)?.ResearchTechnology(cmpPlayer.template.SharedLosTech);
      61             :         }
      62           0 :         if (settings.WorldPopulationCap)
      63           0 :                 Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).SetMaxWorldPopulation(settings.WorldPopulationCap);
      64             : 
      65             :         // Update the grid with all entities created for the map init.
      66           0 :         Engine.QueryInterface(SYSTEM_ENTITY, IID_Pathfinder).UpdateGrid();
      67             : 
      68             :         // Map or player data (handicap...) dependent initialisations of components (i.e. garrisoned units).
      69           0 :         Engine.BroadcastMessage(MT_InitGame, {});
      70             : 
      71           0 :         cmpAIManager.TryLoadSharedComponent();
      72           0 :         cmpAIManager.RunGamestateInit();
      73             : }
      74             : 
      75           0 : Engine.RegisterGlobal("PreInitGame", PreInitGame);
      76           0 : Engine.RegisterGlobal("InitGame", InitGame);

Generated by: LCOV version 1.14