]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/warpzonelib/server.qc
Merge branch 'master' into tzork/ents-onoff
[xonotic/xonotic-data.pk3dir.git] / qcsrc / warpzonelib / server.qc
index d52b9749fd6a6d6b9c059881309145cadf68280a..cfa6ef965ec768949733736a165038d08555fd28 100644 (file)
@@ -111,14 +111,23 @@ void WarpZone_Touch (void)
        e = self.enemy;
        if(WarpZone_Teleport(other))
        {
-               if(self.aiment.target)
-               {
-                       oldself = self;
-                       activator = other;
-                       self = self.aiment;
-                       SUB_UseTargets();
-                       self = oldself;
-               }
+               string save1, save2;
+               activator = other;
+
+               save1 = self.target; self.target = string_null;
+               save2 = self.target3; self.target3 = string_null;
+               SUB_UseTargets();
+               if not(self.target) self.target = save1;
+               if not(self.target3) self.target3 = save2;
+
+               oldself = self;
+               self = self.enemy;
+               save1 = self.target; self.target = string_null;
+               save2 = self.target2; self.target2 = string_null;
+               SUB_UseTargets();
+               if not(self.target) self.target = save1;
+               if not(self.target2) self.target2 = save2;
+               self = oldself;
        }
        else
        {
@@ -128,12 +137,26 @@ void WarpZone_Touch (void)
 
 float WarpZone_Send(entity to, float sendflags)
 {
+       float f;
        WriteByte(MSG_ENTITY, ENT_CLIENT_WARPZONE);
 
+       // we must send this flag for clientside to match properly too
+       f = 0;
+       if(self.warpzone_isboxy)
+               f |= 1;
+       if(self.warpzone_fadestart)
+               f |= 2;
+       if(self.origin != '0 0 0')
+               f |= 4;
+       WriteByte(MSG_ENTITY, f);
+
        // we need THESE to render the warpzone (and cull properly)...
-       WriteCoord(MSG_ENTITY, self.origin_x);
-       WriteCoord(MSG_ENTITY, self.origin_y);
-       WriteCoord(MSG_ENTITY, self.origin_z);
+       if(f & 4)
+       {
+               WriteCoord(MSG_ENTITY, self.origin_x);
+               WriteCoord(MSG_ENTITY, self.origin_y);
+               WriteCoord(MSG_ENTITY, self.origin_z);
+       }
 
        WriteShort(MSG_ENTITY, self.modelindex);
        WriteCoord(MSG_ENTITY, self.mins_x);
@@ -158,17 +181,33 @@ float WarpZone_Send(entity to, float sendflags)
        WriteCoord(MSG_ENTITY, self.warpzone_targetangles_y);
        WriteCoord(MSG_ENTITY, self.warpzone_targetangles_z);
 
+       if(f & 2)
+       {
+               WriteShort(MSG_ENTITY, self.warpzone_fadestart);
+               WriteShort(MSG_ENTITY, self.warpzone_fadeend);
+       }
+
        return TRUE;
 }
 
 float WarpZone_Camera_Send(entity to, float sendflags)
 {
+       float f;
        WriteByte(MSG_ENTITY, ENT_CLIENT_WARPZONE_CAMERA);
 
+       if(self.warpzone_fadestart)
+               f |= 2;
+       if(self.origin != '0 0 0')
+               f |= 4;
+       WriteByte(MSG_ENTITY, f);
+
        // we need THESE to render the warpzone (and cull properly)...
-       WriteCoord(MSG_ENTITY, self.origin_x);
-       WriteCoord(MSG_ENTITY, self.origin_y);
-       WriteCoord(MSG_ENTITY, self.origin_z);
+       if(f & 4)
+       {
+               WriteCoord(MSG_ENTITY, self.origin_x);
+               WriteCoord(MSG_ENTITY, self.origin_y);
+               WriteCoord(MSG_ENTITY, self.origin_z);
+       }
 
        WriteShort(MSG_ENTITY, self.modelindex);
        WriteCoord(MSG_ENTITY, self.mins_x);
@@ -187,6 +226,12 @@ float WarpZone_Camera_Send(entity to, float sendflags)
        WriteCoord(MSG_ENTITY, self.enemy.angles_y);
        WriteCoord(MSG_ENTITY, self.enemy.angles_z);
 
+       if(f & 2)
+       {
+               WriteShort(MSG_ENTITY, self.warpzone_fadestart);
+               WriteShort(MSG_ENTITY, self.warpzone_fadeend);
+       }
+
        return TRUE;
 }
 
@@ -210,7 +255,7 @@ float WarpZone_CheckProjectileImpact()
        WarpZone_TraceBox_ThroughZone(self.warpzone_oldorigin, self.mins, self.maxs, self.warpzone_oldorigin + self.warpzone_oldvelocity * frametime, MOVE_NORMAL, self, wz, WarpZone_trace_callback_t_null); // this will get us through the warpzone
        setorigin(self, trace_endpos);
        self.angles = WarpZone_TransformAngles(WarpZone_trace_transform, self.angles);
-       self.velocity = WarpZone_TransformVelocity(WarpZone_trace_transform, self.velocity);
+       self.velocity = WarpZone_TransformVelocity(WarpZone_trace_transform, self.warpzone_oldvelocity);
        
        // in case we are in our warp zone post-teleport, shift the projectile forward a bit
        mpd = max(vlen(self.mins), vlen(self.maxs));
@@ -262,6 +307,7 @@ void WarpZone_InitStep_FindOriginTarget()
                        error("Warp zone with nonexisting killtarget");
                        return;
                }
