]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/resources.qc
Purge SetResourceAmountExplicit
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / resources.qc
1 #include "resources.qh"
2 #include <common/items/item/ammo.qh>
3
4 /// \file
5 /// \brief Source file that contains implementation of the resource system.
6 /// \copyright GNU GPLv2 or any later version.
7
8 float GetResourceAmount(entity e, int resource_type)
9 {
10         .float resource_field = GetResourceField(resource_type);
11         return e.(resource_field);
12 }
13
14 void SetResourceAmount(entity e, int resource_type, float amount)
15 {
16         .float resource_field = GetResourceField(resource_type);
17         e.(resource_field) = amount;
18 }
19
20 void TakeResource(entity receiver, int resource_type, float amount)
21 {
22         if (amount == 0)
23         {
24                 return;
25         }
26         SetResourceAmount(receiver, resource_type,
27                 GetResourceAmount(receiver, resource_type) - amount);
28 }
29
30 void TakeResourceWithLimit(entity receiver, int resource_type, float amount,
31         float limit)
32 {
33         if (amount == 0)
34         {
35                 return;
36         }
37         float current_amount = GetResourceAmount(receiver, resource_type);
38         if (current_amount - amount < limit)
39         {
40                 amount = limit + current_amount;
41         }
42         TakeResource(receiver, resource_type, amount);
43 }
44
45 int GetResourceType(.float resource_field)
46 {
47         switch (resource_field)
48         {
49                 case health: { return RESOURCE_HEALTH; }
50                 case armorvalue: { return RESOURCE_ARMOR; }
51                 case ammo_shells: { return RESOURCE_SHELLS; }
52                 case ammo_nails: { return RESOURCE_BULLETS; }
53                 case ammo_rockets: { return RESOURCE_ROCKETS; }
54                 case ammo_cells: { return RESOURCE_CELLS; }
55                 case ammo_plasma: { return RESOURCE_PLASMA; }
56                 case ammo_fuel: { return RESOURCE_FUEL; }
57         }
58         error("GetResourceType: Invalid field.");
59         return 0;
60 }
61
62 .float GetResourceField(int resource_type)
63 {
64         switch (resource_type)
65         {
66                 case RESOURCE_HEALTH: { return health; }
67                 case RESOURCE_ARMOR: { return armorvalue; }
68                 case RESOURCE_SHELLS: { return ammo_shells; }
69                 case RESOURCE_BULLETS: { return ammo_nails; }
70                 case RESOURCE_ROCKETS: { return ammo_rockets; }
71                 case RESOURCE_CELLS: { return ammo_cells; }
72                 case RESOURCE_PLASMA: { return ammo_plasma; }
73                 case RESOURCE_FUEL: { return ammo_fuel; }
74         }
75         error("GetResourceField: Invalid resource type.");
76         return health;
77 }