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>
18 #include "../mapvoting.qh"
19 #include <client/view.qh>
21 #include <client/mutators/_mod.qh>
23 #include <common/minigames/cl_minigames_hud.qh>
25 #include <common/mapinfo.qh>
27 void DrawDebugModel(entity this)
29 if (time - floor(time) > 0.5)
37 this.drawmask = MASK_NORMAL;
42 // =======================
43 // Command Sub-Functions
44 // =======================
46 void LocalCommand_blurtest(int request)
49 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
50 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
55 case CMD_REQUEST_COMMAND:
57 blurtest_time0 = time;
58 blurtest_time1 = time + stof(argv(1));
59 blurtest_radius = stof(argv(2));
60 blurtest_power = stof(argv(3));
61 LOG_INFO("Enabled blurtest");
66 case CMD_REQUEST_USAGE:
68 LOG_HELP("Usage:^3 cl_cmd blurtest");
69 LOG_HELP(" No arguments required.");
76 LOG_INFO("Blurtest is not enabled on this client.");
82 void LocalCommand_boxparticles(int request, int argc)
84 TC(int, request); TC(int, argc);
87 case CMD_REQUEST_COMMAND:
91 int effect = _particleeffectnum(argv(1));
94 int index = stoi(argv(2));
97 own = entitybyindex(-index);
99 own = findfloat(NULL, entnum, index);
100 vector org_from = stov(argv(3));
101 vector org_to = stov(argv(4));
102 vector dir_from = stov(argv(5));
103 vector dir_to = stov(argv(6));
104 int countmultiplier = stoi(argv(7));
105 int flags = stoi(argv(8));
106 boxparticles(effect, own, org_from, org_to, dir_from, dir_to, countmultiplier, flags);
113 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
114 case CMD_REQUEST_USAGE:
117 "Usage:^3 cl_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"
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_HELP("Usage:^3 cl_cmd create_scrshot_ent [path]");
170 LOG_HELP(" 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_HELP("Usage:^3 cl_cmd debugmodel model");
200 LOG_HELP(" 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")); }
244 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
245 case CMD_REQUEST_USAGE:
247 LOG_HELP("Usage:^3 cl_cmd handlevote vote");
248 LOG_HELP(" Where 'vote' is the selection for either the current poll or uid2name.");
254 void LocalCommand_hud(int request, int argc)
256 TC(int, request); TC(int, argc);
259 case CMD_REQUEST_COMMAND:
261 if(MUTATOR_CALLHOOK(HUD_Command, argc))
268 cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
274 if (argv(2) == "help")
276 LOG_HELP(" quickmenu [[default | file | \"\"] submenu file]");
277 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.");
278 LOG_HELP("A submenu name can be given to open the quickmenu directly in a submenu; it requires to specify 'default', 'file' or '\"\"' option.");
279 LOG_HELP("A file name can also be given to open a different quickmenu");
282 string file = ((argv(4) == "") ? autocvar_hud_panel_quickmenu_file : argv(4));
283 if (QuickMenu_IsOpened())
286 QuickMenu_Open(argv(2), argv(3), file); // mode, submenu
294 HUD_Panel_ExportCfg(argv(2));
299 break; // go to usage, we're missing the paramater needed here.
303 case "scoreboard_columns_set":
305 Cmd_Scoreboard_SetFields(argc);
309 case "scoreboard_columns_help":
311 Cmd_Scoreboard_Help();
318 HUD_Radar_Show_Maximized(InterpretBoolean(argv(2)), 0);
320 HUD_Radar_Show_Maximized(!hud_panel_radar_maximized, 0);
327 HUD_Radar_Show_Maximized(!hud_panel_radar_mouse, 1);
334 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
335 case CMD_REQUEST_USAGE:
337 LOG_HELP("Usage:^3 cl_cmd hud action [configname | radartoggle | layout]");
338 LOG_HELP(" Where 'action' is the command to complete,");
339 LOG_HELP(" 'configname' is the name to save to for \"save\" action,");
340 LOG_HELP(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,");
341 LOG_HELP(" and 'layout' is how to organize the scoreboard columns for the set action.");
342 LOG_HELP(" Full list of commands here: \"configure, quickmenu, minigame, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"");
348 void LocalCommand_localprint(int request, int argc)
350 TC(int, request); TC(int, argc);
353 case CMD_REQUEST_COMMAND:
357 centerprint_AddStandard(argv(1));
363 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
364 case CMD_REQUEST_USAGE:
366 LOG_HELP("Usage:^3 cl_cmd localprint \"message\"");
367 LOG_HELP(" 'message' is the centerprint message to send to yourself.");
373 void LocalCommand_mv_download(int request, int argc)
375 TC(int, request); TC(int, argc);
378 case CMD_REQUEST_COMMAND:
382 Cmd_MapVote_MapDownload(argc);
388 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
389 case CMD_REQUEST_USAGE:
391 LOG_HELP("Usage:^3 cl_cmd mv_download mapid");
392 LOG_HELP(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.");
398 void LocalCommand_sendcvar(int request, int argc)
400 TC(int, request); TC(int, argc);
403 case CMD_REQUEST_COMMAND:
407 // W_FixWeaponOrder will trash argv, so save what we need.
408 string thiscvar = string_null; strcpy(thiscvar, argv(1));
409 string s = cvar_string(thiscvar);
411 if (thiscvar == "cl_weaponpriority")
412 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
413 else if (substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
414 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
416 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
423 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
424 case CMD_REQUEST_USAGE:
426 LOG_HELP("Usage:^3 cl_cmd sendcvar <cvar>");
427 LOG_HELP(" Where 'cvar' is the cvar to send to the server.");
433 /* use this when creating a new command, making sure to place it in alphabetical order... also,
434 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
435 void LocalCommand_(int request)
439 case CMD_REQUEST_COMMAND:
446 case CMD_REQUEST_USAGE:
448 LOG_HELP("Usage:^3 cl_cmd ");
449 LOG_HELP(" No arguments required.");
457 // ==================================
458 // Macro system for client commands
459 // ==================================
461 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
462 CLIENT_COMMAND(blurtest, "Feature for testing blur postprocessing") { LocalCommand_blurtest(request); }
463 CLIENT_COMMAND(boxparticles, "Spawn particles manually") { LocalCommand_boxparticles(request, arguments); }
464 CLIENT_COMMAND(create_scrshot_ent, "Create an entity at this location for automatic screenshots") { LocalCommand_create_scrshot_ent(request); }
465 CLIENT_COMMAND(debugmodel, "Spawn a debug model manually") { LocalCommand_debugmodel(request, arguments); }
466 CLIENT_COMMAND(handlevote, "System to handle selecting a vote or option") { LocalCommand_handlevote(request, arguments); }
467 CLIENT_COMMAND(hud, "Commands regarding/controlling the HUD system") { LocalCommand_hud(request, arguments); }
468 CLIENT_COMMAND(localprint, "Create your own centerprint sent to yourself") { LocalCommand_localprint(request, arguments); }
469 CLIENT_COMMAND(mv_download, "Retrieve mapshot picture from the server") { LocalCommand_mv_download(request, arguments); }
470 CLIENT_COMMAND(sendcvar, "Send a cvar to the server (like cl_weaponpriority)") { LocalCommand_sendcvar(request, arguments); }
472 void LocalCommand_macro_help()
474 FOREACH(CLIENT_COMMANDS, true, LOG_HELPF(" ^2%s^7: %s", it.m_name, it.m_description));
477 bool LocalCommand_macro_command(int argc, string command)
479 string c = strtolower(argv(0));
480 FOREACH(CLIENT_COMMANDS, it.m_name == c, {
481 it.m_invokecmd(it, CMD_REQUEST_COMMAND, NULL, argc, command);
487 bool LocalCommand_macro_usage(int argc)
489 string c = strtolower(argv(1));
490 FOREACH(CLIENT_COMMANDS, it.m_name == c, {
491 it.m_invokecmd(it, CMD_REQUEST_USAGE, NULL, argc, "");
497 void LocalCommand_macro_write_aliases(int fh)
499 FOREACH(CLIENT_COMMANDS, true, CMD_Write_Alias("qc_cmd_cl", it.m_name, it.m_description));
503 // =========================================
504 // Main Function Called By Engine (cl_cmd)
505 // =========================================
506 // If this function exists, client code handles gamecommand instead of the engine code.
508 void GameCommand(string command)
510 int argc = tokenize_console(command);
512 // Guide for working with argc arguments by example:
513 // argc: 1 - 2 - 3 - 4
514 // argv: 0 - 1 - 2 - 3
515 // cmd vote - master - login - password
516 string s = strtolower(argv(0));
521 LOG_HELP("Client console commands:");
522 LocalCommand_macro_help();
524 LOG_HELP("\nGeneric commands shared by all programs:");
525 GenericCommand_macro_help();
527 LOG_HELP("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.");
528 LOG_HELP("For help about a specific command, type cl_cmd help COMMAND");
532 else if (GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
536 else if (LocalCommand_macro_usage(argc)) // now try for normal commands too
541 // continue as usual and scan for normal commands
542 if (GenericCommand(command) // handled by common/command/generic.qc
543 || LocalCommand_macro_command(argc, command) // handled by one of the above LocalCommand_* functions
544 || MUTATOR_CALLHOOK(CSQC_ConsoleCommand, s, argc, command) // handled by a mutator
547 // nothing above caught the command, must be invalid
548 LOG_INFO(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.");
552 // ===================================
553 // Macro system for console commands
554 // ===================================
556 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
557 // Please add client commands to the function above this, as this is only for special reasons.
558 // NOTE: showaccuracy is kept as legacy command
559 #define CONSOLE_COMMANDS_NORMAL() \
560 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = true; }) \
561 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = false; }) \
562 CONSOLE_COMMAND("+showaccuracy", { }) \
563 CONSOLE_COMMAND("-showaccuracy", { }) \
566 #define CONSOLE_COMMANDS_MOVEMENT() \
567 CONSOLE_COMMAND("+forward", { ++camera_direction.x; }) \
568 CONSOLE_COMMAND("-forward", { --camera_direction.x; }) \
569 CONSOLE_COMMAND("+back", { --camera_direction.x; }) \
570 CONSOLE_COMMAND("-back", { ++camera_direction.x; }) \
571 CONSOLE_COMMAND("+moveup", { ++camera_direction.z; }) \
572 CONSOLE_COMMAND("-moveup", { --camera_direction.z; }) \
573 CONSOLE_COMMAND("+movedown", { --camera_direction.z; }) \
574 CONSOLE_COMMAND("-movedown", { ++camera_direction.z; }) \
575 CONSOLE_COMMAND("+moveright", { --camera_direction.y; }) \
576 CONSOLE_COMMAND("-moveright", { ++camera_direction.y; }) \
577 CONSOLE_COMMAND("+moveleft", { ++camera_direction.y; }) \
578 CONSOLE_COMMAND("-moveleft", { --camera_direction.y; }) \
579 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
580 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
581 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
582 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
585 void ConsoleCommand_macro_init()
587 // first init normal commands
588 #define CONSOLE_COMMAND(name, execution) \
589 { registercommand(name); }
591 CONSOLE_COMMANDS_NORMAL();
592 #undef CONSOLE_COMMAND
594 // then init movement commands
599 #define CONSOLE_COMMAND(name, execution) \
600 registercommand(name);
602 CONSOLE_COMMANDS_MOVEMENT();
603 #undef CONSOLE_COMMAND
609 bool ConsoleCommand_macro_normal(string s, int argc)
611 #define CONSOLE_COMMAND(name, execution) \
612 { if (name == s) { { execution } return true; } }
614 CONSOLE_COMMANDS_NORMAL();
615 #undef CONSOLE_COMMAND
620 bool ConsoleCommand_macro_movement(string s, int argc)
624 #define CONSOLE_COMMAND(name, execution) \
625 { if (name == s) { { execution } return true; } }
627 CONSOLE_COMMANDS_MOVEMENT();
628 #undef CONSOLE_COMMAND
635 // ======================================================
636 // Main Function Called By Engine (registered commands)
637 // ======================================================
638 // Used to parse commands in the console that have been registered with the "registercommand" function
640 bool CSQC_ConsoleCommand(string command)
642 int argc = tokenize_console(command);
643 string s = strtolower(argv(0));
644 // Return value should be true if CSQC handled the command, otherwise return false to have the engine handle it.
645 return ConsoleCommand_macro_normal(s, argc)
646 || ConsoleCommand_macro_movement(s, argc)