Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_dynamic_handicap.qc
Go to the documentation of this file.
7
8//======================= Global variables ====================================
9
20
21//====================== Forward declarations =================================
22
26float DynamicHandicap_ClampHandicap(float handicap);
27
28//========================= Free functions ====================================
29
33{
34 float total_score = 0;
35 float totalplayers = 0;
37 {
38 total_score += PlayerScore_Get(it, SP_SCORE);
39 ++totalplayers;
40 });
41 if (totalplayers == 0)
42 return;
43
44 float mean_score = total_score / totalplayers;
45 FOREACH_CLIENT(true,
46 {
47 float score = PlayerScore_Get(it, SP_SCORE);
48 float handicap = fabs((score - mean_score) *
50 handicap = handicap ** autocvar_g_dynamic_handicap_exponent;
51 if (score < mean_score)
52 {
53 handicap = -handicap;
54 }
55 if (handicap >= 0)
56 {
57 handicap += 1;
58 }
59 else
60 {
61 handicap = 1 / (fabs(handicap) + 1);
62 }
63 handicap = DynamicHandicap_ClampHandicap(handicap);
64 Handicap_SetForcedHandicap(it, handicap, false);
65 Handicap_SetForcedHandicap(it, handicap, true);
66 });
67}
68
69float DynamicHandicap_ClampHandicap(float handicap)
70{
71 if ((autocvar_g_dynamic_handicap_min >= 0) && (handicap <
73 {
75 }
76 if ((autocvar_g_dynamic_handicap_max > 0) && (handicap >
78 {
80 }
81 return handicap;
82}
83
84//============================= Hooks ========================================
85
87
88MUTATOR_HOOKFUNCTION(dynamic_handicap, BuildMutatorsString)
89{
90 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":handicap");
91}
92
93MUTATOR_HOOKFUNCTION(dynamic_handicap, BuildMutatorsPrettyString)
94{
95 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Dynamic handicap");
96}
97
102
107
108MUTATOR_HOOKFUNCTION(dynamic_handicap, MakePlayerObserver)
109{
111}
112
113MUTATOR_HOOKFUNCTION(dynamic_handicap, AddedPlayerScore)
114{
115 if (M_ARGV(0, entity) != SP_SCORE)
116 {
117 return;
118 }
120}
#define REGISTER_MUTATOR(...)
Definition base.qh:295
#define MUTATOR_HOOKFUNCTION(...)
Definition base.qh:335
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define M_ARGV(x, type)
Definition events.qh:17
#define IS_PLAYER(s)
Definition player.qh:243
void Handicap_SetForcedHandicap(entity player, float value, bool receiving)
Sets the forced handicap of the player.
Definition handicap.qc:81
#define HANDICAP_DISABLED()
Definition handicap.qh:57
#define PutClientInServer
Definition _all.inc:246
#define ClientDisconnect
Definition _all.inc:242
float fabs(float f)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define PlayerScore_Get(player, scorefield)
Returns the player's score.
Definition scores.qh:42
float autocvar_g_dynamic_handicap_max
The maximum value of the handicap.
float autocvar_g_dynamic_handicap_scale
The scale of the handicap.
int autocvar_g_dynamic_handicap
Whether to enable dynamic handicap.
float autocvar_g_dynamic_handicap_exponent
The exponent used to calculate handicap.
void DynamicHandicap_UpdateHandicap()
Updates the handicap of all players.
float DynamicHandicap_ClampHandicap(float handicap)
Clamps the value of the handicap.
float autocvar_g_dynamic_handicap_min
The minimum value of the handicap.
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:50