From b3c5eef8bcdab1cc8e4867d2f35cdaf87157608a Mon Sep 17 00:00:00 2001 From: div0 Date: Tue, 12 Dec 2006 10:52:36 +0000 Subject: [PATCH] get rid of the damn LMS player count... no LMS player count, and none can be wrong... git-svn-id: svn://svn.icculus.org/nexuiz/trunk@2039 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/server/cl_client.qc | 15 ++---- data/qcsrc/server/defs.qh | 2 +- data/qcsrc/server/g_damage.qc | 1 - data/qcsrc/server/g_world.qc | 96 +++++++++++++++++++++------------- 4 files changed, 64 insertions(+), 50 deletions(-) diff --git a/data/qcsrc/server/cl_client.qc b/data/qcsrc/server/cl_client.qc index ccb21e15c..4c96660af 100644 --- a/data/qcsrc/server/cl_client.qc +++ b/data/qcsrc/server/cl_client.qc @@ -777,16 +777,10 @@ void ClientConnect (void) if(self.frags < 1) self.frags = 999; - // disallow player to join after the worst player has lost g_lms_last_join lives - // if "g_lms_join_anytime" new players spawn with same amount of lives as the worst active player - if(((cvar("fraglimit") - cvar("g_lms_last_join")) > lms_lowest_lives && !cvar("g_lms_join_anytime")) || lms_lowest_lives < 1) + self.frags = LMS_NewPlayerLives(); + if(!self.frags) { self.frags = -666; - lms_dead_count += 1; - } - else if(cvar("fraglimit") > lms_lowest_lives) - { - self.frags = lms_lowest_lives; } } else if(cvar("g_arena")) @@ -847,10 +841,7 @@ void ClientDisconnect (void) if(self.weaponentity.lasertarget) remove(self.weaponentity.lasertarget); - // player was dead, decrease dead count - if(cvar("g_lms") && self.frags < 0) - lms_dead_count -= 1; - else if(cvar("g_arena")) + if(cvar("g_arena")) { Spawnqueue_Unmark(self); Spawnqueue_Remove(self); diff --git a/data/qcsrc/server/defs.qh b/data/qcsrc/server/defs.qh index 45ca7fb63..703f8ee6c 100644 --- a/data/qcsrc/server/defs.qh +++ b/data/qcsrc/server/defs.qh @@ -5,9 +5,9 @@ entity activator; string string_null; float player_count; -float lms_dead_count; float lms_lowest_lives; float lms_next_place; +float() LMS_NewPlayerLives; float team1_score, team2_score, team3_score, team4_score; diff --git a/data/qcsrc/server/g_damage.qc b/data/qcsrc/server/g_damage.qc index eb4eaae5e..9ef4458a1 100644 --- a/data/qcsrc/server/g_damage.qc +++ b/data/qcsrc/server/g_damage.qc @@ -30,7 +30,6 @@ void GiveFrags (entity attacker, entity targ, float f) // player has no more lives left if (!targ.frags) { - lms_dead_count += 1; if(!lms_next_place) lms_next_place = player_count; targ.frags = -lms_next_place; diff --git a/data/qcsrc/server/g_world.qc b/data/qcsrc/server/g_world.qc index 1d231f609..b87955a72 100644 --- a/data/qcsrc/server/g_world.qc +++ b/data/qcsrc/server/g_world.qc @@ -328,7 +328,6 @@ void worldspawn (void) lightstyle(63, "a"); player_count = 0; - lms_dead_count = 0; lms_lowest_lives = 0; lms_next_place = 0; @@ -1007,59 +1006,84 @@ void(void) ClearWinners = } } +float() LMS_NewPlayerLives = +{ + float fl; + fl = cvar("fraglimit"); + if(fl == 0) + fl = 999; + + // first player has left the game for dying too much? Nobody else can get in. + if(lms_lowest_lives < 1) + return FALSE; + + if(!cvar("g_lms_join_anytime")) + if(lms_lowest_lives < fl - cvar("g_lms_last_join")) + return FALSE; + + return bound(1, lms_lowest_lives, fl); +} + // LMS winning condition: game terminates if and only if there's at most one // one player who's living lives. Top two scores being equal cancels the time // limit. float() WinningCondition_LMS = { entity head; + float have_player; + float have_players; + float l; - if(cvar("developer")) + have_player = FALSE; + have_players = FALSE; + l = LMS_NewPlayerLives(); + + head = find(world, classname, "player"); + if(head) + have_player = TRUE; + head = find(head, classname, "player"); + if(head) + have_players = TRUE; + + if(have_player) { - float real_dead_count; - float real_player_count; - for(head = world; (head = find(head, classname, "player")); ) + // we have at least one player + if(have_players) { - if(head.frags < 1) - real_dead_count += 1; - real_player_count += 1; + // two or more active players - continue with the game } - for(head = world; (head = find(head, classname, "observer")); ) - { - if(head.frags < 1) - real_dead_count += 1; - real_player_count += 1; - } - for(head = world; (head = find(head, classname, "spectator")); ) + else { - if(head.frags < 1) - real_dead_count += 1; - real_player_count += 1; + // exactly one player? + if(l) + { + // but no game has taken place yet + } + else + { + // a winner! + SetWinners(winning, 0); // NOTE: exactly one player is still "player", so this works out + dprint("Have a winner, ending game.\n"); + return WINNING_YES; + } } - - if(player_count != real_player_count) + } + else + { + // nobody is playing at all... + if(l) { - dprint("ERROR: ", ftos(player_count), " is not "); - dprint(ftos(real_player_count), " -> player count mismatch\n"); + // wait for players... } - - if(lms_dead_count != real_dead_count) + else { - dprint("ERROR: ", ftos(lms_dead_count), " is not "); - dprint(ftos(real_dead_count), " -> dead count mismatch\n"); + // SNAFU (maybe a draw game?) + ClearWinners(); + dprint("No players, ending game.\n"); + return WINNING_YES; } } - if(player_count > 1 && lms_dead_count >= player_count - 1) - return WINNING_YES; // He's the last man standing! - - if((player_count == 1 && lms_dead_count == 1)) - return WINNING_YES; // All dead... (n:n is handled by the test above) - - // dprint("player count = "); dprint(ftos(player_count)); - // dprint(", dead count = "); dprint(ftos(lms_dead_count)); - // dprint("\n"); - // When we get here, we have at least two players who are actually LIVING, // or one player who is still waiting for a victim to join the server. Now // check if the top two players have equal score. -- 2.39.2