From: Lyberta Date: Mon, 2 Apr 2018 09:00:31 +0000 (+0300) Subject: Added ResourceWasted hook. X-Git-Tag: xonotic-v0.8.5~2204^2~1 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=926f0330ded4b9886284a680ee3a06f430062902;p=xonotic%2Fxonotic-data.pk3dir.git Added ResourceWasted hook. --- diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index b781db24f..8700e45b8 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -689,10 +689,19 @@ above resource limit so it was not given. */ /** checked entity */ i(entity, MUTATOR_ARGV_0_entity) \ /** resource type */ i(int, MUTATOR_ARGV_1_int) \ /** amount */ i(float, MUTATOR_ARGV_2_float) \ - /** amount wasted */ i(float, MUTATOR_ARGV_3_float) \ /**/ MUTATOR_HOOKABLE(ResourceAmountChanged, EV_ResourceAmountChanged); +/** Called when there was an attempt to set entity resources higher than their +limit. See RESOURCE_* 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(int, MUTATOR_ARGV_1_int) \ + /** amount wasted */ i(float, MUTATOR_ARGV_2_float) \ + /**/ +MUTATOR_HOOKABLE(ResourceWasted, EV_ResourceWasted); + /** Called when entity is being given some resource. See RESOURCE_* constants for resource types. Return true to forbid giving. */ #define EV_GiveResource(i, o) \ diff --git a/qcsrc/server/resources.qc b/qcsrc/server/resources.qc index e3a7b8679..4ad66bb98 100644 --- a/qcsrc/server/resources.qc +++ b/qcsrc/server/resources.qc @@ -91,9 +91,16 @@ void SetResourceAmount(entity e, int resource_type, float amount) amount = max_amount; } .float resource_field = GetResourceField(resource_type); - e.(resource_field) = amount; - MUTATOR_CALLHOOK(ResourceAmountChanged, e, resource_type, amount, - amount_wasted); + if (e.(resource_field) != amount) + { + e.(resource_field) = amount; + MUTATOR_CALLHOOK(ResourceAmountChanged, e, resource_type, amount); + } + if (amount_wasted == 0) + { + return; + } + MUTATOR_CALLHOOK(ResourceWasted, e, resource_type, amount_wasted); } void GiveResource(entity receiver, int resource_type, float amount)