]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/warpzonelib/server.qc
#includes: cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / warpzonelib / server.qc
index 53d903902517cccf9eccc76f790c3a68ac5d25d6..033594d2ef8de8f7b9d07e4f624c06f79b3282e5 100644 (file)
@@ -7,8 +7,6 @@
        #include "../common/constants.qh"
        #include "../common/triggers/subs.qh"
        #include "../common/util.qh"
-       #include "../dpdefs/dpextensions.qh"
-       #include "../dpdefs/progsdefs.qh"
        #include "../server/command/common.qh"
        #include "../server/constants.qh"
        #include "../server/defs.qh"
@@ -54,7 +52,7 @@ void WarpZone_TeleportPlayer(entity teleporter, entity player, vector to, vector
 }
 
 bool WarpZone_Teleported_Send(entity to, int sf)
-{
+{SELFPARAM();
        WriteByte(MSG_ENTITY, ENT_CLIENT_WARPZONE_TELEPORTED);
        WriteCoord(MSG_ENTITY, self.angles.x);
        WriteCoord(MSG_ENTITY, self.angles.y);
@@ -112,7 +110,7 @@ float WarpZone_Teleport(entity wz, entity player, float f0, float f1)
                }
                else
                {
-                       print("would have to put player in solid, won't do that\n");
+                       LOG_INFO("would have to put player in solid, won't do that\n");
                        setorigin(player, o0 - player.view_ofs);
                        return 0;
                }
@@ -132,13 +130,15 @@ float WarpZone_Teleport(entity wz, entity player, float f0, float f1)
                player.warpzone_teleport_finishtime += sys_frametime - dt;
 
 #ifndef WARPZONE_USE_FIXANGLE
+       if(IS_VEHICLE(player) && player.owner)
+               player = player.owner; // hax
        if(IS_PLAYER(player))
        {
                // instead of fixangle, send the transform to the client for smoother operation
                player.fixangle = false;
 
                entity ts = spawn();
-               setmodel(ts, "null");
+               setmodel(ts, MDL_Null);
                ts.SendEntity = WarpZone_Teleported_Send;
                ts.SendFlags = 0xFFFFFF;
                ts.drawonlytoclient = player;
@@ -156,9 +156,7 @@ float WarpZone_Teleport(entity wz, entity player, float f0, float f1)
 }
 
 void WarpZone_Touch (void)
-{
-       entity oldself;
-
+{SELFPARAM();
        if(other.classname == "trigger_warpzone")
                return;
 
@@ -203,23 +201,22 @@ void WarpZone_Touch (void)
                if (!self.target) self.target = save1;
                if (!self.target3) self.target3 = save2;
 
-               oldself = self;
-               self = self.enemy;
+               setself(self.enemy);
                save1 = self.target; self.target = string_null;
                save2 = self.target2; self.target2 = string_null;
                SUB_UseTargets();
                if (!self.target) self.target = save1;
                if (!self.target2) self.target2 = save2;
-               self = oldself;
+               setself(this);
        }
        else
        {
-               dprint("WARPZONE FAIL AHAHAHAHAH))\n");
+               LOG_TRACE("WARPZONE FAIL AHAHAHAHAH))\n");
        }
 }
 
 bool WarpZone_Send(entity to, int sendflags)
-{
+{SELFPARAM();
        WriteByte(MSG_ENTITY, ENT_CLIENT_WARPZONE);
 
        // we must send this flag for clientside to match properly too
@@ -273,7 +270,7 @@ bool WarpZone_Send(entity to, int sendflags)
 }
 
 bool WarpZone_Camera_Send(entity to, int sendflags)
-{
+{SELFPARAM();
        int f = 0;
        WriteByte(MSG_ENTITY, ENT_CLIENT_WARPZONE_CAMERA);
 
@@ -319,7 +316,7 @@ bool WarpZone_Camera_Send(entity to, int sendflags)
 
 #ifdef WARPZONELIB_KEEPDEBUG
 float WarpZone_CheckProjectileImpact(entity player)
-{
+{SELFPARAM();
        vector o0, v0;
 
        o0 = player.origin + player.view_ofs;
@@ -336,13 +333,13 @@ float WarpZone_CheckProjectileImpact(entity player)
                return 0;
 
 #ifdef WARPZONELIB_REMOVEHACK
-       print("impactfilter found something - and it no longer gets handled correctly - please tell divVerent whether anything behaves broken now\n");
+       LOG_INFO("impactfilter found something - and it no longer gets handled correctly - please tell divVerent whether anything behaves broken now\n");
 #else
-       print("impactfilter found something - and it even gets handled correctly - please tell divVerent that this code apparently gets triggered again\n");
+       LOG_INFO("impactfilter found something - and it even gets handled correctly - please tell divVerent that this code apparently gets triggered again\n");
 #endif
-       print("Entity type: ", player.classname, "\n");
-       print("Origin: ", vtos(player.origin), "\n");
-       print("Velocity: ", vtos(player.velocity), "\n");
+       LOG_INFO("Entity type: ", player.classname, "\n");
+       LOG_INFO("Origin: ", vtos(player.origin), "\n");
+       LOG_INFO("Velocity: ", vtos(player.velocity), "\n");
 
 #ifdef WARPZONELIB_REMOVEHACK
        return 0;
@@ -386,7 +383,7 @@ float WarpZone_CheckProjectileImpact(entity player)
 #endif
 
 float WarpZone_Projectile_Touch()
-{
+{SELFPARAM();
        if(other.classname == "trigger_warpzone")
                return true;
 
@@ -454,7 +451,7 @@ float WarpZone_Projectile_Touch()
 }
 
 void WarpZone_InitStep_FindOriginTarget()
-{
+{SELFPARAM();
        if(self.killtarget != "")
        {
                self.aiment = find(world, targetname, self.killtarget);
@@ -468,7 +465,7 @@ void WarpZone_InitStep_FindOriginTarget()
 }
 
 void WarpZonePosition_InitStep_FindTarget()
-{
+{SELFPARAM();
        if(self.target == "")
        {
                error("Warp zone position with no target");
@@ -490,7 +487,7 @@ void WarpZonePosition_InitStep_FindTarget()
 }
 
 void WarpZoneCamera_Think(void)
-{
+{SELFPARAM();
        if(self.warpzone_save_origin != self.origin
        || self.warpzone_save_angles != self.angles
        || self.warpzone_save_eorigin != self.enemy.origin
@@ -506,7 +503,7 @@ void WarpZoneCamera_Think(void)
 }
 
 void WarpZoneCamera_InitStep_FindTarget()
-{
+{SELFPARAM();
        entity e;
        float i;
        if(self.target == "")
@@ -536,7 +533,7 @@ void WarpZoneCamera_InitStep_FindTarget()
 }
 
 void WarpZone_InitStep_UpdateTransform()
-{
+{SELFPARAM();
        vector org, ang, norm, point;
        float area;
        vector tri, a, b, c, n;
@@ -575,7 +572,7 @@ void WarpZone_InitStep_UpdateTransform()
                point = point * (1 / (3 * area));
                if(vlen(norm) < 0.99)
                {
-                       print("trigger_warpzone near ", vtos(self.aiment.origin), " is nonplanar. BEWARE.\n");
+                       LOG_INFO("trigger_warpzone near ", vtos(self.aiment.origin), " is nonplanar. BEWARE.\n");
                        area = 0; // no autofixing in this case
                }
                norm = normalize(norm);
@@ -592,15 +589,15 @@ void WarpZone_InitStep_UpdateTransform()
                        makevectors(ang);
                        if(norm * v_forward < 0)
                        {
-                               print("Position target of trigger_warpzone near ", vtos(self.aiment.origin), " points into trigger_warpzone. BEWARE.\n");
+                               LOG_INFO("Position target of trigger_warpzone near ", vtos(self.aiment.origin), " points into trigger_warpzone. BEWARE.\n");
                                norm = -1 * norm;
                        }
                        ang = vectoangles2(norm, v_up); // keep rotation, but turn exactly against plane
                        ang.x = -ang.x;
                        if(norm * v_forward < 0.99)
-                               print("trigger_warpzone near ", vtos(self.aiment.origin), " has been turned to match plane orientation (", vtos(self.aiment.angles), " -> ", vtos(ang), "\n");
+                               LOG_INFO("trigger_warpzone near ", vtos(self.aiment.origin), " has been turned to match plane orientation (", vtos(self.aiment.angles), " -> ", vtos(ang), "\n");
                        if(vlen(org - self.aiment.origin) > 0.5)
-                               print("trigger_warpzone near ", vtos(self.aiment.origin), " has been moved to match the plane (", vtos(self.aiment.origin), " -> ", vtos(org), ").\n");
+                               LOG_INFO("trigger_warpzone near ", vtos(self.aiment.origin), " has been moved to match the plane (", vtos(self.aiment.origin), " -> ", vtos(org), ").\n");
                }
        }
        else if(area > 0)
@@ -617,7 +614,7 @@ void WarpZone_InitStep_UpdateTransform()
 }
 
 void WarpZone_InitStep_ClearTarget()
-{
+{SELFPARAM();
        if(self.enemy)
                self.enemy.enemy = world;
        self.enemy = world;
@@ -625,7 +622,7 @@ void WarpZone_InitStep_ClearTarget()
 
 entity warpzone_first; .entity warpzone_next;
 void WarpZone_InitStep_FindTarget()
-{
+{SELFPARAM();
        float i;
        entity e, e2;
 
@@ -656,7 +653,7 @@ void WarpZone_InitStep_FindTarget()
 
 void WarpZone_Think();
 void WarpZone_InitStep_FinalizeTransform()
-{
+{SELFPARAM();
        if(!self.enemy || self.enemy.enemy != self)
        {
                error("Invalid warp zone detected. Killed.");
@@ -681,17 +678,17 @@ float warpzone_initialized;
 entity warpzone_position_first;
 entity warpzone_camera_first;
 .entity warpzone_next;
-void spawnfunc_misc_warpzone_position(void)
+spawnfunc(misc_warpzone_position)
 {
        // "target", "angles", "origin"
        self.warpzone_next = warpzone_position_first;
        warpzone_position_first = self;
 }
-void spawnfunc_trigger_warpzone_position(void)
+spawnfunc(trigger_warpzone_position)
 {
-       spawnfunc_misc_warpzone_position();
+       spawnfunc_misc_warpzone_position(this);
 }
-void spawnfunc_trigger_warpzone(void)
+spawnfunc(trigger_warpzone)
 {
        // warp zone entities must have:
        // "killtarget" pointing to a target_position with a direction arrow
@@ -701,11 +698,6 @@ void spawnfunc_trigger_warpzone(void)
        //              the map, with another killtarget to designate its
        //              orientation
 
-#ifndef WARPZONE_USE_FIXANGLE
-       // used when teleporting
-       precache_model("null");
-#endif
-
        if(!self.scale)
                self.scale = self.modelscale;
        if(!self.scale)
@@ -716,7 +708,7 @@ void spawnfunc_trigger_warpzone(void)
        if(m != "")
        {
                precache_model(m);
-               setmodel(self, m); // no precision needed
+               _setmodel(self, m); // no precision needed
        }
        setorigin(self, self.origin);
        if(self.scale)
@@ -729,7 +721,7 @@ void spawnfunc_trigger_warpzone(void)
        self.warpzone_next = warpzone_first;
        warpzone_first = self;
 }
-void spawnfunc_func_camera(void)
+spawnfunc(func_camera)
 {
        if(!self.scale)
                self.scale = self.modelscale;
@@ -738,7 +730,7 @@ void spawnfunc_func_camera(void)
        if(self.model != "")
        {
                precache_model(self.model);
-               setmodel(self, self.model); // no precision needed
+               _setmodel(self, self.model); // no precision needed
        }
        setorigin(self, self.origin);
        if(self.scale)
@@ -755,37 +747,33 @@ void spawnfunc_func_camera(void)
        warpzone_camera_first = self;
 }
 void WarpZones_Reconnect()
-{
-       entity e;
-       e = self;
-       for(self = warpzone_first; self; self = self.warpzone_next)
+{SELFPARAM();
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                WarpZone_InitStep_ClearTarget();
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                WarpZone_InitStep_FindTarget();
-       for(self = warpzone_camera_first; self; self = self.warpzone_next)
+       for(setself(warpzone_camera_first); self; setself(self.warpzone_next))
                WarpZoneCamera_InitStep_FindTarget();
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                WarpZone_InitStep_FinalizeTransform();
-       self = e;
+       setself(this);
 }
 
 void WarpZone_Think()
-{
+{SELFPARAM();
        if(self.warpzone_save_origin != self.origin
        || self.warpzone_save_angles != self.angles
        || self.warpzone_save_eorigin != self.enemy.origin
        || self.warpzone_save_eangles != self.enemy.angles)
        {
-               entity oldself;
-               oldself = self;
                WarpZone_InitStep_UpdateTransform();
-               self = self.enemy;
+               setself(self.enemy);
                WarpZone_InitStep_UpdateTransform();
-               self = oldself;
+               setself(this);
                WarpZone_InitStep_FinalizeTransform();
-               self = self.enemy;
+               setself(self.enemy);
                WarpZone_InitStep_FinalizeTransform();
-               self = oldself;
+               setself(this);
                self.warpzone_save_origin = self.origin;
                self.warpzone_save_angles = self.angles;
                self.warpzone_save_eorigin = self.enemy.origin;
@@ -795,25 +783,23 @@ void WarpZone_Think()
 }
 
 void WarpZone_StartFrame()
-{
+{SELFPARAM();
        entity e;
        if(warpzone_initialized == 0)
        {
                warpzone_initialized = 1;
-               e = self;
-               for(self = warpzone_first; self; self = self.warpzone_next)
+               for(setself(warpzone_first); self; setself(self.warpzone_next))
                        WarpZone_InitStep_FindOriginTarget();
-               for(self = warpzone_position_first; self; self = self.warpzone_next)
+               for(setself(warpzone_position_first); self; setself(self.warpzone_next))
                        WarpZonePosition_InitStep_FindTarget();
-               for(self = warpzone_first; self; self = self.warpzone_next)
+               for(setself(warpzone_first); self; setself(self.warpzone_next))
                        WarpZone_InitStep_UpdateTransform();
-               self = e;
+               setself(this);
                WarpZones_Reconnect();
                WarpZone_PostInitialize_Callback();
        }
 
-       entity oldself, oldother;
-       oldself = self;
+       entity oldother;
        oldother = other;
        for(e = world; (e = nextent(e)); )
        {
@@ -828,14 +814,14 @@ void WarpZone_StartFrame()
 
                                // warpzones
                                if(warpzone_warpzones_exist) {
-                               self = WarpZone_Find(e.origin + e.mins, e.origin + e.maxs);
+                               setself(WarpZone_Find(e.origin + e.mins, e.origin + e.maxs));
                                if(self)
                                if(!WarpZoneLib_ExactTrigger_Touch())
                                        if(WarpZone_PlaneDist(self, e.origin + e.view_ofs) <= 0)
                                                WarpZone_Teleport(self, e, -1, 0); } // NOT triggering targets by this!
 
                                // teleporters
-                               self = Teleport_Find(e.origin + e.mins, e.origin + e.maxs);
+                               setself(Teleport_Find(e.origin + e.mins, e.origin + e.maxs));
                                if(self)
                                if(!WarpZoneLib_ExactTrigger_Touch())
                                        Simple_TeleportPlayer(self, other); // NOT triggering targets by this!
@@ -850,7 +836,7 @@ void WarpZone_StartFrame()
                        break;
                }
        }
-       self = oldself;
+       setself(this);
        other = oldother;
 }
 
@@ -865,42 +851,42 @@ float visible_to_some_client(entity ent)
        return 0;
 }
 void trigger_warpzone_reconnect_use()
-{
+{SELFPARAM();
        entity e;
        e = self;
        // NOTE: this matches for target, not targetname, but of course
        // targetname must be set too on the other entities
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                self.warpzone_reconnecting = ((e.target == "" || self.target == e.target) && !((e.spawnflags & 1) && (visible_to_some_client(self) || visible_to_some_client(self.enemy))));
-       for(self = warpzone_camera_first; self; self = self.warpzone_next)
+       for(setself(warpzone_camera_first); self; setself(self.warpzone_next))
                self.warpzone_reconnecting = ((e.target == "" || self.target == e.target) && !((e.spawnflags & 1) && visible_to_some_client(self)));
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                if(self.warpzone_reconnecting)
                        WarpZone_InitStep_ClearTarget();
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                if(self.warpzone_reconnecting)
                        WarpZone_InitStep_FindTarget();
-       for(self = warpzone_camera_first; self; self = self.warpzone_next)
+       for(setself(warpzone_camera_first); self; setself(self.warpzone_next))
                if(self.warpzone_reconnecting)
                        WarpZoneCamera_InitStep_FindTarget();
-       for(self = warpzone_first; self; self = self.warpzone_next)
+       for(setself(warpzone_first); self; setself(self.warpzone_next))
                if(self.warpzone_reconnecting || self.enemy.warpzone_reconnecting)
                        WarpZone_InitStep_FinalizeTransform();
-       self = e;
+       setself(e);
 }
 
-void spawnfunc_trigger_warpzone_reconnect()
+spawnfunc(trigger_warpzone_reconnect)
 {
        self.use = trigger_warpzone_reconnect_use;
 }
 
-void spawnfunc_target_warpzone_reconnect()
+spawnfunc(target_warpzone_reconnect)
 {
-       spawnfunc_trigger_warpzone_reconnect(); // both names make sense here :(
+       spawnfunc_trigger_warpzone_reconnect(this); // both names make sense here :(
 }
 
 void WarpZone_PlayerPhysics_FixVAngle(void)
-{
+{SELFPARAM();
 #ifndef WARPZONE_DONT_FIX_VANGLE
        if(IS_REAL_CLIENT(self))
        if(self.v_angle.z <= 360) // if not already adjusted