]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/round_handler.qc
Merge commit '40b7b8b8f77676', fixes #1937
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / round_handler.qc
index 0883847815cf2cb348ea7265732d2e2bab7263d4..af69e8e9e55d30a826f56d4bb6d78c384435ff39 100644 (file)
@@ -17,10 +17,10 @@ void round_handler_Think()
 
        if(self.wait)
        {
-               reset_map(TRUE);
                self.wait = FALSE;
                self.cnt = self.count + 1; // init countdown
                round_starttime = time + self.count;
+               reset_map(TRUE);
        }
 
        if(self.cnt > 0) // countdown running
@@ -33,7 +33,7 @@ void round_handler_Think()
                        if(f == 0)
                        {
                                self.cnt = 0;
-                               self.round_endtime = time + self.round_timelimit;
+                               self.round_endtime = (self.round_timelimit) ? time + self.round_timelimit : 0;
                                self.nextthink = time;
                                if(self.roundStart)
                                        self.roundStart();
@@ -62,7 +62,24 @@ void round_handler_Think()
        }
 }
 
-void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, void() roundStart_func, float the_delay, float the_count, float the_round_timelimit)
+void round_handler_Init(float the_delay, float the_count, float the_round_timelimit)
+{
+       round_handler.delay = (the_delay > 0) ? the_delay : 0;
+       round_handler.count = fabs(floor(the_count));
+       round_handler.cnt = round_handler.count + 1;
+       round_handler.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0;
+}
+
+// NOTE: this is only needed because if round_handler spawns at time 1
+// gamestarttime isn't initialized yet
+void round_handler_FirstThink()
+{
+       round_starttime = max(time, game_starttime) + round_handler.count;
+       round_handler.think = round_handler_Think;
+       round_handler.nextthink = max(time, game_starttime);
+}
+
+void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, void() roundStart_func)
 {
        if(round_handler)
        {
@@ -72,44 +89,13 @@ void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, v
        round_handler = spawn();
        round_handler.classname = "round_handler";
 
-       round_handler.think = round_handler_Think;
+       round_handler.think = round_handler_FirstThink;
        round_handler.canRoundStart = canRoundStart_func;
        round_handler.canRoundEnd = canRoundEnd_func;
        round_handler.roundStart = roundStart_func;
-       round_handler.delay = (the_delay > 0) ? the_delay : 0;
-       round_handler.count = fabs(floor(the_count));
        round_handler.wait = FALSE;
-       round_handler.cnt = round_handler.count + 1;
-       round_handler.round_timelimit = the_round_timelimit;
-       // if round_handler spawns at time 1 gamestarttime isn't initialized yet
-       //round_handler.nextthink = max(time, game_starttime + 1);
+       round_handler_Init(5, 5, 180);
        round_handler.nextthink = time;
-       round_starttime = time + round_handler.count;
-}
-
-float round_handler_IsActive()
-{
-       return (round_handler != world);
-}
-
-float round_handler_AwaitingNextRound()
-{
-       return (round_handler.wait);
-}
-
-float round_handler_CountdownRunning()
-{
-       return (!round_handler.wait && round_handler.cnt);
-}
-
-float round_handler_IsRoundStarted()
-{
-       return (!round_handler.wait && !round_handler.cnt);
-}
-
-float round_handler_GetTimeLeft()
-{
-       return (round_handler.round_endtime - time);
 }
 
 void round_handler_Reset(float next_think)