]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Clean up stalemate code a bit
authorMario <mario.mario@y7mail.com>
Tue, 13 Aug 2013 02:34:36 +0000 (12:34 +1000)
committerMario <mario.mario@y7mail.com>
Tue, 13 Aug 2013 02:34:36 +0000 (12:34 +1000)
qcsrc/server/mutators/gamemode_ctf.qc

index f1ae407efe0875bdbd9d32329475e0826b6e6223..78772fce51a51f0eb347928333e360aaf17a7335 100644 (file)
@@ -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;