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

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

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

Go to the source code of this file.

Macros

#define HANDICAP_DISABLED()
#define HANDICAP_MAX_LEVEL_EQUIVALENT   2.0

Functions

float Handicap_GetForcedHandicap (entity player, bool receiving)
 Returns the forced handicap of the player.
float Handicap_GetTotalHandicap (entity player, bool receiving)
 Returns the total handicap of the player.
float Handicap_GetVoluntaryHandicap (entity player, bool receiving)
 Returns the voluntary handicap of the player.
void Handicap_Initialize (entity player)
 Initializes handicap to its default value.
void Handicap_SetForcedHandicap (entity player, float value, bool receiving)
 Sets the forced handicap of the player.
void Handicap_UpdateHandicapLevel (entity player)
 Updates .handicap_level for the player.

Variables

float handicap_avg_given_sum
float handicap_avg_taken_sum
int handicap_level

Detailed Description

Header file that describes the handicap system.

Author
Lyberta

Definition in file handicap.qh.

Macro Definition Documentation

◆ HANDICAP_DISABLED

#define HANDICAP_DISABLED ( )
Value:
(IS_GAMETYPE(CTS) || IS_GAMETYPE(RACE))

Definition at line 57 of file handicap.qh.

57#define HANDICAP_DISABLED() \
58 (IS_GAMETYPE(CTS) || IS_GAMETYPE(RACE))

Referenced by Handicap_GetForcedHandicap(), Handicap_GetTotalHandicap(), Handicap_GetVoluntaryHandicap(), Handicap_SetForcedHandicap(), and Handicap_UpdateHandicapLevel().

◆ HANDICAP_MAX_LEVEL_EQUIVALENT

#define HANDICAP_MAX_LEVEL_EQUIVALENT   2.0

Definition at line 66 of file handicap.qh.

Referenced by Handicap_UpdateHandicapLevel().

Function Documentation

◆ Handicap_GetForcedHandicap()

float Handicap_GetForcedHandicap ( entity player,
bool receiving )

Returns the forced handicap of the player.

Parameters
[in]playerPlayer to check.
[in]receivingWhether handicap is for receiving or dealing.
Returns
Forced handicap of the player.

Definition at line 71 of file handicap.qc.

72{
74 return 1;
75 if (receiving)
76 return (CS(player)) ? CS(player).m_handicap_take : 1;
77 else
78 return (CS(player)) ? CS(player).m_handicap_give : 1;
79}
#define HANDICAP_DISABLED()
Definition handicap.qh:57
ClientState CS(Client this)
Definition state.qh:47

References CS(), entity(), and HANDICAP_DISABLED.

Referenced by Handicap_GetTotalHandicap().

◆ Handicap_GetTotalHandicap()

float Handicap_GetTotalHandicap ( entity player,
bool receiving )

Returns the total handicap of the player.

Parameters
[in]playerPlayer to check.
[in]receivingWhether handicap is for receiving or dealing.
Returns
Total handicap of the player.

Definition at line 96 of file handicap.qc.

97{
99 return 1;
100 return Handicap_GetForcedHandicap(player, receiving) *
101 Handicap_GetVoluntaryHandicap(player, receiving);
102}
float Handicap_GetForcedHandicap(entity player, bool receiving)
Returns the forced handicap of the player.
Definition handicap.qc:71
float Handicap_GetVoluntaryHandicap(entity player, bool receiving)
Returns the voluntary handicap of the player.
Definition handicap.qc:25

References entity(), HANDICAP_DISABLED, Handicap_GetForcedHandicap(), and Handicap_GetVoluntaryHandicap().

Referenced by Handicap_UpdateHandicapLevel(), PlayerDamage(), and PlayerFrame().

◆ Handicap_GetVoluntaryHandicap()

float Handicap_GetVoluntaryHandicap ( entity player,
bool receiving )

Returns the voluntary handicap of the player.

Parameters
[in]playerPlayer to check.
[in]receivingWhether handicap is for receiving or dealing.
Returns
Voluntary handicap of the player.

Definition at line 25 of file handicap.qc.

