Xonotic
race.qh File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void race_AbandonRaceCheck (entity p)
 
void race_checkAndWriteName (entity player)
 
void race_ClearRecords ()
 
float race_GetFractionalLapCount (entity e)
 
void race_ImposePenaltyTime (entity pl, float penalty, string reason)
 
void race_InitSpectator ()
 
float race_NextCheckpoint (float f)
 
void race_PreparePlayer (entity this)
 
float race_PreviousCheckpoint (float f)
 
string race_readName (string map, float pos)
 
float race_readTime (string map, float pos)
 
string race_readUID (string map, float pos)
 
void race_RetractPlayer (entity this)
 
void race_send_rankings_cnt (float msg)
 
void race_send_recordtime (float msg)
 
void race_send_speedaward (float msg)
 
void race_send_speedaward_alltimebest (float msg)
 
void race_SendAll (entity player, bool only_rankings)
 
void race_SendNextCheckpoint (entity e, float spec)
 
void race_SendRanking (float pos, float prevpos, float del, float msg)
 
void race_setTime (string map, float t, string myuid, string mynetname, entity e, bool showmessage)
 
void race_SpeedAwardFrame (entity player)
 
void race_StartCompleting ()
 
 spawnfunc (target_checkpoint)
 
string uid2name (string myuid)
 
void write_recordmarker (entity pl, float tstart, float dt)
 

Variables

bool autocvar_g_allow_checkpoints
 
int autocvar_g_cts_send_rankings_cnt = 15
 
bool g_race_qualifying
 
float race_completed
 
float race_completing
 
float race_fraglimit
 
float race_highest_place_spawn
 
float race_laptime
 
float race_leadlimit
 
float race_lowest_place_spawn
 
float race_movetime
 
float race_movetime_count
 
float race_movetime_frac
 
float race_place
 
float race_respawn_checkpoint
 
entity race_respawn_spotref
 
float race_spawns
 
float race_started
 
float race_teams
 
float race_timelimit
 
float speedaward_alltimebest
 
string speedaward_alltimebest_holder
 
string speedaward_alltimebest_uid
 
string speedaward_holder
 
float speedaward_lastsent
 
float speedaward_lastupdate
 
float speedaward_speed
 
string speedaward_uid
 
const float ST_RACE_LAPS = 1
 

Function Documentation

◆ race_AbandonRaceCheck()

void race_AbandonRaceCheck ( entity  p)

Definition at line 1163 of file race.qc.

References ClientData_Touch(), CS(), MAKE_INDEPENDENT_PLAYER, NULL, race_completed, and race_completing.

Referenced by MUTATOR_HOOKFUNCTION(), and race_StartCompleting().

1164 {
1165  if(race_completing && !CS(p).race_completed)
1166  {
1167  CS(p).race_completed = 1;
1169  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_RACE_ABANDONED, p.netname);
1170  ClientData_Touch(p);
1171  }
1172 }
ClientState CS(Client this)
Definition: state.qh:47
#define MAKE_INDEPENDENT_PLAYER(e)
Definition: client.qh:315
float race_completing
Definition: race.qh:27
#define NULL
Definition: post.qh:17
float race_completed
Definition: race.qh:25
void ClientData_Touch(entity e)
Definition: client.qc:171
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_checkAndWriteName()

void race_checkAndWriteName ( entity  player)

Definition at line 143 of file race.qc.

References CS_CVAR, db_put(), ServerProgsDB, strcat(), strcpy, strzone(), and uid2name().

Referenced by MUTATOR_HOOKFUNCTION().

144 {
145  if(CS_CVAR(player).cvar_cl_allow_uidtracking == 1 && CS_CVAR(player).cvar_cl_allow_uid2name == 1)
146  {
147  if (!player.stored_netname)
148  player.stored_netname = strzone(uid2name(player.crypto_idfp));
149  if(player.stored_netname != player.netname)
150  {
151  db_put(ServerProgsDB, strcat("/uid2name/", player.crypto_idfp), player.netname);
152  strcpy(player.stored_netname, player.netname);
153  }
154  }
155 }
ERASEABLE void db_put(int db, string key, string value)
Definition: map.qh:101
string uid2name(string myuid)
Definition: race.qc:36
float ServerProgsDB
Definition: world.qh:131
#define CS_CVAR(this)
Definition: state.qh:51
#define strcpy(this, s)
Definition: string.qh:49
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"))
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_ClearRecords()

void race_ClearRecords ( )

Definition at line 1210 of file race.qc.

References FOREACH_CLIENT, MAX_CHECKPOINTS, race_checkpoint_recordholders, race_checkpoint_records, race_PreparePlayer(), and strfree.

Referenced by MUTATOR_HOOKFUNCTION().

