]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Added ResourceWasted hook.
authorLyberta <lyberta@lyberta.net>
Mon, 2 Apr 2018 09:00:31 +0000 (12:00 +0300)
committerLyberta <lyberta@lyberta.net>
Mon, 2 Apr 2018 09:00:31 +0000 (12:00 +0300)
qcsrc/server/mutators/events.qh
qcsrc/server/resources.qc

index b781db24f4629860f28ac0cdc82bf40e1ec3bb58..8700e45b8c09b41a5a1c70b904824895671239a3 100644 (file)
@@ -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) \
index e3a7b867978b053c4911776da3b63b64e6604599..4ad66bb98ed2169380e7074ea23147a503e652cf 100644 (file)
@@ -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)