diff --git a/binaries/data/mods/public/simulation/components/PopulationCapManager.js b/binaries/data/mods/public/simulation/components/PopulationCapManager.js index d509ce6212..1726cc5b72 100644 --- a/binaries/data/mods/public/simulation/components/PopulationCapManager.js +++ b/binaries/data/mods/public/simulation/components/PopulationCapManager.js @@ -46,6 +46,13 @@ PopulationCapManager.prototype.SetPopulationCap = function(cap) this.InitializePopCaps(); }; +PopulationCapManager.prototype.SetPerPlayerPopulationCaps = function(playerCaps) +{ + this.perPlayerPopCaps = playerCaps; + this.popCapType = this.CAPTYPE_PLAYER_POPULATION; + this.InitializePopCaps(); +}; + /** * Get the current pop cap. * @returns {number} @@ -84,10 +91,10 @@ PopulationCapManager.prototype.InitializePopCaps = function() */ PopulationCapManager.prototype.InitializePlayerPopCaps = function() { - const players = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetActivePlayers(); - for (const player of players) - QueryPlayerIDInterface(player, IID_Player) - .SetMaxPopulation(this.popCap); + const players = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNonGaiaPlayers(); + for (const i in players) + QueryPlayerIDInterface(players[i], IID_Player) + .SetMaxPopulation(this.perPlayerPopCaps ? this.perPlayerPopCaps[i] : this.popCap); }; /** diff --git a/binaries/data/mods/public/simulation/helpers/InitGame.js b/binaries/data/mods/public/simulation/helpers/InitGame.js index 648b15b578..1af2bd9645 100644 --- a/binaries/data/mods/public/simulation/helpers/InitGame.js +++ b/binaries/data/mods/public/simulation/helpers/InitGame.js @@ -64,13 +64,22 @@ function InitGame(settings) Engine.QueryInterface(cmpPlayer.entity, IID_TechnologyManager)?.ResearchTechnology(Engine.QueryInterface(cmpPlayer.entity, IID_Diplomacy).template.SharedLosTech); } - const cmpPopulationCapManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PopulationCapManager); - 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); + { + const popCap = settings.PopulationCap || 300; + const cmpPopulationCapManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PopulationCapManager); + const nonGaiaPlayers = settings.PlayerData.slice(1); + if (nonGaiaPlayers.some(player => player.PopulationLimit)) + cmpPopulationCapManager.SetPerPlayerPopulationCaps(nonGaiaPlayers.map(player => player.PopulationLimit || popCap)); + else + { + 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(popCap); + } + } // Update the grid with all entities created for the map init. Engine.QueryInterface(SYSTEM_ENTITY, IID_Pathfinder).UpdateGrid();