1211 {
1212  for(int j = 0; j < MAX_CHECKPOINTS; ++j)
1213  {
1214  race_checkpoint_records[j] = 0;
1216  }
1217 
1218  FOREACH_CLIENT(true, {
1219  float p = it.race_place;
1220  race_PreparePlayer(it);
1221  it.race_place = p;
1222  });
1223 }
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
string race_checkpoint_recordholders[MAX_CHECKPOINTS]
Definition: race.qc:169
void race_PreparePlayer(entity this)
Definition: race.qc:1180
float race_checkpoint_records[MAX_CHECKPOINTS]
Definition: race.qc:168
#define strfree(this)
Definition: string.qh:56
const float MAX_CHECKPOINTS
Definition: race.qc:158
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_GetFractionalLapCount()

float race_GetFractionalLapCount ( entity  e)

Definition at line 1289 of file race.qc.

References bound(), CS(), entity(), GameRules_scoring_add, IL_EACH, max(), race_completed, race_highest_checkpoint, race_timed_checkpoint, vector(), and vlen().

1290 {
1291  // interesting metrics (idea by KrimZon) to maybe sort players in the
1292  // scoreboard, immediately updates when overtaking
1293  //
1294  // requires the track to be built so you never get farther away from the
1295  // next checkpoint, though, and current Xonotic race maps are not built that
1296  // way
1297  //
1298  // also, this code is slow and would need optimization (i.e. "next CP"
1299  // links on CP entities)
1300 
1301  float l;
1302  l = GameRules_scoring_add(e, RACE_LAPS, 0);
1303  if(CS(e).race_completed)
1304  return l; // not fractional
1305 
1306  vector o0, o1;
1307  float bestfraction, fraction;
1308  entity lastcp;
1309  float nextcpindex, lastcpindex;
1310 
1311  nextcpindex = max(e.race_checkpoint, 0);
1312  lastcpindex = e.race_respawn_checkpoint;
1313  lastcp = e.race_respawn_spotref;
1314 
1315  if(nextcpindex == lastcpindex)
1316  return l; // finish
1317 
1318  bestfraction = 1;
1319  IL_EACH(g_racecheckpoints, true,
1320  {
1321  if(it.race_checkpoint != lastcpindex)
1322  continue;
1323  if(lastcp)
1324  if(it != lastcp)
1325  continue;
1326  o0 = (it.absmin + it.absmax) * 0.5;
1327  IL_EACH(g_racecheckpoints, true,
1328  {
1329  if(it.race_checkpoint != nextcpindex)
1330  continue;
1331  o1 = (it.absmin + it.absmax) * 0.5;
1332  if(o0 == o1)
1333  continue;
1334  fraction = bound(0.0001, vlen(e.origin - o1) / vlen(o0 - o1), 1);
1335  if(fraction < bestfraction)
1336  bestfraction = fraction;
1337  });
1338  });
1339 
1340  // we are at CP "nextcpindex - bestfraction"
1341  // race_timed_checkpoint == 4: then nextcp==4 means 0.9999x, nextcp==0 means 0.0000x
1342  // race_timed_checkpoint == 0: then nextcp==0 means 0.9999x
1343  float c, nc;
1344  nc = race_highest_checkpoint + 1;
1345  c = ((nextcpindex - race_timed_checkpoint + nc + nc - 1) % nc) + 1 - bestfraction;
1346 
1347  return l + c / nc;
1348 }
#define IL_EACH(this, cond, body)
float race_timed_checkpoint
Definition: race.qc:177
entity() spawn
ClientState CS(Client this)
Definition: state.qh:47
#define GameRules_scoring_add(client, fld, value)
Definition: sv_rules.qh:78
float race_highest_checkpoint
Definition: race.qc:176
IntrusiveList g_racecheckpoints
Definition: race.qc:69
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float race_completed
Definition: race.qh:25
+ Here is the call graph for this function:

◆ race_ImposePenaltyTime()

void race_ImposePenaltyTime ( entity  pl,
float  penalty,
string  reason 
)

Definition at line 1225 of file race.qc.

References g_race_qualifying, IS_REAL_CLIENT, msg_entity, MSG_ONE, RACE_NET_PENALTY_QUALIFYING, RACE_NET_PENALTY_RACE, time, TIME_ENCODE, WriteByte(), WriteShort(), and WriteString().

Referenced by CheatCommand(), checkpoint_passed(), penalty_touch(), and penalty_use().

