reformat g_chase.c

This commit is contained in:
Yamagi Burmeister 2011-10-13 06:26:54 +00:00
parent 502e7c6f80
commit f1ae66d1de

View file

@ -1,26 +1,33 @@
/* /*
Copyright (C) 1997-2001 Id Software, Inc. * 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.
*
* =======================================================================
*/
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.
*/
#include "header/local.h" #include "header/local.h"
void
void UpdateChaseCam(edict_t *ent) UpdateChaseCam(edict_t *ent)
{ {
vec3_t o, ownerv, goal; vec3_t o, ownerv, goal;
edict_t *targ; edict_t *targ;
@ -30,8 +37,9 @@ void UpdateChaseCam(edict_t *ent)
vec3_t oldgoal; vec3_t oldgoal;
vec3_t angles; vec3_t angles;
// is our chase target gone? /* is our chase target gone? */
if (!ent->client->chase_target->inuse) { if (!ent->client->chase_target->inuse)
{
ent->client->chase_target = NULL; ent->client->chase_target = NULL;
return; return;
} }
@ -44,18 +52,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);
@ -63,11 +79,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;
} }
@ -75,7 +93,9 @@ 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;
} }
@ -83,8 +103,12 @@ void UpdateChaseCam(edict_t *ent)
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]); 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]);
}
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);
@ -95,62 +119,94 @@ void UpdateChaseCam(edict_t *ent)
if ((!ent->client->showscores && !ent->client->menu && if ((!ent->client->showscores && !ent->client->menu &&
!ent->client->showinventory && !ent->client->showhelp && !ent->client->showinventory && !ent->client->showhelp &&
!(level.framenum & 31)) || ent->client->update_chase) { !(level.framenum & 31)) || ent->client->update_chase)
{
char s[1024]; char s[1024];
ent->client->update_chase = false; ent->client->update_chase = false;
sprintf(s, "xv 0 yb -68 string2 \"Chasing %s\"", sprintf(s, "xv 0 yb -68 string2 \"Chasing %s\"",
targ->client->pers.netname); targ->client->pers.netname);
gi.WriteByte (svc_layout); gi.WriteByte(svc_layout);
gi.WriteString (s); gi.WriteString(s);
gi.unicast(ent, false); gi.unicast(ent, false);
} }
} }
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->client->chase_target)
{
return; 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->solid != SOLID_NOT) if (e->solid != SOLID_NOT)
{
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->client->chase_target)
{
return; 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->solid != SOLID_NOT) if (e->solid != SOLID_NOT)
{
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;