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