From b91a09ea714b5c0a24dd8dc57e9c6e96f9acf592 Mon Sep 17 00:00:00 2001
From: terencehill <piuntn@gmail.com>
Date: Wed, 19 Dec 2012 12:40:28 +0100
Subject: [PATCH] round_handler: be sure to reset the countdown when warmup
 stage ends

---
 qcsrc/server/arena.qc         |  3 +++
 qcsrc/server/round_handler.qc | 18 +++++++++---------
 qcsrc/server/round_handler.qh |  2 +-
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/qcsrc/server/arena.qc b/qcsrc/server/arena.qc
index e2d73cc442..14caab85b8 100644
--- a/qcsrc/server/arena.qc
+++ b/qcsrc/server/arena.qc
@@ -29,6 +29,9 @@ void reset_map(float dorespawn)
 	entity oldself;
 	oldself = self;
 
+	if(time <= game_starttime && round_handler_IsActive())
+		round_handler_Reset(game_starttime + 1);
+
 	if(g_arena)
 	{
 		warmup = max(time, game_starttime);
diff --git a/qcsrc/server/round_handler.qc b/qcsrc/server/round_handler.qc
index 622347c534..2bac357fba 100644
--- a/qcsrc/server/round_handler.qc
+++ b/qcsrc/server/round_handler.qc
@@ -3,17 +3,15 @@ void round_handler_Think()
 	entity e;
 	float f;
 
-	if(time < game_starttime)
+	if(time <= game_starttime)
 	{
-		self.wait = FALSE;
-		round_handler_ResetCountdown();
-		self.nextthink = game_starttime + 1;
+		round_handler_Reset(game_starttime + 1);
 		return;
 	}
 
 	if(gameover)
 	{
-		round_handler_ResetCountdown();
+		round_handler_Reset(0);
 		round_handler_Remove();
 		return;
 	}
@@ -50,7 +48,7 @@ void round_handler_Think()
 		}
 		else
 		{
-			round_handler_ResetCountdown();
+			round_handler_Reset(0);
 		}
 		self.nextthink = time + 1; // canRoundStart every second
 	}
@@ -86,12 +84,12 @@ void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, f
 	round_handler.count = fabs(floor(the_count));
 	round_handler.wait = FALSE;
 	round_handler.cnt = round_handler.count + 1;
-	round_handler.nextthink = time;
+	round_handler.nextthink = max(time, game_starttime + 1);
 }
 
 float round_handler_IsActive()
 {
-	return (round_handler && time > game_starttime);
+	return (round_handler != world);
 }
 
 float round_handler_AwaitingNextRound()
@@ -109,9 +107,10 @@ float round_handler_IsRoundStarted()
 	return (!round_handler.wait && !round_handler.cnt);
 }
 
-void round_handler_ResetCountdown()
+void round_handler_Reset(float next_think)
 {
 	entity e;
+	round_handler.wait = FALSE;
 	if(round_handler.count)
 	if(round_handler.cnt < round_handler.count + 1)
 	{
@@ -119,6 +118,7 @@ void round_handler_ResetCountdown()
 			Send_CSQC_Centerprint_Generic_Expire(e, CPID_ROUND_STARTING);
 		round_handler.cnt = round_handler.count + 1;
 	}
+	round_handler.nextthink = next_think;
 }
 
 void round_handler_Remove()
diff --git a/qcsrc/server/round_handler.qh b/qcsrc/server/round_handler.qh
index 2539e08fbc..55026fa844 100644
--- a/qcsrc/server/round_handler.qh
+++ b/qcsrc/server/round_handler.qh
@@ -12,6 +12,6 @@ float round_handler_IsActive();
 float round_handler_AwaitingNextRound();
 float round_handler_CountdownRunning();
 float round_handler_IsRoundStarted();
-void round_handler_ResetCountdown();
+void round_handler_Reset(float next_think);
 void round_handler_Remove();
 
-- 
2.39.5