1226 {
1227  if(g_race_qualifying)
1228  {
1229  pl.race_penalty_accumulator += penalty;
1230  if(IS_REAL_CLIENT(pl))
1231  {
1232  msg_entity = pl;
1233  WRITESPECTATABLE_MSG_ONE(msg_entity, {
1234  WriteHeader(MSG_ONE, TE_CSQC_RACE);
1236  WriteShort(MSG_ONE, TIME_ENCODE(penalty));
1237  WriteString(MSG_ONE, reason);
1238  });
1239  }
1240  }
1241  else
1242  {
1243  pl.race_penalty = time + penalty;
1244  if(IS_REAL_CLIENT(pl))
1245  {
1246  msg_entity = pl;
1247  WRITESPECTATABLE_MSG_ONE(msg_entity, {
1248  WriteHeader(MSG_ONE, TE_CSQC_RACE);
1250  WriteShort(MSG_ONE, TIME_ENCODE(penalty));
1251  WriteString(MSG_ONE, reason);
1252  });
1253  }
1254  }
1255 }
bool g_race_qualifying
Definition: race.qh:12
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
#define TIME_ENCODE(t)
Definition: util.qh:61
entity msg_entity
Definition: progsdefs.qc:63
const int RACE_NET_PENALTY_QUALIFYING
Definition: net_linked.qh:17
const int RACE_NET_PENALTY_RACE
Definition: net_linked.qh:16
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_InitSpectator()

void race_InitSpectator ( )

Definition at line 71 of file race.qc.

References g_race_qualifying, msg_entity, and race_SendNextCheckpoint().

Referenced by SetSpectatee_status().

72 {
74  if(msg_entity.enemy.race_laptime)
76 }
void race_SendNextCheckpoint(entity e, float spec)
Definition: race.qc:216
bool g_race_qualifying
Definition: race.qh:12
entity msg_entity
Definition: progsdefs.qc:63
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_NextCheckpoint()

float race_NextCheckpoint ( float  f)

Definition at line 182 of file race.qc.

References race_highest_checkpoint.

Referenced by checkpoint_passed(), and trigger_race_checkpoint_verify().

183 {
184  if(f >= race_highest_checkpoint)
185  return 0;
186  else
187  return f + 1;
188 }
float race_highest_checkpoint
Definition: race.qc:176
+ Here is the caller graph for this function:

◆ race_PreparePlayer()

void race_PreparePlayer ( entity  this)

Definition at line 1180 of file race.qc.

References NULL, race_ClearTime(), race_place, race_respawn_checkpoint, race_respawn_spotref, and race_started.

Referenced by MUTATOR_HOOKFUNCTION(), and race_ClearRecords().

1181 {
1182  race_ClearTime(this);
1183  this.race_place = 0;
1184  this.race_started = 0;
1185  this.race_respawn_checkpoint = 0;
1186  this.race_respawn_spotref = NULL;
1187 }
float race_place
Definition: race.qh:23
entity race_respawn_spotref
Definition: race.qh:34
#define NULL
Definition: post.qh:17
float race_started
Definition: race.qh:24
float race_respawn_checkpoint
Definition: race.qh:33
void race_ClearTime(entity e)
Definition: race.qc:646
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_PreviousCheckpoint()

float race_PreviousCheckpoint ( float  f)

Definition at line 190 of file race.qc.

References race_highest_checkpoint.

191 {
192  if(f == -1)
193  return 0;
194  else if(f == 0)
196  else
197  return f - 1;
198 }
float race_highest_checkpoint
Definition: race.qc:176

◆ race_readName()

string race_readName ( string  map,
float  pos 
)

Definition at line 138 of file race.qc.

References db_get(), ftos(), record_type, ServerProgsDB, strcat(), and uid2name().

Referenced by getrankings(), MUTATOR_HOOKFUNCTION(), race_SendRanking(), and race_setTime().

139 {
140  return uid2name(db_get(ServerProgsDB, strcat(map, record_type, "crypto_idfp", ftos(pos))));
141 }
string uid2name(string myuid)
Definition: race.qc:36
float ServerProgsDB
Definition: world.qh:131
string record_type
Definition: world.qh:49
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"))
ERASEABLE string db_get(int db, string key)
Definition: map.qh:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_readTime()

float race_readTime ( string  map,
float  pos 
)

Definition at line 78 of file race.qc.

References db_get(), ftos(), record_type, ServerProgsDB, stof(), and strcat().

Referenced by getladder(), getlsmaps(), getrankings(), MUTATOR_HOOKFUNCTION(), race_deleteTime(), race_readPos(), race_send_recordtime(), race_SendRanking(), race_setTime(), and race_writeTime().

79 {
80  return stof(db_get(ServerProgsDB, strcat(map, record_type, "time", ftos(pos))));
81 }
float ServerProgsDB
Definition: world.qh:131
string record_type
Definition: world.qh:49
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"))
ERASEABLE string db_get(int db, string key)
Definition: map.qh:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_readUID()

