Debian Codegraph @

prboom2/src/p_spec.c

raw
1 /* Emacs style mode select -*- C -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
5 * PrBoom: a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2000 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11 * Copyright 2005, 2006 by
12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 * 02111-1307, USA.
28 *
29 * DESCRIPTION:
30 * -Loads and initializes texture and flat animation sequences
31 * -Implements utility functions for all linedef/sector special handlers
32 * -Dispatches walkover and gun line triggers
33 * -Initializes and implements special sector types
34 * -Implements donut linedef triggers
35 * -Initializes and implements BOOM linedef triggers for
36 * Scrollers/Conveyors
37 * Friction
38 * Wind/Current
39 *
40 *-----------------------------------------------------------------------------*/
41
42 #include "doomstat.h"
43 #include "p_spec.h"
44 #include "p_tick.h"
45 #include "p_setup.h"
46 #include "m_random.h"
47 #include "d_englsh.h"
48 #include "w_wad.h"
49 #include "r_main.h"
50 #include "p_maputl.h"
51 #include "p_map.h"
52 #include "p_user.h"
53 #include "g_game.h"
54 #include "p_inter.h"
55 #include "p_enemy.h"
56 #include "s_sound.h"
57 #include "sounds.h"
58 #include "i_sound.h"
59 #include "m_bbox.h" // phares 3/20/98
60 #include "d_deh.h"
61 #include "r_plane.h"
62 #include "hu_stuff.h"
63 #include "lprintf.h"
64 #include "e6y.h"//e6y
65
66 #include "dsda.h"
67 #include "dsda/args.h"
68 #include "dsda/configuration.h"
69 #include "dsda/global.h"
70 #include "dsda/id_list.h"
71 #include "dsda/line_special.h"
72 #include "dsda/map_format.h"
73 #include "dsda/mapinfo.h"
74 #include "dsda/messenger.h"
75 #include "dsda/scroll.h"
76 #include "dsda/thing_id.h"
77 #include "dsda/utility.h"
78
79 //
80 // source animation definition
81 //
82 //
83 #ifdef _MSC_VER // proff: This is the same as __attribute__ ((packed)) in GNUC
84 #pragma pack(push)
85 #pragma pack(1)
86 #endif //_MSC_VER
87
88 #if defined(__MWERKS__)
89 #pragma options align=packed
90 #endif
91
92 typedef struct
93 {
94 signed char istexture; //jff 3/23/98 make char for comparison // cph - make signed
95 char endname[9]; // if false, it is a flat
96 char startname[9];
97 int speed;
98 } PACKEDATTR animdef_t; //jff 3/23/98 pack to read from memory
99
100 #if defined(__MWERKS__)
101 #pragma options align=reset
102 #endif
103
104 #ifdef _MSC_VER
105 #pragma pack(pop)
106 #endif //_MSC_VER
107
108 #define MAXANIMS 32 // no longer a strict limit -- killough
109
110 static anim_t* lastanim;
111 static anim_t* anims; // new structure w/o limits -- killough
112 static size_t maxanims;
113
114 // killough 3/7/98: Initialize generalized scrolling
115 static void P_SpawnScrollers(void);
116
117 static void P_SpawnFriction(void); // phares 3/16/98
118 static void P_SpawnPushers(void); // phares 3/20/98
119
120 static const animdef_t heretic_animdefs[] = {
121 // false = flat
122 // true = texture
123 { false, "FLTWAWA3", "FLTWAWA1", 8 }, // Water
124 { false, "FLTSLUD3", "FLTSLUD1", 8 }, // Sludge
125 { false, "FLTTELE4", "FLTTELE1", 6 }, // Teleport
126 { false, "FLTFLWW3", "FLTFLWW1", 9 }, // River - West
127 { false, "FLTLAVA4", "FLTLAVA1", 8 }, // Lava
128 { false, "FLATHUH4", "FLATHUH1", 8 }, // Super Lava
129 { true, "LAVAFL3", "LAVAFL1", 6 }, // Texture: Lavaflow
130 { true, "WATRWAL3", "WATRWAL1", 4 }, // Texture: Waterfall
131 { -1 }
132 };
133
134 // heretic
135 #define MAXLINEANIMS 64*256
136 short numlinespecials;
137 line_t *linespeciallist[MAXLINEANIMS];
138
139 //e6y
140 void MarkAnimatedTextures(void)
141 {
142 anim_t* anim;
143
144 anim_textures = Z_Calloc(numtextures, sizeof(TAnimItemParam));
145 anim_flats = Z_Calloc(numflats, sizeof(TAnimItemParam));
146
147 for (anim = anims ; anim < lastanim ; anim++)
148 {
149 int i;
150 for (i = 0; i < anim->numpics ; i++)
151 {
152 if (anim->istexture)
153 {
154 anim_textures[anim->basepic + i].anim = anim;
155 anim_textures[anim->basepic + i].index = i + 1;
156 }
157 else
158 {
159 anim_flats[anim->basepic + i].anim = anim;
160 anim_flats[anim->basepic + i].index = i + 1;
161 }
162 }
163 }
164 }
165
166 //
167 // P_InitPicAnims
168 //
169 // Load the table of animation definitions, checking for existence of
170 // the start and end of each frame. If the start doesn't exist the sequence
171 // is skipped, if the last doesn't exist, BOOM exits.
172 //
173 // Wall/Flat animation sequences, defined by name of first and last frame,
174 // The full animation sequence is given using all lumps between the start
175 // and end entry, in the order found in the WAD file.
176 //
177 // This routine modified to read its data from a predefined lump or
178 // PWAD lump called ANIMATED rather than a static table in this module to
179 // allow wad designers to insert or modify animation sequences.
180 //
181 // Lump format is an array of byte packed animdef_t structures, terminated
182 // by a structure with istexture == -1. The lump can be generated from a
183 // text source file using SWANTBLS.EXE, distributed with the BOOM utils.
184 // The standard list of switches and animations is contained in the example
185 // source text file DEFSWANI.DAT also in the BOOM util distribution.
186 //
187 //
188 void P_InitPicAnims (void)
189 {
190 int i;
191 const animdef_t *animdefs; //jff 3/23/98 pointer to animation lump
192 int lump = -1;
193 // Init animation
194
195 if (map_format.animdefs)
196 {
197 MarkAnimatedTextures();//e6y
198 return;
199 }
200
201 if (heretic)
202 {
203 lump = W_CheckNumForName("ANIMATED");
204
205 if (lump != LUMP_NOT_FOUND && lumpinfo[lump].source != source_auto_load)
206 animdefs = (const animdef_t *) W_LumpByNum(lump);
207 else
208 animdefs = heretic_animdefs;
209 }
210 else
211 {
212 lump = W_GetNumForName("ANIMATED"); // cph - new wad lump handling
213 //jff 3/23/98 read from predefined or wad lump instead of table
214 animdefs = (const animdef_t *)W_LumpByNum(lump);
215 }
216
217 lastanim = anims;
218 for (i=0 ; animdefs[i].istexture != -1 ; i++)
219 {
220 // 1/11/98 killough -- removed limit by array-doubling
221 if (lastanim >= anims + maxanims)
222 {
223 size_t newmax = maxanims ? maxanims*2 : MAXANIMS;
224 anims = Z_Realloc(anims, newmax*sizeof(*anims)); // killough
225 lastanim = anims + maxanims;
226 maxanims = newmax;
227 }
228
229 if (animdefs[i].istexture)
230 {
231 // different episode ?
232 if (R_CheckTextureNumForName(animdefs[i].startname) == -1)
233 continue;
234
235 lastanim->picnum = R_TextureNumForName (animdefs[i].endname);
236 lastanim->basepic = R_TextureNumForName (animdefs[i].startname);
237 }
238 else
239 {
240 if (!W_LumpNameExists2(animdefs[i].startname, ns_flats)) // killough 4/17/98
241 continue;
242
243 lastanim->picnum = R_FlatNumForName (animdefs[i].endname);
244 lastanim->basepic = R_FlatNumForName (animdefs[i].startname);
245 }
246
247 lastanim->istexture = animdefs[i].istexture;
248 lastanim->numpics = lastanim->picnum - lastanim->basepic + 1;
249 lastanim->speed = LittleLong(animdefs[i].speed);
250
251 // [crispy] skip reading SMMU swirling flats
252 if (lastanim->speed < 65536 && lastanim->numpics != 1)
253 {
254 if (lastanim->numpics < 2)
255 I_Error ("P_InitPicAnims: bad cycle from %s to %s",
256 animdefs[i].startname,
257 animdefs[i].endname);
258 }
259
260 if (lastanim->speed == 0)
261 I_Error ("P_InitPicAnims: %s to %s animation cannot have speed 0",
262 animdefs[i].startname,
263 animdefs[i].endname);
264
265 lastanim++;
266 }
267
268 MarkAnimatedTextures();//e6y
269 }
270
271 ///////////////////////////////////////////////////////////////
272 //
273 // Linedef and Sector Special Implementation Utility Functions
274 //
275 ///////////////////////////////////////////////////////////////
276
277 //
278 // getSide()
279 //
280 // Will return a side_t*
281 // given the number of the current sector,
282 // the line number, and the side (0/1) that you want.
283 //
284 // Note: if side=1 is specified, it must exist or results undefined
285 //
286 side_t* getSide
287 ( int currentSector,
288 int line,
289 int side )
290 {
291 return &sides[ (sectors[currentSector].lines[line])->sidenum[side] ];
292 }
293
294
295 //
296 // getSector()
297 //
298 // Will return a sector_t*
299 // given the number of the current sector,
300 // the line number and the side (0/1) that you want.
301 //
302 // Note: if side=1 is specified, it must exist or results undefined
303 //
304 sector_t* getSector
305 ( int currentSector,
306 int line,
307 int side )
308 {
309 return sides[ (sectors[currentSector].lines[line])->sidenum[side] ].sector;
310 }
311
312
313 //
314 // twoSided()
315 //
316 // Given the sector number and the line number,
317 // it will tell you whether the line is two-sided or not.
318 //
319 // modified to return actual two-sidedness rather than presence
320 // of 2S flag unless compatibility optioned
321 //
322 int twoSided
323 ( int sector,
324 int line )
325 {
326 //jff 1/26/98 return what is actually needed, whether the line
327 //has two sidedefs, rather than whether the 2S flag is set
328
329 return (comp[comp_model]) ?
330 (sectors[sector].lines[line])->flags & ML_TWOSIDED
331 :
332 (sectors[sector].lines[line])->sidenum[1] != NO_INDEX;
333 }
334
335
336 //
337 // getNextSector()
338 //
339 // Return sector_t * of sector next to current across line.
340 //
341 // Note: returns NULL if not two-sided line, or both sides refer to sector
342 //
343 sector_t* getNextSector
344 ( line_t* line,
345 sector_t* sec )
346 {
347 //jff 1/26/98 check unneeded since line->backsector already
348 //returns NULL if the line is not two sided, and does so from
349 //the actual two-sidedness of the line, rather than its 2S flag
350
351 if (comp[comp_model])
352 {
353 if (!(line->flags & ML_TWOSIDED))
354 return NULL;
355 }
356
357 if (line->frontsector == sec) {
358 if (comp[comp_model] || line->backsector!=sec)
359 return line->backsector; //jff 5/3/98 don't retn sec unless compatibility
360 else // fixes an intra-sector line breaking functions
361 return NULL; // like floor->highest floor
362 }
363 return line->frontsector;
364 }
365
366
367 //
368 // P_FindLowestFloorSurrounding()
369 //
370 // Returns the fixed point value of the lowest floor height
371 // in the sector passed or its surrounding sectors.
372 //
373 fixed_t P_FindLowestFloorSurrounding(sector_t* sec)
374 {
375 int i;
376 line_t* check;
377 sector_t* other;
378 fixed_t floor = sec->floorheight;
379
380 for (i=0 ;i < sec->linecount ; i++)
381 {
382 check = sec->lines[i];
383 other = getNextSector(check,sec);
384
385 if (!other)
386 continue;
387
388 if (other->floorheight < floor)
389 floor = other->floorheight;
390 }
391 return floor;
392 }
393
394
395 //
396 // P_FindHighestFloorSurrounding()
397 //
398 // Passed a sector, returns the fixed point value of the largest
399 // floor height in the surrounding sectors, not including that passed
400 //
401 // NOTE: if no surrounding sector exists -32000*FRACUINT is returned
402 // if compatibility then -500*FRACUNIT is the smallest return possible
403 //
404 fixed_t P_FindHighestFloorSurrounding(sector_t *sec)
405 {
406 int i;
407 line_t* check;
408 sector_t* other;
409 fixed_t floor = -500*FRACUNIT;
410
411 //jff 1/26/98 Fix initial value for floor to not act differently
412 //in sections of wad that are below -500 units
413 if (!comp[comp_model]) /* jff 3/12/98 avoid ovf */
414 floor = -32000*FRACUNIT; // in height calculations
415
416 for (i=0 ;i < sec->linecount ; i++)
417 {
418 check = sec->lines[i];
419 other = getNextSector(check,sec);
420
421 if (!other)
422 continue;
423
424 if (other->floorheight > floor)
425 floor = other->floorheight;
426 }
427 return floor;
428 }
429
430
431 //
432 // P_FindNextHighestFloor()
433 //
434 // Passed a sector and a floor height, returns the fixed point value
435 // of the smallest floor height in a surrounding sector larger than
436 // the floor height passed. If no such height exists the floorheight
437 // passed is returned.
438 //
439 // Rewritten by Lee Killough to avoid fixed array and to be faster
440 //
441 fixed_t P_FindNextHighestFloor(sector_t *sec, int currentheight)
442 {
443 sector_t *other;
444 int i;
445
446 // e6y
447 // Original P_FindNextHighestFloor() is restored for demo_compatibility
448 // Adapted for prboom's complevels
449 if (demo_compatibility && !prboom_comp[PC_FORCE_BOOM_FINDNEXTHIGHESTFLOOR].state)
450 {
451 int h;
452 int min;
453 static int MAX_ADJOINING_SECTORS = 0;
454 static fixed_t *heightlist = NULL;
455 static int heightlist_size = 0;
456 line_t* check;
457 fixed_t height = currentheight;
458 static fixed_t last_height_0 = 0;
459
460 // 20 adjoining sectors max!
461 if (!MAX_ADJOINING_SECTORS)
462 MAX_ADJOINING_SECTORS = dsda_Flag(dsda_arg_doom95) ? 500 : 20;
463
464 if (sec->linecount > heightlist_size)
465 {
466 do
467 {
468 heightlist_size = heightlist_size ? heightlist_size * 2 : 128;
469 } while (sec->linecount > heightlist_size);
470 heightlist = Z_Realloc(heightlist, heightlist_size * sizeof(heightlist[0]));
471 }
472
473 for (i=0, h=0 ;i < sec->linecount ; i++)
474 {
475 check = sec->lines[i];
476 other = getNextSector(check,sec);
477
478 if (!other)
479 continue;
480
481 if (other->floorheight > height)
482 {
483 // e6y
484 // Emulation of stack overflow.
485 // 20: overflow affects nothing - just a luck;
486 // 21: can be emulated;
487 // 22..26: overflow affects saved registers - unpredictable behaviour, can crash;
488 // 27: overflow affects return address - crash with high probability;
489 if (compatibility_level < dosdoom_compatibility && h >= MAX_ADJOINING_SECTORS)
490 {
491 if (h == MAX_ADJOINING_SECTORS + 1)
492 height = other->floorheight;
493
494 // 20 & 21 are common and not "warning" worthy
495 if (h > MAX_ADJOINING_SECTORS + 1)
496 {
497 lprintf(LO_WARN, "P_FindNextHighestFloor: Overflow of heightlist[%d] array is detected.\n", MAX_ADJOINING_SECTORS);
498 lprintf(LO_WARN, " Sector %d, line %d, heightlist index %d: ", sec->iSectorID, sec->lines[i]->iLineID, h);
499
500 if (h <= MAX_ADJOINING_SECTORS + 6)
501 lprintf(LO_WARN, "cannot be emulated - unpredictable behaviour.\n");
502 else
503 lprintf(LO_WARN, "cannot be emulated - crash with high probability.\n");
504 }
505 }
506 heightlist[h++] = other->floorheight;
507 }
508
509 // Check for overflow. Warning.
510 if (compatibility_level >= dosdoom_compatibility && h >= MAX_ADJOINING_SECTORS)
511 {
512 lprintf( LO_WARN, "Sector with more than 20 adjoining sectors\n" );
513 break;
514 }
515 }
516
517 // Find lowest height in list
518 if (!h)
519 {
520 // cph - my guess at doom v1.2 - 1.4beta compatibility here.
521 // If there are no higher neighbouring sectors, Heretic just returned
522 // heightlist[0] (local variable), i.e. noise off the stack. 0 is right for
523 // RETURN01 E1M2, so let's take that.
524 //
525 // SmileTheory's response:
526 // It's not *quite* random stack noise. If this function is called
527 // as part of a loop, heightlist will be at the same location as in
528 // the previous call. Doing it this way fixes 1_ON_1.WAD.
529 return (compatibility_level < doom_1666_compatibility ? last_height_0 : currentheight);
530 }
531
532 last_height_0 = heightlist[0];
533 min = heightlist[0];
534
535 // Range checking?
536 for (i = 1;i < h;i++)
537 {
538 if (heightlist[i] < min)
539 min = heightlist[i];
540 }
541
542 return min;
543 }
544
545
546 for (i=0 ;i < sec->linecount ; i++)
547 if ((other = getNextSector(sec->lines[i],sec)) &&
548 other->floorheight > currentheight)
549 {
550 int height = other->floorheight;
551 while (++i < sec->linecount)
552 if ((other = getNextSector(sec->lines[i],sec)) &&
553 other->floorheight < height &&
554 other->floorheight > currentheight)
555 height = other->floorheight;
556 return height;
557 }
558 /* cph - my guess at doom v1.2 - 1.4beta compatibility here.
559 * If there are no higher neighbouring sectors, Heretic just returned
560 * heightlist[0] (local variable), i.e. noise off the stack. 0 is right for
561 * RETURN01 E1M2, so let's take that. */
562 return (compatibility_level < doom_1666_compatibility ? 0 : currentheight);
563 }
564
565
566 //
567 // P_FindNextLowestFloor()
568 //
569 // Passed a sector and a floor height, returns the fixed point value
570 // of the largest floor height in a surrounding sector smaller than
571 // the floor height passed. If no such height exists the floorheight
572 // passed is returned.
573 //
574 // jff 02/03/98 Twiddled Lee's P_FindNextHighestFloor to make this
575 //
576 fixed_t P_FindNextLowestFloor(sector_t *sec, int currentheight)
577 {
578 sector_t *other;
579 int i;
580
581 for (i=0 ;i < sec->linecount ; i++)
582 if ((other = getNextSector(sec->lines[i],sec)) &&
583 other->floorheight < currentheight)
584 {
585 int height = other->floorheight;
586 while (++i < sec->linecount)
587 if ((other = getNextSector(sec->lines[i],sec)) &&
588 other->floorheight > height &&
589 other->floorheight < currentheight)
590 height = other->floorheight;
591 return height;
592 }
593 return currentheight;
594 }
595
596
597 //
598 // P_FindNextLowestCeiling()
599 //
600 // Passed a sector and a ceiling height, returns the fixed point value
601 // of the largest ceiling height in a surrounding sector smaller than
602 // the ceiling height passed. If no such height exists the ceiling height
603 // passed is returned.
604 //
605 // jff 02/03/98 Twiddled Lee's P_FindNextHighestFloor to make this
606 //
607 fixed_t P_FindNextLowestCeiling(sector_t *sec, int currentheight)
608 {
609 sector_t *other;
610 int i;
611
612 for (i=0 ;i < sec->linecount ; i++)
613 if ((other = getNextSector(sec->lines[i],sec)) &&
614 other->ceilingheight < currentheight)
615 {
616 int height = other->ceilingheight;
617 while (++i < sec->linecount)
618 if ((other = getNextSector(sec->lines[i],sec)) &&
619 other->ceilingheight > height &&
620 other->ceilingheight < currentheight)
621 height = other->ceilingheight;
622 return height;
623 }
624 return currentheight;
625 }
626
627
628 //
629 // P_FindNextHighestCeiling()
630 //
631 // Passed a sector and a ceiling height, returns the fixed point value
632 // of the smallest ceiling height in a surrounding sector larger than
633 // the ceiling height passed. If no such height exists the ceiling height
634 // passed is returned.
635 //
636 // jff 02/03/98 Twiddled Lee's P_FindNextHighestFloor to make this
637 //
638 fixed_t P_FindNextHighestCeiling(sector_t *sec, int currentheight)
639 {
640 sector_t *other;
641 int i;
642
643 for (i=0 ;i < sec->linecount ; i++)
644 if ((other = getNextSector(sec->lines[i],sec)) &&
645 other->ceilingheight > currentheight)
646 {
647 int height = other->ceilingheight;
648 while (++i < sec->linecount)
649 if ((other = getNextSector(sec->lines[i],sec)) &&
650 other->ceilingheight < height &&
651 other->ceilingheight > currentheight)
652 height = other->ceilingheight;
653 return height;
654 }
655 return currentheight;
656 }
657
658
659 //
660 // P_FindLowestCeilingSurrounding()
661 //
662 // Passed a sector, returns the fixed point value of the smallest
663 // ceiling height in the surrounding sectors, not including that passed
664 //
665 // NOTE: if no surrounding sector exists 32000*FRACUINT is returned
666 // but if compatibility then INT_MAX is the return
667 //
668 fixed_t P_FindLowestCeilingSurrounding(sector_t* sec)
669 {
670 int i;
671 line_t* check;
672 sector_t* other;
673 fixed_t height = INT_MAX;
674
675 /* jff 3/12/98 avoid ovf in height calculations */
676 if (!comp[comp_model]) height = 32000*FRACUNIT;
677
678 for (i=0 ;i < sec->linecount ; i++)
679 {
680 check = sec->lines[i];
681 other = getNextSector(check,sec);
682
683 if (!other)
684 continue;
685
686 if (other->ceilingheight < height)
687 height = other->ceilingheight;
688 }
689 return height;
690 }
691
692
693 //
694 // P_FindHighestCeilingSurrounding()
695 //
696 // Passed a sector, returns the fixed point value of the largest
697 // ceiling height in the surrounding sectors, not including that passed
698 //
699 // NOTE: if no surrounding sector exists -32000*FRACUINT is returned
700 // but if compatibility then 0 is the smallest return possible
701 //
702 fixed_t P_FindHighestCeilingSurrounding(sector_t* sec)
703 {
704 int i;
705 line_t* check;
706 sector_t* other;
707 fixed_t height = 0;
708
709 /* jff 1/26/98 Fix initial value for floor to not act differently
710 * in sections of wad that are below 0 units
711 * jff 3/12/98 avoid ovf in height calculations */
712 if (!comp[comp_model]) height = -32000*FRACUNIT;
713
714 for (i=0 ;i < sec->linecount ; i++)
715 {
716 check = sec->lines[i];
717 other = getNextSector(check,sec);
718
719 if (!other)
720 continue;
721
722 if (other->ceilingheight > height)
723 height = other->ceilingheight;
724 }
725 return height;
726 }
727
728
729 //
730 // P_FindShortestTextureAround()
731 //
732 // Passed a sector number, returns the shortest lower texture on a
733 // linedef bounding the sector.
734 //
735 // Note: If no lower texture exists 32000*FRACUNIT is returned.
736 // but if compatibility then INT_MAX is returned
737 //
738 // jff 02/03/98 Add routine to find shortest lower texture
739 //
740 fixed_t P_FindShortestTextureAround(int secnum)
741 {
742 int minsize = INT_MAX;
743 side_t* side;
744 int i;
745 sector_t *sec = &sectors[secnum];
746
747 if (!comp[comp_model])
748 minsize = 32000<<FRACBITS; //jff 3/13/98 prevent overflow in height calcs
749
750 for (i = 0; i < sec->linecount; i++)
751 {
752 if (twoSided(secnum, i))
753 {
754 side = getSide(secnum,i,0);
755 if (side->bottomtexture > 0) //jff 8/14/98 texture 0 is a placeholder
756 if (textureheight[side->bottomtexture] < minsize)
757 minsize = textureheight[side->bottomtexture];
758 side = getSide(secnum,i,1);
759 if (side->bottomtexture > 0) //jff 8/14/98 texture 0 is a placeholder
760 if (textureheight[side->bottomtexture] < minsize)
761 minsize = textureheight[side->bottomtexture];
762 }
763 }
764 return minsize;
765 }
766
767
768 //
769 // P_FindShortestUpperAround()
770 //
771 // Passed a sector number, returns the shortest upper texture on a
772 // linedef bounding the sector.
773 //
774 // Note: If no upper texture exists 32000*FRACUNIT is returned.
775 // but if compatibility then INT_MAX is returned
776 //
777 // jff 03/20/98 Add routine to find shortest upper texture
778 //
779 fixed_t P_FindShortestUpperAround(int secnum)
780 {
781 int minsize = INT_MAX;
782 side_t* side;
783 int i;
784 sector_t *sec = &sectors[secnum];
785
786 if (!comp[comp_model])
787 minsize = 32000<<FRACBITS; //jff 3/13/98 prevent overflow
788 // in height calcs
789 for (i = 0; i < sec->linecount; i++)
790 {
791 if (twoSided(secnum, i))
792 {
793 side = getSide(secnum,i,0);
794 if (side->toptexture > 0) //jff 8/14/98 texture 0 is a placeholder
795 if (textureheight[side->toptexture] < minsize)
796 minsize = textureheight[side->toptexture];
797 side = getSide(secnum,i,1);
798 if (side->toptexture > 0) //jff 8/14/98 texture 0 is a placeholder
799 if (textureheight[side->toptexture] < minsize)
800 minsize = textureheight[side->toptexture];
801 }
802 }
803 return minsize;
804 }
805
806
807 //
808 // P_FindModelFloorSector()
809 //
810 // Passed a floor height and a sector number, return a pointer to a
811 // a sector with that floor height across the lowest numbered two sided
812 // line surrounding the sector.
813 //
814 // Note: If no sector at that height bounds the sector passed, return NULL
815 //
816 // jff 02/03/98 Add routine to find numeric model floor
817 // around a sector specified by sector number
818 // jff 3/14/98 change first parameter to plain height to allow call
819 // from routine not using floormove_t
820 //
821 sector_t *P_FindModelFloorSector(fixed_t floordestheight,int secnum)
822 {
823 int i;
824 sector_t *sec=NULL;
825 int linecount;
826
827 sec = &sectors[secnum]; //jff 3/2/98 woops! better do this
828 //jff 5/23/98 don't disturb sec->linecount while searching
829 // but allow early exit in old demos
830 linecount = sec->linecount;
831 for (i = 0; i < (demo_compatibility && sec->linecount<linecount?
832 sec->linecount : linecount); i++)
833 {
834 if ( twoSided(secnum, i) )
835 {
836 if (getSide(secnum,i,0)->sector->iSectorID == secnum)
837 sec = getSector(secnum,i,1);
838 else
839 sec = getSector(secnum,i,0);
840
841 if (heretic || sec->floorheight == floordestheight)
842 return sec;
843 }
844 }
845 return NULL;
846 }
847
848
849 //
850 // P_FindModelCeilingSector()
851 //
852 // Passed a ceiling height and a sector number, return a pointer to a
853 // a sector with that ceiling height across the lowest numbered two sided
854 // line surrounding the sector.
855 //
856 // Note: If no sector at that height bounds the sector passed, return NULL
857 //
858 // jff 02/03/98 Add routine to find numeric model ceiling
859 // around a sector specified by sector number
860 // used only from generalized ceiling types
861 // jff 3/14/98 change first parameter to plain height to allow call
862 // from routine not using ceiling_t
863 //
864 sector_t *P_FindModelCeilingSector(fixed_t ceildestheight,int secnum)
865 {
866 int i;
867 sector_t *sec=NULL;
868 int linecount;
869
870 sec = &sectors[secnum]; //jff 3/2/98 woops! better do this
871 //jff 5/23/98 don't disturb sec->linecount while searching
872 // but allow early exit in old demos
873 linecount = sec->linecount;
874 for (i = 0; i < (demo_compatibility && sec->linecount<linecount?
875 sec->linecount : linecount); i++)
876 {
877 if ( twoSided(secnum, i) )
878 {
879 if (getSide(secnum,i,0)->sector->iSectorID == secnum)
880 sec = getSector(secnum,i,1);
881 else
882 sec = getSector(secnum,i,0);
883
884 if (sec->ceilingheight == ceildestheight)
885 return sec;
886 }
887 }
888 return NULL;
889 }
890
891 // Converts Hexen's 0 (meaning no crush) to the internal value
892 int P_ConvertHexenCrush(int crush)
893 {
894 return (crush ? crush : NO_CRUSH);
895 }
896
897 //
898 // P_FindMinSurroundingLight()
899 //
900 // Passed a sector and a light level, returns the smallest light level
901 // in a surrounding sector less than that passed. If no smaller light
902 // level exists, the light level passed is returned.
903 //
904 int P_FindMinSurroundingLight
905 ( sector_t* sector,
906 int max )
907 {
908 int i;
909 int min;
910 line_t* line;
911 sector_t* check;
912
913 min = max;
914 for (i=0 ; i < sector->linecount ; i++)
915 {
916 line = sector->lines[i];
917 check = getNextSector(line,sector);
918
919 if (!check)
920 continue;
921
922 if (check->lightlevel < min)
923 min = check->lightlevel;
924 }
925 return min;
926 }
927
928
929 //
930 // P_CanUnlockGenDoor()
931 //
932 // Passed a generalized locked door linedef and a player, returns whether
933 // the player has the keys necessary to unlock that door.
934 //
935 // Note: The linedef passed MUST be a generalized locked door type
936 // or results are undefined.
937 //
938 // jff 02/05/98 routine added to test for unlockability of
939 // generalized locked doors
940 //
941 dboolean P_CanUnlockGenDoor
942 ( line_t* line,
943 player_t* player)
944 {
945 // does this line special distinguish between skulls and keys?
946 int skulliscard = (line->special & LockedNKeys)>>LockedNKeysShift;
947
948 // determine for each case of lock type if player's keys are adequate
949 switch((line->special & LockedKey)>>LockedKeyShift)
950 {
951 case AnyKey:
952 if
953 (
954 !player->cards[it_redcard] &&
955 !player->cards[it_redskull] &&
956 !player->cards[it_bluecard] &&
957 !player->cards[it_blueskull] &&
958 !player->cards[it_yellowcard] &&
959 !player->cards[it_yellowskull]
960 )
961 {
962 dsda_AddPlayerMessage(s_PD_ANY, player);
963 S_StartMobjSound(player->mo,sfx_oof); // killough 3/20/98
964 return false;
965 }
966 break;
967 case RCard:
968 if
969 (
970 !player->cards[it_redcard] &&
971 (!skulliscard || !player->cards[it_redskull])
972 )
973 {
974 dsda_AddPlayerMessage(skulliscard ? s_PD_REDK : s_PD_REDC, player);
975 S_StartMobjSound(player->mo,sfx_oof); // killough 3/20/98
976 return false;
977 }
978 break;
979 case BCard:
980 if
981 (
982 !player->cards[it_bluecard] &&
983 (!skulliscard || !player->cards[it_blueskull])
984 )
985 {
986 dsda_AddPlayerMessage(skulliscard ? s_PD_BLUEK : s_PD_BLUEC, player);
987 S_StartMobjSound(player->mo,sfx_oof); // killough 3/20/98
988 return false;
989 }
990 break;
991 case YCard:
992 if
993 (
994 !player->cards[it_yellowcard] &&
995 (!skulliscard || !player->cards[it_yellowskull])
996 )
997 {
998 dsda_AddPlayerMessage(skulliscard ? s_PD_YELLOWK : s_PD_YELLOWC, player);
999 S_StartMobjSound(player->mo,sfx_oof); // killough 3/20/98
1000 return false;
1001 }
1002 break;
1003 case RSkull:
1004 if
1005 (
1006 !player->cards[it_redskull] &&
1007 (!skulliscard || !player->cards[it_redcard])
1008 )
1009 {
1010 dsda_AddPlayerMessage(skulliscard ? s_PD_REDK : s_PD_REDS, player);
1011 S_StartMobjSound(player->mo,sfx_oof); // killough 3/20/98
1012 return false;
1013 }
1014 break;
1015 case BSkull:
1016 if
1017 (
1018 !player->cards[it_blueskull] &&
1019 (!skulliscard || !player->cards[it_bluecard])
1020 )
1021 {
1022 dsda_AddPlayerMessage(skulliscard ? s_PD_BLUEK : s_PD_BLUES, player);
1023 S_StartMobjSound(player->mo,sfx_oof); // killough 3/20/98
1024 return false;
1025 }
1026 break;
1027 case YSkull:
1028 if
1029 (
1030 !player->cards[it_yellowskull] &&
1031 (!skulliscard || !player->cards[it_yellowcard])
1032 )
1033 {
1034 dsda_AddPlayerMessage(skulliscard ? s_PD_YELLOWK : s_PD_YELLOWS, player);
1035 S_StartMobjSound(player->mo,sfx_oof); // killough 3/20/98
1036 return false;
1037 }
1038 break;
1039 case AllKeys:
1040 if
1041 (
1042 !skulliscard &&
1043 (
1044 !player->cards[it_redcard] ||
1045 !player->cards[it_redskull] ||
1046 !player->cards[it_bluecard] ||
1047 !player->cards[it_blueskull] ||
1048 !player->cards[it_yellowcard] ||
1049 !player->cards[it_yellowskull]
1050 )
1051 )
1052 {
1053 dsda_AddPlayerMessage(s_PD_ALL6, player);
1054 S_StartMobjSound(player->mo,sfx_oof); // killough 3/20/98
1055 return false;
1056 }
1057 if
1058 (
1059 skulliscard &&
1060 (
1061 (!player->cards[it_redcard] &&
1062 !player->cards[it_redskull]) ||
1063 (!player->cards[it_bluecard] &&
1064 !player->cards[it_blueskull]) ||
1065 // e6y
1066 // Compatibility with buggy MBF behavior when 3-key door works with only 2 keys
1067 // There is no more desync on 10sector.wad\ts27-137.lmp
1068 // http://www.doomworld.com/tas/ts27-137.zip
1069 (!player->cards[it_yellowcard] &&
1070 (compatibility_level == mbf_compatibility &&
1071 !prboom_comp[PC_FORCE_CORRECT_CODE_FOR_3_KEYS_DOORS_IN_MBF].state ?
1072 player->cards[it_yellowskull] :
1073 !player->cards[it_yellowskull]))
1074 )
1075 )
1076 {
1077 dsda_AddPlayerMessage(s_PD_ALL3, player);
1078 S_StartMobjSound(player->mo,sfx_oof); // killough 3/20/98
1079 return false;
1080 }
1081 break;
1082 }
1083 return true;
1084 }
1085
1086 dboolean P_CheckKeys(mobj_t *mo, zdoom_lock_t lock, dboolean legacy)
1087 {
1088 player_t *player;
1089 const char *message = NULL;
1090 int sfx = sfx_None;
1091 dboolean successful = true;
1092
1093 if (!mo || !mo->player)
1094 return false;
1095
1096 player = mo->player;
1097
1098 switch (lock)
1099 {
1100 case zk_none:
1101 break;
1102 case zk_red_card:
1103 if (!player->cards[it_redcard])
1104 {
1105 message = legacy ? s_PD_REDC : NULL;
1106 sfx = legacy ? sfx_oof : sfx_None;
1107 successful = false;
1108 }
1109 break;
1110 case zk_blue_card:
1111 if (!player->cards[it_bluecard])
1112 {
1113 message = legacy ? s_PD_BLUEC : NULL;
1114 sfx = legacy ? sfx_oof : sfx_None;
1115 successful = false;
1116 }
1117 break;
1118 case zk_yellow_card:
1119 if (!player->cards[it_yellowcard])
1120 {
1121 message = legacy ? s_PD_YELLOWC : NULL;
1122 sfx = legacy ? sfx_oof : sfx_None;
1123 successful = false;
1124 }
1125 break;
1126 case zk_red_skull:
1127 if (!player->cards[it_redskull])
1128 {
1129 message = legacy ? s_PD_REDS : NULL;
1130 sfx = legacy ? sfx_oof : sfx_None;
1131 successful = false;
1132 }
1133 break;
1134 case zk_blue_skull:
1135 if (!player->cards[it_blueskull])
1136 {
1137 message = legacy ? s_PD_BLUES : NULL;
1138 sfx = legacy ? sfx_oof : sfx_None;
1139 successful = false;
1140 }
1141 break;
1142 case zk_yellow_skull:
1143 if (!player->cards[it_yellowskull])
1144 {
1145 message = legacy ? s_PD_YELLOWS : NULL;
1146 sfx = legacy ? sfx_oof : sfx_None;
1147 successful = false;
1148 }
1149 break;
1150 case zk_any:
1151 if (
1152 !player->cards[it_redcard] &&
1153 !player->cards[it_redskull] &&
1154 !player->cards[it_bluecard] &&
1155 !player->cards[it_blueskull] &&
1156 !player->cards[it_yellowcard] &&
1157 !player->cards[it_yellowskull]
1158 )
1159 {
1160 message = legacy ? s_PD_ANY : NULL;
1161 sfx = legacy ? sfx_oof : sfx_None;
1162 successful = false;
1163 }
1164 break;
1165 case zk_all:
1166 if (
1167 !player->cards[it_redcard] ||
1168 !player->cards[it_redskull] ||
1169 !player->cards[it_bluecard] ||
1170 !player->cards[it_blueskull] ||
1171 !player->cards[it_yellowcard] ||
1172 !player->cards[it_yellowskull]
1173 )
1174 {
1175 message = legacy ? s_PD_ALL6 : NULL;
1176 sfx = legacy ? sfx_oof : sfx_None;
1177 successful = false;
1178 }
1179 break;
1180 case zk_red:
1181 case zk_redx:
1182 if (!player->cards[it_redcard] && !player->cards[it_redskull])
1183 {
1184 message = legacy ? s_PD_REDK : NULL;
1185 sfx = legacy ? sfx_oof : sfx_None;
1186 successful = false;
1187 }
1188 break;
1189 case zk_blue:
1190 case zk_bluex:
1191 if (!player->cards[it_bluecard] && !player->cards[it_blueskull])
1192 {
1193 message = legacy ? s_PD_BLUEK : NULL;
1194 sfx = legacy ? sfx_oof : sfx_None;
1195 successful = false;
1196 }
1197 break;
1198 case zk_yellow:
1199 case zk_yellowx:
1200 if (!player->cards[it_yellowcard] && !player->cards[it_yellowskull])
1201 {
1202 message = legacy ? s_PD_YELLOWK : NULL;
1203 sfx = legacy ? sfx_oof : sfx_None;
1204 successful = false;
1205 }
1206 break;
1207 case zk_each_color:
1208 if (
1209 (!player->cards[it_redcard] && !player->cards[it_redskull]) ||
1210 (!player->cards[it_bluecard] && !player->cards[it_blueskull]) ||
1211 (!player->cards[it_yellowcard] && !player->cards[it_yellowskull])
1212 )
1213 {
1214 message = legacy ? s_PD_ALL3 : NULL;
1215 sfx = legacy ? sfx_oof : sfx_None;
1216 successful = false;
1217 }
1218 default:
1219 break;
1220 }
1221
1222 if (message)
1223 {
1224 dsda_AddPlayerMessage(message, player);
1225 }
1226
1227 if (sfx != sfx_None)
1228 {
1229 S_StartMobjSound(mo, sfx);
1230 }
1231
1232 return successful;
1233 }
1234
1235
1236 //
1237 // P_SectorActive()
1238 //
1239 // In old compatibility levels, floor and ceiling data couldn't coexist.
1240 // Lighting data is only relevant in zdoom levels.
1241 //
1242
1243 dboolean PUREFUNC P_PlaneActive(const sector_t *sec)
1244 {
1245 return sec->ceilingdata != NULL || sec->floordata != NULL;
1246 }
1247
1248 dboolean PUREFUNC P_CeilingActive(const sector_t *sec)
1249 {
1250 return sec->ceilingdata != NULL || (demo_compatibility && sec->floordata != NULL);
1251 }
1252
1253 dboolean PUREFUNC P_FloorActive(const sector_t *sec)
1254 {
1255 return sec->floordata != NULL || (demo_compatibility && sec->ceilingdata != NULL);
1256 }
1257
1258 dboolean PUREFUNC P_LightingActive(const sector_t *sec)
1259 {
1260 return sec->lightingdata != NULL;
1261 }
1262
1263 short P_FloorLightLevel(const sector_t *sec)
1264 {
1265 return sec->lightlevel_floor + (
1266 (sec->flags & SECF_LIGHTFLOORABSOLUTE) ? 0 : (
1267 sec->floorlightsec == -1 ? sec->lightlevel
1268 : sectors[sec->floorlightsec].lightlevel
1269 )
1270 );
1271 }
1272
1273 short P_CeilingLightLevel(const sector_t *sec)
1274 {
1275 return sec->lightlevel_ceiling + (
1276 (sec->flags & SECF_LIGHTCEILINGABSOLUTE) ? 0 : (
1277 sec->ceilinglightsec == -1 ? sec->lightlevel
1278 : sectors[sec->ceilinglightsec].lightlevel
1279 )
1280 );
1281 }
1282
1283 dboolean P_FloorPlanesDiffer(const sector_t *sec, const sector_t *other)
1284 {
1285 return sec->floorpic != other->floorpic ||
1286 sec->floor_xoffs != other->floor_xoffs ||
1287 sec->floor_yoffs != other->floor_yoffs ||
1288 sec->floor_rotation != other->floor_rotation ||
1289 sec->floor_xscale != other->floor_xscale ||
1290 sec->floor_yscale != other->floor_yscale ||
1291 sec->special != other->special ||
1292 sec->floorlightsec != other->floorlightsec ||
1293 P_FloorLightLevel(sec) != P_FloorLightLevel(other);
1294 }
1295
1296 dboolean P_CeilingPlanesDiffer(const sector_t *sec, const sector_t *other)
1297 {
1298 return sec->ceilingpic != other->ceilingpic ||
1299 sec->ceiling_xoffs != other->ceiling_xoffs ||
1300 sec->ceiling_yoffs != other->ceiling_yoffs ||
1301 sec->ceiling_rotation != other->ceiling_rotation ||
1302 sec->ceiling_xscale != other->ceiling_xscale ||
1303 sec->ceiling_yscale != other->ceiling_yscale ||
1304 sec->ceilinglightsec != other->ceilinglightsec ||
1305 P_CeilingLightLevel(sec) != P_CeilingLightLevel(other);
1306 }
1307
1308 //
1309 // P_CheckTag()
1310 //
1311 // Passed a line, returns true if the tag is non-zero or the line special
1312 // allows no tag without harm. If compatibility, all linedef specials are
1313 // allowed to have zero tag.
1314 //
1315 // Note: Only line specials activated by walkover, pushing, or shooting are
1316 // checked by this routine.
1317 //
1318 // jff 2/27/98 Added to check for zero tag allowed for regular special types
1319 //
1320 int P_CheckTag(line_t *line)
1321 {
1322 /* tag not zero, allowed, or
1323 * killough 11/98: compatibility option */
1324 if (comp[comp_zerotags] || line->tag)//e6y
1325 return 1;
1326
1327 switch(line->special)
1328 {
1329 case 1: // Manual door specials
1330 case 26:
1331 case 27:
1332 case 28:
1333 case 31:
1334 case 32:
1335 case 33:
1336 case 34:
1337 case 117:
1338 case 118:
1339
1340 case 139: // Lighting specials
1341 case 170:
1342 case 79:
1343 case 35:
1344 case 138:
1345 case 171:
1346 case 81:
1347 case 13:
1348 case 192:
1349 case 169:
1350 case 80:
1351 case 12:
1352 case 194:
1353 case 173:
1354 case 157:
1355 case 104:
1356 case 193:
1357 case 172:
1358 case 156:
1359 case 17:
1360
1361 case 195: // Thing teleporters
1362 case 174:
1363 case 97:
1364 case 39:
1365 case 126:
1366 case 125:
1367 case 210:
1368 case 209:
1369 case 208:
1370 case 207:
1371
1372 case 11: // Exits
1373 case 52:
1374 case 197:
1375 case 51:
1376 case 124:
1377 case 198:
1378
1379 case 48: // Scrolling walls
1380 case 85:
1381 return 1; // zero tag allowed
1382
1383 default:
1384 break;
1385 }
1386 return 0; // zero tag not allowed
1387 }
1388
1389 static const damage_t no_damage = { 0 };
1390
1391 static void P_TransferSectorFlags(unsigned int *dest, unsigned int source)
1392 {
1393 *dest &= ~SECF_TRANSFERMASK;
1394 *dest |= source & SECF_TRANSFERMASK;
1395 }
1396
1397 static void P_ResetSectorTransferFlags(unsigned int *flags)
1398 {
1399 *flags &= ~SECF_TRANSFERMASK;
1400 }
1401
1402 void P_CopySectorSpecial(sector_t *dest, sector_t *source)
1403 {
1404 dest->special = source->special;
1405 dest->damage = source->damage;
1406 P_TransferSectorFlags(&dest->flags, source->flags);
1407 }
1408
1409 void P_TransferSpecial(sector_t *sector, newspecial_t *newspecial)
1410 {
1411 sector->special = newspecial->special;
1412 sector->damage = newspecial->damage;
1413 P_TransferSectorFlags(&sector->flags, newspecial->flags);
1414 }
1415
1416 void P_CopyTransferSpecial(newspecial_t *newspecial, sector_t *sector)
1417 {
1418 newspecial->special = sector->special;
1419 newspecial->damage = sector->damage;
1420 P_TransferSectorFlags(&newspecial->flags, sector->flags);
1421 }
1422
1423 void P_ResetTransferSpecial(newspecial_t *newspecial)
1424 {
1425 newspecial->special = 0;
1426 newspecial->damage = no_damage;
1427 P_ResetSectorTransferFlags(&newspecial->flags);
1428 }
1429
1430 void P_ResetSectorSpecial(sector_t *sector)
1431 {
1432 sector->special = 0;
1433 sector->damage = no_damage;
1434 P_ResetSectorTransferFlags(&sector->flags);
1435 }
1436
1437 void P_ClearNonGeneralizedSectorSpecial(sector_t *sector)
1438 {
1439 // jff 3/14/98 clear non-generalized sector type
1440 sector->special &= map_format.generalized_mask;
1441 }
1442
1443 dboolean P_IsSpecialSector(sector_t *sector)
1444 {
1445 return sector->special || sector->flags & SECF_SECRET || sector->damage.amount;
1446 }
1447
1448 static void P_AddSectorSecret(sector_t *sector)
1449 {
1450 totalsecret++;
1451 sector->flags |= SECF_SECRET | SECF_WASSECRET;
1452 }
1453
1454 void P_AddMobjSecret(mobj_t *mobj)
1455 {
1456 totalsecret++;
1457 mobj->flags2 |= MF2_COUNTSECRET;
1458 }
1459
1460 void P_PlayerCollectSecret(player_t *player)
1461 {
1462 player->secretcount++;
1463
1464 if (dsda_IntConfig(dsda_config_hudadd_secretarea))
1465 {
1466 int sfx_id = raven ? g_sfx_secret :
1467 I_GetSfxLumpNum(&S_sfx[g_sfx_secret]) < 0 ? sfx_itmbk : g_sfx_secret;
1468 SetCustomMessage(player - players, "A secret is revealed!", 2 * TICRATE, sfx_id);
1469 }
1470 }
1471
1472 static void P_CollectSecretCommon(sector_t *sector, player_t *player)
1473 {
1474 sector->flags &= ~SECF_SECRET;
1475
1476 P_PlayerCollectSecret(player);
1477
1478 dsda_WatchSecret();
1479 }
1480
1481 static void P_CollectSecretVanilla(sector_t *sector, player_t *player)
1482 {
1483 sector->special = 0;
1484 P_CollectSecretCommon(sector, player);
1485 }
1486
1487 static void P_CollectSecretBoom(sector_t *sector, player_t *player)
1488 {
1489 sector->special &= ~SECRET_MASK;
1490
1491 if (sector->special < 32) // if all extended bits clear,
1492 sector->special = 0; // sector is not special anymore
1493
1494 P_CollectSecretCommon(sector, player);
1495 }
1496
1497 static void P_CollectSecretZDoom(sector_t *sector, player_t *player)
1498 {
1499 P_CollectSecretCommon(sector, player);
1500 }
1501
1502 //
1503 // P_IsSecret()
1504 //
1505 // Passed a sector, returns if the sector secret type is still active, i.e.
1506 // secret type is set and the secret has not yet been obtained.
1507 //
1508 // jff 3/14/98 added to simplify checks for whether sector is secret
1509 // in automap and other places
1510 //
1511 dboolean PUREFUNC P_IsSecret(const sector_t *sec)
1512 {
1513 return (sec->flags & SECF_SECRET) != 0;
1514 }
1515
1516 //
1517 // P_IsDeathExit()
1518 //
1519 // If the sector a death exit via E1M8 or MBF21 actions
1520 //
1521 dboolean PUREFUNC P_IsDeathExit(const sector_t *sec)
1522 {
1523 if (sec->special < 32)
1524 {
1525 return (sec->special == 11);
1526 }
1527 else if (mbf21 && sec->special & DEATH_MASK)
1528 {
1529 const int i = (sec->special & DAMAGE_MASK) >> DAMAGE_SHIFT;
1530
1531 return (i == 2 || i == 3);
1532 }
1533
1534 return false;
1535 }
1536
1537
1538 //
1539 // P_WasSecret()
1540 //
1541 // Passed a sector, returns if the sector secret type is was active, i.e.
1542 // secret type was set and the secret has been obtained already.
1543 //
1544 // jff 3/14/98 added to simplify checks for whether sector is secret
1545 // in automap and other places
1546 //
1547 dboolean PUREFUNC P_WasSecret(const sector_t *sec)
1548 {
1549 return (sec->flags & SECF_WASSECRET) != 0;
1550 }
1551
1552 dboolean PUREFUNC P_RevealedSecret(const sector_t *sec)
1553 {
1554 return P_WasSecret(sec) && !P_IsSecret(sec);
1555 }
1556
1557 void P_CrossHexenSpecialLine(line_t *line, int side, mobj_t *thing, dboolean bossaction)
1558 {
1559 if (thing->player)
1560 {
1561 P_ActivateLine(line, thing, side, SPAC_CROSS);
1562 }
1563 else if (thing->flags2 & MF2_MCROSS)
1564 {
1565 P_ActivateLine(line, thing, side, SPAC_MCROSS);
1566 }
1567 else if (thing->flags2 & MF2_PCROSS)
1568 {
1569 P_ActivateLine(line, thing, side, SPAC_PCROSS);
1570 }
1571 }
1572
1573 //////////////////////////////////////////////////////////////////////////
1574 //
1575 // Events
1576 //
1577 // Events are operations triggered by using, crossing,
1578 // or shooting special lines, or by timed thinkers.
1579 //
1580 /////////////////////////////////////////////////////////////////////////
1581
1582 //
1583 // P_CrossSpecialLine - Walkover Trigger Dispatcher
1584 //
1585 // Called every time a thing origin is about
1586 // to cross a line with a non 0 special, whether a walkover type or not.
1587 //
1588 // jff 02/12/98 all W1 lines were fixed to check the result from the EV_
1589 // function before clearing the special. This avoids losing the function
1590 // of the line, should the sector already be active when the line is
1591 // crossed. Change is qualified by demo_compatibility.
1592 //
1593 // CPhipps - take a line_t pointer instead of a line number, as in MBF
1594 void P_CrossCompatibleSpecialLine(line_t *line, int side, mobj_t *thing, dboolean bossaction)
1595 {
1596 int ok;
1597
1598 dsda_WatchLineActivation(line, thing);
1599
1600 // Things that should never trigger lines
1601 //
1602 // e6y: Improved support for Doom v1.2
1603 if (compatibility_level == doom_12_compatibility)
1604 {
1605 if (line->special > 98 && line->special != 104)
1606 {
1607 return;
1608 }
1609 }
1610 else
1611 {
1612 if (!thing->player && !bossaction)
1613 {
1614 // Things that should NOT trigger specials...
1615 switch(thing->type)
1616 {
1617 case MT_ROCKET:
1618 case MT_PLASMA:
1619 case MT_BFG:
1620 case MT_TROOPSHOT:
1621 case MT_HEADSHOT:
1622 case MT_BRUISERSHOT:
1623 return;
1624 break;
1625
1626 default: break;
1627 }
1628 }
1629 }
1630
1631 //jff 02/04/98 add check here for generalized lindef types
1632 if (!demo_compatibility) // generalized types not recognized if old demo
1633 {
1634 // pointer to line function is NULL by default, set non-null if
1635 // line special is walkover generalized linedef type
1636 int (*linefunc)(line_t *line)=NULL;
1637
1638 // check each range of generalized linedefs
1639 if ((unsigned)line->special >= GenEnd)
1640 {
1641 // Out of range for GenFloors
1642 }
1643 else if ((unsigned)line->special >= GenFloorBase)
1644 {
1645 if (!thing->player && !bossaction)
1646 if ((line->special & FloorChange) || !(line->special & FloorModel))
1647 return; // FloorModel is "Allow Monsters" if FloorChange is 0
1648 if (!line->tag) //jff 2/27/98 all walk generalized types require tag
1649 return;
1650 linefunc = EV_DoGenFloor;
1651 }
1652 else if ((unsigned)line->special >= GenCeilingBase)
1653 {
1654 if (!thing->player && !bossaction)
1655 if ((line->special & CeilingChange) || !(line->special & CeilingModel))
1656 return; // CeilingModel is "Allow Monsters" if CeilingChange is 0
1657 if (!line->tag) //jff 2/27/98 all walk generalized types require tag
1658 return;
1659 linefunc = EV_DoGenCeiling;
1660 }
1661 else if ((unsigned)line->special >= GenDoorBase)
1662 {
1663 if (!thing->player && !bossaction)
1664 {
1665 if (!(line->special & DoorMonster))
1666 return; // monsters disallowed from this door
1667 if (line->flags & ML_SECRET) // they can't open secret doors either
1668 return;
1669 }
1670 if (!line->tag) //3/2/98 move outside the monster check
1671 return;
1672 linefunc = EV_DoGenDoor;
1673 }
1674 else if ((unsigned)line->special >= GenLockedBase)
1675 {
1676 if (!thing->player || bossaction) // boss actions can't handle locked doors
1677 return; // monsters disallowed from unlocking doors
1678 if (((line->special&TriggerType)==WalkOnce) || ((line->special&TriggerType)==WalkMany))
1679 { //jff 4/1/98 check for being a walk type before reporting door type
1680 if (!P_CanUnlockGenDoor(line,thing->player))
1681 return;
1682 }
1683 else
1684 return;
1685 linefunc = EV_DoGenLockedDoor;
1686 }
1687 else if ((unsigned)line->special >= GenLiftBase)
1688 {
1689 if (!thing->player && !bossaction)
1690 if (!(line->special & LiftMonster))
1691 return; // monsters disallowed
1692 if (!line->tag) //jff 2/27/98 all walk generalized types require tag
1693 return;
1694 linefunc = EV_DoGenLift;
1695 }
1696 else if ((unsigned)line->special >= GenStairsBase)
1697 {
1698 if (!thing->player && !bossaction)
1699 if (!(line->special & StairMonster))
1700 return; // monsters disallowed
1701 if (!line->tag) //jff 2/27/98 all walk generalized types require tag
1702 return;
1703 linefunc = EV_DoGenStairs;
1704 }
1705 else if (mbf21 && (unsigned)line->special >= GenCrusherBase)
1706 {
1707 // haleyjd 06/09/09: This was completely forgotten in BOOM, disabling
1708 // all generalized walk-over crusher types!
1709 if (!thing->player && !bossaction)
1710 if (!(line->special & StairMonster))
1711 return; // monsters disallowed
1712 if (!line->tag) //jff 2/27/98 all walk generalized types require tag
1713 return;
1714 linefunc = EV_DoGenCrusher;
1715 }
1716
1717 if (linefunc) // if it was a valid generalized type
1718 switch((line->special & TriggerType) >> TriggerTypeShift)
1719 {
1720 case WalkOnce:
1721 if (linefunc(line))
1722 line->special = 0; // clear special if a walk once type
1723 return;
1724 case WalkMany:
1725 linefunc(line);
1726 return;
1727 default: // if not a walk type, do nothing here
1728 return;
1729 }
1730 }
1731
1732 if (!thing->player || bossaction)
1733 {
1734 ok = bossaction;
1735 switch(line->special)
1736 {
1737 // teleporters are blocked for boss actions.
1738 case 39: // teleport trigger
1739 case 97: // teleport retrigger
1740 case 125: // teleport monsteronly trigger
1741 case 126: // teleport monsteronly retrigger
1742 //jff 3/5/98 add ability of monsters etc. to use teleporters
1743 case 208: //silent thing teleporters
1744 case 207:
1745 case 243: //silent line-line teleporter
1746 case 244: //jff 3/6/98 make fit within DCK's 256 linedef types
1747 case 262: //jff 4/14/98 add monster only
1748 case 263: //jff 4/14/98 silent thing,line,line rev types
1749 case 264: //jff 4/14/98 plus player/monster silent line
1750 case 265: // reversed types
1751 case 266:
1752 case 267:
1753 case 268:
1754 case 269:
1755 if (bossaction) return;
1756
1757 case 4: // raise door
1758 case 10: // plat down-wait-up-stay trigger
1759 case 88: // plat down-wait-up-stay retrigger
1760 ok = 1;
1761 break;
1762 }
1763 if (!ok)
1764 return;
1765 }
1766
1767 if (!P_CheckTag(line)) //jff 2/27/98 disallow zero tag on some types
1768 return;
1769
1770 // Dispatch on the line special value to the line's action routine
1771 // If a once only function, and successful, clear the line special
1772
1773 switch (line->special)
1774 {
1775 // Regular walk once triggers
1776
1777 case 2:
1778 // Open Door
1779 if (EV_DoDoor(line,openDoor) || demo_compatibility)
1780 line->special = 0;
1781 break;
1782
1783 case 3:
1784 // Close Door
1785 if (EV_DoDoor(line,closeDoor) || demo_compatibility)
1786 line->special = 0;
1787 break;
1788
1789 case 4:
1790 // Raise Door
1791 if (EV_DoDoor(line,normal) || demo_compatibility)
1792 line->special = 0;
1793 break;
1794
1795 case 5:
1796 // Raise Floor
1797 if (EV_DoFloor(line,raiseFloor) || demo_compatibility)
1798 line->special = 0;
1799 break;
1800
1801 case 6:
1802 // Fast Ceiling Crush & Raise
1803 if (EV_DoCeiling(line,fastCrushAndRaise) || demo_compatibility)
1804 line->special = 0;
1805 break;
1806
1807 case 8:
1808 // Build Stairs
1809 if (EV_BuildStairs(line,build8) || demo_compatibility)
1810 line->special = 0;
1811 break;
1812
1813 case 10:
1814 // PlatDownWaitUp
1815 if (EV_DoPlat(line,downWaitUpStay,0) || demo_compatibility)
1816 line->special = 0;
1817 break;
1818
1819 case 12:
1820 // Light Turn On - brightest near
1821 if (EV_LightTurnOn(line,0) || demo_compatibility)
1822 line->special = 0;
1823 break;
1824
1825 case 13:
1826 // Light Turn On 255
1827 if (EV_LightTurnOn(line,255) || demo_compatibility)
1828 line->special = 0;
1829 break;
1830
1831 case 16:
1832 // Close Door 30
1833 if (EV_DoDoor(line,close30ThenOpen) || demo_compatibility)
1834 line->special = 0;
1835 break;
1836
1837 case 17:
1838 // Start Light Strobing
1839 if (EV_StartLightStrobing(line) || demo_compatibility)
1840 line->special = 0;
1841 break;
1842
1843 case 19:
1844 // Lower Floor
1845 if (EV_DoFloor(line,lowerFloor) || demo_compatibility)
1846 line->special = 0;
1847 break;
1848
1849 case 22:
1850 // Raise floor to nearest height and change texture
1851 if (EV_DoPlat(line,raiseToNearestAndChange,0) || demo_compatibility)
1852 line->special = 0;
1853 break;
1854
1855 case 25:
1856 // Ceiling Crush and Raise
1857 if (EV_DoCeiling(line,crushAndRaise) || demo_compatibility)
1858 line->special = 0;
1859 break;
1860
1861 case 30:
1862 // Raise floor to shortest texture height
1863 // on either side of lines.
1864 if (EV_DoFloor(line,raiseToTexture) || demo_compatibility)
1865 line->special = 0;
1866 break;
1867
1868 case 35:
1869 // Lights Very Dark
1870 if (EV_LightTurnOn(line,35) || demo_compatibility)
1871 line->special = 0;
1872 break;
1873
1874 case 36:
1875 // Lower Floor (TURBO)
1876 if (EV_DoFloor(line,turboLower) || demo_compatibility)
1877 line->special = 0;
1878 break;
1879
1880 case 37:
1881 // LowerAndChange
1882 if (EV_DoFloor(line,lowerAndChange) || demo_compatibility)
1883 line->special = 0;
1884 break;
1885
1886 case 38:
1887 // Lower Floor To Lowest
1888 if (EV_DoFloor(line, lowerFloorToLowest) || demo_compatibility)
1889 line->special = 0;
1890 break;
1891
1892 case 39:
1893 // TELEPORT! //jff 02/09/98 fix using up with wrong side crossing
1894 if (map_format.ev_teleport(0, line->tag, line, side, thing, TELF_VANILLA) || demo_compatibility)
1895 line->special = 0;
1896 break;
1897
1898 case 40:
1899 // RaiseCeilingLowerFloor
1900 if (demo_compatibility)
1901 {
1902 EV_DoCeiling( line, raiseToHighest );
1903 EV_DoFloor( line, lowerFloorToLowest ); //jff 02/12/98 doesn't work
1904 line->special = 0;
1905 }
1906 else
1907 if (EV_DoCeiling(line, raiseToHighest))
1908 line->special = 0;
1909 break;
1910
1911 case 44:
1912 // Ceiling Crush
1913 if (EV_DoCeiling(line, lowerAndCrush) || demo_compatibility)
1914 line->special = 0;
1915 break;
1916
1917 case 52:
1918 // EXIT!
1919 // killough 10/98: prevent zombies from exiting levels
1920 if (bossaction || (!(thing->player && thing->player->health <= 0 && !comp[comp_zombie])))
1921 G_ExitLevel(0);
1922 break;
1923
1924 case 53:
1925 // Perpetual Platform Raise
1926 if (EV_DoPlat(line,perpetualRaise,0) || demo_compatibility)
1927 line->special = 0;
1928 break;
1929
1930 case 54:
1931 // Platform Stop
1932 if (EV_StopPlat(line) || demo_compatibility)
1933 line->special = 0;
1934 break;
1935
1936 case 56:
1937 // Raise Floor Crush
1938 if (EV_DoFloor(line,raiseFloorCrush) || demo_compatibility)
1939 line->special = 0;
1940 break;
1941
1942 case 57:
1943 // Ceiling Crush Stop
1944 if (EV_CeilingCrushStop(line) || demo_compatibility)
1945 line->special = 0;
1946 break;
1947
1948 case 58:
1949 // Raise Floor 24
1950 if (EV_DoFloor(line,raiseFloor24) || demo_compatibility)
1951 line->special = 0;
1952 break;
1953
1954 case 59:
1955 // Raise Floor 24 And Change
1956 if (EV_DoFloor(line,raiseFloor24AndChange) || demo_compatibility)
1957 line->special = 0;
1958 break;
1959
1960 case 100:
1961 // Build Stairs Turbo 16
1962 if (EV_BuildStairs(line,turbo16) || demo_compatibility)
1963 line->special = 0;
1964 break;
1965
1966 case 104:
1967 // Turn lights off in sector(tag)
1968 if (EV_TurnTagLightsOff(line) || demo_compatibility)
1969 line->special = 0;
1970 break;
1971
1972 case 108:
1973 // Blazing Door Raise (faster than TURBO!)
1974 if (EV_DoDoor(line,blazeRaise) || demo_compatibility)
1975 line->special = 0;
1976 break;
1977
1978 case 109:
1979 // Blazing Door Open (faster than TURBO!)
1980 if (EV_DoDoor (line,blazeOpen) || demo_compatibility)
1981 line->special = 0;
1982 break;
1983
1984 case 110:
1985 // Blazing Door Close (faster than TURBO!)
1986 if (EV_DoDoor (line,blazeClose) || demo_compatibility)
1987 line->special = 0;
1988 break;
1989
1990 case 119:
1991 // Raise floor to nearest surr. floor
1992 if (EV_DoFloor(line,raiseFloorToNearest) || demo_compatibility)
1993 line->special = 0;
1994 break;
1995
1996 case 121:
1997 // Blazing PlatDownWaitUpStay
1998 if (EV_DoPlat(line,blazeDWUS,0) || demo_compatibility)
1999 line->special = 0;
2000 break;
2001
2002 case 124:
2003 // Secret EXIT
2004 // killough 10/98: prevent zombies from exiting levels
2005 // CPhipps - change for lxdoom's compatibility handling
2006 if (bossaction || (!(thing->player && thing->player->health <= 0 && !comp[comp_zombie])))
2007 G_SecretExitLevel(0);
2008 break;
2009
2010 case 125:
2011 // TELEPORT MonsterONLY
2012 if (!thing->player &&
2013 (map_format.ev_teleport(0, line->tag, line, side, thing, TELF_VANILLA) || demo_compatibility))
2014 line->special = 0;
2015 break;
2016
2017 case 130:
2018 // Raise Floor Turbo
2019 if (EV_DoFloor(line,raiseFloorTurbo) || demo_compatibility)
2020 line->special = 0;
2021 break;
2022
2023 case 141:
2024 // Silent Ceiling Crush & Raise
2025 if (EV_DoCeiling(line,silentCrushAndRaise) || demo_compatibility)
2026 line->special = 0;
2027 break;
2028
2029 // Regular walk many retriggerable
2030
2031 case 72:
2032 // Ceiling Crush
2033 EV_DoCeiling( line, lowerAndCrush );
2034 break;
2035
2036 case 73:
2037 // Ceiling Crush and Raise
2038 EV_DoCeiling(line,crushAndRaise);
2039 break;
2040
2041 case 74:
2042 // Ceiling Crush Stop
2043 EV_CeilingCrushStop(line);
2044 break;
2045
2046 case 75:
2047 // Close Door
2048 EV_DoDoor(line,closeDoor);
2049 break;
2050
2051 case 76:
2052 // Close Door 30
2053 EV_DoDoor(line,close30ThenOpen);
2054 break;
2055
2056 case 77:
2057 // Fast Ceiling Crush & Raise
2058 EV_DoCeiling(line,fastCrushAndRaise);
2059 break;
2060
2061 case 79:
2062 // Lights Very Dark
2063 EV_LightTurnOn(line,35);
2064 break;
2065
2066 case 80:
2067 // Light Turn On - brightest near
2068 EV_LightTurnOn(line,0);
2069 break;
2070
2071 case 81:
2072 // Light Turn On 255
2073 EV_LightTurnOn(line,255);
2074 break;
2075
2076 case 82:
2077 // Lower Floor To Lowest
2078 EV_DoFloor( line, lowerFloorToLowest );
2079 break;
2080
2081 case 83:
2082 // Lower Floor
2083 EV_DoFloor(line,lowerFloor);
2084 break;
2085
2086 case 84:
2087 // LowerAndChange
2088 EV_DoFloor(line,lowerAndChange);
2089 break;
2090
2091 case 86:
2092 // Open Door
2093 EV_DoDoor(line,openDoor);
2094 break;
2095
2096 case 87:
2097 // Perpetual Platform Raise
2098 EV_DoPlat(line,perpetualRaise,0);
2099 break;
2100
2101 case 88:
2102 // PlatDownWaitUp
2103 EV_DoPlat(line,downWaitUpStay,0);
2104 break;
2105
2106 case 89:
2107 // Platform Stop
2108 EV_StopPlat(line);
2109 break;
2110
2111 case 90:
2112 // Raise Door
2113 EV_DoDoor(line,normal);
2114 break;
2115
2116 case 91:
2117 // Raise Floor
2118 EV_DoFloor(line,raiseFloor);
2119 break;
2120
2121 case 92:
2122 // Raise Floor 24
2123 EV_DoFloor(line,raiseFloor24);
2124 break;
2125
2126 case 93:
2127 // Raise Floor 24 And Change
2128 EV_DoFloor(line,raiseFloor24AndChange);
2129 break;
2130
2131 case 94:
2132 // Raise Floor Crush
2133 EV_DoFloor(line,raiseFloorCrush);
2134 break;
2135
2136 case 95:
2137 // Raise floor to nearest height
2138 // and change texture.
2139 EV_DoPlat(line,raiseToNearestAndChange,0);
2140 break;
2141
2142 case 96:
2143 // Raise floor to shortest texture height
2144 // on either side of lines.
2145 EV_DoFloor(line,raiseToTexture);
2146 break;
2147
2148 case 97:
2149 // TELEPORT!
2150 map_format.ev_teleport( 0, line->tag, line, side, thing, TELF_VANILLA );
2151 break;
2152
2153 case 98:
2154 // Lower Floor (TURBO)
2155 EV_DoFloor(line,turboLower);
2156 break;
2157
2158 case 105:
2159 // Blazing Door Raise (faster than TURBO!)
2160 EV_DoDoor (line,blazeRaise);
2161 break;
2162
2163 case 106:
2164 // Blazing Door Open (faster than TURBO!)
2165 EV_DoDoor (line,blazeOpen);
2166 break;
2167
2168 case 107:
2169 // Blazing Door Close (faster than TURBO!)
2170 EV_DoDoor (line,blazeClose);
2171 break;
2172
2173 case 120:
2174 // Blazing PlatDownWaitUpStay.
2175 EV_DoPlat(line,blazeDWUS,0);
2176 break;
2177
2178 case 126:
2179 // TELEPORT MonsterONLY.
2180 if (!thing->player)
2181 map_format.ev_teleport( 0, line->tag, line, side, thing, TELF_VANILLA );
2182 break;
2183
2184 case 128:
2185 // Raise To Nearest Floor
2186 EV_DoFloor(line,raiseFloorToNearest);
2187 break;
2188
2189 case 129:
2190 // Raise Floor Turbo
2191 EV_DoFloor(line,raiseFloorTurbo);
2192 break;
2193
2194 // Extended walk triggers
2195
2196 // jff 1/29/98 added new linedef types to fill all functions out so that
2197 // all have varieties SR, S1, WR, W1
2198
2199 // killough 1/31/98: "factor out" compatibility test, by
2200 // adding inner switch qualified by compatibility flag.
2201 // relax test to demo_compatibility
2202
2203 // killough 2/16/98: Fix problems with W1 types being cleared too early
2204
2205 default:
2206 if (!demo_compatibility)
2207 switch (line->special)
2208 {
2209 // Extended walk once triggers
2210
2211 case 142:
2212 // Raise Floor 512
2213 // 142 W1 EV_DoFloor(raiseFloor512)
2214 if (EV_DoFloor(line,raiseFloor512))
2215 line->special = 0;
2216 break;
2217
2218 case 143:
2219 // Raise Floor 24 and change
2220 // 143 W1 EV_DoPlat(raiseAndChange,24)
2221 if (EV_DoPlat(line,raiseAndChange,24))
2222 line->special = 0;
2223 break;
2224
2225 case 144:
2226 // Raise Floor 32 and change
2227 // 144 W1 EV_DoPlat(raiseAndChange,32)
2228 if (EV_DoPlat(line,raiseAndChange,32))
2229 line->special = 0;
2230 break;
2231
2232 case 145:
2233 // Lower Ceiling to Floor
2234 // 145 W1 EV_DoCeiling(lowerToFloor)
2235 if (EV_DoCeiling( line, lowerToFloor ))
2236 line->special = 0;
2237 break;
2238
2239 case 146:
2240 // Lower Pillar, Raise Donut
2241 // 146 W1 EV_DoDonut()
2242 if (EV_DoDonut(line))
2243 line->special = 0;
2244 break;
2245
2246 case 199:
2247 // Lower ceiling to lowest surrounding ceiling
2248 // 199 W1 EV_DoCeiling(lowerToLowest)
2249 if (EV_DoCeiling(line,lowerToLowest))
2250 line->special = 0;
2251 break;
2252
2253 case 200:
2254 // Lower ceiling to highest surrounding floor
2255 // 200 W1 EV_DoCeiling(lowerToMaxFloor)
2256 if (EV_DoCeiling(line,lowerToMaxFloor))
2257 line->special = 0;
2258 break;
2259
2260 case 207:
2261 // killough 2/16/98: W1 silent teleporter (normal kind)
2262 if (map_format.ev_teleport(0, line->tag, line, side, thing, TELF_SILENT))
2263 line->special = 0;
2264 break;
2265
2266 //jff 3/16/98 renumber 215->153
2267 case 153: //jff 3/15/98 create texture change no motion type
2268 // Texture/Type Change Only (Trig)
2269 // 153 W1 Change Texture/Type Only
2270 if (EV_DoChange(line,trigChangeOnly,line->tag))
2271 line->special = 0;
2272 break;
2273
2274 case 239: //jff 3/15/98 create texture change no motion type
2275 // Texture/Type Change Only (Numeric)
2276 // 239 W1 Change Texture/Type Only
2277 if (EV_DoChange(line,numChangeOnly,line->tag))
2278 line->special = 0;
2279 break;
2280
2281 case 219:
2282 // Lower floor to next lower neighbor
2283 // 219 W1 Lower Floor Next Lower Neighbor
2284 if (EV_DoFloor(line,lowerFloorToNearest))
2285 line->special = 0;
2286 break;
2287
2288 case 227:
2289 // Raise elevator next floor
2290 // 227 W1 Raise Elevator next floor
2291 if (EV_DoElevator(line,elevateUp))
2292 line->special = 0;
2293 break;
2294
2295 case 231:
2296 // Lower elevator next floor
2297 // 231 W1 Lower Elevator next floor
2298 if (EV_DoElevator(line,elevateDown))
2299 line->special = 0;
2300 break;
2301
2302 case 235:
2303 // Elevator to current floor
2304 // 235 W1 Elevator to current floor
2305 if (EV_DoElevator(line,elevateCurrent))
2306 line->special = 0;
2307 break;
2308
2309 case 243: //jff 3/6/98 make fit within DCK's 256 linedef types
2310 // killough 2/16/98: W1 silent teleporter (linedef-linedef kind)
2311 if (EV_SilentLineTeleport(line, side, thing, line->tag, false))
2312 line->special = 0;
2313 break;
2314
2315 case 262: //jff 4/14/98 add silent line-line reversed
2316 if (EV_SilentLineTeleport(line, side, thing, line->tag, true))
2317 line->special = 0;
2318 break;
2319
2320 case 264: //jff 4/14/98 add monster-only silent line-line reversed
2321 if (!thing->player &&
2322 EV_SilentLineTeleport(line, side, thing, line->tag, true))
2323 line->special = 0;
2324 break;
2325
2326 case 266: //jff 4/14/98 add monster-only silent line-line
2327 if (!thing->player &&
2328 EV_SilentLineTeleport(line, side, thing, line->tag, false))
2329 line->special = 0;
2330 break;
2331
2332 case 268: //jff 4/14/98 add monster-only silent
2333 if (!thing->player && map_format.ev_teleport(0, line->tag, line, side, thing, TELF_SILENT))
2334 line->special = 0;
2335 break;
2336
2337 //jff 1/29/98 end of added W1 linedef types
2338
2339 // Extended walk many retriggerable
2340
2341 //jff 1/29/98 added new linedef types to fill all functions
2342 //out so that all have varieties SR, S1, WR, W1
2343
2344 case 147:
2345 // Raise Floor 512
2346 // 147 WR EV_DoFloor(raiseFloor512)
2347 EV_DoFloor(line,raiseFloor512);
2348 break;
2349
2350 case 148:
2351 // Raise Floor 24 and Change
2352 // 148 WR EV_DoPlat(raiseAndChange,24)
2353 EV_DoPlat(line,raiseAndChange,24);
2354 break;
2355
2356 case 149:
2357 // Raise Floor 32 and Change
2358 // 149 WR EV_DoPlat(raiseAndChange,32)
2359 EV_DoPlat(line,raiseAndChange,32);
2360 break;
2361
2362 case 150:
2363 // Start slow silent crusher
2364 // 150 WR EV_DoCeiling(silentCrushAndRaise)
2365 EV_DoCeiling(line,silentCrushAndRaise);
2366 break;
2367
2368 case 151:
2369 // RaiseCeilingLowerFloor
2370 // 151 WR EV_DoCeiling(raiseToHighest),
2371 // EV_DoFloor(lowerFloortoLowest)
2372 EV_DoCeiling( line, raiseToHighest );
2373 EV_DoFloor( line, lowerFloorToLowest );
2374 break;
2375
2376 case 152:
2377 // Lower Ceiling to Floor
2378 // 152 WR EV_DoCeiling(lowerToFloor)
2379 EV_DoCeiling( line, lowerToFloor );
2380 break;
2381
2382 //jff 3/16/98 renumber 153->256
2383 case 256:
2384 // Build stairs, step 8
2385 // 256 WR EV_BuildStairs(build8)
2386 EV_BuildStairs(line,build8);
2387 break;
2388
2389 //jff 3/16/98 renumber 154->257
2390 case 257:
2391 // Build stairs, step 16
2392 // 257 WR EV_BuildStairs(turbo16)
2393 EV_BuildStairs(line,turbo16);
2394 break;
2395
2396 case 155:
2397 // Lower Pillar, Raise Donut
2398 // 155 WR EV_DoDonut()
2399 EV_DoDonut(line);
2400 break;
2401
2402 case 156:
2403 // Start lights strobing
2404 // 156 WR Lights EV_StartLightStrobing()
2405 EV_StartLightStrobing(line);
2406 break;
2407
2408 case 157:
2409 // Lights to dimmest near
2410 // 157 WR Lights EV_TurnTagLightsOff()
2411 EV_TurnTagLightsOff(line);
2412 break;
2413
2414 case 201:
2415 // Lower ceiling to lowest surrounding ceiling
2416 // 201 WR EV_DoCeiling(lowerToLowest)
2417 EV_DoCeiling(line,lowerToLowest);
2418 break;
2419
2420 case 202:
2421 // Lower ceiling to highest surrounding floor
2422 // 202 WR EV_DoCeiling(lowerToMaxFloor)
2423 EV_DoCeiling(line,lowerToMaxFloor);
2424 break;
2425
2426 case 208:
2427 // killough 2/16/98: WR silent teleporter (normal kind)
2428 map_format.ev_teleport(0, line->tag, line, side, thing, TELF_SILENT);
2429 break;
2430
2431 case 212: //jff 3/14/98 create instant toggle floor type
2432 // Toggle floor between C and F instantly
2433 // 212 WR Instant Toggle Floor
2434 EV_DoPlat(line,toggleUpDn,0);
2435 break;
2436
2437 //jff 3/16/98 renumber 216->154
2438 case 154: //jff 3/15/98 create texture change no motion type
2439 // Texture/Type Change Only (Trigger)
2440 // 154 WR Change Texture/Type Only
2441 EV_DoChange(line,trigChangeOnly,line->tag);
2442 break;
2443
2444 case 240: //jff 3/15/98 create texture change no motion type
2445 // Texture/Type Change Only (Numeric)
2446 // 240 WR Change Texture/Type Only
2447 EV_DoChange(line,numChangeOnly,line->tag);
2448 break;
2449
2450 case 220:
2451 // Lower floor to next lower neighbor
2452 // 220 WR Lower Floor Next Lower Neighbor
2453 EV_DoFloor(line,lowerFloorToNearest);
2454 break;
2455
2456 case 228:
2457 // Raise elevator next floor
2458 // 228 WR Raise Elevator next floor
2459 EV_DoElevator(line,elevateUp);
2460 break;
2461
2462 case 232:
2463 // Lower elevator next floor
2464 // 232 WR Lower Elevator next floor
2465 EV_DoElevator(line,elevateDown);
2466 break;
2467
2468 case 236:
2469 // Elevator to current floor
2470 // 236 WR Elevator to current floor
2471 EV_DoElevator(line,elevateCurrent);
2472 break;
2473
2474 case 244: //jff 3/6/98 make fit within DCK's 256 linedef types
2475 // killough 2/16/98: WR silent teleporter (linedef-linedef kind)
2476 EV_SilentLineTeleport(line, side, thing, line->tag, false);
2477 break;
2478
2479 case 263: //jff 4/14/98 add silent line-line reversed
2480 EV_SilentLineTeleport(line, side, thing, line->tag, true);
2481 break;
2482
2483 case 265: //jff 4/14/98 add monster-only silent line-line reversed
2484 if (!thing->player)
2485 EV_SilentLineTeleport(line, side, thing, line->tag, true);
2486 break;
2487
2488 case 267: //jff 4/14/98 add monster-only silent line-line
2489 if (!thing->player)
2490 EV_SilentLineTeleport(line, side, thing, line->tag, false);
2491 break;
2492
2493 case 269: //jff 4/14/98 add monster-only silent
2494 if (!thing->player)
2495 map_format.ev_teleport(0, line->tag, line, side, thing, TELF_SILENT);
2496 break;
2497
2498 //jff 1/29/98 end of added WR linedef types
2499 }
2500 break;
2501 }
2502 }
2503
2504 void P_CrossZDoomSpecialLine(line_t *line, int side, mobj_t *thing, dboolean bossaction)
2505 {
2506 if (thing->player)
2507 {
2508 P_ActivateLine(line, thing, side, SPAC_CROSS);
2509 }
2510 else if (thing->flags2 & MF2_MCROSS)
2511 {
2512 P_ActivateLine(line, thing, side, SPAC_MCROSS);
2513 }
2514 else if (thing->flags2 & MF2_PCROSS)
2515 {
2516 P_ActivateLine(line, thing, side, SPAC_PCROSS);
2517 }
2518 else if (line->special == zl_teleport ||
2519 line->special == zl_teleport_no_fog ||
2520 line->special == zl_teleport_line)
2521 { // [RH] Just a little hack for BOOM compatibility
2522 P_ActivateLine(line, thing, side, SPAC_MCROSS);
2523 }
2524 else
2525 {
2526 P_ActivateLine(line, thing, side, SPAC_ANYCROSS);
2527 }
2528 }
2529
2530 //
2531 // P_ShootSpecialLine - Gun trigger special dispatcher
2532 //
2533 // Called when a thing shoots a special line with bullet, shell, saw, or fist.
2534 //
2535 // jff 02/12/98 all G1 lines were fixed to check the result from the EV_
2536 // function before clearing the special. This avoids losing the function
2537 // of the line, should the sector already be in motion when the line is
2538 // impacted. Change is qualified by demo_compatibility.
2539 //
2540
2541 void P_ShootCompatibleSpecialLine(mobj_t *thing, line_t *line)
2542 {
2543 //jff 02/04/98 add check here for generalized linedef
2544 if (!demo_compatibility)
2545 {
2546 // pointer to line function is NULL by default, set non-null if
2547 // line special is gun triggered generalized linedef type
2548 int (*linefunc)(line_t *line)=NULL;
2549
2550 // check each range of generalized linedefs
2551 if ((unsigned)line->special >= GenEnd)
2552 {
2553 // Out of range for GenFloors
2554 }
2555 else if ((unsigned)line->special >= GenFloorBase)
2556 {
2557 if (!thing->player)
2558 if ((line->special & FloorChange) || !(line->special & FloorModel))
2559 return; // FloorModel is "Allow Monsters" if FloorChange is 0
2560 if (!line->tag) //jff 2/27/98 all gun generalized types require tag
2561 return;
2562
2563 linefunc = EV_DoGenFloor;
2564 }
2565 else if ((unsigned)line->special >= GenCeilingBase)
2566 {
2567 if (!thing->player)
2568 if ((line->special & CeilingChange) || !(line->special & CeilingModel))
2569 return; // CeilingModel is "Allow Monsters" if CeilingChange is 0
2570 if (!line->tag) //jff 2/27/98 all gun generalized types require tag
2571 return;
2572 linefunc = EV_DoGenCeiling;
2573 }
2574 else if ((unsigned)line->special >= GenDoorBase)
2575 {
2576 if (!thing->player)
2577 {
2578 if (!(line->special & DoorMonster))
2579 return; // monsters disallowed from this door
2580 if (line->flags & ML_SECRET) // they can't open secret doors either
2581 return;
2582 }
2583 if (!line->tag) //jff 3/2/98 all gun generalized types require tag
2584 return;
2585 linefunc = EV_DoGenDoor;
2586 }
2587 else if ((unsigned)line->special >= GenLockedBase)
2588 {
2589 if (!thing->player)
2590 return; // monsters disallowed from unlocking doors
2591 if (((line->special&TriggerType)==GunOnce) || ((line->special&TriggerType)==GunMany))
2592 { //jff 4/1/98 check for being a gun type before reporting door type
2593 if (!P_CanUnlockGenDoor(line,thing->player))
2594 return;
2595 }
2596 else
2597 return;
2598 if (!line->tag) //jff 2/27/98 all gun generalized types require tag
2599 return;
2600
2601 linefunc = EV_DoGenLockedDoor;
2602 }
2603 else if ((unsigned)line->special >= GenLiftBase)
2604 {
2605 if (!thing->player)
2606 if (!(line->special & LiftMonster))
2607 return; // monsters disallowed
2608 linefunc = EV_DoGenLift;
2609 }
2610 else if ((unsigned)line->special >= GenStairsBase)
2611 {
2612 if (!thing->player)
2613 if (!(line->special & StairMonster))
2614 return; // monsters disallowed
2615 if (!line->tag) //jff 2/27/98 all gun generalized types require tag
2616 return;
2617 linefunc = EV_DoGenStairs;
2618 }
2619 else if ((unsigned)line->special >= GenCrusherBase)
2620 {
2621 if (!thing->player)
2622 if (!(line->special & StairMonster))
2623 return; // monsters disallowed
2624 if (!line->tag) //jff 2/27/98 all gun generalized types require tag
2625 return;
2626 linefunc = EV_DoGenCrusher;
2627 }
2628
2629 if (linefunc)
2630 switch((line->special & TriggerType) >> TriggerTypeShift)
2631 {
2632 case GunOnce:
2633 if (linefunc(line))
2634 P_ChangeSwitchTexture(line,0);
2635 return;
2636 case GunMany:
2637 if (linefunc(line))
2638 P_ChangeSwitchTexture(line,1);
2639 return;
2640 default: // if not a gun type, do nothing here
2641 return;
2642 }
2643 }
2644
2645 // Impacts that other things can activate.
2646 if (!thing->player)
2647 {
2648 int ok = 0;
2649 switch(line->special)
2650 {
2651 case 46:
2652 // 46 GR Open door on impact weapon is monster activatable
2653 ok = 1;
2654 break;
2655 }
2656 if (!ok)
2657 return;
2658 }
2659
2660 if (!P_CheckTag(line)) //jff 2/27/98 disallow zero tag on some types
2661 return;
2662
2663 switch(line->special)
2664 {
2665 case 24:
2666 // 24 G1 raise floor to highest adjacent
2667 if (EV_DoFloor(line,raiseFloor) || demo_compatibility)
2668 P_ChangeSwitchTexture(line,0);
2669 break;
2670
2671 case 46:
2672 // 46 GR open door, stay open
2673 EV_DoDoor(line,g_door_open);
2674 P_ChangeSwitchTexture(line,1);
2675 break;
2676
2677 case 47:
2678 // 47 G1 raise floor to nearest and change texture and type
2679 if (EV_DoPlat(line,raiseToNearestAndChange,0) || demo_compatibility)
2680 P_ChangeSwitchTexture(line,0);
2681 break;
2682
2683 //jff 1/30/98 added new gun linedefs here
2684 // killough 1/31/98: added demo_compatibility check, added inner switch
2685
2686 default:
2687 if (!demo_compatibility)
2688 switch (line->special)
2689 {
2690 case 197:
2691 // Exit to next level
2692 // killough 10/98: prevent zombies from exiting levels
2693 if(thing->player && thing->player->health<=0 && !comp[comp_zombie])
2694 break;
2695 P_ChangeSwitchTexture(line,0);
2696 G_ExitLevel(0);
2697 break;
2698
2699 case 198:
2700 // Exit to secret level
2701 // killough 10/98: prevent zombies from exiting levels
2702 if(thing->player && thing->player->health<=0 && !comp[comp_zombie])
2703 break;
2704 P_ChangeSwitchTexture(line,0);
2705 G_SecretExitLevel(0);
2706 break;
2707 //jff end addition of new gun linedefs
2708 }
2709 break;
2710 }
2711 }
2712
2713 void P_ShootHexenSpecialLine(mobj_t *thing, line_t *line)
2714 {
2715 P_ActivateLine(line, thing, 0, SPAC_IMPACT);
2716 }
2717
2718 static void P_ApplySectorDamage(player_t *player, int damage, int leak)
2719 {
2720 if (!player->powers[pw_ironfeet] || (leak && P_Random(pr_slimehurt) < leak))
2721 if (!(leveltime & 0x1f))
2722 P_DamageMobj(player->mo, NULL, NULL, damage);
2723 }
2724
2725 static void P_ApplySectorDamageEndLevel(player_t *player)
2726 {
2727 if (comp[comp_god])
2728 player->cheats &= ~CF_GODMODE;
2729
2730 if (!(leveltime & 0x1f))
2731 P_DamageMobj(player->mo, NULL, NULL, 20);
2732
2733 if (player->health <= 10)
2734 G_ExitLevel(0);
2735 }
2736
2737 static void P_ApplyGeneralizedSectorDamage(player_t *player, int bits)
2738 {
2739 switch (bits & 3)
2740 {
2741 case 0:
2742 break;
2743 case 1:
2744 P_ApplySectorDamage(player, 5, 0);
2745 break;
2746 case 2:
2747 P_ApplySectorDamage(player, 10, 0);
2748 break;
2749 case 3:
2750 P_ApplySectorDamage(player, 20, 5);
2751 break;
2752 }
2753 }
2754
2755 void P_PlayerInCompatibleSector(player_t *player, sector_t *sector)
2756 {
2757 //jff add if to handle old vs generalized types
2758 if (sector->special < 32) // regular sector specials
2759 {
2760 switch (sector->special)
2761 {
2762 case 5:
2763 P_ApplySectorDamage(player, 10, 0);
2764 break;
2765 case 7:
2766 P_ApplySectorDamage(player, 5, 0);
2767 break;
2768 case 16:
2769 case 4:
2770 P_ApplySectorDamage(player, 20, 5);
2771 break;
2772 case 9:
2773 P_CollectSecretVanilla(sector, player);
2774 break;
2775 case 11:
2776 P_ApplySectorDamageEndLevel(player);
2777 break;
2778 default:
2779 break;
2780 }
2781 }
2782 else //jff 3/14/98 handle extended sector damage
2783 {
2784 if (mbf21 && sector->special & DEATH_MASK)
2785 {
2786 int i;
2787
2788 switch ((sector->special & DAMAGE_MASK) >> DAMAGE_SHIFT)
2789 {
2790 case 0:
2791 if (!player->powers[pw_invulnerability] && !player->powers[pw_ironfeet])
2792 P_DamageMobj(player->mo, NULL, NULL, 10000);
2793 break;
2794 case 1:
2795 P_DamageMobj(player->mo, NULL, NULL, 10000);
2796 break;
2797 case 2:
2798 for (i = 0; i < g_maxplayers; i++)
2799 if (playeringame[i])
2800 P_DamageMobj(players[i].mo, NULL, NULL, 10000);
2801 G_ExitLevel(0);
2802 break;
2803 case 3:
2804 for (i = 0; i < g_maxplayers; i++)
2805 if (playeringame[i])
2806 P_DamageMobj(players[i].mo, NULL, NULL, 10000);
2807 G_SecretExitLevel(0);
2808 break;
2809 }
2810 }
2811 else
2812 {
2813 P_ApplyGeneralizedSectorDamage(player, (sector->special & DAMAGE_MASK) >> DAMAGE_SHIFT);
2814 }
2815 }
2816
2817 if (sector->flags & SECF_SECRET)
2818 {
2819 P_CollectSecretBoom(sector, player);
2820 }
2821 }
2822
2823 void P_PlayerInZDoomSector(player_t *player, sector_t *sector)
2824 {
2825 static const int heretic_carry[5] = {
2826 2048 * 5,
2827 2048 * 10,
2828 2048 * 25,
2829 2048 * 30,
2830 2048 * 35
2831 };
2832
2833 static const int hexen_carry[3] = {
2834 2048 * 5,
2835 2048 * 10,
2836 2048 * 25
2837 };
2838
2839 if (sector->damage.amount > 0)
2840 {
2841 if (sector->flags & SECF_ENDGODMODE)
2842 {
2843 player->cheats &= ~CF_GODMODE;
2844 }
2845
2846 if (
2847 sector->flags & SECF_DMGUNBLOCKABLE ||
2848 !player->powers[pw_ironfeet] ||
2849 (sector->damage.leakrate && P_Random(pr_slimehurt) < sector->damage.leakrate)
2850 )
2851 {
2852 if (sector->flags & SECF_HAZARD)
2853 {
2854 player->hazardcount += sector->damage.amount;
2855 player->hazardinterval = sector->damage.interval;
2856 }
2857 else
2858 {
2859 if (leveltime % sector->damage.interval == 0)
2860 {
2861 P_DamageMobj(player->mo, NULL, NULL, sector->damage.amount);
2862
2863 if (sector->flags & SECF_ENDLEVEL && player->health <= 10)
2864 {
2865 G_ExitLevel(0);
2866 }
2867
2868 if (sector->flags & SECF_DMGTERRAINFX)
2869 {
2870 // MAP_FORMAT_TODO: damage special effects
2871 }
2872 }
2873 }
2874 }
2875 }
2876 else if (sector->damage.amount < 0)
2877 {
2878 if (leveltime % sector->damage.interval == 0)
2879 {
2880 P_GiveBody(player, -sector->damage.amount);
2881 }
2882 }
2883
2884 switch (sector->special)
2885 {
2886 case zs_d_scroll_east_lava_damage:
2887 P_Thrust(player, 0, 2048 * 28);
2888 break;
2889 case zs_scroll_strife_current:
2890 {
2891 int anglespeed;
2892 fixed_t carryspeed;
2893 angle_t angle;
2894
2895 anglespeed = sector->tag - 100;
2896 carryspeed = (anglespeed % 10) * 4096;
2897 angle = (anglespeed / 10) * ANG45;
2898 P_Thrust(player, angle, carryspeed);
2899 }
2900 break;
2901 case zs_carry_east5:
2902 case zs_carry_east10:
2903 case zs_carry_east25:
2904 case zs_carry_east30:
2905 case zs_carry_east35:
2906 P_Thrust(player, 0, heretic_carry[sector->special - zs_carry_east5]);
2907 break;
2908 case zs_carry_north5:
2909 case zs_carry_north10:
2910 case zs_carry_north25:
2911 case zs_carry_north30:
2912 case zs_carry_north35:
2913 P_Thrust(player, ANG90, heretic_carry[sector->special - zs_carry_north5]);
2914 break;
2915 case zs_carry_south5:
2916 case zs_carry_south10:
2917 case zs_carry_south25:
2918 case zs_carry_south30:
2919 case zs_carry_south35:
2920 P_Thrust(player, ANG270, heretic_carry[sector->special - zs_carry_south5]);
2921 break;
2922 case zs_carry_west5:
2923 case zs_carry_west10:
2924 case zs_carry_west25:
2925 case zs_carry_west30:
2926 case zs_carry_west35:
2927 P_Thrust(player, ANG180, heretic_carry[sector->special - zs_carry_west5]);
2928 break;
2929 case zs_scroll_north_slow:
2930 case zs_scroll_north_medium:
2931 case zs_scroll_north_fast:
2932 P_Thrust(player, ANG90, hexen_carry[sector->special - zs_scroll_north_slow]);
2933 break;
2934 case zs_scroll_east_slow:
2935 case zs_scroll_east_medium:
2936 case zs_scroll_east_fast:
2937 P_Thrust(player, 0, hexen_carry[sector->special - zs_scroll_east_slow]);
2938 break;
2939 case zs_scroll_south_slow:
2940 case zs_scroll_south_medium:
2941 case zs_scroll_south_fast:
2942 P_Thrust(player, ANG270, hexen_carry[sector->special - zs_scroll_south_slow]);
2943 break;
2944 case zs_scroll_west_slow:
2945 case zs_scroll_west_medium:
2946 case zs_scroll_west_fast:
2947 P_Thrust(player, ANG180, hexen_carry[sector->special - zs_scroll_west_slow]);
2948 break;
2949 case zs_scroll_northwest_slow:
2950 case zs_scroll_northwest_medium:
2951 case zs_scroll_northwest_fast:
2952 P_Thrust(player, ANG135, hexen_carry[sector->special - zs_scroll_northwest_slow]);
2953 break;
2954 case zs_scroll_northeast_slow:
2955 case zs_scroll_northeast_medium:
2956 case zs_scroll_northeast_fast:
2957 P_Thrust(player, ANG45, hexen_carry[sector->special - zs_scroll_northeast_slow]);
2958 break;
2959 case zs_scroll_southeast_slow:
2960 case zs_scroll_southeast_medium:
2961 case zs_scroll_southeast_fast:
2962 P_Thrust(player, ANG315, hexen_carry[sector->special - zs_scroll_southeast_slow]);
2963 break;
2964 case zs_scroll_southwest_slow:
2965 case zs_scroll_southwest_medium:
2966 case zs_scroll_southwest_fast:
2967 P_Thrust(player, ANG225, hexen_carry[sector->special - zs_scroll_southwest_slow]);
2968 break;
2969 default:
2970 break;
2971 }
2972
2973 if (sector->flags & SECF_SECRET)
2974 {
2975 P_CollectSecretZDoom(sector, player);
2976 }
2977 }
2978
2979 //
2980 // P_PlayerInSpecialSector()
2981 //
2982 // Called every tick frame
2983 // that the player origin is in a special sector
2984 //
2985 // Changed to ignore sector types the engine does not recognize
2986 //
2987
2988 void P_PlayerInSpecialSector (player_t* player)
2989 {
2990 sector_t* sector;
2991
2992 sector = player->mo->subsector->sector;
2993
2994 // Falling, not all the way down yet?
2995 // Sector specials don't apply in mid-air
2996 if (player->mo->z != sector->floorheight)
2997 return;
2998
2999 map_format.player_in_special_sector(player, sector);
3000 }
3001
3002 dboolean P_MobjInCompatibleSector(mobj_t *mobj)
3003 {
3004 if (mbf21)
3005 {
3006 sector_t* sector = mobj->subsector->sector;
3007
3008 if (
3009 sector->special & KILL_MONSTERS_MASK &&
3010 mobj->z == mobj->floorz &&
3011 mobj->player == NULL &&
3012 mobj->flags & MF_SHOOTABLE &&
3013 !(mobj->flags & MF_FLOAT)
3014 )
3015 {
3016 P_DamageMobj(mobj, NULL, NULL, 10000);
3017
3018 // must have been removed
3019 if (mobj->thinker.function != P_MobjThinker)
3020 return true;
3021 }
3022 }
3023
3024 return false;
3025 }
3026
3027 dboolean P_MobjInHereticSector(mobj_t *mobj)
3028 {
3029 return false;
3030 }
3031
3032 dboolean P_MobjInHexenSector(mobj_t *mobj)
3033 {
3034 return false;
3035 }
3036
3037 dboolean P_MobjInZDoomSector(mobj_t *mobj)
3038 {
3039 return false;
3040 }
3041
3042 //
3043 // P_UpdateSpecials()
3044 //
3045 // Check level timer, frag counter,
3046 // animate flats, scroll walls,
3047 // change button textures
3048 //
3049 // Reads and modifies globals:
3050 // levelTimer, levelTimeCount,
3051 // levelFragLimit, levelFragLimitCount
3052 //
3053
3054 static dboolean levelTimer;
3055 static int levelTimeCount;
3056 dboolean levelFragLimit; // Ty 03/18/98 Added -frags support
3057 int levelFragLimitCount; // Ty 03/18/98 Added -frags support
3058
3059 void P_UpdateSpecials (void)
3060 {
3061 anim_t* anim;
3062 int pic;
3063 int i;
3064
3065 // hexen_note: possibly not needed?
3066 if (!hexen)
3067 {
3068 // Downcount level timer, exit level if elapsed
3069 if (levelTimer == true)
3070 {
3071 levelTimeCount--;
3072 if (!levelTimeCount)
3073 G_ExitLevel(0);
3074 }
3075
3076 // Check frag counters, if frag limit reached, exit level // Ty 03/18/98
3077 // Seems like the total frags should be kept in a simple
3078 // array somewhere, but until they are...
3079 if (levelFragLimit == true) // we used -frags so compare count
3080 {
3081 int k,m,fragcount,exitflag=false;
3082 for (k = 0; k < g_maxplayers; k++)
3083 {
3084 if (!playeringame[k]) continue;
3085 fragcount = 0;
3086 for (m = 0; m < g_maxplayers; m++)
3087 {
3088 if (!playeringame[m]) continue;
3089 fragcount += (m!=k)? players[k].frags[m] : -players[k].frags[m];
3090 }
3091 if (fragcount >= levelFragLimitCount) exitflag = true;
3092 if (exitflag == true) break; // skip out of the loop--we're done
3093 }
3094 if (exitflag == true)
3095 G_ExitLevel(0);
3096 }
3097 }
3098
3099 // MAP_FORMAT_TODO: needs investigation
3100 if (!map_format.animdefs)
3101 {
3102 // Animate flats and textures globally
3103 for (anim = anims ; anim < lastanim ; anim++)
3104 {
3105 for (i = 0; i < anim->numpics; ++i)
3106 {
3107 pic = anim->basepic + ((leveltime / anim->speed + i) % anim->numpics);
3108 if (anim->istexture)
3109 texturetranslation[anim->basepic + i] = pic;
3110 else
3111 flattranslation[anim->basepic + i] = pic;
3112 }
3113 }
3114 }
3115
3116 // Check buttons (retriggerable switches) and change texture on timeout
3117 for (i = 0; i < MAXBUTTONS; i++)
3118 if (buttonlist[i].btimer)
3119 {
3120 buttonlist[i].btimer--;
3121 if (!buttonlist[i].btimer)
3122 {
3123 switch(buttonlist[i].where)
3124 {
3125 case top:
3126 sides[buttonlist[i].line->sidenum[0]].toptexture =
3127 buttonlist[i].btexture;
3128 break;
3129
3130 case middle:
3131 sides[buttonlist[i].line->sidenum[0]].midtexture =
3132 buttonlist[i].btexture;
3133 break;
3134
3135 case bottom:
3136 sides[buttonlist[i].line->sidenum[0]].bottomtexture =
3137 buttonlist[i].btexture;
3138 break;
3139 }
3140 if (!hexen)
3141 {
3142 /* don't take the address of the switch's sound origin,
3143 * unless in a compatibility mode. */
3144 degenmobj_t *so = buttonlist[i].soundorg;
3145 if (comp[comp_sound] || compatibility_level < prboom_6_compatibility)
3146 /* since the buttonlist array is usually zeroed out,
3147 * button popouts generally appear to come from (0,0) */
3148 so = (degenmobj_t *) &buttonlist[i].soundorg;
3149 S_StartLineSound(buttonlist[i].line, so, g_sfx_swtchn);
3150 }
3151 memset(&buttonlist[i],0,sizeof(button_t));
3152 }
3153 }
3154 }
3155
3156 //////////////////////////////////////////////////////////////////////
3157 //
3158 // Sector and Line special thinker spawning at level startup
3159 //
3160 //////////////////////////////////////////////////////////////////////
3161
3162 //
3163 // P_SpawnSpecials
3164 // After the map has been loaded,
3165 // scan for specials that spawn thinkers
3166 //
3167
3168 void P_SpawnCompatibleSectorSpecial(sector_t *sector, int i)
3169 {
3170 if (sector->special & SECRET_MASK) //jff 3/15/98 count extended
3171 P_AddSectorSecret(sector);
3172
3173 if (sector->special & FRICTION_MASK)
3174 sector->flags |= SECF_FRICTION;
3175
3176 if (sector->special & PUSH_MASK)
3177 sector->flags |= SECF_PUSH;
3178
3179 switch ((demo_compatibility && !prboom_comp[PC_TRUNCATED_SECTOR_SPECIALS].state) ?
3180 sector->special : sector->special & 31)
3181 {
3182 case 1:
3183 // random off
3184 P_SpawnLightFlash(sector);
3185 break;
3186
3187 case 2:
3188 // strobe fast
3189 P_SpawnStrobeFlash(sector, FASTDARK, 0);
3190 break;
3191
3192 case 3:
3193 // strobe slow
3194 P_SpawnStrobeFlash(sector, SLOWDARK, 0);
3195 break;
3196
3197 case 4:
3198 // strobe fast/death slime
3199 P_SpawnStrobeFlash(sector, FASTDARK, 0);
3200 if (heretic)
3201 sector->special = 4;
3202 else
3203 sector->special |= 3 << DAMAGE_SHIFT; //jff 3/14/98 put damage bits in
3204 break;
3205
3206 case 8:
3207 // glowing light
3208 P_SpawnGlowingLight(sector);
3209 break;
3210 case 9:
3211 // secret sector
3212 if (sector->special < 32) //jff 3/14/98 bits don't count unless not
3213 P_AddSectorSecret(sector);
3214 break;
3215
3216 case 10:
3217 // door close in 30 seconds
3218 P_SpawnDoorCloseIn30(sector);
3219 break;
3220
3221 case 12:
3222 // sync strobe slow
3223 P_SpawnStrobeFlash(sector, SLOWDARK, 1);
3224 break;
3225
3226 case 13:
3227 // sync strobe fast
3228 P_SpawnStrobeFlash(sector, FASTDARK, 1);
3229 break;
3230
3231 case 14:
3232 // door raise in 5 minutes
3233 P_SpawnDoorRaiseIn5Mins(sector, i);
3234 break;
3235
3236 case 17:
3237 // fire flickering
3238 P_SpawnFireFlicker(sector);
3239 break;
3240 }
3241 }
3242
3243 void P_SpawnZDoomLights(sector_t *sector)
3244 {
3245 switch (sector->special)
3246 {
3247 case zs_light_phased:
3248 P_SpawnPhasedLight(sector, 80, -1);
3249 break;
3250 case zs_light_sequence_start:
3251 P_SpawnLightSequence(sector, 1);
3252 break;
3253 case zs_d_light_flicker:
3254 P_SpawnLightFlash(sector);
3255 break;
3256 case zs_d_light_strobe_fast:
3257 P_SpawnStrobeFlash(sector, FASTDARK, 0);
3258 break;
3259 case zs_d_light_strobe_slow:
3260 P_SpawnStrobeFlash(sector, SLOWDARK, 0);
3261 break;
3262 case zs_d_light_strobe_hurt:
3263 P_SpawnStrobeFlash(sector, FASTDARK, 0);
3264 sector->special |= zs_d_light_strobe_hurt;
3265 break;
3266 case zs_d_light_glow:
3267 P_SpawnGlowingLight(sector);
3268 break;
3269 case zs_d_light_strobe_slow_sync:
3270 P_SpawnStrobeFlash(sector, SLOWDARK, 1);
3271 break;
3272 case zs_d_light_strobe_fast_sync:
3273 P_SpawnStrobeFlash(sector, FASTDARK, 1);
3274 break;
3275 case zs_d_light_fire_flicker:
3276 P_SpawnFireFlicker(sector);
3277 break;
3278 case zs_d_scroll_east_lava_damage:
3279 P_SpawnStrobeFlash(sector, FASTDARK, 0);
3280 sector->special |= zs_d_scroll_east_lava_damage;
3281 break;
3282 case zs_s_light_strobe_hurt:
3283 P_SpawnStrobeFlash(sector, FASTDARK, 0);
3284 sector->special |= zs_s_light_strobe_hurt;
3285 break;
3286 default:
3287 break;
3288 }
3289 }
3290
3291 void P_SetupSectorDamage(sector_t *sector, short amount,
3292 byte interval, byte leakrate, unsigned int flags)
3293 {
3294 // Only set if damage is not yet initialized.
3295 if (sector->damage.amount)
3296 return;
3297
3298 sector->damage.amount = amount;
3299 sector->damage.interval = interval;
3300 sector->damage.leakrate = leakrate;
3301 sector->flags = (sector->flags & ~SECF_DAMAGEFLAGS) | (flags & SECF_DAMAGEFLAGS);
3302 }
3303
3304 static void P_SpawnZDoomGeneralizedSpecials(sector_t *sector)
3305 {
3306 int damage_bits = (sector->special & ZDOOM_DAMAGE_MASK) >> 8;
3307
3308 switch (damage_bits & 3)
3309 {
3310 case 0:
3311 break;
3312 case 1:
3313 P_SetupSectorDamage(sector, 5, 32, 0, 0);
3314 break;
3315 case 2:
3316 P_SetupSectorDamage(sector, 10, 32, 0, 0);
3317 break;
3318 case 3:
3319 P_SetupSectorDamage(sector, 20, 32, 5, 0);
3320 break;
3321 }
3322
3323 if (sector->special & ZDOOM_SECRET_MASK)
3324 P_AddSectorSecret(sector);
3325
3326 if (sector->special & ZDOOM_FRICTION_MASK)
3327 sector->flags |= SECF_FRICTION;
3328
3329 if (sector->special & ZDOOM_PUSH_MASK)
3330 sector->flags |= SECF_PUSH;
3331 }
3332
3333 void P_SpawnZDoomSectorSpecial(sector_t *sector, int i)
3334 {
3335 P_SpawnZDoomGeneralizedSpecials(sector);
3336
3337 sector->special &= 0xff;
3338
3339 P_SpawnZDoomLights(sector);
3340
3341 switch (sector->special)
3342 {
3343 case zs_d_scroll_east_lava_damage:
3344 dsda_AddFloorScroller(-4, 0, sector - sectors, 0);
3345 P_SetupSectorDamage(sector, 5, 32, 0, SECF_DMGTERRAINFX | SECF_DMGUNBLOCKABLE);
3346 break;
3347 case zs_s_light_strobe_hurt:
3348 case zs_d_damage_nukage:
3349 P_SetupSectorDamage(sector, 5, 32, 0, 0);
3350 sector->special = 0;
3351 break;
3352 case zs_d_damage_hellslime:
3353 P_SetupSectorDamage(sector, 10, 32, 0, 0);
3354 sector->special = 0;
3355 break;
3356 case zs_d_light_strobe_hurt:
3357 case zs_d_damage_super_hellslime:
3358 P_SetupSectorDamage(sector, 20, 32, 5, 0);
3359 sector->special = 0;
3360 break;
3361 case zs_d_damage_end:
3362 P_SetupSectorDamage(sector, 20, 32, 0, SECF_ENDGODMODE | SECF_ENDLEVEL | SECF_DMGUNBLOCKABLE);
3363 sector->special = 0;
3364 break;
3365 case zs_damage_instant_death:
3366 P_SetupSectorDamage(sector, 10000, 1, 0, SECF_DMGUNBLOCKABLE);
3367 sector->special = 0;
3368 break;
3369 case zs_h_damage_sludge:
3370 P_SetupSectorDamage(sector, 4, 32, 0, 0);
3371 sector->special = 0;
3372 break;
3373 case zs_d_damage_lava_wimpy:
3374 P_SetupSectorDamage(sector, 5, 32, 0, SECF_DMGTERRAINFX | SECF_DMGUNBLOCKABLE);
3375 sector->special = 0;
3376 break;
3377 case zs_d_damage_lava_hefty:
3378 P_SetupSectorDamage(sector, 8, 32, 0, SECF_DMGTERRAINFX | SECF_DMGUNBLOCKABLE);
3379 sector->special = 0;
3380 break;
3381 case zs_s_damage_hellslime:
3382 P_SetupSectorDamage(sector, 2, 32, 0, SECF_HAZARD);
3383 sector->special = 0;
3384 break;
3385 case zs_s_damage_super_hellslime:
3386 P_SetupSectorDamage(sector, 4, 32, 0, SECF_HAZARD);
3387 sector->special = 0;
3388 break;
3389 case zs_sector_heal:
3390 P_SetupSectorDamage(sector, -1, 32, 0, 0);
3391 sector->special = 0;
3392 break;
3393 case zs_d_sector_door_close_in_30:
3394 P_SpawnDoorCloseIn30(sector);
3395 sector->special = 0;
3396 break;
3397 case zs_d_sector_door_raise_in_5_mins:
3398 P_SpawnDoorRaiseIn5Mins(sector, i);
3399 sector->special = 0;
3400 break;
3401 case zs_d_friction_low:
3402 sector->friction = FRICTION_LOW;
3403 sector->movefactor = 0x269;
3404 sector->flags |= SECF_FRICTION;
3405 break;
3406 case zs_sector_hidden:
3407 sector->flags |= SECF_HIDDEN;
3408 sector->special = 0;
3409 break;
3410 default:
3411 if (sector->special >= zs_scroll_north_slow &&
3412 sector->special <= zs_scroll_southwest_fast)
3413 { // Hexen scroll special
3414 static const fixed_t hexenScrollies[24][2] =
3415 {
3416 { 0, 1 }, { 0, 2 }, { 0, 4 },
3417 { -1, 0 }, { -2, 0 }, { -4, 0 },
3418 { 0, -1 }, { 0, -2 }, { 0, -4 },
3419 { 1, 0 }, { 2, 0 }, { 4, 0 },
3420 { 1, 1 }, { 2, 2 }, { 4, 4 },
3421 { -1, 1 }, { -2, 2 }, { -4, 4 },
3422 { -1, -1 }, { -2, -2 }, { -4, -4 },
3423 { 1, -1 }, { 2, -2 }, { 4, -4 }
3424 };
3425
3426 int i;
3427 fixed_t dx, dy;
3428
3429 i = sector->special - zs_scroll_north_slow;
3430 dx = FixedDiv(hexenScrollies[i][0] << FRACBITS, 2);
3431 dy = FixedDiv(hexenScrollies[i][1] << FRACBITS, 2);
3432 dsda_AddFloorScroller(dx, dy, sector - sectors, 0);
3433 }
3434 else if (sector->special >= zs_carry_east5 &&
3435 sector->special <= zs_carry_east35)
3436 { // Heretic scroll special
3437 // Only east scrollers also scroll the texture
3438 fixed_t dx = FixedDiv((1 << (sector->special - zs_carry_east5)) << FRACBITS, 2);
3439 dsda_AddFloorScroller(dx, 0, sector - sectors, 0);
3440 }
3441 break;
3442 }
3443 }
3444
3445 static void P_SpawnVanillaExtras(void)
3446 {
3447 int i;
3448
3449 // allow MBF sky transfers in all complevels
3450 if (!heretic)
3451 for (i = 0; i < numlines; ++i)
3452 switch (lines[i].special)
3453 {
3454 const int *id_p;
3455
3456 case 271: // Regular sky
3457 case 272: // Same, only flipped
3458 FIND_SECTORS(id_p, lines[i].tag)
3459 {
3460 sectors[*id_p].floorsky = i | PL_SKYFLAT_LINE;
3461 sectors[*id_p].ceilingsky = i | PL_SKYFLAT_LINE;
3462 }
3463 break;
3464 }
3465 }
3466
3467 void P_SpawnCompatibleExtra(line_t *l, int i)
3468 {
3469 const int *id_p;
3470 int sec;
3471
3472 switch (l->special)
3473 {
3474 // killough 3/7/98:
3475 // support for drawn heights coming from different sector
3476 case 242:
3477 sec = sides[*l->sidenum].sector->iSectorID;
3478 FIND_SECTORS(id_p, lines[i].tag)
3479 sectors[*id_p].heightsec = sec;
3480 break;
3481
3482 // killough 3/16/98: Add support for setting
3483 // floor lighting independently (e.g. lava)
3484 case 213:
3485 sec = sides[*l->sidenum].sector->iSectorID;
3486 FIND_SECTORS(id_p, lines[i].tag)
3487 sectors[*id_p].floorlightsec = sec;
3488 break;
3489
3490 // killough 4/11/98: Add support for setting
3491 // ceiling lighting independently
3492 case 261:
3493 sec = sides[*l->sidenum].sector->iSectorID;
3494 FIND_SECTORS(id_p, lines[i].tag)
3495 sectors[*id_p].ceilinglightsec = sec;
3496 break;
3497
3498 // killough 10/98:
3499 //
3500 // Support for sky textures being transferred from sidedefs.
3501 // Allows scrolling and other effects (but if scrolling is
3502 // used, then the same sector tag needs to be used for the
3503 // sky sector, the sky-transfer linedef, and the scroll-effect
3504 // linedef). Still requires user to use F_SKY1 for the floor
3505 // or ceiling texture, to distinguish floor and ceiling sky.
3506
3507 case 271: // Regular sky
3508 case 272: // Same, only flipped
3509 FIND_SECTORS(id_p, lines[i].tag)
3510 {
3511 sectors[*id_p].floorsky = i | PL_SKYFLAT_LINE;
3512 sectors[*id_p].ceilingsky = i | PL_SKYFLAT_LINE;
3513 }
3514 break;
3515 }
3516 }
3517
3518 void P_SpawnZDoomExtra(line_t *l, int i)
3519 {
3520 const int *id_p;
3521 int sec;
3522
3523 switch (l->special)
3524 {
3525 // killough 3/7/98:
3526 // support for drawn heights coming from different sector
3527 case zl_transfer_heights:
3528 sec = sides[*l->sidenum].sector->iSectorID;
3529 FIND_SECTORS(id_p, l->special_args[0])
3530 sectors[*id_p].heightsec = sec;
3531 break;
3532
3533 // killough 3/16/98: Add support for setting
3534 // floor lighting independently (e.g. lava)
3535 case zl_transfer_floor_light:
3536 sec = sides[*l->sidenum].sector->iSectorID;
3537 FIND_SECTORS(id_p, l->special_args[0])
3538 sectors[*id_p].floorlightsec = sec;
3539 break;
3540
3541 // killough 4/11/98: Add support for setting
3542 // ceiling lighting independently
3543 case zl_transfer_ceiling_light:
3544 sec = sides[*l->sidenum].sector->iSectorID;
3545 FIND_SECTORS(id_p, l->special_args[0])
3546 sectors[*id_p].ceilinglightsec = sec;
3547 break;
3548
3549 // [RH] ZDoom Static_Init settings
3550 case zl_static_init:
3551 switch (l->special_args[1])
3552 {
3553 case zi_init_gravity:
3554 {
3555 fixed_t grav = FixedDiv(P_AproxDistance(l->dx, l->dy), 100 * FRACUNIT);
3556 sec = sides[*l->sidenum].sector->iSectorID;
3557 FIND_SECTORS(id_p, l->special_args[0])
3558 sectors[*id_p].gravity = grav;
3559 }
3560 break;
3561
3562 case zi_init_damage:
3563 {
3564 damage_t damage;
3565 unsigned int flags = 0;
3566
3567 damage.amount = P_AproxDistance(l->dx, l->dy) >> FRACBITS;
3568 if (damage.amount < 20)
3569 {
3570 damage.leakrate = 0;
3571 damage.interval = 32;
3572 }
3573 else if (damage.amount < 50)
3574 {
3575 damage.leakrate = 5;
3576 damage.interval = 32;
3577 }
3578 else
3579 {
3580 flags |= SECF_DMGUNBLOCKABLE;
3581 damage.leakrate = 0;
3582 damage.interval = 1;
3583 }
3584
3585 sec = sides[*l->sidenum].sector->iSectorID;
3586 FIND_SECTORS(id_p, l->special_args[0])
3587 {
3588 sectors[*id_p].damage = damage;
3589 sectors[*id_p].flags |= flags;
3590 }
3591 }
3592 break;
3593
3594 // killough 10/98:
3595 //
3596 // Support for sky textures being transferred from sidedefs.
3597 // Allows scrolling and other effects (but if scrolling is
3598 // used, then the same sector tag needs to be used for the
3599 // sky sector, the sky-transfer linedef, and the scroll-effect
3600 // linedef). Still requires user to use F_SKY1 for the floor
3601 // or ceiling texture, to distinguish floor and ceiling sky.
3602 case zi_init_transfer_sky:
3603 FIND_SECTORS(id_p, l->special_args[0])
3604 {
3605 sectors[*id_p].floorsky = i | PL_SKYFLAT_LINE;
3606 sectors[*id_p].ceilingsky = i | PL_SKYFLAT_LINE;
3607 }
3608 break;
3609 }
3610 break;
3611 }
3612 }
3613
3614 static void P_SpawnExtras(void)
3615 {
3616 int i;
3617 line_t *l;
3618
3619 for (i = 0, l = lines; i < numlines; i++, l++)
3620 map_format.spawn_extra(l, i);
3621 }
3622
3623 static void P_EvaluateDeathmatchParams(void)
3624 {
3625 dsda_arg_t *arg;
3626
3627 levelTimer = false;
3628
3629 arg = dsda_Arg(dsda_arg_timer);
3630 if (arg->found && deathmatch)
3631 {
3632 levelTimer = true;
3633 levelTimeCount = arg->value.v_int * 60 * TICRATE;
3634 }
3635
3636 levelFragLimit = false;
3637
3638 arg = dsda_Arg(dsda_arg_frags);
3639 if (arg->found && deathmatch)
3640 {
3641 levelFragLimit = true;
3642 levelFragLimitCount = arg->value.v_int;
3643 }
3644 }
3645
3646 static void P_InitSectorSpecials(void)
3647 {
3648 int i;
3649 sector_t* sector;
3650
3651 sector = sectors;
3652 for (i = 0; i < numsectors; i++, sector++)
3653 if (sector->special)
3654 map_format.init_sector_special(sector, i);
3655 }
3656
3657 static void P_InitButtons(void)
3658 {
3659 int i;
3660
3661 for (i = 0;i < MAXBUTTONS;i++)
3662 memset(&buttonlist[i],0,sizeof(button_t));
3663 }
3664
3665 static void Hexen_P_SpawnSpecials(void);
3666
3667 // Parses command line parameters.
3668 void P_SpawnSpecials (void)
3669 {
3670 if (hexen) return Hexen_P_SpawnSpecials();
3671
3672 P_EvaluateDeathmatchParams();
3673
3674 P_InitSectorSpecials();
3675
3676 if (heretic) P_SpawnLineSpecials();
3677
3678 P_RemoveAllActiveCeilings(); // jff 2/22/98 use killough's scheme
3679 P_RemoveAllActivePlats(); // killough
3680
3681 P_InitButtons();
3682
3683 P_SpawnScrollers(); // killough 3/7/98: Add generalized scrollers
3684
3685 if (demo_compatibility) return P_SpawnVanillaExtras();
3686
3687 P_SpawnFriction(); // phares 3/12/98: New friction model using linedefs
3688 P_SpawnPushers(); // phares 3/20/98: New pusher model using linedefs
3689 P_SpawnExtras();
3690
3691 // MAP_FORMAT_TODO: Start "Open" scripts
3692 }
3693
3694 // Adds wall scroller. Scroll amount is rotated with respect to wall's
3695 // linedef first, so that scrolling towards the wall in a perpendicular
3696 // direction is translated into vertical motion, while scrolling along
3697 // the wall in a parallel direction is translated into horizontal motion.
3698 //
3699 // killough 5/25/98: cleaned up arithmetic to avoid drift due to roundoff
3700 //
3701 // killough 10/98:
3702 // fix scrolling aliasing problems, caused by long linedefs causing overflowing
3703
3704 static void Add_WallScroller(fixed_t dx, fixed_t dy, const line_t *l,
3705 int control, int accel)
3706 {
3707 fixed_t x = D_abs(l->dx);
3708 fixed_t y = D_abs(l->dy);
3709 fixed_t d;
3710
3711 if (y > x)
3712 d = x, x = y, y = d;
3713
3714 d = FixedDiv(x, finesine[(tantoangle[FixedDiv(y,x) >> DBITS] + ANG90) >> ANGLETOFINESHIFT]);
3715
3716 // CPhipps - Import scroller calc overflow fix, compatibility optioned
3717 if (compatibility_level >= lxdoom_1_compatibility)
3718 {
3719 x = (fixed_t) (((int64_t) dy * -l->dy - (int64_t) dx * l->dx) / d);
3720 y = (fixed_t) (((int64_t) dy * l->dx - (int64_t) dx * l->dy) / d);
3721 }
3722 else
3723 {
3724 x = -FixedDiv(FixedMul(dy, l->dy) + FixedMul(dx, l->dx), d);
3725 y = -FixedDiv(FixedMul(dx, l->dy) - FixedMul(dy, l->dx), d);
3726 }
3727
3728 dsda_AddControlSideScroller(x, y, control, *l->sidenum, accel, 0);
3729 }
3730
3731 // Amount (dx,dy) vector linedef is shifted right to get scroll amount
3732 #define SCROLL_SHIFT 5
3733
3734 // Factor to scale scrolling effect into mobj-carrying properties = 3/32.
3735 // (This is so scrolling floors and objects on them can move at same speed.)
3736 #define CARRYFACTOR ((fixed_t)(FRACUNIT*.09375))
3737
3738 void P_SpawnCompatibleScroller(line_t *l, int i)
3739 {
3740 fixed_t dx = l->dx >> SCROLL_SHIFT; // direction and speed of scrolling
3741 fixed_t dy = l->dy >> SCROLL_SHIFT;
3742 int control = -1, accel = 0; // no control sector or acceleration
3743 int special = l->special;
3744
3745 if (demo_compatibility && special != 48) return; //e6y
3746
3747 // killough 3/7/98: Types 245-249 are same as 250-254 except that the
3748 // first side's sector's heights cause scrolling when they change, and
3749 // this linedef controls the direction and speed of the scrolling. The
3750 // most complicated linedef since donuts, but powerful :)
3751 //
3752 // killough 3/15/98: Add acceleration. Types 214-218 are the same but
3753 // are accelerative.
3754
3755 if (special >= 245 && special <= 249) // displacement scrollers
3756 {
3757 special += 250 - 245;
3758 control = sides[*l->sidenum].sector->iSectorID;
3759 }
3760 else if (special >= 214 && special <= 218) // accelerative scrollers
3761 {
3762 accel = 1;
3763 special += 250 - 214;
3764 control = sides[*l->sidenum].sector->iSectorID;
3765 }
3766
3767 switch (special)
3768 {
3769 int side;
3770 const int *id_p;
3771
3772 case 250: // scroll effect ceiling
3773 FIND_SECTORS(id_p, l->tag)
3774 dsda_AddControlCeilingScroller(-dx, dy, control, *id_p, accel, 0);
3775 break;
3776
3777 case 251: // scroll effect floor
3778 case 253: // scroll and carry objects on floor
3779 FIND_SECTORS(id_p, l->tag)
3780 dsda_AddControlFloorScroller(-dx, dy, control, *id_p, accel, 0);
3781 if (special != 253)
3782 break;
3783 // fallthrough
3784
3785 case 252: // carry objects on floor
3786 dx = FixedMul(dx, CARRYFACTOR);
3787 dy = FixedMul(dy, CARRYFACTOR);
3788 FIND_SECTORS(id_p, l->tag)
3789 dsda_AddControlFloorCarryScroller(dx, dy, control, *id_p, accel, 0);
3790 break;
3791
3792 // killough 3/1/98: scroll wall according to linedef
3793 // (same direction and speed as scrolling floors)
3794 case 254:
3795 FIND_LINES(id_p, l->tag)
3796 if (*id_p != i)
3797 Add_WallScroller(dx, dy, lines + *id_p, control, accel);
3798 break;
3799
3800 case 255: // killough 3/2/98: scroll according to sidedef offsets
3801 side = lines[i].sidenum[0];
3802 dsda_AddSideScroller(-sides[side].textureoffset, sides[side].rowoffset, side, 0);
3803 break;
3804
3805 case 1024: // special 255 with tag control
3806 case 1025:
3807 case 1026:
3808 if (l->tag == 0)
3809 I_Error("Line %d is missing a tag!", i);
3810
3811 if (special > 1024)
3812 control = sides[*l->sidenum].sector->iSectorID;
3813
3814 if (special == 1026)
3815 accel = 1;
3816
3817 side = lines[i].sidenum[0];
3818 dx = -sides[side].textureoffset / 8;
3819 dy = sides[side].rowoffset / 8;
3820 FIND_LINES(id_p, l->tag)
3821 if (*id_p != i)
3822 dsda_AddControlSideScroller(dx, dy, control, lines[*id_p].sidenum[0], accel, 0);
3823
3824 break;
3825
3826 case 48: // scroll first side
3827 dsda_AddSideScroller(FRACUNIT, 0, lines[i].sidenum[0], 0);
3828 break;
3829
3830 case 85: // jff 1/30/98 2-way scroll
3831 dsda_AddSideScroller(-FRACUNIT, 0, lines[i].sidenum[0], 0);
3832 break;
3833 }
3834 }
3835
3836 static int copyscroller_count = 0;
3837 static int copyscroller_max = 0;
3838 static line_t **copyscrollers;
3839
3840 static void P_AddCopyScroller(line_t *l)
3841 {
3842 while (copyscroller_count >= copyscroller_max)
3843 {
3844 copyscroller_max = copyscroller_max ? copyscroller_max * 2 : 8;
3845 copyscrollers = Z_Realloc(copyscrollers, copyscroller_max * sizeof(*copyscrollers));
3846 }
3847
3848 copyscrollers[copyscroller_count++] = l;
3849 }
3850
3851 static void P_InitCopyScrollers(void)
3852 {
3853 int i;
3854 line_t *l;
3855
3856 if (!map_format.zdoom) return;
3857
3858 for (i = 0, l = lines; i < numlines; i++, l++)
3859 if (l->special == zl_sector_copy_scroller)
3860 {
3861 // don't allow copying the scroller if the sector has the same tag
3862 // as it would just duplicate it.
3863 if (l->frontsector->tag == l->special_args[0])
3864 P_AddCopyScroller(l);
3865
3866 l->special = 0;
3867 }
3868 }
3869
3870 static void P_FreeCopyScrollers(void)
3871 {
3872 if (copyscrollers)
3873 {
3874 copyscroller_count = 0;
3875 copyscroller_max = 0;
3876 Z_Free(copyscrollers);
3877 }
3878 }
3879
3880 void P_SpawnZDoomScroller(line_t *l, int i)
3881 {
3882 fixed_t dx = 0; // direction and speed of scrolling
3883 fixed_t dy = 0;
3884 int control = -1, accel = 0; // no control sector or acceleration
3885 int special = l->special;
3886
3887 if (special == zl_scroll_ceiling ||
3888 special == zl_scroll_floor ||
3889 special == zl_scroll_texture_model)
3890 {
3891 if (l->special_args[1] & 3)
3892 {
3893 // if 1, then displacement
3894 // if 2, then accelerative (also if 3)
3895 control = sides[*l->sidenum].sector->iSectorID;
3896 if (l->special_args[1] & 2)
3897 accel = 1;
3898 }
3899
3900 if (special == zl_scroll_texture_model || l->special_args[1] & 4)
3901 {
3902 // The line housing the special controls the
3903 // direction and speed of scrolling.
3904 dx = l->dx >> SCROLL_SHIFT;
3905 dy = l->dy >> SCROLL_SHIFT;
3906 }
3907 else
3908 {
3909 // The speed and direction are parameters to the special.
3910 dx = (fixed_t) (l->special_args[3] - 128) * FRACUNIT / 32;
3911 dy = (fixed_t) (l->special_args[4] - 128) * FRACUNIT / 32;
3912 }
3913 }
3914
3915 switch (special)
3916 {
3917 int j;
3918 const int *id_p;
3919
3920 case zl_scroll_ceiling:
3921 FIND_SECTORS(id_p, l->special_args[0])
3922 dsda_AddControlCeilingScroller(-dx, dy, control, *id_p, accel, 0);
3923
3924 for (j = 0; j < copyscroller_count; ++j)
3925 {
3926 line_t *cs = copyscrollers[j];
3927
3928 if (cs->special_args[0] == l->special_args[0] && cs->special_args[1] & 1)
3929 dsda_AddControlCeilingScroller(-dx, dy, control, cs->frontsector->iSectorID, accel, 0);
3930 }
3931
3932 l->special = 0;
3933 break;
3934 case zl_scroll_floor:
3935 if (l->special_args[2] != 1)
3936 { // scroll the floor texture
3937 FIND_SECTORS(id_p, l->special_args[0])
3938 dsda_AddControlFloorScroller(-dx, dy, control, *id_p, accel, 0);
3939
3940 for (j = 0; j < copyscroller_count; ++j)
3941 {
3942 line_t *cs = copyscrollers[j];
3943
3944 if (cs->special_args[0] == l->special_args[0] && cs->special_args[1] & 2)
3945 dsda_AddControlFloorScroller(-dx, dy, control, cs->frontsector->iSectorID, accel, 0);
3946 }
3947 }
3948
3949 if (l->special_args[2] > 0)
3950 { // carry objects on the floor
3951 dx = FixedMul(dx, CARRYFACTOR);
3952 dy = FixedMul(dy, CARRYFACTOR);
3953 FIND_SECTORS(id_p, l->special_args[0])
3954 dsda_AddControlFloorCarryScroller(dx, dy, control, *id_p, accel, 0);
3955
3956 for (j = 0; j < copyscroller_count; ++j)
3957 {
3958 line_t *cs = copyscrollers[j];
3959
3960 if (cs->special_args[0] == l->special_args[0] && cs->special_args[1] & 4)
3961 dsda_AddControlFloorCarryScroller(dx, dy, control, cs->frontsector->iSectorID, accel, 0);
3962 }
3963 }
3964
3965 l->special = 0;
3966 break;
3967 case zl_scroll_texture_model:
3968 // killough 3/1/98: scroll wall according to linedef
3969 // (same direction and speed as scrolling floors)
3970 FIND_LINES(id_p, l->special_args[0])
3971 if (*id_p != i)
3972 Add_WallScroller(dx, dy, lines + *id_p, control, accel);
3973
3974 l->special = 0;
3975 break;
3976 case zl_scroll_texture_offsets:
3977 // killough 3/2/98: scroll according to sidedef offsets
3978 j = lines[i].sidenum[0];
3979 dsda_AddSideScroller(-sides[j].textureoffset, sides[j].rowoffset, j, l->special_args[0]);
3980 l->special = 0;
3981 break;
3982 case zl_scroll_texture_left:
3983 j = lines[i].sidenum[0];
3984 dsda_AddSideScroller(FRACUNIT * l->special_args[0] / 64, 0, j, l->special_args[1]);
3985 break;
3986 case zl_scroll_texture_right:
3987 j = lines[i].sidenum[0];
3988 dsda_AddSideScroller(-FRACUNIT * l->special_args[0] / 64, 0, j, l->special_args[1]);
3989 break;
3990 case zl_scroll_texture_up:
3991 j = lines[i].sidenum[0];
3992 dsda_AddSideScroller(0, FRACUNIT * l->special_args[0] / 64, j, l->special_args[1]);
3993 break;
3994 case zl_scroll_texture_down:
3995 j = lines[i].sidenum[0];
3996 dsda_AddSideScroller(0, -FRACUNIT * l->special_args[0] / 64, j, l->special_args[1]);
3997 break;
3998 case zl_scroll_texture_both:
3999 j = lines[i].sidenum[0];
4000
4001 if (l->special_args[0] == 0) {
4002 dx = FRACUNIT * (l->special_args[1] - l->special_args[2]) / 64;
4003 dy = FRACUNIT * (l->special_args[4] - l->special_args[3]) / 64;
4004 dsda_AddSideScroller(dx, dy, j, 0);
4005 }
4006
4007 l->special = 0;
4008 break;
4009 default:
4010 break;
4011 }
4012 }
4013
4014 // Initialize the scrollers
4015 static void P_SpawnScrollers(void)
4016 {
4017 int i;
4018 line_t *l;
4019
4020 P_InitCopyScrollers();
4021
4022 for (i = 0, l = lines; i < numlines; i++, l++)
4023 map_format.spawn_scroller(l, i);
4024
4025 P_FreeCopyScrollers();
4026 }
4027
4028 // e6y
4029 // restored boom's friction code
4030
4031 /////////////////////////////
4032 //
4033 // Add a friction thinker to the thinker list
4034 //
4035 // Add_Friction adds a new friction thinker to the list of active thinkers.
4036 //
4037
4038 static void Add_Friction(int friction, int movefactor, int affectee)
4039 {
4040 friction_t *f = Z_MallocLevel(sizeof *f);
4041
4042 f->thinker.function/*.acp1*/ = /*(actionf_p1) */T_Friction;
4043 f->friction = friction;
4044 f->movefactor = movefactor;
4045 f->affectee = affectee;
4046 P_AddThinker(&f->thinker);
4047 }
4048
4049 /////////////////////////////
4050 //
4051 // This is where abnormal friction is applied to objects in the sectors.
4052 // A friction thinker has been spawned for each sector where less or
4053 // more friction should be applied. The amount applied is proportional to
4054 // the length of the controlling linedef.
4055
4056 void T_Friction(friction_t *f)
4057 {
4058 sector_t *sec;
4059 mobj_t *thing;
4060 msecnode_t* node;
4061
4062 if (compatibility || !variable_friction)
4063 return;
4064
4065 sec = sectors + f->affectee;
4066
4067 // Be sure the special sector type is still turned on. If so, proceed.
4068 // Else, bail out; the sector type has been changed on us.
4069
4070 if (!(sec->flags & SECF_FRICTION))
4071 return;
4072
4073 // Assign the friction value to players on the floor, non-floating,
4074 // and clipped. Normally the object's friction value is kept at
4075 // ORIG_FRICTION and this thinker changes it for icy or muddy floors.
4076
4077 // In Phase II, you can apply friction to Things other than players.
4078
4079 // When the object is straddling sectors with the same
4080 // floorheight that have different frictions, use the lowest
4081 // friction value (muddy has precedence over icy).
4082
4083 node = sec->touching_thinglist; // things touching this sector
4084 while (node)
4085 {
4086 thing = node->m_thing;
4087 if (thing->player &&
4088 !(thing->flags & (MF_NOGRAVITY | MF_NOCLIP)) &&
4089 thing->z <= sec->floorheight)
4090 {
4091 if ((thing->friction == ORIG_FRICTION) || // normal friction?
4092 (f->friction < thing->friction))
4093 {
4094 thing->friction = f->friction;
4095 thing->movefactor = f->movefactor;
4096 }
4097 }
4098 node = node->m_snext;
4099 }
4100 }
4101
4102
4103 // killough 3/7/98 -- end generalized scroll effects
4104
4105 ////////////////////////////////////////////////////////////////////////////
4106 //
4107 // FRICTION EFFECTS
4108 //
4109 // phares 3/12/98: Start of friction effects
4110 //
4111 // As the player moves, friction is applied by decreasing the x and y
4112 // momentum values on each tic. By varying the percentage of decrease,
4113 // we can simulate muddy or icy conditions. In mud, the player slows
4114 // down faster. In ice, the player slows down more slowly.
4115 //
4116 // The amount of friction change is controlled by the length of a linedef
4117 // with type 223. A length < 100 gives you mud. A length > 100 gives you ice.
4118 //
4119 // Also, each sector where these effects are to take place is given a
4120 // new special type _______. Changing the type value at runtime allows
4121 // these effects to be turned on or off.
4122 //
4123 // Sector boundaries present problems. The player should experience these
4124 // friction changes only when his feet are touching the sector floor. At
4125 // sector boundaries where floor height changes, the player can find
4126 // himself still 'in' one sector, but with his feet at the floor level
4127 // of the next sector (steps up or down). To handle this, Thinkers are used
4128 // in icy/muddy sectors. These thinkers examine each object that is touching
4129 // their sectors, looking for players whose feet are at the same level as
4130 // their floors. Players satisfying this condition are given new friction
4131 // values that are applied by the player movement code later.
4132 //
4133 // killough 8/28/98:
4134 //
4135 // Completely redid code, which did not need thinkers, and which put a heavy
4136 // drag on CPU. Friction is now a property of sectors, NOT objects inside
4137 // them. All objects, not just players, are affected by it, if they touch
4138 // the sector's floor. Code simpler and faster, only calling on friction
4139 // calculations when an object needs friction considered, instead of doing
4140 // friction calculations on every sector during every tic.
4141 //
4142 // Although this -might- ruin Boom demo sync involving friction, it's the only
4143 // way, short of code explosion, to fix the original design bug. Fixing the
4144 // design bug in Boom's original friction code, while maintaining demo sync
4145 // under every conceivable circumstance, would double or triple code size, and
4146 // would require maintenance of buggy legacy code which is only useful for old
4147 // demos. Doom demos, which are more important IMO, are not affected by this
4148 // change.
4149 //
4150 /////////////////////////////
4151 //
4152 // Initialize the sectors where friction is increased or decreased
4153
4154 void P_ResolveFrictionFactor(fixed_t friction_factor, sector_t *sec)
4155 {
4156 sec->friction = friction_factor;
4157
4158 if (sec->friction > FRACUNIT)
4159 sec->friction = FRACUNIT;
4160 else if (sec->friction < 0)
4161 sec->friction = 0;
4162
4163 if (sec->friction > ORIG_FRICTION) // ice
4164 sec->movefactor = ((0x10092 - sec->friction) * (0x70)) / 0x158;
4165 else
4166 sec->movefactor = ((sec->friction - 0xDB34) * (0xA)) / 0x80;
4167
4168 if (sec->movefactor < 32)
4169 sec->movefactor = 32;
4170
4171 sec->flags |= SECF_FRICTION;
4172 }
4173
4174 static void P_ApplySectorFriction(int tag, int value, int use_thinker)
4175 {
4176 const int *id_p;
4177 int friction, movefactor;
4178
4179 friction = (0x1EB8 * value) / 0x80 + 0xD000;
4180
4181 // The following check might seem odd. At the time of movement,
4182 // the move distance is multiplied by 'friction/0x10000', so a
4183 // higher friction value actually means 'less friction'.
4184
4185 if (friction > ORIG_FRICTION) // ice
4186 movefactor = ((0x10092 - friction) * (0x70)) / 0x158;
4187 else
4188 movefactor = ((friction - 0xDB34) * (0xA)) / 0x80;
4189
4190 if (mbf_features)
4191 { // killough 8/28/98: prevent odd situations
4192 if (friction > FRACUNIT)
4193 friction = FRACUNIT;
4194 if (friction < 0)
4195 friction = 0;
4196 if (movefactor < 32)
4197 movefactor = 32;
4198 }
4199
4200 FIND_SECTORS(id_p, tag)
4201 {
4202 // killough 8/28/98:
4203 //
4204 // Instead of spawning thinkers, which are slow and expensive,
4205 // modify the sector's own friction values. Friction should be
4206 // a property of sectors, not objects which reside inside them.
4207 // Original code scanned every object in every friction sector
4208 // on every tic, adjusting its friction, putting unnecessary
4209 // drag on CPU. New code adjusts friction of sector only once
4210 // at level startup, and then uses this friction value.
4211
4212 //e6y: boom's friction code for boom compatibility
4213 if (use_thinker)
4214 Add_Friction(friction, movefactor, *id_p);
4215
4216 sectors[*id_p].friction = friction;
4217 sectors[*id_p].movefactor = movefactor;
4218 }
4219 }
4220
4221 void P_SpawnCompatibleFriction(line_t *l)
4222 {
4223 if (l->special == 223)
4224 {
4225 int value, use_thinker;
4226
4227 value = P_AproxDistance(l->dx, l->dy) >> FRACBITS;
4228 use_thinker = !demo_compatibility && !mbf_features && !prboom_comp[PC_PRBOOM_FRICTION].state;
4229
4230 P_ApplySectorFriction(l->tag, value, use_thinker);
4231 }
4232 }
4233
4234 void P_SpawnZDoomFriction(line_t *l)
4235 {
4236 if (l->special == zl_sector_set_friction)
4237 {
4238 int value;
4239
4240 if (l->special_args[1])
4241 value = l->special_args[1] <= 200 ? l->special_args[1] : 200;
4242 else
4243 value = P_AproxDistance(l->dx, l->dy) >> FRACBITS;
4244
4245 P_ApplySectorFriction(l->special_args[0], value, false);
4246
4247 l->special = 0;
4248 }
4249 }
4250
4251 static void P_SpawnFriction(void)
4252 {
4253 int i;
4254 line_t *l = lines;
4255
4256 for (i = 0; i < numlines; i++, l++)
4257 map_format.spawn_friction(l);
4258 }
4259
4260 //
4261 // phares 3/12/98: End of friction effects
4262 //
4263 ////////////////////////////////////////////////////////////////////////////
4264
4265 ////////////////////////////////////////////////////////////////////////////
4266 //
4267 // PUSH/PULL EFFECT
4268 //
4269 // phares 3/20/98: Start of push/pull effects
4270 //
4271 // This is where push/pull effects are applied to objects in the sectors.
4272 //
4273 // There are four kinds of push effects
4274 //
4275 // 1) Pushing Away
4276 //
4277 // Pushes you away from a point source defined by the location of an
4278 // MT_PUSH Thing. The force decreases linearly with distance from the
4279 // source. This force crosses sector boundaries and is felt w/in a circle
4280 // whose center is at the MT_PUSH. The force is felt only if the point
4281 // MT_PUSH can see the target object.
4282 //
4283 // 2) Pulling toward
4284 //
4285 // Same as Pushing Away except you're pulled toward an MT_PULL point
4286 // source. This force crosses sector boundaries and is felt w/in a circle
4287 // whose center is at the MT_PULL. The force is felt only if the point
4288 // MT_PULL can see the target object.
4289 //
4290 // 3) Wind
4291 //
4292 // Pushes you in a constant direction. Full force above ground, half
4293 // force on the ground, nothing if you're below it (water).
4294 //
4295 // 4) Current
4296 //
4297 // Pushes you in a constant direction. No force above ground, full
4298 // force if on the ground or below it (water).
4299 //
4300 // The magnitude of the force is controlled by the length of a controlling
4301 // linedef. The force vector for types 3 & 4 is determined by the angle
4302 // of the linedef, and is constant.
4303 //
4304 // For each sector where these effects occur, the sector special type has
4305 // to have the PUSH_MASK bit set. If this bit is turned off by a switch
4306 // at run-time, the effect will not occur. The controlling sector for
4307 // types 1 & 2 is the sector containing the MT_PUSH/MT_PULL Thing.
4308
4309
4310 #define PUSH_FACTOR 7
4311
4312 /////////////////////////////
4313 //
4314 // Add a push thinker to the thinker list
4315
4316 static void Add_Pusher(int type, int x_mag, int y_mag, mobj_t* source, int affectee)
4317 {
4318 pusher_t *p = Z_MallocLevel(sizeof *p);
4319
4320 p->thinker.function = T_Pusher;
4321 p->source = source;
4322 p->type = type;
4323 p->x_mag = x_mag>>FRACBITS;
4324 p->y_mag = y_mag>>FRACBITS;
4325 p->magnitude = P_AproxDistance(p->x_mag,p->y_mag);
4326 if (source) // point source exist?
4327 {
4328 p->radius = (p->magnitude)<<(FRACBITS+1); // where force goes to zero
4329 p->x = p->source->x;
4330 p->y = p->source->y;
4331 }
4332 p->affectee = affectee;
4333 P_AddThinker(&p->thinker);
4334 }
4335
4336 /////////////////////////////
4337 //
4338 // PIT_PushThing determines the angle and magnitude of the effect.
4339 // The object's x and y momentum values are changed.
4340 //
4341 // tmpusher belongs to the point source (MT_PUSH/MT_PULL).
4342 //
4343 // killough 10/98: allow to affect things besides players
4344
4345 pusher_t* tmpusher; // pusher structure for blockmap searches
4346
4347 static dboolean PIT_PushThing(mobj_t* thing)
4348 {
4349 /* killough 10/98: made more general */
4350 if (!mbf_features ?
4351 thing->player && !(thing->flags & (MF_NOCLIP | MF_NOGRAVITY)) :
4352 (sentient(thing) || thing->flags & MF_SHOOTABLE) &&
4353 !(thing->flags & MF_NOCLIP))
4354 {
4355 angle_t pushangle;
4356 fixed_t speed;
4357 fixed_t sx = tmpusher->x;
4358 fixed_t sy = tmpusher->y;
4359
4360 speed = (tmpusher->magnitude -
4361 ((P_AproxDistance(thing->x - sx,thing->y - sy)
4362 >>FRACBITS)>>1))<<(FRACBITS-PUSH_FACTOR-1);
4363
4364 // killough 10/98: make magnitude decrease with square
4365 // of distance, making it more in line with real nature,
4366 // so long as it's still in range with original formula.
4367 //
4368 // Removes angular distortion, and makes effort required
4369 // to stay close to source, grow increasingly hard as you
4370 // get closer, as expected. Still, it doesn't consider z :(
4371
4372 if (speed > 0 && mbf_features)
4373 {
4374 int x = (thing->x-sx) >> FRACBITS;
4375 int y = (thing->y-sy) >> FRACBITS;
4376 speed = (int)(((uint64_t) tmpusher->magnitude << 23) / (x*x+y*y+1));
4377 }
4378
4379 // If speed <= 0, you're outside the effective radius. You also have
4380 // to be able to see the push/pull source point.
4381
4382 if (speed > 0 && P_CheckSight(thing,tmpusher->source))
4383 {
4384 pushangle = R_PointToAngle2(thing->x,thing->y,sx,sy);
4385 if (tmpusher->source->type == MT_PUSH)
4386 pushangle += ANG180; // away
4387 pushangle >>= ANGLETOFINESHIFT;
4388 thing->momx += FixedMul(speed,finecosine[pushangle]);
4389 thing->momy += FixedMul(speed,finesine[pushangle]);
4390 thing->intflags |= MIF_SCROLLING;
4391 }
4392 }
4393 return true;
4394 }
4395
4396 /////////////////////////////
4397 //
4398 // T_Pusher looks for all objects that are inside the radius of
4399 // the effect.
4400 //
4401
4402 void T_Pusher(pusher_t *p)
4403 {
4404 sector_t *sec;
4405 mobj_t *thing;
4406 msecnode_t* node;
4407 int xspeed,yspeed;
4408 int xl,xh,yl,yh,bx,by;
4409 int radius;
4410 int ht = 0;
4411
4412 if (!allow_pushers)
4413 return;
4414
4415 sec = sectors + p->affectee;
4416
4417 // Be sure the special sector type is still turned on. If so, proceed.
4418 // Else, bail out; the sector type has been changed on us.
4419
4420 if (!(sec->flags & SECF_PUSH))
4421 return;
4422
4423 // For constant pushers (wind/current) there are 3 situations:
4424 //
4425 // 1) Affected Thing is above the floor.
4426 //
4427 // Apply the full force if wind, no force if current.
4428 //
4429 // 2) Affected Thing is on the ground.
4430 //
4431 // Apply half force if wind, full force if current.
4432 //
4433 // 3) Affected Thing is below the ground (underwater effect).
4434 //
4435 // Apply no force if wind, full force if current.
4436
4437 if (p->type == p_push)
4438 {
4439
4440 // Seek out all pushable things within the force radius of this
4441 // point pusher. Crosses sectors, so use blockmap.
4442
4443 tmpusher = p; // MT_PUSH/MT_PULL point source
4444 radius = p->radius; // where force goes to zero
4445 tmbbox[BOXTOP] = p->y + radius;
4446 tmbbox[BOXBOTTOM] = p->y - radius;
4447 tmbbox[BOXRIGHT] = p->x + radius;
4448 tmbbox[BOXLEFT] = p->x - radius;
4449
4450 xl = P_GetSafeBlockX(tmbbox[BOXLEFT] - bmaporgx - MAXRADIUS);
4451 xh = P_GetSafeBlockX(tmbbox[BOXRIGHT] - bmaporgx + MAXRADIUS);
4452 yl = P_GetSafeBlockY(tmbbox[BOXBOTTOM] - bmaporgy - MAXRADIUS);
4453 yh = P_GetSafeBlockY(tmbbox[BOXTOP] - bmaporgy + MAXRADIUS);
4454 for (bx=xl ; bx<=xh ; bx++)
4455 for (by=yl ; by<=yh ; by++)
4456 P_BlockThingsIterator(bx,by,PIT_PushThing);
4457 return;
4458 }
4459
4460 // constant pushers p_wind and p_current
4461
4462 if (sec->heightsec != -1) // special water sector?
4463 ht = sectors[sec->heightsec].floorheight;
4464 node = sec->touching_thinglist; // things touching this sector
4465 for ( ; node ; node = node->m_snext)
4466 {
4467 thing = node->m_thing;
4468 if (!thing->player || (thing->flags & (MF_NOGRAVITY | MF_NOCLIP)))
4469 continue;
4470 if (p->type == p_wind)
4471 {
4472 if (sec->heightsec == -1) // NOT special water sector
4473 if (thing->z > thing->floorz) // above ground
4474 {
4475 xspeed = p->x_mag; // full force
4476 yspeed = p->y_mag;
4477 }
4478 else // on ground
4479 {
4480 xspeed = (p->x_mag)>>1; // half force
4481 yspeed = (p->y_mag)>>1;
4482 }
4483 else // special water sector
4484 {
4485 if (thing->z > ht) // above ground
4486 {
4487 xspeed = p->x_mag; // full force
4488 yspeed = p->y_mag;
4489 }
4490 else if (thing->player->viewz < ht) // underwater
4491 xspeed = yspeed = 0; // no force
4492 else // wading in water
4493 {
4494 xspeed = (p->x_mag)>>1; // half force
4495 yspeed = (p->y_mag)>>1;
4496 }
4497 }
4498 }
4499 else // p_current
4500 {
4501 if (sec->heightsec == -1) // NOT special water sector
4502 if (thing->z > sec->floorheight) // above ground
4503 xspeed = yspeed = 0; // no force
4504 else // on ground
4505 {
4506 xspeed = p->x_mag; // full force
4507 yspeed = p->y_mag;
4508 }
4509 else // special water sector
4510 if (thing->z > ht) // above ground
4511 xspeed = yspeed = 0; // no force
4512 else // underwater
4513 {
4514 xspeed = p->x_mag; // full force
4515 yspeed = p->y_mag;
4516 }
4517 }
4518 thing->momx += xspeed<<(FRACBITS-PUSH_FACTOR);
4519 thing->momy += yspeed<<(FRACBITS-PUSH_FACTOR);
4520 thing->intflags |= MIF_SCROLLING;
4521 }
4522 }
4523
4524 /////////////////////////////
4525 //
4526 // P_GetPushThing() returns a pointer to an MT_PUSH or MT_PULL thing,
4527 // NULL otherwise.
4528
4529 mobj_t* P_GetPushThing(int s)
4530 {
4531 mobj_t* thing;
4532 sector_t* sec;
4533
4534 sec = sectors + s;
4535 thing = sec->thinglist;
4536 while (thing)
4537 {
4538 switch(thing->type)
4539 {
4540 case MT_PUSH:
4541 case MT_PULL:
4542 return thing;
4543 default:
4544 break;
4545 }
4546 thing = thing->snext;
4547 }
4548 return NULL;
4549 }
4550
4551 /////////////////////////////
4552 //
4553 // Initialize the sectors where pushers are present
4554 //
4555
4556 void P_SpawnCompatiblePusher(line_t *l)
4557 {
4558 const int *id_p;
4559 mobj_t* thing;
4560
4561 switch(l->special)
4562 {
4563 case 224: // wind
4564 FIND_SECTORS(id_p, l->tag)
4565 Add_Pusher(p_wind, l->dx, l->dy, NULL, *id_p);
4566 break;
4567 case 225: // current
4568 FIND_SECTORS(id_p, l->tag)
4569 Add_Pusher(p_current, l->dx, l->dy, NULL, *id_p);
4570 break;
4571 case 226: // push/pull
4572 FIND_SECTORS(id_p, l->tag)
4573 {
4574 thing = P_GetPushThing(*id_p);
4575 if (thing) // No MT_P* means no effect
4576 Add_Pusher(p_push, l->dx, l->dy, thing, *id_p);
4577 }
4578 break;
4579 }
4580 }
4581
4582 static void CalculatePushVector(line_t *l, int magnitude, int angle, fixed_t *dx, fixed_t *dy)
4583 {
4584 if (l->special_args[3])
4585 {
4586 *dx = l->dx;
4587 *dy = l->dy;
4588 return;
4589 }
4590
4591 angle = angle * (ANG180 >> 7); // 256 is 360
4592 angle >>= ANGLETOFINESHIFT;
4593 magnitude <<= FRACBITS;
4594
4595 *dx = FixedMul(magnitude, finecosine[angle]);
4596 *dy = FixedMul(magnitude, finesine[angle]);
4597 }
4598
4599 void P_SpawnZDoomPusher(line_t *l)
4600 {
4601 const int *id_p;
4602 mobj_t* thing;
4603 fixed_t dx, dy;
4604
4605 switch (l->special)
4606 {
4607 case zl_sector_set_wind: // wind
4608 CalculatePushVector(l, l->special_args[1], l->special_args[2], &dx, &dy);
4609 FIND_SECTORS(id_p, l->special_args[0])
4610 Add_Pusher(p_wind, dx, dy, NULL, *id_p);
4611 l->special = 0;
4612 break;
4613 case zl_sector_set_current: // current
4614 CalculatePushVector(l, l->special_args[1], l->special_args[2], &dx, &dy);
4615 FIND_SECTORS(id_p, l->special_args[0])
4616 Add_Pusher(p_current, dx, dy, NULL, *id_p);
4617 l->special = 0;
4618 break;
4619 case zl_point_push_set_force: // push/pull
4620 CalculatePushVector(l, l->special_args[2], 0, &dx, &dy);
4621 if (l->special_args[0])
4622 { // [RH] Find thing by sector
4623 FIND_SECTORS(id_p, l->special_args[0])
4624 {
4625 thing = P_GetPushThing(*id_p);
4626 if (thing) // No MT_P* means no effect
4627 {
4628 // [RH] Allow narrowing it down by tid
4629 if (!l->special_args[1] || l->special_args[1] == thing->tid)
4630 Add_Pusher(p_push, dx, dy, thing, *id_p);
4631 }
4632 }
4633 }
4634 else
4635 { // [RH] Find thing by tid
4636 int s;
4637
4638 for (s = -1; (thing = P_FindMobjFromTID(l->special_args[1], &s)) != NULL;)
4639 if (thing->type == map_format.mt_push || thing->type == map_format.mt_pull)
4640 Add_Pusher(p_push, dx, dy, thing, thing->subsector->sector->iSectorID);
4641 }
4642 l->special = 0;
4643 break;
4644 }
4645 }
4646
4647 static void P_SpawnPushers(void)
4648 {
4649 int i;
4650 line_t *l = lines;
4651
4652 for (i = 0; i < numlines; i++, l++)
4653 map_format.spawn_pusher(l);
4654 }
4655
4656 //
4657 // phares 3/20/98: End of Pusher effects
4658 //
4659 ////////////////////////////////////////////////////////////////////////////
4660
4661 // heretic
4662
4663 #include "heretic/def.h"
4664
4665 typedef enum
4666 {
4667 afxcmd_play, // (sound)
4668 afxcmd_playabsvol, // (sound, volume)
4669 afxcmd_playrelvol, // (sound, volume)
4670 afxcmd_delay, // (ticks)
4671 afxcmd_delayrand, // (andbits)
4672 afxcmd_end // ()
4673 } afxcmd_t;
4674
4675 int *LevelAmbientSfx[MAX_AMBIENT_SFX];
4676 int *AmbSfxPtr;
4677 int AmbSfxPtrIndex;
4678 int AmbSfxCount;
4679 int AmbSfxTics;
4680 int AmbSfxVolume;
4681
4682 int AmbSndSeqInit[] = { // Startup
4683 afxcmd_end
4684 };
4685 int AmbSndSeq1[] = { // Scream
4686 afxcmd_play, heretic_sfx_amb1,
4687 afxcmd_end
4688 };
4689 int AmbSndSeq2[] = { // Squish
4690 afxcmd_play, heretic_sfx_amb2,
4691 afxcmd_end
4692 };
4693 int AmbSndSeq3[] = { // Drops
4694 afxcmd_play, heretic_sfx_amb3,
4695 afxcmd_delay, 16,
4696 afxcmd_delayrand, 31,
4697 afxcmd_play, heretic_sfx_amb7,
4698 afxcmd_delay, 16,
4699 afxcmd_delayrand, 31,
4700 afxcmd_play, heretic_sfx_amb3,
4701 afxcmd_delay, 16,
4702 afxcmd_delayrand, 31,
4703 afxcmd_play, heretic_sfx_amb7,
4704 afxcmd_delay, 16,
4705 afxcmd_delayrand, 31,
4706 afxcmd_play, heretic_sfx_amb3,
4707 afxcmd_delay, 16,
4708 afxcmd_delayrand, 31,
4709 afxcmd_play, heretic_sfx_amb7,
4710 afxcmd_delay, 16,
4711 afxcmd_delayrand, 31,
4712 afxcmd_end
4713 };
4714 int AmbSndSeq4[] = { // SlowFootSteps
4715 afxcmd_play, heretic_sfx_amb4,
4716 afxcmd_delay, 15,
4717 afxcmd_playrelvol, heretic_sfx_amb11, -3,
4718 afxcmd_delay, 15,
4719 afxcmd_playrelvol, heretic_sfx_amb4, -3,
4720 afxcmd_delay, 15,
4721 afxcmd_playrelvol, heretic_sfx_amb11, -3,
4722 afxcmd_delay, 15,
4723 afxcmd_playrelvol, heretic_sfx_amb4, -3,
4724 afxcmd_delay, 15,
4725 afxcmd_playrelvol, heretic_sfx_amb11, -3,
4726 afxcmd_delay, 15,
4727 afxcmd_playrelvol, heretic_sfx_amb4, -3,
4728 afxcmd_delay, 15,
4729 afxcmd_playrelvol, heretic_sfx_amb11, -3,
4730 afxcmd_end
4731 };
4732 int AmbSndSeq5[] = { // Heartbeat
4733 afxcmd_play, heretic_sfx_amb5,
4734 afxcmd_delay, 35,
4735 afxcmd_play, heretic_sfx_amb5,
4736 afxcmd_delay, 35,
4737 afxcmd_play, heretic_sfx_amb5,
4738 afxcmd_delay, 35,
4739 afxcmd_play, heretic_sfx_amb5,
4740 afxcmd_end
4741 };
4742 int AmbSndSeq6[] = { // Bells
4743 afxcmd_play, heretic_sfx_amb6,
4744 afxcmd_delay, 17,
4745 afxcmd_playrelvol, heretic_sfx_amb6, -8,
4746 afxcmd_delay, 17,
4747 afxcmd_playrelvol, heretic_sfx_amb6, -8,
4748 afxcmd_delay, 17,
4749 afxcmd_playrelvol, heretic_sfx_amb6, -8,
4750 afxcmd_end
4751 };
4752 int AmbSndSeq7[] = { // Growl
4753 afxcmd_play, heretic_sfx_bstsit,
4754 afxcmd_end
4755 };
4756 int AmbSndSeq8[] = { // Magic
4757 afxcmd_play, heretic_sfx_amb8,
4758 afxcmd_end
4759 };
4760 int AmbSndSeq9[] = { // Laughter
4761 afxcmd_play, heretic_sfx_amb9,
4762 afxcmd_delay, 16,
4763 afxcmd_playrelvol, heretic_sfx_amb9, -4,
4764 afxcmd_delay, 16,
4765 afxcmd_playrelvol, heretic_sfx_amb9, -4,
4766 afxcmd_delay, 16,
4767 afxcmd_playrelvol, heretic_sfx_amb10, -4,
4768 afxcmd_delay, 16,
4769 afxcmd_playrelvol, heretic_sfx_amb10, -4,
4770 afxcmd_delay, 16,
4771 afxcmd_playrelvol, heretic_sfx_amb10, -4,
4772 afxcmd_end
4773 };
4774 int AmbSndSeq10[] = { // FastFootsteps
4775 afxcmd_play, heretic_sfx_amb4,
4776 afxcmd_delay, 8,
4777 afxcmd_playrelvol, heretic_sfx_amb11, -3,
4778 afxcmd_delay, 8,
4779 afxcmd_playrelvol, heretic_sfx_amb4, -3,
4780 afxcmd_delay, 8,
4781 afxcmd_playrelvol, heretic_sfx_amb11, -3,
4782 afxcmd_delay, 8,
4783 afxcmd_playrelvol, heretic_sfx_amb4, -3,
4784 afxcmd_delay, 8,
4785 afxcmd_playrelvol, heretic_sfx_amb11, -3,
4786 afxcmd_delay, 8,
4787 afxcmd_playrelvol, heretic_sfx_amb4, -3,
4788 afxcmd_delay, 8,
4789 afxcmd_playrelvol, heretic_sfx_amb11, -3,
4790 afxcmd_end
4791 };
4792
4793 int *AmbientSfx[] = {
4794 AmbSndSeq1, // Scream
4795 AmbSndSeq2, // Squish
4796 AmbSndSeq3, // Drops
4797 AmbSndSeq4, // SlowFootsteps
4798 AmbSndSeq5, // Heartbeat
4799 AmbSndSeq6, // Bells
4800 AmbSndSeq7, // Growl
4801 AmbSndSeq8, // Magic
4802 AmbSndSeq9, // Laughter
4803 AmbSndSeq10 // FastFootsteps
4804 };
4805
4806 int *TerrainTypes;
4807 struct
4808 {
4809 const char *name;
4810 int type;
4811 } TerrainTypeDefs[2][6] =
4812 {
4813 {
4814 { "FLTWAWA1", FLOOR_WATER },
4815 { "FLTFLWW1", FLOOR_WATER },
4816 { "FLTLAVA1", FLOOR_LAVA },
4817 { "FLATHUH1", FLOOR_LAVA },
4818 { "FLTSLUD1", FLOOR_SLUDGE },
4819 { "END", -1 }
4820 },
4821 {
4822 { "X_005", FLOOR_WATER },
4823 { "X_001", FLOOR_LAVA },
4824 { "X_009", FLOOR_SLUDGE },
4825 { "F_033", FLOOR_ICE },
4826 { "END", -1 }
4827 }
4828 };
4829
4830 mobj_t LavaInflictor;
4831
4832 void P_AddAmbientSfx(int sequence)
4833 {
4834 if (AmbSfxCount == MAX_AMBIENT_SFX)
4835 {
4836 I_Error("Too many ambient sound sequences");
4837 }
4838 LevelAmbientSfx[AmbSfxCount++] = AmbientSfx[sequence];
4839 }
4840
4841 void P_InitAmbientSound(void)
4842 {
4843 AmbSfxCount = 0;
4844 AmbSfxVolume = 0;
4845 AmbSfxTics = 10 * TICRATE;
4846 AmbSfxPtrIndex = -1;
4847 AmbSfxPtr = AmbSndSeqInit;
4848 }
4849
4850 void P_AmbientSound(void)
4851 {
4852 afxcmd_t cmd;
4853 int sound;
4854 dboolean done;
4855
4856 if (!AmbSfxCount)
4857 { // No ambient sound sequences on current level
4858 return;
4859 }
4860 if (--AmbSfxTics)
4861 {
4862 return;
4863 }
4864 done = false;
4865 do
4866 {
4867 cmd = *AmbSfxPtr++;
4868 switch (cmd)
4869 {
4870 case afxcmd_play:
4871 AmbSfxVolume = P_Random(pr_heretic) >> 2;
4872 S_StartAmbientSound(NULL, *AmbSfxPtr++, AmbSfxVolume);
4873 break;
4874 case afxcmd_playabsvol:
4875 sound = *AmbSfxPtr++;
4876 AmbSfxVolume = *AmbSfxPtr++;
4877 S_StartAmbientSound(NULL, sound, AmbSfxVolume);
4878 break;
4879 case afxcmd_playrelvol:
4880 sound = *AmbSfxPtr++;
4881 AmbSfxVolume += *AmbSfxPtr++;
4882 if (AmbSfxVolume < 0)
4883 {
4884 AmbSfxVolume = 0;
4885 }
4886 else if (AmbSfxVolume > 127)
4887 {
4888 AmbSfxVolume = 127;
4889 }
4890 S_StartAmbientSound(NULL, sound, AmbSfxVolume);
4891 break;
4892 case afxcmd_delay:
4893 AmbSfxTics = *AmbSfxPtr++;
4894 done = true;
4895 break;
4896 case afxcmd_delayrand:
4897 AmbSfxTics = P_Random(pr_heretic) & (*AmbSfxPtr++);
4898 done = true;
4899 break;
4900 case afxcmd_end:
4901 AmbSfxTics = 6 * TICRATE + P_Random(pr_heretic);
4902 AmbSfxPtrIndex = P_Random(pr_heretic) % AmbSfxCount;
4903 AmbSfxPtr = LevelAmbientSfx[AmbSfxPtrIndex];
4904 done = true;
4905 break;
4906 default:
4907 I_Error("P_AmbientSound: Unknown afxcmd %d", cmd);
4908 break;
4909 }
4910 }
4911 while (done == false);
4912 }
4913
4914 void P_InitLava(void)
4915 {
4916 if (!raven) return;
4917
4918 memset(&LavaInflictor, 0, sizeof(mobj_t));
4919 LavaInflictor.type = g_lava_type;
4920 LavaInflictor.flags2 = MF2_FIREDAMAGE | MF2_NODMGTHRUST;
4921 }
4922
4923 void P_InitTerrainTypes(void)
4924 {
4925 int i;
4926 int lump;
4927 int size;
4928
4929 if (!raven) return;
4930
4931 size = (numflats + 1) * sizeof(int);
4932 TerrainTypes = Z_Malloc(size);
4933 memset(TerrainTypes, 0, size);
4934 for (i = 0; TerrainTypeDefs[hexen][i].type != -1; i++)
4935 {
4936 lump = W_CheckNumForName2(TerrainTypeDefs[hexen][i].name, ns_flats);
4937 if (lump != LUMP_NOT_FOUND)
4938 {
4939 TerrainTypes[lump - firstflat] = TerrainTypeDefs[hexen][i].type;
4940 }
4941 }
4942 }
4943
4944 void P_CrossHereticSpecialLine(line_t * line, int side, mobj_t * thing, dboolean bossaction)
4945 {
4946 if (!thing->player)
4947 { // Check if trigger allowed by non-player mobj
4948 switch (line->special)
4949 {
4950 case 39: // Trigger_TELEPORT
4951 case 97: // Retrigger_TELEPORT
4952 case 4: // Trigger_Raise_Door
4953 //case 10: // PLAT DOWN-WAIT-UP-STAY TRIGGER
4954 //case 88: // PLAT DOWN-WAIT-UP-STAY RETRIGGER
4955 break;
4956 default:
4957 return;
4958 break;
4959 }
4960 }
4961 switch (line->special)
4962 {
4963 //====================================================
4964 // TRIGGERS
4965 //====================================================
4966 case 2: // Open Door
4967 EV_DoDoor(line, vld_open);
4968 line->special = 0;
4969 break;
4970 case 3: // Close Door
4971 EV_DoDoor(line, vld_close);
4972 line->special = 0;
4973 break;
4974 case 4: // Raise Door
4975 EV_DoDoor(line, vld_normal);
4976 line->special = 0;
4977 break;
4978 case 5: // Raise Floor
4979 EV_DoFloor(line, raiseFloor);
4980 line->special = 0;
4981 break;
4982 case 6: // Fast Ceiling Crush & Raise
4983 EV_DoCeiling(line, fastCrushAndRaise);
4984 line->special = 0;
4985 break;
4986 case 8: // Trigger_Build_Stairs (8 pixel steps)
4987 EV_BuildStairs(line, heretic_build8);
4988 line->special = 0;
4989 break;
4990 case 106: // Trigger_Build_Stairs_16 (16 pixel steps)
4991 EV_BuildStairs(line, heretic_turbo16);
4992 line->special = 0;
4993 break;
4994 case 10: // PlatDownWaitUp
4995 EV_DoPlat(line, downWaitUpStay, 0);
4996 line->special = 0;
4997 break;
4998 case 12: // Light Turn On - brightest near
4999 EV_LightTurnOn(line, 0);
5000 line->special = 0;
5001 break;
5002 case 13: // Light Turn On 255
5003 EV_LightTurnOn(line, 255);
5004 line->special = 0;
5005 break;
5006 case 16: // Close Door 30
5007 EV_DoDoor(line, vld_close30ThenOpen);
5008 line->special = 0;
5009 break;
5010 case 17: // Start Light Strobing
5011 EV_StartLightStrobing(line);
5012 line->special = 0;
5013 break;
5014 case 19: // Lower Floor
5015 EV_DoFloor(line, lowerFloor);
5016 line->special = 0;
5017 break;
5018 case 22: // Raise floor to nearest height and change texture
5019 EV_DoPlat(line, raiseToNearestAndChange, 0);
5020 line->special = 0;
5021 break;
5022 case 25: // Ceiling Crush and Raise
5023 EV_DoCeiling(line, crushAndRaise);
5024 line->special = 0;
5025 break;
5026 case 30: // Raise floor to shortest texture height
5027 // on either side of lines
5028 EV_DoFloor(line, raiseToTexture);
5029 line->special = 0;
5030 break;
5031 case 35: // Lights Very Dark
5032 EV_LightTurnOn(line, 35);
5033 line->special = 0;
5034 break;
5035 case 36: // Lower Floor (TURBO)
5036 EV_DoFloor(line, turboLower);
5037 line->special = 0;
5038 break;
5039 case 37: // LowerAndChange
5040 EV_DoFloor(line, lowerAndChange);
5041 line->special = 0;
5042 break;
5043 case 38: // Lower Floor To Lowest
5044 EV_DoFloor(line, lowerFloorToLowest);
5045 line->special = 0;
5046 break;
5047 case 39: // TELEPORT!
5048 map_format.ev_teleport(0, line->tag, line, side, thing, TELF_VANILLA);
5049 line->special = 0;
5050 break;
5051 case 40: // RaiseCeilingLowerFloor
5052 EV_DoCeiling(line, raiseToHighest);
5053 EV_DoFloor(line, lowerFloorToLowest);
5054 line->special = 0;
5055 break;
5056 case 44: // Ceiling Crush
5057 EV_DoCeiling(line, lowerAndCrush);
5058 line->special = 0;
5059 break;
5060 case 52: // EXIT!
5061 G_ExitLevel(0);
5062 line->special = 0;
5063 break;
5064 case 53: // Perpetual Platform Raise
5065 EV_DoPlat(line, perpetualRaise, 0);
5066 line->special = 0;
5067 break;
5068 case 54: // Platform Stop
5069 EV_StopPlat(line);
5070 line->special = 0;
5071 break;
5072 case 56: // Raise Floor Crush
5073 EV_DoFloor(line, raiseFloorCrush);
5074 line->special = 0;
5075 break;
5076 case 57: // Ceiling Crush Stop
5077 EV_CeilingCrushStop(line);
5078 line->special = 0;
5079 break;
5080 case 58: // Raise Floor 24
5081 EV_DoFloor(line, raiseFloor24);
5082 line->special = 0;
5083 break;
5084 case 59: // Raise Floor 24 And Change
5085 EV_DoFloor(line, raiseFloor24AndChange);
5086 line->special = 0;
5087 break;
5088 case 104: // Turn lights off in sector(tag)
5089 EV_TurnTagLightsOff(line);
5090 line->special = 0;
5091 break;
5092 case 105: // Trigger_SecretExit
5093 G_SecretExitLevel(0);
5094 line->special = 0;
5095 break;
5096
5097 //====================================================
5098 // RE-DOABLE TRIGGERS
5099 //====================================================
5100
5101 case 72: // Ceiling Crush
5102 EV_DoCeiling(line, lowerAndCrush);
5103 break;
5104 case 73: // Ceiling Crush and Raise
5105 EV_DoCeiling(line, crushAndRaise);
5106 break;
5107 case 74: // Ceiling Crush Stop
5108 EV_CeilingCrushStop(line);
5109 break;
5110 case 75: // Close Door
5111 EV_DoDoor(line, vld_close);
5112 break;
5113 case 76: // Close Door 30
5114 EV_DoDoor(line, vld_close30ThenOpen);
5115 break;
5116 case 77: // Fast Ceiling Crush & Raise
5117 EV_DoCeiling(line, fastCrushAndRaise);
5118 break;
5119 case 79: // Lights Very Dark
5120 EV_LightTurnOn(line, 35);
5121 break;
5122 case 80: // Light Turn On - brightest near
5123 EV_LightTurnOn(line, 0);
5124 break;
5125 case 81: // Light Turn On 255
5126 EV_LightTurnOn(line, 255);
5127 break;
5128 case 82: // Lower Floor To Lowest
5129 EV_DoFloor(line, lowerFloorToLowest);
5130 break;
5131 case 83: // Lower Floor
5132 EV_DoFloor(line, lowerFloor);
5133 break;
5134 case 84: // LowerAndChange
5135 EV_DoFloor(line, lowerAndChange);
5136 break;
5137 case 86: // Open Door
5138 EV_DoDoor(line, vld_open);
5139 break;
5140 case 87: // Perpetual Platform Raise
5141 EV_DoPlat(line, perpetualRaise, 0);
5142 break;
5143 case 88: // PlatDownWaitUp
5144 EV_DoPlat(line, downWaitUpStay, 0);
5145 break;
5146 case 89: // Platform Stop
5147 EV_StopPlat(line);
5148 break;
5149 case 90: // Raise Door
5150 EV_DoDoor(line, vld_normal);
5151 break;
5152 case 100: // Retrigger_Raise_Door_Turbo
5153 EV_DoDoor(line, vld_normal_turbo);
5154 break;
5155 case 91: // Raise Floor
5156 EV_DoFloor(line, raiseFloor);
5157 break;
5158 case 92: // Raise Floor 24
5159 EV_DoFloor(line, raiseFloor24);
5160 break;
5161 case 93: // Raise Floor 24 And Change
5162 EV_DoFloor(line, raiseFloor24AndChange);
5163 break;
5164 case 94: // Raise Floor Crush
5165 EV_DoFloor(line, raiseFloorCrush);
5166 break;
5167 case 95: // Raise floor to nearest height and change texture
5168 EV_DoPlat(line, raiseToNearestAndChange, 0);
5169 break;
5170 case 96: // Raise floor to shortest texture height
5171 // on either side of lines
5172 EV_DoFloor(line, raiseToTexture);
5173 break;
5174 case 97: // TELEPORT!
5175 map_format.ev_teleport(0, line->tag, line, side, thing, TELF_VANILLA);
5176 break;
5177 case 98: // Lower Floor (TURBO)
5178 EV_DoFloor(line, turboLower);
5179 break;
5180 }
5181 }
5182
5183 void P_PlayerInHereticSector(player_t * player, sector_t * sector)
5184 {
5185 static int pushTab[5] = {
5186 2048 * 5,
5187 2048 * 10,
5188 2048 * 25,
5189 2048 * 30,
5190 2048 * 35
5191 };
5192
5193 switch (sector->special)
5194 {
5195 case 7: // Damage_Sludge
5196 if (!(leveltime & 31))
5197 {
5198 P_DamageMobj(player->mo, NULL, NULL, 4);
5199 }
5200 break;
5201 case 5: // Damage_LavaWimpy
5202 if (!(leveltime & 15))
5203 {
5204 P_DamageMobj(player->mo, &LavaInflictor, NULL, 5);
5205 P_HitFloor(player->mo);
5206 }
5207 break;
5208 case 16: // Damage_LavaHefty
5209 if (!(leveltime & 15))
5210 {
5211 P_DamageMobj(player->mo, &LavaInflictor, NULL, 8);
5212 P_HitFloor(player->mo);
5213 }
5214 break;
5215 case 4: // Scroll_EastLavaDamage
5216 P_Thrust(player, 0, 2048 * 28);
5217 if (!(leveltime & 15))
5218 {
5219 P_DamageMobj(player->mo, &LavaInflictor, NULL, 5);
5220 P_HitFloor(player->mo);
5221 }
5222 break;
5223 case 9: // SecretArea
5224 P_CollectSecretVanilla(sector, player);
5225
5226 break;
5227 case 11: // Exit_SuperDamage (DOOM E1M8 finale)
5228 break;
5229
5230 case 25:
5231 case 26:
5232 case 27:
5233 case 28:
5234 case 29: // Scroll_North
5235 P_Thrust(player, ANG90, pushTab[sector->special - 25]);
5236 break;
5237 case 20:
5238 case 21:
5239 case 22:
5240 case 23:
5241 case 24: // Scroll_East
5242 P_Thrust(player, 0, pushTab[sector->special - 20]);
5243 break;
5244 case 30:
5245 case 31:
5246 case 32:
5247 case 33:
5248 case 34: // Scroll_South
5249 P_Thrust(player, ANG270, pushTab[sector->special - 30]);
5250 break;
5251 case 35:
5252 case 36:
5253 case 37:
5254 case 38:
5255 case 39: // Scroll_West
5256 P_Thrust(player, ANG180, pushTab[sector->special - 35]);
5257 break;
5258
5259 case 40:
5260 case 41:
5261 case 42:
5262 case 43:
5263 case 44:
5264 case 45:
5265 case 46:
5266 case 47:
5267 case 48:
5268 case 49:
5269 case 50:
5270 case 51:
5271 // Wind specials are handled in (P_mobj):P_XYMovement
5272 break;
5273
5274 case 15: // Friction_Low
5275 // Only used in (P_mobj):P_XYMovement and (P_user):P_Thrust
5276 break;
5277
5278 default:
5279 I_Error("P_PlayerInSpecialSector: "
5280 "unknown special %i", sector->special);
5281 }
5282 }
5283
5284 void P_SpawnLineSpecials(void)
5285 {
5286 int i;
5287
5288 if (!heretic) return;
5289
5290 //
5291 // Init line EFFECTs
5292 //
5293
5294 numlinespecials = 0;
5295 for (i = 0; i < numlines; i++)
5296 switch (lines[i].special)
5297 {
5298 case 48: // Effect_Scroll_Left
5299 case 99: // Effect_Scroll_Right
5300 linespeciallist[numlinespecials] = &lines[i];
5301 numlinespecials++;
5302 break;
5303 }
5304 }
5305
5306 // hexen
5307
5308 #define MAX_TAGGED_LINES 64
5309
5310 static struct
5311 {
5312 line_t *line;
5313 int lineTag;
5314 } TaggedLines[MAX_TAGGED_LINES];
5315 static int TaggedLineCount;
5316
5317 void P_PlayerOnSpecialFlat(player_t * player, int floorType)
5318 {
5319 if (player->mo->z != player->mo->floorz)
5320 { // Player is not touching the floor
5321 return;
5322 }
5323 switch (floorType)
5324 {
5325 case FLOOR_LAVA:
5326 if (!(leveltime & 31))
5327 {
5328 P_DamageMobj(player->mo, &LavaInflictor, NULL, 10);
5329 S_StartMobjSound(player->mo, hexen_sfx_lava_sizzle);
5330 }
5331 break;
5332 default:
5333 break;
5334 }
5335 }
5336
5337 line_t *P_FindLine(int lineTag, int *searchPosition)
5338 {
5339 int i;
5340
5341 for (i = *searchPosition + 1; i < TaggedLineCount; i++)
5342 {
5343 if (TaggedLines[i].lineTag == lineTag)
5344 {
5345 *searchPosition = i;
5346 return TaggedLines[i].line;
5347 }
5348 }
5349 *searchPosition = -1;
5350 return NULL;
5351 }
5352
5353 dboolean EV_SectorSoundChange(byte * args)
5354 {
5355 const int *id_p;
5356 dboolean rtn;
5357
5358 if (!args[0])
5359 {
5360 return false;
5361 }
5362 rtn = false;
5363 FIND_SECTORS(id_p, args[0])
5364 {
5365 sectors[*id_p].seqType = args[1];
5366 rtn = true;
5367 }
5368 return rtn;
5369 }
5370
5371 char LockedBuffer[80];
5372
5373 static dboolean CheckedLockedDoor(mobj_t * mo, byte lock)
5374 {
5375 extern char *TextKeyMessages[11];
5376
5377 if (!mo->player)
5378 {
5379 return false;
5380 }
5381 if (!lock)
5382 {
5383 return true;
5384 }
5385 if (!mo->player->cards[lock - 1])
5386 {
5387 snprintf(LockedBuffer, sizeof(LockedBuffer),
5388 "YOU NEED THE %s\n", TextKeyMessages[lock - 1]);
5389 P_SetMessage(mo->player, LockedBuffer, true);
5390 S_StartMobjSound(mo, hexen_sfx_door_locked);
5391 return false;
5392 }
5393 return true;
5394 }
5395
5396 dboolean EV_LineSearchForPuzzleItem(line_t * line, byte * args, mobj_t * mo)
5397 {
5398 player_t *player;
5399 int i;
5400 int type;
5401 artitype_t arti;
5402
5403 if (!mo)
5404 return false;
5405 player = mo->player;
5406 if (!player)
5407 return false;
5408
5409 // Search player's inventory for puzzle items
5410 for (i = 0; i < player->artifactCount; i++)
5411 {
5412 arti = player->inventory[i].type;
5413 type = arti - hexen_arti_firstpuzzitem;
5414 if (type < 0)
5415 continue;
5416 if (type == line->special_args[0])
5417 {
5418 // A puzzle item was found for the line
5419 if (P_UseArtifact(player, arti))
5420 {
5421 // A puzzle item was found for the line
5422 P_PlayerRemoveArtifact(player, i);
5423 if (player == &players[consoleplayer])
5424 {
5425 if (arti < hexen_arti_firstpuzzitem)
5426 {
5427 S_StartVoidSound(hexen_sfx_artifact_use);
5428 }
5429 else
5430 {
5431 S_StartVoidSound(hexen_sfx_puzzle_success);
5432 }
5433 ArtifactFlash = 4;
5434 }
5435 return true;
5436 }
5437 }
5438 }
5439 return false;
5440 }
5441
5442 dboolean P_TestActivateZDoomLine(line_t *line, mobj_t *mo, int side, line_activation_t activationType)
5443 {
5444 line_activation_t lineActivation;
5445
5446 lineActivation = line->activation;
5447
5448 if (line->flags & ML_FIRSTSIDEONLY && side)
5449 {
5450 return false;
5451 }
5452
5453 if (
5454 line->special == zl_teleport &&
5455 lineActivation & SPAC_CROSS &&
5456 activationType == SPAC_PCROSS &&
5457 mo && mo->flags & MF_MISSILE
5458 )
5459 { // Let missiles use regular player teleports
5460 lineActivation |= SPAC_PCROSS;
5461 }
5462
5463 if (activationType == SPAC_USE || activationType == SPAC_USEBACK)
5464 {
5465 if (
5466 (line->flags & ML_CHECKSWITCHRANGE || map_info.flags & MI_CHECK_SWITCH_RANGE) &&
5467 !P_CheckSwitchRange(line, mo, side)
5468 )
5469 {
5470 return false;
5471 }
5472 }
5473
5474 if (activationType == SPAC_USE &&
5475 lineActivation & SPAC_MUSE &&
5476 mo && !mo->player && mo->flags2 & MF2_CANUSEWALLS)
5477 {
5478 return true;
5479 }
5480
5481 if (activationType == SPAC_PUSH &&
5482 lineActivation & SPAC_MPUSH &&
5483 mo && !mo->player && mo->flags2 & MF2_PUSHWALL)
5484 {
5485 return true;
5486 }
5487
5488 if (!(lineActivation & activationType))
5489 {
5490 if (activationType != SPAC_MCROSS || lineActivation != SPAC_CROSS)
5491 {
5492 return false;
5493 }
5494 }
5495
5496 if (activationType == SPAC_ANYCROSS)
5497 {
5498 return true;
5499 }
5500
5501 if (
5502 mo && !mo->player &&
5503 !(mo->flags & MF_MISSILE) &&
5504 !(line->flags & ML_MONSTERSCANACTIVATE) &&
5505 (activationType != SPAC_MCROSS || !(lineActivation & SPAC_MCROSS))
5506 )
5507 {
5508 dboolean noway = true;
5509
5510 // [RH] monsters' ability to activate this line depends on its type
5511 // In Hexen, only MCROSS lines could be activated by monsters. With
5512 // lax activation checks, monsters can also activate certain lines
5513 // even without them being marked as monster activate-able. This is
5514 // the default for non-Hexen maps in Hexen format.
5515 if (!(map_info.flags & MI_LAX_MONSTER_ACTIVATION))
5516 {
5517 return false;
5518 }
5519
5520 if ((activationType == SPAC_USE || activationType == SPAC_PUSH) && line->flags & ML_SECRET)
5521 return false; // never open secret doors
5522
5523 switch (activationType)
5524 {
5525 case SPAC_USE:
5526 case SPAC_PUSH:
5527 switch (line->special)
5528 {
5529 case zl_door_raise:
5530 if (line->special_args[0] == 0 && line->special_args[1] < 64)
5531 noway = false;
5532 break;
5533 case zl_teleport:
5534 case zl_teleport_no_fog:
5535 noway = false;
5536 }
5537 break;
5538
5539 case SPAC_MCROSS:
5540 if (!(lineActivation & SPAC_MCROSS))
5541 {
5542 switch (line->special)
5543 {
5544 case zl_door_raise:
5545 if (line->special_args[1] >= 64)
5546 break;
5547 case zl_teleport:
5548 case zl_teleport_no_fog:
5549 case zl_teleport_line:
5550 case zl_plat_down_wait_up_stay_lip:
5551 case zl_plat_down_wait_up_stay:
5552 noway = false;
5553 }
5554 }
5555 else
5556 noway = false;
5557 break;
5558
5559 default:
5560 noway = false;
5561 }
5562 return !noway;
5563 }
5564
5565 if (
5566 activationType == SPAC_MCROSS &&
5567 !(lineActivation & SPAC_MCROSS) &&
5568 !(line->flags & ML_MONSTERSCANACTIVATE)
5569 )
5570 {
5571 return false;
5572 }
5573
5574 return true;
5575 }
5576
5577 dboolean P_TestActivateHexenLine(line_t *line, mobj_t *mo, int side, line_activation_t activationType)
5578 {
5579 line_activation_t lineActivation;
5580
5581 lineActivation = line->activation;
5582
5583 if (lineActivation != activationType)
5584 {
5585 return false;
5586 }
5587
5588 if (!mo->player && !(mo->flags & MF_MISSILE))
5589 {
5590 if (lineActivation != SPAC_MCROSS)
5591 { // currently, monsters can only activate the MCROSS activation type
5592 return false;
5593 }
5594 if (line->flags & ML_SECRET)
5595 return false; // never open secret doors
5596 }
5597
5598 return true;
5599 }
5600
5601 dboolean P_ActivateLine(line_t * line, mobj_t * mo, int side, line_activation_t activationType)
5602 {
5603 dboolean repeat;
5604 dboolean buttonSuccess;
5605
5606 if (!map_format.test_activate_line(line, mo, side, activationType))
5607 {
5608 return false;
5609 }
5610
5611 if (line->locknumber)
5612 {
5613 dboolean legacy;
5614
5615 switch (line->special)
5616 {
5617 case zl_door_close:
5618 case zl_door_open:
5619 case zl_door_raise:
5620 case zl_door_locked_raise:
5621 case zl_door_close_wait_open:
5622 case zl_door_wait_raise:
5623 case zl_door_wait_close:
5624 case zl_generic_door:
5625 legacy = true;
5626 break;
5627 default:
5628 legacy = false;
5629 }
5630
5631 if (!P_CheckKeys(mo, line->locknumber, legacy))
5632 {
5633 return false;
5634 }
5635 }
5636
5637 repeat = (line->flags & ML_REPEATSPECIAL) != 0;
5638
5639 buttonSuccess =
5640 map_format.execute_line_special(line->special, line->special_args, line, side, mo);
5641
5642 if (!repeat && buttonSuccess)
5643 { // clear the special on non-retriggerable lines
5644 line->special = 0;
5645 }
5646
5647 if (buttonSuccess && line->activation & map_format.switch_activation)
5648 {
5649 P_ChangeSwitchTexture(line, repeat);
5650 }
5651
5652 return true;
5653 }
5654
5655 void P_PlayerInHexenSector(player_t * player, sector_t * sector)
5656 {
5657 static int pushTab[3] = {
5658 2048 * 5,
5659 2048 * 10,
5660 2048 * 25
5661 };
5662
5663 switch (sector->special)
5664 {
5665 case 9: // SecretArea
5666 P_CollectSecretVanilla(sector, player);
5667 break;
5668
5669 case 201:
5670 case 202:
5671 case 203: // Scroll_North_xxx
5672 P_Thrust(player, ANG90, pushTab[sector->special - 201]);
5673 break;
5674 case 204:
5675 case 205:
5676 case 206: // Scroll_East_xxx
5677 P_Thrust(player, 0, pushTab[sector->special - 204]);
5678 break;
5679 case 207:
5680 case 208:
5681 case 209: // Scroll_South_xxx
5682 P_Thrust(player, ANG270, pushTab[sector->special - 207]);
5683 break;
5684 case 210:
5685 case 211:
5686 case 212: // Scroll_West_xxx
5687 P_Thrust(player, ANG180, pushTab[sector->special - 210]);
5688 break;
5689 case 213:
5690 case 214:
5691 case 215: // Scroll_NorthWest_xxx
5692 P_Thrust(player, ANG90 + ANG45, pushTab[sector->special - 213]);
5693 break;
5694 case 216:
5695 case 217:
5696 case 218: // Scroll_NorthEast_xxx
5697 P_Thrust(player, ANG45, pushTab[sector->special - 216]);
5698 break;
5699 case 219:
5700 case 220:
5701 case 221: // Scroll_SouthEast_xxx
5702 P_Thrust(player, ANG270 + ANG45, pushTab[sector->special - 219]);
5703 break;
5704 case 222:
5705 case 223:
5706 case 224: // Scroll_SouthWest_xxx
5707 P_Thrust(player, ANG180 + ANG45, pushTab[sector->special - 222]);
5708 break;
5709
5710 case 40:
5711 case 41:
5712 case 42:
5713 case 43:
5714 case 44:
5715 case 45:
5716 case 46:
5717 case 47:
5718 case 48:
5719 case 49:
5720 case 50:
5721 case 51:
5722 // Wind specials are handled in (P_mobj):P_XYMovement
5723 break;
5724
5725 case 26: // Stairs_Special1
5726 case 27: // Stairs_Special2
5727 // Used in (P_floor):ProcessStairSector
5728 break;
5729
5730 case 198: // Lightning Special
5731 case 199: // Lightning Flash special
5732 case 200: // Sky2
5733 // Used in (R_plane):R_Drawplanes
5734 break;
5735 default:
5736 I_Error("P_PlayerInSpecialSector: "
5737 "unknown special %i", sector->special);
5738 }
5739 }
5740
5741 #include "hexen/a_action.h"
5742 #include "hexen/p_anim.h"
5743 #include "hexen/p_things.h"
5744 #include "hexen/p_acs.h"
5745 #include "hexen/po_man.h"
5746
5747 static dboolean P_ArgToCrushType(int arg)
5748 {
5749 return arg == 1 ? false : arg == 2 ? true : hexen;
5750 }
5751
5752 static crushmode_e P_ArgToCrushMode(int arg, dboolean slowdown)
5753 {
5754 static const crushmode_e map[] = { crushDoom, crushHexen, crushSlowdown };
5755
5756 if (arg >= 1 && arg <= 3) return map[arg - 1];
5757
5758 return hexen ? crushHexen : slowdown ? crushSlowdown : crushDoom;
5759 }
5760
5761 static int P_ArgToCrush(int arg)
5762 {
5763 return (arg > 0) ? arg : NO_CRUSH;
5764 }
5765
5766 static byte P_ArgToChange(int arg)
5767 {
5768 static const byte ChangeMap[8] = { 0, 1, 5, 3, 7, 2, 6, 0 };
5769
5770 return (arg >= 0 && arg < 8) ? ChangeMap[arg] : 0;
5771 }
5772
5773 static fixed_t P_ArgToSpeed(fixed_t arg)
5774 {
5775 return arg * FRACUNIT / 8;
5776 }
5777
5778 static fixed_t P_ArgsToFixed(fixed_t arg_i, fixed_t arg_f)
5779 {
5780 return (arg_i << FRACBITS) + (arg_f << FRACBITS) / 100;
5781 }
5782
5783 static angle_t P_ArgToAngle(angle_t arg)
5784 {
5785 return arg * (ANG180 / 128);
5786 }
5787
5788 dboolean P_ExecuteZDoomLineSpecial(int special, int * args, line_t * line, int side, mobj_t * mo)
5789 {
5790 dboolean buttonSuccess = false;
5791
5792 switch (special)
5793 {
5794 case zl_door_close:
5795 buttonSuccess = EV_DoZDoomDoor(closeDoor, line, mo, args[0],
5796 args[1], 0, 0, args[2], false, 0);
5797 break;
5798 case zl_door_open:
5799 buttonSuccess = EV_DoZDoomDoor(openDoor, line, mo, args[0],
5800 args[1], 0, 0, args[2], false, 0);
5801 break;
5802 case zl_door_raise:
5803 buttonSuccess = EV_DoZDoomDoor(normal, line, mo, args[0],
5804 args[1], args[2], 0, args[3], false, 0);
5805 break;
5806 case zl_door_locked_raise:
5807 buttonSuccess = EV_DoZDoomDoor(args[2] ? normal : openDoor, line, mo, args[0],
5808 args[1], args[2], args[3], args[4], false, 0);
5809 break;
5810 case zl_door_close_wait_open:
5811 buttonSuccess = EV_DoZDoomDoor(genCdO, line, mo, args[0],
5812 args[1], args[2] * 35 / 8, 0, args[3], false, 0);
5813 break;
5814 case zl_door_wait_raise:
5815 buttonSuccess = EV_DoZDoomDoor(waitRaiseDoor, line, mo, args[0],
5816 args[1], args[2], 0, args[4], false, args[3]);
5817 break;
5818 case zl_door_wait_close:
5819 buttonSuccess = EV_DoZDoomDoor(waitCloseDoor, line, mo, args[0],
5820 args[1], 0, 0, args[3], false, args[2]);
5821 break;
5822 case zl_generic_door:
5823 {
5824 int tag, lightTag;
5825 vldoor_e type;
5826 dboolean boomgen = false;
5827
5828 switch (args[2] & 63)
5829 {
5830 case 0:
5831 type = normal;
5832 break;
5833 case 1:
5834 type = openDoor;
5835 break;
5836 case 2:
5837 type = genCdO;
5838 break;
5839 case 3:
5840 type = closeDoor;
5841 break;
5842 default:
5843 return 0;
5844 }
5845
5846 // Boom doesn't allow manual generalized doors to be activated while they move
5847 if (args[2] & 64)
5848 boomgen = true;
5849
5850 if (args[2] & 128)
5851 {
5852 tag = 0;
5853 lightTag = args[0];
5854 }
5855 else
5856 {
5857 tag = args[0];
5858 lightTag = 0;
5859 }
5860
5861 buttonSuccess = EV_DoZDoomDoor(type, line, mo, tag, args[1],
5862 args[3] * 35 / 8, args[4], lightTag, boomgen, 0);
5863 }
5864 break;
5865 case zl_pillar_build:
5866 buttonSuccess = EV_DoZDoomPillar(pillarBuild, line, args[0], P_ArgToSpeed(args[1]),
5867 args[2], 0, NO_CRUSH, false);
5868 break;
5869 case zl_pillar_build_and_crush:
5870 buttonSuccess = EV_DoZDoomPillar(pillarBuild, line, args[0], P_ArgToSpeed(args[1]),
5871 args[2], 0, args[3], P_ArgToCrushType(args[4]));
5872 break;
5873 case zl_pillar_open:
5874 buttonSuccess = EV_DoZDoomPillar(pillarOpen, line, args[0], P_ArgToSpeed(args[1]),
5875 args[2], args[3], NO_CRUSH, false);
5876 break;
5877 case zl_elevator_move_to_floor:
5878 buttonSuccess = EV_DoZDoomElevator(line, elevateCurrent, P_ArgToSpeed(args[1]),
5879 0, args[0]);
5880 break;
5881 case zl_elevator_raise_to_nearest:
5882 buttonSuccess = EV_DoZDoomElevator(line, elevateUp, P_ArgToSpeed(args[1]),
5883 0, args[0]);
5884 break;
5885 case zl_elevator_lower_to_nearest:
5886 buttonSuccess = EV_DoZDoomElevator(line, elevateDown, P_ArgToSpeed(args[1]),
5887 0, args[0]);
5888 break;
5889 case zl_floor_and_ceiling_lower_by_value:
5890 buttonSuccess = EV_DoZDoomElevator(line, elevateLower, P_ArgToSpeed(args[1]),
5891 args[2], args[0]);
5892 break;
5893 case zl_floor_and_ceiling_raise_by_value:
5894 buttonSuccess = EV_DoZDoomElevator(line, elevateRaise, P_ArgToSpeed(args[1]),
5895 args[2], args[0]);
5896 break;
5897 case zl_floor_lower_by_value:
5898 buttonSuccess = EV_DoZDoomFloor(floorLowerByValue, line, args[0], args[1], args[2],
5899 NO_CRUSH, P_ArgToChange(args[3]), false, false);
5900 break;
5901 case zl_floor_lower_to_lowest:
5902 buttonSuccess = EV_DoZDoomFloor(floorLowerToLowest, line, args[0], args[1], 0,
5903 NO_CRUSH, P_ArgToChange(args[2]), false, false);
5904 break;
5905 case zl_floor_lower_to_highest:
5906 buttonSuccess = EV_DoZDoomFloor(floorLowerToHighest, line, args[0], args[1],
5907 args[2] - 128, NO_CRUSH, 0, false, args[3] == 1);
5908 break;
5909 case zl_floor_lower_to_highest_ee:
5910 buttonSuccess = EV_DoZDoomFloor(floorLowerToHighest, line, args[0], args[1], 0,
5911 NO_CRUSH, P_ArgToChange(args[2]), false, false);
5912 break;
5913 case zl_floor_lower_to_nearest:
5914 buttonSuccess = EV_DoZDoomFloor(floorLowerToNearest, line, args[0], args[1], 0,
5915 NO_CRUSH, P_ArgToChange(args[2]), false, false);
5916 break;
5917 case zl_floor_raise_by_value:
5918 buttonSuccess = EV_DoZDoomFloor(floorRaiseByValue, line, args[0], args[1], args[2],
5919 P_ArgToCrush(args[4]), P_ArgToChange(args[3]), true, false);
5920 break;
5921 case zl_floor_raise_to_highest:
5922 buttonSuccess = EV_DoZDoomFloor(floorRaiseToHighest, line, args[0], args[1], 0,
5923 P_ArgToCrush(args[3]), P_ArgToChange(args[2]), true, false);
5924 break;
5925 case zl_floor_raise_to_nearest:
5926 buttonSuccess = EV_DoZDoomFloor(floorRaiseToNearest, line, args[0], args[1], 0,
5927 P_ArgToCrush(args[3]), P_ArgToChange(args[2]), true, false);
5928 break;
5929 case zl_floor_raise_to_lowest:
5930 buttonSuccess = EV_DoZDoomFloor(floorRaiseToLowest, line, args[0], 2, 0,
5931 P_ArgToCrush(args[3]), P_ArgToChange(args[2]), true, false);
5932 break;
5933 case zl_floor_raise_and_crush:
5934 buttonSuccess = EV_DoZDoomFloor(floorRaiseAndCrush, line, args[0], args[1], 0,
5935 args[2], 0, P_ArgToCrushType(args[3]), false);
5936 break;
5937 case zl_floor_raise_and_crushdoom:
5938 buttonSuccess = EV_DoZDoomFloor(floorRaiseAndCrushDoom, line, args[0], args[1], 0,
5939 args[2], 0, P_ArgToCrushType(args[3]), false);
5940 break;
5941 case zl_floor_raise_by_value_times_8:
5942 buttonSuccess = EV_DoZDoomFloor(floorRaiseByValue, line, args[0], args[1], args[2] * 8,
5943 P_ArgToCrush(args[4]), P_ArgToChange(args[3]), true, false);
5944 break;
5945 case zl_floor_lower_by_value_times_8:
5946 buttonSuccess = EV_DoZDoomFloor(floorLowerByValue, line, args[0], args[1], args[2] * 8,
5947 NO_CRUSH, P_ArgToChange(args[3]), false, false);
5948 break;
5949 case zl_floor_lower_instant:
5950 buttonSuccess = EV_DoZDoomFloor(floorLowerInstant, line, args[0], 0, args[2] * 8,
5951 NO_CRUSH, P_ArgToChange(args[3]), false, false);
5952 break;
5953 case zl_floor_raise_instant:
5954 buttonSuccess = EV_DoZDoomFloor(floorRaiseInstant, line, args[0], 0, args[2] * 8,
5955 P_ArgToCrush(args[4]), P_ArgToChange(args[3]), true, false);
5956 break;
5957 case zl_floor_to_ceiling_instant:
5958 buttonSuccess = EV_DoZDoomFloor(floorLowerToCeiling, line, args[0], 0, args[3],
5959 P_ArgToCrush(args[2]), P_ArgToChange(args[1]), true, false);
5960 break;
5961 case zl_floor_move_to_value:
5962 buttonSuccess = EV_DoZDoomFloor(floorMoveToValue, line, args[0], args[1],
5963 args[2] * (args[3] ? -1 : 1),
5964 NO_CRUSH, P_ArgToChange(args[4]), false, false);
5965 break;
5966 case zl_floor_move_to_value_times_8:
5967 buttonSuccess = EV_DoZDoomFloor(floorMoveToValue, line, args[0], args[1],
5968 args[2] * 8 * (args[3] ? -1 : 1),
5969 NO_CRUSH, P_ArgToChange(args[4]), false, false);
5970 break;
5971 case zl_floor_move_to_value_and_crush:
5972 buttonSuccess = EV_DoZDoomFloor(floorMoveToValue, line, args[0], args[1],
5973 args[2], P_ArgToCrush(args[3]),
5974 0, P_ArgToCrushType(args[4]), false);
5975 break;
5976 case zl_floor_raise_to_lowest_ceiling:
5977 buttonSuccess = EV_DoZDoomFloor(floorRaiseToLowestCeiling, line, args[0], args[1], 0,
5978 P_ArgToCrush(args[3]), P_ArgToChange(args[2]), true, false);
5979 break;
5980 case zl_floor_lower_to_lowest_ceiling:
5981 buttonSuccess = EV_DoZDoomFloor(floorLowerToLowestCeiling, line, args[0], args[1], args[4],
5982 NO_CRUSH, P_ArgToChange(args[2]), true, false);
5983 break;
5984 case zl_floor_raise_by_texture:
5985 buttonSuccess = EV_DoZDoomFloor(floorRaiseByTexture, line, args[0], args[1], 0,
5986 P_ArgToCrush(args[3]), P_ArgToChange(args[2]), true, false);
5987 break;
5988 case zl_floor_lower_by_texture:
5989 buttonSuccess = EV_DoZDoomFloor(floorLowerByTexture, line, args[0], args[1], 0,
5990 NO_CRUSH, P_ArgToChange(args[2]), true, false);
5991 break;
5992 case zl_floor_raise_to_ceiling:
5993 buttonSuccess = EV_DoZDoomFloor(floorRaiseToCeiling, line, args[0], args[1], args[4],
5994 P_ArgToCrush(args[3]), P_ArgToChange(args[2]), true, false);
5995 break;
5996 case zl_floor_raise_by_value_tx_ty:
5997 buttonSuccess = EV_DoZDoomFloor(floorRaiseAndChange, line, args[0], args[1], args[2],
5998 NO_CRUSH, 0, false, false);
5999 break;
6000 case zl_floor_lower_to_lowest_tx_ty:
6001 buttonSuccess = EV_DoZDoomFloor(floorLowerAndChange, line, args[0], args[1], args[2],
6002 NO_CRUSH, 0, false, false);
6003 break;
6004 case zl_generic_floor:
6005 {
6006 floor_e type;
6007 dboolean raise_or_lower;
6008 byte index;
6009
6010 static floor_e floor_type[2][7] = {
6011 {
6012 floorLowerByValue,
6013 floorLowerToHighest,
6014 floorLowerToLowest,
6015 floorLowerToNearest,
6016 floorLowerToLowestCeiling,
6017 floorLowerToCeiling,
6018 floorLowerByTexture,
6019 },
6020 {
6021 floorRaiseByValue,
6022 floorRaiseToHighest,
6023 floorRaiseToLowest,
6024 floorRaiseToNearest,
6025 floorRaiseToLowestCeiling,
6026 floorRaiseToCeiling,
6027 floorRaiseByTexture,
6028 }
6029 };
6030
6031 raise_or_lower = (args[4] & 8) >> 3;
6032 index = (args[3] < 7) ? args[3] : 0;
6033 type = floor_type[raise_or_lower][index];
6034
6035 buttonSuccess = EV_DoZDoomFloor(type, line, args[0], args[1], args[2],
6036 (args[4] & 16) ? 20 : NO_CRUSH, args[4] & 7, false, false);
6037 }
6038 break;
6039 case zl_floor_crush_stop:
6040 buttonSuccess = EV_ZDoomFloorCrushStop(args[0]);
6041 break;
6042 case zl_floor_stop:
6043 buttonSuccess = EV_ZDoomFloorStop(args[0], line);
6044 break;
6045 case zl_floor_donut:
6046 buttonSuccess = EV_DoZDoomDonut(args[0], line, P_ArgToSpeed(args[1]), P_ArgToSpeed(args[2]));
6047 break;
6048 case zl_ceiling_lower_by_value:
6049 buttonSuccess = EV_DoZDoomCeiling(ceilLowerByValue, line, args[0],
6050 P_ArgToSpeed(args[1]), 0,
6051 args[2], P_ArgToCrush(args[4]), 0,
6052 P_ArgToChange(args[3]), false);
6053 break;
6054 case zl_ceiling_raise_by_value:
6055 buttonSuccess = EV_DoZDoomCeiling(ceilRaiseByValue, line, args[0],
6056 P_ArgToSpeed(args[1]), 0,
6057 args[2], P_ArgToCrush(args[4]), 0,
6058 P_ArgToChange(args[3]), false);
6059 break;
6060 case zl_ceiling_lower_by_value_times_8:
6061 buttonSuccess = EV_DoZDoomCeiling(ceilLowerByValue, line, args[0],
6062 P_ArgToSpeed(args[1]), 0,
6063 args[2] * 8, NO_CRUSH, 0,
6064 P_ArgToChange(args[3]), false);
6065 break;
6066 case zl_ceiling_raise_by_value_times_8:
6067 buttonSuccess = EV_DoZDoomCeiling(ceilRaiseByValue, line, args[0],
6068 P_ArgToSpeed(args[1]), 0,
6069 args[2] * 8, NO_CRUSH, 0,
6070 P_ArgToChange(args[3]), false);
6071 break;
6072 case zl_ceiling_crush_and_raise:
6073 buttonSuccess = EV_DoZDoomCeiling(ceilCrushAndRaise, line, args[0],
6074 P_ArgToSpeed(args[1]), P_ArgToSpeed(args[1]) / 2,
6075 8, args[2], 0,
6076 0, P_ArgToCrushMode(args[3], false));
6077 break;
6078 case zl_ceiling_lower_and_crush:
6079 buttonSuccess = EV_DoZDoomCeiling(ceilLowerAndCrush, line, args[0],
6080 P_ArgToSpeed(args[1]), P_ArgToSpeed(args[1]),
6081 8, args[2], 0,
6082 0, P_ArgToCrushMode(args[3], args[1] == 8));
6083 break;
6084 case zl_ceiling_lower_and_crush_dist:
6085 buttonSuccess = EV_DoZDoomCeiling(ceilLowerAndCrush, line, args[0],
6086 P_ArgToSpeed(args[1]), P_ArgToSpeed(args[1]),
6087 args[3], args[2], 0,
6088 0, P_ArgToCrushMode(args[4], args[1] == 8));
6089 break;
6090 case zl_ceiling_crush_raise_and_stay:
6091 buttonSuccess = EV_DoZDoomCeiling(ceilCrushRaiseAndStay, line, args[0],
6092 P_ArgToSpeed(args[1]), P_ArgToSpeed(args[1]) / 2,
6093 8, args[2], 0,
6094 0, P_ArgToCrushMode(args[3], false));
6095 break;
6096 case zl_ceiling_move_to_value_times_8:
6097 buttonSuccess = EV_DoZDoomCeiling(ceilMoveToValue, line, args[0],
6098 P_ArgToSpeed(args[1]), 0,
6099 args[2] * 8 * (args[3] ? -1 : 1), NO_CRUSH, 0,
6100 P_ArgToChange(args[4]), false);
6101 break;
6102 case zl_ceiling_move_to_value:
6103 buttonSuccess = EV_DoZDoomCeiling(ceilMoveToValue, line, args[0],
6104 P_ArgToSpeed(args[1]), 0,
6105 args[2] * (args[3] ? -1 : 1), NO_CRUSH, 0,
6106 P_ArgToChange(args[4]), false);
6107 break;
6108 case zl_ceiling_move_to_value_and_crush:
6109 buttonSuccess = EV_DoZDoomCeiling(ceilMoveToValue, line, args[0],
6110 P_ArgToSpeed(args[1]), 0,
6111 args[2], P_ArgToCrush(args[3]), 0,
6112 0, P_ArgToCrushMode(args[4], args[1] == 8));
6113 break;
6114 case zl_ceiling_lower_to_highest_floor:
6115 buttonSuccess = EV_DoZDoomCeiling(ceilLowerToHighestFloor, line, args[0],
6116 P_ArgToSpeed(args[1]), 0,
6117 args[4], P_ArgToCrush(args[3]), 0,
6118 P_ArgToChange(args[2]), false);
6119 break;
6120 case zl_ceiling_lower_instant:
6121 buttonSuccess = EV_DoZDoomCeiling(ceilLowerInstant, line, args[0],
6122 0, 0,
6123 args[2] * 8, P_ArgToCrush(args[4]), 0,
6124 P_ArgToChange(args[3]), false);
6125 break;
6126 case zl_ceiling_raise_instant:
6127 buttonSuccess = EV_DoZDoomCeiling(ceilRaiseInstant, line, args[0],
6128 0, 0,
6129 args[2] * 8, NO_CRUSH, 0,
6130 P_ArgToChange(args[3]), false);
6131 break;
6132 case zl_ceiling_crush_raise_and_stay_a:
6133 buttonSuccess = EV_DoZDoomCeiling(ceilCrushRaiseAndStay, line, args[0],
6134 P_ArgToSpeed(args[1]), P_ArgToSpeed(args[2]),
6135 0, args[3], 0,
6136 0, P_ArgToCrushMode(args[4], false));
6137 break;
6138 case zl_ceiling_crush_raise_and_stay_sil_a:
6139 buttonSuccess = EV_DoZDoomCeiling(ceilCrushRaiseAndStay, line, args[0],
6140 P_ArgToSpeed(args[1]), P_ArgToSpeed(args[2]),
6141 0, args[3], 1,
6142 0, P_ArgToCrushMode(args[4], false));
6143 break;
6144 case zl_ceiling_crush_and_raise_a:
6145 buttonSuccess = EV_DoZDoomCeiling(ceilCrushAndRaise, line, args[0],
6146 P_ArgToSpeed(args[1]), P_ArgToSpeed(args[2]),
6147 0, args[3], 0,
6148 0, P_ArgToCrushMode(args[4], args[1] == 8 && args[2] == 8));
6149 break;
6150 case zl_ceiling_crush_and_raise_dist:
6151 buttonSuccess = EV_DoZDoomCeiling(ceilCrushAndRaise, line, args[0],
6152 P_ArgToSpeed(args[2]), P_ArgToSpeed(args[2]),
6153 args[1], args[3], 0,
6154 0, P_ArgToCrushMode(args[4], args[2] == 8));
6155 break;
6156 case zl_ceiling_crush_and_raise_silent_a:
6157 buttonSuccess = EV_DoZDoomCeiling(ceilCrushAndRaise, line, args[0],
6158 P_ArgToSpeed(args[1]), P_ArgToSpeed(args[2]),
6159 0, args[3], 1,
6160 0, P_ArgToCrushMode(args[4], args[1] == 8 && args[2] == 8));
6161 break;
6162 case zl_ceiling_crush_and_raise_silent_dist:
6163 buttonSuccess = EV_DoZDoomCeiling(ceilCrushAndRaise, line, args[0],
6164 P_ArgToSpeed(args[2]), P_ArgToSpeed(args[2]),
6165 args[1], args[3], 1,
6166 0, P_ArgToCrushMode(args[4], args[2] == 8));
6167 break;
6168 case zl_ceiling_raise_to_nearest:
6169 buttonSuccess = EV_DoZDoomCeiling(ceilRaiseToNearest, line, args[0],
6170 P_ArgToSpeed(args[1]), 0,
6171 0, NO_CRUSH, P_ArgToChange(args[2]),
6172 0, false);
6173 break;
6174 case zl_ceiling_raise_to_highest:
6175 buttonSuccess = EV_DoZDoomCeiling(ceilRaiseToHighest, line, args[0],
6176 P_ArgToSpeed(args[1]), 0,
6177 0, NO_CRUSH, P_ArgToChange(args[2]),
6178 0, false);
6179 break;
6180 case zl_ceiling_raise_to_lowest:
6181 buttonSuccess = EV_DoZDoomCeiling(ceilRaiseToLowest, line, args[0],
6182 P_ArgToSpeed(args[1]), 0,
6183 0, NO_CRUSH, P_ArgToChange(args[2]),
6184 0, false);
6185 break;
6186 case zl_ceiling_raise_to_highest_floor:
6187 buttonSuccess = EV_DoZDoomCeiling(ceilRaiseToHighestFloor, line, args[0],
6188 P_ArgToSpeed(args[1]), 0,
6189 0, NO_CRUSH, P_ArgToChange(args[2]),
6190 0, false);
6191 break;
6192 case zl_ceiling_raise_by_texture:
6193 buttonSuccess = EV_DoZDoomCeiling(ceilRaiseByTexture, line, args[0],
6194 P_ArgToSpeed(args[1]), 0,
6195 0, NO_CRUSH, P_ArgToChange(args[2]),
6196 0, false);
6197 break;
6198 case zl_ceiling_lower_to_lowest:
6199 buttonSuccess = EV_DoZDoomCeiling(ceilLowerToLowest, line, args[0],
6200 P_ArgToSpeed(args[1]), 0,
6201 0, P_ArgToCrush(args[3]), 0,
6202 P_ArgToChange(args[2]), false);
6203 break;
6204 case zl_ceiling_lower_to_nearest:
6205 buttonSuccess = EV_DoZDoomCeiling(ceilLowerToNearest, line, args[0],
6206 P_ArgToSpeed(args[1]), 0,
6207 0, P_ArgToCrush(args[3]), 0,
6208 P_ArgToChange(args[2]), false);
6209 break;
6210 case zl_ceiling_to_highest_instant:
6211 buttonSuccess = EV_DoZDoomCeiling(ceilLowerToHighest, line, args[0],
6212 2 * FRACUNIT, 0,
6213 0, P_ArgToCrush(args[2]), 0,
6214 P_ArgToChange(args[1]), false);
6215 break;
6216 case zl_ceiling_to_floor_instant:
6217 buttonSuccess = EV_DoZDoomCeiling(ceilRaiseToFloor, line, args[0],
6218 2 * FRACUNIT, 0,
6219 args[3], P_ArgToCrush(args[2]), 0,
6220 P_ArgToChange(args[1]), false);
6221 break;
6222 case zl_ceiling_lower_to_floor:
6223 buttonSuccess = EV_DoZDoomCeiling(ceilLowerToFloor, line, args[0],
6224 P_ArgToSpeed(args[1]), 0,
6225 args[4], P_ArgToCrush(args[3]), 0,
6226 P_ArgToChange(args[4]), false);
6227 break;
6228 case zl_ceiling_lower_by_texture:
6229 buttonSuccess = EV_DoZDoomCeiling(ceilLowerByTexture, line, args[0],
6230 P_ArgToSpeed(args[1]), 0,
6231 0, P_ArgToCrush(args[3]), 0,
6232 P_ArgToChange(args[4]), false);
6233 break;
6234 case zl_generic_ceiling:
6235 {
6236 ceiling_e type;
6237 dboolean raise_or_lower;
6238 byte index;
6239
6240 static ceiling_e ceiling_type[2][7] = {
6241 {
6242 ceilLowerByValue,
6243 ceilLowerToHighest,
6244 ceilLowerToLowest,
6245 ceilLowerToNearest,
6246 ceilLowerToHighestFloor,
6247 ceilLowerToFloor,
6248 ceilLowerByTexture,
6249 },
6250 {
6251 ceilRaiseByValue,
6252 ceilRaiseToHighest,
6253 ceilRaiseToLowest,
6254 ceilRaiseToNearest,
6255 ceilRaiseToHighestFloor,
6256 ceilRaiseToFloor,
6257 ceilRaiseByTexture,
6258 }
6259 };
6260
6261 raise_or_lower = (args[4] & 8) >> 3;
6262 index = (args[3] < 7) ? args[3] : 0;
6263 type = ceiling_type[raise_or_lower][index];
6264
6265 buttonSuccess = EV_DoZDoomCeiling(type, line, args[0],
6266 P_ArgToSpeed(args[1]), P_ArgToSpeed(args[1]),
6267 args[2], (args[4] & 16) ? 20 : NO_CRUSH, 0,
6268 args[4] & 7, false);
6269 }
6270 break;
6271 case zl_ceiling_crush_stop:
6272 {
6273 dboolean remove;
6274
6275 switch (args[3])
6276 {
6277 case 1:
6278 remove = false;
6279 break;
6280 case 2:
6281 remove = true;
6282 break;
6283 default:
6284 remove = hexen;
6285 break;
6286 }
6287
6288 buttonSuccess = EV_ZDoomCeilingCrushStop(args[0], remove);
6289 }
6290 break;
6291 case zl_ceiling_stop:
6292 buttonSuccess = EV_ZDoomCeilingStop(args[0], line);
6293 break;
6294 case zl_generic_crusher:
6295 buttonSuccess = EV_DoZDoomCeiling(ceilCrushAndRaise, line, args[0],
6296 P_ArgToSpeed(args[1]), P_ArgToSpeed(args[2]),
6297 0, args[4], args[3] ? 2 : 0,
6298 0, (args[1] <= 24 && args[2] <= 24) ? crushSlowdown : crushDoom);
6299 break;
6300 case zl_generic_crusher2:
6301 buttonSuccess = EV_DoZDoomCeiling(ceilCrushAndRaise, line, args[0],
6302 P_ArgToSpeed(args[1]), P_ArgToSpeed(args[2]),
6303 0, args[4], args[3] ? 2 : 0,
6304 0, crushHexen);
6305 break;
6306 case zl_floor_waggle:
6307 buttonSuccess = EV_StartPlaneWaggle(args[0], line, args[1], args[2], args[3], args[4], false);
6308 break;
6309 case zl_ceiling_waggle:
6310 buttonSuccess = EV_StartPlaneWaggle(args[0], line, args[1], args[2], args[3], args[4], true);
6311 break;
6312 case zl_floor_and_ceiling_lower_raise:
6313 buttonSuccess = EV_DoZDoomCeiling(ceilRaiseToHighest, line, args[0],
6314 P_ArgToSpeed(args[2]), 0, 0, 0, 0, 0, false);
6315 buttonSuccess |= EV_DoZDoomFloor(floorLowerToLowest, line, args[0],
6316 args[1], 0, NO_CRUSH, 0, false, false);
6317 break;
6318 case zl_stairs_build_down:
6319 buttonSuccess = EV_BuildZDoomStairs(args[0], stairBuildDown, line,
6320 args[2], P_ArgToSpeed(args[1]), args[3],
6321 args[4], 0, STAIR_USE_SPECIALS);
6322 break;
6323 case zl_stairs_build_up:
6324 buttonSuccess = EV_BuildZDoomStairs(args[0], stairBuildUp, line,
6325 args[2], P_ArgToSpeed(args[1]), args[3],
6326 args[4], 0, STAIR_USE_SPECIALS);
6327 break;
6328 case zl_stairs_build_down_sync:
6329 buttonSuccess = EV_BuildZDoomStairs(args[0], stairBuildDown, line,
6330 args[2], P_ArgToSpeed(args[1]), 0,
6331 args[3], 0, STAIR_USE_SPECIALS | STAIR_SYNC);
6332 break;
6333 case zl_stairs_build_up_sync:
6334 buttonSuccess = EV_BuildZDoomStairs(args[0], stairBuildUp, line,
6335 args[2], P_ArgToSpeed(args[1]), 0,
6336 args[3], 0, STAIR_USE_SPECIALS | STAIR_SYNC);
6337 break;
6338 case zl_stairs_build_down_doom:
6339 buttonSuccess = EV_BuildZDoomStairs(args[0], stairBuildDown, line,
6340 args[2], P_ArgToSpeed(args[1]), args[3],
6341 args[4], 0, 0);
6342 break;
6343 case zl_stairs_build_up_doom:
6344 buttonSuccess = EV_BuildZDoomStairs(args[0], stairBuildUp, line,
6345 args[2], P_ArgToSpeed(args[1]), args[3],
6346 args[4], 0, 0);
6347 break;
6348 case zl_stairs_build_down_doom_sync:
6349 buttonSuccess = EV_BuildZDoomStairs(args[0], stairBuildDown, line,
6350 args[2], P_ArgToSpeed(args[1]), 0,
6351 args[3], 0, STAIR_SYNC);
6352 break;
6353 case zl_stairs_build_up_doom_sync:
6354 buttonSuccess = EV_BuildZDoomStairs(args[0], stairBuildUp, line,
6355 args[2], P_ArgToSpeed(args[1]), 0,
6356 args[3], 0, STAIR_SYNC);
6357 break;
6358 case zl_stairs_build_up_doom_crush:
6359 buttonSuccess = EV_BuildZDoomStairs(args[0], stairBuildUp, line,
6360 args[2], P_ArgToSpeed(args[1]), args[3],
6361 args[4], 0, STAIR_CRUSH);
6362 break;
6363 case zl_generic_stairs:
6364 {
6365 stair_e type;
6366
6367 type = (args[3] & 1) ? stairBuildUp : stairBuildDown;
6368 buttonSuccess = EV_BuildZDoomStairs(args[0], type, line,
6369 args[2], P_ArgToSpeed(args[1]), 0,
6370 args[4], args[3] & 2, 0);
6371
6372 // Toggle direction of next activation of repeatable stairs
6373 if (buttonSuccess && line &&
6374 line->flags & ML_REPEATSPECIAL &&
6375 line->special == zl_generic_stairs)
6376 {
6377 line->special_args[3] ^= 1;
6378 }
6379 }
6380 break;
6381 case zl_plat_stop:
6382 {
6383 dboolean remove;
6384
6385 switch (args[3])
6386 {
6387 case 1:
6388 remove = false;
6389 break;
6390 case 2:
6391 remove = true;
6392 break;
6393 default:
6394 remove = hexen;
6395 break;
6396 }
6397
6398 EV_StopZDoomPlat(args[0], remove);
6399 buttonSuccess = 1;
6400 }
6401 break;
6402 case zl_plat_perpetual_raise:
6403 buttonSuccess = EV_DoZDoomPlat(args[0], line, platPerpetualRaise, 0,
6404 P_ArgToSpeed(args[1]), args[2], 8, 0);
6405 break;
6406 case zl_plat_perpetual_raise_lip:
6407 buttonSuccess = EV_DoZDoomPlat(args[0], line, platPerpetualRaise, 0,
6408 P_ArgToSpeed(args[1]), args[2], args[3], 0);
6409 break;
6410 case zl_plat_down_wait_up_stay:
6411 buttonSuccess = EV_DoZDoomPlat(args[0], line, platDownWaitUpStay, 0,
6412 P_ArgToSpeed(args[1]), args[2], 8, 0);
6413 break;
6414 case zl_plat_down_wait_up_stay_lip:
6415 buttonSuccess = EV_DoZDoomPlat(args[0], line,
6416 args[4] ? platDownWaitUpStayStone : platDownWaitUpStay, 0,
6417 P_ArgToSpeed(args[1]), args[2], args[3], 0);
6418 break;
6419 case zl_plat_down_by_value:
6420 buttonSuccess = EV_DoZDoomPlat(args[0], line, platDownByValue, args[3] * 8,
6421 P_ArgToSpeed(args[1]), args[2], 0, 0);
6422 break;
6423 case zl_plat_up_by_value:
6424 buttonSuccess = EV_DoZDoomPlat(args[0], line, platUpByValue, args[3] * 8,
6425 P_ArgToSpeed(args[1]), args[2], 0, 0);
6426 break;
6427 case zl_plat_up_wait_down_stay:
6428 buttonSuccess = EV_DoZDoomPlat(args[0], line, platUpWaitDownStay, 0,
6429 P_ArgToSpeed(args[1]), args[2], 0, 0);
6430 break;
6431 case zl_plat_up_nearest_wait_down_stay:
6432 buttonSuccess = EV_DoZDoomPlat(args[0], line, platUpNearestWaitDownStay, 0,
6433 P_ArgToSpeed(args[1]), args[2], 0, 0);
6434 break;
6435 case zl_plat_raise_and_stay_tx0:
6436 {
6437 plattype_e type;
6438
6439 switch (args[3])
6440 {
6441 case 1:
6442 type = platRaiseAndStay;
6443 break;
6444 case 2:
6445 type = platRaiseAndStayLockout;
6446 break;
6447 default:
6448 type = (heretic ? platRaiseAndStayLockout : platRaiseAndStay);
6449 break;
6450 }
6451
6452 buttonSuccess = EV_DoZDoomPlat(args[0], line, type, 0, P_ArgToSpeed(args[1]), 0, 0, 1);
6453 }
6454 break;
6455 case zl_plat_up_by_value_stay_tx:
6456 buttonSuccess = EV_DoZDoomPlat(args[0], line, platUpByValueStay, args[2] * 8,
6457 P_ArgToSpeed(args[1]), 0, 0, 2);
6458 break;
6459 case zl_plat_toggle_ceiling:
6460 buttonSuccess = EV_DoZDoomPlat(args[0], line, platToggle, 0, 0, 0, 0, 0);
6461 break;
6462 case zl_generic_lift:
6463 {
6464 plattype_e type;
6465
6466 switch (args[3])
6467 {
6468 case 1:
6469 type = platDownWaitUpStay;
6470 break;
6471 case 2:
6472 type = platDownToNearestFloor;
6473 break;
6474 case 3:
6475 type = platDownToLowestCeiling;
6476 break;
6477 case 4:
6478 type = platPerpetualRaise;
6479 break;
6480 default:
6481 type = platUpByValue;
6482 break;
6483 }
6484
6485 buttonSuccess = EV_DoZDoomPlat(args[0], line, type, args[4] * 8,
6486 P_ArgToSpeed(args[1]), args[2] * 35 / 8, 0, 0);
6487 }
6488 break;
6489 case zl_line_set_blocking:
6490 if (args[0])
6491 {
6492 int i;
6493 const int *id_p;
6494 static const int flags[] =
6495 {
6496 ML_BLOCKING,
6497 ML_BLOCKMONSTERS,
6498 ML_BLOCKPLAYERS,
6499 ML_BLOCKFLOATERS,
6500 ML_BLOCKPROJECTILES,
6501 ML_BLOCKEVERYTHING,
6502 ML_JUMPOVER,
6503 ML_BLOCKUSE,
6504 ML_BLOCKSIGHT,
6505 ML_BLOCKHITSCAN,
6506 ML_SOUNDBLOCK,
6507 ML_BLOCKLANDMONSTERS,
6508 -1
6509 };
6510
6511 int setflags = 0;
6512 int clearflags = 0;
6513
6514 for (i = 0; flags[i] != -1; i++, args[1] >>= 1, args[2] >>= 1)
6515 {
6516 if (args[1] & 1) setflags |= flags[i];
6517 if (args[2] & 1) clearflags |= flags[i];
6518 }
6519
6520 FIND_LINES(id_p, args[0])
6521 {
6522 lines[*id_p].flags = (lines[*id_p].flags & ~clearflags) | setflags;
6523 }
6524
6525 buttonSuccess = 1;
6526 }
6527 break;
6528 case zl_sector_change_flags:
6529 if (args[0])
6530 {
6531 int i;
6532 const int *id_p;
6533 static const int flags[] =
6534 {
6535 SECF_SILENT,
6536 0,
6537 0,
6538 0,
6539 SECF_FRICTION,
6540 SECF_PUSH,
6541 0,
6542 0,
6543 SECF_ENDGODMODE,
6544 SECF_ENDLEVEL,
6545 SECF_HAZARD,
6546 SECF_NOATTACK,
6547 -1
6548 };
6549
6550 int setflags = 0;
6551 int clearflags = 0;
6552
6553 for (i = 0; flags[i] != -1; i++, args[1] >>= 1, args[2] >>= 1)
6554 {
6555 if (args[1] & 1) setflags |= flags[i];
6556 if (args[2] & 1) clearflags |= flags[i];
6557 }
6558
6559 FIND_SECTORS(id_p, args[0])
6560 sectors[*id_p].flags = (sectors[*id_p].flags & ~clearflags) | setflags;
6561
6562 buttonSuccess = 1;
6563 }
6564 break;
6565 case zl_line_set_automap_flags:
6566 if (args[0])
6567 {
6568 int i;
6569 const int *id_p;
6570 static const int flags[] =
6571 {
6572 ML_SECRET,
6573 ML_DONTDRAW,
6574 ML_MAPPED,
6575 ML_REVEALED,
6576 -1
6577 };
6578
6579 int setflags = 0;
6580 int clearflags = 0;
6581
6582 for (i = 0; flags[i] != -1; i++, args[1] >>= 1, args[2] >>= 1)
6583 {
6584 if (args[1] & 1) setflags |= flags[i];
6585 if (args[2] & 1) clearflags |= flags[i];
6586 }
6587
6588 FIND_LINES(id_p, args[0])
6589 {
6590 lines[*id_p].flags = (lines[*id_p].flags & ~clearflags) | setflags;
6591 }
6592
6593 buttonSuccess = 1;
6594 }
6595 break;
6596 case zl_line_set_automap_style:
6597 if (args[1] >= 0 && args[1] <= ams_portal)
6598 {
6599 const int *id_p;
6600
6601 FIND_LINES(id_p, args[0])
6602 {
6603 lines[*id_p].automap_style = args[1];
6604 }
6605
6606 buttonSuccess = 1;
6607 }
6608 break;
6609 case zl_scroll_wall:
6610 if (args[0])
6611 {
6612 const int *id_p;
6613 int side = !!args[3];
6614
6615 FIND_LINES(id_p, args[0])
6616 {
6617 dsda_AddSideScroller(args[1], args[2], lines[*id_p].sidenum[side], args[4]);
6618 }
6619
6620 buttonSuccess = 1;
6621 }
6622 break;
6623 case zl_line_set_texture_offset:
6624 if (args[0])
6625 {
6626 const int *id_p;
6627 const int NO_CHANGE = 32767 << FRACBITS;
6628 int sidenum = !!args[3];
6629
6630 FIND_LINES(id_p, args[0])
6631 {
6632 side_t *side = &sides[lines[*id_p].sidenum[sidenum]];
6633
6634 if (args[4] & 8)
6635 {
6636 if (args[1] != NO_CHANGE)
6637 {
6638 if (args[4] & 1)
6639 side->textureoffset_top += args[1];
6640
6641 if (args[4] & 2)
6642 side->textureoffset_mid += args[1];
6643
6644 if (args[4] & 4)
6645 side->textureoffset_bottom += args[1];
6646 }
6647
6648 if (args[2] != NO_CHANGE)
6649 {
6650 if (args[4] & 1)
6651 side->rowoffset_top += args[2];
6652
6653 if (args[4] & 2)
6654 side->rowoffset_mid += args[2];
6655
6656 if (args[4] & 4)
6657 side->rowoffset_bottom += args[2];
6658 }
6659 }
6660 else
6661 {
6662 if (args[1] != NO_CHANGE)
6663 {
6664 if (args[4] & 1)
6665 side->textureoffset_top = args[1];
6666
6667 if (args[4] & 2)
6668 side->textureoffset_mid = args[1];
6669
6670 if (args[4] & 4)
6671 side->textureoffset_bottom = args[1];
6672 }
6673
6674 if (args[2] != NO_CHANGE)
6675 {
6676 if (args[4] & 1)
6677 side->rowoffset_top = args[2];
6678
6679 if (args[4] & 2)
6680 side->rowoffset_mid = args[2];
6681
6682 if (args[4] & 4)
6683 side->rowoffset_bottom = args[2];
6684 }
6685 }
6686 }
6687
6688 buttonSuccess = 1;
6689 }
6690 break;
6691 case zl_line_set_texturescale:
6692 if (args[0])
6693 {
6694 const int *id_p;
6695 const int NO_CHANGE = 32767 << FRACBITS;
6696 int sidenum = !!args[3];
6697
6698 if (!args[1])
6699 args[1] = FRACUNIT;
6700
6701 if (!args[2])
6702 args[2] = FRACUNIT;
6703
6704 FIND_LINES(id_p, args[0])
6705 {
6706 side_t *side = &sides[lines[*id_p].sidenum[sidenum]];
6707
6708 if (args[4] & 8)
6709 {
6710 if (args[1] != NO_CHANGE)
6711 {
6712 if (args[4] & 1)
6713 side->scalex_top = FixedMul(side->scalex_top, args[1]);
6714
6715 if (args[4] & 2)
6716 side->scalex_mid = FixedMul(side->scalex_mid, args[1]);
6717
6718 if (args[4] & 4)
6719 side->scalex_bottom = FixedMul(side->scalex_bottom, args[1]);
6720 }
6721
6722 if (args[2] != NO_CHANGE)
6723 {
6724 if (args[4] & 1)
6725 side->scaley_top = FixedMul(side->scaley_top, args[2]);
6726
6727 if (args[4] & 2)
6728 side->scaley_mid = FixedMul(side->scaley_mid, args[2]);
6729
6730 if (args[4] & 4)
6731 side->scaley_bottom = FixedMul(side->scaley_bottom, args[2]);
6732 }
6733 }
6734 else
6735 {
6736 if (args[1] != NO_CHANGE)
6737 {
6738 if (args[4] & 1)
6739 side->scalex_top = args[1];
6740
6741 if (args[4] & 2)
6742 side->scalex_mid = args[1];
6743
6744 if (args[4] & 4)
6745 side->scalex_bottom = args[1];
6746 }
6747
6748 if (args[2] != NO_CHANGE)
6749 {
6750 if (args[4] & 1)
6751 side->scaley_top = args[2];
6752
6753 if (args[4] & 2)
6754 side->scaley_mid = args[2];
6755
6756 if (args[4] & 4)
6757 side->scaley_bottom = args[2];
6758 }
6759 }
6760 }
6761
6762 buttonSuccess = 1;
6763 }
6764 break;
6765 case zl_noise_alert:
6766 {
6767 extern void P_NoiseAlert(mobj_t *target, mobj_t *emitter);
6768
6769 mobj_t *target, *emitter;
6770
6771 if (!args[0])
6772 {
6773 target = mo;
6774 }
6775 else
6776 {
6777 // not supported yet
6778 target = NULL;
6779 }
6780
6781 if (!args[1])
6782 {
6783 emitter = mo;
6784 }
6785 else
6786 {
6787 // not supported yet
6788 emitter = NULL;
6789 }
6790
6791 if (emitter)
6792 {
6793 P_NoiseAlert(target, emitter);
6794 }
6795
6796 buttonSuccess = 1;
6797 }
6798 break;
6799 case zl_sector_set_gravity:
6800 {
6801 fixed_t gravity;
6802 const int *id_p;
6803
6804 if (args[2] > 99)
6805 args[2] = 99;
6806
6807 gravity = P_ArgsToFixed(args[1], args[2]);
6808
6809 FIND_SECTORS(id_p, args[0])
6810 sectors[*id_p].gravity = gravity;
6811 }
6812 buttonSuccess = 1;
6813 break;
6814 case zl_sector_set_damage:
6815 {
6816 const int *id_p;
6817 dboolean unblockable = false;
6818
6819 if (args[3] == 0)
6820 {
6821 if (args[1] < 20)
6822 {
6823 args[4] = 0;
6824 args[3] = 32;
6825 }
6826 else if (args[1] < 50)
6827 {
6828 args[4] = 5;
6829 args[3] = 32;
6830 }
6831 else
6832 {
6833 unblockable = true;
6834 args[4] = 0;
6835 args[3] = 1;
6836 }
6837 }
6838
6839 FIND_SECTORS(id_p, args[0])
6840 {
6841 sectors[*id_p].damage.amount = args[1];
6842 sectors[*id_p].damage.interval = args[3];
6843 sectors[*id_p].damage.leakrate = args[4];
6844 if (unblockable)
6845 sectors[*id_p].flags |= SECF_DMGUNBLOCKABLE;
6846 else
6847 sectors[*id_p].flags &= ~SECF_DMGUNBLOCKABLE;
6848 }
6849 }
6850 buttonSuccess = 1;
6851 break;
6852 case zl_floor_transfer_numeric:
6853 buttonSuccess = EV_DoChange(line, numChangeOnly, args[0]);
6854 break;
6855 case zl_floor_transfer_trigger:
6856 buttonSuccess = EV_DoChange(line, trigChangeOnly, args[0]);
6857 break;
6858 case zl_sector_set_floor_panning:
6859 {
6860 const int *id_p;
6861 fixed_t xoffs, yoffs;
6862
6863 xoffs = P_ArgsToFixed(args[1], args[2]);
6864 yoffs = P_ArgsToFixed(args[3], args[4]);
6865
6866 FIND_SECTORS(id_p, args[0])
6867 {
6868 sectors[*id_p].floor_xoffs = xoffs;
6869 sectors[*id_p].floor_yoffs = yoffs;
6870 }
6871 }
6872 buttonSuccess = 1;
6873 break;
6874 case zl_sector_set_ceiling_panning:
6875 {
6876 const int *id_p;
6877 fixed_t xoffs, yoffs;
6878
6879 xoffs = P_ArgsToFixed(args[1], args[2]);
6880 yoffs = P_ArgsToFixed(args[3], args[4]);
6881
6882 FIND_SECTORS(id_p, args[0])
6883 {
6884 sectors[*id_p].ceiling_xoffs = xoffs;
6885 sectors[*id_p].ceiling_yoffs = yoffs;
6886 }
6887 }
6888 buttonSuccess = 1;
6889 break;
6890 case zl_sector_set_rotation:
6891 {
6892 const int *id_p;
6893 angle_t floor, ceiling;
6894
6895 floor = dsda_DegreesToAngle(args[1]);
6896 ceiling = dsda_DegreesToAngle(args[2]);
6897
6898 FIND_SECTORS(id_p, args[0])
6899 {
6900 sectors[*id_p].floor_rotation = floor;
6901 sectors[*id_p].ceiling_rotation = ceiling;
6902 }
6903 }
6904 buttonSuccess = 1;
6905 break;
6906 case zl_sector_set_floor_scale:
6907 {
6908 const int *id_p;
6909 fixed_t xscale, yscale;
6910
6911 xscale = (args[1] << FRACBITS) + (args[2] << FRACBITS) / 100;
6912 yscale = (args[3] << FRACBITS) + (args[4] << FRACBITS) / 100;
6913
6914 if (xscale)
6915 xscale = FixedDiv(FRACUNIT, xscale);
6916
6917 if (yscale)
6918 yscale = FixedDiv(FRACUNIT, yscale);
6919
6920 FIND_SECTORS(id_p, args[0])
6921 {
6922 sectors[*id_p].floor_xscale = xscale;
6923 sectors[*id_p].floor_yscale = yscale;
6924 }
6925 }
6926 buttonSuccess = 1;
6927 break;
6928 case zl_sector_set_floor_scale2:
6929 {
6930 const int *id_p;
6931 fixed_t xscale, yscale;
6932
6933 xscale = args[1];
6934 yscale = args[2];
6935
6936 if (xscale)
6937 xscale = FixedDiv(FRACUNIT, xscale);
6938
6939 if (yscale)
6940 yscale = FixedDiv(FRACUNIT, yscale);
6941
6942 FIND_SECTORS(id_p, args[0])
6943 {
6944 sectors[*id_p].floor_xscale = xscale;
6945 sectors[*id_p].floor_yscale = yscale;
6946 }
6947 }
6948 buttonSuccess = 1;
6949 break;
6950 case zl_sector_set_ceiling_scale:
6951 {
6952 const int *id_p;
6953 fixed_t xscale, yscale;
6954
6955 xscale = (args[1] << FRACBITS) + (args[2] << FRACBITS) / 100;
6956 yscale = (args[3] << FRACBITS) + (args[4] << FRACBITS) / 100;
6957
6958 if (xscale)
6959 xscale = FixedDiv(FRACUNIT, xscale);
6960
6961 if (yscale)
6962 yscale = FixedDiv(FRACUNIT, yscale);
6963
6964 FIND_SECTORS(id_p, args[0])
6965 {
6966 sectors[*id_p].ceiling_xscale = xscale;
6967 sectors[*id_p].ceiling_yscale = yscale;
6968 }
6969 }
6970 buttonSuccess = 1;
6971 break;
6972 case zl_sector_set_ceiling_scale2:
6973 {
6974 const int *id_p;
6975 fixed_t xscale, yscale;
6976
6977 xscale = args[1];
6978 yscale = args[2];
6979
6980 if (xscale)
6981 xscale = FixedDiv(FRACUNIT, xscale);
6982
6983 if (yscale)
6984 yscale = FixedDiv(FRACUNIT, yscale);
6985
6986 FIND_SECTORS(id_p, args[0])
6987 {
6988 sectors[*id_p].ceiling_xscale = xscale;
6989 sectors[*id_p].ceiling_yscale = yscale;
6990 }
6991 }
6992 buttonSuccess = 1;
6993 break;
6994 case zl_heal_thing:
6995 if (mo)
6996 {
6997 int max = args[1];
6998
6999 buttonSuccess = 1;
7000
7001 if (!max || !mo->player)
7002 {
7003 P_HealMobj(mo, args[0]);
7004 break;
7005 }
7006 else if (max == 1)
7007 {
7008 max = max_soul;
7009 }
7010
7011 if (mo->health < max)
7012 {
7013 mo->health += P_PlayerHealthIncrease(args[0]);
7014 if (mo->health > max && max > 0)
7015 {
7016 mo->health = max;
7017 }
7018 mo->player->health = mo->health;
7019 }
7020 }
7021 break;
7022 case zl_force_field:
7023 if (mo)
7024 {
7025 P_DamageMobj(mo, NULL, NULL, 16);
7026 P_ThrustMobj(mo, ANG180 + mo->angle, 2048 * 250);
7027 }
7028 buttonSuccess = 1;
7029 break;
7030 case zl_clear_force_field:
7031 {
7032 const int *id_p;
7033
7034 FIND_SECTORS(id_p, args[0])
7035 {
7036 int i;
7037
7038 buttonSuccess = 1;
7039
7040 for (i = 0; i < sectors[*id_p].linecount; i++)
7041 {
7042 line_t *line = sectors[*id_p].lines[i];
7043
7044 if (line->backsector && line->special == zl_force_field)
7045 {
7046 line->flags &= ~(ML_BLOCKING | ML_BLOCKEVERYTHING);
7047 line->special = 0;
7048 sides[line->sidenum[0]].midtexture = NO_TEXTURE;
7049 sides[line->sidenum[1]].midtexture = NO_TEXTURE;
7050 }
7051 }
7052 }
7053 }
7054 break;
7055 case zl_exit_normal:
7056 G_ExitLevel(args[0]);
7057 buttonSuccess = 1;
7058 break;
7059 case zl_exit_secret:
7060 G_SecretExitLevel(args[0]);
7061 buttonSuccess = 1;
7062 break;
7063 case zl_teleport_new_map:
7064 if (!side)
7065 {
7066 int flags;
7067
7068 flags = args[2] ? LF_SET_ANGLE : 0;
7069
7070 // TODO: this crashes if the map doesn't exist (gzdoom does a no-op)
7071 G_Completed(args[0], args[1], flags, mo->angle);
7072 buttonSuccess = 1;
7073 }
7074 break;
7075 case zl_teleport_end_game:
7076 if (!side)
7077 {
7078 G_Completed(LEAVE_VICTORY, LEAVE_VICTORY, 0, 0);
7079 buttonSuccess = 1;
7080 }
7081 break;
7082 case zl_polyobj_rotate_left:
7083 buttonSuccess = EV_RotateZDoomPoly(line, args[0], args[1], args[2], 1, false);
7084 break;
7085 case zl_polyobj_or_rotate_left:
7086 buttonSuccess = EV_RotateZDoomPoly(line, args[0], args[1], args[2], 1, true);
7087 break;
7088 case zl_polyobj_rotate_right:
7089 buttonSuccess = EV_RotateZDoomPoly(line, args[0], args[1], args[2], -1, false);
7090 break;
7091 case zl_polyobj_or_rotate_right:
7092 buttonSuccess = EV_RotateZDoomPoly(line, args[0], args[1], args[2], -1, true);
7093 break;
7094 case zl_polyobj_move:
7095 buttonSuccess = EV_MoveZDoomPoly(line, args[0], args[1],
7096 args[2], args[3], false, false);
7097 break;
7098 case zl_polyobj_or_move:
7099 buttonSuccess = EV_MoveZDoomPoly(line, args[0], args[1],
7100 args[2], args[3], false, true);
7101 break;
7102 case zl_polyobj_move_times_8:
7103 buttonSuccess = EV_MoveZDoomPoly(line, args[0], args[1],
7104 args[2], args[3], true, false);
7105 break;
7106 case zl_polyobj_or_move_times_8:
7107 buttonSuccess = EV_MoveZDoomPoly(line, args[0], args[1],
7108 args[2], args[3], true, true);
7109 break;
7110 case zl_polyobj_door_swing:
7111 buttonSuccess = EV_OpenZDoomPolyDoor(line, args[0], args[1],
7112 args[2], args[3], args[4], PODOOR_SWING);
7113 break;
7114 case zl_polyobj_door_slide:
7115 buttonSuccess = EV_OpenZDoomPolyDoor(line, args[0], args[1],
7116 args[2], args[3], args[4], PODOOR_SLIDE);
7117 break;
7118 case zl_polyobj_move_to:
7119 buttonSuccess = EV_MovePolyTo(line, args[0], P_ArgToSpeed(args[1]),
7120 args[2] << FRACBITS, args[3] << FRACBITS, false);
7121 break;
7122 case zl_polyobj_or_move_to:
7123 buttonSuccess = EV_MovePolyTo(line, args[0], P_ArgToSpeed(args[1]),
7124 args[2] << FRACBITS, args[3] << FRACBITS, true);
7125 break;
7126 case zl_polyobj_move_to_spot:
7127 {
7128 mobj_t *dest;
7129 thing_id_search_t search;
7130
7131 dsda_ResetThingIDSearch(&search);
7132 dest = dsda_FindMobjFromThingID(args[2], &search);
7133
7134 if (!dest)
7135 {
7136 break;
7137 }
7138
7139 buttonSuccess = EV_MovePolyTo(line, args[0], P_ArgToSpeed(args[1]),
7140 dest->x, dest->y, false);
7141 }
7142 break;
7143 case zl_polyobj_or_move_to_spot:
7144 {
7145 mobj_t *dest;
7146 thing_id_search_t search;
7147
7148 dsda_ResetThingIDSearch(&search);
7149 dest = dsda_FindMobjFromThingID(args[2], &search);
7150
7151 if (!dest)
7152 {
7153 break;
7154 }
7155
7156 buttonSuccess = EV_MovePolyTo(line, args[0], P_ArgToSpeed(args[1]),
7157 dest->x, dest->y, true);
7158 }
7159 break;
7160 case zl_polyobj_stop:
7161 buttonSuccess = EV_StopPoly(args[0]);
7162 break;
7163 case zl_radius_quake:
7164 {
7165 mobj_t *spawn_location;
7166 thing_id_search_t search;
7167
7168 args[0] = BETWEEN(1, 9, args[0]);
7169
7170 dsda_ResetThingIDSearch(&search);
7171 while ((spawn_location = dsda_FindMobjFromThingIDOrMobj(args[4], mo, &search)))
7172 {
7173 dsda_SpawnQuake(spawn_location, args[0], args[1], args[2], args[3]);
7174 buttonSuccess = 1;
7175 }
7176 }
7177 break;
7178 case zl_thing_move:
7179 {
7180 mobj_t *target;
7181 mobj_t *dest;
7182 thing_id_search_t search;
7183
7184 dsda_ResetThingIDSearch(&search);
7185 target = dsda_FindMobjFromThingIDOrMobj(args[0], mo, &search);
7186 dsda_ResetThingIDSearch(&search);
7187 dest = dsda_FindMobjFromThingID(args[1], &search);
7188
7189 if (target && dest)
7190 {
7191 buttonSuccess = P_MoveThing(target, dest->x, dest->y, dest->z, args[2] ? false : true);
7192 }
7193 }
7194 break;
7195 case zl_teleport_other:
7196 if (args[0] && args[1])
7197 {
7198 mobj_t *target;
7199 thing_id_search_t search;
7200
7201 dsda_ResetThingIDSearch(&search);
7202 while ((target = dsda_FindMobjFromThingID(args[0], &search)))
7203 {
7204 buttonSuccess |= map_format.ev_teleport(args[1], 0, NULL, 0, target,
7205 args[2] ? (TELF_DESTFOG | TELF_SOURCEFOG) :
7206 TELF_KEEPORIENTATION);
7207 }
7208 }
7209 break;
7210 case zl_teleport_group:
7211 buttonSuccess = EV_TeleportGroup(args[0], mo, args[1], args[2], args[3], args[4]);
7212 break;
7213 case zl_teleport_in_sector:
7214 buttonSuccess = EV_TeleportInSector(args[0], args[1], args[2], args[3], args[4]);
7215 break;
7216 case zl_teleport:
7217 {
7218 int flags = TELF_DESTFOG;
7219
7220 if (!args[2])
7221 flags |= TELF_SOURCEFOG;
7222
7223 buttonSuccess = map_format.ev_teleport(args[0], args[1], line, side, mo, flags);
7224 }
7225 break;
7226 case zl_teleport_no_fog:
7227 {
7228 int flags = 0;
7229
7230 switch (args[1])
7231 {
7232 case 0:
7233 flags |= TELF_KEEPORIENTATION;
7234 break;
7235
7236 case 2:
7237 if (line)
7238 flags |= TELF_KEEPORIENTATION | TELF_ROTATEBOOM;
7239 break;
7240
7241 case 3:
7242 if (line)
7243 flags |= TELF_KEEPORIENTATION | TELF_ROTATEBOOMINVERSE;
7244 break;
7245
7246 default:
7247 break;
7248 }
7249
7250 if (args[3])
7251 flags |= TELF_KEEPHEIGHT;
7252
7253 buttonSuccess = map_format.ev_teleport(args[0], args[2], line, side, mo, flags);
7254 }
7255 break;
7256 case zl_teleport_no_stop:
7257 {
7258 int flags = TELF_DESTFOG | TELF_KEEPVELOCITY;
7259
7260 if (!args[2])
7261 flags |= TELF_SOURCEFOG;
7262
7263 buttonSuccess = map_format.ev_teleport(args[0], args[1], line, side, mo, flags);
7264 }
7265 break;
7266 case zl_teleport_zombie_changer:
7267 if (mo)
7268 {
7269 map_format.ev_teleport(args[0], args[1], line, side, mo, 0);
7270 if (mo->health >= 0 && mo->info->painstate)
7271 {
7272 P_SetMobjState(mo, mo->info->painstate);
7273 }
7274 buttonSuccess = 1;
7275 }
7276 break;
7277 case zl_teleport_line:
7278 buttonSuccess = EV_SilentLineTeleport(line, side, mo, args[1], args[2]);
7279 break;
7280 case zl_light_raise_by_value:
7281 EV_LightChange(args[0], args[1]);
7282 buttonSuccess = 1;
7283 break;
7284 case zl_light_lower_by_value:
7285 EV_LightChange(args[0], - (short) args[1]);
7286 buttonSuccess = 1;
7287 break;
7288 case zl_light_change_to_value:
7289 EV_LightSet(args[0], args[1]);
7290 buttonSuccess = 1;
7291 break;
7292 case zl_light_min_neighbor:
7293 EV_LightSetMinNeighbor(args[0]);
7294 buttonSuccess = 1;
7295 break;
7296 case zl_light_max_neighbor:
7297 EV_LightSetMaxNeighbor(args[0]);
7298 buttonSuccess = 1;
7299 break;
7300 case zl_light_fade:
7301 EV_StartLightFading(args[0], args[1], args[2]);
7302 buttonSuccess = 1;
7303 break;
7304 case zl_light_glow:
7305 EV_StartLightGlowing(args[0], args[1], args[2], args[3]);
7306 buttonSuccess = 1;
7307 break;
7308 case zl_light_flicker:
7309 EV_StartLightFlickering(args[0], args[1], args[2]);
7310 buttonSuccess = 1;
7311 break;
7312 case zl_light_strobe:
7313 EV_StartZDoomLightStrobing(args[0], args[1], args[2], args[3], args[4]);
7314 buttonSuccess = 1;
7315 break;
7316 case zl_light_strobe_doom:
7317 EV_StartZDoomLightStrobingDoom(args[0], args[1], args[2]);
7318 buttonSuccess = 1;
7319 break;
7320 case zl_light_stop:
7321 EV_StopLightEffect(args[0]);
7322 buttonSuccess = 1;
7323 break;
7324 case zl_thing_set_special:
7325 {
7326 mobj_t *target;
7327 thing_id_search_t search;
7328
7329 dsda_ResetThingIDSearch(&search);
7330 while ((target = dsda_FindMobjFromThingIDOrMobj(args[0], mo, &search)))
7331 {
7332 target->special = args[1];
7333 target->special_args[0] = args[2];
7334 target->special_args[1] = args[3];
7335 target->special_args[2] = args[4];
7336 }
7337 }
7338 buttonSuccess = 1;
7339 break;
7340 case zl_thing_spawn:
7341 buttonSuccess =
7342 P_SpawnThing(args[0], mo, args[1], P_ArgToAngle(args[2]), true, args[3]);
7343 break;
7344 case zl_thing_spawn_no_fog:
7345 buttonSuccess =
7346 P_SpawnThing(args[0], mo, args[1], P_ArgToAngle(args[2]), false, args[3]);
7347 break;
7348 case zl_thing_spawn_facing:
7349 buttonSuccess =
7350 P_SpawnThing(args[0], mo, args[1], ANGLE_MAX, args[2] ? false : true, args[3]);
7351 break;
7352 case zl_thing_projectile:
7353 buttonSuccess = P_SpawnProjectile(args[0], mo, args[1], P_ArgToAngle(args[2]),
7354 P_ArgToSpeed(args[3]), P_ArgToSpeed(args[4]),
7355 0, NULL, 0, 0);
7356 break;
7357 case zl_thing_projectile_gravity:
7358 buttonSuccess = P_SpawnProjectile(args[0], mo, args[1], P_ArgToAngle(args[2]),
7359 P_ArgToSpeed(args[3]), P_ArgToSpeed(args[4]),
7360 0, NULL, 1, 0);
7361 break;
7362 case zl_thing_projectile_aimed:
7363 buttonSuccess = P_SpawnProjectile(args[0], mo, args[1], 0,
7364 P_ArgToSpeed(args[2]), 0,
7365 args[3], mo, 0, args[4]);
7366 break;
7367 case zl_thing_projectile_intercept:
7368 // ZDoom's implementation relies on a bunch of trigonometry
7369 // I tried converting this to fixed points,
7370 // but the calculations easily go out of bounds (dot products).
7371 // Needs a different implementation, or 64 bit fixed point conversions
7372 // Falling back on the default aimed behaviour for now
7373 buttonSuccess = P_SpawnProjectile(args[0], mo, args[1], 0,
7374 P_ArgToSpeed(args[2]), 0,
7375 args[3], mo, 0, args[4]);
7376 break;
7377 case zl_thing_stop:
7378 {
7379 mobj_t *target;
7380 thing_id_search_t search;
7381
7382 dsda_ResetThingIDSearch(&search);
7383 while ((target = dsda_FindMobjFromThingIDOrMobj(args[0], mo, &search)))
7384 {
7385 buttonSuccess = 1;
7386
7387 target->momx = 0;
7388 target->momy = 0;
7389 target->momz = 0;
7390
7391 if (target->player)
7392 {
7393 target->player->momx = 0;
7394 target->player->momy = 0;
7395 }
7396 }
7397 }
7398 break;
7399 case zl_thing_change_tid:
7400 {
7401 mobj_t *target;
7402 thing_id_search_t search;
7403
7404 dsda_ResetThingIDSearch(&search);
7405 while ((target = dsda_FindMobjFromThingIDOrMobj(args[0], mo, &search)))
7406 {
7407 dsda_RemoveMobjThingID(target);
7408 target->tid = args[1];
7409 if (target->tid)
7410 dsda_AddMobjThingID(target, args[1]);
7411 }
7412 }
7413 buttonSuccess = 1;
7414 break;
7415 case zl_thing_hate:
7416 {
7417 mobj_t *hater;
7418 mobj_t *target;
7419 thing_id_search_t search;
7420 thing_id_search_t target_search;
7421
7422 // Currently no support for this arg
7423 if (args[2])
7424 {
7425 break;
7426 }
7427
7428 if (!args[0] && mo && mo->player)
7429 {
7430 break;
7431 }
7432
7433 buttonSuccess = 1;
7434
7435 dsda_ResetThingIDSearch(&target_search);
7436 while ((target = dsda_FindMobjFromThingIDOrMobj(args[1], mo, &target_search)))
7437 {
7438 if (
7439 target->flags & MF_SHOOTABLE &&
7440 target->health > 0 &&
7441 !(target->flags2 & MF2_DORMANT)
7442 )
7443 {
7444 break;
7445 }
7446 }
7447
7448 if (!target)
7449 {
7450 break;
7451 }
7452
7453 dsda_ResetThingIDSearch(&search);
7454 while ((hater = dsda_FindMobjFromThingIDOrMobj(args[0], mo, &search)))
7455 {
7456 if (
7457 hater->health > 0 &&
7458 hater->flags & MF_SHOOTABLE &&
7459 hater->info->seestate
7460 )
7461 {
7462 while ((target = dsda_FindMobjFromThingIDOrMobj(args[1], mo, &target_search)))
7463 {
7464 if (
7465 target->flags & MF_SHOOTABLE &&
7466 target->health > 0 &&
7467 !(target->flags2 & MF2_DORMANT) &&
7468 target != hater
7469 )
7470 {
7471 break;
7472 }
7473 }
7474
7475 // Restart from beginning of list
7476 if (!target)
7477 {
7478 dsda_ResetThingIDSearch(&target_search);
7479 while ((target = dsda_FindMobjFromThingIDOrMobj(args[1], mo, &target_search)))
7480 {
7481 if (
7482 target->flags & MF_SHOOTABLE &&
7483 target->health > 0 &&
7484 !(target->flags2 & MF2_DORMANT) &&
7485 target != hater
7486 )
7487 {
7488 break;
7489 }
7490 }
7491 }
7492
7493 // We might have no target if the hater is the only possible target
7494 if (target)
7495 {
7496 P_SetTarget(&hater->lastenemy, hater->target);
7497 P_SetTarget(&hater->target, target);
7498
7499 if (!(hater->flags2 & MF2_DORMANT))
7500 {
7501 P_SetMobjState(hater, hater->info->seestate);
7502 }
7503 }
7504 }
7505 }
7506 }
7507 break;
7508 case zl_thing_remove:
7509 {
7510 mobj_t *target;
7511 thing_id_search_t search;
7512
7513 dsda_ResetThingIDSearch(&search);
7514 while ((target = dsda_FindMobjFromThingIDOrMobj(args[0], mo, &search)))
7515 {
7516 if (!target->player)
7517 {
7518 if (target->flags & MF_COUNTKILL)
7519 dsda_WatchKill(&players[consoleplayer], target);
7520
7521 P_RemoveMobj(target);
7522 }
7523 }
7524 }
7525 buttonSuccess = 1;
7526 break;
7527 case zl_thing_activate:
7528 {
7529 mobj_t *target;
7530 thing_id_search_t search;
7531
7532 dsda_ResetThingIDSearch(&search);
7533 while ((target = dsda_FindMobjFromThingIDOrMobj(args[0], mo, &search)))
7534 {
7535 if (target->flags2 & MF2_DORMANT)
7536 {
7537 target->flags2 &= ~MF2_DORMANT;
7538 target->tics = 1;
7539 }
7540
7541 buttonSuccess = 1;
7542 }
7543 }
7544 break;
7545 case zl_thing_deactivate:
7546 {
7547 mobj_t *target;
7548 thing_id_search_t search;
7549
7550 dsda_ResetThingIDSearch(&search);
7551 while ((target = dsda_FindMobjFromThingIDOrMobj(args[0], mo, &search)))
7552 {
7553 if (!(target->flags2 & MF2_DORMANT))
7554 {
7555 target->flags2 |= MF2_DORMANT;
7556 target->tics = -1;
7557 }
7558
7559 buttonSuccess = 1;
7560 }
7561 }
7562 break;
7563 case zl_thrust_thing:
7564 {
7565 fixed_t thrust;
7566 mobj_t *target;
7567 thing_id_search_t search;
7568
7569 thrust = args[1] * FRACUNIT;
7570
7571 dsda_ResetThingIDSearch(&search);
7572 while ((target = dsda_FindMobjFromThingIDOrMobj(args[3], mo, &search)))
7573 {
7574 P_ThrustMobj(target, P_ArgToAngle(args[0]), thrust);
7575 }
7576
7577 buttonSuccess = (args[3] != 0 || mo);
7578 }
7579 break;
7580 case zl_thrust_thing_z:
7581 {
7582 fixed_t thrust;
7583 mobj_t *target;
7584 thing_id_search_t search;
7585
7586 thrust = args[1] * FRACUNIT / 4;
7587
7588 if (args[2])
7589 thrust = -thrust;
7590
7591 dsda_ResetThingIDSearch(&search);
7592 while ((target = dsda_FindMobjFromThingIDOrMobj(args[0], mo, &search)))
7593 {
7594 if (!args[3])
7595 target->momz = thrust;
7596 else
7597 target->momz += thrust;
7598
7599 buttonSuccess = 1;
7600 }
7601 }
7602 break;
7603 case zl_thing_raise:
7604 {
7605 mobj_t *target;
7606 thing_id_search_t search;
7607
7608 dsda_ResetThingIDSearch(&search);
7609 while ((target = dsda_FindMobjFromThingIDOrMobj(args[0], mo, &search)))
7610 {
7611 buttonSuccess |= P_RaiseThing(target, NULL);
7612 }
7613 }
7614 break;
7615 case zl_damage_thing:
7616 if (mo)
7617 {
7618 if (args[0] < 0)
7619 {
7620 P_HealMobj(mo, -args[0]);
7621 }
7622 else
7623 {
7624 P_DamageMobj(mo, NULL, NULL, args[0] ? args[0] : 10000);
7625 }
7626 buttonSuccess = 1;
7627 }
7628 break;
7629 case zl_thing_damage:
7630 {
7631 mobj_t *target;
7632 thing_id_search_t search;
7633
7634 dsda_ResetThingIDSearch(&search);
7635 while ((target = dsda_FindMobjFromThingIDOrMobj(args[0], mo, &search)))
7636 {
7637 if (target->flags & MF_SHOOTABLE)
7638 {
7639 if (args[1] > 0)
7640 {
7641 P_DamageMobj(target, NULL, mo, args[1]);
7642 }
7643 else
7644 {
7645 P_HealMobj(mo, -args[1]);
7646 }
7647 }
7648 }
7649 }
7650 buttonSuccess = 1;
7651 break;
7652 case zl_thing_destroy:
7653 if (!args[0] && !args[2])
7654 {
7655 P_Massacre();
7656 }
7657 else if (!args[0])
7658 {
7659 const int *id_p;
7660
7661 FIND_SECTORS(id_p, args[2])
7662 {
7663 msecnode_t *n;
7664 sector_t *sec;
7665
7666 sec = &sectors[*id_p];
7667 for (n = sec->touching_thinglist; n;)
7668 {
7669 mobj_t *target = n->m_thing;
7670
7671 // Not sure if n might be freed when an enemy dies,
7672 // so let's get the next node before applying the damage
7673 n = n->m_snext;
7674
7675 if (target->flags & MF_SHOOTABLE)
7676 P_DamageMobj(target, NULL, mo, args[1] ? 10000 : target->health);
7677 }
7678 }
7679 }
7680 else
7681 {
7682 mobj_t *target;
7683 thing_id_search_t search;
7684
7685 dsda_ResetThingIDSearch(&search);
7686 while ((target = dsda_FindMobjFromThingID(args[0], &search)))
7687 {
7688 if (
7689 target->flags & MF_SHOOTABLE &&
7690 (!args[2] || target->subsector->sector->tag == args[2])
7691 )
7692 P_DamageMobj(target, NULL, mo, args[1] ? 10000 : target->health);
7693 }
7694 }
7695 buttonSuccess = 1;
7696 break;
7697 case zl_map_set_colormap:
7698 if (args[0] >= 0)
7699 {
7700 map_info.default_colormap = args[0];
7701 }
7702 buttonSuccess = 1;
7703 break;
7704 case zl_sector_set_colormap:
7705 if (args[0] >= 0 && args[1])
7706 {
7707 const int *id_p;
7708
7709 FIND_SECTORS(id_p, args[1])
7710 sectors[*id_p].colormap = args[0];
7711 }
7712 buttonSuccess = 1;
7713 break;
7714 case zl_music_change_song:
7715 if (args[0] != LUMP_NOT_FOUND)
7716 {
7717 if (!args[1] || (mo->player && mo->player->mo == mo))
7718 {
7719 S_ChangeMusInfoMusic(args[0], args[2]);
7720 buttonSuccess = 1;
7721 }
7722 }
7723 break;
7724 case zl_music_stop:
7725 if (!args[0] || (mo->player && mo->player->mo == mo))
7726 {
7727 S_StopMusic();
7728 buttonSuccess = 1;
7729 }
7730 break;
7731 default:
7732 break;
7733 }
7734
7735 return buttonSuccess;
7736 }
7737
7738 dboolean P_ExecuteHexenLineSpecial(int special, int * special_args, line_t * line, int side, mobj_t * mo)
7739 {
7740 byte args[5];
7741 dboolean buttonSuccess = false;
7742
7743 COLLAPSE_SPECIAL_ARGS(args, special_args);
7744
7745 switch (special)
7746 {
7747 case 1: // Poly Start Line
7748 break;
7749 case 2: // Poly Rotate Left
7750 buttonSuccess = EV_RotatePoly(line, args, 1, false);
7751 break;
7752 case 3: // Poly Rotate Right
7753 buttonSuccess = EV_RotatePoly(line, args, -1, false);
7754 break;
7755 case 4: // Poly Move
7756 buttonSuccess = EV_MovePoly(line, args, false, false);
7757 break;
7758 case 6: // Poly Move Times 8
7759 buttonSuccess = EV_MovePoly(line, args, true, false);
7760 break;
7761 case 7: // Poly Door Swing
7762 buttonSuccess = EV_OpenPolyDoor(line, args, PODOOR_SWING);
7763 break;
7764 case 8: // Poly Door Slide
7765 buttonSuccess = EV_OpenPolyDoor(line, args, PODOOR_SLIDE);
7766 break;
7767 case 10: // Door Close
7768 buttonSuccess = Hexen_EV_DoDoor(line, args, DREV_CLOSE);
7769 break;
7770 case 11: // Door Open
7771 if (!args[0])
7772 {
7773 buttonSuccess = Hexen_EV_VerticalDoor(line, mo);
7774 }
7775 else
7776 {
7777 buttonSuccess = Hexen_EV_DoDoor(line, args, DREV_OPEN);
7778 }
7779 break;
7780 case 12: // Door Raise
7781 if (!args[0])
7782 {
7783 buttonSuccess = Hexen_EV_VerticalDoor(line, mo);
7784 }
7785 else
7786 {
7787 buttonSuccess = Hexen_EV_DoDoor(line, args, DREV_NORMAL);
7788 }
7789 break;
7790 case 13: // Door Locked_Raise
7791 if (CheckedLockedDoor(mo, args[3]))
7792 {
7793 if (!args[0])
7794 {
7795 buttonSuccess = Hexen_EV_VerticalDoor(line, mo);
7796 }
7797 else
7798 {
7799 buttonSuccess = Hexen_EV_DoDoor(line, args, DREV_NORMAL);
7800 }
7801 }
7802 break;
7803 case 20: // Floor Lower by Value
7804 buttonSuccess = Hexen_EV_DoFloor(line, args, FLEV_LOWERFLOORBYVALUE);
7805 break;
7806 case 21: // Floor Lower to Lowest
7807 buttonSuccess = Hexen_EV_DoFloor(line, args, FLEV_LOWERFLOORTOLOWEST);
7808 break;
7809 case 22: // Floor Lower to Nearest
7810 buttonSuccess = Hexen_EV_DoFloor(line, args, FLEV_LOWERFLOOR);
7811 break;
7812 case 23: // Floor Raise by Value
7813 buttonSuccess = Hexen_EV_DoFloor(line, args, FLEV_RAISEFLOORBYVALUE);
7814 break;
7815 case 24: // Floor Raise to Highest
7816 buttonSuccess = Hexen_EV_DoFloor(line, args, FLEV_RAISEFLOOR);
7817 break;
7818 case 25: // Floor Raise to Nearest
7819 buttonSuccess = Hexen_EV_DoFloor(line, args, FLEV_RAISEFLOORTONEAREST);
7820 break;
7821 case 26: // Stairs Build Down Normal
7822 buttonSuccess = Hexen_EV_BuildStairs(line, args, -1, STAIRS_NORMAL);
7823 break;
7824 case 27: // Build Stairs Up Normal
7825 buttonSuccess = Hexen_EV_BuildStairs(line, args, 1, STAIRS_NORMAL);
7826 break;
7827 case 28: // Floor Raise and Crush
7828 buttonSuccess = Hexen_EV_DoFloor(line, args, FLEV_RAISEFLOORCRUSH);
7829 break;
7830 case 29: // Build Pillar (no crushing)
7831 buttonSuccess = EV_BuildPillar(line, args, false);
7832 break;
7833 case 30: // Open Pillar
7834 buttonSuccess = EV_OpenPillar(line, args);
7835 break;
7836 case 31: // Stairs Build Down Sync
7837 buttonSuccess = Hexen_EV_BuildStairs(line, args, -1, STAIRS_SYNC);
7838 break;
7839 case 32: // Build Stairs Up Sync
7840 buttonSuccess = Hexen_EV_BuildStairs(line, args, 1, STAIRS_SYNC);
7841 break;
7842 case 35: // Raise Floor by Value Times 8
7843 buttonSuccess = Hexen_EV_DoFloor(line, args, FLEV_RAISEBYVALUETIMES8);
7844 break;
7845 case 36: // Lower Floor by Value Times 8
7846 buttonSuccess = Hexen_EV_DoFloor(line, args, FLEV_LOWERBYVALUETIMES8);
7847 break;
7848 case 40: // Ceiling Lower by Value
7849 buttonSuccess = Hexen_EV_DoCeiling(line, args, CLEV_LOWERBYVALUE);
7850 break;
7851 case 41: // Ceiling Raise by Value
7852 buttonSuccess = Hexen_EV_DoCeiling(line, args, CLEV_RAISEBYVALUE);
7853 break;
7854 case 42: // Ceiling Crush and Raise
7855 buttonSuccess = Hexen_EV_DoCeiling(line, args, CLEV_CRUSHANDRAISE);
7856 break;
7857 case 43: // Ceiling Lower and Crush
7858 buttonSuccess = Hexen_EV_DoCeiling(line, args, CLEV_LOWERANDCRUSH);
7859 break;
7860 case 44: // Ceiling Crush Stop
7861 buttonSuccess = Hexen_EV_CeilingCrushStop(line, args);
7862 break;
7863 case 45: // Ceiling Crush Raise and Stay
7864 buttonSuccess = Hexen_EV_DoCeiling(line, args, CLEV_CRUSHRAISEANDSTAY);
7865 break;
7866 case 46: // Floor Crush Stop
7867 buttonSuccess = EV_FloorCrushStop(line, args);
7868 break;
7869 case 60: // Plat Perpetual Raise
7870 buttonSuccess = EV_DoHexenPlat(line, args, PLAT_PERPETUALRAISE, 0);
7871 break;
7872 case 61: // Plat Stop
7873 Hexen_EV_StopPlat(line, args);
7874 break;
7875 case 62: // Plat Down-Wait-Up-Stay
7876 buttonSuccess = EV_DoHexenPlat(line, args, PLAT_DOWNWAITUPSTAY, 0);
7877 break;
7878 case 63: // Plat Down-by-Value*8-Wait-Up-Stay
7879 buttonSuccess = EV_DoHexenPlat(line, args, PLAT_DOWNBYVALUEWAITUPSTAY,
7880 0);
7881 break;
7882 case 64: // Plat Up-Wait-Down-Stay
7883 buttonSuccess = EV_DoHexenPlat(line, args, PLAT_UPWAITDOWNSTAY, 0);
7884 break;
7885 case 65: // Plat Up-by-Value*8-Wait-Down-Stay
7886 buttonSuccess = EV_DoHexenPlat(line, args, PLAT_UPBYVALUEWAITDOWNSTAY,
7887 0);
7888 break;
7889 case 66: // Floor Lower Instant * 8
7890 buttonSuccess = Hexen_EV_DoFloor(line, args, FLEV_LOWERTIMES8INSTANT);
7891 break;
7892 case 67: // Floor Raise Instant * 8
7893 buttonSuccess = Hexen_EV_DoFloor(line, args, FLEV_RAISETIMES8INSTANT);
7894 break;
7895 case 68: // Floor Move to Value * 8
7896 buttonSuccess = Hexen_EV_DoFloor(line, args, FLEV_MOVETOVALUETIMES8);
7897 break;
7898 case 69: // Ceiling Move to Value * 8
7899 buttonSuccess = Hexen_EV_DoCeiling(line, args, CLEV_MOVETOVALUETIMES8);
7900 break;
7901 case 70: // Teleport
7902 if (side == 0)
7903 { // Only teleport when crossing the front side of a line
7904 buttonSuccess = EV_HexenTeleport(args[0], mo, true);
7905 }
7906 break;
7907 case 71: // Teleport, no fog
7908 if (side == 0)
7909 { // Only teleport when crossing the front side of a line
7910 buttonSuccess = EV_HexenTeleport(args[0], mo, false);
7911 }
7912 break;
7913 case 72: // Thrust Mobj
7914 if (!side) // Only thrust on side 0
7915 {
7916 P_ThrustMobj(mo, args[0] * (ANG90 / 64),
7917 args[1] << FRACBITS);
7918 buttonSuccess = 1;
7919 }
7920 break;
7921 case 73: // Damage Mobj
7922 if (args[0])
7923 {
7924 P_DamageMobj(mo, NULL, NULL, args[0]);
7925 }
7926 else
7927 { // If arg1 is zero, then guarantee a kill
7928 P_DamageMobj(mo, NULL, NULL, 10000);
7929 }
7930 buttonSuccess = 1;
7931 break;
7932 case 74: // Teleport_NewMap
7933 if (side == 0)
7934 { // Only teleport when crossing the front side of a line
7935 if (!(mo && mo->player && mo->player->playerstate == PST_DEAD)) // Players must be alive to teleport
7936 {
7937 G_Completed(args[0], args[1], 0, 0);
7938 buttonSuccess = true;
7939 }
7940 }
7941 break;
7942 case 75: // Teleport_EndGame
7943 if (side == 0)
7944 { // Only teleport when crossing the front side of a line
7945 if (!(mo && mo->player && mo->player->playerstate == PST_DEAD)) // Players must be alive to teleport
7946 {
7947 buttonSuccess = true;
7948 if (deathmatch)
7949 { // Winning in deathmatch just goes back to map 1
7950 G_Completed(1, 0, 0, 0);
7951 }
7952 else
7953 { // Starts the Finale
7954 G_Completed(LEAVE_VICTORY, LEAVE_VICTORY, 0, 0);
7955 }
7956 }
7957 }
7958 break;
7959 case 80: // ACS_Execute
7960 buttonSuccess =
7961 P_StartACS(args[0], args[1], &args[2], mo, line, side);
7962 break;
7963 case 81: // ACS_Suspend
7964 buttonSuccess = P_SuspendACS(args[0], args[1]);
7965 break;
7966 case 82: // ACS_Terminate
7967 buttonSuccess = P_TerminateACS(args[0], args[1]);
7968 break;
7969 case 83: // ACS_LockedExecute
7970 buttonSuccess = P_StartLockedACS(line, args, mo, side);
7971 break;
7972 case 90: // Poly Rotate Left Override
7973 buttonSuccess = EV_RotatePoly(line, args, 1, true);
7974 break;
7975 case 91: // Poly Rotate Right Override
7976 buttonSuccess = EV_RotatePoly(line, args, -1, true);
7977 break;
7978 case 92: // Poly Move Override
7979 buttonSuccess = EV_MovePoly(line, args, false, true);
7980 break;
7981 case 93: // Poly Move Times 8 Override
7982 buttonSuccess = EV_MovePoly(line, args, true, true);
7983 break;
7984 case 94: // Build Pillar Crush
7985 buttonSuccess = EV_BuildPillar(line, args, true);
7986 break;
7987 case 95: // Lower Floor and Ceiling
7988 buttonSuccess = EV_DoFloorAndCeiling(line, args, false);
7989 break;
7990 case 96: // Raise Floor and Ceiling
7991 buttonSuccess = EV_DoFloorAndCeiling(line, args, true);
7992 break;
7993 case 109: // Force Lightning
7994 buttonSuccess = true;
7995 P_ForceLightning();
7996 break;
7997 case 110: // Light Raise by Value
7998 buttonSuccess = EV_SpawnLight(line, args, LITE_RAISEBYVALUE);
7999 break;
8000 case 111: // Light Lower by Value
8001 buttonSuccess = EV_SpawnLight(line, args, LITE_LOWERBYVALUE);
8002 break;
8003 case 112: // Light Change to Value
8004 buttonSuccess = EV_SpawnLight(line, args, LITE_CHANGETOVALUE);
8005 break;
8006 case 113: // Light Fade
8007 buttonSuccess = EV_SpawnLight(line, args, LITE_FADE);
8008 break;
8009 case 114: // Light Glow
8010 buttonSuccess = EV_SpawnLight(line, args, LITE_GLOW);
8011 break;
8012 case 115: // Light Flicker
8013 buttonSuccess = EV_SpawnLight(line, args, LITE_FLICKER);
8014 break;
8015 case 116: // Light Strobe
8016 buttonSuccess = EV_SpawnLight(line, args, LITE_STROBE);
8017 break;
8018 case 120: // Quake Tremor
8019 buttonSuccess = A_LocalQuake(args, mo);
8020 break;
8021 case 129: // UsePuzzleItem
8022 buttonSuccess = EV_LineSearchForPuzzleItem(line, args, mo);
8023 break;
8024 case 130: // Thing_Activate
8025 buttonSuccess = EV_ThingActivate(args[0]);
8026 break;
8027 case 131: // Thing_Deactivate
8028 buttonSuccess = EV_ThingDeactivate(args[0]);
8029 break;
8030 case 132: // Thing_Remove
8031 buttonSuccess = EV_ThingRemove(args[0]);
8032 break;
8033 case 133: // Thing_Destroy
8034 buttonSuccess = EV_ThingDestroy(args[0]);
8035 break;
8036 case 134: // Thing_Projectile
8037 buttonSuccess = EV_ThingProjectile(args, 0);
8038 break;
8039 case 135: // Thing_Spawn
8040 buttonSuccess = EV_ThingSpawn(args, 1);
8041 break;
8042 case 136: // Thing_ProjectileGravity
8043 buttonSuccess = EV_ThingProjectile(args, 1);
8044 break;
8045 case 137: // Thing_SpawnNoFog
8046 buttonSuccess = EV_ThingSpawn(args, 0);
8047 break;
8048 case 138: // Floor_Waggle
8049 buttonSuccess = EV_StartFloorWaggle(args[0], args[1],
8050 args[2], args[3], args[4]);
8051 break;
8052 case 140: // Sector_SoundChange
8053 buttonSuccess = EV_SectorSoundChange(args);
8054 break;
8055 default:
8056 break;
8057 }
8058 return buttonSuccess;
8059 }
8060
8061 static void Hexen_P_SpawnSpecials(void)
8062 {
8063 sector_t *sector;
8064 int i;
8065
8066 //
8067 // Init special SECTORs
8068 //
8069 sector = sectors;
8070 for (i = 0; i < numsectors; i++, sector++)
8071 {
8072 if (!sector->special)
8073 continue;
8074 switch (sector->special)
8075 {
8076 case 1: // Phased light
8077 // Hardcoded base, use sector->lightlevel as the index
8078 P_SpawnPhasedLight(sector, 80, -1);
8079 break;
8080 case 2: // Phased light sequence start
8081 P_SpawnLightSequence(sector, 1);
8082 break;
8083 // Specials 3 & 4 are used by the phased light sequences
8084 }
8085 }
8086
8087
8088 //
8089 // Init line EFFECTs
8090 //
8091 numlinespecials = 0;
8092 TaggedLineCount = 0;
8093 for (i = 0; i < numlines; i++)
8094 {
8095 switch (lines[i].special)
8096 {
8097 case 100: // Scroll_Texture_Left
8098 case 101: // Scroll_Texture_Right
8099 case 102: // Scroll_Texture_Up
8100 case 103: // Scroll_Texture_Down
8101 linespeciallist[numlinespecials] = &lines[i];
8102 numlinespecials++;
8103 break;
8104 case 121: // Line_SetIdentification
8105 if (lines[i].special_args[0])
8106 {
8107 if (TaggedLineCount == MAX_TAGGED_LINES)
8108 {
8109 I_Error("P_SpawnSpecials: MAX_TAGGED_LINES "
8110 "(%d) exceeded.", MAX_TAGGED_LINES);
8111 }
8112 TaggedLines[TaggedLineCount].line = &lines[i];
8113 TaggedLines[TaggedLineCount++].lineTag = lines[i].special_args[0];
8114 }
8115 lines[i].special = 0;
8116 break;
8117 }
8118 }
8119
8120 //
8121 // Init other misc stuff
8122 //
8123 P_RemoveAllActiveCeilings();
8124 P_RemoveAllActivePlats();
8125 for (i = 0; i < MAXBUTTONS; i++)
8126 memset(&buttonlist[i], 0, sizeof(button_t));
8127
8128 // Initialize flat and texture animations
8129 P_InitFTAnims();
8130 }