From: terencehill Date: Sun, 20 Mar 2022 15:27:35 +0000 (+0100) Subject: Offset Resource hook args to avoid conflicts as much as possible with other hooks X-Git-Tag: xonotic-v0.8.5~146 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1755790c0;p=xonotic%2Fxonotic-data.pk3dir.git Offset Resource hook args to avoid conflicts as much as possible with other hooks --- diff --git a/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc b/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc index f6a393b9b..2abb0b596 100644 --- a/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc +++ b/qcsrc/common/mutators/mutator/instagib/sv_instagib.qc @@ -396,8 +396,6 @@ MUTATOR_HOOKFUNCTION(mutator_instagib, ItemTouch) if(hp < 100) SetResource(toucher, RES_HEALTH, 100); - // work around SetResource overriding M_ARGV(1, entity) - M_ARGV(1, entity) = toucher; return MUT_ITEMTOUCH_CONTINUE; } diff --git a/qcsrc/common/resources/sv_resources.qc b/qcsrc/common/resources/sv_resources.qc index 9984e9111..37805f852 100644 --- a/qcsrc/common/resources/sv_resources.qc +++ b/qcsrc/common/resources/sv_resources.qc @@ -65,7 +65,7 @@ float GetResourceLimit(entity e, Resource res_type) } } MUTATOR_CALLHOOK(GetResourceLimit, e, res_type, limit); - limit = M_ARGV(2, float); + limit = M_ARGV(9, float); if (limit > RES_AMOUNT_HARD_LIMIT) { limit = RES_AMOUNT_HARD_LIMIT; @@ -96,8 +96,8 @@ void SetResource(entity e, Resource res_type, float amount) { return; } - res_type = M_ARGV(1, entity); - amount = M_ARGV(2, float); + res_type = M_ARGV(8, entity); + amount = M_ARGV(9, float); float max_amount = GetResourceLimit(e, res_type); // TODO: should allow overriding these limits if cheats are enabled! float amount_wasted = 0; if (amount > max_amount && max_amount != RES_LIMIT_NONE) @@ -128,8 +128,8 @@ void GiveResource(entity receiver, Resource res_type, float amount) { return; } - res_type = M_ARGV(1, entity); - amount = M_ARGV(2, float); + res_type = M_ARGV(8, entity); + amount = M_ARGV(9, float); if (amount <= 0) { return; @@ -172,9 +172,9 @@ void GiveResourceWithLimit(entity receiver, Resource res_type, float amount, flo { return; } - res_type = M_ARGV(1, entity); - amount = M_ARGV(2, float); - limit = M_ARGV(3, float); + res_type = M_ARGV(8, entity); + amount = M_ARGV(9, float); + limit = M_ARGV(10, float); if (amount <= 0) { return; @@ -198,8 +198,8 @@ void TakeResource(entity receiver, Resource res_type, float amount) { return; } - res_type = M_ARGV(1, entity); - amount = M_ARGV(2, float); + res_type = M_ARGV(8, entity); + amount = M_ARGV(9, float); if (amount <= 0) { return; @@ -218,9 +218,9 @@ void TakeResourceWithLimit(entity receiver, Resource res_type, float amount, flo { return; } - res_type = M_ARGV(1, entity); - amount = M_ARGV(2, float); - limit = M_ARGV(3, float); + res_type = M_ARGV(8, entity); + amount = M_ARGV(9, float); + limit = M_ARGV(10, float); if (amount <= 0) { return; diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index e7ca8583f..6feb81132 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -714,24 +714,27 @@ enum { /**/ MUTATOR_HOOKABLE(ItemTouched, EV_ItemTouched); +// The Resource hooks are often called by other hooks and to avoid conflicts +// as much as possible their args start from ARGV_7 + /** Called when the amount of entity resources changes. Can be used to override resource limit. */ #define EV_GetResourceLimit(i, o) \ - /** checked entity */ i(entity, MUTATOR_ARGV_0_entity) \ - /** resource type */ i(entity, MUTATOR_ARGV_1_entity) \ - /** limit */ i(float, MUTATOR_ARGV_2_float) \ - /**/ o(float, MUTATOR_ARGV_2_float) \ + /** checked entity */ i(entity, MUTATOR_ARGV_7_entity) \ + /** resource type */ i(entity, MUTATOR_ARGV_8_entity) \ + /** limit */ i(float, MUTATOR_ARGV_9_float) \ + /**/ o(float, MUTATOR_ARGV_9_float) \ /**/ MUTATOR_HOOKABLE(GetResourceLimit, EV_GetResourceLimit); /** Called when the amount of resource of an entity changes. See RES_* constants for resource types. Return true to forbid the change. */ #define EV_SetResource(i, o) \ - /** checked entity */ i(entity, MUTATOR_ARGV_0_entity) \ - /** resource type */ i(entity, MUTATOR_ARGV_1_entity) \ - /**/ o(entity, MUTATOR_ARGV_1_entity) \ - /** amount */ i(float, MUTATOR_ARGV_2_float) \ - /**/ o(float, MUTATOR_ARGV_2_float) \ + /** checked entity */ i(entity, MUTATOR_ARGV_7_entity) \ + /** resource type */ i(entity, MUTATOR_ARGV_8_entity) \ + /**/ o(entity, MUTATOR_ARGV_8_entity) \ + /** amount */ i(float, MUTATOR_ARGV_9_float) \ + /**/ o(float, MUTATOR_ARGV_9_float) \ /**/ MUTATOR_HOOKABLE(SetResource, EV_SetResource); @@ -739,9 +742,9 @@ MUTATOR_HOOKABLE(SetResource, EV_SetResource); constants for resource types. Amount wasted is the amount of resource that is above resource limit so it was not given. */ #define EV_ResourceAmountChanged(i, o) \ - /** checked entity */ i(entity, MUTATOR_ARGV_0_entity) \ - /** resource type */ i(entity, MUTATOR_ARGV_1_entity) \ - /** amount */ i(float, MUTATOR_ARGV_2_float) \ + /** checked entity */ i(entity, MUTATOR_ARGV_7_entity) \ + /** resource type */ i(entity, MUTATOR_ARGV_8_entity) \ + /** amount */ i(float, MUTATOR_ARGV_9_float) \ /**/ MUTATOR_HOOKABLE(ResourceAmountChanged, EV_ResourceAmountChanged); @@ -749,9 +752,9 @@ MUTATOR_HOOKABLE(ResourceAmountChanged, EV_ResourceAmountChanged); limit. See RES_* constants for resource types. Amount wasted is the amount of resource that is above resource limit so it was not given. */ #define EV_ResourceWasted(i, o) \ - /** checked entity */ i(entity, MUTATOR_ARGV_0_entity) \ - /** resource type */ i(entity, MUTATOR_ARGV_1_entity) \ - /** amount wasted */ i(float, MUTATOR_ARGV_2_float) \ + /** checked entity */ i(entity, MUTATOR_ARGV_7_entity) \ + /** resource type */ i(entity, MUTATOR_ARGV_8_entity) \ + /** amount wasted */ i(float, MUTATOR_ARGV_9_float) \ /**/ MUTATOR_HOOKABLE(ResourceWasted, EV_ResourceWasted); @@ -759,24 +762,24 @@ MUTATOR_HOOKABLE(ResourceWasted, EV_ResourceWasted); for resource types. Return true to forbid giving. NOTE: This hook is also called by GiveResourceWithLimit */ #define EV_GiveResource(i, o) \ - /** receiver */ i(entity, MUTATOR_ARGV_0_entity) \ - /** resource type */ i(entity, MUTATOR_ARGV_1_entity) \ - /**/ o(entity, MUTATOR_ARGV_1_entity) \ - /** amount */ i(float, MUTATOR_ARGV_2_float) \ - /**/ o(float, MUTATOR_ARGV_2_float) \ + /** receiver */ i(entity, MUTATOR_ARGV_7_entity) \ + /** resource type */ i(entity, MUTATOR_ARGV_8_entity) \ + /**/ o(entity, MUTATOR_ARGV_8_entity) \ + /** amount */ i(float, MUTATOR_ARGV_9_float) \ + /**/ o(float, MUTATOR_ARGV_9_float) \ /**/ MUTATOR_HOOKABLE(GiveResource, EV_GiveResource); /** Called when entity is being given some resource with specified limit. See RES_* constants for resource types. Return true to forbid giving. */ #define EV_GiveResourceWithLimit(i, o) \ - /** receiver */ i(entity, MUTATOR_ARGV_0_entity) \ - /** resource type */ i(entity, MUTATOR_ARGV_1_entity) \ - /**/ o(entity, MUTATOR_ARGV_1_entity) \ - /** amount */ i(float, MUTATOR_ARGV_2_float) \ - /**/ o(float, MUTATOR_ARGV_2_float) \ - /** limit */ i(float, MUTATOR_ARGV_3_float) \ - /**/ o(float, MUTATOR_ARGV_3_float) \ + /** receiver */ i(entity, MUTATOR_ARGV_7_entity) \ + /** resource type */ i(entity, MUTATOR_ARGV_8_entity) \ + /**/ o(entity, MUTATOR_ARGV_8_entity) \ + /** amount */ i(float, MUTATOR_ARGV_9_float) \ + /**/ o(float, MUTATOR_ARGV_9_float) \ + /** limit */ i(float, MUTATOR_ARGV_10_float) \ + /**/ o(float, MUTATOR_ARGV_10_float) \ /**/ MUTATOR_HOOKABLE(GiveResourceWithLimit, EV_GiveResourceWithLimit); @@ -784,27 +787,29 @@ MUTATOR_HOOKABLE(GiveResourceWithLimit, EV_GiveResourceWithLimit); for resource types. Return true to forbid giving. NOTE: This hook is also called by TakeResourceWithLimit */ #define EV_TakeResource(i, o) \ - /** receiver */ i(entity, MUTATOR_ARGV_0_entity) \ - /** resource type */ i(entity, MUTATOR_ARGV_1_entity) \ - /**/ o(entity, MUTATOR_ARGV_1_entity) \ - /** amount */ i(float, MUTATOR_ARGV_2_float) \ - /**/ o(float, MUTATOR_ARGV_2_float) \ + /** receiver */ i(entity, MUTATOR_ARGV_7_entity) \ + /** resource type */ i(entity, MUTATOR_ARGV_8_entity) \ + /**/ o(entity, MUTATOR_ARGV_8_entity) \ + /** amount */ i(float, MUTATOR_ARGV_9_float) \ + /**/ o(float, MUTATOR_ARGV_9_float) \ /**/ MUTATOR_HOOKABLE(TakeResource, EV_TakeResource); /** Called when some resource is being taken from an entity, with a limit. See RES_* constants for resource types. Return true to forbid giving. */ #define EV_TakeResourceWithLimit(i, o) \ - /** receiver */ i(entity, MUTATOR_ARGV_0_entity) \ - /** resource type */ i(entity, MUTATOR_ARGV_1_entity) \ - /**/ o(entity, MUTATOR_ARGV_1_entity) \ - /** amount */ i(float, MUTATOR_ARGV_2_float) \ - /**/ o(float, MUTATOR_ARGV_2_float) \ - /** limit */ i(float, MUTATOR_ARGV_3_float) \ - /**/ o(float, MUTATOR_ARGV_3_float) \ + /** receiver */ i(entity, MUTATOR_ARGV_7_entity) \ + /** resource type */ i(entity, MUTATOR_ARGV_8_entity) \ + /**/ o(entity, MUTATOR_ARGV_8_entity) \ + /** amount */ i(float, MUTATOR_ARGV_9_float) \ + /**/ o(float, MUTATOR_ARGV_9_float) \ + /** limit */ i(float, MUTATOR_ARGV_10_float) \ + /**/ o(float, MUTATOR_ARGV_10_float) \ /**/ MUTATOR_HOOKABLE(TakeResourceWithLimit, EV_TakeResourceWithLimit); +// END Resource hooks + /** called at when a player connect */ #define EV_ClientConnect(i, o) \ /** player */ i(entity, MUTATOR_ARGV_0_entity) \