]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Don't show an empty race panel in modes where times don't matter, also add a setting...
authorMario <mario@smbclan.net>
Sun, 9 Jul 2017 17:28:49 +0000 (03:28 +1000)
committerMario <mario@smbclan.net>
Sun, 9 Jul 2017 17:28:49 +0000 (03:28 +1000)
defaultXonotic.cfg
qcsrc/client/hud/panel/modicons.qc
qcsrc/client/main.qc
qcsrc/common/net_linked.qh
qcsrc/server/race.qc
qcsrc/server/race.qh

index 2909b60c86a717b3bc99c57008000114e48d4f7d..ba8bdb228d0f7116abaf7a7cea39eb25561d122a 100644 (file)
@@ -1102,6 +1102,8 @@ seta cl_autoscreenshot 1 "Take a screenshot upon the end of a match... 0 = Disab
 
 seta cl_jetpack_jump 1 "Activate jetpack by pressing jump in the air. 0 = Disable, 1 = Stop when touching ground, 2 = Enable"
 
+seta cl_race_cptimes_onlyself 0 "Only show your own times on checkpoints in Race/CTS"
+
 // must be at the bottom of this file:
 
 set g_bugrigs 0
index e87d64c87bb002641fedb5c5884b000593aacb62..065e632f19313ac532db6214bc0dc9e7b96ab7c9 100644 (file)
@@ -512,14 +512,18 @@ void race_showTime(string text, vector pos, vector timeText_ofs, float theTime,
 
 void HUD_Mod_Race(vector pos, vector mySize)
 {
-       mod_active = 1; // race should never hide the mod icons panel
        entity me;
        me = playerslots[player_localnum];
        float score;
        score = me.(scores(ps_primary));
 
        if(!(scores_flags(ps_primary) & SFL_TIME) || teamplay) // race/cts record display on HUD
+       {
+               mod_active = 0; // hide it in this case!
                return; // no records in the actual race
+       }
+
+       mod_active = 1;
 
        // clientside personal record
        string rr;
index c53943221107e129673cb40c09d8153c04211d52..87f3a1bb4afff6f94c43b6df8a7d32c76193b065 100644 (file)
@@ -131,6 +131,8 @@ void CSQC_Init()
 
        registercvar("cl_spawn_near_teammate", "1");
 
+       registercvar("cl_race_cptimes_onlyself", "0");
+
        if(autocvar_cl_lockview)
                cvar_set("cl_lockview", "0");
 
@@ -1044,7 +1046,22 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                                race_penaltyaccumulator = 0;
                                race_laptime = time; // valid
                        }
+                       break;
+               case RACE_NET_CHECKPOINT_HIT_SELF_QUALIFYING:
+                       race_checkpoint = ReadByte();
+                       race_time = ReadInt24_t();
+                       race_previousbesttime = ReadInt24_t();
+                       if(race_previousbestname)
+                               strunzone(race_previousbestname);
+                       race_previousbestname = strzone(""); // handled by MakeRaceString
+
+                       race_checkpointtime = time;
 
+                       if(race_checkpoint == 0 || race_checkpoint == 254)
+                       {
+                               race_penaltyaccumulator = 0;
+                               race_laptime = time; // valid
+                       }
                        break;
 
                case RACE_NET_CHECKPOINT_CLEAR:
@@ -1065,6 +1082,15 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                        race_nextbestname = strzone(ReadString());
                        break;
 
+               case RACE_NET_CHECKPOINT_NEXT_SELF_QUALIFYING:
+                       race_nextcheckpoint = ReadByte();
+
+                       race_nextbesttime = ReadInt24_t();
+                       if(race_nextbestname)
+                               strunzone(race_nextbestname);
+                       race_nextbestname = strzone(""); // handled by MakeRaceString
+                       break;
+
                case RACE_NET_CHECKPOINT_HIT_RACE:
                        race_mycheckpoint = ReadByte();
                        race_mycheckpointtime = time;
@@ -1074,7 +1100,11 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                                race_mycheckpointlapsdelta -= 256;
                        if(race_mycheckpointenemy)
                                strunzone(race_mycheckpointenemy);
-                       race_mycheckpointenemy = strzone(ReadString());
+                       int who = ReadByte();
+                       if(who)
+                               race_mycheckpointenemy = strzone(entcs_GetName(who - 1));
+                       else
+                               race_mycheckpointenemy = strzone(""); // TODO: maybe string_null works fine here?
                        break;
 
                case RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT:
@@ -1086,7 +1116,11 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                                race_othercheckpointlapsdelta -= 256;
                        if(race_othercheckpointenemy)
                                strunzone(race_othercheckpointenemy);
-                       race_othercheckpointenemy = strzone(ReadString());
+                       int what = ReadByte();
+                       if(what)
+                               race_othercheckpointenemy = strzone(entcs_GetName(what - 1));
+                       else
+                               race_othercheckpointenemy = strzone(""); // TODO: maybe string_null works fine here?
                        break;
 
                case RACE_NET_PENALTY_RACE:
index de8cf8f92d9bb9095fe82f9e68147fe0631ca13e..7b69ad5030c9fb9d6ec510612001f2551f37e255 100644 (file)
@@ -20,6 +20,8 @@ const int RACE_NET_SPEED_AWARD = 9; // speed award, sent to client
 const int RACE_NET_SPEED_AWARD_BEST = 10; // all time best speed award, sent to client
 const int RACE_NET_SERVER_RANKINGS = 11;
 const int RACE_NET_SERVER_STATUS = 12;
+const int RACE_NET_CHECKPOINT_HIT_SELF_QUALIFYING = 13; // byte checkpoint, short time, short recordtime
+const int RACE_NET_CHECKPOINT_NEXT_SELF_QUALIFYING = 14; // byte nextcheckpoint, short recordtime
 
 REGISTER_NET_LINKED(_ENT_CLIENT_INIT)
 #ifdef CSQC
index ef82cc3d603c6751f6811bcdab5a75353ade2268..80023e76ada42a67139ba3aeeaa1644aeda14db5 100644 (file)
@@ -116,6 +116,8 @@ float race_checkpoint_lasttimes[MAX_CHECKPOINTS];
 float race_checkpoint_lastlaps[MAX_CHECKPOINTS];
 entity race_checkpoint_lastplayers[MAX_CHECKPOINTS];
 
+.float race_checkpoint_record[MAX_CHECKPOINTS];
+
 float race_highest_checkpoint;
 float race_timed_checkpoint;
 
@@ -158,23 +160,19 @@ float race_CheckpointNetworkID(float f)
 
 void race_SendNextCheckpoint(entity e, float spec) // qualifying only
 {
-       float recordtime;
-       string recordholder;
-       float cp;
-
        if(!e.race_laptime)
                return;
 
-       cp = e.race_checkpoint;
-       recordtime = race_checkpoint_records[cp];
-       recordholder = race_checkpoint_recordholders[cp];
+       int cp = e.race_checkpoint;
+       float recordtime = race_checkpoint_records[cp];
+       string recordholder = race_checkpoint_recordholders[cp];
        if(recordholder == e.netname)
                recordholder = "";
 
        if(!IS_REAL_CLIENT(e))
                return;
 
-       if(!spec)
+       if(!spec && !e.cvar_cl_race_cptimes_onlyself) // don't show spectators the player's personal time
                msg_entity = e;
        WRITESPECTATABLE_MSG_ONE(msg_entity, {
                WriteHeader(MSG_ONE, TE_CSQC_RACE);
@@ -190,6 +188,18 @@ void race_SendNextCheckpoint(entity e, float spec) // qualifying only
                WriteInt24_t(MSG_ONE, recordtime);
                WriteString(MSG_ONE, recordholder);
        });
+
+       if(!spec && e.cvar_cl_race_cptimes_onlyself) // don't send to spectators!
+       {
+               recordtime = e.race_checkpoint_record[cp];
+
+               // not spectatable
+               msg_entity = e;
+               WriteHeader(MSG_ONE, TE_CSQC_RACE);
+               WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_NEXT_SELF_QUALIFYING);
+               WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player will be at next
+               WriteInt24_t(MSG_ONE, recordtime);
+       }
 }
 
 void race_send_recordtime(float msg)
