Unify all sv_* code with dquake

This commit is contained in:
cypress 2024-09-04 19:06:33 -07:00
parent 5686e4f13e
commit cd1fed05c8
6 changed files with 615 additions and 509 deletions

View file

@ -510,7 +510,7 @@ void CL_SendMove (usercmd_t *cmd)
int bits;
sizebuf_t buf;
byte data[128];
vec3_t tempv;
buf.maxsize = 128;
buf.cursize = 0;
buf.data = data;
@ -559,8 +559,9 @@ void CL_SendMove (usercmd_t *cmd)
MSG_WriteFloat (&buf, cl.mtime[0]); // so server can get ping times
VectorAdd(cl.gun_kick, cl.viewangles, tempv);
for (i=0 ; i<3 ; i++)
MSG_WriteAngle (&buf, cl.viewangles[i]);
MSG_WriteFloat (&buf, tempv[i]);
MSG_WriteShort (&buf, cmd->forwardmove);
MSG_WriteShort (&buf, cmd->sidemove);
@ -608,13 +609,6 @@ void CL_SendMove (usercmd_t *cmd)
MSG_WriteByte (&buf, in_impulse);
in_impulse = 0;
#ifdef QUAKE2
//
// light level
//
MSG_WriteByte (&buf, cmd->lightlevel);
#endif
//
// deliver the message
//

View file

@ -638,3 +638,127 @@ fixed16_t Invert24To16(fixed16_t val)
}
#endif
/*
========================================================================
Matrix4x4 operations
========================================================================
*/
void Matrix4x4_VectorTransform( const matrix4x4 in, const float v[3], float out[3] )
{
out[0] = v[0] * in[0][0] + v[1] * in[0][1] + v[2] * in[0][2] + in[0][3];
out[1] = v[0] * in[1][0] + v[1] * in[1][1] + v[2] * in[1][2] + in[1][3];
out[2] = v[0] * in[2][0] + v[1] * in[2][1] + v[2] * in[2][2] + in[2][3];
}
void Matrix4x4_VectorITransform( const matrix4x4 in, const float v[3], float out[3] )
{
vec3_t dir;
dir[0] = v[0] - in[0][3];
dir[1] = v[1] - in[1][3];
dir[2] = v[2] - in[2][3];
out[0] = dir[0] * in[0][0] + dir[1] * in[1][0] + dir[2] * in[2][0];
out[1] = dir[0] * in[0][1] + dir[1] * in[1][1] + dir[2] * in[2][1];
out[2] = dir[0] * in[0][2] + dir[1] * in[1][2] + dir[2] * in[2][2];
}
void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_t origin, float scale )
{
float angle, sr, sp, sy, cr, cp, cy;
if( angles[ROLL] )
{
angle = angles[YAW] * (M_PI*2 / 360);
sincos( angle, &sy, &cy );
angle = angles[PITCH] * (M_PI*2 / 360);
sincos( angle, &sp, &cp );
angle = angles[ROLL] * (M_PI*2 / 360);
sincos( angle, &sr, &cr );
out[0][0] = (cp*cy) * scale;
out[0][1] = (sr*sp*cy+cr*-sy) * scale;
out[0][2] = (cr*sp*cy+-sr*-sy) * scale;
out[0][3] = origin[0];
out[1][0] = (cp*sy) * scale;
out[1][1] = (sr*sp*sy+cr*cy) * scale;
out[1][2] = (cr*sp*sy+-sr*cy) * scale;
out[1][3] = origin[1];
out[2][0] = (-sp) * scale;
out[2][1] = (sr*cp) * scale;
out[2][2] = (cr*cp) * scale;
out[2][3] = origin[2];
out[3][0] = 0;
out[3][1] = 0;
out[3][2] = 0;
out[3][3] = 1;
}
else if( angles[PITCH] )
{
angle = angles[YAW] * (M_PI*2 / 360);
sincos( angle, &sy, &cy );
angle = angles[PITCH] * (M_PI*2 / 360);
sincos( angle, &sp, &cp );
out[0][0] = (cp*cy) * scale;
out[0][1] = (-sy) * scale;
out[0][2] = (sp*cy) * scale;
out[0][3] = origin[0];
out[1][0] = (cp*sy) * scale;
out[1][1] = (cy) * scale;
out[1][2] = (sp*sy) * scale;
out[1][3] = origin[1];
out[2][0] = (-sp) * scale;
out[2][1] = 0;
out[2][2] = (cp) * scale;
out[2][3] = origin[2];
out[3][0] = 0;
out[3][1] = 0;
out[3][2] = 0;
out[3][3] = 1;
}
else if( angles[YAW] )
{
angle = angles[YAW] * (M_PI*2 / 360);
sincos( angle, &sy, &cy );
out[0][0] = (cy) * scale;
out[0][1] = (-sy) * scale;
out[0][2] = 0;
out[0][3] = origin[0];
out[1][0] = (sy) * scale;
out[1][1] = (cy) * scale;
out[1][2] = 0;
out[1][3] = origin[1];
out[2][0] = 0;
out[2][1] = 0;
out[2][2] = scale;
out[2][3] = origin[2];
out[3][0] = 0;
out[3][1] = 0;
out[3][2] = 0;
out[3][3] = 1;
}
else
{
out[0][0] = scale;
out[0][1] = 0;
out[0][2] = 0;
out[0][3] = origin[0];
out[1][0] = 0;
out[1][1] = scale;
out[1][2] = 0;
out[1][3] = origin[1];
out[2][0] = 0;
out[2][1] = 0;
out[2][2] = scale;
out[2][3] = origin[2];
out[3][0] = 0;
out[3][1] = 0;
out[3][2] = 0;
out[3][3] = 1;
}
}

View file

@ -23,6 +23,7 @@ typedef float vec_t;
typedef vec_t vec3_t[3];
typedef vec_t vec5_t[5];
typedef vec_t vec2_t[2];
typedef vec_t matrix4x4[4][4];
typedef int fixed4_t;
typedef int fixed8_t;
@ -97,6 +98,10 @@ void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct mplane_s *plane);
float anglemod(float a);
void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_t origin, float scale );
void Matrix4x4_VectorTransform( const matrix4x4 in, const float v[3], float out[3] );
void Matrix4x4_VectorITransform( const matrix4x4 in, const float v[3], float out[3] );
extern int _mathlib_temp_int1, _mathlib_temp_int2, _mathlib_temp_int3;
extern float _mathlib_temp_float1, _mathlib_temp_float2, _mathlib_temp_float3;
extern vec3_t _mathlib_temp_vec1, _mathlib_temp_vec2, _mathlib_temp_vec3;

