game.h 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318
  1. // Copyright (c) ZeniMax Media Inc.
  2. // Licensed under the GNU General Public License 2.0.
  3. // game.h - game API stuff
  4. #pragma once
  5. #include <array>
  6. #include <limits.h>
  7. // compatibility with legacy float[3] stuff for engine
  8. #ifdef GAME_INCLUDE
  9. using gvec3_t = vec3_t;
  10. using gvec3_ptr_t = vec3_t *;
  11. using gvec3_cptr_t = const vec3_t *;
  12. using gvec3_ref_t = vec3_t &;
  13. using gvec3_cref_t = const vec3_t &;
  14. using gvec4_t = std::array<float, 4>;
  15. #else
  16. using gvec3_t = float[3];
  17. using gvec3_ptr_t = gvec3_t;
  18. using gvec3_ref_t = gvec3_t;
  19. using gvec3_cref_t = const gvec3_t;
  20. using gvec3_cptr_t = const gvec3_t;
  21. using gvec4_t = float[4];
  22. #endif
  23. constexpr size_t MAX_SPLIT_PLAYERS = 8;
  24. struct rgba_t
  25. {
  26. uint8_t r, g, b, a;
  27. };
  28. struct vec2_t
  29. {
  30. float x, y;
  31. };
  32. constexpr rgba_t rgba_red { 255, 0, 0, 255 };
  33. constexpr rgba_t rgba_blue { 0, 0, 255, 255 };
  34. constexpr rgba_t rgba_green { 0, 255, 0, 255 };
  35. constexpr rgba_t rgba_yellow { 255, 255, 0, 255 };
  36. constexpr rgba_t rgba_white { 255, 255, 255, 255 };
  37. constexpr rgba_t rgba_black { 0, 0, 0, 255 };
  38. constexpr rgba_t rgba_cyan { 0, 255, 255, 255 };
  39. constexpr rgba_t rgba_magenta { 255, 0, 255, 255 };
  40. constexpr rgba_t rgba_orange { 116, 61, 50, 255 };
  41. constexpr size_t MAX_NETNAME = 32;
  42. constexpr float STEPSIZE = 18.0f;
  43. // ugly hack to support bitflags on enums
  44. // and use enable_if to prevent confusing cascading
  45. // errors if you use the operators wrongly
  46. #define MAKE_ENUM_BITFLAGS(T) \
  47. constexpr T operator~(const T &v) \
  48. { \
  49. return static_cast<T>(~static_cast<std::underlying_type_t<T>>(v)); \
  50. } \
  51. constexpr T operator|(const T &v, const T &v2) \
  52. { \
  53. return static_cast<T>(static_cast<std::underlying_type_t<T>>(v) | static_cast<std::underlying_type_t<T>>(v2)); \
  54. } \
  55. constexpr T operator&(const T &v, const T &v2) \
  56. { \
  57. return static_cast<T>(static_cast<std::underlying_type_t<T>>(v) & static_cast<std::underlying_type_t<T>>(v2)); \
  58. } \
  59. constexpr T operator^(const T &v, const T &v2) \
  60. { \
  61. return static_cast<T>(static_cast<std::underlying_type_t<T>>(v) ^ static_cast<std::underlying_type_t<T>>(v2)); \
  62. } \
  63. template<typename T2 = T, typename = std::enable_if_t<std::is_same_v<T2, T>>> \
  64. constexpr T &operator|=(T &v, const T &v2) \
  65. { \
  66. v = v | v2; \
  67. return v; \
  68. } \
  69. template<typename T2 = T, typename = std::enable_if_t<std::is_same_v<T2, T>>> \
  70. constexpr T &operator&=(T &v, const T &v2) \
  71. { \
  72. v = v & v2; \
  73. return v; \
  74. } \
  75. template<typename T2 = T, typename = std::enable_if_t<std::is_same_v<T2, T>>> \
  76. constexpr T &operator^=(T &v, const T &v2) \
  77. { \
  78. v = v ^ v2; \
  79. return v; \
  80. }
  81. using byte = uint8_t;
  82. // bit simplification
  83. template<size_t n>
  84. using bit_t = std::conditional_t<n >= 32, uint64_t, uint32_t>;
  85. // template is better for this because you can see
  86. // it in the hover-over preview
  87. template<size_t n>
  88. constexpr bit_t<n> bit_v = 1ull << n;
  89. #if defined(KEX_Q2GAME_EXPORTS)
  90. #define Q2GAME_API extern "C" __declspec( dllexport )
  91. #elif defined(KEX_Q2GAME_IMPORTS)
  92. #define Q2GAME_API extern "C" __declspec( dllimport )
  93. #else
  94. #define Q2GAME_API
  95. #endif
  96. // game.h -- game dll information visible to server
  97. // PARIL_NEW_API - value likely not used by any other Q2-esque engine in the wild
  98. constexpr int32_t GAME_API_VERSION = 2023;
  99. constexpr int32_t CGAME_API_VERSION = 2022;
  100. // forward declarations
  101. struct edict_t;
  102. struct gclient_t;
  103. constexpr size_t MAX_STRING_CHARS = 1024; // max length of a string passed to Cmd_TokenizeString
  104. constexpr size_t MAX_STRING_TOKENS = 80; // max tokens resulting from Cmd_TokenizeString
  105. constexpr size_t MAX_TOKEN_CHARS = 512; // max length of an individual token
  106. constexpr size_t MAX_QPATH = 64; // max length of a quake game pathname
  107. constexpr size_t MAX_OSPATH = 128; // max length of a filesystem pathname
  108. //
  109. // per-level limits
  110. //
  111. constexpr size_t MAX_CLIENTS = 256; // absolute limit
  112. constexpr size_t MAX_EDICTS = 8192; // upper limit, due to svc_sound encoding as 15 bits
  113. constexpr size_t MAX_LIGHTSTYLES = 256;
  114. constexpr size_t MAX_MODELS = 8192; // these are sent over the net as shorts
  115. constexpr size_t MAX_SOUNDS = 2048; // so they cannot be blindly increased
  116. constexpr size_t MAX_IMAGES = 512;
  117. constexpr size_t MAX_ITEMS = 256;
  118. constexpr size_t MAX_GENERAL = (MAX_CLIENTS * 2); // general config strings
  119. // [Sam-KEX]
  120. constexpr size_t MAX_SHADOW_LIGHTS = 256;
  121. // game print flags
  122. enum print_type_t
  123. {
  124. PRINT_LOW = 0, // pickup messages
  125. PRINT_MEDIUM = 1, // death messages
  126. PRINT_HIGH = 2, // critical messages
  127. PRINT_CHAT = 3, // chat messages
  128. PRINT_TYPEWRITER = 4, // centerprint but typed out one char at a time
  129. PRINT_CENTER = 5, // centerprint without a separate function (loc variants only)
  130. PRINT_TTS = 6, // PRINT_HIGH but will speak for players with narration on
  131. PRINT_BROADCAST = (1 << 3), // Bitflag, add to message to broadcast print to all clients.
  132. PRINT_NO_NOTIFY = (1 << 4) // Bitflag, don't put on notify
  133. };
  134. MAKE_ENUM_BITFLAGS(print_type_t);
  135. // [Paril-KEX] max number of arguments (not including the base) for
  136. // localization prints
  137. constexpr size_t MAX_LOCALIZATION_ARGS = 8;
  138. // destination class for gi.multicast()
  139. enum multicast_t
  140. {
  141. MULTICAST_ALL,
  142. MULTICAST_PHS,
  143. MULTICAST_PVS
  144. };
  145. /*
  146. ==========================================================
  147. CVARS (console variables)
  148. ==========================================================
  149. */
  150. enum cvar_flags_t : uint32_t
  151. {
  152. CVAR_NOFLAGS = 0,
  153. CVAR_ARCHIVE = bit_v<0>, // set to cause it to be saved to config
  154. CVAR_USERINFO = bit_v<1>, // added to userinfo when changed
  155. CVAR_SERVERINFO = bit_v<2>, // added to serverinfo when changed
  156. CVAR_NOSET = bit_v<3>, // don't allow change from console at all,
  157. // but can be set from the command line
  158. CVAR_LATCH = bit_v<4>, // save changes until server restart
  159. CVAR_USER_PROFILE = bit_v<5>, // like CVAR_USERINFO but not sent to server
  160. };
  161. MAKE_ENUM_BITFLAGS(cvar_flags_t);
  162. // nothing outside the Cvar_*() functions should modify these fields!
  163. struct cvar_t
  164. {
  165. char *name;
  166. char *string;
  167. char *latched_string; // for CVAR_LATCH vars
  168. cvar_flags_t flags;
  169. int32_t modified_count; // changed each time the cvar is changed, but never zero
  170. float value;
  171. cvar_t *next;
  172. int32_t integer; // integral value
  173. };
  174. // convenience function to check if the given cvar ptr has been
  175. // modified from its previous modified value, and automatically
  176. // assigns modified to cvar's current value
  177. inline bool Cvar_WasModified(const cvar_t *cvar, int32_t &modified)
  178. {
  179. if (cvar->modified_count != modified)
  180. {
  181. modified = cvar->modified_count;
  182. return true;
  183. }
  184. return false;
  185. }
  186. /*
  187. ==============================================================
  188. COLLISION DETECTION
  189. ==============================================================
  190. */
  191. // lower bits are stronger, and will eat weaker brushes completely
  192. enum contents_t : uint32_t
  193. {
  194. CONTENTS_NONE = 0,
  195. CONTENTS_SOLID = bit_v<0>, // an eye is never valid in a solid
  196. CONTENTS_WINDOW = bit_v<1>, // translucent, but not watery
  197. CONTENTS_AUX = bit_v<2>,
  198. CONTENTS_LAVA = bit_v<3>,
  199. CONTENTS_SLIME = bit_v<4>,
  200. CONTENTS_WATER = bit_v<5>,
  201. CONTENTS_MIST = bit_v<6>,
  202. // remaining contents are non-visible, and don't eat brushes
  203. CONTENTS_NO_WATERJUMP = bit_v<13>, // [Paril-KEX] this brush cannot be waterjumped out of
  204. CONTENTS_PROJECTILECLIP = bit_v<14>, // [Paril-KEX] projectiles will collide with this
  205. CONTENTS_AREAPORTAL = bit_v<15>,
  206. CONTENTS_PLAYERCLIP = bit_v<16>,
  207. CONTENTS_MONSTERCLIP = bit_v<17>,
  208. // currents can be added to any other contents, and may be mixed
  209. CONTENTS_CURRENT_0 = bit_v<18>,
  210. CONTENTS_CURRENT_90 = bit_v<19>,
  211. CONTENTS_CURRENT_180 = bit_v<20>,
  212. CONTENTS_CURRENT_270 = bit_v<21>,
  213. CONTENTS_CURRENT_UP = bit_v<22>,
  214. CONTENTS_CURRENT_DOWN = bit_v<23>,
  215. CONTENTS_ORIGIN = bit_v<24>, // removed before bsping an entity
  216. CONTENTS_MONSTER = bit_v<25>, // should never be on a brush, only in game
  217. CONTENTS_DEADMONSTER = bit_v<26>,
  218. CONTENTS_DETAIL = bit_v<27>, // brushes to be added after vis leafs
  219. CONTENTS_TRANSLUCENT = bit_v<28>, // auto set if any surface has trans
  220. CONTENTS_LADDER = bit_v<29>,
  221. CONTENTS_PLAYER = bit_v<30>, // [Paril-KEX] should never be on a brush, only in game; player
  222. CONTENTS_PROJECTILE = bit_v<31> // [Paril-KEX] should never be on a brush, only in game; projectiles.
  223. // used to solve deadmonster collision issues.
  224. };
  225. MAKE_ENUM_BITFLAGS(contents_t);
  226. constexpr contents_t LAST_VISIBLE_CONTENTS = CONTENTS_MIST;
  227. enum surfflags_t : uint32_t
  228. {
  229. SURF_NONE = 0,
  230. SURF_LIGHT = bit_v<0>, // value will hold the light strength
  231. SURF_SLICK = bit_v<1>, // effects game physics
  232. SURF_SKY = bit_v<2>, // don't draw, but add to skybox
  233. SURF_WARP = bit_v<3>, // turbulent water warp
  234. SURF_TRANS33 = bit_v<4>,
  235. SURF_TRANS66 = bit_v<5>,
  236. SURF_FLOWING = bit_v<6>, // scroll towards angle
  237. SURF_NODRAW = bit_v<7>, // don't bother referencing the texture
  238. SURF_ALPHATEST = bit_v<25>, // [Paril-KEX] alpha test using widely supported flag
  239. SURF_N64_UV = bit_v<28>, // [Sam-KEX] Stretches texture UVs
  240. SURF_N64_SCROLL_X = bit_v<29>, // [Sam-KEX] Texture scroll X-axis
  241. SURF_N64_SCROLL_Y = bit_v<30>, // [Sam-KEX] Texture scroll Y-axis
  242. SURF_N64_SCROLL_FLIP = bit_v<31> // [Sam-KEX] Flip direction of texture scroll
  243. };
  244. MAKE_ENUM_BITFLAGS(surfflags_t);
  245. // content masks
  246. constexpr contents_t MASK_ALL = static_cast<contents_t>(-1);
  247. constexpr contents_t MASK_SOLID = (CONTENTS_SOLID | CONTENTS_WINDOW);
  248. constexpr contents_t MASK_PLAYERSOLID = (CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_WINDOW | CONTENTS_MONSTER | CONTENTS_PLAYER);
  249. constexpr contents_t MASK_DEADSOLID = (CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_WINDOW);
  250. constexpr contents_t MASK_MONSTERSOLID = (CONTENTS_SOLID | CONTENTS_MONSTERCLIP | CONTENTS_WINDOW | CONTENTS_MONSTER | CONTENTS_PLAYER);
  251. constexpr contents_t MASK_WATER = (CONTENTS_WATER | CONTENTS_LAVA | CONTENTS_SLIME);
  252. constexpr contents_t MASK_OPAQUE = (CONTENTS_SOLID | CONTENTS_SLIME | CONTENTS_LAVA);
  253. constexpr contents_t MASK_SHOT = (CONTENTS_SOLID | CONTENTS_MONSTER | CONTENTS_PLAYER | CONTENTS_WINDOW | CONTENTS_DEADMONSTER);
  254. constexpr contents_t MASK_CURRENT = (CONTENTS_CURRENT_0 | CONTENTS_CURRENT_90 | CONTENTS_CURRENT_180 | CONTENTS_CURRENT_270 | CONTENTS_CURRENT_UP | CONTENTS_CURRENT_DOWN);
  255. constexpr contents_t MASK_BLOCK_SIGHT = ( CONTENTS_SOLID | CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_MONSTER | CONTENTS_PLAYER );
  256. constexpr contents_t MASK_NAV_SOLID = ( CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_WINDOW );
  257. constexpr contents_t MASK_LADDER_NAV_SOLID = ( CONTENTS_SOLID | CONTENTS_WINDOW );
  258. constexpr contents_t MASK_WALK_NAV_SOLID = ( CONTENTS_SOLID | CONTENTS_PLAYERCLIP | CONTENTS_WINDOW | CONTENTS_MONSTERCLIP );
  259. constexpr contents_t MASK_PROJECTILE = MASK_SHOT | CONTENTS_PROJECTILECLIP;
  260. // gi.BoxEdicts() can return a list of either solid or trigger entities
  261. // FIXME: eliminate AREA_ distinction?
  262. enum solidity_area_t
  263. {
  264. AREA_SOLID = 1,
  265. AREA_TRIGGERS = 2
  266. };
  267. // plane_t structure
  268. // !!! if this is changed, it must be changed in asm code too !!!
  269. struct cplane_t
  270. {
  271. gvec3_t normal;
  272. float dist;
  273. byte type; // for fast side tests
  274. byte signbits; // signx + (signy<<1) + (signz<<1)
  275. byte pad[2];
  276. };
  277. // [Paril-KEX]
  278. constexpr size_t MAX_MATERIAL_NAME = 16;
  279. struct csurface_t
  280. {
  281. char name[32];
  282. surfflags_t flags;
  283. int32_t value;
  284. // [Paril-KEX]
  285. uint32_t id; // unique texinfo ID, offset by 1 (0 is 'null')
  286. char material[MAX_MATERIAL_NAME];
  287. };
  288. // a trace is returned when a box is swept through the world
  289. struct trace_t
  290. {
  291. bool allsolid; // if true, plane is not valid
  292. bool startsolid; // if true, the initial point was in a solid area
  293. float fraction; // time completed, 1.0 = didn't hit anything
  294. gvec3_t endpos; // final position
  295. cplane_t plane; // surface normal at impact
  296. csurface_t *surface; // surface hit
  297. contents_t contents; // contents on other side of surface hit
  298. edict_t *ent; // not set by CM_*() functions
  299. // [Paril-KEX] the second-best surface hit from a trace
  300. cplane_t plane2; // second surface normal at impact
  301. csurface_t *surface2; // second surface hit
  302. };
  303. // pmove_state_t is the information necessary for client side movement
  304. // prediction
  305. enum pmtype_t
  306. {
  307. // can accelerate and turn
  308. PM_NORMAL,
  309. PM_GRAPPLE, // [Paril-KEX] pull towards velocity, no gravity
  310. PM_NOCLIP,
  311. PM_SPECTATOR, // [Paril-KEX] clip against walls, but not entities
  312. // no acceleration or turning
  313. PM_DEAD,
  314. PM_GIB, // different bounding box
  315. PM_FREEZE
  316. };
  317. // pmove->pm_flags
  318. enum pmflags_t : uint16_t
  319. {
  320. PMF_NONE = 0,
  321. PMF_DUCKED = bit_v<0>,
  322. PMF_JUMP_HELD = bit_v<1>,
  323. PMF_ON_GROUND = bit_v<2>,
  324. PMF_TIME_WATERJUMP = bit_v<3>, // pm_time is waterjump
  325. PMF_TIME_LAND = bit_v<4>, // pm_time is time before rejump
  326. PMF_TIME_TELEPORT = bit_v<5>, // pm_time is non-moving time
  327. PMF_NO_POSITIONAL_PREDICTION = bit_v<6>, // temporarily disables positional prediction (used for grappling hook)
  328. PMF_ON_LADDER = bit_v<7>, // signal to game that we are on a ladder
  329. PMF_NO_ANGULAR_PREDICTION = bit_v<8>, // temporary disables angular prediction
  330. PMF_IGNORE_PLAYER_COLLISION = bit_v<9>, // don't collide with other players
  331. PMF_TIME_TRICK = bit_v<10>, // pm_time is trick jump time
  332. };
  333. MAKE_ENUM_BITFLAGS(pmflags_t);
  334. // this structure needs to be communicated bit-accurate
  335. // from the server to the client to guarantee that
  336. // prediction stays in sync.
  337. // if any part of the game code modifies this struct, it
  338. // will result in a prediction error of some degree.
  339. struct pmove_state_t
  340. {
  341. pmtype_t pm_type;
  342. vec3_t origin;
  343. vec3_t velocity;
  344. pmflags_t pm_flags; // ducked, jump_held, etc
  345. uint16_t pm_time;
  346. int16_t gravity;
  347. gvec3_t delta_angles; // add to command angles to get view direction
  348. // changed by spawns, rotating objects, and teleporters
  349. int8_t viewheight; // view height, added to origin[2] + viewoffset[2], for crouching
  350. };
  351. //
  352. // button bits
  353. //
  354. enum button_t : uint8_t
  355. {
  356. BUTTON_NONE = 0,
  357. BUTTON_ATTACK = bit_v<0>,
  358. BUTTON_USE = bit_v<1>,
  359. BUTTON_HOLSTER = bit_v<2>, // [Paril-KEX]
  360. BUTTON_JUMP = bit_v<3>,
  361. BUTTON_CROUCH = bit_v<4>,
  362. BUTTON_ANY = bit_v<7> // any key whatsoever
  363. };
  364. MAKE_ENUM_BITFLAGS(button_t);
  365. // usercmd_t is sent to the server each client frame
  366. struct usercmd_t
  367. {
  368. byte msec;
  369. button_t buttons;
  370. gvec3_t angles;
  371. float forwardmove, sidemove;
  372. uint32_t server_frame; // for integrity, etc
  373. };
  374. enum water_level_t : uint8_t
  375. {
  376. WATER_NONE,
  377. WATER_FEET,
  378. WATER_WAIST,
  379. WATER_UNDER
  380. };
  381. // player_state_t->refdef flags
  382. enum refdef_flags_t : uint8_t
  383. {
  384. RDF_NONE = 0,
  385. RDF_UNDERWATER = bit_v<0>, // warp the screen as appropriate
  386. RDF_NOWORLDMODEL = bit_v<1>, // used for player configuration screen
  387. // ROGUE
  388. RDF_IRGOGGLES = bit_v<2>,
  389. RDF_UVGOGGLES = bit_v<3>,
  390. // ROGUE
  391. RDF_NO_WEAPON_LERP = bit_v<4>
  392. };
  393. constexpr size_t MAXTOUCH = 32;
  394. struct touch_list_t
  395. {
  396. uint32_t num = 0;
  397. std::array<trace_t, MAXTOUCH> traces;
  398. };
  399. struct pmove_t
  400. {
  401. // state (in / out)
  402. pmove_state_t s;
  403. // command (in)
  404. usercmd_t cmd;
  405. bool snapinitial; // if s has been changed outside pmove
  406. // results (out)
  407. touch_list_t touch;
  408. gvec3_t viewangles; // clamped
  409. gvec3_t mins, maxs; // bounding box size
  410. edict_t *groundentity;
  411. cplane_t groundplane;
  412. contents_t watertype;
  413. water_level_t waterlevel;
  414. edict_t *player; // opaque handle
  415. // clip against world & entities
  416. trace_t (*trace)(gvec3_cref_t start, gvec3_cptr_t mins, gvec3_cptr_t maxs, gvec3_cref_t end, const edict_t* passent, contents_t contentmask);
  417. // [Paril-KEX] clip against world only
  418. trace_t (*clip)(gvec3_cref_t start, gvec3_cptr_t mins, gvec3_cptr_t maxs, gvec3_cref_t end, contents_t contentmask);
  419. contents_t (*pointcontents)(gvec3_cref_t point);
  420. // [KEX] variables (in)
  421. vec3_t viewoffset; // last viewoffset (for accurate calculation of blending)
  422. // [KEX] results (out)
  423. gvec4_t screen_blend;
  424. refdef_flags_t rdflags; // merged with rdflags from server
  425. bool jump_sound; // play jump sound
  426. bool step_clip; // we clipped on top of an object from below
  427. float impact_delta; // impact delta, for falling damage
  428. };
  429. // entity_state_t->effects
  430. // Effects are things handled on the client side (lights, particles, frame animations)
  431. // that happen constantly on the given entity.
  432. // An entity that has effects will be sent to the client
  433. // even if it has a zero index model.
  434. enum effects_t : uint64_t
  435. {
  436. EF_NONE = 0, // no effects
  437. EF_ROTATE = bit_v<0>, // rotate (bonus items)
  438. EF_GIB = bit_v<1>, // leave a trail
  439. EF_BOB = bit_v<2>, // bob (bonus items)
  440. EF_BLASTER = bit_v<3>, // redlight + trail
  441. EF_ROCKET = bit_v<4>, // redlight + trail
  442. EF_GRENADE = bit_v<5>,
  443. EF_HYPERBLASTER = bit_v<6>,
  444. EF_BFG = bit_v<7>,
  445. EF_COLOR_SHELL = bit_v<8>,
  446. EF_POWERSCREEN = bit_v<9>,
  447. EF_ANIM01 = bit_v<10>, // automatically cycle between frames 0 and 1 at 2 hz
  448. EF_ANIM23 = bit_v<11>, // automatically cycle between frames 2 and 3 at 2 hz
  449. EF_ANIM_ALL = bit_v<12>, // automatically cycle through all frames at 2hz
  450. EF_ANIM_ALLFAST = bit_v<13>, // automatically cycle through all frames at 10hz
  451. EF_FLIES = bit_v<14>,
  452. EF_QUAD = bit_v<15>,
  453. EF_PENT = bit_v<16>,
  454. EF_TELEPORTER = bit_v<17>, // particle fountain
  455. EF_FLAG1 = bit_v<18>,
  456. EF_FLAG2 = bit_v<19>,
  457. // RAFAEL
  458. EF_IONRIPPER = bit_v<20>,
  459. EF_GREENGIB = bit_v<21>,
  460. EF_BLUEHYPERBLASTER = bit_v<22>,
  461. EF_SPINNINGLIGHTS = bit_v<23>,
  462. EF_PLASMA = bit_v<24>,
  463. EF_TRAP = bit_v<25>,
  464. // ROGUE
  465. EF_TRACKER = bit_v<26>,
  466. EF_DOUBLE = bit_v<27>,
  467. EF_SPHERETRANS = bit_v<28>,
  468. EF_TAGTRAIL = bit_v<29>,
  469. EF_HALF_DAMAGE = bit_v<30>,
  470. EF_TRACKERTRAIL = bit_v<31>,
  471. // ROGUE
  472. EF_DUALFIRE = bit_v<32>, // [KEX] dualfire damage color shell
  473. EF_HOLOGRAM = bit_v<33>, // [Paril-KEX] N64 hologram
  474. EF_FLASHLIGHT = bit_v<34>, // [Paril-KEX] project flashlight, only for players
  475. EF_BARREL_EXPLODING= bit_v<35>,
  476. EF_TELEPORTER2 = bit_v<36>, // [Paril-KEX] n64 teleporter
  477. EF_GRENADE_LIGHT = bit_v<37>
  478. };
  479. MAKE_ENUM_BITFLAGS(effects_t);
  480. constexpr effects_t EF_FIREBALL = EF_ROCKET | EF_GIB;
  481. // entity_state_t->renderfx flags
  482. enum renderfx_t : uint32_t
  483. {
  484. RF_NONE = 0,
  485. RF_MINLIGHT = bit_v<0>, // always have some light (viewmodel)
  486. RF_VIEWERMODEL = bit_v<1>, // don't draw through eyes, only mirrors
  487. RF_WEAPONMODEL = bit_v<2>, // only draw through eyes
  488. RF_FULLBRIGHT = bit_v<3>, // always draw full intensity
  489. RF_DEPTHHACK = bit_v<4>, // for view weapon Z crunching
  490. RF_TRANSLUCENT = bit_v<5>,
  491. RF_NO_ORIGIN_LERP = bit_v<6>, // no interpolation for origins
  492. RF_BEAM = bit_v<7>,
  493. RF_CUSTOMSKIN = bit_v<8>, // [Paril-KEX] implemented; set skinnum (or frame for RF_FLARE) to specify
  494. // an image in CS_IMAGES to use as skin.
  495. RF_GLOW = bit_v<9>, // pulse lighting for bonus items
  496. RF_SHELL_RED = bit_v<10>,
  497. RF_SHELL_GREEN = bit_v<11>,
  498. RF_SHELL_BLUE = bit_v<12>,
  499. RF_NOSHADOW = bit_v<13>,
  500. RF_CASTSHADOW = bit_v<14>, // [Sam-KEX]
  501. // ROGUE
  502. RF_IR_VISIBLE = bit_v<15>,
  503. RF_SHELL_DOUBLE = bit_v<16>,
  504. RF_SHELL_HALF_DAM = bit_v<17>,
  505. RF_USE_DISGUISE = bit_v<18>,
  506. // ROGUE
  507. RF_SHELL_LITE_GREEN = bit_v<19>,
  508. RF_CUSTOM_LIGHT = bit_v<20>, // [Paril-KEX] custom point dlight that is designed to strobe/be turned off; s.frame is radius, s.skinnum is color
  509. RF_FLARE = bit_v<21>, // [Sam-KEX]
  510. RF_OLD_FRAME_LERP = bit_v<22>, // [Paril-KEX] force model to lerp from oldframe in entity state; otherwise it uses last frame client received
  511. RF_DOT_SHADOW = bit_v<23>, // [Paril-KEX] draw blobby shadow
  512. RF_LOW_PRIORITY = bit_v<24>, // [Paril-KEX] low priority object; if we can't be added to the scene, don't bother replacing entities,
  513. // and we can be replaced if anything non-low-priority needs room
  514. RF_NO_LOD = bit_v<25>, // [Paril-KEX] never LOD
  515. RF_NO_STEREO = RF_WEAPONMODEL, // [Paril-KEX] this is a bit dumb, but, for looping noises if this is set there's no stereo
  516. RF_STAIR_STEP = bit_v<26>, // [Paril-KEX] re-tuned, now used to handle stair steps for monsters
  517. RF_FLARE_LOCK_ANGLE = RF_MINLIGHT
  518. };
  519. MAKE_ENUM_BITFLAGS(renderfx_t);
  520. constexpr renderfx_t RF_BEAM_LIGHTNING = RF_BEAM | RF_GLOW; // [Paril-KEX] make a lightning bolt instead of a laser
  521. MAKE_ENUM_BITFLAGS(refdef_flags_t);
  522. //
  523. // muzzle flashes / player effects
  524. //
  525. enum player_muzzle_t : uint8_t
  526. {
  527. MZ_BLASTER = 0,
  528. MZ_MACHINEGUN = 1,
  529. MZ_SHOTGUN = 2,
  530. MZ_CHAINGUN1 = 3,
  531. MZ_CHAINGUN2 = 4,
  532. MZ_CHAINGUN3 = 5,
  533. MZ_RAILGUN = 6,
  534. MZ_ROCKET = 7,
  535. MZ_GRENADE = 8,
  536. MZ_LOGIN = 9,
  537. MZ_LOGOUT = 10,
  538. MZ_RESPAWN = 11,
  539. MZ_BFG = 12,
  540. MZ_SSHOTGUN = 13,
  541. MZ_HYPERBLASTER = 14,
  542. MZ_ITEMRESPAWN = 15,
  543. // RAFAEL
  544. MZ_IONRIPPER = 16,
  545. MZ_BLUEHYPERBLASTER = 17,
  546. MZ_PHALANX = 18,
  547. MZ_BFG2 = 19,
  548. MZ_PHALANX2 = 20,
  549. // ROGUE
  550. MZ_ETF_RIFLE = 30,
  551. MZ_PROX = 31, // [Paril-KEX]
  552. MZ_ETF_RIFLE_2 = 32, // [Paril-KEX] unused, so using it for the other barrel
  553. MZ_HEATBEAM = 33,
  554. MZ_BLASTER2 = 34,
  555. MZ_TRACKER = 35,
  556. MZ_NUKE1 = 36,
  557. MZ_NUKE2 = 37,
  558. MZ_NUKE4 = 38,
  559. MZ_NUKE8 = 39,
  560. // ROGUE
  561. MZ_SILENCED = bit_v<7>, // bit flag ORed with one of the above numbers
  562. MZ_NONE = 0 // "no" bitflags
  563. };
  564. MAKE_ENUM_BITFLAGS(player_muzzle_t);
  565. //
  566. // monster muzzle flashes
  567. // NOTE: this needs to match the m_flash table!
  568. //
  569. enum monster_muzzleflash_id_t : uint16_t
  570. {
  571. MZ2_UNUSED_0,
  572. MZ2_TANK_BLASTER_1,
  573. MZ2_TANK_BLASTER_2,
  574. MZ2_TANK_BLASTER_3,
  575. MZ2_TANK_MACHINEGUN_1,
  576. MZ2_TANK_MACHINEGUN_2,
  577. MZ2_TANK_MACHINEGUN_3,
  578. MZ2_TANK_MACHINEGUN_4,
  579. MZ2_TANK_MACHINEGUN_5,
  580. MZ2_TANK_MACHINEGUN_6,
  581. MZ2_TANK_MACHINEGUN_7,
  582. MZ2_TANK_MACHINEGUN_8,
  583. MZ2_TANK_MACHINEGUN_9,
  584. MZ2_TANK_MACHINEGUN_10,
  585. MZ2_TANK_MACHINEGUN_11,
  586. MZ2_TANK_MACHINEGUN_12,
  587. MZ2_TANK_MACHINEGUN_13,
  588. MZ2_TANK_MACHINEGUN_14,
  589. MZ2_TANK_MACHINEGUN_15,
  590. MZ2_TANK_MACHINEGUN_16,
  591. MZ2_TANK_MACHINEGUN_17,
  592. MZ2_TANK_MACHINEGUN_18,
  593. MZ2_TANK_MACHINEGUN_19,
  594. MZ2_TANK_ROCKET_1,
  595. MZ2_TANK_ROCKET_2,
  596. MZ2_TANK_ROCKET_3,
  597. MZ2_INFANTRY_MACHINEGUN_1,
  598. MZ2_INFANTRY_MACHINEGUN_2,
  599. MZ2_INFANTRY_MACHINEGUN_3,
  600. MZ2_INFANTRY_MACHINEGUN_4,
  601. MZ2_INFANTRY_MACHINEGUN_5,
  602. MZ2_INFANTRY_MACHINEGUN_6,
  603. MZ2_INFANTRY_MACHINEGUN_7,
  604. MZ2_INFANTRY_MACHINEGUN_8,
  605. MZ2_INFANTRY_MACHINEGUN_9,
  606. MZ2_INFANTRY_MACHINEGUN_10,
  607. MZ2_INFANTRY_MACHINEGUN_11,
  608. MZ2_INFANTRY_MACHINEGUN_12,
  609. MZ2_INFANTRY_MACHINEGUN_13,
  610. MZ2_SOLDIER_BLASTER_1,
  611. MZ2_SOLDIER_BLASTER_2,
  612. MZ2_SOLDIER_SHOTGUN_1,
  613. MZ2_SOLDIER_SHOTGUN_2,
  614. MZ2_SOLDIER_MACHINEGUN_1,
  615. MZ2_SOLDIER_MACHINEGUN_2,
  616. MZ2_GUNNER_MACHINEGUN_1,
  617. MZ2_GUNNER_MACHINEGUN_2,
  618. MZ2_GUNNER_MACHINEGUN_3,
  619. MZ2_GUNNER_MACHINEGUN_4,
  620. MZ2_GUNNER_MACHINEGUN_5,
  621. MZ2_GUNNER_MACHINEGUN_6,
  622. MZ2_GUNNER_MACHINEGUN_7,
  623. MZ2_GUNNER_MACHINEGUN_8,
  624. MZ2_GUNNER_GRENADE_1,
  625. MZ2_GUNNER_GRENADE_2,
  626. MZ2_GUNNER_GRENADE_3,
  627. MZ2_GUNNER_GRENADE_4,
  628. MZ2_CHICK_ROCKET_1,
  629. MZ2_FLYER_BLASTER_1,
  630. MZ2_FLYER_BLASTER_2,
  631. MZ2_MEDIC_BLASTER_1,
  632. MZ2_GLADIATOR_RAILGUN_1,
  633. MZ2_HOVER_BLASTER_1,
  634. MZ2_ACTOR_MACHINEGUN_1,
  635. MZ2_SUPERTANK_MACHINEGUN_1,
  636. MZ2_SUPERTANK_MACHINEGUN_2,
  637. MZ2_SUPERTANK_MACHINEGUN_3,
  638. MZ2_SUPERTANK_MACHINEGUN_4,
  639. MZ2_SUPERTANK_MACHINEGUN_5,
  640. MZ2_SUPERTANK_MACHINEGUN_6,
  641. MZ2_SUPERTANK_ROCKET_1,
  642. MZ2_SUPERTANK_ROCKET_2,
  643. MZ2_SUPERTANK_ROCKET_3,
  644. MZ2_BOSS2_MACHINEGUN_L1,
  645. MZ2_BOSS2_MACHINEGUN_L2,
  646. MZ2_BOSS2_MACHINEGUN_L3,
  647. MZ2_BOSS2_MACHINEGUN_L4,
  648. MZ2_BOSS2_MACHINEGUN_L5,
  649. MZ2_BOSS2_ROCKET_1,
  650. MZ2_BOSS2_ROCKET_2,
  651. MZ2_BOSS2_ROCKET_3,
  652. MZ2_BOSS2_ROCKET_4,
  653. MZ2_FLOAT_BLASTER_1,
  654. MZ2_SOLDIER_BLASTER_3,
  655. MZ2_SOLDIER_SHOTGUN_3,
  656. MZ2_SOLDIER_MACHINEGUN_3,
  657. MZ2_SOLDIER_BLASTER_4,
  658. MZ2_SOLDIER_SHOTGUN_4,
  659. MZ2_SOLDIER_MACHINEGUN_4,
  660. MZ2_SOLDIER_BLASTER_5,
  661. MZ2_SOLDIER_SHOTGUN_5,
  662. MZ2_SOLDIER_MACHINEGUN_5,
  663. MZ2_SOLDIER_BLASTER_6,
  664. MZ2_SOLDIER_SHOTGUN_6,
  665. MZ2_SOLDIER_MACHINEGUN_6,
  666. MZ2_SOLDIER_BLASTER_7,
  667. MZ2_SOLDIER_SHOTGUN_7,
  668. MZ2_SOLDIER_MACHINEGUN_7,
  669. MZ2_SOLDIER_BLASTER_8,
  670. MZ2_SOLDIER_SHOTGUN_8,
  671. MZ2_SOLDIER_MACHINEGUN_8,
  672. // --- Xian shit below ---
  673. MZ2_MAKRON_BFG,
  674. MZ2_MAKRON_BLASTER_1,
  675. MZ2_MAKRON_BLASTER_2,
  676. MZ2_MAKRON_BLASTER_3,
  677. MZ2_MAKRON_BLASTER_4,
  678. MZ2_MAKRON_BLASTER_5,
  679. MZ2_MAKRON_BLASTER_6,
  680. MZ2_MAKRON_BLASTER_7,
  681. MZ2_MAKRON_BLASTER_8,
  682. MZ2_MAKRON_BLASTER_9,
  683. MZ2_MAKRON_BLASTER_10,
  684. MZ2_MAKRON_BLASTER_11,
  685. MZ2_MAKRON_BLASTER_12,
  686. MZ2_MAKRON_BLASTER_13,
  687. MZ2_MAKRON_BLASTER_14,
  688. MZ2_MAKRON_BLASTER_15,
  689. MZ2_MAKRON_BLASTER_16,
  690. MZ2_MAKRON_BLASTER_17,
  691. MZ2_MAKRON_RAILGUN_1,
  692. MZ2_JORG_MACHINEGUN_L1,
  693. MZ2_JORG_MACHINEGUN_L2,
  694. MZ2_JORG_MACHINEGUN_L3,
  695. MZ2_JORG_MACHINEGUN_L4,
  696. MZ2_JORG_MACHINEGUN_L5,
  697. MZ2_JORG_MACHINEGUN_L6,
  698. MZ2_JORG_MACHINEGUN_R1,
  699. MZ2_JORG_MACHINEGUN_R2,
  700. MZ2_JORG_MACHINEGUN_R3,
  701. MZ2_JORG_MACHINEGUN_R4,
  702. MZ2_JORG_MACHINEGUN_R5,
  703. MZ2_JORG_MACHINEGUN_R6,
  704. MZ2_JORG_BFG_1,
  705. MZ2_BOSS2_MACHINEGUN_R1,
  706. MZ2_BOSS2_MACHINEGUN_R2,
  707. MZ2_BOSS2_MACHINEGUN_R3,
  708. MZ2_BOSS2_MACHINEGUN_R4,
  709. MZ2_BOSS2_MACHINEGUN_R5,
  710. // ROGUE
  711. MZ2_CARRIER_MACHINEGUN_L1,
  712. MZ2_CARRIER_MACHINEGUN_R1,
  713. MZ2_CARRIER_GRENADE,
  714. MZ2_TURRET_MACHINEGUN,
  715. MZ2_TURRET_ROCKET,
  716. MZ2_TURRET_BLASTER,
  717. MZ2_STALKER_BLASTER,
  718. MZ2_DAEDALUS_BLASTER,
  719. MZ2_MEDIC_BLASTER_2,
  720. MZ2_CARRIER_RAILGUN,
  721. MZ2_WIDOW_DISRUPTOR,
  722. MZ2_WIDOW_BLASTER,
  723. MZ2_WIDOW_RAIL,
  724. MZ2_WIDOW_PLASMABEAM, // PMM - not used
  725. MZ2_CARRIER_MACHINEGUN_L2,
  726. MZ2_CARRIER_MACHINEGUN_R2,
  727. MZ2_WIDOW_RAIL_LEFT,
  728. MZ2_WIDOW_RAIL_RIGHT,
  729. MZ2_WIDOW_BLASTER_SWEEP1,
  730. MZ2_WIDOW_BLASTER_SWEEP2,
  731. MZ2_WIDOW_BLASTER_SWEEP3,
  732. MZ2_WIDOW_BLASTER_SWEEP4,
  733. MZ2_WIDOW_BLASTER_SWEEP5,
  734. MZ2_WIDOW_BLASTER_SWEEP6,
  735. MZ2_WIDOW_BLASTER_SWEEP7,
  736. MZ2_WIDOW_BLASTER_SWEEP8,
  737. MZ2_WIDOW_BLASTER_SWEEP9,
  738. MZ2_WIDOW_BLASTER_100,
  739. MZ2_WIDOW_BLASTER_90,
  740. MZ2_WIDOW_BLASTER_80,
  741. MZ2_WIDOW_BLASTER_70,
  742. MZ2_WIDOW_BLASTER_60,
  743. MZ2_WIDOW_BLASTER_50,
  744. MZ2_WIDOW_BLASTER_40,
  745. MZ2_WIDOW_BLASTER_30,
  746. MZ2_WIDOW_BLASTER_20,
  747. MZ2_WIDOW_BLASTER_10,
  748. MZ2_WIDOW_BLASTER_0,
  749. MZ2_WIDOW_BLASTER_10L,
  750. MZ2_WIDOW_BLASTER_20L,
  751. MZ2_WIDOW_BLASTER_30L,
  752. MZ2_WIDOW_BLASTER_40L,
  753. MZ2_WIDOW_BLASTER_50L,
  754. MZ2_WIDOW_BLASTER_60L,
  755. MZ2_WIDOW_BLASTER_70L,
  756. MZ2_WIDOW_RUN_1,
  757. MZ2_WIDOW_RUN_2,
  758. MZ2_WIDOW_RUN_3,
  759. MZ2_WIDOW_RUN_4,
  760. MZ2_WIDOW_RUN_5,
  761. MZ2_WIDOW_RUN_6,
  762. MZ2_WIDOW_RUN_7,
  763. MZ2_WIDOW_RUN_8,
  764. MZ2_CARRIER_ROCKET_1,
  765. MZ2_CARRIER_ROCKET_2,
  766. MZ2_CARRIER_ROCKET_3,
  767. MZ2_CARRIER_ROCKET_4,
  768. MZ2_WIDOW2_BEAMER_1,
  769. MZ2_WIDOW2_BEAMER_2,
  770. MZ2_WIDOW2_BEAMER_3,
  771. MZ2_WIDOW2_BEAMER_4,
  772. MZ2_WIDOW2_BEAMER_5,
  773. MZ2_WIDOW2_BEAM_SWEEP_1,
  774. MZ2_WIDOW2_BEAM_SWEEP_2,
  775. MZ2_WIDOW2_BEAM_SWEEP_3,
  776. MZ2_WIDOW2_BEAM_SWEEP_4,
  777. MZ2_WIDOW2_BEAM_SWEEP_5,
  778. MZ2_WIDOW2_BEAM_SWEEP_6,
  779. MZ2_WIDOW2_BEAM_SWEEP_7,
  780. MZ2_WIDOW2_BEAM_SWEEP_8,
  781. MZ2_WIDOW2_BEAM_SWEEP_9,
  782. MZ2_WIDOW2_BEAM_SWEEP_10,
  783. MZ2_WIDOW2_BEAM_SWEEP_11,
  784. // ROGUE
  785. // [Paril-KEX]
  786. MZ2_SOLDIER_RIPPER_1,
  787. MZ2_SOLDIER_RIPPER_2,
  788. MZ2_SOLDIER_RIPPER_3,
  789. MZ2_SOLDIER_RIPPER_4,
  790. MZ2_SOLDIER_RIPPER_5,
  791. MZ2_SOLDIER_RIPPER_6,
  792. MZ2_SOLDIER_RIPPER_7,
  793. MZ2_SOLDIER_RIPPER_8,
  794. MZ2_SOLDIER_HYPERGUN_1,
  795. MZ2_SOLDIER_HYPERGUN_2,
  796. MZ2_SOLDIER_HYPERGUN_3,
  797. MZ2_SOLDIER_HYPERGUN_4,
  798. MZ2_SOLDIER_HYPERGUN_5,
  799. MZ2_SOLDIER_HYPERGUN_6,
  800. MZ2_SOLDIER_HYPERGUN_7,
  801. MZ2_SOLDIER_HYPERGUN_8,
  802. MZ2_GUARDIAN_BLASTER,
  803. MZ2_ARACHNID_RAIL1,
  804. MZ2_ARACHNID_RAIL2,
  805. MZ2_ARACHNID_RAIL_UP1,
  806. MZ2_ARACHNID_RAIL_UP2,
  807. MZ2_INFANTRY_MACHINEGUN_14, // run-attack
  808. MZ2_INFANTRY_MACHINEGUN_15, // run-attack
  809. MZ2_INFANTRY_MACHINEGUN_16, // run-attack
  810. MZ2_INFANTRY_MACHINEGUN_17, // run-attack
  811. MZ2_INFANTRY_MACHINEGUN_18, // run-attack
  812. MZ2_INFANTRY_MACHINEGUN_19, // run-attack
  813. MZ2_INFANTRY_MACHINEGUN_20, // run-attack
  814. MZ2_INFANTRY_MACHINEGUN_21, // run-attack
  815. MZ2_GUNCMDR_CHAINGUN_1, // straight
  816. MZ2_GUNCMDR_CHAINGUN_2, // dodging
  817. MZ2_GUNCMDR_GRENADE_MORTAR_1,
  818. MZ2_GUNCMDR_GRENADE_MORTAR_2,
  819. MZ2_GUNCMDR_GRENADE_MORTAR_3,
  820. MZ2_GUNCMDR_GRENADE_FRONT_1,
  821. MZ2_GUNCMDR_GRENADE_FRONT_2,
  822. MZ2_GUNCMDR_GRENADE_FRONT_3,
  823. MZ2_GUNCMDR_GRENADE_CROUCH_1,
  824. MZ2_GUNCMDR_GRENADE_CROUCH_2,
  825. MZ2_GUNCMDR_GRENADE_CROUCH_3,
  826. // prone
  827. MZ2_SOLDIER_BLASTER_9,
  828. MZ2_SOLDIER_SHOTGUN_9,
  829. MZ2_SOLDIER_MACHINEGUN_9,
  830. MZ2_SOLDIER_RIPPER_9,
  831. MZ2_SOLDIER_HYPERGUN_9,
  832. // alternate frontwards grenades
  833. MZ2_GUNNER_GRENADE2_1,
  834. MZ2_GUNNER_GRENADE2_2,
  835. MZ2_GUNNER_GRENADE2_3,
  836. MZ2_GUNNER_GRENADE2_4,
  837. MZ2_INFANTRY_MACHINEGUN_22,
  838. // supertonk
  839. MZ2_SUPERTANK_GRENADE_1,
  840. MZ2_SUPERTANK_GRENADE_2,
  841. // hover & daedalus other side
  842. MZ2_HOVER_BLASTER_2,
  843. MZ2_DAEDALUS_BLASTER_2,
  844. // medic (commander) sweeps
  845. MZ2_MEDIC_HYPERBLASTER1_1,
  846. MZ2_MEDIC_HYPERBLASTER1_2,
  847. MZ2_MEDIC_HYPERBLASTER1_3,
  848. MZ2_MEDIC_HYPERBLASTER1_4,
  849. MZ2_MEDIC_HYPERBLASTER1_5,
  850. MZ2_MEDIC_HYPERBLASTER1_6,
  851. MZ2_MEDIC_HYPERBLASTER1_7,
  852. MZ2_MEDIC_HYPERBLASTER1_8,
  853. MZ2_MEDIC_HYPERBLASTER1_9,
  854. MZ2_MEDIC_HYPERBLASTER1_10,
  855. MZ2_MEDIC_HYPERBLASTER1_11,
  856. MZ2_MEDIC_HYPERBLASTER1_12,
  857. MZ2_MEDIC_HYPERBLASTER2_1,
  858. MZ2_MEDIC_HYPERBLASTER2_2,
  859. MZ2_MEDIC_HYPERBLASTER2_3,
  860. MZ2_MEDIC_HYPERBLASTER2_4,
  861. MZ2_MEDIC_HYPERBLASTER2_5,
  862. MZ2_MEDIC_HYPERBLASTER2_6,
  863. MZ2_MEDIC_HYPERBLASTER2_7,
  864. MZ2_MEDIC_HYPERBLASTER2_8,
  865. MZ2_MEDIC_HYPERBLASTER2_9,
  866. MZ2_MEDIC_HYPERBLASTER2_10,
  867. MZ2_MEDIC_HYPERBLASTER2_11,
  868. MZ2_MEDIC_HYPERBLASTER2_12,
  869. // only used for compile time checks
  870. MZ2_LAST
  871. };
  872. // temp entity events
  873. //
  874. // Temp entity events are for things that happen
  875. // at a location seperate from any existing entity.
  876. // Temporary entity messages are explicitly constructed
  877. // and broadcast.
  878. enum temp_event_t : uint8_t
  879. {
  880. TE_GUNSHOT,
  881. TE_BLOOD,
  882. TE_BLASTER,
  883. TE_RAILTRAIL,
  884. TE_SHOTGUN,
  885. TE_EXPLOSION1,
  886. TE_EXPLOSION2,
  887. TE_ROCKET_EXPLOSION,
  888. TE_GRENADE_EXPLOSION,
  889. TE_SPARKS,
  890. TE_SPLASH,
  891. TE_BUBBLETRAIL,
  892. TE_SCREEN_SPARKS,
  893. TE_SHIELD_SPARKS,
  894. TE_BULLET_SPARKS,
  895. TE_LASER_SPARKS,
  896. TE_PARASITE_ATTACK,
  897. TE_ROCKET_EXPLOSION_WATER,
  898. TE_GRENADE_EXPLOSION_WATER,
  899. TE_MEDIC_CABLE_ATTACK,
  900. TE_BFG_EXPLOSION,
  901. TE_BFG_BIGEXPLOSION,
  902. TE_BOSSTPORT, // used as '22' in a map, so DON'T RENUMBER!!!
  903. TE_BFG_LASER,
  904. TE_GRAPPLE_CABLE,
  905. TE_WELDING_SPARKS,
  906. TE_GREENBLOOD,
  907. TE_BLUEHYPERBLASTER_DUMMY, // [Paril-KEX] leaving for compatibility, do not use; use TE_BLUEHYPERBLASTER
  908. TE_PLASMA_EXPLOSION,
  909. TE_TUNNEL_SPARKS,
  910. // ROGUE
  911. TE_BLASTER2,
  912. TE_RAILTRAIL2,
  913. TE_FLAME,
  914. TE_LIGHTNING,
  915. TE_DEBUGTRAIL,
  916. TE_PLAIN_EXPLOSION,
  917. TE_FLASHLIGHT,
  918. TE_FORCEWALL,
  919. TE_HEATBEAM,
  920. TE_MONSTER_HEATBEAM,
  921. TE_STEAM,
  922. TE_BUBBLETRAIL2,
  923. TE_MOREBLOOD,
  924. TE_HEATBEAM_SPARKS,
  925. TE_HEATBEAM_STEAM,
  926. TE_CHAINFIST_SMOKE,
  927. TE_ELECTRIC_SPARKS,
  928. TE_TRACKER_EXPLOSION,
  929. TE_TELEPORT_EFFECT,
  930. TE_DBALL_GOAL,
  931. TE_WIDOWBEAMOUT,
  932. TE_NUKEBLAST,
  933. TE_WIDOWSPLASH,
  934. TE_EXPLOSION1_BIG,
  935. TE_EXPLOSION1_NP,
  936. TE_FLECHETTE,
  937. // ROGUE
  938. // [Paril-KEX]
  939. TE_BLUEHYPERBLASTER,
  940. TE_BFG_ZAP,
  941. TE_BERSERK_SLAM,
  942. TE_GRAPPLE_CABLE_2,
  943. TE_POWER_SPLASH,
  944. TE_LIGHTNING_BEAM,
  945. TE_EXPLOSION1_NL,
  946. TE_EXPLOSION2_NL,
  947. };
  948. enum splash_color_t : uint8_t
  949. {
  950. SPLASH_UNKNOWN = 0,
  951. SPLASH_SPARKS = 1,
  952. SPLASH_BLUE_WATER = 2,
  953. SPLASH_BROWN_WATER = 3,
  954. SPLASH_SLIME = 4,
  955. SPLASH_LAVA = 5,
  956. SPLASH_BLOOD = 6,
  957. // [Paril-KEX] N64 electric sparks that go zap
  958. SPLASH_ELECTRIC = 7
  959. };
  960. // sound channels
  961. // channel 0 never willingly overrides
  962. // other channels (1-7) always override a playing sound on that channel
  963. enum soundchan_t : uint8_t
  964. {
  965. CHAN_AUTO = 0,
  966. CHAN_WEAPON = 1,
  967. CHAN_VOICE = 2,
  968. CHAN_ITEM = 3,
  969. CHAN_BODY = 4,
  970. CHAN_AUX = 5,
  971. CHAN_FOOTSTEP = 6,
  972. CHAN_AUX3 = 7,
  973. // modifier flags
  974. CHAN_NO_PHS_ADD = bit_v<3>, // send to all clients, not just ones in PHS (ATTN 0 will also do this)
  975. CHAN_RELIABLE = bit_v<4>, // send by reliable message, not datagram
  976. CHAN_FORCE_POS = bit_v<5>, // always use position sent in packet
  977. };
  978. MAKE_ENUM_BITFLAGS(soundchan_t);
  979. // sound attenuation values
  980. constexpr float ATTN_LOOP_NONE = -1; // full volume the entire level, for loop only
  981. constexpr float ATTN_NONE = 0; // full volume the entire level, for sounds only
  982. constexpr float ATTN_NORM = 1;
  983. constexpr float ATTN_IDLE = 2;
  984. constexpr float ATTN_STATIC = 3; // diminish very rapidly with distance
  985. // total stat count
  986. constexpr size_t MAX_STATS = 64;
  987. /*
  988. ROGUE - VERSIONS
  989. 1234 08/13/1998 Activision
  990. 1235 08/14/1998 Id Software
  991. 1236 08/15/1998 Steve Tietze
  992. 1237 08/15/1998 Phil Dobranski
  993. 1238 08/15/1998 John Sheley
  994. 1239 08/17/1998 Barrett Alexander
  995. 1230 08/17/1998 Brandon Fish
  996. 1245 08/17/1998 Don MacAskill
  997. 1246 08/17/1998 David "Zoid" Kirsch
  998. 1247 08/17/1998 Manu Smith
  999. 1248 08/17/1998 Geoff Scully
  1000. 1249 08/17/1998 Andy Van Fossen
  1001. 1240 08/20/1998 Activision Build 2
  1002. 1256 08/20/1998 Ranger Clan
  1003. 1257 08/20/1998 Ensemble Studios
  1004. 1258 08/21/1998 Robert Duffy
  1005. 1259 08/21/1998 Stephen Seachord
  1006. 1250 08/21/1998 Stephen Heaslip
  1007. 1267 08/21/1998 Samir Sandesara
  1008. 1268 08/21/1998 Oliver Wyman
  1009. 1269 08/21/1998 Steven Marchegiano
  1010. 1260 08/21/1998 Build #2 for Nihilistic
  1011. 1278 08/21/1998 Build #2 for Ensemble
  1012. 1279 08/26/1998 Build for Ron Solo - DEFUNCT
  1013. 1270 08/26/1998 Build #3 for Activision
  1014. 1289 08/26/1998 Build for Don MacAskill
  1015. 1280 08/26/1998 Build for Robert Duffy
  1016. 1290 08/26/1998 Build #2 for Rangers
  1017. 1345 08/28/1998 Build #4 for Activision
  1018. 2345 08/26/1998 Build for Zoid
  1019. 9999 08/20/1998 Internal Use
  1020. */
  1021. // ROGUE
  1022. /*
  1023. ==========================================================
  1024. ELEMENTS COMMUNICATED ACROSS THE NET
  1025. ==========================================================
  1026. */
  1027. //=============================================
  1028. // INFO STRINGS
  1029. //
  1030. // NB: the Q2 protocol does not dictate the type
  1031. // of strings being used, so it's kind of a crapshoot.
  1032. // Kex's protocol assumes info strings are always UTF8.
  1033. //=============================================
  1034. //
  1035. // key / value info strings
  1036. //
  1037. constexpr size_t MAX_INFO_KEY = 64;
  1038. constexpr size_t MAX_INFO_VALUE = 256;
  1039. constexpr size_t MAX_INFO_STRING = 2048;
  1040. // CONFIG STRINGS
  1041. // bound by number of things we can fit in two stats
  1042. constexpr size_t MAX_WHEEL_ITEMS = 32;
  1043. // CS_WHEEL_xxx are special configstrings that
  1044. // map individual weapon and ammo ids to each other, separated by a pipe |
  1045. // the format for CS_WHEEL_WEAPONS is:
  1046. // <CS_ITEMS INDEX>|<CS_IMAGES INDEX>|<CS_WHEEL_AMMO INDEX>|<min ammo>|<on powerup wheel>|<sort id>|<warn quantity>|<droppable>
  1047. // if the weapon does not take ammo, the index will be -1
  1048. // the format for CS_WHEEL_AMMO is:
  1049. // <CS_ITEMS INDEX>|<CS_IMAGES INDEX>
  1050. // the indices here are not related to the IT_ or AMMO_
  1051. // indices, and are just as they appear in the configstrings.
  1052. // the format for CS_WHEEL_POWERUP is:
  1053. // <CS_ITEMS INDEX>|<CS_IMAGES INDEX>|<USE ON/OFF INSTEAD OF COUNT>|<SORT_ID>|<DROPPABLE>|<AMMO, IF APPLICABLE>
  1054. enum game_style_t : uint8_t
  1055. {
  1056. GAME_STYLE_PVE,
  1057. GAME_STYLE_FFA,
  1058. GAME_STYLE_TDM
  1059. };
  1060. //
  1061. // config strings are a general means of communication from
  1062. // the server to all connected clients.
  1063. // Each config string can be at most CS_MAX_STRING_LENGTH characters.
  1064. //
  1065. enum
  1066. {
  1067. CS_NAME,
  1068. CS_CDTRACK,
  1069. CS_SKY,
  1070. CS_SKYAXIS, // %f %f %f format
  1071. CS_SKYROTATE,
  1072. CS_STATUSBAR, // display program string
  1073. CS_AIRACCEL = 59, // air acceleration control
  1074. CS_MAXCLIENTS,
  1075. CS_MAPCHECKSUM, // for catching cheater maps
  1076. CS_MODELS,
  1077. CS_SOUNDS = (CS_MODELS + MAX_MODELS),
  1078. CS_IMAGES = (CS_SOUNDS + MAX_SOUNDS),
  1079. CS_LIGHTS = (CS_IMAGES + MAX_IMAGES),
  1080. CS_SHADOWLIGHTS = (CS_LIGHTS + MAX_LIGHTSTYLES), // [Sam-KEX]
  1081. CS_ITEMS = (CS_SHADOWLIGHTS + MAX_SHADOW_LIGHTS),
  1082. CS_PLAYERSKINS = (CS_ITEMS + MAX_ITEMS),
  1083. CS_GENERAL = (CS_PLAYERSKINS + MAX_CLIENTS),
  1084. CS_WHEEL_WEAPONS = (CS_GENERAL + MAX_GENERAL), // [Paril-KEX] see MAX_WHEEL_ITEMS
  1085. CS_WHEEL_AMMO = (CS_WHEEL_WEAPONS + MAX_WHEEL_ITEMS), // [Paril-KEX] see MAX_WHEEL_ITEMS
  1086. CS_WHEEL_POWERUPS = (CS_WHEEL_AMMO + MAX_WHEEL_ITEMS), // [Paril-KEX] see MAX_WHEEL_ITEMS
  1087. CS_CD_LOOP_COUNT = (CS_WHEEL_POWERUPS + MAX_WHEEL_ITEMS), // [Paril-KEX] override default loop count
  1088. CS_GAME_STYLE, // [Paril-KEX] see game_style_t
  1089. MAX_CONFIGSTRINGS
  1090. };
  1091. static_assert(MAX_CONFIGSTRINGS <= 0x7FFF, "configstrings too big");
  1092. // [Sam-KEX] New define for max config string length
  1093. constexpr size_t CS_MAX_STRING_LENGTH = 96;
  1094. constexpr size_t CS_MAX_STRING_LENGTH_OLD = 64;
  1095. // certain configstrings are allowed to be larger
  1096. // than CS_MAX_STRING_LENGTH; this gets the absolute size
  1097. // for the given configstring at the specified id
  1098. // since vanilla didn't do a very good job of size checking
  1099. constexpr size_t CS_SIZE(int32_t in)
  1100. {
  1101. if (in >= CS_STATUSBAR && in < CS_AIRACCEL)
  1102. return CS_MAX_STRING_LENGTH * (CS_AIRACCEL - in);
  1103. else if (in >= CS_GENERAL && in < CS_WHEEL_WEAPONS)
  1104. return CS_MAX_STRING_LENGTH * (MAX_CONFIGSTRINGS - in);
  1105. return CS_MAX_STRING_LENGTH;
  1106. }
  1107. constexpr size_t MAX_MODELS_OLD = 256, MAX_SOUNDS_OLD = 256, MAX_IMAGES_OLD = 256;
  1108. enum
  1109. {
  1110. CS_NAME_OLD,
  1111. CS_CDTRACK_OLD,
  1112. CS_SKY_OLD,
  1113. CS_SKYAXIS_OLD, // %f %f %f format
  1114. CS_SKYROTATE_OLD,
  1115. CS_STATUSBAR_OLD, // display program string
  1116. CS_AIRACCEL_OLD = 29, // air acceleration control
  1117. CS_MAXCLIENTS_OLD,
  1118. CS_MAPCHECKSUM_OLD, // for catching cheater maps
  1119. CS_MODELS_OLD,
  1120. CS_SOUNDS_OLD = (CS_MODELS_OLD + MAX_MODELS_OLD),
  1121. CS_IMAGES_OLD = (CS_SOUNDS_OLD + MAX_SOUNDS_OLD),
  1122. CS_LIGHTS_OLD = (CS_IMAGES_OLD + MAX_IMAGES_OLD),
  1123. CS_ITEMS_OLD = (CS_LIGHTS_OLD + MAX_LIGHTSTYLES),
  1124. CS_PLAYERSKINS_OLD = (CS_ITEMS_OLD + MAX_ITEMS),
  1125. CS_GENERAL_OLD = (CS_PLAYERSKINS_OLD + MAX_CLIENTS),
  1126. MAX_CONFIGSTRINGS_OLD = (CS_GENERAL_OLD + MAX_GENERAL)
  1127. };
  1128. // remaps old configstring IDs to new ones
  1129. // for old DLL & demo support
  1130. struct configstring_remap_t
  1131. {
  1132. // start position in the configstring list
  1133. // to write into
  1134. size_t start;
  1135. // max length to write into; [start+length-1] should always
  1136. // be set to '\0'
  1137. size_t length;
  1138. };
  1139. constexpr configstring_remap_t CS_REMAP(int32_t id)
  1140. {
  1141. // direct mapping
  1142. if (id < CS_STATUSBAR_OLD)
  1143. return { id * CS_MAX_STRING_LENGTH, CS_MAX_STRING_LENGTH };
  1144. // statusbar needs a bit of special handling, since we have a different
  1145. // max configstring length and these are just segments of a longer string
  1146. else if (id < CS_AIRACCEL_OLD)
  1147. return { (CS_STATUSBAR * CS_MAX_STRING_LENGTH) + ((id - CS_STATUSBAR_OLD) * CS_MAX_STRING_LENGTH_OLD), (CS_AIRACCEL - CS_STATUSBAR) * CS_MAX_STRING_LENGTH };
  1148. // offset
  1149. else if (id < CS_MODELS_OLD)
  1150. return { (id + (CS_AIRACCEL - CS_AIRACCEL_OLD)) * CS_MAX_STRING_LENGTH, CS_MAX_STRING_LENGTH };
  1151. else if (id < CS_SOUNDS_OLD)
  1152. return { (id + (CS_MODELS - CS_MODELS_OLD)) * CS_MAX_STRING_LENGTH, CS_MAX_STRING_LENGTH };
  1153. else if (id < CS_IMAGES_OLD)
  1154. return { (id + (CS_SOUNDS - CS_SOUNDS_OLD)) * CS_MAX_STRING_LENGTH, CS_MAX_STRING_LENGTH };
  1155. else if (id < CS_LIGHTS_OLD)
  1156. return { (id + (CS_IMAGES - CS_IMAGES_OLD)) * CS_MAX_STRING_LENGTH, CS_MAX_STRING_LENGTH };
  1157. else if (id < CS_ITEMS_OLD)
  1158. return { (id + (CS_LIGHTS - CS_LIGHTS_OLD)) * CS_MAX_STRING_LENGTH, CS_MAX_STRING_LENGTH };
  1159. else if (id < CS_PLAYERSKINS_OLD)
  1160. return { (id + (CS_ITEMS - CS_ITEMS_OLD)) * CS_MAX_STRING_LENGTH, CS_MAX_STRING_LENGTH };
  1161. else if (id < CS_GENERAL_OLD)
  1162. return { (id + (CS_PLAYERSKINS - CS_PLAYERSKINS_OLD)) * CS_MAX_STRING_LENGTH, CS_MAX_STRING_LENGTH };
  1163. // general also needs some special handling because it's both
  1164. // offset *and* allowed to overflow
  1165. return { (id + (CS_GENERAL - CS_GENERAL_OLD)) * CS_MAX_STRING_LENGTH_OLD, (MAX_CONFIGSTRINGS - CS_GENERAL) * CS_MAX_STRING_LENGTH };
  1166. }
  1167. static_assert(CS_REMAP(CS_MODELS_OLD).start == (CS_MODELS * 96), "check CS_REMAP");
  1168. static_assert(CS_REMAP(CS_SOUNDS_OLD).start == (CS_SOUNDS * 96), "check CS_REMAP");
  1169. static_assert(CS_REMAP(CS_IMAGES_OLD).start == (CS_IMAGES * 96), "check CS_REMAP");
  1170. static_assert(CS_REMAP(CS_LIGHTS_OLD).start == (CS_LIGHTS * 96), "check CS_REMAP");
  1171. static_assert(CS_REMAP(CS_PLAYERSKINS_OLD).start == (CS_PLAYERSKINS * 96), "check CS_REMAP");
  1172. static_assert(CS_REMAP(CS_ITEMS_OLD).start == (CS_ITEMS * 96), "check CS_REMAP");
  1173. static_assert(CS_REMAP(CS_GENERAL_OLD).start == (CS_GENERAL * 64), "check CS_REMAP");
  1174. static_assert(CS_REMAP(CS_AIRACCEL_OLD).start == (CS_AIRACCEL * 96), "check CS_REMAP");
  1175. //==============================================
  1176. // entity_state_t->event values
  1177. // ertity events are for effects that take place reletive
  1178. // to an existing entities origin. Very network efficient.
  1179. // All muzzle flashes really should be converted to events...
  1180. enum entity_event_t : uint8_t
  1181. {
  1182. EV_NONE,
  1183. EV_ITEM_RESPAWN,
  1184. EV_FOOTSTEP,
  1185. EV_FALLSHORT,
  1186. EV_FALL,
  1187. EV_FALLFAR,
  1188. EV_PLAYER_TELEPORT,
  1189. EV_OTHER_TELEPORT,
  1190. // [Paril-KEX]
  1191. EV_OTHER_FOOTSTEP,
  1192. EV_LADDER_STEP,
  1193. };
  1194. // [Paril-KEX] player s.skinnum's encode additional data
  1195. union player_skinnum_t
  1196. {
  1197. int32_t skinnum;
  1198. struct {
  1199. uint8_t client_num; // client index
  1200. uint8_t vwep_index; // vwep index
  1201. int8_t viewheight; // viewheight
  1202. uint8_t team_index : 4; // team #; note that teams are 1-indexed here, with 0 meaning no team
  1203. // (spectators in CTF would be 0, for instance)
  1204. uint8_t poi_icon : 4; // poi icon; 0 default friendly, 1 dead, others unused
  1205. };
  1206. };
  1207. // entity_state_t is the information conveyed from the server
  1208. // in an update message about entities that the client will
  1209. // need to render in some way
  1210. struct entity_state_t
  1211. {
  1212. uint32_t number; // edict index
  1213. gvec3_t origin;
  1214. gvec3_t angles;
  1215. gvec3_t old_origin; // for lerping
  1216. int32_t modelindex;
  1217. int32_t modelindex2, modelindex3, modelindex4; // weapons, CTF flags, etc
  1218. int32_t frame;
  1219. int32_t skinnum;
  1220. effects_t effects; // PGM - we're filling it, so it needs to be unsigned
  1221. renderfx_t renderfx;
  1222. uint32_t solid; // for client side prediction
  1223. int32_t sound; // for looping sounds, to guarantee shutoff
  1224. entity_event_t event; // impulse events -- muzzle flashes, footsteps, etc
  1225. // events only go out for a single frame, they
  1226. // are automatically cleared each frame
  1227. float alpha; // [Paril-KEX] alpha scalar; 0 is a "default" value, which will respect other
  1228. // settings (default 1.0 for most things, EF_TRANSLUCENT will default this
  1229. // to 0.3, etc)
  1230. float scale; // [Paril-KEX] model scale scalar; 0 is a "default" value, like with alpha.
  1231. uint8_t instance_bits; // [Paril-KEX] players that *can't* see this entity will have a bit of 1. handled by
  1232. // the server, do not set directly.
  1233. // [Paril-KEX] allow specifying volume/attn for looping noises; note that
  1234. // zero will be defaults (1.0 and 3.0 respectively); -1 attenuation is used
  1235. // for "none" (similar to target_speaker) for no phs/pvs looping noises
  1236. float loop_volume;
  1237. float loop_attenuation;
  1238. // [Paril-KEX] for proper client-side owner collision skipping
  1239. int32_t owner;
  1240. // [Paril-KEX] for custom interpolation stuff
  1241. int32_t old_frame;
  1242. };
  1243. //==============================================
  1244. // player_state_t is the information needed in addition to pmove_state_t
  1245. // to rendered a view. There will only be 10 player_state_t sent each second,
  1246. // but the number of pmove_state_t changes will be relative to client
  1247. // frame rates
  1248. struct player_state_t
  1249. {
  1250. pmove_state_t pmove; // for prediction
  1251. // these fields do not need to be communicated bit-precise
  1252. gvec3_t viewangles; // for fixed views
  1253. gvec3_t viewoffset; // add to pmovestate->origin
  1254. gvec3_t kick_angles; // add to view direction to get render angles
  1255. // set by weapon kicks, pain effects, etc
  1256. gvec3_t gunangles;
  1257. gvec3_t gunoffset;
  1258. int32_t gunindex;
  1259. int32_t gunskin; // [Paril-KEX] gun skin #
  1260. int32_t gunframe;
  1261. int32_t gunrate; // [Paril-KEX] tickrate of gun animations; 0 and 10 are equivalent
  1262. std::array<float, 4> screen_blend; // rgba full screen effect
  1263. std::array<float, 4> damage_blend; // [Paril-KEX] rgba damage blend effect
  1264. float fov; // horizontal field of view
  1265. refdef_flags_t rdflags; // refdef flags
  1266. std::array<int16_t, MAX_STATS> stats; // fast status bar updates
  1267. uint8_t team_id; // team identifier
  1268. };
  1269. // protocol bytes that can be directly added to messages
  1270. enum server_command_t : uint8_t
  1271. {
  1272. svc_bad,
  1273. svc_muzzleflash,
  1274. svc_muzzleflash2,
  1275. svc_temp_entity,
  1276. svc_layout,
  1277. svc_inventory,
  1278. svc_nop,
  1279. svc_disconnect,
  1280. svc_reconnect,
  1281. svc_sound, // <see code>
  1282. svc_print, // [byte] id [string] null terminated string
  1283. svc_stufftext, // [string] stuffed into client's console buffer, should be \n terminated
  1284. svc_serverdata, // [long] protocol ...
  1285. svc_configstring, // [short] [string]
  1286. svc_spawnbaseline,
  1287. svc_centerprint, // [string] to put in center of the screen
  1288. svc_download, // [short] size [size bytes]
  1289. svc_playerinfo, // variable
  1290. svc_packetentities, // [...]
  1291. svc_deltapacketentities, // [...]
  1292. svc_frame,
  1293. svc_splitclient,
  1294. svc_configblast, // [Kex] A compressed version of svc_configstring
  1295. svc_spawnbaselineblast, // [Kex] A compressed version of svc_spawnbaseline
  1296. svc_level_restart, // [Paril-KEX] level was soft-rebooted
  1297. svc_damage, // [Paril-KEX] damage indicators
  1298. svc_locprint, // [Kex] localized + libfmt version of print
  1299. svc_fog, // [Paril-KEX] change current fog values
  1300. svc_waitingforplayers, // [Kex-Edward] Inform clients that the server is waiting for remaining players
  1301. svc_bot_chat, // [Kex] bot specific chat
  1302. svc_poi, // [Paril-KEX] point of interest
  1303. svc_help_path, // [Paril-KEX] help path
  1304. svc_muzzleflash3, // [Paril-KEX] muzzleflashes, but ushort id
  1305. svc_achievement, // [Paril-KEX]
  1306. svc_last // only for checks
  1307. };
  1308. enum svc_poi_flags
  1309. {
  1310. POI_FLAG_NONE = 0,
  1311. POI_FLAG_HIDE_ON_AIM = 1, // hide the POI if we get close to it with our aim
  1312. };
  1313. // data for svc_fog
  1314. struct svc_fog_data_t
  1315. {
  1316. enum bits_t : uint16_t
  1317. {
  1318. // global fog
  1319. BIT_DENSITY = bit_v<0>,
  1320. BIT_R = bit_v<1>,
  1321. BIT_G = bit_v<2>,
  1322. BIT_B = bit_v<3>,
  1323. BIT_TIME = bit_v<4>, // if set, the transition takes place over N milliseconds
  1324. // height fog
  1325. BIT_HEIGHTFOG_FALLOFF = bit_v<5>,
  1326. BIT_HEIGHTFOG_DENSITY = bit_v<6>,
  1327. BIT_MORE_BITS = bit_v<7>, // read additional bit
  1328. BIT_HEIGHTFOG_START_R = bit_v<8>,
  1329. BIT_HEIGHTFOG_START_G = bit_v<9>,
  1330. BIT_HEIGHTFOG_START_B = bit_v<10>,
  1331. BIT_HEIGHTFOG_START_DIST= bit_v<11>,
  1332. BIT_HEIGHTFOG_END_R = bit_v<12>,
  1333. BIT_HEIGHTFOG_END_G = bit_v<13>,
  1334. BIT_HEIGHTFOG_END_B = bit_v<14>,
  1335. BIT_HEIGHTFOG_END_DIST = bit_v<15>
  1336. };
  1337. bits_t bits;
  1338. float density; // bits & BIT_DENSITY
  1339. uint8_t skyfactor; // bits & BIT_DENSITY
  1340. uint8_t red; // bits & BIT_R
  1341. uint8_t green; // bits & BIT_G
  1342. uint8_t blue; // bits & BIT_B
  1343. uint16_t time; // bits & BIT_TIME
  1344. float hf_falloff; // bits & BIT_HEIGHTFOG_FALLOFF
  1345. float hf_density; // bits & BIT_HEIGHTFOG_DENSITY
  1346. uint8_t hf_start_r; // bits & (BIT_MORE_BITS | BIT_HEIGHTFOG_START_R)
  1347. uint8_t hf_start_g; // bits & (BIT_MORE_BITS | BIT_HEIGHTFOG_START_G)
  1348. uint8_t hf_start_b; // bits & (BIT_MORE_BITS | BIT_HEIGHTFOG_START_B)
  1349. int32_t hf_start_dist; // bits & (BIT_MORE_BITS | BIT_HEIGHTFOG_START_DIST)
  1350. uint8_t hf_end_r; // bits & (BIT_MORE_BITS | BIT_HEIGHTFOG_END_R)
  1351. uint8_t hf_end_g; // bits & (BIT_MORE_BITS | BIT_HEIGHTFOG_END_G)
  1352. uint8_t hf_end_b; // bits & (BIT_MORE_BITS | BIT_HEIGHTFOG_END_B)
  1353. int32_t hf_end_dist; // bits & (BIT_MORE_BITS | BIT_HEIGHTFOG_END_DIST)
  1354. };
  1355. MAKE_ENUM_BITFLAGS(svc_fog_data_t::bits_t);
  1356. // bit masks
  1357. static constexpr svc_fog_data_t::bits_t BITS_GLOBAL_FOG = (svc_fog_data_t::BIT_DENSITY | svc_fog_data_t::BIT_R | svc_fog_data_t::BIT_G | svc_fog_data_t::BIT_B);
  1358. static constexpr svc_fog_data_t::bits_t BITS_HEIGHTFOG = (svc_fog_data_t::BIT_HEIGHTFOG_FALLOFF | svc_fog_data_t::BIT_HEIGHTFOG_DENSITY | svc_fog_data_t::BIT_HEIGHTFOG_START_R | svc_fog_data_t::BIT_HEIGHTFOG_START_G |
  1359. svc_fog_data_t::BIT_HEIGHTFOG_START_B | svc_fog_data_t::BIT_HEIGHTFOG_START_DIST | svc_fog_data_t::BIT_HEIGHTFOG_END_R | svc_fog_data_t::BIT_HEIGHTFOG_END_G |
  1360. svc_fog_data_t::BIT_HEIGHTFOG_END_B | svc_fog_data_t::BIT_HEIGHTFOG_END_DIST);
  1361. // edict->svflags
  1362. enum svflags_t : uint32_t
  1363. {
  1364. SVF_NONE = 0, // no serverflags
  1365. SVF_NOCLIENT = bit_v<0>, // don't send entity to clients, even if it has effects
  1366. SVF_DEADMONSTER = bit_v<1>, // treat as CONTENTS_DEADMONSTER for collision
  1367. SVF_MONSTER = bit_v<2>, // treat as CONTENTS_MONSTER for collision
  1368. SVF_PLAYER = bit_v<3>, // [Paril-KEX] treat as CONTENTS_PLAYER for collision
  1369. SVF_BOT = bit_v<4>, // entity is controlled by a bot AI.
  1370. SVF_NOBOTS = bit_v<5>, // don't allow bots to use/interact with entity
  1371. SVF_RESPAWNING = bit_v<6>, // entity will respawn on it's next think.
  1372. SVF_PROJECTILE = bit_v<7>, // treat as CONTENTS_PROJECTILE for collision
  1373. SVF_INSTANCED = bit_v<8>, // entity has different visibility per player
  1374. SVF_DOOR = bit_v<9>, // entity is a door of some kind
  1375. SVF_NOCULL = bit_v<10>, // always send, even if we normally wouldn't
  1376. SVF_HULL = bit_v<11> // always use hull when appropriate (triggers, etc; for gi.clip)
  1377. };
  1378. MAKE_ENUM_BITFLAGS(svflags_t);
  1379. // edict->solid values
  1380. enum solid_t : uint8_t
  1381. {
  1382. SOLID_NOT, // no interaction with other objects
  1383. SOLID_TRIGGER, // only touch when inside, after moving
  1384. SOLID_BBOX, // touch on edge
  1385. SOLID_BSP // bsp clip, touch on edge
  1386. };
  1387. // bitflags for STAT_LAYOUTS
  1388. enum layout_flags_t : int16_t
  1389. {
  1390. LAYOUTS_LAYOUT = bit_v<0>, // svc_layout is active; escape remapped to putaway
  1391. LAYOUTS_INVENTORY = bit_v<1>, // inventory is active; escape remapped to putaway
  1392. LAYOUTS_HIDE_HUD = bit_v<2>, // hide entire hud, for cameras, etc
  1393. LAYOUTS_INTERMISSION = bit_v<3>, // intermission is being drawn; collapse splitscreen into 1 view
  1394. LAYOUTS_HELP = bit_v<4>, // help is active; escape remapped to putaway
  1395. LAYOUTS_HIDE_CROSSHAIR = bit_v<5> // hide crosshair only
  1396. };
  1397. MAKE_ENUM_BITFLAGS(layout_flags_t);
  1398. enum GoalReturnCode {
  1399. Error = 0,
  1400. Started,
  1401. InProgress,
  1402. Finished
  1403. };
  1404. enum gesture_type {
  1405. GESTURE_NONE = -1,
  1406. GESTURE_FLIP_OFF,
  1407. GESTURE_SALUTE,
  1408. GESTURE_TAUNT,
  1409. GESTURE_WAVE,
  1410. GESTURE_POINT,
  1411. GESTURE_POINT_NO_PING,
  1412. GESTURE_MAX
  1413. };
  1414. enum class PathReturnCode {
  1415. ReachedGoal = 0, // we're at our destination
  1416. ReachedPathEnd, // we're as close to the goal as we can get with a path
  1417. TraversalPending, // the upcoming path segment is a traversal
  1418. RawPathFound, // user wanted ( and got ) just a raw path ( no processing )
  1419. InProgress, // pathing in progress
  1420. StartPathErrors, // any code after this one indicates an error of some kind.
  1421. InvalidStart, // start position is invalid.
  1422. InvalidGoal, // goal position is invalid.
  1423. NoNavAvailable, // no nav file available for this map.
  1424. NoStartNode, // can't find a nav node near the start position
  1425. NoGoalNode, // can't find a nav node near the goal position
  1426. NoPathFound, // can't find a path from the start to the goal
  1427. MissingWalkOrSwimFlag // MUST have at least Walk or Water path flags set!
  1428. };
  1429. enum class PathLinkType {
  1430. Walk, // can walk between the path points
  1431. WalkOffLedge, // will walk off a ledge going between path points
  1432. LongJump, // will need to perform a long jump between path points
  1433. BarrierJump, // will need to jump over a low barrier between path points
  1434. Elevator // will need to use an elevator between path points
  1435. };
  1436. enum PathFlags : uint32_t {
  1437. All = static_cast<uint32_t>( -1 ),
  1438. Water = bit_v<0>, // swim to your goal ( useful for fish/gekk/etc. )
  1439. Walk = bit_v<1>, // walk to your goal
  1440. WalkOffLedge = bit_v<2>, // allow walking over ledges
  1441. LongJump = bit_v<3>, // allow jumping over gaps
  1442. BarrierJump = bit_v<4>, // allow jumping over low barriers
  1443. Elevator = bit_v<5> // allow using elevators
  1444. };
  1445. MAKE_ENUM_BITFLAGS(PathFlags);
  1446. struct PathRequest {
  1447. gvec3_t start = { 0.0f, 0.0f, 0.0f };
  1448. gvec3_t goal = { 0.0f, 0.0f, 0.0f };
  1449. PathFlags pathFlags = PathFlags::Walk;
  1450. float moveDist = 0.0f;
  1451. struct DebugSettings {
  1452. float drawTime = 0.0f; // if > 0, how long ( in seconds ) to draw path in world
  1453. } debugging;
  1454. struct NodeSettings {
  1455. bool ignoreNodeFlags = false; // true = ignore node flags when considering nodes
  1456. float minHeight = 0.0f; // 0 <= use default values
  1457. float maxHeight = 0.0f; // 0 <= use default values
  1458. float radius = 0.0f; // 0 <= use default values
  1459. } nodeSearch;
  1460. struct TraversalSettings {
  1461. float dropHeight = 0.0f; // 0 = don't drop down
  1462. float jumpHeight = 0.0f; // 0 = don't jump up
  1463. } traversals;
  1464. struct PathArray {
  1465. mutable gvec3_t * array = nullptr; // array to store raw path points
  1466. int64_t count = 0; // number of elements in array
  1467. } pathPoints;
  1468. };
  1469. struct PathInfo {
  1470. int32_t numPathPoints = 0;
  1471. float pathDistSqr = 0.0f;
  1472. gvec3_t firstMovePoint = { 0.0f, 0.0f, 0.0f };
  1473. gvec3_t secondMovePoint = { 0.0f, 0.0f, 0.0f };
  1474. PathLinkType pathLinkType = PathLinkType::Walk;
  1475. PathReturnCode returnCode = PathReturnCode::StartPathErrors;
  1476. };
  1477. //===============================================================
  1478. constexpr int32_t MODELINDEX_WORLD = 1; // special index for world
  1479. constexpr int32_t MODELINDEX_PLAYER = MAX_MODELS_OLD - 1; // special index for player models
  1480. // short stubs only used by the engine; the game DLL's version
  1481. // must be compatible with this.
  1482. #ifndef GAME_INCLUDE
  1483. struct gclient_t
  1484. #else
  1485. struct gclient_shared_t
  1486. #endif
  1487. {
  1488. player_state_t ps; // communicated by server to clients
  1489. int32_t ping;
  1490. // the game dll can add anything it wants after
  1491. // this point in the structure
  1492. };
  1493. static constexpr int32_t Team_None = 0;
  1494. static constexpr int32_t Item_UnknownRespawnTime = INT_MAX;
  1495. static constexpr int32_t Item_Invalid = -1;
  1496. static constexpr int32_t Item_Null = 0;
  1497. enum sv_ent_flags_t : uint64_t {
  1498. SVFL_NONE = 0, // no flags
  1499. SVFL_ONGROUND = bit_v< 0 >,
  1500. SVFL_HAS_DMG_BOOST = bit_v< 1 >,
  1501. SVFL_HAS_PROTECTION = bit_v< 2 >,
  1502. SVFL_HAS_INVISIBILITY = bit_v< 3 >,
  1503. SVFL_IS_JUMPING = bit_v< 4 >,
  1504. SVFL_IS_CROUCHING = bit_v< 5 >,
  1505. SVFL_IS_ITEM = bit_v< 6 >,
  1506. SVFL_IS_OBJECTIVE = bit_v< 7 >,
  1507. SVFL_HAS_TELEPORTED = bit_v< 8 >,
  1508. SVFL_TAKES_DAMAGE = bit_v< 9 >,
  1509. SVFL_IS_HIDDEN = bit_v< 10 >,
  1510. SVFL_IS_NOCLIP = bit_v< 11 >,
  1511. SVFL_IN_WATER = bit_v< 12 >,
  1512. SVFL_NO_TARGET = bit_v< 13 >,
  1513. SVFL_GOD_MODE = bit_v< 14 >,
  1514. SVFL_IS_FLIPPING_OFF = bit_v< 15 >,
  1515. SVFL_IS_SALUTING = bit_v< 16 >,
  1516. SVFL_IS_TAUNTING = bit_v< 17 >,
  1517. SVFL_IS_WAVING = bit_v< 18 >,
  1518. SVFL_IS_POINTING = bit_v< 19 >,
  1519. SVFL_ON_LADDER = bit_v< 20 >,
  1520. SVFL_MOVESTATE_TOP = bit_v< 21 >,
  1521. SVFL_MOVESTATE_BOTTOM = bit_v< 22 >,
  1522. SVFL_MOVESTATE_MOVING = bit_v< 23 >,
  1523. SVFL_IS_LOCKED_DOOR = bit_v< 24 >,
  1524. SVFL_CAN_GESTURE = bit_v< 25 >,
  1525. SVFL_WAS_TELEFRAGGED = bit_v< 26 >,
  1526. SVFL_TRAP_DANGER = bit_v< 27 >,
  1527. SVFL_ACTIVE = bit_v< 28 >,
  1528. SVFL_IS_SPECTATOR = bit_v< 29 >,
  1529. SVFL_IN_TEAM = bit_v< 30 >
  1530. };
  1531. MAKE_ENUM_BITFLAGS( sv_ent_flags_t );
  1532. static constexpr int Max_Armor_Types = 3;
  1533. struct armorInfo_t {
  1534. int32_t item_id = Item_Null;
  1535. int32_t max_count = 0;
  1536. };
  1537. // Used by AI/Tools on the engine side...
  1538. struct sv_entity_t {
  1539. bool init;
  1540. sv_ent_flags_t ent_flags;
  1541. button_t buttons;
  1542. uint32_t spawnflags;
  1543. int32_t item_id;
  1544. int32_t armor_type;
  1545. int32_t armor_value;
  1546. int32_t health;
  1547. int32_t max_health;
  1548. int32_t starting_health;
  1549. int32_t weapon;
  1550. int32_t team;
  1551. int32_t lobby_usernum;
  1552. int32_t respawntime;
  1553. int32_t viewheight;
  1554. int32_t last_attackertime;
  1555. water_level_t waterlevel;
  1556. gvec3_t viewangles;
  1557. gvec3_t viewforward;
  1558. gvec3_t velocity;
  1559. gvec3_t start_origin;
  1560. gvec3_t end_origin;
  1561. edict_t * enemy;
  1562. edict_t * ground_entity;
  1563. const char * classname;
  1564. const char * targetname;
  1565. char netname[ MAX_NETNAME ];
  1566. int32_t inventory[ MAX_ITEMS ] = { 0 };
  1567. armorInfo_t armor_info[ Max_Armor_Types ];
  1568. };
  1569. #ifndef GAME_INCLUDE
  1570. struct edict_t
  1571. #else
  1572. struct edict_shared_t
  1573. #endif
  1574. {
  1575. entity_state_t s;
  1576. gclient_t *client; // nullptr if not a player
  1577. // the server expects the first part
  1578. // of gclient_t to be a player_state_t
  1579. // but the rest of it is opaque
  1580. sv_entity_t sv; // read only info about this entity for the server
  1581. bool inuse;
  1582. // world linkage data
  1583. bool linked;
  1584. int32_t linkcount;
  1585. int32_t areanum, areanum2;
  1586. svflags_t svflags;
  1587. vec3_t mins, maxs;
  1588. vec3_t absmin, absmax, size;
  1589. solid_t solid;
  1590. contents_t clipmask;
  1591. edict_t *owner;
  1592. };
  1593. #define CHECK_INTEGRITY(from_type, to_type, member) \
  1594. static_assert(offsetof(from_type, member) == offsetof(to_type, member) && \
  1595. sizeof(from_type::member) == sizeof(to_type::member), \
  1596. "structure malformed; not compatible with server: check member \"" #member "\"")
  1597. #define CHECK_GCLIENT_INTEGRITY \
  1598. CHECK_INTEGRITY(gclient_t, gclient_shared_t, ps); \
  1599. CHECK_INTEGRITY(gclient_t, gclient_shared_t, ping)
  1600. #define CHECK_EDICT_INTEGRITY \
  1601. CHECK_INTEGRITY(edict_t, edict_shared_t, s); \
  1602. CHECK_INTEGRITY(edict_t, edict_shared_t, client); \
  1603. CHECK_INTEGRITY(edict_t, edict_shared_t, sv); \
  1604. CHECK_INTEGRITY(edict_t, edict_shared_t, inuse); \
  1605. CHECK_INTEGRITY(edict_t, edict_shared_t, linked); \
  1606. CHECK_INTEGRITY(edict_t, edict_shared_t, linkcount); \
  1607. CHECK_INTEGRITY(edict_t, edict_shared_t, areanum); \
  1608. CHECK_INTEGRITY(edict_t, edict_shared_t, areanum2); \
  1609. CHECK_INTEGRITY(edict_t, edict_shared_t, svflags); \
  1610. CHECK_INTEGRITY(edict_t, edict_shared_t, mins); \
  1611. CHECK_INTEGRITY(edict_t, edict_shared_t, maxs); \
  1612. CHECK_INTEGRITY(edict_t, edict_shared_t, absmin); \
  1613. CHECK_INTEGRITY(edict_t, edict_shared_t, absmax); \
  1614. CHECK_INTEGRITY(edict_t, edict_shared_t, size); \
  1615. CHECK_INTEGRITY(edict_t, edict_shared_t, solid); \
  1616. CHECK_INTEGRITY(edict_t, edict_shared_t, clipmask); \
  1617. CHECK_INTEGRITY(edict_t, edict_shared_t, owner)
  1618. //===============================================================
  1619. // file system stuff
  1620. using fs_handle_t = uint64_t;
  1621. enum fs_search_flags_t
  1622. {
  1623. FS_SEARCH_NONE = 0,
  1624. // flags for individual file filtering; note that if none
  1625. // of these are set, they will all apply.
  1626. FS_SEARCH_FOR_DIRECTORIES = bit_v<0>, // only get directories
  1627. FS_SEARCH_FOR_FILES = bit_v<1> // only get files
  1628. };
  1629. MAKE_ENUM_BITFLAGS(fs_search_flags_t);
  1630. enum class BoxEdictsResult_t
  1631. {
  1632. Keep, // keep the given entity in the result and keep looping
  1633. Skip, // skip the given entity
  1634. End = 64, // stop searching any further
  1635. Flags = End
  1636. };
  1637. MAKE_ENUM_BITFLAGS(BoxEdictsResult_t);
  1638. using BoxEdictsFilter_t = BoxEdictsResult_t (*)(edict_t *, void *);
  1639. //
  1640. // functions provided by the main engine
  1641. //
  1642. struct game_import_t
  1643. {
  1644. uint32_t tick_rate;
  1645. float frame_time_s;
  1646. uint32_t frame_time_ms;
  1647. // broadcast to all clients
  1648. void (*Broadcast_Print)(print_type_t printlevel, const char *message);
  1649. // print to appropriate places (console, log file, etc)
  1650. void (*Com_Print)(const char *msg);
  1651. // print directly to a single client (or nullptr for server console)
  1652. void (*Client_Print)(edict_t *ent, print_type_t printlevel, const char *message);
  1653. // center-print to player (legacy function)
  1654. void (*Center_Print)(edict_t *ent, const char *message);
  1655. void (*sound)(edict_t *ent, soundchan_t channel, int soundindex, float volume, float attenuation, float timeofs);
  1656. void (*positioned_sound)(gvec3_cref_t origin, edict_t *ent, soundchan_t channel, int soundindex, float volume, float attenuation, float timeofs);
  1657. // [Paril-KEX] like sound, but only send to the player indicated by the parameter;
  1658. // this is mainly to handle split screen properly
  1659. void (*local_sound)(edict_t *target, gvec3_cptr_t origin, edict_t *ent, soundchan_t channel, int soundindex, float volume, float attenuation, float timeofs, uint32_t dupe_key);
  1660. // config strings hold all the index strings, the lightstyles,
  1661. // and misc data like the sky definition and cdtrack.
  1662. // All of the current configstrings are sent to clients when
  1663. // they connect, and changes are sent to all connected clients.
  1664. void (*configstring)(int num, const char *string);
  1665. const char *(*get_configstring)(int num);
  1666. void (*Com_Error)(const char *message);
  1667. // the *index functions create configstrings and some internal server state
  1668. int (*modelindex)(const char *name);
  1669. int (*soundindex)(const char *name);
  1670. // [Paril-KEX] imageindex can precache both pics for the HUD and
  1671. // textures used for RF_CUSTOMSKIN; to register an image as a texture,
  1672. // the path must be relative to the mod dir and end in an extension
  1673. // ie models/my_model/skin.tga
  1674. int (*imageindex)(const char *name);
  1675. void (*setmodel)(edict_t *ent, const char *name);
  1676. // collision detection
  1677. trace_t (*trace)(gvec3_cref_t start, gvec3_cptr_t mins, gvec3_cptr_t maxs, gvec3_cref_t end, const edict_t *passent, contents_t contentmask);
  1678. // [Paril-KEX] clip the box against the specified entity
  1679. trace_t (*clip)(edict_t *entity, gvec3_cref_t start, gvec3_cptr_t mins, gvec3_cptr_t maxs, gvec3_cref_t end, contents_t contentmask);
  1680. contents_t (*pointcontents)(gvec3_cref_t point);
  1681. bool (*inPVS)(gvec3_cref_t p1, gvec3_cref_t p2, bool portals);
  1682. bool (*inPHS)(gvec3_cref_t p1, gvec3_cref_t p2, bool portals);
  1683. void (*SetAreaPortalState)(int portalnum, bool open);
  1684. bool (*AreasConnected)(int area1, int area2);
  1685. // an entity will never be sent to a client or used for collision
  1686. // if it is not passed to linkentity. If the size, position, or
  1687. // solidity changes, it must be relinked.
  1688. void (*linkentity)(edict_t *ent);
  1689. void (*unlinkentity)(edict_t *ent); // call before removing an interactive edict
  1690. // return a list of entities that touch the input absmin/absmax.
  1691. // if maxcount is 0, it will return a count but not attempt to fill "list".
  1692. // if maxcount > 0, once it reaches maxcount, it will keep going but not fill
  1693. // any more of list (the return count will cap at maxcount).
  1694. // the filter function can remove unnecessary entities from the final list; it is illegal
  1695. // to modify world links in this callback.
  1696. size_t (*BoxEdicts)(gvec3_cref_t mins, gvec3_cref_t maxs, edict_t **list, size_t maxcount, solidity_area_t areatype, BoxEdictsFilter_t filter, void *filter_data);
  1697. // network messaging
  1698. void (*multicast)(gvec3_cref_t origin, multicast_t to, bool reliable);
  1699. // [Paril-KEX] `dupe_key` is a key unique to a group of calls to unicast
  1700. // that will prevent sending the message on this frame with the same key
  1701. // to the same player (for splitscreen players).
  1702. void (*unicast)(edict_t *ent, bool reliable, uint32_t dupe_key);
  1703. void (*WriteChar)(int c);
  1704. void (*WriteByte)(int c);
  1705. void (*WriteShort)(int c);
  1706. void (*WriteLong)(int c);
  1707. void (*WriteFloat)(float f);
  1708. void (*WriteString)(const char *s);
  1709. void (*WritePosition)(gvec3_cref_t pos);
  1710. void (*WriteDir)(gvec3_cref_t pos); // single byte encoded, very coarse
  1711. void (*WriteAngle)(float f); // legacy 8-bit angle
  1712. void (*WriteEntity)(const edict_t *e);
  1713. // managed memory allocation
  1714. void *(*TagMalloc)(size_t size, int tag);
  1715. void (*TagFree)(void *block);
  1716. void (*FreeTags)(int tag);
  1717. // console variable interaction
  1718. cvar_t *(*cvar)(const char *var_name, const char *value, cvar_flags_t flags);
  1719. cvar_t *(*cvar_set)(const char *var_name, const char *value);
  1720. cvar_t *(*cvar_forceset)(const char *var_name, const char *value);
  1721. // ClientCommand and ServerCommand parameter access
  1722. int (*argc)();
  1723. const char *(*argv)(int n);
  1724. const char *(*args)(); // concatenation of all argv >= 1
  1725. // add commands to the server console as if they were typed in
  1726. // for map changing, etc
  1727. void (*AddCommandString)(const char *text);
  1728. void (*DebugGraph)(float value, int color);
  1729. // Fetch named extension from engine.
  1730. void *(*GetExtension)(const char *name);
  1731. // === [KEX] Additional APIs ===
  1732. // bots
  1733. void (*Bot_RegisterEdict)(const edict_t * edict);
  1734. void (*Bot_UnRegisterEdict)(const edict_t * edict);
  1735. GoalReturnCode (*Bot_MoveToPoint)(const edict_t * bot, gvec3_cref_t point, const float moveTolerance);
  1736. GoalReturnCode (*Bot_FollowActor)(const edict_t * bot, const edict_t * actor);
  1737. // pathfinding - returns true if a path was found
  1738. bool (*GetPathToGoal)(const PathRequest & request, PathInfo & info);
  1739. // localization
  1740. void (*Loc_Print)(edict_t* ent, print_type_t level, const char* base, const char** args, size_t num_args);
  1741. // drawing
  1742. void (*Draw_Line)(gvec3_cref_t start, gvec3_cref_t end, const rgba_t &color, const float lifeTime, const bool depthTest);
  1743. void (*Draw_Point)(gvec3_cref_t point, const float size, const rgba_t &color, const float lifeTime, const bool depthTest);
  1744. void (*Draw_Circle)(gvec3_cref_t origin, const float radius, const rgba_t &color, const float lifeTime, const bool depthTest);
  1745. void (*Draw_Bounds)(gvec3_cref_t mins, gvec3_cref_t maxs, const rgba_t &color, const float lifeTime, const bool depthTest);
  1746. void (*Draw_Sphere)(gvec3_cref_t origin, const float radius, const rgba_t &color, const float lifeTime, const bool depthTest);
  1747. void (*Draw_OrientedWorldText)(gvec3_cref_t origin, const char * text, const rgba_t &color, const float size, const float lifeTime, const bool depthTest);
  1748. void (*Draw_StaticWorldText)(gvec3_cref_t origin, gvec3_cref_t angles, const char * text, const rgba_t & color, const float size, const float lifeTime, const bool depthTest);
  1749. void (*Draw_Cylinder)(gvec3_cref_t origin, const float halfHeight, const float radius, const rgba_t &color, const float lifeTime, const bool depthTest);
  1750. void (*Draw_Ray)(gvec3_cref_t origin, gvec3_cref_t direction, const float length, const float size, const rgba_t &color, const float lifeTime, const bool depthTest);
  1751. void (*Draw_Arrow)(gvec3_cref_t start, gvec3_cref_t end, const float size, const rgba_t & lineColor, const rgba_t & arrowColor, const float lifeTime, const bool depthTest);
  1752. // scoreboard
  1753. void (*ReportMatchDetails_Multicast)(bool is_end);
  1754. // get server frame #
  1755. uint32_t (*ServerFrame)();
  1756. // misc utils
  1757. void (*SendToClipBoard)(const char * text);
  1758. // info string stuff
  1759. size_t (*Info_ValueForKey) (const char *s, const char *key, char *buffer, size_t buffer_len);
  1760. bool (*Info_RemoveKey) (char *s, const char *key);
  1761. bool (*Info_SetValueForKey) (char *s, const char *key, const char *value);
  1762. };
  1763. enum class shadow_light_type_t
  1764. {
  1765. point,
  1766. cone
  1767. };
  1768. struct shadow_light_data_t
  1769. {
  1770. shadow_light_type_t lighttype;
  1771. float radius;
  1772. int resolution;
  1773. float intensity = 1;
  1774. float fade_start;
  1775. float fade_end;
  1776. int lightstyle = -1;
  1777. float coneangle = 45;
  1778. vec3_t conedirection;
  1779. };
  1780. enum server_flags_t
  1781. {
  1782. SERVER_FLAGS_NONE = 0,
  1783. SERVER_FLAG_SLOW_TIME = bit_v<0>,
  1784. SERVER_FLAG_INTERMISSION = bit_v<1>,
  1785. SERVER_FLAG_LOADING = bit_v<2>
  1786. };
  1787. MAKE_ENUM_BITFLAGS(server_flags_t);
  1788. //
  1789. // functions exported by the game subsystem
  1790. //
  1791. struct game_export_t
  1792. {
  1793. int apiversion;
  1794. // the init function will only be called when a game starts,
  1795. // not each time a level is loaded. Persistant data for clients
  1796. // and the server can be allocated in init
  1797. void (*PreInit)(); // [Paril-KEX] called before InitGame, to potentially change maxclients
  1798. void (*Init)();
  1799. void (*Shutdown)();
  1800. // each new level entered will cause a call to SpawnEntities
  1801. void (*SpawnEntities)(const char *mapname, const char *entstring, const char *spawnpoint);
  1802. // Read/Write Game is for storing persistant cross level information
  1803. // about the world state and the clients.
  1804. // WriteGame is called every time a level is exited.
  1805. // ReadGame is called on a loadgame.
  1806. // returns pointer to tagmalloc'd allocated string.
  1807. // tagfree after use
  1808. char *(*WriteGameJson)(bool autosave, size_t *out_size);
  1809. void (*ReadGameJson)(const char *json);
  1810. // ReadLevel is called after the default map information has been
  1811. // loaded with SpawnEntities
  1812. // returns pointer to tagmalloc'd allocated string.
  1813. // tagfree after use
  1814. char *(*WriteLevelJson)(bool transition, size_t *out_size);
  1815. void (*ReadLevelJson)(const char *json);
  1816. // [Paril-KEX] game can tell the server whether a save is allowed
  1817. // currently or not.
  1818. bool (*CanSave)();
  1819. // [Paril-KEX] choose a free gclient_t slot for the given social ID; for
  1820. // coop slot re-use. Return nullptr if none is available. You can not
  1821. // return a slot that is currently in use by another client; that must
  1822. // throw a fatal error.
  1823. edict_t *(*ClientChooseSlot) (const char *userinfo, const char *social_id, bool isBot, edict_t **ignore, size_t num_ignore, bool cinematic);
  1824. bool (*ClientConnect)(edict_t *ent, char *userinfo, const char *social_id, bool isBot);
  1825. void (*ClientBegin)(edict_t *ent);
  1826. void (*ClientUserinfoChanged)(edict_t *ent, const char *userinfo);
  1827. void (*ClientDisconnect)(edict_t *ent);
  1828. void (*ClientCommand)(edict_t *ent);
  1829. void (*ClientThink)(edict_t *ent, usercmd_t *cmd);
  1830. void (*RunFrame)(bool main_loop);
  1831. // [Paril-KEX] allow the game DLL to clear per-frame stuff
  1832. void (*PrepFrame)();
  1833. // ServerCommand will be called when an "sv <command>" command is issued on the
  1834. // server console.
  1835. // The game can issue gi.argc() / gi.argv() commands to get the rest
  1836. // of the parameters
  1837. void (*ServerCommand)();
  1838. //
  1839. // global variables shared between game and server
  1840. //
  1841. // The edict array is allocated in the game dll so it
  1842. // can vary in size from one game to another.
  1843. //
  1844. // The size will be fixed when ge->Init() is called
  1845. edict_t *edicts;
  1846. size_t edict_size;
  1847. uint32_t num_edicts; // current number, <= max_edicts
  1848. uint32_t max_edicts;
  1849. // [Paril-KEX] special flags to indicate something to the server
  1850. server_flags_t server_flags;
  1851. // [KEX]: Pmove as export
  1852. void (*Pmove)(pmove_t *pmove); // player movement code called by server & client
  1853. // Fetch named extension from game DLL.
  1854. void *(*GetExtension)(const char *name);
  1855. void (*Bot_SetWeapon)(edict_t * botEdict, const int weaponIndex, const bool instantSwitch);
  1856. void (*Bot_TriggerEdict)(edict_t * botEdict, edict_t * edict);
  1857. void (*Bot_UseItem)(edict_t * botEdict, const int32_t itemID);
  1858. int32_t (*Bot_GetItemID)(const char * classname);
  1859. void (*Edict_ForceLookAtPoint)(edict_t * edict, gvec3_cref_t point);
  1860. bool (*Bot_PickedUpItem )(edict_t * botEdict, edict_t * itemEdict);
  1861. // [KEX]: Checks entity visibility instancing
  1862. bool (*Entity_IsVisibleToPlayer)(edict_t* ent, edict_t* player);
  1863. // Fetch info from the shadow light, for culling
  1864. const shadow_light_data_t *(*GetShadowLightData)(int32_t entity_number);
  1865. };
  1866. // generic rectangle
  1867. struct vrect_t
  1868. {
  1869. int32_t x, y, width, height;
  1870. };
  1871. enum class text_align_t
  1872. {
  1873. LEFT,
  1874. CENTER,
  1875. RIGHT
  1876. };
  1877. // transient data from server
  1878. struct cg_server_data_t
  1879. {
  1880. char layout[1024];
  1881. std::array<int16_t, MAX_ITEMS> inventory;
  1882. };
  1883. constexpr int32_t PROTOCOL_VERSION_3XX = 34;
  1884. constexpr int32_t PROTOCOL_VERSION_DEMOS = 2022;
  1885. constexpr int32_t PROTOCOL_VERSION = 2023;
  1886. //
  1887. // functions provided by main engine for client
  1888. //
  1889. struct cgame_import_t
  1890. {
  1891. uint32_t tick_rate;
  1892. float frame_time_s;
  1893. uint32_t frame_time_ms;
  1894. // print to appropriate places (console, log file, etc)
  1895. void (*Com_Print)(const char *msg);
  1896. // config strings hold all the index strings, the lightstyles,
  1897. // and misc data like the sky definition and cdtrack.
  1898. // All of the current configstrings are sent to clients when
  1899. // they connect, and changes are sent to all connected clients.
  1900. const char *(*get_configstring)(int num);
  1901. void (*Com_Error)(const char *message);
  1902. // managed memory allocation
  1903. void *(*TagMalloc)(size_t size, int tag);
  1904. void (*TagFree)(void *block);
  1905. void (*FreeTags)(int tag);
  1906. // console variable interaction
  1907. cvar_t *(*cvar)(const char *var_name, const char *value, cvar_flags_t flags);
  1908. cvar_t *(*cvar_set)(const char *var_name, const char *value);
  1909. cvar_t *(*cvar_forceset)(const char *var_name, const char *value);
  1910. // add commands to the server console as if they were typed in
  1911. // for map changing, etc
  1912. void (*AddCommandString)(const char *text);
  1913. // Fetch named extension from engine.
  1914. void *(*GetExtension)(const char *name);
  1915. // Check whether current frame is valid
  1916. bool (*CL_FrameValid) ();
  1917. // Get client frame time delta
  1918. float (*CL_FrameTime) ();
  1919. // [Paril-KEX] cgame-specific stuff
  1920. uint64_t (*CL_ClientTime) ();
  1921. uint64_t (*CL_ClientRealTime) ();
  1922. int32_t (*CL_ServerFrame) ();
  1923. int32_t (*CL_ServerProtocol) ();
  1924. const char *(*CL_GetClientName) (int32_t index);
  1925. const char *(*CL_GetClientPic) (int32_t index);
  1926. const char *(*CL_GetClientDogtag) (int32_t index);
  1927. const char *(*CL_GetKeyBinding) (const char *binding); // fetch key bind for key, or empty string
  1928. bool (*Draw_RegisterPic) (const char *name);
  1929. void (*Draw_GetPicSize) (int *w, int *h, const char *name); // will return 0 0 if not found
  1930. void (*SCR_DrawChar)(int x, int y, int scale, int num, bool shadow);
  1931. void (*SCR_DrawPic) (int x, int y, int w, int h, const char *name);
  1932. void (*SCR_DrawColorPic)(int x, int y, int w, int h, const char* name, const rgba_t &color);
  1933. // [Paril-KEX] kfont stuff
  1934. void(*SCR_SetAltTypeface)(bool enabled);
  1935. void (*SCR_DrawFontString)(const char *str, int x, int y, int scale, const rgba_t &color, bool shadow, text_align_t align);
  1936. vec2_t (*SCR_MeasureFontString)(const char *str, int scale);
  1937. float (*SCR_FontLineHeight)(int scale);
  1938. // [Paril-KEX] for legacy text input (not used in lobbies)
  1939. bool (*CL_GetTextInput)(const char **msg, bool *is_team);
  1940. // [Paril-KEX] FIXME this probably should be an export instead...
  1941. int32_t (*CL_GetWarnAmmoCount)(int32_t weapon_id);
  1942. // === [KEX] Additional APIs ===
  1943. // returns a *temporary string* ptr to a localized input
  1944. const char* (*Localize) (const char *base, const char **args, size_t num_args);
  1945. // [Paril-KEX] Draw binding, for centerprint; returns y offset
  1946. int32_t (*SCR_DrawBind) (int32_t isplit, const char *binding, const char *purpose, int x, int y, int scale);
  1947. // [Paril-KEX]
  1948. bool (*CL_InAutoDemoLoop) ();
  1949. };
  1950. //
  1951. // functions exported for client by game subsystem
  1952. //
  1953. struct cgame_export_t
  1954. {
  1955. int apiversion;
  1956. // the init/shutdown functions will be called between levels/connections
  1957. // and when the client initially loads.
  1958. void (*Init)();
  1959. void (*Shutdown)();
  1960. // [Paril-KEX] hud drawing
  1961. void (*DrawHUD) (int32_t isplit, const cg_server_data_t *data, vrect_t hud_vrect, vrect_t hud_safe, int32_t scale, int32_t playernum, const player_state_t *ps);
  1962. // [Paril-KEX] precache special pics used by hud
  1963. void (*TouchPics) ();
  1964. // [Paril-KEX] layout flags; see layout_flags_t
  1965. layout_flags_t (*LayoutFlags) (const player_state_t *ps);
  1966. // [Paril-KEX] fetch the current wheel weapon ID in use
  1967. int32_t (*GetActiveWeaponWheelWeapon) (const player_state_t *ps);
  1968. // [Paril-KEX] fetch owned weapon IDs
  1969. uint32_t (*GetOwnedWeaponWheelWeapons) (const player_state_t *ps);
  1970. // [Paril-KEX] fetch ammo count for given ammo id
  1971. int16_t (*GetWeaponWheelAmmoCount)(const player_state_t *ps, int32_t ammo_id);
  1972. // [Paril-KEX] fetch powerup count for given powerup id
  1973. int16_t (*GetPowerupWheelCount)(const player_state_t *ps, int32_t powerup_id);
  1974. // [Paril-KEX] fetch how much damage was registered by these stats
  1975. int16_t (*GetHitMarkerDamage)(const player_state_t *ps);
  1976. // [KEX]: Pmove as export
  1977. void (*Pmove)(pmove_t *pmove); // player movement code called by server & client
  1978. // [Paril-KEX] allow cgame to react to configstring changes
  1979. void (*ParseConfigString)(int32_t i, const char *s);
  1980. // [Paril-KEX] parse centerprint-like messages
  1981. void (*ParseCenterPrint)(const char *str, int isplit, bool instant);
  1982. // [Paril-KEX] tell the cgame to clear notify stuff
  1983. void (*ClearNotify)(int32_t isplit);
  1984. // [Paril-KEX] tell the cgame to clear centerprint state
  1985. void (*ClearCenterprint)(int32_t isplit);
  1986. // [Paril-KEX] be notified by the game DLL of a message of some sort
  1987. void (*NotifyMessage)(int32_t isplit, const char *msg, bool is_chat);
  1988. // [Paril-KEX]
  1989. void (*GetMonsterFlashOffset)(monster_muzzleflash_id_t id, gvec3_ref_t offset);
  1990. // Fetch named extension from cgame DLL.
  1991. void *(*GetExtension)(const char *name);
  1992. };
  1993. // EOF