string race_readUID ( string  map,
float  pos 
)

Definition at line 83 of file race.qc.

References db_get(), ftos(), record_type, ServerProgsDB, and strcat().

Referenced by getladder(), race_deleteTime(), race_setTime(), and race_writeTime().

84 {
85  return db_get(ServerProgsDB, strcat(map, record_type, "crypto_idfp", ftos(pos)));
86 }
float ServerProgsDB
Definition: world.qh:131
string record_type
Definition: world.qh:49
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"))
ERASEABLE string db_get(int db, string key)
Definition: map.qh:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_RetractPlayer()

void race_RetractPlayer ( entity  this)

Definition at line 1189 of file race.qc.

References g_cts, g_race, race_checkpoint, race_ClearTime(), race_respawn_checkpoint, and race_timed_checkpoint.

Referenced by MUTATOR_HOOKFUNCTION().

1190 {
1191  if(!g_race && !g_cts)
1192  return;
1194  race_ClearTime(this);
1196 }
float race_timed_checkpoint
Definition: race.qc:177
float race_checkpoint
Definition: race.qc:163
#define g_cts
Definition: cts.qh:36
#define g_race
Definition: race.qh:46
float race_respawn_checkpoint
Definition: race.qh:33
void race_ClearTime(entity e)
Definition: race.qc:646
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_send_rankings_cnt()

void race_send_rankings_cnt ( float  msg)

Definition at line 277 of file race.qc.

References autocvar_g_cts_send_rankings_cnt, min(), RACE_NET_RANKINGS_CNT, and WriteByte().

Referenced by race_SendAll().

278 {
279  WriteHeader(msg, TE_CSQC_RACE);
281  int m = min(RANKINGS_CNT, autocvar_g_cts_send_rankings_cnt);
282  WriteByte(msg, m);
283 }
int autocvar_g_cts_send_rankings_cnt
Definition: race.qh:10
const int RACE_NET_RANKINGS_CNT
Definition: net_linked.qh:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_send_recordtime()

void race_send_recordtime ( float  msg)

Definition at line 251 of file race.qc.

References GetMapname(), RACE_NET_SERVER_RECORD, race_readTime(), and WriteByte().

Referenced by race_deleteTime(), race_SendAll(), and race_setTime().

252 {
253  // send the server best time
254  WriteHeader(msg, TE_CSQC_RACE);
256  WriteInt24_t(msg, race_readTime(GetMapname(), 1));
257 }
string GetMapname()
Definition: intermission.qc:18
const int RACE_NET_SERVER_RECORD
Definition: net_linked.qh:18
float race_readTime(string map, float pos)
Definition: race.qc:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_send_speedaward()

void race_send_speedaward ( float  msg)

Definition at line 259 of file race.qc.

References floor(), RACE_NET_SPEED_AWARD, speedaward_holder, speedaward_speed, WriteByte(), and WriteString().

Referenced by race_SendAll(), and race_SpeedAwardFrame().

260 {
261  // send the best speed of the round
262  WriteHeader(msg, TE_CSQC_RACE);
264  WriteInt24_t(msg, floor(speedaward_speed+0.5));
266 }
const int RACE_NET_SPEED_AWARD
Definition: net_linked.qh:19
float speedaward_speed
Definition: race.qh:57
string speedaward_holder
Definition: race.qh:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_send_speedaward_alltimebest()

void race_send_speedaward_alltimebest ( float  msg)

Definition at line 268 of file race.qc.

References floor(), RACE_NET_SPEED_AWARD_BEST, speedaward_alltimebest, speedaward_alltimebest_holder, WriteByte(), and WriteString().

Referenced by race_SendAll(), and race_SpeedAwardFrame().

269 {
270  // send the best speed
271  WriteHeader(msg, TE_CSQC_RACE);
273  WriteInt24_t(msg, floor(speedaward_alltimebest+0.5));
275 }
string speedaward_alltimebest_holder
Definition: race.qh:62
float speedaward_alltimebest
Definition: race.qh:61
const int RACE_NET_SPEED_AWARD_BEST
Definition: net_linked.qh:20
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_SendAll()

void race_SendAll ( entity  player,
bool  only_rankings 
)

Definition at line 324 of file race.qc.

References autocvar_g_cts_send_rankings_cnt, db_get(), GetMapname(), IS_REAL_CLIENT, min(), msg_entity, MSG_ONE, race_send_rankings_cnt(), race_send_recordtime(), race_send_speedaward(), race_send_speedaward_alltimebest(), race_SendRanking(), record_type, ServerProgsDB, speedaward_alltimebest, speedaward_alltimebest_holder, stof(), strcat(), and uid2name().

