From: TimePath Date: Sat, 15 Aug 2015 09:40:46 +0000 (+1000) Subject: Convert more calls X-Git-Tag: xonotic-v0.8.2~2071^2~1 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fe5ae130b2124c7abc32aee4cd0b5c8584c0dbc4;p=xonotic%2Fxonotic-data.pk3dir.git Convert more calls --- diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index eec507f07..cc8e19673 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -888,11 +888,6 @@ void SV_ParseClientCommand(string command) float argc = tokenize_console(command); - // for the mutator hook system - cmd_name = strtolower(argv(0)); - cmd_argc = argc; - cmd_string = command; - // Guide for working with argc arguments by example: // argc: 1 - 2 - 3 - 4 // argv: 0 - 1 - 2 - 3 @@ -941,7 +936,7 @@ void SV_ParseClientCommand(string command) return; } } - else if(MUTATOR_CALLHOOK(SV_ParseClientCommand)) + else if(MUTATOR_CALLHOOK(SV_ParseClientCommand, strtolower(argv(0)), argc, command)) { return; // handled by a mutator } diff --git a/qcsrc/server/mutators/base.qh b/qcsrc/server/mutators/base.qh index 478a0b963..9ffd08e8c 100644 --- a/qcsrc/server/mutators/base.qh +++ b/qcsrc/server/mutators/base.qh @@ -370,85 +370,104 @@ 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 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(SV_ParseClientCommand, 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() - // INPUT - string cmd_name; // command name - int cmd_argc; // also, argv() can be used - string cmd_string; // whole command, use only if you really have to - /* - // example: - MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand) - { - if(MUTATOR_RETURNVALUE) // command was already handled? - return 0; - if(cmd_name == "echocvar" && cmd_argc >= 2) - { - print(cvar_string(argv(1)), "\n"); - return 1; - } - 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 1; - } - return 0; - } - */ - -MUTATOR_HOOKABLE(Spawn_Score, EV_NO_ARGS); - // called when a spawnpoint is being evaluated - // return 1 to make the spawnpoint unusable - // INPUT -// entity self; // player wanting to spawn -// entity spawn_spot; // spot to be evaluated - // IN+OUT - vector spawn_score; // _x is priority, _y is "distance" +/** + * 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); - // runs globally each server frame -MUTATOR_HOOKABLE(SetModname, EV_NO_ARGS); - // OUT -// string modname; // name of the mutator/mod if it warrants showing as such in the server browser +#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); -MUTATOR_HOOKABLE(Item_Spawn, EV_NO_ARGS); - // called for each item being spawned on a map, including dropped weapons - // return 1 to remove an item - // INPUT -// entity self; // the item +/** + * 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); -MUTATOR_HOOKABLE(SetWeaponreplace, EV_NO_ARGS); - // IN -// entity self; // map entity -// entity other; // weapon info - // IN+OUT -// string ret_string; +#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 */ MUTATOR_HOOKABLE(Item_RespawnCountdown, EV_NO_ARGS); - // called when an item is about to respawn // INPUT+OUTPUT: string item_name; vector item_color; +/** called when a bot checks a target to attack */ MUTATOR_HOOKABLE(BotShouldAttack, EV_NO_ARGS); - // called when a bot checks a target to attack // INPUT entity checkentity; -MUTATOR_HOOKABLE(PortalTeleport, EV_NO_ARGS); - // 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 - // INPUT -// entity self; +/** + * 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); MUTATOR_HOOKABLE(HelpMePing, EV_NO_ARGS); // called whenever a player uses impulse 33 (help me) in cl_impulse.qc diff --git a/qcsrc/server/mutators/mutator_buffs.qc b/qcsrc/server/mutators/mutator_buffs.qc index 170f59874..b582e1686 100644 --- a/qcsrc/server/mutators/mutator_buffs.qc +++ b/qcsrc/server/mutators/mutator_buffs.qc @@ -629,7 +629,7 @@ MUTATOR_HOOKFUNCTION(buffs_PlayerThrowKey) if(closest.flagcarried) { ctf_Handle_Throw(closest, world, DROP_THROW); } if(closest.nade) { toss_nade(closest, '0 0 0', time + 0.05); } - MUTATOR_CALLHOOK(PortalTeleport); // initiate flag dropper + MUTATOR_CALLHOOK(PortalTeleport, self); // initiate flag dropper setorigin(self, their_org); setorigin(closest, my_org); diff --git a/qcsrc/server/mutators/mutator_nades.qc b/qcsrc/server/mutators/mutator_nades.qc index f4267716e..40f4f7247 100644 --- a/qcsrc/server/mutators/mutator_nades.qc +++ b/qcsrc/server/mutators/mutator_nades.qc @@ -360,11 +360,7 @@ void nade_translocate_boom() makevectors(self.realowner.angles); - entity oldself = self; - self = self.realowner; - MUTATOR_CALLHOOK(PortalTeleport); - self.realowner = self; - self = oldself; + MUTATOR_CALLHOOK(PortalTeleport, self.realowner); TeleportPlayer(self, self.realowner, locout, self.realowner.angles, v_forward * vlen(self.realowner.velocity), '0 0 0', '0 0 0', TELEPORT_FLAGS_TELEPORTER); } diff --git a/qcsrc/server/portals.qc b/qcsrc/server/portals.qc index ad8aea50c..438ff00d3 100644 --- a/qcsrc/server/portals.qc +++ b/qcsrc/server/portals.qc @@ -170,11 +170,7 @@ float Portal_TeleportPlayer(entity teleporter, entity player) // factor -1 allows chaining portals, but may be weird player.right_vector = -1 * AnglesTransform_Apply(transform, player.right_vector); - entity oldself = self; - self = player; - MUTATOR_CALLHOOK(PortalTeleport); - player = self; - self = oldself; + MUTATOR_CALLHOOK(PortalTeleport, player); if (!teleporter.enemy) { diff --git a/qcsrc/server/spawnpoints.qc b/qcsrc/server/spawnpoints.qc index b86da6b54..bc191f74f 100644 --- a/qcsrc/server/spawnpoints.qc +++ b/qcsrc/server/spawnpoints.qc @@ -228,7 +228,7 @@ vector Spawn_Score(entity spot, float mindist, float teamcheck) } } - MUTATOR_CALLHOOK(Spawn_Score); + MUTATOR_CALLHOOK(Spawn_Score, self, spawn_spot, spawn_score); return spawn_score; } diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index 873f7a53c..ffcf7624d 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -1358,7 +1358,7 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, self.SendFlags |= ISF_ANGLES; // call this hook after everything else has been done - if(MUTATOR_CALLHOOK(Item_Spawn)) + if(MUTATOR_CALLHOOK(Item_Spawn, self)) { startitem_failed = true; remove(self); diff --git a/qcsrc/server/weapons/spawning.qc b/qcsrc/server/weapons/spawning.qc index 9096b2f9c..8e7810bbb 100644 --- a/qcsrc/server/weapons/spawning.qc +++ b/qcsrc/server/weapons/spawning.qc @@ -55,9 +55,7 @@ void weapon_defaultspawnfunc(float wpn) } s = W_Apply_Weaponreplace(e.netname); - ret_string = s; - other = e; - MUTATOR_CALLHOOK(SetWeaponreplace); + MUTATOR_CALLHOOK(SetWeaponreplace, self, e, s); s = ret_string; if(s == "") {