]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Store record type into a global to avoid some gamemode checks
authorterencehill <piuntn@gmail.com>
Sat, 13 Feb 2021 12:00:19 +0000 (13:00 +0100)
committerterencehill <piuntn@gmail.com>
Sat, 13 Feb 2021 12:00:19 +0000 (13:00 +0100)
qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc
qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc
qcsrc/common/gamemodes/gamemode/race/sv_race.qc
qcsrc/server/race.qc
qcsrc/server/race.qh

index 7ec85cdaf1958a67aea7b2d14b3267e16cc1bf9f..d29f3972ad863d821f60a48f7929a0d6d178911d 100644 (file)
@@ -2834,6 +2834,7 @@ void ctf_DelayedInit(entity this) // Do this check with a delay so we can wait f
 
 void ctf_Initialize()
 {
+       record_type = CTF_RECORD;
        ctf_captimerecord = stof(db_get(ServerProgsDB, strcat(GetMapname(), "/captimerecord/time")));
 
        ctf_captureshield_min_negscore = autocvar_g_ctf_shield_min_negscore;
index 9861ab887cc8ff49a92f74fa2e5372e85d821b12..22164c57a1d3621364039877f035f9166e008cdb 100644 (file)
@@ -181,14 +181,12 @@ MUTATOR_HOOKFUNCTION(cts, ClientConnect)
 
        if(IS_REAL_CLIENT(player))
        {
-               string rr = CTS_RECORD;
-
                msg_entity = player;
                race_send_recordtime(MSG_ONE);
                race_send_speedaward(MSG_ONE);
 
-               speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
-               speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
+               speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), record_type, "speed/speed")));
+               speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), record_type, "speed/crypto_idfp")));
                race_send_speedaward_alltimebest(MSG_ONE);
 
                float i;
@@ -295,7 +293,6 @@ MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
                }
                if (speedaward_speed > speedaward_lastsent && (time - speedaward_lastupdate > 1 || intermission_running))
                {
-                       string rr = CTS_RECORD;
                        race_send_speedaward(MSG_ALL);
                        speedaward_lastsent = speedaward_speed;
                        if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
@@ -303,8 +300,8 @@ MUTATOR_HOOKFUNCTION(cts, GetPressedKeys)
                                speedaward_alltimebest = speedaward_speed;
                                speedaward_alltimebest_holder = speedaward_holder;
                                speedaward_alltimebest_uid = speedaward_uid;
-                               db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
-                               db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
+                               db_put(ServerProgsDB, strcat(GetMapname(), record_type, "speed/speed"), ftos(speedaward_alltimebest));
+                               db_put(ServerProgsDB, strcat(GetMapname(), record_type, "speed/crypto_idfp"), speedaward_alltimebest_uid);
                                race_send_speedaward_alltimebest(MSG_ALL);
                        }
                }
@@ -409,5 +406,6 @@ MUTATOR_HOOKFUNCTION(cts, ForbidDropCurrentWeapon)
 
 void cts_Initialize()
 {
+       record_type = CTS_RECORD;
        cts_ScoreRules();
 }
index e092c91f126ab58d2f3d585411db7fadda29b248..d00a163084a34b2461a989b362ae1f4740d2aac6 100644 (file)
@@ -238,16 +238,14 @@ MUTATOR_HOOKFUNCTION(rc, ClientConnect)
        race_PreparePlayer(player);
        player.race_checkpoint = -1;
 
-       string rr = RACE_RECORD;
-
        if(IS_REAL_CLIENT(player))
        {
                msg_entity = player;
                race_send_recordtime(MSG_ONE);
                race_send_speedaward(MSG_ONE);
 
-               speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed")));
-               speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp")));
+               speedaward_alltimebest = stof(db_get(ServerProgsDB, strcat(GetMapname(), record_type, "speed/speed")));
+               speedaward_alltimebest_holder = uid2name(db_get(ServerProgsDB, strcat(GetMapname(), record_type, "speed/crypto_idfp")));
                race_send_speedaward_alltimebest(MSG_ONE);
 
                float i;
@@ -341,7 +339,6 @@ MUTATOR_HOOKFUNCTION(rc, GetPressedKeys)
                }
                if (speedaward_speed > speedaward_lastsent && (time - speedaward_lastupdate > 1 || intermission_running))
                {
-                       string rr = RACE_RECORD;
                        race_send_speedaward(MSG_ALL);
                        speedaward_lastsent = speedaward_speed;
                        if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
@@ -349,8 +346,8 @@ MUTATOR_HOOKFUNCTION(rc, GetPressedKeys)
                                speedaward_alltimebest = speedaward_speed;
                                speedaward_alltimebest_holder = speedaward_holder;
                                speedaward_alltimebest_uid = speedaward_uid;
-                               db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
-                               db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
+                               db_put(ServerProgsDB, strcat(GetMapname(), record_type, "speed/speed"), ftos(speedaward_alltimebest));
+                               db_put(ServerProgsDB, strcat(GetMapname(), record_type, "speed/crypto_idfp"), speedaward_alltimebest_uid);
                                race_send_speedaward_alltimebest(MSG_ALL);
                        }
                }
@@ -464,6 +461,8 @@ void rc_SetLimits()
 
        float want_qualifying = ((qualifying_override >= 0) ? qualifying_override : autocvar_g_race_qualifying_timelimit) > 0;
 
