OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
gravpath.h
1/*
2===========================================================================
3Copyright (C) 2024 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23// gravpath.h: Gravity path - Used for underwater currents and wells.
24
25#pragma once
26
27#include "g_local.h"
28#include "class.h"
29#include "container.h"
30
31
32class GravPathNode : public Entity
33 {
34 private:
35 float speed;
36 float radius;
37 qboolean headnode;
38 float max_speed;
39
40 public:
41 qboolean active;
42
43 CLASS_PROTOTYPE(GravPathNode);
44 GravPathNode();
45 void SetSpeed( Event *ev );
46 void SetMaxSpeed( Event *ev );
47 void SetRadius( Event *ev );
48 void CreatePath( Event *ev );
49 void Activate( Event *ev );
50 void Deactivate( Event *ev );
51 float Speed( void );
52 float MaxSpeed( void );
53 float Radius( void ) { return radius; };
54 void Archive( Archiver &arc ) override;
55 };
56
57inline void GravPathNode::Archive
58 (
59 Archiver &arc
60 )
61 {
62 Entity::Archive( arc );
63
64 arc.ArchiveFloat( &speed );
65 arc.ArchiveFloat( &radius );
66 arc.ArchiveBoolean( &headnode );
67 arc.ArchiveBoolean( &active );
68 arc.ArchiveFloat( &max_speed );
69 }
70
71typedef SafePtr<GravPathNode> GravPathNodePtr;
72
73class GravPath : public Listener
74 {
75 private:
77 float pathlength;
78
79 GravPathNodePtr from;
80 GravPathNodePtr to;
81 int nextnode;
82
83 public:
84 CLASS_PROTOTYPE( GravPath );
85
86 GravPath();
87 ~GravPath();
88 void Clear(void);
89 void Reset(void);
90 void AddNode(GravPathNode *node);
91 GravPathNode *GetNode(int num);
92 GravPathNode *NextNode(void);
93 Vector ClosestPointOnPath(Vector pos, Entity &ent,float *bestdist,float *speed,float *radius);
94 float DistanceAlongPath(Vector pos, float *speed);
95 Vector PointAtDistance( Vector pos, float dist, qboolean is_player, float *max_distance );
96 void DrawPath(float r, float g, float b);
97 int NumNodes(void);
98 float Length(void);
99 GravPathNode *Start(void);
100 GravPathNode *End(void);
101 void Archive( Archiver &arc ) override;
102
103 Vector mins;
104 Vector maxs;
105 Vector origin;
106 qboolean force;
107 };
108
109inline void GravPath::Archive
110 (
111 Archiver &arc
112 )
113
114 {
115 GravPathNodePtr *tempPtr;
116 int i, num;
117
118 Listener::Archive( arc );
119
120 if ( arc.Loading() )
121 {
122 Reset();
123 }
124 else
125 {
126 num = pathlist.NumObjects();
127 }
128 arc.ArchiveInteger( &num );
129 if ( arc.Loading() )
130 {
131 pathlist.Resize( num );
132 }
133
134 for ( i = 1; i <= num; i++ )
135 {
136 tempPtr = pathlist.AddressOfObjectAt( i );
137 arc.ArchiveSafePointer( tempPtr );
138 }
139
140 arc.ArchiveFloat( &pathlength );
141 arc.ArchiveSafePointer( &from );
142 arc.ArchiveSafePointer( &to );
143 arc.ArchiveInteger( &nextnode );
144 arc.ArchiveVector( &mins );
145 arc.ArchiveVector( &maxs );
146 arc.ArchiveVector( &origin );
147 arc.ArchiveBoolean( &force );
148 }
149
150class GravPathManager : public Class
151 {
152 private:
153 Container<GravPath *> pathList;
154
155 public:
156 CLASS_PROTOTYPE( GravPathManager );
158 void Reset( void );
159 void AddPath(GravPath *p);
160 void RemovePath(GravPath *p);
161 Vector CalculateGravityPull(Entity &ent, Vector position, qboolean *force, float *max_speed);
162 void DrawGravPaths( void );
163 void Archive( Archiver &arc ) override;
164 };
165
166inline void GravPathManager::Archive
167 (
168 Archiver &arc
169 )
170 {
171 GravPath * ptr;
172 int i, num;
173
174 Class::Archive( arc );
175
176 if ( arc.Saving() )
177 {
178 num = pathList.NumObjects();
179 }
180 else
181 {
182 Reset();
183 }
184 arc.ArchiveInteger( &num );
185 for ( i = 1; i <= num; i++ )
186 {
187 if ( arc.Saving() )
188 {
189 ptr = pathList.ObjectAt( i );
190 }
191 else
192 {
193 ptr = new GravPath;
194 }
195 arc.ArchiveObject( ptr );
196 if ( arc.Loading() )
197 {
198 pathList.AddObject( ptr );
199 }
200 }
201 }
202
203extern GravPathManager gravPathManager;
Definition archive.h:86
Definition container.h:85
Definition entity.h:203
Definition listener.h:246
Definition gravpath.h:151
Definition gravpath.h:33
Definition gravpath.h:74
Definition safeptr.h:160
Definition vector.h:61