]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
g_maxplayers -1: when rounding to a team multiple, go down at the midpoint
authorbones_was_here <bones_was_here@xonotic.au>
Fri, 29 Sep 2023 05:13:49 +0000 (15:13 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Fri, 29 Sep 2023 05:13:49 +0000 (15:13 +1000)
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.

qcsrc/server/world.qc

index 3487b68073ac571998f6879d957f5093e2a0ff30..311800dcd10eee8509b43ea99352d738835b0594 100644 (file)
@@ -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