rogue/src/g_chase.c

245 lines
3.7 KiB
C
Raw Normal View History

/*
* =======================================================================
*
* 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
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;
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);
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);
2009-03-12 20:03:41 +00:00
if (angles[PITCH] > 56)
{
2009-03-12 20:03:41 +00:00
angles[PITCH] = 56;
}
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)
{
2009-03-12 20:03:41 +00:00
o[2] = targ->s.origin[2] + 20;
}
2009-03-12 20:03:41 +00:00
/* jump animation lifts */
2009-03-12 20:03:41 +00:00
if (!targ->groundentity)
{
2009-03-12 20:03:41 +00:00
o[2] += 16;
}
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);
/* 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);
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);
if (trace.fraction < 1)
{
2009-03-12 20:03:41 +00:00
VectorCopy(trace.endpos, goal);
goal[2] += 6;
}
if (targ->deadflag)
{
2009-03-12 20:03:41 +00:00
ent->client->ps.pmove.pm_type = PM_DEAD;
}
2009-03-12 20:03:41 +00:00
else
{
2009-03-12 20:03:41 +00:00
ent->client->ps.pmove.pm_type = PM_FREEZE;
}
2009-03-12 20:03:41 +00:00
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)
{
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;
}
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);
}
void
ChaseNext(edict_t *ent)
2009-03-12 20:03:41 +00:00
{
int i;
edict_t *e;
if (!ent)
{
return;
}
2009-03-12 20:03:41 +00:00
if (!ent->client->chase_target)
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
i = ent->client->chase_target - g_edicts;
do
{
2009-03-12 20:03:41 +00:00
i++;
2009-03-12 20:03:41 +00:00
if (i > maxclients->value)
{
2009-03-12 20:03:41 +00:00
i = 1;
}
2009-03-12 20:03:41 +00:00
e = g_edicts + i;
2009-03-12 20:03:41 +00:00
if (!e->inuse)
{
2009-03-12 20:03:41 +00:00
continue;
}
2009-03-12 20:03:41 +00:00
if (!e->client->resp.spectator)
{
2009-03-12 20:03:41 +00:00
break;
}
}
while (e != ent->client->chase_target);
2009-03-12 20:03:41 +00:00
ent->client->chase_target = e;
ent->client->update_chase = true;
}
void
ChasePrev(edict_t *ent)
2009-03-12 20:03:41 +00:00
{
int i;
edict_t *e;
if (!ent)
{
return;
}
2009-03-12 20:03:41 +00:00
if (!ent->client->chase_target)
{
2009-03-12 20:03:41 +00:00
return;
}
2009-03-12 20:03:41 +00:00
i = ent->client->chase_target - g_edicts;
do
{
2009-03-12 20:03:41 +00:00
i--;
2009-03-12 20:03:41 +00:00
if (i < 1)
{
2009-03-12 20:03:41 +00:00
i = maxclients->value;
}
2009-03-12 20:03:41 +00:00
e = g_edicts + i;
2009-03-12 20:03:41 +00:00
if (!e->inuse)
{
2009-03-12 20:03:41 +00:00
continue;
}
2009-03-12 20:03:41 +00:00
if (!e->client->resp.spectator)
{
2009-03-12 20:03:41 +00:00
break;
}
}
while (e != ent->client->chase_target);
2009-03-12 20:03:41 +00:00
ent->client->chase_target = e;
ent->client->update_chase = true;
}
void
GetChaseTarget(edict_t *ent)
2009-03-12 20:03:41 +00:00
{
int i;
edict_t *other;
if (!ent)
{
return;
}
for (i = 1; i <= maxclients->value; i++)
{
2009-03-12 20:03:41 +00:00
other = g_edicts + i;
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;
}
}
2009-03-12 20:03:41 +00:00
gi.centerprintf(ent, "No other players to chase.");
}