]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/command/cl_cmd.qc
Merge remote-tracking branch 'origin/Mario/minstagib_powerups_fix'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / command / cl_cmd.qc
1 // ==============================================
2 //  CSQC client commands code, written by Samual
3 //  Last updated: December 28th, 2011
4 // ==============================================
5
6 void DrawDebugModel()
7 {
8         if(time - floor(time) > 0.5)
9         {
10                 PolyDrawModel(self);
11                 self.drawmask = 0;
12         }
13         else
14         {
15                 self.renderflags = 0;
16                 self.drawmask = MASK_NORMAL;
17         }
18 }
19
20
21 // =======================
22 //  Command Sub-Functions
23 // =======================
24
25 void LocalCommand_blurtest(float request)
26 {
27         // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
28         // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
29         
30         #ifdef BLURTEST
31         switch(request)
32         {
33                 case CMD_REQUEST_COMMAND:
34                 {
35                         blurtest_time0 = time;
36                         blurtest_time1 = time + stof(argv(1));
37                         blurtest_radius = stof(argv(2));
38                         blurtest_power = stof(argv(3));
39                         print("Enabled blurtest\n");
40                         return; 
41                 }
42                         
43                 default:
44                 case CMD_REQUEST_USAGE:
45                 {
46                         print("\nUsage:^3 cl_cmd blurtest\n");
47                         print("  No arguments required.\n");
48                         return;
49                 }
50         }
51         #else
52         if(request)
53         {
54                 print("Blurtest is not enabled on this client.\n");
55                 return;
56         }
57         #endif
58 }
59
60 void LocalCommand_create_scrshot_ent(float request)
61 {
62         switch(request)
63         {
64                 case CMD_REQUEST_COMMAND:
65                 {
66                         float fh;
67                         string filename = strcat(MapInfo_Map_bspname, "_scrshot_ent.txt");
68                         fh = fopen(filename, FILE_WRITE);
69                         
70                         if(fh >= 0)
71                         {
72                                 fputs(fh, "{\n");
73                                 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
74                                 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin_x), " ", ftos(view_origin_y), " ", ftos(view_origin_z)), "\"\n"));
75                                 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles_x), " ", ftos(view_angles_y), " ", ftos(view_angles_z)), "\"\n"));
76                                 fputs(fh, "}\n");
77                                 
78                                 print("Completed screenshot entity dump in ^2data/data/", MapInfo_Map_bspname, "_scrshot_ent.txt^7.\n");
79                                 
80                                 fclose(fh);
81                         }
82                         else
83                         {
84                                 print("^1Error: ^7Could not dump to file!\n");
85                         }
86                         return;
87                 }
88                         
89                 default:
90                 case CMD_REQUEST_USAGE:
91                 {
92                         print("\nUsage:^3 cl_cmd create_scrshot_ent\n");
93                         print("  No arguments required.\n");
94                         return;
95                 }
96         }
97 }
98
99 void LocalCommand_debugmodel(float request, float argc)
100 {
101         switch(request)
102         {
103                 case CMD_REQUEST_COMMAND:
104                 {
105                         string modelname = argv(1);
106                         entity debugmodel_entity;
107                         
108                         debugmodel_entity = spawn();
109                         precache_model(modelname);
110                         setmodel(debugmodel_entity, modelname);
111                         setorigin(debugmodel_entity, view_origin);
112                         debugmodel_entity.angles = view_angles;
113                         debugmodel_entity.draw = DrawDebugModel;
114                         debugmodel_entity.classname = "debugmodel";
115                         
116                         return; 
117                 }
118                         
119                 default:
120                 case CMD_REQUEST_USAGE:
121                 {
122                         print("\nUsage:^3 cl_cmd debugmodel model\n");
123                         print("  Where 'model' is a string of the model name to use for the debug model.\n");
124                         return;
125                 }
126         }
127 }
128
129 void LocalCommand_handlevote(float request, float argc)
130 {
131         switch(request)
132         {
133                 case CMD_REQUEST_COMMAND:
134                 {
135                         float vote_selection;
136                         string vote_string;
137                         
138                         if(InterpretBoolean(argv(1)))
139                         {
140                                 vote_selection = 2; 
141                                 vote_string = "yes";
142                         }
143                         else
144                         {
145                                 vote_selection = 1; 
146                                 vote_string = "no"; 
147                         }
148                         
149                         if(vote_selection)
150                         {
151                                 if(uid2name_dialog) // handled by "uid2name" option
152                                 {
153                                         vote_active = 0;
154                                         vote_prev = 0;
155                                         vote_change = -9999;
156                                         localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
157                                         uid2name_dialog = 0;
158                                 }
159                                 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
160                                 
161                                 return;
162                         }
163                 }
164                         
165                 default:
166                         print("Incorrect parameters for ^2handlevote^7\n");
167                 case CMD_REQUEST_USAGE:
168                 {
169                         print("\nUsage:^3 cl_cmd handlevote vote\n");
170                         print("  Where 'vote' is the selection for either the current poll or uid2name.\n");
171                         return;
172                 }
173         }
174 }
175
176 void LocalCommand_hud(float request, float argc)
177 {
178         switch(request)
179         {
180                 case CMD_REQUEST_COMMAND:
181                 {
182                         switch(argv(1))
183                         {
184                                 case "configure":
185                                 {
186                                         cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
187                                         return;
188                                 }
189                                 
190                                 case "save":
191                                 {
192                                         if(argv(2))
193                                         {
194                                                 HUD_Panel_ExportCfg(argv(2));
195                                                 return;
196                                         }
197                                         else
198                                         {
199                                                 break; // go to usage, we're missing the paramater needed here.
200                                         }
201                                 }
202                                 
203                                 case "scoreboard_columns_set":
204                                 {
205                                         Cmd_HUD_SetFields(argc); 
206                                         return;
207                                 }
208
209                                 case "scoreboard_columns_help":
210                                 {
211                                         Cmd_HUD_Help();
212                                         return;
213                                 }
214                                 
215                                 case "radar":
216                                 {
217                                         if(argv(2))
218                                                 hud_panel_radar_maximized = InterpretBoolean(argv(2));
219                                         else
220                                                 hud_panel_radar_maximized = !hud_panel_radar_maximized;
221                                         return;
222                                 }
223                         }
224                 }
225                         
226                 default:
227                         print("Incorrect parameters for ^2hud^7\n");
228                 case CMD_REQUEST_USAGE:
229                 {
230                         print("\nUsage:^3 cl_cmd hud action [configname | radartoggle | layout]\n");
231                         print("  Where 'action' is the command to complete,\n");
232                         print("  'configname' is the name to save to for \"save\" action,\n");
233                         print("  'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,\n");
234                         print("  and 'layout' is how to organize the scoreboard columns for the set action.\n");
235                         print("  Full list of commands here: \"configure, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"\n");
236                         return;
237                 }
238         }
239 }
240
241 void LocalCommand_localprint(float request, float argc)
242 {
243         switch(request)
244         {
245                 case CMD_REQUEST_COMMAND:
246                 {
247                         if(argv(1))
248                         {
249                                 centerprint_hud(argv(1));
250                                 return; 
251                         }
252                 }
253                         
254                 default:
255                         print("Incorrect parameters for ^2localprint^7\n");
256                 case CMD_REQUEST_USAGE:
257                 {
258                         print("\nUsage:^3 cl_cmd localprint \"message\"\n");
259                         print("  'message' is the centerprint message to send to yourself.\n");
260                         return;
261                 }
262         }
263 }
264
265 void LocalCommand_mv_download(float request, float argc)
266 {
267         switch(request)
268         {
269                 case CMD_REQUEST_COMMAND:
270                 {
271                         if(argv(1))
272                         {
273                                 Cmd_MapVote_MapDownload(argc);
274                                 return; 
275                         }
276                 }
277                         
278                 default:
279                         print("Incorrect parameters for ^2mv_download^7\n");
280                 case CMD_REQUEST_USAGE:
281                 {
282                         print("\nUsage:^3 cl_cmd mv_download mapid\n");
283                         print("  Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
284                         return;
285                 }
286         }
287 }
288
289 void LocalCommand_sendcvar(float request, float argc)
290 {
291         switch(request)
292         {
293                 case CMD_REQUEST_COMMAND:
294                 {
295                         if(argv(1))
296                         {
297                                 // W_FixWeaponOrder will trash argv, so save what we need.
298                                 string thiscvar = strzone(argv(1));
299                                 string s = cvar_string(thiscvar);
300                                 
301                                 if(thiscvar == "cl_weaponpriority")
302                                         s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
303                                 else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
304                                         s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
305                                         
306                                 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
307                                 strunzone(thiscvar);
308                                 return; 
309                         }
310                 }
311                         
312                 default:
313                         print("Incorrect parameters for ^2sendcvar^7\n");
314                 case CMD_REQUEST_USAGE:
315                 {
316                         print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
317                         print("  Where 'cvar' is the cvar plus arguments to send to the server.\n");
318                         return;
319                 }
320         }
321 }
322
323 /* use this when creating a new command, making sure to place it in alphabetical order... also,
324 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
325 void LocalCommand_(float request)
326 {
327         switch(request)
328         {
329                 case CMD_REQUEST_COMMAND:
330                 {
331                         
332                         return; 
333                 }
334                         
335                 default:
336                 case CMD_REQUEST_USAGE:
337                 {
338                         print("\nUsage:^3 cl_cmd \n");
339                         print("  No arguments required.\n");
340                         return;
341                 }
342         }
343 }
344 */
345
346
347 // ==================================
348 //  Macro system for client commands
349 // ==================================
350
351 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
352 #define CLIENT_COMMANDS(request,arguments) \
353         CLIENT_COMMAND("blurtest", LocalCommand_blurtest(request), "Feature for testing blur postprocessing") \
354         CLIENT_COMMAND("create_scrshot_ent", LocalCommand_create_scrshot_ent(request), "Create an entity at this location for automatic screenshots") \
355         CLIENT_COMMAND("debugmodel", LocalCommand_debugmodel(request, arguments), "Spawn a debug model manually") \
356         CLIENT_COMMAND("handlevote", LocalCommand_handlevote(request, arguments), "System to handle selecting a vote or option") \
357         CLIENT_COMMAND("hud", LocalCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
358         CLIENT_COMMAND("localprint", LocalCommand_localprint(request, arguments), "Create your own centerprint sent to yourself") \
359         CLIENT_COMMAND("mv_download", LocalCommand_mv_download(request, arguments), "Retrieve mapshot picture from the server") \
360         CLIENT_COMMAND("sendcvar", LocalCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
361         /* nothing */
362         
363 void LocalCommand_macro_help()
364 {
365         #define CLIENT_COMMAND(name,function,description) \
366                 { if(strtolower(description) != "") { print("  ^2", name, "^7: ", description, "\n"); } }
367                 
368         CLIENT_COMMANDS(0, 0)
369         #undef CLIENT_COMMAND
370         
371         return;
372 }
373
374 float LocalCommand_macro_command(float argc)
375 {
376         #define CLIENT_COMMAND(name,function,description) \
377                 { if(name == strtolower(argv(0))) { function; return TRUE; } }
378                 
379         CLIENT_COMMANDS(CMD_REQUEST_COMMAND, argc)
380         #undef CLIENT_COMMAND
381         
382         return FALSE;
383 }
384
385 float LocalCommand_macro_usage(float argc)
386 {
387         #define CLIENT_COMMAND(name,function,description) \
388                 { if(name == strtolower(argv(1))) { function; return TRUE; } }
389                 
390         CLIENT_COMMANDS(CMD_REQUEST_USAGE, argc)
391         #undef CLIENT_COMMAND
392         
393         return FALSE;
394 }
395
396 void LocalCommand_macro_write_aliases(float fh)
397 {
398         #define CLIENT_COMMAND(name,function,description) \
399                 { if(strtolower(description) != "") { CMD_Write_Alias("qc_cmd_cl", name, description); } }
400                 
401         CLIENT_COMMANDS(0, 0)
402         #undef CLIENT_COMMAND
403         
404         return;
405 }
406
407
408 // =========================================
409 //  Main Function Called By Engine (cl_cmd)
410 // =========================================
411 // If this function exists, client code handles gamecommand instead of the engine code.
412
413 void GameCommand(string command)
414 {
415         float argc = tokenize_console(command);
416
417         // Guide for working with argc arguments by example:
418         // argc:   1    - 2      - 3     - 4
419         // argv:   0    - 1      - 2     - 3 
420         // cmd     vote - master - login - password
421
422         if(strtolower(argv(0)) == "help") 
423         {
424                 if(argc == 1) 
425                 {
426                         print("\nClient console commands:\n");
427                         LocalCommand_macro_help();
428
429                         print("\nGeneric commands shared by all programs:\n");
430                         GenericCommand_macro_help();
431                         
432                         print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.\n");
433                         print("For help about a specific command, type cl_cmd help COMMAND\n");
434                         
435                         return;
436                 } 
437                 else if(GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
438                 {
439                         return;
440                 }
441                 else if(LocalCommand_macro_usage(argc)) // now try for normal commands too
442                 {
443                         return;
444                 }
445         } 
446         else if(GenericCommand(command)) 
447         {
448                 return; // handled by common/command/generic.qc
449         }
450         else if(LocalCommand_macro_command(argc)) // continue as usual and scan for normal commands
451         {
452                 return; // handled by one of the above LocalCommand_* functions
453         }
454         
455         // nothing above caught the command, must be invalid
456         print(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
457         
458         return;
459 }
460
461
462 // ===================================
463 //  Macro system for console commands
464 // ===================================
465
466 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
467 // Please add client commands to the function above this, as this is only for special reasons.
468 #define CONSOLE_COMMANDS_NORMAL \
469         CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
470         CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
471         CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
472         CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
473         /* nothing */
474         
475 #define CONSOLE_COMMANDS_MOVEMENT \
476         CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
477         CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
478         CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
479         CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
480         CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
481         CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
482         CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
483         CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
484         CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
485         CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
486         CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
487         CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
488         CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
489         CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
490         CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
491         CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
492         /* nothing */
493
494 void ConsoleCommand_macro_init()
495 {
496         // first init normal commands
497         #define CONSOLE_COMMAND(name,execution) \
498                 { registercommand(name); }
499
500         CONSOLE_COMMANDS_NORMAL
501         #undef CONSOLE_COMMAND
502         
503         // then init movement commands
504         #ifndef CAMERATEST
505         if(isdemo())
506         {
507         #endif
508                 #define CONSOLE_COMMAND(name,execution) \
509                         { registercommand(name); }
510
511                 CONSOLE_COMMANDS_MOVEMENT
512                 #undef CONSOLE_COMMAND
513         #ifndef CAMERATEST
514         }
515         #endif
516         
517         return;
518 }
519
520 float ConsoleCommand_macro_normal(float argc)
521 {
522         #define CONSOLE_COMMAND(name,execution) \
523                 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
524                 
525         CONSOLE_COMMANDS_NORMAL
526         #undef CONSOLE_COMMAND
527         
528         return FALSE;
529 }
530
531 float ConsoleCommand_macro_movement(float argc)
532 {
533         if(camera_active)
534         {
535                 #define CONSOLE_COMMAND(name,execution) \
536                         { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
537
538                 CONSOLE_COMMANDS_MOVEMENT
539                 #undef CONSOLE_COMMAND
540         }
541         
542         return FALSE;
543 }
544
545
546 // ======================================================
547 //  Main Function Called By Engine (registered commands)
548 // ======================================================
549 // Used to parse commands in the console that have been registered with the "registercommand" function
550
551 float CSQC_ConsoleCommand(string command)
552 {
553         float argc = tokenize_console(command);
554
555         if(ConsoleCommand_macro_normal(argc))
556         {
557                 return TRUE;
558         }
559         else if(ConsoleCommand_macro_movement(argc))
560         {
561                 return TRUE;
562         }
563         
564         // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
565
566         return FALSE;
567 }