4 /// \brief Source file that contains implementation of the handicap system.
6 /// \copyright GNU GPLv2 or any later version.
8 #include <common/state.qh>
9 #include <server/client.qh>
11 .float m_handicap_give; ///< Holds the forced handicap value.
12 .float m_handicap_take; ///< Holds the forced handicap value.
14 void Handicap_Initialize(entity player)
16 // forced handicap defaults
17 CS(player).m_handicap_give = 1;
18 CS(player).m_handicap_take = 1;
21 float Handicap_GetVoluntaryHandicap(entity player, bool receiving)
25 return bound(1.0, CS_CVAR(player).cvar_cl_handicap_damage_taken, 10.0);
27 return bound(1.0, CS_CVAR(player).cvar_cl_handicap_damage_given, 10.0);
29 // TODO: remove the else vector branch after 0.9 release
30 // Forwards compatibility for old clients on new servers. `cl_handicap 2`
31 // ( '2 0 0' ) is treated the same as `cl_handicap_damage_{given,taken} 2`.
32 // The x is give and y is take.
33 // '2 0 0' gives and takes x2
34 // '2 2 0' gives and takes x2
35 // '2 1 0' only gives x2
36 // '1 2 0' only takes x2
41 // First read if the new cvars have a valid value,
42 // if they don't then read old cvar, checking if the old cvar has
43 // separate give and take values or we should use the first value for both
46 if (CS_CVAR(player).cvar_cl_handicap_damage_taken > 1)
47 handicap_value = CS_CVAR(player).cvar_cl_handicap_damage_taken;
48 else if (CS_CVAR(player).cvar_cl_handicap.y > 0)
49 handicap_value = CS_CVAR(player).cvar_cl_handicap.y;
51 handicap_value = CS_CVAR(player).cvar_cl_handicap.x;
55 if (CS_CVAR(player).cvar_cl_handicap_damage_given > 1)
56 handicap_value = CS_CVAR(player).cvar_cl_handicap_damage_given;
58 handicap_value = CS_CVAR(player).cvar_cl_handicap.x;
61 return bound(1.0, handicap_value, 10.0);
66 float Handicap_GetForcedHandicap(entity player, bool receiving)
69 return (CS(player)) ? CS(player).m_handicap_take : 1;
71 return (CS(player)) ? CS(player).m_handicap_give : 1;
75 void Handicap_SetForcedHandicap(entity player, float value, bool receiving)
78 error("Handicap_SetForcedHandicap: Invalid handicap value.");
81 CS(player).m_handicap_take = value;
83 CS(player).m_handicap_give = value;
86 float Handicap_GetTotalHandicap(entity player, bool receiving)
88 return Handicap_GetForcedHandicap(player, receiving) *
89 Handicap_GetVoluntaryHandicap(player, receiving);