]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/gamecommand.qc
Merge remote branch 'origin/master' into samual/updatecommands
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / gamecommand.qc
index 65bf3f63ac935a3584b4741bdac28d6de493a345..ab6aa359f7c4ffc3a9fafb698a3bf624ff30f65a 100644 (file)
@@ -1,15 +1,12 @@
 // ==============================================
 //  CSQC client commands code, written by Samual
-//  Last updated: November 8th, 2011
+//  Last updated: November 26th, 2011
 // ==============================================
 
        /*
        if(cmd == "mv_download") {
                Cmd_MapVote_MapDownload(argc);
        }
-       else if(cmd == "settemp") {
-               cvar_clientsettemp(argv(1), argv(2));
-       }
        else if(cmd == "scoreboard_columns_set") {
                Cmd_HUD_SetFields(argc);
        }
@@ -73,26 +70,38 @@ entity debug_shotorg;
 //  Misc. Supporting Functions
 // ============================
 
-void cvar_clientsettemp(string cv, string val)
+float cvar_clientsettemp(string tmp_cvar, string value)
 {
        entity e;
+       
        for(e = world; (e = find(e, classname, "saved_cvar_value")); )
-               if(e.netname == cv)
+               if(e.netname == tmp_cvar)
                        goto saved;
+                       
+       // creating a new entity to keep track of this cvar
        e = spawn();
        e.classname = "saved_cvar_value";
-       e.netname = strzone(cv);
-       e.message = strzone(cvar_string(cv));
+       e.netname = strzone(tmp_cvar);
+       e.message = strzone(cvar_string(tmp_cvar));
+       return TRUE;
+       
+       // an entity for this cvar already exists, update the value
        :saved
-       cvar_set(cv, val);
+       cvar_set(tmp_cvar, value);
+       return FALSE;
 }
 
-void cvar_clientsettemp_restore()
+float cvar_clientsettemp_restore()
 {
+       float i;
        entity e;
+       
        for(e = world; (e = find(e, classname, "saved_cvar_value")); )
-                       cvar_set(e.netname, e.message);
+               { cvar_set(e.netname, e.message); ++i; } 
+               
+       return i;
 }
+
 void DrawDebugModel()
 {
        if(time - floor(time) > 0.5)
@@ -183,6 +192,20 @@ void GameCommand_hud(float request, float argc) // TODO: Add aliases in commands
                                        
                                        return;
                                }
+                               
+                               case "scoreboard_columns_set":
+                               {
+                                       Cmd_HUD_SetFields(argc); // todo update this function
+                                       
+                                       return;
+                               }
+
+                               case "scoreboard_columns_help":
+                               {
+                                       Cmd_HUD_Help(argc); // todo update this function
+                                       
+                                       return;
+                               }
                        }
                        return; 
                }
@@ -194,14 +217,14 @@ void GameCommand_hud(float request, float argc) // TODO: Add aliases in commands
                        print("\nUsage:^3 cl_cmd hud action [configname | radartoggle]\n");
                        print("  Where 'action' is the command to complete,\n");
                        print("  'configname' is the name to save to for \"save\" action,\n");
-                       print("  and 'radartoggle' is what to set hud_panel_radar_maximized to.\n");
+                       print("  and 'radartoggle' is to control hud_panel_radar_maximized for \"radar\" action.\n");
                        print("  Full list of commands here: \"configure, save, radar.\"\n");
                        return;
                }
        }
 }
 
-void GameCommand_sendcvar(float request, float argc) // wtf? why?
+void GameCommand_sendcvar(float request, float argc)
 {
        switch(request)
        {
@@ -232,6 +255,43 @@ void GameCommand_sendcvar(float request, float argc) // wtf? why?
        }
 }
 
+void GameCommand_settemp(float request, float argc)
+{
+       switch(request)
+       {
+               case GC_REQUEST_COMMAND:
+               {
+                       if((argv(1) == "restore") && (argc == 3))
+                       {
+                               float i = cvar_clientsettemp_restore();
+                               
+                               if(i)
+                                       print("Restored ", ftos(i), " temporary cvar settings to their original values.\n");
+                               else
+                                       print("Nothing to restore.\n");
+                       }
+                       else
+                       {
+                               if(cvar_clientsettemp(argv(1), argv(2)))
+                                       print("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n"); 
+                               else
+                                       print("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n");
+                       }
+                               
+                       return; 
+               }
+                       
+               default:
+               case GC_REQUEST_USAGE:
+               {
+                       print("\nUsage:^3 cl_cmd settemp <cvar> | [restore]\n");
+                       print("  Where 'cvar' is the cvar plus arguments to send to the server,\n");
+                       print("  or 'restore' allows you to restore all of the original temporary cvar values.\n");
+                       return;
+               }
+       }
+}
+
 /* use this when creating a new command, making sure to place it in alphabetical order.
 void GameCommand_(float request)
 {
@@ -264,6 +324,7 @@ void GameCommand_(float request)
        CLIENT_COMMAND("blurtest", GameCommand_blurtest(request), "Feature for testing blur postprocessing") \
        CLIENT_COMMAND("hud", GameCommand_hud(request, arguments), "Commands regarding/controlling the HUD system") \
        CLIENT_COMMAND("sendcvar", GameCommand_sendcvar(request, arguments), "Send a cvar to the server (like weaponpriority)") \
+       CLIENT_COMMAND("settemp", GameCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored by command or end of each match") \
        /* nothing */
        
 void GameCommand_macro_help()
@@ -334,7 +395,7 @@ void GameCommand(string command)
        }
        
        // nothing above caught the command, must be invalid
-       print("Invalid command", (command ? strcat(" '", command, "'") : ""), ". For a list of supported commands, try cl_cmd help.\n");
+       print("Unknown client command", ((command != "") ? strcat(" \"", command, "\"") : ""), ". For a list of supported commands, try cl_cmd help.\n");
        
        return;
 }
@@ -376,7 +437,7 @@ void ConsoleCommand_macro_init()
 {
        // first init normal commands
        #define CONSOLE_COMMAND(name,execution) \
-               { registercmd(name); }
+               { registercommand(name); }
 
        CONSOLE_COMMANDS_NORMAL
        #undef CONSOLE_COMMAND
@@ -387,7 +448,7 @@ void ConsoleCommand_macro_init()
        {
        #endif
                #define CONSOLE_COMMAND(name,execution) \
-                       { registercmd(name); }
+                       { registercommand(name); }
 
                CONSOLE_COMMANDS_MOVEMENT
                #undef CONSOLE_COMMAND
@@ -427,7 +488,7 @@ float ConsoleCommand_macro_movement(float argc)
 // ======================================================
 //  Main Function Called By Engine (registered commands)
 // ======================================================
-// Used to parse commands in the console that have been registered with the "registercmd" function
+// Used to parse commands in the console that have been registered with the "registercommand" function
 
 float CSQC_ConsoleCommand(string command)
 {