Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
cl_race.qc File Reference
#include "cl_race.qh"
#include <client/draw.qh>
#include <common/mutators/base.qh>
Include dependency graph for cl_race.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void HUD_Mod_Race (vector pos, vector mySize, bool should_draw)
 MUTATOR_HOOKFUNCTION (cl_race, DrawScoreboardAccuracy)
 MUTATOR_HOOKFUNCTION (cl_race, DrawScoreboardItemStats)
 MUTATOR_HOOKFUNCTION (cl_race, HUD_Physics_showoptional)
 MUTATOR_HOOKFUNCTION (cl_race, HUD_Score_show)
 MUTATOR_HOOKFUNCTION (cl_race, HUD_StrafeHUD_showoptional)
 MUTATOR_HOOKFUNCTION (cl_race, ShowRaceTimer)
 MUTATOR_HOOKFUNCTION (cl_race, ShowRankings)
 MUTATOR_HOOKFUNCTION (cl_race, TeamRadar_Draw)
int race_CheckName (string net_name)
void race_showTime (string text, vector pos, vector timeText_ofs, float theTime, vector textSize, float f)
void race_UpdateDB (string rr, float new_score, float old_score)
 REGISTER_MUTATOR (cl_race, true)

Variables

float crecordtime_change_time
float crecordtime_prev
string race_status_name_prev
int race_status_prev
float race_status_time
float srecordtime_change_time
float srecordtime_prev

Function Documentation

◆ HUD_Mod_Race()

void HUD_Mod_Race ( vector pos,
vector mySize,
bool should_draw )

Definition at line 59 of file cl_race.qc.

