]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/spawnpoints.qc
Merge master into qc_physics_prehax (blame TimePath if it's completely broken)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / spawnpoints.qc
index b84185e52eae3e6ed7b19b59a60352ea2616dc77..b86da6b54ee9f0823dec8d72f2a34d11de7f40b0 100644 (file)
@@ -1,39 +1,48 @@
-
-.float last_spawn_time;
-.float send_spawn;
-float Spawn_Send(entity to, float sf)
+#include "spawnpoints.qh"
+#include "_all.qh"
+
+#include "mutators/mutators_include.qh"
+#include "g_world.qh"
+#include "race.qh"
+#include "../common/constants.qh"
+#include "../common/teams.qh"
+#include "../common/util.qh"
+#include "../warpzonelib/util_server.qh"
+
+float SpawnPoint_Send(entity to, int sf)
 {
        WriteByte(MSG_ENTITY, ENT_CLIENT_SPAWNPOINT);
-       WriteByte(MSG_ENTITY, sf);
-       
-       if(sf & 1)
-       {
-               WriteByte(MSG_ENTITY, self.team);
-               WriteShort(MSG_ENTITY, self.origin_x);
-               WriteShort(MSG_ENTITY, self.origin_y);
-               WriteShort(MSG_ENTITY, self.origin_z);
-       }
-       if(sf & 2)
-       {
-               WriteLong(MSG_ENTITY, self.last_spawn_time);
-       }
-       
-       return TRUE;
+
+       WriteByte(MSG_ENTITY, self.team);
+       WriteShort(MSG_ENTITY, self.origin.x);
+       WriteShort(MSG_ENTITY, self.origin.y);
+       WriteShort(MSG_ENTITY, self.origin.z);
+
+       return true;
 }
 
-void Spawn_Think(void)
+float SpawnEvent_Send(entity to, int sf)
 {
-       if(self.send_spawn < 0)
+       float send;
+
+       WriteByte(MSG_ENTITY, ENT_CLIENT_SPAWNEVENT);
+
+       if(autocvar_g_spawn_alloweffects)
        {
-               self.send_spawn = 0;
-               self.SendFlags |= 1;
+               WriteByte(MSG_ENTITY, num_for_edict(self.owner));
+               WriteShort(MSG_ENTITY, self.owner.origin.x);
+               WriteShort(MSG_ENTITY, self.owner.origin.y);
+               WriteShort(MSG_ENTITY, self.owner.origin.z);
+               send = true;
        }
-       else
+       else if((to == self.owner) || (IS_SPEC(to) && (to.enemy == self.owner)) )
        {
-               self.last_spawn_time = self.send_spawn;
-               self.send_spawn = 0;
-               self.SendFlags |= 2;
+               WriteByte(MSG_ENTITY, 0);
+               send = true;
        }
+       else { send = false; }
+
+       return send;
 }
 
 void spawnpoint_use()
@@ -45,8 +54,6 @@ void spawnpoint_use()
                some_spawn_has_been_used = 1;
        }
        print("spawnpoint was used!\n");
-       self.send_spawn = time;
-       self.nextthink = time;
 }
 
 void relocate_spawnpoint()
@@ -54,19 +61,19 @@ void relocate_spawnpoint()
     // nudge off the floor
     setorigin(self, self.origin + '0 0 1');
 
