]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/resources.qc
Merge branch 'master' into Mario/stats_eloranking
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / resources.qc
index 4ff31c3c066e191341a231836075eebc683c84a9..e36eb57508680f7d4b9fd8e980aaa3c9d59b9864 100644 (file)
@@ -76,6 +76,17 @@ float GetResource(entity e, int res_type)
        return e.(GetResourceField(res_type));
 }
 
+bool SetResourceExplicit(entity e, int res_type, float amount)
+{
+       .float res_field = GetResourceField(res_type);
+       if (e.(res_field) != amount)
+       {
+               e.(res_field) = amount;
+               return true;
+       }
+       return false;
+}
+
 void SetResource(entity e, int res_type, float amount)
 {
        bool forbid = MUTATOR_CALLHOOK(SetResource, e, res_type, amount);
@@ -92,10 +103,9 @@ void SetResource(entity e, int res_type, float amount)
                amount_wasted = amount - max_amount;
                amount = max_amount;
        }
-       .float res_field = GetResourceField(res_type);
-       if (e.(res_field) != amount)
+       bool changed = SetResourceExplicit(e, res_type, amount);
+       if (changed)
        {
-               e.(res_field) = amount;
                MUTATOR_CALLHOOK(ResourceAmountChanged, e, res_type, amount);
        }
        if (amount_wasted == 0)
@@ -220,30 +230,6 @@ void TakeResourceWithLimit(entity receiver, int res_type, float amount, float li
        TakeResource(receiver, res_type, amount);
 }
 
-void GiveOrTakeResource(entity receiver, int res_type, float amount)
-{
-       if(amount < 0)
-       {
-               TakeResource(receiver, res_type, amount * -1);
-       }
-       else
-       {
-               GiveResource(receiver, res_type, amount);
-       }
-}
-
-void GiveOrTakeResourceWithLimit(entity receiver, int res_type, float amount, float limit)
-{
-       if(amount < 0)
-       {
-               TakeResourceWithLimit(receiver, res_type, amount * -1, limit);
-       }
-       else
-       {
-               GiveResourceWithLimit(receiver, res_type, amount, limit);
-       }
-}
-
 int GetResourceType(.float res_field)
 {
        switch (res_field)