Quake-2

Quake 2 GPL Source Release
Log | Files | Refs

qcommon.h (23346B)


      1 /*
      2 Copyright (C) 1997-2001 Id Software, Inc.
      3 
      4 This program is free software; you can redistribute it and/or
      5 modify it under the terms of the GNU General Public License
      6 as published by the Free Software Foundation; either version 2
      7 of the License, or (at your option) any later version.
      8 
      9 This program is distributed in the hope that it will be useful,
     10 but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
     12 
     13 See the GNU General Public License for more details.
     14 
     15 You should have received a copy of the GNU General Public License
     16 along with this program; if not, write to the Free Software
     17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     18 
     19 */
     20 
     21 // qcommon.h -- definitions common between client and server, but not game.dll
     22 
     23 #include "../game/q_shared.h"
     24 
     25 
     26 #define	VERSION		3.19
     27 
     28 #define	BASEDIRNAME	"baseq2"
     29 
     30 #ifdef WIN32
     31 
     32 #ifdef NDEBUG
     33 #define BUILDSTRING "Win32 RELEASE"
     34 #else
     35 #define BUILDSTRING "Win32 DEBUG"
     36 #endif
     37 
     38 #ifdef _M_IX86
     39 #define	CPUSTRING	"x86"
     40 #elif defined _M_ALPHA
     41 #define	CPUSTRING	"AXP"
     42 #endif
     43 
     44 #elif defined __linux__
     45 
     46 #define BUILDSTRING "Linux"
     47 
     48 #ifdef __i386__
     49 #define CPUSTRING "i386"
     50 #elif defined __alpha__
     51 #define CPUSTRING "axp"
     52 #else
     53 #define CPUSTRING "Unknown"
     54 #endif
     55 
     56 #elif defined __sun__
     57 
     58 #define BUILDSTRING "Solaris"
     59 
     60 #ifdef __i386__
     61 #define CPUSTRING "i386"
     62 #else
     63 #define CPUSTRING "sparc"
     64 #endif
     65 
     66 #else	// !WIN32
     67 
     68 #define BUILDSTRING "NON-WIN32"
     69 #define	CPUSTRING	"NON-WIN32"
     70 
     71 #endif
     72 
     73 //============================================================================
     74 
     75 typedef struct sizebuf_s
     76 {
     77 	qboolean	allowoverflow;	// if false, do a Com_Error
     78 	qboolean	overflowed;		// set to true if the buffer size failed
     79 	byte	*data;
     80 	int		maxsize;
     81 	int		cursize;
     82 	int		readcount;
     83 } sizebuf_t;
     84 
     85 void SZ_Init (sizebuf_t *buf, byte *data, int length);
     86 void SZ_Clear (sizebuf_t *buf);
     87 void *SZ_GetSpace (sizebuf_t *buf, int length);
     88 void SZ_Write (sizebuf_t *buf, void *data, int length);
     89 void SZ_Print (sizebuf_t *buf, char *data);	// strcats onto the sizebuf
     90 
     91 //============================================================================
     92 
     93 struct usercmd_s;
     94 struct entity_state_s;
     95 
     96 void MSG_WriteChar (sizebuf_t *sb, int c);
     97 void MSG_WriteByte (sizebuf_t *sb, int c);
     98 void MSG_WriteShort (sizebuf_t *sb, int c);
     99 void MSG_WriteLong (sizebuf_t *sb, int c);
    100 void MSG_WriteFloat (sizebuf_t *sb, float f);
    101 void MSG_WriteString (sizebuf_t *sb, char *s);
    102 void MSG_WriteCoord (sizebuf_t *sb, float f);
    103 void MSG_WritePos (sizebuf_t *sb, vec3_t pos);
    104 void MSG_WriteAngle (sizebuf_t *sb, float f);
    105 void MSG_WriteAngle16 (sizebuf_t *sb, float f);
    106 void MSG_WriteDeltaUsercmd (sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd);
    107 void MSG_WriteDeltaEntity (struct entity_state_s *from, struct entity_state_s *to, sizebuf_t *msg, qboolean force, qboolean newentity);
    108 void MSG_WriteDir (sizebuf_t *sb, vec3_t vector);
    109 
    110 
    111 void	MSG_BeginReading (sizebuf_t *sb);
    112 
    113 int		MSG_ReadChar (sizebuf_t *sb);
    114 int		MSG_ReadByte (sizebuf_t *sb);
    115 int		MSG_ReadShort (sizebuf_t *sb);
    116 int		MSG_ReadLong (sizebuf_t *sb);
    117 float	MSG_ReadFloat (sizebuf_t *sb);
    118 char	*MSG_ReadString (sizebuf_t *sb);
    119 char	*MSG_ReadStringLine (sizebuf_t *sb);
    120 
    121 float	MSG_ReadCoord (sizebuf_t *sb);
    122 void	MSG_ReadPos (sizebuf_t *sb, vec3_t pos);
    123 float	MSG_ReadAngle (sizebuf_t *sb);
    124 float	MSG_ReadAngle16 (sizebuf_t *sb);
    125 void	MSG_ReadDeltaUsercmd (sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd);
    126 
    127 void	MSG_ReadDir (sizebuf_t *sb, vec3_t vector);
    128 
    129 void	MSG_ReadData (sizebuf_t *sb, void *buffer, int size);
    130 
    131 //============================================================================
    132 
    133 extern	qboolean		bigendien;
    134 
    135 extern	short	BigShort (short l);
    136 extern	short	LittleShort (short l);
    137 extern	int		BigLong (int l);
    138 extern	int		LittleLong (int l);
    139 extern	float	BigFloat (float l);
    140 extern	float	LittleFloat (float l);
    141 
    142 //============================================================================
    143 
    144 
    145 int	COM_Argc (void);
    146 char *COM_Argv (int arg);	// range and null checked
    147 void COM_ClearArgv (int arg);
    148 int COM_CheckParm (char *parm);
    149 void COM_AddParm (char *parm);
    150 
    151 void COM_Init (void);
    152 void COM_InitArgv (int argc, char **argv);
    153 
    154 char *CopyString (char *in);
    155 
    156 //============================================================================
    157 
    158 void Info_Print (char *s);
    159 
    160 
    161 /* crc.h */
    162 
    163 void CRC_Init(unsigned short *crcvalue);
    164 void CRC_ProcessByte(unsigned short *crcvalue, byte data);
    165 unsigned short CRC_Value(unsigned short crcvalue);
    166 unsigned short CRC_Block (byte *start, int count);
    167 
    168 
    169 
    170 /*
    171 ==============================================================
    172 
    173 PROTOCOL
    174 
    175 ==============================================================
    176 */
    177 
    178 // protocol.h -- communications protocols
    179 
    180 #define	PROTOCOL_VERSION	34
    181 
    182 //=========================================
    183 
    184 #define	PORT_MASTER	27900
    185 #define	PORT_CLIENT	27901
    186 #define	PORT_SERVER	27910
    187 
    188 //=========================================
    189 
    190 #define	UPDATE_BACKUP	16	// copies of entity_state_t to keep buffered
    191 							// must be power of two
    192 #define	UPDATE_MASK		(UPDATE_BACKUP-1)
    193 
    194 
    195 
    196 //==================
    197 // the svc_strings[] array in cl_parse.c should mirror this
    198 //==================
    199 
    200 //
    201 // server to client
    202 //
    203 enum svc_ops_e
    204 {
    205 	svc_bad,
    206 
    207 	// these ops are known to the game dll
    208 	svc_muzzleflash,
    209 	svc_muzzleflash2,
    210 	svc_temp_entity,
    211 	svc_layout,
    212 	svc_inventory,
    213 
    214 	// the rest are private to the client and server
    215 	svc_nop,
    216 	svc_disconnect,
    217 	svc_reconnect,
    218 	svc_sound,					// <see code>
    219 	svc_print,					// [byte] id [string] null terminated string
    220 	svc_stufftext,				// [string] stuffed into client's console buffer, should be \n terminated
    221 	svc_serverdata,				// [long] protocol ...
    222 	svc_configstring,			// [short] [string]
    223 	svc_spawnbaseline,		
    224 	svc_centerprint,			// [string] to put in center of the screen
    225 	svc_download,				// [short] size [size bytes]
    226 	svc_playerinfo,				// variable
    227 	svc_packetentities,			// [...]
    228 	svc_deltapacketentities,	// [...]
    229 	svc_frame
    230 };
    231 
    232 //==============================================
    233 
    234 //
    235 // client to server
    236 //
    237 enum clc_ops_e
    238 {
    239 	clc_bad,
    240 	clc_nop, 		
    241 	clc_move,				// [[usercmd_t]
    242 	clc_userinfo,			// [[userinfo string]
    243 	clc_stringcmd			// [string] message
    244 };
    245 
    246 //==============================================
    247 
    248 // plyer_state_t communication
    249 
    250 #define	PS_M_TYPE			(1<<0)
    251 #define	PS_M_ORIGIN			(1<<1)
    252 #define	PS_M_VELOCITY		(1<<2)
    253 #define	PS_M_TIME			(1<<3)
    254 #define	PS_M_FLAGS			(1<<4)
    255 #define	PS_M_GRAVITY		(1<<5)
    256 #define	PS_M_DELTA_ANGLES	(1<<6)
    257 
    258 #define	PS_VIEWOFFSET		(1<<7)
    259 #define	PS_VIEWANGLES		(1<<8)
    260 #define	PS_KICKANGLES		(1<<9)
    261 #define	PS_BLEND			(1<<10)
    262 #define	PS_FOV				(1<<11)
    263 #define	PS_WEAPONINDEX		(1<<12)
    264 #define	PS_WEAPONFRAME		(1<<13)
    265 #define	PS_RDFLAGS			(1<<14)
    266 
    267 //==============================================
    268 
    269 // user_cmd_t communication
    270 
    271 // ms and light always sent, the others are optional
    272 #define	CM_ANGLE1 	(1<<0)
    273 #define	CM_ANGLE2 	(1<<1)
    274 #define	CM_ANGLE3 	(1<<2)
    275 #define	CM_FORWARD	(1<<3)
    276 #define	CM_SIDE		(1<<4)
    277 #define	CM_UP		(1<<5)
    278 #define	CM_BUTTONS	(1<<6)
    279 #define	CM_IMPULSE	(1<<7)
    280 
    281 //==============================================
    282 
    283 // a sound without an ent or pos will be a local only sound
    284 #define	SND_VOLUME		(1<<0)		// a byte
    285 #define	SND_ATTENUATION	(1<<1)		// a byte
    286 #define	SND_POS			(1<<2)		// three coordinates
    287 #define	SND_ENT			(1<<3)		// a short 0-2: channel, 3-12: entity
    288 #define	SND_OFFSET		(1<<4)		// a byte, msec offset from frame start
    289 
    290 #define DEFAULT_SOUND_PACKET_VOLUME	1.0
    291 #define DEFAULT_SOUND_PACKET_ATTENUATION 1.0
    292 
    293 //==============================================
    294 
    295 // entity_state_t communication
    296 
    297 // try to pack the common update flags into the first byte
    298 #define	U_ORIGIN1	(1<<0)
    299 #define	U_ORIGIN2	(1<<1)
    300 #define	U_ANGLE2	(1<<2)
    301 #define	U_ANGLE3	(1<<3)
    302 #define	U_FRAME8	(1<<4)		// frame is a byte
    303 #define	U_EVENT		(1<<5)
    304 #define	U_REMOVE	(1<<6)		// REMOVE this entity, don't add it
    305 #define	U_MOREBITS1	(1<<7)		// read one additional byte
    306 
    307 // second byte
    308 #define	U_NUMBER16	(1<<8)		// NUMBER8 is implicit if not set
    309 #define	U_ORIGIN3	(1<<9)
    310 #define	U_ANGLE1	(1<<10)
    311 #define	U_MODEL		(1<<11)
    312 #define U_RENDERFX8	(1<<12)		// fullbright, etc
    313 #define	U_EFFECTS8	(1<<14)		// autorotate, trails, etc
    314 #define	U_MOREBITS2	(1<<15)		// read one additional byte
    315 
    316 // third byte
    317 #define	U_SKIN8		(1<<16)
    318 #define	U_FRAME16	(1<<17)		// frame is a short
    319 #define	U_RENDERFX16 (1<<18)	// 8 + 16 = 32
    320 #define	U_EFFECTS16	(1<<19)		// 8 + 16 = 32
    321 #define	U_MODEL2	(1<<20)		// weapons, flags, etc
    322 #define	U_MODEL3	(1<<21)
    323 #define	U_MODEL4	(1<<22)
    324 #define	U_MOREBITS3	(1<<23)		// read one additional byte
    325 
    326 // fourth byte
    327 #define	U_OLDORIGIN	(1<<24)		// FIXME: get rid of this
    328 #define	U_SKIN16	(1<<25)
    329 #define	U_SOUND		(1<<26)
    330 #define	U_SOLID		(1<<27)
    331 
    332 
    333 /*
    334 ==============================================================
    335 
    336 CMD
    337 
    338 Command text buffering and command execution
    339 
    340 ==============================================================
    341 */
    342 
    343 /*
    344 
    345 Any number of commands can be added in a frame, from several different sources.
    346 Most commands come from either keybindings or console line input, but remote
    347 servers can also send across commands and entire text files can be execed.
    348 
    349 The + command line options are also added to the command buffer.
    350 
    351 The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute ();
    352 
    353 */
    354 
    355 #define	EXEC_NOW	0		// don't return until completed
    356 #define	EXEC_INSERT	1		// insert at current position, but don't run yet
    357 #define	EXEC_APPEND	2		// add to end of the command buffer
    358 
    359 void Cbuf_Init (void);
    360 // allocates an initial text buffer that will grow as needed
    361 
    362 void Cbuf_AddText (char *text);
    363 // as new commands are generated from the console or keybindings,
    364 // the text is added to the end of the command buffer.
    365 
    366 void Cbuf_InsertText (char *text);
    367 // when a command wants to issue other commands immediately, the text is
    368 // inserted at the beginning of the buffer, before any remaining unexecuted
    369 // commands.
    370 
    371 void Cbuf_ExecuteText (int exec_when, char *text);
    372 // this can be used in place of either Cbuf_AddText or Cbuf_InsertText
    373 
    374 void Cbuf_AddEarlyCommands (qboolean clear);
    375 // adds all the +set commands from the command line
    376 
    377 qboolean Cbuf_AddLateCommands (void);
    378 // adds all the remaining + commands from the command line
    379 // Returns true if any late commands were added, which
    380 // will keep the demoloop from immediately starting
    381 
    382 void Cbuf_Execute (void);
    383 // Pulls off \n terminated lines of text from the command buffer and sends
    384 // them through Cmd_ExecuteString.  Stops when the buffer is empty.
    385 // Normally called once per frame, but may be explicitly invoked.
    386 // Do not call inside a command function!
    387 
    388 void Cbuf_CopyToDefer (void);
    389 void Cbuf_InsertFromDefer (void);
    390 // These two functions are used to defer any pending commands while a map
    391 // is being loaded
    392 
    393 //===========================================================================
    394 
    395 /*
    396 
    397 Command execution takes a null terminated string, breaks it into tokens,
    398 then searches for a command or variable that matches the first token.
    399 
    400 */
    401 
    402 typedef void (*xcommand_t) (void);
    403 
    404 void	Cmd_Init (void);
    405 
    406 void	Cmd_AddCommand (char *cmd_name, xcommand_t function);
    407 // called by the init functions of other parts of the program to
    408 // register commands and functions to call for them.
    409 // The cmd_name is referenced later, so it should not be in temp memory
    410 // if function is NULL, the command will be forwarded to the server
    411 // as a clc_stringcmd instead of executed locally
    412 void	Cmd_RemoveCommand (char *cmd_name);
    413 
    414 qboolean Cmd_Exists (char *cmd_name);
    415 // used by the cvar code to check for cvar / command name overlap
    416 
    417 char 	*Cmd_CompleteCommand (char *partial);
    418 // attempts to match a partial command for automatic command line completion
    419 // returns NULL if nothing fits
    420 
    421 int		Cmd_Argc (void);
    422 char	*Cmd_Argv (int arg);
    423 char	*Cmd_Args (void);
    424 // The functions that execute commands get their parameters with these
    425 // functions. Cmd_Argv () will return an empty string, not a NULL
    426 // if arg > argc, so string operations are always safe.
    427 
    428 void	Cmd_TokenizeString (char *text, qboolean macroExpand);
    429 // Takes a null terminated string.  Does not need to be /n terminated.
    430 // breaks the string up into arg tokens.
    431 
    432 void	Cmd_ExecuteString (char *text);
    433 // Parses a single line of text into arguments and tries to execute it
    434 // as if it was typed at the console
    435 
    436 void	Cmd_ForwardToServer (void);
    437 // adds the current command line as a clc_stringcmd to the client message.
    438 // things like godmode, noclip, etc, are commands directed to the server,
    439 // so when they are typed in at the console, they will need to be forwarded.
    440 
    441 
    442 /*
    443 ==============================================================
    444 
    445 CVAR
    446 
    447 ==============================================================
    448 */
    449 
    450 /*
    451 
    452 cvar_t variables are used to hold scalar or string variables that can be changed or displayed at the console or prog code as well as accessed directly
    453 in C code.
    454 
    455 The user can access cvars from the console in three ways:
    456 r_draworder			prints the current value
    457 r_draworder 0		sets the current value to 0
    458 set r_draworder 0	as above, but creates the cvar if not present
    459 Cvars are restricted from having the same names as commands to keep this
    460 interface from being ambiguous.
    461 */
    462 
    463 extern	cvar_t	*cvar_vars;
    464 
    465 cvar_t *Cvar_Get (char *var_name, char *value, int flags);
    466 // creates the variable if it doesn't exist, or returns the existing one
    467 // if it exists, the value will not be changed, but flags will be ORed in
    468 // that allows variables to be unarchived without needing bitflags
    469 
    470 cvar_t 	*Cvar_Set (char *var_name, char *value);
    471 // will create the variable if it doesn't exist
    472 
    473 cvar_t *Cvar_ForceSet (char *var_name, char *value);
    474 // will set the variable even if NOSET or LATCH
    475 
    476 cvar_t 	*Cvar_FullSet (char *var_name, char *value, int flags);
    477 
    478 void	Cvar_SetValue (char *var_name, float value);
    479 // expands value to a string and calls Cvar_Set
    480 
    481 float	Cvar_VariableValue (char *var_name);
    482 // returns 0 if not defined or non numeric
    483 
    484 char	*Cvar_VariableString (char *var_name);
    485 // returns an empty string if not defined
    486 
    487 char 	*Cvar_CompleteVariable (char *partial);
    488 // attempts to match a partial variable name for command line completion
    489 // returns NULL if nothing fits
    490 
    491 void	Cvar_GetLatchedVars (void);
    492 // any CVAR_LATCHED variables that have been set will now take effect
    493 
    494 qboolean Cvar_Command (void);
    495 // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
    496 // command.  Returns true if the command was a variable reference that
    497 // was handled. (print or change)
    498 
    499 void 	Cvar_WriteVariables (char *path);
    500 // appends lines containing "set variable value" for all variables
    501 // with the archive flag set to true.
    502 
    503 void	Cvar_Init (void);
    504 
    505 char	*Cvar_Userinfo (void);
    506 // returns an info string containing all the CVAR_USERINFO cvars
    507 
    508 char	*Cvar_Serverinfo (void);
    509 // returns an info string containing all the CVAR_SERVERINFO cvars
    510 
    511 extern	qboolean	userinfo_modified;
    512 // this is set each time a CVAR_USERINFO variable is changed
    513 // so that the client knows to send it to the server
    514 
    515 /*
    516 ==============================================================
    517 
    518 NET
    519 
    520 ==============================================================
    521 */
    522 
    523 // net.h -- quake's interface to the networking layer
    524 
    525 #define	PORT_ANY	-1
    526 
    527 #define	MAX_MSGLEN		1400		// max length of a message
    528 #define	PACKET_HEADER	10			// two ints and a short
    529 
    530 typedef enum {NA_LOOPBACK, NA_BROADCAST, NA_IP, NA_IPX, NA_BROADCAST_IPX} netadrtype_t;
    531 
    532 typedef enum {NS_CLIENT, NS_SERVER} netsrc_t;
    533 
    534 typedef struct
    535 {
    536 	netadrtype_t	type;
    537 
    538 	byte	ip[4];
    539 	byte	ipx[10];
    540 
    541 	unsigned short	port;
    542 } netadr_t;
    543 
    544 void		NET_Init (void);
    545 void		NET_Shutdown (void);
    546 
    547 void		NET_Config (qboolean multiplayer);
    548 
    549 qboolean	NET_GetPacket (netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message);
    550 void		NET_SendPacket (netsrc_t sock, int length, void *data, netadr_t to);
    551 
    552 qboolean	NET_CompareAdr (netadr_t a, netadr_t b);
    553 qboolean	NET_CompareBaseAdr (netadr_t a, netadr_t b);
    554 qboolean	NET_IsLocalAddress (netadr_t adr);
    555 char		*NET_AdrToString (netadr_t a);
    556 qboolean	NET_StringToAdr (char *s, netadr_t *a);
    557 void		NET_Sleep(int msec);
    558 
    559 //============================================================================
    560 
    561 #define	OLD_AVG		0.99		// total = oldtotal*OLD_AVG + new*(1-OLD_AVG)
    562 
    563 #define	MAX_LATENT	32
    564 
    565 typedef struct
    566 {
    567 	qboolean	fatal_error;
    568 
    569 	netsrc_t	sock;
    570 
    571 	int			dropped;			// between last packet and previous
    572 
    573 	int			last_received;		// for timeouts
    574 	int			last_sent;			// for retransmits
    575 
    576 	netadr_t	remote_address;
    577 	int			qport;				// qport value to write when transmitting
    578 
    579 // sequencing variables
    580 	int			incoming_sequence;
    581 	int			incoming_acknowledged;
    582 	int			incoming_reliable_acknowledged;	// single bit
    583 
    584 	int			incoming_reliable_sequence;		// single bit, maintained local
    585 
    586 	int			outgoing_sequence;
    587 	int			reliable_sequence;			// single bit
    588 	int			last_reliable_sequence;		// sequence number of last send
    589 
    590 // reliable staging and holding areas
    591 	sizebuf_t	message;		// writing buffer to send to server
    592 	byte		message_buf[MAX_MSGLEN-16];		// leave space for header
    593 
    594 // message is copied to this buffer when it is first transfered
    595 	int			reliable_length;
    596 	byte		reliable_buf[MAX_MSGLEN-16];	// unacked reliable message
    597 } netchan_t;
    598 
    599 extern	netadr_t	net_from;
    600 extern	sizebuf_t	net_message;
    601 extern	byte		net_message_buffer[MAX_MSGLEN];
    602 
    603 
    604 void Netchan_Init (void);
    605 void Netchan_Setup (netsrc_t sock, netchan_t *chan, netadr_t adr, int qport);
    606 
    607 qboolean Netchan_NeedReliable (netchan_t *chan);
    608 void Netchan_Transmit (netchan_t *chan, int length, byte *data);
    609 void Netchan_OutOfBand (int net_socket, netadr_t adr, int length, byte *data);
    610 void Netchan_OutOfBandPrint (int net_socket, netadr_t adr, char *format, ...);
    611 qboolean Netchan_Process (netchan_t *chan, sizebuf_t *msg);
    612 
    613 qboolean Netchan_CanReliable (netchan_t *chan);
    614 
    615 
    616 /*
    617 ==============================================================
    618 
    619 CMODEL
    620 
    621 ==============================================================
    622 */
    623 
    624 
    625 #include "../qcommon/qfiles.h"
    626 
    627 cmodel_t	*CM_LoadMap (char *name, qboolean clientload, unsigned *checksum);
    628 cmodel_t	*CM_InlineModel (char *name);	// *1, *2, etc
    629 
    630 int			CM_NumClusters (void);
    631 int			CM_NumInlineModels (void);
    632 char		*CM_EntityString (void);
    633 
    634 // creates a clipping hull for an arbitrary box
    635 int			CM_HeadnodeForBox (vec3_t mins, vec3_t maxs);
    636 
    637 
    638 // returns an ORed contents mask
    639 int			CM_PointContents (vec3_t p, int headnode);
    640 int			CM_TransformedPointContents (vec3_t p, int headnode, vec3_t origin, vec3_t angles);
    641 
    642 trace_t		CM_BoxTrace (vec3_t start, vec3_t end,
    643 						  vec3_t mins, vec3_t maxs,
    644 						  int headnode, int brushmask);
    645 trace_t		CM_TransformedBoxTrace (vec3_t start, vec3_t end,
    646 						  vec3_t mins, vec3_t maxs,
    647 						  int headnode, int brushmask,
    648 						  vec3_t origin, vec3_t angles);
    649 
    650 byte		*CM_ClusterPVS (int cluster);
    651 byte		*CM_ClusterPHS (int cluster);
    652 
    653 int			CM_PointLeafnum (vec3_t p);
    654 
    655 // call with topnode set to the headnode, returns with topnode
    656 // set to the first node that splits the box
    657 int			CM_BoxLeafnums (vec3_t mins, vec3_t maxs, int *list,
    658 							int listsize, int *topnode);
    659 
    660 int			CM_LeafContents (int leafnum);
    661 int			CM_LeafCluster (int leafnum);
    662 int			CM_LeafArea (int leafnum);
    663 
    664 void		CM_SetAreaPortalState (int portalnum, qboolean open);
    665 qboolean	CM_AreasConnected (int area1, int area2);
    666 
    667 int			CM_WriteAreaBits (byte *buffer, int area);
    668 qboolean	CM_HeadnodeVisible (int headnode, byte *visbits);
    669 
    670 void		CM_WritePortalState (FILE *f);
    671 void		CM_ReadPortalState (FILE *f);
    672 
    673 /*
    674 ==============================================================
    675 
    676 PLAYER MOVEMENT CODE
    677 
    678 Common between server and client so prediction matches
    679 
    680 ==============================================================
    681 */
    682 
    683 extern float pm_airaccelerate;
    684 
    685 void Pmove (pmove_t *pmove);
    686 
    687 /*
    688 ==============================================================
    689 
    690 FILESYSTEM
    691 
    692 ==============================================================
    693 */
    694 
    695 void	FS_InitFilesystem (void);
    696 void	FS_SetGamedir (char *dir);
    697 char	*FS_Gamedir (void);
    698 char	*FS_NextPath (char *prevpath);
    699 void	FS_ExecAutoexec (void);
    700 
    701 int		FS_FOpenFile (char *filename, FILE **file);
    702 void	FS_FCloseFile (FILE *f);
    703 // note: this can't be called from another DLL, due to MS libc issues
    704 
    705 int		FS_LoadFile (char *path, void **buffer);
    706 // a null buffer will just return the file length without loading
    707 // a -1 length is not present
    708 
    709 void	FS_Read (void *buffer, int len, FILE *f);
    710 // properly handles partial reads
    711 
    712 void	FS_FreeFile (void *buffer);
    713 
    714 void	FS_CreatePath (char *path);
    715 
    716 
    717 /*
    718 ==============================================================
    719 
    720 MISC
    721 
    722 ==============================================================
    723 */
    724 
    725 
    726 #define	ERR_FATAL	0		// exit the entire game with a popup window
    727 #define	ERR_DROP	1		// print to console and disconnect from game
    728 #define	ERR_QUIT	2		// not an error, just a normal exit
    729 
    730 #define	EXEC_NOW	0		// don't return until completed
    731 #define	EXEC_INSERT	1		// insert at current position, but don't run yet
    732 #define	EXEC_APPEND	2		// add to end of the command buffer
    733 
    734 #define	PRINT_ALL		0
    735 #define PRINT_DEVELOPER	1	// only print when "developer 1"
    736 
    737 void		Com_BeginRedirect (int target, char *buffer, int buffersize, void (*flush));
    738 void		Com_EndRedirect (void);
    739 void 		Com_Printf (char *fmt, ...);
    740 void 		Com_DPrintf (char *fmt, ...);
    741 void 		Com_Error (int code, char *fmt, ...);
    742 void 		Com_Quit (void);
    743 
    744 int			Com_ServerState (void);		// this should have just been a cvar...
    745 void		Com_SetServerState (int state);
    746 
    747 unsigned	Com_BlockChecksum (void *buffer, int length);
    748 byte		COM_BlockSequenceCRCByte (byte *base, int length, int sequence);
    749 
    750 float	frand(void);	// 0 ti 1
    751 float	crand(void);	// -1 to 1
    752 
    753 extern	cvar_t	*developer;
    754 extern	cvar_t	*dedicated;
    755 extern	cvar_t	*host_speeds;
    756 extern	cvar_t	*log_stats;
    757 
    758 extern	FILE *log_stats_file;
    759 
    760 // host_speeds times
    761 extern	int		time_before_game;
    762 extern	int		time_after_game;
    763 extern	int		time_before_ref;
    764 extern	int		time_after_ref;
    765 
    766 void Z_Free (void *ptr);
    767 void *Z_Malloc (int size);			// returns 0 filled memory
    768 void *Z_TagMalloc (int size, int tag);
    769 void Z_FreeTags (int tag);
    770 
    771 void Qcommon_Init (int argc, char **argv);
    772 void Qcommon_Frame (int msec);
    773 void Qcommon_Shutdown (void);
    774 
    775 #define NUMVERTEXNORMALS	162
    776 extern	vec3_t	bytedirs[NUMVERTEXNORMALS];
    777 
    778 // this is in the client code, but can be used for debugging from server
    779 void SCR_DebugGraph (float value, int color);
    780 
    781 
    782 /*
    783 ==============================================================
    784 
    785 NON-PORTABLE SYSTEM SERVICES
    786 
    787 ==============================================================
    788 */
    789 
    790 void	Sys_Init (void);
    791 
    792 void	Sys_AppActivate (void);
    793 
    794 void	Sys_UnloadGame (void);
    795 void	*Sys_GetGameAPI (void *parms);
    796 // loads the game dll and calls the api init function
    797 
    798 char	*Sys_ConsoleInput (void);
    799 void	Sys_ConsoleOutput (char *string);
    800 void	Sys_SendKeyEvents (void);
    801 void	Sys_Error (char *error, ...);
    802 void	Sys_Quit (void);
    803 char	*Sys_GetClipboardData( void );
    804 void	Sys_CopyProtect (void);
    805 
    806 /*
    807 ==============================================================
    808 
    809 CLIENT / SERVER SYSTEMS
    810 
    811 ==============================================================
    812 */
    813 
    814 void CL_Init (void);
    815 void CL_Drop (void);
    816 void CL_Shutdown (void);
    817 void CL_Frame (int msec);
    818 void Con_Print (char *text);
    819 void SCR_BeginLoadingPlaque (void);
    820 
    821 void SV_Init (void);
    822 void SV_Shutdown (char *finalmsg, qboolean reconnect);
    823 void SV_Frame (int msec);
    824 
    825 
    826