]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/command/cl_cmd.qc
Now make everything else compile too
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / command / cl_cmd.qc
1 // ==============================================
2 //  CSQC client commands code, written by Samual
3 //  Last updated: November 26th, 2011
4 // ==============================================
5
6         /*
7         if(cmd == "mv_download") {
8                 Cmd_MapVote_MapDownload(argc);
9         }
10         else if(cmd == "scoreboard_columns_set") {
11                 Cmd_HUD_SetFields(argc);
12         }
13         else if(cmd == "scoreboard_columns_help") {
14                 Cmd_HUD_Help(argc);
15         }
16         else if(cmd == "spawn") {
17                 s = argv(1);
18                 e = spawn();
19                 precache_model(s);
20                 setmodel(e, s);
21                 setorigin(e, view_origin);
22                 e.angles = view_angles;
23                 e.draw = DrawDebugModel;
24                 e.classname = "debugmodel";
25         }
26     else if(cmd == "vyes")
27     {
28         if(uid2name_dialog)
29         {
30             vote_active = 0; // force the panel to disappear right as we have selected the value (to prevent it from fading out in the normal vote panel pos)
31             vote_prev = 0;
32             localcmd("setreport cl_allow_uid2name 1\n");
33             vote_change = -9999;
34                         uid2name_dialog = 0;
35         }
36         else
37         {
38             localcmd("cmd vote yes\n");
39         }
40     }
41     else if(cmd == "vno")
42     {
43         if(uid2name_dialog)
44         {
45             vote_active = 0;
46             vote_prev = 0;
47             localcmd("setreport cl_allow_uid2name 0\n");
48             vote_change = -9999;
49                         uid2name_dialog = 0;
50         }
51         else
52         {
53             localcmd("cmd vote no\n");
54         }
55     }
56         */
57
58 // ============================
59 //  Misc. Supporting Functions
60 // ============================
61
62 float cvar_clientsettemp(string tmp_cvar, string value)
63 {
64         entity e;
65         
66         for(e = world; (e = find(e, classname, "saved_cvar_value")); )
67                 if(e.netname == tmp_cvar)
68                         goto saved;
69                         
70         // creating a new entity to keep track of this cvar
71         e = spawn();
72         e.classname = "saved_cvar_value";
73         e.netname = strzone(tmp_cvar);
74         e.message = strzone(cvar_string(tmp_cvar));
75         return TRUE;
76         
77         // an entity for this cvar already exists, update the value
78         :saved
79         cvar_set(tmp_cvar, value);
80         return FALSE;
81 }
82
83 float cvar_clientsettemp_restore()
84 {
85         float i;
86         entity e;
87         
88         for(e = world; (e = find(e, classname, "saved_cvar_value")); )
89                 { cvar_set(e.netname, e.message); ++i; } 
90                 
91         return i;
92 }
93
94 void DrawDebugModel()
95 {
96         if(time - floor(time) > 0.5)
97         {
98                 PolyDrawModel(self);
99                 self.drawmask = 0;
100         }
101         else
102         {
103                 self.renderflags = 0;
104                 self.drawmask = MASK_NORMAL;
105         }
106 }
107
108
109 // =======================
110 //  Command Sub-Functions
111 // =======================
112
113 void GameCommand_blurtest(float request)
114 {
115         // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
116         // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
117         
118         #ifdef BLURTEST
119         switch(request)
120         {
121                 case GC_REQUEST_COMMAND:
122                 {
123                         blurtest_time0 = time;
124                         blurtest_time1 = time + stof(argv(1));
125                         blurtest_radius = stof(argv(2));
126                         blurtest_power = stof(argv(3));
127                         print("Enabled blurtest\n");
128                         return; 
129                 }
130                         
131                 default:
132                 case GC_REQUEST_USAGE:
133                 {
134                         print("\nUsage:^3 cl_cmd blurtest\n");
135                         print("  No arguments required.\n");
136                         return;
137                 }
138         }
139         #else
140         if(request)
141         {
142                 print("Blurtest is not enabled on this client.\n");
143                 return;
144         }
145         #endif
146 }
147
148 void GameCommand_hud(float request, float argc) // TODO: Add aliases in commands.cfg
149 {
150         switch(request)
151         {
152                 case GC_REQUEST_COMMAND:
153                 {
154                         switch(argv(1))
155                         {
156                                 case "configure":
157                                 {
158                                         cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
159                                         return;
160                                 }
161                                 
162                                 case "save":
163                                 {
164                                         if(argv(2))
165                                         {
166                                                 HUD_Panel_ExportCfg(argv(2));
167                                                 return;
168                                         }
169                                         else
170                                         {
171                                                 break; // go to usage, we're missing the paramater needed here.
172                                         }
173                                 }
174                                 
175                                 case "radar":
176                                 {
177                                         if(argv(2))
178                                                 hud_panel_radar_maximized = (stof(argv(2)) != 0);
179                                         else
180                                                 hud_panel_radar_maximized = !hud_panel_radar_maximized;
181                                         
182                                         return;
183                                 }
184                                 
185                                 case "scoreboard_columns_set":
186                                 {
187                                         Cmd_HUD_SetFields(argc); // todo update this function
188                                         
189                                         return;
190                                 }
191
192                                 case "scoreboard_columns_help":
193                                 {
194                                         Cmd_HUD_Help(argc); // todo update this function
195                                         
196                                         return;
197                                 }
198                         }
199                         return; 
200                 }
201                         
202                 default:
203                         print("Incorrect parameters for ^2hud^7\n");
204                 case GC_REQUEST_USAGE:
205                 {
206                         print("\nUsage:^3 cl_cmd hud action [configname | radartoggle]\n");
207                         print("  Where 'action' is the command to complete,\n");
208                         print("  'configname' is the name to save to for \"save\" action,\n");
209                         print("  and 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action.\n");
210                         print("  Full list of commands here: \"configure, save, radar.\"\n");
211                         return;
212                 }
213         }
214 }
215
216 void GameCommand_sendcvar(float request, float argc)
217 {
218         switch(request)
219         {
220                 case GC_REQUEST_COMMAND:
221                 {
222                         // W_FixWeaponOrder will trash argv, so save what we need.
223                         string thiscvar = strzone(argv(1));
224                         string s = cvar_string(thiscvar);
225                         
226                         if(thiscvar == "cl_weaponpriority")
227                                 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
228                         else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
229                                 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
230                                 
231                         localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
232                         strunzone(thiscvar);
233                         
234                         return; 
235                 }
236                         
237                 default:
238                 case GC_REQUEST_USAGE:
239                 {
240                         print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
241                         print("  Where 'cvar' is the cvar plus arguments to send to the server.\n");
242                         return;
243                 }
244         }
245 }
246
247 /* use this when creating a new command, making sure to place it in alphabetical order.
248 void GameCommand_(float request)
249 {
250         switch(request)
251         {
252                 case GC_REQUEST_COMMAND:
253                 {
254                         
255                         return; 
256                 }
257                         
258                 default:
259                 case GC_REQUEST_USAGE:
260                 {
261                         print("\nUsage:^3 cl_cmd \n");
262                         print("  No arguments required.\n");
263                         return;
264                 }
265         }
266 }
267 */
268
269
270 // ==================================
271 //  Macro system for client commands
272 // ==================================
273
274 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
275 #define CLIENT_COMMANDS(request,arguments) \
276         CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
277         CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
278         CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
279         /* nothing */
280         
281 void GameCommand_macro_help()
282 {
283         #define CLIENT_COMMAND(name,function,description) \
284                 { print("  ^2", name, "^7: ", description, "\n"); }
285                 
286         CLIENT_COMMANDS(0, 0)
287         #undef CLIENT_COMMAND
288         
289         return;
290 }
291
292 float GameCommand_macro_command(float argc)
293 {
294         #define CLIENT_COMMAND(name,function,description) \
295                 { if(name == strtolower(argv(0))) { function; return TRUE; } }
296                 
297         CLIENT_COMMANDS(GC_REQUEST_COMMAND, argc)
298         #undef CLIENT_COMMAND
299         
300         return FALSE;
301 }
302
303 float GameCommand_macro_usage(float argc)
304 {
305         #define CLIENT_COMMAND(name,function,description) \
306                 { if(name == strtolower(argv(1))) { function; return TRUE; } }
307                 
308         CLIENT_COMMANDS(GC_REQUEST_USAGE, argc)
309         #undef CLIENT_COMMAND
310         
311         return FALSE;
312 }
313
314
315 // =========================================
316 //  Main Function Called By Engine (cl_cmd)
317 // =========================================
318 // If this function exists, client code handles gamecommand instead of the engine code.
319
320 void GameCommand(string command)
321 {
322         float argc = tokenize_console(command);
323
324         if(strtolower(argv(0)) == "help") 
325         {
326                 if(argc == 1) 
327                 {
328                         print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
329                         GameCommand_macro_help();
330                         GameCommand_Generic("help");
331                         print("For help about specific commands, type cl_cmd help COMMAND\n");
332                         return;
333                 } 
334                 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
335                 {
336                         return;
337                 }
338         } 
339         else if(GameCommand_Generic(command)) 
340         {
341                 return; // handled by common/gamecommand.qc
342         }
343         else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands
344         {
345                 return; // handled by one of the above GameCommand_* functions
346         }
347         
348         // nothing above caught the command, must be invalid
349         print("Unknown client command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try cl_cmd help.\n");
350         
351         return;
352 }
353
354
355 // ===================================
356 //  Macro system for console commands
357 // ===================================
358
359 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
360 // Please add client commands to the function above this, as this is only for special reasons.
361 #define CONSOLE_COMMANDS_NORMAL \
362         CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
363         CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
364         CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
365         CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
366         /* nothing */
367         
368 #define CONSOLE_COMMANDS_MOVEMENT \
369         CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
370         CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
371         CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
372         CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
373         CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
374         CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
375         CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
376         CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
377         CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
378         CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
379         CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
380         CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
381         CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
382         CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
383         CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
384         CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
385         /* nothing */
386
387 void ConsoleCommand_macro_init()
388 {
389         // first init normal commands
390         #define CONSOLE_COMMAND(name,execution) \
391                 { registercommand(name); }
392
393         CONSOLE_COMMANDS_NORMAL
394         #undef CONSOLE_COMMAND
395         
396         // then init movement commands
397         #ifndef CAMERATEST
398         if(isdemo())
399         {
400         #endif
401                 #define CONSOLE_COMMAND(name,execution) \
402                         { registercommand(name); }
403
404                 CONSOLE_COMMANDS_MOVEMENT
405                 #undef CONSOLE_COMMAND
406         #ifndef CAMERATEST
407         }
408         #endif
409         
410         return;
411 }
412
413 float ConsoleCommand_macro_normal(float argc)
414 {
415         #define CONSOLE_COMMAND(name,execution) \
416                 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
417                 
418         CONSOLE_COMMANDS_NORMAL
419         #undef CONSOLE_COMMAND
420         
421         return FALSE;
422 }
423
424 float ConsoleCommand_macro_movement(float argc)
425 {
426         if(camera_active)
427         {
428                 #define CONSOLE_COMMAND(name,execution) \
429                         { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
430
431                 CONSOLE_COMMANDS_MOVEMENT
432                 #undef CONSOLE_COMMAND
433         }
434         
435         return FALSE;
436 }
437
438
439 // ======================================================
440 //  Main Function Called By Engine (registered commands)
441 // ======================================================
442 // Used to parse commands in the console that have been registered with the "registercommand" function
443
444 float CSQC_ConsoleCommand(string command)
445 {
446         float argc = tokenize_console(command);
447
448         if(ConsoleCommand_macro_normal(argc))
449         {
450                 return TRUE;
451         }
452         else if(ConsoleCommand_macro_movement(argc))
453         {
454                 return TRUE;
455         }
456         
457         // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
458
459         return FALSE;
460 }