UFO: Alien Invasion
Loading...
Searching...
No Matches
game.h
Go to the documentation of this file.
1
5
6/*
7All original material Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9Original file from Quake 2 v3.21: quake2-2.31/game/game.h
10Copyright (C) 1997-2001 Id Software, Inc.
11
12This program is free software; you can redistribute it and/or
13modify it under the terms of the GNU General Public License
14as published by the Free Software Foundation; either version 2
15of the License, or (at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
21See the GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License
24along with this program; if not, write to the Free Software
25Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27*/
28
29#pragma once
30
31#include "../common/tracing.h"
32#include "../common/grid.h"
33#include "../common/cvar.h"
34
35#define GAME_API_VERSION 10
36
37/*=============================================================== */
38
39class Edict;
40class Actor;
41class SrvEdict;
42
43#ifndef GAME_INCLUDE
44
46{
47public:
48 bool inuse;
49 int num;
50 bool ready;
51
52 inline bool isInUse () const {
53 return inuse;
54 }
55 inline void setInUse (bool inuse) {
56 this->inuse = inuse;
57 }
58 inline int getNum (void) const {
59 return num;
60 }
61 inline void setNum (int num) {
62 this->num = num;
63 }
64 inline bool isReady () const {
65 return ready;
66 }
67 inline void setReady (bool ready) {
68 this->ready = ready;
69 }
70
71};
73
74#else
75
77typedef struct client_persistent_s {
78 char userinfo[MAX_INFO_STRING];
79 char netname[16];
80
81 int team;
83 bool ai;
84
86 Actor* _last;
87
88 float flood_locktill;
89 float flood_when[10];
90 int flood_whenhead;
91
92 inline void setLastActor(Actor* lastActor) {
93 _last = lastActor;
94 }
95 inline Actor* getLastActor() {
96 return _last;
97 }
98} client_persistent_t;
99
103class Player {
104public:
105 /* known to server */
106 bool inuse;
107 int num;
108 bool ready;
109
110 /* private to game */
111 bool spawned;
112 bool began;
113 bool roundDone;
114 int lastSeen;
115 bool autostand;
116
117 client_persistent_t pers;
118
119 inline void reset () {
120 OBJZERO(*this);
121 }
122 inline bool isInUse () const {
123 return inuse;
124 }
125 inline void setInUse (bool inuse) {
126 this->inuse = inuse;
127 }
128 inline int getNum (void) const {
129 return num;
130 }
131 inline void setNum (int num) {
132 this->num = num;
133 }
134 inline bool isReady () const {
135 return ready;
136 }
137 inline void setReady (bool ready) {
138 this->ready = ready;
139 }
140 inline int getTeam (void) const {
141 return pers.team;
142 }
143 inline void setTeam (int team) {
144 pers.team = team;
145 }
146};
147typedef Player player_t;
148
149#endif
150
151
159
160#ifndef GAME_INCLUDE
161
162#include "srvedict.h"
163
165#else
166typedef Edict edict_t;
167
168#endif /* GAME_INCLUDE */
169
170/*=============================================================== */
171
173typedef struct game_import_s {
174 /* client/server information */
175 int seed;
176 const csi_t* csi;
177
178 /* special messages */
179
181 void (IMPORT* BroadcastPrintf) (int printlevel, const char* fmt, ...) __attribute__((format(__printf__, 2, 3)));
183 void (IMPORT* DPrintf) (const char* fmt, ...) __attribute__((format(__printf__, 1, 2)));
185 void (IMPORT* PlayerPrintf) (const player_t* player, int printlevel, const char* fmt, va_list ap);
186
190 void (IMPORT* ConfigString) (int num, const char* fmt, ...) __attribute__((format(__printf__, 2, 3)));
191
193 void (IMPORT* Error) (const char* fmt, ...) __attribute__((noreturn, format(__printf__, 1, 2)));
194
196 unsigned int (IMPORT* ModelIndex) (const char* name);
197
199 void (IMPORT* SetInlineModelOrientation) (const char* name, const vec3_t origin, const vec3_t angles);
200 void (IMPORT* GetInlineModelAABB) (const char* name, AABB& aabb);
201
202 void (IMPORT* SetModel) (edict_t* ent, const char* name);
203
209 trace_t (IMPORT* Trace) (const Line& traceLine, const AABB& box, const edict_t* passent, int contentmask);
210
211 int (IMPORT* PointContents) (const vec3_t point);
212 const char* (IMPORT* GetFootstepSound) (const char* texture);
213 float (IMPORT* GetBounceFraction) (const char* texture);
214 bool (IMPORT* LoadModelAABB) (const char* model, int frame, AABB& aabb);
215
218 void (IMPORT* LinkEdict) (edict_t* ent);
220 void (IMPORT* UnlinkEdict) (edict_t* ent);
221
223 bool (IMPORT* TestLine) (const vec3_t start, const vec3_t stop, const int levelmask);
225 bool (IMPORT* TestLineWithEnt) (const vec3_t start, const vec3_t stop, const int levelmask, const char** entlist);
226 float (IMPORT* GrenadeTarget) (const vec3_t from, const vec3_t at, float speed, bool launched, bool rolled, vec3_t v0);
227
228 void (IMPORT* GridCalcPathing) (actorSizeEnum_t actorSize, pathing_t* path, const pos3_t from, int distance, forbiddenList_t* fb_list);
229 bool (IMPORT* GridFindPath) (const actorSizeEnum_t actorSize, pathing_t* path, const pos3_t from, const pos3_t targetPos, byte crouchingState, int maxTUs, forbiddenList_t* fb_list);
230 void (IMPORT* MoveStore) (pathing_t* path);
231 pos_t (IMPORT* MoveLength) (const pathing_t* path, const pos3_t to, byte crouchingState, bool stored);
232 int (IMPORT* MoveNext) (const pathing_t* path, const pos3_t from, byte crouchingState);
233 int (IMPORT* GetTUsForDirection) (int dir, bool crouched);
234 pos_t (IMPORT* GridFall) (actorSizeEnum_t actorSize, const pos3_t pos);
235 void (IMPORT* GridPosToVec) (actorSizeEnum_t actorSize, const pos3_t pos, vec3_t vec);
236 bool (IMPORT* isOnMap) (const vec3_t vec);
237 void (IMPORT* GridRecalcRouting) (const char* name, const GridBox& box, const char** list);
238 bool (IMPORT* CanActorStandHere) (actorSizeEnum_t actorSize, const pos3_t pos);
239 bool (IMPORT* GridShouldUseAutostand) (const pathing_t* path, const pos3_t pos);
240 float (IMPORT* GetVisibility) (const pos3_t position);
241
242 /* filesystem functions */
243 const char* (IMPORT* FS_Gamedir) (void);
244 int (IMPORT* FS_LoadFile) (const char* path, byte** buffer);
246 FILE* (IMPORT* Sys_Fopen) (const char *filename, const char *mode);
247
248 /* network messaging (writing) */
249 void (IMPORT* WriteChar) (char c);
250
251 void (IMPORT* WriteByte) (byte c);
252 void (IMPORT* WriteShort) (int c);
253
254 void (IMPORT* WriteLong) (int c);
255 void (IMPORT* WriteString) (const char* s);
256 void (IMPORT* WritePos) (const vec3_t pos);
257 void (IMPORT* WriteGPos) (const pos3_t pos);
258 void (IMPORT* WriteDir) (const vec3_t pos);
259 void (IMPORT* WriteAngle) (float f);
260 void (IMPORT* WriteFormat) (const char* format, ...);
261
262 void (IMPORT* AbortEvents) (void);
263 void (IMPORT* EndEvents) (void);
264 void (IMPORT* AddEvent) (unsigned int mask, int eType, int entnum);
265 int (IMPORT* GetEvent) (void);
267
268 void (IMPORT* QueueEvent) (unsigned int mask, int eType, int entnum);
269 void (IMPORT* QueueWriteByte) (byte c);
270 void (IMPORT* QueueWritePos) (const vec3_t pos);
271 void (IMPORT* QueueWriteString) (const char* s);
272 void (IMPORT* QueueWriteShort) (int c);
273
274 /* network messaging (reading) */
275 int (IMPORT* ReadChar) (void);
276 int (IMPORT* ReadByte) (void);
277 int (IMPORT* ReadShort) (void);
278 int (IMPORT* ReadLong) (void);
279 int (IMPORT* ReadString) (char* str, size_t length);
280 void (IMPORT* ReadPos) (vec3_t pos);
281 void (IMPORT* ReadGPos) (pos3_t pos);
282 void (IMPORT* ReadDir) (vec3_t vector);
283 float (IMPORT* ReadAngle) (void);
284 void (IMPORT* ReadData) (void* buffer, int size);
285 void (IMPORT* ReadFormat) (const char* format, ...);
286
287 bool (IMPORT* GetConstInt) (const char* name, int* value);
288 bool (IMPORT* GetConstIntFromNamespace) (const char* space, const char* name, int* value);
289 const char* (IMPORT* GetConstVariable) (const char* space, int value);
290 void (IMPORT* RegisterConstInt) (const char* name, int value);
291 bool (IMPORT* UnregisterConstVariable) (const char* name);
292
293 /* misc functions */
294 void (IMPORT* GetCharacterValues) (const char* teamDefinition, character_t* chr);
295
296 /* managed memory allocation */
297 void* (IMPORT* TagMalloc) (int size, int tag, const char* file, int line);
298 void (IMPORT* TagFree) (void* block, const char* file, int line);
299 void (IMPORT* FreeTags) (int tag, const char* file, int line);
300
301 /* console variable interaction */
302 cvar_t* (IMPORT* Cvar_Get) (const char* varName, const char* value, int flags, const char* desc);
303 cvar_t* (IMPORT* Cvar_Set) (const char* varName, const char* value, ...) __attribute__((format(__printf__, 2, 3)));
304 const char* (IMPORT* Cvar_String) (const char* varName);
305
306 /* ClientCommand and ServerCommand parameter access */
307 int (IMPORT* Cmd_Argc) (void);
308 const char* (IMPORT* Cmd_Argv) (int n);
309 const char* (IMPORT* Cmd_Args) (void);
310
313 void (IMPORT* AddCommandString) (const char* text, ...) __attribute__((format(__printf__, 1, 2)));
315
317typedef struct game_export_s {
319
323 void (EXPORT* Init) (void);
324 void (EXPORT* Shutdown) (void);
325
326 /* each new level entered will cause a call to G_SpawnEntities */
327 void (EXPORT* SpawnEntities) (const char* mapname, bool day, const char* entstring);
328
329 bool (EXPORT* ClientConnect) (player_t* client, char* userinfo, size_t userinfoSize);
330 bool (EXPORT* ClientBegin) (player_t& client);
331 void (EXPORT* ClientStartMatch) (player_t& client);
332 void (EXPORT* ClientUserinfoChanged) (player_t& client, const char* userinfo);
333 void (EXPORT* ClientDisconnect) (player_t& client);
334 void (EXPORT* ClientCommand) (player_t& client);
335
336 int (EXPORT* ClientAction) (player_t& client);
337 void (EXPORT* ClientEndRound) (player_t& client);
338 void (EXPORT* ClientTeamInfo) (const player_t& client);
339 void (EXPORT* ClientInitActorStates) (const player_t& client);
340 int (EXPORT* ClientGetTeamNum) (const player_t& client);
341 bool (EXPORT* ClientIsReady) (const player_t* client); /* assert ! */
342
343 int (EXPORT* ClientGetActiveTeam) (void);
344 const char* (EXPORT* ClientGetName) (int pnum);
345
346 bool (EXPORT* RunFrame) (void);
347
352 void (EXPORT* ServerCommand) (void);
353
354 /* global variables shared between game and server */
355
356 /* The edict array is allocated in the game dll so it */
357 /* can vary in size from one game to another. */
358
364
369
370#ifdef _MSC_VER
371extern "C" __declspec(dllexport) game_export_t* GetGameAPI(game_import_t* import);
372#else
373extern "C" game_export_t* GetGameAPI(game_import_t* import);
374#endif
Definition aabb.h:42
An Edict of type Actor.
Definition g_edict.h:348
Definition line.h:31
bool isInUse() const
Definition game.h:52
void setInUse(bool inuse)
Definition game.h:55
void setNum(int num)
Definition game.h:61
int getNum(void) const
Definition game.h:58
bool isReady() const
Definition game.h:64
bool ready
Definition game.h:50
void setReady(bool ready)
Definition game.h:67
bool inuse
Definition game.h:48
int num
Definition game.h:49
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
Definition cmd.cpp:505
Cvar (console variable) header file.
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
Definition files.cpp:384
void FS_FreeFile(void *buffer)
Definition files.cpp:411
game_export_t * GetGameAPI(game_import_t *import)
Returns a pointer to the structure with all entry points and global variables.
Definition g_main.cpp:384
SrvEdict edict_t
Definition game.h:164
solid_t
edict->solid values
Definition game.h:153
@ SOLID_TRIGGER
Definition game.h:155
@ SOLID_BBOX
Definition game.h:156
@ SOLID_NOT
Definition game.h:154
@ SOLID_BSP
Definition game.h:157
SrvPlayer player_t
Definition game.h:72
Battlescape grid functions.
#define MAX_INFO_STRING
Definition infostring.h:36
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
const char * filename
Definition ioapi.h:41
const char int mode
Definition ioapi.h:41
void format(__printf__, 1, 2)))
QGL_EXTERN void(APIENTRY *qglActiveTexture)(GLenum texture)
QGL_EXTERN GLfloat f
Definition r_gl.h:114
#define EXPORT
Definition shared.h:74
#define IMPORT
Definition shared.h:75
#define OBJZERO(obj)
Definition shared.h:178
Interface to game library.
Describes a character with all its attributes.
Definition chr_shared.h:388
The csi structure is the client-server-information structure which contains all the static data neede...
Definition q_shared.h:515
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition cvar.h:71
A list of locations that cannot be moved to.
Definition grid.h:35
functions exported by the game subsystem
Definition game.h:317
bool day
Definition game.h:327
void(EXPORT *ServerCommand)(void)
int player_size
Definition game.h:366
void(EXPORT *ClientInitActorStates)(const player_t &client)
int apiversion
Definition game.h:318
void(EXPORT *ClientEndRound)(player_t &client)
void(EXPORT *ClientStartMatch)(player_t &client)
int edict_size
Definition game.h:361
int max_edicts
Definition game.h:363
bool(EXPORT *ClientIsReady)(const player_t *client)
int(EXPORT *ClientGetActiveTeam)(void)
void(EXPORT *ClientCommand)(player_t &client)
int num_edicts
Definition game.h:362
bool const char * entstring
Definition game.h:327
int maxplayersperteam
Definition game.h:367
char * userinfo
Definition game.h:329
edict_t * edicts
Definition game.h:360
bool(EXPORT *RunFrame)(void)
char size_t userinfoSize
Definition game.h:329
void(EXPORT *ClientDisconnect)(player_t &client)
void(EXPORT *Shutdown)(void)
void(EXPORT *Init)(void)
void(EXPORT *ClientTeamInfo)(const player_t &client)
int(EXPORT *ClientAction)(player_t &client)
player_t * players
Definition game.h:365
bool(EXPORT *ClientBegin)(player_t &client)
int(EXPORT *ClientGetTeamNum)(const player_t &client)
bool(EXPORT *ClientConnect)(player_t *client
const char *EXPORT * ClientGetName(int pnum)
functions provided by the main engine
Definition game.h:173
bool crouched
Definition game.h:233
bool(IMPORT *isOnMap)(const vec3_t vec)
int(IMPORT *GetEvent)(void)
const vec3_t at
Definition game.h:226
const csi_t * csi
Definition game.h:176
void(IMPORT *EndEvents)(void)
void(IMPORT *WriteDir)(const vec3_t pos)
__attribute__((format(__printf__, 1, 2)))
const char int line
Definition game.h:298
const pos3_t vec3_t vec
Definition game.h:235
const vec3_t const vec3_t angles
Definition game.h:199
const vec3_t origin
Definition game.h:199
void(IMPORT *QueueWriteByte)(byte c)
void(IMPORT *QueueEvent)(unsigned int mask
bool(IMPORT *GridShouldUseAutostand)(const pathing_t *path
const pos3_t to
Definition game.h:231
void(IMPORT *UnlinkEdict)(edict_t *ent)
byte ** buffer
Definition game.h:244
const vec3_t float speed
Definition game.h:226
int int entnum
Definition game.h:264
int(IMPORT *ReadString)(char *str
edict_t *IMPORT * GetEventEdict(void)
size_t length
Definition game.h:279
float(IMPORT *GetVisibility)(const pos3_t position)
const AABB const edict_t int contentmask
Definition game.h:209
void(IMPORT *ReadDir)(vec3_t vector)
void(IMPORT *LinkEdict)(edict_t *ent)
pathing_t const pos3_t const pos3_t byte int maxTUs
Definition game.h:229
const vec3_t stop
Definition game.h:223
trace_t(IMPORT *Trace)(const Line &traceLine
collision detection
const char * name
Definition game.h:202
int(IMPORT *PointContents)(const vec3_t point)
const char __attribute__((format(__printf__, 2, 3)))
void(IMPORT *WriteString)(const char *s)
int eType
Definition game.h:264
void(IMPORT *WriteGPos)(const pos3_t pos)
const char * fmt
Definition game.h:181
bool(IMPORT *GetConstIntFromNamespace)(const char *space
void(IMPORT *QueueWritePos)(const vec3_t pos)
bool(IMPORT *LoadModelAABB)(const char *model
void(IMPORT *ReadGPos)(pos3_t pos)
int(IMPORT *ReadByte)(void)
void(IMPORT *WriteLong)(int c)
cvar_t *IMPORT * Cvar_Set(const char *varName, const char *value,...) __attribute__((format(__printf__
pathing_t const pos3_t from
Definition game.h:228
float(IMPORT *GetBounceFraction)(const char *texture)
bool(IMPORT *TestLine)(const vec3_t start
fast version of a line trace but without including entities
int frame
Definition game.h:214
cvar_t *IMPORT * Cvar_Get(const char *varName, const char *value, int flags, const char *desc)
character_t * chr
Definition game.h:294
FILE *IMPORT * Sys_Fopen(const char *filename, const char *mode)
int * value
Definition game.h:287
pathing_t const pos3_t const pos3_t byte crouchingState
Definition game.h:229
const vec3_t float bool bool vec3_t v0
Definition game.h:226
void(IMPORT *WriteChar)(char c)
bool(IMPORT *CanActorStandHere)(actorSizeEnum_t actorSize
void(IMPORT *WriteFormat)(const char *format
const vec3_t float bool bool rolled
Definition game.h:226
bool(IMPORT *TestLineWithEnt)(const vec3_t start
fast version of a line trace that also includes entities
void(IMPORT *WriteByte)(byte c)
const char *IMPORT * Cmd_Argv(int n)
void(IMPORT *BroadcastPrintf)(int printlevel
const pos3_t byte bool stored
Definition game.h:231
void(IMPORT *WriteAngle)(float f)
unsigned int(IMPORT *ModelIndex)(const char *name)
pathing_t const pos3_t int distance
Definition game.h:228
bool(IMPORT *UnregisterConstVariable)(const char *name)
void(IMPORT *WritePos)(const vec3_t pos)
const vec3_t const int levelmask
Definition game.h:223
AABB & aabb
Definition game.h:200
int(IMPORT *ReadShort)(void)
int const char va_list ap
Definition game.h:185
float(IMPORT *ReadAngle)(void)
const char *IMPORT * Cmd_Args(void)
const AABB const edict_t * passent
Definition game.h:209
void(IMPORT *ReadPos)(vec3_t pos)
bool(IMPORT *GetConstInt)(const char *name
pathing_t const pos3_t const pos3_t targetPos
Definition game.h:229
const vec3_t const int const char ** entlist
Definition game.h:225
pathing_t const pos3_t int forbiddenList_t * fb_list
Definition game.h:228
void(IMPORT *QueueWriteString)(const char *s)
bool(IMPORT *GridFindPath)(const actorSizeEnum_t actorSize
void(IMPORT *ReadFormat)(const char *format
pathing_t * path
Definition game.h:228
void *IMPORT * TagMalloc(int size, int tag, const char *file, int line)
const char * file
Definition game.h:298
const char *IMPORT * GetFootstepSound(const char *texture)
const char *IMPORT * GetConstVariable(const char *space, int value)
const vec3_t float bool launched
Definition game.h:226
int(IMPORT *ReadLong)(void)
const AABB & box
Definition game.h:209
const char *IMPORT * FS_Gamedir(void)
int(IMPORT *ReadChar)(void)
int printlevel
Definition game.h:185
void(IMPORT *FS_FreeFile)(void *buffer)
void(IMPORT *WriteShort)(int c)
const pos3_t pos
Definition game.h:234
__attribute__((noreturn, format(__printf__, 1, 2)))
void(IMPORT *QueueWriteShort)(int c)
cvar_t *IMPORT const char *IMPORT * Cvar_String(const char *varName)
const GridBox const char ** list
Definition game.h:237
void(IMPORT *AbortEvents)(void)
void(IMPORT *MoveStore)(pathing_t *path)
void(IMPORT *FreeTags)(int tag
#define FILE
Tracing functions.
pos_t pos3_t[3]
Definition ufotypes.h:58
byte pos_t
Definition ufotypes.h:57
vec_t vec3_t[3]
Definition ufotypes.h:39
int32_t actorSizeEnum_t
Definition ufotypes.h:77