Index: binaries/data/mods/public/simulation/helpers/Commands.js =================================================================== --- binaries/data/mods/public/simulation/helpers/Commands.js +++ binaries/data/mods/public/simulation/helpers/Commands.js @@ -1124,6 +1124,7 @@ // To calculate this with an entity requires ownership, so use the template instead let cmpCost = Engine.QueryInterface(ent, IID_Cost); let costs = cmpCost.GetResourceCosts(player); + let popCost = cmpCost.GetPopCost(player); if (!cmpPlayer.TrySubtractResources(costs)) { @@ -1134,6 +1135,17 @@ cmpPosition.MoveOutOfWorld(); return false; } + + // check pop cost too. Offset the popCost as the entity is added already. Also, notice TryReservePopulationCost can't be used here. + if (popCost > (cmpPlayer.GetPopulationLimit() - cmpPlayer.GetPopulationCount() + popCost)) + { + if (g_DebugCommands) + warn("Invalid command: building poulation cost check failed for player "+player+": "+uneval(cmd)); + + Engine.DestroyEntity(ent); + cmpPosition.MoveOutOfWorld(); + return false; + } var cmpVisual = Engine.QueryInterface(ent, IID_Visual); if (cmpVisual && cmd.actorSeed !== undefined)