From: bones_was_here Date: Fri, 29 Sep 2023 05:13:49 +0000 (+1000) Subject: g_maxplayers -1: when rounding to a team multiple, go down at the midpoint X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fd673ca98255dc41b080411c59712137b189079e;p=xonotic%2Fxonotic-data.pk3dir.git g_maxplayers -1: when rounding to a team multiple, go down at the midpoint It seems a 5 players max DM map is more likely to suit 2v2 TDM/FT than 3v3. It will still round up to 6 if there's 3 teams. Also catches misconfigurations with g_maxplayers -1 and no teams. Changes to more meaningful var names. --- diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index 3487b6807..311800dcd 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -663,14 +663,18 @@ void GameplayMode_DelayedInit(entity this) if (!g_duel) MapReadSizes(mapname); - if (autocvar_g_maxplayers < 0 && teamplay) + if (autocvar_g_maxplayers < 0) { - // automatic maxplayers should be a multiple of team count - if (map_maxplayers == 0 || map_maxplayers > maxclients) + if (map_maxplayers <= 0) map_maxplayers = maxclients; // unlimited, but may need rounding - int d = map_maxplayers % AVAILABLE_TEAMS; - int u = AVAILABLE_TEAMS - d; - map_maxplayers += (u <= d && u + map_maxplayers <= maxclients) ? u : -d; + map_maxplayers = bound(max(2, AVAILABLE_TEAMS * 2), map_maxplayers, maxclients); + if (teamplay) + { + // automatic maxplayers should be a multiple of team count + int down = map_maxplayers % AVAILABLE_TEAMS; + int up = AVAILABLE_TEAMS - down; + map_maxplayers += (up < down && up + map_maxplayers <= maxclients) ? up : -down; + } } if (warmup_stage < 0) @@ -681,9 +685,9 @@ void GameplayMode_DelayedInit(entity this) if (teamplay) { // automatic minplayers should be a multiple of team count - int d = map_minplayers % AVAILABLE_TEAMS; - int u = AVAILABLE_TEAMS - d; - map_minplayers += (u < d && u + map_minplayers <= m) ? u : -d; + int down = map_minplayers % AVAILABLE_TEAMS; + int up = AVAILABLE_TEAMS - down; + map_minplayers += (up < down && up + map_minplayers <= m) ? up : -down; } } else