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