Xonotic
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:

Go to the source code of this file.

Functions

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

Variables

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

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 65 of file sv_dynamic_handicap.qc.

References autocvar_g_dynamic_handicap, autocvar_g_dynamic_handicap_max, autocvar_g_dynamic_handicap_min, and REGISTER_MUTATOR().

Referenced by DynamicHandicap_UpdateHandicap().

66 {
67  if ((autocvar_g_dynamic_handicap_min >= 0) && (handicap <
69  {
71  }
72  if ((autocvar_g_dynamic_handicap_max > 0) && (handicap >
74  {
76  }
77  return handicap;
78 }
float autocvar_g_dynamic_handicap_max
The maximum value of the handicap.
float autocvar_g_dynamic_handicap_min
The minimum value of the handicap.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DynamicHandicap_UpdateHandicap()

void DynamicHandicap_UpdateHandicap ( )

Updates the handicap of all players.

Returns
No return.

Definition at line 32 of file sv_dynamic_handicap.qc.

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().

33 {
34  float total_score = 0;
35  float totalplayers = 0;
37  {
38  total_score += PlayerScore_Get(it, SP_SCORE);
39  ++totalplayers;
40  });
41  float mean_score = total_score / totalplayers;
42  FOREACH_CLIENT(true,
43  {
44  float score = PlayerScore_Get(it, SP_SCORE);
45  float handicap = fabs((score - mean_score) *
47  handicap = handicap ** autocvar_g_dynamic_handicap_exponent;
48  if (score < mean_score)
49  {
50  handicap = -handicap;
51  }
52  if (handicap >= 0)
53  {
54  handicap += 1;
55  }
56  else
57  {
58  handicap = 1 / (fabs(handicap) + 1);
59  }
60  handicap = DynamicHandicap_ClampHandicap(handicap);
61  Handicap_SetForcedHandicap(it, handicap);
62  });
63 }
#define PlayerScore_Get(player, scorefield)
Returns the player&#39;s score.
Definition: scores.qh:43
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
float autocvar_g_dynamic_handicap_exponent
The exponent used to calculate handicap.
float DynamicHandicap_ClampHandicap(float handicap)
Clamps the value of the handicap.
float autocvar_g_dynamic_handicap_scale
The scale of the handicap.
#define IS_PLAYER(v)
Definition: utils.qh:9
void Handicap_SetForcedHandicap(entity player, float value)
Sets the forced handicap of the player.
Definition: handicap.qc:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MUTATOR_HOOKFUNCTION() [1/6]

MUTATOR_HOOKFUNCTION ( dynamic_handicap  ,
BuildMutatorsString   
)

Definition at line 84 of file sv_dynamic_handicap.qc.

References M_ARGV, and strcat().

85 {
86  M_ARGV(0, string) = strcat(M_ARGV(0, string), ":handicap");
87 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [2/6]

MUTATOR_HOOKFUNCTION ( dynamic_handicap  ,
BuildMutatorsPrettyString   
)

Definition at line 89 of file sv_dynamic_handicap.qc.

References M_ARGV, and strcat().

90 {
91  M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Dynamic handicap");
92 }
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [3/6]

MUTATOR_HOOKFUNCTION ( dynamic_handicap  ,
ClientDisconnect   
)

Definition at line 94 of file sv_dynamic_handicap.qc.

References DynamicHandicap_UpdateHandicap().

95 {
97 }
void DynamicHandicap_UpdateHandicap()
Updates the handicap of all players.
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [4/6]

MUTATOR_HOOKFUNCTION ( dynamic_handicap  ,
PutClientInServer   
)

Definition at line 99 of file sv_dynamic_handicap.qc.

References DynamicHandicap_UpdateHandicap().

100 {
102 }
void DynamicHandicap_UpdateHandicap()
Updates the handicap of all players.
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [5/6]

MUTATOR_HOOKFUNCTION ( dynamic_handicap  ,
MakePlayerObserver   
)

Definition at line 104 of file sv_dynamic_handicap.qc.

References DynamicHandicap_UpdateHandicap().

105 {
107 }
void DynamicHandicap_UpdateHandicap()
Updates the handicap of all players.
+ Here is the call graph for this function:

◆ MUTATOR_HOOKFUNCTION() [6/6]

MUTATOR_HOOKFUNCTION ( dynamic_handicap  ,
AddedPlayerScore   
)

Definition at line 109 of file sv_dynamic_handicap.qc.

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

110 {
111  if (M_ARGV(0, entity) != SP_SCORE)
112  {
113  return;
114  }
116 }
void DynamicHandicap_UpdateHandicap()
Updates the handicap of all players.
entity() spawn
#define M_ARGV(x, type)
Definition: events.qh:17
+ Here is the call graph for this function:

◆ REGISTER_MUTATOR()

REGISTER_MUTATOR ( dynamic_handicap  ,
autocvar_g_dynamic_handicap   
)

Referenced by DynamicHandicap_ClampHandicap().

+ Here is the caller graph for this function:

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 DynamicHandicap_ClampHandicap().

◆ 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().