Debian Codegraph @

prboom2/src/p_ceilng.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 * Ceiling aninmation (lowering, crushing, raising)
31 *
32 *-----------------------------------------------------------------------------*/
33
34 #include "doomstat.h"
35 #include "r_main.h"
36 #include "p_map.h"
37 #include "p_spec.h"
38 #include "p_tick.h"
39 #include "s_sound.h"
40 #include "sounds.h"
41 #include "e6y.h"//e6y
42
43 #include "hexen/p_acs.h"
44 #include "hexen/sn_sonix.h"
45
46 #include "dsda/id_list.h"
47 #include "dsda/map_format.h"
48
49 // the list of ceilings moving currently, including crushers
50 ceilinglist_t *activeceilings;
51
52 /////////////////////////////////////////////////////////////////
53 //
54 // Ceiling action routine and linedef type handler
55 //
56 /////////////////////////////////////////////////////////////////
57
58 //
59 // T_MoveCeilingPlane()
60 //
61 // Move a ceiling plane and check for crushing. Called
62 // every tick by all actions that move ceiling.
63 //
64 // Passed the sector to move a plane in, the speed to move it at,
65 // the dest height it is to achieve, whether it crushes obstacles,
66 // and the direction up or down to move.
67 //
68 // Returns a result_e:
69 // ok - plane moved normally, has not achieved destination yet
70 // pastdest - plane moved normally and is now at destination height
71 // crushed - plane encountered an obstacle, is holding until removed
72 //
73 result_e T_MoveCeilingPlane
74 ( sector_t* sector,
75 fixed_t speed,
76 fixed_t dest,
77 int crush,
78 int direction,
79 dboolean hexencrush )
80 {
81 dboolean flag;
82 fixed_t lastpos;
83 fixed_t destheight; //jff 02/04/98 used to keep ceilings from moving thru each other
84
85 if (V_IsOpenGLMode())
86 {
87 gld_UpdateSplitData(sector);
88 }
89
90 switch(direction)
91 {
92 case -1:
93 // moving a ceiling down
94 // jff 02/04/98 keep ceiling from moving thru floors
95 // jff 2/22/98 weaken check to demo_compatibility
96 destheight = (comp[comp_floors] || dest>sector->floorheight)?
97 dest : sector->floorheight;
98 if (sector->ceilingheight - speed < destheight)
99 {
100 lastpos = sector->ceilingheight;
101 sector->ceilingheight = destheight;
102 flag = P_CheckSector(sector,crush); //jff 3/19/98 use faster chk
103
104 if (flag == true)
105 {
106 sector->ceilingheight = lastpos;
107 P_CheckSector(sector,crush); //jff 3/19/98 use faster chk
108 }
109 return pastdest;
110 }
111 else
112 {
113 // crushing is possible
114 lastpos = sector->ceilingheight;
115 sector->ceilingheight -= speed;
116 flag = P_CheckSector(sector,crush); //jff 3/19/98 use faster chk
117
118 if (flag == true)
119 {
120 if (!hexencrush && crush >= 0)
121 return crushed;
122 sector->ceilingheight = lastpos;
123 P_CheckSector(sector,crush); //jff 3/19/98 use faster chk
124 return crushed;
125 }
126 }
127 break;
128
129 case 1:
130 // moving a ceiling up
131 if (sector->ceilingheight + speed > dest)
132 {
133 lastpos = sector->ceilingheight;
134 sector->ceilingheight = dest;
135 flag = P_CheckSector(sector,crush); //jff 3/19/98 use faster chk
136 if (flag == true)
137 {
138 sector->ceilingheight = lastpos;
139 P_CheckSector(sector,crush); //jff 3/19/98 use faster chk
140 }
141 return pastdest;
142 }
143 else
144 {
145 lastpos = sector->ceilingheight;
146 sector->ceilingheight += speed;
147 flag = P_CheckSector(sector,crush); //jff 3/19/98 use faster chk
148 }
149 break;
150 }
151
152 return ok;
153 }
154
155 //
156 // T_MoveCeiling
157 //
158 // Action routine that moves ceilings. Called once per tick.
159 //
160 // Passed a ceiling_t structure that contains all the info about the move.
161 // see P_SPEC.H for fields. No return.
162 //
163 // jff 02/08/98 all cases with labels beginning with gen added to support
164 // generalized line type behaviors.
165 //
166
167 void T_MoveCompatibleCeiling(ceiling_t * ceiling)
168 {
169 result_e res;
170
171 switch(ceiling->direction)
172 {
173 case 0:
174 // If ceiling in stasis, do nothing
175 break;
176
177 case 1:
178 // Ceiling is moving up
179 res = T_MoveCeilingPlane
180 (
181 ceiling->sector,
182 ceiling->speed,
183 ceiling->topheight,
184 NO_CRUSH,
185 ceiling->direction,
186 false
187 );
188
189 // if not silent, make moving sound
190 if (!(leveltime & 7) && !ceiling->silent)
191 S_LoopSectorSound(ceiling->sector, g_sfx_stnmov, 8);
192
193 // handle reaching destination height
194 if (res == pastdest)
195 {
196 switch(ceiling->type)
197 {
198 // plain movers are just removed
199 case raiseToHighest:
200 case genCeiling:
201 P_RemoveActiveCeiling(ceiling);
202 break;
203
204 // movers with texture change, change the texture then get removed
205 case genCeilingChgT:
206 case genCeilingChg0:
207 P_TransferSpecial(ceiling->sector, &ceiling->newspecial);
208 // fallthrough
209 case genCeilingChg:
210 ceiling->sector->ceilingpic = ceiling->texture;
211 P_RemoveActiveCeiling(ceiling);
212 break;
213
214 // crushers reverse direction at the top
215 case silentCrushAndRaise:
216 S_StartSectorSound(ceiling->sector, sfx_pstop);
217 // fallthrough
218 case genSilentCrusher:
219 case genCrusher:
220 case fastCrushAndRaise:
221 case crushAndRaise:
222 ceiling->direction = -1;
223 break;
224
225 case ceilCrushAndRaise:
226 ceiling->direction = -1;
227 ceiling->speed = ceiling->oldspeed;
228 if (ceiling->silent == 1)
229 S_StartSectorSound(ceiling->sector, sfx_pstop);
230 break;
231
232 default:
233 if (map_format.zdoom)
234 P_RemoveActiveCeiling(ceiling);
235 break;
236 }
237 }
238 break;
239
240 case -1:
241 // Ceiling moving down
242 res = T_MoveCeilingPlane
243 (
244 ceiling->sector,
245 ceiling->speed,
246 ceiling->bottomheight,
247 ceiling->crush,
248 ceiling->direction,
249 ceiling->crushmode == crushHexen
250 );
251
252 // if not silent, make moving sound
253 if (!(leveltime & 7) && !ceiling->silent)
254 S_LoopSectorSound(ceiling->sector, g_sfx_stnmov, 8);
255
256 // handle reaching destination height
257 if (res == pastdest)
258 {
259 switch(ceiling->type)
260 {
261 // 02/09/98 jff change slow crushers' speed back to normal
262 // start back up
263 case genSilentCrusher:
264 case genCrusher:
265 if (ceiling->oldspeed<CEILSPEED*3)
266 ceiling->speed = ceiling->oldspeed;
267 ceiling->direction = 1; //jff 2/22/98 make it go back up!
268 break;
269
270 // make platform stop at bottom of all crusher strokes
271 // except generalized ones, reset speed, start back up
272 case silentCrushAndRaise:
273 S_StartSectorSound(ceiling->sector, sfx_pstop);
274 // fallthrough
275 case crushAndRaise:
276 ceiling->speed = CEILSPEED;
277 // fallthrough
278 case fastCrushAndRaise:
279 ceiling->direction = 1;
280 break;
281
282 // in the case of ceiling mover/changer, change the texture
283 // then remove the active ceiling
284 case genCeilingChgT:
285 case genCeilingChg0:
286 P_TransferSpecial(ceiling->sector, &ceiling->newspecial);
287 // fallthrough
288 case genCeilingChg:
289 ceiling->sector->ceilingpic = ceiling->texture;
290 P_RemoveActiveCeiling(ceiling);
291 break;
292
293 // all other case, just remove the active ceiling
294 case lowerAndCrush:
295 case lowerToFloor:
296 case lowerToLowest:
297 case lowerToMaxFloor:
298 case genCeiling:
299 P_RemoveActiveCeiling(ceiling);
300 break;
301
302 case ceilCrushAndRaise:
303 case ceilCrushRaiseAndStay:
304 ceiling->speed = ceiling->speed2;
305 ceiling->direction = 1;
306 if (ceiling->silent == 1)
307 S_StartSectorSound(ceiling->sector, sfx_pstop);
308 break;
309
310 default:
311 if (map_format.zdoom)
312 P_RemoveActiveCeiling(ceiling);
313 break;
314 }
315 }
316 else // ( res != pastdest )
317 {
318 // handle the crusher encountering an obstacle
319 if (res == crushed)
320 {
321 switch(ceiling->type)
322 {
323 //jff 02/08/98 slow down slow crushers on obstacle
324 case genCrusher:
325 case genSilentCrusher:
326 if (ceiling->oldspeed < CEILSPEED*3)
327 ceiling->speed = CEILSPEED / 8;
328 break;
329 case silentCrushAndRaise:
330 case crushAndRaise:
331 case lowerAndCrush:
332 ceiling->speed = CEILSPEED / 8;
333 break;
334
335 case ceilCrushAndRaise:
336 case ceilLowerAndCrush:
337 if (ceiling->crushmode == crushSlowdown)
338 ceiling->speed = FRACUNIT / 8;
339 break;
340
341 default:
342 break;
343 }
344 }
345 }
346 break;
347 }
348 }
349
350 void T_MoveHexenCeiling(ceiling_t * ceiling)
351 {
352 result_e res;
353
354 switch (ceiling->direction)
355 {
356 // case 0: // IN STASIS
357 // break;
358 case 1: // UP
359 res = T_MoveCeilingPlane(ceiling->sector, ceiling->speed,
360 ceiling->topheight, NO_CRUSH,
361 ceiling->direction, true);
362 if (res == pastdest)
363 {
364 SN_StopSequence((mobj_t *) & ceiling->sector->soundorg);
365 switch (ceiling->type)
366 {
367 case CLEV_CRUSHANDRAISE:
368 ceiling->direction = -1;
369 ceiling->speed = ceiling->speed * 2;
370 break;
371 default:
372 P_RemoveActiveCeiling(ceiling);
373 break;
374 }
375 }
376 break;
377 case -1: // DOWN
378 res = T_MoveCeilingPlane(ceiling->sector, ceiling->speed,
379 ceiling->bottomheight, ceiling->crush,
380 ceiling->direction, true);
381 if (res == pastdest)
382 {
383 SN_StopSequence((mobj_t *) & ceiling->sector->soundorg);
384 switch (ceiling->type)
385 {
386 case CLEV_CRUSHANDRAISE:
387 case CLEV_CRUSHRAISEANDSTAY:
388 ceiling->direction = 1;
389 ceiling->speed = ceiling->speed / 2;
390 break;
391 default:
392 P_RemoveActiveCeiling(ceiling);
393 break;
394 }
395 }
396 else if (res == crushed)
397 {
398 switch (ceiling->type)
399 {
400 case CLEV_CRUSHANDRAISE:
401 case CLEV_LOWERANDCRUSH:
402 case CLEV_CRUSHRAISEANDSTAY:
403 //ceiling->speed = ceiling->speed/4;
404 break;
405 default:
406 break;
407 }
408 }
409 break;
410 }
411 }
412
413 void T_MoveCeiling (ceiling_t * ceiling)
414 {
415 map_format.t_move_ceiling(ceiling);
416 }
417
418
419 //
420 // EV_DoCeiling
421 //
422 // Move a ceiling up/down or start a crusher
423 //
424 // Passed the linedef activating the function and the type of function desired
425 // returns true if a thinker started
426 //
427 int EV_DoCeiling
428 ( line_t* line,
429 ceiling_e type )
430 {
431 const int *id_p;
432 int rtn;
433 sector_t* sec;
434 ceiling_t* ceiling;
435
436 rtn = 0;
437
438 // Reactivate in-stasis ceilings...for certain types.
439 // This restarts a crusher after it has been stopped
440 switch(type)
441 {
442 case fastCrushAndRaise:
443 case silentCrushAndRaise:
444 case crushAndRaise:
445 //jff 4/5/98 return if activated
446 rtn = P_ActivateInStasisCeiling(line->tag); // heretic_note: rtn not set in heretic
447 default:
448 break;
449 }
450
451 // affects all sectors with the same tag as the linedef
452 FIND_SECTORS(id_p, line->tag)
453 {
454 sec = &sectors[*id_p];
455
456 // if ceiling already moving, don't start a second function on it
457 if (P_CeilingActive(sec)) //jff 2/22/98
458 continue;
459
460 // create a new ceiling thinker
461 rtn = 1;
462 ceiling = Z_MallocLevel (sizeof(*ceiling));
463 memset(ceiling, 0, sizeof(*ceiling));
464 P_AddThinker (&ceiling->thinker);
465 sec->ceilingdata = ceiling; //jff 2/22/98
466 ceiling->thinker.function = T_MoveCeiling;
467 ceiling->sector = sec;
468 ceiling->crush = NO_CRUSH;
469
470 // setup ceiling structure according to type of function
471 switch(type)
472 {
473 case fastCrushAndRaise:
474 ceiling->crush = DOOM_CRUSH;
475 ceiling->topheight = sec->ceilingheight;
476 ceiling->bottomheight = sec->floorheight + (8*FRACUNIT);
477 ceiling->direction = -1;
478 ceiling->speed = CEILSPEED * 2;
479 break;
480
481 case silentCrushAndRaise:
482 ceiling->silent = 1;
483 case crushAndRaise:
484 ceiling->crush = DOOM_CRUSH;
485 ceiling->topheight = sec->ceilingheight;
486 // fallthrough
487 case lowerAndCrush:
488 case lowerToFloor:
489 ceiling->bottomheight = sec->floorheight;
490 if (type != lowerToFloor)
491 ceiling->bottomheight += 8*FRACUNIT;
492 ceiling->direction = -1;
493 ceiling->speed = CEILSPEED;
494 break;
495
496 case raiseToHighest:
497 ceiling->topheight = P_FindHighestCeilingSurrounding(sec);
498 ceiling->direction = 1;
499 ceiling->speed = CEILSPEED;
500 break;
501
502 case lowerToLowest:
503 ceiling->bottomheight = P_FindLowestCeilingSurrounding(sec);
504 ceiling->direction = -1;
505 ceiling->speed = CEILSPEED;
506 break;
507
508 case lowerToMaxFloor:
509 ceiling->bottomheight = P_FindHighestFloorSurrounding(sec);
510 ceiling->direction = -1;
511 ceiling->speed = CEILSPEED;
512 break;
513
514 default:
515 break;
516 }
517
518 // add the ceiling to the active list
519 ceiling->tag = sec->tag;
520 ceiling->type = type;
521 P_AddActiveCeiling(ceiling);
522 }
523 return rtn;
524 }
525
526 //////////////////////////////////////////////////////////////////////
527 //
528 // Active ceiling list primitives
529 //
530 /////////////////////////////////////////////////////////////////////
531
532 // jff 2/22/98 - modified Lee's plat code to work for ceilings
533 //
534 // The following were all rewritten by Lee Killough
535 // to use the new structure which places no limits
536 // on active ceilings. It also avoids spending as much
537 // time searching for active ceilings. Previously a
538 // fixed-size array was used, with NULL indicating
539 // empty entries, while now a doubly-linked list
540 // is used.
541
542 //
543 // P_ActivateInStasisCeiling()
544 //
545 // Reactivates all stopped crushers with the right tag
546 //
547 // Passed the line reactivating the crusher
548 // Returns true if a ceiling reactivated
549 //
550 //jff 4/5/98 return if activated
551 int P_ActivateInStasisCeiling(int tag)
552 {
553 ceilinglist_t *cl;
554 int rtn=0;
555
556 for (cl=activeceilings; cl; cl=cl->next)
557 {
558 ceiling_t *ceiling = cl->ceiling;
559 if (ceiling->tag == tag && ceiling->direction == 0)
560 {
561 ceiling->direction = ceiling->olddirection;
562 ceiling->thinker.function = T_MoveCeiling;
563 //jff 4/5/98 return if activated
564 rtn=1;
565 }
566 }
567 return rtn;
568 }
569
570 // TODO: without reflection, we don't know if the ceilingdata needs special handling
571 int EV_ZDoomCeilingStop(int tag, line_t *line)
572 {
573 const int *id_p;
574 ceilinglist_t *cl;
575
576 for (cl = activeceilings; cl; cl = cl->next)
577 {
578 ceiling_t *ceiling = cl->ceiling;
579 if (ceiling->tag == tag)
580 {
581 P_RemoveActiveCeiling(ceiling);
582 }
583 }
584
585 FIND_SECTORS2(id_p, tag, line)
586 {
587 sector_t *sec = &sectors[*id_p];
588 ceiling_t *ceiling = (ceiling_t *) sec->ceilingdata;
589
590 if (ceiling)
591 {
592 sec->ceilingdata = NULL;
593 P_RemoveThinker(&ceiling->thinker);
594 }
595 }
596
597 return true;
598 }
599
600 int EV_ZDoomCeilingCrushStop(int tag, dboolean remove)
601 {
602 dboolean rtn = 0;
603 ceilinglist_t *cl;
604
605 for (cl = activeceilings; cl; cl = cl->next)
606 {
607 ceiling_t *ceiling = cl->ceiling;
608 if (ceiling->direction != 0 && ceiling->tag == tag)
609 {
610 if (!remove)
611 {
612 ceiling->olddirection = ceiling->direction;
613 ceiling->direction = 0;
614 }
615 else
616 {
617 P_RemoveActiveCeiling(ceiling);
618 }
619 rtn = 1;
620 }
621 }
622
623 return rtn;
624 }
625
626 //
627 // EV_CeilingCrushStop()
628 //
629 // Stops all active ceilings with the right tag
630 //
631 // Passed the linedef stopping the ceilings
632 // Returns true if a ceiling put in stasis
633 //
634 int EV_CeilingCrushStop(line_t* line)
635 {
636 int rtn=0;
637
638 ceilinglist_t *cl;
639 for (cl=activeceilings; cl; cl=cl->next)
640 {
641 ceiling_t *ceiling = cl->ceiling;
642 if (ceiling->direction != 0 && ceiling->tag == line->tag)
643 {
644 ceiling->olddirection = ceiling->direction;
645 ceiling->direction = 0;
646 ceiling->thinker.function = NULL;
647 rtn=1;
648 }
649 }
650 return rtn;
651 }
652
653 //
654 // P_AddActiveCeiling()
655 //
656 // Adds a ceiling to the head of the list of active ceilings
657 //
658 // Passed the ceiling motion structure
659 // Returns nothing
660 //
661 void P_AddActiveCeiling(ceiling_t* ceiling)
662 {
663 ceilinglist_t *list = Z_Malloc(sizeof *list);
664 list->ceiling = ceiling;
665 ceiling->list = list;
666 if ((list->next = activeceilings))
667 list->next->prev = &list->next;
668 list->prev = &activeceilings;
669 activeceilings = list;
670 }
671
672 //
673 // P_RemoveActiveCeiling()
674 //
675 // Removes a ceiling from the list of active ceilings
676 //
677 // Passed the ceiling motion structure
678 // Returns nothing
679 //
680 void P_RemoveActiveCeiling(ceiling_t* ceiling)
681 {
682 ceilinglist_t *list = ceiling->list;
683 ceiling->sector->ceilingdata = NULL; //jff 2/22/98
684 P_RemoveThinker(&ceiling->thinker);
685 P_TagFinished(ceiling->sector->tag);
686 if ((*list->prev = list->next))
687 list->next->prev = list->prev;
688 Z_Free(list);
689 }
690
691 //
692 // P_RemoveAllActiveCeilings()
693 //
694 // Removes all ceilings from the active ceiling list
695 //
696 // Passed nothing, returns nothing
697 //
698 void P_RemoveAllActiveCeilings(void)
699 {
700 while (activeceilings)
701 {
702 ceilinglist_t *next = activeceilings->next;
703 Z_Free(activeceilings);
704 activeceilings = next;
705 }
706 }
707
708 // hexen
709
710 int Hexen_EV_CeilingCrushStop(line_t * line, byte * args)
711 {
712 ceilinglist_t *cl;
713 for (cl=activeceilings; cl; cl=cl->next)
714 {
715 ceiling_t *ceiling = cl->ceiling;
716 if (ceiling->tag == args[0])
717 {
718 SN_StopSequence((mobj_t *) & ceiling->sector->soundorg);
719 P_RemoveActiveCeiling(ceiling);
720
721 return 1;
722 }
723 }
724 return 0;
725 }
726
727 static void P_SpawnZDoomCeiling(sector_t *sec, ceiling_e type, line_t *line, int tag,
728 fixed_t speed, fixed_t speed2, fixed_t height, int crush,
729 byte silent, int change, crushmode_e crushmode)
730 {
731 ceiling_t *ceiling;
732 fixed_t targheight = 0;
733
734 ceiling = Z_MallocLevel(sizeof(*ceiling));
735 memset(ceiling, 0, sizeof(*ceiling));
736 P_AddThinker(&ceiling->thinker);
737 sec->ceilingdata = ceiling;
738 ceiling->thinker.function = T_MoveCeiling;
739 ceiling->sector = sec;
740 ceiling->speed = speed;
741 ceiling->oldspeed = speed;
742 ceiling->speed2 = speed2;
743 ceiling->silent = (silent & ~4);
744 ceiling->texture = NO_TEXTURE;
745
746 switch (type)
747 {
748 case ceilCrushAndRaise:
749 case ceilCrushRaiseAndStay:
750 ceiling->topheight = sec->ceilingheight;
751 case ceilLowerAndCrush:
752 targheight = sec->floorheight + height;
753 ceiling->bottomheight = targheight;
754 ceiling->direction = -1;
755 break;
756 case ceilRaiseToHighest:
757 targheight = P_FindHighestCeilingSurrounding(sec);
758 ceiling->topheight = targheight;
759 ceiling->direction = 1;
760 break;
761 case ceilLowerByValue:
762 targheight = sec->ceilingheight - height;
763 ceiling->bottomheight = targheight;
764 ceiling->direction = -1;
765 break;
766 case ceilRaiseByValue:
767 targheight = sec->ceilingheight + height;
768 ceiling->topheight = targheight;
769 ceiling->direction = 1;
770 break;
771 case ceilMoveToValue:
772 {
773 fixed_t diff = height - sec->ceilingheight;
774
775 targheight = height;
776 if (diff < 0)
777 {
778 ceiling->bottomheight = height;
779 ceiling->direction = -1;
780 }
781 else
782 {
783 ceiling->topheight = height;
784 ceiling->direction = 1;
785 }
786 }
787 break;
788 case ceilLowerToHighestFloor:
789 targheight = P_FindHighestFloorSurrounding(sec) + height;
790 ceiling->bottomheight = targheight;
791 ceiling->direction = -1;
792 break;
793 case ceilRaiseToHighestFloor:
794 targheight = P_FindHighestFloorSurrounding(sec);
795 ceiling->topheight = targheight;
796 ceiling->direction = 1;
797 break;
798 case ceilLowerInstant:
799 targheight = sec->ceilingheight - height;
800 ceiling->bottomheight = targheight;
801 ceiling->direction = -1;
802 ceiling->speed = height;
803 break;
804 case ceilRaiseInstant:
805 targheight = sec->ceilingheight + height;
806 ceiling->topheight = targheight;
807 ceiling->direction = 1;
808 ceiling->speed = height;
809 break;
810 case ceilLowerToNearest:
811 targheight = P_FindNextLowestCeiling(sec, sec->ceilingheight);
812 ceiling->bottomheight = targheight;
813 ceiling->direction = -1;
814 break;
815 case ceilRaiseToNearest:
816 targheight = P_FindNextHighestCeiling(sec, sec->ceilingheight);
817 ceiling->topheight = targheight;
818 ceiling->direction = 1;
819 break;
820 case ceilLowerToLowest:
821 targheight = P_FindLowestCeilingSurrounding(sec);
822 ceiling->bottomheight = targheight;
823 ceiling->direction = -1;
824 break;
825 case ceilRaiseToLowest:
826 targheight = P_FindLowestCeilingSurrounding(sec);
827 ceiling->topheight = targheight;
828 ceiling->direction = 1;
829 break;
830 case ceilLowerToFloor:
831 targheight = sec->floorheight + height;
832 ceiling->bottomheight = targheight;
833 ceiling->direction = -1;
834 break;
835 case ceilRaiseToFloor:
836 targheight = sec->floorheight + height;
837 ceiling->topheight = targheight;
838 ceiling->direction = 1;
839 break;
840 case ceilLowerToHighest:
841 targheight = P_FindHighestCeilingSurrounding(sec);
842 ceiling->bottomheight = targheight;
843 ceiling->direction = -1;
844 break;
845 case ceilLowerByTexture:
846 targheight = sec->ceilingheight - P_FindShortestUpperAround(sec->iSectorID);
847 ceiling->bottomheight = targheight;
848 ceiling->direction = -1;
849 break;
850 case ceilRaiseByTexture:
851 targheight = sec->ceilingheight + P_FindShortestUpperAround(sec->iSectorID);
852 ceiling->topheight = targheight;
853 ceiling->direction = 1;
854 break;
855 default:
856 break;
857 }
858
859 ceiling->tag = tag;
860 ceiling->type = type;
861 ceiling->crush = crush;
862 ceiling->crushmode = crushmode;
863
864 // Don't make noise for instant movement ceilings
865 if (ceiling->direction < 0)
866 {
867 if (ceiling->speed >= sec->ceilingheight - ceiling->bottomheight)
868 if (silent & 4)
869 ceiling->silent = 2;
870 }
871 else
872 {
873 if (ceiling->speed >= ceiling->topheight - sec->ceilingheight)
874 if (silent & 4)
875 ceiling->silent = 2;
876 }
877
878 // set texture/type change properties
879 if (change & 3) // if a texture change is indicated
880 {
881 if (change & 4) // if a numeric model change
882 {
883 sector_t *modelsec;
884
885 // jff 5/23/98 find model with floor at target height if target is a floor type
886 modelsec = (type == ceilRaiseToFloor || type == ceilLowerToFloor) ?
887 P_FindModelFloorSector(targheight, sec->iSectorID) :
888 P_FindModelCeilingSector(targheight, sec->iSectorID);
889
890 if (modelsec != NULL)
891 {
892 ceiling->texture = modelsec->ceilingpic;
893 switch (change & 3)
894 {
895 case 0:
896 break;
897 case 1: // type is zeroed
898 P_ResetTransferSpecial(&ceiling->newspecial);
899 ceiling->type = genCeilingChg0;
900 break;
901 case 2: // type is copied
902 P_CopyTransferSpecial(&ceiling->newspecial, sec);
903 ceiling->type = genCeilingChgT;
904 break;
905 case 3: // type is left alone
906 ceiling->type = genCeilingChg;
907 break;
908 }
909 }
910 }
911 else if (line) // else if a trigger model change
912 {
913 ceiling->texture = line->frontsector->ceilingpic;
914 switch (change & 3)
915 {
916 case 0:
917 break;
918 case 1: // type is zeroed
919 P_ResetTransferSpecial(&ceiling->newspecial);
920 ceiling->type = genCeilingChg0;
921 break;
922 case 2: // type is copied
923 P_CopyTransferSpecial(&ceiling->newspecial, line->frontsector);
924 ceiling->type = genCeilingChgT;
925 break;
926 case 3: // type is left alone
927 ceiling->type = genCeilingChg;
928 break;
929 }
930 }
931 }
932
933 P_AddActiveCeiling(ceiling);
934
935 return;
936 }
937
938 int EV_DoZDoomCeiling(ceiling_e type, line_t *line, int tag, fixed_t speed, fixed_t speed2,
939 fixed_t height, int crush, byte silent, int change, crushmode_e crushmode)
940 {
941 sector_t *sec;
942 const int *id_p;
943 int retcode = 0;
944
945 height *= FRACUNIT;
946
947 // check if a manual trigger, if so do just the sector on the backside
948 if (tag == 0)
949 {
950 int secnum;
951
952 if (!line || !(sec = line->backsector))
953 return 0;
954
955 secnum = sec - sectors;
956 // [RH] Hack to let manual crushers be retriggerable, too
957 tag ^= secnum | 0x1000000;
958 P_ActivateInStasisCeiling(tag);
959
960 if (sec->ceilingdata)
961 return 0;
962
963 P_SpawnZDoomCeiling(sec, type, line, tag, speed, speed2,
964 height, crush, silent, change, crushmode);
965 return 1;
966 }
967
968 // Reactivate in-stasis ceilings...for certain types.
969 // This restarts a crusher after it has been stopped
970 if (type == ceilCrushAndRaise)
971 {
972 P_ActivateInStasisCeiling(tag);
973 }
974
975 FIND_SECTORS(id_p, tag)
976 {
977 sec = &sectors[*id_p];
978 if (sec->ceilingdata)
979 {
980 continue;
981 }
982 retcode = 1;
983 P_SpawnZDoomCeiling(sec, type, line, tag, speed, speed2,
984 height, crush, silent, change, crushmode);
985 }
986
987 return retcode;
988 }
989
990 int Hexen_EV_DoCeiling(line_t * line, byte * arg, ceiling_e type)
991 {
992 const int *id_p;
993 int rtn;
994 sector_t *sec;
995 ceiling_t *ceiling;
996
997 rtn = 0;
998
999 FIND_SECTORS(id_p, arg[0])
1000 {
1001 sec = &sectors[*id_p];
1002 if (sec->floordata || sec->ceilingdata)
1003 continue;
1004
1005 //
1006 // new door thinker
1007 //
1008 rtn = 1;
1009 ceiling = Z_MallocLevel(sizeof(*ceiling));
1010 memset(ceiling, 0, sizeof(*ceiling));
1011 P_AddThinker(&ceiling->thinker);
1012 sec->ceilingdata = ceiling;
1013 ceiling->thinker.function = T_MoveCeiling;
1014 ceiling->sector = sec;
1015 ceiling->crush = NO_CRUSH;
1016 ceiling->speed = arg[1] * (FRACUNIT / 8);
1017 switch (type)
1018 {
1019 case CLEV_CRUSHRAISEANDSTAY:
1020 ceiling->crush = P_ConvertHexenCrush(arg[2]); // arg[2] = crushing value
1021 ceiling->topheight = sec->ceilingheight;
1022 ceiling->bottomheight = sec->floorheight + (8 * FRACUNIT);
1023 ceiling->direction = -1;
1024 break;
1025 case CLEV_CRUSHANDRAISE:
1026 ceiling->topheight = sec->ceilingheight;
1027 case CLEV_LOWERANDCRUSH:
1028 ceiling->crush = P_ConvertHexenCrush(arg[2]); // arg[2] = crushing value
1029 case CLEV_LOWERTOFLOOR:
1030 ceiling->bottomheight = sec->floorheight;
1031 if (type != CLEV_LOWERTOFLOOR)
1032 {
1033 ceiling->bottomheight += 8 * FRACUNIT;
1034 }
1035 ceiling->direction = -1;
1036 break;
1037 case CLEV_RAISETOHIGHEST:
1038 ceiling->topheight = P_FindHighestCeilingSurrounding(sec);
1039 ceiling->direction = 1;
1040 break;
1041 case CLEV_LOWERBYVALUE:
1042 ceiling->bottomheight =
1043 sec->ceilingheight - arg[2] * FRACUNIT;
1044 ceiling->direction = -1;
1045 break;
1046 case CLEV_RAISEBYVALUE:
1047 ceiling->topheight = sec->ceilingheight + arg[2] * FRACUNIT;
1048 ceiling->direction = 1;
1049 break;
1050 case CLEV_MOVETOVALUETIMES8:
1051 {
1052 int destHeight = arg[2] * FRACUNIT * 8;
1053
1054 if (arg[3])
1055 {
1056 destHeight = -destHeight;
1057 }
1058 if (sec->ceilingheight <= destHeight)
1059 {
1060 ceiling->direction = 1;
1061 ceiling->topheight = destHeight;
1062 if (sec->ceilingheight == destHeight)
1063 {
1064 rtn = 0;
1065 }
1066 }
1067 else if (sec->ceilingheight > destHeight)
1068 {
1069 ceiling->direction = -1;
1070 ceiling->bottomheight = destHeight;
1071 }
1072 break;
1073 }
1074 default:
1075 rtn = 0;
1076 break;
1077 }
1078 ceiling->tag = sec->tag;
1079 ceiling->type = type;
1080 P_AddActiveCeiling(ceiling);
1081 if (rtn)
1082 {
1083 SN_StartSequence((mobj_t *) & ceiling->sector->soundorg,
1084 SEQ_PLATFORM + ceiling->sector->seqType);
1085 }
1086 }
1087 return rtn;
1088 }