Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_mayhem.qh File Reference
Include dependency graph for sv_mayhem.qh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void mayhem_Initialize ()
void MayhemCalculatePlayerScore (entity scorer)
 REGISTER_MUTATOR (mayhem, false)

Function Documentation

◆ mayhem_Initialize()

void mayhem_Initialize ( )

Definition at line 41 of file sv_mayhem.qc.

42{
45
46 // unused for now
47 //InitializeEntity(NULL, mayhem_DelayedInit, INITPRIO_GAMETYPE);
48}
float autocvar_g_mayhem_point_limit
Definition sv_mayhem.qc:7
float autocvar_g_mayhem_point_leadlimit
Definition sv_mayhem.qc:8
void GameRules_limit_score(int limit)
Definition sv_rules.qc:23
void GameRules_limit_lead(int limit)
Definition sv_rules.qc:33

References autocvar_g_mayhem_point_leadlimit, autocvar_g_mayhem_point_limit, GameRules_limit_lead(), and GameRules_limit_score().

Referenced by REGISTER_MUTATOR().

◆ MayhemCalculatePlayerScore()

void MayhemCalculatePlayerScore ( entity scorer)

Definition at line 145 of file sv_mayhem.qc.

146{
147 int scoringmethod = 1;
148 float upscaler; // how much score does 1 frag give
149 float frag_weight; // how many frags should a kill be worth
150 float damage_weight; // how many frags is damage worth of player's spawn health+armor
151
152 // if frag is 0.25 , damage is 0.75 and upscaler is 20
153 // then killing a full hp opponent is 1 frag which is worth of 20 score
154 // or damage worth of 2 starting health+armor is 1.5 frags or 30 score even if no kills were gotten
155
156 bool disable_selfdamage2score;
157
158 if (teamplay) {
159 // use Team Mayhem values
164 } else {
165 // use FFA Mayhem values
170 }
171
172 // decide scoringmethod and avoid potential divide by 0 errors
173
174 if (frag_weight && damage_weight) // both frag and damage weights have non-zero values
175 scoringmethod = 1;
176 else if (frag_weight) // frag weight has a value
177 scoringmethod = 2;
178 else if (damage_weight) // damage weight has a value
179 scoringmethod = 3;
180 else
181 return; // neither frags nor damage are set to give score
182
183 switch (scoringmethod)
184 {
185 default:
186 case 1:
187 {
188 // calculate how much score the player should have based on their damage dealt and frags gotten and then add the missing score
189
190 // give a different weight for suicides if scoring method 1 doesn't have selfdamage2score enabled to harshly punish for suicides to avoid exploiting
191 float suicide_weight = 1 + (disable_selfdamage2score / frag_weight);
192
193 // total damage divided by player start health&armor to get how many lives worth of damage they've dealt,
194 // then calculate new value affected by weight
195 float playerdamagescore = ((scorer.total_damage_dealt / (start_health + start_armorvalue)) * 100) * upscaler * damage_weight;
196 // * 100 to avoid float inaccuracy at that decimal level
197
198 // playerdamagescore rounded to one decimal
199 float roundedplayerdamagescore = rint(playerdamagescore * 10) / 10;
200
201 // amount of kills
202 float killcount = PlayerScore_Get(scorer, SP_KILLS) - PlayerScore_Get(scorer, SP_TEAMKILLS) - (PlayerScore_Get(scorer, SP_SUICIDES) * suicide_weight);
203
204 // kills minus suicides, calculate weight
205 float playerkillscore = (killcount * 100) * upscaler * frag_weight;
206 // * 100 to avoid float inaccuracy at that decimal level
207
208 float playerscore = roundedplayerdamagescore + playerkillscore;
209
210 // calculated how much score the player has and now calculate total of how much they are supposed to have
211 float scoretoadd = playerscore - (PlayerScore_Get(scorer, SP_SCORE) * 100);
212 // * 100 to avoid float inaccuracy at that decimal level
213
214 // adjust total score to be what the player is supposed to have
215 GameRules_scoring_add_team(scorer, SCORE, floor(scoretoadd / 100));
216 // / 100 to move back to the original decimal level
217
218 #if 0
219 // debug printing
220 if(!IS_BOT_CLIENT(scorer)){
221 print(sprintf("%f", scorer.total_damage_dealt), " scorer.total_damage_dealt \n");
222 print(sprintf("%f", scorer.hitsound_damage_dealt), " scorer.hitsound_damage_dealt \n");
223 print(sprintf("%f", playerdamagescore/100), " playerdamagescore \n");
224 print(sprintf("%f", roundedplayerdamagescore/100), " rounded playerdamagescore \n");
225 print(sprintf("%f", playerkillscore/100), " playerkillscore \n");
226 print(sprintf("%f", PlayerScore_Get(scorer, SP_KILLS)), " PlayerScore_Get(scorer, SP_KILLS) \n");
227 print(sprintf("%f", playerscore/100), " playerscore \n");
228 print(sprintf("%f", scoretoadd/100), " scoretoadd \n");
229 print(sprintf("%f", PlayerScore_Get(scorer, SP_SCORE)), " PlayerScore_Get(scorer, SP_SCORE) \n \n");
230 }
231 #endif
232 return;
233 }
234
235 case 2:
236 {
237 // calculate how much score the player should have based on their frags gotten and then add the missing score
238 float playerkillscore = PlayerScore_Get(scorer, SP_KILLS) - PlayerScore_Get(scorer, SP_TEAMKILLS) - PlayerScore_Get(scorer, SP_SUICIDES);
239 float upscaledplayerscore = playerkillscore * upscaler;
240 float scoretoadd = upscaledplayerscore - PlayerScore_Get(scorer, SP_SCORE);
241 GameRules_scoring_add_team(scorer, SCORE, floor(scoretoadd));
242
243 #if 0
244 // debug printing
245 if(!IS_BOT_CLIENT(scorer)){
246 print(sprintf("%f", playerkillscore), " playerkillscore \n");
247 print(sprintf("%f", PlayerScore_Get(scorer, SP_KILLS)), " PlayerScore_Get(scorer, SP_KILLS) \n");
248 print(sprintf("%f", upscaledplayerscore), " upscaled playerscore \n");
249 print(sprintf("%f", scoretoadd), " scoretoadd \n");
250 print(sprintf("%f", PlayerScore_Get(scorer, SP_SCORE)), " PlayerScore_Get(scorer, SP_SCORE) \n \n");
251 }
252 #endif
253 return;
254 }
255
256 case 3:
257 {
258 // calculate how much score the player should have based on their damage dealt and then add the missing score
259 float playerdamagescore = ((scorer.total_damage_dealt / (start_health + start_armorvalue)) * 100);
260 float roundedplayerdamagescore = rint(playerdamagescore * 10) / 10;
261 float upscaledplayerscore = roundedplayerdamagescore * upscaler;
262 float scoretoadd = upscaledplayerscore - (PlayerScore_Get(scorer, SP_SCORE) * 100);
263 GameRules_scoring_add_team(scorer, SCORE, floor(scoretoadd / 100));
264
265 #if 0
266 // debug printing
267 if(!IS_BOT_CLIENT(scorer)){
268 print(sprintf("%f", scorer.total_damage_dealt), " scorer.total_damage_dealt \n");
269 print(sprintf("%f", playerdamagescore), " playerdamagescore \n");
270 print(sprintf("%f", roundedplayerdamagescore), " rounded playerdamagescore \n");
271 print(sprintf("%f", upscaledplayerscore), " upscaled playerscore \n");
272 print(sprintf("%f", scoretoadd), " scoretoadd \n");
273 print(sprintf("%f", PlayerScore_Get(scorer, SP_SCORE)), " PlayerScore_Get(scorer, SP_SCORE) \n \n");
274 }
275 #endif
276 return;
277 }
278 }
279}
float rint(float f)
void print(string text,...)
float floor(float f)
int killcount
Definition client.qh:315
#define PlayerScore_Get(player, scorefield)
Returns the player's score.
Definition scores.qh:42
bool autocvar_g_mayhem_scoring_disable_selfdamage2score
Definition sv_mayhem.qc:18
float autocvar_g_mayhem_scoring_kill_weight
Definition sv_mayhem.qc:17
float autocvar_g_mayhem_scoring_damage_weight
Definition sv_mayhem.qc:16
float autocvar_g_mayhem_scoring_upscaler
Definition sv_mayhem.qc:15
#define GameRules_scoring_add_team(client, fld, value)
Definition sv_rules.qh:89
float autocvar_g_tmayhem_scoring_damage_weight
Definition sv_tmayhem.qh:8
float autocvar_g_tmayhem_scoring_upscaler
Definition sv_tmayhem.qh:6
float autocvar_g_tmayhem_scoring_kill_weight
Definition sv_tmayhem.qh:7
bool autocvar_g_tmayhem_scoring_disable_selfdamage2score
Definition sv_tmayhem.qh:9
bool teamplay
Definition teams.qh:59
#define IS_BOT_CLIENT(v)
want: (IS_CLIENT(v) && !IS_REAL_CLIENT(v))
Definition utils.qh:15
float start_armorvalue
Definition world.qh:97
float start_health
Definition world.qh:96

References autocvar_g_mayhem_scoring_damage_weight, autocvar_g_mayhem_scoring_disable_selfdamage2score, autocvar_g_mayhem_scoring_kill_weight, autocvar_g_mayhem_scoring_upscaler, autocvar_g_tmayhem_scoring_damage_weight, autocvar_g_tmayhem_scoring_disable_selfdamage2score, autocvar_g_tmayhem_scoring_kill_weight, autocvar_g_tmayhem_scoring_upscaler, entity(), floor(), GameRules_scoring_add_team, IS_BOT_CLIENT, killcount, PlayerScore_Get, print(), rint(), start_armorvalue, start_health, and teamplay.

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

◆ REGISTER_MUTATOR()

REGISTER_MUTATOR ( mayhem ,
false  )

Definition at line 7 of file sv_mayhem.qh.

8{
11 {
13 }
14 return 0;
15}
#define MUTATOR_ONADD
Definition base.qh:309
#define MUTATOR_STATIC()
Definition base.qh:313
void mayhem_Initialize()
Definition sv_mayhem.qc:41

References mayhem_Initialize(), MUTATOR_ONADD, and MUTATOR_STATIC.