]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/handicap.qc
Separated handicap into give and take variables
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / handicap.qc
1 #include "handicap.qh"
2
3 /// \file
4 /// \brief Source file that contains implementation of the handicap system.
5 /// \author Lyberta
6 /// \copyright GNU GPLv2 or any later version.
7
8 #include <common/state.qh>
9 #include <server/client.qh>
10
11 .float m_handicap_give; ///< Holds the forced handicap value.
12 .float m_handicap_take; ///< Holds the forced handicap value.
13
14 void Handicap_Initialize(entity player)
15 {
16         // forced handicap defaults
17         CS(player).m_handicap_give = 1;
18         CS(player).m_handicap_take = 1;
19 }
20
21 float Handicap_GetVoluntaryHandicap(entity player, bool receiving)
22 {
23 #if 0
24         if (receiving)
25                 return bound(1.0, CS_CVAR(player).cvar_cl_handicap_damage_taken, 10.0);
26         else
27                 return bound(1.0, CS_CVAR(player).cvar_cl_handicap_damage_given, 10.0);
28 #else
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
37         // z is wasted
38
39         int handicap_value;
40
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
44         if (receiving)
45         {
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;
50                 else
51                         handicap_value = CS_CVAR(player).cvar_cl_handicap.x;
52         }
53         else
54         {
55                 if (CS_CVAR(player).cvar_cl_handicap_damage_given > 1)
56                         handicap_value = CS_CVAR(player).cvar_cl_handicap_damage_given;
57                 else
58                         handicap_value = CS_CVAR(player).cvar_cl_handicap.x;
59         }
60
61         return bound(1.0, handicap_value, 10.0);
62 #endif
63
64 }
65
66 float Handicap_GetForcedHandicap(entity player, bool receiving)
67 {
68         if (receiving)
69                 return (CS(player)) ? CS(player).m_handicap_take : 1;
70         else
71                 return (CS(player)) ? CS(player).m_handicap_give : 1;
72
73 }
74
75 void Handicap_SetForcedHandicap(entity player, float value, bool receiving)
76 {
77         if (value <= 0)
78                 error("Handicap_SetForcedHandicap: Invalid handicap value.");
79
80         if (receiving)
81                 CS(player).m_handicap_take = value;
82         else
83                 CS(player).m_handicap_give = value;
84 }
85
86 float Handicap_GetTotalHandicap(entity player, bool receiving)
87 {
88         return Handicap_GetForcedHandicap(player, receiving) *
89                 Handicap_GetVoluntaryHandicap(player, receiving);
90 }