1 #include "cl_resources.qh"
3 #include <common/items/item/ammo.qh>
4 #include <common/resources/resources.qh>
7 /// \brief Source file that contains implementation of the resource system.
8 /// \copyright GNU GPLv2 or any later version.
10 float GetResource(entity e, Resource res_type)
12 return e.(GetResourceField(res_type));
15 bool SetResourceExplicit(entity e, Resource res_type, float amount)
17 .float res_field = GetResourceField(res_type);
18 if (e.(res_field) != amount)
20 e.(res_field) = amount;
26 void SetResource(entity e, Resource res_type, float amount)
28 SetResourceExplicit(e, res_type, amount);
31 void TakeResource(entity receiver, Resource res_type, float amount)
37 SetResource(receiver, res_type, GetResource(receiver, res_type) - amount);
40 void TakeResourceWithLimit(entity receiver, Resource res_type, float amount, float limit)
46 float current_amount = GetResource(receiver, res_type);
47 if (current_amount - amount < limit)
49 amount = limit + current_amount;
51 TakeResource(receiver, res_type, amount);