OpenMoHAA 0.82.1
Loading...
Searching...
No Matches
g_utils.h
1/*
2===========================================================================
3Copyright (C) 2025 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#pragma once
24
25#include "../qcommon/str.h"
26
27class Archiver;
28class Entity;
29class SimpleEntity;
31class ScriptThread;
32
33void G_ArchivePlayerState(Archiver& arc, playerState_t *ps);
34void G_ArchiveTrace(Archiver& arc, trace_t *trace);
35void G_ArchiveClient(Archiver& arc, gclient_t *client);
36void G_ArchiveEdict(Archiver& arc, gentity_t *edict);
37
38void G_AllocDebugLines(void);
39void G_DeAllocDebugLines(void);
40
41void G_TouchTriggers(Entity *ent);
42void G_TouchSolids(Entity *ent);
43
44Entity *G_FindClass(Entity *ent, const char *classname);
45Entity *G_NextEntity(Entity *ent);
46
47void G_CalcBoundsOfMove(Vector& start, Vector& end, Vector& mins, Vector& maxs, Vector *minbounds, Vector *maxbounds);
48
49void G_ShowTrace(trace_t *trace, const gentity_t *passent, const char *reason);
50void G_ShowSightTrace(trace_t *trace, const gentity_t *passent, const char *reason);
51
52bool G_SightTrace(
53 const Vector& start,
54 const Vector& mins,
55 const Vector& maxs,
56 const Vector& end,
57 Entity *passent,
58 Entity *passent2,
59 int contentmask,
60 qboolean cylindrical,
61 const char *reason
62);
63bool G_SightTrace(
64 const Vector& start,
65 const Vector& mins,
66 const Vector& maxs,
67 const Vector& end,
68 gentity_t *passent,
69 gentity_t *passent2,
70 int contentmask,
71 qboolean cylindrical,
72 const char *reason
73);
74
75void G_PMDrawTrace(
76 trace_t *results,
77 const vec3_t start,
78 const vec3_t mins,
79 const vec3_t maxs,
80 const vec3_t end,
81 int passEntityNum,
82 int contentMask,
83 qboolean cylinder,
84 qboolean traceDeep
85);
86
87trace_t G_Trace(
88 const Vector& start,
89 const Vector& mins,
90 const Vector& maxs,
91 const Vector& end,
92 const Entity *passent,
93 int contentmask,
94 qboolean cylindrical,
95 const char *reason,
96 qboolean tracedeep = qfalse
97);
98trace_t G_Trace(
99 vec3_t start,
100 vec3_t mins,
101 vec3_t maxs,
102 vec3_t end,
103 const gentity_t *passent,
104 int contentmask,
105 qboolean cylindrical,
106 const char *reason,
107 qboolean tracedeep = qfalse
108);
109void G_TraceEntities(
110 Vector& start,
111 Vector& mins,
112 Vector& maxs,
113 Vector& end,
114 Container<Entity *> *victimlist,
115 int contentmask,
116 qboolean bIncludeTriggers = qfalse
117);
118float G_VisualObfuscation(const Vector& start, const Vector& end);
119
120void SelectSpawnPoint(Vector& org, Vector& angles, str& thread);
121
122Entity *G_FindTarget(Entity *ent, const char *name);
123Entity *G_FindRandomTarget(const char *name);
124SimpleEntity *G_FindRandomSimpleTarget(const char *name);
125Entity *G_NextEntity(Entity *ent);
126
127qboolean M_CheckBottom(Entity *ent);
128
129Vector G_GetMovedir(float angle);
130float G_GetAngle(Vector movedir);
131qboolean KillBox(Entity *ent);
132qboolean IsNumeric(const char *str);
133
134Entity *findradius(Entity *startent, Vector org, float rad);
135Entity *findclientsinradius(Entity *startent, Vector org, float rad);
136
137Vector G_CalculateImpulse(Vector start, Vector end, float speed, float gravity);
138Vector G_PredictPosition(Vector start, Vector target, Vector targetvelocity, float speed);
139
140qboolean G_LoadAndExecScript(const char *filename, const char *label = NULL, qboolean quiet = qfalse);
141ScriptThread *ExecuteThread(str thread_name, qboolean start = true);
142
143int MOD_string_to_int(const str& immune_string);
144qboolean MOD_matches(int incoming_damage, int damage_type);
145
146void G_MissionFailed(void);
147void G_FadeOut(float delaytime);
148void G_FadeSound(float delaytime);
149void G_RestartLevelWithDelay(float delaytime);
150void G_AutoFadeIn(void);
151void G_ClearFade(void);
152void G_StartCinematic(void);
153void G_StopCinematic(void);
154
155// copy the entity exactly including all its children
156void CloneEntity(Entity *dest, Entity *src);
157
158qboolean OnSameTeam(Entity *ent1, Entity *ent2);
159
160//
161// caching commands
162//
163void CacheResource(const char *stuff);
164int modelIndex(const char *mdl);
165
166void G_SetTrajectory(gentity_t *ent, vec3_t org);
167void G_SetConstantLight(
168 int *constantlight, float *red, float *green, float *blue, float *radius, int *lightstyle = NULL
169);
170
171void ChangeMusic(const char *current, const char *fallback, qboolean force);
172
173void ChangeMusicVolume(float volume, float fade_time);
174
175void RestoreMusicVolume(float fade_time);
176
177void ChangeSoundtrack(const char *soundtrack);
178
179void RestoreSoundtrack(void);
180
181void G_BroadcastSound(Entity *ent, Vector origin, float radius = SOUND_RADIUS);
182
183SimpleArchivedEntity *G_FindArchivedClass(SimpleArchivedEntity *ent, const char *classname);
184Entity *G_FindClass(Entity *ent, const char *classname);
185int G_GetClientNumber(gentity_t *ent);
186int G_GetClientNumber(Entity *ent);
187Entity *G_GetEntityByClient(int clientNum);
188int G_GetEntityIndex(int number);
189int G_GetEntityIndex(gentity_t *ent);
190gentity_t *G_GetGEntity(int id);
191
192//==================================================================
193//
194// Inline functions
195//
196//==================================================================
197
198/*
199=================
200G_GetEntity
201
202Takes an index to an entity and returns pointer to it.
203=================
204*/
205
206inline Entity *G_GetEntity(int entnum)
207{
208 if ((entnum < 0) || (entnum >= globals.max_entities)) {
209 gi.Error(ERR_DROP, "G_GetEntity: %d out of valid range.", entnum);
210 }
211
212 return (Entity *)g_entities[entnum].entity;
213}
214
215/*
216=================
217G_Random
218
219Returns a number from 0<= num < 1
220
221random()
222=================
223*/
224
225inline float G_Random(void)
226{
227 return ((float)(rand() & 0x7fff)) / ((float)0x8000);
228}
229
230/*
231=================
232G_Random
233
234Returns a number from 0 <= num < n
235
236random()
237=================
238*/
239
240inline float G_Random(float n)
241{
242 return G_Random() * n;
243}
244
245/*
246=================
247G_CRandom
248
249Returns a number from -1 <= num < 1
250
251crandom()
252=================
253*/
254
255inline float G_CRandom(void)
256{
257 return G_Random(2) - 1;
258}
259
260/*
261=================
262G_CRandom
263
264Returns a number from -n <= num < n
265
266crandom()
267=================
268*/
269
270inline float G_CRandom(float n)
271{
272 return G_CRandom() * n;
273}
274
275/*
276=================
277G_FixSlashes
278
279Converts all backslashes in a string to forward slashes.
280Used to make filenames consistant.
281=================
282*/
283
284inline str G_FixSlashes(const char *filename)
285{
286 int i;
287 size_t len;
288 str text;
289
290 if (filename) {
291 // Convert all forward slashes to back slashes
292 text = filename;
293 len = text.length();
294 for (i = 0; i < len; i++) {
295 if (text[i] == '\\') {
296 text[i] = '/';
297 }
298 }
299 }
300
301 return text;
302}
303
304typedef enum {
305 WEAPON_MAIN,
306 WEAPON_OFFHAND,
307 WEAPON_ERROR
308} weaponhand_t;
309
310#define NUM_ACTIVE_WEAPONS WEAPON_ERROR
311
312typedef enum {
313 FIRE_PRIMARY,
314 FIRE_SECONDARY,
315 MAX_FIREMODES,
316 FIRE_ERROR
317} firemode_t;
318
319firemode_t WeaponModeNameToNum(str mode);
320const char *WeaponHandNumToName(weaponhand_t hand);
321weaponhand_t WeaponHandNameToNum(str side);
322void G_DebugTargets(Entity *e, str from);
323void G_DebugDamage(float damage, Entity *victim, Entity *attacker, Entity *inflictor);
324unsigned int G_GetWeaponCommandMask();
325unsigned int G_GetWeaponCommand(unsigned int buttons);
Definition archive.h:86
Definition container.h:85
Definition entity.h:203
Definition scriptthread.h:28
Definition simpleentity.h:119
Definition simpleentity.h:42
Definition vector.h:61
Definition str.h:77
Definition q_shared.h:1452