From ab9feece49d63372380d0e169cceb2825f3e83e2 Mon Sep 17 00:00:00 2001 From: Samual Date: Wed, 28 Dec 2011 10:45:17 -0500 Subject: [PATCH] Finish writing new generic.qc file -- probably still needs a lot of work, but very very close now --- qcsrc/common/command/generic.qc | 246 ++++++++++++++++++++------------ qcsrc/common/command/rpn.qc | 56 +------- 2 files changed, 154 insertions(+), 148 deletions(-) diff --git a/qcsrc/common/command/generic.qc b/qcsrc/common/command/generic.qc index 85849b329..856f29bc8 100644 --- a/qcsrc/common/command/generic.qc +++ b/qcsrc/common/command/generic.qc @@ -161,6 +161,145 @@ void GenericCommand_addtolist(float request) } } +void GenericCommand_maplist(float request, float argc) +{ + switch(request) + { + case CMD_REQUEST_COMMAND: + { + string tmp_string; + float i; + + switch(argv(1)) + { + case "add": // appends new maps to the maplist + { + if(argc == 3) + { + if (!fexists(strcat("maps/", argv(2), ".bsp"))) + { + print("maplist: ERROR: ", argv(2), " does not exist!\n"); + break; + } + + if(cvar_string("g_maplist") == "") + cvar_set("g_maplist", argv(2)); + else + cvar_set("g_maplist", strcat(argv(2), " ", cvar_string("g_maplist"))); + + return; + } + break; // go to usage + } + + case "remove": // scans maplist and only adds back whatever maps were not provided in argv(2) + { + if(argc == 3) + { + argc = tokenizebyseparator(cvar_string("g_maplist"), " "); + + for(i = 0; i < argc; ++i) + if(argv(i) != argv(2)) + tmp_string = strcat(tmp_string, " ", argv(i)); + + tmp_string = substring(tmp_string, 1, strlen(tmp_string) - 1); + cvar_set("g_maplist", tmp_string); + + return; + } + break; // go to usage + } + + case "shuffle": // randomly shuffle the maplist + { + cvar_set("g_maplist", shufflewords(cvar_string("g_maplist"))); + return; + } + + case "cleanup": // scans maplist and only adds back the ones which are really usable + { + MapInfo_Enumerate(); + MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0); + argc = tokenizebyseparator(cvar_string("g_maplist"), " "); + + for(i = 0; i < argc; ++i) + if(MapInfo_CheckMap(argv(i))) + tmp_string = strcat(tmp_string, " ", argv(i)); + + tmp_string = substring(tmp_string, 1, strlen(tmp_string) - 1); + cvar_set("g_maplist", tmp_string); + + return; + } + + default: break; + } + } + + default: + case CMD_REQUEST_USAGE: + { + print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(caller), " maplist command [map]"))); // todo + print(" No arguments required.\n"); + return; + } + } +} + +void GenericCommand_settemp(float request, float argc) +{ + switch(request) + { + case CMD_REQUEST_COMMAND: + { + if(argc >= 3) + { + if(cvar_settemp(argv(1), argv(2))) + dprint("Creating new settemp tracker for ", argv(1), " and setting it to \"", argv(2), "\" temporarily.\n"); + else + dprint("Already had a tracker for ", argv(1), ", updating it to \"", argv(2), "\".\n"); + + return; + } + } + + default: + print("Incorrect parameters for ^2settemp^7\n"); + case CMD_REQUEST_USAGE: + { + print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(caller), " settemp \"cvar\" \"arguments\"\n")); + print(" Where 'cvar' is the cvar you want to temporarily set with 'arguments'.\n"); + return; + } + } +} + +void GenericCommand_settemp_restore(float request, float argc) +{ + switch(request) + { + case CMD_REQUEST_COMMAND: + { + float i = cvar_settemp_restore(); + + if(i) + dprint("Restored ", ftos(i), " temporary cvar settings to their original values.\n"); + else + dprint("Nothing to restore.\n"); + + return; + } + + default: + case CMD_REQUEST_USAGE: + { + print(strcat("\nUsage:^3 ", GetProgramCommandPrefix(caller), " settemp_restore\n")); + print(" No arguments required.\n"); + return; + } + } +} + /* use this when creating a new command, making sure to place it in alphabetical order... also, ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION! void GenericCommand_(float request) @@ -190,8 +329,11 @@ void GenericCommand_(float request) // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;) #define GENERIC_COMMANDS(request,arguments,command) \ - GENERIC_COMMAND("addtolist", GenericCommand_addtolist(request, arguments), "") \ - GENERIC_COMMAND("", GenericCommand_(request, arguments), "") \ + GENERIC_COMMAND("addtolist", GenericCommand_addtolist(request, arguments), "Add a string to a cvar at the end of a list") \ + GENERIC_COMMAND("maplist", GenericCommand_maplist(request, arguments), "Automatic control of maplist") \ + GENERIC_COMMAND("rpn", GenericCommand_rpn(request, arguments, command), "RPN calculator") \ + GENERIC_COMMAND("settemp", GenericCommand_settemp(request, arguments), "Temporarily set a value to a cvar which is restored later") \ + GENERIC_COMMAND("settemp_restore", GenericCommand_settemp_restore(request, arguments), "Restore all cvars set by settemp command") \ /* nothing */ void GenericCommand_macro_help() @@ -242,66 +384,21 @@ float GenericCommand(string command) // argv: 0 - 1 - 2 - 3 // cmd vote - master - login - password - if(argv(0) == "help") + if(strtolower(argv(0)) == "help") { - print(" maplist add map\n"); - print(" maplist remove map\n"); - print(" maplist shuffle\n"); - print(" maplist cleanup\n"); - print(" maplist maplist\n"); - print(" maplist lsmaps\n"); - print(" maplist lsnewmaps\n"); - print(" addtolist variable addedvalue\n"); - print(" settemp cvar value\n"); - print(" settemp_restore\n"); - return TRUE; - } - - if(argv(0) == "maplist") - { - if(argv(1) == "add" && argc == 3) - { - if (!fexists(strcat("maps/", argv(2), ".bsp"))) - { - print("maplist: ERROR: ", argv(2), " does not exist!\n"); - return TRUE; - } - if(cvar_string("g_maplist") == "") - cvar_set("g_maplist", argv(2)); - else - cvar_set("g_maplist", strcat(argv(2), " ", cvar_string("g_maplist"))); - return TRUE; - } - else if(argv(1) == "remove" && argc == 3) - { - s = argv(2); - n = tokenizebyseparator(cvar_string("g_maplist"), " "); - s2 = ""; - for(i = 0; i < n; ++i) - if(argv(i) != s) - s2 = strcat(s2, " ", argv(i)); - s2 = substring(s2, 1, strlen(s2) - 1); - cvar_set("g_maplist", s2); - return TRUE; - } - else if(argv(1) == "shuffle" && argc == 2) + if(argc == 1) { - cvar_set("g_maplist", shufflewords(cvar_string("g_maplist"))); + GenericCommand_macro_help(); return TRUE; - } - else if(argv(1) == "cleanup") + } + else if(GenericCommand_macro_usage(argc)) // Instead of trying to call a command, we're going to see detailed information about it { - MapInfo_Enumerate(); - MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0); - n = tokenizebyseparator(cvar_string("g_maplist"), " "); - s2 = ""; - for(i = 0; i < n; ++i) - if(MapInfo_CheckMap(argv(i))) - s2 = strcat(s2, " ", argv(i)); - s2 = substring(s2, 1, strlen(s2) - 1); - cvar_set("g_maplist", s2); return TRUE; } + } + else if(GenericCommand_macro_command(argc)) // continue as usual and scan for normal commands + { + return TRUE; // handled by one of the above LocalCommand_* functions } else if(argc >= 3 && argv(0) == "red") { @@ -384,43 +481,6 @@ float GenericCommand(string command) return TRUE; } - else if(argv(0) == "addtolist") { - if(argc >= 2) - { - s = argv(1); - s2 = argv(2); - if(cvar_string(s) == "") - cvar_set(s, s2); - else { - n = tokenizebyseparator(cvar_string(s), " "); - for(i = 0; i < n; ++i) - if(argv(i) == s2) - return TRUE; // already in list - cvar_set(s, strcat(s2, " ", cvar_string(s))); - } - } - return TRUE; - } -#ifdef MENUQC - } else if(argv(0) == "cp") { - if(argc >= 2) - { - s = argv(1); - for(i = 2; i < argc; ++i) - s = strcat(s, " ", argv(i)); - centerprint(unescape(s)); - } - return TRUE; -#endif - } - else if(argv(0) == "settemp") { - cvar_settemp(argv(1), argv(2)); - return TRUE; - } - else if(argv(0) == "settemp_restore") { - cvar_settemp_restore(); - return TRUE; - } return FALSE; } diff --git a/qcsrc/common/command/rpn.qc b/qcsrc/common/command/rpn.qc index 837b99184..a5a68f62f 100644 --- a/qcsrc/common/command/rpn.qc +++ b/qcsrc/common/command/rpn.qc @@ -554,58 +554,4 @@ void GenericCommand_rpn(float request, float argc, string command) return; } } -} - -float GameCommand_Generic(string command) -{ - if(argv(0) == "help") - { - print(" rpn EXPRESSION... - a RPN calculator.\n"); - print(" Operator description (x: string, s: set, f: float):\n"); - print(" x pop -----------------------------> : removes the top\n"); - print(" x dup -----------------------------> x x : duplicates the top\n"); - print(" x x exch --------------------------> x x : swap the top two\n"); - print(" /cvarname load --------------------> x : loads a cvar\n"); - print(" /cvarname x def -------------------> : writes to a cvar\n"); - print(" f f add|sub|mul|div|mod|max|min ---> f : adds/... two numbers\n"); - print(" f f eq|ne|gt|ge|lt|le -------------> f : compares two numbers\n"); - print(" f neg|abs|sgn|rand|floor|ceil------> f : negates/... a number\n"); - print(" f f f bound -----------------------> f : bounds the middle number\n"); - print(" f1 f2 b when ----------------------> f : f1 if b, f2 otherwise\n"); - print(" s s union|intersection|difference -> s : set operations\n"); - print(" s shuffle -------------------------> s : randomly arrange elements\n"); - print(" /key /value put -------------------> : set a database key\n"); - print(" /key get --------------------------> s : get a database value\n"); - print(" x dbpush --------------------------> : pushes the top onto the database\n"); - print(" dbpop|dbget -----------------------> x : removes/reads DB's top\n"); - print(" dblen|dbat ------------------------> f : gets the DB's size/cursor pos\n"); - print(" dbclr -----------------------------> : clear the DB\n"); - print(" s dbsave|dbload--------------------> : save/load the DB to/from a file\n"); - print(" x dbins ---------------------------> : moves the top into the DB\n"); - print(" dbext|dbread ----------------------> x : extract/get from the DB's cursor\n"); - print(" f dbmov|dbgoto --------------------> : move or set the DB's cursor\n"); - print(" s localtime -----------------------> s : formats the current local time\n"); - print(" s gmtime --------------------------> s : formats the current UTC time\n"); - print(" time ------------------------------> f : seconds since VM start\n"); - print(" s /MD4 digest ---------------------> s : MD4 digest\n"); - print(" s /SHA256 digest ------------------> s : SHA256 digest\n"); - print(" s /formatstring sprintf1s ---------> s : sprintf with 1 string (pad, cut)\n"); - print(" Set operations operate on 'such''strings'.\n"); - print(" Unknown tokens insert their cvar value.\n"); - print(" maplist add map\n"); - print(" maplist remove map\n"); - print(" maplist shuffle\n"); - print(" maplist cleanup\n"); - print(" maplist maplist\n"); - print(" maplist lsmaps\n"); - print(" maplist lsnewmaps\n"); - print(" addtolist variable addedvalue\n"); - print(" records\n"); - print(" rankings (map argument optional)\n"); - print(" settemp cvar value\n"); - print(" settemp_restore\n"); - return TRUE; - } - - else if(argv(0) == "rpn") - { \ No newline at end of file +} \ No newline at end of file -- 2.39.2