5 //==================================================================
6 //==================================================================
10 //==================================================================
11 //==================================================================
15 //==================================================================
17 // Move a plane (floor or ceiling) and check for crushing
19 //==================================================================
20 result_e T_MovePlane(sector_t *sector,fixed_t speed,
21 fixed_t dest,boolean crush,int floorOrCeiling,int direction)
26 switch(floorOrCeiling)
32 if (sector->floorheight - speed < dest)
34 lastpos = sector->floorheight;
35 sector->floorheight = dest;
36 flag = P_ChangeSector(sector,crush);
39 sector->floorheight =lastpos;
40 P_ChangeSector(sector,crush);
47 lastpos = sector->floorheight;
48 sector->floorheight -= speed;
49 flag = P_ChangeSector(sector,crush);
52 sector->floorheight = lastpos;
53 P_ChangeSector(sector,crush);
60 if (sector->floorheight + speed > dest)
62 lastpos = sector->floorheight;
63 sector->floorheight = dest;
64 flag = P_ChangeSector(sector,crush);
67 sector->floorheight = lastpos;
68 P_ChangeSector(sector,crush);
73 else // COULD GET CRUSHED
75 lastpos = sector->floorheight;
76 sector->floorheight += speed;
77 flag = P_ChangeSector(sector,crush);
82 sector->floorheight = lastpos;
83 P_ChangeSector(sector,crush);
95 if (sector->ceilingheight - speed < dest)
97 lastpos = sector->ceilingheight;
98 sector->ceilingheight = dest;
99 flag = P_ChangeSector(sector,crush);
102 sector->ceilingheight = lastpos;
103 P_ChangeSector(sector,crush);
108 else // COULD GET CRUSHED
110 lastpos = sector->ceilingheight;
111 sector->ceilingheight -= speed;
112 flag = P_ChangeSector(sector,crush);
117 sector->ceilingheight = lastpos;
118 P_ChangeSector(sector,crush);
125 if (sector->ceilingheight + speed > dest)
127 lastpos = sector->ceilingheight;
128 sector->ceilingheight = dest;
129 flag = P_ChangeSector(sector,crush);
132 sector->ceilingheight = lastpos;
133 P_ChangeSector(sector,crush);
140 lastpos = sector->ceilingheight;
141 sector->ceilingheight += speed;
142 flag = P_ChangeSector(sector,crush);
146 sector->ceilingheight = lastpos;
147 P_ChangeSector(sector,crush);
160 //==================================================================
162 // MOVE A FLOOR TO IT'S DESTINATION (UP OR DOWN)
164 //==================================================================
165 void T_MoveFloor(floormove_t *floor)
169 res = T_MovePlane(floor->sector,floor->speed,
170 floor->floordestheight,floor->crush,0,floor->direction);
173 S_StartSound((mobj_t *)&floor->sector->soundorg, sfx_dormov);
178 floor->sector->specialdata = NULL;
179 if(floor->type == raiseBuildStep)
181 S_StartSound((mobj_t *)&floor->sector->soundorg, sfx_pstop);
183 if (floor->direction == 1)
187 floor->sector->special = floor->newspecial;
188 floor->sector->floorpic = floor->texture;
192 else if (floor->direction == -1)
196 floor->sector->special = floor->newspecial;
197 floor->sector->floorpic = floor->texture;
201 P_RemoveThinker(&floor->thinker);
206 //==================================================================
208 // HANDLE FLOOR TYPES
210 //==================================================================
211 int EV_DoFloor(line_t *line,floor_e floortype)
221 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
223 sec = §ors[secnum];
225 // ALREADY MOVING? IF SO, KEEP GOING...
226 if (sec->specialdata)
233 floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
234 P_AddThinker (&floor->thinker);
235 sec->specialdata = floor;
236 floor->thinker.function = T_MoveFloor;
237 floor->type = floortype;
238 floor->crush = false;
242 floor->direction = -1;
244 floor->speed = FLOORSPEED;
245 floor->floordestheight =
246 P_FindHighestFloorSurrounding(sec);
248 case lowerFloorToLowest:
249 floor->direction = -1;
251 floor->speed = FLOORSPEED;
252 floor->floordestheight =
253 P_FindLowestFloorSurrounding(sec);
256 floor->direction = -1;
258 floor->speed = FLOORSPEED * 4;
259 floor->floordestheight = (8*FRACUNIT) +
260 P_FindHighestFloorSurrounding(sec);
262 case raiseFloorCrush:
265 floor->direction = 1;
267 floor->speed = FLOORSPEED;
268 floor->floordestheight =
269 P_FindLowestCeilingSurrounding(sec);
270 if (floor->floordestheight > sec->ceilingheight)
271 floor->floordestheight = sec->ceilingheight;
272 floor->floordestheight -= (8*FRACUNIT)*
273 (floortype == raiseFloorCrush);
275 case raiseFloorToNearest:
276 floor->direction = 1;
278 floor->speed = FLOORSPEED;
279 floor->floordestheight =
280 P_FindNextHighestFloor(sec,sec->floorheight);
283 floor->direction = 1;
285 floor->speed = FLOORSPEED;
286 floor->floordestheight = floor->sector->floorheight +
289 case raiseFloor24AndChange:
290 floor->direction = 1;
292 floor->speed = FLOORSPEED;
293 floor->floordestheight = floor->sector->floorheight +
295 sec->floorpic = line->frontsector->floorpic;
296 sec->special = line->frontsector->special;
300 int minsize = MAXINT;
303 floor->direction = 1;
305 floor->speed = FLOORSPEED;
306 for (i = 0; i < sec->linecount; i++)
307 if (twoSided (secnum, i) )
309 side = getSide(secnum,i,0);
310 if (side->bottomtexture >= 0)
311 if (textureheight[side->bottomtexture] <
314 textureheight[side->bottomtexture];
315 side = getSide(secnum,i,1);
316 if (side->bottomtexture >= 0)
317 if (textureheight[side->bottomtexture] <
320 textureheight[side->bottomtexture];
322 floor->floordestheight = floor->sector->floorheight +
327 floor->direction = -1;
329 floor->speed = FLOORSPEED;
330 floor->floordestheight =
331 P_FindLowestFloorSurrounding(sec);
332 floor->texture = sec->floorpic;
333 for (i = 0; i < sec->linecount; i++)
334 if ( twoSided(secnum, i) )
336 if (getSide(secnum,i,0)->sector-sectors == secnum)
338 sec = getSector(secnum,i,1);
339 floor->texture = sec->floorpic;
340 floor->newspecial = sec->special;
345 sec = getSector(secnum,i,0);
346 floor->texture = sec->floorpic;
347 floor->newspecial = sec->special;
358 //==================================================================
360 // BUILD A STAIRCASE!
362 //==================================================================
363 int EV_BuildStairs(line_t *line, fixed_t stepDelta)
372 sector_t *sec, *tsec;
377 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
379 sec = §ors[secnum];
381 // ALREADY MOVING? IF SO, KEEP GOING...
382 if (sec->specialdata)
389 height = sec->floorheight+stepDelta;
390 floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
391 P_AddThinker (&floor->thinker);
392 sec->specialdata = floor;
393 floor->thinker.function = T_MoveFloor;
394 floor->type = raiseBuildStep;
395 floor->direction = 1;
397 floor->speed = FLOORSPEED;
398 floor->floordestheight = height;
400 texture = sec->floorpic;
403 // Find next sector to raise
404 // 1. Find 2-sided line with same sector side[0]
405 // 2. Other side is the next sector to raise
410 for (i = 0;i < sec->linecount;i++)
412 if ( !((sec->lines[i])->flags & ML_TWOSIDED) )
415 tsec = (sec->lines[i])->frontsector;
416 newsecnum = tsec-sectors;
417 if (secnum != newsecnum)
419 tsec = (sec->lines[i])->backsector;
420 newsecnum = tsec - sectors;
421 if (tsec->floorpic != texture)
425 if (tsec->specialdata)
430 floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
431 P_AddThinker (&floor->thinker);
432 sec->specialdata = floor;
433 floor->thinker.function = T_MoveFloor;
434 floor->type = raiseBuildStep;
435 floor->direction = 1;
437 floor->speed = FLOORSPEED;
438 floor->floordestheight = height;