26{
28 return 1;
29#if 0
30 if (receiving)
31 return bound(1.0, CS_CVAR(player).cvar_cl_handicap_damage_taken, 10.0);
32 else
33 return bound(1.0, CS_CVAR(player).cvar_cl_handicap_damage_given, 10.0);
34#else
35 // TODO: remove the else vector branch after 0.9 release
36 // Forwards compatibility for old clients on new servers. `cl_handicap 2`
37 // ( '2 0 0' ) is treated the same as `cl_handicap_damage_{given,taken} 2`.
38 // The x is give and y is take.
39 // '2 0 0' gives and takes x2
40 // '2 2 0' gives and takes x2
41 // '2 1 0' only gives x2
42 // '1 2 0' only takes x2
43 // z is wasted
44
45 int handicap_value;
46
47 // First read if the new cvars have a valid value,
48 // if they don't then read old cvar, checking if the old cvar has
49 // separate give and take values or we should use the first value for both
50 if (receiving)
51 {
52 if (CS_CVAR(player).cvar_cl_handicap_damage_taken > 1)
53 handicap_value = CS_CVAR(player).cvar_cl_handicap_damage_taken;
54 else if (CS_CVAR(player).cvar_cl_handicap.y > 0)
55 handicap_value = CS_CVAR(player).cvar_cl_handicap.y;
56 else
57 handicap_value = CS_CVAR(player).cvar_cl_handicap.x;
58 }
59 else
60 {
61 if (CS_CVAR(player).cvar_cl_handicap_damage_given > 1)
62 handicap_value = CS_CVAR(player).cvar_cl_handicap_damage_given;
63 else
64 handicap_value = CS_CVAR(player).cvar_cl_handicap.x;
65 }
66
67 return bound(1.0, handicap_value, 10.0);
68#endif
69}
float bound(float min, float value, float max)
#define CS_CVAR(this)
Definition state.qh:51

References bound(), CS_CVAR, entity(), and HANDICAP_DISABLED.

Referenced by Handicap_GetTotalHandicap().

◆ Handicap_Initialize()

void Handicap_Initialize ( entity player)

Initializes handicap to its default value.

Parameters
[in,out]playerPlayer to initialize.
Returns
No return.

Definition at line 16 of file handicap.qc.

17{
18 // forced handicap defaults
19 CS(player).m_handicap_give = 1;
20 CS(player).m_handicap_take = 1;
21
23}
void Handicap_UpdateHandicapLevel(entity player)
Updates .handicap_level for the player.
Definition handicap.qc:104

References CS(), entity(), and Handicap_UpdateHandicapLevel().

Referenced by ClientConnect().

◆ Handicap_SetForcedHandicap()

void Handicap_SetForcedHandicap ( entity player,
float value,
bool receiving )

Sets the forced handicap of the player.

Parameters
[in]playerPlayer to alter.
[in]valueHandicap value to set.
[in]receivingWhether handicap is for receiving or dealing.
Returns
No return.

Definition at line 81 of file handicap.qc.

82{
84 return;
85 if (value <= 0)
86 error("Handicap_SetForcedHandicap: Invalid handicap value.");
87
88 if (receiving)
89 CS(player).m_handicap_take = value;
90 else
91 CS(player).m_handicap_give = value;
92
94}
#define error
Definition pre.qh:6

References CS(), entity(), error, HANDICAP_DISABLED, and Handicap_UpdateHandicapLevel().

Referenced by DynamicHandicap_UpdateHandicap().

◆ Handicap_UpdateHandicapLevel()

void Handicap_UpdateHandicapLevel ( entity player)

Updates .handicap_level for the player.

Parameters
[in]playerPlayer to check.

Definition at line 104 of file handicap.qc.

105{
106 if (HANDICAP_DISABLED())
107 {
108 player.handicap_level = 0;
109 return;
110 }
111
112 float handicap_total = (Handicap_GetTotalHandicap(player, true) +
113 Handicap_GetTotalHandicap(player, false)) / 2;
114 player.handicap_level = floor(map_bound_ranges(handicap_total, 1, HANDICAP_MAX_LEVEL_EQUIVALENT, 0, 16));
115}
float Handicap_GetTotalHandicap(entity player, bool receiving)
Returns the total handicap of the player.
Definition handicap.qc:96
#define HANDICAP_MAX_LEVEL_EQUIVALENT
Definition handicap.qh:66
ERASEABLE float map_bound_ranges(float value, float src_min, float src_max, float dest_min, float dest_max)
Same as map_ranges except that values outside the source range are clamped to min or max.
Definition math.qh:372
float floor(float f)

References entity(), floor(), HANDICAP_DISABLED, Handicap_GetTotalHandicap(), HANDICAP_MAX_LEVEL_EQUIVALENT, and map_bound_ranges().

Referenced by Handicap_Initialize(), Handicap_SetForcedHandicap(), REPLICATE_APPLYCHANGE(), and REPLICATE_APPLYCHANGE().

Variable Documentation

◆ handicap_avg_given_sum

float handicap_avg_given_sum

Definition at line 71 of file handicap.qh.

Referenced by PlayerFrame().

◆ handicap_avg_taken_sum

float handicap_avg_taken_sum

Definition at line 72 of file handicap.qh.

Referenced by PlayerFrame().

◆ handicap_level

int handicap_level

Definition at line 64 of file handicap.qh.