OpenMoHAA 0.82.1
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
31class GravPathNode : public Entity
32{
33private:
34 float speed;
35 float radius;
36 qboolean headnode;
37 float max_speed;
38
39public:
40 qboolean active;
41
42 CLASS_PROTOTYPE(GravPathNode);
43 GravPathNode();
44 void SetSpeed(Event *ev);
45 void SetMaxSpeed(Event *ev);
46 void SetRadius(Event *ev);
47 void CreatePath(Event *ev);
48 void Activate(Event *ev);
49 void Deactivate(Event *ev);
50 float Speed(void);
51 float MaxSpeed(void);
52
53 float Radius(void) { return radius; };
54
55 void Archive(Archiver& arc) override;
56};
57
58inline void GravPathNode::Archive(Archiver& arc)
59{
60 Entity::Archive(arc);
61
62 arc.ArchiveFloat(&speed);
63 arc.ArchiveFloat(&radius);
64 arc.ArchiveBoolean(&headnode);
65 arc.ArchiveBoolean(&active);
66 arc.ArchiveFloat(&max_speed);
67}
68
69typedef SafePtr<GravPathNode> GravPathNodePtr;
70
71class GravPath : public Listener
72{
73private:
75 float pathlength;
76
77 GravPathNodePtr from;
78 GravPathNodePtr to;
79 int nextnode;
80
81public:
82 CLASS_PROTOTYPE(GravPath);
83
84 GravPath();
85 ~GravPath();
86 void Clear(void);
87 void Reset(void);
88 void AddNode(GravPathNode *node);
89 GravPathNode *GetNode(int num);
90 GravPathNode *NextNode(void);
91 Vector ClosestPointOnPath(Vector pos, Entity& ent, float *bestdist, float *speed, float *radius);
92 float DistanceAlongPath(Vector pos, float *speed);
93 Vector PointAtDistance(Vector pos, float dist, qboolean is_player, float *max_distance);
94 void DrawPath(float r, float g, float b);
95 int NumNodes(void);
96 float Length(void);
97 GravPathNode *Start(void);
98 GravPathNode *End(void);
99 void Archive(Archiver& arc) override;
100
101 Vector mins;
102 Vector maxs;
103 Vector origin;
104 qboolean force;
105};
106
107inline void GravPath::Archive(Archiver& arc)
108{
109 GravPathNodePtr *tempPtr;
110 int i, num;
111
112 Listener::Archive(arc);
113
114 if (arc.Loading()) {
115 Reset();
116 } else {
117 num = pathlist.NumObjects();
118 }
119 arc.ArchiveInteger(&num);
120 if (arc.Loading()) {
121 pathlist.Resize(num);
122 }
123
124 for (i = 1; i <= num; i++) {
125 tempPtr = pathlist.AddressOfObjectAt(i);
126 arc.ArchiveSafePointer(tempPtr);
127 }
128
129 arc.ArchiveFloat(&pathlength);
130 arc.ArchiveSafePointer(&from);
131 arc.ArchiveSafePointer(&to);
132 arc.ArchiveInteger(&nextnode);
133 arc.ArchiveVector(&mins);
134 arc.ArchiveVector(&maxs);
135 arc.ArchiveVector(&origin);
136 arc.ArchiveBoolean(&force);
137}
138
139class GravPathManager : public Class
140{
141private:
142 Container<GravPath *> pathList;
143
144public:
145 CLASS_PROTOTYPE(GravPathManager);
147 void Reset(void);
148 void AddPath(GravPath *p);
149 void RemovePath(GravPath *p);
150 Vector CalculateGravityPull(Entity& ent, Vector position, qboolean *force, float *max_speed);
151 void DrawGravPaths(void);
152 void Archive(Archiver& arc) override;
153};
154
155inline void GravPathManager::Archive(Archiver& arc)
156{
157 GravPath *ptr;
158 int i, num;
159
160 Class::Archive(arc);
161
162 if (arc.Saving()) {
163 num = pathList.NumObjects();
164 } else {
165 Reset();
166 }
167 arc.ArchiveInteger(&num);
168 for (i = 1; i <= num; i++) {
169 if (arc.Saving()) {
170 ptr = pathList.ObjectAt(i);
171 } else {
172 ptr = new GravPath;
173 }
174 arc.ArchiveObject(ptr);
175 if (arc.Loading()) {
176 pathList.AddObject(ptr);
177 }
178 }
179}
180
181extern GravPathManager gravPathManager;
Definition archive.h:86
Definition container.h:85
Definition entity.h:203
Definition listener.h:246
Definition gravpath.h:140
Definition gravpath.h:32
Definition gravpath.h:72
Definition safeptr.h:160
Definition vector.h:61