From: terencehill Date: Thu, 11 Mar 2021 17:08:57 +0000 (+0100) Subject: Move some identical ctf / race / cts code to shared functions X-Git-Tag: xonotic-v0.8.5~512^2~3 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fa07bf42b5cb0aec76ec9834bf5f5e8863ab597e;p=xonotic%2Fxonotic-data.pk3dir.git Move some identical ctf / race / cts code to shared functions --- diff --git a/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc b/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc index d29f3972a..8ec8613cc 100644 --- a/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc +++ b/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc @@ -2300,15 +2300,7 @@ MUTATOR_HOOKFUNCTION(ctf, ClientConnect) entity player = M_ARGV(0, entity); - if(IS_REAL_CLIENT(player)) - { - int m = min(RANKINGS_CNT, autocvar_g_cts_send_rankings_cnt); - race_send_rankings_cnt(MSG_ONE); - for (int i = 1; i <= m; ++i) - { - race_SendRankings(i, 0, 0, MSG_ONE); - } - } + race_SendAll(player, true); } MUTATOR_HOOKFUNCTION(ctf, GetPressedKeys) diff --git a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc index 22164c57a..458465faa 100644 --- a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc +++ b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc @@ -179,24 +179,7 @@ MUTATOR_HOOKFUNCTION(cts, ClientConnect) race_PreparePlayer(player); player.race_checkpoint = -1; - 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(), 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; - int m = min(RANKINGS_CNT, autocvar_g_cts_send_rankings_cnt); - race_send_rankings_cnt(MSG_ONE); - for (i = 1; i <= m; ++i) - { - race_SendRankings(i, 0, 0, MSG_ONE); - } - } + race_SendAll(player, false); } MUTATOR_HOOKFUNCTION(cts, AbortSpeedrun) @@ -281,31 +264,7 @@ MUTATOR_HOOKFUNCTION(cts, GetPressedKeys) entity player = M_ARGV(0, entity); race_checkAndWriteName(player); - - if (!IS_OBSERVER(player)) - { - if(vdist(player.velocity - player.velocity_z * '0 0 1', >, speedaward_speed)) - { - speedaward_speed = vlen(player.velocity - player.velocity_z * '0 0 1'); - speedaward_holder = player.netname; - speedaward_uid = player.crypto_idfp; - speedaward_lastupdate = time; - } - if (speedaward_speed > speedaward_lastsent && (time - speedaward_lastupdate > 1 || intermission_running)) - { - race_send_speedaward(MSG_ALL); - speedaward_lastsent = speedaward_speed; - if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") - { - speedaward_alltimebest = speedaward_speed; - speedaward_alltimebest_holder = speedaward_holder; - speedaward_alltimebest_uid = speedaward_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); - } - } - } + race_SpeedAwardFrame(player); } MUTATOR_HOOKFUNCTION(cts, ForbidThrowCurrentWeapon) diff --git a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc index d00a16308..74929ebd1 100644 --- a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc +++ b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc @@ -238,24 +238,7 @@ MUTATOR_HOOKFUNCTION(rc, ClientConnect) race_PreparePlayer(player); player.race_checkpoint = -1; - 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(), 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; - int m = min(RANKINGS_CNT, autocvar_g_cts_send_rankings_cnt); - race_send_rankings_cnt(MSG_ONE); - for (i = 1; i <= m; ++i) - { - race_SendRankings(i, 0, 0, MSG_ONE); - } - } + race_SendAll(player, false); } MUTATOR_HOOKFUNCTION(rc, MakePlayerObserver) @@ -327,31 +310,7 @@ MUTATOR_HOOKFUNCTION(rc, GetPressedKeys) entity player = M_ARGV(0, entity); race_checkAndWriteName(player); - - if (!IS_OBSERVER(player)) - { - if(vdist(player.velocity - player.velocity_z * '0 0 1', >, speedaward_speed)) - { - speedaward_speed = vlen(player.velocity - player.velocity_z * '0 0 1'); - speedaward_holder = player.netname; - speedaward_uid = player.crypto_idfp; - speedaward_lastupdate = time; - } - if (speedaward_speed > speedaward_lastsent && (time - speedaward_lastupdate > 1 || intermission_running)) - { - race_send_speedaward(MSG_ALL); - speedaward_lastsent = speedaward_speed; - if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") - { - speedaward_alltimebest = speedaward_speed; - speedaward_alltimebest_holder = speedaward_holder; - speedaward_alltimebest_uid = speedaward_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); - } - } - } + race_SpeedAwardFrame(player); } MUTATOR_HOOKFUNCTION(rc, ForbidPlayerScore_Clear) diff --git a/qcsrc/server/race.qc b/qcsrc/server/race.qc index c5a96b62a..c09cd69ea 100644 --- a/qcsrc/server/race.qc +++ b/qcsrc/server/race.qc @@ -260,7 +260,6 @@ void race_send_recordtime(float msg) WriteInt24_t(msg, race_readTime(GetMapname(), 1)); } - void race_send_speedaward(float msg) { // send the best speed of the round @@ -298,6 +297,56 @@ void race_SendRankings(float pos, float prevpos, float del, float msg) WriteInt24_t(msg, race_readTime(GetMapname(), pos)); } +void race_SpeedAwardFrame(entity player) +{ + if (IS_OBSERVER(player)) + return; + + if(vdist(player.velocity - player.velocity_z * '0 0 1', >, speedaward_speed)) + { + speedaward_speed = vlen(player.velocity - player.velocity_z * '0 0 1'); + speedaward_holder = player.netname; + speedaward_uid = player.crypto_idfp; + speedaward_lastupdate = time; + } + if (speedaward_speed > speedaward_lastsent && (time - speedaward_lastupdate > 1 || intermission_running)) + { + race_send_speedaward(MSG_ALL); + speedaward_lastsent = speedaward_speed; + if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "") + { + speedaward_alltimebest = speedaward_speed; + speedaward_alltimebest_holder = speedaward_holder; + speedaward_alltimebest_uid = speedaward_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); + } + } +} + +void race_SendAll(entity player, bool only_rankings) +{ + if(!IS_REAL_CLIENT(player)) + return; + + msg_entity = player; + if (!only_rankings) + { + race_send_recordtime(MSG_ONE); + race_send_speedaward(MSG_ONE); + + 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); + } + + int m = min(RANKINGS_CNT, autocvar_g_cts_send_rankings_cnt); + race_send_rankings_cnt(MSG_ONE); + for (int i = 1; i <= m; ++i) + race_SendRankings(i, 0, 0, MSG_ONE); +} + void race_SendStatus(float id, entity e) { if(!IS_REAL_CLIENT(e)) diff --git a/qcsrc/server/race.qh b/qcsrc/server/race.qh index bb94520ab..2665e75a0 100644 --- a/qcsrc/server/race.qh +++ b/qcsrc/server/race.qh @@ -65,12 +65,12 @@ string speedaward_alltimebest_holder; string speedaward_alltimebest_uid; void race_send_speedaward(float msg); - void race_send_speedaward_alltimebest(float msg); +void race_SpeedAwardFrame(entity player); void race_send_rankings_cnt(float msg); - void race_SendRankings(float pos, float prevpos, float del, float msg); +void race_SendAll(entity player, bool only_rankings); void race_RetractPlayer(entity this);