]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/gamecommand.qc
Delete sendcvar comment
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / gamecommand.qc
1 // ==============================================
2 //  CSQC client commands code, written by Samual
3 //  Last updated: November 8th, 2011
4 // ==============================================
5
6         /*
7         if(cmd == "mv_download") {
8                 Cmd_MapVote_MapDownload(argc);
9         }
10         else if(cmd == "settemp") {
11                 cvar_clientsettemp(argv(1), argv(2));
12         }
13         else if(cmd == "scoreboard_columns_set") {
14                 Cmd_HUD_SetFields(argc);
15         }
16         else if(cmd == "scoreboard_columns_help") {
17                 Cmd_HUD_Help(argc);
18         }
19         else if(cmd == "spawn") {
20                 s = argv(1);
21                 e = spawn();
22                 precache_model(s);
23                 setmodel(e, s);
24                 setorigin(e, view_origin);
25                 e.angles = view_angles;
26                 e.draw = DrawDebugModel;
27                 e.classname = "debugmodel";
28         }
29     else if(cmd == "vyes")
30     {
31         if(uid2name_dialog)
32         {
33             vote_active = 0; // force the panel to disappear right as we have selected the value (to prevent it from fading out in the normal vote panel pos)
34             vote_prev = 0;
35             localcmd("setreport cl_allow_uid2name 1\n");
36             vote_change = -9999;
37                         uid2name_dialog = 0;
38         }
39         else
40         {
41             localcmd("cmd vote yes\n");
42         }
43     }
44     else if(cmd == "vno")
45     {
46         if(uid2name_dialog)
47         {
48             vote_active = 0;
49             vote_prev = 0;
50             localcmd("setreport cl_allow_uid2name 0\n");
51             vote_change = -9999;
52                         uid2name_dialog = 0;
53         }
54         else
55         {
56             localcmd("cmd vote no\n");
57         }
58     }
59         */
60
61
62 #define GC_REQUEST_COMMAND 1
63 #define GC_REQUEST_USAGE 2
64
65 void Cmd_HUD_SetFields(float);
66 void Cmd_HUD_Help(float);
67
68 .vector view_ofs;
69 entity debug_shotorg;
70
71
72 // ============================
73 //  Misc. Supporting Functions
74 // ============================
75
76 void cvar_clientsettemp(string cv, string val)
77 {
78         entity e;
79         for(e = world; (e = find(e, classname, "saved_cvar_value")); )
80                 if(e.netname == cv)
81                         goto saved;
82         e = spawn();
83         e.classname = "saved_cvar_value";
84         e.netname = strzone(cv);
85         e.message = strzone(cvar_string(cv));
86         :saved
87         cvar_set(cv, val);
88 }
89
90 void cvar_clientsettemp_restore()
91 {
92         entity e;
93         for(e = world; (e = find(e, classname, "saved_cvar_value")); )
94                         cvar_set(e.netname, e.message);
95 }
96 void DrawDebugModel()
97 {
98         if(time - floor(time) > 0.5)
99         {
100                 PolyDrawModel(self);
101                 self.drawmask = 0;
102         }
103         else
104         {
105                 self.renderflags = 0;
106                 self.drawmask = MASK_NORMAL;
107         }
108 }
109
110
111 // =======================
112 //  Command Sub-Functions
113 // =======================
114
115 void GameCommand_blurtest(float request)
116 {
117         // Simple command to work with postprocessing temporarily... possibly completely pointless, the glsl shader is used for a real feature now...
118         // Anyway, to enable it, just compile the client with -DBLURTEST and then you can use the command.
119         
120         #ifdef BLURTEST
121         switch(request)
122         {
123                 case GC_REQUEST_COMMAND:
124                 {
125                         blurtest_time0 = time;
126                         blurtest_time1 = time + stof(argv(1));
127                         blurtest_radius = stof(argv(2));
128                         blurtest_power = stof(argv(3));
129                         print("Enabled blurtest\n");
130                         return; 
131                 }
132                         
133                 default:
134                 case GC_REQUEST_USAGE:
135                 {
136                         print("\nUsage:^3 cl_cmd blurtest\n");
137                         print("  No arguments required.\n");
138                         return;
139                 }
140         }
141         #else
142         if(request)
143         {
144                 print("Blurtest is not enabled on this client.\n");
145                 return;
146         }
147         #endif
148 }
149
150 void GameCommand_hud(float request, float argc) // TODO: Add aliases in commands.cfg
151 {
152         switch(request)
153         {
154                 case GC_REQUEST_COMMAND:
155                 {
156                         switch(argv(1))
157                         {
158                                 case "configure":
159                                 {
160                                         cvar_set("_hud_configure", ftos(!autocvar__hud_configure));
161                                         return;
162                                 }
163                                 
164                                 case "save":
165                                 {
166                                         if(argv(2))
167                                         {
168                                                 HUD_Panel_ExportCfg(argv(2));
169                                                 return;
170                                         }
171                                         else
172                                         {
173                                                 break; // go to usage, we're missing the paramater needed here.
174                                         }
175                                 }
176                                 
177                                 case "radar":
178                                 {
179                                         if(argv(2))
180                                                 hud_panel_radar_maximized = (stof(argv(2)) != 0);
181                                         else
182                                                 hud_panel_radar_maximized = !hud_panel_radar_maximized;
183                                         
184                                         return;
185                                 }
186                         }
187                         return; 
188                 }
189                         
190                 default:
191                         print("Incorrect parameters for ^2hud^7\n");
192                 case GC_REQUEST_USAGE:
193                 {
194                         print("\nUsage:^3 cl_cmd hud action [configname | radartoggle]\n");
195                         print("  Where 'action' is the command to complete,\n");
196                         print("  'configname' is the name to save to for \"save\" action,\n");
197                         print("  and 'radartoggle' is what to set hud_panel_radar_maximized to.\n");
198                         print("  Full list of commands here: \"configure, save, radar.\"\n");
199                         return;
200                 }
201         }
202 }
203
204 void GameCommand_sendcvar(float request, float argc) // wtf? why?
205 {
206         switch(request)
207         {
208                 case GC_REQUEST_COMMAND:
209                 {
210                         // W_FixWeaponOrder will trash argv, so save what we need.
211                         string thiscvar = strzone(argv(1));
212                         string s = cvar_string(thiscvar);
213                         
214                         if(thiscvar == "cl_weaponpriority")
215                                 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 1);
216                         else if(substring(thiscvar, 0, 17) == "cl_weaponpriority" && strlen(thiscvar) == 18)
217                                 s = W_FixWeaponOrder(W_NumberWeaponOrder(s), 0);
218                                 
219                         localcmd("cmd sentcvar ", thiscvar, " \"", s, "\"\n");
220                         strunzone(thiscvar);
221                         
222                         return; 
223                 }
224                         
225                 default:
226                 case GC_REQUEST_USAGE:
227                 {
228                         print("\nUsage:^3 cl_cmd sendcvar <cvar>\n");
229                         print("  Where 'cvar' is the cvar plus arguments to send to the server.\n");
230                         return;
231                 }
232         }
233 }
234
235 /* use this when creating a new command, making sure to place it in alphabetical order.
236 void GameCommand_(float request)
237 {
238         switch(request)
239         {
240                 case GC_REQUEST_COMMAND:
241                 {
242                         
243                         return; 
244                 }
245                         
246                 default:
247                 case GC_REQUEST_USAGE:
248                 {
249                         print("\nUsage:^3 cl_cmd \n");
250                         print("  No arguments required.\n");
251                         return;
252                 }
253         }
254 }
255 */
256
257
258 // ==================================
259 //  Macro system for client commands
260 // ==================================
261
262 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
263 #define CLIENT_COMMANDS(request,arguments) \
264         CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
265         CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
266         CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
267         /* nothing */
268         
269 void GameCommand_macro_help()
270 {
271         #define CLIENT_COMMAND(name,function,description) \
272                 { print("  ^2", name, "^7: ", description, "\n"); }
273                 
274         CLIENT_COMMANDS(0, 0)
275         #undef CLIENT_COMMAND
276         
277         return;
278 }
279
280 float GameCommand_macro_command(float argc)
281 {
282         #define CLIENT_COMMAND(name,function,description) \
283                 { if(name == strtolower(argv(0))) { function; return TRUE; } }
284                 
285         CLIENT_COMMANDS(GC_REQUEST_COMMAND, argc)
286         #undef CLIENT_COMMAND
287         
288         return FALSE;
289 }
290
291 float GameCommand_macro_usage(float argc)
292 {
293         #define CLIENT_COMMAND(name,function,description) \
294                 { if(name == strtolower(argv(1))) { function; return TRUE; } }
295                 
296         CLIENT_COMMANDS(GC_REQUEST_USAGE, argc)
297         #undef CLIENT_COMMAND
298         
299         return FALSE;
300 }
301
302
303 // =========================================
304 //  Main Function Called By Engine (cl_cmd)
305 // =========================================
306 // If this function exists, client code handles gamecommand instead of the engine code.
307
308 void GameCommand(string command)
309 {
310         float argc = tokenize_console(command);
311
312         if(strtolower(argv(0)) == "help") 
313         {
314                 if(argc == 1) 
315                 {
316                         print("\nUsage:^3 cl_cmd COMMAND...^7, where possible commands are:\n");
317                         GameCommand_macro_help();
318                         GameCommand_Generic("help");
319                         print("For help about specific commands, type cl_cmd help COMMAND\n");
320                         return;
321                 } 
322                 else if(GameCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it
323                 {
324                         return;
325                 }
326         } 
327         else if(GameCommand_Generic(command)) 
328         {
329                 return; // handled by common/gamecommand.qc
330         }
331         else if(GameCommand_macro_command(argc)) // continue as usual and scan for normal commands
332         {
333                 return; // handled by one of the above GameCommand_* functions
334         }
335         
336         // nothing above caught the command, must be invalid
337         print("Invalid command. For a list of supported commands, try cl_cmd help.\n");
338         
339         return;
340 }
341
342
343 // ===================================
344 //  Macro system for console commands
345 // ===================================
346
347 // These functions are here specifically to add special + - commands to the game, and are not really normal commands.
348 // Please add client commands to the function above this, as this is only for special reasons.
349 #define CONSOLE_COMMANDS_NORMAL \
350         CONSOLE_COMMAND("+showscores", { scoreboard_showscores = TRUE; }) \
351         CONSOLE_COMMAND("-showscores", { scoreboard_showscores = FALSE; }) \
352         CONSOLE_COMMAND("+showaccuracy", { scoreboard_showaccuracy = TRUE; }) \
353         CONSOLE_COMMAND("-showaccuracy", { scoreboard_showaccuracy = FALSE; }) \
354         /* nothing */
355         
356 #define CONSOLE_COMMANDS_MOVEMENT \
357         CONSOLE_COMMAND("+forward", { ++camera_direction_x; }) \
358         CONSOLE_COMMAND("-forward", { --camera_direction_x; }) \
359         CONSOLE_COMMAND("+back", { --camera_direction_x; }) \
360         CONSOLE_COMMAND("-back", { ++camera_direction_x; }) \
361         CONSOLE_COMMAND("+moveup", { ++camera_direction_z; }) \
362         CONSOLE_COMMAND("-moveup", { --camera_direction_z; }) \
363         CONSOLE_COMMAND("+movedown", { --camera_direction_z; }) \
364         CONSOLE_COMMAND("-movedown", { ++camera_direction_z; }) \
365         CONSOLE_COMMAND("+moveright", { --camera_direction_y; }) \
366         CONSOLE_COMMAND("-moveright", { ++camera_direction_y; }) \
367         CONSOLE_COMMAND("+moveleft", { ++camera_direction_y; }) \
368         CONSOLE_COMMAND("-moveleft", { --camera_direction_y; }) \
369         CONSOLE_COMMAND("+roll_right", { ++camera_roll; }) \
370         CONSOLE_COMMAND("-roll_right", { --camera_roll; }) \
371         CONSOLE_COMMAND("+roll_left", { --camera_roll; }) \
372         CONSOLE_COMMAND("-roll_left", { ++camera_roll; }) \
373         /* nothing */
374
375 void ConsoleCommand_macro_init()
376 {
377         // first init normal commands
378         #define CONSOLE_COMMAND(name,execution) \
379                 { registercmd(name); }
380
381         CONSOLE_COMMANDS_NORMAL
382         #undef CONSOLE_COMMAND
383         
384         // then init movement commands
385         #ifndef CAMERATEST
386         if(isdemo())
387         {
388         #endif
389                 #define CONSOLE_COMMAND(name,execution) \
390                         { registercmd(name); }
391
392                 CONSOLE_COMMANDS_MOVEMENT
393                 #undef CONSOLE_COMMAND
394         #ifndef CAMERATEST
395         }
396         #endif
397         
398         return;
399 }
400
401 float ConsoleCommand_macro_normal(float argc)
402 {
403         #define CONSOLE_COMMAND(name,execution) \
404                 { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
405                 
406         CONSOLE_COMMANDS_NORMAL
407         #undef CONSOLE_COMMAND
408         
409         return FALSE;
410 }
411
412 float ConsoleCommand_macro_movement(float argc)
413 {
414         if(camera_active)
415         {
416                 #define CONSOLE_COMMAND(name,execution) \
417                         { if(name == strtolower(argv(0))) { { execution } return TRUE; } }
418
419                 CONSOLE_COMMANDS_MOVEMENT
420                 #undef CONSOLE_COMMAND
421         }
422         
423         return FALSE;
424 }
425
426
427 // ======================================================
428 //  Main Function Called By Engine (registered commands)
429 // ======================================================
430 // Used to parse commands in the console that have been registered with the "registercmd" function
431
432 float CSQC_ConsoleCommand(string command)
433 {
434         float argc = tokenize_console(command);
435
436         if(ConsoleCommand_macro_normal(argc))
437         {
438                 return TRUE;
439         }
440         else if(ConsoleCommand_macro_movement(argc))
441         {
442                 return TRUE;
443         }
444         
445         // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.
446
447         return FALSE;
448 }