p_doors.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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.
  11. //
  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.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION: Door animation code (opening/closing)
  20. //
  21. //-----------------------------------------------------------------------------
  22. static const char
  23. rcsid[] = "$Id: p_doors.c,v 1.4 1997/02/03 16:47:53 b1 Exp $";
  24. #include "z_zone.h"
  25. #include "doomdef.h"
  26. #include "p_local.h"
  27. #include "s_sound.h"
  28. // State.
  29. #include "doomstat.h"
  30. #include "r_state.h"
  31. // Data.
  32. #include "dstrings.h"
  33. #include "sounds.h"
  34. #if 0
  35. //
  36. // Sliding door frame information
  37. //
  38. slidename_t slideFrameNames[MAXSLIDEDOORS] =
  39. {
  40. {"GDOORF1","GDOORF2","GDOORF3","GDOORF4", // front
  41. "GDOORB1","GDOORB2","GDOORB3","GDOORB4"}, // back
  42. {"\0","\0","\0","\0"}
  43. };
  44. #endif
  45. //
  46. // VERTICAL DOORS
  47. //
  48. //
  49. // T_VerticalDoor
  50. //
  51. void T_VerticalDoor (vldoor_t* door)
  52. {
  53. result_e res;
  54. switch(door->direction)
  55. {
  56. case 0:
  57. // WAITING
  58. if (!--door->topcountdown)
  59. {
  60. switch(door->type)
  61. {
  62. case blazeRaise:
  63. door->direction = -1; // time to go back down
  64. S_StartSound((mobj_t *)&door->sector->soundorg,
  65. sfx_bdcls);
  66. break;
  67. case normal:
  68. door->direction = -1; // time to go back down
  69. S_StartSound((mobj_t *)&door->sector->soundorg,
  70. sfx_dorcls);
  71. break;
  72. case close30ThenOpen:
  73. door->direction = 1;
  74. S_StartSound((mobj_t *)&door->sector->soundorg,
  75. sfx_doropn);
  76. break;
  77. default:
  78. break;
  79. }
  80. }
  81. break;
  82. case 2:
  83. // INITIAL WAIT
  84. if (!--door->topcountdown)
  85. {
  86. switch(door->type)
  87. {
  88. case raiseIn5Mins:
  89. door->direction = 1;
  90. door->type = normal;
  91. S_StartSound((mobj_t *)&door->sector->soundorg,
  92. sfx_doropn);
  93. break;
  94. default:
  95. break;
  96. }
  97. }
  98. break;
  99. case -1:
  100. // DOWN
  101. res = T_MovePlane(door->sector,
  102. door->speed,
  103. door->sector->floorheight,
  104. false,1,door->direction);
  105. if (res == pastdest)
  106. {
  107. switch(door->type)
  108. {
  109. case blazeRaise:
  110. case blazeClose:
  111. door->sector->specialdata = NULL;
  112. P_RemoveThinker (&door->thinker); // unlink and free
  113. S_StartSound((mobj_t *)&door->sector->soundorg,
  114. sfx_bdcls);
  115. break;
  116. case normal:
  117. case close:
  118. door->sector->specialdata = NULL;
  119. P_RemoveThinker (&door->thinker); // unlink and free
  120. break;
  121. case close30ThenOpen:
  122. door->direction = 0;
  123. door->topcountdown = 35*30;
  124. break;
  125. default:
  126. break;
  127. }
  128. }
  129. else if (res == crushed)
  130. {
  131. switch(door->type)
  132. {
  133. case blazeClose:
  134. case close: // DO NOT GO BACK UP!
  135. break;
  136. default:
  137. door->direction = 1;
  138. S_StartSound((mobj_t *)&door->sector->soundorg,
  139. sfx_doropn);
  140. break;
  141. }
  142. }
  143. break;
  144. case 1:
  145. // UP
  146. res = T_MovePlane(door->sector,
  147. door->speed,
  148. door->topheight,
  149. false,1,door->direction);
  150. if (res == pastdest)
  151. {
  152. switch(door->type)
  153. {
  154. case blazeRaise:
  155. case normal:
  156. door->direction = 0; // wait at top
  157. door->topcountdown = door->topwait;
  158. break;
  159. case close30ThenOpen:
  160. case blazeOpen:
  161. case open:
  162. door->sector->specialdata = NULL;
  163. P_RemoveThinker (&door->thinker); // unlink and free
  164. break;
  165. default:
  166. break;
  167. }
  168. }
  169. break;
  170. }
  171. }
  172. //
  173. // EV_DoLockedDoor
  174. // Move a locked door up/down
  175. //
  176. int
  177. EV_DoLockedDoor
  178. ( line_t* line,
  179. vldoor_e type,
  180. mobj_t* thing )
  181. {
  182. player_t* p;
  183. p = thing->player;
  184. if (!p)
  185. return 0;
  186. switch(line->special)
  187. {
  188. case 99: // Blue Lock
  189. case 133:
  190. if ( !p )
  191. return 0;
  192. if (!p->cards[it_bluecard] && !p->cards[it_blueskull])
  193. {
  194. p->message = PD_BLUEO;
  195. S_StartSound(NULL,sfx_oof);
  196. return 0;
  197. }
  198. break;
  199. case 134: // Red Lock
  200. case 135:
  201. if ( !p )
  202. return 0;
  203. if (!p->cards[it_redcard] && !p->cards[it_redskull])
  204. {
  205. p->message = PD_REDO;
  206. S_StartSound(NULL,sfx_oof);
  207. return 0;
  208. }
  209. break;
  210. case 136: // Yellow Lock
  211. case 137:
  212. if ( !p )
  213. return 0;
  214. if (!p->cards[it_yellowcard] &&
  215. !p->cards[it_yellowskull])
  216. {
  217. p->message = PD_YELLOWO;
  218. S_StartSound(NULL,sfx_oof);
  219. return 0;
  220. }
  221. break;
  222. }
  223. return EV_DoDoor(line,type);
  224. }
  225. int
  226. EV_DoDoor
  227. ( line_t* line,
  228. vldoor_e type )
  229. {
  230. int secnum,rtn;
  231. sector_t* sec;
  232. vldoor_t* door;
  233. secnum = -1;
  234. rtn = 0;
  235. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  236. {
  237. sec = &sectors[secnum];
  238. if (sec->specialdata)
  239. continue;
  240. // new door thinker
  241. rtn = 1;
  242. door = Z_Malloc (sizeof(*door), PU_LEVSPEC, 0);
  243. P_AddThinker (&door->thinker);
  244. sec->specialdata = door;
  245. door->thinker.function.acp1 = (actionf_p1) T_VerticalDoor;
  246. door->sector = sec;
  247. door->type = type;
  248. door->topwait = VDOORWAIT;
  249. door->speed = VDOORSPEED;
  250. switch(type)
  251. {
  252. case blazeClose:
  253. door->topheight = P_FindLowestCeilingSurrounding(sec);
  254. door->topheight -= 4*FRACUNIT;
  255. door->direction = -1;
  256. door->speed = VDOORSPEED * 4;
  257. S_StartSound((mobj_t *)&door->sector->soundorg,
  258. sfx_bdcls);
  259. break;
  260. case close:
  261. door->topheight = P_FindLowestCeilingSurrounding(sec);
  262. door->topheight -= 4*FRACUNIT;
  263. door->direction = -1;
  264. S_StartSound((mobj_t *)&door->sector->soundorg,
  265. sfx_dorcls);
  266. break;
  267. case close30ThenOpen:
  268. door->topheight = sec->ceilingheight;
  269. door->direction = -1;
  270. S_StartSound((mobj_t *)&door->sector->soundorg,
  271. sfx_dorcls);
  272. break;
  273. case blazeRaise:
  274. case blazeOpen:
  275. door->direction = 1;
  276. door->topheight = P_FindLowestCeilingSurrounding(sec);
  277. door->topheight -= 4*FRACUNIT;
  278. door->speed = VDOORSPEED * 4;
  279. if (door->topheight != sec->ceilingheight)
  280. S_StartSound((mobj_t *)&door->sector->soundorg,
  281. sfx_bdopn);
  282. break;
  283. case normal:
  284. case open:
  285. door->direction = 1;
  286. door->topheight = P_FindLowestCeilingSurrounding(sec);
  287. door->topheight -= 4*FRACUNIT;
  288. if (door->topheight != sec->ceilingheight)
  289. S_StartSound((mobj_t *)&door->sector->soundorg,
  290. sfx_doropn);
  291. break;
  292. default:
  293. break;
  294. }
  295. }
  296. return rtn;
  297. }
  298. //
  299. // EV_VerticalDoor : open a door manually, no tag value
  300. //
  301. void
  302. EV_VerticalDoor
  303. ( line_t* line,
  304. mobj_t* thing )
  305. {
  306. player_t* player;
  307. int secnum;
  308. sector_t* sec;
  309. vldoor_t* door;
  310. int side;
  311. side = 0; // only front sides can be used
  312. // Check for locks
  313. player = thing->player;
  314. switch(line->special)
  315. {
  316. case 26: // Blue Lock
  317. case 32:
  318. if ( !player )
  319. return;
  320. if (!player->cards[it_bluecard] && !player->cards[it_blueskull])
  321. {
  322. player->message = PD_BLUEK;
  323. S_StartSound(NULL,sfx_oof);
  324. return;
  325. }
  326. break;
  327. case 27: // Yellow Lock
  328. case 34:
  329. if ( !player )
  330. return;
  331. if (!player->cards[it_yellowcard] &&
  332. !player->cards[it_yellowskull])
  333. {
  334. player->message = PD_YELLOWK;
  335. S_StartSound(NULL,sfx_oof);
  336. return;
  337. }
  338. break;
  339. case 28: // Red Lock
  340. case 33:
  341. if ( !player )
  342. return;
  343. if (!player->cards[it_redcard] && !player->cards[it_redskull])
  344. {
  345. player->message = PD_REDK;
  346. S_StartSound(NULL,sfx_oof);
  347. return;
  348. }
  349. break;
  350. }
  351. // if the sector has an active thinker, use it
  352. sec = sides[ line->sidenum[side^1]] .sector;
  353. secnum = sec-sectors;
  354. if (sec->specialdata)
  355. {
  356. door = sec->specialdata;
  357. switch(line->special)
  358. {
  359. case 1: // ONLY FOR "RAISE" DOORS, NOT "OPEN"s
  360. case 26:
  361. case 27:
  362. case 28:
  363. case 117:
  364. if (door->direction == -1)
  365. door->direction = 1; // go back up
  366. else
  367. {
  368. if (!thing->player)
  369. return; // JDC: bad guys never close doors
  370. door->direction = -1; // start going down immediately
  371. }
  372. return;
  373. }
  374. }
  375. // for proper sound
  376. switch(line->special)
  377. {
  378. case 117: // BLAZING DOOR RAISE
  379. case 118: // BLAZING DOOR OPEN
  380. S_StartSound((mobj_t *)&sec->soundorg,sfx_bdopn);
  381. break;
  382. case 1: // NORMAL DOOR SOUND
  383. case 31:
  384. S_StartSound((mobj_t *)&sec->soundorg,sfx_doropn);
  385. break;
  386. default: // LOCKED DOOR SOUND
  387. S_StartSound((mobj_t *)&sec->soundorg,sfx_doropn);
  388. break;
  389. }
  390. // new door thinker
  391. door = Z_Malloc (sizeof(*door), PU_LEVSPEC, 0);
  392. P_AddThinker (&door->thinker);
  393. sec->specialdata = door;
  394. door->thinker.function.acp1 = (actionf_p1) T_VerticalDoor;
  395. door->sector = sec;
  396. door->direction = 1;
  397. door->speed = VDOORSPEED;
  398. door->topwait = VDOORWAIT;
  399. switch(line->special)
  400. {
  401. case 1:
  402. case 26:
  403. case 27:
  404. case 28:
  405. door->type = normal;
  406. break;
  407. case 31:
  408. case 32:
  409. case 33:
  410. case 34:
  411. door->type = open;
  412. line->special = 0;
  413. break;
  414. case 117: // blazing door raise
  415. door->type = blazeRaise;
  416. door->speed = VDOORSPEED*4;
  417. break;
  418. case 118: // blazing door open
  419. door->type = blazeOpen;
  420. line->special = 0;
  421. door->speed = VDOORSPEED*4;
  422. break;
  423. }
  424. // find the top and bottom of the movement range
  425. door->topheight = P_FindLowestCeilingSurrounding(sec);
  426. door->topheight -= 4*FRACUNIT;
  427. }
  428. //
  429. // Spawn a door that closes after 30 seconds
  430. //
  431. void P_SpawnDoorCloseIn30 (sector_t* sec)
  432. {
  433. vldoor_t* door;
  434. door = Z_Malloc ( sizeof(*door), PU_LEVSPEC, 0);
  435. P_AddThinker (&door->thinker);
  436. sec->specialdata = door;
  437. sec->special = 0;
  438. door->thinker.function.acp1 = (actionf_p1)T_VerticalDoor;
  439. door->sector = sec;
  440. door->direction = 0;
  441. door->type = normal;
  442. door->speed = VDOORSPEED;
  443. door->topcountdown = 30 * 35;
  444. }
  445. //
  446. // Spawn a door that opens after 5 minutes
  447. //
  448. void
  449. P_SpawnDoorRaiseIn5Mins
  450. ( sector_t* sec,
  451. int secnum )
  452. {
  453. vldoor_t* door;
  454. door = Z_Malloc ( sizeof(*door), PU_LEVSPEC, 0);
  455. P_AddThinker (&door->thinker);
  456. sec->specialdata = door;
  457. sec->special = 0;
  458. door->thinker.function.acp1 = (actionf_p1)T_VerticalDoor;
  459. door->sector = sec;
  460. door->direction = 2;
  461. door->type = raiseIn5Mins;
  462. door->speed = VDOORSPEED;
  463. door->topheight = P_FindLowestCeilingSurrounding(sec);
  464. door->topheight -= 4*FRACUNIT;
  465. door->topwait = VDOORWAIT;
  466. door->topcountdown = 5 * 60 * 35;
  467. }
  468. // UNUSED
  469. // Separate into p_slidoor.c?
  470. #if 0 // ABANDONED TO THE MISTS OF TIME!!!
  471. //
  472. // EV_SlidingDoor : slide a door horizontally
  473. // (animate midtexture, then set noblocking line)
  474. //
  475. slideframe_t slideFrames[MAXSLIDEDOORS];
  476. void P_InitSlidingDoorFrames(void)
  477. {
  478. int i;
  479. int f1;
  480. int f2;
  481. int f3;
  482. int f4;
  483. // DOOM II ONLY...
  484. if ( gamemode != commercial)
  485. return;
  486. for (i = 0;i < MAXSLIDEDOORS; i++)
  487. {
  488. if (!slideFrameNames[i].frontFrame1[0])
  489. break;
  490. f1 = R_TextureNumForName(slideFrameNames[i].frontFrame1);
  491. f2 = R_TextureNumForName(slideFrameNames[i].frontFrame2);
  492. f3 = R_TextureNumForName(slideFrameNames[i].frontFrame3);
  493. f4 = R_TextureNumForName(slideFrameNames[i].frontFrame4);
  494. slideFrames[i].frontFrames[0] = f1;
  495. slideFrames[i].frontFrames[1] = f2;
  496. slideFrames[i].frontFrames[2] = f3;
  497. slideFrames[i].frontFrames[3] = f4;
  498. f1 = R_TextureNumForName(slideFrameNames[i].backFrame1);
  499. f2 = R_TextureNumForName(slideFrameNames[i].backFrame2);
  500. f3 = R_TextureNumForName(slideFrameNames[i].backFrame3);
  501. f4 = R_TextureNumForName(slideFrameNames[i].backFrame4);
  502. slideFrames[i].backFrames[0] = f1;
  503. slideFrames[i].backFrames[1] = f2;
  504. slideFrames[i].backFrames[2] = f3;
  505. slideFrames[i].backFrames[3] = f4;
  506. }
  507. }
  508. //
  509. // Return index into "slideFrames" array
  510. // for which door type to use
  511. //
  512. int P_FindSlidingDoorType(line_t* line)
  513. {
  514. int i;
  515. int val;
  516. for (i = 0;i < MAXSLIDEDOORS;i++)
  517. {
  518. val = sides[line->sidenum[0]].midtexture;
  519. if (val == slideFrames[i].frontFrames[0])
  520. return i;
  521. }
  522. return -1;
  523. }
  524. void T_SlidingDoor (slidedoor_t* door)
  525. {
  526. switch(door->status)
  527. {
  528. case sd_opening:
  529. if (!door->timer--)
  530. {
  531. if (++door->frame == SNUMFRAMES)
  532. {
  533. // IF DOOR IS DONE OPENING...
  534. sides[door->line->sidenum[0]].midtexture = 0;
  535. sides[door->line->sidenum[1]].midtexture = 0;
  536. door->line->flags &= ML_BLOCKING^0xff;
  537. if (door->type == sdt_openOnly)
  538. {
  539. door->frontsector->specialdata = NULL;
  540. P_RemoveThinker (&door->thinker);
  541. break;
  542. }
  543. door->timer = SDOORWAIT;
  544. door->status = sd_waiting;
  545. }
  546. else
  547. {
  548. // IF DOOR NEEDS TO ANIMATE TO NEXT FRAME...
  549. door->timer = SWAITTICS;
  550. sides[door->line->sidenum[0]].midtexture =
  551. slideFrames[door->whichDoorIndex].
  552. frontFrames[door->frame];
  553. sides[door->line->sidenum[1]].midtexture =
  554. slideFrames[door->whichDoorIndex].
  555. backFrames[door->frame];
  556. }
  557. }
  558. break;
  559. case sd_waiting:
  560. // IF DOOR IS DONE WAITING...
  561. if (!door->timer--)
  562. {
  563. // CAN DOOR CLOSE?
  564. if (door->frontsector->thinglist != NULL ||
  565. door->backsector->thinglist != NULL)
  566. {
  567. door->timer = SDOORWAIT;
  568. break;
  569. }
  570. //door->frame = SNUMFRAMES-1;
  571. door->status = sd_closing;
  572. door->timer = SWAITTICS;
  573. }
  574. break;
  575. case sd_closing:
  576. if (!door->timer--)
  577. {
  578. if (--door->frame < 0)
  579. {
  580. // IF DOOR IS DONE CLOSING...
  581. door->line->flags |= ML_BLOCKING;
  582. door->frontsector->specialdata = NULL;
  583. P_RemoveThinker (&door->thinker);
  584. break;
  585. }
  586. else
  587. {
  588. // IF DOOR NEEDS TO ANIMATE TO NEXT FRAME...
  589. door->timer = SWAITTICS;
  590. sides[door->line->sidenum[0]].midtexture =
  591. slideFrames[door->whichDoorIndex].
  592. frontFrames[door->frame];
  593. sides[door->line->sidenum[1]].midtexture =
  594. slideFrames[door->whichDoorIndex].
  595. backFrames[door->frame];
  596. }
  597. }
  598. break;
  599. }
  600. }
  601. void
  602. EV_SlidingDoor
  603. ( line_t* line,
  604. mobj_t* thing )
  605. {
  606. sector_t* sec;
  607. slidedoor_t* door;
  608. // DOOM II ONLY...
  609. if (gamemode != commercial)
  610. return;
  611. // Make sure door isn't already being animated
  612. sec = line->frontsector;
  613. door = NULL;
  614. if (sec->specialdata)
  615. {
  616. if (!thing->player)
  617. return;
  618. door = sec->specialdata;
  619. if (door->type == sdt_openAndClose)
  620. {
  621. if (door->status == sd_waiting)
  622. door->status = sd_closing;
  623. }
  624. else
  625. return;
  626. }
  627. // Init sliding door vars
  628. if (!door)
  629. {
  630. door = Z_Malloc (sizeof(*door), PU_LEVSPEC, 0);
  631. P_AddThinker (&door->thinker);
  632. sec->specialdata = door;
  633. door->type = sdt_openAndClose;
  634. door->status = sd_opening;
  635. door->whichDoorIndex = P_FindSlidingDoorType(line);
  636. if (door->whichDoorIndex < 0)
  637. I_Error("EV_SlidingDoor: Can't use texture for sliding door!");
  638. door->frontsector = sec;
  639. door->backsector = line->backsector;
  640. door->thinker.function = T_SlidingDoor;
  641. door->timer = SWAITTICS;
  642. door->frame = 0;
  643. door->line = line;
  644. }
  645. }
  646. #endif