Referenced by MUTATOR_HOOKFUNCTION().

325 {
326  if(!IS_REAL_CLIENT(player))
327  return;
328 
329  msg_entity = player;
330  if (!only_rankings)
331  {
334 
338  }
339 
340  int m = min(RANKINGS_CNT, autocvar_g_cts_send_rankings_cnt);
342  for (int i = 1; i <= m; ++i)
343  race_SendRanking(i, 0, 0, MSG_ONE);
344 }
int autocvar_g_cts_send_rankings_cnt
Definition: race.qh:10
string uid2name(string myuid)
Definition: race.qc:36
string GetMapname()
Definition: intermission.qc:18
float ServerProgsDB
Definition: world.qh:131
string speedaward_alltimebest_holder
Definition: race.qh:62
void race_send_speedaward_alltimebest(float msg)
Definition: race.qc:268
void race_send_speedaward(float msg)
Definition: race.qc:259
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
entity msg_entity
Definition: progsdefs.qc:63
float speedaward_alltimebest
Definition: race.qh:61
string record_type
Definition: world.qh:49
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"))
void race_send_recordtime(float msg)
Definition: race.qc:251
ERASEABLE string db_get(int db, string key)
Definition: map.qh:91
void race_SendRanking(float pos, float prevpos, float del, float msg)
Definition: race.qc:285
void race_send_rankings_cnt(float msg)
Definition: race.qc:277
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_SendNextCheckpoint()

void race_SendNextCheckpoint ( entity  e,
float  spec 
)

Definition at line 216 of file race.qc.

References IS_REAL_CLIENT, msg_entity, MSG_ONE, race_checkpoint_recordholders, race_checkpoint_records, race_CheckpointNetworkID(), RACE_NET_CHECKPOINT_NEXT_QUALIFYING, RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING, time, WriteByte(), WriteCoord(), and WriteString().

Referenced by checkpoint_passed(), and race_InitSpectator().

217 {
218  if(!e.race_laptime)
219  return;
220 
221  int cp = e.race_checkpoint;
222  float recordtime = race_checkpoint_records[cp];
223  float myrecordtime = e.race_checkpoint_record[cp];
224  string recordholder = race_checkpoint_recordholders[cp];
225  if(recordholder == e.netname)
226  recordholder = "";
227 
228  if(!IS_REAL_CLIENT(e))
229  return;
230 
231  if(!spec)
232  msg_entity = e;
233  WRITESPECTATABLE_MSG_ONE(msg_entity, {
234  WriteHeader(MSG_ONE, TE_CSQC_RACE);
235  if(spec)
236  {
238  //WriteCoord(MSG_ONE, e.race_laptime - e.race_penalty_accumulator);
239  WriteCoord(MSG_ONE, time - e.race_movetime - e.race_penalty_accumulator);
240  }
241  else
243  WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player will be at next
244  WriteInt24_t(MSG_ONE, recordtime);
245  if(!spec)
246  WriteInt24_t(MSG_ONE, myrecordtime);
247  WriteString(MSG_ONE, recordholder);
248  });
249 }
const int RACE_NET_CHECKPOINT_NEXT_QUALIFYING
Definition: net_linked.qh:12
const int RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING
Definition: net_linked.qh:15
float race_CheckpointNetworkID(float f)
Definition: race.qc:204
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
string race_checkpoint_recordholders[MAX_CHECKPOINTS]
Definition: race.qc:169
entity msg_entity
Definition: progsdefs.qc:63
float race_checkpoint_records[MAX_CHECKPOINTS]
Definition: race.qc:168
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_SendRanking()

void race_SendRanking ( float  pos,
float  prevpos,
float  del,
float  msg 
)

Definition at line 285 of file race.qc.

References GetMapname(), RACE_NET_SERVER_RANKINGS, race_readName(), race_readTime(), WriteByte(), WriteShort(), and WriteString().

Referenced by race_deleteTime(), race_SendAll(), and race_setTime().

286 {
287  WriteHeader(msg, TE_CSQC_RACE);
289  WriteShort(msg, pos);
290  WriteShort(msg, prevpos);
291  WriteShort(msg, del);
292  WriteString(msg, race_readName(GetMapname(), pos));
293  WriteInt24_t(msg, race_readTime(GetMapname(), pos));
294 }
string GetMapname()
Definition: intermission.qc:18
const int RACE_NET_SERVER_RANKINGS
Definition: net_linked.qh:21
float race_readTime(string map, float pos)
Definition: race.qc:78
string race_readName(string map, float pos)
Definition: race.qc:138
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_setTime()

void race_setTime ( string  map,
float  t,
string  myuid,
string  mynetname,
entity  e,
bool  showmessage 
)

