]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/resources.qc
Purge client/defs.qh
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / resources.qc
index 8b21fe0cb31724169d8695f50a5672466b46a029..88a1fffc931c2cb23ebe36c9ff00432d189c054b 100644 (file)
@@ -5,14 +5,25 @@
 /// \brief Source file that contains implementation of the resource system.
 /// \copyright GNU GPLv2 or any later version.
 
-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)
 {
-       e.(GetResourceField(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)
+{
+       SetResourceExplicit(e, res_type, amount);
 }
 
 void TakeResource(entity receiver, int res_type, float amount)
@@ -21,7 +32,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)
@@ -30,7 +41,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;