@@ -411,13 +421,16 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                }
        }
 
-       float recordtime;
-       string recordholder;
        if(g_race_qualifying)
        {
+               float recordtime;
+               float myrecordtime;
+               string recordholder;
+
                if(tvalid)
                {
                        recordtime = race_checkpoint_records[cp];
+                       myrecordtime = e.race_checkpoint_record[cp];
                        recordholder = strcat1(race_checkpoint_recordholders[cp]); // make a tempstring copy, as we'll possibly strunzone it!
                        if(recordholder == e.netname)
                                recordholder = "";
@@ -436,10 +449,11 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                                                strunzone(race_checkpoint_recordholders[cp]);
                                        race_checkpoint_recordholders[cp] = strzone(e.netname);
                                        if(g_race_qualifying)
-                                       {
                                                FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.race_checkpoint == cp, LAMBDA(race_SendNextCheckpoint(it, 0)));
-                                       }
                                }
+
+                               if(t < myrecordtime || myrecordtime == 0)
+                                       e.race_checkpoint_record[cp] = t; // resending done below
                        }
                }
                else
@@ -447,6 +461,7 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                        // dummies
                        t = 0;
                        recordtime = 0;
+                       myrecordtime = 0;
                        recordholder = "";
                }
 
@@ -455,7 +470,9 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                        msg_entity = e;
                        if(g_race_qualifying)
                        {
-                               WRITESPECTATABLE_MSG_ONE(msg_entity, {
+                               WRITESPECTATABLE_MSG_ONE(e, {
+                                       if(it == e && e.cvar_cl_race_cptimes_onlyself)
+                                               continue;
                                        WriteHeader(MSG_ONE, TE_CSQC_RACE);
                                        WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_QUALIFYING);
                                        WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
@@ -463,14 +480,23 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                                        WriteInt24_t(MSG_ONE, recordtime); // previously best time
                                        WriteString(MSG_ONE, recordholder); // record holder
                                });
+
+                               if(e.cvar_cl_race_cptimes_onlyself)
+                               {
+                                       msg_entity = e;
+                                       WriteHeader(MSG_ONE, TE_CSQC_RACE);
+                                       WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_SELF_QUALIFYING);
+                                       WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
+                                       WriteInt24_t(MSG_ONE, t); // time to that intermediate
+                                       WriteInt24_t(MSG_ONE, myrecordtime); // previously best time
+                               }
                        }
                }
        }
        else // RACE! Not Qualifying
        {
                float mylaps, lother, othtime;
-               entity oth;
-               oth = race_checkpoint_lastplayers[cp];
+               entity oth = race_checkpoint_lastplayers[cp];
                if(oth)
                {
                        mylaps = PlayerScore_Add(e, SP_RACE_LAPS, 0);
@@ -491,13 +517,13 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                                {
                                        WriteInt24_t(MSG_ONE, 0);
                                        WriteByte(MSG_ONE, 0);
-                                       WriteString(MSG_ONE, "");
+                                       WriteByte(MSG_ONE, 0);
                                }
                                else
                                {
                                        WriteInt24_t(MSG_ONE, TIME_ENCODE(time - race_checkpoint_lasttimes[cp]));
                                        WriteByte(MSG_ONE, mylaps - lother);
-                                       WriteString(MSG_ONE, oth.netname); // record holder
+                                       WriteByte(MSG_ONE, etof(oth)); // record holder
                                }
                        });
                }
@@ -517,13 +543,13 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                                {
                                        WriteInt24_t(MSG_ONE, 0);
                                        WriteByte(MSG_ONE, 0);
-                                       WriteString(MSG_ONE, "");
+                                       WriteByte(MSG_ONE, 0);
                                }
                                else
                                {
                                        WriteInt24_t(MSG_ONE, TIME_ENCODE(time - othtime));
                                        WriteByte(MSG_ONE, lother - mylaps);
-                                       WriteString(MSG_ONE, e.netname); // record holder
+                                       WriteByte(MSG_ONE, etof(e) - 1); // record holder
                                }
                        });
                }
index 472827efa4a81d13a014ae84d998f1b88d62628f..7f6a194f291748213ba4e91e46124d15ce488168 100644 (file)
@@ -66,3 +66,7 @@ void race_SendRankings(float pos, float prevpos, float del, float msg);
 void race_RetractPlayer(entity this);
 
 void race_InitSpectator();
+
+.bool cvar_cl_race_cptimes_onlyself;
+
+REPLICATE(cvar_cl_race_cptimes_onlyself, bool, "cl_race_cptimes_onlyself");