View file

@ -107,7 +107,8 @@ possible, no move is done, false is returned, and
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)
qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink)//Blubs edited this to make zombies walk through zombies
{
float dz;
vec3_t oldorg, neworg, end;
@ -135,7 +136,7 @@ qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
if (dz < 30)
neworg[2] += 8;
}
trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, neworg, MOVE_NOMONSTERS, ent); //sB fixing zombies, was FALSE thanks blubs
trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, neworg,MOVE_NOMONSTERS, ent);//blubs edit, was 'false'
if (trace.fraction == 1)
{
@ -151,7 +152,6 @@ qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
if (enemy == sv.edicts)
break;
}
return false;
}
@ -160,17 +160,21 @@ qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
VectorCopy (neworg, end);
end[2] -= STEPSIZE*2;
trace = SV_Move (neworg, ent->v.mins, ent->v.maxs, end, MOVE_NOMONSTERS, ent); //sB see above
trace = SV_Move (neworg, ent->v.mins, ent->v.maxs, end,MOVE_NOMONSTERS , ent);//blubsmove, 'false'
if (trace.allsolid)
{
return false;
}
if (trace.startsolid)
{
neworg[2] -= STEPSIZE;
trace = SV_Move (neworg, ent->v.mins, ent->v.maxs, end, MOVE_NOMONSTERS, ent); //sB
trace = SV_Move (neworg, ent->v.mins, ent->v.maxs, end,MOVE_NOMONSTERS , ent);//blubs edit, 'false'
if (trace.allsolid || trace.startsolid)
{
return false;
}
}
if (trace.fraction == 1)
{
@ -181,10 +185,8 @@ qboolean SV_movestep (edict_t *ent, vec3_t move, qboolean relink)
if (relink)
SV_LinkEdict (ent, true);
ent->v.flags = (int)ent->v.flags & ~FL_ONGROUND;
// Con_Printf ("fall down\n");
return true;
}
return false; // walked off an edge
}
@ -239,8 +241,8 @@ qboolean SV_StepDirection (edict_t *ent, float yaw, float dist)
PF_changeyaw();
yaw = yaw*M_PI*2 / 360;
move[0] = cos(yaw)*dist;
move[1] = sin(yaw)*dist;
move[0] = cosf(yaw)*dist;
move[1] = sinf(yaw)*dist;
move[2] = 0;
VectorCopy (ent->v.origin, oldorigin);
@ -362,6 +364,94 @@ void SV_NewChaseDir (edict_t *actor, edict_t *enemy, float dist)
if (!SV_CheckBottom (actor))
SV_FixCheckBottom (actor);
}
/*
================
SV_NewChaseDirO
================
*/
void SV_NewChaseDirO (edict_t *actor, vec3_t goal, float dist)
{
float deltax,deltay;
float d[3];
float tdir, olddir, turnaround;
olddir = anglemod( (int)(actor->v.ideal_yaw/45)*45 );
turnaround = anglemod(olddir - 180);
deltax = goal[0] - actor->v.origin[0];
deltay = goal[1] - actor->v.origin[1];
if (deltax>10)
d[1]= 0;
else if (deltax<-10)
d[1]= 180;
else
d[1]= DI_NODIR;
if (deltay<-10)
d[2]= 270;
else if (deltay>10)
d[2]= 90;
else
d[2]= DI_NODIR;
// try direct route
if (d[1] != DI_NODIR && d[2] != DI_NODIR)
{
if (d[1] == 0)
tdir = d[2] == 90 ? 45 : 315;
else
tdir = d[2] == 90 ? 135 : 215;
if (tdir != turnaround && SV_StepDirection(actor, tdir, dist))
return;
}
// try other directions
if ( ((rand()&3) & 1) || abs(deltay)>abs(deltax))
{
tdir=d[1];
d[1]=d[2];
d[2]=tdir;
}
if (d[1]!=DI_NODIR && d[1]!=turnaround
&& SV_StepDirection(actor, d[1], dist))
return;
if (d[2]!=DI_NODIR && d[2]!=turnaround
&& SV_StepDirection(actor, d[2], dist))
return;
/* there is no direct path to the player, so pick another direction */
if (olddir!=DI_NODIR && SV_StepDirection(actor, olddir, dist))
return;
if (rand()&1) /*randomly determine direction of search*/
{
for (tdir=0 ; tdir<=315 ; tdir += 45)
if (tdir!=turnaround && SV_StepDirection(actor, tdir, dist) )
return;
}
else
{
for (tdir=315 ; tdir >=0 ; tdir -= 45)
if (tdir!=turnaround && SV_StepDirection(actor, tdir, dist) )
return;
}
if (turnaround != DI_NODIR && SV_StepDirection(actor, turnaround, dist) )
return;
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
if (!SV_CheckBottom (actor))
SV_FixCheckBottom (actor);
}
/*
@ -384,6 +474,26 @@ qboolean SV_CloseEnough (edict_t *ent, edict_t *goal, float dist)
return true;
}
/*
======================
SV_CloseEnough
======================
*/
qboolean SV_CloseEnoughO (edict_t *ent, vec3_t goal, float dist)
{
int i;
for (i=0 ; i<3 ; i++)
{
if (goal[i] > ent->v.absmax[i] + dist)
return false;
if (goal[i] < ent->v.absmin[i] - dist)
return false;
}
return true;
}
/*
======================
SV_MoveToGoal
@ -392,15 +502,14 @@ SV_MoveToGoal
*/
void SV_MoveToGoal (void)
{
edict_t *ent, *goal;
edict_t *ent;
float dist;
#ifdef QUAKE2
edict_t *enemy;
#endif
float *goal;
ent = PROG_TO_EDICT(pr_global_struct->self);
goal = PROG_TO_EDICT(ent->v.goalentity);
dist = G_FLOAT(OFS_PARM0);
goal = G_VECTOR(OFS_PARM1);
if ( !( (int)ent->v.flags & (FL_ONGROUND|FL_FLY|FL_SWIM) ) )
{
@ -409,20 +518,13 @@ void SV_MoveToGoal (void)
}
// if the next step hits the enemy, return immediately
#ifdef QUAKE2
enemy = PROG_TO_EDICT(ent->v.enemy);
if (enemy != sv.edicts && SV_CloseEnough (ent, enemy, dist) )
#else
if ( PROG_TO_EDICT(ent->v.enemy) != sv.edicts && SV_CloseEnough (ent, goal, dist) )
#endif
if ( PROG_TO_EDICT(ent->v.enemy) != sv.edicts && SV_CloseEnoughO (ent, goal, dist) )
return;
// bump around...
if ( (rand()&3)==1 ||
!SV_StepDirection (ent, ent->v.ideal_yaw, dist))
{
SV_NewChaseDir (ent, goal, dist);
}
if ((rand()&3)==1 || !SV_StepDirection (ent, ent->v.ideal_yaw, dist))
SV_NewChaseDirO (ent, goal, dist);
}
/*
@ -455,3 +557,4 @@ void SV_MoveToOrigin (void)
SV_NewChaseDir (ent, goal, dist);
}

View file

@ -45,10 +45,6 @@ cvar_t sv_gravity = {"sv_gravity","800",false,true};
cvar_t sv_maxvelocity = {"sv_maxvelocity","100000"};
cvar_t sv_nostep = {"sv_nostep","0"};
#ifdef QUAKE2
static vec3_t vec_origin = {0.0, 0.0, 0.0};
#endif
#define MOVE_EPSILON 0.01
void SV_Physics_Toss (edict_t *ent);
@ -71,9 +67,7 @@ void SV_CheckAllEnts (void)
continue;
if (check->v.movetype == MOVETYPE_PUSH
|| check->v.movetype == MOVETYPE_NONE
#ifdef QUAKE2
|| check->v.movetype == MOVETYPE_FOLLOW
#endif
|| check->v.movetype == MOVETYPE_NOCLIP)
continue;
@ -372,20 +366,13 @@ void SV_AddGravity (edict_t *ent)
{
float ent_gravity;
#ifdef QUAKE2
if (ent->v.gravity)
ent_gravity = ent->v.gravity;
else
ent_gravity = 1.0;
#else
eval_t *val;
val = GetEdictFieldValue(ent, "gravity");
val = GETEDICTFIELDVALUE(ent, eval_gravity);
if (val && val->_float)
ent_gravity = val->_float;
else
ent_gravity = 1.0;
#endif
ent->v.velocity[2] -= ent_gravity * sv_gravity.value * host_frametime;
}
@ -398,6 +385,23 @@ PUSHMOVE
===============================================================================
*/
/*
============
SV_AllowPushRotate
Allows to change entity yaw?
============
*/
qboolean SV_AllowPushRotate( edict_t *ent )
{
model_t *mod;
mod = sv.models[ (int)ent->v.modelindex ];
if(!mod || mod->type != mod_brush)
return true;
return /*(mod->flags & MODEL_HAS_ORIGIN) ? true :*/ false;
}
/*
============
SV_PushEntity
@ -405,7 +409,7 @@ SV_PushEntity
Does not change the entities velocity at all
============
*/
trace_t SV_PushEntity (edict_t *ent, vec3_t push)
trace_t SV_PushEntity (edict_t *ent, vec3_t push, vec3_t apush)
{
trace_t trace;
vec3_t end;
@ -420,7 +424,21 @@ trace_t SV_PushEntity (edict_t *ent, vec3_t push)
else
trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, end, MOVE_NORMAL, ent);
VectorCopy (trace.endpos, ent->v.origin);
if( trace.fraction != 0.0f )
{
VectorCopy( trace.endpos, ent->v.origin );
if( apush[YAW] && ( (int)ent->v.flags & FL_CLIENT ))
{
ent->v.avelocity[1] += apush[1];
ent->v.fixangle = 2;
}
// don't rotate pushables!
if( SV_AllowPushRotate( ent ))
ent->v.angles[YAW] += trace.fraction * apush[YAW];
}
SV_LinkEdict (ent, true);
if (trace.ent)
@ -436,23 +454,23 @@ SV_PushMove
============
*/
void SV_PushMove (edict_t *pusher, float movetime)
edict_t *moved_edict[MAX_EDICTS];
vec3_t moved_from[MAX_EDICTS];
edict_t * SV_PushMove (edict_t *pusher, float movetime)
{
int i, e;
int i, e, oldsolid;
edict_t *check, *block;
vec3_t mins, maxs, move;
vec3_t entorig, pushorig;
int num_moved;
edict_t *moved_edict[MAX_EDICTS];
vec3_t moved_from[MAX_EDICTS];
if (!pusher->v.velocity[0] && !pusher->v.velocity[1] && !pusher->v.velocity[2])
{
pusher->v.ltime += movetime;
return;
return NULL;
}
for (i=0 ; i<3 ; i++)
for (i = 0; i < 3; i++)
{
move[i] = pusher->v.velocity[i] * movetime;
mins[i] = pusher->v.absmin[i] + move[i];
@ -461,48 +479,50 @@ void SV_PushMove (edict_t *pusher, float movetime)
VectorCopy (pusher->v.origin, pushorig);
// move the pusher to it's final position
// move the pusher to it's final position
VectorAdd (pusher->v.origin, move, pusher->v.origin);
pusher->v.ltime += movetime;
SV_LinkEdict (pusher, false);
pusher->v.ltime += movetime;
oldsolid = pusher->v.solid;
// non-solid pushers can't push anything
if( pusher->v.solid == SOLID_NOT )
return NULL;
// see if any solid entities are inside the final position
num_moved = 0;
check = NEXT_EDICT(sv.edicts);
for (e=1 ; e<sv.num_edicts ; e++, check = NEXT_EDICT(check))
// see if any solid entities are inside the final position
num_moved = 0;
check = NEXT_EDICT (sv.edicts);
for (e = 1; e < sv.num_edicts; e++, check = NEXT_EDICT (check))
{
if (check->free)
continue;
if (check->v.movetype == MOVETYPE_PUSH
|| check->v.movetype == MOVETYPE_NONE
#ifdef QUAKE2
|| check->v.movetype == MOVETYPE_FOLLOW
#endif
|| check->v.movetype == MOVETYPE_NOCLIP)
|| check->v.movetype == MOVETYPE_NONE
|| check->v.movetype == MOVETYPE_NOCLIP)
continue;
// if the entity is standing on the pusher, it will definately be moved
if ( ! ( ((int)check->v.flags & FL_ONGROUND)
&& PROG_TO_EDICT(check->v.groundentity) == pusher) )
// if the entity is standing on the pusher, it will definately be moved
if (!(((int) check->v.flags & FL_ONGROUND)
&& PROG_TO_EDICT (check->v.groundentity) == pusher))
{
if ( check->v.absmin[0] >= maxs[0]
|| check->v.absmin[1] >= maxs[1]
|| check->v.absmin[2] >= maxs[2]
|| check->v.absmax[0] <= mins[0]
|| check->v.absmax[1] <= mins[1]
|| check->v.absmax[2] <= mins[2] )
if (check->v.absmin[0] >= maxs[0]
|| check->v.absmin[1] >= maxs[1]
|| check->v.absmin[2] >= maxs[2]
|| check->v.absmax[0] <= mins[0]
|| check->v.absmax[1] <= mins[1]
|| check->v.absmax[2] <= mins[2])
continue;
// see if the ent's bbox is inside the pusher's final position
// see if the ent's bbox is inside the pusher's final position
if (!SV_TestEntityPosition (check))
continue;
}
// remove the onground flag for non-players
// remove the onground flag for non-players
if (check->v.movetype != MOVETYPE_WALK)
check->v.flags = (int)check->v.flags & ~FL_ONGROUND;
check->v.flags = (int) check->v.flags & ~FL_ONGROUND;
VectorCopy (check->v.origin, entorig);
VectorCopy (check->v.origin, moved_from[num_moved]);
@ -511,17 +531,21 @@ void SV_PushMove (edict_t *pusher, float movetime)
// try moving the contacted entity
pusher->v.solid = SOLID_NOT;
SV_PushEntity (check, move);
pusher->v.solid = SOLID_BSP;
SV_PushEntity (check, move, vec3_origin);
pusher->v.solid = oldsolid;
// if it is still inside the pusher, block
// if it is still inside the pusher, block
block = SV_TestEntityPosition (check);
if (block)
{ // fail the move
{
// fail the move
if (check->v.mins[0] == check->v.maxs[0])
continue;
if (check->v.solid == SOLID_NOT || check->v.solid == SOLID_TRIGGER)
{ // corpse
{
// corpse
check->v.mins[0] = check->v.mins[1] = 0;
VectorCopy (check->v.mins, check->v.maxs);
continue;
@ -538,123 +562,137 @@ void SV_PushMove (edict_t *pusher, float movetime)
// otherwise, just stay in place until the obstacle is gone
if (pusher->v.blocked)
{
pr_global_struct->self = EDICT_TO_PROG(pusher);
pr_global_struct->other = EDICT_TO_PROG(check);
pr_global_struct->self = EDICT_TO_PROG (pusher);
pr_global_struct->other = EDICT_TO_PROG (check);
PR_ExecuteProgram (pusher->v.blocked);
}
// move back any entities we already moved
for (i=0 ; i<num_moved ; i++)
// move back any entities we already moved
for (i = 0; i < num_moved; i++)
{
VectorCopy (moved_from[i], moved_edict[i]->v.origin);
SV_LinkEdict (moved_edict[i], false);
SV_LinkEdict (moved_edict[i], (moved_edict[i] == check) ? true : false);
}
return;
return check;
}
}
return NULL;
}
#ifdef QUAKE2
/*
============
SV_PushRotate
============
*/
void SV_PushRotate (edict_t *pusher, float movetime)
edict_t * SV_PushRotate (edict_t *pusher, float movetime)
{
int i, e;
edict_t *check, *block;
vec3_t move, a, amove;
vec3_t entorig, pushorig;
int num_moved;
edict_t *moved_edict[MAX_EDICTS];
vec3_t moved_from[MAX_EDICTS];
vec3_t org, org2;
vec3_t forward, right, up;
int i, e, oldsolid;
matrix4x4 start_l, end_l;;
edict_t *check, *block;
vec3_t move, amove;
vec3_t entorig, pushorig;
int num_moved;
vec3_t org, org2, temp;
if (!pusher->v.avelocity[0] && !pusher->v.avelocity[1] && !pusher->v.avelocity[2])
{
pusher->v.ltime += movetime;
return;
return NULL;
}
for (i=0 ; i<3 ; i++)
for (i = 0; i < 3; i++)
amove[i] = pusher->v.avelocity[i] * movetime;
VectorSubtract (vec3_origin, amove, a);
AngleVectors (a, forward, right, up);
// create pusher initial position
Matrix4x4_CreateFromEntity( start_l, pusher->v.angles, pusher->v.origin, 1.0f );
VectorCopy (pusher->v.angles, pushorig);
// move the pusher to it's final position
// move the pusher to it's final position
VectorAdd (pusher->v.angles, amove, pusher->v.angles);
pusher->v.ltime += movetime;
SV_LinkEdict (pusher, false);
oldsolid = pusher->v.solid;
// non-solid pushers can't push anything
if( pusher->v.solid == SOLID_NOT )
return NULL;
// see if any solid entities are inside the final position
num_moved = 0;
check = NEXT_EDICT(sv.edicts);
for (e=1 ; e<sv.num_edicts ; e++, check = NEXT_EDICT(check))
// create pusher final position
Matrix4x4_CreateFromEntity( end_l, pusher->v.angles, pusher->v.origin, 1.0f );
// see if any solid entities are inside the final position
num_moved = 0;
check = NEXT_EDICT (sv.edicts);
for (e = 1; e < sv.num_edicts; e++, check = NEXT_EDICT (check))
{
if (check->free)
continue;
if (check->v.movetype == MOVETYPE_PUSH
|| check->v.movetype == MOVETYPE_NONE
|| check->v.movetype == MOVETYPE_FOLLOW
|| check->v.movetype == MOVETYPE_NOCLIP)
continue;
// if the entity is standing on the pusher, it will definately be moved
if ( ! ( ((int)check->v.flags & FL_ONGROUND)
&& PROG_TO_EDICT(check->v.groundentity) == pusher) )
// if the entity is standing on the pusher, it will definately be moved
if (!(((int) check->v.flags & FL_ONGROUND) && PROG_TO_EDICT (check->v.groundentity) == pusher))
{
if ( check->v.absmin[0] >= pusher->v.absmax[0]
|| check->v.absmin[1] >= pusher->v.absmax[1]
|| check->v.absmin[2] >= pusher->v.absmax[2]
|| check->v.absmax[0] <= pusher->v.absmin[0]
|| check->v.absmax[1] <= pusher->v.absmin[1]
|| check->v.absmax[2] <= pusher->v.absmin[2] )
if (check->v.absmin[0] >= pusher->v.absmax[0]
|| check->v.absmin[1] >= pusher->v.absmax[1]
|| check->v.absmin[2] >= pusher->v.absmax[2]
|| check->v.absmax[0] <= pusher->v.absmin[0]
|| check->v.absmax[1] <= pusher->v.absmin[1]
|| check->v.absmax[2] <= pusher->v.absmin[2])
continue;
// see if the ent's bbox is inside the pusher's final position
// see if the ent's bbox is inside the pusher's final position
if (!SV_TestEntityPosition (check))
continue;
}
// remove the onground flag for non-players
// remove the onground flag for non-players
if (check->v.movetype != MOVETYPE_WALK)
check->v.flags = (int)check->v.flags & ~FL_ONGROUND;
check->v.flags = (int) check->v.flags & ~FL_ONGROUND;
VectorCopy (check->v.origin, entorig);
VectorCopy (check->v.origin, moved_from[num_moved]);
moved_edict[num_moved] = check;
num_moved++;
// calculate destination position
VectorSubtract (check->v.origin, pusher->v.origin, org);
org2[0] = DotProduct (org, forward);
org2[1] = -DotProduct (org, right);
org2[2] = DotProduct (org, up);
VectorSubtract (org2, org, move);
//if( check->v.movetype == MOVETYPE_PUSHSTEP )
// VectorAverage( check->v.absmin, check->v.absmax, org );
//else
VectorCopy( check->v.origin, org );
Matrix4x4_VectorITransform( start_l, org, temp );
Matrix4x4_VectorTransform( end_l, temp, org2 );
VectorSubtract( org2, org, move );
// try moving the contacted entity
pusher->v.solid = SOLID_NOT;
SV_PushEntity (check, move);
pusher->v.solid = SOLID_BSP;
SV_PushEntity (check, move, amove);
pusher->v.solid = oldsolid;
// if it is still inside the pusher, block
// if it is still inside the pusher, block
block = SV_TestEntityPosition (check);
if (block)
{ // fail the move
{
// fail the move
if (check->v.mins[0] == check->v.maxs[0])
continue;
if (check->v.solid == SOLID_NOT || check->v.solid == SOLID_TRIGGER)
{ // corpse
{
// corpse
check->v.mins[0] = check->v.mins[1] = 0;
VectorCopy (check->v.mins, check->v.maxs);
continue;
@ -671,29 +709,29 @@ void SV_PushRotate (edict_t *pusher, float movetime)
// otherwise, just stay in place until the obstacle is gone
if (pusher->v.blocked)
{
pr_global_struct->self = EDICT_TO_PROG(pusher);
pr_global_struct->other = EDICT_TO_PROG(check);
pr_global_struct->self = EDICT_TO_PROG (pusher);
pr_global_struct->other = EDICT_TO_PROG (check);
PR_ExecuteProgram (pusher->v.blocked);
}
// move back any entities we already moved
for (i=0 ; i<num_moved ; i++)
// move back any entities we already moved
for (i = 0; i < num_moved; i++)
{
VectorCopy (moved_from[i], moved_edict[i]->v.origin);
VectorSubtract (moved_edict[i]->v.angles, amove, moved_edict[i]->v.angles);
SV_LinkEdict (moved_edict[i], false);
SV_LinkEdict (moved_edict[i], (moved_edict[i] == check) ? true : false);
}
return;
return check;
}
else
{
VectorAdd (check->v.angles, amove, check->v.angles);
}
}
return NULL;
}
#endif
/*
================
@ -719,15 +757,14 @@ void SV_Physics_Pusher (edict_t *ent)
else
movetime = host_frametime;
if (movetime)
{
#ifdef QUAKE2
if (ent->v.avelocity[0] || ent->v.avelocity[1] || ent->v.avelocity[2])
SV_PushRotate (ent, movetime);
else
#endif
SV_PushMove (ent, movetime); // advances ent->v.ltime if not blocked
}
if (ent->v.avelocity[0] || ent->v.avelocity[1] || ent->v.avelocity[2])
SV_PushRotate (ent, host_frametime);
if (movetime)
SV_PushMove (ent, movetime); // advances ent->v.ltime if not blocked
if (thinktime > oldltime && thinktime <= ent->v.ltime)
{
@ -809,9 +846,6 @@ qboolean SV_CheckWater (edict_t *ent)
{
vec3_t point;
int cont;
#ifdef QUAKE2
int truecont;
#endif
point[0] = ent->v.origin[0];
point[1] = ent->v.origin[1];
@ -822,9 +856,6 @@ qboolean SV_CheckWater (edict_t *ent)
cont = SV_PointContents (point);
if (cont <= CONTENTS_WATER)
{
#ifdef QUAKE2
truecont = SV_TruePointContents (point);
#endif
ent->v.watertype = cont;
ent->v.waterlevel = 1;
point[2] = ent->v.origin[2] + (ent->v.mins[2] + ent->v.maxs[2])*0.5;
@ -837,22 +868,6 @@ qboolean SV_CheckWater (edict_t *ent)
if (cont <= CONTENTS_WATER)
ent->v.waterlevel = 3;
}
#ifdef QUAKE2
if (truecont <= CONTENTS_CURRENT_0 && truecont >= CONTENTS_CURRENT_DOWN)
{
static vec3_t current_table[] =
{
{1, 0, 0},
{0, 1, 0},
{-1, 0, 0},
{0, -1, 0},
{0, 0, 1},
{0, 0, -1}
};
VectorMA (ent->v.basevelocity, 150.0*ent->v.waterlevel/3.0, current_table[CONTENTS_CURRENT_0 - truecont], ent->v.basevelocity);
}
#endif
}
return ent->v.waterlevel > 1;
@ -924,7 +939,7 @@ int SV_TryUnstick (edict_t *ent, vec3_t oldvel)
case 7: dir[0] = -2; dir[1] = -2; break;
}
SV_PushEntity (ent, dir);
SV_PushEntity (ent, dir, vec3_origin);
// retry the original move
ent->v.velocity[0] = oldvel[0];
@ -932,8 +947,8 @@ int SV_TryUnstick (edict_t *ent, vec3_t oldvel)
ent->v. velocity[2] = 0;
clip = SV_FlyMove (ent, 0.1, &steptrace);
if ( fabs(oldorg[1] - ent->v.origin[1]) > 4
|| fabs(oldorg[0] - ent->v.origin[0]) > 4 )
if ( fabsf(oldorg[1] - ent->v.origin[1]) > 4
|| fabsf(oldorg[0] - ent->v.origin[0]) > 4 )
{
//Con_DPrintf ("unstuck!\n");
return clip;
@ -1004,7 +1019,7 @@ void SV_WalkMove (edict_t *ent)
downmove[2] = -STEPSIZE + oldvel[2]*host_frametime;
// move up
SV_PushEntity (ent, upmove); // FIXME: don't link?
SV_PushEntity (ent, upmove, vec3_origin); // FIXME: don't link?
// move forward
ent->v.velocity[0] = oldvel[0];
@ -1016,8 +1031,8 @@ void SV_WalkMove (edict_t *ent)
// in the clipping hulls
if (clip)
{
if ( fabs(oldorg[1] - ent->v.origin[1]) < 0.03125
&& fabs(oldorg[0] - ent->v.origin[0]) < 0.03125 )
if ( fabsf(oldorg[1] - ent->v.origin[1]) < 0.03125
&& fabsf(oldorg[0] - ent->v.origin[0]) < 0.03125 )
{ // stepping up didn't make any progress
clip = SV_TryUnstick (ent, oldvel);
}
@ -1028,7 +1043,7 @@ void SV_WalkMove (edict_t *ent)
SV_WallFriction (ent, &steptrace);
// move down
downtrace = SV_PushEntity (ent, downmove); // FIXME: don't link?
downtrace = SV_PushEntity (ent, downmove, vec3_origin); // FIXME: don't link?
if (downtrace.plane.normal[2] > 0.7)
{
@ -1208,16 +1223,15 @@ void SV_CheckStuck_IgnoreMonsters (edict_t *ent)
if (!SV_TestEntityPosition_NOMONSTERS(ent))
{
VectorCopy (ent->v.origin, ent->v.oldorigin);
//ent->v.zoom = 0; // naievil -- fixme
ent->v.zoom = 0;
return;
}
// naievil -- fixme
//if(ent->v.zoom == 1)//if used setorigin
//{
// VectorCopy (ent->v.origin, ent->v.oldorigin);
// return;//we don't care to adjust for stuckness, whoever used setorigin in qc better handle that
//}
if(ent->v.zoom == 1)//if used setorigin
{
VectorCopy (ent->v.origin, ent->v.oldorigin);
return;//we don't care to adjust for stuckness, whoever used setorigin in qc better handle that
}
VectorCopy (ent->v.origin, org);
VectorCopy (ent->v.oldorigin, ent->v.origin);
if (!SV_TestEntityPosition_NOMONSTERS(ent))
@ -1254,7 +1268,7 @@ void SV_CheckStuck_IgnoreMonsters (edict_t *ent)
void SV_PushAwayZombies(edict_t *ent)
{
edict_t *other_ent;
float rad = 64;//approx. length of bbox corner
float rad = 23;//approx. length of bbox corner
float *org = ent->v.origin;
vec3_t eorg;
int i, j;
@ -1262,28 +1276,23 @@ void SV_PushAwayZombies(edict_t *ent)
other_ent = NEXT_EDICT(sv.edicts);
for (i=1 ; i<sv.num_edicts ; i++, ent = NEXT_EDICT(other_ent))
{
//if (other_ent->free)
//continue;
if (other_ent->free)
continue;
//if (ent->v.solid == SOLID_NOT)
// continue;
if( other_ent->v.solid != SOLID_CORPSE)
if( other_ent->v.solid != SOLID_SLIDEBOX)
continue;
if( other_ent->v.movetype != MOVETYPE_WALK)
continue;
for (j=0 ; j<3 ; j++)
eorg[j] = org[j] - (other_ent->v.origin[j] + (other_ent->v.mins[j] + other_ent->v.maxs[j])*0.5);
if (Length(eorg) > rad)
{
Con_Printf ("Length Greater than bbox corner. \n");
continue;
}
//Process nearby zombie
for(j = 0; j < 2; j++)//only x & y
{
Con_Printf ("Pushing Zombie \n");
other_ent->v.velocity[j] += (other_ent->v.origin[j] - ent->v.origin[j]) * 0.01;//push away other zombie was 0.001
other_ent->v.velocity[j] += (other_ent->v.origin[j] - ent->v.origin[j]) * 0.001;//push away other zombie
//ent->v.velocity[j] += (ent->v.origin[j] - other_ent->v.origin[j]) * 0.01;//push away self
}
}
}
//=============================
@ -1304,7 +1313,7 @@ void SV_Physics_Walk(edict_t *ent)
VectorCopy(ent->v.mins,old_mins);
VectorCopy(ent->v.maxs,old_maxs);
//'-16,-16,-32', '16,16,40' sB reenabled PushAwayZombies
//'-16,-16,-32', '16,16,40'
ent->v.mins[0] = -16; ent->v.mins[1] = -16; ent->v.mins[2] = -32;
ent->v.maxs[0] = 16; ent->v.maxs[1] = 16; ent->v.maxs[2] = 40;
@ -1354,6 +1363,7 @@ void SV_Physics_Walk(edict_t *ent)
SV_LinkEdict(ent,true);
}
/*
================
SV_Physics_Client
@ -1394,14 +1404,8 @@ void SV_Physics_Client (edict_t *ent, int num)
if (!SV_CheckWater (ent) && ! ((int)ent->v.flags & FL_WATERJUMP) )
SV_AddGravity (ent);
SV_CheckStuck (ent);
#ifdef QUAKE2
VectorAdd (ent->v.velocity, ent->v.basevelocity, ent->v.velocity);
#endif
SV_WalkMove (ent);
#ifdef QUAKE2
VectorSubtract (ent->v.velocity, ent->v.basevelocity, ent->v.velocity);
#endif
break;
case MOVETYPE_TOSS:
@ -1428,6 +1432,7 @@ void SV_Physics_Client (edict_t *ent, int num)
//
// call standard player post-think
//
SV_LinkEdict (ent, true);
pr_global_struct->time = sv.time;
@ -1450,6 +1455,7 @@ void SV_Physics_None (edict_t *ent)
SV_RunThink (ent);
}
/*
=============
SV_Physics_Follow
@ -1501,16 +1507,7 @@ SV_CheckWaterTransition
void SV_CheckWaterTransition (edict_t *ent)
{
int cont;
#ifdef QUAKE2
vec3_t point;
point[0] = ent->v.origin[0];
point[1] = ent->v.origin[1];
point[2] = ent->v.origin[2] + ent->v.mins[2] + 1;
cont = SV_PointContents (point);
#else
cont = SV_PointContents (ent->v.origin);
#endif
if (!ent->v.watertype)
{ // just spawned here
ent->v.watertype = cont;
@ -1520,19 +1517,19 @@ void SV_CheckWaterTransition (edict_t *ent)
if (cont <= CONTENTS_WATER)
{
if (ent->v.watertype == CONTENTS_EMPTY)
/*if (ent->v.watertype == CONTENTS_EMPTY)
{ // just crossed into water
//SV_StartSound (ent, 0, "misc/h2ohit1.wav", 255, 1);
}
SV_StartSound (ent, 0, "misc/h2ohit1.wav", 255, 1);
} */
ent->v.watertype = cont;
ent->v.waterlevel = 1;
}
else
{
{/*
if (ent->v.watertype != CONTENTS_EMPTY)
{ // just crossed into water
//SV_StartSound (ent, 0, "misc/h2ohit1.wav", 255, 1);
}
SV_StartSound (ent, 0, "misc/h2ohit1.wav", 255, 1);
} */
ent->v.watertype = CONTENTS_EMPTY;
ent->v.waterlevel = cont;
}
@ -1550,9 +1547,9 @@ void SV_Physics_Toss (edict_t *ent)
trace_t trace;
vec3_t move;
float backoff;
#ifdef QUAKE2
edict_t *groundentity;
groundentity = PROG_TO_EDICT(ent->v.groundentity);
if ((int)groundentity->v.flags & FL_CONVEYOR)
VectorScale(groundentity->v.movedir, groundentity->v.speed, ent->v.basevelocity);
@ -1560,6 +1557,7 @@ void SV_Physics_Toss (edict_t *ent)
VectorCopy(vec_origin, ent->v.basevelocity);
SV_CheckWater (ent);
#endif
// regular thinking
if (!SV_RunThink (ent))
return;
@ -1603,7 +1601,7 @@ void SV_Physics_Toss (edict_t *ent)
VectorAdd (ent->v.velocity, ent->v.basevelocity, ent->v.velocity);
#endif
VectorScale (ent->v.velocity, host_frametime, move);
trace = SV_PushEntity (ent, move);
trace = SV_PushEntity (ent, move, vec3_origin);
#ifdef QUAKE2
VectorSubtract (ent->v.velocity, ent->v.basevelocity, ent->v.velocity);
#endif
@ -1643,6 +1641,7 @@ void SV_Physics_Toss (edict_t *ent)
SV_CheckWaterTransition (ent);
}
/*
===============================================================================
@ -1662,107 +1661,7 @@ This is also used for objects that have become still on the ground, but
will fall if the floor is pulled out from under them.
=============
*/
#ifdef QUAKE2
void SV_Physics_Step (edict_t *ent)
{
qboolean wasonground;
qboolean inwater;
qboolean hitsound = false;
float *vel;
float speed, newspeed, control;
float friction;
edict_t *groundentity;
groundentity = PROG_TO_EDICT(ent->v.groundentity);
if ((int)groundentity->v.flags & FL_CONVEYOR)
VectorScale(groundentity->v.movedir, groundentity->v.speed, ent->v.basevelocity);
else
VectorCopy(vec_origin, ent->v.basevelocity);
//@@
pr_global_struct->time = sv.time;
pr_global_struct->self = EDICT_TO_PROG(ent);
PF_WaterMove();
SV_CheckVelocity (ent);
wasonground = (int)ent->v.flags & FL_ONGROUND;
// ent->v.flags = (int)ent->v.flags & ~FL_ONGROUND;
// add gravity except:
// flying monsters
// swimming monsters who are in the water
inwater = SV_CheckWater(ent);
if (! wasonground)
if (!((int)ent->v.flags & FL_FLY))
if (!(((int)ent->v.flags & FL_SWIM) && (ent->v.waterlevel > 0)))
{
if (ent->v.velocity[2] < sv_gravity.value*-0.1)
hitsound = true;
if (!inwater)
SV_AddGravity (ent);
}
if (!VectorCompare(ent->v.velocity, vec_origin) || !VectorCompare(ent->v.basevelocity, vec_origin))
{
ent->v.flags = (int)ent->v.flags & ~FL_ONGROUND;
// apply friction
// let dead monsters who aren't completely onground slide
if (wasonground)
if (!(ent->v.health <= 0.0 && !SV_CheckBottom(ent)))
{
vel = ent->v.velocity;
speed = sqrt(vel[0]*vel[0] +vel[1]*vel[1]);
if (speed)
{
friction = sv_friction.value;
control = speed < sv_stopspeed.value ? sv_stopspeed.value : speed;
newspeed = speed - host_frametime*control*friction;
if (newspeed < 0)
newspeed = 0;
newspeed /= speed;
vel[0] = vel[0] * newspeed;
vel[1] = vel[1] * newspeed;
}
}
VectorAdd (ent->v.velocity, ent->v.basevelocity, ent->v.velocity);
SV_FlyMove (ent, host_frametime, NULL);
VectorSubtract (ent->v.velocity, ent->v.basevelocity, ent->v.velocity);
// determine if it's on solid ground at all
{
vec3_t mins, maxs, point;
int x, y;
VectorAdd (ent->v.origin, ent->v.mins, mins);
VectorAdd (ent->v.origin, ent->v.maxs, maxs);
point[2] = mins[2] - 1;
for (x=0 ; x<=1 ; x++)
for (y=0 ; y<=1 ; y++)
{
point[0] = x ? maxs[0] : mins[0];
point[1] = y ? maxs[1] : mins[1];
if (SV_PointContents (point) == CONTENTS_SOLID)
{
ent->v.flags = (int)ent->v.flags | FL_ONGROUND;
break;
}
}
}
SV_LinkEdict (ent, true);
}
// regular thinking
SV_RunThink (ent);
SV_CheckWaterTransition (ent);
}
#else
void SV_Physics_Step (edict_t *ent)
{
qboolean hitsound;
@ -1779,6 +1678,12 @@ void SV_Physics_Step (edict_t *ent)
SV_CheckVelocity (ent);
SV_FlyMove (ent, host_frametime, NULL);
SV_LinkEdict (ent, true);
/*if ( (int)ent->v.flags & FL_ONGROUND ) // just hit ground
{
if (hitsound)
SV_StartSound (ent, 0, "demon/dland2.wav", 255, 1);
}*/
}
// regular thinking
@ -1786,7 +1691,6 @@ void SV_Physics_Step (edict_t *ent)
SV_CheckWaterTransition (ent);
}
#endif
//============================================================================
@ -1820,9 +1724,8 @@ void SV_Physics (void)
if (pr_global_struct->force_retouch)
{
SV_LinkEdict (ent, true); // force retouch even for stationary
SV_LinkEdict (ent, true);// force retouch even for stationary
}
if (i > 0 && i <= svs.maxclients)
SV_Physics_Client (ent, i);
else if (ent->v.movetype == MOVETYPE_PUSH)
@ -1863,23 +1766,17 @@ void SV_Physics (void)
sv.time += host_frametime;
}
#ifdef QUAKE2
trace_t SV_Trace_Toss (edict_t *ent, edict_t *ignore)
{
double save_frametime;
vec3_t move, end;
edict_t tempent, *tent;
trace_t trace;
vec3_t move;
vec3_t end;
double save_frametime;
// extern particle_t *active_particles, *free_particles;
// particle_t *p;
save_frametime = host_frametime;
host_frametime = 0.05;
memcpy(&tempent, ent, sizeof(edict_t));
memcpy_vfpu(&tempent, ent, sizeof(edict_t));
tent = &tempent;
while (1)
@ -1892,26 +1789,11 @@ trace_t SV_Trace_Toss (edict_t *ent, edict_t *ignore)
trace = SV_Move (tent->v.origin, tent->v.mins, tent->v.maxs, end, MOVE_NORMAL, tent);
VectorCopy (trace.endpos, tent->v.origin);
// p = free_particles;
// if (p)
// {
// free_particles = p->next;
// p->next = active_particles;
// active_particles = p;
//
// p->die = 256;
// p->color = 15;
// p->type = pt_static;
// VectorCopy (vec3_origin, p->vel);
// VectorCopy (tent->v.origin, p->org);
// }
if (trace.ent)
if (trace.ent != ignore)
break;
}
// p->color = 224;
host_frametime = save_frametime;
return trace;
}
#endif

View file

@ -63,8 +63,8 @@ void SV_SetIdealPitch (void)
return;
angleval = sv_player->v.angles[YAW] * M_PI*2 / 360;
sinval = sin(angleval);
cosval = cos(angleval);
sinval = sinf(angleval);
cosval = cosf(angleval);
for (i=0 ; i<MAX_FORWARD ; i++)
{
@ -129,7 +129,7 @@ void SV_UserFriction (void)
vel = velocity;
speed = sqrt(vel[0]*vel[0] +vel[1]*vel[1]);
speed = sqrtf(vel[0]*vel[0] +vel[1]*vel[1]);
if (!speed)
return;
@ -232,7 +232,7 @@ void DropPunchAngle (void)
len = VectorNormalize (sv_player->v.punchangle);
len -= 10*host_frametime;
len -= 20*host_frametime;
if (len < 0)
len = 0;
VectorScale (sv_player->v.punchangle, len, sv_player->v.punchangle);
@ -358,7 +358,7 @@ void SV_AirMove (void)
{ // noclip
VectorCopy (wishvel, velocity);
}
else if ( (int)sv_player->v.flags & FL_ONGROUND )
else if ( onground )
{
SV_UserFriction ();
SV_Accelerate ();
@ -384,7 +384,10 @@ void SV_ClientThink (void)
if (sv_player->v.movetype == MOVETYPE_NONE)
return;
onground = (int)sv_player->v.flags & FL_ONGROUND;
if ((int)sv_player->v.flags & FL_ONGROUND)
onground = qtrue;
else
onground = qfalse;
origin = sv_player->v.origin;
velocity = sv_player->v.velocity;
@ -448,7 +451,7 @@ void SV_ReadClientMove (usercmd_t *move)
// read current angles
for (i=0 ; i<3 ; i++)
angle[i] = MSG_ReadAngle ();
angle[i] = MSG_ReadFloat ();
VectorCopy (angle, host_client->edict->v.v_angle);
@ -472,11 +475,6 @@ void SV_ReadClientMove (usercmd_t *move)
i = MSG_ReadByte ();
if (i)
host_client->edict->v.impulse = i;
#ifdef QUAKE2
// read light level
host_client->edict->v.light_level = MSG_ReadByte ();
#endif
}
/*