This repository has been archived by the owner on Sep 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gravpath.h
271 lines (229 loc) · 6.49 KB
/
gravpath.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
//-----------------------------------------------------------------------------
//
// $Logfile:: /Quake 2 Engine/Sin/code/game/gravpath.h $
// $Revision:: 11 $
// $Author:: Jimdose $
// $Date:: 10/25/98 11:53p $
//
// Copyright (C) 1998 by Ritual Entertainment, Inc.
// All rights reserved.
//
// This source is may not be distributed and/or modified without
// expressly written permission by Ritual Entertainment, Inc.
//
// $Log:: /Quake 2 Engine/Sin/code/game/gravpath.h $
//
// 11 10/25/98 11:53p Jimdose
// added EXPORT_TEMPLATE
//
// 10 10/21/98 2:18a Jimdose
// Added Reset to Unarchive
//
// 9 10/07/98 11:51p Jimdose
// Added destructor for GravPathManager
// added Reset to GravPath::Unarchive
//
// 8 9/30/98 4:36p Aldie
// Added reset
//
// 7 9/29/98 11:46p Aldie
// Added force spawnflag
//
// 6 9/28/98 9:12p Markd
// Put in archive and unarchive functions
//
// 5 8/27/98 2:54p Aldie
// Added a headnode flag
//
// 4 8/27/98 2:31p Aldie
// Update active flag as a public var
//
// 3 8/26/98 9:45p Aldie
// Added activate and deactivate
//
// 2 5/22/98 12:19p Aldie
// First version of gravpath
//
// DESCRIPTION:
// Gravity path - Used for underwater currents and wells.
#ifndef __GRAVPATH_H__
#define __GRAVPATH_H__
#include "g_local.h"
#include "class.h"
#include "container.h"
class EXPORT_FROM_DLL GravPathNode : public Entity
{
private:
float speed;
float radius;
qboolean headnode;
public:
qboolean active;
CLASS_PROTOTYPE(GravPathNode);
GravPathNode();
void CreatePath(Event *ev);
void Activate(Event *ev);
void Deactivate(Event *ev);
float Speed(void);
float Radius(void) {return radius;};
virtual void Archive( Archiver &arc );
virtual void Unarchive( Archiver &arc );
};
inline EXPORT_FROM_DLL void GravPathNode::Archive
(
Archiver &arc
)
{
Entity::Archive( arc );
arc.WriteFloat( speed );
arc.WriteFloat( radius );
arc.WriteBoolean( headnode );
arc.WriteBoolean( active );
}
inline EXPORT_FROM_DLL void GravPathNode::Unarchive
(
Archiver &arc
)
{
Entity::Unarchive( arc );
arc.ReadFloat( &speed );
arc.ReadFloat( &radius );
arc.ReadBoolean( &headnode );
arc.ReadBoolean( &active );
}
typedef SafePtr<GravPathNode> GravPathNodePtr;
//
// Exported templated classes must be explicitly instantiated
//
#ifdef EXPORT_TEMPLATE
template class EXPORT_FROM_DLL SafePtr<GravPathNode>;
template class EXPORT_FROM_DLL Container<GravPathNodePtr>;
#endif
class EXPORT_FROM_DLL GravPath : public Listener
{
private:
Container<GravPathNodePtr> pathlist;
float pathlength;
GravPathNodePtr from;
GravPathNodePtr to;
int nextnode;
public:
CLASS_PROTOTYPE( GravPath );
GravPath();
~GravPath();
void Clear(void);
void Reset(void);
void AddNode(GravPathNode *node);
GravPathNode *GetNode(int num);
GravPathNode *NextNode(void);
Vector ClosestPointOnPath(Vector pos, Entity &ent,float *bestdist,float *speed,float *radius);
float DistanceAlongPath(Vector pos, float *speed);
Vector PointAtDistance(float dist);
void DrawPath(Event *ev);
int NumNodes(void);
float Length(void);
GravPathNode *Start(void);
GravPathNode *End(void);
virtual void Archive( Archiver &arc );
virtual void Unarchive( Archiver &arc );
Vector mins;
Vector maxs;
Vector origin;
qboolean force;
};
inline EXPORT_FROM_DLL void GravPath::Archive
(
Archiver &arc
)
{
int i, num;
Listener::Archive( arc );
num = pathlist.NumObjects();
arc.WriteInteger( num );
for ( i = 1; i <= num; i++ )
{
arc.WriteSafePointer( pathlist.ObjectAt( i ) );
}
arc.WriteFloat( pathlength );
arc.WriteSafePointer( from );
arc.WriteSafePointer( to );
arc.WriteInteger( nextnode );
arc.WriteVector( mins );
arc.WriteVector( maxs );
arc.WriteVector( origin );
arc.WriteBoolean( force );
}
inline EXPORT_FROM_DLL void GravPath::Unarchive
(
Archiver &arc
)
{
int i, num;
Reset();
Listener::Unarchive( arc );
arc.ReadInteger( &num );
pathlist.Resize( num );
for ( i = 1; i <= num; i++ )
{
arc.ReadSafePointer( pathlist.AddressOfObjectAt( i ) );
}
arc.ReadFloat( &pathlength );
arc.ReadSafePointer( &from );
arc.ReadSafePointer( &to );
arc.ReadInteger( &nextnode );
arc.ReadVector( &mins );
arc.ReadVector( &maxs );
arc.ReadVector( &origin );
arc.ReadBoolean( &force );
}
#ifdef EXPORT_TEMPLATE
template class EXPORT_FROM_DLL Container<GravPath *>;
#endif
class EXPORT_FROM_DLL GravPathManager : public Class
{
private:
Container<GravPath *> pathList;
public:
CLASS_PROTOTYPE( GravPathManager );
~GravPathManager();
void Reset( void );
void AddPath(GravPath *p);
void RemovePath(GravPath *p);
Vector CalculateGravityPull(Entity &ent, Vector position, qboolean *force);
virtual void Archive( Archiver &arc );
virtual void Unarchive( Archiver &arc );
};
inline EXPORT_FROM_DLL void GravPathManager::Archive
(
Archiver &arc
)
{
int i, num;
Class::Archive( arc );
num = pathList.NumObjects();
arc.WriteInteger( num );
for ( i = 1; i <= num; i++ )
{
arc.WriteObject( pathList.ObjectAt( i ) );
}
}
inline EXPORT_FROM_DLL void GravPathManager::Unarchive
(
Archiver &arc
)
{
int i, num;
Reset();
Class::Unarchive( arc );
arc.ReadInteger( &num );
for ( i = 1; i <= num; i++ )
{
GravPath * ptr;
ptr = new GravPath;
arc.ReadObject( ptr );
pathList.AddObject( ptr );
}
}
extern GravPathManager gravPathManager;
extern Event EV_DrawGravPath;
#endif /* gravpath.h */