]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Improved SetResourceLimit.
authorLyberta <lyberta@lyberta.net>
Thu, 29 Mar 2018 07:55:33 +0000 (10:55 +0300)
committerLyberta <lyberta@lyberta.net>
Thu, 29 Mar 2018 07:55:33 +0000 (10:55 +0300)
qcsrc/server/mutators/events.qh
qcsrc/server/resources.qc

index 165353fffefc5377a71456f4aa88b4126059c82e..a93c7687856ee9ea899d6995f6e5c0e6c0b98eef 100644 (file)
@@ -680,11 +680,13 @@ constants for resource types. Return true to forbid the change. */
 MUTATOR_HOOKABLE(SetResourceAmount, EV_SetResourceAmount);
 
 /** Called after the amount of resource of an entity has changed. See RESOURCE_*
-constants for resource types. */
+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(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);
 
index 23cdea096a111a85c1934932bfeab30009aac038..fc20caeba1fe6096bf4d7871ca33b4fecb810642 100644 (file)
@@ -83,18 +83,21 @@ void SetResourceAmount(entity e, int resource_type, float amount)
        }
        resource_type = M_ARGV(1, int);
        amount = M_ARGV(2, float);
-       .float resource_field = GetResourceField(resource_type);
-       if (e.(resource_field) == amount)
-       {
-               return;
-       }
        float max_amount = GetResourceLimit(e, resource_type);
+       float amount_wasted = 0;
        if (amount > max_amount)
        {
+               amount_wasted = amount - max_amount;
                amount = max_amount;
        }
+       .float resource_field = GetResourceField(resource_type);
+       if (e.(resource_field) == amount)
+       {
+               return;
+       }
        e.(resource_field) = amount;
-       MUTATOR_CALLHOOK(ResourceAmountChanged, e, resource_type, amount);
+       MUTATOR_CALLHOOK(ResourceAmountChanged, e, resource_type, amount,
+               amount_wasted);
 }
 
 void GiveResource(entity receiver, int resource_type, float amount)