1 //
2 // Copyright(C) 1993-1996 Id Software, Inc.
3 // Copyright(C) 1993-2008 Raven Software
4 // Copyright(C) 2005-2014 Simon Howard
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.  See the
14 // GNU General Public License for more details.
15 //
16 
17 // P_spec.h
18 
19 /*
20 ===============================================================================
21 
22 							P_SPEC
23 
24 ===============================================================================
25 */
26 
27 //
28 //      Animating textures and planes
29 //
30 typedef struct
31 {
32     boolean istexture;
33     int picnum;
34     int basepic;
35     int numpics;
36     int speed;
37 } anim_t;
38 
39 //
40 //      source animation definition
41 //
42 typedef struct
43 {
44     int istexture;          // if false, it's a flat
45     char endname[9];
46     char startname[9];
47     int speed;
48 } animdef_t;
49 
50 #define	MAXANIMS		32
51 
52 extern anim_t anims[MAXANIMS], *lastanim;
53 extern int *TerrainTypes;
54 
55 //
56 //      Animating line specials
57 //
58 #define	MAXLINEANIMS		64*256
59 extern short numlinespecials;
60 extern line_t *linespeciallist[MAXLINEANIMS];
61 
62 //      Define values for map objects
63 #define	MO_TELEPORTMAN		14
64 
65 // at game start
66 void P_InitPicAnims(void);
67 void P_InitTerrainTypes(void);
68 void P_InitLava(void);
69 
70 // at map load
71 void P_SpawnSpecials(void);
72 void P_InitAmbientSound(void);
73 void P_AddAmbientSfx(int sequence);
74 
75 // every tic
76 void P_UpdateSpecials(void);
77 void P_AmbientSound(void);
78 
79 // when needed
80 boolean P_UseSpecialLine(mobj_t * thing, line_t * line);
81 void P_ShootSpecialLine(mobj_t * thing, line_t * line);
82 void P_CrossSpecialLine(int linenum, int side, mobj_t * thing);
83 
84 void P_PlayerInSpecialSector(player_t * player);
85 
86 int twoSided(int sector, int line);
87 sector_t *getSector(int currentSector, int line, int side);
88 side_t *getSide(int currentSector, int line, int side);
89 fixed_t P_FindLowestFloorSurrounding(sector_t * sec);
90 fixed_t P_FindHighestFloorSurrounding(sector_t * sec);
91 fixed_t P_FindNextHighestFloor(sector_t * sec, int currentheight);
92 fixed_t P_FindLowestCeilingSurrounding(sector_t * sec);
93 fixed_t P_FindHighestCeilingSurrounding(sector_t * sec);
94 int P_FindSectorFromLineTag(line_t * line, int start);
95 int P_FindMinSurroundingLight(sector_t * sector, int max);
96 sector_t *getNextSector(line_t * line, sector_t * sec);
97 
98 //
99 //      SPECIAL
100 //
101 int EV_DoDonut(line_t * line);
102 
103 /*
104 ===============================================================================
105 
106 							P_LIGHTS
107 
108 ===============================================================================
109 */
110 typedef struct
111 {
112     thinker_t thinker;
113     sector_t *sector;
114     int count;
115     int maxlight;
116     int minlight;
117     int maxtime;
118     int mintime;
119 } lightflash_t;
120 
121 typedef struct
122 {
123     thinker_t thinker;
124     sector_t *sector;
125     int count;
126     int minlight;
127     int maxlight;
128     int darktime;
129     int brighttime;
130 } strobe_t;
131 
132 typedef struct
133 {
134     thinker_t thinker;
135     sector_t *sector;
136     int minlight;
137     int maxlight;
138     int direction;
139 } glow_t;
140 
141 #define GLOWSPEED		8
142 #define	STROBEBRIGHT	5
143 #define	FASTDARK		15
144 #define	SLOWDARK		35
145 
146 void T_LightFlash(lightflash_t * flash);
147 void P_SpawnLightFlash(sector_t * sector);
148 void T_StrobeFlash(strobe_t * flash);
149 void P_SpawnStrobeFlash(sector_t * sector, int fastOrSlow, int inSync);
150 void EV_StartLightStrobing(line_t * line);
151 void EV_TurnTagLightsOff(line_t * line);
152 void EV_LightTurnOn(line_t * line, int bright);
153 void T_Glow(glow_t * g);
154 void P_SpawnGlowingLight(sector_t * sector);
155 
156 /*
157 ===============================================================================
158 
159 							P_SWITCH
160 
161 ===============================================================================
162 */
163 typedef struct
164 {
165     char name1[9];
166     char name2[9];
167     short episode;
168 } switchlist_t;
169 
170 typedef enum
171 {
172     top,
173     middle,
174     bottom
175 } bwhere_e;
176 
177 typedef struct
178 {
179     line_t *line;
180     bwhere_e where;
181     int btexture;
182     int btimer;
183     void *soundorg;
184 } button_t;
185 
186 #define	MAXSWITCHES	50      // max # of wall switches in a level
187 #define	MAXBUTTONS	16      // 4 players, 4 buttons each at once, max.
188 #define BUTTONTIME	35      // 1 second
189 
190 extern button_t buttonlist[MAXBUTTONS];
191 
192 void P_ChangeSwitchTexture(line_t * line, int useAgain);
193 void P_InitSwitchList(void);
194 
195 /*
196 ===============================================================================
197 
198 							P_PLATS
199 
200 ===============================================================================
201 */
202 typedef enum
203 {
204     up,
205     down,
206     waiting,
207     in_stasis
208 } plat_e;
209 
210 typedef enum
211 {
212     perpetualRaise,
213     downWaitUpStay,
214     raiseAndChange,
215     raiseToNearestAndChange
216 } plattype_e;
217 
218 typedef struct
219 {
220     thinker_t thinker;
221     sector_t *sector;
222     fixed_t speed;
223     fixed_t low;
224     fixed_t high;
225     int wait;
226     int count;
227     plat_e status;
228     plat_e oldstatus;
229     boolean crush;
230     int tag;
231     plattype_e type;
232 } plat_t;
233 
234 #define	PLATWAIT	3
235 #define	PLATSPEED	FRACUNIT
236 #define	MAXPLATS	30*256
237 
238 extern plat_t *activeplats[MAXPLATS];
239 
240 void T_PlatRaise(plat_t * plat);
241 int EV_DoPlat(line_t * line, plattype_e type, int amount);
242 void P_AddActivePlat(plat_t * plat);
243 void P_RemoveActivePlat(plat_t * plat);
244 void EV_StopPlat(line_t * line);
245 void P_ActivateInStasis(int tag);
246 
247 /*
248 ===============================================================================
249 
250 							P_DOORS
251 
252 ===============================================================================
253 */
254 typedef enum
255 {
256     vld_normal,
257     vld_close30ThenOpen,
258     vld_close,
259     vld_open,
260     vld_raiseIn5Mins
261 } vldoor_e;
262 
263 typedef struct
264 {
265     thinker_t thinker;
266     vldoor_e type;
267     sector_t *sector;
268     fixed_t topheight;
269     fixed_t speed;
270     int direction;              // 1 = up, 0 = waiting at top, -1 = down
271     int topwait;                // tics to wait at the top
272     // (keep in case a door going down is reset)
273     int topcountdown;           // when it reaches 0, start going down
274 } vldoor_t;
275 
276 #define	VDOORSPEED	FRACUNIT*2
277 #define	VDOORWAIT		150
278 
279 void EV_VerticalDoor(line_t * line, mobj_t * thing);
280 int EV_DoDoor(line_t * line, vldoor_e type, fixed_t speed);
281 void T_VerticalDoor(vldoor_t * door);
282 void P_SpawnDoorCloseIn30(sector_t * sec);
283 void P_SpawnDoorRaiseIn5Mins(sector_t * sec, int secnum);
284 
285 /*
286 ===============================================================================
287 
288 							P_CEILNG
289 
290 ===============================================================================
291 */
292 typedef enum
293 {
294     lowerToFloor,
295     raiseToHighest,
296     lowerAndCrush,
297     crushAndRaise,
298     fastCrushAndRaise
299 } ceiling_e;
300 
301 typedef struct
302 {
303     thinker_t thinker;
304     ceiling_e type;
305     sector_t *sector;
306     fixed_t bottomheight, topheight;
307     fixed_t speed;
308     boolean crush;
309     int direction;              // 1 = up, 0 = waiting, -1 = down
310     int tag;                    // ID
311     int olddirection;
312 } ceiling_t;
313 
314 #define	CEILSPEED		FRACUNIT
315 #define	CEILWAIT		150
316 #define MAXCEILINGS		30
317 
318 extern ceiling_t *activeceilings[MAXCEILINGS];
319 
320 int EV_DoCeiling(line_t * line, ceiling_e type);
321 void T_MoveCeiling(ceiling_t * ceiling);
322 void P_AddActiveCeiling(ceiling_t * c);
323 void P_RemoveActiveCeiling(ceiling_t * c);
324 int EV_CeilingCrushStop(line_t * line);
325 void P_ActivateInStasisCeiling(line_t * line);
326 
327 /*
328 ===============================================================================
329 
330 							P_FLOOR
331 
332 ===============================================================================
333 */
334 typedef enum
335 {
336     lowerFloor,                 // lower floor to highest surrounding floor
337     lowerFloorToLowest,         // lower floor to lowest surrounding floor
338     turboLower,                 // lower floor to highest surrounding floor VERY FAST
339     raiseFloor,                 // raise floor to lowest surrounding CEILING
340     raiseFloorToNearest,        // raise floor to next highest surrounding floor
341     raiseToTexture,             // raise floor to shortest height texture around it
342     lowerAndChange,             // lower floor to lowest surrounding floor and change
343     // floorpic
344     raiseFloor24,
345     raiseFloor24AndChange,
346     raiseFloorCrush,
347     donutRaise,
348     raiseBuildStep              // One step of a staircase
349 } floor_e;
350 
351 typedef struct
352 {
353     thinker_t thinker;
354     floor_e type;
355     boolean crush;
356     sector_t *sector;
357     int direction;
358     int newspecial;
359     short texture;
360     fixed_t floordestheight;
361     fixed_t speed;
362 } floormove_t;
363 
364 #define	FLOORSPEED	FRACUNIT
365 
366 typedef enum
367 {
368     ok,
369     crushed,
370     pastdest
371 } result_e;
372 
373 result_e T_MovePlane(sector_t * sector, fixed_t speed,
374                      fixed_t dest, boolean crush, int floorOrCeiling,
375                      int direction);
376 
377 int EV_BuildStairs(line_t * line, fixed_t stepDelta);
378 int EV_DoFloor(line_t * line, floor_e floortype);
379 void T_MoveFloor(floormove_t * floor);
380 
381 /*
382 ===============================================================================
383 
384 							P_TELEPT
385 
386 ===============================================================================
387 */
388 
389 boolean P_Teleport(mobj_t * thing, fixed_t x, fixed_t y, angle_t angle);
390 boolean EV_Teleport(line_t * line, int side, mobj_t * thing);
391