From 3a73dffc1c3d2f7ee6f0decb5850ad6ecf1445e4 Mon Sep 17 00:00:00 2001 From: Vantha Date: Wed, 26 Nov 2025 21:49:07 +0100 Subject: [PATCH] Add fallback values for pop cap and pop cap type Make InitGame.js responsible for providing proper (defined) values. Refs #7850 Fixes #7695 --- .../simulation/components/PopulationCapManager.js | 12 +++++------- .../data/mods/public/simulation/helpers/InitGame.js | 8 ++++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/PopulationCapManager.js b/binaries/data/mods/public/simulation/components/PopulationCapManager.js index 32d055d1fa..d509ce6212 100644 --- a/binaries/data/mods/public/simulation/components/PopulationCapManager.js +++ b/binaries/data/mods/public/simulation/components/PopulationCapManager.js @@ -17,13 +17,11 @@ PopulationCapManager.prototype.Init = function() */ PopulationCapManager.prototype.SetPopulationCapType = function(type) { - if ([this.CAPTYPE_PLAYER_POPULATION, this.CAPTYPE_TEAM_POPULATION, this.CAPTYPE_WORLD_POPULATION].includes(type)) - this.popCapType = type; - else - { - warn(`Attempted to set an unknown population capacity type: '${type}'. Continuing with type 'Player Population'...`); - this.popCapType = this.CAPTYPE_PLAYER_POPULATION; - } + if (![this.CAPTYPE_PLAYER_POPULATION, this.CAPTYPE_TEAM_POPULATION, this.CAPTYPE_WORLD_POPULATION].includes(type)) + error("Invalid population cap type specified: " + type); + + this.popCapType = type; + if (this.popCap) this.InitializePopCaps(); }; diff --git a/binaries/data/mods/public/simulation/helpers/InitGame.js b/binaries/data/mods/public/simulation/helpers/InitGame.js index e6910b8d8b..648b15b578 100644 --- a/binaries/data/mods/public/simulation/helpers/InitGame.js +++ b/binaries/data/mods/public/simulation/helpers/InitGame.js @@ -65,8 +65,12 @@ function InitGame(settings) } const cmpPopulationCapManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PopulationCapManager); - cmpPopulationCapManager.SetPopulationCapType(settings.PopulationCapType); - cmpPopulationCapManager.SetPopulationCap(settings.PopulationCap); + if ([cmpPopulationCapManager.CAPTYPE_PLAYER_POPULATION, cmpPopulationCapManager.CAPTYPE_TEAM_POPULATION, + cmpPopulationCapManager.CAPTYPE_WORLD_POPULATION].includes(settings.PopulationCapType)) + cmpPopulationCapManager.SetPopulationCapType(settings.PopulationCapType); + else + cmpPopulationCapManager.SetPopulationCapType(cmpPopulationCapManager.CAPTYPE_PLAYER_POPULATION); + cmpPopulationCapManager.SetPopulationCap(settings.PopulationCap || 300); // Update the grid with all entities created for the map init. Engine.QueryInterface(SYSTEM_ENTITY, IID_Pathfinder).UpdateGrid();