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