Definition at line 365 of file race.qc.

References GetMapname(), getrankings(), MSG_ALL, NULL, race_readName(), race_readPos(), race_readTime(), race_readUID(), race_send_recordtime(), race_SendRanking(), race_SendStatus(), race_writeTime(), strcpy, time, TIME_DECODE, uid2name(), and write_recordmarker().

Referenced by ctf_CaptureRecord(), and race_SendTime().

366 {
367  // netname only used TEMPORARILY for printing
368  int newpos = race_readPos(map, t);
369 
370  int player_prevpos = 0;
371  for(int i = 1; i <= RANKINGS_CNT; ++i)
372  {
373  if(race_readUID(map, i) == myuid)
374  player_prevpos = i;
375  }
376 
377  float oldrec;
378  string oldrec_holder;
379  if (player_prevpos && (player_prevpos < newpos || !newpos))
380  {
381  oldrec = race_readTime(GetMapname(), player_prevpos);
382  race_SendStatus(0, e); // "fail"
383  if(showmessage)
384  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_RACE_FAIL_RANKED, mynetname, player_prevpos, t, oldrec);
385  return;
386  }
387  else if (!newpos)
388  {
389  // no ranking, time worse than the worst ranked
390  oldrec = race_readTime(GetMapname(), RANKINGS_CNT);
391  race_SendStatus(0, e); // "fail"
392  if(showmessage)
393  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_RACE_FAIL_UNRANKED, mynetname, RANKINGS_CNT, t, oldrec);
394  return;
395  }
396 
397  // if we didn't hit a return yet, we have a new record!
398 
399  // if the player does not have a UID we can unfortunately not store the record, as the rankings system relies on UIDs
400  if(myuid == "")
401  {
402  if(showmessage)
403  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_RACE_NEW_MISSING_UID, mynetname, t);
404  return;
405  }
406 
407  if(uid2name(myuid) == "^1Unregistered Player")
408  {
409  if(showmessage)
410  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_RACE_NEW_MISSING_NAME, mynetname, t);
411  return;
412  }
413 
414  oldrec = race_readTime(GetMapname(), newpos);
415  oldrec_holder = race_readName(GetMapname(), newpos);
416 
417  // store new ranking
418  race_writeTime(GetMapname(), t, myuid);
419 
420  if (newpos == 1 && showmessage)
421  {
424  }
425 
426  race_SendRanking(newpos, player_prevpos, 0, MSG_ALL);
427  strcpy(rankings_reply, getrankings());
428 
429  if(newpos == player_prevpos)
430  {
431  if(showmessage)
432  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_RACE_NEW_IMPROVED, mynetname, newpos, t, oldrec);
433  if(newpos == 1) { race_SendStatus(3, e); } // "new server record"
434  else { race_SendStatus(1, e); } // "new time"
435  }
436  else if(oldrec == 0)
437  {
438  if(showmessage)
439  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_RACE_NEW_SET, mynetname, newpos, t);
440  if(newpos == 1) { race_SendStatus(3, e); } // "new server record"
441  else { race_SendStatus(2, e); } // "new rank"
442  }
443  else
444  {
445  if(showmessage)
446  Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_RACE_NEW_BROKEN, mynetname, oldrec_holder, newpos, t, oldrec);
447  if(newpos == 1) { race_SendStatus(3, e); } // "new server record"
448  else { race_SendStatus(2, e); } // "new rank"
449  }
450 }
string getrankings()
Definition: getreplies.qc:46
void race_writeTime(string map, float t, string myuid)
Definition: race.qc:100
float race_readPos(string map, float t)
Definition: race.qc:88
string uid2name(string myuid)
Definition: race.qc:36
string GetMapname()
Definition: intermission.qc:18
string race_readUID(string map, float pos)
Definition: race.qc:83
void write_recordmarker(entity pl, float tstart, float dt)
Definition: race.qc:57
#define TIME_DECODE(n)
Definition: util.qh:62
#define strcpy(this, s)
Definition: string.qh:49
void race_SendStatus(float id, entity e)
Definition: race.qc:346
void race_send_recordtime(float msg)
Definition: race.qc:251
float race_readTime(string map, float pos)
Definition: race.qc:78
#define NULL
Definition: post.qh:17
string race_readName(string map, float pos)
Definition: race.qc:138
float time
Definition: csprogsdefs.qc:16
void race_SendRanking(float pos, float prevpos, float del, float msg)
Definition: race.qc:285
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_SpeedAwardFrame()

void race_SpeedAwardFrame ( entity  player)

Definition at line 296 of file race.qc.

