]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/ctf.qc
Committed my CSQC stuff, let's see:
[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';
29         po = '0 8';
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                 //drawstring(ps, strcat("N1 = ", ftos(player_localnum), " - N2 = ", ftos(player_localentnum)), '8 8 0', '1 1 0', 1, 0); ps += po;
37                 drawcolorcodedstring(ps, "1) ^3previous page", '8 8 0', 1, 0); ps += po;
38                 drawcolorcodedstring(ps, "2) ^3next page", '8 8 0', 1, 0); ps += po;
39                 //drawcolorcodedstring(ps, strcat("Clients to go: ", ftos(maxclients)), '8 8 0', 1, 0); ps += po;
40                 for((n = 2), (p = i = 0); i < maxclients && n > 0; ++i) {
41                         frags = getplayerkey(i, "frags");
42                         /*print(strcat(ftos(i), "/", ftos(p), "/", ftos(n), "/", getplayerkey(i, "viewentity"), "\n"));
43                         print(strcat(" - name: ", getplayerkey(i, "name"), " - frags: ", frags, "\n"));
44                         print(strcat(" - color: ", getplayerkey(i, "topcolor"), " - ", color, "\n"));*/
45                         if(!frags || (i+1) == player_localentnum)
46                                 continue;
47                         if(frags == "-666" || getplayerkey(i, "topcolor") != color)
48                                 continue;
49                         ++p;
50                         if(p > (8*order_page))
51                         {
52                                 // only render current page
53                                 ++n;
54                                 if(n == 10)
55                                         n = 0;
56                                 drawcolorcodedstring(ps, strcat(ftos(n), ") ", getplayerkey(i, "name"), " : ", ftos(getstatf(STAT_CTF_STATE))), '8 8 0', 1, 0); ps += po;
57                         }
58                 }
59                 //drawstring(ps, strcat("LocalEntNum = ", ftos(player_localnum)), '8 8 0', '1 1 0', 1, 0); ps += po;
60                 drawstring(ps, "ESC) Exit Menu", '8 8 0', '1 1 0', 1, 0); ps += po;
61         } else {
62                 menu_close();
63         }
64 };
65
66 float(float bInputType, float nPrimary, float nSecondary) order_menu_action =
67 {
68         local string arg;
69         local float p, i, n, chose;
70         local string frags, color;
71         if(bInputType != 0) // key down wanted
72                 return FALSE;
73         
74         arg = chr2str(nSecondary);
75         chose = stof(chr2str(nPrimary));
76         //str2chr
77         if(arg == "1") {
78                 color = getplayerkey(player_localentnum-1, "topcolor");
79                 ++order_page;
80                 for(p = i = 0; i < maxclients; ++i) {
81                         frags = getplayerkey(i, "frags");
82                         if(!frags || (i+1) == player_localentnum)
83                                 continue;
84                         if(frags == "-666" || getplayerkey(i, "topcolor") != color)
85                                 continue;
86                         ++p;
87                 }
88                 if(p <= (8*order_page)) // no ppl on page
89                         order_page = 0;
90         } else if(arg == "2") {
91                 color = getplayerkey(player_localentnum-1, "topcolor");
92                 --order_page;
93                 if(order_page < 0) {
94                         for(p = i = 0; i < maxclients; ++i) {
95                                 frags = getplayerkey(i, "frags");
96                                 if(!frags || (i+1) == player_localentnum)
97                                         continue;
98                                 if(frags == "-666" || getplayerkey(i, "topcolor") != color)
99                                         continue;
100                                 ++p;
101                         }
102                         order_page = floor(p/8);
103                 }
104         } else if(chose >= 3 && chose <= 9 || arg == "0") { // the 10 needs extra checking, assuming that stof(astring) returns 0
105                 if(chose == 0)
106                         chose = 10;
107                 n = 2;
108                 color = getplayerkey(player_localentnum-1, "topcolor");
109                 for(p = i = 0; i < maxclients && n > 0; ++i) {
110                         frags = getplayerkey(i, "frags");
111                         if(!frags || (i+1) == player_localentnum)
112                                 continue;
113                         if(frags == "-666" || getplayerkey(i, "topcolor") != color)
114                                 continue;
115                         ++p;
116                         if(p > (8*order_page))
117                         {
118                                 // only render current page
119                                 ++n;
120                                 if(n == chose) {
121                                         n = 0;
122                                         break;
123                                 }
124                         }
125                 }
126                 if(n == 0) {
127                         //print(strcat("Issuing order to: ", ftos(i+1), "\n"));
128                         //print(strcat("cmd order #", ftos(i+1), " ", ctf_temp_1, ";\n"));
129                         localcmd(strcat("\ncmd order #", ftos(i+1), " ", ctf_temp_1, ";"));
130                 } else {
131                         print(strcat("Couldn't find player ", ftos(chose), "\n"));
132                 }
133                 return TRUE;
134         } else if(nSecondary == K_ESCAPE) {
135                 strunzone(ctf_temp_1);
136                 menu_close();
137         } else {
138                 //print(strcat("Menu action ", arg, " does not exist.\n"));
139                 return FALSE;
140         }
141         return TRUE;
142 };
143
144 void() order_menu_show =
145 {
146         order_page = 0;
147         menu_show = order_menu_render;
148         menu_action = order_menu_action;
149 };
150
151
152 void() ctf_menu_render =
153 {
154         local vector ps, po;
155         ps = '0 200';
156         po = '0 8';
157         
158         if(getstati(STAT_CTF_STATE) == CTF_STATE_COMMANDER) {
159                 drawstring(ps, "\x1D\x1E\x1E\x1E\x1E Command Menu \x1E\x1E\x1E\x1E\x1F", '8 8 0', '1 1 0', 1, 0); ps += po;
160                 drawstring(ps, "Issue orders:", '8 8 0', '1 1 0', 1, 0); ps += po;
161                 drawstring(ps, " 1) Attack ", '8 8 0', '1 1 0', 1, 0);
162                 drawstring(ps + '80 0', " \x0F", '8 8 0', '1 1 1', 1, 0); ps += po;
163                 drawstring(ps, " 2) Defend \x0E", '8 8 0', '1 1 0', 1, 0); ps += po;
164                 ps += po;
165                 drawstring(ps, "3) Resign from command.", '8 8 0', '1 1 0', 1, 0); ps += po;
166                 drawstring(ps, "ESC) Exit Menu", '8 8 0', '1 1 0', 1, 0); ps += po;
167         } else {
168                 menu_close();
169         }
170 };
171
172 float(float bInputType, float nPrimary, float nSecondary) ctf_menu_action =
173 {
174         local string arg;
175         if(bInputType != 0) // key down wanted
176                 return FALSE;
177         
178         arg = chr2str(nSecondary);
179
180         if(arg == "1") {
181                 ctf_temp_1 = strzone("attack");
182                 order_menu_show();
183         } else if(arg == "2") {
184                 ctf_temp_1 = strzone("defend");
185                 order_menu_show();
186         } else if(arg == "3") {
187                 localcmd("\ncmd order resign;");
188                 menu_close();
189         } else if(nSecondary == K_ESCAPE) {
190                 menu_close();
191         } else {
192                 //print(strcat("Menu action ", arg, " does not exist.\n"));
193                 return FALSE;
194         }
195         return TRUE;
196 };
197
198 void() ctf_menu_show =
199 {
200         if(getstati(STAT_CTF_STATE) < 0)
201                 return;
202         menu_show = ctf_menu_render;
203         menu_action = ctf_menu_action;
204         menu_visible = TRUE;
205         //menu_default_binds();
206 };
207
208 void() ctf_view =
209 {
210         local float stat;
211         stat = getstati(STAT_CTF_STATE);
212         if(stat == CTF_STATE_ATTACK) {
213                 drawpic('0 0', "gfx/ctf_ic_atk.tga", '64 64 0', '1 1 1', 1, 0);
214         } else if(stat == CTF_STATE_DEFEND) {
215                 drawpic('0 0', "gfx/ctf_ic_def.tga", '64 64 0', '1 1 1', 1, 0);
216         } else if(stat == CTF_STATE_COMMANDER) {
217                 drawstring('0 0', "You're commander!", '8 8 0', '1 1 1', 1, 0);
218         } else if(stat < 0) {
219         } else {
220                 drawstring('0 0', "Awaiting orders...", '8 8 0', '1 1 1', 0.5, 0);
221         }
222 };