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_INFO("Usage:^3 cl_cmd blurtest");
67 LOG_INFO(" 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);
112 LOG_INFO("Incorrect parameters for ^2boxparticles^7");
114 case CMD_REQUEST_USAGE:
117 "Usage:^3 lv_cmd boxparticles effectname own org_from org_to, dir_from, dir_to, countmultiplier, flags\n"
118 " 'effectname' is the name of a particle effect in effectinfo.txt\n"
119 " 'own' is the entity number of the owner (negative for csqc ent, positive for svqc ent)\n"
120 " 'org_from' is the starting origin of the box\n"
121 " 'org_to' is the ending origin of the box\n"
122 " 'dir_from' is the minimum velocity\n"
123 " 'dir_to' is the maximum velocity\n"
124 " 'countmultiplier' defines a multiplier for the particle count (affects count only, not countabsolute or trailspacing)\n"
125 " 'flags' can contain:\n"
126 " 1 to respect globals particles_alphamin, particles_alphamax (set right before via prvm_globalset client)\n"
127 " 2 to respect globals particles_colormin, particles_colormax (set right before via prvm_globalset client)\n"
128 " 4 to respect globals particles_fade (set right before via prvm_globalset client)\n"
129 " 128 to draw a trail, not a box\n"
136 void LocalCommand_create_scrshot_ent(int request)
141 case CMD_REQUEST_COMMAND:
143 string path = ((argv(1) == "") ? "" : strcat(argv(1), "/"));
144 string filename = strcat(path, MapInfo_Map_bspname, "_scrshot_ent.txt");
145 int fh = fopen(filename, FILE_APPEND);
150 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
151 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin.x), " ", ftos(view_origin.y), " ", ftos(view_origin.z)), "\"\n"));
152 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles.x), " ", ftos(view_angles.y), " ", ftos(view_angles.z)), "\"\n"));
155 LOG_INFO("Completed screenshot entity dump in ^2data/data/", path, MapInfo_Map_bspname, "_scrshot_ent.txt^7.");
161 LOG_INFO("^1Error: ^7Could not dump to file!");
167 case CMD_REQUEST_USAGE:
169 LOG_INFO("Usage:^3 cl_cmd create_scrshot_ent [path]");
170 LOG_INFO(" Where 'path' can be the subdirectory of data/data in which the file is saved.");
176 void LocalCommand_debugmodel(int request, int argc)
178 TC(int, request); TC(int, argc);
181 case CMD_REQUEST_COMMAND:
183 string modelname = argv(1);
185 entity debugmodel_entity = new(debugmodel);
186 precache_model(modelname);
187 _setmodel(debugmodel_entity, modelname);
188 setorigin(debugmodel_entity, view_origin);
189 debugmodel_entity.angles = view_angles;
190 debugmodel_entity.draw = DrawDebugModel;
191 IL_PUSH(g_drawables, debugmodel_entity);
197 case CMD_REQUEST_USAGE:
199 LOG_INFO("Usage:^3 cl_cmd debugmodel model");
200 LOG_INFO(" Where 'model' is a string of the model name to use for the debug model.");
206 void LocalCommand_handlevote(int request, int argc)
208 TC(int, request); TC(int, argc);
211 case CMD_REQUEST_COMMAND:
216 if (InterpretBoolean(argv(1)))
229 if (uid2name_dialog) // handled by "uid2name" option
234 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
237 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
245 LOG_INFO("Incorrect parameters for ^2handlevote^7");
247 case CMD_REQUEST_USAGE:
249 LOG_INFO("Usage:^3 cl_cmd handlevote vote");
250 LOG_INFO(" Where 'vote' is the selection for either the current poll or uid2name.");
256 void LocalCommand_hud(int request, int argc)
258 TC(int, request); TC(int, argc);
261 case CMD_REQUEST_COMMAND:
263 if(MUTATOR_CALLHOOK(HUD_Command, argc))
270 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
276 if (argv(2) == "help")
278 LOG_INFO(" quickmenu [[default | file | \"\"] submenu file]");
279 LOG_INFO("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.");
280 LOG_INFO("A submenu name can be given to open the quickmenu directly in a submenu; it requires to specify 'default', 'file' or '\"\"' option.");
281 LOG_INFO("A file name can also be given to open a different quickmenu");
284 string file = ((argv(4) == "") ? autocvar_hud_panel_quickmenu_file : argv(4));
285 if (QuickMenu_IsOpened())
288 QuickMenu_Open(argv(2), argv(3), file); // mode, submenu
296 HUD_Panel_ExportCfg(argv(2));
301 break; // go to usage, we're missing the paramater needed here.
305 case "scoreboard_columns_set":
307 Cmd_Scoreboard_SetFields(argc);
311 case "scoreboard_columns_help":
313 Cmd_Scoreboard_Help();
320 HUD_Radar_Show_Maximized(InterpretBoolean(argv(2)), 0);
322 HUD_Radar_Show_Maximized(!hud_panel_radar_maximized, 0);
329 HUD_Radar_Show_Maximized(!hud_panel_radar_mouse, 1);
337 LOG_INFO("Incorrect parameters for ^2hud^7");
339 case CMD_REQUEST_USAGE:
341 LOG_INFO("Usage:^3 cl_cmd hud action [configname | radartoggle | layout]");
342 LOG_INFO(" Where 'action' is the command to complete,");
343 LOG_INFO(" 'configname' is the name to save to for \"save\" action,");
344 LOG_INFO(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,");
345 LOG_INFO(" and 'layout' is how to organize the scoreboard columns for the set action.");
346 LOG_INFO(" Full list of commands here: \"configure, quickmenu, minigame, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"");
352 void LocalCommand_localprint(int request, int argc)
354 TC(int, request); TC(int, argc);
357 case CMD_REQUEST_COMMAND:
361 centerprint_hud(argv(1));
368 LOG_INFO("Incorrect parameters for ^2localprint^7");
370 case CMD_REQUEST_USAGE:
372 LOG_INFO("Usage:^3 cl_cmd localprint \"message\"");
373 LOG_INFO(" 'message' is the centerprint message to send to yourself.");
379 void LocalCommand_mv_download(int request, int argc)
381 TC(int, request); TC(int, argc);
384 case CMD_REQUEST_COMMAND:
388 Cmd_MapVote_MapDownload(argc);
395 LOG_INFO("Incorrect parameters for ^2mv_download^7");
397 case CMD_REQUEST_USAGE:
399 LOG_INFO("Usage:^3 cl_cmd mv_download mapid");
400 LOG_INFO(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.");
406 void LocalCommand_sendcvar(int request, int argc)
408 TC(int, request); TC(int, argc);
411 case CMD_REQUEST_COMMAND:
415 // W_FixWeaponOrder will trash argv, so save what we need.
416 string thiscvar = string_null; strcpy(thiscvar, argv(1));
417 string s = cvar_string(thiscvar);
419 if (thiscvar == "cl_weaponpriority")
420 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
421 else if (substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
422 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
424 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
432 LOG_INFO("Incorrect parameters for ^2sendcvar^7");
434 case CMD_REQUEST_USAGE:
436 LOG_INFO("Usage:^3 cl_cmd sendcvar <cvar>");
437 LOG_INFO(" Where 'cvar' is the cvar to send to the server.");
443 /* use this when creating a new command, making sure to place it in alphabetical order... also,
444 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
445 void LocalCommand_(int request)
449 case CMD_REQUEST_COMMAND:
456 case CMD_REQUEST_USAGE:
458 print("\nUsage:^3 cl_cmd \n");
459 print(" No arguments required.\n");
467 // ==================================
468 // Macro system for client commands
469 // ==================================
471 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
472 CLIENT_COMMAND(blurtest, "Feature for testing blur postprocessing") { LocalCommand_blurtest(request); }
473 CLIENT_COMMAND(boxparticles, "Spawn particles manually") { LocalCommand_boxparticles(request, arguments); }
474 CLIENT_COMMAND(create_scrshot_ent, "Create an entity at this location for automatic screenshots") { LocalCommand_create_scrshot_ent(request); }
475 CLIENT_COMMAND(debugmodel, "Spawn a debug model manually") { LocalCommand_debugmodel(request, arguments); }
476 CLIENT_COMMAND(handlevote, "System to handle selecting a vote or option") { LocalCommand_handlevote(request, arguments); }
477 CLIENT_COMMAND(hud, "Commands regarding/controlling the HUD system") { LocalCommand_hud(request, arguments); }
478 CLIENT_COMMAND(localprint, "Create your own centerprint sent to yourself") { LocalCommand_localprint(request, arguments); }
479 CLIENT_COMMAND(mv_download, "Retrieve mapshot picture from the server") { LocalCommand_mv_download(request, arguments); }
480 CLIENT_COMMAND(sendcvar, "Send a cvar to the server (like cl_weaponpriority)") { LocalCommand_sendcvar(request, arguments); }
482 void LocalCommand_macro_help()
484 FOREACH(CLIENT_COMMANDS, true, LOG_INFOF(" ^2%s^7: %s", it.m_name, it.m_description));
487 bool LocalCommand_macro_command(int argc, string command)
489 string c = strtolower(argv(0));
490 FOREACH(CLIENT_COMMANDS, it.m_name == c, {
491 it.m_invokecmd(it, CMD_REQUEST_COMMAND, NULL, argc, command);
497 bool LocalCommand_macro_usage(int argc)
499 string c = strtolower(argv(1));
500 FOREACH(CLIENT_COMMANDS, it.m_name == c, {
501 it.m_invokecmd(it, CMD_REQUEST_USAGE, NULL, argc, "");
507 void LocalCommand_macro_write_aliases(int fh)
509 FOREACH(CLIENT_COMMANDS, true, CMD_Write_Alias("qc_cmd_cl", it.m_name, it.m_description));
513 // =========================================
514 // Main Function Called By Engine (cl_cmd)
515 // =========================================
516 // If this function exists, client code handles gamecommand instead of the engine code.
518 void GameCommand(string command)
520 int argc = tokenize_console(command);
522 // Guide for working with argc arguments by example:
523 // argc: 1 - 2 - 3 - 4
524 // argv: 0 - 1 - 2 - 3
525 // cmd vote - master - login - password
526 string s = strtolower(argv(0));
531 LOG_INFO("Client console commands:");
532 LocalCommand_macro_help();
534 LOG_INFO("\nGeneric commands shared by all programs:");
535 GenericCommand_macro_help();
537 LOG_INFO("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.");
538 LOG_INFO("For help about a specific command, type cl_cmd help COMMAND");
542 else if (GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
546 else if (LocalCommand_macro_usage(argc)) // now try for normal commands too
551 // continue as usual and scan for normal commands
552 if (GenericCommand(command) // handled by common/command/generic.qc
553 || LocalCommand_macro_command(argc, command) // handled by one of the above LocalCommand_* functions
554 || MUTATOR_CALLHOOK(CSQC_ConsoleCommand, s, argc, command) // handled by a mutator
557 // nothing above caught the command, must be invalid
558 LOG_INFO(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.");
562 // ===================================
563 // Macro system for console commands
564 // ===================================
566 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
567 // Please add client commands to the function above this, as this is only for special reasons.
568 // NOTE: showaccuracy is kept as legacy command
569 #define CONSOLE_COMMANDS_NORMAL() \
570 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = true; }) \
571 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = false; }) \
572 CONSOLE_COMMAND("+showaccuracy", { }) \
573 CONSOLE_COMMAND("-showaccuracy", { }) \
576 #define CONSOLE_COMMANDS_MOVEMENT() \
577 CONSOLE_COMMAND("+forward", { ++camera_direction.x; }) \
578 CONSOLE_COMMAND("-forward", { --camera_direction.x; }) \
579 CONSOLE_COMMAND("+back", { --camera_direction.x; }) \
580 CONSOLE_COMMAND("-back", { ++camera_direction.x; }) \
581 CONSOLE_COMMAND("+moveup", { ++camera_direction.z; }) \
582 CONSOLE_COMMAND("-moveup", { --camera_direction.z; }) \
583 CONSOLE_COMMAND("+movedown", { --camera_direction.z; }) \
584 CONSOLE_COMMAND("-movedown", { ++camera_direction.z; }) \
585 CONSOLE_COMMAND("+moveright", { --camera_direction.y; }) \
586 CONSOLE_COMMAND("-moveright", { ++camera_direction.y; }) \
587 CONSOLE_COMMAND("+moveleft", { ++camera_direction.y; }) \
588 CONSOLE_COMMAND("-moveleft", { --camera_direction.y; }) \
589 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
590 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
591 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
592 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
595 void ConsoleCommand_macro_init()
597 // first init normal commands
598 #define CONSOLE_COMMAND(name, execution) \
599 { registercommand(name); }
601 CONSOLE_COMMANDS_NORMAL();
602 #undef CONSOLE_COMMAND
604 // then init movement commands
609 #define CONSOLE_COMMAND(name, execution) \
610 registercommand(name);
612 CONSOLE_COMMANDS_MOVEMENT();
613 #undef CONSOLE_COMMAND
619 bool ConsoleCommand_macro_normal(string s, int argc)
621 #define CONSOLE_COMMAND(name, execution) \
622 { if (name == s) { { execution } return true; } }
624 CONSOLE_COMMANDS_NORMAL();
625 #undef CONSOLE_COMMAND
630 bool ConsoleCommand_macro_movement(string s, int argc)
634 #define CONSOLE_COMMAND(name, execution) \
635 { if (name == s) { { execution } return true; } }
637 CONSOLE_COMMANDS_MOVEMENT();
638 #undef CONSOLE_COMMAND
645 // ======================================================
646 // Main Function Called By Engine (registered commands)
647 // ======================================================
648 // Used to parse commands in the console that have been registered with the "registercommand" function
650 bool CSQC_ConsoleCommand(string command)
652 int argc = tokenize_console(command);
653 string s = strtolower(argv(0));
654 // Return value should be true if CSQC handled the command, otherwise return false to have the engine handle it.
655 return ConsoleCommand_macro_normal(s, argc)
656 || ConsoleCommand_macro_movement(s, argc)