-
Notifications
You must be signed in to change notification settings - Fork 3
/
nextfollowteam.patch
93 lines (88 loc) · 3.43 KB
/
nextfollowteam.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
diff --git src/fpsgame/fps.cpp src/fpsgame/fps.cpp
index 1f6919b..64993a9 100644
--- src/fpsgame/fps.cpp
+++ src/fpsgame/fps.cpp
@@ -31,19 +31,22 @@ namespace game
intret(f ? f->clientnum : -1);
});
+ void follow(int cn, int dir = 0)
+ {
+ int ofollowing = following;
+ following = cn;
+ if(following==player1->clientnum) following = -1;
+ followdir = dir;
+ if(following!=ofollowing) clearfragmessages();
+ if((ofollowing>=0) != (following>=0)) conoutf("follow %s", following>=0 ? "on" : "off");
+ }
+
void follow(char *arg)
{
- if(arg[0] ? player1->state==CS_SPECTATOR : following>=0)
- {
- int ofollowing = following;
- following = arg[0] ? parseplayer(arg) : -1;
- if(following==player1->clientnum) following = -1;
- followdir = 0;
- if(following!=ofollowing) clearfragmessages();
- conoutf("follow %s", following>=0 ? "on" : "off");
- }
+ if(arg[0] && player1->state==CS_SPECTATOR) follow(parseplayer(arg));
+ else if(following>=0) follow(-1);
}
- COMMAND(follow, "s");
+ ICOMMAND(follow, "s", (char *arg), follow(arg));
void nextfollow(int dir)
{
@@ -58,10 +61,7 @@ namespace game
cur = (cur + dir + clients.length()) % clients.length();
if(clients[cur] && clients[cur]->state!=CS_SPECTATOR)
{
- if(following!=cur) clearfragmessages();
- if(following<0) conoutf("follow on");
- following = cur;
- followdir = dir;
+ follow(cur, dir);
return;
}
}
@@ -69,6 +69,43 @@ namespace game
}
ICOMMAND(nextfollow, "i", (int *dir), nextfollow(*dir < 0 ? -1 : 1));
+ void nextfollowteam(int dir)
+ {
+ if(player1->state!=CS_SPECTATOR || clients.empty()) { stopfollowing(); return; }
+ if(!m_teammode || !clients.inrange(following) || clients[following]->state==CS_SPECTATOR) { nextfollow(dir); return; }
+ char *followingteam = clients[following]->team;
+ int cur = following;
+ loopv(clients)
+ {
+ cur = (cur + dir + clients.length()) % clients.length();
+ if(!clients[cur] || clients[cur]->state==CS_SPECTATOR) continue;
+ if(strcmp(clients[cur]->team, followingteam)) continue;
+ if(dir<0 ? cur>=following : cur<=following) break; // wrapped around, move on to next team
+ // found next player in current team
+ follow(cur, dir);
+ return;
+ }
+ // pick next team
+ int numgroups = groupplayers();
+ const char *nextteam = followingteam;
+ loopv(groups) if(!strcmp(groups[i]->team, followingteam))
+ {
+ nextteam = groups[(i+dir+numgroups)%numgroups]->team;
+ break;
+ }
+ // find player with lowest cn in next team
+ cur = 0 - dir; // allow 0 after first +dir in loop
+ loopv(clients)
+ {
+ cur = (cur + dir + clients.length()) % clients.length();
+ if(!clients[cur] || clients[cur]->state==CS_SPECTATOR) continue;
+ if(strcmp(clients[cur]->team, nextteam)) continue;
+ follow(cur, dir);
+ return;
+ }
+ nextfollow(dir);
+ }
+ ICOMMAND(nextfollowteam, "i", (int *dir), nextfollowteam(*dir < 0 ? -1 : 1));
const char *getclientmap() { return clientmap; }