]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/ctf.qc
sync crosshair effects to weapon switch delay
[divverent/nexuiz.git] / data / qcsrc / client / ctf.qc
1 //include "main.qh"
2 // NOTE: This file contains lots of debugging stuff
3 // it is not really used... can be seen as another sample...
4
5 string STR_PLAYER = "player";
6 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
7
8 string ctf_temp_1;
9 float order_page;
10
11 void() menu_close =
12 {
13         menu_visible = false;
14         menu_show = menu_show_error;
15         menu_action = menu_sub_null;
16         
17         /*if(ctf_temp_1)
18           strunzone(ctf_temp_1);*/
19         
20         localcmd("\nin_bindmap 0 0;");
21 };
22
23 void() order_menu_render =
24 {
25         local vector ps, po;
26         local float i, p, n;
27         local string frags, color;
28         ps = '0 200 0';
29         po = '0 8 0';
30
31         color = getplayerkey(player_localentnum-1, "topcolor");
32         
33         if(getstati(STAT_CTF_STATE) == CTF_STATE_COMMANDER) {
34                 drawstring(ps, "\x1D\x1E\x1E\x1E\x1E Order Menu \x1E\x1E\x1E\x1E\x1F", '8 8 0', '1 1 0', 1, 0); ps += po;
35                 drawstring(ps, strcat("Order: ", ctf_temp_1), '8 8 0', '1 1 0', 1, 0); ps += po;
36                 drawcolorcodedstring(ps, "1) ^3previous page", '8 8 0', 1, 0); ps += po;
37                 drawcolorcodedstring(ps, "2) ^3next page", '8 8 0', 1, 0); ps += po;
38                 for((n = 2), (p = i = 0); i < maxclients && n > 0; ++i) {
39                         frags = getplayerkey(i, "frags");
40                         if(!frags || (i+1) == player_localentnum)
41                                 continue;
42                         if(frags == "-666" || getplayerkey(i, "topcolor") != color) // FIXME use GetPlayerTeam
43                                 continue;
44                         ++p;
45                         if(p > (8*order_page))
46                         {
47                                 // only render current page
48                                 ++n;
49                                 if(n == 10)
50                                         n = 0;
51                                 drawcolorcodedstring(ps, strcat(ftos(n), ") ", GetPlayerName(i), " : ", ftos(getstatf(STAT_CTF_STATE))), '8 8 0', 1, 0); ps += po;
52                         }
53                 }
54                 drawstring(ps, "ESC) Exit Menu", '8 8 0', '1 1 0', 1, 0); ps += po;
55         } else {
56                 menu_close();
57         }
58 };
59
60 float(float bInputType, float nPrimary, float nSecondary) order_menu_action =
61 {
62         local string arg;
63         local float p, i, n, chose;
64         local string frags, color;
65         if(bInputType != 0) // key down wanted
66                 return FALSE;
67         
68         arg = chr2str(nSecondary);
69         chose = stof(chr2str(nPrimary));
70         //str2chr
71         if(arg == "1") {
72                 color = getplayerkey(player_localentnum-1, "topcolor");
73                 ++order_page;
74                 for(p = i = 0; i < maxclients; ++i) {
75                         frags = getplayerkey(i, "frags");
76                         if(!frags || (i+1) == player_localentnum)
77                                 continue;
78                         if(frags == "-666" || getplayerkey(i, "topcolor") != color) // FIXME use GetPlayerTeam
79                                 continue;
80                         ++p;
81                 }
82                 if(p <= (8*order_page)) // no ppl on page
83                         order_page = 0;
84         } else if(arg == "2") {
85                 color = getplayerkey(player_localentnum-1, "topcolor");
86                 --order_page;
87                 if(order_page < 0) {
88                         for(p = i = 0; i < maxclients; ++i) {
89                                 frags = getplayerkey(i, "frags");
90                                 if(!frags || (i+1) == player_localentnum)
91                                         continue;
92                                 if(frags == "-666" || getplayerkey(i, "topcolor") != color) // FIXME use GetPlayerTeam
93                                         continue;
94                                 ++p;
95                         }
96                         order_page = floor(p/8);
97                 }
98         } else if(chose >= 3 && chose <= 9 || arg == "0") { // the 10 needs extra checking, assuming that stof(astring) returns 0
99                 if(chose == 0)
100                         chose = 10;
101                 n = 2;
102                 color = getplayerkey(player_localentnum-1, "topcolor");
103                 for(p = i = 0; i < maxclients && n > 0; ++i) {
104                         frags = getplayerkey(i, "frags");
105                         if(!frags || (i+1) == player_localentnum)
106                                 continue;
107                         if(frags == "-666" || getplayerkey(i, "topcolor") != color) // FIXME use GetPlayerTeam
108                                 continue;
109                         ++p;
110                         if(p > (8*order_page))
111                         {
112                                 // only render current page
113                                 ++n;
114                                 if(n == chose) {
115                                         n = 0;
116                                         break;
117                                 }
118                         }
119                 }
120                 if(n == 0) {
121                         //print(strcat("Issuing order to: ", ftos(i+1), "\n"));
122                         //print(strcat("cmd order #", ftos(i+1), " ", ctf_temp_1, ";\n"));
123                         localcmd(strcat("\ncmd order #", ftos(i+1), " ", ctf_temp_1, ";"));
124                 } else {
125                         print(strcat("Couldn't find player ", ftos(chose), "\n"));
126                 }
127                 return TRUE;
128         } else if(nSecondary == K_ESCAPE) {
129                 strunzone(ctf_temp_1);
130                 menu_close();
131         } else {
132                 //print(strcat("Menu action ", arg, " does not exist.\n"));
133                 return FALSE;
134         }
135         return TRUE;
136 };
137
138 void() order_menu_show =
139 {
140         order_page = 0;
141         menu_show = order_menu_render;
142         menu_action = order_menu_action;
143 };
144
145
146 void() ctf_menu_render =
147 {
148         local vector ps, po;
149         ps = '0 200 0';
150         po = '0 8 0';
151         
152         if(getstati(STAT_CTF_STATE) == CTF_STATE_COMMANDER) {
153                 drawstring(ps, "\x1D\x1E\x1E\x1E\x1E Command Menu \x1E\x1E\x1E\x1E\x1F", '8 8 0', '1 1 0', 1, 0); ps += po;
154                 drawstring(ps, "Issue orders:", '8 8 0', '1 1 0', 1, 0); ps += po;
155                 drawstring(ps, " 1) Attack ", '8 8 0', '1 1 0', 1, 0);
156                 drawstring(ps + '80 0 0', " \x0F", '8 8 0', '1 1 1', 1, 0); ps += po;
157                 drawstring(ps, " 2) Defend \x0E", '8 8 0', '1 1 0', 1, 0); ps += po;
158                 ps += po;
159                 drawstring(ps, "3) Resign from command.", '8 8 0', '1 1 0', 1, 0); ps += po;
160                 drawstring(ps, "ESC) Exit Menu", '8 8 0', '1 1 0', 1, 0); ps += po;
161         } else {
162                 menu_close();
163         }
164 };
165
166 float(float bInputType, float nPrimary, float nSecondary) ctf_menu_action =
167 {
168         local string arg;
169         if(bInputType != 0) // key down wanted
170                 return FALSE;
171         
172         arg = chr2str(nSecondary);
173
174         if(arg == "1") {
175                 ctf_temp_1 = strzone("attack");
176                 order_menu_show();
177         } else if(arg == "2") {
178                 ctf_temp_1 = strzone("defend");
179                 order_menu_show();
180         } else if(arg == "3") {
181                 localcmd("\ncmd order resign;");
182                 menu_close();
183         } else if(nSecondary == K_ESCAPE) {
184                 menu_close();
185         } else {
186                 //print(strcat("Menu action ", arg, " does not exist.\n"));
187                 return FALSE;
188         }
189         return TRUE;
190 };
191
192 void() ctf_menu_show =
193 {
194         if(getstati(STAT_CTF_STATE) < 0)
195                 return;
196         menu_show = ctf_menu_render;
197         menu_action = ctf_menu_action;
198         menu_visible = TRUE;
199         //menu_default_binds();
200 };
201
202 void() ctf_view =
203 {
204         local float stat;
205         stat = getstati(STAT_CTF_STATE);
206         if(stat == CTF_STATE_ATTACK) {
207                 drawpic('0 0 0', "gfx/ctf_ic_atk.tga", '64 64 0', '1 1 1', 1, 0);
208         } else if(stat == CTF_STATE_DEFEND) {
209                 drawpic('0 0 0', "gfx/ctf_ic_def.tga", '64 64 0', '1 1 1', 1, 0);
210         } else if(stat == CTF_STATE_COMMANDER) {
211                 drawstring('0 0 0', "You're commander!", '8 8 0', '1 1 1', 1, 0);
212         } else if(stat < 0) {
213         } else {
214                 drawstring('0 0 0', "Awaiting orders...", '8 8 0', '1 1 1', 0.5, 0);
215         }
216 };