]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/race.qc
Merge branch 'master' into Mario/vaporizer_damage
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / race.qc
index 0dbe7d11832a3dc00f10d4918c56533410cc552f..bb7f0eccc2297ad547b06181fa225d3957ad318d 100644 (file)
@@ -1,3 +1,7 @@
+#include "race.qh"
+
+void W_Porto_Fail(float failhard);
+
 float race_readTime(string map, float pos)
 {
        string rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
@@ -67,7 +71,7 @@ string race_readName(string map, float pos)
 }
 
 
-#define MAX_CHECKPOINTS 255
+const float MAX_CHECKPOINTS = 255;
 
 void spawnfunc_target_checkpoint();
 
@@ -141,6 +145,9 @@ void race_SendNextCheckpoint(entity e, float spec) // qualifying only
        if(recordholder == e.netname)
                recordholder = "";
 
+       if(!IS_REAL_CLIENT(e))
+               return;
+
        if(!spec)
                msg_entity = e;
        WRITESPECTATABLE_MSG_ONE({
@@ -183,6 +190,9 @@ void race_SendRankings(float pos, float prevpos, float del, float msg)
 
 void race_SendStatus(float id, entity e)
 {
+       if(!IS_REAL_CLIENT(e))
+               return;
+
        float msg;
        if (id == 0)
                msg = MSG_ONE;
@@ -399,18 +409,21 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                        recordholder = "";
                }
 
-               msg_entity = e;
-               if(g_race_qualifying)
+               if(IS_REAL_CLIENT(e))
                {
-                       WRITESPECTATABLE_MSG_ONE_VARNAME(dummy1, {
-                               WriteByte(MSG_ONE, SVC_TEMPENTITY);
-                               WriteByte(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
-                               WriteInt24_t(MSG_ONE, t); // time to that intermediate
-                               WriteInt24_t(MSG_ONE, recordtime); // previously best time
-                               WriteString(MSG_ONE, recordholder); // record holder
-                       });
+                       msg_entity = e;
+                       if(g_race_qualifying)
+                       {
+                               WRITESPECTATABLE_MSG_ONE_VARNAME(dummy1, {
+                                       WriteByte(MSG_ONE, SVC_TEMPENTITY);
+                                       WriteByte(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
+                                       WriteInt24_t(MSG_ONE, t); // time to that intermediate
+                                       WriteInt24_t(MSG_ONE, recordtime); // previously best time
+                                       WriteString(MSG_ONE, recordholder); // record holder
+                               });
+                       }
                }
        }
        else // RACE! Not Qualifying
@@ -427,49 +440,55 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                else
                        lself = lother = othtime = 0;
 
-               msg_entity = e;
-               WRITESPECTATABLE_MSG_ONE_VARNAME(dummy2, {
-                       WriteByte(MSG_ONE, SVC_TEMPENTITY);
-                       WriteByte(MSG_ONE, TE_CSQC_RACE);
-                       WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_RACE);
-                       WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
-                       if(e == oth)
-                       {
-                               WriteInt24_t(MSG_ONE, 0);
-                               WriteByte(MSG_ONE, 0);
-                               WriteString(MSG_ONE, "");
-                       }
-                       else
-                       {
-                               WriteInt24_t(MSG_ONE, TIME_ENCODE(time - race_checkpoint_lasttimes[cp]));
-                               WriteByte(MSG_ONE, lself - lother);
-                               WriteString(MSG_ONE, oth.netname); // record holder
-                       }
-               });
+               if(IS_REAL_CLIENT(e))
+               {
+                       msg_entity = e;
+                       WRITESPECTATABLE_MSG_ONE_VARNAME(dummy2, {
+                               WriteByte(MSG_ONE, SVC_TEMPENTITY);
+                               WriteByte(MSG_ONE, TE_CSQC_RACE);
+                               WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_RACE);
+                               WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
+                               if(e == oth)
+                               {
+                                       WriteInt24_t(MSG_ONE, 0);
+                                       WriteByte(MSG_ONE, 0);
+                                       WriteString(MSG_ONE, "");
+                               }
+                               else
+                               {
+                                       WriteInt24_t(MSG_ONE, TIME_ENCODE(time - race_checkpoint_lasttimes[cp]));
+                                       WriteByte(MSG_ONE, lself - lother);
+                                       WriteString(MSG_ONE, oth.netname); // record holder
+                               }
+                       });
+               }
 
                race_checkpoint_lastplayers[cp] = e;
                race_checkpoint_lasttimes[cp] = time;
                race_checkpoint_lastlaps[cp] = lself;
 
-               msg_entity = oth;
-               WRITESPECTATABLE_MSG_ONE_VARNAME(dummy3, {
-                       WriteByte(MSG_ONE, SVC_TEMPENTITY);
-                       WriteByte(MSG_ONE, TE_CSQC_RACE);
-                       WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT);
-                       WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
-                       if(e == oth)
-                       {
-                               WriteInt24_t(MSG_ONE, 0);
-                               WriteByte(MSG_ONE, 0);
-                               WriteString(MSG_ONE, "");
-                       }
-                       else
-                       {
-                               WriteInt24_t(MSG_ONE, TIME_ENCODE(time - othtime));
-                               WriteByte(MSG_ONE, lother - lself);
-                               WriteString(MSG_ONE, e.netname); // record holder
-                       }
-               });
+               if(IS_REAL_CLIENT(oth))
+               {
+                       msg_entity = oth;
+                       WRITESPECTATABLE_MSG_ONE_VARNAME(dummy3, {
+                               WriteByte(MSG_ONE, SVC_TEMPENTITY);
+                               WriteByte(MSG_ONE, TE_CSQC_RACE);
+                               WriteByte(MSG_ONE, RACE_NET_CHECKPOINT_HIT_RACE_BY_OPPONENT);
+                               WriteByte(MSG_ONE, race_CheckpointNetworkID(cp)); // checkpoint the player now is at
+                               if(e == oth)
+                               {
+                                       WriteInt24_t(MSG_ONE, 0);
+                                       WriteByte(MSG_ONE, 0);
+                                       WriteString(MSG_ONE, "");
+                               }
+                               else
+                               {
+                                       WriteInt24_t(MSG_ONE, TIME_ENCODE(time - othtime));
+                                       WriteByte(MSG_ONE, lother - lself);
+                                       WriteString(MSG_ONE, e.netname); // record holder
+                               }
+                       });
+               }
        }
 }
 
