]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/movetypes/walk.qc
Kill the use of self in movetype code, to make it usable from the player physics...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / movetypes / walk.qc
index 0f18a47bfc6ee4bcc487f464ddd6eeb625e615ef..23d6e01a8f0ce7e2790222785c05bd377ee5ab84 100644 (file)
@@ -1,5 +1,5 @@
-void _Movetype_Physics_Walk(float dt)  // SV_WalkMove
-{SELFPARAM();
+void _Movetype_Physics_Walk(entity this, float dt)  // SV_WalkMove
+{
        vector stepnormal = '0 0 0';
 
        // if frametime is 0 (due to client sending the same timestamp twice), don't move
@@ -7,61 +7,61 @@ void _Movetype_Physics_Walk(float dt)  // SV_WalkMove
                return;
 
        if (GAMEPLAYFIX_UNSTICKPLAYERS)
-               _Movetype_UnstickEntity();
+               _Movetype_UnstickEntity(this);
 
-       bool applygravity = (!_Movetype_CheckWater(self) && self.move_movetype == MOVETYPE_WALK && !(self.move_flags & FL_WATERJUMP));
+       bool applygravity = (!_Movetype_CheckWater(this) && this.move_movetype == MOVETYPE_WALK && !(this.move_flags & FL_WATERJUMP));
 
-       _Movetype_CheckVelocity();
+       _Movetype_CheckVelocity(this);
 
        // do a regular slide move unless it looks like you ran into a step
-       bool oldonground = (self.move_flags & FL_ONGROUND);
+       bool oldonground = (this.move_flags & FL_ONGROUND);
 
-       vector start_origin = self.move_origin;
-       vector start_velocity = self.move_velocity;
+       vector start_origin = this.move_origin;
+       vector start_velocity = this.move_velocity;
 
-       int clip = _Movetype_FlyMove(dt, applygravity, stepnormal, GAMEPLAYFIX_STEPMULTIPLETIMES ? PHYS_STEPHEIGHT : 0);
+       int clip = _Movetype_FlyMove(this, dt, applygravity, stepnormal, GAMEPLAYFIX_STEPMULTIPLETIMES ? PHYS_STEPHEIGHT : 0);
 
        if (GAMEPLAYFIX_DOWNTRACEONGROUND && !(clip & 1))
        {
                // only try this if there was no floor in the way in the trace (no,
                // this check seems to be not REALLY necessary, because if clip & 1,
                // our trace will hit that thing too)
-               vector upmove = self.move_origin + '0 0 1';
-               vector downmove = self.move_origin - '0 0 1';
+               vector upmove = this.move_origin + '0 0 1';
+               vector downmove = this.move_origin - '0 0 1';
                int type;
-               if (self.move_movetype == MOVETYPE_FLYMISSILE)
+               if (this.move_movetype == MOVETYPE_FLYMISSILE)
                        type = MOVE_MISSILE;
-               else if (self.move_movetype == MOVETYPE_FLY_WORLDONLY)
+               else if (this.move_movetype == MOVETYPE_FLY_WORLDONLY)
                        type = MOVE_WORLDONLY;
-               else if (self.solid == SOLID_TRIGGER || self.solid == SOLID_NOT)
+               else if (this.solid == SOLID_TRIGGER || this.solid == SOLID_NOT)
                        type = MOVE_NOMONSTERS;
                else type = MOVE_NORMAL;
-               tracebox(upmove, self.mins, self.maxs, downmove, type, self);
+               tracebox(upmove, this.mins, this.maxs, downmove, type, this);
                if (trace_fraction < 1 && trace_plane_normal.z > 0.7)
                        clip |= 1;  // but we HAVE found a floor
        }
 
        // if the move did not hit the ground at any point, we're not on ground
        if (!(clip & 1))
-               self.move_flags &= ~FL_ONGROUND;
+               this.move_flags &= ~FL_ONGROUND;
 
-       _Movetype_CheckVelocity();
-       _Movetype_LinkEdict(true);
+       _Movetype_CheckVelocity(this);
+       _Movetype_LinkEdict(this, true);
 
        if (clip & 8)  // teleport
                return;
 
-       if (self.move_flags & FL_WATERJUMP)
+       if (this.move_flags & FL_WATERJUMP)
                return;
 
        if (PHYS_NOSTEP)
                return;
 
-       vector originalmove_origin = self.move_origin;
-       vector originalmove_velocity = self.move_velocity;
+       vector originalmove_origin = this.move_origin;
+       vector originalmove_velocity = this.move_velocity;
        // originalmove_clip = clip;
-       int originalmove_flags = self.move_flags;
-       entity originalmove_groundentity = self.move_groundentity;
+       int originalmove_flags = this.move_flags;
+       entity originalmove_groundentity = this.move_groundentity;
 
        // if move didn't block on a step, return
        if (clip & 2)
@@ -70,39 +70,39 @@ void _Movetype_Physics_Walk(float dt)  // SV_WalkMove
                if (fabs(start_velocity.x) < 0.03125 && fabs(start_velocity.y) < 0.03125)
                        return;
 
-               if (self.move_movetype != MOVETYPE_FLY)
+               if (this.move_movetype != MOVETYPE_FLY)
                {
                        // return if gibbed by a trigger
-                       if (self.move_movetype != MOVETYPE_WALK)
+                       if (this.move_movetype != MOVETYPE_WALK)
                                return;
 
                        // return if attempting to jump while airborn (unless sv_jumpstep)
                        if (!PHYS_JUMPSTEP)
-                               if (!oldonground && self.move_waterlevel == 0)
+                               if (!oldonground && this.move_waterlevel == 0)
                                        return;
                }
 
                // try moving up and forward to go up a step
                // back to start pos
-               self.move_origin = start_origin;
-               self.move_velocity = start_velocity;
+               this.move_origin = start_origin;
+               this.move_velocity = start_velocity;
 
                // move up
                vector upmove = '0 0 1' * PHYS_STEPHEIGHT;
-               vector prev_origin = self.move_origin;
-               _Movetype_PushEntity(upmove, true);
-               if(wasfreed(self))
+               vector prev_origin = this.move_origin;
+               _Movetype_PushEntity(this, upmove, true);
+               if(wasfreed(this))
                        return;
-               if(trace_startsolid && self.move_origin != prev_origin)
+               if(trace_startsolid && this.move_origin != prev_origin)
                {
                        // we got teleported when upstepping... must abort the move
                        return;
                }
 
                // move forward
-               self.move_velocity_z = 0;
-               clip = _Movetype_FlyMove(dt, applygravity, stepnormal, 0);
-               self.move_velocity_z += start_velocity.z;
+               this.move_velocity_z = 0;
+               clip = _Movetype_FlyMove(this, dt, applygravity, stepnormal, 0);
+               this.move_velocity_z += start_velocity.z;
                if (clip & 8)
                {
                        // we got teleported when upstepping... must abort the move
@@ -110,22 +110,22 @@ void _Movetype_Physics_Walk(float dt)  // SV_WalkMove
                        return;
                }
 
-               _Movetype_CheckVelocity();
-               _Movetype_LinkEdict(true);
+               _Movetype_CheckVelocity(this);
+               _Movetype_LinkEdict(this, true);
 
                // check for stuckness, possibly due to the limited precision of floats
                // in the clipping hulls
                if (clip
-                   && fabs(originalmove_origin.y - self.move_origin.y) < 0.03125
-                   && fabs(originalmove_origin.x - self.move_origin.x) < 0.03125)
+                   && fabs(originalmove_origin.y - this.move_origin.y) < 0.03125
+                   && fabs(originalmove_origin.x - this.move_origin.x) < 0.03125)
                {
                        // Con_Printf("wall\n");
                        // stepping up didn't make any progress, revert to original move
-                       self.move_origin = originalmove_origin;
-                       self.move_velocity = originalmove_velocity;
+                       this.move_origin = originalmove_origin;
+                       this.move_velocity = originalmove_velocity;
                        // clip = originalmove_clip;
-                       self.move_flags = originalmove_flags;
-                       self.move_groundentity = originalmove_groundentity;
+                       this.move_flags = originalmove_flags;
+                       this.move_groundentity = originalmove_groundentity;
                        // now try to unstick if needed
                        // clip = SV_TryUnstick (ent, oldvel);
                        return;
@@ -135,22 +135,22 @@ void _Movetype_Physics_Walk(float dt)  // SV_WalkMove
 
                // extra friction based on view angle
                if ((clip & 2) && PHYS_WALLFRICTION)
-                       _Movetype_WallFriction(stepnormal);
+                       _Movetype_WallFriction(this, stepnormal);
        }
        // don't do the down move if stepdown is disabled, moving upward, not in water, or the move started offground or ended onground
-       else if (!GAMEPLAYFIX_STEPDOWN || self.move_waterlevel >= 3 || start_velocity.z >= (1.0 / 32.0) || !oldonground || (self.move_flags & FL_ONGROUND))
+       else if (!GAMEPLAYFIX_STEPDOWN || this.move_waterlevel >= 3 || start_velocity.z >= (1.0 / 32.0) || !oldonground || (this.move_flags & FL_ONGROUND))
        {
                return;
        }
 
        // move down
        vector downmove = '0 0 1' * (-PHYS_STEPHEIGHT + start_velocity.z * dt);
-       vector prev_origin = self.move_origin;
-       _Movetype_PushEntity(downmove, true);
-       if(wasfreed(self))
+       vector prev_origin = this.move_origin;
+       _Movetype_PushEntity(this, downmove, true);
+       if(wasfreed(this))
                return;
 
-       if(trace_startsolid && self.move_origin != prev_origin)
+       if(trace_startsolid && this.move_origin != prev_origin)
        {
                // we got teleported when downstepping... must abort the move
                return;
@@ -167,12 +167,12 @@ void _Movetype_Physics_Walk(float dt)  // SV_WalkMove
                // if the push down didn't end up on good ground, use the move without
                // the step up.  This happens near wall / slope combinations, and can
                // cause the player to hop up higher on a slope too steep to climb
-               self.move_origin = originalmove_origin;
-               self.move_velocity = originalmove_velocity;
-               self.move_flags = originalmove_flags;
-               self.move_groundentity = originalmove_groundentity;
+               this.move_origin = originalmove_origin;
+               this.move_velocity = originalmove_velocity;
+               this.move_flags = originalmove_flags;
+               this.move_groundentity = originalmove_groundentity;
        }
 
-       _Movetype_CheckVelocity();
-       _Movetype_LinkEdict(true);
+       _Movetype_CheckVelocity(this);
+       _Movetype_LinkEdict(this, true);
 }