1 // g_local.h -- local definitions for game module
2 
3 #include "q_shared.h"
4 
5 // define GAME_INCLUDE so that game.h does not define the
6 // short, server-visible gclient_t and edict_t structures,
7 // because we define the full size ones in this file
8 #define	GAME_INCLUDE
9 #include "game.h"
10 
11 #ifdef GAME_MOD
12 #include "b_coopcam.h"
13 #endif
14 
15 // some custom defines
16 #ifdef Z_MAX
17 #undef Z_MAX
18 #endif // Z_MAX
19 #define Z_MAX(a,b)	((a) > (b) ? (a) : (b))
20 
21 #ifdef Z_MIN
22 #undef Z_MIN
23 #endif // Z_MIN
24 #define Z_MIN(a,b)	((a) < (b) ? (a) : (b))
25 
26 #define Z_MALLOC(size)	gi.TagMalloc(size, TAG_GAME)
27 #define Z_FREE(block)	gi.TagFree(block)
28 
29 // Zaero includes
30 #include "z_debug.h"
31 #ifdef CACHE_SOUND
32 #include "z_list.h"
33 #endif
34 
35 // the "gamename" client command will print this plus compile date
36 #define	GAMEVERSION	"Zaero 1.1"
37 
38 // protocol bytes that can be directly added to messages
39 #define	svc_muzzleflash		1
40 #define	svc_muzzleflash2	2
41 #define	svc_temp_entity		3
42 #define	svc_layout			4
43 #define	svc_inventory		5
44 
45 //==================================================================
46 
47 // view pitching times
48 #define DAMAGE_TIME		0.5
49 #define	FALL_TIME		0.3
50 
51 
52 // edict->spawnflags
53 // these are set with checkboxes on each entity in the map editor
54 #define	SPAWNFLAG_NOT_EASY			0x00000100
55 #define	SPAWNFLAG_NOT_MEDIUM		0x00000200
56 #define	SPAWNFLAG_NOT_HARD			0x00000400
57 #define	SPAWNFLAG_NOT_DEATHMATCH	0x00000800
58 #define	SPAWNFLAG_NOT_COOP			0x00001000
59 
60 // edict->spawnflags2
61 // these are set with checkboxes on each entity in the map editor
62 #define	SPAWNFLAG2_MIRRORLEVEL  0x0001
63 #define	SPAWNFLAG2_NOT_COOP			0x0002
64 #define SPAWNFLAG2_NOT_SINGLE   0x0004
65 
66 // edict->flags
67 #define	FL_FLY					0x00000001
68 #define	FL_SWIM					0x00000002	// implied immunity to drowining
69 #define FL_IMMUNE_LASER			0x00000004
70 #define	FL_INWATER				0x00000008
71 #define	FL_GODMODE				0x00000010
72 #define	FL_NOTARGET				0x00000020
73 #define FL_IMMUNE_SLIME			0x00000040
74 #define FL_IMMUNE_LAVA			0x00000080
75 #define	FL_PARTIALGROUND		0x00000100	// not all corners are valid
76 #define	FL_WATERJUMP			0x00000200	// player jumping out of water
77 #define	FL_TEAMSLAVE			0x00000400	// not the first on the team
78 #define FL_NO_KNOCKBACK				0x00000800
79 #define FL_POWER_ARMOR				0x00001000	// power armor (if any) is active
80 #define FL_DONTSETOLDORIGIN		0x00002000  // Don't set the old_origin for this entity
81 #define FL_BFGMISSFIRE				0x00004000  // BFG Miss Fire
82 #define FL_RESPAWN						0x80000000	// used for item respawning
83 
84 
85 
86 #define	FRAMETIME		0.1
87 
88 // memory tags to allow dynamic memory to be cleaned up
89 #define	TAG_GAME	765		// clear when unloading the dll
90 #define	TAG_LEVEL	766		// clear when loading a new level
91 
92 
93 #define MELEE_DISTANCE	80
94 
95 #define BODY_QUEUE_SIZE		8
96 
97 typedef enum
98 {
99 	DAMAGE_NO,
100 	DAMAGE_YES,			// will take damage if hit
101 	DAMAGE_AIM,			// auto targeting recognizes this
102 	DAMAGE_IMMORTAL		// similar to DAMAGE_YES, but health is not deducted
103 } damage_t;
104 
105 typedef enum
106 {
107 	WEAPON_READY,
108 	WEAPON_ACTIVATING,
109 	WEAPON_DROPPING,
110 	WEAPON_FIRING
111 } weaponstate_t;
112 
113 typedef enum
114 {
115 	AMMO_BULLETS,
116 	AMMO_SHELLS,
117 	AMMO_ROCKETS,
118 	AMMO_FLARES,
119 	AMMO_GRENADES,
120 	AMMO_CELLS,
121 	AMMO_SLUGS,
122 	AMMO_LASERTRIPBOMB,
123 	AMMO_EMPNUKE,
124 	AMMO_A2K,
125 	AMMO_PLASMASHIELD
126 } ammo_t;
127 
128 
129 //deadflag
130 #define DEAD_NO					  0
131 #define DEAD_DYING				1
132 #define DEAD_DEAD				  2
133 #define DEAD_RESPAWNABLE	3
134 
135 //range
136 #define RANGE_MELEE				0
137 #define RANGE_NEAR				1
138 #define RANGE_MID				  2
139 #define RANGE_FAR				  3
140 
141 //gib types
142 #define GIB_ORGANIC				0
143 #define GIB_METALLIC			1
144 
145 //monster ai flags
146 #define AI_STAND_GROUND					0x00000001
147 #define AI_TEMP_STAND_GROUND		0x00000002
148 #define AI_SOUND_TARGET					0x00000004
149 #define AI_LOST_SIGHT						0x00000008
150 #define AI_PURSUIT_LAST_SEEN		0x00000010
151 #define AI_PURSUE_NEXT					0x00000020
152 #define AI_PURSUE_TEMP					0x00000040
153 #define AI_HOLD_FRAME						0x00000080
154 #define AI_GOOD_GUY							0x00000100
155 #define AI_BRUTAL								0x00000200
156 #define AI_NOSTEP								0x00000400
157 #define AI_DUCKED								0x00000800
158 #define AI_COMBAT_POINT					0x00001000
159 #define AI_MEDIC								0x00002000
160 #define AI_RESURRECTING					0x00004000
161 #define AI_SCHOOLING  					0x00008000
162 #define AI_REDUCEDDAMAGE				0x00010000
163 #define AI_SCHOOLINGTURNING			0x00020000
164 #define AI_SCHOOLINGTURNINGFAST 0x00040000
165 #define AI_DODGETIMEOUT					0x00080000
166 #define AI_JUMPING							0x00100000
167 #define AI_MONREDUCEDDAMAGE			0x00200000
168 #define AI_ONESHOTTARGET				0x00400000
169 
170 
171 //monster attack state
172 #define AS_STRAIGHT				1
173 #define AS_SLIDING				2
174 #define	AS_MELEE				  3
175 #define	AS_MISSILE				4
176 #define AS_FLY_STRAFE			5
177 
178 // armor types
179 #define ARMOR_NONE				0
180 #define ARMOR_JACKET			1
181 #define ARMOR_COMBAT			2
182 #define ARMOR_BODY				3
183 #define ARMOR_SHARD				4
184 
185 // power armor types
186 #define POWER_ARMOR_NONE		0
187 #define POWER_ARMOR_SCREEN		1
188 #define POWER_ARMOR_SHIELD		2
189 
190 // handedness values
191 #define RIGHT_HANDED			0
192 #define LEFT_HANDED				1
193 #define CENTER_HANDED			2
194 
195 
196 // game.serverflags values
197 #define SFL_CROSS_TRIGGER_1		0x00000001
198 #define SFL_CROSS_TRIGGER_2		0x00000002
199 #define SFL_CROSS_TRIGGER_3		0x00000004
200 #define SFL_CROSS_TRIGGER_4		0x00000008
201 #define SFL_CROSS_TRIGGER_5		0x00000010
202 #define SFL_CROSS_TRIGGER_6		0x00000020
203 #define SFL_CROSS_TRIGGER_7		0x00000040
204 #define SFL_CROSS_TRIGGER_8		0x00000080
205 #define SFL_CROSS_TRIGGER_MASK	0x000000ff
206 
207 
208 // noise types for PlayerNoise
209 #define PNOISE_SELF				0
210 #define PNOISE_WEAPON			1
211 #define PNOISE_IMPACT			2
212 
213 
214 // edict->movetype values
215 typedef enum
216 {
217 MOVETYPE_NONE,			// never moves
218 MOVETYPE_NOCLIP,		// origin and angles change with no interaction
219 MOVETYPE_PUSH,			// no clip to world, push on box contact
220 MOVETYPE_STOP,			// no clip to world, stops on box contact
221 
222 MOVETYPE_WALK,			// gravity
223 MOVETYPE_STEP,			// gravity, special edge handling
224 MOVETYPE_FLY,
225 MOVETYPE_TOSS,			// gravity
226 MOVETYPE_FLYMISSILE,	// extra size to monsters
227 MOVETYPE_BOUNCE,
228 MOVETYPE_BOUNCEFLY,
229 MOVETYPE_FREEZE,       // player freeze, used for Zaero Camera
230 MOVETYPE_FALLFLOAT,		// falls down slopes and floats in water
231 MOVETYPE_RIDE			// basically won't move unless it rides on a MOVETYPE_PUSH entity
232 } movetype_t;
233 
234 
235 
236 
237 typedef struct
238 {
239 	int		base_count;
240 	int		max_count;
241 	float	normal_protection;
242 	float	energy_protection;
243 	int		armor;
244 } gitem_armor_t;
245 
246 
247 // gitem_t->flags
248 #define	IT_WEAPON		1		// use makes active weapon
249 #define	IT_AMMO			2
250 #define IT_ARMOR		4
251 #define IT_STAY_COOP	8
252 #define IT_KEY			16
253 #define IT_POWERUP		32
254 
255 // hide flags
256 #define HIDE_FROM_INVENTORY	1	// don't list this item in the inventory
257 #define HIDE_DONT_KEEP		2	// don't keep in the lastweapon variable
258 #define HIDE_FROM_SELECTION	4	// don't autoselect or weapnext thru
259 
260 typedef struct gitem_s
261 {
262 	char		*classname;	// spawning name
263 	qboolean	(*pickup)(struct edict_s *ent, struct edict_s *other);
264 	void		(*use)(struct edict_s *ent, struct gitem_s *item);
265 	void		(*drop)(struct edict_s *ent, struct gitem_s *item);
266 	void		(*weaponthink)(struct edict_s *ent);
267 	char		*pickup_sound;
268 	char		*world_model;
269 	int			world_model_flags;
270 	char		*view_model;
271 
272 	// client side info
273 	char		*icon;
274 	char		*pickup_name;	// for printing on pickup
275 	int			count_width;		// number of digits to display by icon
276 
277 	int			quantity;		// for ammo how much, for weapons how much is used per shot
278 	char		*ammo;			// for weapons
279 	int			flags;			// IT_* flags
280 
281 	void		*info;
282 	int			tag;
283 
284 	char		*precaches;		// string of all models, sounds, and images this item will use
285 	int		hideFlags;
286 	char    *weapon;        // weapon used by ammo
287 
288 } gitem_t;
289 
290 
291 
292 //
293 // this structure is left intact through an entire game
294 // it should be initialized at dll load time, and read/written to
295 // the server.ssv file for savegames
296 //
297 typedef struct
298 {
299 	char		helpmessage1[512];
300 	char		helpmessage2[512];
301 	int			helpchanged;	// flash F1 icon if non 0, play sound
302 								// and increment only if 1, 2, or 3
303 
304 	gclient_t	*clients;		// [maxclients]
305 
306 	// can't store spawnpoint in level, because
307 	// it would get overwritten by the savegame restore
308 	char		spawnpoint[512];	// needed for coop respawns
309 
310 	// store latched cvars here that we want to get at often
311 	int			maxclients;
312 	int			maxentities;
313 
314 	// cross level triggers
315 	int			serverflags;
316 
317 	// items
318 	int			num_items;
319 
320 	qboolean	autosaved;
321 } game_locals_t;
322 
323 
324 //
325 // this structure is cleared as each map is entered
326 // it is read/written to the level.sav file for savegames
327 //
328 typedef struct
329 {
330 	int			framenum;
331 	float		time;
332 
333 	char		level_name[MAX_QPATH];	// the descriptive name (Outer Base, etc)
334 	char		mapname[MAX_QPATH];		// the server name (base1, etc)
335 	char		nextmap[MAX_QPATH];		// go here when fraglimit is hit
336 
337 	// intermission state
338 	float		intermissiontime;		// time the intermission was started
339 	char		*changemap;
340 	int			exitintermission;
341 	int			fadeFrames;
342 	vec3_t		intermission_origin;
343 	vec3_t		intermission_angle;
344 
345 	edict_t		*sight_client;	// changed once each frame for coop games
346 
347 	edict_t		*sight_entity;
348 	int			sight_entity_framenum;
349 	edict_t		*sound_entity;
350 	int			sound_entity_framenum;
351 	edict_t		*sound2_entity;
352 	int			sound2_entity_framenum;
353 
354 	int			pic_health;
355 
356 	int			total_secrets;
357 	int			found_secrets;
358 
359 	int			total_goals;
360 	int			found_goals;
361 
362 	int			total_monsters;
363 	int			killed_monsters;
364 
365 	edict_t		*current_entity;	// entity running from G_RunFrame
366 	int			body_que;			// dead bodies
367 
368 	int			power_cubes;		// ugly necessity for coop
369 } level_locals_t;
370 
371 
372 // spawn_temp_t is only used to hold entity field values that
373 // can be set from the editor, but aren't actualy present
374 // in edict_t during gameplay
375 typedef struct
376 {
377 	// world vars
378 	char		*sky;
379 	float		skyrotate;
380 	vec3_t		skyaxis;
381 	char		*nextmap;
382 
383 	int			lip;
384 	int			distance;
385 	int			height;
386 	char		*noise;
387 	float		pausetime;
388 	char		*item;
389 	char		*gravity;
390 
391 	float		minyaw;
392 	float		maxyaw;
393 	float		minpitch;
394 	float		maxpitch;
395 } spawn_temp_t;
396 
397 
398 typedef struct
399 {
400 	// fixed data
401 	vec3_t		start_origin;
402 	vec3_t		start_angles;
403 	vec3_t		end_origin;
404 	vec3_t		end_angles;
405 
406 	int			sound_start;
407 	int			sound_middle;
408 	int			sound_end;
409 
410 	float		accel;
411 	float		speed;
412 	float		decel;
413 	float		distance;
414 
415 	float		wait;
416 
417 	// state data
418 	int			state;
419 	vec3_t		dir;
420 	float		current_speed;
421 	float		move_speed;
422 	float		next_speed;
423 	float		remaining_distance;
424 	float		decel_distance;
425 	void		(*endfunc)(edict_t *);
426 } moveinfo_t;
427 
428 
429 typedef struct
430 {
431 	void	(*aifunc)(edict_t *self, float dist);
432 	float	dist;
433 	void	(*thinkfunc)(edict_t *self);
434 } mframe_t;
435 
436 typedef struct
437 {
438 	int			firstframe;
439 	int			lastframe;
440 	mframe_t	*frame;
441 	void		(*endfunc)(edict_t *self);
442 } mmove_t;
443 
444 typedef struct
445 {
446 	mmove_t		*currentmove;
447 	int			aiflags;
448 	int			nextframe;
449 	float		scale;
450 
451 	void		(*stand)(edict_t *self);
452 	void		(*idle)(edict_t *self);
453 	void		(*search)(edict_t *self);
454 	void		(*walk)(edict_t *self);
455 	void		(*run)(edict_t *self);
456 	void		(*dodge)(edict_t *self, edict_t *other, float eta);
457 	void		(*attack)(edict_t *self);
458 	void		(*melee)(edict_t *self);
459 	void		(*sight)(edict_t *self, edict_t *other);
460 	qboolean	(*checkattack)(edict_t *self);
461 	void		(*backwalk)(edict_t *self);
462 	void		(*sidestepright)(edict_t *self);
463 	void		(*sidestepleft)(edict_t *self);
464 
465 	float		pausetime;
466 	float		attack_finished;
467 
468 	vec3_t		saved_goal;
469 	float		search_time;
470 	float		trail_time;
471 	vec3_t		last_sighting;
472 	int			attack_state;
473 	int			lefty;
474 	float		idle_time;
475 	int			linkcount;
476 
477 	int			power_armor_type;
478 	int			power_armor_power;
479 
480 	int flashTime;
481 	int flashBase;
482 
483 	// strafing
484 	float flyStrafePitch;
485 	float flyStrafeTimeout;
486 
487   //schooling info
488   float zSchoolSightRadius;
489   float zSchoolMaxSpeed, zSchoolMinSpeed;
490   float zSpeedStandMax, zSpeedWalkMax;
491   float zSchoolDecayRate, zSchoolMinimumDistance;
492   int   zSchoolFlags;
493 
494 	float reducedDamageAmount;
495 
496 	float dodgetimeout;
497 
498 	vec3_t shottarget;
499 } monsterinfo_t;
500 
501 
502 
503 extern	game_locals_t	game;
504 extern	level_locals_t	level;
505 extern	game_import_t	gi;
506 extern	game_export_t	globals;
507 extern	spawn_temp_t	st;
508 
509 extern	int	sm_meat_index;
510 extern	int	snd_fry;
511 
512 extern	int	jacket_armor_index;
513 extern	int	combat_armor_index;
514 extern	int	body_armor_index;
515 
516 
517 // means of death
518 #define MOD_UNKNOWN			    0
519 #define MOD_BLASTER			    1
520 #define MOD_SHOTGUN			    2
521 #define MOD_SSHOTGUN		    3
522 #define MOD_MACHINEGUN		  4
523 #define MOD_CHAINGUN		    5
524 #define MOD_GRENADE			    6
525 #define MOD_G_SPLASH		    7
526 #define MOD_ROCKET			    8
527 #define MOD_R_SPLASH		    9
528 #define MOD_HYPERBLASTER	  10
529 #define MOD_RAILGUN			    11
530 #define MOD_BFG_LASER		    12
531 #define MOD_BFG_BLAST		    13
532 #define MOD_BFG_EFFECT		  14
533 #define MOD_HANDGRENADE		  15
534 #define MOD_HG_SPLASH		    16
535 #define MOD_WATER			      17
536 #define MOD_SLIME			      18
537 #define MOD_LAVA			      19
538 #define MOD_CRUSH			      20
539 #define MOD_TELEFRAG		    21
540 #define MOD_FALLING			    22
541 #define MOD_SUICIDE			    23
542 #define MOD_HELD_GRENADE	  24
543 #define MOD_EXPLOSIVE		    25
544 #define MOD_BARREL			    26
545 #define MOD_BOMB			      27
546 #define MOD_EXIT			      28
547 #define MOD_SPLASH			    29
548 #define MOD_TARGET_LASER	  30
549 #define MOD_TRIGGER_HURT	  31
550 #define MOD_HIT				      32
551 #define MOD_TARGET_BLASTER	33
552 #define MOD_SNIPERRIFLE		  34
553 #define MOD_TRIPBOMB		    35
554 #define MOD_FLARE			      36
555 #define MOD_A2K				      37
556 #define MOD_SONICCANNON		  38
557 #define MOD_AUTOCANNON		  39
558 #define MOD_GL_POLYBLEND	40
559 #define MOD_FRIENDLY_FIRE	  0x8000000
560 
561 extern	int	meansOfDeath;
562 
563 
564 extern	edict_t			*g_edicts;
565 
566 #define	FOFS(x) (int)&(((edict_t *)0)->x)
567 #define	STOFS(x) (int)&(((spawn_temp_t *)0)->x)
568 #define	LLOFS(x) (int)&(((level_locals_t *)0)->x)
569 #define	CLOFS(x) (int)&(((gclient_t *)0)->x)
570 
571 #define random()	((rand () & 0x7fff) / ((float)0x7fff))
572 #define crandom()	(2.0 * (random() - 0.5))
573 
574 extern	cvar_t	*maxentities;
575 extern	cvar_t	*deathmatch;
576 extern	cvar_t	*coop;
577 extern	cvar_t	*dmflags;
578 extern	cvar_t	*zdmflags;
579 extern	cvar_t	*skill;
580 extern	cvar_t	*fraglimit;
581 extern	cvar_t	*timelimit;
582 extern	cvar_t	*password;
583 extern	cvar_t	*g_select_empty;
584 extern	cvar_t	*dedicated;
585 
586 extern	cvar_t	*sv_gravity;
587 extern	cvar_t	*sv_maxvelocity;
588 
589 extern	cvar_t	*gun_x, *gun_y, *gun_z;
590 extern	cvar_t	*sv_rollspeed;
591 extern	cvar_t	*sv_rollangle;
592 
593 extern	cvar_t	*run_pitch;
594 extern	cvar_t	*run_roll;
595 extern	cvar_t	*bob_up;
596 extern	cvar_t	*bob_pitch;
597 extern	cvar_t	*bob_roll;
598 
599 extern	cvar_t	*sv_cheats;
600 extern	cvar_t	*maxclients;
601 
602 extern	cvar_t  *gamedir;
603 
604 extern	cvar_t	*grenadeammotype;
605 extern	cvar_t	*grenadeammo;
606 extern	cvar_t	*bettyammo;
607 #ifdef CACHE_SOUND
608 extern cvar_t *printSoundRejects;
609 #endif
610 #ifdef WITH_ACEBOT
611 extern	cvar_t	*botchat; //<-------botchat
612 extern	cvar_t	*botauto_respawn;
613 #endif
614 #ifdef GAME_MOD
615 extern	cvar_t	*weap_shell;
616 extern  cvar_t  *alt_fire_blaster;
617 extern	cvar_t	*eject_bullets;
618 extern	cvar_t	*eject_bullets_dm_coop;
619 extern  cvar_t  *opt_dm_scoreboard;
620 extern  cvar_t  *help_min;
621 extern 	cvar_t 	*camoffset;
622 #endif
623 
624 #define world	(&g_edicts[0])
625 
626 // item spawnflags
627 #define ITEM_TRIGGER_SPAWN		0x00000001
628 #define ITEM_NO_TOUCH			0x00000002
629 // 6 bits reserved for editor flags
630 // 8 bits used as power cube id bits for coop games
631 #define DROPPED_ITEM			0x00010000
632 #define	DROPPED_PLAYER_ITEM		0x00020000
633 #define ITEM_TARGETS_USED		0x00040000
634 
635 //
636 // fields are needed for spawning from the entity string
637 // and saving / loading games
638 //
639 #define FFL_SPAWNTEMP		1
640 
641 typedef enum {
642 	F_INT,
643 	F_FLOAT,
644 	F_LSTRING,			// string on disk, pointer in memory, TAG_LEVEL
645 	F_GSTRING,			// string on disk, pointer in memory, TAG_GAME
646 	F_VECTOR,
647 	F_ANGLEHACK,
648 	F_EDICT,			// index on disk, pointer in memory
649 	F_ITEM,				// index on disk, pointer in memory
650 	F_CLIENT,			// index on disk, pointer in memory
651 	F_IGNORE
652 } fieldtype_t;
653 
654 typedef struct
655 {
656 	char	*name;
657 	int		ofs;
658 	fieldtype_t	type;
659 	int		flags;
660 } field_t;
661 
662 
663 extern	field_t fields[];
664 extern	gitem_t	itemlist[];
665 
666 
667 //
668 // g_cmds.c
669 //
670 void Cmd_Help_f (edict_t *ent);
671 void Cmd_Score_f (edict_t *ent);
672 
673 //
674 // g_items.c
675 //
676 void PrecacheItem (gitem_t *it);
677 void InitItems (void);
678 void SetItemNames (void);
679 gitem_t	*FindItem (char *pickup_name);
680 gitem_t	*FindItemByClassname (char *classname);
681 #define	ITEM_INDEX(x) ((x)-itemlist)
682 edict_t *Drop_Item (edict_t *ent, gitem_t *item);
683 void SetRespawn (edict_t *ent, float delay);
684 void ChangeWeapon (edict_t *ent);
685 void SpawnItem (edict_t *ent, gitem_t *item);
686 void Think_Weapon (edict_t *ent);
687 int ArmorIndex (edict_t *ent);
688 int PowerArmorType (edict_t *ent);
689 gitem_t	*GetItemByIndex (int index);
690 qboolean Add_Ammo (edict_t *ent, gitem_t *item, int count);
691 void Touch_Item (edict_t *ent, edict_t *other, cplane_t *plane, csurface_t *surf);
692 void precacheAllItems();
693 
694 //
695 // g_utils.c
696 //
697 qboolean	KillBox (edict_t *ent);
698 qboolean MonsterKillBox (edict_t *ent);
699 qboolean MonsterPlayerKillBox (edict_t *ent);
700 void	G_ProjectSource (vec3_t point, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result);
701 edict_t *G_Find (edict_t *from, int fieldofs, char *match);
702 edict_t *findradius (edict_t *from, vec3_t org, float rad);
703 edict_t *G_PickTarget (char *targetname);
704 void	G_UseTargets (edict_t *ent, edict_t *activator);
705 void	G_SetMovedir (vec3_t angles, vec3_t movedir);
706 
707 void	G_InitEdict (edict_t *e);
708 edict_t	*G_Spawn (void);
709 void	G_FreeEdict (edict_t *e);
710 
711 void	G_TouchTriggers (edict_t *ent);
712 void	G_TouchSolids (edict_t *ent);
713 
714 char	*G_CopyString (char *in);
715 
716 float	*tv (float x, float y, float z);
717 char	*vtos (vec3_t v);
718 
719 float vectoyaw (vec3_t vec);
720 void vectoangles (vec3_t vec, vec3_t angles);
721 
722 //
723 // g_combat.c
724 //
725 qboolean OnSameTeam (edict_t *ent1, edict_t *ent2);
726 qboolean CanDamage (edict_t *targ, edict_t *inflictor);
727 void T_Damage (edict_t *targ, edict_t *inflictor, edict_t *attacker, vec3_t dir, vec3_t point, vec3_t normal, int damage, int knockback, int dflags, int mod);
728 void T_RadiusDamage (edict_t *inflictor, edict_t *attacker, float damage, edict_t *ignore, float radius, int mod);
729 void T_RadiusDamagePosition (vec3_t origin, edict_t *inflictor, edict_t *attacker, float damage, edict_t *ignore, float radius, int mod);
730 
731 // damage flags
732 #define DAMAGE_RADIUS			    0x00000001	// damage was indirect
733 #define DAMAGE_NO_ARMOR			  0x00000002	// armour does not protect from this damage
734 #define DAMAGE_ENERGY			    0x00000004	// damage is from an energy based weapon
735 #define DAMAGE_NO_KNOCKBACK		0x00000008	// do not affect velocity, just view angles
736 #define DAMAGE_BULLET			    0x00000010  // damage is from a bullet (used for ricochets)
737 #define DAMAGE_NO_PROTECTION	0x00000020  // armor, shields, invulnerability, and godmode have no effect
738 #define DAMAGE_ARMORMOSTLY    0x00000040  // reduces the armor more than the health
739 
740 #define DEFAULT_BULLET_HSPREAD	300
741 #define DEFAULT_BULLET_VSPREAD	500
742 #define DEFAULT_SHOTGUN_HSPREAD	1000
743 #define DEFAULT_SHOTGUN_VSPREAD	500
744 #define DEFAULT_DEATHMATCH_SHOTGUN_COUNT	12
745 #define DEFAULT_SHOTGUN_COUNT	12
746 #define DEFAULT_SSHOTGUN_COUNT	20
747 
748 //
749 // g_monster.c
750 //
751 void monster_fire_bullet (edict_t *self, vec3_t start, vec3_t dir, int damage, int kick, int hspread, int vspread, int flashtype);
752 void monster_fire_shotgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int flashtype);
753 void monster_fire_blaster (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int flashtype, int effect);
754 void monster_fire_grenade (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int flashtype);
755 void monster_fire_rocket (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, int flashtype);
756 void monster_fire_railgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int flashtype);
757 void monster_fire_bfg (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int kick, float damage_radius, int flashtype);
758 void M_droptofloor (edict_t *ent);
759 void monster_think (edict_t *self);
760 void walkmonster_start (edict_t *self);
761 void swimmonster_start (edict_t *self);
762 void flymonster_start (edict_t *self);
763 void AttackFinished (edict_t *self, float time);
764 void monster_death_use (edict_t *self);
765 void M_CatagorizePosition (edict_t *ent);
766 qboolean M_CheckAttack (edict_t *self);
767 void M_FlyCheck (edict_t *self);
768 void M_CheckGround (edict_t *ent);
769 
770 //
771 // g_misc.c
772 //
773 void ThrowHead (edict_t *self, char *gibname, int damage, int type);
774 void ThrowClientHead (edict_t *self, int damage);
775 void ThrowGib (edict_t *self, char *gibname, int damage, int type);
776 void BecomeExplosion1(edict_t *self);
777 
778 //
779 // g_ai.c
780 //
781 void AI_SetSightClient (void);
782 
783 void ai_stand (edict_t *self, float dist);
784 void ai_move (edict_t *self, float dist);
785 void ai_walk (edict_t *self, float dist);
786 void ai_turn (edict_t *self, float dist);
787 void ai_run (edict_t *self, float dist);
788 void ai_charge (edict_t *self, float dist);
789 int range (edict_t *self, edict_t *other);
790 
791 void FoundTarget (edict_t *self);
792 qboolean infront (edict_t *self, edict_t *other);
793 qboolean visible (edict_t *self, edict_t *other);
794 qboolean FacingIdeal(edict_t *self);
795 qboolean inweaponLineOfSight (edict_t *self, edict_t *other);
796 
797 //
798 // g_weapon.c
799 //
800 void ThrowDebris (edict_t *self, char *modelname, float speed, vec3_t origin);
801 qboolean fire_hit (edict_t *self, vec3_t aim, int damage, int kick);
802 void fire_bullet (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int mod);
803 void fire_shotgun (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick, int hspread, int vspread, int count, int mod);
804 void fire_blaster (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, int effect, qboolean hyper);
805 void fire_grenade (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius);
806 void fire_grenade2 (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius, qboolean held);
807 void fire_rocket (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius, int radius_damage);
808 void fire_rail (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int kick);
809 void fire_bfg (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius);
810 
811 //
812 // g_ptrail.c
813 //
814 void PlayerTrail_Init (void);
815 void PlayerTrail_Add (vec3_t spot);
816 void PlayerTrail_New (vec3_t spot);
817 edict_t *PlayerTrail_PickFirst (edict_t *self);
818 edict_t *PlayerTrail_PickNext (edict_t *self);
819 edict_t	*PlayerTrail_LastSpot (void);
820 
821 
822 //
823 // g_client.c
824 //
825 void respawn (edict_t *ent);
826 void BeginIntermission (edict_t *targ);
827 void PutClientInServer (edict_t *ent);
828 void InitClientPersistant (gclient_t *client);
829 void InitClientResp (gclient_t *client);
830 void InitBodyQue (void);
831 void ClientBeginServerFrame (edict_t *ent);
832 
833 //
834 // g_player.c
835 //
836 void player_pain (edict_t *self, edict_t *other, float kick, int damage);
837 void player_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point);
838 
839 //
840 // g_svcmds.c
841 //
842 void	ServerCommand (void);
843 
844 //
845 // p_view.c
846 //
847 void ClientEndServerFrame (edict_t *ent);
848 
849 //
850 // p_hud.c
851 //
852 void MoveClientToIntermission (edict_t *client);
853 void G_SetStats (edict_t *ent);
854 void ValidateSelectedItem (edict_t *ent);
855 void DeathmatchScoreboardMessage (edict_t *client, edict_t *killer);
856 
857 //
858 // g_pweapon.c
859 //
860 void PlayerNoise(edict_t *who, vec3_t where, int type);
861 
862 //
863 // m_move.c
864 //
865 qboolean M_CheckBottom (edict_t *ent);
866 qboolean M_walkmove (edict_t *ent, float yaw, float dist);
867 void M_MoveToGoal (edict_t *ent, float dist);
868 void M_ChangeYaw (edict_t *ent);
869 
870 //
871 // g_phys.c
872 //
873 void G_RunEntity (edict_t *ent);
874 
875 //
876 // g_main.c
877 //
878 void SaveClientData (void);
879 void FetchClientEntData (edict_t *ent);
880 
881 
882 #if defined(_DEBUG) && defined(_Z_TESTMODE)
883 
884 //
885 // z_mtest.c
886 //
887 void Cmd_TestItem (edict_t *ent);
888 
889 #endif
890 
891 //
892 // z_trigger.c
893 //
894 #ifdef CACHE_SOUND
895 void printSoundNum();
896 void initSoundList();
897 #endif
898 
899 //
900 // z_item.c
901 //
902 qboolean EMPNukeCheck(edict_t	*ent, vec3_t pos);
903 
904 
905 //
906 // z_weapon.c
907 //
908 void fire_bb (edict_t *self, vec3_t start, vec3_t aimdir, int damage, int speed, float timer, float damage_radius);
909 void fire_flare (edict_t *self, vec3_t start, vec3_t dir, int damage, int speed, float damage_radius, int radius_damage);
910 
911 
912 //
913 // z_ai.c
914 //
915 void ai_schoolStand (edict_t *self, float dist);
916 void ai_schoolRun (edict_t *self, float dist);
917 void ai_schoolWalk (edict_t *self, float dist);
918 void ai_schoolCharge (edict_t *self, float dist);
919 void ai_schoolBackWalk (edict_t *self, float dist);
920 void ai_schoolSideStepRight (edict_t *self, float dist);
921 void ai_schoolSideStepLeft (edict_t *self, float dist);
922 
923 
924 //
925 // p_weapon
926 //
927 void P_ProjectSource (gclient_t *client, vec3_t point, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result);
928 
929 //============================================================================
930 
931 // client_t->anim_priority
932 #define	ANIM_BASIC		0		// stand / run
933 #define	ANIM_WAVE		1
934 #define	ANIM_JUMP		2
935 #define	ANIM_PAIN		3
936 #define	ANIM_ATTACK		4
937 #define	ANIM_DEATH		5
938 
939 
940 // client data that stays across multiple level loads
941 typedef struct
942 {
943 	char		userinfo[MAX_INFO_STRING];
944 	char		netname[16];
945 	int			hand;
946 	int			gl_polyblend; // so that we know whether to damage "cheating" players
947 
948 	qboolean	connected;			// a loadgame will leave valid entities that
949 									// just don't have a connection yet
950 
951 	// values saved and restored from edicts when changing levels
952 	int			health;
953 	int			max_health;
954 	qboolean	powerArmorActive;
955 
956 	int			selected_item;
957 	int			inventory[MAX_ITEMS];
958 
959 	// ammo capacities
960 	int			max_bullets;
961 	int			max_shells;
962 	int			max_rockets;
963 	int			max_flares;
964 	int			max_grenades;
965 	int			max_cells;
966 	int			max_slugs;
967 	int			max_tbombs;
968 	int			max_a2k;
969 	int			max_empnuke;
970 	int			max_plasmashield;
971 
972 	gitem_t		*weapon;
973 	gitem_t		*lastweapon;
974 	gitem_t		*lastweapon2; // this if for inventory hiding items
975 
976 	int			power_cubes;	// used for tracking the cubes in coop games
977 	int			score;			// for calculating total unit score in coop games
978 
979 	float visorFrames;
980 	qboolean 		spectator;			// client is a spectator
981 } client_persistant_t;
982 
983 // client data that stays across deathmatch respawns
984 typedef struct
985 {
986 	client_persistant_t	coop_respawn;	// what to set client->pers to on a respawn
987 	int			enterframe;			// level.framenum the client entered the game
988 	int			score;				// frags, etc
989 	vec3_t		cmd_angles;			// angles sent over in the last command
990 	int			game_helpchanged;
991 	int			helpchanged;
992 	qboolean		spectator;			// client is a spectator
993 } client_respawn_t;
994 
995 // this structure is cleared on each PutClientInServer(),
996 // except for 'client->pers'
997 struct gclient_s
998 {
999 	// known to server
1000 	player_state_t	ps;				// communicated by server to clients
1001 	int				ping;
1002 
1003 	// private to game
1004 	client_persistant_t	pers;
1005 	client_respawn_t	resp;
1006 	pmove_state_t		old_pmove;	// for detecting out-of-pmove changes
1007 
1008 	qboolean	showscores;			// set layout stat
1009 	qboolean	showinventory;		// set layout stat
1010 	qboolean	showhelp;
1011 	qboolean	showhelpicon;
1012 
1013 	int			ammo_index;
1014 
1015 	int			buttons;
1016 	int			oldbuttons;
1017 	int			latched_buttons;
1018 
1019 	qboolean	weapon_thunk;
1020 
1021 	gitem_t		*newweapon;
1022 
1023 	// sum up damage over an entire frame, so
1024 	// shotgun blasts give a single big kick
1025 	int			damage_armor;		// damage absorbed by armor
1026 	int			damage_parmor;		// damage absorbed by power armor
1027 	int			damage_blood;		// damage taken out of health
1028 	int			damage_knockback;	// impact damage
1029 	vec3_t		damage_from;		// origin for vector calculation
1030 
1031 	float		killer_yaw;			// when dead, look at killer
1032 
1033 	weaponstate_t	weaponstate;
1034 	vec3_t		kick_angles;	// weapon kicks
1035 	vec3_t		kick_origin;
1036 	float		v_dmg_roll, v_dmg_pitch, v_dmg_time;	// damage kicks
1037 	float		fall_time, fall_value;		// for view drop on fall
1038 	float		damage_alpha;
1039 	float		bonus_alpha;
1040 	vec3_t		damage_blend;
1041 	vec3_t		v_angle;			// aiming direction
1042 	float		bobtime;			// so off-ground doesn't change it
1043 	vec3_t		oldviewangles;
1044 	vec3_t		oldvelocity;
1045 
1046 	float		next_drown_time;
1047 	int			old_waterlevel;
1048 	int			breather_sound;
1049 
1050 	int			machinegun_shots;	// for weapon raising
1051 
1052 	// animation vars
1053 	int			anim_end;
1054 	int			anim_priority;
1055 	qboolean	anim_duck;
1056 	qboolean	anim_run;
1057 
1058 	// powerup timers
1059 	float		quad_framenum;
1060 	float		invincible_framenum;
1061 	float		breather_framenum;
1062 	float		enviro_framenum;
1063 	float		a2kFramenum;
1064 
1065 	qboolean	grenade_blew_up;
1066 	float		grenade_time;
1067 	int			silencer_shots;
1068 	int			weapon_sound;
1069 
1070 	float		pickup_msg_time;
1071 
1072 	float		respawn_time;		// can respawn when time > this
1073 
1074 #if defined(_DEBUG) && defined(_Z_TESTMODE)
1075 	struct edict_s *lineDraw;
1076 #endif
1077 
1078 	// used for blinding
1079 	int flashTime;
1080 	int flashBase;
1081 
1082 	edict_t		*zCameraTrack;    // the entity to see through
1083 	vec3_t     zCameraOffset;   // offset from camera origin
1084 	edict_t		*zCameraLocalEntity;
1085 	float zCameraStaticFramenum;
1086 
1087 	qboolean showOrigin;
1088 
1089 	// for sniper rifle
1090 	int sniperFramenum;
1091 
1092 	// for sonic cannon
1093 	float startFireTime;
1094 #ifdef GAME_MOD
1095 	BlinkyClient_t blinky_client;
1096 #endif
1097 };
1098 
1099 struct edict_s
1100 {
1101 	entity_state_t	s;
1102 	struct gclient_s	*client;	// NULL if not a player
1103 									// the server expects the first part
1104 									// of gclient_s to be a player_state_t
1105 									// but the rest of it is opaque
1106 
1107 	qboolean	inuse;
1108 	int			linkcount;
1109 
1110 	// FIXME: move these fields to a server private sv_entity_t
1111 	link_t		area;				// linked to a division node or leaf
1112 
1113 	int			num_clusters;		// if -1, use headnode instead
1114 	int			clusternums[MAX_ENT_CLUSTERS];
1115 	int			headnode;			// unused if num_clusters != -1
1116 	int			areanum, areanum2;
1117 
1118 	//================================
1119 
1120 	int			svflags;
1121 	vec3_t		mins, maxs;
1122 	vec3_t		absmin, absmax, size;
1123 	solid_t		solid;
1124 	int			clipmask;
1125 	edict_t		*owner;
1126 
1127 
1128 	// DO NOT MODIFY ANYTHING ABOVE THIS, THE SERVER
1129 	// EXPECTS THE FIELDS IN THAT ORDER!
1130 
1131 	//================================
1132 	int			movetype;
1133 	int			flags;
1134 
1135 	char		*model;
1136 	char		*model2;
1137 	char		*model3;
1138 	char		*model4;
1139 	float		freetime;			// sv.time when the object was freed
1140 
1141 	//
1142 	// only used locally in game, not by server
1143 	//
1144 	char		*message;
1145 	char		*classname;
1146 	int			spawnflags;
1147 
1148 	float		timestamp;
1149 
1150 	float		angle;			// set in qe3, -1 = up, -2 = down
1151 	char		*target;
1152 	char		*targetname;
1153 	char		*killtarget;
1154 	char		*team;
1155 	char		*pathtarget;
1156 	char		*deathtarget;
1157 	char		*combattarget;
1158 	edict_t		*target_ent;
1159 
1160 	float		speed, accel, decel, aspeed;
1161 	vec3_t		movedir;
1162 	vec3_t		pos1, pos2;
1163 
1164 	vec3_t		velocity;
1165 	vec3_t		avelocity;
1166 	int			mass;
1167 	float		air_finished;
1168 	float		gravity;		// per entity gravity multiplier (1.0 is normal)
1169 								// use for lowgrav artifact, flares
1170 
1171 	edict_t		*goalentity;
1172 	edict_t		*movetarget;
1173 	float		yaw_speed;
1174 	float		ideal_yaw;
1175 
1176 	float		nextthink;
1177 	void		(*prethink) (edict_t *ent);
1178 	void		(*think)(edict_t *self);
1179 	void		(*blocked)(edict_t *self, edict_t *other);	//move to moveinfo?
1180 	void		(*touch)(edict_t *self, edict_t *other, cplane_t *plane, csurface_t *surf);
1181 	void		(*use)(edict_t *self, edict_t *other, edict_t *activator);
1182 	void		(*pain)(edict_t *self, edict_t *other, float kick, int damage);
1183 	void		(*die)(edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point);
1184 
1185 	float		touch_debounce_time;		// are all these legit?  do we need more/less of them?
1186 	float		pain_debounce_time;
1187 	float		damage_debounce_time;
1188 	float		fly_sound_debounce_time;	//move to clientinfo
1189 	float		last_move_time;
1190 
1191 	int			health;
1192 	int			max_health;
1193 	int			gib_health;
1194 	int			deadflag;
1195 	qboolean	show_hostile;
1196 
1197 	float		powerarmor_time;
1198 
1199 	char		*map;			// target_changelevel
1200 
1201 	int			viewheight;		// height above origin where eyesight is determined
1202 	int			takedamage;
1203 	int			dmg;
1204 	int			radius_dmg;
1205 	float		dmg_radius;
1206 	int			sounds;			//make this a spawntemp var?
1207 	int			count;
1208 
1209 	edict_t		*chain;
1210 	edict_t		*enemy;
1211 	edict_t		*oldenemy;
1212 	edict_t		*activator;
1213 	edict_t		*groundentity;
1214 	int			groundentity_linkcount;
1215 	edict_t		*teamchain;
1216 	edict_t		*teammaster;
1217 
1218 	edict_t		*mynoise;		// can go in client only
1219 	edict_t		*mynoise2;
1220 
1221 	int			noise_index;
1222 	int			noise_index2;
1223 	float		volume;
1224 	float		attenuation;
1225 
1226 	// timing variables
1227 	float		wait;
1228 	float		delay;			// before firing targets
1229 	float		random;
1230 
1231 	float		teleport_time;
1232 
1233 	int			watertype;
1234 	int			waterlevel;
1235 
1236 	vec3_t		move_origin;
1237 	vec3_t		move_angles;
1238 
1239 	// move this to clientinfo?
1240 	int			light_level;
1241 
1242 	int			style;			// also used as areaportal number
1243 
1244 	gitem_t		*item;			// for bonus items
1245 
1246 	// common data blocks
1247 	moveinfo_t		moveinfo;
1248 	monsterinfo_t	monsterinfo;
1249 
1250 	// can use this for misc. timeouts
1251 	float timeout;
1252 
1253 	// for func_door, also used by monster_autocannon, and misc_securitycamera
1254 	int active;
1255 	int seq;
1256 
1257 	// between level saves/loads
1258 	int spawnflags2;
1259 	int oldentnum;
1260 
1261 	// titan laser
1262 	edict_t *laser;
1263 
1264 	float weaponsound_time;
1265 
1266 #if defined(_DEBUG) && defined(_Z_TESTMODE)
1267 	//can't teach an old dog new tricks
1268 	void *extra_data;
1269 #endif
1270 
1271 	// schooling info
1272 	edict_t *zRaduisList, *zSchoolChain;
1273 	float zDistance;
1274 
1275 	// this is for MOVETYPE_RIDE
1276 	edict_t *rideWith[2];
1277 	vec3_t rideWithOffset[2];
1278 
1279 	// camera number
1280 	vec3_t mangle;
1281 
1282 	// time left for the visor (stored if a visor is dropped)
1283 	int visorFrames;
1284 
1285 	// monster team
1286 	char *mteam;
1287 
1288 	// for random func_timer targets
1289 	char targets[16][MAX_QPATH];
1290 	int numTargets;
1291 
1292 	// used by floor-mounted autocannon
1293 	int onFloor;
1294 
1295   float bossFireTimeout;
1296   int bossFireCount;
1297 #ifdef WITH_ACEBOT
1298 // ACEBOT_ADD
1299 	qboolean is_bot;
1300 	qboolean is_jumping;
1301 
1302 	// For movement
1303 	vec3_t move_vector;
1304 	float next_move_time;
1305 	float wander_timeout;
1306 	float suicide_timeout;
1307 
1308 	// For node code
1309 	int current_node; // current node
1310 	int goal_node; // current goal node
1311 	int next_node; // the node that will take us one step closer to our goal
1312 	int node_timeout;
1313 	int last_node;
1314 	int tries;
1315 	int state;
1316 // ACEBOT_END
1317 //botchat>
1318 	float last_insult;
1319  	float last_taunt;
1320  	float last_chat;
1321 //<botchat
1322 #endif
1323 };
1324 
1325 //zaero debug includes (need type info)
1326 #include "z_frames.h"
1327 #include "z_anim.h"
1328 
1329 // Zaero dmflags
1330 #define ZDM_NO_GL_POLYBLEND_DAMAGE	1
1331 #define ZDM_ZAERO_ITEMS				2
1332 
1333 #ifdef WITH_ACEBOT
1334 // ACEBOT_ADD
1335 #include "ace/acebot.h"
1336 // ACEBOT_END
1337 //botchat>
1338 void bFakeChat(edict_t *bot);
1339 void bInsult(edict_t *bot, edict_t *loser);
1340 void bTaunt(edict_t *bot, edict_t *other);
1341 //<botchat
1342 #endif
1343 
1344