]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/resources.qc
Merge branch 'martin-t/nottarg' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / resources.qc
index cea10dcbef74706e21b4ef7970b4b46d2e7ea50f..a2a1358b97856196366b7dc95c909c620f2152ec 100644 (file)
@@ -1,5 +1,10 @@
 #include "resources.qh"
 
+/// \file
+/// \brief Source file that contains implementation of the resource system.
+/// \author Lyberta
+/// \copyright GNU GPLv2 or any later version.
+
 #include "autocvars.qh"
 #include "miscfunctions.qh"
 
@@ -136,6 +141,21 @@ void GiveResource(entity receiver, int resource_type, float amount)
        }
 }
 
+void GiveResourceWithLimit(entity receiver, int resource_type, float amount,
+       float limit)
+{
+       if (amount == 0)
+       {
+               return;
+       }
+       float current_amount = GetResourceAmount(receiver, resource_type);
+       if (current_amount + amount > limit)
+       {
+               amount = limit - current_amount;
+       }
+       GiveResource(receiver, resource_type, amount);
+}
+
 int GetResourceType(.float resource_field)
 {
        switch (resource_field)