ctf/src/g_chase.c

211 lines
3.9 KiB
C
Raw Normal View History

2011-10-09 16:11:15 +00:00
/*
2011-10-13 06:26:54 +00:00
* Copyright (C) 1997-2001 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.
*
* =======================================================================
*
* Chase cam.
*
* =======================================================================
*/
2011-10-09 16:11:15 +00:00
2011-10-11 06:57:12 +00:00
#include "header/local.h"
2011-10-09 16:11:15 +00:00
2011-10-13 06:26:54 +00:00
void
UpdateChaseCam(edict_t *ent)
2011-10-09 16:11:15 +00:00
{
vec3_t o, ownerv, goal;
edict_t *targ;
vec3_t forward, right;
trace_t trace;
int i;
vec3_t angles;
2011-10-13 06:26:54 +00:00
/* is our chase target gone? */
if (!ent->client->chase_target->inuse)
{
2011-10-09 16:11:15 +00:00
ent->client->chase_target = NULL;
return;
}
targ = ent->client->chase_target;
VectorCopy(targ->s.origin, ownerv);
ownerv[2] += targ->viewheight;
VectorCopy(targ->client->v_angle, angles);
2011-10-13 06:26:54 +00:00
2011-10-09 16:11:15 +00:00
if (angles[PITCH] > 56)
2011-10-13 06:26:54 +00:00
{
2011-10-09 16:11:15 +00:00
angles[PITCH] = 56;
2011-10-13 06:26:54 +00:00
}
AngleVectors(angles, forward, right, NULL);
2011-10-09 16:11:15 +00:00
VectorNormalize(forward);
VectorMA(ownerv, -30, forward, o);
if (o[2] < targ->s.origin[2] + 20)
2011-10-13 06:26:54 +00:00
{
2011-10-09 16:11:15 +00:00
o[2] = targ->s.origin[2] + 20;
2011-10-13 06:26:54 +00:00
}
2011-10-09 16:11:15 +00:00
2011-10-13 06:26:54 +00:00
/* jump animation lifts */
2011-10-09 16:11:15 +00:00
if (!targ->groundentity)
2011-10-13 06:26:54 +00:00
{
2011-10-09 16:11:15 +00:00
o[2] += 16;
2011-10-13 06:26:54 +00:00
}
2011-10-09 16:11:15 +00:00
trace = gi.trace(ownerv, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
VectorCopy(trace.endpos, goal);
VectorMA(goal, 2, forward, goal);
2011-10-13 06:26:54 +00:00
/* pad for floors and ceilings */
2011-10-09 16:11:15 +00:00
VectorCopy(goal, o);
o[2] += 6;
trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
2011-10-13 06:26:54 +00:00
if (trace.fraction < 1)
{
2011-10-09 16:11:15 +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);
2011-10-13 06:26:54 +00:00
if (trace.fraction < 1)
{
2011-10-09 16:11:15 +00:00
VectorCopy(trace.endpos, goal);
goal[2] += 6;
}
ent->client->ps.pmove.pm_type = PM_FREEZE;
VectorCopy(goal, ent->s.origin);
2011-10-13 06:26:54 +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]);
}
2011-10-09 16:11:15 +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);
if ((!ent->client->showscores && !ent->client->menu &&
2011-10-13 06:26:54 +00:00
!ent->client->showinventory && !ent->client->showhelp &&
!(level.framenum & 31)) || ent->client->update_chase)
{
2011-10-09 16:11:15 +00:00
char s[1024];
ent->client->update_chase = false;
sprintf(s, "xv 0 yb -68 string2 \"Chasing %s\"",
2011-10-13 06:26:54 +00:00
targ->client->pers.netname);
gi.WriteByte(svc_layout);
gi.WriteString(s);
2011-10-09 16:11:15 +00:00
gi.unicast(ent, false);
}
}
2011-10-13 06:26:54 +00:00
void
ChaseNext(edict_t *ent)
2011-10-09 16:11:15 +00:00
{
int i;
edict_t *e;
if (!ent->client->chase_target)
2011-10-13 06:26:54 +00:00
{
2011-10-09 16:11:15 +00:00
return;
2011-10-13 06:26:54 +00:00
}
2011-10-09 16:11:15 +00:00
i = ent->client->chase_target - g_edicts;
2011-10-13 06:26:54 +00:00
do
{
2011-10-09 16:11:15 +00:00
i++;
2011-10-13 06:26:54 +00:00
2011-10-09 16:11:15 +00:00
if (i > maxclients->value)
2011-10-13 06:26:54 +00:00
{
2011-10-09 16:11:15 +00:00
i = 1;
2011-10-13 06:26:54 +00:00
}
2011-10-09 16:11:15 +00:00
e = g_edicts + i;
2011-10-13 06:26:54 +00:00
2011-10-09 16:11:15 +00:00
if (!e->inuse)
2011-10-13 06:26:54 +00:00
{
2011-10-09 16:11:15 +00:00
continue;
2011-10-13 06:26:54 +00:00
}
2011-10-09 16:11:15 +00:00
if (e->solid != SOLID_NOT)
2011-10-13 06:26:54 +00:00
{
2011-10-09 16:11:15 +00:00
break;
2011-10-13 06:26:54 +00:00
}
}
while (e != ent->client->chase_target);
2011-10-09 16:11:15 +00:00
ent->client->chase_target = e;
ent->client->update_chase = true;
}
2011-10-13 06:26:54 +00:00
void
ChasePrev(edict_t *ent)
2011-10-09 16:11:15 +00:00
{
int i;
edict_t *e;
if (!ent->client->chase_target)
2011-10-13 06:26:54 +00:00
{
2011-10-09 16:11:15 +00:00
return;
2011-10-13 06:26:54 +00:00
}
2011-10-09 16:11:15 +00:00
i = ent->client->chase_target - g_edicts;
2011-10-13 06:26:54 +00:00
do
{
2011-10-09 16:11:15 +00:00
i--;
2011-10-13 06:26:54 +00:00
2011-10-09 16:11:15 +00:00
if (i < 1)
2011-10-13 06:26:54 +00:00
{
2011-10-09 16:11:15 +00:00
i = maxclients->value;
2011-10-13 06:26:54 +00:00
}
2011-10-09 16:11:15 +00:00
e = g_edicts + i;
2011-10-13 06:26:54 +00:00
2011-10-09 16:11:15 +00:00
if (!e->inuse)
2011-10-13 06:26:54 +00:00
{
2011-10-09 16:11:15 +00:00
continue;
2011-10-13 06:26:54 +00:00
}
2011-10-09 16:11:15 +00:00
if (e->solid != SOLID_NOT)
2011-10-13 06:26:54 +00:00
{
2011-10-09 16:11:15 +00:00
break;
2011-10-13 06:26:54 +00:00
}
}
while (e != ent->client->chase_target);
2011-10-09 16:11:15 +00:00
ent->client->chase_target = e;
ent->client->update_chase = true;
}