From 75ee7f157eae155afa8bda2f233f39bb30153139 Mon Sep 17 00:00:00 2001 From: terencehill Date: Mon, 19 Nov 2012 20:22:54 +0100 Subject: [PATCH] Freezetag: instead of counting alive players and changing the count temporarily at some events, make so that they are added and removed only at every possible event, not counting them each frame. Hopefully (NEED TESTING) this could fix the issue #229: Sometimes a round ends even though there are still unfrozen players on both teams. --- qcsrc/server/arena.qc | 35 +---------- qcsrc/server/mutators/gamemode_freezetag.qc | 66 ++++++++++++++------- 2 files changed, 44 insertions(+), 57 deletions(-) diff --git a/qcsrc/server/arena.qc b/qcsrc/server/arena.qc index ff4a57b6c..d5004cbc8 100644 --- a/qcsrc/server/arena.qc +++ b/qcsrc/server/arena.qc @@ -327,9 +327,9 @@ void count_players() void count_alive_players() { - totalalive = redalive = bluealive = yellowalive = pinkalive = 0; if(g_ca) { + totalalive = redalive = bluealive = yellowalive = pinkalive = 0; FOR_EACH_PLAYER(self) { if (self.team == COLOR_TEAM1 && self.health >= 1) { @@ -347,39 +347,6 @@ void count_alive_players() self.bluealive_stat = bluealive; } } - else if(g_freezetag) - { - // count amount of alive players in each team - FOR_EACH_PLAYER(self) { - if (self.team == COLOR_TEAM1 && self.freezetag_frozen == 0 && self.health >= 1) - { - redalive += 1; - totalalive += 1; - } - else if (self.team == COLOR_TEAM2 && self.freezetag_frozen == 0 && self.health >= 1) - { - bluealive += 1; - totalalive += 1; - } - else if (self.team == COLOR_TEAM3 && self.freezetag_frozen == 0 && self.health >= 1) - { - yellowalive += 1; - totalalive += 1; - } - else if (self.team == COLOR_TEAM4 && self.freezetag_frozen == 0 && self.health >= 1) - { - pinkalive += 1; - totalalive += 1; - } - } - FOR_EACH_REALCLIENT(self) { - self.redalive_stat = redalive; - self.bluealive_stat = bluealive; - self.yellowalive_stat = yellowalive; - self.pinkalive_stat = pinkalive; - } - } - } /** diff --git a/qcsrc/server/mutators/gamemode_freezetag.qc b/qcsrc/server/mutators/gamemode_freezetag.qc index 8a00f52a7..c8a386882 100644 --- a/qcsrc/server/mutators/gamemode_freezetag.qc +++ b/qcsrc/server/mutators/gamemode_freezetag.qc @@ -51,6 +51,7 @@ void freezetag_CheckWinner() TeamScore_AddToTeam(winner.team, ST_SCORE, +1); } + totalalive = redalive = bluealive = yellowalive = pinkalive = 0; next_round = time + 5; } @@ -63,6 +64,37 @@ void freezetag_Ice_Think() self.nextthink = time; } +void freezetag_update_alive_stats() +{ + entity e; + FOR_EACH_REALCLIENT(e) { + e.redalive_stat = redalive; + e.bluealive_stat = bluealive; + e.yellowalive_stat = yellowalive; + e.pinkalive_stat = pinkalive; + } +} + +void freezetag_add_alive() +{ + if(self.team == COLOR_TEAM1) ++redalive; + else if(self.team == COLOR_TEAM2) ++bluealive; + else if(self.team == COLOR_TEAM3) ++yellowalive; + else if(self.team == COLOR_TEAM4) ++pinkalive; + ++totalalive; + freezetag_update_alive_stats(); +} + +void freezetag_remove_alive() +{ + if(self.team == COLOR_TEAM1) --redalive; + else if(self.team == COLOR_TEAM2) --bluealive; + else if(self.team == COLOR_TEAM3) --yellowalive; + else if(self.team == COLOR_TEAM4) --pinkalive; + --totalalive; + freezetag_update_alive_stats(); +} + void freezetag_Freeze(entity attacker) { if(self.freezetag_frozen) @@ -241,23 +273,13 @@ void havocbot_role_ft_freeing() MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer) { if(self.freezetag_frozen == 0 && self.health >= 1) - { - if(self.team == COLOR_TEAM1) - --redalive; - else if(self.team == COLOR_TEAM2) - --bluealive; - else if(self.team == COLOR_TEAM3) - --yellowalive; - else if(self.team == COLOR_TEAM4) - --pinkalive; - --totalalive; - } + freezetag_remove_alive(); + + freezetag_Unfreeze(world); if(total_players > 2) // only check for winners if we had more than two players (one of them left, don't let the other player win just because of that) freezetag_CheckWinner(); - freezetag_Unfreeze(world); - return 1; } @@ -265,17 +287,8 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerDies) { if(self.freezetag_frozen == 0) { - if(self.team == COLOR_TEAM1) - --redalive; - else if(self.team == COLOR_TEAM2) - --bluealive; - else if(self.team == COLOR_TEAM3) - --yellowalive; - else if(self.team == COLOR_TEAM4) - --pinkalive; - --totalalive; - freezetag_Freeze(frag_attacker); + freezetag_remove_alive(); } if(frag_attacker == frag_target || frag_attacker == world) @@ -302,6 +315,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerDies) MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn) { + freezetag_add_alive(); if(time <= game_starttime || total_players == 0) return 1; @@ -310,6 +324,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn) if(total_players == 1) // only one player active on server, start a new match immediately if(!next_round && warmup && (time < warmup - autocvar_g_freezetag_warmup || time > warmup)) // not awaiting next round { + totalalive = redalive = bluealive = yellowalive = pinkalive = 0; next_round = time; return 1; } @@ -318,6 +333,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn) { centerprint(self, "^1You spawned after the round started, you'll spawn as frozen.\n"); freezetag_Freeze(world); + freezetag_remove_alive(); } return 1; @@ -334,6 +350,9 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink) float n; vector revive_extra_size; + if(next_round || (time > warmup - autocvar_g_freezetag_warmup && time < warmup)) + return 1; // already waiting for next round to start + revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size; entity o; @@ -363,6 +382,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink) if(self.freezetag_revive_progress >= 1) { freezetag_Unfreeze(self); + freezetag_add_alive(); // EVERY team mate nearby gets a point (even if multiple!) FOR_EACH_PLAYER(other) if(self != other) -- 2.39.2