Quake II RTX doxygen  1.0 dev
p_trail.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 modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (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. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 #include "g_local.h"
19 
20 
21 /*
22 ==============================================================================
23 
24 PLAYER TRAIL
25 
26 ==============================================================================
27 
28 This is a circular list containing the a list of points of where
29 the player has been recently. It is used by monsters for pursuit.
30 
31 .origin the spot
32 .owner forward link
33 .aiment backward link
34 */
35 
36 
37 #define TRAIL_LENGTH 8
38 
39 edict_t *trail[TRAIL_LENGTH];
41 qboolean trail_active = qfalse;
42 
43 #define NEXT(n) (((n) + 1) & (TRAIL_LENGTH - 1))
44 #define PREV(n) (((n) - 1) & (TRAIL_LENGTH - 1))
45 
46 
47 void PlayerTrail_Init(void)
48 {
49  int n;
50 
51  if (deathmatch->value /* FIXME || coop */)
52  return;
53 
54  for (n = 0; n < TRAIL_LENGTH; n++) {
55  trail[n] = G_Spawn();
56  trail[n]->classname = "player_trail";
57  }
58 
59  trail_head = 0;
60  trail_active = qtrue;
61 }
62 
63 
64 void PlayerTrail_Add(vec3_t spot)
65 {
66  vec3_t temp;
67 
68  if (!trail_active)
69  return;
70 
71  VectorCopy(spot, trail[trail_head]->s.origin);
72 
73  trail[trail_head]->timestamp = level.time;
74 
75  VectorSubtract(spot, trail[PREV(trail_head)]->s.origin, temp);
76  trail[trail_head]->s.angles[1] = vectoyaw(temp);
77 
79 }
80 
81 
82 void PlayerTrail_New(vec3_t spot)
83 {
84  if (!trail_active)
85  return;
86 
88  PlayerTrail_Add(spot);
89 }
90 
91 
92 edict_t *PlayerTrail_PickFirst(edict_t *self)
93 {
94  int marker;
95  int n;
96 
97  if (!trail_active)
98  return NULL;
99 
100  for (marker = trail_head, n = TRAIL_LENGTH; n; n--) {
101  if (trail[marker]->timestamp <= self->monsterinfo.trail_time)
102  marker = NEXT(marker);
103  else
104  break;
105  }
106 
107  if (visible(self, trail[marker])) {
108  return trail[marker];
109  }
110 
111  if (visible(self, trail[PREV(marker)])) {
112  return trail[PREV(marker)];
113  }
114 
115  return trail[marker];
116 }
117 
118 edict_t *PlayerTrail_PickNext(edict_t *self)
119 {
120  int marker;
121  int n;
122 
123  if (!trail_active)
124  return NULL;
125 
126  for (marker = trail_head, n = TRAIL_LENGTH; n; n--) {
127  if (trail[marker]->timestamp <= self->monsterinfo.trail_time)
128  marker = NEXT(marker);
129  else
130  break;
131  }
132 
133  return trail[marker];
134 }
135 
136 edict_t *PlayerTrail_LastSpot(void)
137 {
138  return trail[PREV(trail_head)];
139 }
deathmatch
cvar_t * deathmatch
Definition: g_main.c:33
PlayerTrail_New
void PlayerTrail_New(vec3_t spot)
Definition: p_trail.c:82
G_Spawn
edict_t * G_Spawn(void)
Definition: g_utils.c:391
PlayerTrail_LastSpot
edict_t * PlayerTrail_LastSpot(void)
Definition: p_trail.c:136
PlayerTrail_Add
void PlayerTrail_Add(vec3_t spot)
Definition: p_trail.c:64
vectoyaw
float vectoyaw(vec3_t vec)
Definition: g_utils.c:310
PlayerTrail_PickFirst
edict_t * PlayerTrail_PickFirst(edict_t *self)
Definition: p_trail.c:92
TRAIL_LENGTH
#define TRAIL_LENGTH
Definition: p_trail.c:37
trail
edict_t * trail[TRAIL_LENGTH]
Definition: p_trail.c:39
PREV
#define PREV(n)
Definition: p_trail.c:44
level_locals_t::time
float time
Definition: g_local.h:299
visible
qboolean visible(edict_t *self, edict_t *other)
Definition: g_ai.c:268
trail_head
int trail_head
Definition: p_trail.c:40
NEXT
#define NEXT(n)
Definition: p_trail.c:43
level
level_locals_t level
Definition: g_main.c:22
trail_active
qboolean trail_active
Definition: p_trail.c:41
PlayerTrail_Init
void PlayerTrail_Init(void)
Definition: p_trail.c:47
g_local.h
PlayerTrail_PickNext
edict_t * PlayerTrail_PickNext(edict_t *self)
Definition: p_trail.c:118