1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
6 // Copyright (C) 1993-1996 by id Software, Inc.
8 // This source is available for distribution and/or modification
9 // only under the terms of the DOOM Source Code License as
10 // published by id Software. All rights reserved.
12 // The source is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
19 // DESCRIPTION: Ceiling aninmation (lowering, crushing, raising)
21 //-----------------------------------------------------------------------------
24 rcsid[] = "$Id: p_ceilng.c,v 1.4 1997/02/03 16:47:53 b1 Exp $";
45 ceiling_t* activeceilings[MAXCEILINGS];
52 void T_MoveCeiling (void *_ceiling, void*)
54 ceiling_t *ceiling = (ceiling_t *)_ceiling;
57 switch(ceiling->direction)
64 res = T_MovePlane(ceiling->sector,
67 false,1,ceiling->direction);
73 case silentCrushAndRaise:
76 S_StartSound((mobj_t *)&ceiling->sector->soundorg,
88 P_RemoveActiveCeiling(ceiling);
91 case silentCrushAndRaise:
92 S_StartSound((mobj_t *)&ceiling->sector->soundorg,
94 case fastCrushAndRaise:
96 ceiling->direction = -1;
108 res = T_MovePlane(ceiling->sector,
110 ceiling->bottomheight,
111 ceiling->crush,1,ceiling->direction);
115 switch(ceiling->type)
117 case silentCrushAndRaise: break;
119 S_StartSound((mobj_t *)&ceiling->sector->soundorg,
126 switch(ceiling->type)
128 case silentCrushAndRaise:
129 S_StartSound((mobj_t *)&ceiling->sector->soundorg,
132 ceiling->speed = CEILSPEED;
133 case fastCrushAndRaise:
134 ceiling->direction = 1;
139 P_RemoveActiveCeiling(ceiling);
146 else // ( res != pastdest )
150 switch(ceiling->type)
152 case silentCrushAndRaise:
155 ceiling->speed = CEILSPEED / 8;
170 // Move a ceiling up/down and all around!
185 // Reactivate in-stasis ceilings...for certain types.
188 case fastCrushAndRaise:
189 case silentCrushAndRaise:
191 P_ActivateInStasisCeiling(line);
196 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
198 sec = §ors[secnum];
199 if (sec->specialdata)
204 ceiling = Z_Malloc (sizeof(*ceiling), PU_LEVSPEC, 0);
205 P_AddThinker (&ceiling->thinker);
206 sec->specialdata = ceiling;
207 ceiling->thinker.function = T_MoveCeiling;
208 ceiling->sector = sec;
209 ceiling->crush = false;
213 case fastCrushAndRaise:
214 ceiling->crush = true;
215 ceiling->topheight = sec->ceilingheight;
216 ceiling->bottomheight = sec->floorheight + (8*FRACUNIT);
217 ceiling->direction = -1;
218 ceiling->speed = CEILSPEED * 2;
221 case silentCrushAndRaise:
223 ceiling->crush = true;
224 ceiling->topheight = sec->ceilingheight;
227 ceiling->bottomheight = sec->floorheight;
228 if (type != lowerToFloor)
229 ceiling->bottomheight += 8*FRACUNIT;
230 ceiling->direction = -1;
231 ceiling->speed = CEILSPEED;
235 ceiling->topheight = P_FindHighestCeilingSurrounding(sec);
236 ceiling->direction = 1;
237 ceiling->speed = CEILSPEED;
241 ceiling->tag = sec->tag;
242 ceiling->type = type;
243 P_AddActiveCeiling(ceiling);
250 // Add an active ceiling
252 void P_AddActiveCeiling(ceiling_t* c)
256 for (i = 0; i < MAXCEILINGS;i++)
258 if (activeceilings[i] == NULL)
260 activeceilings[i] = c;
269 // Remove a ceiling's thinker
271 void P_RemoveActiveCeiling(ceiling_t* c)
275 for (i = 0;i < MAXCEILINGS;i++)
277 if (activeceilings[i] == c)
279 activeceilings[i]->sector->specialdata = NULL;
280 P_RemoveThinker (&activeceilings[i]->thinker);
281 activeceilings[i] = NULL;
290 // Restart a ceiling that's in-stasis
292 void P_ActivateInStasisCeiling(line_t* line)
296 for (i = 0;i < MAXCEILINGS;i++)
298 if (activeceilings[i]
299 && (activeceilings[i]->tag == line->tag)
300 && (activeceilings[i]->direction == 0))
302 activeceilings[i]->direction = activeceilings[i]->olddirection;
303 activeceilings[i]->thinker.function = T_MoveCeiling;
311 // EV_CeilingCrushStop
312 // Stop a ceiling from crushing!
314 int EV_CeilingCrushStop(line_t *line)
320 for (i = 0;i < MAXCEILINGS;i++)
322 if (activeceilings[i]
323 && (activeceilings[i]->tag == line->tag)
324 && (activeceilings[i]->direction != 0))
326 activeceilings[i]->olddirection = activeceilings[i]->direction;
327 activeceilings[i]->thinker.function = (actionf_t)NULL;
328 activeceilings[i]->direction = 0; // in-stasis