Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
cl_resources.qh File Reference

Header file that describes the resource system. More...

Include dependency graph for cl_resources.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

float GetResource (entity e, Resource res_type)
 Returns the current amount of resource the given entity has.
void SetResource (entity e, Resource res_type, float amount)
 Sets the current amount of resource the given entity will have.
bool SetResourceExplicit (entity e, Resource res_type, float amount)
 Sets the resource amount of an entity without calling any hooks.
void TakeResource (entity receiver, Resource res_type, float amount)
 Takes an entity some resource.
void TakeResourceWithLimit (entity receiver, Resource res_type, float amount, float limit)
 Takes an entity some resource but not less than a limit.

Detailed Description

Header file that describes the resource system.

Definition in file cl_resources.qh.

Function Documentation

◆ GetResource()

float GetResource ( entity e,
Resource res_type )

Returns the current amount of resource the given entity has.

Parameters
[in]eEntity to check.
[in]res_typeType of the resource (a RES_* constant).
Returns
Current amount of resource the given entity has.

Definition at line 10 of file cl_resources.qc.

11{
12 return e.(GetResourceField(res_type));
13}

◆ SetResource()

void SetResource ( entity e,
Resource res_type,
float amount )

Sets the current amount of resource the given entity will have.

Parameters
[in,out]eEntity to adjust.
[in]res_typeType of the resource (a RES_* constant).
[in]amountAmount of resource to set.
Returns
No return.

Definition at line 26 of file cl_resources.qc.

27{
28 SetResourceExplicit(e, res_type, amount);
29}
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.

◆ SetResourceExplicit()

bool SetResourceExplicit ( entity e,
Resource res_type,
float amount )

Sets the resource amount of an entity without calling any hooks.

Parameters
[in,out]eEntity to adjust.
[in]res_typeType of the resource (a RES_* constant).
[in]amountAmount of resource to set.
Returns
Boolean for whether the ammo amount was changed

Definition at line 15 of file cl_resources.qc.

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}
float GetResourceField(Resource res_type)
Converts resource type (a RES_* constant) to entity field.
Definition resources.qc:11

◆ TakeResource()

void TakeResource ( entity receiver,
Resource res_type,
float amount )

Takes an entity some resource.

Parameters
[in,out]receiverEntity to take resource from.
[in]res_typeType of the resource (a RES_* constant).
[in]amountAmount of resource to take.
Returns
No return.

Definition at line 31 of file cl_resources.qc.

32{
33 if (amount == 0)
34 {
35 return;
36 }
37 SetResource(receiver, res_type, GetResource(receiver, res_type) - amount);
38}
void SetResource(entity e, Resource res_type, float amount)
Sets the current amount of resource the given entity will have.
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.

◆ TakeResourceWithLimit()

void TakeResourceWithLimit ( entity receiver,
Resource res_type,
float amount,
float limit )

Takes an entity some resource but not less than a limit.

Parameters
[in,out]receiverEntity to take resource from.
[in]res_typeType of the resource (a RES_* constant).
[in]amountAmount of resource to take.
[in]limitLimit of resources to take.
Returns
No return.

Definition at line 40 of file cl_resources.qc.

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}
void TakeResource(entity receiver, Resource res_type, float amount)
Takes an entity some resource.