]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move some identical ctf / race / cts code to shared functions
authorterencehill <piuntn@gmail.com>
Thu, 11 Mar 2021 17:08:57 +0000 (18:08 +0100)
committerterencehill <piuntn@gmail.com>
Thu, 11 Mar 2021 17:08:57 +0000 (18:08 +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 d29f3972ad863d821f60a48f7929a0d6d178911d..8ec8613cc2951428ea5bfbea15f4ba2e2e62c011 100644 (file)
@@ -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)
index 22164c57a1d3621364039877f035f9166e008cdb..458465faaa260587a60563407fa72630d228c21e 100644 (file)
@@ -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)
index d00a163084a34b2461a989b362ae1f4740d2aac6..74929ebd1c48f353d05864e8a4fedf0ecc13a0ea 100644 (file)
@@ -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)
index c5a96b62a266509c42c327f6f862b7bed6c2b8ee..c09cd69ea83cb1db4316cb19936d9dd9a10fef8a 100644 (file)
@@ -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))
index bb94520abdb39f9274d2a2c63d4bc1c64a3dcc6c..2665e75a00c587af16cc0fd7a08e04000a53914d 100644 (file)
@@ -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);