2 // ==============================================
3 // CSQC client commands code, written by Samual
4 // Last updated: December 28th, 2011
5 // ==============================================
7 #include <common/command/_mod.qh>
10 #include "../autocvars.qh"
12 #include <client/hud/_mod.qh>
13 #include <client/hud/panel/quickmenu.qh>
14 #include <client/hud/panel/radar.qh>
16 #include "../mapvoting.qh"
17 #include "../miscfunctions.qh"
19 #include <client/mutators/_mod.qh>
21 #include <common/minigames/cl_minigames_hud.qh>
23 #include <common/mapinfo.qh>
25 void DrawDebugModel(entity this)
27 if (time - floor(time) > 0.5)
35 this.drawmask = MASK_NORMAL;
40 // =======================
41 // Command Sub-Functions
42 // =======================
44 void LocalCommand_blurtest(int request)
47 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
48 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
53 case CMD_REQUEST_COMMAND:
55 blurtest_time0 = time;
56 blurtest_time1 = time + stof(argv(1));
57 blurtest_radius = stof(argv(2));
58 blurtest_power = stof(argv(3));
59 LOG_INFO("Enabled blurtest");
64 case CMD_REQUEST_USAGE:
66 LOG_HELP("Usage:^3 cl_cmd blurtest");
67 LOG_HELP(" No arguments required.");
74 LOG_INFO("Blurtest is not enabled on this client.");
80 void LocalCommand_boxparticles(int request, int argc)
82 TC(int, request); TC(int, argc);
85 case CMD_REQUEST_COMMAND:
89 int effect = _particleeffectnum(argv(1));
92 int index = stoi(argv(2));
95 own = entitybyindex(-index);
97 own = findfloat(NULL, entnum, index);
98 vector org_from = stov(argv(3));
99 vector org_to = stov(argv(4));
100 vector dir_from = stov(argv(5));
101 vector dir_to = stov(argv(6));
102 int countmultiplier = stoi(argv(7));
103 int flags = stoi(argv(8));
104 boxparticles(effect, own, org_from, org_to, dir_from, dir_to, countmultiplier, flags);
111 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
112 case CMD_REQUEST_USAGE:
115 "Usage:^3 cl_cmd boxparticles effectname own org_from org_to, dir_from, dir_to, countmultiplier, flags\n"
116 " 'effectname' is the name of a particle effect in effectinfo.txt\n"
117 " 'own' is the entity number of the owner (negative for csqc ent, positive for svqc ent)\n"
118 " 'org_from' is the starting origin of the box\n"
119 " 'org_to' is the ending origin of the box\n"
120 " 'dir_from' is the minimum velocity\n"
121 " 'dir_to' is the maximum velocity\n"
122 " 'countmultiplier' defines a multiplier for the particle count (affects count only, not countabsolute or trailspacing)\n"
123 " 'flags' can contain:\n"
124 " 1 to respect globals particles_alphamin, particles_alphamax (set right before via prvm_globalset client)\n"
125 " 2 to respect globals particles_colormin, particles_colormax (set right before via prvm_globalset client)\n"
126 " 4 to respect globals particles_fade (set right before via prvm_globalset client)\n"
127 " 128 to draw a trail, not a box"
134 void LocalCommand_create_scrshot_ent(int request)
139 case CMD_REQUEST_COMMAND:
141 string path = ((argv(1) == "") ? "" : strcat(argv(1), "/"));
142 string filename = strcat(path, MapInfo_Map_bspname, "_scrshot_ent.txt");
143 int fh = fopen(filename, FILE_APPEND);
148 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
149 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin.x), " ", ftos(view_origin.y), " ", ftos(view_origin.z)), "\"\n"));
150 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles.x), " ", ftos(view_angles.y), " ", ftos(view_angles.z)), "\"\n"));
153 LOG_INFO("Completed screenshot entity dump in ^2data/data/", path, MapInfo_Map_bspname, "_scrshot_ent.txt^7.");
159 LOG_INFO("^1Error: ^7Could not dump to file!");
165 case CMD_REQUEST_USAGE:
167 LOG_HELP("Usage:^3 cl_cmd create_scrshot_ent [path]");
168 LOG_HELP(" Where 'path' can be the subdirectory of data/data in which the file is saved.");
174 void LocalCommand_debugmodel(int request, int argc)
176 TC(int, request); TC(int, argc);
179 case CMD_REQUEST_COMMAND:
181 string modelname = argv(1);
183 entity debugmodel_entity = new(debugmodel);
184 precache_model(modelname);
185 _setmodel(debugmodel_entity, modelname);
186 setorigin(debugmodel_entity, view_origin);
187 debugmodel_entity.angles = view_angles;
188 debugmodel_entity.draw = DrawDebugModel;
189 IL_PUSH(g_drawables, debugmodel_entity);
195 case CMD_REQUEST_USAGE:
197 LOG_HELP("Usage:^3 cl_cmd debugmodel model");
198 LOG_HELP(" Where 'model' is a string of the model name to use for the debug model.");
204 void LocalCommand_handlevote(int request, int argc)
206 TC(int, request); TC(int, argc);
209 case CMD_REQUEST_COMMAND:
214 if (InterpretBoolean(argv(1)))
227 if (uid2name_dialog) // handled by "uid2name" option
232 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
235 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
242 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
243 case CMD_REQUEST_USAGE:
245 LOG_HELP("Usage:^3 cl_cmd handlevote vote");
246 LOG_HELP(" Where 'vote' is the selection for either the current poll or uid2name.");
252 void LocalCommand_hud(int request, int argc)
254 TC(int, request); TC(int, argc);
257 case CMD_REQUEST_COMMAND:
259 if(MUTATOR_CALLHOOK(HUD_Command, argc))
266 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
272 if (argv(2) == "help")
274 LOG_HELP(" quickmenu [[default | file | \"\"] submenu file]");
275 LOG_HELP("Called without options (or with \"\") loads either the default quickmenu or a quickmenu file if hud_panel_quickmenu_file is set to a valid filename.");
276 LOG_HELP("A submenu name can be given to open the quickmenu directly in a submenu; it requires to specify 'default', 'file' or '\"\"' option.");
277 LOG_HELP("A file name can also be given to open a different quickmenu");
280 string file = ((argv(4) == "") ? autocvar_hud_panel_quickmenu_file : argv(4));
281 if (QuickMenu_IsOpened())
284 QuickMenu_Open(argv(2), argv(3), file); // mode, submenu
292 HUD_Panel_ExportCfg(argv(2));
297 break; // go to usage, we're missing the paramater needed here.
301 case "scoreboard_columns_set":
303 Cmd_Scoreboard_SetFields(argc);
307 case "scoreboard_columns_help":
309 Cmd_Scoreboard_Help();
316 HUD_Radar_Show_Maximized(InterpretBoolean(argv(2)), 0);
318 HUD_Radar_Show_Maximized(!hud_panel_radar_maximized, 0);
325 HUD_Radar_Show_Maximized(!hud_panel_radar_mouse, 1);
332 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
333 case CMD_REQUEST_USAGE:
335 LOG_HELP("Usage:^3 cl_cmd hud action [configname | radartoggle | layout]");
336 LOG_HELP(" Where 'action' is the command to complete,");
337 LOG_HELP(" 'configname' is the name to save to for \"save\" action,");
338 LOG_HELP(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,");
339 LOG_HELP(" and 'layout' is how to organize the scoreboard columns for the set action.");
340 LOG_HELP(" Full list of commands here: \"configure, quickmenu, minigame, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"");
346 void LocalCommand_localprint(int request, int argc)
348 TC(int, request); TC(int, argc);
351 case CMD_REQUEST_COMMAND:
355 centerprint_AddStandard(argv(1));
361 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
362 case CMD_REQUEST_USAGE:
364 LOG_HELP("Usage:^3 cl_cmd localprint \"message\"");
365 LOG_HELP(" 'message' is the centerprint message to send to yourself.");
371 void LocalCommand_mv_download(int request, int argc)
373 TC(int, request); TC(int, argc);
376 case CMD_REQUEST_COMMAND:
380 Cmd_MapVote_MapDownload(argc);
386 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
387 case CMD_REQUEST_USAGE:
389 LOG_HELP("Usage:^3 cl_cmd mv_download mapid");
390 LOG_HELP(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.");
396 void LocalCommand_sendcvar(int request, int argc)
398 TC(int, request); TC(int, argc);
401 case CMD_REQUEST_COMMAND:
405 // W_FixWeaponOrder will trash argv, so save what we need.
406 string thiscvar = string_null; strcpy(thiscvar, argv(1));
407 string s = cvar_string(thiscvar);
409 if (thiscvar == "cl_weaponpriority")
410 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
411 else if (substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
412 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
414 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
421 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
422 case CMD_REQUEST_USAGE:
424 LOG_HELP("Usage:^3 cl_cmd sendcvar <cvar>");
425 LOG_HELP(" Where 'cvar' is the cvar to send to the server.");
431 /* use this when creating a new command, making sure to place it in alphabetical order... also,
432 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
433 void LocalCommand_(int request)
437 case CMD_REQUEST_COMMAND:
444 case CMD_REQUEST_USAGE:
446 LOG_HELP("Usage:^3 cl_cmd ");
447 LOG_HELP(" No arguments required.");
455 // ==================================
456 // Macro system for client commands
457 // ==================================
459 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
460 CLIENT_COMMAND(blurtest, "Feature for testing blur postprocessing") { LocalCommand_blurtest(request); }
461 CLIENT_COMMAND(boxparticles, "Spawn particles manually") { LocalCommand_boxparticles(request, arguments); }
462 CLIENT_COMMAND(create_scrshot_ent, "Create an entity at this location for automatic screenshots") { LocalCommand_create_scrshot_ent(request); }
463 CLIENT_COMMAND(debugmodel, "Spawn a debug model manually") { LocalCommand_debugmodel(request, arguments); }
464 CLIENT_COMMAND(handlevote, "System to handle selecting a vote or option") { LocalCommand_handlevote(request, arguments); }
465 CLIENT_COMMAND(hud, "Commands regarding/controlling the HUD system") { LocalCommand_hud(request, arguments); }
466 CLIENT_COMMAND(localprint, "Create your own centerprint sent to yourself") { LocalCommand_localprint(request, arguments); }
467 CLIENT_COMMAND(mv_download, "Retrieve mapshot picture from the server") { LocalCommand_mv_download(request, arguments); }
468 CLIENT_COMMAND(sendcvar, "Send a cvar to the server (like cl_weaponpriority)") { LocalCommand_sendcvar(request, arguments); }
470 void LocalCommand_macro_help()
472 FOREACH(CLIENT_COMMANDS, true, LOG_HELPF(" ^2%s^7: %s", it.m_name, it.m_description));
475 bool LocalCommand_macro_command(int argc, string command)
477 string c = strtolower(argv(0));
478 FOREACH(CLIENT_COMMANDS, it.m_name == c, {
479 it.m_invokecmd(it, CMD_REQUEST_COMMAND, NULL, argc, command);
485 bool LocalCommand_macro_usage(int argc)
487 string c = strtolower(argv(1));
488 FOREACH(CLIENT_COMMANDS, it.m_name == c, {
489 it.m_invokecmd(it, CMD_REQUEST_USAGE, NULL, argc, "");
495 void LocalCommand_macro_write_aliases(int fh)
497 FOREACH(CLIENT_COMMANDS, true, CMD_Write_Alias("qc_cmd_cl", it.m_name, it.m_description));
501 // =========================================
502 // Main Function Called By Engine (cl_cmd)
503 // =========================================
504 // If this function exists, client code handles gamecommand instead of the engine code.
506 void GameCommand(string command)
508 int argc = tokenize_console(command);
510 // Guide for working with argc arguments by example:
511 // argc: 1 - 2 - 3 - 4
512 // argv: 0 - 1 - 2 - 3
513 // cmd vote - master - login - password
514 string s = strtolower(argv(0));
519 LOG_HELP("Client console commands:");
520 LocalCommand_macro_help();
522 LOG_HELP("\nGeneric commands shared by all programs:");
523 GenericCommand_macro_help();
525 LOG_HELP("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.");
526 LOG_HELP("For help about a specific command, type cl_cmd help COMMAND");
530 else if (GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
534 else if (LocalCommand_macro_usage(argc)) // now try for normal commands too
539 // continue as usual and scan for normal commands
540 if (GenericCommand(command) // handled by common/command/generic.qc
541 || LocalCommand_macro_command(argc, command) // handled by one of the above LocalCommand_* functions
542 || MUTATOR_CALLHOOK(CSQC_ConsoleCommand, s, argc, command) // handled by a mutator
545 // nothing above caught the command, must be invalid
546 LOG_INFO(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.");
550 // ===================================
551 // Macro system for console commands
552 // ===================================
554 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
555 // Please add client commands to the function above this, as this is only for special reasons.
556 // NOTE: showaccuracy is kept as legacy command
557 #define CONSOLE_COMMANDS_NORMAL() \
558 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = true; }) \
559 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = false; }) \
560 CONSOLE_COMMAND("+showaccuracy", { }) \
561 CONSOLE_COMMAND("-showaccuracy", { }) \
564 #define CONSOLE_COMMANDS_MOVEMENT() \
565 CONSOLE_COMMAND("+forward", { ++camera_direction.x; }) \
566 CONSOLE_COMMAND("-forward", { --camera_direction.x; }) \
567 CONSOLE_COMMAND("+back", { --camera_direction.x; }) \
568 CONSOLE_COMMAND("-back", { ++camera_direction.x; }) \
569 CONSOLE_COMMAND("+moveup", { ++camera_direction.z; }) \
570 CONSOLE_COMMAND("-moveup", { --camera_direction.z; }) \
571 CONSOLE_COMMAND("+movedown", { --camera_direction.z; }) \
572 CONSOLE_COMMAND("-movedown", { ++camera_direction.z; }) \
573 CONSOLE_COMMAND("+moveright", { --camera_direction.y; }) \
574 CONSOLE_COMMAND("-moveright", { ++camera_direction.y; }) \
575 CONSOLE_COMMAND("+moveleft", { ++camera_direction.y; }) \
576 CONSOLE_COMMAND("-moveleft", { --camera_direction.y; }) \
577 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
578 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
579 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
580 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
583 void ConsoleCommand_macro_init()
585 // first init normal commands
586 #define CONSOLE_COMMAND(name, execution) \
587 { registercommand(name); }
589 CONSOLE_COMMANDS_NORMAL();
590 #undef CONSOLE_COMMAND
592 // then init movement commands
597 #define CONSOLE_COMMAND(name, execution) \
598 registercommand(name);
600 CONSOLE_COMMANDS_MOVEMENT();
601 #undef CONSOLE_COMMAND
607 bool ConsoleCommand_macro_normal(string s, int argc)
609 #define CONSOLE_COMMAND(name, execution) \
610 { if (name == s) { { execution } return true; } }
612 CONSOLE_COMMANDS_NORMAL();
613 #undef CONSOLE_COMMAND
618 bool ConsoleCommand_macro_movement(string s, int argc)
622 #define CONSOLE_COMMAND(name, execution) \
623 { if (name == s) { { execution } return true; } }
625 CONSOLE_COMMANDS_MOVEMENT();
626 #undef CONSOLE_COMMAND
633 // ======================================================
634 // Main Function Called By Engine (registered commands)
635 // ======================================================
636 // Used to parse commands in the console that have been registered with the "registercommand" function
638 bool CSQC_ConsoleCommand(string command)
640 int argc = tokenize_console(command);
641 string s = strtolower(argv(0));
642 // Return value should be true if CSQC handled the command, otherwise return false to have the engine handle it.
643 return ConsoleCommand_macro_normal(s, argc)
644 || ConsoleCommand_macro_movement(s, argc)