X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=sv_move.c;h=9fc5b31d3d05545266eadc5fa3f26aa7fa450cff;hb=b89f5eded7d906d0779f774a3aad690d90407ad8;hp=87f3ed434a38ab1cd53b99de326a0701472b501c;hpb=8dcce44300385b12c46d494c06aadcfa35a8bc14;p=xonotic%2Fdarkplaces.git diff --git a/sv_move.c b/sv_move.c index 87f3ed43..9fc5b31d 100644 --- a/sv_move.c +++ b/sv_move.c @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -21,8 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" -#define STEPSIZE 18 - /* ============= SV_CheckBottom @@ -40,9 +38,9 @@ qboolean SV_CheckBottom (edict_t *ent) trace_t trace; int x, y; float mid, bottom; - - VectorAdd (ent->v.origin, ent->v.mins, mins); - VectorAdd (ent->v.origin, ent->v.maxs, maxs); + + VectorAdd (ent->v->origin, ent->v->mins, mins); + VectorAdd (ent->v->origin, ent->v->maxs, maxs); // if all of the points under the corners are solid world, don't bother // with the tougher checks @@ -53,7 +51,7 @@ qboolean SV_CheckBottom (edict_t *ent) { start[0] = x ? maxs[0] : mins[0]; start[1] = y ? maxs[1] : mins[1]; - if (SV_PointContents (start) != CONTENTS_SOLID) + if (!(SV_PointSuperContents(start) & SUPERCONTENTS_SOLID)) goto realcheck; } @@ -66,29 +64,29 @@ realcheck: // check it for real... // start[2] = mins[2]; - + // the midpoint must be within 16 of the bottom 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*STEPSIZE; - trace = SV_Move (start, vec3_origin, vec3_origin, stop, true, ent); + stop[2] = start[2] - 2*sv_stepheight.value; + trace = SV_Move (start, vec3_origin, vec3_origin, stop, MOVE_NOMONSTERS, ent); if (trace.fraction == 1.0) return false; mid = bottom = trace.endpos[2]; - -// the corners must be within 16 of the midpoint + +// the corners must be within 16 of the midpoint for (x=0 ; x<=1 ; x++) for (y=0 ; y<=1 ; y++) { 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, true, ent); - + + trace = SV_Move (start, vec3_origin, vec3_origin, stop, MOVE_NOMONSTERS, ent); + if (trace.fraction != 1.0 && trace.endpos[2] > bottom) bottom = trace.endpos[2]; - if (trace.fraction == 1.0 || mid - trace.endpos[2] > STEPSIZE) + if (trace.fraction == 1.0 || mid - trace.endpos[2] > sv_stepheight.value) return false; } @@ -110,78 +108,75 @@ pr_global_struct->trace_normal is set to the normal of the blocking wall qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink) { float dz; - vec3_t oldorg, neworg, end; + vec3_t oldorg, neworg, end, traceendpos; trace_t trace; int i; edict_t *enemy; -// try the move - VectorCopy (ent->v.origin, oldorg); - VectorAdd (ent->v.origin, move, neworg); +// try the move + VectorCopy (ent->v->origin, oldorg); + VectorAdd (ent->v->origin, move, neworg); // flying monsters don't step up - if ( (int)ent->v.flags & (FL_SWIM | FL_FLY) ) + if ( (int)ent->v->flags & (FL_SWIM | FL_FLY) ) { // try one move with vertical motion, then one without for (i=0 ; i<2 ; i++) { - VectorAdd (ent->v.origin, move, neworg); - enemy = PROG_TO_EDICT(ent->v.enemy); + VectorAdd (ent->v->origin, move, neworg); + enemy = PROG_TO_EDICT(ent->v->enemy); if (i == 0 && enemy != sv.edicts) { - dz = ent->v.origin[2] - PROG_TO_EDICT(ent->v.enemy)->v.origin[2]; + dz = ent->v->origin[2] - PROG_TO_EDICT(ent->v->enemy)->v->origin[2]; if (dz > 40) neworg[2] -= 8; if (dz < 30) neworg[2] += 8; } - trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, neworg, false, ent); - + trace = SV_Move (ent->v->origin, ent->v->mins, ent->v->maxs, neworg, MOVE_NORMAL, ent); + if (trace.fraction == 1) { - if ( ((int)ent->v.flags & FL_SWIM) && SV_PointContents(trace.endpos) == CONTENTS_EMPTY ) + VectorCopy(trace.endpos, traceendpos); + if (((int)ent->v->flags & FL_SWIM) && !(SV_PointSuperContents(traceendpos) & SUPERCONTENTS_LIQUIDSMASK)) return false; // swim monster left water - - VectorCopy (trace.endpos, ent->v.origin); + + VectorCopy (traceendpos, ent->v->origin); if (relink) SV_LinkEdict (ent, true); return true; } - + if (enemy == sv.edicts) break; } - + return false; } // push down from a step height above the wished position - neworg[2] += STEPSIZE; + neworg[2] += sv_stepheight.value; VectorCopy (neworg, end); - end[2] -= STEPSIZE*2; + end[2] -= sv_stepheight.value*2; - trace = SV_Move (neworg, ent->v.mins, ent->v.maxs, end, false, ent); - - if (trace.allsolid) - return false; + trace = SV_Move (neworg, ent->v->mins, ent->v->maxs, end, MOVE_NORMAL, ent); if (trace.startsolid) { - neworg[2] -= STEPSIZE; - trace = SV_Move (neworg, ent->v.mins, ent->v.maxs, end, false, ent); - if (trace.allsolid || trace.startsolid) + neworg[2] -= sv_stepheight.value; + trace = SV_Move (neworg, ent->v->mins, ent->v->maxs, end, MOVE_NORMAL, ent); + if (trace.startsolid) return false; } if (trace.fraction == 1) { // if monster had the ground pulled out, go ahead and fall - if ( (int)ent->v.flags & FL_PARTIALGROUND ) + if ( (int)ent->v->flags & FL_PARTIALGROUND ) { - VectorAdd (ent->v.origin, move, ent->v.origin); + VectorAdd (ent->v->origin, move, ent->v->origin); if (relink) SV_LinkEdict (ent, true); - ent->v.flags = (int)ent->v.flags & ~FL_ONGROUND; -// Con_Printf ("fall down\n"); + ent->v->flags = (int)ent->v->flags & ~FL_ONGROUND; return true; } @@ -189,27 +184,25 @@ qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink) } // check point traces down for dangling corners - VectorCopy (trace.endpos, ent->v.origin); - + VectorCopy (trace.endpos, ent->v->origin); + if (!SV_CheckBottom (ent)) { - if ( (int)ent->v.flags & FL_PARTIALGROUND ) + if ( (int)ent->v->flags & FL_PARTIALGROUND ) { // entity had floor mostly pulled out from underneath it // and is trying to correct if (relink) SV_LinkEdict (ent, true); return true; } - VectorCopy (oldorg, ent->v.origin); + VectorCopy (oldorg, ent->v->origin); return false; } - if ( (int)ent->v.flags & FL_PARTIALGROUND ) - { -// Con_Printf ("back on ground\n"); - ent->v.flags = (int)ent->v.flags & ~FL_PARTIALGROUND; - } - ent->v.groundentity = EDICT_TO_PROG(trace.ent); + if ( (int)ent->v->flags & FL_PARTIALGROUND ) + ent->v->flags = (int)ent->v->flags & ~FL_PARTIALGROUND; + + ent->v->groundentity = EDICT_TO_PROG(trace.ent); // the move is ok if (relink) @@ -234,28 +227,28 @@ qboolean SV_StepDirection (edict_t *ent, float yaw, float dist) { vec3_t move, oldorigin; float delta; - - ent->v.ideal_yaw = yaw; + + ent->v->ideal_yaw = yaw; PF_changeyaw(); - + yaw = yaw*M_PI*2 / 360; move[0] = cos(yaw)*dist; move[1] = sin(yaw)*dist; move[2] = 0; - VectorCopy (ent->v.origin, oldorigin); + VectorCopy (ent->v->origin, oldorigin); if (SV_movestep (ent, move, false)) { - delta = ent->v.angles[YAW] - ent->v.ideal_yaw; + delta = ent->v->angles[YAW] - ent->v->ideal_yaw; if (delta > 45 && delta < 315) { // not turned far enough, so don't take the step - VectorCopy (oldorigin, ent->v.origin); + VectorCopy (oldorigin, ent->v->origin); } SV_LinkEdict (ent, true); return true; } SV_LinkEdict (ent, true); - + return false; } @@ -267,9 +260,7 @@ SV_FixCheckBottom */ void SV_FixCheckBottom (edict_t *ent) { -// Con_Printf ("SV_FixCheckBottom\n"); - - ent->v.flags = (int)ent->v.flags | FL_PARTIALGROUND; + ent->v->flags = (int)ent->v->flags | FL_PARTIALGROUND; } @@ -287,11 +278,11 @@ void SV_NewChaseDir (edict_t *actor, edict_t *enemy, float dist) float d[3]; float tdir, olddir, turnaround; - olddir = anglemod( (int)(actor->v.ideal_yaw/45)*45 ); - turnaround = anglemod(olddir - 180); + olddir = ANGLEMOD((int)(actor->v->ideal_yaw/45)*45); + turnaround = ANGLEMOD(olddir - 180); - deltax = enemy->v.origin[0] - actor->v.origin[0]; - deltay = enemy->v.origin[1] - actor->v.origin[1]; + deltax = enemy->v->origin[0] - actor->v->origin[0]; + deltay = enemy->v->origin[1] - actor->v->origin[1]; if (deltax>10) d[1]= 0; else if (deltax<-10) @@ -312,7 +303,7 @@ void SV_NewChaseDir (edict_t *actor, edict_t *enemy, float dist) tdir = d[2] == 90 ? 45 : 315; else tdir = d[2] == 90 ? 135 : 215; - + if (tdir != turnaround && SV_StepDirection(actor, tdir, dist)) return; } @@ -325,7 +316,7 @@ void SV_NewChaseDir (edict_t *actor, edict_t *enemy, float dist) d[2]=tdir; } - if (d[1]!=DI_NODIR && d[1]!=turnaround + if (d[1]!=DI_NODIR && d[1]!=turnaround && SV_StepDirection(actor, d[1], dist)) return; @@ -354,7 +345,7 @@ void SV_NewChaseDir (edict_t *actor, edict_t *enemy, float dist) if (turnaround != DI_NODIR && SV_StepDirection(actor, turnaround, dist) ) return; - actor->v.ideal_yaw = olddir; // can't move + actor->v->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 @@ -373,12 +364,12 @@ SV_CloseEnough qboolean SV_CloseEnough (edict_t *ent, edict_t *goal, float dist) { int i; - + for (i=0 ; i<3 ; i++) { - if (goal->v.absmin[i] > ent->v.absmax[i] + dist) + if (goal->v->absmin[i] > ent->v->absmax[i] + dist) return false; - if (goal->v.absmax[i] < ent->v.absmin[i] - dist) + if (goal->v->absmax[i] < ent->v->absmin[i] - dist) return false; } return true; @@ -396,22 +387,22 @@ void SV_MoveToGoal (void) float dist; ent = PROG_TO_EDICT(pr_global_struct->self); - goal = PROG_TO_EDICT(ent->v.goalentity); + goal = PROG_TO_EDICT(ent->v->goalentity); dist = G_FLOAT(OFS_PARM0); - if ( !( (int)ent->v.flags & (FL_ONGROUND|FL_FLY|FL_SWIM) ) ) + if ( !( (int)ent->v->flags & (FL_ONGROUND|FL_FLY|FL_SWIM) ) ) { G_FLOAT(OFS_RETURN) = 0; return; } // if the next step hits the enemy, return immediately - if ( PROG_TO_EDICT(ent->v.enemy) != sv.edicts && SV_CloseEnough (ent, goal, dist) ) + if ( PROG_TO_EDICT(ent->v->enemy) != sv.edicts && SV_CloseEnough (ent, goal, dist) ) return; // bump around... if ( (rand()&3)==1 || - !SV_StepDirection (ent, ent->v.ideal_yaw, dist)) + !SV_StepDirection (ent, ent->v->ideal_yaw, dist)) { SV_NewChaseDir (ent, goal, dist); }