1 /* 2 Copyright (C) 1997-2001 Id Software, Inc. 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU General Public License 6 as published by the Free Software Foundation; either version 2 7 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13 See the GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 */ 20 21 // game.h -- game module information visible to server 22 23 #define GAME_API_VERSION 3 24 25 // edict->svflags 26 27 #define SVF_NOCLIENT 0x00000001 // don't send entity to clients, even if it has effects 28 #define SVF_DEADMONSTER 0x00000002 // treat as CONTENTS_DEADMONSTER for collision 29 #define SVF_MONSTER 0x00000004 // treat as CONTENTS_MONSTER for collision 30 #define SVF_FAKECLIENT 0x00000020 // do not try to send anything to this client 31 32 // edict->solid values 33 34 typedef enum 35 { 36 SOLID_NOT, // no interaction with other objects 37 SOLID_TRIGGER, // only touch when inside, after moving 38 SOLID_BBOX, // touch on edge 39 SOLID_BSP // bsp clip, touch on edge 40 } solid_t; 41 42 //=============================================================== 43 44 // link_t is only used for entity area links now 45 typedef struct link_s 46 { 47 struct link_s *prev, *next; 48 } link_t; 49 50 #define MAX_ENT_CLUSTERS 16 51 52 53 typedef struct edict_s edict_t; 54 typedef struct gclient_s gclient_t; 55 56 57 #ifndef GAME_INCLUDE 58 59 struct gclient_s 60 { 61 player_state_t ps; // communicated by server to clients 62 int ping; 63 64 // the game dll can add anything it wants after 65 // this point in the structure 66 67 }; 68 69 70 struct edict_s 71 { 72 entity_state_t s; 73 struct gclient_s *client; 74 qboolean inuse; 75 int linkcount; 76 77 // FIXME: move these fields to a server private sv_entity_t 78 link_t area; // linked to a division node or leaf 79 80 int num_clusters; // if -1, use headnode instead 81 int clusternums[MAX_ENT_CLUSTERS]; 82 int headnode; // unused if num_clusters != -1 83 int areanum, areanum2; 84 85 //================================ 86 87 int svflags; // SVF_NOCLIENT, SVF_DEADMONSTER, SVF_MONSTER, etc 88 vec3_t mins, maxs; 89 vec3_t absmin, absmax, size; 90 solid_t solid; 91 int clipmask; 92 edict_t *owner; 93 94 int redirect_number; //for ghost mode 95 96 // must be accessible to server code for collision detection 97 int dmteam; 98 int teamset; 99 #define RED_TEAM 0 100 #define BLUE_TEAM 1 101 #define NO_TEAM 2 102 103 // the game dll can add anything it wants after 104 // this point in the structure 105 }; 106 107 #endif // GAME_INCLUDE 108 109 //=============================================================== 110 111 // 112 // functions provided by the main engine 113 // 114 typedef struct 115 { 116 117 // special messages 118 void (*bprintf) (int printlevel, char *fmt, ...); 119 void (*dprintf) (char *fmt, ...); 120 void (*cprintf) (edict_t *ent, int printlevel, char *fmt, ...); 121 void (*centerprintf) (edict_t *ent, char *fmt, ...); 122 void (*sound) (edict_t *ent, int channel, int soundindex, float volume, float attenuation, float timeofs); 123 void (*positioned_sound) (vec3_t origin, edict_t *ent, int channel, int soundinedex, float volume, float attenuation, float timeofs); 124 125 // config strings hold all the index strings, the lightstyles, 126 // and misc data like the sky definition and cdtrack. 127 // All of the current configstrings are sent to clients when 128 // they connect, and changes are sent to all connected clients. 129 void (*configstring) (int num, char *string); 130 131 void (*error) (char *fmt, ...); 132 133 // the *index functions create configstrings and some internal server state 134 int (*modelindex) (char *name); 135 int (*soundindex) (char *name); 136 int (*imageindex) (char *name); 137 138 // for checking if assets are already loaded - return 0 if they are not 139 int (*checkmodelindex) (char *name); 140 int (*checksoundindex) (char *name); 141 int (*checkimageindex) (char *name); 142 143 void (*setmodel) (edict_t *ent, char *name); 144 145 // collision detection 146 trace_t (*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask); 147 int (*pointcontents) (vec3_t point); 148 qboolean (*inPVS) (vec3_t p1, vec3_t p2); 149 qboolean (*inPHS) (vec3_t p1, vec3_t p2); 150 void (*SetAreaPortalState) (int portalnum, qboolean open); 151 qboolean (*AreasConnected) (int area1, int area2); 152 153 // an entity will never be sent to a client or used for collision 154 // if it is not passed to linkentity. If the size, position, or 155 // solidity changes, it must be relinked. 156 void (*linkentity) (edict_t *ent); 157 void (*unlinkentity) (edict_t *ent); // call before removing an interactive edict 158 int (*BoxEdicts) (vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype); 159 void (*Pmove) (pmove_t *pmove); // player movement code common with client prediction 160 161 // network messaging 162 void (*multicast) (vec3_t origin, multicast_t to); 163 void (*unicast) (edict_t *ent, qboolean reliable); 164 void (*WriteChar) (int c); 165 void (*WriteByte) (int c); 166 void (*WriteShort) (int c); 167 void (*WriteLong) (int c); 168 void (*WriteFloat) (float f); 169 void (*WriteString) (char *s); 170 void (*WritePosition) (vec3_t pos); // some fractional bits 171 void (*WriteDir) (vec3_t pos); // single byte encoded, very coarse 172 void (*WriteAngle) (float f); 173 174 // managed memory allocation 175 void *(*TagMalloc) (int size, int tag); 176 void (*TagFree) (void *block); 177 void (*FreeTags) (int tag); 178 179 // console variable interaction 180 cvar_t *(*cvar) (char *var_name, char *value, int flags); 181 void (*cvar_set) (char *var_name, char *value); 182 cvar_t *(*cvar_forceset) (char *var_name, char *value); 183 void (*cvar_describe) (cvar_t *var, char *description_string); 184 185 // ClientCommand and ServerCommand parameter access 186 int (*argc) (void); 187 char *(*argv) (int n); 188 char *(*args) (void); // concatenation of all argv >= 1 189 190 // add commands to the server console as if they were typed in 191 // for map changing, etc 192 void (*AddCommandString) (char *text); 193 194 void (*DebugGraph) (float value, const float color[]); 195 196 int (*Sys_Milliseconds) (void); 197 198 // File System path from relative path (added 2010-08) 199 qboolean (*FullPath)(char *full_path, size_t pathsize, const char *relative_path); 200 void (*FullWritePath)(char *full_path, size_t pathsize, const char *relative_path); 201 202 } game_import_t; 203 204 // 205 // functions exported by the game subsystem 206 // 207 typedef struct 208 { 209 int apiversion; 210 211 // the init function will only be called when a game starts, 212 // not each time a level is loaded. Persistant data for clients 213 // and the server can be allocated in init 214 void (*Init) (void); 215 void (*Shutdown) (void); 216 217 // each new level entered will cause a call to SpawnEntities 218 void (*SpawnEntities) (char *mapname, char *entstring, char *spawnpoint); 219 220 qboolean (*ClientConnect)( edict_t *ent, char *userinfo); 221 222 void (*ClientBegin) (edict_t *ent); 223 void (*ClientUserinfoChanged) (edict_t *ent, char *userinfo, int whereFrom); 224 void (*ClientDisconnect) (edict_t *ent); 225 void (*ClientCommand) (edict_t *ent); 226 void (*ClientThink) (edict_t *ent, usercmd_t *cmd); 227 228 int (*ACESP_FindBotNum) (void); 229 230 void (*RunFrame) (void); 231 void (*ForceExitIntermission) (void); 232 233 // ServerCommand will be called when an "sv <command>" command is issued on the 234 // server console. 235 // The game can issue gi.argc() / gi.argv() commands to get the rest 236 // of the parameters 237 void (*ServerCommand) (void); 238 239 // 240 // global variables shared between game and server 241 // 242 243 // The edict array is allocated in the game dll so it 244 // can vary in size from one game to another. 245 // 246 // The size will be fixed when ge->Init() is called 247 struct edict_s *edicts; 248 int edict_size; 249 int num_edicts; // current number, <= max_edicts 250 int max_edicts; 251 } game_export_t; 252 253 game_export_t *GetGameApi (game_import_t *import); 254