game.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. // game.h -- game dll information visible to server
  4. #define GAME_API_VERSION 3
  5. // edict->svflags
  6. #define SVF_NOCLIENT 0x00000001 // don't send entity to clients, even if it has effects
  7. #define SVF_DEADMONSTER 0x00000002 // treat as CONTENTS_DEADMONSTER for collision
  8. #define SVF_MONSTER 0x00000004 // treat as CONTENTS_MONSTER for collision
  9. //ROGUE -- added for things that are damageable, but not monsters
  10. // right now, only the tesla has this
  11. #define SVF_DAMAGEABLE 0x00000008
  12. //ROGUE end
  13. // edict->solid values
  14. typedef enum
  15. {
  16. SOLID_NOT, // no interaction with other objects
  17. SOLID_TRIGGER, // only touch when inside, after moving
  18. SOLID_BBOX, // touch on edge
  19. SOLID_BSP // bsp clip, touch on edge
  20. } solid_t;
  21. //===============================================================
  22. // link_t is only used for entity area links now
  23. typedef struct link_s
  24. {
  25. struct link_s *prev, *next;
  26. } link_t;
  27. #define MAX_ENT_CLUSTERS 16
  28. typedef struct edict_s edict_t;
  29. typedef struct gclient_s gclient_t;
  30. #ifndef GAME_INCLUDE
  31. struct gclient_s
  32. {
  33. player_state_t ps; // communicated by server to clients
  34. int ping;
  35. // the game dll can add anything it wants after
  36. // this point in the structure
  37. };
  38. struct edict_s
  39. {
  40. entity_state_t s;
  41. struct gclient_s *client;
  42. qboolean inuse;
  43. int linkcount;
  44. // FIXME: move these fields to a server private sv_entity_t
  45. link_t area; // linked to a division node or leaf
  46. int num_clusters; // if -1, use headnode instead
  47. int clusternums[MAX_ENT_CLUSTERS];
  48. int headnode; // unused if num_clusters != -1
  49. int areanum, areanum2;
  50. //================================
  51. int svflags; // SVF_NOCLIENT, SVF_DEADMONSTER, SVF_MONSTER, etc
  52. vec3_t mins, maxs;
  53. vec3_t absmin, absmax, size;
  54. solid_t solid;
  55. int clipmask;
  56. edict_t *owner;
  57. // the game dll can add anything it wants after
  58. // this point in the structure
  59. };
  60. #endif // GAME_INCLUDE
  61. //===============================================================
  62. //
  63. // functions provided by the main engine
  64. //
  65. typedef struct
  66. {
  67. // special messages
  68. void (*bprintf) (int printlevel, char *fmt, ...);
  69. void (*dprintf) (char *fmt, ...);
  70. void (*cprintf) (edict_t *ent, int printlevel, char *fmt, ...);
  71. void (*centerprintf) (edict_t *ent, char *fmt, ...);
  72. void (*sound) (edict_t *ent, int channel, int soundindex, float volume, float attenuation, float timeofs);
  73. void (*positioned_sound) (vec3_t origin, edict_t *ent, int channel, int soundinedex, float volume, float attenuation, float timeofs);
  74. // config strings hold all the index strings, the lightstyles,
  75. // and misc data like the sky definition and cdtrack.
  76. // All of the current configstrings are sent to clients when
  77. // they connect, and changes are sent to all connected clients.
  78. void (*configstring) (int num, char *string);
  79. void (*error) (char *fmt, ...);
  80. // the *index functions create configstrings and some internal server state
  81. int (*modelindex) (char *name);
  82. int (*soundindex) (char *name);
  83. int (*imageindex) (char *name);
  84. void (*setmodel) (edict_t *ent, char *name);
  85. // collision detection
  86. trace_t (*trace) (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passent, int contentmask);
  87. int (*pointcontents) (vec3_t point);
  88. qboolean (*inPVS) (vec3_t p1, vec3_t p2);
  89. qboolean (*inPHS) (vec3_t p1, vec3_t p2);
  90. void (*SetAreaPortalState) (int portalnum, qboolean open);
  91. qboolean (*AreasConnected) (int area1, int area2);
  92. // an entity will never be sent to a client or used for collision
  93. // if it is not passed to linkentity. If the size, position, or
  94. // solidity changes, it must be relinked.
  95. void (*linkentity) (edict_t *ent);
  96. void (*unlinkentity) (edict_t *ent); // call before removing an interactive edict
  97. int (*BoxEdicts) (vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype);
  98. void (*Pmove) (pmove_t *pmove); // player movement code common with client prediction
  99. // network messaging
  100. void (*multicast) (vec3_t origin, multicast_t to);
  101. void (*unicast) (edict_t *ent, qboolean reliable);
  102. void (*WriteChar) (int c);
  103. void (*WriteByte) (int c);
  104. void (*WriteShort) (int c);
  105. void (*WriteLong) (int c);
  106. void (*WriteFloat) (float f);
  107. void (*WriteString) (char *s);
  108. void (*WritePosition) (vec3_t pos); // some fractional bits
  109. void (*WriteDir) (vec3_t pos); // single byte encoded, very coarse
  110. void (*WriteAngle) (float f);
  111. // managed memory allocation
  112. void *(*TagMalloc) (int size, int tag);
  113. void (*TagFree) (void *block);
  114. void (*FreeTags) (int tag);
  115. // console variable interaction
  116. cvar_t *(*cvar) (char *var_name, char *value, int flags);
  117. cvar_t *(*cvar_set) (char *var_name, char *value);
  118. cvar_t *(*cvar_forceset) (char *var_name, char *value);
  119. // ClientCommand and ServerCommand parameter access
  120. int (*argc) (void);
  121. char *(*argv) (int n);
  122. char *(*args) (void); // concatenation of all argv >= 1
  123. // add commands to the server console as if they were typed in
  124. // for map changing, etc
  125. void (*AddCommandString) (char *text);
  126. void (*DebugGraph) (float value, int color);
  127. } game_import_t;
  128. //
  129. // functions exported by the game subsystem
  130. //
  131. typedef struct
  132. {
  133. int apiversion;
  134. // the init function will only be called when a game starts,
  135. // not each time a level is loaded. Persistant data for clients
  136. // and the server can be allocated in init
  137. void (*Init) (void);
  138. void (*Shutdown) (void);
  139. // each new level entered will cause a call to SpawnEntities
  140. void (*SpawnEntities) (char *mapname, char *entstring, char *spawnpoint);
  141. // Read/Write Game is for storing persistant cross level information
  142. // about the world state and the clients.
  143. // WriteGame is called every time a level is exited.
  144. // ReadGame is called on a loadgame.
  145. void (*WriteGame) (char *filename, qboolean autosave);
  146. void (*ReadGame) (char *filename);
  147. // ReadLevel is called after the default map information has been
  148. // loaded with SpawnEntities
  149. void (*WriteLevel) (char *filename);
  150. void (*ReadLevel) (char *filename);
  151. qboolean (*ClientConnect) (edict_t *ent, char *userinfo);
  152. void (*ClientBegin) (edict_t *ent);
  153. void (*ClientUserinfoChanged) (edict_t *ent, char *userinfo);
  154. void (*ClientDisconnect) (edict_t *ent);
  155. void (*ClientCommand) (edict_t *ent);
  156. void (*ClientThink) (edict_t *ent, usercmd_t *cmd);
  157. void (*RunFrame) (void);
  158. // ServerCommand will be called when an "sv <command>" command is issued on the
  159. // server console.
  160. // The game can issue gi.argc() / gi.argv() commands to get the rest
  161. // of the parameters
  162. void (*ServerCommand) (void);
  163. //
  164. // global variables shared between game and server
  165. //
  166. // The edict array is allocated in the game dll so it
  167. // can vary in size from one game to another.
  168. //
  169. // The size will be fixed when ge->Init() is called
  170. struct edict_s *edicts;
  171. int edict_size;
  172. int num_edicts; // current number, <= max_edicts
  173. int max_edicts;
  174. } game_export_t;
  175. game_export_t *GetGameApi (game_import_t *import);