From 9ff7ce8cc439211d86751ba7ff30a7a1bb9dbe23 Mon Sep 17 00:00:00 2001
From: terencehill <piuntn@gmail.com>
Date: Tue, 25 Dec 2012 15:40:33 +0100
Subject: [PATCH] Restore functionality of g_ca_round_timelimit and add
 g_freezetag_round_timelimit

---
 gamemodes.cfg                               |  1 +
 qcsrc/server/autocvars.qh                   |  1 +
 qcsrc/server/mutators/gamemode_ca.qc        | 13 ++++++++++---
 qcsrc/server/mutators/gamemode_freezetag.qc | 12 ++++++++++--
 qcsrc/server/round_handler.qc               |  9 ++++++++-
 qcsrc/server/round_handler.qh               |  5 ++++-
 6 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/gamemodes.cfg b/gamemodes.cfg
index 515b8ce6c8..596477cca5 100644
--- a/gamemodes.cfg
+++ b/gamemodes.cfg
@@ -285,6 +285,7 @@ seta g_freezetag_point_leadlimit -1	"Freeze Tag point lead limit overriding the
 seta g_freezetag_revive_speed 0.4 "Speed for reviving a frozen teammate"
 seta g_freezetag_revive_clearspeed 1.6 "Speed at which reviving progress gets lost when out of range"
 seta g_freezetag_revive_extra_size 100 "Distance in qu that you can stand from a frozen teammate to keep reviving him"
+set g_freezetag_round_timelimit 180
 seta g_freezetag_frozen_force 0.6 "How much to multiply the force on a frozen player with"
 seta g_freezetag_teams_override 0
 set g_freezetag_teams 0
diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh
index bbae1e234d..28387db04c 100644
--- a/qcsrc/server/autocvars.qh
+++ b/qcsrc/server/autocvars.qh
@@ -856,6 +856,7 @@ float autocvar_g_freezetag_point_limit;
 float autocvar_g_freezetag_revive_extra_size;
 float autocvar_g_freezetag_revive_speed;
 float autocvar_g_freezetag_revive_clearspeed;
+float autocvar_g_freezetag_round_timelimit;
 float autocvar_g_freezetag_teams;
 float autocvar_g_freezetag_teams_override;
 float autocvar_g_freezetag_warmup;
diff --git a/qcsrc/server/mutators/gamemode_ca.qc b/qcsrc/server/mutators/gamemode_ca.qc
index 03e68c05d9..8f6d6923eb 100644
--- a/qcsrc/server/mutators/gamemode_ca.qc
+++ b/qcsrc/server/mutators/gamemode_ca.qc
@@ -59,7 +59,15 @@ float CA_GetWinnerTeam()
 
 float CA_CheckWinner()
 {
-	// TODO round tied if(time - warmup > autocvar_g_ca_round_timelimit
+	entity e;
+	if(round_handler_GetTimeLeft() <= 0)
+	{
+		FOR_EACH_REALCLIENT(e)
+			centerprint(e, "Round over, there's no winner");
+		bprint("Round over, there's no winner.\n");
+		allowed_to_spawn = TRUE;
+		return 1;
+	}
 
 	if(inWarmupStage)
 		allowed_to_spawn = TRUE;
@@ -70,7 +78,6 @@ float CA_CheckWinner()
 	if(CA_ALIVE_TEAMS() > 1)
 		return 0;
 
-	entity e;
 	float winner_team;
 	string teamname;
 	winner_team = CA_GetWinnerTeam();
@@ -178,7 +185,7 @@ void ca_Initialize()
 {
 	allowed_to_spawn = TRUE;
 
-	round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, 5, autocvar_g_ca_warmup);
+	round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, 5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
 
 	addstat(STAT_REDALIVE, AS_INT, redalive_stat);
 	addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
diff --git a/qcsrc/server/mutators/gamemode_freezetag.qc b/qcsrc/server/mutators/gamemode_freezetag.qc
index 4e7fbd1d7d..f2e624c563 100644
--- a/qcsrc/server/mutators/gamemode_freezetag.qc
+++ b/qcsrc/server/mutators/gamemode_freezetag.qc
@@ -6,7 +6,7 @@ void freezetag_Initialize()
 	precache_model("models/ice/ice.md3");
 	ScoreRules_freezetag();
 
-	round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, 5, autocvar_g_freezetag_warmup);
+	round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, 5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
 
 	addstat(STAT_REDALIVE, AS_INT, redalive_stat);
 	addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
@@ -112,10 +112,18 @@ float freezetag_getWinnerTeam()
 
 float freezetag_CheckWinner()
 {
+	entity e;
+	if(round_handler_GetTimeLeft() <= 0)
+	{
+		FOR_EACH_REALCLIENT(e)
+			centerprint(e, "Round over, there's no winner");
+		bprint("Round over, there's no winner.\n");
+		return 1;
+	}
+
 	if(FREEZETAG_ALIVE_TEAMS() > 1)
 		return 0;
 
-	entity e;
 	float winner_team;
 	string teamname;
 	winner_team = freezetag_getWinnerTeam();
diff --git a/qcsrc/server/round_handler.qc b/qcsrc/server/round_handler.qc
index 2bac357fba..5fbe24ead3 100644
--- a/qcsrc/server/round_handler.qc
+++ b/qcsrc/server/round_handler.qc
@@ -38,6 +38,7 @@ void round_handler_Think()
 				FOR_EACH_REALCLIENT(e)
 					Send_CSQC_Centerprint_Generic(e, CPID_ROUND_STARTING, "^1Begin!", 1, 0);
 				self.cnt = 0;
+				self.round_endtime = time + self.round_timelimit;
 				self.nextthink = time;
 				return;
 			}
@@ -67,7 +68,7 @@ void round_handler_Think()
 	}
 }
 
-void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, float the_delay, float the_count)
+void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, float the_delay, float the_count, float the_round_timelimit)
 {
 	if(round_handler)
 	{
@@ -84,6 +85,7 @@ 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.round_timelimit = the_round_timelimit;
 	round_handler.nextthink = max(time, game_starttime + 1);
 }
 
@@ -107,6 +109,11 @@ 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)
 {
 	entity e;
diff --git a/qcsrc/server/round_handler.qh b/qcsrc/server/round_handler.qh
index 55026fa844..3ab61bc3e2 100644
--- a/qcsrc/server/round_handler.qh
+++ b/qcsrc/server/round_handler.qh
@@ -4,14 +4,17 @@ entity round_handler;
 .float wait; // it's set to TRUE when round ends, to FALSE when countdown starts
 .float cnt;	// its initial value is .count + 1, then decreased while counting down
 			// reaches 0 when the round starts
+.float round_timelimit;
+.float round_endtime;
 .float() canRoundStart;
 .float() canRoundEnd;
 
-void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, float the_delay, float the_count);
+void round_handler_Spawn(float() canRoundStart_func, float() canRoundEnd_func, float the_delay, float the_count, float the_round_timelimit);
 float round_handler_IsActive();
 float round_handler_AwaitingNextRound();
 float round_handler_CountdownRunning();
 float round_handler_IsRoundStarted();
+float round_handler_GetTimeLeft();
 void round_handler_Reset(float next_think);
 void round_handler_Remove();
 
-- 
2.39.5