+               self.killtarget = string_null;
        }
 }
 
@@ -300,6 +346,8 @@ void WarpZoneCamera_InitStep_FindTarget()
                error("Camera with nonexisting target");
                return;
        }
+       ++warpzone_cameras_exist;
+       WarpZone_Camera_SetUp(self, self.enemy.origin, self.enemy.angles);
 }
 
 void WarpZone_InitStep_UpdateTransform()
@@ -321,7 +369,7 @@ void WarpZone_InitStep_UpdateTransform()
                tex = getsurfacetexture(self, i_s);
                if not(tex)
                        break; // this is beyond the last one
-               if(tex != "textures/common/warpzone")
+               if(tex == "textures/common/trigger")
                        continue;
                n_t = getsurfacenumtriangles(self, i_s);
                for(i_t = 0; i_t < n_t; ++i_t)
@@ -393,21 +441,29 @@ void WarpZone_InitStep_ClearTarget()
        self.enemy = world;
 }
 
+entity warpzone_first; .entity warpzone_next;
 void WarpZone_InitStep_FindTarget()
 {
        float i;
        entity e, e2;
 
+       if(self.enemy)
+               return;
+
        // this way only one of the two ents needs to target
        if(self.target != "")
        {
+               self.enemy = self; // so the if(!e.enemy) check also skips self, saves one IF
+
                e2 = world;
-               for(e = world; (e = find(world, targetname, self.target)); )
+               for(e = world, i = 0; (e = find(e, targetname, self.target)); )
                        if(!e.enemy)
-                               if(random() * ++i < 1)
-                                       e2 = e;
+                               if(e.classname == self.classname) // possibly non-warpzones may use the same targetname!
+                                       if(random() * ++i < 1)
+                                               e2 = e;
                if(!e2)
                {
+                       self.enemy = world;
                        error("Warpzone with non-existing target");
                        return;
                }
@@ -424,6 +480,7 @@ void WarpZone_InitStep_FinalizeTransform()
                return;
        }
 
+       ++warpzone_warpzones_exist;
        WarpZone_SetUp(self, self.warpzone_origin, self.warpzone_angles, self.enemy.warpzone_origin, self.enemy.warpzone_angles);
        self.touch = WarpZone_Touch;
        self.SendFlags = 0xFFFFFF;
@@ -537,7 +594,7 @@ void WarpZone_StartFrame()
                WarpZone_StoreProjectileData(e);
 }
 
-void target_warpzone_reconnect_use()
+void trigger_warpzone_reconnect_use()
 {
        entity e;
        e = self;
@@ -555,7 +612,12 @@ void target_warpzone_reconnect_use()
        self = e;
 }
 
-void trigger_warpzone_reconnect()
+void spawnfunc_trigger_warpzone_reconnect()
+{
+       self.use = trigger_warpzone_reconnect_use;
+}
+
+void spawnfunc_target_warpzone_reconnect()
 {
-       self.use = target_warpzone_reconnect_use;
+       spawnfunc_trigger_warpzone_reconnect(); // both names make sense here :(
 }