@@ -481,6 +500,9 @@ void race_ClearTime(entity e)
        e.race_penalty_accumulator = 0;
        e.race_lastpenalty = world;
 
+       if(!IS_REAL_CLIENT(e))
+               return;
+
        msg_entity = e;
        WRITESPECTATABLE_MSG_ONE({
                WriteByte(MSG_ONE, SVC_TEMPENTITY);
@@ -671,11 +693,11 @@ void checkpoint_use()
 float race_waypointsprite_visible_for_player(entity e)
 {
        if(e.race_checkpoint == -1 || self.owner.race_checkpoint == -2)
-               return TRUE;
+               return true;
        else if(e.race_checkpoint == self.owner.race_checkpoint)
-               return TRUE;
+               return true;
        else
-               return FALSE;
+               return false;
 }
 
 float have_verified;
@@ -704,7 +726,7 @@ void trigger_race_checkpoint_verify()
                        // race only (middle of the race)
                        g_race_qualifying = 0;
                        self.race_place = 0;
-                       if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), 0, FALSE))
+                       if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), 0, false))
                                error(strcat("Checkpoint ", ftos(i), " misses a spawnpoint with race_place==", ftos(self.race_place), " (used for respawning in race) - bailing out"));
 
                        if(i == 0)
@@ -712,7 +734,7 @@ void trigger_race_checkpoint_verify()
                                // qualifying only
                                g_race_qualifying = 1;
                                self.race_place = race_lowest_place_spawn;
-                               if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), 0, FALSE))
+                               if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), 0, false))
                                        error(strcat("Checkpoint ", ftos(i), " misses a spawnpoint with race_place==", ftos(self.race_place), " (used for qualifying) - bailing out"));
 
                                // race only (initial spawn)
@@ -720,7 +742,7 @@ void trigger_race_checkpoint_verify()
                                for(p = 1; p <= race_highest_place_spawn; ++p)
                                {
                                        self.race_place = p;
-                                       if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), 0, FALSE))
+                                       if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), 0, false))
                                                error(strcat("Checkpoint ", ftos(i), " misses a spawnpoint with race_place==", ftos(self.race_place), " (used for initially spawning in race) - bailing out"));
                                }
                        }
@@ -732,7 +754,7 @@ void trigger_race_checkpoint_verify()
                self.race_checkpoint = race_NextCheckpoint(0);
                g_race_qualifying = 1;
                self.race_place = race_lowest_place_spawn;
-               if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), 0, FALSE))
+               if(!Spawn_FilterOutBadSpots(findchain(classname, "info_player_deathmatch"), 0, false))
                        error(strcat("Checkpoint 0 misses a spawnpoint with race_place==", ftos(self.race_place), " (used for qualifying) - bailing out"));
        }
        else
