Xonotic
cl_resources.qc
Go to the documentation of this file.
1 #include "cl_resources.qh"
2 
5 
9 
10 float GetResource(entity e, Resource res_type)
11 {
12  return e.(GetResourceField(res_type));
13 }
14 
15 bool SetResourceExplicit(entity e, Resource res_type, float amount)
16 {
17  .float res_field = GetResourceField(res_type);
18  if (e.(res_field) != amount)
19  {
20  e.(res_field) = amount;
21  return true;
22  }
23  return false;
24 }
25 
26 void SetResource(entity e, Resource res_type, float amount)
27 {
28  SetResourceExplicit(e, res_type, amount);
29 }
30 
31 void TakeResource(entity receiver, Resource res_type, float amount)
32 {
33  if (amount == 0)
34  {
35  return;
36  }
37  SetResource(receiver, res_type, GetResource(receiver, res_type) - amount);
38 }
39 
40 void TakeResourceWithLimit(entity receiver, Resource res_type, float amount, float limit)
41 {
42  if (amount == 0)
43  {
44  return;
45  }
46  float current_amount = GetResource(receiver, res_type);
47  if (current_amount - amount < limit)
48  {
49  amount = limit + current_amount;
50  }
51  TakeResource(receiver, res_type, amount);
52 }
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
Definition: cl_resources.qc:15
entity() spawn
void TakeResource(entity receiver, Resource res_type, float amount)
Takes an entity some resource.
Definition: cl_resources.qc:31
void TakeResourceWithLimit(entity receiver, Resource res_type, float amount, float limit)
Takes an entity some resource but not less than a limit.
Definition: cl_resources.qc:40
void SetResource(entity e, Resource res_type, float amount)
Sets the current amount of resource the given entity will have.
Definition: cl_resources.qc:26
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
Header file that describes the resource system.