]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
CA: fix spectate
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 21 Nov 2015 09:06:49 +0000 (20:06 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 21 Nov 2015 09:07:30 +0000 (20:07 +1100)
closes #1592

qcsrc/server/mutators/events.qh
qcsrc/server/mutators/mutator/gamemode_ca.qc

index 4795aab28dcb5dcf7fca777e3758c4e61670f5ee..5c7c2311b2bfbb3a60bee91274f63c664ac13a3d 100644 (file)
@@ -701,6 +701,7 @@ MUTATOR_HOOKABLE(FixClientCvars, EV_FixClientCvars);
 #define EV_SpectateSet(i, o) \
     /**/ i(entity, __self) \
     /**/ i(entity, spec_player) \
+    /**/ o(entity, spec_player) \
     /**/
 entity spec_player;
 MUTATOR_HOOKABLE(SpectateSet, EV_SpectateSet);
@@ -708,12 +709,14 @@ MUTATOR_HOOKABLE(SpectateSet, EV_SpectateSet);
 #define EV_SpectateNext(i, o) \
     /**/ i(entity, __self) \
     /**/ i(entity, spec_player) \
+    /**/ o(entity, spec_player) \
     /**/
 MUTATOR_HOOKABLE(SpectateNext, EV_SpectateNext);
 
 #define EV_SpectatePrev(i, o) \
     /**/ i(entity, __self) \
     /**/ i(entity, spec_player) \
+    /**/ o(entity, spec_player) \
     /**/ i(entity, spec_first) \
     /**/
 entity spec_first;
index 725569bfff6469745c55a56ffcce910131287071..9b9c8a05b6cedaca9daa36d8fb16d23f14224ce6 100644 (file)
@@ -202,28 +202,24 @@ float ca_isEliminated(entity e)
        return false;
 }
 
-// Returns next available player to spectate if g_ca_spectate_enemies == 0
+/** Returns next available player to spectate if g_ca_spectate_enemies == 0 */
 entity CA_SpectateNext(entity player, entity start)
 {
-       if(SAME_TEAM(start, player))
-               return start;
-
-       entity spec_other = start;
+    if (SAME_TEAM(start, player)) return start;
        // continue from current player
-       while(spec_other && DIFF_TEAM(spec_other, player))
-               spec_other = find(spec_other, classname, "player");
-
-       if (!spec_other)
+       for (entity e = start; (e = find(e, classname, "player")); )
        {
-               // restart from begining
-               spec_other = find(spec_other, classname, "player");
-               while(spec_other && DIFF_TEAM(spec_other, player))
-                       spec_other = find(spec_other, classname, "player");
+               if (SAME_TEAM(player, e)) return e;
        }
-
-       return spec_other;
+       // restart from begining
+       for (entity e = NULL; (e = find(e, classname, "player")); )
+       {
+               if (SAME_TEAM(player, e)) return e;
+       }
+       return start;
 }
 
+
 MUTATOR_HOOKFUNCTION(ca, PlayerSpawn)
 {SELFPARAM();
        self.caplayer = 1;