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