1
0
forked from mirrors/0ad

Complete the per-player pop cap implementation

The 'PopulationLimit' attribute of each player seems to have been
without effect for a long time, but this patch fixes it.

Fixes #7850
This commit is contained in:
Vantha
2025-11-27 11:26:18 +01:00
parent 3a73dffc1c
commit 9b8ff77265
2 changed files with 27 additions and 11 deletions
@@ -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);
};
/**
@@ -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();