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"
11 #include <client/draw.qh>
12 #include <client/hud/_mod.qh>
13 #include <client/hud/panel/quickmenu.qh>
14 #include <client/hud/panel/radar.qh>
15 #include <client/hud/panel/scoreboard.qh>
16 #include <client/hud/panel/vote.qh>
17 #include "../mapvoting.qh"
18 #include <client/view.qh>
20 #include <client/mutators/_mod.qh>
22 #include <common/minigames/cl_minigames_hud.qh>
24 #include <common/mapinfo.qh>
26 void DrawDebugModel(entity this)
28 if (time - floor(time) > 0.5)
36 this.drawmask = MASK_NORMAL;
41 // =======================
42 // Command Sub-Functions
43 // =======================
45 void LocalCommand_blurtest(int request)
48 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
49 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
54 case CMD_REQUEST_COMMAND:
56 blurtest_time0 = time;
57 blurtest_time1 = time + stof(argv(1));
58 blurtest_radius = stof(argv(2));
59 blurtest_power = stof(argv(3));
60 LOG_INFO("Enabled blurtest");
65 case CMD_REQUEST_USAGE:
67 LOG_HELP("Usage:^3 cl_cmd blurtest");
68 LOG_HELP(" No arguments required.");
75 LOG_INFO("Blurtest is not enabled on this client.");
81 void LocalCommand_boxparticles(int request, int argc)
83 TC(int, request); TC(int, argc);
86 case CMD_REQUEST_COMMAND:
90 int effect = _particleeffectnum(argv(1));
93 int index = stoi(argv(2));
96 own = entitybyindex(-index);
98 own = findfloat(NULL, entnum, index);
99 vector org_from = stov(argv(3));
100 vector org_to = stov(argv(4));
101 vector dir_from = stov(argv(5));
102 vector dir_to = stov(argv(6));
103 int countmultiplier = stoi(argv(7));
104 int flags = stoi(argv(8));
105 boxparticles(effect, own, org_from, org_to, dir_from, dir_to, countmultiplier, flags);
112 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
113 case CMD_REQUEST_USAGE:
116 "Usage:^3 cl_cmd boxparticles effectname own org_from org_to, dir_from, dir_to, countmultiplier, flags\n"
117 " 'effectname' is the name of a particle effect in effectinfo.txt\n"
118 " 'own' is the entity number of the owner (negative for csqc ent, positive for svqc ent)\n"
119 " 'org_from' is the starting origin of the box\n"
120 " 'org_to' is the ending origin of the box\n"
121 " 'dir_from' is the minimum velocity\n"
122 " 'dir_to' is the maximum velocity\n"
123 " 'countmultiplier' defines a multiplier for the particle count (affects count only, not countabsolute or trailspacing)\n"
124 " 'flags' can contain:\n"
125 " 1 to respect globals particles_alphamin, particles_alphamax (set right before via prvm_globalset client)\n"
126 " 2 to respect globals particles_colormin, particles_colormax (set right before via prvm_globalset client)\n"
127 " 4 to respect globals particles_fade (set right before via prvm_globalset client)\n"
128 " 128 to draw a trail, not a box"
135 void LocalCommand_create_scrshot_ent(int request)
140 case CMD_REQUEST_COMMAND:
142 string path = ((argv(1) == "") ? "" : strcat(argv(1), "/"));
143 string filename = strcat(path, MapInfo_Map_bspname, "_scrshot_ent.txt");
144 int fh = fopen(filename, FILE_APPEND);
149 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
150 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin.x), " ", ftos(view_origin.y), " ", ftos(view_origin.z)), "\"\n"));
151 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles.x), " ", ftos(view_angles.y), " ", ftos(view_angles.z)), "\"\n"));
154 LOG_INFO("Completed screenshot entity dump in ^2data/data/", path, MapInfo_Map_bspname, "_scrshot_ent.txt^7.");
160 LOG_INFO("^1Error: ^7Could not dump to file!");
166 case CMD_REQUEST_USAGE:
168 LOG_HELP("Usage:^3 cl_cmd create_scrshot_ent [path]");
169 LOG_HELP(" Where 'path' can be the subdirectory of data/data in which the file is saved.");
175 void LocalCommand_debugmodel(int request, int argc)
177 TC(int, request); TC(int, argc);
180 case CMD_REQUEST_COMMAND:
182 string modelname = argv(1);
184 entity debugmodel_entity = new(debugmodel);
185 precache_model(modelname);
186 _setmodel(debugmodel_entity, modelname);
187 setorigin(debugmodel_entity, view_origin);
188 debugmodel_entity.angles = view_angles;
189 debugmodel_entity.draw = DrawDebugModel;
190 IL_PUSH(g_drawables, debugmodel_entity);
196 case CMD_REQUEST_USAGE:
198 LOG_HELP("Usage:^3 cl_cmd debugmodel model");
199 LOG_HELP(" Where 'model' is a string of the model name to use for the debug model.");
205 void LocalCommand_handlevote(int request, int argc)
207 TC(int, request); TC(int, argc);
210 case CMD_REQUEST_COMMAND:
215 if (InterpretBoolean(argv(1)))
228 if (uid2name_dialog) // handled by "uid2name" option
233 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
236 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
243 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
244 case CMD_REQUEST_USAGE:
246 LOG_HELP("Usage:^3 cl_cmd handlevote vote");
247 LOG_HELP(" Where 'vote' is the selection for either the current poll or uid2name.");
253 void LocalCommand_hud(int request, int argc)
255 TC(int, request); TC(int, argc);
258 case CMD_REQUEST_COMMAND:
260 if(MUTATOR_CALLHOOK(HUD_Command, argc))
267 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
273 if (argv(2) == "help")
275 LOG_HELP(" quickmenu [[default | file | \"\"] submenu file]");
276 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.");
277 LOG_HELP("A submenu name can be given to open the quickmenu directly in a submenu; it requires to specify 'default', 'file' or '\"\"' option.");
278 LOG_HELP("A file name can also be given to open a different quickmenu");
281 string file = ((argv(4) == "") ? autocvar_hud_panel_quickmenu_file : argv(4));
282 if (QuickMenu_IsOpened())
285 QuickMenu_Open(argv(2), argv(3), file); // mode, submenu
293 HUD_Panel_ExportCfg(argv(2));
298 break; // go to usage, we're missing the paramater needed here.
302 case "scoreboard_columns_set":
304 Cmd_Scoreboard_SetFields(argc);
308 case "scoreboard_columns_help":
310 Cmd_Scoreboard_Help();
317 HUD_Radar_Show_Maximized(InterpretBoolean(argv(2)), 0);
319 HUD_Radar_Show_Maximized(!hud_panel_radar_maximized, 0);
326 HUD_Radar_Show_Maximized(!hud_panel_radar_mouse, 1);
333 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
334 case CMD_REQUEST_USAGE:
336 LOG_HELP("Usage:^3 cl_cmd hud action [configname | radartoggle | layout]");
337 LOG_HELP(" Where 'action' is the command to complete,");
338 LOG_HELP(" 'configname' is the name to save to for \"save\" action,");
339 LOG_HELP(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,");
340 LOG_HELP(" and 'layout' is how to organize the scoreboard columns for the set action.");
341 LOG_HELP(" Full list of commands here: \"configure, quickmenu, minigame, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"");
347 void LocalCommand_localprint(int request, int argc)
349 TC(int, request); TC(int, argc);
352 case CMD_REQUEST_COMMAND:
356 centerprint_AddStandard(argv(1));
362 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
363 case CMD_REQUEST_USAGE:
365 LOG_HELP("Usage:^3 cl_cmd localprint \"message\"");
366 LOG_HELP(" 'message' is the centerprint message to send to yourself.");
372 void LocalCommand_mv_download(int request, int argc)
374 TC(int, request); TC(int, argc);
377 case CMD_REQUEST_COMMAND:
381 Cmd_MapVote_MapDownload(argc);
387 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
388 case CMD_REQUEST_USAGE:
390 LOG_HELP("Usage:^3 cl_cmd mv_download mapid");
391 LOG_HELP(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.");
397 void LocalCommand_sendcvar(int request, int argc)
399 TC(int, request); TC(int, argc);
402 case CMD_REQUEST_COMMAND:
406 // W_FixWeaponOrder will trash argv, so save what we need.
407 string thiscvar = string_null; strcpy(thiscvar, argv(1));
408 string s = cvar_string(thiscvar);
410 if (thiscvar == "cl_weaponpriority")
411 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
412 else if (substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
413 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
415 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
422 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
423 case CMD_REQUEST_USAGE:
425 LOG_HELP("Usage:^3 cl_cmd sendcvar <cvar>");
426 LOG_HELP(" Where 'cvar' is the cvar to send to the server.");
432 /* use this when creating a new command, making sure to place it in alphabetical order... also,
433 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
434 void LocalCommand_(int request)
438 case CMD_REQUEST_COMMAND:
445 case CMD_REQUEST_USAGE:
447 LOG_HELP("Usage:^3 cl_cmd ");
448 LOG_HELP(" No arguments required.");
456 // ==================================
457 // Macro system for client commands
458 // ==================================
460 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
461 CLIENT_COMMAND(blurtest, "Feature for testing blur postprocessing") { LocalCommand_blurtest(request); }
462 CLIENT_COMMAND(boxparticles, "Spawn particles manually") { LocalCommand_boxparticles(request, arguments); }
463 CLIENT_COMMAND(create_scrshot_ent, "Create an entity at this location for automatic screenshots") { LocalCommand_create_scrshot_ent(request); }
464 CLIENT_COMMAND(debugmodel, "Spawn a debug model manually") { LocalCommand_debugmodel(request, arguments); }
465 CLIENT_COMMAND(handlevote, "System to handle selecting a vote or option") { LocalCommand_handlevote(request, arguments); }
466 CLIENT_COMMAND(hud, "Commands regarding/controlling the HUD system") { LocalCommand_hud(request, arguments); }
467 CLIENT_COMMAND(localprint, "Create your own centerprint sent to yourself") { LocalCommand_localprint(request, arguments); }
468 CLIENT_COMMAND(mv_download, "Retrieve mapshot picture from the server") { LocalCommand_mv_download(request, arguments); }
469 CLIENT_COMMAND(sendcvar, "Send a cvar to the server (like cl_weaponpriority)") { LocalCommand_sendcvar(request, arguments); }
471 void LocalCommand_macro_help()
473 FOREACH(CLIENT_COMMANDS, true, LOG_HELPF(" ^2%s^7: %s", it.m_name, it.m_description));
476 bool LocalCommand_macro_command(int argc, string command)
478 string c = strtolower(argv(0));
479 FOREACH(CLIENT_COMMANDS, it.m_name == c, {
480 it.m_invokecmd(it, CMD_REQUEST_COMMAND, NULL, argc, command);
486 bool LocalCommand_macro_usage(int argc)
488 string c = strtolower(argv(1));
489 FOREACH(CLIENT_COMMANDS, it.m_name == c, {
490 it.m_invokecmd(it, CMD_REQUEST_USAGE, NULL, argc, "");
496 void LocalCommand_macro_write_aliases(int fh)
498 FOREACH(CLIENT_COMMANDS, true, CMD_Write_Alias("qc_cmd_cl", it.m_name, it.m_description));
502 // =========================================
503 // Main Function Called By Engine (cl_cmd)
504 // =========================================
505 // If this function exists, client code handles gamecommand instead of the engine code.
507 void GameCommand(string command)
509 int argc = tokenize_console(command);
511 // Guide for working with argc arguments by example:
512 // argc: 1 - 2 - 3 - 4
513 // argv: 0 - 1 - 2 - 3
514 // cmd vote - master - login - password
515 string s = strtolower(argv(0));
520 LOG_HELP("Client console commands:");
521 LocalCommand_macro_help();
523 LOG_HELP("\nGeneric commands shared by all programs:");
524 GenericCommand_macro_help();
526 LOG_HELP("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.");
527 LOG_HELP("For help about a specific command, type cl_cmd help COMMAND");
531 else if (GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
535 else if (LocalCommand_macro_usage(argc)) // now try for normal commands too
540 // continue as usual and scan for normal commands
541 if (GenericCommand(command) // handled by common/command/generic.qc
542 || LocalCommand_macro_command(argc, command) // handled by one of the above LocalCommand_* functions
543 || MUTATOR_CALLHOOK(CSQC_ConsoleCommand, s, argc, command) // handled by a mutator
546 // nothing above caught the command, must be invalid
547 LOG_INFO(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.");
551 // ===================================
552 // Macro system for console commands
553 // ===================================
555 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
556 // Please add client commands to the function above this, as this is only for special reasons.
557 // NOTE: showaccuracy is kept as legacy command
558 #define CONSOLE_COMMANDS_NORMAL() \
559 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = true; }) \
560 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = false; }) \
561 CONSOLE_COMMAND("+showaccuracy", { }) \
562 CONSOLE_COMMAND("-showaccuracy", { }) \
565 #define CONSOLE_COMMANDS_MOVEMENT() \
566 CONSOLE_COMMAND("+forward", { ++camera_direction.x; }) \
567 CONSOLE_COMMAND("-forward", { --camera_direction.x; }) \
568 CONSOLE_COMMAND("+back", { --camera_direction.x; }) \
569 CONSOLE_COMMAND("-back", { ++camera_direction.x; }) \
570 CONSOLE_COMMAND("+moveup", { ++camera_direction.z; }) \
571 CONSOLE_COMMAND("-moveup", { --camera_direction.z; }) \
572 CONSOLE_COMMAND("+movedown", { --camera_direction.z; }) \
573 CONSOLE_COMMAND("-movedown", { ++camera_direction.z; }) \
574 CONSOLE_COMMAND("+moveright", { --camera_direction.y; }) \
575 CONSOLE_COMMAND("-moveright", { ++camera_direction.y; }) \
576 CONSOLE_COMMAND("+moveleft", { ++camera_direction.y; }) \
577 CONSOLE_COMMAND("-moveleft", { --camera_direction.y; }) \
578 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
579 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
580 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
581 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
584 void ConsoleCommand_macro_init()
586 // first init normal commands
587 #define CONSOLE_COMMAND(name, execution) \
588 { registercommand(name); }
590 CONSOLE_COMMANDS_NORMAL();
591 #undef CONSOLE_COMMAND
593 // then init movement commands
598 #define CONSOLE_COMMAND(name, execution) \
599 registercommand(name);
601 CONSOLE_COMMANDS_MOVEMENT();
602 #undef CONSOLE_COMMAND
608 bool ConsoleCommand_macro_normal(string s, int argc)
610 #define CONSOLE_COMMAND(name, execution) \
611 { if (name == s) { { execution } return true; } }
613 CONSOLE_COMMANDS_NORMAL();
614 #undef CONSOLE_COMMAND
619 bool ConsoleCommand_macro_movement(string s, int argc)
623 #define CONSOLE_COMMAND(name, execution) \
624 { if (name == s) { { execution } return true; } }
626 CONSOLE_COMMANDS_MOVEMENT();
627 #undef CONSOLE_COMMAND
634 // ======================================================
635 // Main Function Called By Engine (registered commands)
636 // ======================================================
637 // Used to parse commands in the console that have been registered with the "registercommand" function
639 bool CSQC_ConsoleCommand(string command)
641 int argc = tokenize_console(command);
642 string s = strtolower(argv(0));
643 // Return value should be true if CSQC handled the command, otherwise return false to have the engine handle it.
644 return ConsoleCommand_macro_normal(s, argc)
645 || ConsoleCommand_macro_movement(s, argc)