]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/resources.qc
Merge branch 'terencehill/cl_forceplayercolors_3' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / resources.qc
index b894d6d1f74fab6af9726230d62154e57c7b9e5c..e36eb57508680f7d4b9fd8e980aaa3c9d59b9864 100644 (file)
@@ -71,14 +71,25 @@ float GetResourceLimit(entity e, int res_type)
        return limit;
 }
 
-float GetResourceAmount(entity e, int res_type)
+float GetResource(entity e, int res_type)
 {
        return e.(GetResourceField(res_type));
 }
 
-void SetResourceAmount(entity e, int res_type, float amount)
+bool SetResourceExplicit(entity e, int res_type, float amount)
 {
-       bool forbid = MUTATOR_CALLHOOK(SetResourceAmount, e, res_type, 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);
        if (forbid)
        {
                return;
@@ -92,10 +103,9 @@ void SetResourceAmount(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)
@@ -122,7 +132,7 @@ void GiveResource(entity receiver, int res_type, float amount)
        {
                return;
        }
-       SetResourceAmount(receiver, res_type, GetResourceAmount(receiver, res_type) + amount);
+       SetResource(receiver, res_type, GetResource(receiver, res_type) + amount);
        switch (res_type)
        {
                case RES_HEALTH:
@@ -166,7 +176,7 @@ void GiveResourceWithLimit(entity receiver, int res_type, float amount, float li
        {
                return;
        }
-       float current_amount = GetResourceAmount(receiver, res_type);
+       float current_amount = GetResource(receiver, res_type);
        if (current_amount + amount > limit && limit != RES_LIMIT_NONE)
        {
                amount = limit - current_amount;
@@ -191,7 +201,7 @@ void TakeResource(entity receiver, int res_type, float amount)
        {
                return;
        }
-       SetResourceAmount(receiver, res_type, GetResourceAmount(receiver, res_type) - amount);
+       SetResource(receiver, res_type, GetResource(receiver, res_type) - amount);
 }
 
 void TakeResourceWithLimit(entity receiver, int res_type, float amount, float limit)
@@ -212,7 +222,7 @@ void TakeResourceWithLimit(entity receiver, int res_type, float amount, float li
        {
                return;
        }
-       float current_amount = GetResourceAmount(receiver, res_type);
+       float current_amount = GetResource(receiver, res_type);
        if (current_amount - amount < -limit)
        {
                amount = -limit + current_amount;
@@ -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)