X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fhandicap.qc;h=5c03cd11b9965ca52ac644a732d47735f0b4d1d8;hb=ffb8fdacbf2a687215db9fc6ed69ac5485f282fe;hp=ce0d6cd0a6c10f3fe0653d33da3ed700b0d95fb2;hpb=fbd14504426f7f8ce515827885157bc14d8172fa;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/handicap.qc b/qcsrc/server/handicap.qc index ce0d6cd0a..5c03cd11b 100644 --- a/qcsrc/server/handicap.qc +++ b/qcsrc/server/handicap.qc @@ -8,34 +8,83 @@ #include #include -.float m_handicap; ///< Holds the handicap value. +.float m_handicap_give; ///< Holds the forced handicap value. +.float m_handicap_take; ///< Holds the forced handicap value. void Handicap_Initialize(entity player) { - CS(player).m_handicap = 1; + // forced handicap defaults + CS(player).m_handicap_give = 1; + CS(player).m_handicap_take = 1; } -float Handicap_GetVoluntaryHandicap(entity player) +float Handicap_GetVoluntaryHandicap(entity player, bool receiving) { - return bound(1.0, CS_CVAR(player).cvar_cl_handicap, 10.0); +#if 0 + if (receiving) + return bound(1.0, CS_CVAR(player).cvar_cl_handicap_damage_taken, 10.0); + else + return bound(1.0, CS_CVAR(player).cvar_cl_handicap_damage_given, 10.0); +#else + // TODO: remove the else vector branch after 0.9 release + // Forwards compatibility for old clients on new servers. `cl_handicap 2` + // ( '2 0 0' ) is treated the same as `cl_handicap_damage_{given,taken} 2`. + // The x is give and y is take. + // '2 0 0' gives and takes x2 + // '2 2 0' gives and takes x2 + // '2 1 0' only gives x2 + // '1 2 0' only takes x2 + // z is wasted + + int handicap_value; + + // First read if the new cvars have a valid value, + // if they don't then read old cvar, checking if the old cvar has + // separate give and take values or we should use the first value for both + if (receiving) + { + if (CS_CVAR(player).cvar_cl_handicap_damage_taken > 1) + handicap_value = CS_CVAR(player).cvar_cl_handicap_damage_taken; + else if (CS_CVAR(player).cvar_cl_handicap.y > 0) + handicap_value = CS_CVAR(player).cvar_cl_handicap.y; + else + handicap_value = CS_CVAR(player).cvar_cl_handicap.x; + } + else + { + if (CS_CVAR(player).cvar_cl_handicap_damage_given > 1) + handicap_value = CS_CVAR(player).cvar_cl_handicap_damage_given; + else + handicap_value = CS_CVAR(player).cvar_cl_handicap.x; + } + + return bound(1.0, handicap_value, 10.0); +#endif + } -float Handicap_GetForcedHandicap(entity player) +float Handicap_GetForcedHandicap(entity player, bool receiving) { - return (CS(player)) ? CS(player).m_handicap : 1; + if (receiving) + return (CS(player)) ? CS(player).m_handicap_take : 1; + else + return (CS(player)) ? CS(player).m_handicap_give : 1; + } -void Handicap_SetForcedHandicap(entity player, float value) +void Handicap_SetForcedHandicap(entity player, float value, bool receiving) { if (value <= 0) - { error("Handicap_SetForcedHandicap: Invalid handicap value."); - } - CS(player).m_handicap = value; + + if (receiving) + CS(player).m_handicap_take = value; + else + CS(player).m_handicap_give = value; } -float Handicap_GetTotalHandicap(entity player) +float Handicap_GetTotalHandicap(entity player, bool receiving) { - return Handicap_GetForcedHandicap(player) * Handicap_GetVoluntaryHandicap( - player); + return Handicap_GetForcedHandicap(player, receiving) * + Handicap_GetVoluntaryHandicap(player, receiving); }