From 9297a512db903776ebf5369b2cf33f0e6d35afc3 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 13 Aug 2013 12:34:36 +1000 Subject: [PATCH] Clean up stalemate code a bit --- qcsrc/server/mutators/gamemode_ctf.qc | 61 +++++++-------------------- 1 file changed, 16 insertions(+), 45 deletions(-) diff --git a/qcsrc/server/mutators/gamemode_ctf.qc b/qcsrc/server/mutators/gamemode_ctf.qc index f1ae407ef..78772fce5 100644 --- a/qcsrc/server/mutators/gamemode_ctf.qc +++ b/qcsrc/server/mutators/gamemode_ctf.qc @@ -614,7 +614,7 @@ void ctf_CheckFlagReturn(entity flag, float returntype) void ctf_CheckStalemate(void) { // declarations - float stale_red_flags = 0, stale_blue_flags = 0, stale_yellow_flags = 0, stale_pink_flags = 0; + float stale_flags = 0, stale_red_flags = 0, stale_blue_flags = 0, stale_yellow_flags = 0, stale_pink_flags = 0; entity tmp_entity; entity ctf_staleflaglist = world; // reset the list, we need to build the list each time this function runs @@ -629,49 +629,21 @@ void ctf_CheckStalemate(void) tmp_entity.ctf_staleflagnext = ctf_staleflaglist; // link flag into staleflaglist ctf_staleflaglist = tmp_entity; - switch(tmp_entity.team) - { - case NUM_TEAM_1: ++stale_red_flags; break; - case NUM_TEAM_2: ++stale_blue_flags; break; - case NUM_TEAM_3: ++stale_yellow_flags; break; - case NUM_TEAM_4: ++stale_pink_flags; break; - } + if(tmp_entity.team == NUM_TEAM_1) { ++stale_red_flags; } + if(tmp_entity.team == NUM_TEAM_2) { ++stale_blue_flags; } + if(tmp_entity.team == NUM_TEAM_3) { ++stale_yellow_flags; } + if(tmp_entity.team == NUM_TEAM_4) { ++stale_pink_flags; } } } - switch(ctf_teams) - { - case 2: - { - if(stale_red_flags && stale_blue_flags) - ctf_stalemate = TRUE; - else if((!stale_red_flags && !stale_blue_flags) && autocvar_g_ctf_stalemate_endcondition == 2) - { ctf_stalemate = FALSE; wpforenemy_announced = FALSE; } - else if((!stale_red_flags || !stale_blue_flags) && autocvar_g_ctf_stalemate_endcondition == 1) - { ctf_stalemate = FALSE; wpforenemy_announced = FALSE; } - break; - } - case 3: - { - if(stale_red_flags && stale_blue_flags && stale_yellow_flags) - ctf_stalemate = TRUE; - else if((!stale_red_flags && !stale_blue_flags && !stale_yellow_flags) && autocvar_g_ctf_stalemate_endcondition == 2) - { ctf_stalemate = FALSE; wpforenemy_announced = FALSE; } - else if((!stale_red_flags || !stale_blue_flags || !stale_yellow_flags) && autocvar_g_ctf_stalemate_endcondition == 1) - { ctf_stalemate = FALSE; wpforenemy_announced = FALSE; } - break; - } - case 4: - { - if(stale_red_flags && stale_blue_flags && stale_yellow_flags && stale_pink_flags) - ctf_stalemate = TRUE; - else if((!stale_red_flags && !stale_blue_flags && !stale_yellow_flags && !stale_pink_flags) && autocvar_g_ctf_stalemate_endcondition == 2) - { ctf_stalemate = FALSE; wpforenemy_announced = FALSE; } - else if((!stale_red_flags || !stale_blue_flags || !stale_yellow_flags || !stale_pink_flags) && autocvar_g_ctf_stalemate_endcondition == 1) - { ctf_stalemate = FALSE; wpforenemy_announced = FALSE; } - break; - } - } + stale_flags = (stale_red_flags > 0) + (stale_blue_flags > 0) + (stale_yellow_flags > 0) + (stale_pink_flags > 0); + + if(stale_flags >= ctf_teams) + ctf_stalemate = TRUE; + else if(stale_flags < ctf_teams && autocvar_g_ctf_stalemate_endcondition == 2) + { ctf_stalemate = FALSE; wpforenemy_announced = FALSE; } + else if(stale_flags > 0 && autocvar_g_ctf_stalemate_endcondition == 1) + { ctf_stalemate = FALSE; wpforenemy_announced = FALSE; } // if sufficient stalemate, then set up the waypointsprite and announce the stalemate if necessary if(ctf_stalemate) @@ -822,6 +794,7 @@ void ctf_FlagThink() if((self.pass_target == world) || (self.pass_target.deadflag != DEAD_NO) + || (self.pass_target.flagcarried) || (vlen(self.origin - targ_origin) > autocvar_g_ctf_pass_radius) || ((trace_fraction < 1) && (trace_ent != self.pass_target)) || (time > self.ctf_droptime + autocvar_g_ctf_pass_timelimit)) @@ -2339,11 +2312,9 @@ void ctf_DelayedInit() // Do this check with a delay so we can wait for teams to ctf_SpawnTeam("Red", NUM_TEAM_1 - 1); ctf_SpawnTeam("Blue", NUM_TEAM_2 - 1); if(ctf_teams >= 3) - { ctf_SpawnTeam("Yellow", NUM_TEAM_3 - 1); - if(ctf_teams >= 4) - ctf_SpawnTeam("Pink", NUM_TEAM_4 - 1); - } + if(ctf_teams >= 4) + ctf_SpawnTeam("Pink", NUM_TEAM_4 - 1); } ret_float = ctf_teams; -- 2.39.2