rotate through all spec-able players
| 1701 | |
| 1702 | // rotate through all spec-able players |
| 1703 | playerent *updatefollowplayer(int shiftdirection) |
| 1704 | { |
| 1705 | playerent *f = players.inrange(player1->followplayercn) ? players[player1->followplayercn] : NULL; // last spectated player |
| 1706 | |
| 1707 | // collect spec-able players |
| 1708 | int omit_team = m_teammode && !watchingdemo && player1->team != TEAM_SPECT ? team_opposite(team_base(player1->team)) : TEAM_NUM; // don't spect enemy team in team mode |
| 1709 | bool stayondeadplayers = spectatepersistent || !m_arena; |
| 1710 | vector<playerent *> available; |
| 1711 | loopv(players) if(players[i]) |
| 1712 | { |
| 1713 | if(team_group(players[i]->team) == omit_team) continue; // if not team SPECT and not watchingdemo and teammode: don't spectate enemy team |
| 1714 | if((players[i]->state == CS_DEAD || players[i]->isspectating()) && (!stayondeadplayers || players[i] != f)) continue; // don't spect dead players, but in some cases stay on them |
| 1715 | available.add(players[i]); |
| 1716 | } |
| 1717 | if(available.length() < 1) return NULL; |
| 1718 | |
| 1719 | // rotate |
| 1720 | int oldidx = f ? available.find(f) : 0; |
| 1721 | if(oldidx < 0) oldidx = 0; |
| 1722 | int idx = ((oldidx + shiftdirection) % available.length() + available.length()) % available.length(); |
| 1723 | |
| 1724 | if(player1->followplayercn != available[idx]->clientnum) addmsg(SV_SPECTCN, "ri", available[idx]->clientnum); |
| 1725 | player1->followplayercn = available[idx]->clientnum; |
| 1726 | return players[player1->followplayercn]; |
| 1727 | } |
| 1728 | |
| 1729 | void spectate() |
| 1730 | { |
no test coverage detected