]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/resources.qc
Add Quake 3 map entity compatibility with duel
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / resources.qc
index 1dbbe6646a7f72873acc0f30077c862c22a5d6ff..285ebad639c4ea4f66cdfeeb2394280f5e711d32 100644 (file)
@@ -1,4 +1,5 @@
 #include "resources.qh"
+#include <common/items/item/ammo.qh>
 
 /// \file
 /// \brief Source file that contains implementation of the resource system.
@@ -26,6 +27,31 @@ void SetResourceAmount(entity e, int resource_type, float amount)
        SetResourceAmountExplicit(e, resource_type, amount);
 }
 
+void TakeResource(entity receiver, int resource_type, float amount)
+{
+       if (amount == 0)
+       {
+               return;
+       }
+       SetResourceAmount(receiver, resource_type,
+               GetResourceAmount(receiver, resource_type) - amount);
+}
+
+void TakeResourceWithLimit(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;
+       }
+       TakeResource(receiver, resource_type, amount);
+}
+
 int GetResourceType(.float resource_field)
 {
        switch (resource_field)