UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
game.h
Go to the documentation of this file.
1 
6 /*
7 All original material Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 Original file from Quake 2 v3.21: quake2-2.31/game/game.h
10 Copyright (C) 1997-2001 Id Software, Inc.
11 
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (at your option) any later version.
16 
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 
21 See the GNU General Public License for more details.
22 
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, 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 
39 class Edict;
40 class Actor;
41 class SrvEdict;
42 
43 #ifndef GAME_INCLUDE
44 
45 class SrvPlayer
46 {
47 public:
48  bool inuse;
49  int num;
50  bool ready;
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  }
71 };
73 
74 #else
75 
77 typedef struct client_persistent_s {
78  char userinfo[MAX_INFO_STRING];
79  char netname[16];
80 
81  int team;
83  bool ai;
86  Actor* _last;
88  float flood_locktill;
89  float flood_when[10];
90  int flood_whenhead;
92  inline void setLastActor(Actor* lastActor) {
93  _last = lastActor;
94  }
95  inline Actor* getLastActor() {
96  return _last;
97  }
98 } client_persistent_t;
99 
103 class Player {
104 public:
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;
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 };
147 typedef Player player_t;
148 
149 #endif
150 
151 
153 typedef enum {
158 } solid_t;
159 
160 #ifndef GAME_INCLUDE
161 
162 #include "srvedict.h"
163 
165 #else
166 typedef Edict edict_t;
167 
168 #endif /* GAME_INCLUDE */
169 
170 /*=============================================================== */
171 
173 typedef 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);
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);
245  void (IMPORT* FS_FreeFile) (void* 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);
266  edict_t* (IMPORT* GetEventEdict) (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);
313  void (IMPORT* AddCommandString) (const char* text, ...) __attribute__((format(__printf__, 1, 2)));
314 } game_import_t;
315 
317 typedef 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 
368 } game_export_t;
369 
370 #ifdef _MSC_VER
371 extern "C" __declspec(dllexport) game_export_t* GetGameAPI(game_import_t* import);
372 #else
373 extern "C" game_export_t* GetGameAPI(game_import_t* import);
374 #endif
#define IMPORT
Definition: shared.h:75
const AABB & box
Definition: game.h:209
const char * userinfo
Definition: game.h:332
const char * fmt
Definition: game.h:181
const vec3_t float bool launched
Definition: game.h:226
int printlevel
Definition: game.h:185
SrvPlayer player_t
Definition: game.h:72
player_t * players
Definition: game.h:365
const char *IMPORT * GetFootstepSound(const char *texture)
pathing_t const pos3_t const pos3_t targetPos
Definition: game.h:229
const GridBox const char ** list
Definition: game.h:237
int maxplayersperteam
Definition: game.h:367
const vec3_t float speed
Definition: game.h:226
void setInUse(bool inuse)
Definition: game.h:55
pos_t(IMPORT *MoveLength)(const pathing_t *path
const AABB const edict_t int contentmask
Definition: game.h:209
int player_size
Definition: game.h:366
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition: cvar.h:71
const char * file
Definition: game.h:298
int eType
Definition: game.h:264
Definition: game.h:45
#define EXPORT
Definition: shared.h:74
int32_t actorSizeEnum_t
Definition: ufotypes.h:77
Definition: aabb.h:42
const char * filename
Definition: ioapi.h:41
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
int int entnum
Definition: game.h:264
bool ready
Definition: game.h:50
#define FILE
Definition: test_webapi.cpp:30
pathing_t const pos3_t const pos3_t byte crouchingState
Definition: game.h:229
const AABB const edict_t * passent
Definition: game.h:209
const vec3_t origin
Definition: game.h:199
bool const char * entstring
Definition: game.h:327
solid_t
edict->solid values
Definition: game.h:153
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
Definition: files.cpp:384
const vec3_t const int levelmask
Definition: game.h:223
pathing_t * path
Definition: game.h:228
int value
Definition: game.h:290
size_t length
Definition: game.h:279
const csi_t * csi
Definition: game.h:176
const char int line
Definition: game.h:298
pathing_t const pos3_t const pos3_t byte int maxTUs
Definition: game.h:229
char size_t userinfoSize
Definition: game.h:329
functions exported by the game subsystem
Definition: game.h:317
pathing_t const pos3_t int distance
Definition: game.h:228
int size
Definition: game.h:284
functions provided by the main engine
Definition: game.h:173
#define MAX_INFO_STRING
Definition: infostring.h:36
GLsizei size
Definition: r_gl.h:152
#define OBJZERO(obj)
Definition: shared.h:178
float(IMPORT *GetBounceFraction)(const char *texture)
The csi structure is the client-server-information structure which contains all the static data neede...
Definition: q_shared.h:515
const char * name
Definition: game.h:202
const vec3_t float bool bool rolled
Definition: game.h:226
const vec3_t const vec3_t angles
Definition: game.h:199
AABB & aabb
Definition: game.h:200
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
const char *IMPORT * GetConstVariable(const char *space, int value)
bool isReady() const
Definition: game.h:64
pathing_t const pos3_t int forbiddenList_t * fb_list
Definition: game.h:228
const vec3_t float bool bool vec3_t v0
Definition: game.h:226
int const char va_list ap
Definition: game.h:185
const char *IMPORT * FS_Gamedir(void)
int num
Definition: game.h:49
void(IMPORT *BroadcastPrintf)(int printlevel
An Edict of type Actor.
Definition: g_edict.h:348
bool isInUse() const
Definition: game.h:52
Definition: line.h:31
Definition: grid.h:83
const pos3_t vec3_t vec
Definition: game.h:235
pos_t pos3_t[3]
Definition: ufotypes.h:58
bool crouched
Definition: game.h:233
int seed
Definition: game.h:175
const pos3_t from
Definition: game.h:232
pathing_t const pos3_t from
Definition: game.h:228
void setReady(bool ready)
Definition: game.h:67
int getNum(void) const
Definition: game.h:58
Interface to game library.
QGL_EXTERN GLfloat f
Definition: r_gl.h:114
struct game_export_s game_export_t
functions exported by the game subsystem
cvar_t *IMPORT * Cvar_Get(const char *varName, const char *value, int flags, const char *desc)
character_t * chr
Definition: game.h:294
int * value
Definition: game.h:287
cvar_t *IMPORT const char *IMPORT * Cvar_String(const char *varName)
const vec3_t stop
Definition: game.h:223
SrvEdict edict_t
Definition: game.h:164
const vec3_t const int const char ** entlist
Definition: game.h:225
int apiversion
Definition: game.h:318
int max_edicts
Definition: game.h:363
int frame
Definition: game.h:214
const pos3_t pos
Definition: game.h:234
const char __attribute__((format(__printf__, 2, 3)))
const char int mode
Definition: ioapi.h:41
edict_t *IMPORT * GetEventEdict(void)
FILE *IMPORT * Sys_Fopen(const char *filename, const char *mode)
const char *IMPORT * Cmd_Args(void)
const pos3_t byte bool stored
Definition: game.h:231
vec_t vec3_t[3]
Definition: ufotypes.h:39
bool inuse
Definition: game.h:48
cvar_t *IMPORT * Cvar_Set(const char *varName, const char *value,...) __attribute__((format(__printf__
bool(IMPORT *LoadModelAABB)(const char *model
unsigned int(IMPORT *ModelIndex)(const char *name)
void *IMPORT * TagMalloc(int size, int tag, const char *file, int line)
byte ** buffer
Definition: game.h:244
trace_t(IMPORT *Trace)(const Line &traceLine
collision detection
const pos3_t to
Definition: game.h:231
A list of locations that cannot be moved to.
Definition: grid.h:35
const char int * value
Definition: game.h:288
void setNum(int num)
Definition: game.h:61
Definition: g_edict.h:45
uint8_t byte
Definition: ufotypes.h:34
int edict_size
Definition: game.h:361
const char *IMPORT * Cmd_Argv(int n)
const vec3_t at
Definition: game.h:226
void format(__printf__, 1, 2)))
int num_edicts
Definition: game.h:362
edict_t * edicts
Definition: game.h:360
void FS_FreeFile(void *buffer)
Definition: files.cpp:411
Describes a character with all its attributes.
Definition: chr_shared.h:369