vkQuake2 doxygen  1.0 dev
g_chase.c
Go to the documentation of this file.
1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 */
20 #include "g_local.h"
21 
23 {
24  vec3_t o, ownerv, goal;
25  edict_t *targ;
27  trace_t trace;
28  int i;
29  vec3_t oldgoal;
30  vec3_t angles;
31 
32  // is our chase target gone?
33  if (!ent->client->chase_target->inuse
35  edict_t *old = ent->client->chase_target;
36  ChaseNext(ent);
37  if (ent->client->chase_target == old) {
38  ent->client->chase_target = NULL;
40  return;
41  }
42  }
43 
44  targ = ent->client->chase_target;
45 
46  VectorCopy(targ->s.origin, ownerv);
47  VectorCopy(ent->s.origin, oldgoal);
48 
49  ownerv[2] += targ->viewheight;
50 
51  VectorCopy(targ->client->v_angle, angles);
52  if (angles[PITCH] > 56)
53  angles[PITCH] = 56;
54  AngleVectors (angles, forward, right, NULL);
56  VectorMA(ownerv, -30, forward, o);
57 
58  if (o[2] < targ->s.origin[2] + 20)
59  o[2] = targ->s.origin[2] + 20;
60 
61  // jump animation lifts
62  if (!targ->groundentity)
63  o[2] += 16;
64 
65  trace = gi.trace(ownerv, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
66 
67  VectorCopy(trace.endpos, goal);
68 
69  VectorMA(goal, 2, forward, goal);
70 
71  // pad for floors and ceilings
72  VectorCopy(goal, o);
73  o[2] += 6;
74  trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
75  if (trace.fraction < 1) {
76  VectorCopy(trace.endpos, goal);
77  goal[2] -= 6;
78  }
79 
80  VectorCopy(goal, o);
81  o[2] -= 6;
82  trace = gi.trace(goal, vec3_origin, vec3_origin, o, targ, MASK_SOLID);
83  if (trace.fraction < 1) {
84  VectorCopy(trace.endpos, goal);
85  goal[2] += 6;
86  }
87 
88  if (targ->deadflag)
89  ent->client->ps.pmove.pm_type = PM_DEAD;
90  else
92 
93  VectorCopy(goal, ent->s.origin);
94  for (i=0 ; i<3 ; i++)
96 
97  if (targ->deadflag) {
98  ent->client->ps.viewangles[ROLL] = 40;
99  ent->client->ps.viewangles[PITCH] = -15;
100  ent->client->ps.viewangles[YAW] = targ->client->killer_yaw;
101  } else {
102  VectorCopy(targ->client->v_angle, ent->client->ps.viewangles);
103  VectorCopy(targ->client->v_angle, ent->client->v_angle);
104  }
105 
106  ent->viewheight = 0;
108  gi.linkentity(ent);
109 }
110 
111 void ChaseNext(edict_t *ent)
112 {
113  int i;
114  edict_t *e;
115 
116  if (!ent->client->chase_target)
117  return;
118 
119  i = ent->client->chase_target - g_edicts;
120  do {
121  i++;
122  if (i > maxclients->value)
123  i = 1;
124  e = g_edicts + i;
125  if (!e->inuse)
126  continue;
127  if (!e->client->resp.spectator)
128  break;
129  } while (e != ent->client->chase_target);
130 
131  ent->client->chase_target = e;
132  ent->client->update_chase = true;
133 }
134 
135 void ChasePrev(edict_t *ent)
136 {
137  int i;
138  edict_t *e;
139 
140  if (!ent->client->chase_target)
141  return;
142 
143  i = ent->client->chase_target - g_edicts;
144  do {
145  i--;
146  if (i < 1)
147  i = maxclients->value;
148  e = g_edicts + i;
149  if (!e->inuse)
150  continue;
151  if (!e->client->resp.spectator)
152  break;
153  } while (e != ent->client->chase_target);
154 
155  ent->client->chase_target = e;
156  ent->client->update_chase = true;
157 }
158 
160 {
161  int i;
162  edict_t *other;
163 
164  for (i = 1; i <= maxclients->value; i++) {
165  other = g_edicts + i;
166  if (other->inuse && !other->client->resp.spectator) {
167  ent->client->chase_target = other;
168  ent->client->update_chase = true;
169  UpdateChaseCam(ent);
170  return;
171  }
172  }
173  gi.centerprintf(ent, "No other players to chase.");
174 }
175 
gi
game_import_t gi
Definition: g_main.c:25
UpdateChaseCam
void UpdateChaseCam(edict_t *ent)
Definition: g_chase.c:22
edict_s::s
entity_state_t s
Definition: g_local.h:970
edict_s::groundentity
edict_t * groundentity
Definition: g_local.h:1079
YAW
#define YAW
Definition: q_shared.h:73
gclient_s::v_angle
vec3_t v_angle
Definition: g_local.h:927
game_import_t::trace
trace_t(* trace)(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask)
Definition: game.h:128
ChasePrev
void ChasePrev(edict_t *ent)
Definition: g_chase.c:135
trace_t::fraction
float fraction
Definition: q_shared.h:457
gclient_s::update_chase
qboolean update_chase
Definition: g_local.h:964
maxclients
cvar_t * maxclients
Definition: g_main.c:44
PMF_NO_PREDICTION
#define PMF_NO_PREDICTION
Definition: q_shared.h:487
PM_FREEZE
@ PM_FREEZE
Definition: q_shared.h:477
entity_state_s::origin
vec3_t origin
Definition: q_shared.h:1149
edict_s::inuse
qboolean inuse
Definition: g_local.h:976
trace_t
Definition: q_shared.h:453
i
int i
Definition: q_shared.c:305
edict_s::client
struct gclient_s * client
Definition: g_local.h:971
PITCH
#define PITCH
Definition: q_shared.h:72
client_respawn_t::spectator
qboolean spectator
Definition: g_local.h:878
g_edicts
edict_t * g_edicts
Definition: g_main.c:33
MASK_SOLID
#define MASK_SOLID
Definition: q_shared.h:395
AngleVectors
void AngleVectors(vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
Definition: q_shared.c:93
edict_s
Definition: g_local.h:968
pmove_state_t::pm_type
pmtype_t pm_type
Definition: q_shared.h:496
edict_s::viewheight
int viewheight
Definition: g_local.h:1067
ROLL
#define ROLL
Definition: q_shared.h:74
player_state_t::viewangles
vec3_t viewangles
Definition: q_shared.h:1180
forward
static vec3_t forward
Definition: p_view.c:29
player_state_t::pmove
pmove_state_t pmove
Definition: q_shared.h:1176
GetChaseTarget
void GetChaseTarget(edict_t *ent)
Definition: g_chase.c:159
edict_s::deadflag
int deadflag
Definition: g_local.h:1060
client_respawn_t::cmd_angles
vec3_t cmd_angles
Definition: g_local.h:876
gclient_s::killer_yaw
float killer_yaw
Definition: g_local.h:917
cvar_s::value
float value
Definition: q_shared.h:331
pmove_state_t::delta_angles
short delta_angles[3]
Definition: q_shared.h:503
VectorNormalize
vec_t VectorNormalize(vec3_t v)
Definition: q_shared.c:681
gclient_s::ps
player_state_t ps
Definition: g_local.h:886
NULL
#define NULL
Definition: q_shared.h:67
PM_DEAD
@ PM_DEAD
Definition: q_shared.h:475
game_import_t::centerprintf
void(* centerprintf)(edict_t *ent, char *fmt,...)
Definition: game.h:108
VectorCopy
#define VectorCopy(a, b)
Definition: q_shared.h:165
trace_t::endpos
vec3_t endpos
Definition: q_shared.h:458
vec3_origin
vec3_t vec3_origin
Definition: q_shared.c:24
ChaseNext
void ChaseNext(edict_t *ent)
Definition: g_chase.c:111
VectorMA
void VectorMA(vec3_t veca, float scale, vec3_t vecb, vec3_t vecc)
Definition: q_shared.c:719
gclient_s::chase_target
edict_t * chase_target
Definition: g_local.h:963
right
GLdouble right
Definition: qgl_win.c:159
ANGLE2SHORT
#define ANGLE2SHORT(x)
Definition: q_shared.h:1092
game_import_t::linkentity
void(* linkentity)(edict_t *ent)
Definition: game.h:138
pmove_state_t::pm_flags
byte pm_flags
Definition: q_shared.h:500
vec3_t
vec_t vec3_t[3]
Definition: q_shared.h:134
gclient_s::resp
client_respawn_t resp
Definition: g_local.h:891
g_local.h