mirror of
https://github.com/yquake2/xatrix.git
synced 2024-11-10 06:42:22 +00:00
Cleanup g_chase.c and add sanity checks
This commit is contained in:
parent
f0a577d6b7
commit
848fbea4ce
2 changed files with 124 additions and 25 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
/* =======================================================================
|
||||||
|
*
|
||||||
|
* The basic AI functions like enemy detection, attacking and so on.
|
||||||
|
*
|
||||||
|
* =======================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
#include "header/local.h"
|
#include "header/local.h"
|
||||||
|
|
||||||
qboolean FindTarget(edict_t *self);
|
qboolean FindTarget(edict_t *self);
|
||||||
|
|
142
src/g_chase.c
142
src/g_chase.c
|
@ -1,6 +1,15 @@
|
||||||
|
/*
|
||||||
|
* =======================================================================
|
||||||
|
*
|
||||||
|
* Chase cam. Only used in multiplayer mode.
|
||||||
|
*
|
||||||
|
* =======================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
#include "header/local.h"
|
#include "header/local.h"
|
||||||
|
|
||||||
void UpdateChaseCam(edict_t *ent)
|
void
|
||||||
|
UpdateChaseCam(edict_t *ent)
|
||||||
{
|
{
|
||||||
vec3_t o, ownerv, goal;
|
vec3_t o, ownerv, goal;
|
||||||
edict_t *targ;
|
edict_t *targ;
|
||||||
|
@ -10,12 +19,20 @@ void UpdateChaseCam(edict_t *ent)
|
||||||
vec3_t oldgoal;
|
vec3_t oldgoal;
|
||||||
vec3_t angles;
|
vec3_t angles;
|
||||||
|
|
||||||
// is our chase target gone?
|
if (!ent)
|
||||||
if (!ent->client->chase_target->inuse
|
{
|
||||||
|| ent->client->chase_target->client->resp.spectator) {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* is our chase target gone? */
|
||||||
|
if (!ent->client->chase_target->inuse ||
|
||||||
|
ent->client->chase_target->client->resp.spectator)
|
||||||
|
{
|
||||||
edict_t *old = ent->client->chase_target;
|
edict_t *old = ent->client->chase_target;
|
||||||
ChaseNext(ent);
|
ChaseNext(ent);
|
||||||
if (ent->client->chase_target == old) {
|
|
||||||
|
if (ent->client->chase_target == old)
|
||||||
|
{
|
||||||
ent->client->chase_target = NULL;
|
ent->client->chase_target = NULL;
|
||||||
ent->client->ps.pmove.pm_flags &= ~PMF_NO_PREDICTION;
|
ent->client->ps.pmove.pm_flags &= ~PMF_NO_PREDICTION;
|
||||||
return;
|
return;
|
||||||
|
@ -30,18 +47,26 @@ void UpdateChaseCam(edict_t *ent)
|
||||||
ownerv[2] += targ->viewheight;
|
ownerv[2] += targ->viewheight;
|
||||||
|
|
||||||
VectorCopy(targ->client->v_angle, angles);
|
VectorCopy(targ->client->v_angle, angles);
|
||||||
|
|
||||||
if (angles[PITCH] > 56)
|
if (angles[PITCH] > 56)
|
||||||
|
{
|
||||||
angles[PITCH] = 56;
|
angles[PITCH] = 56;
|
||||||
AngleVectors (angles, forward, right, NULL);
|
}
|
||||||
|
|
||||||
|
AngleVectors(angles, forward, right, NULL);
|
||||||
VectorNormalize(forward);
|
VectorNormalize(forward);
|
||||||
VectorMA(ownerv, -30, forward, o);
|
VectorMA(ownerv, -30, forward, o);
|
||||||
|
|
||||||
if (o[2] < targ->s.origin[2] + 20)
|
if (o[2] < targ->s.origin[2] + 20)
|
||||||
|
{
|
||||||
o[2] = targ->s.origin[2] + 20;
|
o[2] = targ->s.origin[2] + 20;
|
||||||
|
}
|
||||||
|
|
||||||
// jump animation lifts
|
/* jump animation lifts */
|
||||||
if (!targ->groundentity)
|
if (!targ->groundentity)
|
||||||
|
{
|
||||||
o[2] += 16;
|
o[2] += 16;
|
||||||
|
}
|
||||||
|
|
||||||
trace = gi.trace(ownerv, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
|
trace = gi.trace(ownerv, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
|
||||||
|
|
||||||
|
@ -49,11 +74,13 @@ void UpdateChaseCam(edict_t *ent)
|
||||||
|
|
||||||
VectorMA(goal, 2, forward, goal);
|
VectorMA(goal, 2, forward, goal);
|
||||||
|
|
||||||
// pad for floors and ceilings
|
/* pad for floors and ceilings */
|
||||||
VectorCopy(goal, o);
|
VectorCopy(goal, o);
|
||||||
o[2] += 6;
|
o[2] += 6;
|
||||||
trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
|
trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
|
||||||
if (trace.fraction < 1) {
|
|
||||||
|
if (trace.fraction < 1)
|
||||||
|
{
|
||||||
VectorCopy(trace.endpos, goal);
|
VectorCopy(trace.endpos, goal);
|
||||||
goal[2] -= 6;
|
goal[2] -= 6;
|
||||||
}
|
}
|
||||||
|
@ -61,25 +88,38 @@ void UpdateChaseCam(edict_t *ent)
|
||||||
VectorCopy(goal, o);
|
VectorCopy(goal, o);
|
||||||
o[2] -= 6;
|
o[2] -= 6;
|
||||||
trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
|
trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
|
||||||
if (trace.fraction < 1) {
|
|
||||||
|
if (trace.fraction < 1)
|
||||||
|
{
|
||||||
VectorCopy(trace.endpos, goal);
|
VectorCopy(trace.endpos, goal);
|
||||||
goal[2] += 6;
|
goal[2] += 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targ->deadflag)
|
if (targ->deadflag)
|
||||||
|
{
|
||||||
ent->client->ps.pmove.pm_type = PM_DEAD;
|
ent->client->ps.pmove.pm_type = PM_DEAD;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
ent->client->ps.pmove.pm_type = PM_FREEZE;
|
ent->client->ps.pmove.pm_type = PM_FREEZE;
|
||||||
|
}
|
||||||
|
|
||||||
VectorCopy(goal, ent->s.origin);
|
VectorCopy(goal, ent->s.origin);
|
||||||
for (i=0 ; i<3 ; i++)
|
|
||||||
ent->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(targ->client->v_angle[i] - ent->client->resp.cmd_angles[i]);
|
|
||||||
|
|
||||||
if (targ->deadflag) {
|
for (i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
ent->client->ps.pmove.delta_angles[i] = ANGLE2SHORT(
|
||||||
|
targ->client->v_angle[i] - ent->client->resp.cmd_angles[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targ->deadflag)
|
||||||
|
{
|
||||||
ent->client->ps.viewangles[ROLL] = 40;
|
ent->client->ps.viewangles[ROLL] = 40;
|
||||||
ent->client->ps.viewangles[PITCH] = -15;
|
ent->client->ps.viewangles[PITCH] = -15;
|
||||||
ent->client->ps.viewangles[YAW] = targ->client->killer_yaw;
|
ent->client->ps.viewangles[YAW] = targ->client->killer_yaw;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
VectorCopy(targ->client->v_angle, ent->client->ps.viewangles);
|
VectorCopy(targ->client->v_angle, ent->client->ps.viewangles);
|
||||||
VectorCopy(targ->client->v_angle, ent->client->v_angle);
|
VectorCopy(targ->client->v_angle, ent->client->v_angle);
|
||||||
}
|
}
|
||||||
|
@ -89,68 +129,120 @@ void UpdateChaseCam(edict_t *ent)
|
||||||
gi.linkentity(ent);
|
gi.linkentity(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChaseNext(edict_t *ent)
|
void
|
||||||
|
ChaseNext(edict_t *ent)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
edict_t *e;
|
edict_t *e;
|
||||||
|
|
||||||
if (!ent->client->chase_target)
|
if (!ent)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ent->client->chase_target)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
i = ent->client->chase_target - g_edicts;
|
i = ent->client->chase_target - g_edicts;
|
||||||
do {
|
|
||||||
|
do
|
||||||
|
{
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
if (i > maxclients->value)
|
if (i > maxclients->value)
|
||||||
|
{
|
||||||
i = 1;
|
i = 1;
|
||||||
|
}
|
||||||
|
|
||||||
e = g_edicts + i;
|
e = g_edicts + i;
|
||||||
|
|
||||||
if (!e->inuse)
|
if (!e->inuse)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!e->client->resp.spectator)
|
if (!e->client->resp.spectator)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
} while (e != ent->client->chase_target);
|
}
|
||||||
|
}
|
||||||
|
while (e != ent->client->chase_target);
|
||||||
|
|
||||||
ent->client->chase_target = e;
|
ent->client->chase_target = e;
|
||||||
ent->client->update_chase = true;
|
ent->client->update_chase = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChasePrev(edict_t *ent)
|
void
|
||||||
|
ChasePrev(edict_t *ent)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
edict_t *e;
|
edict_t *e;
|
||||||
|
|
||||||
if (!ent->client->chase_target)
|
if (!ent)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ent->client->chase_target)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
i = ent->client->chase_target - g_edicts;
|
i = ent->client->chase_target - g_edicts;
|
||||||
do {
|
|
||||||
|
do
|
||||||
|
{
|
||||||
i--;
|
i--;
|
||||||
|
|
||||||
if (i < 1)
|
if (i < 1)
|
||||||
|
{
|
||||||
i = maxclients->value;
|
i = maxclients->value;
|
||||||
|
}
|
||||||
|
|
||||||
e = g_edicts + i;
|
e = g_edicts + i;
|
||||||
|
|
||||||
if (!e->inuse)
|
if (!e->inuse)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!e->client->resp.spectator)
|
if (!e->client->resp.spectator)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
} while (e != ent->client->chase_target);
|
}
|
||||||
|
}
|
||||||
|
while (e != ent->client->chase_target);
|
||||||
|
|
||||||
ent->client->chase_target = e;
|
ent->client->chase_target = e;
|
||||||
ent->client->update_chase = true;
|
ent->client->update_chase = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetChaseTarget(edict_t *ent)
|
void
|
||||||
|
GetChaseTarget(edict_t *ent)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
edict_t *other;
|
edict_t *other;
|
||||||
|
|
||||||
for (i = 1; i <= maxclients->value; i++) {
|
if (!ent)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 1; i <= maxclients->value; i++)
|
||||||
|
{
|
||||||
other = g_edicts + i;
|
other = g_edicts + i;
|
||||||
if (other->inuse && !other->client->resp.spectator) {
|
|
||||||
|
if (other->inuse && !other->client->resp.spectator)
|
||||||
|
{
|
||||||
ent->client->chase_target = other;
|
ent->client->chase_target = other;
|
||||||
ent->client->update_chase = true;
|
ent->client->update_chase = true;
|
||||||
UpdateChaseCam(ent);
|
UpdateChaseCam(ent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gi.centerprintf(ent, "No other players to chase.");
|
gi.centerprintf(ent, "No other players to chase.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue