diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 22888457..6b90bfd7 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -821,6 +821,20 @@ void refreshsopmenu(void *menu, bool init) } } +playerent *findfollowplayer(int shiftdirection) +{ + if(!shiftdirection) + { + playerent *f = players.inrange(player1->followplayercn) ? players[player1->followplayercn] : NULL; + if(f) return f; + } + + vector available; + loopv(players) if(players[i]) available.add(players[i]); + player1->followplayercn = (player1->followplayercn+shiftdirection) % available.length(); + return players[player1->followplayercn]; +} + void spectate(int mode) // set new spect mode { if(!player1->isspectating()) return; @@ -834,7 +848,7 @@ void spectate(int mode) // set new spect mode { if(players.length()) { - player1->followplayercn %= players.length(); + findfollowplayer(); break; } else mode = SM_FLY; @@ -843,9 +857,10 @@ void spectate(int mode) // set new spect mode { if(player1->spectatemode != SM_FLY) { - if(players.inrange(player1->followplayercn)) // set spectator location to last followed player + // set spectator location to last followed player + playerent *f = findfollowplayer(); + if(f) { - playerent *f = players[player1->followplayercn]; player1->o = f->o; player1->yaw = f->yaw; player1->pitch = 0.0f; diff --git a/source/src/protos.h b/source/src/protos.h index c10036e5..d1b2d3b3 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -293,6 +293,7 @@ extern void refreshsopmenu(void *menu, bool init); extern char *colorname(playerent *d, int num = 0, char *name = NULL, const char *prefix = ""); extern char *colorping(int ping); extern void togglespect(); +extern playerent *findfollowplayer(int shiftdirection = 0); struct votedisplayinfo { diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index 15ecb51f..384820c6 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -309,7 +309,6 @@ void recomputecamera() { if((player1->state==CS_SPECTATE || player1->state==CS_DEAD) && !editmode) { - bool followvalid = players.inrange(player1->followplayercn) && players[player1->followplayercn]; switch(player1->spectatemode) { case SM_DEATHCAM: @@ -329,12 +328,17 @@ void recomputecamera() camera1 = player1; break; case SM_FOLLOW1ST: - if(!followvalid) { togglespect(); return; } - camera1 = players[player1->followplayercn]; + { + playerent *f = findfollowplayer(); + if(!f) { togglespect(); return; } + camera1 = f; break; + } case SM_FOLLOW3RD: case SM_FOLLOW3RD_TRANSPARENT: - if(!followvalid) { togglespect(); return; } + { + playerent *f = findfollowplayer(); + if(!f) { togglespect(); return; } playerent *p = players[player1->followplayercn]; static physent followcam; static playerent *lastplayer; @@ -362,6 +366,7 @@ void recomputecamera() followcam.vel.x = followcam.vel.y = followcam.vel.z = 0.0f; followcam.yaw = p->yaw; break; + } } } else diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 287b97ea..d3225961 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -58,7 +58,7 @@ void shiftweapon(int s) selectweapon(player1->weapons[trygun]); } } - else if(player1->isspectating()) { (player1->followplayercn += s) %= players.length(); } + else if(player1->isspectating()) findfollowplayer(s); } int currentprimary() { return player1->primweap->type; }