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
20 // Floor animation: raising stairs.
22 //-----------------------------------------------------------------------------
25 rcsid[] = "$Id: p_floor.c,v 1.4 1997/02/03 16:47:54 b1 Exp $";
46 // Move a plane (floor or ceiling) and check for crushing
60 switch(floorOrCeiling)
68 if (sector->floorheight - speed < dest)
70 lastpos = sector->floorheight;
71 sector->floorheight = dest;
72 flag = P_ChangeSector(sector,crush);
75 sector->floorheight =lastpos;
76 P_ChangeSector(sector,crush);
83 lastpos = sector->floorheight;
84 sector->floorheight -= speed;
85 flag = P_ChangeSector(sector,crush);
88 sector->floorheight = lastpos;
89 P_ChangeSector(sector,crush);
97 if (sector->floorheight + speed > dest)
99 lastpos = sector->floorheight;
100 sector->floorheight = dest;
101 flag = P_ChangeSector(sector,crush);
104 sector->floorheight = lastpos;
105 P_ChangeSector(sector,crush);
113 lastpos = sector->floorheight;
114 sector->floorheight += speed;
115 flag = P_ChangeSector(sector,crush);
120 sector->floorheight = lastpos;
121 P_ChangeSector(sector,crush);
135 if (sector->ceilingheight - speed < dest)
137 lastpos = sector->ceilingheight;
138 sector->ceilingheight = dest;
139 flag = P_ChangeSector(sector,crush);
143 sector->ceilingheight = lastpos;
144 P_ChangeSector(sector,crush);
152 lastpos = sector->ceilingheight;
153 sector->ceilingheight -= speed;
154 flag = P_ChangeSector(sector,crush);
160 sector->ceilingheight = lastpos;
161 P_ChangeSector(sector,crush);
169 if (sector->ceilingheight + speed > dest)
171 lastpos = sector->ceilingheight;
172 sector->ceilingheight = dest;
173 flag = P_ChangeSector(sector,crush);
176 sector->ceilingheight = lastpos;
177 P_ChangeSector(sector,crush);
184 sector->ceilingheight += speed;
185 P_ChangeSector(sector,crush);
197 // MOVE A FLOOR TO IT'S DESTINATION (UP OR DOWN)
199 void T_MoveFloor(void* _floor, void*)
201 floormove_t *floor = (floormove_t*)_floor;
204 res = T_MovePlane(floor->sector,
206 floor->floordestheight,
207 floor->crush,0,floor->direction);
210 S_StartSound((mobj_t *)&floor->sector->soundorg,
215 floor->sector->specialdata = NULL;
217 if (floor->direction == 1)
222 floor->sector->special = floor->newspecial;
223 floor->sector->floorpic = floor->texture;
228 else if (floor->direction == -1)
233 floor->sector->special = floor->newspecial;
234 floor->sector->floorpic = floor->texture;
239 P_RemoveThinker(&floor->thinker);
241 S_StartSound((mobj_t *)&floor->sector->soundorg,
248 // HANDLE FLOOR TYPES
263 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
265 sec = §ors[secnum];
267 // ALREADY MOVING? IF SO, KEEP GOING...
268 if (sec->specialdata)
273 floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
274 P_AddThinker (&floor->thinker);
275 sec->specialdata = floor;
276 floor->thinker.function = T_MoveFloor;
277 floor->type = floortype;
278 floor->crush = false;
283 floor->direction = -1;
285 floor->speed = FLOORSPEED;
286 floor->floordestheight =
287 P_FindHighestFloorSurrounding(sec);
290 case lowerFloorToLowest:
291 floor->direction = -1;
293 floor->speed = FLOORSPEED;
294 floor->floordestheight =
295 P_FindLowestFloorSurrounding(sec);
299 floor->direction = -1;
301 floor->speed = FLOORSPEED * 4;
302 floor->floordestheight =
303 P_FindHighestFloorSurrounding(sec);
304 if (floor->floordestheight != sec->floorheight)
305 floor->floordestheight += 8*FRACUNIT;
308 case raiseFloorCrush:
311 floor->direction = 1;
313 floor->speed = FLOORSPEED;
314 floor->floordestheight =
315 P_FindLowestCeilingSurrounding(sec);
316 if (floor->floordestheight > sec->ceilingheight)
317 floor->floordestheight = sec->ceilingheight;
318 floor->floordestheight -= (8*FRACUNIT)*
319 (floortype == raiseFloorCrush);
322 case raiseFloorTurbo:
323 floor->direction = 1;
325 floor->speed = FLOORSPEED*4;
326 floor->floordestheight =
327 P_FindNextHighestFloor(sec,sec->floorheight);
330 case raiseFloorToNearest:
331 floor->direction = 1;
333 floor->speed = FLOORSPEED;
334 floor->floordestheight =
335 P_FindNextHighestFloor(sec,sec->floorheight);
339 floor->direction = 1;
341 floor->speed = FLOORSPEED;
342 floor->floordestheight = floor->sector->floorheight +
346 floor->direction = 1;
348 floor->speed = FLOORSPEED;
349 floor->floordestheight = floor->sector->floorheight +
353 case raiseFloor24AndChange:
354 floor->direction = 1;
356 floor->speed = FLOORSPEED;
357 floor->floordestheight = floor->sector->floorheight +
359 sec->floorpic = line->frontsector->floorpic;
360 sec->special = line->frontsector->special;
365 int minsize = MAXINT;
368 floor->direction = 1;
370 floor->speed = FLOORSPEED;
371 for (i = 0; i < sec->linecount; i++)
373 if (twoSided (secnum, i) )
375 side = getSide(secnum,i,0);
376 if (side->bottomtexture >= 0)
377 if (textureheight[side->bottomtexture] <
380 textureheight[side->bottomtexture];
381 side = getSide(secnum,i,1);
382 if (side->bottomtexture >= 0)
383 if (textureheight[side->bottomtexture] <
386 textureheight[side->bottomtexture];
389 floor->floordestheight =
390 floor->sector->floorheight + minsize;
395 floor->direction = -1;
397 floor->speed = FLOORSPEED;
398 floor->floordestheight =
399 P_FindLowestFloorSurrounding(sec);
400 floor->texture = sec->floorpic;
402 for (i = 0; i < sec->linecount; i++)
404 if ( twoSided(secnum, i) )
406 if (getSide(secnum,i,0)->sector-sectors == secnum)
408 sec = getSector(secnum,i,1);
410 if (sec->floorheight == floor->floordestheight)
412 floor->texture = sec->floorpic;
413 floor->newspecial = sec->special;
419 sec = getSector(secnum,i,0);
421 if (sec->floorheight == floor->floordestheight)
423 floor->texture = sec->floorpic;
424 floor->newspecial = sec->special;
441 // BUILD A STAIRCASE!
466 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
468 sec = §ors[secnum];
470 // ALREADY MOVING? IF SO, KEEP GOING...
471 if (sec->specialdata)
476 floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
477 P_AddThinker (&floor->thinker);
478 sec->specialdata = floor;
479 floor->thinker.function = T_MoveFloor;
480 floor->direction = 1;
486 speed = FLOORSPEED/4;
487 stairsize = 8*FRACUNIT;
490 speed = FLOORSPEED*4;
491 stairsize = 16*FRACUNIT;
494 floor->speed = speed;
495 height = sec->floorheight + stairsize;
496 floor->floordestheight = height;
498 texture = sec->floorpic;
500 // Find next sector to raise
501 // 1. Find 2-sided line with same sector side[0]
502 // 2. Other side is the next sector to raise
506 for (i = 0;i < sec->linecount;i++)
508 if ( !((sec->lines[i])->flags & ML_TWOSIDED) )
511 tsec = (sec->lines[i])->frontsector;
512 newsecnum = tsec-sectors;
514 if (secnum != newsecnum)
517 tsec = (sec->lines[i])->backsector;
518 newsecnum = tsec - sectors;
520 if (tsec->floorpic != texture)
525 if (tsec->specialdata)
530 floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
532 P_AddThinker (&floor->thinker);
534 sec->specialdata = floor;
535 floor->thinker.function = T_MoveFloor;
536 floor->direction = 1;
538 floor->speed = speed;
539 floor->floordestheight = height;