]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_move.c
Doxygen: disable CALL_GRAPH and CALLER_GRAPH
[xonotic/darkplaces.git] / sv_move.c
index bd7404c137f293f251aabe2d359ef0e7261d6db2..0699180d12f6e3bcdd1460723a6a157ff346d9e8 100644 (file)
--- a/sv_move.c
+++ b/sv_move.c
@@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // sv_move.c -- monster movement
 
 #include "quakedef.h"
 // sv_move.c -- monster movement
 
 #include "quakedef.h"
+#include "prvm_cmds.h"
 
 /*
 =============
 
 /*
 =============
@@ -32,15 +33,16 @@ is not a staircase.
 */
 int c_yes, c_no;
 
 */
 int c_yes, c_no;
 
-qboolean SV_CheckBottom (prvm_edict_t *ent)
+qbool SV_CheckBottom (prvm_edict_t *ent)
 {
 {
+       prvm_prog_t *prog = SVVM_prog;
        vec3_t  mins, maxs, start, stop;
        trace_t trace;
        int             x, y;
        float   mid, bottom;
 
        vec3_t  mins, maxs, start, stop;
        trace_t trace;
        int             x, y;
        float   mid, bottom;
 
-       VectorAdd (ent->fields.server->origin, ent->fields.server->mins, mins);
-       VectorAdd (ent->fields.server->origin, ent->fields.server->maxs, maxs);
+       VectorAdd (PRVM_serveredictvector(ent, origin), PRVM_serveredictvector(ent, mins), mins);
+       VectorAdd (PRVM_serveredictvector(ent, origin), PRVM_serveredictvector(ent, maxs), maxs);
 
 // if all of the points under the corners are solid world, don't bother
 // with the tougher checks
 
 // if all of the points under the corners are solid world, don't bother
 // with the tougher checks
@@ -69,7 +71,7 @@ realcheck:
        start[0] = stop[0] = (mins[0] + maxs[0])*0.5;
        start[1] = stop[1] = (mins[1] + maxs[1])*0.5;
        stop[2] = start[2] - 2*sv_stepheight.value;
        start[0] = stop[0] = (mins[0] + maxs[0])*0.5;
        start[1] = stop[1] = (mins[1] + maxs[1])*0.5;
        stop[2] = start[2] - 2*sv_stepheight.value;
-       trace = SV_Move (start, vec3_origin, vec3_origin, stop, MOVE_NOMONSTERS, ent);
+       trace = SV_TraceLine(start, stop, MOVE_NOMONSTERS, ent, SV_GenericHitSuperContentsMask(ent), 0, 0, collision_extendmovelength.value);
 
        if (trace.fraction == 1.0)
                return false;
 
        if (trace.fraction == 1.0)
                return false;
@@ -82,7 +84,7 @@ realcheck:
                        start[0] = stop[0] = x ? maxs[0] : mins[0];
                        start[1] = stop[1] = y ? maxs[1] : mins[1];
 
                        start[0] = stop[0] = x ? maxs[0] : mins[0];
                        start[1] = stop[1] = y ? maxs[1] : mins[1];
 
-                       trace = SV_Move (start, vec3_origin, vec3_origin, stop, MOVE_NOMONSTERS, ent);
+                       trace = SV_TraceLine(start, stop, MOVE_NOMONSTERS, ent, SV_GenericHitSuperContentsMask(ent), 0, 0, collision_extendmovelength.value);
 
                        if (trace.fraction != 1.0 && trace.endpos[2] > bottom)
                                bottom = trace.endpos[2];
 
                        if (trace.fraction != 1.0 && trace.endpos[2] > bottom)
                                bottom = trace.endpos[2];
@@ -101,49 +103,60 @@ SV_movestep
 
 Called by monster program code.
 The move will be adjusted for slopes and stairs, but if the move isn't
 
 Called by monster program code.
 The move will be adjusted for slopes and stairs, but if the move isn't
-possible, no move is done, false is returned, and
-prog->globals.server->trace_normal is set to the normal of the blocking wall
+possible, no move is done and false is returned
 =============
 */
 =============
 */
-qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink)
+qbool SV_movestep (prvm_edict_t *ent, vec3_t move, qbool relink, qbool noenemy, qbool settrace)
 {
 {
+       prvm_prog_t *prog = SVVM_prog;
        float           dz;
        float           dz;
-       vec3_t          oldorg, neworg, end, traceendpos;
+       vec3_t          oldorg, neworg, end, traceendpos, entorigin, entmins, entmaxs;
        trace_t         trace;
        int                     i;
        prvm_edict_t            *enemy;
 
 // try the move
        trace_t         trace;
        int                     i;
        prvm_edict_t            *enemy;
 
 // try the move
-       VectorCopy (ent->fields.server->origin, oldorg);
-       VectorAdd (ent->fields.server->origin, move, neworg);
+       VectorCopy (PRVM_serveredictvector(ent, origin), oldorg);
+       VectorAdd (PRVM_serveredictvector(ent, origin), move, neworg);
+       VectorCopy(PRVM_serveredictvector(ent, mins), entmins);
+       VectorCopy(PRVM_serveredictvector(ent, maxs), entmaxs);
 
 // flying monsters don't step up
 
 // flying monsters don't step up
-       if ( (int)ent->fields.server->flags & (FL_SWIM | FL_FLY) )
+       if ( (int)PRVM_serveredictfloat(ent, flags) & (FL_SWIM | FL_FLY) )
        {
        // try one move with vertical motion, then one without
                for (i=0 ; i<2 ; i++)
                {
        {
        // try one move with vertical motion, then one without
                for (i=0 ; i<2 ; i++)
                {
-                       VectorAdd (ent->fields.server->origin, move, neworg);
-                       enemy = PRVM_PROG_TO_EDICT(ent->fields.server->enemy);
-                       if (i == 0 && enemy != prog->edicts)
+                       VectorAdd (PRVM_serveredictvector(ent, origin), move, neworg);
+                       if (noenemy)
+                               enemy = prog->edicts;
+                       else
                        {
                        {
-                               dz = ent->fields.server->origin[2] - PRVM_PROG_TO_EDICT(ent->fields.server->enemy)->fields.server->origin[2];
-                               if (dz > 40)
-                                       neworg[2] -= 8;
-                               if (dz < 30)
-                                       neworg[2] += 8;
+                               enemy = PRVM_PROG_TO_EDICT(PRVM_serveredictedict(ent, enemy));
+                               if (i == 0 && enemy != prog->edicts)
+                               {
+                                       dz = PRVM_serveredictvector(ent, origin)[2] - PRVM_serveredictvector(enemy, origin)[2];
+                                       if (dz > 40)
+                                               neworg[2] -= 8;
+                                       if (dz < 30)
+                                               neworg[2] += 8;
+                               }
                        }
                        }
-                       trace = SV_Move (ent->fields.server->origin, ent->fields.server->mins, ent->fields.server->maxs, neworg, MOVE_NORMAL, ent);
+                       VectorCopy(PRVM_serveredictvector(ent, origin), entorigin);
+                       trace = SV_TraceBox(entorigin, entmins, entmaxs, neworg, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent), 0, 0, collision_extendmovelength.value);
 
                        if (trace.fraction == 1)
                        {
                                VectorCopy(trace.endpos, traceendpos);
 
                        if (trace.fraction == 1)
                        {
                                VectorCopy(trace.endpos, traceendpos);
-                               if (((int)ent->fields.server->flags & FL_SWIM) && !(SV_PointSuperContents(traceendpos) & SUPERCONTENTS_LIQUIDSMASK))
+                               if (((int)PRVM_serveredictfloat(ent, flags) & FL_SWIM) && !(SV_PointSuperContents(traceendpos) & SUPERCONTENTS_LIQUIDSMASK))
                                        return false;   // swim monster left water
 
                                        return false;   // swim monster left water
 
-                               VectorCopy (traceendpos, ent->fields.server->origin);
+                               VectorCopy (traceendpos, PRVM_serveredictvector(ent, origin));
                                if (relink)
                                if (relink)
-                                       SV_LinkEdict (ent, true);
+                               {
+                                       SV_LinkEdict(ent);
+                                       SV_LinkEdict_TouchAreaGrid(ent);
+                               }
                                return true;
                        }
 
                                return true;
                        }
 
@@ -159,24 +172,27 @@ qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink)
        VectorCopy (neworg, end);
        end[2] -= sv_stepheight.value*2;
 
        VectorCopy (neworg, end);
        end[2] -= sv_stepheight.value*2;
 
-       trace = SV_Move (neworg, ent->fields.server->mins, ent->fields.server->maxs, end, MOVE_NORMAL, ent);
+       trace = SV_TraceBox(neworg, entmins, entmaxs, end, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent), 0, 0, collision_extendmovelength.value);
 
        if (trace.startsolid)
        {
                neworg[2] -= sv_stepheight.value;
 
        if (trace.startsolid)
        {
                neworg[2] -= sv_stepheight.value;
-               trace = SV_Move (neworg, ent->fields.server->mins, ent->fields.server->maxs, end, MOVE_NORMAL, ent);
+               trace = SV_TraceBox(neworg, entmins, entmaxs, end, MOVE_NORMAL, ent, SV_GenericHitSuperContentsMask(ent), 0, 0, collision_extendmovelength.value);
                if (trace.startsolid)
                        return false;
        }
        if (trace.fraction == 1)
        {
        // if monster had the ground pulled out, go ahead and fall
                if (trace.startsolid)
                        return false;
        }
        if (trace.fraction == 1)
        {
        // if monster had the ground pulled out, go ahead and fall
-               if ( (int)ent->fields.server->flags & FL_PARTIALGROUND )
+               if ( (int)PRVM_serveredictfloat(ent, flags) & FL_PARTIALGROUND )
                {
                {
-                       VectorAdd (ent->fields.server->origin, move, ent->fields.server->origin);
+                       VectorAdd (PRVM_serveredictvector(ent, origin), move, PRVM_serveredictvector(ent, origin));
                        if (relink)
                        if (relink)
-                               SV_LinkEdict (ent, true);
-                       ent->fields.server->flags = (int)ent->fields.server->flags & ~FL_ONGROUND;
+                       {
+                               SV_LinkEdict(ent);
+                               SV_LinkEdict_TouchAreaGrid(ent);
+                       }
+                       PRVM_serveredictfloat(ent, flags) = (int)PRVM_serveredictfloat(ent, flags) & ~FL_ONGROUND;
                        return true;
                }
 
                        return true;
                }
 
@@ -184,29 +200,45 @@ qboolean SV_movestep (prvm_edict_t *ent, vec3_t move, qboolean relink)
        }
 
 // check point traces down for dangling corners
        }
 
 // check point traces down for dangling corners
-       VectorCopy (trace.endpos, ent->fields.server->origin);
+       VectorCopy (trace.endpos, PRVM_serveredictvector(ent, origin));
 
        if (!SV_CheckBottom (ent))
        {
 
        if (!SV_CheckBottom (ent))
        {
-               if ( (int)ent->fields.server->flags & FL_PARTIALGROUND )
+               if ( (int)PRVM_serveredictfloat(ent, flags) & FL_PARTIALGROUND )
                {       // entity had floor mostly pulled out from underneath it
                        // and is trying to correct
                        if (relink)
                {       // entity had floor mostly pulled out from underneath it
                        // and is trying to correct
                        if (relink)
-                               SV_LinkEdict (ent, true);
+                       {
+                               SV_LinkEdict(ent);
+                               SV_LinkEdict_TouchAreaGrid(ent);
+                       }
                        return true;
                }
                        return true;
                }
-               VectorCopy (oldorg, ent->fields.server->origin);
+               VectorCopy (oldorg, PRVM_serveredictvector(ent, origin));
                return false;
        }
 
                return false;
        }
 
-       if ( (int)ent->fields.server->flags & FL_PARTIALGROUND )
-               ent->fields.server->flags = (int)ent->fields.server->flags & ~FL_PARTIALGROUND;
+       if ( (int)PRVM_serveredictfloat(ent, flags) & FL_PARTIALGROUND )
+               PRVM_serveredictfloat(ent, flags) = (int)PRVM_serveredictfloat(ent, flags) & ~FL_PARTIALGROUND;
 
 
-       ent->fields.server->groundentity = PRVM_EDICT_TO_PROG(trace.ent);
+// gameplayfix: check if reached pretty steep plane and bail
+       if ( ! ( (int)PRVM_serveredictfloat(ent, flags) & (FL_SWIM | FL_FLY) ) && sv_gameplayfix_nostepmoveonsteepslopes.integer )
+       {
+               if (trace.plane.normal[ 2 ] < 0.5)
+               {
+                       VectorCopy (oldorg, PRVM_serveredictvector(ent, origin));
+                       return false;
+               }
+       }
+
+       PRVM_serveredictedict(ent, groundentity) = PRVM_EDICT_TO_PROG(trace.ent);
 
 // the move is ok
        if (relink)
 
 // the move is ok
        if (relink)
-               SV_LinkEdict (ent, true);
+       {
+               SV_LinkEdict(ent);
+               SV_LinkEdict_TouchAreaGrid(ent);
+       }
        return true;
 }
 
        return true;
 }
 
@@ -222,32 +254,34 @@ facing it.
 
 ======================
 */
 
 ======================
 */
-void VM_changeyaw (void);
-qboolean SV_StepDirection (prvm_edict_t *ent, float yaw, float dist)
+static qbool SV_StepDirection (prvm_edict_t *ent, float yaw, float dist)
 {
 {
+       prvm_prog_t *prog = SVVM_prog;
        vec3_t          move, oldorigin;
        float           delta;
 
        vec3_t          move, oldorigin;
        float           delta;
 
-       ent->fields.server->ideal_yaw = yaw;
-       VM_changeyaw();
+       PRVM_serveredictfloat(ent, ideal_yaw) = yaw;
+       VM_changeyaw(prog);
 
        yaw = yaw*M_PI*2 / 360;
        move[0] = cos(yaw)*dist;
        move[1] = sin(yaw)*dist;
        move[2] = 0;
 
 
        yaw = yaw*M_PI*2 / 360;
        move[0] = cos(yaw)*dist;
        move[1] = sin(yaw)*dist;
        move[2] = 0;
 
-       VectorCopy (ent->fields.server->origin, oldorigin);
-       if (SV_movestep (ent, move, false))
+       VectorCopy (PRVM_serveredictvector(ent, origin), oldorigin);
+       if (SV_movestep (ent, move, false, false, false))
        {
        {
-               delta = ent->fields.server->angles[YAW] - ent->fields.server->ideal_yaw;
+               delta = PRVM_serveredictvector(ent, angles)[YAW] - PRVM_serveredictfloat(ent, ideal_yaw);
                if (delta > 45 && delta < 315)
                {               // not turned far enough, so don't take the step
                if (delta > 45 && delta < 315)
                {               // not turned far enough, so don't take the step
-                       VectorCopy (oldorigin, ent->fields.server->origin);
+                       VectorCopy (oldorigin, PRVM_serveredictvector(ent, origin));
                }
                }
-               SV_LinkEdict (ent, true);
+               SV_LinkEdict(ent);
+               SV_LinkEdict_TouchAreaGrid(ent);
                return true;
        }
                return true;
        }
-       SV_LinkEdict (ent, true);
+       SV_LinkEdict(ent);
+       SV_LinkEdict_TouchAreaGrid(ent);
 
        return false;
 }
 
        return false;
 }
@@ -258,9 +292,10 @@ SV_FixCheckBottom
 
 ======================
 */
 
 ======================
 */
-void SV_FixCheckBottom (prvm_edict_t *ent)
+static void SV_FixCheckBottom (prvm_edict_t *ent)
 {
 {
-       ent->fields.server->flags = (int)ent->fields.server->flags | FL_PARTIALGROUND;
+       prvm_prog_t *prog = SVVM_prog;
+       PRVM_serveredictfloat(ent, flags) = (int)PRVM_serveredictfloat(ent, flags) | FL_PARTIALGROUND;
 }
 
 
 }
 
 
@@ -272,17 +307,18 @@ SV_NewChaseDir
 ================
 */
 #define        DI_NODIR        -1
 ================
 */
 #define        DI_NODIR        -1
-void SV_NewChaseDir (prvm_edict_t *actor, prvm_edict_t *enemy, float dist)
+static void SV_NewChaseDir (prvm_edict_t *actor, prvm_edict_t *enemy, float dist)
 {
 {
+       prvm_prog_t *prog = SVVM_prog;
        float           deltax,deltay;
        float                   d[3];
        float           tdir, olddir, turnaround;
 
        float           deltax,deltay;
        float                   d[3];
        float           tdir, olddir, turnaround;
 
-       olddir = ANGLEMOD((int)(actor->fields.server->ideal_yaw/45)*45);
+       olddir = ANGLEMOD((int)(PRVM_serveredictfloat(actor, ideal_yaw)/45)*45);
        turnaround = ANGLEMOD(olddir - 180);
 
        turnaround = ANGLEMOD(olddir - 180);
 
-       deltax = enemy->fields.server->origin[0] - actor->fields.server->origin[0];
-       deltay = enemy->fields.server->origin[1] - actor->fields.server->origin[1];
+       deltax = PRVM_serveredictvector(enemy, origin)[0] - PRVM_serveredictvector(actor, origin)[0];
+       deltay = PRVM_serveredictvector(enemy, origin)[1] - PRVM_serveredictvector(actor, origin)[1];
        if (deltax>10)
                d[1]= 0;
        else if (deltax<-10)
        if (deltax>10)
                d[1]= 0;
        else if (deltax<-10)
@@ -345,7 +381,7 @@ void SV_NewChaseDir (prvm_edict_t *actor, prvm_edict_t *enemy, float dist)
        if (turnaround != DI_NODIR && SV_StepDirection(actor, turnaround, dist) )
                        return;
 
        if (turnaround != DI_NODIR && SV_StepDirection(actor, turnaround, dist) )
                        return;
 
-       actor->fields.server->ideal_yaw = olddir;               // can't move
+       PRVM_serveredictfloat(actor, ideal_yaw) = olddir;               // can't move
 
 // if a bridge was pulled out from underneath a monster, it may not have
 // a valid standing position at all
 
 // if a bridge was pulled out from underneath a monster, it may not have
 // a valid standing position at all
@@ -361,7 +397,7 @@ SV_CloseEnough
 
 ======================
 */
 
 ======================
 */
-qboolean SV_CloseEnough (prvm_edict_t *ent, prvm_edict_t *goal, float dist)
+static qbool SV_CloseEnough (prvm_edict_t *ent, prvm_edict_t *goal, float dist)
 {
        int             i;
 
 {
        int             i;
 
@@ -377,32 +413,34 @@ qboolean SV_CloseEnough (prvm_edict_t *ent, prvm_edict_t *goal, float dist)
 
 /*
 ======================
 
 /*
 ======================
-SV_MoveToGoal
+VM_SV_MoveToGoal
 
 ======================
 */
 
 ======================
 */
-void SV_MoveToGoal (void)
+void VM_SV_MoveToGoal(prvm_prog_t *prog)
 {
        prvm_edict_t            *ent, *goal;
        float           dist;
 
 {
        prvm_edict_t            *ent, *goal;
        float           dist;
 
-       ent = PRVM_PROG_TO_EDICT(prog->globals.server->self);
-       goal = PRVM_PROG_TO_EDICT(ent->fields.server->goalentity);
+       VM_SAFEPARMCOUNT(1, VM_SV_MoveToGoal);
+
+       ent = PRVM_PROG_TO_EDICT(PRVM_serverglobaledict(self));
+       goal = PRVM_PROG_TO_EDICT(PRVM_serveredictedict(ent, goalentity));
        dist = PRVM_G_FLOAT(OFS_PARM0);
 
        dist = PRVM_G_FLOAT(OFS_PARM0);
 
-       if ( !( (int)ent->fields.server->flags & (FL_ONGROUND|FL_FLY|FL_SWIM) ) )
+       if ( !( (int)PRVM_serveredictfloat(ent, flags) & (FL_ONGROUND|FL_FLY|FL_SWIM) ) )
        {
                PRVM_G_FLOAT(OFS_RETURN) = 0;
                return;
        }
 
 // if the next step hits the enemy, return immediately
        {
                PRVM_G_FLOAT(OFS_RETURN) = 0;
                return;
        }
 
 // if the next step hits the enemy, return immediately
-       if ( PRVM_PROG_TO_EDICT(ent->fields.server->enemy) != prog->edicts &&  SV_CloseEnough (ent, goal, dist) )
+       if ( PRVM_PROG_TO_EDICT(PRVM_serveredictedict(ent, enemy)) != prog->edicts &&  SV_CloseEnough (ent, goal, dist) )
                return;
 
 // bump around...
        if ( (rand()&3)==1 ||
                return;
 
 // bump around...
        if ( (rand()&3)==1 ||
-       !SV_StepDirection (ent, ent->fields.server->ideal_yaw, dist))
+       !SV_StepDirection (ent, PRVM_serveredictfloat(ent, ideal_yaw), dist))
        {
                SV_NewChaseDir (ent, goal, dist);
        }
        {
                SV_NewChaseDir (ent, goal, dist);
        }