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

          Line data    Source code
       1             : 
       2             : /**
       3             :  * Used to initialize non-player settings relevant to the map, like
       4             :  * default stance and victory conditions. DO NOT load players here
       5             :  */
       6             : function LoadMapSettings(settings)
       7             : {
       8           0 :         if (!settings)
       9           0 :                 settings = {};
      10             : 
      11           0 :         if (settings.DefaultStance)
      12           0 :                 for (const ent of Engine.GetEntitiesWithInterface(IID_UnitAI))
      13             :                 {
      14           0 :                         const cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
      15           0 :                         cmpUnitAI.SwitchToStance(settings.DefaultStance);
      16             :                 }
      17             : 
      18           0 :         if (settings.RevealMap)
      19             :         {
      20           0 :                 const cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
      21           0 :                 if (cmpRangeManager)
      22           0 :                         cmpRangeManager.SetLosRevealAll(-1, true);
      23             :         }
      24             : 
      25           0 :         if (settings.DisableTreasures)
      26           0 :                 for (const ent of Engine.GetEntitiesWithInterface(IID_Treasure))
      27           0 :                         Engine.DestroyEntity(ent);
      28             : 
      29           0 :         const cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
      30           0 :         if (cmpRangeManager)
      31           0 :                 cmpRangeManager.SetLosCircular(!!settings.CircularMap);
      32             : 
      33           0 :         const cmpObstructionManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ObstructionManager);
      34           0 :         if (cmpObstructionManager)
      35           0 :                 cmpObstructionManager.SetPassabilityCircular(!!settings.CircularMap);
      36             : 
      37           0 :         if (settings.TriggerDifficulty !== undefined)
      38           0 :                 Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger).SetDifficulty(settings.TriggerDifficulty);
      39           0 :         else if (settings.SupportedTriggerDifficulties) // used by Atlas and autostart games
      40             :         {
      41           0 :                 let difficulties = Engine.ReadJSONFile("simulation/data/settings/trigger_difficulties.json").Data;
      42             :                 let defaultDiff;
      43           0 :                 if (settings.SupportedTriggerDifficulties.Default)
      44           0 :                         defaultDiff = difficulties.find(d => d.Name == settings.SupportedTriggerDifficulties.Default).Difficulty;
      45             :                 else
      46           0 :                         defaultDiff = difficulties.find(d => d.Default).Difficulty;
      47           0 :                 Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger).SetDifficulty(defaultDiff);
      48             :         }
      49             : 
      50           0 :         const cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager);
      51           0 :         const gameSettings = { "victoryConditions": clone(settings.VictoryConditions) };
      52           0 :         if (gameSettings.victoryConditions.indexOf("capture_the_relic") != -1)
      53             :         {
      54           0 :                 gameSettings.relicCount = (settings.RelicCount ?? 1);
      55           0 :                 gameSettings.relicDuration = (settings.RelicDuration ?? 1) * 60 * 1000;
      56             :         }
      57           0 :         if (gameSettings.victoryConditions.indexOf("wonder") != -1)
      58           0 :                 gameSettings.wonderDuration = (settings.WonderDuration ?? 1) * 60 * 1000;
      59           0 :         if (gameSettings.victoryConditions.indexOf("regicide") != -1)
      60           0 :                 gameSettings.regicideGarrison = settings.RegicideGarrison;
      61           0 :         cmpEndGameManager.SetGameSettings(gameSettings);
      62             : 
      63           0 :         cmpEndGameManager.SetAlliedVictory(settings.LockTeams || !settings.LastManStanding);
      64           0 :         if (settings.LockTeams && settings.LastManStanding)
      65           0 :                 warn("Last man standing is only available in games with unlocked teams!");
      66             : 
      67           0 :         const cmpCeasefireManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CeasefireManager);
      68           0 :         if (settings.Ceasefire)
      69           0 :                 cmpCeasefireManager.StartCeasefire((settings.Ceasefire ?? 1) * 60 * 1000);
      70             : }
      71             : 
      72           0 : Engine.RegisterGlobal("LoadMapSettings", LoadMapSettings);

Generated by: LCOV version 1.14