2013-05-01 08:28:42 +00:00
|
|
|
/*
|
|
|
|
* =======================================================================
|
|
|
|
*
|
|
|
|
* Chase cam. Only used in multiplayer mode.
|
|
|
|
*
|
|
|
|
* =======================================================================
|
|
|
|
*/
|
|
|
|
|
2011-10-11 11:40:43 +00:00
|
|
|
#include "header/local.h"
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2013-05-01 08:28:42 +00:00
|
|
|
void
|
|
|
|
UpdateChaseCam(edict_t *ent)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
vec3_t o, ownerv, goal;
|
|
|
|
edict_t *targ;
|
|
|
|
vec3_t forward, right;
|
|
|
|
trace_t trace;
|
|
|
|
int i;
|
|
|
|
vec3_t angles;
|
2013-05-01 08:28:42 +00:00
|
|
|
|
|
|
|
if (!ent)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* is our chase target gone? */
|
|
|
|
if (!ent->client->chase_target->inuse ||
|
|
|
|
ent->client->chase_target->client->resp.spectator)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
edict_t *old = ent->client->chase_target;
|
|
|
|
ChaseNext(ent);
|
2013-05-01 08:28:42 +00:00
|
|
|
|
|
|
|
if (ent->client->chase_target == old)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
ent->client->chase_target = NULL;
|
|
|
|
ent->client->ps.pmove.pm_flags &= ~PMF_NO_PREDICTION;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
targ = ent->client->chase_target;
|
|
|
|
|
|
|
|
VectorCopy(targ->s.origin, ownerv);
|
|
|
|
ownerv[2] += targ->viewheight;
|
|
|
|
|
|
|
|
VectorCopy(targ->client->v_angle, angles);
|
2013-05-01 08:28:42 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (angles[PITCH] > 56)
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
angles[PITCH] = 56;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AngleVectors(angles, forward, right, NULL);
|
2009-03-12 20:03:41 +00:00
|
|
|
VectorNormalize(forward);
|
|
|
|
VectorMA(ownerv, -30, forward, o);
|
|
|
|
|
|
|
|
if (o[2] < targ->s.origin[2] + 20)
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
o[2] = targ->s.origin[2] + 20;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
2013-05-01 08:28:42 +00:00
|
|
|
/* jump animation lifts */
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!targ->groundentity)
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
o[2] += 16;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
trace = gi.trace(ownerv, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
|
|
|
|
|
|
|
|
VectorCopy(trace.endpos, goal);
|
|
|
|
|
|
|
|
VectorMA(goal, 2, forward, goal);
|
|
|
|
|
2013-05-01 08:28:42 +00:00
|
|
|
/* pad for floors and ceilings */
|
2009-03-12 20:03:41 +00:00
|
|
|
VectorCopy(goal, o);
|
|
|
|
o[2] += 6;
|
|
|
|
trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
|
2013-05-01 08:28:42 +00:00
|
|
|
|
|
|
|
if (trace.fraction < 1)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
VectorCopy(trace.endpos, goal);
|
|
|
|
goal[2] -= 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
VectorCopy(goal, o);
|
|
|
|
o[2] -= 6;
|
|
|
|
trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
|
2013-05-01 08:28:42 +00:00
|
|
|
|
|
|
|
if (trace.fraction < 1)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
VectorCopy(trace.endpos, goal);
|
|
|
|
goal[2] += 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (targ->deadflag)
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
ent->client->ps.pmove.pm_type = PM_DEAD;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
else
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
ent->client->ps.pmove.pm_type = PM_FREEZE;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
VectorCopy(goal, ent->s.origin);
|
|
|
|
|
2013-05-01 08:28:42 +00:00
|
|
|
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)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
ent->client->ps.viewangles[ROLL] = 40;
|
|
|
|
ent->client->ps.viewangles[PITCH] = -15;
|
|
|
|
ent->client->ps.viewangles[YAW] = targ->client->killer_yaw;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
VectorCopy(targ->client->v_angle, ent->client->ps.viewangles);
|
|
|
|
VectorCopy(targ->client->v_angle, ent->client->v_angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
ent->viewheight = 0;
|
|
|
|
ent->client->ps.pmove.pm_flags |= PMF_NO_PREDICTION;
|
|
|
|
gi.linkentity(ent);
|
|
|
|
}
|
|
|
|
|
2013-05-01 08:28:42 +00:00
|
|
|
void
|
|
|
|
ChaseNext(edict_t *ent)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
edict_t *e;
|
2013-05-01 08:28:42 +00:00
|
|
|
|
|
|
|
if (!ent)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!ent->client->chase_target)
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
i = ent->client->chase_target - g_edicts;
|
2013-05-01 08:28:42 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
i++;
|
2013-05-01 08:28:42 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (i > maxclients->value)
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
i = 1;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = g_edicts + i;
|
2013-05-01 08:28:42 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!e->inuse)
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
continue;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!e->client->resp.spectator)
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
break;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while (e != ent->client->chase_target);
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
ent->client->chase_target = e;
|
|
|
|
ent->client->update_chase = true;
|
|
|
|
}
|
|
|
|
|
2013-05-01 08:28:42 +00:00
|
|
|
void
|
|
|
|
ChasePrev(edict_t *ent)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
edict_t *e;
|
2013-05-01 08:28:42 +00:00
|
|
|
|
|
|
|
if (!ent)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!ent->client->chase_target)
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
return;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
i = ent->client->chase_target - g_edicts;
|
2013-05-01 08:28:42 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
i--;
|
2013-05-01 08:28:42 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (i < 1)
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
i = maxclients->value;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
e = g_edicts + i;
|
2013-05-01 08:28:42 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!e->inuse)
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
continue;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
if (!e->client->resp.spectator)
|
2013-05-01 08:28:42 +00:00
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
break;
|
2013-05-01 08:28:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while (e != ent->client->chase_target);
|
2009-03-12 20:03:41 +00:00
|
|
|
|
|
|
|
ent->client->chase_target = e;
|
|
|
|
ent->client->update_chase = true;
|
|
|
|
}
|
|
|
|
|
2013-05-01 08:28:42 +00:00
|
|
|
void
|
|
|
|
GetChaseTarget(edict_t *ent)
|
2009-03-12 20:03:41 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
edict_t *other;
|
2013-05-01 08:28:42 +00:00
|
|
|
|
|
|
|
if (!ent)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i <= maxclients->value; i++)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
other = g_edicts + i;
|
2013-05-01 08:28:42 +00:00
|
|
|
|
|
|
|
if (other->inuse && !other->client->resp.spectator)
|
|
|
|
{
|
2009-03-12 20:03:41 +00:00
|
|
|
ent->client->chase_target = other;
|
|
|
|
ent->client->update_chase = true;
|
|
|
|
UpdateChaseCam(ent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-05-01 08:28:42 +00:00
|
|
|
|
2009-03-12 20:03:41 +00:00
|
|
|
gi.centerprintf(ent, "No other players to chase.");
|
|
|
|
}
|