q_shared.h 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426
  1. #ifndef __Q_SHARED_H
  2. #define __Q_SHARED_H
  3. // q_shared.h -- included first by ALL program modules.
  4. // A user mod should never modify this file
  5. #ifdef _WIN32
  6. #pragma warning(disable : 4018) // signed/unsigned mismatch
  7. //#pragma warning(disable : 4032) //formal parameter 'number' has different type when promoted
  8. //#pragma warning(disable : 4051) //type conversion; possible loss of data
  9. //#pragma warning(disable : 4057) // slightly different base types
  10. #pragma warning(disable : 4100) // unreferenced formal parameter
  11. //#pragma warning(disable : 4115) //'type' : named type definition in parentheses
  12. #pragma warning(disable : 4125) // decimal digit terminates octal escape sequence
  13. #pragma warning(disable : 4127) // conditional expression is constant
  14. //#pragma warning(disable : 4136) //conversion between different floating-point types
  15. //#pragma warning(disable : 4201) //nonstandard extension used : nameless struct/union
  16. //#pragma warning(disable : 4214) //nonstandard extension used : bit field types other than int
  17. //#pragma warning(disable : 4220) // varargs matches remaining parameters
  18. #pragma warning(disable : 4244) //'conversion' conversion from 'type1' to 'type2', possible loss of data
  19. #pragma warning(disable : 4284) // return type not UDT
  20. //#pragma warning(disable : 4305) // truncation from const double to float
  21. #pragma warning(disable : 4310) // cast truncates constant value
  22. #pragma warning(disable : 4514) //unreferenced inline/local function has been removed
  23. #pragma warning(disable : 4710) // not inlined
  24. #pragma warning(disable : 4711) // selected for automatic inline expansion
  25. #pragma warning(disable : 4786) // identifier was truncated
  26. #endif
  27. //rww - conveniently toggle "gore" code, for model decals and stuff.
  28. #ifndef _XBOX
  29. #define _G2_GORE
  30. #endif
  31. #ifndef FINAL_BUILD
  32. #define G2_PERFORMANCE_ANALYSIS
  33. #endif
  34. #include <assert.h>
  35. #include <math.h>
  36. #include <stdio.h>
  37. #include <stdarg.h>
  38. #include <string.h>
  39. #include <stdlib.h>
  40. #include <time.h>
  41. #include <ctype.h>
  42. #ifdef _XBOX
  43. #define tvector(T) std::vector< T >
  44. #define tdeque(T) std::deque< T >
  45. #define tlist(T) std::list< T >
  46. #define tslist(T) std::slist< T >
  47. #define tset(T) std::set< T, std::less< T > >
  48. #define tmultiset(T) std::multiset< T, std::less< T > >
  49. #define tcset(T,C) std::set< T, C >
  50. #define tcmultiset(T,C) std::multiset< T, C >
  51. #define tmap(K,T) std::map< K, T, std::less< K > >
  52. #define tmultimap(K,T) std::multimap< K, T, std::less< K > >
  53. #define tcmap(K,T,C) std::map< K, T, C >
  54. #define tcmultimap(K,T,C) std::multimap< K, T, C >
  55. #endif // _XBOX
  56. // this is the define for determining if we have an asm version of a C function
  57. #if (defined _M_IX86 || defined __i386__) && !defined __sun__ && !defined __LCC__
  58. #define id386 1
  59. #else
  60. #define id386 0
  61. #endif
  62. // for windows fastcall option
  63. #define QDECL
  64. //======================= WIN32 DEFINES =================================
  65. #ifdef WIN32
  66. #define MAC_STATIC
  67. #undef QDECL
  68. #define QDECL __cdecl
  69. // buildstring will be incorporated into the version string
  70. #ifdef NDEBUG
  71. #ifdef _M_IX86
  72. #define CPUSTRING "win-x86"
  73. #elif defined _M_ALPHA
  74. #define CPUSTRING "win-AXP"
  75. #endif
  76. #else
  77. #ifdef _M_IX86
  78. #define CPUSTRING "win-x86-debug"
  79. #elif defined _M_ALPHA
  80. #define CPUSTRING "win-AXP-debug"
  81. #endif
  82. #endif
  83. #define PATH_SEP '\\'
  84. #endif
  85. //======================= MAC OS X SERVER DEFINES =====================
  86. #if defined(__MACH__) && defined(__APPLE__)
  87. #define MAC_STATIC
  88. #ifdef __ppc__
  89. #define CPUSTRING "MacOSXS-ppc"
  90. #elif defined __i386__
  91. #define CPUSTRING "MacOSXS-i386"
  92. #else
  93. #define CPUSTRING "MacOSXS-other"
  94. #endif
  95. #define PATH_SEP '/'
  96. #define GAME_HARD_LINKED
  97. #define CGAME_HARD_LINKED
  98. #define UI_HARD_LINKED
  99. #endif
  100. //======================= MAC DEFINES =================================
  101. #ifdef __MACOS__
  102. #define MAC_STATIC static
  103. #define CPUSTRING "MacOS-PPC"
  104. #define PATH_SEP ':'
  105. #define GAME_HARD_LINKED
  106. #define CGAME_HARD_LINKED
  107. #define UI_HARD_LINKED
  108. void Sys_PumpEvents( void );
  109. #endif
  110. //======================= LINUX DEFINES =================================
  111. // the mac compiler can't handle >32k of locals, so we
  112. // just waste space and make big arrays static...
  113. #ifdef __linux__
  114. #define MAC_STATIC
  115. #ifdef __i386__
  116. #define CPUSTRING "linux-i386"
  117. #elif defined __axp__
  118. #define CPUSTRING "linux-alpha"
  119. #else
  120. #define CPUSTRING "linux-other"
  121. #endif
  122. #define PATH_SEP '/'
  123. #endif
  124. //=============================================================
  125. typedef unsigned long ulong;
  126. typedef unsigned short word;
  127. typedef unsigned char byte;
  128. typedef const char *LPCSTR;
  129. typedef enum {qfalse, qtrue} qboolean;
  130. #define qboolean int //don't want strict type checking on the qboolean
  131. typedef int qhandle_t;
  132. typedef int thandle_t;
  133. typedef int fxHandle_t;
  134. typedef int sfxHandle_t;
  135. typedef int fileHandle_t;
  136. typedef int clipHandle_t;
  137. #ifndef NULL
  138. #define NULL ((void *)0)
  139. #endif
  140. #define MAX_QINT 0x7fffffff
  141. #define MIN_QINT (-MAX_QINT-1)
  142. // angle indexes
  143. #define PITCH 0 // up / down
  144. #define YAW 1 // left / right
  145. #define ROLL 2 // fall over
  146. // the game guarantees that no string from the network will ever
  147. // exceed MAX_STRING_CHARS
  148. #define MAX_STRING_CHARS 1024 // max length of a string passed to Cmd_TokenizeString
  149. #define MAX_STRING_TOKENS 256 // max tokens resulting from Cmd_TokenizeString
  150. #define MAX_TOKEN_CHARS 1024 // max length of an individual token
  151. #define MAX_INFO_STRING 1024
  152. #define MAX_INFO_KEY 1024
  153. #define MAX_INFO_VALUE 1024
  154. #define MAX_QPATH 64 // max length of a quake game pathname
  155. #ifdef _XBOX
  156. #define MAX_OSPATH 128 // max length of a filesystem pathname
  157. #else
  158. #define MAX_OSPATH 260 // max length of a filesystem pathname
  159. #endif
  160. #define MAX_NAME_LENGTH 32 // max length of a client name
  161. // paramters for command buffer stuffing
  162. typedef enum {
  163. EXEC_NOW, // don't return until completed, a VM should NEVER use this,
  164. // because some commands might cause the VM to be unloaded...
  165. EXEC_INSERT, // insert at current position, but don't run yet
  166. EXEC_APPEND // add to end of the command buffer (normal case)
  167. } cbufExec_t;
  168. //
  169. // these aren't needed by any of the VMs. put in another header?
  170. //
  171. #define MAX_MAP_AREA_BYTES 32 // bit vector of area visibility
  172. // Light Style Constants
  173. #define LS_STYLES_START 0
  174. #define LS_NUM_STYLES 32
  175. #define LS_SWITCH_START (LS_STYLES_START+LS_NUM_STYLES)
  176. #define LS_NUM_SWITCH 32
  177. #define MAX_LIGHT_STYLES 64
  178. // print levels from renderer (FIXME: set up for game / cgame?)
  179. typedef enum {
  180. PRINT_ALL,
  181. PRINT_DEVELOPER, // only print when "developer 1"
  182. PRINT_WARNING,
  183. PRINT_ERROR
  184. } printParm_t;
  185. // parameters to the main Error routine
  186. typedef enum {
  187. ERR_FATAL, // exit the entire game with a popup window
  188. ERR_DROP, // print to console and disconnect from game
  189. ERR_DISCONNECT, // don't kill server
  190. ERR_NEED_CD // pop up the need-cd dialog
  191. } errorParm_t;
  192. // font rendering values used by ui and cgame
  193. #define PROP_GAP_WIDTH 2
  194. //#define PROP_GAP_WIDTH 3
  195. #define PROP_SPACE_WIDTH 4
  196. #define PROP_HEIGHT 16
  197. #define PROP_TINY_SIZE_SCALE 1
  198. #define PROP_SMALL_SIZE_SCALE 1
  199. #define PROP_BIG_SIZE_SCALE 1
  200. #define PROP_GIANT_SIZE_SCALE 2
  201. #define PROP_TINY_HEIGHT 10
  202. #define PROP_GAP_TINY_WIDTH 1
  203. #define PROP_SPACE_TINY_WIDTH 3
  204. #define PROP_BIG_HEIGHT 24
  205. #define PROP_GAP_BIG_WIDTH 3
  206. #define PROP_SPACE_BIG_WIDTH 6
  207. #define BLINK_DIVISOR 600
  208. #define PULSE_DIVISOR 75
  209. #define UI_LEFT 0x00000000 // default
  210. #define UI_CENTER 0x00000001
  211. #define UI_RIGHT 0x00000002
  212. #define UI_FORMATMASK 0x00000007
  213. #define UI_SMALLFONT 0x00000010
  214. #define UI_BIGFONT 0x00000020 // default
  215. #define UI_GIANTFONT 0x00000040
  216. #define UI_DROPSHADOW 0x00000800
  217. #define UI_BLINK 0x00001000
  218. #define UI_INVERSE 0x00002000
  219. #define UI_PULSE 0x00004000
  220. #define UI_UNDERLINE 0x00008000
  221. #define UI_TINYFONT 0x00010000
  222. // stuff for TA's ROQ cinematic code...
  223. //
  224. #define CIN_system 1
  225. #define CIN_loop 2
  226. #define CIN_hold 4
  227. #define CIN_silent 8
  228. #define CIN_shader 16
  229. /*
  230. ==============================================================
  231. MATHLIB
  232. ==============================================================
  233. */
  234. typedef float vec_t;
  235. typedef vec_t vec2_t[2];
  236. typedef vec_t vec3_t[3];
  237. typedef vec_t vec4_t[4];
  238. typedef vec_t vec5_t[5];
  239. typedef vec3_t vec3pair_t[2];
  240. typedef int ivec2_t[2];
  241. typedef int ivec3_t[3];
  242. typedef int ivec4_t[4];
  243. typedef int ivec5_t[5];
  244. typedef int fixed4_t;
  245. typedef int fixed8_t;
  246. typedef int fixed16_t;
  247. #ifndef M_PI
  248. #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
  249. #endif
  250. #define NUMVERTEXNORMALS 162
  251. extern vec3_t bytedirs[NUMVERTEXNORMALS];
  252. // all drawing is done to a 640*480 virtual screen size
  253. // and will be automatically scaled to the real resolution
  254. #define SCREEN_WIDTH 640
  255. #define SCREEN_HEIGHT 480
  256. #define TINYCHAR_WIDTH (SMALLCHAR_WIDTH)
  257. #define TINYCHAR_HEIGHT (SMALLCHAR_HEIGHT/2)
  258. #define SMALLCHAR_WIDTH 8
  259. #define SMALLCHAR_HEIGHT 16
  260. #define BIGCHAR_WIDTH 16
  261. #define BIGCHAR_HEIGHT 16
  262. #define GIANTCHAR_WIDTH 32
  263. #define GIANTCHAR_HEIGHT 48
  264. typedef enum
  265. {
  266. CT_NONE,
  267. CT_BLACK,
  268. CT_RED,
  269. CT_GREEN,
  270. CT_BLUE,
  271. CT_YELLOW,
  272. CT_MAGENTA,
  273. CT_CYAN,
  274. CT_WHITE,
  275. CT_LTGREY,
  276. CT_MDGREY,
  277. CT_DKGREY,
  278. CT_DKGREY2,
  279. CT_VLTORANGE,
  280. CT_LTORANGE,
  281. CT_DKORANGE,
  282. CT_VDKORANGE,
  283. CT_VLTBLUE1,
  284. CT_LTBLUE1,
  285. CT_DKBLUE1,
  286. CT_VDKBLUE1,
  287. CT_VLTBLUE2,
  288. CT_LTBLUE2,
  289. CT_DKBLUE2,
  290. CT_VDKBLUE2,
  291. CT_VLTBROWN1,
  292. CT_LTBROWN1,
  293. CT_DKBROWN1,
  294. CT_VDKBROWN1,
  295. CT_VLTGOLD1,
  296. CT_LTGOLD1,
  297. CT_DKGOLD1,
  298. CT_VDKGOLD1,
  299. CT_VLTPURPLE1,
  300. CT_LTPURPLE1,
  301. CT_DKPURPLE1,
  302. CT_VDKPURPLE1,
  303. CT_VLTPURPLE2,
  304. CT_LTPURPLE2,
  305. CT_DKPURPLE2,
  306. CT_VDKPURPLE2,
  307. CT_VLTPURPLE3,
  308. CT_LTPURPLE3,
  309. CT_DKPURPLE3,
  310. CT_VDKPURPLE3,
  311. CT_VLTRED1,
  312. CT_LTRED1,
  313. CT_DKRED1,
  314. CT_VDKRED1,
  315. CT_VDKRED,
  316. CT_DKRED,
  317. CT_VLTAQUA,
  318. CT_LTAQUA,
  319. CT_DKAQUA,
  320. CT_VDKAQUA,
  321. CT_LTPINK,
  322. CT_DKPINK,
  323. CT_LTCYAN,
  324. CT_DKCYAN,
  325. CT_LTBLUE3,
  326. CT_BLUE3,
  327. CT_DKBLUE3,
  328. CT_HUD_GREEN,
  329. CT_HUD_RED,
  330. CT_ICON_BLUE,
  331. CT_NO_AMMO_RED,
  332. CT_HUD_ORANGE,
  333. CT_TITLE,
  334. CT_MAX
  335. } ct_table_t;
  336. extern vec4_t colorTable[CT_MAX];
  337. #define Q_COLOR_ESCAPE '^'
  338. // you MUST have the last bit on here about colour strings being less than 7 or taiwanese strings register as colour!!!!
  339. #define Q_IsColorString(p) ( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && *((p)+1) != Q_COLOR_ESCAPE && *((p)+1) <= '7' && *((p)+1) >= '0' )
  340. #define COLOR_BLACK '0'
  341. #define COLOR_RED '1'
  342. #define COLOR_GREEN '2'
  343. #define COLOR_YELLOW '3'
  344. #define COLOR_BLUE '4'
  345. #define COLOR_CYAN '5'
  346. #define COLOR_MAGENTA '6'
  347. #define COLOR_WHITE '7'
  348. #define ColorIndex(c) ( ( (c) - '0' ) & 7 )
  349. #define S_COLOR_BLACK "^0"
  350. #define S_COLOR_RED "^1"
  351. #define S_COLOR_GREEN "^2"
  352. #define S_COLOR_YELLOW "^3"
  353. #define S_COLOR_BLUE "^4"
  354. #define S_COLOR_CYAN "^5"
  355. #define S_COLOR_MAGENTA "^6"
  356. #define S_COLOR_WHITE "^7"
  357. extern vec4_t g_color_table[8];
  358. #define MAKERGB( v, r, g, b ) v[0]=r;v[1]=g;v[2]=b
  359. #define MAKERGBA( v, r, g, b, a ) v[0]=r;v[1]=g;v[2]=b;v[3]=a
  360. // Player weapons effects
  361. typedef enum
  362. {
  363. SABER_RED,
  364. SABER_ORANGE,
  365. SABER_YELLOW,
  366. SABER_GREEN,
  367. SABER_BLUE,
  368. SABER_PURPLE
  369. } saber_colors_t;
  370. #define MAX_BATTERIES 2500
  371. #define PI_DIV_180 0.017453292519943295769236907684886
  372. #define INV_PI_DIV_180 57.295779513082320876798154814105
  373. // Punish Aurelio if you don't like these performance enhancements. :-)
  374. #define DEG2RAD( a ) ( ( (a) * PI_DIV_180 ) )
  375. #define RAD2DEG( a ) ( ( (a) * INV_PI_DIV_180 ) )
  376. // A divide can be avoided by just multiplying by PI_DIV_180 which is PI divided by 180. - Aurelio
  377. //#define DEG2RAD( a ) ( ( (a) * M_PI ) / 180.0F )
  378. // A divide can be avoided by just multiplying by INV_PI_DIV_180(inverse of PI/180) which is 180 divided by PI. - Aurelio
  379. //#define RAD2DEG( a ) ( ( (a) * 180.0f ) / M_PI )
  380. #define ENUM2STRING(arg) #arg,arg
  381. struct cplane_s;
  382. extern const vec3_t vec3_origin;
  383. extern const vec3_t axisDefault[3];
  384. #define nanmask (255<<23)
  385. #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
  386. #ifdef _XBOX
  387. inline void Q_CastShort2Float(float *f, const short *s)
  388. {
  389. *f = ((float)*s);
  390. }
  391. inline void Q_CastUShort2Float(float *f, const unsigned short *s)
  392. {
  393. *f = ((float)*s);
  394. }
  395. inline void Q_CastShort2FloatScale(float *f, const short *s, float scale)
  396. {
  397. *f = ((float)*s) * scale;
  398. }
  399. inline void Q_CastUShort2FloatScale(float *f, const unsigned short *s, float scale)
  400. {
  401. *f = ((float)*s) * scale;
  402. }
  403. #endif
  404. float Q_fabs( float f );
  405. float Q_rsqrt( float f ); // reciprocal square root
  406. #define SQRTFAST( x ) ( 1.0f / Q_rsqrt( x ) )
  407. signed char ClampChar( int i );
  408. signed short ClampShort( int i );
  409. // this isn't a real cheap function to call!
  410. int DirToByte( vec3_t dir );
  411. void ByteToDir( int b, vec3_t dir );
  412. #define _DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
  413. #define _VectorSubtract(a,b,c) ((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
  414. #define _VectorAdd(a,b,c) ((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2])
  415. #define _VectorCopy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2])
  416. #define _VectorScale(v, s, o) ((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s))
  417. #define _VectorMA(v, s, b, o) ((o)[0]=(v)[0]+(b)[0]*(s),(o)[1]=(v)[1]+(b)[1]*(s),(o)[2]=(v)[2]+(b)[2]*(s))
  418. #define VectorClear(a) ((a)[0]=(a)[1]=(a)[2]=0)
  419. #define VectorNegate(a,b) ((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2])
  420. #define VectorSet(v, x, y, z) ((v)[0]=(x), (v)[1]=(y), (v)[2]=(z))
  421. #define Vector4Copy(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
  422. #define SnapVector(v) {v[0]=(int)v[0];v[1]=(int)v[1];v[2]=(int)v[2];}
  423. // just in case you do't want to use the macros
  424. inline void VectorMA( const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc) {
  425. vecc[0] = veca[0] + scale*vecb[0];
  426. vecc[1] = veca[1] + scale*vecb[1];
  427. vecc[2] = veca[2] + scale*vecb[2];
  428. }
  429. #ifdef _XBOX
  430. inline void VectorMA( const vec3_t veca, float scale, const short vecb[3], vec3_t vecc) {
  431. // The only time this overload gets used is with normals, so
  432. // (I think) it's safe to do this....
  433. vecc[0] = veca[0] + scale * ((float)vecb[0] / 32767.0f);
  434. vecc[1] = veca[1] + scale * ((float)vecb[1] / 32767.0f);
  435. vecc[2] = veca[2] + scale * ((float)vecb[2] / 32767.0f);
  436. }
  437. #endif
  438. inline vec_t DotProduct( const vec3_t v1, const vec3_t v2 ) {
  439. #ifdef _XBOX1 /// use SSE
  440. float res;
  441. __asm {
  442. mov edx, v1
  443. movss xmm1, [edx]
  444. movhps xmm1, [edx+4]
  445. mov edx, v2
  446. movss xmm2, [edx]
  447. movhps xmm2, [edx+4]
  448. mulps xmm1, xmm2
  449. movaps xmm0, xmm1
  450. shufps xmm0, xmm0, 32h
  451. addps xmm1, xmm0
  452. shufps xmm0, xmm0, 32h
  453. addps xmm1, xmm0
  454. movss [res], xmm1
  455. }
  456. return res;
  457. #else
  458. return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
  459. #endif
  460. }
  461. #ifdef _XBOX
  462. inline vec_t DotProduct( const short v1[3], const vec3_t v2 ) {
  463. return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
  464. }
  465. #endif
  466. inline void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross ) {
  467. cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
  468. cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
  469. cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
  470. }
  471. inline void VectorSubtract( const vec3_t veca, const vec3_t vecb, vec3_t o ) {
  472. #ifdef _XBOX1
  473. __asm {
  474. mov ecx, veca
  475. movss xmm0, [ecx]
  476. movhps xmm0, [ecx+4]
  477. mov edx, vecb
  478. movss xmm1, [edx]
  479. movhps xmm1, [edx+4]
  480. subps xmm0, xmm1
  481. mov eax, o
  482. movss [eax], xmm0
  483. movhps [eax+4], xmm0
  484. }
  485. #else
  486. o[0] = veca[0]-vecb[0];
  487. o[1] = veca[1]-vecb[1];
  488. o[2] = veca[2]-vecb[2];
  489. #endif
  490. }
  491. #ifdef _XBOX
  492. inline void VectorSubtract( const short veca[3], const vec3_t vecb, vec3_t o ) {
  493. o[0] = veca[0]-vecb[0];
  494. o[1] = veca[1]-vecb[1];
  495. o[2] = veca[2]-vecb[2];
  496. }
  497. inline void VectorSubtract( const vec3_t veca, const short vecb[3], vec3_t o ) {
  498. o[0] = veca[0]-vecb[0];
  499. o[1] = veca[1]-vecb[1];
  500. o[2] = veca[2]-vecb[2];
  501. }
  502. inline void VectorSubtract( const short veca[3], const short vecb[3], vec3_t o ) {
  503. o[0] = veca[0]-vecb[0];
  504. o[1] = veca[1]-vecb[1];
  505. o[2] = veca[2]-vecb[2];
  506. }
  507. #endif
  508. inline void VectorAdd( const vec3_t veca, const vec3_t vecb, vec3_t o ) {
  509. #ifdef _XBOX1
  510. __asm {
  511. mov ecx, veca
  512. movss xmm0, [ecx]
  513. movhps xmm0, [ecx+4]
  514. mov edx, vecb
  515. movss xmm1, [edx]
  516. movhps xmm1, [edx+4]
  517. addps xmm0, xmm1
  518. mov eax, o
  519. movss [eax], xmm0
  520. movhps [eax+4], xmm0
  521. }
  522. #else
  523. o[0] = veca[0]+vecb[0];
  524. o[1] = veca[1]+vecb[1];
  525. o[2] = veca[2]+vecb[2];
  526. #endif
  527. }
  528. inline void VectorCopy( const vec3_t in, vec3_t out ) {
  529. out[0] = in[0];
  530. out[1] = in[1];
  531. out[2] = in[2];
  532. }
  533. #ifdef _XBOX
  534. inline void VectorCopy( const short in[3], vec3_t out ) {
  535. out[0] = (float)in[0];
  536. out[1] = (float)in[1];
  537. out[2] = (float)in[2];
  538. }
  539. #endif
  540. inline void VectorScale( const vec3_t i, vec_t scale, vec3_t o ) {
  541. #ifdef _XBOX1
  542. __asm {
  543. movss xmm0, scale
  544. shufps xmm0, xmm0, 0h
  545. mov edx, i
  546. movss xmm1, [edx]
  547. movhps xmm1, [edx+4]
  548. mulps xmm0, xmm1
  549. mov eax, o
  550. movss [eax], xmm0
  551. movhps [eax+4], xmm0
  552. }
  553. #else
  554. o[0] = i[0]*scale;
  555. o[1] = i[1]*scale;
  556. o[2] = i[2]*scale;
  557. #endif
  558. }
  559. float DotProductNormalize( const vec3_t inVec1, const vec3_t inVec2 );
  560. unsigned ColorBytes3 (float r, float g, float b);
  561. unsigned ColorBytes4 (float r, float g, float b, float a);
  562. float NormalizeColor( const vec3_t in, vec3_t out );
  563. float RadiusFromBounds( const vec3_t mins, const vec3_t maxs );
  564. void ClearBounds( vec3_t mins, vec3_t maxs );
  565. #ifdef _XBOX
  566. inline void AddPointToBounds( const short v[3], vec3_t mins, vec3_t maxs ) {
  567. if ( v[0] < mins[0] ) {
  568. mins[0] = v[0];
  569. }
  570. if ( v[0] > maxs[0]) {
  571. maxs[0] = v[0];
  572. }
  573. if ( v[1] < mins[1] ) {
  574. mins[1] = v[1];
  575. }
  576. if ( v[1] > maxs[1]) {
  577. maxs[1] = v[1];
  578. }
  579. if ( v[2] < mins[2] ) {
  580. mins[2] = v[2];
  581. }
  582. if ( v[2] > maxs[2]) {
  583. maxs[2] = v[2];
  584. }
  585. }
  586. #endif
  587. inline void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs ) {
  588. if ( v[0] < mins[0] ) {
  589. mins[0] = v[0];
  590. }
  591. if ( v[0] > maxs[0]) {
  592. maxs[0] = v[0];
  593. }
  594. if ( v[1] < mins[1] ) {
  595. mins[1] = v[1];
  596. }
  597. if ( v[1] > maxs[1]) {
  598. maxs[1] = v[1];
  599. }
  600. if ( v[2] < mins[2] ) {
  601. mins[2] = v[2];
  602. }
  603. if ( v[2] > maxs[2]) {
  604. maxs[2] = v[2];
  605. }
  606. }
  607. inline int VectorCompare( const vec3_t v1, const vec3_t v2 ) {
  608. if (v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2]) {
  609. return 0;
  610. }
  611. return 1;
  612. }
  613. //NOTE: less precise
  614. inline int VectorCompare2( const vec3_t v1, const vec3_t v2 ) {
  615. if ( v1[0] > v2[0]+0.0001f || v1[0] < v2[0]-0.0001f
  616. || v1[1] > v2[1]+0.0001f || v1[1] < v2[1]-0.0001f
  617. || v1[2] > v2[2]+0.0001f || v1[2] < v2[2]-0.0001f ) {
  618. return 0;
  619. }
  620. return 1;
  621. }
  622. inline vec_t VectorLength( const vec3_t v ) {
  623. #ifdef _XBOX1
  624. float res;
  625. __asm {
  626. mov edx, v
  627. movss xmm1, [edx]
  628. movhps xmm1, [edx+4]
  629. movaps xmm2, xmm1
  630. mulps xmm1, xmm2
  631. movaps xmm0, xmm1
  632. shufps xmm0, xmm0, 32h
  633. addps xmm1, xmm0
  634. shufps xmm0, xmm0, 32h
  635. addps xmm1, xmm0
  636. sqrtss xmm1, xmm1
  637. movss [res], xmm1
  638. }
  639. return res;
  640. #else
  641. return (vec_t)sqrt (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
  642. #endif
  643. }
  644. inline vec_t VectorLengthSquared( const vec3_t v ) {
  645. #ifdef _XBOX1
  646. float res;
  647. __asm {
  648. mov edx, v
  649. movss xmm1, [edx]
  650. movhps xmm1, [edx+4]
  651. movaps xmm2, xmm1
  652. mulps xmm1, xmm2
  653. movaps xmm0, xmm1
  654. shufps xmm0, xmm0, 32h
  655. addps xmm1, xmm0
  656. shufps xmm0, xmm0, 32h
  657. addps xmm1, xmm0
  658. movss [res], xmm1
  659. }
  660. return res;
  661. #else
  662. return (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
  663. #endif
  664. }
  665. inline vec_t Distance( const vec3_t p1, const vec3_t p2 ) {
  666. vec3_t v;
  667. VectorSubtract (p2, p1, v);
  668. return VectorLength( v );
  669. }
  670. inline vec_t DistanceSquared( const vec3_t p1, const vec3_t p2 ) {
  671. vec3_t v;
  672. VectorSubtract (p2, p1, v);
  673. return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
  674. }
  675. // fast vector normalize routine that does not check to make sure
  676. // that length != 0, nor does it return length, uses rsqrt approximation
  677. inline void VectorNormalizeFast( vec3_t v )
  678. {
  679. float ilength;
  680. ilength = Q_rsqrt( DotProduct( v, v ) );
  681. v[0] *= ilength;
  682. v[1] *= ilength;
  683. v[2] *= ilength;
  684. }
  685. inline void VectorInverse( vec3_t v ){
  686. v[0] = -v[0];
  687. v[1] = -v[1];
  688. v[2] = -v[2];
  689. }
  690. inline void VectorRotate( vec3_t in, vec3_t matrix[3], vec3_t out )
  691. {
  692. out[0] = DotProduct( in, matrix[0] );
  693. out[1] = DotProduct( in, matrix[1] );
  694. out[2] = DotProduct( in, matrix[2] );
  695. }
  696. //if length is 0, v is untouched otherwise v is normalized
  697. inline vec_t VectorNormalize( vec3_t v ) {
  698. float length, ilength;
  699. length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
  700. length = sqrt (length);
  701. if ( length > 0.0001f ) {
  702. ilength = 1/length;
  703. v[0] *= ilength;
  704. v[1] *= ilength;
  705. v[2] *= ilength;
  706. }
  707. return length;
  708. }
  709. //if length is 0, out is cleared, otherwise out is normalized
  710. inline vec_t VectorNormalize2( const vec3_t v, vec3_t out) {
  711. float length, ilength;
  712. length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
  713. length = sqrt (length);
  714. if (length)
  715. {
  716. ilength = 1/length;
  717. out[0] = v[0]*ilength;
  718. out[1] = v[1]*ilength;
  719. out[2] = v[2]*ilength;
  720. } else {
  721. VectorClear( out );
  722. }
  723. return length;
  724. }
  725. #ifdef _XBOX
  726. inline vec_t VectorNormalize2( const vec3_t v, short out[3]) {
  727. float length, ilength;
  728. length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
  729. length = sqrt (length);
  730. if (length)
  731. {
  732. ilength = 1/length;
  733. out[0] = (short)(v[0]*ilength * 32767.0f);
  734. out[1] = (short)(v[1]*ilength * 32767.0f);
  735. out[2] = (short)(v[2]*ilength * 32767.0f);
  736. } else {
  737. VectorClear( out );
  738. }
  739. return length;
  740. }
  741. #endif
  742. int Q_log2(int val);
  743. inline int Q_rand( int *seed ) {
  744. *seed = (69069 * *seed + 1);
  745. return *seed;
  746. }
  747. inline float Q_random( int *seed ) {
  748. return ( Q_rand( seed ) & 0xffff ) / (float)0x10000;
  749. }
  750. inline float Q_crandom( int *seed ) {
  751. return 2.0F * ( Q_random( seed ) - 0.5f );
  752. }
  753. // Returns a float min <= x < max (exclusive; will get max - 0.00001; but never max
  754. inline float Q_flrand(float min, float max) {
  755. return ((rand() * (max - min)) / 32768.0F) + min;
  756. }
  757. // Returns an integer min <= x <= max (ie inclusive)
  758. inline int Q_irand(int min, int max) {
  759. max++; //so it can round down
  760. return ((rand() * (max - min)) >> 15) + min;
  761. }
  762. //returns a float between 0 and 1.0
  763. inline float random() {
  764. return (rand() / ((float)0x7fff));
  765. }
  766. //returns a float between -1 and 1.0
  767. inline float crandom() {
  768. return (2.0F * (random() - 0.5F));
  769. }
  770. float erandom( float mean );
  771. void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
  772. /*
  773. =================
  774. AnglesToAxis
  775. =================
  776. */
  777. inline void AnglesToAxis( const vec3_t angles, vec3_t axis[3] ) {
  778. vec3_t right;
  779. // angle vectors returns "right" instead of "y axis"
  780. AngleVectors( angles, axis[0], right, axis[2] );
  781. VectorSubtract( vec3_origin, right, axis[1] );
  782. }
  783. inline void AxisClear( vec3_t axis[3] ) {
  784. axis[0][0] = 1;
  785. axis[0][1] = 0;
  786. axis[0][2] = 0;
  787. axis[1][0] = 0;
  788. axis[1][1] = 1;
  789. axis[1][2] = 0;
  790. axis[2][0] = 0;
  791. axis[2][1] = 0;
  792. axis[2][2] = 1;
  793. }
  794. inline void AxisCopy( const vec3_t in[3], vec3_t out[3] ) {
  795. VectorCopy( in[0], out[0] );
  796. VectorCopy( in[1], out[1] );
  797. VectorCopy( in[2], out[2] );
  798. }
  799. void vectoangles( const vec3_t value1, vec3_t angles);
  800. vec_t DistanceHorizontal( const vec3_t p1, const vec3_t p2 );
  801. vec_t DistanceHorizontalSquared( const vec3_t p1, const vec3_t p2 );
  802. inline vec_t GetYawForDirection( const vec3_t p1, const vec3_t p2 ) {
  803. vec3_t v, angles;
  804. VectorSubtract( p2, p1, v );
  805. vectoangles( v, angles );
  806. return angles[YAW];
  807. }
  808. inline void GetAnglesForDirection( const vec3_t p1, const vec3_t p2, vec3_t out ) {
  809. vec3_t v;
  810. VectorSubtract( p2, p1, v );
  811. vectoangles( v, out );
  812. }
  813. void SetPlaneSignbits( struct cplane_s *out );
  814. int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct cplane_s *plane);
  815. //float AngleMod(float a);
  816. inline float LerpAngle (float from, float to, float frac) {
  817. float a;
  818. if ( to - from > 180 ) {
  819. to -= 360;
  820. }
  821. if ( to - from < -180 ) {
  822. to += 360;
  823. }
  824. a = from + frac * (to - from);
  825. return a;
  826. }
  827. /*
  828. =================
  829. AngleSubtract
  830. Always returns a value from -180 to 180
  831. =================
  832. */
  833. inline float AngleSubtract( float a1, float a2 ) {
  834. float a;
  835. a = a1 - a2;
  836. while ( a > 180 ) {
  837. a -= 360;
  838. }
  839. while ( a < -180 ) {
  840. a += 360;
  841. }
  842. return a;
  843. }
  844. inline void AnglesSubtract( vec3_t v1, vec3_t v2, vec3_t v3 ) {
  845. v3[0] = AngleSubtract( v1[0], v2[0] );
  846. v3[1] = AngleSubtract( v1[1], v2[1] );
  847. v3[2] = AngleSubtract( v1[2], v2[2] );
  848. }
  849. /*
  850. =================
  851. AngleNormalize360
  852. returns angle normalized to the range [0 <= angle < 360]
  853. =================
  854. */
  855. inline float AngleNormalize360 ( float angle ) {
  856. return (360.0 / 65536) * ((int)(angle * (65536 / 360.0)) & 65535);
  857. }
  858. /*
  859. =================
  860. AngleNormalize180
  861. returns angle normalized to the range [-180 < angle <= 180]
  862. =================
  863. */
  864. inline float AngleNormalize180 ( float angle ) {
  865. angle = AngleNormalize360( angle );
  866. if ( angle > 180.0 ) {
  867. angle -= 360.0;
  868. }
  869. return angle;
  870. }
  871. /*
  872. =================
  873. AngleDelta
  874. returns the normalized delta from angle1 to angle2
  875. =================
  876. */
  877. inline float AngleDelta ( float angle1, float angle2 ) {
  878. return AngleNormalize180( angle1 - angle2 );
  879. }
  880. qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c );
  881. #ifdef _XBOX
  882. qboolean PlaneFromPoints( vec4_t plane, const short a[3], const short b[3], const short c[3] );
  883. #endif
  884. void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal );
  885. void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
  886. void RotateAroundDirection( vec3_t axis[3], float yaw );
  887. void MakeNormalVectors( const vec3_t forward, vec3_t right, vec3_t up );
  888. // perpendicular vector could be replaced by this
  889. int PlaneTypeForNormal (vec3_t normal);
  890. void MatrixMultiply(float in1[3][3], float in2[3][3], float out[3][3]);
  891. void PerpendicularVector( vec3_t dst, const vec3_t src );
  892. //=============================================
  893. float Com_Clamp( float min, float max, float value );
  894. char *COM_SkipPath( char *pathname );
  895. void COM_StripExtension( const char *in, char *out );
  896. void COM_DefaultExtension( char *path, int maxSize, const char *extension );
  897. //JLFCALLOUT include MPNOTUSED
  898. #ifdef _XBOX
  899. void COM_BeginParseSession( bool nested = false );
  900. #else
  901. void COM_BeginParseSession( void );
  902. #endif
  903. int COM_GetCurrentParseLine( void );
  904. char *COM_Parse( const char **data_p );
  905. char *COM_ParseExt( const char **data_p, qboolean allowLineBreak );
  906. int COM_Compress( char *data_p );
  907. qboolean COM_ParseString( const char **data, const char **s );
  908. qboolean COM_ParseInt( const char **data, int *i );
  909. qboolean COM_ParseFloat( const char **data, float *f );
  910. qboolean COM_ParseVec4( const char **buffer, vec4_t *c);
  911. // data is an in/out parm, returns a parsed out token
  912. void COM_MatchToken( char**buf_p, char *match );
  913. void SkipBracedSection (const char **program);
  914. void SkipRestOfLine ( const char **data );
  915. void Parse1DMatrix (const char **buf_p, int x, float *m);
  916. void Parse2DMatrix (const char **buf_p, int y, int x, float *m);
  917. void Parse3DMatrix (const char **buf_p, int z, int y, int x, float *m);
  918. void QDECL Com_sprintf (char *dest, int size, const char *fmt, ...);
  919. // mode parm for FS_FOpenFile
  920. typedef enum {
  921. FS_READ,
  922. FS_WRITE,
  923. FS_APPEND,
  924. FS_APPEND_SYNC
  925. } fsMode_t;
  926. typedef enum {
  927. FS_SEEK_CUR,
  928. FS_SEEK_END,
  929. FS_SEEK_SET
  930. } fsOrigin_t;
  931. //=============================================
  932. int Q_isprint( int c );
  933. int Q_islower( int c );
  934. int Q_isupper( int c );
  935. int Q_isalpha( int c );
  936. // portable case insensitive compare
  937. //inline int Q_stricmp (const char *s1, const char *s2) {return Q_stricmpn (s1, s2, 99999);}
  938. //int Q_strncmp (const char *s1, const char *s2, int n);
  939. //int Q_stricmpn (const char *s1, const char *s2, int n);
  940. //char *Q_strlwr( char *s1 );
  941. //char *Q_strupr( char *s1 );
  942. //char *Q_strrchr( const char* string, int c );
  943. // NON-portable (but faster) versions
  944. inline int Q_stricmp (const char *s1, const char *s2) { return stricmp(s1, s2); }
  945. inline int Q_strncmp (const char *s1, const char *s2, int n) { return strncmp(s1, s2, n); }
  946. inline int Q_stricmpn (const char *s1, const char *s2, int n) { return strnicmp(s1, s2, n); }
  947. inline char *Q_strlwr( char *s1 ) { return strlwr(s1); }
  948. inline char *Q_strupr( char *s1 ) { return strupr(s1); }
  949. inline char *Q_strrchr( const char* str, int c ) { return strrchr(str, c); }
  950. // buffer size safe library replacements
  951. void Q_strncpyz( char *dest, const char *src, int destsize, qboolean bBarfIfTooLong=qfalse );
  952. void Q_strcat( char *dest, int size, const char *src );
  953. // strlen that discounts Quake color sequences
  954. int Q_PrintStrlen( const char *string );
  955. // removes color sequences from string
  956. char *Q_CleanStr( char *string );
  957. //=============================================
  958. #ifdef _M_IX86
  959. //
  960. // optimised stuff for Intel, since most of our data is in that format anyway...
  961. //
  962. short BigShort(short l);
  963. int BigLong (int l);
  964. float BigFloat (float l);
  965. #define LittleShort(l) l
  966. #define LittleLong(l) l
  967. #define LittleFloat(l) l
  968. //
  969. #else
  970. //
  971. // standard smart-swap code...
  972. //
  973. short BigShort(short l);
  974. short LittleShort(short l);
  975. int BigLong (int l);
  976. int LittleLong (int l);
  977. float BigFloat (float l);
  978. float LittleFloat (float l);
  979. //
  980. #endif
  981. void Swap_Init (void);
  982. char * QDECL va(const char *format, ...);
  983. //=============================================
  984. //
  985. // key / value info strings
  986. //
  987. char *Info_ValueForKey( const char *s, const char *key );
  988. void Info_RemoveKey( char *s, const char *key );
  989. void Info_SetValueForKey( char *s, const char *key, const char *value );
  990. qboolean Info_Validate( const char *s );
  991. void Info_NextPair( const char **s, char key[MAX_INFO_KEY], char value[MAX_INFO_VALUE] );
  992. // this is only here so the functions in q_shared.c and bg_*.c can link
  993. void QDECL Com_Error( int level, const char *error, ... );
  994. void QDECL Com_Printf( const char *msg, ... );
  995. /*
  996. ==========================================================
  997. CVARS (console variables)
  998. Many variables can be used for cheating purposes, so when
  999. cheats is zero, force all unspecified variables to their
  1000. default values.
  1001. ==========================================================
  1002. */
  1003. #define CVAR_TEMP 0 // can be set even when cheats are disabled, but is not archived
  1004. #define CVAR_ARCHIVE 1 // set to cause it to be saved to vars.rc
  1005. // used for system variables, not for player
  1006. // specific configurations
  1007. #define CVAR_USERINFO 2 // sent to server on connect or change
  1008. #define CVAR_SERVERINFO 4 // sent in response to front end requests
  1009. #define CVAR_SYSTEMINFO 8 // these cvars will be duplicated on all clients
  1010. #define CVAR_INIT 16 // don't allow change from console at all,
  1011. // but can be set from the command line
  1012. #define CVAR_LATCH 32 // will only change when C code next does
  1013. // a Cvar_Get(), so it can't be changed
  1014. // without proper initialization. modified
  1015. // will be set, even though the value hasn't
  1016. // changed yet
  1017. #define CVAR_ROM 64 // display only, cannot be set by user at all
  1018. #define CVAR_USER_CREATED 128 // created by a set command
  1019. #define CVAR_SAVEGAME 256 // store this in the savegame
  1020. #define CVAR_CHEAT 512 // can not be changed if cheats are disabled
  1021. #define CVAR_NORESTART 1024 // do not clear when a cvar_restart is issued
  1022. //JLF MPMOVED
  1023. #define CVAR_PROFILE 2048 //used to mark profile cvars.
  1024. // nothing outside the Cvar_*() functions should modify these fields!
  1025. typedef struct cvar_s {
  1026. char *name;
  1027. char *string;
  1028. char *resetString; // cvar_restart will reset to this value
  1029. char *latchedString; // for CVAR_LATCH vars
  1030. int flags;
  1031. qboolean modified; // set each time the cvar is changed
  1032. int modificationCount; // incremented each time the cvar is changed
  1033. float value; // atof( string )
  1034. int integer; // atoi( string )
  1035. struct cvar_s *next;
  1036. } cvar_t;
  1037. #define MAX_CVAR_VALUE_STRING 256
  1038. typedef int cvarHandle_t;
  1039. // the modules that run in the virtual machine can't access the cvar_t directly,
  1040. // so they must ask for structured updates
  1041. typedef struct {
  1042. cvarHandle_t handle;
  1043. int modificationCount;
  1044. float value;
  1045. int integer;
  1046. char string[MAX_CVAR_VALUE_STRING];
  1047. } vmCvar_t;
  1048. /*
  1049. ==============================================================
  1050. COLLISION DETECTION
  1051. ==============================================================
  1052. */
  1053. #include "surfaceflags.h" // shared with the q3map utility
  1054. // plane types are used to speed some tests
  1055. // 0-2 are axial planes
  1056. #define PLANE_X 0
  1057. #define PLANE_Y 1
  1058. #define PLANE_Z 2
  1059. #define PLANE_NON_AXIAL 3
  1060. // plane_t structure
  1061. // !!! if this is changed, it must be changed in asm code too !!!
  1062. typedef struct cplane_s {
  1063. vec3_t normal;
  1064. float dist;
  1065. byte type; // for fast side tests: 0,1,2 = axial, 3 = nonaxial
  1066. byte signbits; // signx + (signy<<1) + (signz<<2), used as lookup during collision
  1067. byte pad[2];
  1068. } cplane_t;
  1069. /*
  1070. Ghoul2 Insert Start
  1071. */
  1072. #if !defined(GHOUL2_SHARED_H_INC)
  1073. #include "..\game\ghoul2_shared.h" //for CGhoul2Info_v
  1074. #endif
  1075. /*
  1076. Ghoul2 Insert End
  1077. */
  1078. #define MAX_G2_COLLISIONS 16
  1079. // a trace is returned when a box is swept through the world
  1080. typedef struct {
  1081. qboolean allsolid; // if true, plane is not valid
  1082. qboolean startsolid; // if true, the initial point was in a solid area
  1083. float fraction; // time completed, 1.0 = didn't hit anything
  1084. vec3_t endpos; // final position
  1085. cplane_t plane; // surface normal at impact, transformed to world space
  1086. int surfaceFlags; // surface hit
  1087. int contents; // contents on other side of surface hit
  1088. int entityNum; // entity the contacted sirface is a part of
  1089. /*
  1090. Ghoul2 Insert Start
  1091. */
  1092. CCollisionRecord G2CollisionMap[MAX_G2_COLLISIONS]; // map that describes all of the parts of ghoul2 models that got hit
  1093. /*
  1094. Ghoul2 Insert End
  1095. */
  1096. } trace_t;
  1097. // trace->entityNum can also be 0 to (MAX_GENTITIES-1)
  1098. // or ENTITYNUM_NONE, ENTITYNUM_WORLD
  1099. // markfragments are returned by CM_MarkFragments()
  1100. typedef struct {
  1101. int firstPoint;
  1102. int numPoints;
  1103. } markFragment_t;
  1104. typedef struct {
  1105. vec3_t origin;
  1106. vec3_t axis[3];
  1107. } orientation_t;
  1108. //=====================================================================
  1109. // in order from highest priority to lowest
  1110. // if none of the catchers are active, bound key strings will be executed
  1111. #define KEYCATCH_CONSOLE 1
  1112. #define KEYCATCH_UI 2
  1113. #define KEYCATCH_MESSAGE 4
  1114. // sound channels
  1115. // channel 0 never willingly overrides
  1116. // other channels will allways override a playing sound on that channel
  1117. #include "channels.h"
  1118. /*
  1119. ========================================================================
  1120. ELEMENTS COMMUNICATED ACROSS THE NET
  1121. ========================================================================
  1122. */
  1123. #define ANGLE2SHORT(x) ((int)((x)*65536/360) & 65535)
  1124. #define SHORT2ANGLE(x) ((x)*(360.0/65536))
  1125. #define SNAPFLAG_RATE_DELAYED 1
  1126. #define SNAPFLAG_NOT_ACTIVE 2 // snapshot used during connection and for zombies
  1127. #define SNAPFLAG_SERVERCOUNT 4 // toggled every map_restart so transitions can be detected
  1128. //
  1129. // per-level limits
  1130. //
  1131. #define MAX_CLIENTS 1 // 128 // absolute limit
  1132. #define MAX_TERRAINS 1 //32
  1133. #define GENTITYNUM_BITS 10 // don't need to send any more
  1134. #define MAX_GENTITIES (1<<GENTITYNUM_BITS)
  1135. // entitynums are communicated with GENTITY_BITS, so any reserved
  1136. // values thatare going to be communcated over the net need to
  1137. // also be in this range
  1138. #define ENTITYNUM_NONE (MAX_GENTITIES-1)
  1139. #define ENTITYNUM_WORLD (MAX_GENTITIES-2)
  1140. #define ENTITYNUM_MAX_NORMAL (MAX_GENTITIES-2)
  1141. #define MAX_MODELS 256
  1142. #define MAX_SOUNDS 380
  1143. #define MAX_SUB_BSP 32
  1144. #ifdef _IMMERSION
  1145. #define MAX_FORCES 96
  1146. #endif // _IMMERSION
  1147. #define MAX_SUBMODELS 512 // nine bits
  1148. #define MAX_FX 128
  1149. #define MAX_WORLD_FX 66 // was 16 // was 4
  1150. /*
  1151. Ghoul2 Insert Start
  1152. */
  1153. #define MAX_CHARSKINS 64 // character skins
  1154. /*
  1155. Ghoul2 Insert End
  1156. */
  1157. #define MAX_CONFIGSTRINGS 1300//1024 //rww - I had to up this for terrains
  1158. // these are the only configstrings that the system reserves, all the
  1159. // other ones are strictly for servergame to clientgame communication
  1160. #define CS_SERVERINFO 0 // an info string with all the serverinfo cvars
  1161. #define CS_SYSTEMINFO 1 // an info string for server system to client system configuration (timescale, etc)
  1162. #define RESERVED_CONFIGSTRINGS 2 // game can't modify below this, only the system can
  1163. //
  1164. // config strings are a general means of communicating variable length strings
  1165. // from the server to all connected clients.
  1166. //
  1167. // CS_SERVERINFO and CS_SYSTEMINFO are defined in q_shared.h
  1168. #define CS_MUSIC 2
  1169. #define CS_MESSAGE 3 // from the map worldspawn's message field
  1170. #define CS_ITEMS 4 // string of 0's and 1's that tell which items are present
  1171. #define CS_AMBIENT_SET 5 // ambient set information for the player
  1172. #define CS_MODELS 10
  1173. #define CS_SKYBOXORG (CS_MODELS+MAX_MODELS) //rww - skybox info
  1174. #define CS_SOUNDS (CS_SKYBOXORG+1)
  1175. #ifdef _IMMERSION
  1176. #define CS_FORCES (CS_SOUNDS+MAX_SOUNDS)
  1177. #define CS_PLAYERS (CS_FORCES+MAX_FORCES)
  1178. #else
  1179. #define CS_PLAYERS (CS_SOUNDS+MAX_SOUNDS)
  1180. #endif // _IMMERSION
  1181. #define CS_LIGHT_STYLES (CS_PLAYERS+MAX_CLIENTS)
  1182. #define CS_TERRAINS (CS_LIGHT_STYLES + (MAX_LIGHT_STYLES*3))
  1183. #define CS_BSP_MODELS (CS_TERRAINS + MAX_TERRAINS)
  1184. #define CS_EFFECTS (CS_BSP_MODELS + MAX_SUB_BSP)//(CS_LIGHT_STYLES + (MAX_LIGHT_STYLES*3))
  1185. /*
  1186. Ghoul2 Insert Start
  1187. */
  1188. #define CS_CHARSKINS (CS_EFFECTS + MAX_FX)
  1189. /*
  1190. Ghoul2 Insert End
  1191. */
  1192. #define CS_DYNAMIC_MUSIC_STATE (CS_CHARSKINS + MAX_CHARSKINS)
  1193. #define CS_WORLD_FX (CS_DYNAMIC_MUSIC_STATE + 1)
  1194. #define CS_MAX (CS_WORLD_FX + MAX_WORLD_FX)
  1195. #if (CS_MAX) > MAX_CONFIGSTRINGS
  1196. #error overflow: (CS_MAX) > MAX_CONFIGSTRINGS
  1197. #endif
  1198. #define MAX_GAMESTATE_CHARS 16000
  1199. typedef struct {
  1200. int stringOffsets[MAX_CONFIGSTRINGS];
  1201. char stringData[MAX_GAMESTATE_CHARS];
  1202. int dataCount;
  1203. } gameState_t;
  1204. typedef enum
  1205. {
  1206. FP_FIRST = 0,//marker
  1207. FP_HEAL = 0,//instant
  1208. FP_LEVITATION,//hold/duration
  1209. FP_SPEED,//duration
  1210. FP_PUSH,//hold/duration
  1211. FP_PULL,//hold/duration
  1212. FP_TELEPATHY,//instant
  1213. FP_GRIP,//hold/duration
  1214. FP_LIGHTNING,//hold/duration
  1215. FP_SABERTHROW,
  1216. FP_SABER_DEFENSE,
  1217. FP_SABER_OFFENSE,
  1218. //new Jedi Academy powers
  1219. FP_RAGE,//duration - speed, invincibility and extra damage for short period, drains your health and leaves you weak and slow afterwards.
  1220. FP_PROTECT,//duration - protect against physical/energy (level 1 stops blaster/energy bolts, level 2 stops projectiles, level 3 protects against explosions)
  1221. FP_ABSORB,//duration - protect against dark force powers (grip, lightning, drain - maybe push/pull, too?)
  1222. FP_DRAIN,//hold/duration - drain force power for health
  1223. FP_SEE,//duration - detect/see hidden enemies
  1224. NUM_FORCE_POWERS
  1225. } forcePowers_t;
  1226. typedef enum
  1227. {
  1228. SABER_NONE = 0,
  1229. SABER_SINGLE,
  1230. SABER_STAFF,
  1231. SABER_DAGGER,
  1232. SABER_BROAD,
  1233. SABER_PRONG,
  1234. SABER_ARC,
  1235. SABER_SAI,
  1236. SABER_CLAW,
  1237. SABER_LANCE,
  1238. SABER_STAR,
  1239. SABER_TRIDENT,
  1240. SABER_SITH_SWORD,
  1241. NUM_SABERS
  1242. } saberType_t;
  1243. //=========================================================
  1244. // bit field limits
  1245. #define MAX_STATS 16
  1246. // NOTE!!! be careful about altering this because although it's used to define an array size, the entry indexes come from
  1247. // the typedef'd enum "persEnum_t" in bg_public.h, and there's no compile-tie between the 2 -slc
  1248. //
  1249. #define MAX_PERSISTANT 16
  1250. #define MAX_POWERUPS 16
  1251. #define MAX_WEAPONS 32
  1252. #define MAX_AMMO 10
  1253. #define MAX_INVENTORY 15 // See INV_MAX
  1254. #define MAX_SECURITY_KEYS 5
  1255. #define MAX_SECURITY_KEY_MESSSAGE 24
  1256. #define MAX_PS_EVENTS 2 // this must be a power of 2 unless you change some &'s to %'s -ste
  1257. #define MAX_WORLD_COORD ( 64*1024 )
  1258. #define MIN_WORLD_COORD ( -64*1024 )
  1259. #define WORLD_SIZE ( MAX_WORLD_COORD - MIN_WORLD_COORD )
  1260. typedef enum
  1261. {
  1262. WHL_NONE,
  1263. WHL_ANKLES,
  1264. WHL_KNEES,
  1265. WHL_WAIST,
  1266. WHL_TORSO,
  1267. WHL_SHOULDERS,
  1268. WHL_HEAD,
  1269. WHL_UNDER
  1270. } waterHeightLevel_t;
  1271. // !!!!!!! loadsave affecting struct !!!!!!!
  1272. typedef struct
  1273. {
  1274. // Actual trail stuff
  1275. int inAction; // controls whether should we even consider starting one
  1276. int duration; // how long each trail seg stays in existence
  1277. int lastTime; // time a saber segement was last stored
  1278. vec3_t base;
  1279. vec3_t tip;
  1280. // Marks stuff
  1281. qboolean haveOldPos[2];
  1282. vec3_t oldPos[2];
  1283. vec3_t oldNormal[2]; // store this in case we don't have a connect-the-dots situation
  1284. // ..then we'll need the normal to project a mark blob onto the impact point
  1285. } saberTrail_t;
  1286. #define MAX_SABER_TRAIL_SEGS 8
  1287. // !!!!!!!!!!!!! loadsave affecting struct !!!!!!!!!!!!!!!
  1288. typedef struct
  1289. {
  1290. qboolean active;
  1291. saber_colors_t color;
  1292. float radius;
  1293. float length;
  1294. float lengthMax;
  1295. float lengthOld;
  1296. vec3_t muzzlePoint;
  1297. vec3_t muzzlePointOld;
  1298. vec3_t muzzleDir;
  1299. vec3_t muzzleDirOld;
  1300. saberTrail_t trail;
  1301. void ActivateTrail ( float duration )
  1302. {
  1303. trail.inAction = qtrue;
  1304. trail.duration = duration;
  1305. };
  1306. void DeactivateTrail ( float duration )
  1307. {
  1308. trail.inAction = qfalse;
  1309. trail.duration = duration;
  1310. };
  1311. } bladeInfo_t;
  1312. #define MAX_BLADES 8
  1313. typedef enum
  1314. {
  1315. SS_NONE = 0,
  1316. SS_FAST,
  1317. SS_MEDIUM,
  1318. SS_STRONG,
  1319. SS_DESANN,
  1320. SS_TAVION,
  1321. SS_DUAL,
  1322. SS_STAFF,
  1323. SS_NUM_SABER_STYLES
  1324. } saber_styles_t;
  1325. // !!!!!!!!!!!! loadsave affecting struct !!!!!!!!!!!!!!!!!!!!!!!!!!
  1326. typedef struct
  1327. {
  1328. char *name; //entry in sabers.cfg, if any
  1329. char *fullName; //the "Proper Name" of the saber, shown in the UI
  1330. saberType_t type; //none, single or staff
  1331. char *model; //hilt model
  1332. char *skin; //hilt custom skin
  1333. int soundOn; //game soundindex for turning on sound
  1334. int soundLoop; //game soundindex for hum/loop sound
  1335. int soundOff; //game soundindex for turning off sound
  1336. int numBlades;
  1337. bladeInfo_t blade[MAX_BLADES]; //blade info - like length, trail, origin, dir, etc.
  1338. saber_styles_t style; //locked style to use, if any
  1339. int maxChain; //how many moves can be chained in a row with this weapon (-1 is infinite, 0 is use default behavior)
  1340. qboolean lockable; //can get into a saberlock
  1341. qboolean throwable; //whether or not this saber can be thrown - FIXME: maybe make this a max level of force saber throw that can be used with this saber?
  1342. qboolean disarmable; //whether or not this saber can be dropped
  1343. qboolean activeBlocking; //whether or not to try to block incoming shots with this saber
  1344. qboolean twoHanded; //uses both hands
  1345. int forceRestrictions; //force powers that cannot be used while this saber is on (bitfield) - FIXME: maybe make this a limit on the max level, per force power, that can be used with this type?
  1346. int lockBonus; //in saberlocks, this type of saber pushes harder or weaker
  1347. int parryBonus; //added to strength of parry with this saber
  1348. int breakParryBonus; //added to strength when hit a parry
  1349. int disarmBonus; //added to disarm chance when win saberlock or have a good parry (knockaway)
  1350. saber_styles_t singleBladeStyle; //makes it so that you use a different style if you only have the first blade active
  1351. qboolean singleBladeThrowable; //makes it so that you can throw this saber if only the first blade is on
  1352. char *brokenSaber1; //if saber is actually hit by another saber, it can be cut in half/broken and will be replaced with this saber in your right hand
  1353. char *brokenSaber2; //if saber is actually hit by another saber, it can be cut in half/broken and will be replaced with this saber in your left hand
  1354. qboolean returnDamage; //when returning from a saber throw, it keeps spinning and doing damage
  1355. void Activate( void )
  1356. {
  1357. for ( int i = 0; i < numBlades; i++ )
  1358. {
  1359. blade[i].active = qtrue;
  1360. }
  1361. };
  1362. void Deactivate( void )
  1363. {
  1364. for ( int i = 0; i < numBlades; i++ )
  1365. {
  1366. blade[i].active = qfalse;
  1367. }
  1368. };
  1369. // Description: Activate a specific Blade of this Saber.
  1370. // Created: 10/03/02 by Aurelio Reis, Modified: 10/03/02 by Aurelio Reis.
  1371. // [in] int iBlade Which Blade to activate.
  1372. // [in] bool bActive Whether to activate it (default true), or deactivate it (false).
  1373. // [return] void
  1374. void BladeActivate( int iBlade, qboolean bActive = qtrue )
  1375. {
  1376. // Validate blade ID/Index.
  1377. if ( iBlade < 0 || iBlade >= numBlades )
  1378. return;
  1379. blade[iBlade].active = bActive;
  1380. }
  1381. qboolean Active()
  1382. {
  1383. for ( int i = 0; i < numBlades; i++ )
  1384. {
  1385. if ( blade[i].active )
  1386. {
  1387. return qtrue;
  1388. }
  1389. }
  1390. return qfalse;
  1391. }
  1392. void SetLength( float length )
  1393. {
  1394. for ( int i = 0; i < numBlades; i++ )
  1395. {
  1396. blade[i].length = length;
  1397. }
  1398. }
  1399. float Length()
  1400. {//return largest length
  1401. float len1 = 0;
  1402. for ( int i = 0; i < numBlades; i++ )
  1403. {
  1404. if ( blade[i].length > len1 )
  1405. {
  1406. len1 = blade[i].length;
  1407. }
  1408. }
  1409. return len1;
  1410. };
  1411. float LengthMax()
  1412. {
  1413. float len1 = 0;
  1414. for ( int i = 0; i < numBlades; i++ )
  1415. {
  1416. if ( blade[i].lengthMax > len1 )
  1417. {
  1418. len1 = blade[i].lengthMax;
  1419. }
  1420. }
  1421. return len1;
  1422. };
  1423. void ActivateTrail ( float duration )
  1424. {
  1425. for ( int i = 0; i < numBlades; i++ )
  1426. {
  1427. blade[i].ActivateTrail( duration );
  1428. }
  1429. };
  1430. void DeactivateTrail ( float duration )
  1431. {
  1432. for ( int i = 0; i < numBlades; i++ )
  1433. {
  1434. blade[i].DeactivateTrail( duration );
  1435. }
  1436. };
  1437. } saberInfo_t;
  1438. #define MAX_SABERS 2 // if this ever changes then update the table "static const save_field_t savefields_gClient[]"!!!!!!!!!!!!
  1439. // playerState_t is the information needed by both the client and server
  1440. // to predict player motion and actions
  1441. // nothing outside of pmove should modify these, or some degree of prediction error
  1442. // will occur
  1443. // you can't add anything to this without modifying the code in msg.c
  1444. // playerState_t is a full superset of entityState_t as it is used by players,
  1445. // so if a playerState_t is transmitted, the entityState_t can be fully derived
  1446. // from it.
  1447. // !!!!!!!!!! LOADSAVE-affecting structure !!!!!!!!!!
  1448. typedef struct playerState_s {
  1449. int commandTime; // cmd->serverTime of last executed command
  1450. int pm_type;
  1451. int bobCycle; // for view bobbing and footstep generation
  1452. int pm_flags; // ducked, jump_held, etc
  1453. int pm_time;
  1454. vec3_t origin;
  1455. vec3_t velocity;
  1456. int weaponTime;
  1457. int weaponChargeTime;
  1458. int rechargeTime; // for the phaser
  1459. int gravity;
  1460. int leanofs;
  1461. int friction;
  1462. int speed;
  1463. int delta_angles[3]; // add to command angles to get view direction
  1464. // changed by spawns, rotating objects, and teleporters
  1465. int groundEntityNum;// ENTITYNUM_NONE = in air
  1466. int legsAnim; //
  1467. int legsAnimTimer; // don't change low priority animations on legs until this runs out
  1468. int torsoAnim; //
  1469. int torsoAnimTimer; // don't change low priority animations on torso until this runs out
  1470. int movementDir; // a number 0 to 7 that represents the relative angle
  1471. // of movement to the view angle (axial and diagonals)
  1472. // when at rest, the value will remain unchanged
  1473. // used to twist the legs during strafing
  1474. int eFlags; // copied to entityState_t->eFlags
  1475. int eventSequence; // pmove generated events
  1476. int events[MAX_PS_EVENTS];
  1477. int eventParms[MAX_PS_EVENTS];
  1478. int externalEvent; // events set on player from another source
  1479. int externalEventParm;
  1480. int externalEventTime;
  1481. int clientNum; // ranges from 0 to MAX_CLIENTS-1
  1482. int weapon; // copied to entityState_t->weapon
  1483. int weaponstate;
  1484. int batteryCharge;
  1485. vec3_t viewangles; // for fixed views
  1486. float legsYaw; // actual legs forward facing
  1487. int viewheight;
  1488. // damage feedback
  1489. int damageEvent; // when it changes, latch the other parms
  1490. int damageYaw;
  1491. int damagePitch;
  1492. int damageCount;
  1493. int stats[MAX_STATS];
  1494. int persistant[MAX_PERSISTANT]; // stats that aren't cleared on death
  1495. int powerups[MAX_POWERUPS]; // level.time that the powerup runs out
  1496. int ammo[MAX_AMMO];
  1497. int inventory[MAX_INVENTORY]; // Count of each inventory item.
  1498. char security_key_message[MAX_SECURITY_KEYS][MAX_SECURITY_KEY_MESSSAGE]; // Security key types
  1499. vec3_t serverViewOrg;
  1500. qboolean saberInFlight;
  1501. int viewEntity; // For overriding player movement controls and vieworg
  1502. int forcePowersActive; //prediction needs to know this
  1503. //NEW vehicle stuff
  1504. // This has been localized to the vehicle stuff (NOTE: We can still use it later, I'm just commenting it to
  1505. // root out all the calls. We can store the data in vehicles and update by copying it here).
  1506. //int vehicleIndex; // Index into vehicleData table
  1507. //vec3_t vehicleAngles; // current angles of your vehicle
  1508. //int vehicleArmor; // current armor of your vehicle (explodes if drops to 0)
  1509. // !!
  1510. // not communicated over the net at all
  1511. // !!
  1512. //int vehicleLastFXTime; //timer for all cgame-FX...?
  1513. //int vehicleExplodeTime; //when it will go BOOM!
  1514. int useTime; //not sent
  1515. int lastShotTime;//last time you shot your weapon
  1516. int ping; // server to game info for scoreboard
  1517. int lastOnGround; //last time you were on the ground
  1518. int lastStationary; //last time you were on the ground
  1519. int weaponShotCount;
  1520. //FIXME: maybe allocate all these structures (saber, force powers, vehicles)
  1521. // or descend them as classes - so not every client has all this info
  1522. saberInfo_t saber[MAX_SABERS];
  1523. qboolean dualSabers;
  1524. qboolean SaberStaff( void ) { return ( saber[0].type == SABER_STAFF || (dualSabers && saber[1].type == SABER_STAFF) ); };
  1525. qboolean SaberActive() { return ( saber[0].Active() || (dualSabers&&saber[1].Active()) ); };
  1526. void SetSaberLength( float length )
  1527. {
  1528. saber[0].SetLength( length );
  1529. if ( dualSabers )
  1530. {
  1531. saber[1].SetLength( length );
  1532. }
  1533. }
  1534. float SaberLength()
  1535. {//return largest length
  1536. float len1 = saber[0].Length();
  1537. if ( dualSabers && saber[1].Length() > len1 )
  1538. {
  1539. return saber[1].Length();
  1540. }
  1541. return len1;
  1542. };
  1543. float SaberLengthMax()
  1544. {
  1545. if ( saber[0].LengthMax() > saber[1].LengthMax() )
  1546. {
  1547. return saber[0].LengthMax();
  1548. }
  1549. else if ( dualSabers )
  1550. {
  1551. return saber[1].LengthMax();
  1552. }
  1553. return 0.0f;
  1554. };
  1555. // Activate or deactivate a specific Blade of a Saber.
  1556. // Created: 10/03/02 by Aurelio Reis, Modified: 10/03/02 by Aurelio Reis.
  1557. // [in] int iSaber Which Saber to modify.
  1558. // [in] int iBlade Which blade to modify (0 - (NUM_BLADES - 1)).
  1559. // [in] bool bActive Whether to make it active (default true) or inactive (false).
  1560. // [return] void
  1561. void SaberBladeActivate( int iSaber, int iBlade, qboolean bActive = qtrue )
  1562. {
  1563. // Validate saber (if it's greater than or equal to zero, OR it above the first saber but we
  1564. // are not doing duel Sabers, leave, something is not right.
  1565. if ( iSaber < 0 || ( iSaber > 0 && !dualSabers ) )
  1566. return;
  1567. saber[iSaber].BladeActivate( iBlade, bActive );
  1568. }
  1569. void SaberActivate( void )
  1570. {
  1571. saber[0].Activate();
  1572. if ( dualSabers )
  1573. {
  1574. saber[1].Activate();
  1575. }
  1576. }
  1577. void SaberDeactivate( void )
  1578. {
  1579. saber[0].Deactivate();
  1580. saber[1].Deactivate();
  1581. };
  1582. void SaberActivateTrail ( float duration )
  1583. {
  1584. saber[0].ActivateTrail( duration );
  1585. if ( dualSabers )
  1586. {
  1587. saber[1].ActivateTrail( duration );
  1588. }
  1589. };
  1590. void SaberDeactivateTrail ( float duration )
  1591. {
  1592. saber[0].DeactivateTrail( duration );
  1593. if ( dualSabers )
  1594. {
  1595. saber[1].DeactivateTrail( duration );
  1596. }
  1597. };
  1598. int SaberDisarmBonus( void )
  1599. {
  1600. int disarmBonus = 0;
  1601. if ( saber[0].Active() )
  1602. {
  1603. disarmBonus += saber[0].disarmBonus;
  1604. }
  1605. if ( dualSabers && saber[1].Active() )
  1606. {//bonus for having 2 sabers
  1607. disarmBonus += 1 + saber[1].disarmBonus;
  1608. }
  1609. return disarmBonus;
  1610. };
  1611. int SaberParryBonus( void )
  1612. {
  1613. int parryBonus = 0;
  1614. if ( saber[0].Active() )
  1615. {
  1616. parryBonus += saber[0].parryBonus;
  1617. }
  1618. if ( dualSabers && saber[1].Active() )
  1619. {//bonus for having 2 sabers
  1620. parryBonus += 1 + saber[1].parryBonus;
  1621. }
  1622. return parryBonus;
  1623. };
  1624. short saberMove;
  1625. short saberMoveNext;
  1626. short saberBounceMove;
  1627. short saberBlocking;
  1628. short saberBlocked;
  1629. short leanStopDebounceTime;
  1630. int saberEntityNum;
  1631. float saberEntityDist;
  1632. int saberThrowTime;
  1633. int saberEntityState;
  1634. int saberDamageDebounceTime;
  1635. int saberHitWallSoundDebounceTime;
  1636. int saberEventFlags;
  1637. int saberBlockingTime;
  1638. int saberAnimLevel;
  1639. int saberAttackChainCount;
  1640. int saberLockTime;
  1641. int saberLockEnemy;
  1642. int saberStylesKnown;
  1643. int forcePowersKnown;
  1644. int forcePowerDuration[NUM_FORCE_POWERS]; //for effects that have a duration
  1645. int forcePowerDebounce[NUM_FORCE_POWERS]; //for effects that must have an interval
  1646. int forcePower;
  1647. int forcePowerMax;
  1648. int forcePowerRegenDebounceTime;
  1649. int forcePowerRegenRate; //default is 100ms
  1650. int forcePowerRegenAmount; //default is 1
  1651. int forcePowerLevel[NUM_FORCE_POWERS]; //so we know the max forceJump power you have
  1652. float forceJumpZStart; //So when you land, you don't get hurt as much
  1653. float forceJumpCharge; //you're current forceJump charge-up level, increases the longer you hold the force jump button down
  1654. int forceGripEntityNum; //what entity I'm gripping
  1655. vec3_t forceGripOrg; //where the gripped ent should be lifted to
  1656. int forceDrainEntityNum; //what entity I'm draining
  1657. vec3_t forceDrainOrg; //where the drained ent should be lifted to
  1658. int forceHealCount; //how many points of force heal have been applied so far
  1659. //new Jedi Academy force powers
  1660. int forceAllowDeactivateTime;
  1661. int forceRageDrainTime;
  1662. int forceRageRecoveryTime;
  1663. int forceDrainEntNum;
  1664. float forceDrainTime;
  1665. int forcePowersForced; //client is being forced to use these powers (FIXME: and only these?)
  1666. int pullAttackEntNum;
  1667. int pullAttackTime;
  1668. int lastKickedEntNum;
  1669. int taunting; //replaced BUTTON_GESTURE
  1670. float jumpZStart; //So when you land, you don't get hurt as much
  1671. vec3_t moveDir;
  1672. float waterheight; //exactly what the z org of the water is (will be +4 above if under water, -4 below if not in water)
  1673. waterHeightLevel_t waterHeightLevel; //how high it really is
  1674. //testing IK grabbing
  1675. qboolean ikStatus; //for IK
  1676. int heldClient; //for IK, who I'm grabbing, if anyone
  1677. int heldByClient; //for IK, someone is grabbing me
  1678. int heldByBolt; //for IK, what bolt I'm attached to on the holdersomeone is grabbing me by
  1679. int heldByBone; //for IK, what bone I'm being held by
  1680. //vehicle turn-around stuff... FIXME: only vehicles need this in SP...
  1681. int vehTurnaroundIndex;
  1682. int vehTurnaroundTime;
  1683. //NOTE: not really used in SP, just for Fighter Vehicle damage stuff
  1684. int brokenLimbs;
  1685. int electrifyTime;
  1686. } playerState_t;
  1687. //====================================================================
  1688. //
  1689. // usercmd_t->button bits, many of which are generated by the client system,
  1690. // so they aren't game/cgame only definitions
  1691. //
  1692. #define BUTTON_ATTACK 1
  1693. #define BUTTON_FORCE_LIGHTNING 2 // displays talk balloon and disables actions
  1694. #define BUTTON_USE_FORCE 4
  1695. #define BUTTON_FORCE_DRAIN 8 // draining
  1696. #define BUTTON_VEH_SPEED 8 // used for some horrible vehicle hack... :)
  1697. #define BUTTON_WALKING 16 // walking can't just be infered from MOVE_RUN because a key pressed late in the frame will
  1698. // only generate a small move value for that frame walking will use different animations and
  1699. // won't generate footsteps
  1700. #define BUTTON_USE 32 // the ol' use key returns!
  1701. #define BUTTON_FORCEGRIP 64 //
  1702. #define BUTTON_ALT_ATTACK 128
  1703. #define BUTTON_FORCE_FOCUS 256 // any key whatsoever
  1704. #define MOVE_RUN 120 // if forwardmove or rightmove are >= MOVE_RUN,
  1705. // then BUTTON_WALKING should be set
  1706. typedef enum
  1707. {
  1708. GENCMD_FORCE_HEAL = 1,
  1709. GENCMD_FORCE_SPEED,
  1710. GENCMD_FORCE_THROW,
  1711. GENCMD_FORCE_PULL,
  1712. GENCMD_FORCE_DISTRACT,
  1713. GENCMD_FORCE_GRIP,
  1714. GENCMD_FORCE_LIGHTNING,
  1715. GENCMD_FORCE_RAGE,
  1716. GENCMD_FORCE_PROTECT,
  1717. GENCMD_FORCE_ABSORB,
  1718. GENCMD_FORCE_DRAIN,
  1719. GENCMD_FORCE_SEEING,
  1720. } genCmds_t;
  1721. // usercmd_t is sent to the server each client frame
  1722. // !!!!!!!!!! LOADSAVE-affecting structure !!!!!!!!!!
  1723. typedef struct usercmd_s {
  1724. int serverTime;
  1725. int buttons;
  1726. byte weapon;
  1727. int angles[3];
  1728. byte generic_cmd;
  1729. signed char forwardmove, rightmove, upmove;
  1730. } usercmd_t;
  1731. //===================================================================
  1732. // if entityState->solid == SOLID_BMODEL, modelindex is an inline model number
  1733. #define SOLID_BMODEL 0xffffff
  1734. typedef enum {// !!!!!!!!!!! LOADSAVE-affecting struct !!!!!!!!!!
  1735. TR_STATIONARY,
  1736. TR_INTERPOLATE, // non-parametric, but interpolate between snapshots
  1737. TR_LINEAR,
  1738. TR_LINEAR_STOP,
  1739. TR_NONLINEAR_STOP,
  1740. TR_SINE, // value = base + sin( time / duration ) * delta
  1741. TR_GRAVITY
  1742. } trType_t;
  1743. typedef struct {// !!!!!!!!!!! LOADSAVE-affecting struct !!!!!!!!!!
  1744. trType_t trType;
  1745. int trTime;
  1746. int trDuration; // if non 0, trTime + trDuration = stop time
  1747. vec3_t trBase;
  1748. vec3_t trDelta; // velocity, etc
  1749. } trajectory_t;
  1750. // entityState_t is the information conveyed from the server
  1751. // in an update message about entities that the client will
  1752. // need to render in some way
  1753. // Different eTypes may use the information in different ways
  1754. // The messages are delta compressed, so it doesn't really matter if
  1755. // the structure size is fairly large
  1756. typedef struct entityState_s {// !!!!!!!!!!! LOADSAVE-affecting struct !!!!!!!!!!!!!
  1757. int number; // entity index
  1758. int eType; // entityType_t
  1759. int eFlags;
  1760. trajectory_t pos; // for calculating position
  1761. trajectory_t apos; // for calculating angles
  1762. int time;
  1763. int time2;
  1764. vec3_t origin;
  1765. vec3_t origin2;
  1766. vec3_t angles;
  1767. vec3_t angles2;
  1768. int otherEntityNum; // shotgun sources, etc
  1769. int otherEntityNum2;
  1770. int groundEntityNum; // -1 = in air
  1771. int constantLight; // r + (g<<8) + (b<<16) + (intensity<<24)
  1772. int loopSound; // constantly loop this sound
  1773. int modelindex;
  1774. int modelindex2;
  1775. int modelindex3;
  1776. int clientNum; // 0 to (MAX_CLIENTS - 1), for players and corpses
  1777. int frame;
  1778. int solid; // for client side prediction, gi.linkentity sets this properly
  1779. int event; // impulse events -- muzzle flashes, footsteps, etc
  1780. int eventParm;
  1781. // for players
  1782. int powerups; // bit flags
  1783. int weapon; // determines weapon and flash model, etc
  1784. int legsAnim; //
  1785. int legsAnimTimer; // don't change low priority animations on legs until this runs out
  1786. int torsoAnim; //
  1787. int torsoAnimTimer; // don't change low priority animations on torso until this runs out
  1788. int scale; //Scale players
  1789. //FIXME: why did IMMERSION dupe these 2 fields here? There's no reason for this!!!
  1790. qboolean saberInFlight;
  1791. qboolean saberActive;
  1792. //int vehicleIndex; // What kind of vehicle you're driving
  1793. vec3_t vehicleAngles; //
  1794. int vehicleArmor; // current armor of your vehicle (explodes if drops to 0)
  1795. // 0 if not in a vehicle, otherwise the client number.
  1796. int m_iVehicleNum;
  1797. /*
  1798. Ghoul2 Insert Start
  1799. */
  1800. vec3_t modelScale; // used to scale models in any axis
  1801. int radius; // used for culling all the ghoul models attached to this ent NOTE - this is automatically scaled by Ghoul2 if/when you scale the model. This is a 100% size value
  1802. int boltInfo; // info used for bolting entities to Ghoul2 models - NOT used for bolting ghoul2 models to themselves, more for stuff like bolting effects to ghoul2 models
  1803. /*
  1804. Ghoul2 Insert End
  1805. */
  1806. qboolean isPortalEnt;
  1807. } entityState_t;
  1808. typedef enum {
  1809. CA_UNINITIALIZED,
  1810. CA_DISCONNECTED, // not talking to a server
  1811. CA_CONNECTING, // sending request packets to the server
  1812. CA_CHALLENGING, // sending challenge packets to the server
  1813. CA_CONNECTED, // netchan_t established, getting gamestate
  1814. CA_LOADING, // only during cgame initialization, never during main loop
  1815. CA_PRIMED, // got gamestate, waiting for first frame
  1816. CA_ACTIVE, // game views should be displayed
  1817. CA_CINEMATIC // playing a cinematic or a static pic, not connected to a server
  1818. } connstate_t;
  1819. typedef struct SSkinGoreData_s
  1820. {
  1821. vec3_t angles;
  1822. vec3_t position;
  1823. int currentTime;
  1824. int entNum;
  1825. vec3_t rayDirection; // in world space
  1826. vec3_t hitLocation; // in world space
  1827. vec3_t scale;
  1828. float SSize; // size of splotch in the S texture direction in world units
  1829. float TSize; // size of splotch in the T texture direction in world units
  1830. float theta; // angle to rotate the splotch
  1831. vec3_t uaxis; //mark direction
  1832. float depthStart; // limit marks begin depth
  1833. float depthEnd; // depth to stop making marks
  1834. bool useTheta;
  1835. bool frontFaces;
  1836. bool backFaces;
  1837. bool fadeRGB; //specify fade method to modify RGB (by default, the alpha is set instead)
  1838. // growing stuff
  1839. int growDuration; // time over which we want this to scale up, set to -1 for no scaling
  1840. float goreScaleStartFraction; // fraction of the final size at which we want the gore to initially appear
  1841. //qboolean baseModelOnly;
  1842. int lifeTime; // effect expires after this amount of time
  1843. int fadeOutTime; //specify the duration of fading, from the lifeTime (e.g. 3000 will start fading 3 seconds before removal and be faded entirely by removal)
  1844. //int shrinkOutTime; // unimplemented
  1845. //float alphaModulate; // unimplemented
  1846. //vec3_t tint; // unimplemented
  1847. //float impactStrength; // unimplemented
  1848. int shader; // shader handle
  1849. int myIndex; // used internally
  1850. } SSkinGoreData;
  1851. //rww - used for my ik stuff (ported directly from mp)
  1852. typedef struct
  1853. {
  1854. vec3_t angles;
  1855. vec3_t position;
  1856. vec3_t scale;
  1857. vec3_t velocity;
  1858. int me;
  1859. } sharedRagDollUpdateParams_t;
  1860. //rww - update parms for ik bone stuff
  1861. typedef struct
  1862. {
  1863. char boneName[512]; //name of bone
  1864. vec3_t desiredOrigin; //world coordinate that this bone should be attempting to reach
  1865. vec3_t origin; //world coordinate of the entity who owns the g2 instance that owns the bone
  1866. float movementSpeed; //how fast the bone should move toward the destination
  1867. } sharedIKMoveParams_t;
  1868. typedef struct
  1869. {
  1870. vec3_t pcjMins; //ik joint limit
  1871. vec3_t pcjMaxs; //ik joint limit
  1872. vec3_t origin; //origin of caller
  1873. vec3_t angles; //angles of caller
  1874. vec3_t scale; //scale of caller
  1875. float radius; //bone rad
  1876. int blendTime; //bone blend time
  1877. int pcjOverrides; //override ik bone flags
  1878. int startFrame; //base pose start
  1879. int endFrame; //base pose end
  1880. } sharedSetBoneIKStateParams_t;
  1881. enum sharedEIKMoveState
  1882. {
  1883. IKS_NONE = 0,
  1884. IKS_DYNAMIC
  1885. };
  1886. /*
  1887. ========================================================================
  1888. String ID Tables
  1889. ========================================================================
  1890. */
  1891. typedef struct stringID_table_s
  1892. {
  1893. char *name;
  1894. int id;
  1895. } stringID_table_t;
  1896. int GetIDForString ( const stringID_table_t *table, const char *string );
  1897. const char *GetStringForID( const stringID_table_t *table, int id );
  1898. // savegame screenshot size stuff...
  1899. //
  1900. //#define SG_SCR_WIDTH 512 //256
  1901. //#define SG_SCR_HEIGHT 512 //256
  1902. #define iSG_COMMENT_SIZE 64
  1903. #define sCVARNAME_PLAYERSAVE "playersave" // used for level-transition, accessed by game and server modules
  1904. /*
  1905. Ghoul2 Insert Start
  1906. */
  1907. // For ghoul2 axis use
  1908. enum Eorientations
  1909. {
  1910. ORIGIN = 0,
  1911. POSITIVE_X,
  1912. POSITIVE_Z,
  1913. POSITIVE_Y,
  1914. NEGATIVE_X,
  1915. NEGATIVE_Z,
  1916. NEGATIVE_Y
  1917. };
  1918. /*
  1919. Ghoul2 Insert End
  1920. */
  1921. #define MAX_PARSEFILES 16
  1922. typedef struct parseData_s
  1923. {
  1924. char fileName[MAX_QPATH]; // Name of current file being read in
  1925. int com_lines; // Number of lines read in
  1926. const char *bufferStart; // Start address of buffer holding data that was read in
  1927. const char *bufferCurrent; // Where data is currently being parsed from buffer
  1928. } parseData_t;
  1929. //JFLCALLOUT include
  1930. //changed to array
  1931. extern parseData_t parseData[];
  1932. extern int parseDataCount;
  1933. // cinematic states
  1934. typedef enum {
  1935. FMV_IDLE,
  1936. FMV_PLAY, // play
  1937. FMV_EOF, // all other conditions, i.e. stop/EOF/abort
  1938. FMV_ID_BLT,
  1939. FMV_ID_IDLE,
  1940. FMV_LOOPED,
  1941. FMV_ID_WAIT
  1942. } e_status;
  1943. // define the new memory tags for the zone, used by all modules now
  1944. //
  1945. #define TAGDEF(blah) TAG_ ## blah
  1946. enum {
  1947. #include "../qcommon/tags.h"
  1948. };
  1949. typedef char memtag_t;
  1950. // stuff to help out during development process, force reloading/uncacheing of certain filetypes...
  1951. //
  1952. typedef enum
  1953. {
  1954. eForceReload_NOTHING,
  1955. eForceReload_BSP,
  1956. eForceReload_MODELS,
  1957. eForceReload_ALL
  1958. } ForceReload_e;
  1959. #include "../game/genericparser2.h"
  1960. #ifdef _IMMERSION
  1961. #include "../ff/ff_public.h"
  1962. #endif // _IMMERSION
  1963. #endif // __Q_SHARED_H