From bda0fa435b85e09e3dfc01d31d8b175cdbad16ec Mon Sep 17 00:00:00 2001 From: fruitiex Date: Sun, 11 Oct 2009 10:27:17 +0000 Subject: [PATCH] show server record on the hud (race/cts) git-svn-id: svn://svn.icculus.org/nexuiz/trunk@8091 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/client/Defs.qc | 1 + data/qcsrc/client/Main.qc | 4 +++ data/qcsrc/client/sbar.qc | 55 ++++++++++++++++++++++++++-------- data/qcsrc/common/constants.qh | 1 + data/qcsrc/server/cl_client.qc | 5 ++++ data/qcsrc/server/race.qc | 21 ++++++++++++- 6 files changed, 73 insertions(+), 14 deletions(-) diff --git a/data/qcsrc/client/Defs.qc b/data/qcsrc/client/Defs.qc index e19094c73..5340abda8 100644 --- a/data/qcsrc/client/Defs.qc +++ b/data/qcsrc/client/Defs.qc @@ -192,6 +192,7 @@ float race_penaltyaccumulator; // qualifying: total penalty time in tenths float race_penaltyeventtime; // time when the player got the penalty float race_penaltytime; // duration of penalty time, in tenths string race_penaltyreason; // reason for penalty +float race_server_record; // server record // RACE float race_mycheckpoint; diff --git a/data/qcsrc/client/Main.qc b/data/qcsrc/client/Main.qc index 97c5c8d8f..72cd9998d 100644 --- a/data/qcsrc/client/Main.qc +++ b/data/qcsrc/client/Main.qc @@ -1027,6 +1027,10 @@ void Net_ReadRace() strunzone(race_penaltyreason); race_penaltyreason = strzone(ReadString()); break; + + case RACE_NET_SERVER_RECORD: + race_server_record = ReadInt24_t(); + break; } } diff --git a/data/qcsrc/client/sbar.qc b/data/qcsrc/client/sbar.qc index f90921180..a928915f1 100644 --- a/data/qcsrc/client/sbar.qc +++ b/data/qcsrc/client/sbar.qc @@ -3038,14 +3038,22 @@ void CSQC_nb_hud(void) float crecordtime_prev; // last remembered crecordtime float crecordtime_change_time; // time when crecordtime last changed +float srecordtime_prev; // last remembered srecordtime +float srecordtime_change_time; // time when srecordtime last changed void CSQC_race_hud(void) { entity me; me = (spectatee_status > 0) ? playerslots[spectatee_status - 1] : playerslots[player_localentnum - 1]; - float crecordtime, score; + float crecordtime, srecordtime, score; float f; // yet another function has this score = me.(scores[ps_primary]); + drawfont = sbar_bigfont; + vector pos; + pos_x = 2; + pos_y = vid_conheight - 48; + + // clientside personal record string rr; if(gametype == GAME_CTS) rr = CTS_RECORD; @@ -3062,26 +3070,47 @@ void CSQC_race_hud(void) } f = time - crecordtime_change_time; - vector pos; - pos_x = 2; - pos_y = vid_conheight - 48; - - float pmin, psec, pmsec; - pmin = floor(crecordtime/(60 * TIME_FACTOR)); - psec = floor((crecordtime - pmin*(60 * TIME_FACTOR))/TIME_FACTOR); - pmsec = crecordtime - pmin*60*TIME_FACTOR - psec*TIME_FACTOR; - drawfont = sbar_bigfont; + float cmin, csec, cmsec; + cmin = floor(crecordtime/(60 * TIME_FACTOR)); + csec = floor((crecordtime - cmin*(60 * TIME_FACTOR))/TIME_FACTOR); + cmsec = crecordtime - cmin*60*TIME_FACTOR - csec*TIME_FACTOR; if (f > 1) { drawstring(pos, "Personal best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - drawstring(pos + '0 10 0', strcat(ftos(pmin),":", ftos(psec),":",ftos(pmsec)),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + drawstring(pos + '0 10 0', strcat(ftos(cmin),":", ftos(csec),":",ftos(cmsec)),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); } else { drawstring(pos, "Personal best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); - drawstring(pos + '0 10 0', strcat(ftos(pmin),":", ftos(psec),":",ftos(pmsec)),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + drawstring(pos + '0 10 0', strcat(ftos(cmin),":", ftos(csec),":",ftos(cmsec)),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); // expanding drawstring(pos - '0 50 0' * f, "Personal best ", '10 10 0' + '30 30 0' * f, '1 1 1', sbar_alpha_fg * (1 - f), DRAWFLAG_NORMAL); - drawstring(pos + '0 10 0' - '0 30 0' * f, strcat(ftos(pmin),":", ftos(psec),":",ftos(pmsec)),'14 14 0' + '42 42 0' * f, '1 1 1', sbar_alpha_fg * (1 - f), DRAWFLAG_NORMAL); + drawstring(pos + '0 10 0' - '0 30 0' * f, strcat(ftos(cmin),":", ftos(csec),":",ftos(cmsec)),'14 14 0' + '42 42 0' * f, '1 1 1', sbar_alpha_fg * (1 - f), DRAWFLAG_NORMAL); + } + + // server record + pos_y += 26; + srecordtime = race_server_record; + if(srecordtime != srecordtime_prev) { + srecordtime_prev = srecordtime; + srecordtime_change_time = time; + } + f = time - srecordtime_change_time; + + float smin, ssec, smsec; + smin = floor(srecordtime/(60 * TIME_FACTOR)); + ssec = floor((srecordtime - smin*(60 * TIME_FACTOR))/TIME_FACTOR); + smsec = srecordtime - smin*60*TIME_FACTOR - ssec*TIME_FACTOR; + + if (f > 1) { + drawstring(pos, "Server best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + drawstring(pos + '0 10 0', strcat(ftos(smin),":", ftos(ssec),":",ftos(smsec)),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + } else { + drawstring(pos, "Server best ", '10 10 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + drawstring(pos + '0 10 0', strcat(ftos(smin),":", ftos(ssec),":",ftos(smsec)),'14 14 0', '1 1 1', sbar_alpha_fg, DRAWFLAG_NORMAL); + + // expanding + drawstring(pos - '0 50 0' * f, "Server best ", '10 10 0' + '30 30 0' * f, '1 1 1', sbar_alpha_fg * (1 - f), DRAWFLAG_NORMAL); + drawstring(pos + '0 10 0' - '0 30 0' * f, strcat(ftos(smin),":", ftos(ssec),":",ftos(smsec)),'14 14 0' + '42 42 0' * f, '1 1 1', sbar_alpha_fg * (1 - f), DRAWFLAG_NORMAL); } drawfont = sbar_font; } diff --git a/data/qcsrc/common/constants.qh b/data/qcsrc/common/constants.qh index a6f122bcf..820ed031f 100644 --- a/data/qcsrc/common/constants.qh +++ b/data/qcsrc/common/constants.qh @@ -59,6 +59,7 @@ const float RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT = 4; // byte checkpoint, sh const float RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING = 5; // byte nextcheckpoint, float laptime, short recordtime, string recordholder const float RACE_NET_PENALTY_RACE = 6; // byte penaltytime, string reason const float RACE_NET_PENALTY_QUALIFYING = 7; // byte penaltytime, string reason +const float RACE_NET_SERVER_RECORD = 8; // server record, sent to client const float ENT_CLIENT = 0; const float ENT_CLIENT_DEAD = 1; diff --git a/data/qcsrc/server/cl_client.qc b/data/qcsrc/server/cl_client.qc index 8f392255e..50a0fed61 100644 --- a/data/qcsrc/server/cl_client.qc +++ b/data/qcsrc/server/cl_client.qc @@ -1,3 +1,5 @@ +void race_send_recordtime(); + float ClientData_Send(entity to, float sf) { if(to != self.owner) @@ -1283,6 +1285,9 @@ void ClientConnect (void) local string s; float t; + if(g_race || g_cts) + race_send_recordtime(); + if(self.flags & FL_CLIENT) { print("Warning: ClientConnect, but already connected!\n"); diff --git a/data/qcsrc/server/race.qc b/data/qcsrc/server/race.qc index ea4a45178..0c2df3b4e 100644 --- a/data/qcsrc/server/race.qc +++ b/data/qcsrc/server/race.qc @@ -18,6 +18,8 @@ entity race_checkpoint_lastplayers[MAX_CHECKPOINTS]; float race_highest_checkpoint; float race_timed_checkpoint; +void race_send_recordtime(); + float race_NextCheckpoint(float f) { if(f >= race_highest_checkpoint) @@ -138,7 +140,6 @@ void race_SendTime(entity e, float cp, float t, float tvalid) float recordtime; string recordholder; - if(g_race_qualifying) { if(tvalid) @@ -174,6 +175,7 @@ void race_SendTime(entity e, float cp, float t, float tvalid) db_put(ServerProgsDB, strcat(GetMapname(), rr, "time"), ftos(t)); db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname"), e.netname); write_recordmarker(e, time - TIME_DECODE(t), TIME_DECODE(t)); + race_send_recordtime(); } else if(t < grecordtime) { @@ -184,6 +186,7 @@ void race_SendTime(entity e, float cp, float t, float tvalid) db_put(ServerProgsDB, strcat(GetMapname(), rr, "time"), ftos(t)); db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname"), e.netname); write_recordmarker(e, time - TIME_DECODE(t), TIME_DECODE(t)); + race_send_recordtime(); } else { @@ -764,3 +767,19 @@ void spawnfunc_trigger_race_penalty() if (!self.race_penalty) self.race_penalty = 5; } + +void race_send_recordtime() +{ + float grecordtime; + string rr; + if(g_cts) + rr = CTS_RECORD; + else + rr = RACE_RECORD; + grecordtime = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "time"))); + // send the server best time + WriteByte(MSG_ONE, SVC_TEMPENTITY); + WriteByte(MSG_ONE, TE_CSQC_RACE); + WriteByte(MSG_ONE, RACE_NET_SERVER_RECORD); + WriteInt24_t(MSG_ONE, grecordtime); +} -- 2.39.2