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