2014-02-22 12:20:22 +00:00
|
|
|
/*
|
2014-01-26 14:53:04 +00:00
|
|
|
* =======================================================================
|
|
|
|
*
|
|
|
|
* Rogue specific AI code
|
|
|
|
*
|
|
|
|
* =======================================================================
|
|
|
|
*/
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2011-10-11 11:40:43 +00:00
|
|
|
#include "header/local.h"
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
#define STATE_TOP 0
|
|
|
|
#define STATE_BOTTOM 1
|
|
|
|
#define STATE_UP 2
|
|
|
|
#define STATE_DOWN 3
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
#define HINT_ENDPOINT 0x0001
|
|
|
|
#define MAX_HINT_CHAINS 100
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
#define TESLA_DAMAGE_RADIUS 128
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
edict_t *hint_path_start[MAX_HINT_CHAINS];
|
|
|
|
int hint_paths_present;
|
|
|
|
int num_hint_paths;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
qboolean face_wall(edict_t *self);
|
|
|
|
qboolean monsterlost_checkhint2(edict_t *self);
|
|
|
|
void HuntTarget(edict_t *self);
|
|
|
|
|
|
|
|
qboolean
|
|
|
|
blocked_checkplat(edict_t *self, float dist)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
int playerPosition;
|
|
|
|
trace_t trace;
|
|
|
|
vec3_t pt1, pt2;
|
|
|
|
vec3_t forward;
|
|
|
|
edict_t *plat;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self->enemy)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* check player's relative altitude */
|
|
|
|
if (self->enemy->absmin[2] >= self->absmax[2])
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
playerPosition = 1;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
else if (self->enemy->absmax[2] <= self->absmin[2])
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
playerPosition = -1;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
else
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
playerPosition = 0;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if we're close to the same position, don't bother trying plats. */
|
|
|
|
if (playerPosition == 0)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
plat = NULL;
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* see if we're already standing on a plat. */
|
|
|
|
if (self->groundentity && (self->groundentity != world))
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!strncmp(self->groundentity->classname, "func_plat", 8))
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
plat = self->groundentity;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if we're not, check to see if we'll step onto one with this move */
|
|
|
|
if (!plat)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
AngleVectors(self->s.angles, forward, NULL, NULL);
|
2009-03-12 20:03:41 +00:00
|
|
|
VectorMA(self->s.origin, dist, forward, pt1);
|
2014-01-26 14:53:04 +00:00
|
|
|
VectorCopy(pt1, pt2);
|
2009-03-12 20:03:41 +00:00
|
|
|
pt2[2] -= 384;
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
trace = gi.trace(pt1, vec3_origin, vec3_origin, pt2,
|
|
|
|
self, MASK_MONSTERSOLID);
|
|
|
|
|
|
|
|
if ((trace.fraction < 1) && !trace.allsolid && !trace.startsolid)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!strncmp(trace.ent->classname, "func_plat", 8))
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
plat = trace.ent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if we've found a plat, trigger it. */
|
|
|
|
if (plat && plat->use)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
if (playerPosition == 1)
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (((self->groundentity == plat) &&
|
|
|
|
(plat->moveinfo.state == STATE_BOTTOM)) ||
|
|
|
|
((self->groundentity != plat) &&
|
|
|
|
(plat->moveinfo.state == STATE_TOP)))
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
plat->use(plat, self, self);
|
|
|
|
return true;
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
else if (playerPosition == -1)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (((self->groundentity == plat) &&
|
|
|
|
(plat->moveinfo.state == STATE_TOP)) ||
|
|
|
|
((self->groundentity != plat) &&
|
|
|
|
(plat->moveinfo.state == STATE_BOTTOM)))
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
plat->use(plat, self, self);
|
2009-03-12 20:03:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
qboolean
|
|
|
|
blocked_checkjump(edict_t *self, float dist, float maxDown, float maxUp)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
int playerPosition;
|
|
|
|
trace_t trace;
|
|
|
|
vec3_t pt1, pt2;
|
|
|
|
vec3_t forward, up;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self->enemy)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
AngleVectors(self->s.angles, forward, NULL, up);
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (self->enemy->absmin[2] > (self->absmin[2] + 16))
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
playerPosition = 1;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
else if (self->enemy->absmin[2] < (self->absmin[2] - 16))
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
playerPosition = -1;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
else
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
playerPosition = 0;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if ((playerPosition == -1) && maxDown)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
/* check to make sure we can even get to the spot we're going to "fall" from */
|
2009-03-12 20:03:41 +00:00
|
|
|
VectorMA(self->s.origin, 48, forward, pt1);
|
2014-01-26 14:53:04 +00:00
|
|
|
trace = gi.trace(self->s.origin, self->mins, self->maxs, pt1,
|
|
|
|
self, MASK_MONSTERSOLID);
|
|
|
|
|
|
|
|
if (trace.fraction < 1)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
VectorCopy(pt1, pt2);
|
2019-11-04 17:18:29 +00:00
|
|
|
pt2[2] = self->absmin[2] - maxDown - 1;
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
trace = gi.trace(pt1, vec3_origin, vec3_origin, pt2, self,
|
|
|
|
MASK_MONSTERSOLID | MASK_WATER);
|
|
|
|
|
|
|
|
if ((trace.fraction < 1) && !trace.allsolid && !trace.startsolid)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (((self->absmin[2] - trace.endpos[2]) >=
|
2019-11-04 17:18:29 +00:00
|
|
|
24) && (trace.contents & MASK_SOLID))
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if ((self->enemy->absmin[2] - trace.endpos[2]) > 32)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
return false;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (trace.plane.normal[2] < 0.9)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
else if ((playerPosition == 1) && maxUp)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
VectorMA(self->s.origin, 48, forward, pt1);
|
|
|
|
VectorCopy(pt1, pt2);
|
|
|
|
pt1[2] = self->absmax[2] + maxUp;
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
trace = gi.trace(pt1, vec3_origin, vec3_origin, pt2, self,
|
|
|
|
MASK_MONSTERSOLID | MASK_WATER);
|
|
|
|
|
|
|
|
if ((trace.fraction < 1) && !trace.allsolid && !trace.startsolid)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (((trace.endpos[2] - self->absmin[2]) <= maxUp) &&
|
|
|
|
trace.contents & MASK_SOLID)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
face_wall(self);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
qboolean
|
|
|
|
blocked_checknewenemy(edict_t *self)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
edict_t *
|
|
|
|
hintpath_findstart(edict_t *ent)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
edict_t *e;
|
|
|
|
edict_t *last;
|
|
|
|
int field;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!ent)
|
|
|
|
{
|
2014-08-03 09:34:06 +00:00
|
|
|
return NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (ent->target) /* starting point */
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
last = world;
|
|
|
|
field = FOFS(targetname);
|
|
|
|
e = G_Find(NULL, field, ent->target);
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
while (e)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
last = e;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
if (!e->target)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
break;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = G_Find(NULL, field, e->target);
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
else /* end point */
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
last = world;
|
|
|
|
field = FOFS(target);
|
|
|
|
e = G_Find(NULL, field, ent->targetname);
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
while (e)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
last = e;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
if (!e->targetname)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
break;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = G_Find(NULL, field, e->targetname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!(last->spawnflags & HINT_ENDPOINT))
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (last == world)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
last = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
edict_t *
|
|
|
|
hintpath_other_end(edict_t *ent)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
edict_t *e;
|
|
|
|
edict_t *last;
|
|
|
|
int field;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!ent)
|
|
|
|
{
|
2014-08-03 09:34:06 +00:00
|
|
|
return NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (ent->target) /* starting point */
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
last = world;
|
|
|
|
field = FOFS(targetname);
|
|
|
|
e = G_Find(NULL, field, ent->target);
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
while (e)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
last = e;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
if (!e->target)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
break;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = G_Find(NULL, field, e->target);
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
else /* end point */
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
last = world;
|
|
|
|
field = FOFS(target);
|
|
|
|
e = G_Find(NULL, field, ent->targetname);
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
while (e)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
last = e;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
if (!e->targetname)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
break;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = G_Find(NULL, field, e->targetname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!(last->spawnflags & HINT_ENDPOINT))
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (last == world)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
last = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
hintpath_go(edict_t *self, edict_t *point)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
vec3_t dir;
|
|
|
|
vec3_t angles;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self || !point)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
VectorSubtract(point->s.origin, self->s.origin, dir);
|
|
|
|
vectoangles2(dir, angles);
|
|
|
|
|
|
|
|
self->ideal_yaw = angles[YAW];
|
|
|
|
self->goalentity = self->movetarget = point;
|
|
|
|
self->monsterinfo.pausetime = 0;
|
|
|
|
self->monsterinfo.aiflags |= AI_HINT_PATH;
|
|
|
|
self->monsterinfo.aiflags &= ~(AI_SOUND_TARGET | AI_PURSUIT_LAST_SEEN | AI_PURSUE_NEXT | AI_PURSUE_TEMP);
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* run for it */
|
2009-03-12 20:03:41 +00:00
|
|
|
self->monsterinfo.search_time = level.time;
|
2014-01-26 14:53:04 +00:00
|
|
|
self->monsterinfo.run(self);
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
hintpath_stop(edict_t *self)
|
2014-02-22 12:20:22 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
self->goalentity = NULL;
|
|
|
|
self->movetarget = NULL;
|
|
|
|
self->monsterinfo.last_hint_time = level.time;
|
|
|
|
self->monsterinfo.goal_hint = NULL;
|
|
|
|
self->monsterinfo.aiflags &= ~AI_HINT_PATH;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (has_valid_enemy(self))
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if we can see our target, go nuts */
|
2009-03-12 20:03:41 +00:00
|
|
|
if (visible(self, self->enemy))
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
FoundTarget(self);
|
2009-03-12 20:03:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* otherwise, keep chasing */
|
|
|
|
HuntTarget(self);
|
2009-03-12 20:03:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* if our enemy is no longer valid, forget about our enemy and go into stand */
|
2009-03-12 20:03:41 +00:00
|
|
|
self->enemy = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* we need the pausetime otherwise the stand code
|
|
|
|
will just revert to walking with no target and
|
2014-02-22 12:20:22 +00:00
|
|
|
the monsters will wonder around aimlessly trying
|
2014-01-26 14:53:04 +00:00
|
|
|
to hunt the world entity */
|
2009-03-12 20:03:41 +00:00
|
|
|
self->monsterinfo.pausetime = level.time + 100000000;
|
2014-01-26 14:53:04 +00:00
|
|
|
self->monsterinfo.stand(self);
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
qboolean
|
|
|
|
monsterlost_checkhint(edict_t *self)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
edict_t *e, *monster_pathchain, *target_pathchain;
|
|
|
|
edict_t *checkpoint = NULL;
|
|
|
|
edict_t *closest;
|
|
|
|
float closest_range = 1000000;
|
|
|
|
edict_t *start, *destination;
|
|
|
|
int count1 = 0, count2 = 0, count4 = 0, count5 = 0;
|
|
|
|
float r;
|
|
|
|
int i;
|
|
|
|
qboolean hint_path_represented[MAX_HINT_CHAINS];
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if there are no hint paths on this map, exit immediately. */
|
|
|
|
if (!hint_paths_present)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self->enemy)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
if (self->monsterinfo.aiflags & AI_STAND_GROUND)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!strcmp(self->classname, "monster_turret"))
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
monster_pathchain = NULL;
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* find all the hint_paths. */
|
|
|
|
for (i = 0; i < num_hint_paths; i++)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
e = hint_path_start[i];
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
while (e)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
count1++;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (e->monster_hint_chain)
|
|
|
|
{
|
|
|
|
e->monster_hint_chain = NULL;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (monster_pathchain)
|
|
|
|
{
|
|
|
|
checkpoint->monster_hint_chain = e;
|
|
|
|
checkpoint = e;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
monster_pathchain = e;
|
|
|
|
checkpoint = e;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = e->hint_chain;
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* filter them by distance and visibility to the monster */
|
2009-03-12 20:03:41 +00:00
|
|
|
e = monster_pathchain;
|
|
|
|
checkpoint = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
while (e)
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
r = realrange(self, e);
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
if (r > 512)
|
|
|
|
{
|
|
|
|
count2++;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (checkpoint)
|
|
|
|
{
|
|
|
|
checkpoint->monster_hint_chain = e->monster_hint_chain;
|
|
|
|
e->monster_hint_chain = NULL;
|
|
|
|
e = checkpoint->monster_hint_chain;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
/* use checkpoint as temp pointer */
|
2009-03-12 20:03:41 +00:00
|
|
|
checkpoint = e;
|
|
|
|
e = e->monster_hint_chain;
|
|
|
|
checkpoint->monster_hint_chain = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* and clear it again */
|
2009-03-12 20:03:41 +00:00
|
|
|
checkpoint = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2014-02-22 12:20:22 +00:00
|
|
|
/* since we have yet to find a valid one (or else
|
2014-01-26 14:53:04 +00:00
|
|
|
checkpoint would be set) move the start of
|
|
|
|
monster_pathchain */
|
2009-03-12 20:03:41 +00:00
|
|
|
monster_pathchain = e;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!visible(self, e))
|
|
|
|
{
|
|
|
|
count4++;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (checkpoint)
|
|
|
|
{
|
|
|
|
checkpoint->monster_hint_chain = e->monster_hint_chain;
|
|
|
|
e->monster_hint_chain = NULL;
|
|
|
|
e = checkpoint->monster_hint_chain;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
/* use checkpoint as temp pointer */
|
2009-03-12 20:03:41 +00:00
|
|
|
checkpoint = e;
|
|
|
|
e = e->monster_hint_chain;
|
|
|
|
checkpoint->monster_hint_chain = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* and clear it again */
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
checkpoint = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
/* since we have yet to find a valid one (or else
|
2014-02-22 12:20:22 +00:00
|
|
|
checkpoint would be set) move the start of
|
2014-01-26 14:53:04 +00:00
|
|
|
monster_pathchain */
|
2009-03-12 20:03:41 +00:00
|
|
|
monster_pathchain = e;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* if it passes all the tests, it's a keeper */
|
2009-03-12 20:03:41 +00:00
|
|
|
count5++;
|
|
|
|
checkpoint = e;
|
|
|
|
e = e->monster_hint_chain;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* at this point, we have a list of all of the eligible
|
|
|
|
hint nodes for the monster we now take them, figure out
|
2014-02-22 12:20:22 +00:00
|
|
|
what hint chains they're on, and traverse down those
|
2014-01-26 14:53:04 +00:00
|
|
|
chains, seeing whether any can see the player. first,
|
|
|
|
we figure out which hint chains we have represented
|
|
|
|
in monster_pathchain */
|
2009-03-12 20:03:41 +00:00
|
|
|
if (count5 == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
for (i = 0; i < num_hint_paths; i++)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
hint_path_represented[i] = false;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = monster_pathchain;
|
|
|
|
checkpoint = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
while (e)
|
|
|
|
{
|
|
|
|
if ((e->hint_chain_id < 0) || (e->hint_chain_id > num_hint_paths))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
hint_path_represented[e->hint_chain_id] = true;
|
|
|
|
e = e->monster_hint_chain;
|
|
|
|
}
|
|
|
|
|
|
|
|
count2 = 0;
|
|
|
|
count4 = 0;
|
|
|
|
count5 = 0;
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* now, build the target_pathchain which contains all of
|
2014-02-22 12:20:22 +00:00
|
|
|
the hint_path nodes we need to check for validity
|
2014-01-26 14:53:04 +00:00
|
|
|
(within range, visibility) */
|
2009-03-12 20:03:41 +00:00
|
|
|
target_pathchain = NULL;
|
|
|
|
checkpoint = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num_hint_paths; i++)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if this hint chain is represented in the
|
|
|
|
monster_hint_chain, add all of it's nodes
|
|
|
|
to the target_pathchain for validity checking */
|
2009-03-12 20:03:41 +00:00
|
|
|
if (hint_path_represented[i])
|
|
|
|
{
|
|
|
|
e = hint_path_start[i];
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
while (e)
|
|
|
|
{
|
|
|
|
if (target_pathchain)
|
|
|
|
{
|
|
|
|
checkpoint->target_hint_chain = e;
|
|
|
|
checkpoint = e;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
target_pathchain = e;
|
|
|
|
checkpoint = e;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = e->hint_chain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 12:20:22 +00:00
|
|
|
/* target_pathchain is a list of all of the hint_path nodes
|
2014-01-26 14:53:04 +00:00
|
|
|
we need to check for validity relative to the target */
|
2009-03-12 20:03:41 +00:00
|
|
|
e = target_pathchain;
|
|
|
|
checkpoint = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
while (e)
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
r = realrange(self->enemy, e);
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
if (r > 512)
|
|
|
|
{
|
|
|
|
count2++;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (checkpoint)
|
|
|
|
{
|
|
|
|
checkpoint->target_hint_chain = e->target_hint_chain;
|
|
|
|
e->target_hint_chain = NULL;
|
|
|
|
e = checkpoint->target_hint_chain;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
/* use checkpoint as temp pointer */
|
2009-03-12 20:03:41 +00:00
|
|
|
checkpoint = e;
|
|
|
|
e = e->target_hint_chain;
|
|
|
|
checkpoint->target_hint_chain = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* and clear it again */
|
2009-03-12 20:03:41 +00:00
|
|
|
checkpoint = NULL;
|
|
|
|
target_pathchain = e;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!visible(self->enemy, e))
|
|
|
|
{
|
|
|
|
count4++;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (checkpoint)
|
|
|
|
{
|
|
|
|
checkpoint->target_hint_chain = e->target_hint_chain;
|
|
|
|
e->target_hint_chain = NULL;
|
|
|
|
e = checkpoint->target_hint_chain;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
/* use checkpoint as temp pointer */
|
2009-03-12 20:03:41 +00:00
|
|
|
checkpoint = e;
|
|
|
|
e = e->target_hint_chain;
|
|
|
|
checkpoint->target_hint_chain = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* and clear it again */
|
2009-03-12 20:03:41 +00:00
|
|
|
checkpoint = NULL;
|
|
|
|
target_pathchain = e;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* if it passes all the tests, it's a keeper */
|
2009-03-12 20:03:41 +00:00
|
|
|
count5++;
|
|
|
|
checkpoint = e;
|
|
|
|
e = e->target_hint_chain;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* at this point we should have:
|
|
|
|
- monster_pathchain - a list of "monster valid" hint_path nodes linked
|
|
|
|
together by monster_hint_chain
|
2014-02-22 12:20:22 +00:00
|
|
|
- target_pathcain - a list of "target valid" hint_path nodes linked
|
2014-01-26 14:53:04 +00:00
|
|
|
together by target_hint_chain. these are filtered
|
2014-02-22 12:20:22 +00:00
|
|
|
such that only nodes which are on the same chain
|
2014-01-26 14:53:04 +00:00
|
|
|
as "monster valid" nodes
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
Now, we figure out which "monster valid" node we want to use. To do this, we
|
2014-02-22 12:20:22 +00:00
|
|
|
first off make sure we have some target nodes. If we don't, there are no
|
2014-01-26 14:53:04 +00:00
|
|
|
valid hint_path nodes for us to take. If we have some, we filter all of our
|
|
|
|
"monster valid" nodes by which ones have "target valid" nodes on them. Once
|
|
|
|
this filter is finished, we select the closest "monster valid" node, and go to it. */
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
if (count5 == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-22 12:20:22 +00:00
|
|
|
/* reuse the hint_chain_represented array, this time
|
2014-01-26 14:53:04 +00:00
|
|
|
to see which chains are represented by the target */
|
|
|
|
for (i = 0; i < num_hint_paths; i++)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
hint_path_represented[i] = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
e = target_pathchain;
|
|
|
|
checkpoint = NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
while (e)
|
|
|
|
{
|
|
|
|
if ((e->hint_chain_id < 0) || (e->hint_chain_id > num_hint_paths))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
hint_path_represented[e->hint_chain_id] = true;
|
|
|
|
e = e->target_hint_chain;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* traverse the monster_pathchain - if the hint_node isn't represented
|
2014-02-22 12:20:22 +00:00
|
|
|
in the "target valid" chain list, remove it. if it is on the list,
|
2014-01-26 14:53:04 +00:00
|
|
|
check it for range from the monster. If the range is the closest, keep it */
|
2009-03-12 20:03:41 +00:00
|
|
|
closest = NULL;
|
|
|
|
e = monster_pathchain;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
while (e)
|
|
|
|
{
|
|
|
|
if (!(hint_path_represented[e->hint_chain_id]))
|
|
|
|
{
|
|
|
|
checkpoint = e->monster_hint_chain;
|
|
|
|
e->monster_hint_chain = NULL;
|
|
|
|
e = checkpoint;
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
r = realrange(self, e);
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (r < closest_range)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
closest = e;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = e->monster_hint_chain;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!closest)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
start = closest;
|
|
|
|
|
2014-02-22 12:20:22 +00:00
|
|
|
/* now we know which one is the closest to the monster..
|
2014-01-26 14:53:04 +00:00
|
|
|
this is the one the monster will go to. we need to
|
|
|
|
finally determine what the DESTINATION node is for the
|
|
|
|
monster. walk down the hint_chain, and find the closest one
|
|
|
|
to the player */
|
2009-03-12 20:03:41 +00:00
|
|
|
closest = NULL;
|
|
|
|
closest_range = 10000000;
|
|
|
|
e = target_pathchain;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
while (e)
|
|
|
|
{
|
|
|
|
if (start->hint_chain_id == e->hint_chain_id)
|
|
|
|
{
|
|
|
|
r = realrange(self, e);
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (r < closest_range)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
closest = e;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = e->target_hint_chain;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!closest)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
destination = closest;
|
|
|
|
|
|
|
|
self->monsterinfo.goal_hint = destination;
|
|
|
|
hintpath_go(self, start);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
hint_path_touch(edict_t *self, edict_t *other, cplane_t *plane /* unused */,
|
|
|
|
csurface_t *surf /* unused */)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
edict_t *e, *goal;
|
|
|
|
edict_t *next = NULL;
|
|
|
|
qboolean goalFound = false;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self || !other)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* make sure we're the target of it's obsession */
|
|
|
|
if (other->movetarget == self)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
goal = other->monsterinfo.goal_hint;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* if the monster is where he wants to be */
|
2009-03-12 20:03:41 +00:00
|
|
|
if (goal == self)
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
hintpath_stop(other);
|
2009-03-12 20:03:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if we aren't, figure out which way we want to go */
|
2009-03-12 20:03:41 +00:00
|
|
|
e = hint_path_start[self->hint_chain_id];
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
while (e)
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if we get up to ourselves on the hint chain, we're going down it */
|
2009-03-12 20:03:41 +00:00
|
|
|
if (e == self)
|
|
|
|
{
|
|
|
|
next = e->hint_chain;
|
|
|
|
break;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (e == goal)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
goalFound = true;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 12:20:22 +00:00
|
|
|
/* if we get to where the next link on the chain is this hint_path
|
|
|
|
and have found the goal on the way we're going upstream, so
|
2014-01-26 14:53:04 +00:00
|
|
|
remember who the previous link is */
|
2009-03-12 20:03:41 +00:00
|
|
|
if ((e->hint_chain == self) && goalFound)
|
|
|
|
{
|
|
|
|
next = e;
|
|
|
|
break;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = e->hint_chain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if we couldn't find it, have the monster go back to normal hunting. */
|
|
|
|
if (!next)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
hintpath_stop(other);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* set the last_hint entry to this hint_path,
|
|
|
|
and send him on his way */
|
2009-03-12 20:03:41 +00:00
|
|
|
hintpath_go(other, next);
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* have the monster freeze if the hint path we
|
|
|
|
just touched has a wait time on it, for e
|
|
|
|
xample, when riding a plat. */
|
|
|
|
if (self->wait)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
other->nextthink = level.time + self->wait;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/*
|
|
|
|
* QUAKED hint_path (.5 .3 0) (-8 -8 -8) (8 8 8) END
|
2014-02-22 12:20:22 +00:00
|
|
|
*
|
2014-01-26 14:53:04 +00:00
|
|
|
* Target: next hint path
|
|
|
|
*
|
|
|
|
* END - set this flag on the endpoints of each hintpath.
|
|
|
|
* "wait" - set this if you want the monster to freeze when they touch this hintpath
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
SP_hint_path(edict_t *self)
|
2014-02-22 12:20:22 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (deathmatch->value)
|
|
|
|
{
|
|
|
|
G_FreeEdict(self);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!self->targetname && !self->target)
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
gi.dprintf("unlinked hint_path at %s\n", vtos(self->s.origin));
|
|
|
|
G_FreeEdict(self);
|
2009-03-12 20:03:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->solid = SOLID_TRIGGER;
|
|
|
|
self->touch = hint_path_touch;
|
2014-01-26 14:53:04 +00:00
|
|
|
VectorSet(self->mins, -8, -8, -8);
|
|
|
|
VectorSet(self->maxs, 8, 8, 8);
|
2009-03-12 20:03:41 +00:00
|
|
|
self->svflags |= SVF_NOCLIENT;
|
2014-01-26 14:53:04 +00:00
|
|
|
gi.linkentity(self);
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
InitHintPaths(void)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
edict_t *e, *current;
|
|
|
|
int field, i, count2;
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
hint_paths_present = 0;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* check all the hint_paths. */
|
2009-03-12 20:03:41 +00:00
|
|
|
field = FOFS(classname);
|
|
|
|
e = G_Find(NULL, field, "hint_path");
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
if (e)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
hint_paths_present = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
memset(hint_path_start, 0, MAX_HINT_CHAINS * sizeof(edict_t *));
|
2009-03-12 20:03:41 +00:00
|
|
|
num_hint_paths = 0;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
while (e)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (e->spawnflags & HINT_ENDPOINT)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (e->target) /* start point */
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (e->targetname) /* this is a bad end, ignore it */
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
gi.dprintf("Hint path at %s marked as endpoint with both target (%s) and targetname (%s)\n",
|
|
|
|
vtos(e->s.origin), e->target, e->targetname);
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (num_hint_paths >= MAX_HINT_CHAINS)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
hint_path_start[num_hint_paths++] = e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = G_Find(e, field, "hint_path");
|
|
|
|
}
|
|
|
|
|
|
|
|
field = FOFS(targetname);
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num_hint_paths; i++)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
count2 = 1;
|
|
|
|
current = hint_path_start[i];
|
|
|
|
current->hint_chain_id = i;
|
|
|
|
e = G_Find(NULL, field, current->target);
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (G_Find(e, field, current->target))
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
gi.dprintf("\nForked hint path at %s detected for chain %d, target %s\n",
|
|
|
|
vtos(current->s.origin), num_hint_paths, current->target);
|
2009-03-12 20:03:41 +00:00
|
|
|
hint_path_start[i]->hint_chain = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
while (e)
|
|
|
|
{
|
|
|
|
if (e->hint_chain)
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
gi.dprintf("\nCircular hint path at %s detected for chain %d, targetname %s\n",
|
|
|
|
vtos(e->s.origin), num_hint_paths, e->targetname);
|
2009-03-12 20:03:41 +00:00
|
|
|
hint_path_start[i]->hint_chain = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
count2++;
|
|
|
|
current->hint_chain = e;
|
|
|
|
current = e;
|
|
|
|
current->hint_chain_id = i;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!current->target)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
break;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = G_Find(NULL, field, current->target);
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (G_Find(e, field, current->target))
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
gi.dprintf("\nForked hint path at %s detected for chain %d, target %s\n",
|
|
|
|
vtos(current->s.origin), num_hint_paths, current->target);
|
2009-03-12 20:03:41 +00:00
|
|
|
hint_path_start[i]->hint_chain = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
qboolean
|
|
|
|
inback(edict_t *self, edict_t *other)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
vec3_t vec;
|
|
|
|
float dot;
|
|
|
|
vec3_t forward;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self || !other)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
AngleVectors(self->s.angles, forward, NULL, NULL);
|
|
|
|
VectorSubtract(other->s.origin, self->s.origin, vec);
|
|
|
|
VectorNormalize(vec);
|
|
|
|
dot = DotProduct(vec, forward);
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (dot < -0.3)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return true;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
float
|
|
|
|
realrange(edict_t *self, edict_t *other)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
vec3_t dir;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self || !other)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
VectorSubtract(self->s.origin, other->s.origin, dir);
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
return VectorLength(dir);
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
qboolean
|
|
|
|
face_wall(edict_t *self)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
vec3_t pt;
|
|
|
|
vec3_t forward;
|
|
|
|
vec3_t ang;
|
|
|
|
trace_t tr;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
AngleVectors(self->s.angles, forward, NULL, NULL);
|
2009-03-12 20:03:41 +00:00
|
|
|
VectorMA(self->s.origin, 64, forward, pt);
|
2014-01-26 14:53:04 +00:00
|
|
|
tr = gi.trace(self->s.origin, vec3_origin, vec3_origin,
|
|
|
|
pt, self, MASK_MONSTERSOLID);
|
|
|
|
|
|
|
|
if ((tr.fraction < 1) && !tr.allsolid && !tr.startsolid)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
vectoangles2(tr.plane.normal, ang);
|
|
|
|
self->ideal_yaw = ang[YAW] + 180;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
if (self->ideal_yaw > 360)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
self->ideal_yaw -= 360;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
M_ChangeYaw(self);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
badarea_touch(edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
edict_t *
|
|
|
|
SpawnBadArea(vec3_t mins, vec3_t maxs, float lifespan, edict_t *owner)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
edict_t *badarea;
|
2014-01-26 14:53:04 +00:00
|
|
|
vec3_t origin;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!owner)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
VectorAdd(mins, maxs, origin);
|
|
|
|
VectorScale(origin, 0.5, origin);
|
|
|
|
|
|
|
|
VectorSubtract(maxs, origin, maxs);
|
|
|
|
VectorSubtract(mins, origin, mins);
|
|
|
|
|
|
|
|
badarea = G_Spawn();
|
|
|
|
VectorCopy(origin, badarea->s.origin);
|
|
|
|
VectorCopy(maxs, badarea->maxs);
|
|
|
|
VectorCopy(mins, badarea->mins);
|
|
|
|
badarea->touch = badarea_touch;
|
|
|
|
badarea->movetype = MOVETYPE_NONE;
|
|
|
|
badarea->solid = SOLID_TRIGGER;
|
|
|
|
badarea->classname = "bad_area";
|
2014-01-26 14:53:04 +00:00
|
|
|
gi.linkentity(badarea);
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (lifespan)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
badarea->think = G_FreeEdict;
|
|
|
|
badarea->nextthink = level.time + lifespan;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2019-09-23 20:38:56 +00:00
|
|
|
badarea->owner = owner;
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
return badarea;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
edict_t *
|
|
|
|
CheckForBadArea(edict_t *ent)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
int i, num;
|
|
|
|
edict_t *touch[MAX_EDICTS], *hit;
|
|
|
|
vec3_t mins, maxs;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!ent)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
VectorAdd(ent->s.origin, ent->mins, mins);
|
|
|
|
VectorAdd(ent->s.origin, ent->maxs, maxs);
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
num = gi.BoxEdicts(mins, maxs, touch, MAX_EDICTS, AREA_TRIGGERS);
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* be careful, it is possible to have an entity in this
|
|
|
|
list removed before we get to it (killtriggered) */
|
|
|
|
for (i = 0; i < num; i++)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
hit = touch[i];
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!hit->inuse)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
continue;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (hit->touch == badarea_touch)
|
|
|
|
{
|
|
|
|
return hit;
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
qboolean
|
|
|
|
MarkTeslaArea(edict_t *self, edict_t *tesla)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
vec3_t mins, maxs;
|
2009-03-12 20:03:41 +00:00
|
|
|
edict_t *e;
|
|
|
|
edict_t *tail;
|
|
|
|
edict_t *area;
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!tesla || !self)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
area = NULL;
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* make sure this tesla doesn't have a bad area around it already... */
|
2009-03-12 20:03:41 +00:00
|
|
|
e = tesla->teamchain;
|
|
|
|
tail = tesla;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
while (e)
|
|
|
|
{
|
|
|
|
tail = tail->teamchain;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
if (!strcmp(e->classname, "bad_area"))
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = e->teamchain;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* see if we can grab the trigger directly */
|
|
|
|
if (tesla->teamchain && tesla->teamchain->inuse)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
edict_t *trigger;
|
|
|
|
|
|
|
|
trigger = tesla->teamchain;
|
|
|
|
|
|
|
|
VectorCopy(trigger->absmin, mins);
|
|
|
|
VectorCopy(trigger->absmax, maxs);
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (tesla->air_finished)
|
|
|
|
{
|
|
|
|
area = SpawnBadArea(mins, maxs, tesla->air_finished, tesla);
|
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
else
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
|
|
|
area = SpawnBadArea(mins, maxs, tesla->nextthink, tesla);
|
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
/* otherwise we just guess at how long it'll last. */
|
2009-03-12 20:03:41 +00:00
|
|
|
else
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
VectorSet(mins, -TESLA_DAMAGE_RADIUS, -TESLA_DAMAGE_RADIUS,
|
|
|
|
tesla->mins[2]);
|
|
|
|
VectorSet(maxs, TESLA_DAMAGE_RADIUS, TESLA_DAMAGE_RADIUS, TESLA_DAMAGE_RADIUS);
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
area = SpawnBadArea(mins, maxs, 30, tesla);
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if we spawned a bad area, then link it to the tesla */
|
|
|
|
if (area)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
tail->teamchain = area;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
PredictAim(edict_t *target, vec3_t start, float bolt_speed, qboolean eye_height,
|
|
|
|
float offset, vec3_t aimdir, vec3_t aimpoint)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
vec3_t dir, vec;
|
|
|
|
float dist, time;
|
|
|
|
|
|
|
|
if (!target || !target->inuse)
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
VectorCopy(vec3_origin, aimdir);
|
2009-03-12 20:03:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VectorSubtract(target->s.origin, start, dir);
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (eye_height)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
dir[2] += target->viewheight;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
dist = VectorLength(dir);
|
|
|
|
time = dist / bolt_speed;
|
|
|
|
|
|
|
|
VectorMA(target->s.origin, time - offset, target->velocity, vec);
|
|
|
|
|
|
|
|
if (eye_height)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
vec[2] += target->viewheight;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
if (aimdir)
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
VectorSubtract(vec, start, aimdir);
|
|
|
|
VectorNormalize(aimdir);
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (aimpoint)
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
VectorCopy(vec, aimpoint);
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
qboolean
|
|
|
|
below(edict_t *self, edict_t *other)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
vec3_t vec;
|
|
|
|
float dot;
|
|
|
|
vec3_t down;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self || !other)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
VectorSubtract(other->s.origin, self->s.origin, vec);
|
|
|
|
VectorNormalize(vec);
|
|
|
|
VectorSet(down, 0, 0, -1);
|
|
|
|
dot = DotProduct(vec, down);
|
|
|
|
|
|
|
|
if (dot > 0.95) /* 18 degree arc below */
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return true;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
drawbbox(edict_t *self)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
int lines[4][3] = {
|
2009-03-12 20:03:41 +00:00
|
|
|
{1, 2, 4},
|
|
|
|
{1, 2, 7},
|
|
|
|
{1, 4, 5},
|
|
|
|
{2, 4, 7}
|
|
|
|
};
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
int starts[4] = {0, 3, 5, 6};
|
|
|
|
|
|
|
|
vec3_t pt[8];
|
|
|
|
int i, j, k;
|
|
|
|
vec3_t coords[2];
|
|
|
|
vec3_t newbox;
|
2014-01-26 14:53:04 +00:00
|
|
|
vec3_t f, r, u, dir;
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
VectorCopy(self->absmin, coords[0]);
|
|
|
|
VectorCopy(self->absmax, coords[1]);
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
for (i = 0; i <= 1; i++)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
for (j = 0; j <= 1; j++)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
for (k = 0; k <= 1; k++)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
pt[4 * i + 2 * j + k][0] = coords[i][0];
|
|
|
|
pt[4 * i + 2 * j + k][1] = coords[j][1];
|
|
|
|
pt[4 * i + 2 * j + k][2] = coords[k][2];
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
for (i = 0; i <= 3; i++)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
for (j = 0; j <= 2; j++)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
gi.WriteByte(svc_temp_entity);
|
|
|
|
gi.WriteByte(TE_DEBUGTRAIL);
|
|
|
|
gi.WritePosition(pt[starts[i]]);
|
|
|
|
gi.WritePosition(pt[lines[i][j]]);
|
|
|
|
gi.multicast(pt[starts[i]], MULTICAST_ALL);
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
vectoangles2(self->s.angles, dir);
|
|
|
|
AngleVectors(dir, f, r, u);
|
|
|
|
|
|
|
|
VectorMA(self->s.origin, 50, f, newbox);
|
|
|
|
gi.WriteByte(svc_temp_entity);
|
|
|
|
gi.WriteByte(TE_DEBUGTRAIL);
|
|
|
|
gi.WritePosition(self->s.origin);
|
|
|
|
gi.WritePosition(newbox);
|
|
|
|
gi.multicast(self->s.origin, MULTICAST_PVS);
|
|
|
|
VectorClear(newbox);
|
|
|
|
|
|
|
|
VectorMA(self->s.origin, 50, r, newbox);
|
|
|
|
gi.WriteByte(svc_temp_entity);
|
|
|
|
gi.WriteByte(TE_DEBUGTRAIL);
|
|
|
|
gi.WritePosition(self->s.origin);
|
|
|
|
gi.WritePosition(newbox);
|
|
|
|
gi.multicast(self->s.origin, MULTICAST_PVS);
|
|
|
|
VectorClear(newbox);
|
|
|
|
|
|
|
|
VectorMA(self->s.origin, 50, u, newbox);
|
|
|
|
gi.WriteByte(svc_temp_entity);
|
|
|
|
gi.WriteByte(TE_DEBUGTRAIL);
|
|
|
|
gi.WritePosition(self->s.origin);
|
|
|
|
gi.WritePosition(newbox);
|
|
|
|
gi.multicast(self->s.origin, MULTICAST_PVS);
|
|
|
|
VectorClear(newbox);
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
M_MonsterDodge(edict_t *self, edict_t *attacker, float eta, trace_t *tr)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
float r = random();
|
|
|
|
float height;
|
|
|
|
qboolean ducker = false, dodger = false;
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self || !attacker || !tr)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
|
|
|
/* this needs to be here since this can be
|
2014-01-26 14:53:04 +00:00
|
|
|
called after the monster has "died" */
|
2009-03-12 20:03:41 +00:00
|
|
|
if (self->health < 1)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
if ((self->monsterinfo.duck) && (self->monsterinfo.unduck))
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
ducker = true;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((self->monsterinfo.sidestep) &&
|
|
|
|
!(self->monsterinfo.aiflags & AI_STAND_GROUND))
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
dodger = true;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
if ((!ducker) && (!dodger))
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
if (!self->enemy)
|
|
|
|
{
|
|
|
|
self->enemy = attacker;
|
2014-01-26 14:53:04 +00:00
|
|
|
FoundTarget(self);
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((eta < 0.1) || (eta > 5))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* skill level determination.. */
|
|
|
|
if (r > (0.25 * ((skill->value) + 1)))
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ducker)
|
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
height = self->absmax[2] - 32 - 1; /* the -1 is because the absmax is s.origin + maxs + 1 */
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
if ((!dodger) && ((tr->endpos[2] <= height) || (self->monsterinfo.aiflags & AI_DUCKED)))
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
else
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
height = self->absmax[2];
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
if (dodger)
|
|
|
|
{
|
2014-02-22 12:20:22 +00:00
|
|
|
/* if we're already dodging, just finish
|
2014-01-26 14:53:04 +00:00
|
|
|
the sequence, i.e. don't do anything else */
|
2009-03-12 20:03:41 +00:00
|
|
|
if (self->monsterinfo.aiflags & AI_DODGING)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if we're ducking already, or the shot is at our knees */
|
2009-03-12 20:03:41 +00:00
|
|
|
if ((tr->endpos[2] <= height) || (self->monsterinfo.aiflags & AI_DUCKED))
|
|
|
|
{
|
|
|
|
vec3_t right, diff;
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
AngleVectors(self->s.angles, NULL, right, NULL);
|
|
|
|
VectorSubtract(tr->endpos, self->s.origin, diff);
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (DotProduct(right, diff) < 0)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
self->monsterinfo.lefty = 0;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
self->monsterinfo.lefty = 1;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if we are currently ducked, unduck */
|
2009-03-12 20:03:41 +00:00
|
|
|
if ((ducker) && (self->monsterinfo.aiflags & AI_DUCKED))
|
|
|
|
{
|
|
|
|
self->monsterinfo.unduck(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
self->monsterinfo.aiflags |= AI_DODGING;
|
|
|
|
self->monsterinfo.attack_state = AS_SLIDING;
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* call the monster specific code here */
|
|
|
|
self->monsterinfo.sidestep(self);
|
2009-03-12 20:03:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ducker)
|
|
|
|
{
|
|
|
|
if (self->monsterinfo.next_duck_time > level.time)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
monster_done_dodge(self);
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* set this prematurely; it doesn't hurt, and prevents extra iterations */
|
|
|
|
self->monsterinfo.aiflags |= AI_DUCKED;
|
|
|
|
self->monsterinfo.duck(self, eta);
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
monster_duck_down(edict_t *self)
|
2014-02-22 12:20:22 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
self->monsterinfo.aiflags |= AI_DUCKED;
|
|
|
|
self->maxs[2] = self->monsterinfo.base_height - 32;
|
|
|
|
self->takedamage = DAMAGE_YES;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (self->monsterinfo.duck_wait_time < level.time)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
self->monsterinfo.duck_wait_time = level.time + 1;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gi.linkentity(self);
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
monster_duck_hold(edict_t *self)
|
2014-02-22 12:20:22 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (level.time >= self->monsterinfo.duck_wait_time)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
self->monsterinfo.aiflags &= ~AI_HOLD_FRAME;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
else
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
self->monsterinfo.aiflags |= AI_HOLD_FRAME;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
monster_duck_up(edict_t *self)
|
2014-02-22 12:20:22 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
self->monsterinfo.aiflags &= ~AI_DUCKED;
|
|
|
|
self->maxs[2] = self->monsterinfo.base_height;
|
|
|
|
self->takedamage = DAMAGE_AIM;
|
|
|
|
self->monsterinfo.next_duck_time = level.time + DUCK_INTERVAL;
|
2014-01-26 14:53:04 +00:00
|
|
|
gi.linkentity(self);
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
qboolean
|
|
|
|
has_valid_enemy(edict_t *self)
|
2014-02-22 12:20:22 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!self->enemy)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
if (!self->enemy->inuse)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
if (self->enemy->health < 1)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return false;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
TargetTesla(edict_t *self, edict_t *tesla)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
if ((!self) || (!tesla))
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* medic bails on healing things */
|
2009-03-12 20:03:41 +00:00
|
|
|
if (self->monsterinfo.aiflags & AI_MEDIC)
|
|
|
|
{
|
|
|
|
if (self->enemy)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
cleanupHealTarget(self->enemy);
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
self->monsterinfo.aiflags &= ~AI_MEDIC;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* store the player enemy in case we lose track of him. */
|
|
|
|
if (self->enemy && self->enemy->client)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
self->monsterinfo.last_player_enemy = self->enemy;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
if (self->enemy != tesla)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
self->oldenemy = self->enemy;
|
|
|
|
self->enemy = tesla;
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
if (self->monsterinfo.attack)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
if (self->health <= 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
self->monsterinfo.attack(self);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FoundTarget(self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
edict_t *
|
|
|
|
PickCoopTarget(edict_t *self)
|
2014-02-22 12:20:22 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
2014-08-03 09:34:06 +00:00
|
|
|
return NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* no more than 4 players in coop, so.. */
|
2009-03-12 20:03:41 +00:00
|
|
|
edict_t *targets[4];
|
2014-01-26 14:53:04 +00:00
|
|
|
int num_targets = 0, targetID;
|
2009-03-12 20:03:41 +00:00
|
|
|
edict_t *ent;
|
2014-01-26 14:53:04 +00:00
|
|
|
int player;
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if we're not in coop, this is a noop */
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!coop || !coop->value)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
memset(targets, 0, 4 * sizeof(edict_t *));
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
for (player = 1; player <= game.maxclients; player++)
|
|
|
|
{
|
|
|
|
ent = &g_edicts[player];
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!ent->inuse)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
continue;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!ent->client)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
continue;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (visible(self, ent))
|
|
|
|
{
|
|
|
|
targets[num_targets++] = ent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!num_targets)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return NULL;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* get a number from 0 to (num_targets-1) */
|
2009-03-12 20:03:41 +00:00
|
|
|
targetID = (random() * (float)num_targets);
|
2014-01-26 14:53:04 +00:00
|
|
|
|
|
|
|
/* just in case we got a 1.0 from random */
|
2009-03-12 20:03:41 +00:00
|
|
|
if (targetID == num_targets)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
targetID--;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
return targets[targetID];
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
int
|
|
|
|
CountPlayers(void)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
edict_t *ent;
|
2014-01-26 14:53:04 +00:00
|
|
|
int count = 0;
|
|
|
|
int player;
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
/* if we're not in coop, this is a noop */
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!coop || !coop->value)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return 1;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
for (player = 1; player <= game.maxclients; player++)
|
|
|
|
{
|
|
|
|
ent = &g_edicts[player];
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!ent->inuse)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
continue;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!ent->client)
|
2014-01-26 14:53:04 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
continue;
|
2014-01-26 14:53:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
count++;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
void
|
|
|
|
monster_jump_start(edict_t *self)
|
2014-02-22 12:20:22 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
self->timestamp = level.time;
|
|
|
|
}
|
|
|
|
|
2014-01-26 14:53:04 +00:00
|
|
|
qboolean
|
|
|
|
monster_jump_finished(edict_t *self)
|
2014-02-22 12:20:22 +00:00
|
|
|
{
|
2014-01-26 14:53:04 +00:00
|
|
|
if (!self)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-22 12:20:22 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if ((level.time - self->timestamp) > 3)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-26 14:53:04 +00:00
|
|
|
|
2009-03-31 09:18:35 +00:00
|
|
|
return false;
|
2009-03-12 20:03:41 +00:00
|
|
|
}
|