OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
g_utils.h
1/*
2===========================================================================
3Copyright (C) 2023 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{
209 if ((entnum < 0) || (entnum >= globals.max_entities)) {
210 gi.Error(ERR_DROP, "G_GetEntity: %d out of valid range.", entnum);
211 }
212
213 return (Entity *)g_entities[entnum].entity;
214}
215
216/*
217=================
218G_Random
219
220Returns a number from 0<= num < 1
221
222random()
223=================
224*/
225
226inline float G_Random(void)
227
228{
229 return ((float)(rand() & 0x7fff)) / ((float)0x8000);
230}
231
232/*
233=================
234G_Random
235
236Returns a number from 0 <= num < n
237
238random()
239=================
240*/
241
242inline float G_Random(float n)
243
244{
245 return G_Random() * n;
246}
247
248/*
249=================
250G_CRandom
251
252Returns a number from -1 <= num < 1
253
254crandom()
255=================
256*/
257
258inline float G_CRandom(void)
259
260{
261 return G_Random(2) - 1;
262}
263
264/*
265=================
266G_CRandom
267
268Returns a number from -n <= num < n
269
270crandom()
271=================
272*/
273
274inline float G_CRandom(float n)
275
276{
277 return G_CRandom() * n;
278}
279
280/*
281=================
282G_FixSlashes
283
284Converts all backslashes in a string to forward slashes.
285Used to make filenames consistant.
286=================
287*/
288
289inline str G_FixSlashes(const char *filename)
290
291{
292 int i;
293 size_t len;
294 str text;
295
296 if (filename) {
297 // Convert all forward slashes to back slashes
298 text = filename;
299 len = text.length();
300 for (i = 0; i < len; i++) {
301 if (text[i] == '\\') {
302 text[i] = '/';
303 }
304 }
305 }
306
307 return text;
308}
309
310typedef enum {
311 WEAPON_MAIN,
312 WEAPON_OFFHAND,
313 WEAPON_ERROR
314} weaponhand_t;
315
316#define NUM_ACTIVE_WEAPONS WEAPON_ERROR
317
318typedef enum {
319 FIRE_PRIMARY,
320 FIRE_SECONDARY,
321 MAX_FIREMODES,
322 FIRE_ERROR
323} firemode_t;
324
325firemode_t WeaponModeNameToNum(str mode);
326const char *WeaponHandNumToName(weaponhand_t hand);
327weaponhand_t WeaponHandNameToNum(str side);
328void G_DebugTargets(Entity *e, str from);
329void G_DebugDamage(float damage, Entity *victim, Entity *attacker, Entity *inflictor);
330unsigned 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