References db_put(), ftos(), GetMapname(), intermission_running, IS_OBSERVER, MSG_ALL, race_send_speedaward(), race_send_speedaward_alltimebest(), record_type, ServerProgsDB, speedaward_alltimebest, speedaward_alltimebest_holder, speedaward_alltimebest_uid, speedaward_holder, speedaward_lastsent, speedaward_lastupdate, speedaward_speed, speedaward_uid, strcat(), time, vdist, and vlen().

Referenced by MUTATOR_HOOKFUNCTION().

297 {
298  if (IS_OBSERVER(player))
299  return;
300 
301  if(vdist(player.velocity - player.velocity_z * '0 0 1', >, speedaward_speed))
302  {
303  speedaward_speed = vlen(player.velocity - player.velocity_z * '0 0 1');
304  speedaward_holder = player.netname;
305  speedaward_uid = player.crypto_idfp;
307  }
309  {
313  {
320  }
321  }
322 }
ERASEABLE void db_put(int db, string key, string value)
Definition: map.qh:101
string speedaward_uid
Definition: race.qh:59
string GetMapname()
Definition: intermission.qc:18
float ServerProgsDB
Definition: world.qh:131
float speedaward_lastupdate
Definition: race.qh:15
string speedaward_alltimebest_uid
Definition: race.qh:63
string speedaward_alltimebest_holder
Definition: race.qh:62
#define IS_OBSERVER(v)
Definition: utils.qh:11
void race_send_speedaward_alltimebest(float msg)
Definition: race.qc:268
void race_send_speedaward(float msg)
Definition: race.qc:259
float speedaward_alltimebest
Definition: race.qh:61
string record_type
Definition: world.qh:49
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 vdist(v, cmp, f)
Vector distance comparison, avoids sqrt()
Definition: vector.qh:8
float speedaward_speed
Definition: race.qh:57
float speedaward_lastsent
Definition: race.qh:14
bool intermission_running
Definition: intermission.qh:9
float time
Definition: csprogsdefs.qc:16
string speedaward_holder
Definition: race.qh:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ race_StartCompleting()

void race_StartCompleting ( )

Definition at line 1174 of file race.qc.

References FOREACH_CLIENT, IS_DEAD, IS_PLAYER, race_AbandonRaceCheck(), and race_completing.

Referenced by InitiateSuddenDeath(), and race_SendTime().

1175 {
1176  race_completing = 1;
1177  FOREACH_CLIENT(IS_PLAYER(it) && IS_DEAD(it), { race_AbandonRaceCheck(it); });
1178 }
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
float race_completing
Definition: race.qh:27
#define IS_DEAD(s)
Definition: utils.qh:26
#define IS_PLAYER(v)
Definition: utils.qh:9
void race_AbandonRaceCheck(entity p)
Definition: race.qc:1163
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spawnfunc()

spawnfunc ( target_checkpoint  )

Definition at line 1153 of file race.qc.

References target_checkpoint_setup().

1154 {
1155  // xonotic defrag entity
1157 }
void target_checkpoint_setup(entity this)
Definition: race.qc:1102
+ Here is the call graph for this function:

◆ uid2name()

string uid2name ( string  myuid)

Definition at line 36 of file race.qc.

References db_get(), db_put(), db_remove, ServerProgsDB, and strcat().

Referenced by getladder(), race_checkAndWriteName(), race_readName(), race_SendAll(), and race_setTime().

37 {
38  string s = db_get(ServerProgsDB, strcat("/uid2name/", myuid));
39 
40  // FIXME remove this later after 0.6 release
41  // convert old style broken records to correct style
42  if(s == "")
43  {
44  s = db_get(ServerProgsDB, strcat("uid2name", myuid));
45  if(s != "")
46  {
47  db_put(ServerProgsDB, strcat("/uid2name/", myuid), s);
48  db_remove(ServerProgsDB, strcat("uid2name", myuid));
49  }
50  }
51 
52  if(s == "")
53  s = "^1Unregistered Player";
54  return s;
55 }
ERASEABLE void db_put(int db, string key, string value)
Definition: map.qh:101
float ServerProgsDB
Definition: world.qh:131
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"))
ERASEABLE string db_get(int db, string key)
Definition: map.qh:91
#define db_remove(db, key)
Definition: map.qh:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write_recordmarker()

void write_recordmarker ( entity  pl,
float  tstart,
float  dt 
)

Definition at line 57 of file race.qc.

References ftos(), GameLogEcho(), GetGametype(), strcat(), stuffcmd, TIME_ENCODE, and TIME_ENCODED_TOSTRING.

Referenced by ctf_CaptureRecord(), and race_setTime().