+       record_type = RACE_RECORD;
+
        if(autocvar_g_campaign)
        {
                g_race_qualifying = 1;
index 40b2ca148483f50707a5c9c155a62005404881be..c5a96b62a266509c42c327f6f862b7bed6c2b8ee 100644 (file)
@@ -81,16 +81,12 @@ void race_InitSpectator()
 
 float race_readTime(string map, float pos)
 {
-       string rr = ((g_cts) ? CTS_RECORD : ((g_ctf) ? CTF_RECORD : RACE_RECORD));
-
-       return stof(db_get(ServerProgsDB, strcat(map, rr, "time", ftos(pos))));
+       return stof(db_get(ServerProgsDB, strcat(map, record_type, "time", ftos(pos))));
 }
 
 string race_readUID(string map, float pos)
 {
-       string rr = ((g_cts) ? CTS_RECORD : ((g_ctf) ? CTF_RECORD : RACE_RECORD));
-
-       return db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos)));
+       return db_get(ServerProgsDB, strcat(map, record_type, "crypto_idfp", ftos(pos)));
 }
 
 float race_readPos(string map, float t)
@@ -107,8 +103,6 @@ float race_readPos(string map, float t)
 
 void race_writeTime(string map, float t, string myuid)
 {
-       string rr = ((g_cts) ? CTS_RECORD : ((g_ctf) ? CTF_RECORD : RACE_RECORD));
-
        float newpos;
        newpos = race_readPos(map, t);
 
@@ -123,8 +117,8 @@ void race_writeTime(string map, float t, string myuid)
                // player improved his existing record, only have to iterate on ranks between new and old recs
                for (i = prevpos; i > newpos; --i)
                {
-                       db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(race_readTime(map, i - 1)));
-                       db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(map, i - 1));
+                       db_put(ServerProgsDB, strcat(map, record_type, "time", ftos(i)), ftos(race_readTime(map, i - 1)));
+                       db_put(ServerProgsDB, strcat(map, record_type, "crypto_idfp", ftos(i)), race_readUID(map, i - 1));
                }
        }
        else
@@ -134,22 +128,20 @@ void race_writeTime(string map, float t, string myuid)
                {
                        float other_time = race_readTime(map, i - 1);
                        if (other_time) {
-                               db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(other_time));
-                               db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(map, i - 1));
+                               db_put(ServerProgsDB, strcat(map, record_type, "time", ftos(i)), ftos(other_time));
+                               db_put(ServerProgsDB, strcat(map, record_type, "crypto_idfp", ftos(i)), race_readUID(map, i - 1));
                        }
                }
        }
 
        // store new time itself
-       db_put(ServerProgsDB, strcat(map, rr, "time", ftos(newpos)), ftos(t));
-       db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(newpos)), myuid);
+       db_put(ServerProgsDB, strcat(map, record_type, "time", ftos(newpos)), ftos(t));
+       db_put(ServerProgsDB, strcat(map, record_type, "crypto_idfp", ftos(newpos)), myuid);
 }
 
 string race_readName(string map, float pos)
 {
-       string rr = ((g_cts) ? CTS_RECORD : ((g_ctf) ? CTF_RECORD : RACE_RECORD));
-
-       return uid2name(db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos))));
+       return uid2name(db_get(ServerProgsDB, strcat(map, record_type, "crypto_idfp", ftos(pos))));
 }
 
 void race_checkAndWriteName(entity player)
@@ -414,20 +406,18 @@ void race_setTime(string map, float t, string myuid, string mynetname, entity e,
 
 void race_deleteTime(string map, float pos)
 {
-       string rr = ((g_cts) ? CTS_RECORD : ((g_ctf) ? CTF_RECORD : RACE_RECORD));
-
        for(int i = pos; i <= RANKINGS_CNT; ++i)
        {
                string therank = ftos(i);
                if (i == RANKINGS_CNT)
                {
-                       db_remove(ServerProgsDB, strcat(map, rr, "time", therank));
-                       db_remove(ServerProgsDB, strcat(map, rr, "crypto_idfp", therank));
+                       db_remove(ServerProgsDB, strcat(map, record_type, "time", therank));
+                       db_remove(ServerProgsDB, strcat(map, record_type, "crypto_idfp", therank));
                }
                else
                {
-                       db_put(ServerProgsDB, strcat(map, rr, "time", therank), ftos(race_readTime(GetMapname(), i+1)));
-                       db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", therank), race_readUID(GetMapname(), i+1));
+                       db_put(ServerProgsDB, strcat(map, record_type, "time", therank), ftos(race_readTime(GetMapname(), i+1)));
+                       db_put(ServerProgsDB, strcat(map, record_type, "crypto_idfp", therank), race_readUID(GetMapname(), i+1));
                }
        }
 
index 09aec88236194121289efb34973a7ad6b4a6fd0a..bb94520abdb39f9274d2a2c63d4bc1c64a3dcc6c 100644 (file)
@@ -4,6 +4,9 @@ bool autocvar_g_allow_checkpoints;
 
 float race_teams;
 
+// default to RACE_RECORD, can be overwritten by gamemodes
+string record_type = RACE_RECORD;
+
 // scores
 const float ST_RACE_LAPS = 1;