1 // ==============================================
2 // CSQC client commands code, written by Samual
3 // Last updated: December 28th, 2011
4 // ==============================================
6 #include "../../common/command/command.qh"
9 #include "../autocvars.qh"
11 #include "../hud/all.qh"
13 #include "../mapvoting.qh"
14 #include "../miscfunctions.qh"
16 #include "../mutators/events.qh"
18 #include "../../common/mapinfo.qh"
20 #include "../../common/command/generic.qh"
22 void DrawDebugModel(entity this)
24 if (time - floor(time) > 0.5)
32 self.drawmask = MASK_NORMAL;
37 // =======================
38 // Command Sub-Functions
39 // =======================
41 void LocalCommand_blurtest(int request)
43 // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
44 // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
49 case CMD_REQUEST_COMMAND:
51 blurtest_time0 = time;
52 blurtest_time1 = time + stof(argv(1));
53 blurtest_radius = stof(argv(2));
54 blurtest_power = stof(argv(3));
55 LOG_INFO("Enabled blurtest\n");
60 case CMD_REQUEST_USAGE:
62 LOG_INFO("\nUsage:^3 cl_cmd blurtest\n");
63 LOG_INFO(" No arguments required.\n");
70 LOG_INFO("Blurtest is not enabled on this client.\n");
76 void LocalCommand_boxparticles(int request, int argc)
80 case CMD_REQUEST_COMMAND:
84 int effect = _particleeffectnum(argv(1));
87 int index = stoi(argv(2));
90 own = entitybyindex(-index);
92 own = findfloat(world, entnum, index);
93 vector org_from = stov(argv(3));
94 vector org_to = stov(argv(4));
95 vector dir_from = stov(argv(5));
96 vector dir_to = stov(argv(6));
97 int countmultiplier = stoi(argv(7));
98 int flags = stoi(argv(8));
99 boxparticles(effect, own, org_from, org_to, dir_from, dir_to, countmultiplier, flags);
107 LOG_INFO("Incorrect parameters for ^2boxparticles^7\n");
109 case CMD_REQUEST_USAGE:
111 LOG_INFO("\nUsage:^3 lv_cmd boxparticles effectname own org_from org_to, dir_from, dir_to, countmultiplier, flags\n");
112 LOG_INFO(" 'effectname' is the name of a particle effect in effectinfo.txt\n");
113 LOG_INFO(" 'own' is the entity number of the owner (negative for csqc ent, positive for svqc ent)\n");
114 LOG_INFO(" 'org_from' is the starting origin of the box\n");
115 LOG_INFO(" 'org_to' is the ending origin of the box\n");
116 LOG_INFO(" 'dir_from' is the minimum velocity\n");
117 LOG_INFO(" 'dir_to' is the maximum velocity\n");
118 LOG_INFO(" 'countmultiplier' defines a multiplier for the particle count (affects count only, not countabsolute or trailspacing)\n");
119 LOG_INFO(" 'flags' can contain:\n");
120 LOG_INFO(" 1 to respect globals particles_alphamin, particles_alphamax (set right before via prvm_globalset client)\n");
121 LOG_INFO(" 2 to respect globals particles_colormin, particles_colormax (set right before via prvm_globalset client)\n");
122 LOG_INFO(" 4 to respect globals particles_fade (set right before via prvm_globalset client)\n");
123 LOG_INFO(" 128 to draw a trail, not a box\n");
129 void LocalCommand_create_scrshot_ent(int request)
133 case CMD_REQUEST_COMMAND:
135 string filename = strcat(MapInfo_Map_bspname, "_scrshot_ent.txt");
136 int fh = fopen(filename, FILE_WRITE);
141 fputs(fh, strcat("\"classname\" \"info_autoscreenshot\"\n"));
142 fputs(fh, strcat("\"origin\" \"", strcat(ftos(view_origin.x), " ", ftos(view_origin.y), " ", ftos(view_origin.z)), "\"\n"));
143 fputs(fh, strcat("\"angles\" \"", strcat(ftos(view_angles.x), " ", ftos(view_angles.y), " ", ftos(view_angles.z)), "\"\n"));
146 LOG_INFO("Completed screenshot entity dump in ^2data/data/", MapInfo_Map_bspname, "_scrshot_ent.txt^7.\n");
152 LOG_INFO("^1Error: ^7Could not dump to file!\n");
158 case CMD_REQUEST_USAGE:
160 LOG_INFO("\nUsage:^3 cl_cmd create_scrshot_ent\n");
161 LOG_INFO(" No arguments required.\n");
167 void LocalCommand_debugmodel(int request, int argc)
171 case CMD_REQUEST_COMMAND:
173 string modelname = argv(1);
175 entity debugmodel_entity = new(debugmodel);
176 precache_model(modelname);
177 _setmodel(debugmodel_entity, modelname);
178 setorigin(debugmodel_entity, view_origin);
179 debugmodel_entity.angles = view_angles;
180 debugmodel_entity.draw = DrawDebugModel;
186 case CMD_REQUEST_USAGE:
188 LOG_INFO("\nUsage:^3 cl_cmd debugmodel model\n");
189 LOG_INFO(" Where 'model' is a string of the model name to use for the debug model.\n");
195 void LocalCommand_handlevote(int request, int argc)
199 case CMD_REQUEST_COMMAND:
204 if (InterpretBoolean(argv(1)))
217 if (uid2name_dialog) // handled by "uid2name" option
222 localcmd(strcat("setreport cl_allow_uid2name ", ftos(vote_selection - 1), "\n"));
225 else { localcmd(strcat("cmd vote ", vote_string, "\n")); }
233 LOG_INFO("Incorrect parameters for ^2handlevote^7\n");
235 case CMD_REQUEST_USAGE:
237 LOG_INFO("\nUsage:^3 cl_cmd handlevote vote\n");
238 LOG_INFO(" Where 'vote' is the selection for either the current poll or uid2name.\n");
244 bool QuickMenu_IsOpened();
245 void QuickMenu_Close();
246 bool QuickMenu_Open(string mode, string submenu);
248 bool HUD_MinigameMenu_IsOpened();
249 void HUD_MinigameMenu_Close();
250 void HUD_MinigameMenu_Open();
252 void HUD_Radar_Show_Maximized(bool doshow, bool clickable);
254 void LocalCommand_hud(int request, 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_INFO(" quickmenu [[default | file | \"\"] submenu]\n");
276 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.\n");
277 LOG_INFO("A submenu name can be given to open the quickmenu directly in a submenu; it requires to specify 'default', 'file' or '\"\"' option.\n");
280 if (QuickMenu_IsOpened())
283 QuickMenu_Open(argv(2), argv(3)); // mode, submenu
291 HUD_Panel_ExportCfg(argv(2));
296 break; // go to usage, we're missing the paramater needed here.
300 case "scoreboard_columns_set":
302 Cmd_HUD_SetFields(argc);
306 case "scoreboard_columns_help":
315 HUD_Radar_Show_Maximized(InterpretBoolean(argv(2)), 0);
317 HUD_Radar_Show_Maximized(!hud_panel_radar_maximized, 0);
323 HUD_Radar_Show_Maximized(!hud_panel_radar_mouse, 1);
331 LOG_INFO("Incorrect parameters for ^2hud^7\n");
333 case CMD_REQUEST_USAGE:
335 LOG_INFO("\nUsage:^3 cl_cmd hud action [configname | radartoggle | layout]\n");
336 LOG_INFO(" Where 'action' is the command to complete,\n");
337 LOG_INFO(" 'configname' is the name to save to for \"save\" action,\n");
338 LOG_INFO(" 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action,\n");
339 LOG_INFO(" and 'layout' is how to organize the scoreboard columns for the set action.\n");
340 LOG_INFO(" Full list of commands here: \"configure, quickmenu, minigame, save, scoreboard_columns_help, scoreboard_columns_set, radar.\"\n");
346 void LocalCommand_localprint(int request, int argc)
350 case CMD_REQUEST_COMMAND:
354 centerprint_hud(argv(1));
361 LOG_INFO("Incorrect parameters for ^2localprint^7\n");
363 case CMD_REQUEST_USAGE:
365 LOG_INFO("\nUsage:^3 cl_cmd localprint \"message\"\n");
366 LOG_INFO(" 'message' is the centerprint message to send to yourself.\n");
372 void LocalCommand_mv_download(int request, int argc)
376 case CMD_REQUEST_COMMAND:
380 Cmd_MapVote_MapDownload(argc);
387 LOG_INFO("Incorrect parameters for ^2mv_download^7\n");
389 case CMD_REQUEST_USAGE:
391 LOG_INFO("\nUsage:^3 cl_cmd mv_download mapid\n");
392 LOG_INFO(" Where 'mapid' is the id number of the map to request an image of on the map vote selection menu.\n");
398 void LocalCommand_find(int request, int argc)
402 case CMD_REQUEST_COMMAND:
404 FOREACH_ENTITY_CLASS(argv(1), true, LAMBDA(LOG_INFO(etos(it), "\n")));
410 LOG_INFO("Incorrect parameters for ^2find^7\n");
412 case CMD_REQUEST_USAGE:
414 LOG_INFO("\nUsage:^3 cl_cmd find classname\n");
415 LOG_INFO(" Where 'classname' is the classname to search for.\n");
421 void LocalCommand_sendcvar(int request, int argc)
425 case CMD_REQUEST_COMMAND:
429 // W_FixWeaponOrder will trash argv, so save what we need.
430 string thiscvar = strzone(argv(1));
431 string s = cvar_string(thiscvar);
433 if (thiscvar == "cl_weaponpriority")
434 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
435 else if (substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
436 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
438 localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
446 LOG_INFO("Incorrect parameters for ^2sendcvar^7\n");
448 case CMD_REQUEST_USAGE:
450 LOG_INFO("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
451 LOG_INFO(" Where 'cvar' is the cvar plus arguments to send to the server.\n");
457 /* use this when creating a new command, making sure to place it in alphabetical order... also,
458 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
459 void LocalCommand_(int request)
463 case CMD_REQUEST_COMMAND:
470 case CMD_REQUEST_USAGE:
472 print("\nUsage:^3 cl_cmd \n");
473 print(" No arguments required.\n");
481 // ==================================
482 // Macro system for client commands
483 // ==================================
485 // Normally do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
486 CLIENT_COMMAND(blurtest, "Feature for testing blur postprocessing") { LocalCommand_blurtest(request); }
487 CLIENT_COMMAND(boxparticles, "Spawn particles manually") { LocalCommand_boxparticles(request, arguments); }
488 CLIENT_COMMAND(create_scrshot_ent, "Create an entity at this location for automatic screenshots") { LocalCommand_create_scrshot_ent(request); }
489 CLIENT_COMMAND(debugmodel, "Spawn a debug model manually") { LocalCommand_debugmodel(request, arguments); }
490 CLIENT_COMMAND(handlevote, "System to handle selecting a vote or option") { LocalCommand_handlevote(request, arguments); }
491 CLIENT_COMMAND(hud, "Commands regarding/controlling the HUD system") { LocalCommand_hud(request, arguments); }
492 CLIENT_COMMAND(localprint, "Create your own centerprint sent to yourself") { LocalCommand_localprint(request, arguments); }
493 CLIENT_COMMAND(find, "Search through entities for matching classname") { LocalCommand_find(request, arguments); }
494 CLIENT_COMMAND(mv_download, "Retrieve mapshot picture from the server") { LocalCommand_mv_download(request, arguments); }
495 CLIENT_COMMAND(sendcvar, "Send a cvar to the server (like weaponpriority)") { LocalCommand_sendcvar(request, arguments); }
497 void LocalCommand_macro_help()
499 FOREACH(CLIENT_COMMANDS, true, LAMBDA(LOG_INFOF(" ^2%s^7: %s\n", it.m_name, it.m_description)));
502 bool LocalCommand_macro_command(int argc, string command)
504 string c = strtolower(argv(0));
505 FOREACH(CLIENT_COMMANDS, it.m_name == c, LAMBDA(
506 it.m_invokecmd(CMD_REQUEST_COMMAND, NULL, argc, command);
512 bool LocalCommand_macro_usage(int argc)
514 string c = strtolower(argv(1));
515 FOREACH(CLIENT_COMMANDS, it.m_name == c, LAMBDA(
516 it.m_invokecmd(CMD_REQUEST_USAGE, NULL, argc, "");
522 void LocalCommand_macro_write_aliases(int fh)
524 FOREACH(CLIENT_COMMANDS, true, LAMBDA(CMD_Write_Alias("qc_cmd_cl", it.m_name, it.m_description)));
528 // =========================================
529 // Main Function Called By Engine (cl_cmd)
530 // =========================================
531 // If this function exists, client code handles gamecommand instead of the engine code.
533 void GameCommand(string command)
535 int argc = tokenize_console(command);
537 // Guide for working with argc arguments by example:
538 // argc: 1 - 2 - 3 - 4
539 // argv: 0 - 1 - 2 - 3
540 // cmd vote - master - login - password
541 string s = strtolower(argv(0));
546 LOG_INFO("\nClient console commands:\n");
547 LocalCommand_macro_help();
549 LOG_INFO("\nGeneric commands shared by all programs:\n");
550 GenericCommand_macro_help();
552 LOG_INFO("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are listed above.\n");
553 LOG_INFO("For help about a specific command, type cl_cmd help COMMAND\n");
557 else if (GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
561 else if (LocalCommand_macro_usage(argc)) // now try for normal commands too
566 // continue as usual and scan for normal commands
567 if (GenericCommand(command) // handled by common/command/generic.qc
568 || LocalCommand_macro_command(argc, command) // handled by one of the above LocalCommand_* functions
569 || MUTATOR_CALLHOOK(CSQC_ConsoleCommand, s, argc, command) // handled by a mutator
572 // nothing above caught the command, must be invalid
573 LOG_INFO(((command != "") ? strcat("Unknown client command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try cl_cmd help.\n");
577 // ===================================
578 // Macro system for console commands
579 // ===================================
581 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
582 // Please add client commands to the function above this, as this is only for special reasons.
583 #define CONSOLE_COMMANDS_NORMAL() \
584 CONSOLE_COMMAND("+showscores", { scoreboard_showscores = true; }) \
585 CONSOLE_COMMAND("-showscores", { scoreboard_showscores = false; }) \
586 CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = true; }) \
587 CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = false; }) \
590 #define CONSOLE_COMMANDS_MOVEMENT() \
591 CONSOLE_COMMAND("+forward", { ++camera_direction.x; }) \
592 CONSOLE_COMMAND("-forward", { --camera_direction.x; }) \
593 CONSOLE_COMMAND("+back", { --camera_direction.x; }) \
594 CONSOLE_COMMAND("-back", { ++camera_direction.x; }) \
595 CONSOLE_COMMAND("+moveup", { ++camera_direction.z; }) \
596 CONSOLE_COMMAND("-moveup", { --camera_direction.z; }) \
597 CONSOLE_COMMAND("+movedown", { --camera_direction.z; }) \
598 CONSOLE_COMMAND("-movedown", { ++camera_direction.z; }) \
599 CONSOLE_COMMAND("+moveright", { --camera_direction.y; }) \
600 CONSOLE_COMMAND("-moveright", { ++camera_direction.y; }) \
601 CONSOLE_COMMAND("+moveleft", { ++camera_direction.y; }) \
602 CONSOLE_COMMAND("-moveleft", { --camera_direction.y; }) \
603 CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
604 CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
605 CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
606 CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
609 void ConsoleCommand_macro_init()
611 // first init normal commands
612 #define CONSOLE_COMMAND(name, execution) \
613 { registercommand(name); }
615 CONSOLE_COMMANDS_NORMAL();
616 #undef CONSOLE_COMMAND
618 // then init movement commands
623 #define CONSOLE_COMMAND(name, execution) \
624 registercommand(name);
626 CONSOLE_COMMANDS_MOVEMENT();
627 #undef CONSOLE_COMMAND
633 bool ConsoleCommand_macro_normal(string s, int argc)
635 #define CONSOLE_COMMAND(name, execution) \
636 { if (name == s) { { execution } return true; } }
638 CONSOLE_COMMANDS_NORMAL();
639 #undef CONSOLE_COMMAND
644 bool ConsoleCommand_macro_movement(string s, int argc)
648 #define CONSOLE_COMMAND(name, execution) \
649 { if (name == s) { { execution } return true; } }
651 CONSOLE_COMMANDS_MOVEMENT();
652 #undef CONSOLE_COMMAND
659 // ======================================================
660 // Main Function Called By Engine (registered commands)
661 // ======================================================
662 // Used to parse commands in the console that have been registered with the "registercommand" function
664 bool CSQC_ConsoleCommand(string command)
666 int argc = tokenize_console(command);
667 string s = strtolower(argv(0));
668 // Return value should be true if CSQC handled the command, otherwise return false to have the engine handle it.
669 return ConsoleCommand_macro_normal(s, argc)
670 || ConsoleCommand_macro_movement(s, argc)