From: TimePath Date: Fri, 9 Oct 2015 11:33:48 +0000 (+1100) Subject: Commands: move dump commands to their respective systems X-Git-Tag: xonotic-v0.8.2~1839^2~6 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=14a31565a2bc3c9a8871e6b3e768c68f7e58eda5;p=xonotic%2Fxonotic-data.pk3dir.git Commands: move dump commands to their respective systems --- diff --git a/qcsrc/common/command/all.qh b/qcsrc/common/command/all.qh index 253dc857b..756b36d59 100644 --- a/qcsrc/common/command/all.qh +++ b/qcsrc/common/command/all.qh @@ -14,6 +14,10 @@ REGISTRY_SORT(GENERIC_COMMANDS, m_name, 0) REGISTER(RegisterGENERIC_COMMANDS, CMD_G, GENERIC_COMMANDS, id, m_id, NEW(genericcommand_##id)); \ METHOD(genericcommand_##id, m_invokecmd, void(int request, int arguments, string command)) +STATIC_INIT(GENERIC_COMMANDS_aliases) { + FOREACH(GENERIC_COMMANDS, true, LAMBDA(localcmd(sprintf("alias %1$s \"%2$s %1$s ${* ?}\"\n", it.m_name, "qc_cmd_svmenu")))); +} + #include "generic.qh" #include "markup.qh" #include "rpn.qh" diff --git a/qcsrc/common/command/generic.qc b/qcsrc/common/command/generic.qc index 0c6380cfa..6649950dd 100644 --- a/qcsrc/common/command/generic.qc +++ b/qcsrc/common/command/generic.qc @@ -184,7 +184,7 @@ void GenericCommand_qc_curl(float request, float argc) } } -void GenericCommand_dumpcommands(float request) +GENERIC_COMMAND(dumpcommands, "Dump all commands on the program to *_cmd_dump.txt") { switch(request) { @@ -239,224 +239,6 @@ void GenericCommand_dumpcommands(float request) } } -#ifndef MENUQC -void effectinfo_dump(int fh, bool alsoprint); -#endif -void GenericCommand_dumpeffectinfo(float request) -{ - switch (request) { - case CMD_REQUEST_COMMAND: { - #ifndef MENUQC - string filename = argv(1); - bool alsoprint = false; - if (filename == "") { - filename = "effectinfo_dump.txt"; - alsoprint = false; - } else if (filename == "-") { - filename = "effectinfo_dump.txt"; - alsoprint = true; - } - int fh = fopen(filename, FILE_WRITE); - if (fh >= 0) { - effectinfo_dump(fh, alsoprint); - LOG_INFOF("Dumping effectinfo... File located at ^2data/data/%s^7.\n", filename); - LOG_INFOF("Reload with ^2cl_particles_reloadeffects data/%s^7.\n", filename); - fclose(fh); - } else { - LOG_WARNINGF("Could not open file '%s'!\n", filename); - } - #else - LOG_INFO(_("Effectinfo dump command only works with cl_cmd and sv_cmd.\n")); - #endif - return; - } - default: - case CMD_REQUEST_USAGE: { - LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpeffectinfo [filename]")); - LOG_INFO(" Where 'filename' is the file to write (default is effectinfo_dump.txt),\n"); - LOG_INFO(" if supplied with '-' output to console as well as default,\n"); - LOG_INFO(" if left blank, it will only write to default.\n"); - return; - } - } -} -STATIC_INIT(dumpeffectinfo) { localcmd("alias dumpeffectinfo \"qc_cmd_svcl dumpeffectinfo ${* ?}\"\n"); } - -void GenericCommand_dumpitems(float request) -{ - switch(request) - { - case CMD_REQUEST_COMMAND: - { - Dump_Items(); - return; - } - - default: - case CMD_REQUEST_USAGE: - { - LOG_INFOF("\nUsage:^3 %s dumpitems", GetProgramCommandPrefix()); - return; - } - } -} - -void GenericCommand_dumpnotifs(float request) -{ - switch(request) - { - case CMD_REQUEST_COMMAND: - { - #ifndef MENUQC - float fh, alsoprint = false; - string filename = argv(1); - - if(filename == "") - { - filename = "notifications_dump.cfg"; - alsoprint = false; - } - else if(filename == "-") - { - filename = "notifications_dump.cfg"; - alsoprint = true; - } - fh = fopen(filename, FILE_WRITE); - - if(fh >= 0) - { - Dump_Notifications(fh, alsoprint); - LOG_INFOF("Dumping notifications... File located in ^2data/data/%s^7.\n", filename); - fclose(fh); - } - else - { - LOG_INFOF("^1Error: ^7Could not open file '%s'!\n", filename); - } - #else - LOG_INFO(_("Notification dump command only works with cl_cmd and sv_cmd.\n")); - #endif - return; - } - - default: - case CMD_REQUEST_USAGE: - { - LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpnotifs [filename]")); - LOG_INFO(" Where 'filename' is the file to write (default is notifications_dump.cfg),\n"); - LOG_INFO(" if supplied with '-' output to console as well as default,\n"); - LOG_INFO(" if left blank, it will only write to default.\n"); - return; - } - } -} - -void GenericCommand_dumpweapons(float request) // WEAPONTODO: make this work with other progs than just server -{ - switch(request) - { - case CMD_REQUEST_COMMAND: - { - #ifdef SVQC - wep_config_file = -1; - wep_config_alsoprint = -1; - string filename = argv(1); - - if(filename == "") - { - filename = "weapons_dump.cfg"; - wep_config_alsoprint = false; - } - else if(filename == "-") - { - filename = "weapons_dump.cfg"; - wep_config_alsoprint = true; - } - wep_config_file = fopen(filename, FILE_WRITE); - - if(wep_config_file >= 0) - { - Dump_Weapon_Settings(); - LOG_INFO(sprintf("Dumping weapons... File located in ^2data/data/%s^7.\n", filename)); - fclose(wep_config_file); - wep_config_file = -1; - wep_config_alsoprint = -1; - } - else - { - LOG_INFO(sprintf("^1Error: ^7Could not open file '%s'!\n", filename)); - } - #else - LOG_INFO(_("Weapons dump command only works with sv_cmd.\n")); - #endif - return; - } - - default: - case CMD_REQUEST_USAGE: - { - LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpweapons [filename]")); - LOG_INFO(" Where 'filename' is the file to write (default is weapons_dump.cfg),\n"); - LOG_INFO(" if supplied with '-' output to console as well as default,\n"); - LOG_INFO(" if left blank, it will only write to default.\n"); - return; - } - } -} - -void GenericCommand_dumpturrets(float request) -{ - switch(request) - { - case CMD_REQUEST_COMMAND: - { - #ifdef SVQC - tur_config_file = -1; - tur_config_alsoprint = -1; - string filename = argv(1); - - if(filename == "") - { - filename = "turrets_dump.cfg"; - tur_config_alsoprint = FALSE; - } - else if(filename == "-") - { - filename = "turrets_dump.cfg"; - tur_config_alsoprint = TRUE; - } - tur_config_file = fopen(filename, FILE_WRITE); - - if(tur_config_file >= 0) - { - Dump_Turret_Settings(); - LOG_INFO(sprintf("Dumping turrets... File located in ^2data/data/%s^7.\n", filename)); - fclose(tur_config_file); - tur_config_file = -1; - tur_config_alsoprint = -1; - } - else - { - LOG_INFO(sprintf("^1Error: ^7Could not open file '%s'!\n", filename)); - } - #else - LOG_INFO(_("Turrets dump command only works with sv_cmd.\n")); - #endif - return; - } - - default: - case CMD_REQUEST_USAGE: - { - LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpturrets [filename]")); - LOG_INFO(" Where 'filename' is the file to write (default is turrets_dump.cfg),\n"); - LOG_INFO(" if supplied with '-' output to console as well as default,\n"); - LOG_INFO(" if left blank, it will only write to default.\n"); - return; - } - } -} - void GenericCommand_maplist(float request, float argc) { switch(request) @@ -758,12 +540,6 @@ void GenericCommand_(float request) // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;) GENERIC_COMMAND(addtolist, "Add a string to a cvar") { GenericCommand_addtolist(request, arguments); } -GENERIC_COMMAND(dumpcommands, "Dump all commands on the program to *_cmd_dump.txt") { GenericCommand_dumpcommands(request); } -GENERIC_COMMAND(dumpeffectinfo, "Dump all effectinfo to effectinfo_dump.txt") { GenericCommand_dumpeffectinfo(request); } -GENERIC_COMMAND(dumpitems, "Dump all items to the console") { GenericCommand_dumpitems(request); } -GENERIC_COMMAND(dumpnotifs, "Dump all notifications into notifications_dump.txt") { GenericCommand_dumpnotifs(request); } -GENERIC_COMMAND(dumpturrets, "Dump all turrets into turrets_dump.txt") { GenericCommand_dumpturrets(request); } -GENERIC_COMMAND(dumpweapons, "Dump all weapons into weapons_dump.txt") { GenericCommand_dumpweapons(request); } GENERIC_COMMAND(maplist, "Automatic control of maplist") { GenericCommand_maplist(request, arguments); } GENERIC_COMMAND(nextframe, "Execute the given command next frame of this VM") { GenericCommand_nextframe(request, arguments, command); } GENERIC_COMMAND(qc_curl, "Queries a URL") { GenericCommand_qc_curl(request, arguments); } diff --git a/qcsrc/common/effects/effectinfo.qc b/qcsrc/common/effects/effectinfo.qc index 731903b63..deff4dc15 100644 --- a/qcsrc/common/effects/effectinfo.qc +++ b/qcsrc/common/effects/effectinfo.qc @@ -283,6 +283,41 @@ void effectinfo_dump(int fh, bool alsoprint) #undef WRITE } +GENERIC_COMMAND(dumpeffectinfo, "Dump all effectinfo to effectinfo_dump.txt") +{ + switch (request) { + case CMD_REQUEST_COMMAND: { + string filename = argv(1); + bool alsoprint = false; + if (filename == "") { + filename = "effectinfo_dump.txt"; + alsoprint = false; + } else if (filename == "-") { + filename = "effectinfo_dump.txt"; + alsoprint = true; + } + int fh = fopen(filename, FILE_WRITE); + if (fh >= 0) { + effectinfo_dump(fh, alsoprint); + LOG_INFOF("Dumping effectinfo... File located at ^2data/data/%s^7.\n", filename); + LOG_INFOF("Reload with ^2cl_particles_reloadeffects data/%s^7.\n", filename); + fclose(fh); + } else { + LOG_WARNINGF("Could not open file '%s'!\n", filename); + } + return; + } + default: + case CMD_REQUEST_USAGE: { + LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpeffectinfo [filename]")); + LOG_INFO(" Where 'filename' is the file to write (default is effectinfo_dump.txt),\n"); + LOG_INFO(" if supplied with '-' output to console as well as default,\n"); + LOG_INFO(" if left blank, it will only write to default.\n"); + return; + } + } +} + REGISTRY(EffectInfos, BIT(9)) REGISTER_REGISTRY(RegisterEffectInfos) diff --git a/qcsrc/common/items/all.qh b/qcsrc/common/items/all.qh index 672ed707c..92c77579a 100644 --- a/qcsrc/common/items/all.qh +++ b/qcsrc/common/items/all.qh @@ -1,6 +1,8 @@ #ifndef ITEMS_ALL_H #define ITEMS_ALL_H +#include "../command/all.qh" + #include "item.qh" REGISTRY(Items, BIT(5)) @@ -10,6 +12,20 @@ REGISTER_REGISTRY(RegisterItems) void Dump_Items(); +GENERIC_COMMAND(dumpitems, "Dump all items to the console") { + switch (request) { + case CMD_REQUEST_COMMAND: { + Dump_Items(); + return; + } + default: + case CMD_REQUEST_USAGE: { + LOG_INFOF("\nUsage:^3 %s dumpitems", GetProgramCommandPrefix()); + return; + } + } +} + #ifndef MENUQC string Item_Model(string item_mdl); #endif diff --git a/qcsrc/common/notifications.qh b/qcsrc/common/notifications.qh index 01d6cbe55..043ec38b9 100644 --- a/qcsrc/common/notifications.qh +++ b/qcsrc/common/notifications.qh @@ -1,6 +1,8 @@ #ifndef NOTIFICATIONS_H #define NOTIFICATIONS_H +#include "command/all.qh" + #include "constants.qh" #include "teams.qh" #include "util.qh" @@ -83,6 +85,57 @@ void Create_Notification_Entity( void Dump_Notifications(float fh, float alsoprint); + +GENERIC_COMMAND(dumpnotifs, "Dump all notifications into notifications_dump.txt") +{ + switch(request) + { + case CMD_REQUEST_COMMAND: + { + #ifndef MENUQC + float fh, alsoprint = false; + string filename = argv(1); + + if(filename == "") + { + filename = "notifications_dump.cfg"; + alsoprint = false; + } + else if(filename == "-") + { + filename = "notifications_dump.cfg"; + alsoprint = true; + } + fh = fopen(filename, FILE_WRITE); + + if(fh >= 0) + { + Dump_Notifications(fh, alsoprint); + LOG_INFOF("Dumping notifications... File located in ^2data/data/%s^7.\n", filename); + fclose(fh); + } + else + { + LOG_INFOF("^1Error: ^7Could not open file '%s'!\n", filename); + } + #else + LOG_INFO(_("Notification dump command only works with cl_cmd and sv_cmd.\n")); + #endif + return; + } + + default: + case CMD_REQUEST_USAGE: + { + LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpnotifs [filename]")); + LOG_INFO(" Where 'filename' is the file to write (default is notifications_dump.cfg),\n"); + LOG_INFO(" if supplied with '-' output to console as well as default,\n"); + LOG_INFO(" if left blank, it will only write to default.\n"); + return; + } + } +} + #ifdef NOTIFICATIONS_DEBUG void Debug_Notification(string input); #endif diff --git a/qcsrc/common/turrets/all.qh b/qcsrc/common/turrets/all.qh index 2b9a87d42..3f9eba4f3 100644 --- a/qcsrc/common/turrets/all.qh +++ b/qcsrc/common/turrets/all.qh @@ -1,10 +1,69 @@ #ifndef TURRETS_ALL_H #define TURRETS_ALL_H +#include "../command/all.qh" +#include "config.qh" + #include "turret.qh" REGISTRY(Turrets, BIT(5)) REGISTER_REGISTRY(RegisterTurrets) + + +GENERIC_COMMAND(dumpturrets, "Dump all turrets into turrets_dump.txt") +{ + switch(request) + { + case CMD_REQUEST_COMMAND: + { + #ifdef SVQC + tur_config_file = -1; + tur_config_alsoprint = -1; + string filename = argv(1); + + if(filename == "") + { + filename = "turrets_dump.cfg"; + tur_config_alsoprint = FALSE; + } + else if(filename == "-") + { + filename = "turrets_dump.cfg"; + tur_config_alsoprint = TRUE; + } + tur_config_file = fopen(filename, FILE_WRITE); + + if(tur_config_file >= 0) + { + Dump_Turret_Settings(); + LOG_INFO(sprintf("Dumping turrets... File located in ^2data/data/%s^7.\n", filename)); + fclose(tur_config_file); + tur_config_file = -1; + tur_config_alsoprint = -1; + } + else + { + LOG_INFO(sprintf("^1Error: ^7Could not open file '%s'!\n", filename)); + } + #else + LOG_INFO(_("Turrets dump command only works with sv_cmd.\n")); + #endif + return; + } + + default: + case CMD_REQUEST_USAGE: + { + LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpturrets [filename]")); + LOG_INFO(" Where 'filename' is the file to write (default is turrets_dump.cfg),\n"); + LOG_INFO(" if supplied with '-' output to console as well as default,\n"); + LOG_INFO(" if left blank, it will only write to default.\n"); + return; + } + } +} + + const int TUR_FIRST = 1; #define TUR_LAST (Turrets_COUNT - 1) diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index c96061fe6..7bf6715f5 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -1,6 +1,9 @@ #ifndef WEAPONS_ALL_H #define WEAPONS_ALL_H +#include "../command/all.qh" +#include "config.qh" + // weapon sets typedef vector WepSet; #define WEPSET(id) WepSet_FromWeapon(WEP_##id.m_id) @@ -34,9 +37,63 @@ REGISTRY(Weapons, 72) // Increase as needed. Can be up to 72. REGISTER_REGISTRY(RegisterWeapons) entity get_weaponinfo(int id); + +GENERIC_COMMAND(dumpweapons, "Dump all weapons into weapons_dump.txt") // WEAPONTODO: make this work with other progs than just server +{ + switch(request) + { + case CMD_REQUEST_COMMAND: + { + #ifdef SVQC + wep_config_file = -1; + wep_config_alsoprint = -1; + string filename = argv(1); + + if(filename == "") + { + filename = "weapons_dump.cfg"; + wep_config_alsoprint = false; + } + else if(filename == "-") + { + filename = "weapons_dump.cfg"; + wep_config_alsoprint = true; + } + wep_config_file = fopen(filename, FILE_WRITE); + + if(wep_config_file >= 0) + { + Dump_Weapon_Settings(); + LOG_INFO(sprintf("Dumping weapons... File located in ^2data/data/%s^7.\n", filename)); + fclose(wep_config_file); + wep_config_file = -1; + wep_config_alsoprint = -1; + } + else + { + LOG_INFO(sprintf("^1Error: ^7Could not open file '%s'!\n", filename)); + } + #else + LOG_INFO(_("Weapons dump command only works with sv_cmd.\n")); + #endif + return; + } + + default: + case CMD_REQUEST_USAGE: + { + LOG_INFO(strcat("\nUsage:^3 ", GetProgramCommandPrefix(), " dumpweapons [filename]")); + LOG_INFO(" Where 'filename' is the file to write (default is weapons_dump.cfg),\n"); + LOG_INFO(" if supplied with '-' output to console as well as default,\n"); + LOG_INFO(" if left blank, it will only write to default.\n"); + return; + } + } +} + #define REGISTER_WEAPON(id, inst) \ - /* WepSet WEPSET_##id; */ \ - REGISTER(RegisterWeapons, WEP, Weapons, id, m_id, inst) + /* WepSet WEPSET_##id; */ \ + REGISTER(RegisterWeapons, WEP, Weapons, id, m_id, inst) // create cvars for weapon settings #define WEP_ADD_CVAR_NONE(wepname,name) [[last]] float autocvar_g_balance_##wepname##_##name; @@ -44,15 +101,15 @@ entity get_weaponinfo(int id); #define WEP_ADD_CVAR_PRI(wepname,name) WEP_ADD_CVAR_NONE(wepname, primary_##name) #define WEP_ADD_CVAR_SEC(wepname,name) WEP_ADD_CVAR_NONE(wepname, secondary_##name) #define WEP_ADD_CVAR_BOTH(wepname,name) \ - WEP_ADD_CVAR_PRI(wepname, name) \ - WEP_ADD_CVAR_SEC(wepname, name) + WEP_ADD_CVAR_PRI(wepname, name) \ + WEP_ADD_CVAR_SEC(wepname, name) #define WEP_ADD_CVAR(wepid,wepname,mode,name) WEP_ADD_CVAR_##mode(wepname, name) // create properties for weapon settings #define WEP_ADD_PROP(wepid,wepname,type,prop,name) \ - .type prop; \ - [[last]] type autocvar_g_balance_##wepname##_##name; + .type prop; \ + [[last]] type autocvar_g_balance_##wepname##_##name; // read cvars from weapon settings #define WEP_CVAR(wepname,name) autocvar_g_balance_##wepname##_##name @@ -75,11 +132,11 @@ REGISTER_WEAPON(Null, NEW(Weapon)); entity get_weaponinfo(int id) { - if (id >= WEP_FIRST && id <= WEP_LAST) { - Weapon w = Weapons[id]; - if (w) return w; - } - return WEP_Null; + if (id >= WEP_FIRST && id <= WEP_LAST) { + Weapon w = Weapons[id]; + if (w) return w; + } + return WEP_Null; } // TODO: remove after 0.8.2. Retains impulse number compatibility because 0.8.1 clients don't reload the weapons.cfg @@ -93,28 +150,28 @@ REGISTRY_SORT(Weapons, netname, WEP_HARDCODED_IMPULSES + 1) STATIC_INIT(register_weapons_done) { - for (int i = 0; i < Weapons_COUNT; ++i) { - Weapon it = Weapons[i]; - it.m_id = i; - WepSet set = WepSet_FromWeapon(it.m_id); - WEPSET_ALL |= set; - if ((it.spawnflags) & WEP_FLAG_SUPERWEAPON) WEPSET_SUPERWEAPONS |= set; - it.weapon = it.m_id; - it.weapons = set; - #ifdef CSQC - it.wr_init(it); - #endif - int imp = WEP_IMPULSE_BEGIN + it.m_id - 1; - if (imp <= WEP_IMPULSE_END) - localcmd(sprintf("alias weapon_%s \"impulse %d\"\n", it.netname, imp)); - else - LOG_TRACEF(_("Impulse limit exceeded, weapon will not be directly accessible: %s\n"), it.netname); - } - weaponorder_byid = ""; - for (int i = Weapons_MAX - 1; i >= 1; --i) - if (Weapons[i]) - weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i)); - weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1)); + for (int i = 0; i < Weapons_COUNT; ++i) { + Weapon it = Weapons[i]; + it.m_id = i; + WepSet set = WepSet_FromWeapon(it.m_id); + WEPSET_ALL |= set; + if ((it.spawnflags) & WEP_FLAG_SUPERWEAPON) WEPSET_SUPERWEAPONS |= set; + it.weapon = it.m_id; + it.weapons = set; + #ifdef CSQC + it.wr_init(it); + #endif + int imp = WEP_IMPULSE_BEGIN + it.m_id - 1; + if (imp <= WEP_IMPULSE_END) + localcmd(sprintf("alias weapon_%s \"impulse %d\"\n", it.netname, imp)); + else + LOG_TRACEF(_("Impulse limit exceeded, weapon will not be directly accessible: %s\n"), it.netname); + } + weaponorder_byid = ""; + for (int i = Weapons_MAX - 1; i >= 1; --i) + if (Weapons[i]) + weaponorder_byid = strcat(weaponorder_byid, " ", ftos(i)); + weaponorder_byid = strzone(substring(weaponorder_byid, 1, strlen(weaponorder_byid) - 1)); } #endif diff --git a/qcsrc/common/weapons/config.qh b/qcsrc/common/weapons/config.qh index 410dbdfad..c50c1e544 100644 --- a/qcsrc/common/weapons/config.qh +++ b/qcsrc/common/weapons/config.qh @@ -1,6 +1,7 @@ #ifndef WEAPONS_CONFIG_H #define WEAPONS_CONFIG_H +#ifdef SVQC // ========================== // Balance Config Generator // ========================== @@ -47,3 +48,4 @@ string wep_config_queue[MAX_WEP_CONFIG]; #define WEP_CONFIG_WRITE_PROPS(wepid,wepname,type,prop,name) WEP_CONFIG_WRITE_PROPS_##type(wepname,name) #endif +#endif