3 // ==============================================
4 // CSQC client commands code, written by Samual
5 // Last updated: December 28th, 2011
6 // ==============================================
8 #include <client/autocvars.qh>
9 #include <client/draw.qh>
10 #include <client/hud/_mod.qh>
11 #include <client/hud/panel/quickmenu.qh>
12 #include <client/hud/panel/radar.qh>
13 #include <client/hud/panel/scoreboard.qh>
14 #include <client/hud/panel/vote.qh>
15 #include <client/mapvoting.qh>
16 #include <client/mutators/_mod.qh>
17 #include <client/view.qh>
18 #include <common/command/_mod.qh>
19 #include <common/mapinfo.qh>
20 #include <common/minigames/cl_minigames_hud.qh>
22 void DrawDebugModel(entity this)
24 if (time - floor(time) > 0.5)
32 this.drawmask = MASK_NORMAL;
37 // =======================
38 // Command Sub-Functions
39 // =======================
41 void LocalCommand_blurtest(int request)
44 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
45 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
50 case CMD_REQUEST_COMMAND:
52 blurtest_time0 = time;
53 blurtest_time1 = time + stof(argv(1));
54 blurtest_radius = stof(argv(2));
55 blurtest_power = stof(argv(3));
56 LOG_INFO("Enabled blurtest");
61 case CMD_REQUEST_USAGE:
63 LOG_HELP("Usage:^3 cl_cmd blurtest");
64 LOG_HELP(" No arguments required.");
71 LOG_INFO("Blurtest is not enabled on this client.");
77 void LocalCommand_boxparticles(int request, int argc)
79 TC(int, request); TC(int, argc);
82 case CMD_REQUEST_COMMAND:
86 int effect = _particleeffectnum(argv(1));
89 int index = stoi(argv(2));
92 own = entitybyindex(-index);
94 own = findfloat(NULL, entnum, index);
95 vector org_from = stov(argv(3));
96 vector org_to = stov(argv(4));
97 vector dir_from = stov(argv(5));
98 vector dir_to = stov(argv(6));
99 int countmultiplier = stoi(argv(7));
100 int flags = stoi(argv(8));
101 boxparticles(effect, own, org_from, org_to, dir_from, dir_to, countmultiplier, flags);
108 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
109 case CMD_REQUEST_USAGE:
112 "Usage:^3 cl_cmd boxparticles effectname own org_from org_to, dir_from, dir_to, countmultiplier, flags\n"
113 " 'effectname' is the name of a particle effect in effectinfo.txt\n"
114 " 'own' is the entity number of the owner (negative for csqc ent, positive for svqc ent)\n"
115 " 'org_from' is the starting origin of the box\n"
116 " 'org_to' is the ending origin of the box\n"
117 " 'dir_from' is the minimum velocity\n"
118 " 'dir_to' is the maximum velocity\n"
119 " 'countmultiplier' defines a multiplier for the particle count (affects count only, not countabsolute or trailspacing)\n"
120 " 'flags' can contain:\n"
121 " 1 to respect globals particles_alphamin, particles_alphamax (set right before via prvm_globalset client)\n"
122 " 2 to respect globals particles_colormin, particles_colormax (set right before via prvm_globalset client)\n"
123 " 4 to respect globals particles_fade (set right before via prvm_globalset client)\n"
124 " 128 to draw a trail, not a box"
131 void LocalCommand_create_scrshot_ent(int request)
136 case CMD_REQUEST_COMMAND:
138 string path = ((argv(1) == "") ? "" : strcat(argv(1), "/"));
139 string filename = strcat(path, MapInfo_Map_bspname, "_scrshot_ent.txt");
140 int fh = fopen(filename, FILE_APPEND);
145 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
146 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin.x), " ", ftos(view_origin.y), " ", ftos(view_origin.z)), "\"\n"));
147 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles.x), " ", ftos(view_angles.y), " ", ftos(view_angles.z)), "\"\n"));
150 LOG_INFO("Completed screenshot entity dump in ^2data/data/", path, MapInfo_Map_bspname, "_scrshot_ent.txt^7.");
156 LOG_INFO("^1Error: ^7Could not dump to file!");
162 case CMD_REQUEST_USAGE:
164 LOG_HELP("Usage:^3 cl_cmd create_scrshot_ent [path]");
165 LOG_HELP(" Where 'path' can be the subdirectory of data/data in which the file is saved.");
171 void LocalCommand_debugmodel(int request, int argc)
173 TC(int, request); TC(int, argc);
176 case CMD_REQUEST_COMMAND:
178 string modelname = argv(1);
180 entity debugmodel_entity = new(debugmodel);
181 precache_model(modelname);
182 _setmodel(debugmodel_entity, modelname);
183 setorigin(debugmodel_entity, view_origin);
184 debugmodel_entity.angles = view_angles;
185 debugmodel_entity.draw = DrawDebugModel;
186 IL_PUSH(g_drawables, debugmodel_entity);
192 case CMD_REQUEST_USAGE:
194 LOG_HELP("Usage:^3 cl_cmd debugmodel model");
195 LOG_HELP(" Where 'model' is a string of the model name to use for the debug model.");
201 void LocalCommand_handlevote(int request, int argc)
203 TC(int, request); TC(int, argc);
206 case CMD_REQUEST_COMMAND:
211 if (InterpretBoolean(argv(1)))
224 if (uid2name_dialog) // handled by "uid2name" option
229 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
232 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
239 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
240 case CMD_REQUEST_USAGE:
242 LOG_HELP("Usage:^3 cl_cmd handlevote vote");
243 LOG_HELP(" Where 'vote' is the selection for either the current poll or uid2name.");
249 void LocalCommand_hud(int request, int argc)
251 TC(int, request); TC(int, argc);
254 case CMD_REQUEST_COMMAND:
256 if(MUTATOR_CALLHOOK(HUD_Command, argc))
263 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
269 if (argv(2) == "help")
271 LOG_HELP(" quickmenu [[default | file | \"\"] submenu file]");
272 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.");
273 LOG_HELP("A submenu name can be given to open the quickmenu directly in a submenu; it requires to specify 'default', 'file' or '\"\"' option.");
274 LOG_HELP("A file name can also be given to open a different quickmenu");
277 string file = ((argv(4) == "") ? autocvar_hud_panel_quickmenu_file : argv(4));
278 if (QuickMenu_IsOpened())
281 QuickMenu_Open(argv(2), argv(3), file); // mode, submenu
289 HUD_Panel_ExportCfg(argv(2));
294 break; // go to usage, we're missing the paramater needed here.
298 case "scoreboard_columns_set":
300 Cmd_Scoreboard_SetFields(argc);
304 case "scoreboard_columns_help":
306 Cmd_Scoreboard_Help();
313 HUD_Radar_Show_Maximized(InterpretBoolean(argv(2)), 0);
315 HUD_Radar_Show_Maximized(!hud_panel_radar_maximized, 0);
322 HUD_Radar_Show_Maximized(!hud_panel_radar_mouse, 1);
329 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
330 case CMD_REQUEST_USAGE:
332 LOG_HELP("Usage:^3 cl_cmd hud action [configname | radartoggle | layout]");
333 LOG_HELP(" Where 'action' is the command to complete,");
334 LOG_HELP(" 'configname' is the name to save to for \"save\" action,");
335 LOG_HELP(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,");
336 LOG_HELP(" and 'layout' is how to organize the scoreboard columns for the set action.");
337 LOG_HELP(" Full list of commands here: \"configure, quickmenu, minigame, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"");
343 void LocalCommand_localprint(int request, int argc)
345 TC(int, request); TC(int, argc);
348 case CMD_REQUEST_COMMAND:
352 centerprint_AddStandard(argv(1));
358 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
359 case CMD_REQUEST_USAGE:
361 LOG_HELP("Usage:^3 cl_cmd localprint \"message\"");
362 LOG_HELP(" 'message' is the centerprint message to send to yourself.");
368 void LocalCommand_mv_download(int request, int argc)
370 TC(int, request); TC(int, argc);
373 case CMD_REQUEST_COMMAND:
377 Cmd_MapVote_MapDownload(argc);
383 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
384 case CMD_REQUEST_USAGE:
386 LOG_HELP("Usage:^3 cl_cmd mv_download mapid");
387 LOG_HELP(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.");
393 void LocalCommand_sendcvar(int request, int argc)
395 TC(int, request); TC(int, argc);
398 case CMD_REQUEST_COMMAND:
402 // W_FixWeaponOrder will trash argv, so save what we need.
403 string thiscvar = string_null; strcpy(thiscvar, argv(1));
404 string s = cvar_string(thiscvar);
406 if (thiscvar == "cl_weaponpriority")
407 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
408 else if (substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
409 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
411 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
418 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
419 case CMD_REQUEST_USAGE:
421 LOG_HELP("Usage:^3 cl_cmd sendcvar <cvar>");
422 LOG_HELP(" Where 'cvar' is the cvar to send to the server.");
428 /* use this when creating a new command, making sure to place it in alphabetical order... also,
429 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
430 void LocalCommand_(int request)
434 case CMD_REQUEST_COMMAND:
441 case CMD_REQUEST_USAGE:
443 LOG_HELP("Usage:^3 cl_cmd ");
444 LOG_HELP(" No arguments required.");
452 // ==================================
453 // Macro system for client commands
454 // ==================================
456 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
457 CLIENT_COMMAND(blurtest, "Feature for testing blur postprocessing") { LocalCommand_blurtest(request); }
458 CLIENT_COMMAND(boxparticles, "Spawn particles manually") { LocalCommand_boxparticles(request, arguments); }
459 CLIENT_COMMAND(create_scrshot_ent, "Create an entity at this location for automatic screenshots") { LocalCommand_create_scrshot_ent(request); }
460 CLIENT_COMMAND(debugmodel, "Spawn a debug model manually") { LocalCommand_debugmodel(request, arguments); }
461 CLIENT_COMMAND(handlevote, "System to handle selecting a vote or option") { LocalCommand_handlevote(request, arguments); }
462 CLIENT_COMMAND(hud, "Commands regarding/controlling the HUD system") { LocalCommand_hud(request, arguments); }
463 CLIENT_COMMAND(localprint, "Create your own centerprint sent to yourself") { LocalCommand_localprint(request, arguments); }
464 CLIENT_COMMAND(mv_download, "Retrieve mapshot picture from the server") { LocalCommand_mv_download(request, arguments); }
465 CLIENT_COMMAND(sendcvar, "Send a cvar to the server (like cl_weaponpriority)") { LocalCommand_sendcvar(request, arguments); }
467 void LocalCommand_macro_help()
469 FOREACH(CLIENT_COMMANDS, true, LOG_HELPF(" ^2%s^7: %s", it.m_name, it.m_description));
472 bool LocalCommand_macro_command(int argc, string command)
474 string c = strtolower(argv(0));
475 FOREACH(CLIENT_COMMANDS, it.m_name == c, {
476 it.m_invokecmd(it, CMD_REQUEST_COMMAND, NULL, argc, command);
482 bool LocalCommand_macro_usage(int argc)
484 string c = strtolower(argv(1));
485 FOREACH(CLIENT_COMMANDS, it.m_name == c, {
486 it.m_invokecmd(it, CMD_REQUEST_USAGE, NULL, argc, "");
492 void LocalCommand_macro_write_aliases(int fh)
494 FOREACH(CLIENT_COMMANDS, true, CMD_Write_Alias("qc_cmd_cl", it.m_name, it.m_description));
498 // =========================================
499 // Main Function Called By Engine (cl_cmd)
500 // =========================================
501 // If this function exists, client code handles gamecommand instead of the engine code.
503 void GameCommand(string command)
505 int argc = tokenize_console(command);
507 // Guide for working with argc arguments by example:
508 // argc: 1 - 2 - 3 - 4
509 // argv: 0 - 1 - 2 - 3
510 // cmd vote - master - login - password
511 string s = strtolower(argv(0));
516 LOG_HELP("Client console commands:");
517 LocalCommand_macro_help();
519 LOG_HELP("\nGeneric commands shared by all programs:");
520 GenericCommand_macro_help();
522 LOG_HELP("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.");
523 LOG_HELP("For help about a specific command, type cl_cmd help COMMAND");
527 else if (GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
531 else if (LocalCommand_macro_usage(argc)) // now try for normal commands too
536 // continue as usual and scan for normal commands
537 if (GenericCommand(command) // handled by common/command/generic.qc
538 || LocalCommand_macro_command(argc, command) // handled by one of the above LocalCommand_* functions
539 || MUTATOR_CALLHOOK(CSQC_ConsoleCommand, s, argc, command) // handled by a mutator
542 // nothing above caught the command, must be invalid
543 LOG_INFO(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.");
547 // ===================================
548 // Macro system for console commands
549 // ===================================
551 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
552 // Please add client commands to the function above this, as this is only for special reasons.
553 // NOTE: showaccuracy is kept as legacy command
554 #define CONSOLE_COMMANDS_NORMAL() \
555 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = true; }) \
556 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = false; }) \
557 CONSOLE_COMMAND("+showaccuracy", { }) \
558 CONSOLE_COMMAND("-showaccuracy", { }) \
561 #define CONSOLE_COMMANDS_MOVEMENT() \
562 CONSOLE_COMMAND("+forward", { ++camera_direction.x; }) \
563 CONSOLE_COMMAND("-forward", { --camera_direction.x; }) \
564 CONSOLE_COMMAND("+back", { --camera_direction.x; }) \
565 CONSOLE_COMMAND("-back", { ++camera_direction.x; }) \
566 CONSOLE_COMMAND("+moveup", { ++camera_direction.z; }) \
567 CONSOLE_COMMAND("-moveup", { --camera_direction.z; }) \
568 CONSOLE_COMMAND("+movedown", { --camera_direction.z; }) \
569 CONSOLE_COMMAND("-movedown", { ++camera_direction.z; }) \
570 CONSOLE_COMMAND("+moveright", { --camera_direction.y; }) \
571 CONSOLE_COMMAND("-moveright", { ++camera_direction.y; }) \
572 CONSOLE_COMMAND("+moveleft", { ++camera_direction.y; }) \
573 CONSOLE_COMMAND("-moveleft", { --camera_direction.y; }) \
574 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
575 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
576 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
577 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
580 void ConsoleCommand_macro_init()
582 // first init normal commands
583 #define CONSOLE_COMMAND(name, execution) \
584 { registercommand(name); }
586 CONSOLE_COMMANDS_NORMAL();
587 #undef CONSOLE_COMMAND
589 // then init movement commands
594 #define CONSOLE_COMMAND(name, execution) \
595 registercommand(name);
597 CONSOLE_COMMANDS_MOVEMENT();
598 #undef CONSOLE_COMMAND
604 bool ConsoleCommand_macro_normal(string s, int argc)
606 #define CONSOLE_COMMAND(name, execution) \
607 { if (name == s) { { execution } return true; } }
609 CONSOLE_COMMANDS_NORMAL();
610 #undef CONSOLE_COMMAND
615 bool ConsoleCommand_macro_movement(string s, int argc)
619 #define CONSOLE_COMMAND(name, execution) \
620 { if (name == s) { { execution } return true; } }
622 CONSOLE_COMMANDS_MOVEMENT();
623 #undef CONSOLE_COMMAND
630 // ======================================================
631 // Main Function Called By Engine (registered commands)
632 // ======================================================
633 // Used to parse commands in the console that have been registered with the "registercommand" function
635 bool CSQC_ConsoleCommand(string command)
637 int argc = tokenize_console(command);
638 string s = strtolower(argv(0));
639 // Return value should be true if CSQC handled the command, otherwise return false to have the engine handle it.
640 return ConsoleCommand_macro_normal(s, argc)
641 || ConsoleCommand_macro_movement(s, argc)