1 //
2 // Copyright(C) 1993-1996 Id Software, Inc.
3 // Copyright(C) 2005-2014 Simon Howard
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // DESCRIPTION:
16 //	Play functions, animation, global header.
17 //
18 
19 
20 #ifndef __P_LOCAL__
21 #define __P_LOCAL__
22 
23 #ifndef __R_LOCAL__
24 #include "r_local.h"
25 #endif
26 
27 #define FLOATSPEED		(FRACUNIT*4)
28 
29 
30 #define MAXHEALTH		100
31 #define VIEWHEIGHT		(41*FRACUNIT)
32 
33 // mapblocks are used to check movement
34 // against lines and things
35 #define MAPBLOCKUNITS	128
36 #define MAPBLOCKSIZE	(MAPBLOCKUNITS*FRACUNIT)
37 #define MAPBLOCKSHIFT	(FRACBITS+7)
38 #define MAPBMASK		(MAPBLOCKSIZE-1)
39 #define MAPBTOFRAC		(MAPBLOCKSHIFT-FRACBITS)
40 
41 
42 // player radius for movement checking
43 #define PLAYERRADIUS	16*FRACUNIT
44 
45 // MAXRADIUS is for precalculated sector block boxes
46 // the spider demon is larger,
47 // but we do not have any moving sectors nearby
48 #define MAXRADIUS		32*FRACUNIT
49 
50 #define GRAVITY		FRACUNIT
51 #define MAXMOVE		(30*FRACUNIT)
52 
53 #define USERANGE		(64*FRACUNIT)
54 #define MELEERANGE		(64*FRACUNIT)
55 #define MISSILERANGE	(32*64*FRACUNIT)
56 
57 // follow a player exlusively for 3 seconds
58 #define	BASETHRESHOLD	 	100
59 
60 
61 
62 //
63 // P_TICK
64 //
65 
66 // both the head and tail of the thinker list
67 extern	thinker_t	thinkercap;
68 
69 
70 void P_InitThinkers (void);
71 void P_AddThinker (thinker_t* thinker);
72 void P_RemoveThinker (thinker_t* thinker);
73 
74 
75 //
76 // P_PSPR
77 //
78 void P_SetupPsprites (player_t* curplayer);
79 void P_MovePsprites (player_t* curplayer);
80 void P_DropWeapon (player_t* player);
81 
82 
83 //
84 // P_USER
85 //
86 void	P_PlayerThink (player_t* player);
87 
88 
89 //
90 // P_MOBJ
91 //
92 #define ONFLOORZ		INT_MIN
93 #define ONCEILINGZ		INT_MAX
94 
95 // Time interval for item respawning.
96 #define ITEMQUESIZE		128
97 
98 extern mapthing_t	itemrespawnque[ITEMQUESIZE];
99 extern int		itemrespawntime[ITEMQUESIZE];
100 extern int		iquehead;
101 extern int		iquetail;
102 
103 
104 void P_RespawnSpecials (void);
105 
106 mobj_t*
107 P_SpawnMobj
108 ( fixed_t	x,
109   fixed_t	y,
110   fixed_t	z,
111   mobjtype_t	type );
112 
113 void 	P_RemoveMobj (mobj_t* th);
114 mobj_t* P_SubstNullMobj (mobj_t* th);
115 boolean	P_SetMobjState (mobj_t* mobj, statenum_t state);
116 void 	P_MobjThinker (mobj_t* mobj);
117 
118 void	P_SpawnPuff (fixed_t x, fixed_t y, fixed_t z);
119 void 	P_SpawnBlood (fixed_t x, fixed_t y, fixed_t z, int damage);
120 mobj_t* P_SpawnMissile (mobj_t* source, mobj_t* dest, mobjtype_t type);
121 void	P_SpawnPlayerMissile (mobj_t* source, mobjtype_t type);
122 
123 
124 //
125 // P_ENEMY
126 //
127 void P_NoiseAlert (mobj_t* target, mobj_t* emmiter);
128 
129 
130 //
131 // P_MAPUTL
132 //
133 typedef struct
134 {
135     fixed_t	x;
136     fixed_t	y;
137     fixed_t	dx;
138     fixed_t	dy;
139 
140 } divline_t;
141 
142 typedef struct
143 {
144     fixed_t	frac;		// along trace line
145     boolean	isaline;
146     union {
147 	mobj_t*	thing;
148 	line_t*	line;
149     }			d;
150 } intercept_t;
151 
152 // Extended MAXINTERCEPTS, to allow for intercepts overrun emulation.
153 
154 #define MAXINTERCEPTS_ORIGINAL 128
155 #define MAXINTERCEPTS          (MAXINTERCEPTS_ORIGINAL + 61)
156 
157 extern intercept_t	intercepts[MAXINTERCEPTS];
158 extern intercept_t*	intercept_p;
159 
160 typedef boolean (*traverser_t) (intercept_t *in);
161 
162 fixed_t P_AproxDistance (fixed_t dx, fixed_t dy);
163 int 	P_PointOnLineSide (fixed_t x, fixed_t y, line_t* line);
164 int 	P_PointOnDivlineSide (fixed_t x, fixed_t y, divline_t* line);
165 void 	P_MakeDivline (line_t* li, divline_t* dl);
166 fixed_t P_InterceptVector (divline_t* v2, divline_t* v1);
167 int 	P_BoxOnLineSide (fixed_t* tmbox, line_t* ld);
168 
169 extern fixed_t		opentop;
170 extern fixed_t 		openbottom;
171 extern fixed_t		openrange;
172 extern fixed_t		lowfloor;
173 
174 void 	P_LineOpening (line_t* linedef);
175 
176 boolean P_BlockLinesIterator (int x, int y, boolean(*func)(line_t*) );
177 boolean P_BlockThingsIterator (int x, int y, boolean(*func)(mobj_t*) );
178 
179 #define PT_ADDLINES		1
180 #define PT_ADDTHINGS	2
181 #define PT_EARLYOUT		4
182 
183 extern divline_t	trace;
184 
185 boolean
186 P_PathTraverse
187 ( fixed_t	x1,
188   fixed_t	y1,
189   fixed_t	x2,
190   fixed_t	y2,
191   int		flags,
192   boolean	(*trav) (intercept_t *));
193 
194 void P_UnsetThingPosition (mobj_t* thing);
195 void P_SetThingPosition (mobj_t* thing);
196 
197 
198 //
199 // P_MAP
200 //
201 
202 // If "floatok" true, move would be ok
203 // if within "tmfloorz - tmceilingz".
204 extern boolean		floatok;
205 extern fixed_t		tmfloorz;
206 extern fixed_t		tmceilingz;
207 
208 
209 extern	line_t*		ceilingline;
210 
211 // fraggle: I have increased the size of this buffer.  In the original Doom,
212 // overrunning past this limit caused other bits of memory to be overwritten,
213 // affecting demo playback.  However, in doing so, the limit was still
214 // exceeded.  So we have to support more than 8 specials.
215 //
216 // We keep the original limit, to detect what variables in memory were
217 // overwritten (see SpechitOverrun())
218 
219 #define MAXSPECIALCROSS 		20
220 #define MAXSPECIALCROSS_ORIGINAL	8
221 
222 extern	line_t*	spechit[MAXSPECIALCROSS];
223 extern	int	numspechit;
224 
225 boolean P_CheckPosition (mobj_t *thing, fixed_t x, fixed_t y);
226 boolean P_TryMove (mobj_t* thing, fixed_t x, fixed_t y);
227 boolean P_TeleportMove (mobj_t* thing, fixed_t x, fixed_t y);
228 void	P_SlideMove (mobj_t* mo);
229 boolean P_CheckSight (mobj_t* t1, mobj_t* t2);
230 void 	P_UseLines (player_t* player);
231 
232 boolean P_ChangeSector (sector_t* sector, boolean crunch);
233 
234 extern mobj_t*	linetarget;	// who got hit (or NULL)
235 
236 fixed_t
237 P_AimLineAttack
238 ( mobj_t*	t1,
239   angle_t	angle,
240   fixed_t	distance );
241 
242 void
243 P_LineAttack
244 ( mobj_t*	t1,
245   angle_t	angle,
246   fixed_t	distance,
247   fixed_t	slope,
248   int		damage );
249 
250 void
251 P_RadiusAttack
252 ( mobj_t*	spot,
253   mobj_t*	source,
254   int		damage );
255 
256 
257 
258 //
259 // P_SETUP
260 //
261 extern byte*		rejectmatrix;	// for fast sight rejection
262 extern short*		blockmaplump;	// offsets in blockmap are from here
263 extern short*		blockmap;
264 extern int		bmapwidth;
265 extern int		bmapheight;	// in mapblocks
266 extern fixed_t		bmaporgx;
267 extern fixed_t		bmaporgy;	// origin of block map
268 extern mobj_t**		blocklinks;	// for thing chains
269 
270 
271 
272 //
273 // P_INTER
274 //
275 extern int		maxammo[NUMAMMO];
276 extern int		clipammo[NUMAMMO];
277 
278 void
279 P_TouchSpecialThing
280 ( mobj_t*	special,
281   mobj_t*	toucher );
282 
283 void
284 P_DamageMobj
285 ( mobj_t*	target,
286   mobj_t*	inflictor,
287   mobj_t*	source,
288   int		damage );
289 
290 
291 //
292 // P_SPEC
293 //
294 #include "p_spec.h"
295 
296 
297 #endif	// __P_LOCAL__
298