2004-08-23 00:15:46 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
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.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
// sv_move.c -- monster movement
|
|
|
|
|
2009-11-17 00:15:44 +00:00
|
|
|
#include "quakedef.h"
|
|
|
|
#include "pr_common.h"
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2009-11-17 00:15:44 +00:00
|
|
|
#if defined(CSQC_DAT) || !defined(CLIENTONLY)
|
2004-08-23 00:15:46 +00:00
|
|
|
/*
|
|
|
|
=============
|
|
|
|
SV_CheckBottom
|
|
|
|
|
|
|
|
Returns false if any part of the bottom of the entity is off an edge that
|
|
|
|
is not a staircase.
|
|
|
|
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
int c_yes, c_no;
|
|
|
|
|
2014-06-21 17:58:17 +00:00
|
|
|
hull_t *Q1BSP_ChooseHull(model_t *model, int hullnum, vec3_t mins, vec3_t maxs, vec3_t offset);
|
|
|
|
|
|
|
|
//this function is axial. major axis determines ground. if it switches slightly, a new axis may become the ground...
|
|
|
|
qboolean World_CheckBottom (world_t *world, wedict_t *ent, vec3_t up)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
int savedhull;
|
|
|
|
vec3_t mins, maxs, start, stop;
|
|
|
|
trace_t trace;
|
|
|
|
int x, y;
|
2014-06-21 17:58:17 +00:00
|
|
|
float mid;
|
|
|
|
|
|
|
|
int a0,a1,a2; //logical x, y, z
|
|
|
|
int sign;
|
|
|
|
|
|
|
|
mins[0] = fabs(up[0]);
|
|
|
|
mins[1] = fabs(up[1]);
|
|
|
|
mins[2] = fabs(up[2]);
|
|
|
|
if (mins[2] > mins[0] && mins[2] > mins[1])
|
|
|
|
{
|
|
|
|
a0 = 0;
|
|
|
|
a1 = 1;
|
|
|
|
a2 = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a2 = mins[1] > mins[0];
|
|
|
|
a0 = 1 - a2;
|
|
|
|
a1 = 2;
|
|
|
|
}
|
|
|
|
sign = (up[a2]>0)?1:-1;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
VectorAdd (ent->v->origin, ent->v->mins, mins);
|
2014-06-21 17:58:17 +00:00
|
|
|
if (world->worldmodel->fromgame == fg_quake)
|
|
|
|
{
|
|
|
|
//quake's hulls are weird. sizes are defined as from mins to mins+hullsize. the actual maxs is ignored other than for its size.
|
|
|
|
hull_t *hull;
|
|
|
|
hull = Q1BSP_ChooseHull(world->worldmodel, ent->xv->hull, ent->v->mins, ent->v->maxs, start);
|
|
|
|
VectorAdd (mins, start, mins);
|
|
|
|
VectorSubtract (mins, hull->clip_mins, maxs);
|
|
|
|
VectorAdd (maxs, hull->clip_maxs, maxs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
VectorAdd (ent->v->origin, ent->v->maxs, maxs);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
// if all of the points under the corners are solid world, don't bother
|
|
|
|
// with the tougher checks
|
|
|
|
// the corners must be within 16 of the midpoint
|
2014-06-21 17:58:17 +00:00
|
|
|
start[a2] = (sign<0)?maxs[a2]:mins[a2] - sign;
|
2004-08-23 00:15:46 +00:00
|
|
|
for (x=0 ; x<=1 ; x++)
|
|
|
|
for (y=0 ; y<=1 ; y++)
|
|
|
|
{
|
2014-06-21 17:58:17 +00:00
|
|
|
start[a0] = x ? maxs[a0] : mins[a0];
|
|
|
|
start[a1] = y ? maxs[a1] : mins[a1];
|
2009-11-17 00:15:44 +00:00
|
|
|
if (!(World_PointContents (world, start) & FTECONTENTS_SOLID))
|
2004-08-23 00:15:46 +00:00
|
|
|
goto realcheck;
|
|
|
|
}
|
|
|
|
|
|
|
|
c_yes++;
|
|
|
|
return true; // we got out easy
|
|
|
|
|
|
|
|
realcheck:
|
|
|
|
c_no++;
|
|
|
|
//
|
|
|
|
// check it for real...
|
|
|
|
//
|
2014-06-21 17:58:17 +00:00
|
|
|
start[a2] = (sign<0)?maxs[a2]:mins[a2];
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
// the midpoint must be within 16 of the bottom
|
2014-06-21 17:58:17 +00:00
|
|
|
start[a0] = stop[a0] = (mins[a0] + maxs[a0])*0.5;
|
|
|
|
start[a1] = stop[a1] = (mins[a1] + maxs[a1])*0.5;
|
|
|
|
stop[a2] = start[a2] - 2*movevars.stepheight*sign;
|
2007-09-02 19:55:17 +00:00
|
|
|
savedhull = ent->xv->hull;
|
2014-04-12 03:31:59 +00:00
|
|
|
ent->xv->hull = 0; //stop the hull from breaking tracelines
|
2009-11-17 00:15:44 +00:00
|
|
|
trace = World_Move (world, start, vec3_origin, vec3_origin, stop, true, ent);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
if (trace.fraction == 1.0)
|
2014-04-12 03:31:59 +00:00
|
|
|
{
|
|
|
|
ent->xv->hull = savedhull;
|
2004-08-23 00:15:46 +00:00
|
|
|
return false;
|
2014-04-12 03:31:59 +00:00
|
|
|
}
|
2014-06-21 17:58:17 +00:00
|
|
|
mid = trace.endpos[2];
|
|
|
|
|
|
|
|
mid = (mid-start[a2]-(movevars.stepheight*sign)) / (stop[a2]-start[a2]);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
// the corners must be within 16 of the midpoint
|
|
|
|
for (x=0 ; x<=1 ; x++)
|
|
|
|
for (y=0 ; y<=1 ; y++)
|
|
|
|
{
|
2014-06-21 17:58:17 +00:00
|
|
|
start[a0] = stop[a0] = x ? maxs[a0] : mins[a0];
|
|
|
|
start[a1] = stop[a1] = y ? maxs[a1] : mins[a1];
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2009-11-17 00:15:44 +00:00
|
|
|
trace = World_Move (world, start, vec3_origin, vec3_origin, stop, true, ent);
|
2014-04-12 03:31:59 +00:00
|
|
|
|
2014-06-21 17:58:17 +00:00
|
|
|
if (trace.fraction == 1.0 || trace.fraction > mid)//mid - trace.endpos[2] > movevars.stepheight)
|
2014-04-12 03:31:59 +00:00
|
|
|
{
|
|
|
|
ent->xv->hull = savedhull;
|
2004-08-23 00:15:46 +00:00
|
|
|
return false;
|
2014-04-12 03:31:59 +00:00
|
|
|
}
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c_yes++;
|
2014-04-12 03:31:59 +00:00
|
|
|
ent->xv->hull = savedhull;
|
2004-08-23 00:15:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============
|
|
|
|
SV_movestep
|
|
|
|
|
|
|
|
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
|
|
|
|
pr_global_struct->trace_normal is set to the normal of the blocking wall
|
|
|
|
=============
|
|
|
|
*/
|
2014-12-08 21:18:32 +00:00
|
|
|
qboolean World_movestep (world_t *world, wedict_t *ent, vec3_t move, vec3_t axis[3], qboolean relink, qboolean noenemy, void (*set_move_trace)(pubprogfuncs_t *prinst, struct globalvars_s *pr_globals, trace_t *trace), struct globalvars_s *set_trace_globs)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
float dz;
|
|
|
|
vec3_t oldorg, neworg, end;
|
|
|
|
trace_t trace;
|
|
|
|
int i;
|
2009-11-17 00:15:44 +00:00
|
|
|
wedict_t *enemy = world->edicts;
|
2012-01-17 07:57:46 +00:00
|
|
|
int eflags = ent->v->flags;
|
2014-06-21 17:58:17 +00:00
|
|
|
vec3_t eaxis[3];
|
|
|
|
|
|
|
|
if (!axis)
|
|
|
|
{
|
|
|
|
//fixme?
|
|
|
|
World_GetEntGravityAxis(ent, eaxis);
|
|
|
|
axis = eaxis;
|
|
|
|
}
|
2012-01-17 07:57:46 +00:00
|
|
|
|
2012-01-25 04:11:27 +00:00
|
|
|
#ifndef CLIENTONLY
|
|
|
|
if (progstype != PROG_H2 || world != &sv.world)
|
|
|
|
#endif
|
2012-01-17 07:57:46 +00:00
|
|
|
eflags &= ~FLH2_NOZ|FLH2_HUNTFACE;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
// try the move
|
2005-03-28 00:11:59 +00:00
|
|
|
VectorCopy (ent->v->origin, oldorg);
|
|
|
|
VectorAdd (ent->v->origin, move, neworg);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
// flying monsters don't step up
|
2012-01-25 04:11:27 +00:00
|
|
|
if ((eflags & (FL_SWIM | FL_FLY)) && !(eflags & (FLH2_NOZ|FLH2_HUNTFACE)))
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
// try one move with vertical motion, then one without
|
|
|
|
for (i=0 ; i<2 ; i++)
|
|
|
|
{
|
2005-03-28 00:11:59 +00:00
|
|
|
VectorAdd (ent->v->origin, move, neworg);
|
2004-08-23 00:15:46 +00:00
|
|
|
if (!noenemy)
|
|
|
|
{
|
2009-11-17 00:15:44 +00:00
|
|
|
enemy = (wedict_t*)PROG_TO_EDICT(world->progs, ent->v->enemy);
|
|
|
|
if (i == 0 && enemy->entnum)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2014-06-21 17:58:17 +00:00
|
|
|
VectorSubtract(ent->v->origin, ((wedict_t*)PROG_TO_EDICT(world->progs, ent->v->enemy))->v->origin, end);
|
|
|
|
dz = DotProduct(end, axis[2]);
|
2012-01-17 07:57:46 +00:00
|
|
|
if (eflags & FLH2_HUNTFACE) /*get the ent's origin_z to match its victims face*/
|
|
|
|
dz += ((wedict_t*)PROG_TO_EDICT(world->progs, ent->v->enemy))->v->view_ofs[2];
|
2004-08-23 00:15:46 +00:00
|
|
|
if (dz > 40)
|
2014-06-21 17:58:17 +00:00
|
|
|
VectorMA(neworg, -8, axis[2], neworg);
|
2004-08-23 00:15:46 +00:00
|
|
|
if (dz < 30)
|
2014-06-21 17:58:17 +00:00
|
|
|
VectorMA(neworg, 8, axis[2], neworg);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-17 00:15:44 +00:00
|
|
|
trace = World_Move (world, ent->v->origin, ent->v->mins, ent->v->maxs, neworg, false, ent);
|
2010-11-21 03:39:12 +00:00
|
|
|
if (set_move_trace)
|
2014-12-08 21:18:32 +00:00
|
|
|
set_move_trace(world->progs, set_trace_globs, &trace);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
if (trace.fraction == 1)
|
|
|
|
{
|
2012-01-17 07:57:46 +00:00
|
|
|
if ( (eflags & FL_SWIM) && !(World_PointContents(world, trace.endpos) & FTECONTENTS_FLUID))
|
2010-12-18 17:02:47 +00:00
|
|
|
continue; // swim monster left water
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
VectorCopy (trace.endpos, ent->v->origin);
|
2004-08-23 00:15:46 +00:00
|
|
|
if (relink)
|
2009-11-17 00:15:44 +00:00
|
|
|
World_LinkEdict (world, ent, true);
|
2004-08-23 00:15:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-11-17 00:15:44 +00:00
|
|
|
if (noenemy || !enemy->entnum)
|
2004-08-23 00:15:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// push down from a step height above the wished position
|
2014-06-21 17:58:17 +00:00
|
|
|
VectorMA(neworg, movevars.stepheight, axis[2], neworg);
|
|
|
|
VectorMA(neworg, movevars.stepheight*-2, axis[2], end);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2009-11-17 00:15:44 +00:00
|
|
|
trace = World_Move (world, neworg, ent->v->mins, ent->v->maxs, end, false, ent);
|
2010-11-21 03:39:12 +00:00
|
|
|
if (set_move_trace)
|
2014-12-08 21:18:32 +00:00
|
|
|
set_move_trace(world->progs, set_trace_globs, &trace);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
if (trace.allsolid)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (trace.startsolid)
|
|
|
|
{
|
2014-06-21 17:58:17 +00:00
|
|
|
//move up by an extra step, if needed
|
|
|
|
VectorMA(neworg, -movevars.stepheight, axis[2], neworg);
|
2009-11-17 00:15:44 +00:00
|
|
|
trace = World_Move (world, neworg, ent->v->mins, ent->v->maxs, end, false, ent);
|
2010-11-21 03:39:12 +00:00
|
|
|
if (set_move_trace)
|
2014-12-08 21:18:32 +00:00
|
|
|
set_move_trace(world->progs, set_trace_globs, &trace);
|
2004-08-23 00:15:46 +00:00
|
|
|
if (trace.allsolid || trace.startsolid)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (trace.fraction == 1)
|
|
|
|
{
|
|
|
|
// if monster had the ground pulled out, go ahead and fall
|
2005-03-28 00:11:59 +00:00
|
|
|
if ( (int)ent->v->flags & FL_PARTIALGROUND )
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2005-03-28 00:11:59 +00:00
|
|
|
VectorAdd (ent->v->origin, move, ent->v->origin);
|
2004-08-23 00:15:46 +00:00
|
|
|
if (relink)
|
2009-11-17 00:15:44 +00:00
|
|
|
World_LinkEdict (world, ent, true);
|
2005-03-28 00:11:59 +00:00
|
|
|
ent->v->flags = (int)ent->v->flags & ~FL_ONGROUND;
|
2004-08-23 00:15:46 +00:00
|
|
|
// Con_Printf ("fall down\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false; // walked off an edge
|
|
|
|
}
|
|
|
|
|
|
|
|
// check point traces down for dangling corners
|
2005-03-28 00:11:59 +00:00
|
|
|
VectorCopy (trace.endpos, ent->v->origin);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2014-06-21 17:58:17 +00:00
|
|
|
if (!World_CheckBottom (world, ent, axis[2]))
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2005-03-28 00:11:59 +00:00
|
|
|
if ( (int)ent->v->flags & FL_PARTIALGROUND )
|
2004-08-23 00:15:46 +00:00
|
|
|
{ // entity had floor mostly pulled out from underneath it
|
|
|
|
// and is trying to correct
|
|
|
|
if (relink)
|
2009-11-17 00:15:44 +00:00
|
|
|
World_LinkEdict (world, ent, true);
|
2004-08-23 00:15:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2005-03-28 00:11:59 +00:00
|
|
|
VectorCopy (oldorg, ent->v->origin);
|
2004-08-23 00:15:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
if ( (int)ent->v->flags & FL_PARTIALGROUND )
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
// Con_Printf ("back on ground\n");
|
2005-03-28 00:11:59 +00:00
|
|
|
ent->v->flags = (int)ent->v->flags & ~FL_PARTIALGROUND;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
2009-11-17 00:15:44 +00:00
|
|
|
ent->v->groundentity = EDICT_TO_PROG(world->progs, trace.ent);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
// the move is ok
|
|
|
|
if (relink)
|
2009-11-17 00:15:44 +00:00
|
|
|
World_LinkEdict (world, ent, true);
|
2004-08-23 00:15:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2014-06-21 17:58:17 +00:00
|
|
|
qboolean World_GetEntGravityAxis(wedict_t *ent, vec3_t axis[3])
|
|
|
|
{
|
|
|
|
if (ent->xv->gravitydir[0] || ent->xv->gravitydir[1] || ent->xv->gravitydir[2])
|
|
|
|
{
|
|
|
|
void PerpendicularVector( vec3_t dst, const vec3_t src );
|
|
|
|
VectorNegate(ent->xv->gravitydir, axis[2]);
|
|
|
|
VectorNormalize(axis[2]);
|
|
|
|
PerpendicularVector(axis[0], axis[2]);
|
|
|
|
VectorNormalize(axis[0]);
|
|
|
|
CrossProduct(axis[2], axis[0], axis[1]);
|
|
|
|
VectorNormalize(axis[1]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
VectorSet(axis[0], 1, 0, 0);
|
|
|
|
VectorSet(axis[1], 0, 1, 0);
|
|
|
|
VectorSet(axis[2], 0, 0, 1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-17 00:15:44 +00:00
|
|
|
/*
|
|
|
|
==============
|
|
|
|
PF_changeyaw
|
|
|
|
|
|
|
|
This was a major timewaster in progs, so it was converted to C
|
|
|
|
==============
|
|
|
|
*/
|
2014-06-21 17:58:17 +00:00
|
|
|
float World_changeyaw (wedict_t *ent)
|
2009-11-17 00:15:44 +00:00
|
|
|
{
|
|
|
|
float ideal, current, move, speed;
|
2014-06-21 17:58:17 +00:00
|
|
|
vec3_t surf[3];
|
|
|
|
if (World_GetEntGravityAxis(ent, surf))
|
|
|
|
{
|
|
|
|
//complex matrix stuff
|
|
|
|
float mat[16];
|
|
|
|
float surfm[16], invsurfm[16];
|
|
|
|
float viewm[16];
|
|
|
|
vec3_t view[4];
|
|
|
|
vec3_t vang;
|
|
|
|
|
|
|
|
/*calc current view matrix relative to the surface*/
|
|
|
|
ent->v->angles[PITCH] *= -1;
|
|
|
|
AngleVectors(ent->v->angles, view[0], view[1], view[2]);
|
|
|
|
VectorNegate(view[1], view[1]);
|
|
|
|
|
|
|
|
World_GetEntGravityAxis(ent, surf);
|
|
|
|
|
|
|
|
Matrix4x4_RM_FromVectors(surfm, surf[0], surf[1], surf[2], vec3_origin);
|
|
|
|
Matrix3x4_InvertTo4x4_Simple(surfm, invsurfm);
|
|
|
|
|
|
|
|
/*calc current view matrix relative to the surface*/
|
|
|
|
Matrix4x4_RM_FromVectors(viewm, view[0], view[1], view[2], vec3_origin);
|
|
|
|
Matrix4_Multiply(viewm, invsurfm, mat);
|
|
|
|
/*convert that back to angles*/
|
|
|
|
Matrix3x4_RM_ToVectors(mat, view[0], view[1], view[2], view[3]);
|
|
|
|
VectorAngles(view[0], view[2], vang);
|
|
|
|
|
|
|
|
/*edit it*/
|
|
|
|
|
|
|
|
ideal = ent->v->ideal_yaw;
|
|
|
|
speed = ent->v->yaw_speed;
|
|
|
|
move = ideal - anglemod(vang[YAW]);
|
|
|
|
if (move > 180)
|
|
|
|
move -= 360;
|
|
|
|
else if (move < -180)
|
|
|
|
move += 360;
|
|
|
|
if (move > 0)
|
|
|
|
{
|
|
|
|
if (move > speed)
|
|
|
|
move = speed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (move < -speed)
|
|
|
|
move = -speed;
|
|
|
|
}
|
|
|
|
vang[YAW] = anglemod(vang[YAW] + move);
|
|
|
|
|
|
|
|
/*clamp pitch, kill roll. monsters don't pitch/roll.*/
|
|
|
|
vang[PITCH] = 0;
|
|
|
|
vang[ROLL] = 0;
|
|
|
|
|
|
|
|
move = ideal - vang[YAW];
|
|
|
|
|
|
|
|
/*turn those angles back to a matrix*/
|
|
|
|
AngleVectors(vang, view[0], view[1], view[2]);
|
|
|
|
VectorNegate(view[1], view[1]);
|
|
|
|
Matrix4x4_RM_FromVectors(mat, view[0], view[1], view[2], vec3_origin);
|
|
|
|
/*rotate back into world space*/
|
|
|
|
Matrix4_Multiply(mat, surfm, viewm);
|
|
|
|
/*and figure out the final result*/
|
|
|
|
Matrix3x4_RM_ToVectors(viewm, view[0], view[1], view[2], view[3]);
|
|
|
|
VectorAngles(view[0], view[2], ent->v->angles);
|
|
|
|
|
|
|
|
//make sure everything is sane
|
|
|
|
ent->v->angles[PITCH] = anglemod(ent->v->angles[PITCH]);
|
|
|
|
ent->v->angles[YAW] = anglemod(ent->v->angles[YAW]);
|
|
|
|
ent->v->angles[ROLL] = anglemod(ent->v->angles[ROLL]);
|
|
|
|
return move;
|
|
|
|
}
|
|
|
|
|
2009-11-17 00:15:44 +00:00
|
|
|
|
2014-01-13 02:42:25 +00:00
|
|
|
//FIXME: gravitydir. reorient the angles to change the yaw with respect to the current ground surface.
|
|
|
|
|
2009-11-17 00:15:44 +00:00
|
|
|
current = anglemod( ent->v->angles[1] );
|
|
|
|
ideal = ent->v->ideal_yaw;
|
|
|
|
speed = ent->v->yaw_speed;
|
|
|
|
|
|
|
|
if (current == ideal)
|
2014-06-21 17:58:17 +00:00
|
|
|
return 0;
|
2009-11-17 00:15:44 +00:00
|
|
|
move = ideal - current;
|
|
|
|
if (ideal > current)
|
|
|
|
{
|
|
|
|
if (move >= 180)
|
|
|
|
move = move - 360;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (move <= -180)
|
|
|
|
move = move + 360;
|
|
|
|
}
|
|
|
|
if (move > 0)
|
|
|
|
{
|
|
|
|
if (move > speed)
|
|
|
|
move = speed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (move < -speed)
|
|
|
|
move = -speed;
|
|
|
|
}
|
|
|
|
|
|
|
|
ent->v->angles[1] = anglemod (current + move);
|
2014-06-21 17:58:17 +00:00
|
|
|
|
|
|
|
return ideal - ent->v->angles[1];
|
2009-11-17 00:15:44 +00:00
|
|
|
}
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
/*
|
|
|
|
======================
|
|
|
|
SV_StepDirection
|
|
|
|
|
|
|
|
Turns to the movement direction, and walks the current distance if
|
|
|
|
facing it.
|
|
|
|
|
|
|
|
======================
|
|
|
|
*/
|
2014-06-21 17:58:17 +00:00
|
|
|
qboolean World_StepDirection (world_t *world, wedict_t *ent, float yaw, float dist, vec3_t axis[3])
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
vec3_t move, oldorigin;
|
2014-06-21 17:58:17 +00:00
|
|
|
float delta, s;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
ent->v->ideal_yaw = yaw;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2014-06-21 17:58:17 +00:00
|
|
|
delta = World_changeyaw(ent);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
yaw = yaw*M_PI*2 / 360;
|
2014-06-21 17:58:17 +00:00
|
|
|
|
|
|
|
s = cos(yaw)*dist;
|
|
|
|
VectorScale(axis[0], s, move);
|
|
|
|
s = sin(yaw)*dist;
|
|
|
|
VectorMA(move, s, axis[1], move);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2012-01-17 07:57:46 +00:00
|
|
|
//FIXME: Hexen2: ent flags & FL_SET_TRACE
|
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
VectorCopy (ent->v->origin, oldorigin);
|
2014-06-21 17:58:17 +00:00
|
|
|
if (World_movestep (world, ent, move, axis, false, false, NULL, NULL))
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2014-06-21 17:58:17 +00:00
|
|
|
delta = anglemod(delta);
|
2004-08-23 00:15:46 +00:00
|
|
|
if (delta > 45 && delta < 315)
|
2014-06-21 17:58:17 +00:00
|
|
|
{ // not turned far enough, so don't take the step
|
|
|
|
//FIXME: surely this is noticably inefficient?
|
2005-03-28 00:11:59 +00:00
|
|
|
VectorCopy (oldorigin, ent->v->origin);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
2009-11-17 00:15:44 +00:00
|
|
|
World_LinkEdict (world, ent, true);
|
2004-08-23 00:15:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-11-17 00:15:44 +00:00
|
|
|
World_LinkEdict (world, ent, true);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
SV_FixCheckBottom
|
|
|
|
|
|
|
|
======================
|
|
|
|
*/
|
2009-11-17 00:15:44 +00:00
|
|
|
void World_FixCheckBottom (wedict_t *ent)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
// Con_Printf ("SV_FixCheckBottom\n");
|
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
ent->v->flags = (int)ent->v->flags | FL_PARTIALGROUND;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
SV_NewChaseDir
|
|
|
|
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
#define DI_NODIR -1
|
|
|
|
|
2014-06-21 17:58:17 +00:00
|
|
|
void World_NewChaseDir (world_t *world, wedict_t *actor, wedict_t *enemy, float dist, vec3_t axis[3])
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
float deltax,deltay;
|
|
|
|
float d[3];
|
|
|
|
float tdir, olddir, turnaround;
|
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
olddir = anglemod( (int)(actor->v->ideal_yaw/45)*45 );
|
2004-08-23 00:15:46 +00:00
|
|
|
turnaround = anglemod(olddir - 180);
|
|
|
|
|
2014-06-21 17:58:17 +00:00
|
|
|
VectorSubtract(enemy->v->origin, actor->v->origin, d);
|
|
|
|
deltax = DotProduct(d, axis[0]);
|
|
|
|
deltay = DotProduct(d, axis[1]);
|
2004-08-23 00:15:46 +00:00
|
|
|
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;
|
|
|
|
|
2014-06-21 17:58:17 +00:00
|
|
|
if (tdir != turnaround && World_StepDirection(world, actor, tdir, dist, axis))
|
2004-08-23 00:15:46 +00:00
|
|
|
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
|
2014-06-21 17:58:17 +00:00
|
|
|
&& World_StepDirection(world, actor, d[1], dist, axis))
|
2004-08-23 00:15:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (d[2]!=DI_NODIR && d[2]!=turnaround
|
2014-06-21 17:58:17 +00:00
|
|
|
&& World_StepDirection(world, actor, d[2], dist, axis))
|
2004-08-23 00:15:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* there is no direct path to the player, so pick another direction */
|
|
|
|
|
2014-06-21 17:58:17 +00:00
|
|
|
if (olddir!=DI_NODIR && World_StepDirection(world, actor, olddir, dist, axis))
|
2004-08-23 00:15:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (rand()&1) /*randomly determine direction of search*/
|
|
|
|
{
|
|
|
|
for (tdir=0 ; tdir<=315 ; tdir += 45)
|
2014-06-21 17:58:17 +00:00
|
|
|
if (tdir!=turnaround && World_StepDirection(world, actor, tdir, dist, axis) )
|
2004-08-23 00:15:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (tdir=315 ; tdir >=0 ; tdir -= 45)
|
2014-06-21 17:58:17 +00:00
|
|
|
if (tdir!=turnaround && World_StepDirection(world, actor, tdir, dist, axis) )
|
2004-08-23 00:15:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-21 17:58:17 +00:00
|
|
|
if (turnaround != DI_NODIR && World_StepDirection(world, actor, turnaround, dist, axis) )
|
2004-08-23 00:15:46 +00:00
|
|
|
return;
|
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
actor->v->ideal_yaw = olddir; // can't move
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
// if a bridge was pulled out from underneath a monster, it may not have
|
|
|
|
// a valid standing position at all
|
|
|
|
|
2014-06-21 17:58:17 +00:00
|
|
|
if (!World_CheckBottom (world, actor, axis[2]))
|
2009-11-17 00:15:44 +00:00
|
|
|
World_FixCheckBottom (actor);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
SV_CloseEnough
|
|
|
|
|
|
|
|
======================
|
|
|
|
*/
|
2009-11-17 00:15:44 +00:00
|
|
|
qboolean World_CloseEnough (wedict_t *ent, wedict_t *goal, float dist)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0 ; i<3 ; i++)
|
|
|
|
{
|
2005-03-28 00:11:59 +00:00
|
|
|
if (goal->v->absmin[i] > ent->v->absmax[i] + dist)
|
2004-08-23 00:15:46 +00:00
|
|
|
return false;
|
2005-03-28 00:11:59 +00:00
|
|
|
if (goal->v->absmax[i] < ent->v->absmin[i] - dist)
|
2004-08-23 00:15:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
SV_MoveToGoal
|
|
|
|
|
|
|
|
======================
|
|
|
|
*/
|
2009-11-17 00:15:44 +00:00
|
|
|
qboolean World_MoveToGoal (world_t *world, wedict_t *ent, float dist)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2009-11-17 00:15:44 +00:00
|
|
|
wedict_t *goal;
|
2014-06-21 17:58:17 +00:00
|
|
|
vec3_t axis[3];
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2011-09-16 05:56:54 +00:00
|
|
|
ent = (wedict_t*)PROG_TO_EDICT(world->progs, *world->g.self);
|
2009-11-17 00:15:44 +00:00
|
|
|
goal = (wedict_t*)PROG_TO_EDICT(world->progs, ent->v->goalentity);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2005-03-28 00:11:59 +00:00
|
|
|
if ( !( (int)ent->v->flags & (FL_ONGROUND|FL_FLY|FL_SWIM) ) )
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2009-11-17 00:15:44 +00:00
|
|
|
return false;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if the next step hits the enemy, return immediately
|
2009-11-17 00:15:44 +00:00
|
|
|
if ( PROG_TO_EDICT(world->progs, ent->v->enemy) != (edict_t*)world->edicts && World_CloseEnough (ent, goal, dist) )
|
|
|
|
return true;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
2014-06-21 17:58:17 +00:00
|
|
|
|
|
|
|
World_GetEntGravityAxis(ent, axis);
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
// bump around...
|
|
|
|
if ( (rand()&3)==1 ||
|
2014-06-21 17:58:17 +00:00
|
|
|
!World_StepDirection (world, ent, ent->v->ideal_yaw, dist, axis))
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
2014-06-21 17:58:17 +00:00
|
|
|
World_NewChaseDir (world, ent, goal, dist, axis);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
2009-11-17 00:15:44 +00:00
|
|
|
return true;
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
2004-11-29 01:21:00 +00:00
|
|
|
#endif
|