MCPcopy Create free account
hub / github.com/assaultcube/AC / updatefollowplayer

Function updatefollowplayer

source/src/clientgame.cpp:1703–1727  ·  view source on GitHub ↗

rotate through all spec-able players

Source from the content-addressed store, hash-verified

1701
1702// rotate through all spec-able players
1703playerent *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
1729void spectate()
1730{

Callers 4

recomputecameraFunction · 0.85
shiftweaponFunction · 0.85
spectatemodeFunction · 0.85
changefollowplayerFunction · 0.85

Calls 7

addmsgFunction · 0.85
inrangeMethod · 0.80
isspectatingMethod · 0.80
loopvFunction · 0.70
addMethod · 0.45
lengthMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected