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

Definition at line 42 of file cl_race.qc.

43{
45 float score = me.(scores(ps_primary));
46
47 if(!(scores_flags(ps_primary) & SFL_TIME) || teamplay) // race/cts record display on HUD
48 {
49 mod_active = 0; // hide it in this case!
50 return; // no records in the actual race
51 }
52
53 mod_active = 1;
54
55 // clientside personal record
56 string rr;
57 if(ISGAMETYPE(CTS))
58 rr = CTS_RECORD;
59 else
60 rr = RACE_RECORD;
61 float t = stof(db_get(ClientProgsDB, strcat(mi_shortname, rr, "time")));
62
63 if(score && (score < t || !t) && !isdemo()) {
64 db_put(ClientProgsDB, strcat(mi_shortname, rr, "time"), ftos(score));
66 {
68 f &= ~1;
69 cvar_set("cl_autodemo_delete", ftos(f)); // don't delete demo with new record!
70 }
71 localcmd("\ncl_hook_race_pb \"",
72 TIME_ENCODED_TOSTRING(score, false), "\" \"",
73 TIME_ENCODED_TOSTRING(t, false), "\" \"",
74 (t ? TIME_ENCODED_TOSTRING(t-score, false) : "0"), "\" \"",
75 sprintf("%d", race_myrank), "\"\n");
76 }
77
78 if(t != crecordtime_prev) {
81 }
82
83 vector textPos, medalPos;
84 float squareSize;
85 if(mySize.x > mySize.y) {
86 // text on left side
87 squareSize = min(mySize.y, mySize.x/2);
88 vector ofs = vec2(0.5 * max(0, mySize.x/2 - squareSize), 0.5 * (mySize.y - squareSize));
89 textPos = pos + ofs;
90 ofs.x += 0.5 * mySize.x;
91 medalPos = pos + ofs;
92 } else {
93 // text on top
94 squareSize = min(mySize.x, mySize.y/2);
95 vector ofs = vec2(0.5 * (mySize.x - squareSize), 0.5 * max(0, mySize.y/2 - squareSize));
96 textPos = pos + ofs;
97 ofs.y += 0.5 * mySize.y;
98 medalPos = pos + ofs;
99 }
100 vector textSize = vec2(squareSize, 0.25 * squareSize);
101
102 race_showTime(_("Personal best"), textPos, eY * 0.25 * squareSize, t, textSize, time - crecordtime_change_time);
103
104 // server record
106 if(t != srecordtime_prev) {
109 }
110
111 textPos += eY * 0.5 * squareSize;
112 race_showTime(_("Server best"), textPos, eY * 0.25 * squareSize, t, textSize, time - srecordtime_change_time);
113
118 }
119
120 // race "awards"
121 float a = bound(0, race_status_time - time, 1);
122 string s = textShortenToWidth(ColorTranslateRGB(race_status_name), squareSize, '1 1 0' * 0.1 * squareSize, stringwidth_colors);
123
124 float rank = 0;
125 if(race_status > 0)
127 string rankname = count_ordinal(rank);
128 vector namepos = medalPos + '0 0.8 0' * squareSize;
129 vector rankpos = medalPos + '0 0.15 0' * squareSize;
130
131 if(race_status == 0)
132 drawpic_aspect_skin(medalPos, "race_newfail", '1 1 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
133 else if(race_status == 1) {
134 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);
135 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
136 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
137 } else if(race_status == 2) {
138 if(strdecolorize(race_status_name) == strdecolorize(entcs_GetName(player_localnum)) || !race_myrank || race_myrank < rank)
139 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);
140 else
141 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);
142 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
143 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
144 } else if(race_status == 3) {
145 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);
146 drawcolorcodedstring_aspect(namepos, s, '1 0.2 0' * squareSize, panel_fg_alpha * a, DRAWFLAG_NORMAL);
147 drawstring_aspect(rankpos, rankname, '1 0.15 0' * squareSize, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
148 }
149
150 if (race_status_time - time <= 0) {
151 race_status_prev = -1;
152 race_status = -1;
155 }
156}
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_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
bool autocvar_cl_autodemo_delete_keeprecords
Definition cl_race.qh:3
void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag)
Definition draw.qc:110
void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAlpha, float drawflag)
Definition draw.qc:116
#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
bool autocvar_cl_autodemo_delete
Definition main.qh:32
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:1071
string mi_shortname
Definition util.qh:126
#define CTS_RECORD
Definition util.qh:98
#define TIME_ENCODED_TOSTRING(n, compact)
Definition util.qh:96
#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
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)
float isdemo()
float stof(string val,...)
float bound(float min, float value, float max)
float min(float f,...)
string ftos(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 autocvar_cl_autodemo_delete, autocvar_cl_autodemo_delete_keeprecords, bound(), ClientProgsDB, ColorTranslateRGB(), count_ordinal(), crecordtime_change_time, crecordtime_prev, CTS_RECORD, cvar_set(), db_get(), db_put(), drawcolorcodedstring_aspect(), DRAWFLAG_NORMAL, drawpic_aspect_skin, drawstring_aspect(), entcs_GetName(), entity(), eY, ftos(), isdemo(), ISGAMETYPE, localcmd(), 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, scores_flags, SFL_TIME, srecordtime_change_time, srecordtime_prev, stof(), strcat(), strcpy, strfree, stringwidth_colors(), teamplay, textShortenToWidth(), time, TIME_ENCODED_TOSTRING, vec2, and vector.

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

◆ MUTATOR_HOOKFUNCTION() [1/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
DrawScoreboardAccuracy  )

Definition at line 189 of file cl_race.qc.

190{
191 return ISGAMETYPE(RACE); // accuracy is not a factor in this gametype
192}

References ISGAMETYPE.

◆ MUTATOR_HOOKFUNCTION() [2/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
DrawScoreboardItemStats  )

Definition at line 175 of file cl_race.qc.

176{
177 return ISGAMETYPE(RACE); // hide the item stats panel
178}

References ISGAMETYPE.

◆ MUTATOR_HOOKFUNCTION() [3/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
HUD_Physics_showoptional  )

Definition at line 160 of file cl_race.qc.

161{
162 return ISGAMETYPE(RACE); // show the optional physics panel
163}

References ISGAMETYPE.

◆ MUTATOR_HOOKFUNCTION() [4/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
HUD_Score_show  )

Definition at line 170 of file cl_race.qc.

171{
172 return spectatee_status == -1 && ISGAMETYPE(RACE); // hide the score panel while observing
173}
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 165 of file cl_race.qc.

166{
167 return ISGAMETYPE(RACE); // show the optional strafehud
168}

References ISGAMETYPE.

◆ MUTATOR_HOOKFUNCTION() [6/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
ShowRaceTimer  )

Definition at line 194 of file cl_race.qc.

195{
196 return ISGAMETYPE(RACE); // show the race timer panel
197}

References ISGAMETYPE.

◆ MUTATOR_HOOKFUNCTION() [7/8]

MUTATOR_HOOKFUNCTION ( cl_race ,
ShowRankings  )

Definition at line 180 of file cl_race.qc.

181{
182 if(ISGAMETYPE(RACE))
183 {
184 M_ARGV(0, string) = _("Rankings");
185 return true;
186 }
187}
#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 199 of file cl_race.qc.

200{
201 return ISGAMETYPE(RACE); // show all competitors in a race
202}

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

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

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