From: terencehill Date: Mon, 3 Dec 2012 23:20:20 +0000 (+0100) Subject: Freezetag: update player count before checking it, besides making the code more intui... X-Git-Tag: xonotic-v0.7.0~61^2~90 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=541f90a585c890b1ff3966df5a710fef93bd1aee;p=xonotic%2Fxonotic-data.pk3dir.git Freezetag: update player count before checking it, besides making the code more intuitive it prevents logic issues when multiple clients join/leave the game at once (bots case) --- diff --git a/qcsrc/server/arena.qc b/qcsrc/server/arena.qc index 6f38c4569..a4968af80 100644 --- a/qcsrc/server/arena.qc +++ b/qcsrc/server/arena.qc @@ -439,16 +439,13 @@ void Arena_Main() if(!(g_ca || g_freezetag || g_arena)) return; - if(g_ca || g_freezetag) + if(g_ca) { count_players(); - if(g_ca) - count_alive_players(); - Arena_Warmup(); + count_alive_players(); } - else if(arena_roundbased) + if(!g_arena || arena_roundbased) Arena_Warmup(); - Spawnqueue_Check(); } diff --git a/qcsrc/server/mutators/gamemode_freezetag.qc b/qcsrc/server/mutators/gamemode_freezetag.qc index efc3d8f9d..ca453c5c0 100644 --- a/qcsrc/server/mutators/gamemode_freezetag.qc +++ b/qcsrc/server/mutators/gamemode_freezetag.qc @@ -74,12 +74,28 @@ void freezetag_Ice_Think() void freezetag_count_alive_players() { entity e; - redalive = bluealive = yellowalive = pinkalive = 0; + total_players = redalive = bluealive = yellowalive = pinkalive = 0; FOR_EACH_PLAYER(e) { - if(e.team == COLOR_TEAM1 && e.freezetag_frozen == 0 && e.health >= 1) ++redalive; - else if(e.team == COLOR_TEAM2 && e.freezetag_frozen == 0 && e.health >= 1) ++bluealive; - else if(e.team == COLOR_TEAM3 && e.freezetag_frozen == 0 && e.health >= 1) ++yellowalive; - else if(e.team == COLOR_TEAM4 && e.freezetag_frozen == 0 && e.health >= 1) ++pinkalive; + if(e.team == COLOR_TEAM1 && e.health >= 1) + { + ++total_players; + if (!e.freezetag_frozen) ++redalive; + } + else if(e.team == COLOR_TEAM2 && e.health >= 1) + { + ++total_players; + if (!e.freezetag_frozen) ++bluealive; + } + else if(e.team == COLOR_TEAM3 && e.health >= 1) + { + ++total_players; + if (!e.freezetag_frozen) ++yellowalive; + } + else if(e.team == COLOR_TEAM4 && e.health >= 1) + { + ++total_players; + if (!e.freezetag_frozen) ++pinkalive; + } } FOR_EACH_REALCLIENT(e) { e.redalive_stat = redalive; @@ -146,8 +162,6 @@ void freezetag_Unfreeze(entity attacker) self.freezetag_frozen_timeout = 0; self.freezetag_revive_progress = 0; - freezetag_count_alive_players(); - // remove the ice block entity ice; for(ice = world; (ice = find(ice, classname, "freezetag_ice")); ) if(ice.owner == self) @@ -275,7 +289,9 @@ MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer) self.health = 0; // neccessary to update correctly alive stats 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_count_alive_players(); + + if(total_players > 1) // 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(); return 1; @@ -336,10 +352,10 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn) if(self.freezetag_frozen) // stay frozen if respawning after death (DEATH_HURTTRIGGER) return 1; - if(time <= game_starttime || inWarmupStage || total_players == 0) + if(time <= game_starttime || inWarmupStage || total_players == 1) return 1; - if(total_players == 1) // only one player active on server, start a new match immediately + if(total_players == 2) // 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 { next_round = time; @@ -398,6 +414,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink) { self.health = autocvar_g_balance_health_start; freezetag_Unfreeze(world); + freezetag_count_alive_players(); return 1; } } @@ -433,6 +450,7 @@ MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink) if(self.freezetag_revive_progress >= 1) { freezetag_Unfreeze(self); + freezetag_count_alive_players(); // EVERY team mate nearby gets a point (even if multiple!) FOR_EACH_PLAYER(other) if(self != other)