60{
61 if (!should_draw)
62 return;
63
65 float score = me.(scores(ps_primary));
66
67 if(!(scores_flags(ps_primary) & SFL_TIME) || teamplay) // race/cts record display on HUD
68 {
69 mod_active = 0; // hide it in this case!
70 return; // no records in the actual race
71 }
72
73 mod_active = 1;
74
75 // clientside personal record
76 string rr;
77 if(ISGAMETYPE(CTS))
78 rr = CTS_RECORD;
79 else
80 rr = RACE_RECORD;
81 float t = stof(db_get(ClientProgsDB, strcat(mi_shortname, rr, "time")));
82
83 if (score && (score < t || !t) && !isdemo())
84 race_UpdateDB(rr, score, t);
85
86 if(t != crecordtime_prev) {
89 }
90
91 vector textPos, medalPos;
92 float squareSize;
93 if(mySize.x > mySize.y) {
94 // text on left side
95 squareSize = min(mySize.y, mySize.x/2);
96 vector ofs = vec2(0.5 * max(0, mySize.x/2 - squareSize), 0.5 * (mySize.y - squareSize));
97 textPos = pos + ofs;
98 ofs.x += 0.5 * mySize.x;
99 medalPos = pos + ofs;
100 } else {
101 // text on top
102 squareSize = min(mySize.x, mySize.y/2);
103 vector ofs = vec2(0.5 * (mySize.x - squareSize), 0.5 * max(0, mySize.y/2 - squareSize));
104 textPos = pos + ofs;
105 ofs.y += 0.5 * mySize.y;
106 medalPos = pos + ofs;
107 }
108 vector textSize = vec2(squareSize, 0.25 * squareSize);
109
110 race_showTime(_("Personal best"), textPos, eY * 0.25 * squareSize, t, textSize, time - crecordtime_change_time);
111
112 // server record
114 if(t != srecordtime_prev) {
117 }
118
119 textPos += eY * 0.5 * squareSize;
120 race_showTime(_("Server best"), textPos, eY * 0.25 * squareSize, t, textSize, time - srecordtime_change_time);
121
126 }
127
128 // race "awards"
129 float a = bound(0, race_status_time - time, 1);
130 string s = textShortenToWidth(ColorTranslateRGB(race_status_name), squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
131
132 float rank = 0;
133 if(race_status > 0)
135 string rankname = count_ordinal(rank);
136 vector namepos = medalPos + '0 0.8 0' * squareSize;
137 vector rankpos = medalPos + '0 0.15 0' * squareSize;
138
139 if(race_status == 0)
140 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
141 else if(race_status == 1) {
142 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newtime", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
143 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
144 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
145 } else if(race_status == 2) {
146 if(strdecolorize(race_status_name) == strdecolorize(entcs_GetName(player_localnum)) || !race_myrank || race_myrank < rank)
147 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankgreen", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
148 else
149 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrankyellow", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
150 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
151 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
152 } else if(race_status == 3) {
153 drawpic_aspect_skin(medalPos + '0.1 0 0' * squareSize, "race_newrecordserver", '1 1 0' * 0.8 * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
154 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
155 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
156 }
157
158 if (race_status_time - time <= 0) {
159 race_status_prev = -1;
160 race_status = -1;
163 }
164}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
int race_CheckName(string net_name)
Definition cl_race.qc:18
float srecordtime_change_time
Definition cl_race.qc:10
float crecordtime_prev
Definition cl_race.qc:7
float srecordtime_prev
Definition cl_race.qc:9
float race_status_time
Definition cl_race.qc:12
void race_UpdateDB(string rr, float new_score, float old_score)
Definition cl_race.qc:42
void race_showTime(string text, vector pos, vector timeText_ofs, float theTime, vector textSize, float f)
Definition cl_race.qc:32
float crecordtime_change_time
Definition cl_race.qc:8
string race_status_name_prev
Definition cl_race.qc:14
int race_status_prev
Definition cl_race.qc:13
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition draw.qc:109
void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag)
Definition draw.qc:115
#define drawpic_aspect_skin(pos, pic, sz, color, theAlpha, drawflag)
Definition draw.qh:78
entity playerslots[255]
Definition main.qh:84
int ClientProgsDB
Definition main.qh:204
#define ISGAMETYPE(NAME)
Definition main.qh:46
const int SFL_TIME
Display as mm:ss.s, value is stored as 10ths of a second (AND 0 is the worst possible value!...
Definition scores.qh:122
#define scores_flags(this)
Definition scores.qh:147
string textShortenToWidth(string theText, float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1171
string mi_shortname
Definition util.qh:126
#define CTS_RECORD
Definition util.qh:98
#define RACE_RECORD
Definition util.qh:97
ERASEABLE string count_ordinal(int interval)
Definition counting.qh:66
const float DRAWFLAG_NORMAL
float player_localnum
float time
string entcs_GetName(int i)
Definition ent_cs.qh:151
float panel_fg_alpha
Definition hud.qh:169
PlayerScoreField ps_primary
Definition hud.qh:117
ERASEABLE string db_get(int db, string key)
Definition map.qh:91
float isdemo()
float stof(string val,...)
float bound(float min, float value, float max)
float min(float f,...)
float max(float f,...)
bool mod_active
Definition modicons.qh:7
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
float race_myrank
Definition racetimer.qh:49
float race_server_record
Definition racetimer.qh:29
string race_status_name
Definition racetimer.qh:48
float race_status
Definition racetimer.qh:47
vector
Definition self.qh:92
ERASEABLE string ColorTranslateRGB(string s)
Definition string.qh:196
#define strfree(this)
Definition string.qh:59
#define strcpy(this, s)
Definition string.qh:52
float stringwidth_colors(string s, vector theSize)
Definition string.qh:30
bool teamplay
Definition teams.qh:59
const vector eY
Definition vector.qh:45
#define vec2(...)
Definition vector.qh:90

References bound(), ClientProgsDB, ColorTranslateRGB(), count_ordinal(), crecordtime_change_time, crecordtime_prev, CTS_RECORD, db_get(), drawcolorcodedstring_aspect(), DRAWFLAG_NORMAL, drawpic_aspect_skin, drawstring_aspect(), entcs_GetName(), entity(), eY, isdemo(), ISGAMETYPE, max(), mi_shortname, min(), mod_active, panel_fg_alpha, player_localnum, playerslots, ps_primary, race_CheckName(), race_myrank, RACE_RECORD, race_server_record, race_showTime(), race_status, race_status_name, race_status_name_prev, race_status_prev, race_status_time, race_UpdateDB(), scores_flags, SFL_TIME, srecordtime_change_time, srecordtime_prev, stof(), strcat(), strcpy, strfree, stringwidth_colors(), teamplay, textShortenToWidth(), time, vec2, and vector.

Referenced by Race::void(), and RaceCTS::void().

◆ MUTATOR_HOOKFUNCTION() [1/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
DrawScoreboardAccuracy  )

Definition at line 197 of file cl_race.qc.

198{
199 return ISGAMETYPE(RACE); // accuracy is not a factor in this gametype
200}

References ISGAMETYPE.

◆ MUTATOR_HOOKFUNCTION() [2/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
DrawScoreboardItemStats  )

Definition at line 183 of file cl_race.qc.

184{
185 return ISGAMETYPE(RACE); // hide the item stats panel
186}

References ISGAMETYPE.

◆ MUTATOR_HOOKFUNCTION() [3/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
HUD_Physics_showoptional  )

Definition at line 168 of file cl_race.qc.

169{
170 return ISGAMETYPE(RACE); // show the optional physics panel
171}

References ISGAMETYPE.

◆ MUTATOR_HOOKFUNCTION() [4/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
HUD_Score_show  )

Definition at line 178 of file cl_race.qc.

179{
180 return spectatee_status == -1 && ISGAMETYPE(RACE); // hide the score panel while observing
181}
int spectatee_status
the -1 disables HUD panels before CSQC receives necessary data
Definition main.qh:197

References ISGAMETYPE, and spectatee_status.

◆ MUTATOR_HOOKFUNCTION() [5/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
HUD_StrafeHUD_showoptional  )

Definition at line 173 of file cl_race.qc.

174{
175 return ISGAMETYPE(RACE); // show the optional strafehud
176}

References ISGAMETYPE.

◆ MUTATOR_HOOKFUNCTION() [6/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
ShowRaceTimer  )

Definition at line 202 of file cl_race.qc.

203{
204 return ISGAMETYPE(RACE); // show the race timer panel
205}

References ISGAMETYPE.

◆ MUTATOR_HOOKFUNCTION() [7/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
ShowRankings  )

Definition at line 188 of file cl_race.qc.

189{
190 if(ISGAMETYPE(RACE))
191 {
192 M_ARGV(0, string) = _("Rankings");
193 return true;
194 }
195}
#define M_ARGV(x, type)
Definition events.qh:17

References ISGAMETYPE, and M_ARGV.

◆ MUTATOR_HOOKFUNCTION() [8/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
TeamRadar_Draw  )

Definition at line 207 of file cl_race.qc.

208{
209 return ISGAMETYPE(RACE); // show all competitors in a race
210}

References ISGAMETYPE.

◆ race_CheckName()

int race_CheckName ( string net_name)

Definition at line 18 of file cl_race.qc.

19{
20 int rank = 0;
21 string zoned_name = strzone(strdecolorize(net_name));
22 for (int i = RANKINGS_CNT - 1; i >= 0; --i)
23 if (strdecolorize(grecordholder[i]) == zoned_name)
24 {
25 rank = i + 1;
26 break;
27 }
28 strfree(zoned_name);
29 return rank;
30}
string grecordholder[RANKINGS_CNT]
Definition main.qh:81
const int RANKINGS_CNT
Definition constants.qh:31
string strzone(string s)

References grecordholder, RANKINGS_CNT, strfree, and strzone().

Referenced by HUD_Mod_Race().

◆ race_showTime()

void race_showTime ( string text,
vector pos,
vector timeText_ofs,
float theTime,
vector textSize,
float f )

Definition at line 32 of file cl_race.qc.

33{
34 drawstring_aspect(pos, text, textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
35 drawstring_aspect(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime, false), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
36 if (f < 1) {
37 drawstring_aspect_expanding(pos, text, textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
38 drawstring_aspect_expanding(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime, false), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
39 }
40}
void drawstring_aspect_expanding(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag, float fadelerp)
Definition draw.qc:137
#define TIME_ENCODED_TOSTRING(n, compact)
Definition util.qh:96

References DRAWFLAG_NORMAL, drawstring_aspect(), drawstring_aspect_expanding(), panel_fg_alpha, TIME_ENCODED_TOSTRING, and vector.

Referenced by HUD_Mod_Race().

◆ race_UpdateDB()

void race_UpdateDB ( string rr,
float new_score,
float old_score )

Definition at line 42 of file cl_race.qc.

43{
44 // TODO: relocate this out of HUD code
45 db_put(ClientProgsDB, strcat(mi_shortname, rr, "time"), ftos(new_score));
47 {
49 i &= ~1;
50 cvar_set("cl_autodemo_delete", itos(i)); // don't delete demo with new record!
51 }
52 localcmd("\ncl_hook_race_pb \"",
53 TIME_ENCODED_TOSTRING(new_score, false), "\" \"",
54 TIME_ENCODED_TOSTRING(old_score, false), "\" \"",
55 (old_score ? TIME_ENCODED_TOSTRING(old_score - new_score, false) : "0"), "\" \"",
56 sprintf("%d", race_myrank), "\"\n");
57}
bool autocvar_cl_autodemo_delete_keeprecords
Definition cl_race.qh:3
bool autocvar_cl_autodemo_delete
Definition main.qh:32
#define itos(i)
Definition int.qh:6
ERASEABLE void db_put(int db, string key, string value)
Definition map.qh:101
void localcmd(string command,...)
void cvar_set(string name, string value)
string ftos(float f)

References autocvar_cl_autodemo_delete, autocvar_cl_autodemo_delete_keeprecords, ClientProgsDB, cvar_set(), db_put(), ftos(), itos, localcmd(), mi_shortname, race_myrank, strcat(), and TIME_ENCODED_TOSTRING.

Referenced by HUD_Mod_Race().

◆ REGISTER_MUTATOR()

REGISTER_MUTATOR ( cl_race ,
true  )

Variable Documentation

◆ crecordtime_change_time

float crecordtime_change_time

Definition at line 8 of file cl_race.qc.

Referenced by HUD_Mod_Race().

◆ crecordtime_prev

float crecordtime_prev

Definition at line 7 of file cl_race.qc.

Referenced by HUD_Mod_Race().

◆ race_status_name_prev

string race_status_name_prev

Definition at line 14 of file cl_race.qc.

Referenced by HUD_Mod_Race().

◆ race_status_prev

int race_status_prev

Definition at line 13 of file cl_race.qc.

Referenced by HUD_Mod_Race().

◆ race_status_time

float race_status_time

Definition at line 12 of file cl_race.qc.

Referenced by HUD_Mod_Race().

◆ srecordtime_change_time

float srecordtime_change_time

Definition at line 10 of file cl_race.qc.

Referenced by HUD_Mod_Race().

◆ srecordtime_prev

float srecordtime_prev

Definition at line 9 of file cl_race.qc.

Referenced by HUD_Mod_Race().