]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/command/vote.qc
Implement automatic per-map min & max player limits
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / vote.qc
index 42d78dd0ac29dae5653e216bc227920eb4669f05..3367ef310c2e1eb5d97852b34964f1aa5188ab02 100644 (file)
@@ -11,6 +11,7 @@
 #include <common/stats.qh>
 #include <common/util.qh>
 #include <common/weapons/_all.qh>
+#include <server/campaign.qh>
 #include <server/client.qh>
 #include <server/command/banning.qh>
 #include <server/command/common.qh>
@@ -439,6 +440,8 @@ void ReadyRestart_force(bool is_fake_round_start)
 
        if(warmup_stage)
                game_starttime = time; // Warmup: No countdown in warmup
+       else if (autocvar_g_campaign)
+               game_starttime = time + 3;
        else
                game_starttime = time + RESTART_COUNTDOWN; // Go into match mode
 
@@ -483,10 +486,16 @@ void ReadyRestart_force(bool is_fake_round_start)
 
 void ReadyRestart(bool forceWarmupEnd)
 {
-       if (MUTATOR_CALLHOOK(ReadyRestart_Deny) || intermission_running || race_completing) localcmd("restart\n");
+       if (MUTATOR_CALLHOOK(ReadyRestart_Deny) || intermission_running || race_completing)
+       {
+               // NOTE: ReadyRestart support is mandatory in campaign
+               if (autocvar_g_campaign)
+                       error("ReadyRestart must be supported in campaign mode!");
+               localcmd("restart\n"); // if ReadyRestart is denied, restart the server
+       }
        else localcmd("\nsv_hook_readyrestart\n");
 
-       if(forceWarmupEnd)
+       if(forceWarmupEnd || autocvar_g_campaign)
                warmup_stage = 0; // forcefully end warmup and go to match stage
        else
                warmup_stage = cvar("g_warmup"); // go into warmup if it's enabled, otherwise restart into match stage
@@ -494,21 +503,46 @@ void ReadyRestart(bool forceWarmupEnd)
        ReadyRestart_force(false);
 }
 
-// Count the players who are ready and determine whether or not to restart the match
+/* Count the players who are ready and determine whether or not to restart the match when:
+ * a player presses F4                      server/command/cmd.qc  ClientCommand_ready()
+ * a player switches from players to specs  server/client.qc       PutObserverInServer()
+ * a player joins (from specs or directly)  server/client.qc       PutPlayerInServer()
+ * a player disconnects                     server/client.qc       ClientDisconnect()  */
 void ReadyCount()
 {
+       // cannot reset the game while a timeout is active or pending
+       if (timeout_status) return;
+
        float ready_needed_factor, ready_needed_count;
-       float t_ready = 0, t_players = 0;
+       float t_players = 0;
+       readycount = 0;
 
        FOREACH_CLIENT(IS_REAL_CLIENT(it) && (IS_PLAYER(it) || INGAME_JOINED(it)), {
                ++t_players;
-               if (it.ready) ++t_ready;
+               if (it.ready) ++readycount;
        });
 
-       readycount = t_ready;
-
        Nagger_ReadyCounted();
 
+       if (t_players < map_minplayers) // map_minplayers will only be set if g_warmup -1 at worldspawn
+       {
+               // TODO: handle player spectating/disconnecting during countdown
+               if (warmup_limit > 0)
+                       warmup_limit = -1;
+               return; // don't ReadyRestart if players are ready but too few
+       }
+       else if (map_minplayers && warmup_limit <= 0)
+       {
+               // there's enough players now but we're still in infinite warmup
+               warmup_limit = cvar("g_warmup_limit");
+               if (warmup_limit == 0)
+                       warmup_limit = autocvar_timelimit * 60;
+               if (warmup_limit > 0)
+                       game_starttime = time;
+               // implicit else: g_warmup -1 && g_warmup_limit -1 means
+               // warmup continues until enough players AND enough RUPs (no time limit)
+       }
+
        ready_needed_factor = bound(0.5, cvar("g_warmup_majority_factor"), 0.999);
        ready_needed_count = floor(t_players * ready_needed_factor) + 1;