-#include "command.qh"
-#include "generic.qh"
+#include "all.qh"
#include "markup.qh"
#include "rpn.qh"
}
*/
-// ==================================
-// Macro system for server commands
-// ==================================
-
// 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), "Add a string to a cvar") \
- GENERIC_COMMAND("dumpcommands", GenericCommand_dumpcommands(request), "Dump all commands on the program to *_cmd_dump.txt") \
- GENERIC_COMMAND("dumpeffectinfo", GenericCommand_dumpeffectinfo(request), "Dump all effectinfo to effectinfo_dump.txt") \
- GENERIC_COMMAND("dumpitems", GenericCommand_dumpitems(request), "Dump all items to the console") \
- GENERIC_COMMAND("dumpnotifs", GenericCommand_dumpnotifs(request), "Dump all notifications into notifications_dump.txt") \
- GENERIC_COMMAND("dumpturrets", GenericCommand_dumpturrets(request), "Dump all turrets into turrets_dump.txt") \
- GENERIC_COMMAND("dumpweapons", GenericCommand_dumpweapons(request), "Dump all weapons into weapons_dump.txt") \
- GENERIC_COMMAND("maplist", GenericCommand_maplist(request, arguments), "Automatic control of maplist") \
- GENERIC_COMMAND("nextframe", GenericCommand_nextframe(request, arguments, command), "Execute the given command next frame of this VM") \
- GENERIC_COMMAND("qc_curl", GenericCommand_qc_curl(request, arguments), "Queries a URL") \
- GENERIC_COMMAND("removefromlist", GenericCommand_removefromlist(request, arguments), "Remove a string from a cvar") \
- GENERIC_COMMAND("restartnotifs", GenericCommand_restartnotifs(request), "Re-initialize all notifications") \
- 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") \
- GENERIC_COMMAND("runtest", GenericCommand_runtest(request, arguments), "Run unit tests") \
- /* nothing */
+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); }
+GENERIC_COMMAND(removefromlist, "Remove a string from a cvar") { GenericCommand_removefromlist(request, arguments); }
+GENERIC_COMMAND(restartnotifs, "Re-initialize all notifications") { GenericCommand_restartnotifs(request); }
+GENERIC_COMMAND(rpn, "RPN calculator") { GenericCommand_rpn(request, arguments, command); }
+GENERIC_COMMAND(settemp, "Temporarily set a value to a cvar which is restored later") { GenericCommand_settemp(request, arguments); }
+GENERIC_COMMAND(settemp_restore, "Restore all cvars set by settemp command") { GenericCommand_settemp_restore(request, arguments); }
+GENERIC_COMMAND(runtest, "Run unit tests") { GenericCommand_runtest(request, arguments); }
void GenericCommand_macro_help()
{
- #define GENERIC_COMMAND(name,function,description) \
- { LOG_INFO(" ^2", name, "^7: ", description, "\n"); }
-
- GENERIC_COMMANDS(0, 0, "");
- #undef GENERIC_COMMAND
-
- return;
+ FOREACH(GENERIC_COMMANDS, true, LAMBDA(LOG_INFOF(" ^2%s^7: %s\n", it.m_name, it.m_description)));
}
float GenericCommand_macro_command(float argc, string command)
{
- #define GENERIC_COMMAND(name,function,description) \
- { if(name == strtolower(argv(0))) { function; return true; } }
-
- GENERIC_COMMANDS(CMD_REQUEST_COMMAND, argc, command);
- #undef GENERIC_COMMAND
-
+ string c = strtolower(argv(0));
+ FOREACH(GENERIC_COMMANDS, it.m_name == c, LAMBDA(
+ it.m_invokecmd(CMD_REQUEST_COMMAND, argc, command);
+ return true;
+ ));
return false;
}
float GenericCommand_macro_usage(float argc)
{
- #define GENERIC_COMMAND(name,function,description) \
- { if(name == strtolower(argv(1))) { function; return true; } }
-
- GENERIC_COMMANDS(CMD_REQUEST_USAGE, argc, "");
- #undef GENERIC_COMMAND
-
+ string c = strtolower(argv(1));
+ FOREACH(GENERIC_COMMANDS, it.m_name == c, LAMBDA(
+ it.m_invokecmd(CMD_REQUEST_USAGE, argc, "");
+ return true;
+ ));
return false;
}
void GenericCommand_macro_write_aliases(float fh)
{
- #define GENERIC_COMMAND(name,function,description) \
- { CMD_Write_Alias("qc_cmd_svmenu", name, description); }
-
- GENERIC_COMMANDS(0, 0, "");
- #undef GENERIC_COMMAND
-
- return;
+ FOREACH(GENERIC_COMMANDS, true, LAMBDA(CMD_Write_Alias("qc_cmd_svmenu", it.m_name, it.m_description)));
}
* @param fld The field to store the current count into
* @param inst An expression to create a new instance, invoked for every registration
*/
-#define REGISTER(initfunc, ns, array, id, fld, inst) \
- entity ns##_##id; \
- REGISTER_INIT(ns, id) { } \
- REGISTER_INIT_POST(ns, id) { } \
- .entity enemy; /* internal next pointer */ \
- void Register_##ns##_##id() { \
+#define REGISTER(initfunc, ns, array, id, fld, inst) \
+ entity ns##_##id; \
+ REGISTER_INIT(ns, id) { } \
+ REGISTER_INIT_POST(ns, id) { } \
+ void Register_##ns##_##id() { \
if (array##_COUNT >= array##_MAX) LOG_FATALF("Registry capacity exceeded (%s)", ftos(array##_MAX)); \
- entity this = inst; \
- ns##_##id = this; \
- this.fld = array##_COUNT; \
- array[array##_COUNT++] = this; \
- if (!array##_first) array##_first = this; \
- if ( array##_last) array##_last.enemy = this; \
- array##_last = this; \
- Register_##ns##_##id##_init(this); \
- Register_##ns##_##id##_init_post(this); \
- } \
- ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id) \
+ entity this = inst; \
+ ns##_##id = this; \
+ this.fld = array##_COUNT; \
+ array[array##_COUNT++] = this; \
+ if (!array##_first) array##_first = this; \
+ if ( array##_last) array##_last.REGISTRY_NEXT = this; \
+ array##_last = this; \
+ Register_##ns##_##id##_init(this); \
+ Register_##ns##_##id##_init_post(this); \
+ } \
+ ACCUMULATE_FUNCTION(initfunc, Register_##ns##_##id) \
REGISTER_INIT(ns, id)
-#define REGISTRY_SORT(id, field, skip) \
- void _REGISTRY_SWAP_##id(int i, int j, entity pass) { \
- i += skip; j += skip; \
- entity e = id[i]; \
- id[i] = id[j]; \
- id[j] = e; \
- } \
- float _REGISTRY_CMP_##id(int i, int j, entity pass) { \
- i += skip; j += skip; \
- string a = id[i].field; \
- string b = id[j].field; \
- return strcasecmp(a, b); \
- } \
- STATIC_INIT(Registry_sort_##id) { \
+/** internal next pointer */
+#define REGISTRY_NEXT enemy
+.entity REGISTRY_NEXT;
+
+#define REGISTRY_SORT(id, field, skip) \
+ void _REGISTRY_SWAP_##id(int i, int j, entity pass) { \
+ i += skip; j += skip; \
+ \
+ entity a = id[i], b = id[j]; \
+ id[i] = b; \
+ id[j] = a; \
+ \
+ entity a_next = a.REGISTRY_NEXT, b_next = b.REGISTRY_NEXT; \
+ a.REGISTRY_NEXT = b_next; \
+ b.REGISTRY_NEXT = a_next; \
+ \
+ if (i == 0) id##_first = b; \
+ else id[i - 1].REGISTRY_NEXT = b; \
+ \
+ if (j == 0) id##_first = a; \
+ else id[j - 1].REGISTRY_NEXT = a; \
+ } \
+ float _REGISTRY_CMP_##id(int i, int j, entity pass) { \
+ i += skip; j += skip; \
+ string a = id[i].field; \
+ string b = id[j].field; \
+ return strcasecmp(a, b); \
+ } \
+ STATIC_INIT(Registry_sort_##id) { \
heapsort(id##_COUNT - (skip), _REGISTRY_SWAP_##id, _REGISTRY_CMP_##id, NULL); \
}