1 // Emacs style mode select   -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // $Id: p_local.h 4542 2014-02-09 17:39:42Z dr_sean $
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 // Copyright (C) 2006-2014 by The Odamex Team.
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License
11 // as published by the Free Software Foundation; either version 2
12 // of the License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // DESCRIPTION:
20 //	Play functions, animation, global header.
21 //
22 //-----------------------------------------------------------------------------
23 
24 
25 #ifndef __P_LOCAL__
26 #define __P_LOCAL__
27 
28 #ifndef __R_LOCAL__
29 #include "r_local.h"
30 #endif
31 
32 #include <set>
33 
34 #define FLOATSPEED		(FRACUNIT*4)
35 
36 #define STEEPSLOPE		46341	// [RH] Minimum floorplane.c value for walking
37 
38 #define MAXHEALTH		100
39 #define VIEWHEIGHT		(41*FRACUNIT)
40 
41 // mapblocks are used to check movement
42 // against lines and things
43 #define MAPBLOCKUNITS	128
44 #define MAPBLOCKSIZE	(MAPBLOCKUNITS*FRACUNIT)
45 #define MAPBLOCKSHIFT	(FRACBITS+7)
46 #define MAPBMASK		(MAPBLOCKSIZE-1)
47 #define MAPBTOFRAC		(MAPBLOCKSHIFT-FRACBITS)
48 
49 
50 // player radius for movement checking
51 #define PLAYERRADIUS	16*FRACUNIT
52 
53 // MAXRADIUS is for precalculated sector block boxes
54 // the spider demon is larger,
55 // but we do not have any moving sectors nearby
56 #define MAXRADIUS		32*FRACUNIT
57 
58 //#define GRAVITY 		FRACUNIT
59 #define MAXMOVE 		(30*FRACUNIT)
60 
61 #define STOPSPEED						0x1000
62 #define FRICTION						0xe800
63 
64 #define USERANGE		(64*FRACUNIT)
65 #define MELEERANGE		(64*FRACUNIT)
66 #define MISSILERANGE	(32*64*FRACUNIT)
67 
68 #define WATER_SINK_FACTOR		3
69 #define WATER_SINK_SMALL_FACTOR	4
70 #define WATER_SINK_SPEED		(FRACUNIT/2)
71 #define WATER_JUMP_SPEED		(FRACUNIT*7/2)
72 
73 // follow a player exlusively for 3 seconds
74 #define BASETHRESHOLD	100
75 
76 //
77 // P_PSPR
78 //
79 void P_SetupPsprites (player_t* curplayer);
80 void P_MovePsprites (player_t* curplayer);
81 void P_DropWeapon (player_t* player);
82 
83 
84 //
85 // P_USER
86 //
87 void P_FallingDamage (AActor *ent);
88 void P_PlayerThink (player_t *player);
89 bool P_AreTeammates(player_t &a, player_t &b);
90 bool P_CanSpy(player_t &viewer, player_t &other);
91 
92 //
93 // P_MOBJ
94 //
95 #define ONFLOORZ		MININT
96 #define ONCEILINGZ		MAXINT
97 
98 // Time interval for item respawning.
99 #define ITEMQUESIZE 	128
100 
101 extern mapthing2_t		itemrespawnque[ITEMQUESIZE];
102 extern int				itemrespawntime[ITEMQUESIZE];
103 extern int				iquehead;
104 extern int				iquetail;
105 
106 void 	P_ThrustMobj (AActor *mo, angle_t angle, fixed_t move);
107 void	P_RespawnSpecials (void);
108 
109 bool	P_SetMobjState (AActor* mobj, statenum_t state, bool cl_update = false);
110 
111 void	P_SpawnPuff (fixed_t x, fixed_t y, fixed_t z);
112 void	P_SpawnBlood (fixed_t x, fixed_t y, fixed_t z, int damage);
113 AActor* P_SpawnMissile (AActor* source, AActor* dest, mobjtype_t type);
114 void	P_SpawnPlayerMissile (AActor* source, mobjtype_t type);
115 
116 void	P_RailAttack (AActor *source, int damage, int offset);	// [RH] Shoot a railgun
117 bool	P_HitFloor (AActor *thing);
118 //
119 // [RH] P_THINGS
120 //
121 extern int SpawnableThings[];
122 extern const int NumSpawnableThings;
123 
124 BOOL	P_Thing_Spawn (int tid, int type, angle_t angle, BOOL fog);
125 BOOL	P_Thing_Projectile (int tid, int type, angle_t angle,
126 							fixed_t speed, fixed_t vspeed, BOOL gravity);
127 BOOL	P_ActivateMobj (AActor *mobj, AActor *activator);
128 BOOL	P_DeactivateMobj (AActor *mobj);
129 
130 //
131 // P_ENEMY
132 //
133 void	P_NoiseAlert (AActor* target, AActor* emmiter);
134 void	P_SpawnBrainTargets(void);	// killough 3/26/98: spawn icon landings
135 
136 extern struct brain_s {				// killough 3/26/98: global state of boss brain
137 	int easy, targeton;
138 } brain;
139 
140 
141 //
142 // P_MAPUTL
143 //
144 typedef struct
145 {
146 	fixed_t 	x;
147 	fixed_t 	y;
148 	fixed_t 	dx;
149 	fixed_t 	dy;
150 
151 } divline_t;
152 
153 typedef struct
154 {
155 	fixed_t 	frac;			// along trace line
156 	BOOL 	isaline;
157 	union {
158 		AActor* thing;
159 		line_t* line;
160 	}					d;
161 } intercept_t;
162 
163 #define MAXINTERCEPTS	128
164 
165 extern TArray<intercept_t> intercepts;
166 
167 typedef BOOL (*traverser_t) (intercept_t *in);
168 
169 subsector_t* P_PointInSubsector(fixed_t x, fixed_t y);
170 fixed_t P_AproxDistance (fixed_t dx, fixed_t dy);
171 fixed_t P_AproxDistance2 (fixed_t *pos_array, fixed_t x, fixed_t y);
172 fixed_t P_AproxDistance2 (AActor *mo, fixed_t x, fixed_t y);
173 fixed_t P_AproxDistance2 (AActor *a, AActor *b);
174 
175 bool P_ActorInFOV(AActor* origin, AActor* mo , float f, fixed_t dist);
176 
177 int 	P_PointOnLineSide (fixed_t x, fixed_t y, const line_t *line);
178 int 	P_PointOnDivlineSide (fixed_t x, fixed_t y, const divline_t *line);
179 void	P_MakeDivline (const line_t *li, divline_t *dl);
180 fixed_t P_InterceptVector (const divline_t *v2, const divline_t *v1);
181 int 	P_BoxOnLineSide (const fixed_t *tmbox, const line_t *ld);
182 
183 extern fixed_t			opentop;
184 extern fixed_t			openbottom;
185 extern fixed_t			openrange;
186 extern fixed_t			lowfloor;
187 
188 void P_LineOpening (const line_t *linedef, fixed_t x, fixed_t y, fixed_t refx=MINFIXED, fixed_t refy=0);
189 
190 BOOL P_BlockLinesIterator (int x, int y, BOOL(*func)(line_t*) );
191 BOOL P_BlockThingsIterator (int x, int y, BOOL(*func)(AActor*), AActor *start=NULL);
192 
193 #define PT_ADDLINES 	1
194 #define PT_ADDTHINGS	2
195 #define PT_EARLYOUT 	4
196 
197 extern divline_t		trace;
198 
199 BOOL
200 P_PathTraverse
201 ( fixed_t		x1,
202   fixed_t		y1,
203   fixed_t		x2,
204   fixed_t		y2,
205   int			flags,
206   BOOL		(*trav) (intercept_t *));
207 
208 // [ML] 2/1/10: Break out P_PointToAngle from R_PointToAngle2 (from EE)
209 angle_t P_PointToAngle(fixed_t xo, fixed_t yo, fixed_t x, fixed_t y);
210 
211 //
212 // P_MAP
213 //
214 
215 // If "floatok" true, move would be ok
216 // if within "tmfloorz - tmceilingz".
217 extern BOOL				floatok;
218 extern fixed_t			tmfloorz;
219 extern fixed_t			tmceilingz;
220 extern msecnode_t		*sector_list;		// phares 3/16/98
221 extern AActor			*BlockingMobj;
222 extern line_t			*BlockingLine;		// Used only by P_Move
223 											// This is not necessarily a *blocking* line
224 
225 extern fixed_t			tmdropoffz; //Needed in b_move.c
226 extern sector_t			*tmfloorsector;
227 
228 extern	line_t* 		ceilingline;
229 
230 void	P_TestActorMovement(AActor *mo, fixed_t tryx, fixed_t tryy, fixed_t tryz,
231 						fixed_t &destx, fixed_t &desty, fixed_t &destz);
232 bool	P_TestMobjZ (AActor *actor);
233 BOOL	P_TestMobjLocation (AActor *mobj);
234 bool	P_CheckPosition (AActor *thing, fixed_t x, fixed_t y);
235 AActor	*P_CheckOnmobj (AActor *thing);
236 void	P_FakeZMovement (AActor *mo);
237 bool	P_CheckSlopeWalk (AActor *actor, fixed_t &xmove, fixed_t &ymove);
238 BOOL	P_TryMove (AActor* thing, fixed_t x, fixed_t y, bool dropoff, bool onfloor = false);
239 BOOL	P_TeleportMove (AActor* thing, fixed_t x, fixed_t y, fixed_t z, BOOL telefrag);	// [RH] Added z and telefrag parameters
240 void	P_SlideMove (AActor* mo);
241 bool	P_CheckSight (const AActor* t1, const AActor* t2);
242 void	P_UseLines (player_t* player);
243 void	P_ApplyTorque(AActor *mo);
244 void	P_CopySector(sector_t *dest, sector_t *src);
245 
246 fixed_t P_PlaneZ(fixed_t x, fixed_t y, const plane_t *plane);
247 double P_PlaneZ(double x, double y, const plane_t *plane);
248 fixed_t P_FloorHeight(fixed_t x, fixed_t y, const sector_t *sec = NULL);
249 fixed_t P_FloorHeight(const AActor *mo);
250 fixed_t P_FloorHeight(const sector_t *sector);
251 fixed_t P_CeilingHeight(fixed_t x, fixed_t y, const sector_t *sec = NULL);
252 fixed_t P_CeilingHeight(const AActor *mo);
253 fixed_t P_CeilingHeight(const sector_t *sector);
254 fixed_t P_LowestHeightOfCeiling(sector_t *sector);
255 fixed_t P_LowestHeightOfFloor(sector_t *sector);
256 fixed_t P_HighestHeightOfCeiling(sector_t *sector);
257 fixed_t P_HighestHeightOfFloor(sector_t *sector);
258 
259 bool P_IsPlaneLevel(const plane_t *plane);
260 bool P_IdenticalPlanes(const plane_t *pl1, const plane_t *pl2);
261 void P_InvertPlane(plane_t *plane);
262 void P_ChangeCeilingHeight(sector_t *sector, fixed_t amount);
263 void P_ChangeFloorHeight(sector_t *sector, fixed_t amount);
264 void P_SetCeilingHeight(sector_t *sector, fixed_t value);
265 void P_SetFloorHeight(sector_t *sector, fixed_t value);
266 bool P_PointOnPlane(const plane_t *plane, fixed_t x, fixed_t y, fixed_t z);
267 bool P_PointAbovePlane(const plane_t *plane, fixed_t x, fixed_t y, fixed_t z);
268 bool P_PointBelowPlane(const plane_t *plane, fixed_t x, fixed_t y, fixed_t z);
269 
270 struct v3fixed_t;
271 v3fixed_t P_LinePlaneIntersection(const plane_t *plane, const v3fixed_t &lineorg, const v3fixed_t &linedir);
272 
273 
274 bool P_CheckSightEdges(const AActor* t1, const AActor* t2, float radius_boost);
275 
276 bool	P_ChangeSector (sector_t* sector, bool crunch);
277 
278 extern	AActor*	linetarget; 	// who got hit (or NULL)
279 
280 fixed_t P_AimLineAttack (AActor *t1, angle_t angle, fixed_t distance);
281 fixed_t P_AutoAimLineAttack(AActor* actor, angle_t& angle, const angle_t spread, const int tracers, fixed_t distance);
282 void	P_LineAttack (AActor *t1, angle_t angle, fixed_t distance, fixed_t slope, int damage);
283 
284 // [RH] Position the chasecam
285 void	P_AimCamera (AActor *t1);
286 extern	fixed_t CameraX, CameraY, CameraZ;
287 
288 // [RH] Means of death
289 void	P_RadiusAttack (AActor *spot, AActor *source, int damage, int distance, bool hurtSelf, int mod);
290 
291 void	P_DelSeclist(msecnode_t *);							// phares 3/16/98
292 void	P_CreateSecNodeList(AActor*,fixed_t,fixed_t);		// phares 3/14/98
293 int		P_GetMoveFactor(const AActor *mo, int *frictionp);	// phares  3/6/98
294 int		P_GetFriction(const AActor *mo, int *frictionfactor);
295 BOOL	Check_Sides(AActor *, int, int);					// phares
296 
297 
298 //
299 // P_SETUP
300 //
301 extern byte*			rejectmatrix;	// for fast sight rejection
302 extern BOOL				rejectempty;
303 extern int*				blockmaplump;	// offsets in blockmap are from here
304 extern int*				blockmap;
305 extern int				bmapwidth;
306 extern int				bmapheight; 	// in mapblocks
307 extern fixed_t			bmaporgx;
308 extern fixed_t			bmaporgy;		// origin of block map
309 extern AActor** 		blocklinks; 	// for thing chains
310 
311 extern std::set<short>	movable_sectors;
312 
313 
314 //
315 // P_INTER
316 //
317 extern int				maxammo[NUMAMMO];
318 extern int				clipammo[NUMAMMO];
319 
320 void P_GiveSpecial(player_t *player, AActor *special);
321 void P_TouchSpecialThing (AActor *special, AActor *toucher);
322 
323 void P_DamageMobj (AActor *target, AActor *inflictor, AActor *source, int damage, int mod=0, int flags=0);
324 
325 #define DMG_NO_ARMOR		1
326 
327 // [RH] Means of death flags (based on Quake2's)
328 #define MOD_UNKNOWN			0
329 #define MOD_FIST			1
330 #define MOD_PISTOL			2
331 #define MOD_SHOTGUN			3
332 #define MOD_CHAINGUN		4
333 #define MOD_ROCKET			5
334 #define MOD_R_SPLASH		6
335 #define MOD_PLASMARIFLE		7
336 #define MOD_BFG_BOOM		8
337 #define MOD_BFG_SPLASH		9
338 #define MOD_CHAINSAW		10
339 #define MOD_SSHOTGUN		11
340 #define MOD_WATER			12
341 #define MOD_SLIME			13
342 #define MOD_LAVA			14
343 #define MOD_CRUSH			15
344 #define MOD_TELEFRAG		16
345 #define MOD_FALLING			17
346 #define MOD_SUICIDE			18
347 #define MOD_BARREL			19
348 #define MOD_EXIT			20
349 #define MOD_SPLASH			21
350 #define MOD_HIT				22
351 #define MOD_RAILGUN			23
352 #define MOD_FRIENDLY_FIRE	0x80000000
353 
354 extern	int MeansOfDeath;
355 
356 //
357 // PO_MAN
358 //
359 typedef enum
360 {
361 	PODOOR_NONE,
362 	PODOOR_SLIDE,
363 	PODOOR_SWING,
364 
365 	NUMTYPES
366 } podoortype_t;
367 
368 inline FArchive &operator<< (FArchive &arc, podoortype_t type)
369 {
370 	return arc << (BYTE)type;
371 }
372 inline FArchive &operator>> (FArchive &arc, podoortype_t &out)
373 {
374 	BYTE in; arc >> in; out = (podoortype_t)in; return arc;
375 }
376 
377 class DPolyAction : public DThinker
378 {
379 	DECLARE_SERIAL (DPolyAction, DThinker)
380 public:
381 	DPolyAction (int polyNum);
382 protected:
383 	DPolyAction ();
384 	int m_PolyObj;
385 	int m_Speed;
386 	int m_Dist;
387 
388 	friend void ThrustMobj (AActor *actor, seg_t *seg, polyobj_t *po);
389 };
390 
391 class DRotatePoly : public DPolyAction
392 {
393 	DECLARE_SERIAL (DRotatePoly, DPolyAction)
394 public:
395 	DRotatePoly (int polyNum);
396 	void RunThink ();
397 protected:
398 	friend BOOL EV_RotatePoly (line_t *line, int polyNum, int speed, int byteAngle, int direction, BOOL overRide);
399 private:
400 	DRotatePoly ();
401 };
402 
403 class DMovePoly : public DPolyAction
404 {
405 	DECLARE_SERIAL (DMovePoly, DPolyAction)
406 public:
407 	DMovePoly (int polyNum);
408 	void RunThink ();
409 protected:
410 	DMovePoly ();
411 	int m_Angle;
412 	fixed_t m_xSpeed; // for sliding walls
413 	fixed_t m_ySpeed;
414 
415 	friend BOOL EV_MovePoly (line_t *line, int polyNum, int speed, angle_t angle, fixed_t dist, BOOL overRide);
416 };
417 
418 class DPolyDoor : public DMovePoly
419 {
420 	DECLARE_SERIAL (DPolyDoor, DMovePoly)
421 public:
422 	DPolyDoor (int polyNum, podoortype_t type);
423 	void RunThink ();
424 protected:
425 	int m_Direction;
426 	int m_TotalDist;
427 	int m_Tics;
428 	int m_WaitTics;
429 	podoortype_t m_Type;
430 	bool m_Close;
431 
432 	friend BOOL EV_OpenPolyDoor (line_t *line, int polyNum, int speed, angle_t angle, int delay, int distance, podoortype_t type);
433 private:
434 	DPolyDoor ();
435 };
436 
437 // [RH] Data structure for P_SpawnMapThing() to keep track
438 //		of polyobject-related things.
439 typedef struct polyspawns_s
440 {
441 	struct polyspawns_s *next;
442 	fixed_t x;
443 	fixed_t y;
444 	short angle;
445 	short type;
446 } polyspawns_t;
447 
448 enum
449 {
450 	PO_HEX_ANCHOR_TYPE = 3000,
451 	PO_HEX_SPAWN_TYPE,
452 	PO_HEX_SPAWNCRUSH_TYPE,
453 
454 	// [RH] Thing numbers that don't conflict with Doom things
455 	PO_ANCHOR_TYPE = 9300,
456 	PO_SPAWN_TYPE,
457 	PO_SPAWNCRUSH_TYPE
458 };
459 
460 #define PO_LINE_START 1 // polyobj line start special
461 #define PO_LINE_EXPLICIT 5
462 
463 extern polyobj_t *polyobjs; // list of all poly-objects on the level
464 extern int po_NumPolyobjs;
465 extern polyspawns_t *polyspawns;	// [RH] list of polyobject things to spawn
466 
467 
468 BOOL PO_MovePolyobj (int num, int x, int y);
469 BOOL PO_RotatePolyobj (int num, angle_t angle);
470 void PO_Init (void);
471 BOOL PO_Busy (int polyobj);
472 
473 //
474 // P_SPEC
475 //
476 #include "p_spec.h"
477 
478 
479 #endif	// __P_LOCAL__
480 
481 
482