-    tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
+    tracebox(self.origin, PL_MIN_CONST, PL_MAX_CONST, self.origin, true, self);
     if (trace_startsolid)
     {
         vector o;
         o = self.origin;
-        self.mins = PL_MIN;
-        self.maxs = PL_MAX;
+        self.mins = PL_MIN_CONST;
+        self.maxs = PL_MAX_CONST;
         if (!move_out_of_solid(self))
             objerror("could not get out of solid at all!");
         print("^1NOTE: this map needs FIXING. Spawnpoint at ", vtos(o - '0 0 1'));
-        print(" needs to be moved out of solid, e.g. by '", ftos(self.origin_x - o_x));
-        print(" ", ftos(self.origin_y - o_y));
-        print(" ", ftos(self.origin_z - o_z), "'\n");
+        print(" needs to be moved out of solid, e.g. by '", ftos(self.origin.x - o.x));
+        print(" ", ftos(self.origin.y - o.y));
+        print(" ", ftos(self.origin.z - o.z), "'\n");
         if (autocvar_g_spawnpoints_auto_move_out_of_solid)
         {
             if (!spawnpoint_nag)
@@ -104,11 +111,34 @@ void relocate_spawnpoint()
         e.solid = SOLID_TRIGGER;
     }
 
-       self.send_spawn = -1;
-       self.think = Spawn_Think;
-       self.nextthink = time;
-
-    Net_LinkEntity(self, FALSE, 0, Spawn_Send);
+       // Don't show team spawns in non-team matches,
+       // and don't show non-team spawns in team matches.
+       // (Unless useallspawns is activated)
+       if(
+               !(
+                       ( // if this passes, there is a DM spawn on a team match
+                               teamplay
+                               && (self.team != NUM_TEAM_1)
+                               && (self.team != NUM_TEAM_2)
+                               && (self.team != NUM_TEAM_3)
+                               && (self.team != NUM_TEAM_4)
+                       )
+                       ||
+                       ( // if this passes, there is a team spawn on a DM match
+                               !teamplay
+                               &&
+                               (
+                                       (self.team == NUM_TEAM_1)
+                                       || (self.team == NUM_TEAM_2)
+                                       || (self.team == NUM_TEAM_3)
+                                       || (self.team == NUM_TEAM_4)
+                               )
+                       )
+               )
+               ||
+               autocvar_g_spawn_useallspawns
+       )
+       { Net_LinkEntity(self, false, 0, SpawnPoint_Send); }
 }
 
 void spawnfunc_info_player_survivor (void)
@@ -147,7 +177,7 @@ vector Spawn_Score(entity spot, float mindist, float teamcheck)
                if(spot.target == "")
                        return '-1 0 0';
 
-       if(clienttype(self) == CLIENTTYPE_REAL)
+       if(IS_REAL_CLIENT(self))
        {
                if(spot.restriction == 1)
                        return '-1 0 0';
@@ -186,7 +216,7 @@ vector Spawn_Score(entity spot, float mindist, float teamcheck)
                                self = ent;
                                spawn_score = ent.spawn_evalfunc(oldself, spot, spawn_score);
                                self = oldself;
-                               if(spawn_score_x < 0)
+                               if(spawn_score.x < 0)
                                        return spawn_score;
                        }
                }
@@ -220,7 +250,7 @@ entity Spawn_FilterOutBadSpots(entity firstspot, float mindist, float teamcheck)
 
        for(spot = firstspot; spot; spot = spot.chain)
        {
-               if(spot.spawnpoint_score_x >= 0) // spawning allowed here
+               if(spot.spawnpoint_score.x >= 0) // spawning allowed here
                {
                        if(spotlistend)
                                spotlistend.chain = spot;
@@ -243,7 +273,7 @@ entity Spawn_WeightedPoint(entity firstspot, float lower, float upper, float exp
 
        RandomSelection_Init();
        for(spot = firstspot; spot; spot = spot.chain)
-               RandomSelection_Add(spot, 0, string_null, pow(bound(lower, spot.spawnpoint_score_y, upper), exponent) * spot.cnt, (spot.spawnpoint_score_y >= lower) * 0.5 + spot.spawnpoint_score_x);
+               RandomSelection_Add(spot, 0, string_null, pow(bound(lower, spot.spawnpoint_score.y, upper), exponent) * spot.cnt, (spot.spawnpoint_score.y >= lower) * 0.5 + spot.spawnpoint_score.x);
 
        return RandomSelection_chosen_ent;
 }
@@ -299,12 +329,7 @@ entity SelectSpawnPoint (float anypoint)
        }
        else
        {
-               float mindist;
-               if(g_arena && arena_roundbased)
-                       mindist = 800;
-               else
-                       mindist = 100;
-               firstspot = Spawn_FilterOutBadSpots(firstspot, mindist, teamcheck);
+               firstspot = Spawn_FilterOutBadSpots(firstspot, 100, teamcheck);
 
                // there is 50/50 chance of choosing a random spot or the furthest spot
                // (this means that roughly every other spawn will be furthest, so you