# Correct the needed linklibs in curl-config also.
[AROS-Contrib.git] / Games / Doom / p_floor.c
blob0251856ab1f03d4a573e0b7e9315469e3b4b8f3a
1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // $Id$
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 //
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
15 // for more details.
17 // $Log$
18 // Revision 1.1 2000/02/29 18:21:04 stegerg
19 // Doom port based on ADoomPPC. Read README.AROS!
22 // DESCRIPTION:
23 // Floor animation: raising stairs.
25 //-----------------------------------------------------------------------------
27 static const char
28 rcsid[] = "$Id$";
31 #include "z_zone.h"
32 #include "doomdef.h"
33 #include "p_local.h"
35 #include "s_sound.h"
37 // State.
38 #include "doomstat.h"
39 #include "r_state.h"
40 // Data.
41 #include "sounds.h"
45 // FLOORS
49 // Move a plane (floor or ceiling) and check for crushing
51 result_e
52 T_MovePlane
53 ( sector_t* sector,
54 fixed_t speed,
55 fixed_t dest,
56 boolean crush,
57 int floorOrCeiling,
58 int direction )
60 boolean flag;
61 fixed_t lastpos;
63 switch(floorOrCeiling)
65 case 0:
66 // FLOOR
67 switch(direction)
69 case -1:
70 // DOWN
71 if (sector->floorheight - speed < dest)
73 lastpos = sector->floorheight;
74 sector->floorheight = dest;
75 flag = P_ChangeSector(sector,crush);
76 if (flag == true)
78 sector->floorheight =lastpos;
79 P_ChangeSector(sector,crush);
80 //return crushed;
82 return pastdest;
84 else
86 lastpos = sector->floorheight;
87 sector->floorheight -= speed;
88 flag = P_ChangeSector(sector,crush);
89 if (flag == true)
91 sector->floorheight = lastpos;
92 P_ChangeSector(sector,crush);
93 return crushed;
96 break;
98 case 1:
99 // UP
100 if (sector->floorheight + speed > dest)
102 lastpos = sector->floorheight;
103 sector->floorheight = dest;
104 flag = P_ChangeSector(sector,crush);
105 if (flag == true)
107 sector->floorheight = lastpos;
108 P_ChangeSector(sector,crush);
109 //return crushed;
111 return pastdest;
113 else
115 // COULD GET CRUSHED
116 lastpos = sector->floorheight;
117 sector->floorheight += speed;
118 flag = P_ChangeSector(sector,crush);
119 if (flag == true)
121 if (crush == true)
122 return crushed;
123 sector->floorheight = lastpos;
124 P_ChangeSector(sector,crush);
125 return crushed;
128 break;
130 break;
132 case 1:
133 // CEILING
134 switch(direction)
136 case -1:
137 // DOWN
138 if (sector->ceilingheight - speed < dest)
140 lastpos = sector->ceilingheight;
141 sector->ceilingheight = dest;
142 flag = P_ChangeSector(sector,crush);
144 if (flag == true)
146 sector->ceilingheight = lastpos;
147 P_ChangeSector(sector,crush);
148 //return crushed;
150 return pastdest;
152 else
154 // COULD GET CRUSHED
155 lastpos = sector->ceilingheight;
156 sector->ceilingheight -= speed;
157 flag = P_ChangeSector(sector,crush);
159 if (flag == true)
161 if (crush == true)
162 return crushed;
163 sector->ceilingheight = lastpos;
164 P_ChangeSector(sector,crush);
165 return crushed;
168 break;
170 case 1:
171 // UP
172 if (sector->ceilingheight + speed > dest)
174 lastpos = sector->ceilingheight;
175 sector->ceilingheight = dest;
176 flag = P_ChangeSector(sector,crush);
177 if (flag == true)
179 sector->ceilingheight = lastpos;
180 P_ChangeSector(sector,crush);
181 //return crushed;
183 return pastdest;
185 else
187 lastpos = sector->ceilingheight;
188 sector->ceilingheight += speed;
189 flag = P_ChangeSector(sector,crush);
190 // UNUSED
191 #if 0
192 if (flag == true)
194 sector->ceilingheight = lastpos;
195 P_ChangeSector(sector,crush);
196 return crushed;
198 #endif
200 break;
202 break;
205 return ok;
210 // MOVE A FLOOR TO IT'S DESTINATION (UP OR DOWN)
212 void T_MoveFloor(floormove_t* floor)
214 result_e res;
216 res = T_MovePlane(floor->sector,
217 floor->speed,
218 floor->floordestheight,
219 floor->crush,0,floor->direction);
221 if (!(leveltime&7))
222 S_StartSound((mobj_t *)&floor->sector->soundorg,
223 sfx_stnmov);
225 if (res == pastdest)
227 floor->sector->specialdata = NULL;
229 if (floor->direction == 1)
231 switch(floor->type)
233 case donutRaise:
234 floor->sector->special = floor->newspecial;
235 floor->sector->floorpic = floor->texture;
236 default:
237 break;
240 else if (floor->direction == -1)
242 switch(floor->type)
244 case lowerAndChange:
245 floor->sector->special = floor->newspecial;
246 floor->sector->floorpic = floor->texture;
247 default:
248 break;
251 P_RemoveThinker(&floor->thinker);
253 S_StartSound((mobj_t *)&floor->sector->soundorg,
254 sfx_pstop);
260 // HANDLE FLOOR TYPES
263 EV_DoFloor
264 ( line_t* line,
265 floor_e floortype )
267 int secnum;
268 int rtn;
269 int i;
270 sector_t* sec;
271 floormove_t* floor;
273 secnum = -1;
274 rtn = 0;
275 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
277 sec = &sectors[secnum];
279 // ALREADY MOVING? IF SO, KEEP GOING...
280 if (sec->specialdata)
281 continue;
283 // new floor thinker
284 rtn = 1;
285 floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
286 P_AddThinker (&floor->thinker);
287 sec->specialdata = floor;
288 floor->thinker.function.acp1 = (actionf_p1) T_MoveFloor;
289 floor->type = floortype;
290 floor->crush = false;
292 switch(floortype)
294 case lowerFloor:
295 floor->direction = -1;
296 floor->sector = sec;
297 floor->speed = FLOORSPEED;
298 floor->floordestheight =
299 P_FindHighestFloorSurrounding(sec);
300 break;
302 case lowerFloorToLowest:
303 floor->direction = -1;
304 floor->sector = sec;
305 floor->speed = FLOORSPEED;
306 floor->floordestheight =
307 P_FindLowestFloorSurrounding(sec);
308 break;
310 case turboLower:
311 floor->direction = -1;
312 floor->sector = sec;
313 floor->speed = FLOORSPEED * 4;
314 floor->floordestheight =
315 P_FindHighestFloorSurrounding(sec);
316 if (floor->floordestheight != sec->floorheight)
317 floor->floordestheight += 8*FRACUNIT;
318 break;
320 case raiseFloorCrush:
321 floor->crush = true;
322 case raiseFloor:
323 floor->direction = 1;
324 floor->sector = sec;
325 floor->speed = FLOORSPEED;
326 floor->floordestheight =
327 P_FindLowestCeilingSurrounding(sec);
328 if (floor->floordestheight > sec->ceilingheight)
329 floor->floordestheight = sec->ceilingheight;
330 floor->floordestheight -= (8*FRACUNIT)*
331 (floortype == raiseFloorCrush);
332 break;
334 case raiseFloorTurbo:
335 floor->direction = 1;
336 floor->sector = sec;
337 floor->speed = FLOORSPEED*4;
338 floor->floordestheight =
339 P_FindNextHighestFloor(sec,sec->floorheight);
340 break;
342 case raiseFloorToNearest:
343 floor->direction = 1;
344 floor->sector = sec;
345 floor->speed = FLOORSPEED;
346 floor->floordestheight =
347 P_FindNextHighestFloor(sec,sec->floorheight);
348 break;
350 case raiseFloor24:
351 floor->direction = 1;
352 floor->sector = sec;
353 floor->speed = FLOORSPEED;
354 floor->floordestheight = floor->sector->floorheight +
355 24 * FRACUNIT;
356 break;
357 case raiseFloor512:
358 floor->direction = 1;
359 floor->sector = sec;
360 floor->speed = FLOORSPEED;
361 floor->floordestheight = floor->sector->floorheight +
362 512 * FRACUNIT;
363 break;
365 case raiseFloor24AndChange:
366 floor->direction = 1;
367 floor->sector = sec;
368 floor->speed = FLOORSPEED;
369 floor->floordestheight = floor->sector->floorheight +
370 24 * FRACUNIT;
371 sec->floorpic = line->frontsector->floorpic;
372 sec->special = line->frontsector->special;
373 break;
375 case raiseToTexture:
377 int minsize = MAXINT;
378 side_t* side;
380 floor->direction = 1;
381 floor->sector = sec;
382 floor->speed = FLOORSPEED;
383 for (i = 0; i < sec->linecount; i++)
385 if (twoSided (secnum, i) )
387 side = getSide(secnum,i,0);
388 if (side->bottomtexture >= 0)
389 if (textureheight[side->bottomtexture] <
390 minsize)
391 minsize =
392 textureheight[side->bottomtexture];
393 side = getSide(secnum,i,1);
394 if (side->bottomtexture >= 0)
395 if (textureheight[side->bottomtexture] <
396 minsize)
397 minsize =
398 textureheight[side->bottomtexture];
401 floor->floordestheight =
402 floor->sector->floorheight + minsize;
404 break;
406 case lowerAndChange:
407 floor->direction = -1;
408 floor->sector = sec;
409 floor->speed = FLOORSPEED;
410 floor->floordestheight =
411 P_FindLowestFloorSurrounding(sec);
412 floor->texture = sec->floorpic;
414 for (i = 0; i < sec->linecount; i++)
416 if ( twoSided(secnum, i) )
418 if (getSide(secnum,i,0)->sector-sectors == secnum)
420 sec = getSector(secnum,i,1);
422 if (sec->floorheight == floor->floordestheight)
424 floor->texture = sec->floorpic;
425 floor->newspecial = sec->special;
426 break;
429 else
431 sec = getSector(secnum,i,0);
433 if (sec->floorheight == floor->floordestheight)
435 floor->texture = sec->floorpic;
436 floor->newspecial = sec->special;
437 break;
442 default:
443 break;
446 return rtn;
453 // BUILD A STAIRCASE!
456 EV_BuildStairs
457 ( line_t* line,
458 stair_e type )
460 int secnum;
461 int height;
462 int i;
463 int newsecnum;
464 int texture;
465 int ok;
466 int rtn;
468 sector_t* sec;
469 sector_t* tsec;
471 floormove_t* floor;
473 fixed_t stairsize = 0;
474 fixed_t speed = 0;
476 secnum = -1;
477 rtn = 0;
478 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
480 sec = &sectors[secnum];
482 // ALREADY MOVING? IF SO, KEEP GOING...
483 if (sec->specialdata)
484 continue;
486 // new floor thinker
487 rtn = 1;
488 floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
489 P_AddThinker (&floor->thinker);
490 sec->specialdata = floor;
491 floor->thinker.function.acp1 = (actionf_p1) T_MoveFloor;
492 floor->direction = 1;
493 floor->sector = sec;
494 switch(type)
496 case build8:
497 speed = FLOORSPEED/4;
498 stairsize = 8*FRACUNIT;
499 break;
500 case turbo16:
501 speed = FLOORSPEED*4;
502 stairsize = 16*FRACUNIT;
503 break;
505 floor->speed = speed;
506 height = sec->floorheight + stairsize;
507 floor->floordestheight = height;
509 texture = sec->floorpic;
511 // Find next sector to raise
512 // 1. Find 2-sided line with same sector side[0]
513 // 2. Other side is the next sector to raise
516 ok = 0;
517 for (i = 0;i < sec->linecount;i++)
519 if ( !((sec->lines[i])->flags & ML_TWOSIDED) )
520 continue;
522 tsec = (sec->lines[i])->frontsector;
523 newsecnum = tsec-sectors;
525 if (secnum != newsecnum)
526 continue;
528 tsec = (sec->lines[i])->backsector;
529 newsecnum = tsec - sectors;
531 if (tsec->floorpic != texture)
532 continue;
534 height += stairsize;
536 if (tsec->specialdata)
537 continue;
539 sec = tsec;
540 secnum = newsecnum;
541 floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
543 P_AddThinker (&floor->thinker);
545 sec->specialdata = floor;
546 floor->thinker.function.acp1 = (actionf_p1) T_MoveFloor;
547 floor->direction = 1;
548 floor->sector = sec;
549 floor->speed = speed;
550 floor->floordestheight = height;
551 ok = 1;
552 break;
554 } while(ok);
556 return rtn;