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

Source file that contains implementation of the Dynamic handicap mutator. More...

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

Go to the source code of this file.

Functions

float DynamicHandicap_ClampHandicap (float handicap)
 Clamps the value of the handicap.
void DynamicHandicap_UpdateHandicap ()
 Updates the handicap of all players.
 MUTATOR_HOOKFUNCTION (dynamic_handicap, AddedPlayerScore)
 MUTATOR_HOOKFUNCTION (dynamic_handicap, BuildMutatorsPrettyString)
 MUTATOR_HOOKFUNCTION (dynamic_handicap, BuildMutatorsString)
 MUTATOR_HOOKFUNCTION (dynamic_handicap, ClientDisconnect)
 MUTATOR_HOOKFUNCTION (dynamic_handicap, MakePlayerObserver)
 MUTATOR_HOOKFUNCTION (dynamic_handicap, PutClientInServer)
 REGISTER_MUTATOR (dynamic_handicap, autocvar_g_dynamic_handicap &&!HANDICAP_DISABLED())

Variables

int autocvar_g_dynamic_handicap
 Whether to enable dynamic handicap.
float autocvar_g_dynamic_handicap_exponent
 The exponent used to calculate handicap.
float autocvar_g_dynamic_handicap_max
 The maximum value of the handicap.
float autocvar_g_dynamic_handicap_min
 The minimum value of the handicap.
float autocvar_g_dynamic_handicap_scale
 The scale of the handicap.

Detailed Description

Source file that contains implementation of the Dynamic handicap mutator.

Author
Lyberta

Definition in file sv_dynamic_handicap.qc.

Function Documentation

◆ DynamicHandicap_ClampHandicap()

float DynamicHandicap_ClampHandicap ( float handicap)

Clamps the value of the handicap.

Parameters
[in]handicapValue to clamp.
Returns
Clamped value.

Definition at line 69 of file sv_dynamic_handicap.qc.

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}
float autocvar_g_dynamic_handicap_max
The maximum value of the handicap.
float autocvar_g_dynamic_handicap_min
The minimum value of the handicap.

References autocvar_g_dynamic_handicap_max, and autocvar_g_dynamic_handicap_min.

Referenced by DynamicHandicap_UpdateHandicap().

◆ DynamicHandicap_UpdateHandicap()

void DynamicHandicap_UpdateHandicap ( )

Updates the handicap of all players.

Returns
No return.

Definition at line 32 of file sv_dynamic_handicap.qc.

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}
#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
float fabs(float f)
#define PlayerScore_Get(player, scorefield)
Returns the player's score.
Definition scores.qh:42
float autocvar_g_dynamic_handicap_scale
The scale of the handicap.
float autocvar_g_dynamic_handicap_exponent
The exponent used to calculate handicap.
float DynamicHandicap_ClampHandicap(float handicap)
Clamps the value of the handicap.
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:50

References autocvar_g_dynamic_handicap_exponent, autocvar_g_dynamic_handicap_scale, DynamicHandicap_ClampHandicap(), fabs(), FOREACH_CLIENT, Handicap_SetForcedHandicap(), IS_PLAYER, and PlayerScore_Get.

Referenced by MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), MUTATOR_HOOKFUNCTION(), and MUTATOR_HOOKFUNCTION().

◆ MUTATOR_HOOKFUNCTION() [1/6]

MUTATOR_HOOKFUNCTION ( dynamic_handicap ,
AddedPlayerScore  )

Definition at line 113 of file sv_dynamic_handicap.qc.

114{
115 if (M_ARGV(0, entity) != SP_SCORE)
116 {
117 return;
118 }
120}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define M_ARGV(x, type)
Definition events.qh:17
void DynamicHandicap_UpdateHandicap()
Updates the handicap of all players.

References DynamicHandicap_UpdateHandicap(), entity(), and M_ARGV.

◆ MUTATOR_HOOKFUNCTION() [2/6]

MUTATOR_HOOKFUNCTION ( dynamic_handicap ,
BuildMutatorsPrettyString  )

Definition at line 93 of file sv_dynamic_handicap.qc.

94{
95 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Dynamic handicap");
96}
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

References M_ARGV, and strcat().

◆ MUTATOR_HOOKFUNCTION() [3/6]

MUTATOR_HOOKFUNCTION ( dynamic_handicap ,
BuildMutatorsString  )

Definition at line 88 of file sv_dynamic_handicap.qc.

89{
90 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":handicap");
91}

References M_ARGV, and strcat().

◆ MUTATOR_HOOKFUNCTION() [4/6]

MUTATOR_HOOKFUNCTION ( dynamic_handicap ,
ClientDisconnect  )

◆ MUTATOR_HOOKFUNCTION() [5/6]

MUTATOR_HOOKFUNCTION ( dynamic_handicap ,
MakePlayerObserver  )

Definition at line 108 of file sv_dynamic_handicap.qc.

References DynamicHandicap_UpdateHandicap().

◆ MUTATOR_HOOKFUNCTION() [6/6]

MUTATOR_HOOKFUNCTION ( dynamic_handicap ,
PutClientInServer  )

◆ REGISTER_MUTATOR()

REGISTER_MUTATOR ( dynamic_handicap ,
autocvar_g_dynamic_handicap &&! HANDICAP_DISABLED() )

Variable Documentation

◆ autocvar_g_dynamic_handicap

int autocvar_g_dynamic_handicap

Whether to enable dynamic handicap.

Definition at line 10 of file sv_dynamic_handicap.qc.

Referenced by REGISTER_MUTATOR().

◆ autocvar_g_dynamic_handicap_exponent

float autocvar_g_dynamic_handicap_exponent

The exponent used to calculate handicap.

1 means linear scale. Values more than 1 mean stronger non-linear handicap. Values less than 1 mean weaker non-linear handicap.

Definition at line 17 of file sv_dynamic_handicap.qc.

Referenced by DynamicHandicap_UpdateHandicap().

◆ autocvar_g_dynamic_handicap_max

float autocvar_g_dynamic_handicap_max

The maximum value of the handicap.

Definition at line 19 of file sv_dynamic_handicap.qc.

Referenced by DynamicHandicap_ClampHandicap().

◆ autocvar_g_dynamic_handicap_min

float autocvar_g_dynamic_handicap_min

The minimum value of the handicap.

Definition at line 18 of file sv_dynamic_handicap.qc.

Referenced by DynamicHandicap_ClampHandicap().

◆ autocvar_g_dynamic_handicap_scale

float autocvar_g_dynamic_handicap_scale

The scale of the handicap.

Larger values mean more penalties for strong players and more buffs for weak players.

Definition at line 13 of file sv_dynamic_handicap.qc.

Referenced by DynamicHandicap_UpdateHandicap().