58 {
59  GameLogEcho(strcat(":recordset:", ftos(pl.playerid), ":", ftos(dt)));
60 
61  // also write a marker into demo files for demotc-race-record-extractor to find
62  stuffcmd(pl,
63  strcat(
64  strcat("//", strconv(2, 0, 0, GetGametype()), " RECORD SET ", TIME_ENCODED_TOSTRING(TIME_ENCODE(dt))),
65  " ", ftos(tstart), " ", ftos(dt), "\n"));
66 }
#define TIME_ENCODED_TOSTRING(n)
Definition: util.qh:57
#define TIME_ENCODE(t)
Definition: util.qh:61
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"))
void GameLogEcho(string s)
Definition: gamelog.qc:12
#define stuffcmd(cl,...)
Definition: progsdefs.qh:23
string GetGametype()
Definition: intermission.qc:13
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ autocvar_g_allow_checkpoints

bool autocvar_g_allow_checkpoints

Definition at line 3 of file race.qh.

Referenced by CheatImpulse(), checkpoint_passed(), IMPULSE(), and MUTATOR_HOOKFUNCTION().

◆ autocvar_g_cts_send_rankings_cnt

int autocvar_g_cts_send_rankings_cnt = 15

Definition at line 10 of file race.qh.

Referenced by race_send_rankings_cnt(), and race_SendAll().

◆ g_race_qualifying

◆ race_completed

◆ race_completing

float race_completing

Definition at line 27 of file race.qh.

Referenced by race_AbandonRaceCheck(), race_SendTime(), race_StartCompleting(), and ReadyRestart().

◆ race_fraglimit

float race_fraglimit

Definition at line 20 of file race.qh.

Referenced by MUTATOR_HOOKFUNCTION(), and rc_SetLimits().

◆ race_highest_place_spawn

float race_highest_place_spawn

◆ race_laptime

float race_laptime

Definition at line 26 of file race.qh.

◆ race_leadlimit

float race_leadlimit

Definition at line 21 of file race.qh.

Referenced by MUTATOR_HOOKFUNCTION(), and rc_SetLimits().

◆ race_lowest_place_spawn

float race_lowest_place_spawn

◆ race_movetime

float race_movetime

Definition at line 29 of file race.qh.

◆ race_movetime_count

float race_movetime_count

Definition at line 31 of file race.qh.

◆ race_movetime_frac

float race_movetime_frac

Definition at line 30 of file race.qh.

◆ race_place

float race_place

Definition at line 23 of file race.qh.

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

◆ race_respawn_checkpoint

float race_respawn_checkpoint

Definition at line 33 of file race.qh.

Referenced by race_PreparePlayer(), and race_RetractPlayer().

◆ race_respawn_spotref

entity race_respawn_spotref

Definition at line 34 of file race.qh.

Referenced by race_PreparePlayer().

◆ race_spawns

float race_spawns

Definition at line 17 of file race.qh.

Referenced by Spawn_Score(), and spawnfunc().

◆ race_started

float race_started

Definition at line 24 of file race.qh.

Referenced by race_PreparePlayer().

◆ race_teams

float race_teams

Definition at line 5 of file race.qh.

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

◆ race_timelimit

float race_timelimit

Definition at line 22 of file race.qh.

Referenced by MUTATOR_HOOKFUNCTION(), and rc_SetLimits().

◆ speedaward_alltimebest

float speedaward_alltimebest

Definition at line 61 of file race.qh.

Referenced by race_send_speedaward_alltimebest(), race_SendAll(), and race_SpeedAwardFrame().

◆ speedaward_alltimebest_holder

string speedaward_alltimebest_holder

Definition at line 62 of file race.qh.

Referenced by race_send_speedaward_alltimebest(), race_SendAll(), and race_SpeedAwardFrame().

◆ speedaward_alltimebest_uid

string speedaward_alltimebest_uid

Definition at line 63 of file race.qh.

Referenced by race_SpeedAwardFrame().

◆ speedaward_holder

string speedaward_holder

Definition at line 58 of file race.qh.

Referenced by race_send_speedaward(), and race_SpeedAwardFrame().

◆ speedaward_lastsent

float speedaward_lastsent

Definition at line 14 of file race.qh.

Referenced by race_SpeedAwardFrame().

◆ speedaward_lastupdate

float speedaward_lastupdate

Definition at line 15 of file race.qh.

Referenced by race_SpeedAwardFrame().

◆ speedaward_speed

float speedaward_speed

Definition at line 57 of file race.qh.

Referenced by race_send_speedaward(), and race_SpeedAwardFrame().

◆ speedaward_uid

string speedaward_uid

Definition at line 59 of file race.qh.

Referenced by race_SpeedAwardFrame().

◆ ST_RACE_LAPS

const float ST_RACE_LAPS = 1

Definition at line 8 of file race.qh.

Referenced by race_ScoreRules().