1 #include "resources.qh"
3 //#include <server/autocvars.qh>
5 float GetResourceLimit(entity e, int resource_type)
12 limit = autocvar_g_balance_health_limit;
17 limit = autocvar_g_balance_armor_limit;
22 limit = g_pickup_shells_max;
25 case RESOURCE_BULLETS:
27 limit = g_pickup_nails_max;
30 case RESOURCE_ROCKETS:
32 limit = g_pickup_rockets_max;
37 limit = g_pickup_cells_max;
42 limit = g_pickup_plasma_max;
47 limit = autocvar_g_balance_fuel_limit;
52 error("GetResourceLimit: Invalid resource type.");
56 MUTATOR_CALLHOOK(GetResourceLimit, e, resource_type, limit);
57 limit = M_ARGV(2, float);
58 if (limit > RESOURCE_AMOUNT_HARD_LIMIT)
60 limit = RESOURCE_AMOUNT_HARD_LIMIT;
65 float GetResourceAmount(entity e, int resource_type)
67 .float resource_field = GetResourceField(resource_type);
68 return e.(resource_field);
71 void GiveResource(entity receiver, int resource_type, float amount)
77 bool forbid = MUTATOR_CALLHOOK(GiveResource, receiver, resource_type,
83 resource_type = M_ARGV(1, int);
84 amount = M_ARGV(2, float);
85 .float resource_field = GetResourceField(resource_type);
86 float max_amount = GetResourceLimit(receiver, resource_type);
87 receiver.(resource_field) = bound(receiver.(resource_field),
88 receiver.(resource_field) + amount, max_amount);
89 switch (resource_type)
93 receiver.pauserothealth_finished =
94 max(receiver.pauserothealth_finished, time +
95 autocvar_g_balance_pause_health_rot);
100 receiver.pauserotarmor_finished =
101 max(receiver.pauserotarmor_finished, time +
102 autocvar_g_balance_pause_armor_rot);
107 receiver.pauserotfuel_finished = max(receiver.pauserotfuel_finished,
108 time + autocvar_g_balance_pause_fuel_rot);
114 int GetResourceType(.float resource_field)
116 switch (resource_field)
118 case health: { return RESOURCE_HEALTH; }
119 case armorvalue: { return RESOURCE_ARMOR; }
120 case ammo_shells: { return RESOURCE_SHELLS; }
121 case ammo_nails: { return RESOURCE_BULLETS; }
122 case ammo_rockets: { return RESOURCE_ROCKETS; }
123 case ammo_cells: { return RESOURCE_CELLS; }
124 case ammo_plasma: { return RESOURCE_PLASMA; }
125 case ammo_fuel: { return RESOURCE_FUEL; }
127 error("GetResourceType: Invalid field.");
131 .float GetResourceField(int resource_type)
133 switch (resource_type)
135 case RESOURCE_HEALTH: { return health; }
136 case RESOURCE_ARMOR: { return armorvalue; }
137 case RESOURCE_SHELLS: { return ammo_shells; }
138 case RESOURCE_BULLETS: { return ammo_nails; }
139 case RESOURCE_ROCKETS: { return ammo_rockets; }
140 case RESOURCE_CELLS: { return ammo_cells; }
141 case RESOURCE_PLASMA: { return ammo_plasma; }
142 case RESOURCE_FUEL: { return ammo_fuel; }
144 error("GetResourceField: Invalid resource type.");