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