]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move mutator system to common
authorTimePath <andrew.hardaker1995@gmail.com>
Wed, 19 Aug 2015 00:04:12 +0000 (10:04 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Wed, 19 Aug 2015 09:17:41 +0000 (19:17 +1000)
mod/server/main.qc
qcsrc/common/mutators/base.qh [new file with mode: 0644]
qcsrc/common/mutators/events.qh [new file with mode: 0644]
qcsrc/server/miscfunctions.qh
qcsrc/server/mutators/base.qc [deleted file]
qcsrc/server/mutators/base.qh [deleted file]
qcsrc/server/mutators/events.qh [new file with mode: 0644]
qcsrc/server/mutators/mutator.qh
qcsrc/server/mutators/mutators_include.qc
qcsrc/server/mutators/mutators_include.qh
qcsrc/server/sys-post.qh

index 1342b7b4adb56af8526ad039d1cbec6ab34dc22d..f6c94ca653f78283d6f2908b1450a44e83e2c3bd 100644 (file)
@@ -10,6 +10,7 @@ MUTATOR_HOOKFUNCTION(mod_BuildMutatorsPrettyString)
     return false;
 }
 
+MUTATOR_DECLARATION(mutator_mod);
 MUTATOR_DEFINITION(mutator_mod)
 {
     MUTATOR_HOOK(BuildMutatorsString, mod_BuildMutatorsString, CBC_ORDER_ANY);
diff --git a/qcsrc/common/mutators/base.qh b/qcsrc/common/mutators/base.qh
new file mode 100644 (file)
index 0000000..dfd73a7
--- /dev/null
@@ -0,0 +1,234 @@
+#ifndef MUTATORS_BASE_H
+#define MUTATORS_BASE_H
+
+const int CBC_ORDER_FIRST = 1;
+const int CBC_ORDER_LAST = 2;
+const int CBC_ORDER_EXCLUSIVE = 3;
+const int CBC_ORDER_ANY = 4;
+
+bool CallbackChain_ReturnValue; // read-only field of the current return value
+
+/**
+ * Callbacks may be added to zero or more callback chains.
+ */
+CLASS(Callback, Object)
+    /**
+     * a callback function is like this:
+     * bool mycallback()
+     * {
+     *     do something
+     *     return false;
+     * }
+     */
+    ATTRIB(Callback, cbc_func, bool(), func_null)
+    CONSTRUCTOR(Callback, bool() func) {
+        CONSTRUCT(Callback);
+        this.cbc_func = func;
+        return this;
+    }
+ENDCLASS(Callback)
+
+/**
+ * Callback chains contain zero or more callbacks.
+ */
+CLASS(CallbackChain, Object)
+    CLASS(CallbackNode, Object)
+        ATTRIB(CallbackNode, cbc, Callback, NULL)
+        ATTRIB(CallbackNode, cbc_next, CallbackNode, NULL)
+        ATTRIB(CallbackNode, cbc_order, int, 0)
+        CONSTRUCTOR(CallbackNode, Callback it, int order) {
+            CONSTRUCT(CallbackNode);
+            this.cbc = it;
+            this.cbc_order = order;
+            return this;
+        }
+    ENDCLASS(CallbackNode)
+
+    ATTRIB(CallbackChain, cbc_next, CallbackNode, NULL)
+    ATTRIB(CallbackChain, cbc_order, int, 0)
+    CONSTRUCTOR(CallbackChain, string name) {
+        CONSTRUCT(CallbackChain);
+        this.netname = name;
+        return this;
+    }
+
+    bool CallbackChain_Add(CallbackChain this, Callback cb, int order)
+    {
+        if (order & CBC_ORDER_FIRST) {
+            if (order & CBC_ORDER_LAST)
+                if (this.cbc_order & CBC_ORDER_ANY)
+                    return false;
+            if (this.cbc_order & CBC_ORDER_FIRST)
+                return false;
+        } else if (order & CBC_ORDER_LAST) {
+            if (this.cbc_order & CBC_ORDER_LAST)
+                return false;
+        }
+        entity node = NEW(CallbackNode, cb, order);
+        if (order & CBC_ORDER_FIRST) {
+            node.cbc_next = this.cbc_next;
+            this.cbc_next = node;
+        } else if (order & CBC_ORDER_LAST) {
+            CallbackNode prev = NULL, it = this.cbc_next;
+            while (it) { prev = it, it = it.cbc_next; }
+            if (prev) prev.cbc_next = node;
+            else this.cbc_next = node;
+        } else {
+            // by default we execute last, but before a possible CBC_ORDER_LAST callback
+            CallbackNode prev = NULL, it = this.cbc_next;
+            while (it && !(it.cbc_order & CBC_ORDER_LAST)) { prev = it, it = it.cbc_next; }
+            node.cbc_next = it;
+            if (prev) prev.cbc_next = node;
+            else this.cbc_next = node;
+        }
+        this.cbc_order |= (order | CBC_ORDER_ANY);
+        return true;
+    }
+    int CallbackChain_Remove(CallbackChain this, Callback cb)
+    {
+        int n = 0, order = 0;
+        for (Callback prev = NULL, it = this.cbc_next; it; prev = it, it = it.cbc_next) {
+            if (it.cbc == cb) {
+                // remove it from the chain
+                Callback next = it.cbc_next;
+                if (prev) prev.cbc_next = next;
+                else this.cbc_next = next;
+                ++n;
+            }
+            // it is now something we want to keep
+            order |= (it.cbc_order & CBC_ORDER_ANY);
+        }
+        this.cbc_order = order;
+        return n;
+    }
+    bool CallbackChain_Call(CallbackChain this)
+    {
+        bool r = false;
+        for (Callback it = this.cbc_next; it; it = it.cbc_next) {
+            CallbackChain_ReturnValue = r;
+            r |= it.cbc.cbc_func();
+        }
+        return r; // callbacks return an error status, so 0 is default return value
+    }
+ENDCLASS(CallbackChain)
+
+#define _MUTATOR_HANDLE_NOP(type, id)
+#define _MUTATOR_HANDLE_PARAMS(type, id) , type in_##id
+#define _MUTATOR_HANDLE_PREPARE(type, id) id = in_##id;
+#define _MUTATOR_HANDLE_PUSHTMP(type, id) type tmp_##id = id;
+#define _MUTATOR_HANDLE_PUSHOUT(type, id) type out_##id = id;
+#define _MUTATOR_HANDLE_POPTMP(type, id) id = tmp_##id;
+#define _MUTATOR_HANDLE_POPOUT(type, id) id = out_##id;
+
+#define _MUTATOR_HOOKABLE(id, ...) CallbackChain HOOK_##id; bool __Mutator_Send_##id(__VA_ARGS__)
+#define MUTATOR_HOOKABLE(id, params) \
+    _MUTATOR_HOOKABLE(id, int params(_MUTATOR_HANDLE_PARAMS, _MUTATOR_HANDLE_NOP)) { \
+        params(_MUTATOR_HANDLE_PUSHTMP, _MUTATOR_HANDLE_NOP) \
+        params(_MUTATOR_HANDLE_PREPARE, _MUTATOR_HANDLE_NOP) \
+        bool ret = CallbackChain_Call(HOOK_##id); \
+        params(_MUTATOR_HANDLE_NOP,     _MUTATOR_HANDLE_PUSHOUT) \
+        params(_MUTATOR_HANDLE_POPTMP,  _MUTATOR_HANDLE_NOP) \
+        params(_MUTATOR_HANDLE_NOP,     _MUTATOR_HANDLE_POPOUT) \
+        return ret; \
+    } \
+    STATIC_INIT(HOOK_##id) { HOOK_##id = NEW(CallbackChain, #id); }
+#define MUTATOR_CALLHOOK(id, ...) APPLY(__Mutator_Send_##id, 0, ##__VA_ARGS__)
+
+enum {
+    MUTATOR_REMOVING,
+    MUTATOR_ADDING,
+    MUTATOR_ROLLING_BACK
+};
+
+typedef bool(int) mutatorfunc_t;
+
+CLASS(Mutator, Object)
+    ATTRIB(Mutator, mutatorname, string, string_null)
+    ATTRIB(Mutator, mutatorfunc, mutatorfunc_t, func_null)
+    CONSTRUCTOR(Mutator, string name, mutatorfunc_t func) {
+        CONSTRUCT(Mutator);
+        this.mutatorname = name;
+        this.mutatorfunc = func;
+        return this;
+    }
+ENDCLASS(Mutator)
+
+const int MAX_MUTATORS = 15;
+Mutator loaded_mutators[MAX_MUTATORS];
+
+bool Mutator_Add(Mutator mut)
+{
+    int j = -1;
+    for (int i = 0; i < MAX_MUTATORS; ++i) {
+        if (loaded_mutators[i] == mut)
+            return true; // already added
+        if (!(loaded_mutators[i]))
+            j = i;
+    }
+    if (j < 0) {
+        backtrace("WARNING: too many mutators, cannot add any more\n");
+        return false;
+    }
+    loaded_mutators[j] = mut;
+    mutatorfunc_t func = mut.mutatorfunc;
+    if (!func(MUTATOR_ADDING)) {
+        // good
+        return true;
+    }
+    backtrace("WARNING: when adding mutator: adding failed, rolling back\n");
+    if (func(MUTATOR_ROLLING_BACK)) {
+        // baaaaad
+        error("WARNING: when adding mutator: rolling back failed");
+    }
+    return false;
+}
+
+void Mutator_Remove(Mutator mut)
+{
+    int i;
+    for (i = 0; i < MAX_MUTATORS; ++i)
+        if (loaded_mutators[i] == mut)
+            break;
+    if (i >= MAX_MUTATORS) {
+        backtrace("WARNING: removing not-added mutator\n");
+        return;
+    }
+    loaded_mutators[i] = NULL;
+    mutatorfunc_t func = mut.mutatorfunc;
+    if (func(MUTATOR_REMOVING)) {
+        // baaaaad
+        error("Mutator_Remove: removing mutator failed");
+    }
+}
+
+#define MUTATOR_DECLARATION(name) \
+    Mutator MUTATOR_##name
+#define MUTATOR_DEFINITION(name) \
+    bool MUTATORFUNCTION_##name(int mode); \
+    STATIC_INIT(MUTATOR_##name) { MUTATOR_##name = NEW(Mutator, #name, MUTATORFUNCTION_##name); } \
+    bool MUTATORFUNCTION_##name(int mode)
+#define MUTATOR_ONADD                   if (mode == MUTATOR_ADDING)
+#define MUTATOR_ONREMOVE                if (mode == MUTATOR_REMOVING)
+#define MUTATOR_ONROLLBACK_OR_REMOVE    if (mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK)
+#define MUTATOR_ADD(name)               Mutator_Add(MUTATOR_##name)
+#define MUTATOR_REMOVE(name)            Mutator_Remove(MUTATOR_##name)
+#define MUTATOR_RETURNVALUE             CallbackChain_ReturnValue
+#define MUTATOR_HOOKFUNCTION(name) \
+    bool HOOKFUNCTION_##name(); \
+    Callback CALLBACK_##name; STATIC_INIT(CALLBACK_##name) { CALLBACK_##name = NEW(Callback, HOOKFUNCTION_##name); } \
+    bool HOOKFUNCTION_##name()
+#define MUTATOR_HOOK(cb, func, order) do {                              \
+    MUTATOR_ONADD {                                                     \
+        if (!CallbackChain_Add(HOOK_##cb, CALLBACK_##func, order)) {    \
+            print("HOOK FAILED: ", #cb, ":", #func, "\n");              \
+            return true;                                                \
+        }                                                               \
+    }                                                                   \
+    MUTATOR_ONROLLBACK_OR_REMOVE {                                      \
+        CallbackChain_Remove(HOOK_##cb, CALLBACK_##func);               \
+    }                                                                   \
+} while (0)
+
+#include "events.qh"
+
+#endif
diff --git a/qcsrc/common/mutators/events.qh b/qcsrc/common/mutators/events.qh
new file mode 100644 (file)
index 0000000..e193d5f
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef COMMON_MUTATORS_EVENTS_H
+#define COMMON_MUTATORS_EVENTS_H
+
+#define EV_NO_ARGS(i, o)
+
+string ret_string;
+
+/** appends ":mutatorname" to ret_string for logging */
+#define EV_BuildMutatorsString(i, o) \
+    /**/ i(string, ret_string) \
+    /**/ o(string, ret_string) \
+    /**/
+MUTATOR_HOOKABLE(BuildMutatorsString, EV_BuildMutatorsString);
+
+/** appends ", Mutator name" to ret_string for display */
+#define EV_BuildMutatorsPrettyString(i, o) \
+    /**/ i(string, ret_string) \
+    /**/ o(string, ret_string) \
+    /**/
+MUTATOR_HOOKABLE(BuildMutatorsPrettyString, EV_BuildMutatorsPrettyString);
+
+#endif
index 12dbe3a2c795a72512c012cf9deaba5cb1dbbfe6..860eadcaa29f85852777eecc68150266581187df 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "t_items.qh"
 
-#include "mutators/base.qh"
+#include "mutators/events.qh"
 #include "mutators/gamemode_race.qh"
 
 #include "../common/constants.qh"
@@ -75,7 +75,6 @@ vector shotorg_adjust(vector vecs, float y_is_right, float visual);
 
 float DistributeEvenly_amount;
 float DistributeEvenly_totalweight;
-var void remove(entity e);
 void objerror(string s);
 void droptofloor();
 void() spawnfunc_info_player_deathmatch; // needed for the other spawnpoints
diff --git a/qcsrc/server/mutators/base.qc b/qcsrc/server/mutators/base.qc
deleted file mode 100644 (file)
index 2f78ec1..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-#include "base.qh"
-#include "../_all.qh"
-
-.bool() cbc_func;
-.entity cbc_next;
-.int cbc_order;
-
-entity CallbackChain_New(string name)
-{
-       entity e = spawn();
-       e.classname = "callbackchain";
-       e.netname = name;
-       return e;
-}
-
-bool CallbackChain_Add(entity cb, bool() func, int order)
-{
-       if (order & CBC_ORDER_FIRST) {
-               if (order & CBC_ORDER_LAST)
-                       if (cb.cbc_order & CBC_ORDER_ANY)
-                               return false;
-               if (cb.cbc_order & CBC_ORDER_FIRST)
-                       return false;
-       } else if (order & CBC_ORDER_LAST) {
-               if (cb.cbc_order & CBC_ORDER_LAST)
-                       return false;
-       }
-       entity thiscb = spawn();
-       thiscb.classname = "callback";
-       thiscb.cbc_func = func;
-       thiscb.cbc_order = order;
-       if (order & CBC_ORDER_FIRST) {
-               thiscb.cbc_next = cb.cbc_next;
-               cb.cbc_next = thiscb;
-       } else if (order & CBC_ORDER_LAST) {
-               entity e = cb;
-               while (e.cbc_next) e = e.cbc_next;
-               e.cbc_next = thiscb;
-       } else {
-               // by default we execute last, but before a possible CBC_ORDER_LAST callback
-               entity e = cb;
-               // we must make sure that we insert BEFORE an CBC_ORDER_LAST mutator!
-               while (e.cbc_next && !(e.cbc_next.cbc_order & CBC_ORDER_LAST)) e = e.cbc_next;
-               thiscb.cbc_next = e.cbc_next;
-               e.cbc_next = thiscb;
-       }
-       cb.cbc_order |= (order | CBC_ORDER_ANY);
-       return true;
-}
-
-int CallbackChain_Remove(entity cb, bool() func)
-{
-       int n = 0, order = 0;
-       for (entity e = cb; e.cbc_next; e = e.cbc_next) {
-               while (e.cbc_next.cbc_func == func) {
-                       // remove e.cbc_next from the chain
-                       entity e2 = e.cbc_next.cbc_next;
-                       remove(e.cbc_next);
-                       e.cbc_next = e2;
-                       ++n;
-               }
-               // e.cbc_next is now something we want to keep
-               order |= (e.cbc_next.cbc_order & CBC_ORDER_ANY);
-       }
-       cb.cbc_order = order;
-       return n;
-}
-
-bool CallbackChain_Call(entity cb)
-{
-       bool r = false;
-       for (entity e = cb; e.cbc_next; e = e.cbc_next) {
-               CallbackChain_ReturnValue = r;
-               r |= e.cbc_next.cbc_func();
-       }
-       return r; // callbacks return an error status, so 0 is default return value
-}
-
-const int MAX_MUTATORS = 15;
-string loaded_mutators[MAX_MUTATORS];
-bool Mutator_Add(mutatorfunc_t func, string name)
-{
-       int j = -1;
-       for (int i = 0; i < MAX_MUTATORS; ++i) {
-               if (name == loaded_mutators[i])
-                       return true; // already added
-               if (!(loaded_mutators[i]))
-                       j = i;
-       }
-       if (j < 0) {
-               backtrace("WARNING: too many mutators, cannot add any more\n");
-               return false;
-       }
-       loaded_mutators[j] = name;
-
-       if (!func(MUTATOR_ADDING)) {
-               // good
-               return true;
-       }
-
-       backtrace("WARNING: when adding mutator: adding failed, rolling back\n");
-
-       if (func(MUTATOR_ROLLING_BACK)) {
-               // baaaaad
-               error("WARNING: when adding mutator: rolling back failed");
-       }
-       return false;
-}
-void Mutator_Remove(mutatorfunc_t func, string name)
-{
-       int i;
-       for (i = 0; i < MAX_MUTATORS; ++i)
-               if (name == loaded_mutators[i])
-                       break;
-       if (i >= MAX_MUTATORS) {
-               backtrace("WARNING: removing not-added mutator\n");
-               return;
-       }
-       loaded_mutators[i] = string_null;
-
-       if (func(MUTATOR_REMOVING) != 0) {
-               // baaaaad
-               error("Mutator_Remove: removing mutator failed");
-       }
-}
diff --git a/qcsrc/server/mutators/base.qh b/qcsrc/server/mutators/base.qh
deleted file mode 100644 (file)
index c12050c..0000000
+++ /dev/null
@@ -1,569 +0,0 @@
-#ifndef MUTATORS_BASE_H
-#define MUTATORS_BASE_H
-const int CBC_ORDER_FIRST = 1;
-const int CBC_ORDER_LAST = 2;
-const int CBC_ORDER_EXCLUSIVE = 3;
-const int CBC_ORDER_ANY = 4;
-
-bool CallbackChain_ReturnValue; // read-only field of the current return value
-
-entity CallbackChain_New(string name);
-bool CallbackChain_Add(entity cb, bool() func, int order);
-int CallbackChain_Remove(entity cb, bool() func);
-// a callback function is like this:
-// bool mycallback(entity me)
-// {
-//   do something
-//   return false;
-// }
-bool CallbackChain_Call(entity cb);
-
-enum {
-       MUTATOR_REMOVING,
-       MUTATOR_ADDING,
-       MUTATOR_ROLLING_BACK
-};
-typedef bool(int) mutatorfunc_t;
-bool Mutator_Add(mutatorfunc_t func, string name);
-void Mutator_Remove(mutatorfunc_t func, string name); // calls error() on fail
-
-#define MUTATOR_ADD(name) Mutator_Add(MUTATOR_##name, #name)
-#define MUTATOR_REMOVE(name) Mutator_Remove(MUTATOR_##name, #name)
-#define MUTATOR_DEFINITION(name) bool MUTATOR_##name(int mode)
-#define MUTATOR_DECLARATION(name) bool MUTATOR_##name(int mode)
-#define MUTATOR_HOOKFUNCTION(name) bool HOOKFUNCTION_##name()
-#define MUTATOR_HOOK(cb, func, order) do {                                                                             \
-       MUTATOR_ONADD {                                                                                                                         \
-               if (!HOOK_##cb) HOOK_##cb = CallbackChain_New(#cb);                                     \
-               if (!CallbackChain_Add(HOOK_##cb, HOOKFUNCTION_##func, order)) {                \
-                       print("HOOK FAILED: ", #func, "\n");                                                            \
-                       return true;                                                                                                            \
-               }                                                                                                                                               \
-       }                                                                                                                                                       \
-       MUTATOR_ONROLLBACK_OR_REMOVE {                                                                                          \
-               if (HOOK_##cb) CallbackChain_Remove(HOOK_##cb, HOOKFUNCTION_##func);    \
-       }                                                                                                                                                       \
-} while(0)
-#define MUTATOR_ONADD if (mode == MUTATOR_ADDING)
-#define MUTATOR_ONREMOVE if (mode == MUTATOR_REMOVING)
-#define MUTATOR_ONROLLBACK_OR_REMOVE if (mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK)
-
-#define _MUTATOR_HOOKABLE(id, ...) entity HOOK_##id; bool __Mutator_Send_##id(__VA_ARGS__)
-#define MUTATOR_CALLHOOK(id, ...) APPLY(__Mutator_Send_##id, 0, ##__VA_ARGS__)
-
-#define MUTATOR_RETURNVALUE CallbackChain_ReturnValue
-
-#define HANDLE_NOP(type, id)
-#define HANDLE_PARAMS(type, id) , type in_##id
-#define HANDLE_PREPARE(type, id) id = in_##id;
-#define HANDLE_PUSHTMP(type, id) type tmp_##id = id;
-#define HANDLE_PUSHOUT(type, id) type out_##id = id;
-#define HANDLE_POPTMP(type, id) id = tmp_##id;
-#define HANDLE_POPOUT(type, id) id = out_##id;
-
-#define MUTATOR_HOOKABLE(id, params) \
-       _MUTATOR_HOOKABLE(id, int params(HANDLE_PARAMS, HANDLE_NOP)) { \
-               params(HANDLE_PUSHTMP, HANDLE_NOP) \
-               params(HANDLE_PREPARE, HANDLE_NOP) \
-               bool ret = CallbackChain_Call(HOOK_##id); \
-               params(HANDLE_NOP,     HANDLE_PUSHOUT) \
-               params(HANDLE_POPTMP,  HANDLE_NOP) \
-               params(HANDLE_NOP,     HANDLE_POPOUT) \
-               return ret; \
-       }
-
-
-
-// register all possible hooks here
-// some parameters are commented to avoid duplicate declarations
-
-#define EV_NO_ARGS(i, o)
-
-/** called when a player becomes observer, after shared setup */
-#define EV_MakePlayerObserver(i, o) \
-    /**/
-MUTATOR_HOOKABLE(MakePlayerObserver, EV_MakePlayerObserver)
-
-/** */
-#define EV_PutClientInServer(i, o) \
-    /** client wanting to spawn */ i(entity, self) \
-    /**/
-MUTATOR_HOOKABLE(PutClientInServer, EV_PutClientInServer);
-
-/** called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here) */
-#define EV_PlayerSpawn(i, o) \
-    /** spot that was used, or world */ i(entity, spawn_spot) \
-    /**/
-entity spawn_spot;
-MUTATOR_HOOKABLE(PlayerSpawn, EV_PlayerSpawn);
-
-/** called in reset_map */
-#define EV_reset_map_global(i, o) \
-    /**/
-MUTATOR_HOOKABLE(reset_map_global, EV_reset_map_global);
-
-/** called in reset_map */
-#define EV_reset_map_players(i, o) \
-    /**/
-MUTATOR_HOOKABLE(reset_map_players, EV_reset_map_players);
-
-/** returns 1 if clearing player score shall not be allowed */
-#define EV_ForbidPlayerScore_Clear(i, o) \
-    /**/
-MUTATOR_HOOKABLE(ForbidPlayerScore_Clear, EV_ForbidPlayerScore_Clear);
-
-/** called when a player disconnects */
-#define EV_ClientDisconnect(i, o) \
-    /**/
-MUTATOR_HOOKABLE(ClientDisconnect, EV_ClientDisconnect);
-
-/** called when a player dies to e.g. remove stuff he was carrying. */
-#define EV_PlayerDies(i, o) \
-    /**/ i(entity, frag_inflictor) \
-    /**/ i(entity, frag_attacker) \
-    /** same as self */ i(entity, frag_target) \
-    /**/ i(int, frag_deathtype) \
-    /**/
-entity frag_inflictor;
-entity frag_attacker;
-entity frag_target;
-int frag_deathtype;
-MUTATOR_HOOKABLE(PlayerDies, EV_PlayerDies);
-
-/** called when a player presses the jump key */
-#define EV_PlayerJump(i, o) \
-    /**/ i(float, player_multijump) \
-    /**/ i(float, player_jumpheight) \
-    /**/ o(float, player_multijump) \
-    /**/ o(float, player_jumpheight) \
-    /**/
-float player_multijump;
-float player_jumpheight;
-MUTATOR_HOOKABLE(PlayerJump, EV_PlayerJump);
-
-/** called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill */
-#define EV_GiveFragsForKill(i, o) \
-    /** same as self */ i(entity, frag_attacker) \
-    /**/ i(entity, frag_target) \
-    /**/ i(float, frag_score) \
-    /**/ o(float, frag_score) \
-    /**/
-float frag_score;
-MUTATOR_HOOKABLE(GiveFragsForKill, EV_GiveFragsForKill);
-
-/** called when the match ends */
-MUTATOR_HOOKABLE(MatchEnd, EV_NO_ARGS);
-
-/** should adjust ret_float to contain the team count */
-#define EV_GetTeamCount(i, o) \
-    /**/ i(float, ret_float) \
-    /**/ o(float, ret_float) \
-    /**/
-float ret_float;
-MUTATOR_HOOKABLE(GetTeamCount, EV_GetTeamCount);
-
-/** copies variables for spectating "other" to "self" */
-#define EV_SpectateCopy(i, o) \
-    /**/ i(entity, other) \
-    /**/ i(entity, self) \
-    /**/
-MUTATOR_HOOKABLE(SpectateCopy, EV_SpectateCopy);
-
-/** returns 1 if throwing the current weapon shall not be allowed */
-MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon, EV_NO_ARGS);
-
-/** allows changing attack rate */
-#define EV_WeaponRateFactor(i, o) \
-    /**/ i(float, weapon_rate) \
-    /**/ o(float, weapon_rate) \
-    /**/
-float weapon_rate;
-MUTATOR_HOOKABLE(WeaponRateFactor, EV_WeaponRateFactor);
-
-/** allows changing weapon speed (projectiles mostly) */
-#define EV_WeaponSpeedFactor(i, o) \
-    /**/ i(float, ret_float) \
-    /**/ o(float, ret_float) \
-    /**/
-MUTATOR_HOOKABLE(WeaponSpeedFactor, EV_WeaponSpeedFactor);
-
-/** adjusts {warmup_}start_{items,weapons,ammo_{cells,plasma,rockets,nails,shells,fuel}} */
-MUTATOR_HOOKABLE(SetStartItems, EV_NO_ARGS);
-
-/** appends ":mutatorname" to ret_string for logging */
-#define EV_BuildMutatorsString(i, o) \
-    /**/ i(string, ret_string) \
-    /**/ o(string, ret_string) \
-    /**/
-string ret_string;
-MUTATOR_HOOKABLE(BuildMutatorsString, EV_BuildMutatorsString);
-
-/** appends ", Mutator name" to ret_string for display */
-#define EV_BuildMutatorsPrettyString(i, o) \
-    /**/ i(string, ret_string) \
-    /**/ o(string, ret_string) \
-    /**/
-MUTATOR_HOOKABLE(BuildMutatorsPrettyString, EV_BuildMutatorsPrettyString);
-
-/** called every frame. customizes the waypoint for spectators */
-#define EV_CustomizeWaypoint(i, o) \
-    /** waypoint */ i(entity, self) \
-    /** player; other.enemy = spectator */ i(entity, other) \
-    /**/
-MUTATOR_HOOKABLE(CustomizeWaypoint, EV_CustomizeWaypoint);
-
-/**
- * checks if the current item may be spawned (self.items and self.weapons may be read and written to, as well as the ammo_ fields)
- * return error to request removal
- */
-MUTATOR_HOOKABLE(FilterItem, EV_NO_ARGS);
-
-/** return error to request removal */
-#define EV_TurretSpawn(i, o) \
-    /** turret */ i(entity, self) \
-    /**/
-MUTATOR_HOOKABLE(TurretSpawn, EV_TurretSpawn);
-
-/** return error to prevent entity spawn, or modify the entity */
-MUTATOR_HOOKABLE(OnEntityPreSpawn, EV_NO_ARGS);
-
-/** runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators */
-MUTATOR_HOOKABLE(PlayerPreThink, EV_NO_ARGS);
-
-/** TODO change this into a general PlayerPostThink hook? */
-MUTATOR_HOOKABLE(GetPressedKeys, EV_NO_ARGS);
-
-/**
- * called before any player physics, may adjust variables for movement,
- * is run AFTER bot code and idle checking
- */
-MUTATOR_HOOKABLE(PlayerPhysics, EV_NO_ARGS);
-
-/** is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client */
-#define EV_GetCvars(i, o) \
-    /**/ i(float, get_cvars_f) \
-    /**/ i(string, get_cvars_s) \
-    /**/
-float get_cvars_f;
-string get_cvars_s;
-MUTATOR_HOOKABLE(GetCvars, EV_NO_ARGS); // NOTE: Can't use EV_GetCvars because of `SZ_GetSpace: overflow`
-
-/** can edit any "just fired" projectile */
-#define EV_EditProjectile(i, o) \
-    /**/ i(entity, self) \
-    /**/ i(entity, other) \
-    /**/
-MUTATOR_HOOKABLE(EditProjectile, EV_EditProjectile);
-
-/** called when a monster spawns */
-MUTATOR_HOOKABLE(MonsterSpawn, EV_NO_ARGS);
-
-/** called when a monster dies */
-#define EV_MonsterDies(i, o) \
-    /**/ i(entity, frag_attacker) \
-    /**/
-MUTATOR_HOOKABLE(MonsterDies, EV_MonsterDies);
-
-/** called when a monster wants to respawn */
-#define EV_MonsterRespawn(i, o) \
-    /**/ i(entity, other) \
-    /**/
-MUTATOR_HOOKABLE(MonsterRespawn, EV_MonsterRespawn);
-
-/** called when a monster is dropping loot */
-#define EV_MonsterDropItem(i, o) \
-    /**/ i(entity, other) \
-    /**/ o(entity, other) \
-    /**/
-.void() monster_loot;
-MUTATOR_HOOKABLE(MonsterDropItem, EV_MonsterDropItem);
-
-/**
- * called when a monster moves
- * returning true makes the monster stop
- */
-#define EV_MonsterMove(i, o) \
-    /**/ i(float, monster_speed_run) \
-    /**/ o(float, monster_speed_run) \
-    /**/ i(float, monster_speed_walk) \
-    /**/ o(float, monster_speed_walk) \
-    /**/ i(entity, monster_target) \
-    /**/
-float monster_speed_run;
-float monster_speed_walk;
-entity monster_target;
-MUTATOR_HOOKABLE(MonsterMove, EV_MonsterMove);
-
-/** called when a monster looks for another target */
-MUTATOR_HOOKABLE(MonsterFindTarget, EV_NO_ARGS);
-
-/** called to change a random monster to a miniboss */
-MUTATOR_HOOKABLE(MonsterCheckBossFlag, EV_NO_ARGS);
-
-/**
- * called when a player tries to spawn a monster
- * return 1 to prevent spawning
- */
-MUTATOR_HOOKABLE(AllowMobSpawning, EV_NO_ARGS);
-
-/** called when a player gets damaged to e.g. remove stuff he was carrying. */
-#define EV_PlayerDamage_SplitHealthArmor(i, o) \
-    /**/ i(entity, frag_inflictor) \
-    /**/ i(entity, frag_attacker) \
-    /** same as self */ i(entity, frag_target) \
-    /** NOTE: this force already HAS been applied */ i(vector, damage_force) \
-    /**/ i(float, damage_take) \
-    /**/ o(float, damage_take) \
-       /**/ i(float, damage_save) \
-    /**/ o(float, damage_save) \
-    /**/
-vector damage_force;
-float damage_take;
-float damage_save;
-MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor, EV_PlayerDamage_SplitHealthArmor);
-
-/**
- * called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier
- * i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
- */
-#define EV_PlayerDamage_Calculate(i, o) \
-    /**/ i(entity, frag_attacker) \
-    /**/ i(entity, frag_target) \
-    /**/ i(float, frag_deathtype) \
-       /**/ i(float, frag_damage) \
-    /**/ o(float, frag_damage) \
-       /**/ i(float, frag_mirrordamage) \
-    /**/ o(float, frag_mirrordamage) \
-    /**/ i(vector, frag_force) \
-    /**/ o(vector, frag_force) \
-    /**/
-float frag_damage;
-float frag_mirrordamage;
-vector frag_force;
-MUTATOR_HOOKABLE(PlayerDamage_Calculate, EV_PlayerDamage_Calculate);
-
-/** called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items. */
-#define EV_PlayerPowerups(i, o) \
-    /**/ i(entity, self) \
-    /**/ i(int, olditems) \
-    /**/
-int olditems;
-MUTATOR_HOOKABLE(PlayerPowerups, EV_PlayerPowerups);
-
-/**
- * called every player think frame
- * return 1 to disable regen
- */
-#define EV_PlayerRegen(i, o) \
-    /**/ i(float, regen_mod_max) \
-    /**/ o(float, regen_mod_max) \
-    /**/ i(float, regen_mod_regen) \
-    /**/ o(float, regen_mod_regen) \
-    /**/ i(float, regen_mod_rot) \
-    /**/ o(float, regen_mod_rot) \
-    /**/ i(float, regen_mod_limit) \
-    /**/ o(float, regen_mod_limit) \
-    /**/
-float regen_mod_max;
-float regen_mod_regen;
-float regen_mod_rot;
-float regen_mod_limit;
-MUTATOR_HOOKABLE(PlayerRegen, EV_PlayerRegen);
-
-/**
- * called when the use key is pressed
- * if MUTATOR_RETURNVALUE is 1, don't do anything
- * return 1 if the use key actually did something
- */
-MUTATOR_HOOKABLE(PlayerUseKey, EV_NO_ARGS);
-
-/**
- * called when a client command is parsed
- * NOTE: hooks MUST start with if(MUTATOR_RETURNVALUE) return 0;
- * NOTE: return 1 if you handled the command, return 0 to continue handling
- * NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
- * // example:
- * MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
- * {
- *     if (MUTATOR_RETURNVALUE) // command was already handled?
- *         return false;
- *     if (cmd_name == "echocvar" && cmd_argc >= 2)
- *     {
- *         print(cvar_string(argv(1)), "\n");
- *         return true;
- *     }
- *     if (cmd_name == "echostring" && cmd_argc >= 2)
- *     {
- *         print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
- *         return true;
- *     }
- *     return false;
- * }
- */
-#define EV_SV_ParseClientCommand(i, o) \
-    /** command name */ i(string, cmd_name) \
-    /** also, argv() can be used */ i(int, cmd_argc) \
-    /** whole command, use only if you really have to */ i(string, cmd_string) \
-    /**/
-string cmd_name;
-int cmd_argc;
-string cmd_string;
-MUTATOR_HOOKABLE(SV_ParseClientCommand, EV_SV_ParseClientCommand);
-
-/**
- * called when a spawnpoint is being evaluated
- * return 1 to make the spawnpoint unusable
- */
-#define EV_Spawn_Score(i, o) \
-    /** player wanting to spawn */ i(entity, self) \
-    /** spot to be evaluated */ i(entity, spawn_spot) \
-    /** _x is priority, _y is "distance" */ i(vector, spawn_score) \
-    /**/ o(vector, spawn_score) \
-    /**/
-vector spawn_score;
-MUTATOR_HOOKABLE(Spawn_Score, EV_Spawn_Score);
-
-/** runs globally each server frame */
-MUTATOR_HOOKABLE(SV_StartFrame, EV_NO_ARGS);
-
-#define EV_SetModname(i, o) \
-    /** name of the mutator/mod if it warrants showing as such in the server browser */ \
-    o(string, modname) \
-    /**/
-MUTATOR_HOOKABLE(SetModname, EV_SetModname);
-
-/**
- * called for each item being spawned on a map, including dropped weapons
- * return 1 to remove an item
- */
-#define EV_Item_Spawn(i, o) \
-    /** the item */ i(entity, self) \
-    /**/
-MUTATOR_HOOKABLE(Item_Spawn, EV_Item_Spawn);
-
-#define EV_SetWeaponreplace(i, o) \
-    /** map entity */ i(entity, self) \
-    /** weapon info */ i(entity, other) \
-    /**/ i(string, ret_string) \
-    /**/ o(string, ret_string) \
-    /**/
-MUTATOR_HOOKABLE(SetWeaponreplace, EV_SetWeaponreplace);
-
-/** called when an item is about to respawn */
-#define EV_Item_RespawnCountdown(i, o) \
-    /**/ i(string, item_name) \
-    /**/ o(string, item_name) \
-    /**/ i(vector, item_color) \
-    /**/ o(vector, item_color) \
-    /**/
-string item_name;
-vector item_color;
-MUTATOR_HOOKABLE(Item_RespawnCountdown, EV_Item_RespawnCountdown);
-
-/** called when a bot checks a target to attack */
-#define EV_BotShouldAttack(i, o) \
-    /**/ i(entity, checkentity) \
-    /**/
-entity checkentity;
-MUTATOR_HOOKABLE(BotShouldAttack, EV_BotShouldAttack);
-
-/**
- * called whenever a player goes through a portal gun teleport
- * allows you to strip a player of an item if they go through the teleporter to help prevent cheating
- */
-#define EV_PortalTeleport(i, o) \
-    /**/ i(entity, self) \
-    /**/
-MUTATOR_HOOKABLE(PortalTeleport, EV_PortalTeleport);
-
-/**
- * called whenever a player uses impulse 33 (help me) in cl_impulse.qc
- * normally help me ping uses self.waypointsprite_attachedforcarrier,
- * but if your mutator uses something different then you can handle it
- * in a special manner using this hook
- */
-#define EV_HelpMePing(i, o) \
-    /** the player who pressed impulse 33 */ i(entity, self) \
-    /**/
-MUTATOR_HOOKABLE(HelpMePing, EV_HelpMePing);
-
-/**
- * called when a vehicle initializes
- * return true to remove the vehicle
- */
-MUTATOR_HOOKABLE(VehicleSpawn, EV_NO_ARGS);
-
-/**
- * called when a player enters a vehicle
- * allows mutators to set special settings in this event
- */
-#define EV_VehicleEnter(i, o) \
-    /** player */ i(entity, vh_player) \
-    /** vehicle */ i(entity, vh_vehicle) \
-    /**/
-entity vh_player;
-entity vh_vehicle;
-MUTATOR_HOOKABLE(VehicleEnter, EV_VehicleEnter);
-
-/**
- * called when a player touches a vehicle
- * return true to stop player from entering the vehicle
- */
-#define EV_VehicleTouch(i, o) \
-    /** vehicle */ i(entity, self) \
-    /** player */ i(entity, other) \
-    /**/
-MUTATOR_HOOKABLE(VehicleTouch, EV_VehicleTouch);
-
-/**
- * called when a player exits a vehicle
- * allows mutators to set special settings in this event
- */
-#define EV_VehicleExit(i, o) \
-    /** player */ i(entity, vh_player) \
-    /** vehicle */ i(entity, vh_vehicle) \
-    /**/
-MUTATOR_HOOKABLE(VehicleExit, EV_VehicleExit);
-
-/** called when a speedrun is aborted and the player is teleported back to start position */
-#define EV_AbortSpeedrun(i, o) \
-    /** player */ i(entity, self) \
-    /**/
-MUTATOR_HOOKABLE(AbortSpeedrun, EV_AbortSpeedrun);
-
-/** called at when a item is touched. Called early, can edit item properties. */
-#define EV_ItemTouch(i, o) \
-    /** item */ i(entity, self) \
-    /** player */ i(entity, other) \
-    /**/
-MUTATOR_HOOKABLE(ItemTouch, EV_ItemTouch);
-
-enum {
-       MUT_ITEMTOUCH_CONTINUE, // return this flag to make the function continue as normal
-       MUT_ITEMTOUCH_RETURN, // return this flag to make the function return (handled entirely by mutator)
-       MUT_ITEMTOUCH_PICKUP // return this flag to have the item "picked up" and taken even after mutator handled it
-};
-
-/** called at when a player connect */
-#define EV_ClientConnect(i, o) \
-    /** player */ i(entity, self) \
-    /**/
-MUTATOR_HOOKABLE(ClientConnect, EV_ClientConnect);
-
-#define EV_HavocBot_ChooseRole(i, o) \
-    /**/ i(entity, self) \
-    /**/
-MUTATOR_HOOKABLE(HavocBot_ChooseRole, EV_HavocBot_ChooseRole);
-
-/** called when a target is checked for accuracy */
-#define EV_AccuracyTargetValid(i, o) \
-    /** attacker */ i(entity, frag_attacker) \
-    /** target */ i(entity, frag_target) \
-    /**/
-MUTATOR_HOOKABLE(AccuracyTargetValid, EV_AccuracyTargetValid);
-enum {
-       MUT_ACCADD_VALID, // return this flag to make the function continue if target is a client
-       MUT_ACCADD_INVALID, // return this flag to make the function always continue
-       MUT_ACCADD_INDIFFERENT // return this flag to make the function always return
-};
-#endif
diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh
new file mode 100644 (file)
index 0000000..52be590
--- /dev/null
@@ -0,0 +1,480 @@
+#ifndef SERVER_MUTATORS_EVENTS_H
+#define SERVER_MUTATORS_EVENTS_H
+
+#include "../../common/mutators/base.qh"
+
+// register all possible hooks here
+
+/** called when a player becomes observer, after shared setup */
+#define EV_MakePlayerObserver(i, o) \
+    /**/
+MUTATOR_HOOKABLE(MakePlayerObserver, EV_MakePlayerObserver)
+
+/** */
+#define EV_PutClientInServer(i, o) \
+    /** client wanting to spawn */ i(entity, self) \
+    /**/
+MUTATOR_HOOKABLE(PutClientInServer, EV_PutClientInServer);
+
+/** called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here) */
+#define EV_PlayerSpawn(i, o) \
+    /** spot that was used, or world */ i(entity, spawn_spot) \
+    /**/
+entity spawn_spot;
+MUTATOR_HOOKABLE(PlayerSpawn, EV_PlayerSpawn);
+
+/** called in reset_map */
+#define EV_reset_map_global(i, o) \
+    /**/
+MUTATOR_HOOKABLE(reset_map_global, EV_reset_map_global);
+
+/** called in reset_map */
+#define EV_reset_map_players(i, o) \
+    /**/
+MUTATOR_HOOKABLE(reset_map_players, EV_reset_map_players);
+
+/** returns 1 if clearing player score shall not be allowed */
+#define EV_ForbidPlayerScore_Clear(i, o) \
+    /**/
+MUTATOR_HOOKABLE(ForbidPlayerScore_Clear, EV_ForbidPlayerScore_Clear);
+
+/** called when a player disconnects */
+#define EV_ClientDisconnect(i, o) \
+    /**/
+MUTATOR_HOOKABLE(ClientDisconnect, EV_ClientDisconnect);
+
+/** called when a player dies to e.g. remove stuff he was carrying. */
+#define EV_PlayerDies(i, o) \
+    /**/ i(entity, frag_inflictor) \
+    /**/ i(entity, frag_attacker) \
+    /** same as self */ i(entity, frag_target) \
+    /**/ i(int, frag_deathtype) \
+    /**/
+entity frag_inflictor;
+entity frag_attacker;
+entity frag_target;
+int frag_deathtype;
+MUTATOR_HOOKABLE(PlayerDies, EV_PlayerDies);
+
+/** called when a player presses the jump key */
+#define EV_PlayerJump(i, o) \
+    /**/ i(float, player_multijump) \
+    /**/ i(float, player_jumpheight) \
+    /**/ o(float, player_multijump) \
+    /**/ o(float, player_jumpheight) \
+    /**/
+float player_multijump;
+float player_jumpheight;
+MUTATOR_HOOKABLE(PlayerJump, EV_PlayerJump);
+
+/** called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill */
+#define EV_GiveFragsForKill(i, o) \
+    /** same as self */ i(entity, frag_attacker) \
+    /**/ i(entity, frag_target) \
+    /**/ i(float, frag_score) \
+    /**/ o(float, frag_score) \
+    /**/
+float frag_score;
+MUTATOR_HOOKABLE(GiveFragsForKill, EV_GiveFragsForKill);
+
+/** called when the match ends */
+MUTATOR_HOOKABLE(MatchEnd, EV_NO_ARGS);
+
+/** should adjust ret_float to contain the team count */
+#define EV_GetTeamCount(i, o) \
+    /**/ i(float, ret_float) \
+    /**/ o(float, ret_float) \
+    /**/
+float ret_float;
+MUTATOR_HOOKABLE(GetTeamCount, EV_GetTeamCount);
+
+/** copies variables for spectating "other" to "self" */
+#define EV_SpectateCopy(i, o) \
+    /**/ i(entity, other) \
+    /**/ i(entity, self) \
+    /**/
+MUTATOR_HOOKABLE(SpectateCopy, EV_SpectateCopy);
+
+/** returns 1 if throwing the current weapon shall not be allowed */
+MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon, EV_NO_ARGS);
+
+/** allows changing attack rate */
+#define EV_WeaponRateFactor(i, o) \
+    /**/ i(float, weapon_rate) \
+    /**/ o(float, weapon_rate) \
+    /**/
+float weapon_rate;
+MUTATOR_HOOKABLE(WeaponRateFactor, EV_WeaponRateFactor);
+
+/** allows changing weapon speed (projectiles mostly) */
+#define EV_WeaponSpeedFactor(i, o) \
+    /**/ i(float, ret_float) \
+    /**/ o(float, ret_float) \
+    /**/
+MUTATOR_HOOKABLE(WeaponSpeedFactor, EV_WeaponSpeedFactor);
+
+/** adjusts {warmup_}start_{items,weapons,ammo_{cells,plasma,rockets,nails,shells,fuel}} */
+MUTATOR_HOOKABLE(SetStartItems, EV_NO_ARGS);
+
+/** called every frame. customizes the waypoint for spectators */
+#define EV_CustomizeWaypoint(i, o) \
+    /** waypoint */ i(entity, self) \
+    /** player; other.enemy = spectator */ i(entity, other) \
+    /**/
+MUTATOR_HOOKABLE(CustomizeWaypoint, EV_CustomizeWaypoint);
+
+/**
+ * checks if the current item may be spawned (self.items and self.weapons may be read and written to, as well as the ammo_ fields)
+ * return error to request removal
+ */
+MUTATOR_HOOKABLE(FilterItem, EV_NO_ARGS);
+
+/** return error to request removal */
+#define EV_TurretSpawn(i, o) \
+    /** turret */ i(entity, self) \
+    /**/
+MUTATOR_HOOKABLE(TurretSpawn, EV_TurretSpawn);
+
+/** return error to prevent entity spawn, or modify the entity */
+MUTATOR_HOOKABLE(OnEntityPreSpawn, EV_NO_ARGS);
+
+/** runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators */
+MUTATOR_HOOKABLE(PlayerPreThink, EV_NO_ARGS);
+
+/** TODO change this into a general PlayerPostThink hook? */
+MUTATOR_HOOKABLE(GetPressedKeys, EV_NO_ARGS);
+
+/**
+ * called before any player physics, may adjust variables for movement,
+ * is run AFTER bot code and idle checking
+ */
+MUTATOR_HOOKABLE(PlayerPhysics, EV_NO_ARGS);
+
+/** is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client */
+#define EV_GetCvars(i, o) \
+    /**/ i(float, get_cvars_f) \
+    /**/ i(string, get_cvars_s) \
+    /**/
+float get_cvars_f;
+string get_cvars_s;
+MUTATOR_HOOKABLE(GetCvars, EV_NO_ARGS); // NOTE: Can't use EV_GetCvars because of `SZ_GetSpace: overflow`
+
+/** can edit any "just fired" projectile */
+#define EV_EditProjectile(i, o) \
+    /**/ i(entity, self) \
+    /**/ i(entity, other) \
+    /**/
+MUTATOR_HOOKABLE(EditProjectile, EV_EditProjectile);
+
+/** called when a monster spawns */
+MUTATOR_HOOKABLE(MonsterSpawn, EV_NO_ARGS);
+
+/** called when a monster dies */
+#define EV_MonsterDies(i, o) \
+    /**/ i(entity, frag_attacker) \
+    /**/
+MUTATOR_HOOKABLE(MonsterDies, EV_MonsterDies);
+
+/** called when a monster wants to respawn */
+#define EV_MonsterRespawn(i, o) \
+    /**/ i(entity, other) \
+    /**/
+MUTATOR_HOOKABLE(MonsterRespawn, EV_MonsterRespawn);
+
+/** called when a monster is dropping loot */
+#define EV_MonsterDropItem(i, o) \
+    /**/ i(entity, other) \
+    /**/ o(entity, other) \
+    /**/
+.void() monster_loot;
+MUTATOR_HOOKABLE(MonsterDropItem, EV_MonsterDropItem);
+
+/**
+ * called when a monster moves
+ * returning true makes the monster stop
+ */
+#define EV_MonsterMove(i, o) \
+    /**/ i(float, monster_speed_run) \
+    /**/ o(float, monster_speed_run) \
+    /**/ i(float, monster_speed_walk) \
+    /**/ o(float, monster_speed_walk) \
+    /**/ i(entity, monster_target) \
+    /**/
+float monster_speed_run;
+float monster_speed_walk;
+entity monster_target;
+MUTATOR_HOOKABLE(MonsterMove, EV_MonsterMove);
+
+/** called when a monster looks for another target */
+MUTATOR_HOOKABLE(MonsterFindTarget, EV_NO_ARGS);
+
+/** called to change a random monster to a miniboss */
+MUTATOR_HOOKABLE(MonsterCheckBossFlag, EV_NO_ARGS);
+
+/**
+ * called when a player tries to spawn a monster
+ * return 1 to prevent spawning
+ */
+MUTATOR_HOOKABLE(AllowMobSpawning, EV_NO_ARGS);
+
+/** called when a player gets damaged to e.g. remove stuff he was carrying. */
+#define EV_PlayerDamage_SplitHealthArmor(i, o) \
+    /**/ i(entity, frag_inflictor) \
+    /**/ i(entity, frag_attacker) \
+    /** same as self */ i(entity, frag_target) \
+    /** NOTE: this force already HAS been applied */ i(vector, damage_force) \
+    /**/ i(float, damage_take) \
+    /**/ o(float, damage_take) \
+       /**/ i(float, damage_save) \
+    /**/ o(float, damage_save) \
+    /**/
+vector damage_force;
+float damage_take;
+float damage_save;
+MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor, EV_PlayerDamage_SplitHealthArmor);
+
+/**
+ * called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier
+ * i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
+ */
+#define EV_PlayerDamage_Calculate(i, o) \
+    /**/ i(entity, frag_attacker) \
+    /**/ i(entity, frag_target) \
+    /**/ i(float, frag_deathtype) \
+       /**/ i(float, frag_damage) \
+    /**/ o(float, frag_damage) \
+       /**/ i(float, frag_mirrordamage) \
+    /**/ o(float, frag_mirrordamage) \
+    /**/ i(vector, frag_force) \
+    /**/ o(vector, frag_force) \
+    /**/
+float frag_damage;
+float frag_mirrordamage;
+vector frag_force;
+MUTATOR_HOOKABLE(PlayerDamage_Calculate, EV_PlayerDamage_Calculate);
+
+/** called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items. */
+#define EV_PlayerPowerups(i, o) \
+    /**/ i(entity, self) \
+    /**/ i(int, olditems) \
+    /**/
+int olditems;
+MUTATOR_HOOKABLE(PlayerPowerups, EV_PlayerPowerups);
+
+/**
+ * called every player think frame
+ * return 1 to disable regen
+ */
+#define EV_PlayerRegen(i, o) \
+    /**/ i(float, regen_mod_max) \
+    /**/ o(float, regen_mod_max) \
+    /**/ i(float, regen_mod_regen) \
+    /**/ o(float, regen_mod_regen) \
+    /**/ i(float, regen_mod_rot) \
+    /**/ o(float, regen_mod_rot) \
+    /**/ i(float, regen_mod_limit) \
+    /**/ o(float, regen_mod_limit) \
+    /**/
+float regen_mod_max;
+float regen_mod_regen;
+float regen_mod_rot;
+float regen_mod_limit;
+MUTATOR_HOOKABLE(PlayerRegen, EV_PlayerRegen);
+
+/**
+ * called when the use key is pressed
+ * if MUTATOR_RETURNVALUE is 1, don't do anything
+ * return 1 if the use key actually did something
+ */
+MUTATOR_HOOKABLE(PlayerUseKey, EV_NO_ARGS);
+
+/**
+ * called when a client command is parsed
+ * NOTE: hooks MUST start with if(MUTATOR_RETURNVALUE) return 0;
+ * NOTE: return 1 if you handled the command, return 0 to continue handling
+ * NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
+ * // example:
+ * MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
+ * {
+ *     if (MUTATOR_RETURNVALUE) // command was already handled?
+ *         return false;
+ *     if (cmd_name == "echocvar" && cmd_argc >= 2)
+ *     {
+ *         print(cvar_string(argv(1)), "\n");
+ *         return true;
+ *     }
+ *     if (cmd_name == "echostring" && cmd_argc >= 2)
+ *     {
+ *         print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
+ *         return true;
+ *     }
+ *     return false;
+ * }
+ */
+#define EV_SV_ParseClientCommand(i, o) \
+    /** command name */ i(string, cmd_name) \
+    /** also, argv() can be used */ i(int, cmd_argc) \
+    /** whole command, use only if you really have to */ i(string, cmd_string) \
+    /**/
+string cmd_name;
+int cmd_argc;
+string cmd_string;
+MUTATOR_HOOKABLE(SV_ParseClientCommand, EV_SV_ParseClientCommand);
+
+/**
+ * called when a spawnpoint is being evaluated
+ * return 1 to make the spawnpoint unusable
+ */
+#define EV_Spawn_Score(i, o) \
+    /** player wanting to spawn */ i(entity, self) \
+    /** spot to be evaluated */ i(entity, spawn_spot) \
+    /** _x is priority, _y is "distance" */ i(vector, spawn_score) \
+    /**/ o(vector, spawn_score) \
+    /**/
+vector spawn_score;
+MUTATOR_HOOKABLE(Spawn_Score, EV_Spawn_Score);
+
+/** runs globally each server frame */
+MUTATOR_HOOKABLE(SV_StartFrame, EV_NO_ARGS);
+
+#define EV_SetModname(i, o) \
+    /** name of the mutator/mod if it warrants showing as such in the server browser */ \
+    o(string, modname) \
+    /**/
+MUTATOR_HOOKABLE(SetModname, EV_SetModname);
+
+/**
+ * called for each item being spawned on a map, including dropped weapons
+ * return 1 to remove an item
+ */
+#define EV_Item_Spawn(i, o) \
+    /** the item */ i(entity, self) \
+    /**/
+MUTATOR_HOOKABLE(Item_Spawn, EV_Item_Spawn);
+
+#define EV_SetWeaponreplace(i, o) \
+    /** map entity */ i(entity, self) \
+    /** weapon info */ i(entity, other) \
+    /**/ i(string, ret_string) \
+    /**/ o(string, ret_string) \
+    /**/
+MUTATOR_HOOKABLE(SetWeaponreplace, EV_SetWeaponreplace);
+
+/** called when an item is about to respawn */
+#define EV_Item_RespawnCountdown(i, o) \
+    /**/ i(string, item_name) \
+    /**/ o(string, item_name) \
+    /**/ i(vector, item_color) \
+    /**/ o(vector, item_color) \
+    /**/
+string item_name;
+vector item_color;
+MUTATOR_HOOKABLE(Item_RespawnCountdown, EV_Item_RespawnCountdown);
+
+/** called when a bot checks a target to attack */
+#define EV_BotShouldAttack(i, o) \
+    /**/ i(entity, checkentity) \
+    /**/
+entity checkentity;
+MUTATOR_HOOKABLE(BotShouldAttack, EV_BotShouldAttack);
+
+/**
+ * called whenever a player goes through a portal gun teleport
+ * allows you to strip a player of an item if they go through the teleporter to help prevent cheating
+ */
+#define EV_PortalTeleport(i, o) \
+    /**/ i(entity, self) \
+    /**/
+MUTATOR_HOOKABLE(PortalTeleport, EV_PortalTeleport);
+
+/**
+ * called whenever a player uses impulse 33 (help me) in cl_impulse.qc
+ * normally help me ping uses self.waypointsprite_attachedforcarrier,
+ * but if your mutator uses something different then you can handle it
+ * in a special manner using this hook
+ */
+#define EV_HelpMePing(i, o) \
+    /** the player who pressed impulse 33 */ i(entity, self) \
+    /**/
+MUTATOR_HOOKABLE(HelpMePing, EV_HelpMePing);
+
+/**
+ * called when a vehicle initializes
+ * return true to remove the vehicle
+ */
+MUTATOR_HOOKABLE(VehicleSpawn, EV_NO_ARGS);
+
+/**
+ * called when a player enters a vehicle
+ * allows mutators to set special settings in this event
+ */
+#define EV_VehicleEnter(i, o) \
+    /** player */ i(entity, vh_player) \
+    /** vehicle */ i(entity, vh_vehicle) \
+    /**/
+entity vh_player;
+entity vh_vehicle;
+MUTATOR_HOOKABLE(VehicleEnter, EV_VehicleEnter);
+
+/**
+ * called when a player touches a vehicle
+ * return true to stop player from entering the vehicle
+ */
+#define EV_VehicleTouch(i, o) \
+    /** vehicle */ i(entity, self) \
+    /** player */ i(entity, other) \
+    /**/
+MUTATOR_HOOKABLE(VehicleTouch, EV_VehicleTouch);
+
+/**
+ * called when a player exits a vehicle
+ * allows mutators to set special settings in this event
+ */
+#define EV_VehicleExit(i, o) \
+    /** player */ i(entity, vh_player) \
+    /** vehicle */ i(entity, vh_vehicle) \
+    /**/
+MUTATOR_HOOKABLE(VehicleExit, EV_VehicleExit);
+
+/** called when a speedrun is aborted and the player is teleported back to start position */
+#define EV_AbortSpeedrun(i, o) \
+    /** player */ i(entity, self) \
+    /**/
+MUTATOR_HOOKABLE(AbortSpeedrun, EV_AbortSpeedrun);
+
+/** called at when a item is touched. Called early, can edit item properties. */
+#define EV_ItemTouch(i, o) \
+    /** item */ i(entity, self) \
+    /** player */ i(entity, other) \
+    /**/
+MUTATOR_HOOKABLE(ItemTouch, EV_ItemTouch);
+
+enum {
+       MUT_ITEMTOUCH_CONTINUE, // return this flag to make the function continue as normal
+       MUT_ITEMTOUCH_RETURN, // return this flag to make the function return (handled entirely by mutator)
+       MUT_ITEMTOUCH_PICKUP // return this flag to have the item "picked up" and taken even after mutator handled it
+};
+
+/** called at when a player connect */
+#define EV_ClientConnect(i, o) \
+    /** player */ i(entity, self) \
+    /**/
+MUTATOR_HOOKABLE(ClientConnect, EV_ClientConnect);
+
+#define EV_HavocBot_ChooseRole(i, o) \
+    /**/ i(entity, self) \
+    /**/
+MUTATOR_HOOKABLE(HavocBot_ChooseRole, EV_HavocBot_ChooseRole);
+
+/** called when a target is checked for accuracy */
+#define EV_AccuracyTargetValid(i, o) \
+    /** attacker */ i(entity, frag_attacker) \
+    /** target */ i(entity, frag_target) \
+    /**/
+MUTATOR_HOOKABLE(AccuracyTargetValid, EV_AccuracyTargetValid);
+enum {
+       MUT_ACCADD_VALID, // return this flag to make the function continue if target is a client
+       MUT_ACCADD_INVALID, // return this flag to make the function always continue
+       MUT_ACCADD_INDIFFERENT // return this flag to make the function always return
+};
+#endif
index 36bf631bbd3551608130cabe1a10ff80f6e649a7..f23f42a8924dd717ab63e900f57d13be6ea0f4ff 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef MUTATOR_H
 #define MUTATOR_H
 
-#include "base.qh"
+#include "../../common/mutators/base.qh"
 #include "mutator_nades.qh"
 
 #include "../cl_client.qh"
index e139865ab56395936c000fe3e28a6981d8f553a5..d0fe0a60a846ec78c2785875369ba785dbf45e24 100644 (file)
@@ -79,7 +79,7 @@
     #include "../vehicles/all.qh"
 #endif
 
-#include "base.qc"
+#include "../../common/mutators/base.qh"
 #include "gamemode_assault.qc"
 #include "gamemode_ca.qc"
 #include "gamemode_ctf.qc"
index da723d927963bbfec2941394dd2dcbe736e9b07e..44e51828b1d2db962ede2865efad9bf77747581d 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef MUTATORS_INCLUDE_H
 #define MUTATORS_INCLUDE_H
 
-#include "base.qh"
+#include "../../common/mutators/base.qh"
 #include "mutators.qh"
 #include "gamemode_assault.qh"
 #include "gamemode_ca.qh"
index 3143699f2d7b18064466b4e3df3714850cd590c4..5b8dfd4989b84076a3d0e37ebf5c2a12fada9b69 100644 (file)
@@ -12,6 +12,7 @@
 var float(string name) cvar;
 var string(string name) cvar_string;
 var void(string name, string value) cvar_set;
+var void remove(entity e);
 
 #pragma noref 0