@@ -859,7 +881,7 @@ vector trigger_race_checkpoint_spawn_evalfunc(entity player, entity spot, vector
                        return '-1 0 0';
                // try reusing the previous spawn
                if(self == player.race_respawn_spotref || spot == player.race_respawn_spotref)
-                       current_x += SPAWN_PRIO_RACE_PREVIOUS_SPAWN;
+                       current.x += SPAWN_PRIO_RACE_PREVIOUS_SPAWN;
                if(self.race_checkpoint == 0)
                {
                        float pl;
@@ -887,7 +909,7 @@ void spawnfunc_trigger_race_checkpoint()
                self.touch = checkpoint_touch;
 
        o = (self.absmin + self.absmax) * 0.5;
-       tracebox(o, PL_MIN, PL_MAX, o - '0 0 1' * (o_z - self.absmin_z), MOVE_NORMAL, self);
+       tracebox(o, PL_MIN, PL_MAX, o - '0 0 1' * (o.z - self.absmin.z), MOVE_NORMAL, self);
        waypoint_spawnforitem_force(self, trace_endpos);
        self.nearestwaypointtimeout = time + 1000000000;
 
@@ -936,7 +958,7 @@ void spawnfunc_target_checkpoint() // defrag entity
                self.touch = checkpoint_touch;
 
        o = (self.absmin + self.absmax) * 0.5;
-       tracebox(o, PL_MIN, PL_MAX, o - '0 0 1' * (o_z - self.absmin_z), MOVE_NORMAL, self);
+       tracebox(o, PL_MIN, PL_MAX, o - '0 0 1' * (o.z - self.absmin.z), MOVE_NORMAL, self);
        waypoint_spawnforitem_force(self, trace_endpos);
        self.nearestwaypointtimeout = time + 1000000000;
 
@@ -1046,26 +1068,32 @@ void race_ImposePenaltyTime(entity pl, float penalty, string reason)
        if(g_race_qualifying)
        {
                pl.race_penalty_accumulator += penalty;
-               msg_entity = pl;
-               WRITESPECTATABLE_MSG_ONE({
-                       WriteByte(MSG_ONE, SVC_TEMPENTITY);
-                       WriteByte(MSG_ONE, TE_CSQC_RACE);
-                       WriteByte(MSG_ONE, RACE_NET_PENALTY_QUALIFYING);
-                       WriteShort(MSG_ONE, TIME_ENCODE(penalty));
-                       WriteString(MSG_ONE, reason);
-               });
+               if(IS_REAL_CLIENT(pl))
+               {
+                       msg_entity = pl;
+                       WRITESPECTATABLE_MSG_ONE({
+                               WriteByte(MSG_ONE, SVC_TEMPENTITY);
+                               WriteByte(MSG_ONE, TE_CSQC_RACE);
+                               WriteByte(MSG_ONE, RACE_NET_PENALTY_QUALIFYING);
+                               WriteShort(MSG_ONE, TIME_ENCODE(penalty));
+                               WriteString(MSG_ONE, reason);
+                       });
+               }
        }
        else
        {
                pl.race_penalty = time + penalty;
-               msg_entity = pl;
-               WRITESPECTATABLE_MSG_ONE_VARNAME(dummy, {
-                       WriteByte(MSG_ONE, SVC_TEMPENTITY);
-                       WriteByte(MSG_ONE, TE_CSQC_RACE);
-                       WriteByte(MSG_ONE, RACE_NET_PENALTY_RACE);
-                       WriteShort(MSG_ONE, TIME_ENCODE(penalty));
-                       WriteString(MSG_ONE, reason);
-               });
+               if(IS_REAL_CLIENT(pl))
+               {
+                       msg_entity = pl;
+                       WRITESPECTATABLE_MSG_ONE_VARNAME(dummy, {
+                               WriteByte(MSG_ONE, SVC_TEMPENTITY);
+                               WriteByte(MSG_ONE, TE_CSQC_RACE);
+                               WriteByte(MSG_ONE, RACE_NET_PENALTY_RACE);
+                               WriteShort(MSG_ONE, TIME_ENCODE(penalty));
+                               WriteString(MSG_ONE, reason);
+                       });
+               }
        }
 }
 
@@ -1154,7 +1182,7 @@ float race_GetFractionalLapCount(entity e)
        // race_timed_checkpoint == 0: then nextcp==0 means 0.9999x
        float c, nc;
        nc = race_highest_checkpoint + 1;
-       c = (mod(nextcpindex - race_timed_checkpoint + nc + nc - 1, nc) + 1) - bestfraction;
+       c = ((nextcpindex - race_timed_checkpoint + nc + nc - 1) % nc) + 1 - bestfraction;
 
        return l + c / nc;
 }