From: terencehill Date: Sat, 13 Feb 2021 12:00:19 +0000 (+0100) Subject: Store record type into a global to avoid some gamemode checks X-Git-Tag: xonotic-v0.8.5~512^2~5 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=80ffd95ff0679bd8fdc1902cdb6646e8905bb29a;p=xonotic%2Fxonotic-data.pk3dir.git Store record type into a global to avoid some gamemode checks --- diff --git a/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc b/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc index 7ec85cdaf..d29f3972a 100644 --- a/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc +++ b/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc @@ -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; diff --git a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc index 9861ab887..22164c57a 100644 --- a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc +++ b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc @@ -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(); } diff --git a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc index e092c91f1..d00a16308 100644 --- a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc +++ b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc @@ -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; diff --git a/qcsrc/server/race.qc b/qcsrc/server/race.qc index 40b2ca148..c5a96b62a 100644 --- a/qcsrc/server/race.qc +++ b/qcsrc/server/race.qc @@ -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)); } } diff --git a/qcsrc/server/race.qh b/qcsrc/server/race.qh index 09aec8823..bb94520ab 100644 --- a/qcsrc/server/race.qh +++ b/qcsrc/server/race.qh @@ -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;