p_genlin.c.svn-base 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. /* Emacs style mode select -*- C++ -*-
  2. *-----------------------------------------------------------------------------
  3. *
  4. *
  5. * PrBoom: a Doom port merged with LxDoom and LSDLDoom
  6. * based on BOOM, a modified and improved DOOM engine
  7. * Copyright (C) 1999 by
  8. * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  9. * Copyright (C) 1999-2000 by
  10. * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  11. * Copyright 2005, 2006 by
  12. * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  27. * 02111-1307, USA.
  28. *
  29. * DESCRIPTION:
  30. * Generalized linedef type handlers
  31. * Floors, Ceilings, Doors, Locked Doors, Lifts, Stairs, Crushers
  32. *
  33. *-----------------------------------------------------------------------------*/
  34. #include "doomstat.h" //jff 6/19/98 for demo_compatibility
  35. #include "r_main.h"
  36. #include "p_spec.h"
  37. #include "p_tick.h"
  38. #include "m_random.h"
  39. #include "s_sound.h"
  40. #include "sounds.h"
  41. //////////////////////////////////////////////////////////
  42. //
  43. // Generalized Linedef Type handlers
  44. //
  45. //////////////////////////////////////////////////////////
  46. //
  47. // EV_DoGenFloor()
  48. //
  49. // Handle generalized floor types
  50. //
  51. // Passed the line activating the generalized floor function
  52. // Returns true if a thinker is created
  53. //
  54. // jff 02/04/98 Added this routine (and file) to handle generalized
  55. // floor movers using bit fields in the line special type.
  56. //
  57. int EV_DoGenFloor
  58. ( line_t* line )
  59. {
  60. int secnum;
  61. int rtn;
  62. boolean manual;
  63. sector_t* sec;
  64. floormove_t* floor;
  65. unsigned value = (unsigned)line->special - GenFloorBase;
  66. // parse the bit fields in the line's special type
  67. int Crsh = (value & FloorCrush) >> FloorCrushShift;
  68. int ChgT = (value & FloorChange) >> FloorChangeShift;
  69. int Targ = (value & FloorTarget) >> FloorTargetShift;
  70. int Dirn = (value & FloorDirection) >> FloorDirectionShift;
  71. int ChgM = (value & FloorModel) >> FloorModelShift;
  72. int Sped = (value & FloorSpeed) >> FloorSpeedShift;
  73. int Trig = (value & TriggerType) >> TriggerTypeShift;
  74. rtn = 0;
  75. // check if a manual trigger, if so do just the sector on the backside
  76. manual = false;
  77. if (Trig==PushOnce || Trig==PushMany)
  78. {
  79. if (!(sec = line->backsector))
  80. return rtn;
  81. secnum = sec-sectors;
  82. manual = true;
  83. goto manual_floor;
  84. }
  85. secnum = -1;
  86. // if not manual do all sectors tagged the same as the line
  87. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  88. {
  89. sec = &sectors[secnum];
  90. manual_floor:
  91. // Do not start another function if floor already moving
  92. if (P_SectorActive(floor_special,sec))
  93. {
  94. if (!manual)
  95. continue;
  96. else
  97. return rtn;
  98. }
  99. // new floor thinker
  100. rtn = 1;
  101. floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
  102. memset(floor, 0, sizeof(*floor));
  103. P_AddThinker (&floor->thinker);
  104. sec->floordata = floor;
  105. floor->thinker.function = T_MoveFloor;
  106. floor->crush = Crsh;
  107. floor->direction = Dirn? 1 : -1;
  108. floor->sector = sec;
  109. floor->texture = sec->floorpic;
  110. floor->newspecial = sec->special;
  111. //jff 3/14/98 transfer old special field too
  112. floor->oldspecial = sec->oldspecial;
  113. floor->type = genFloor;
  114. // set the speed of motion
  115. switch (Sped)
  116. {
  117. case SpeedSlow:
  118. floor->speed = FLOORSPEED;
  119. break;
  120. case SpeedNormal:
  121. floor->speed = FLOORSPEED*2;
  122. break;
  123. case SpeedFast:
  124. floor->speed = FLOORSPEED*4;
  125. break;
  126. case SpeedTurbo:
  127. floor->speed = FLOORSPEED*8;
  128. break;
  129. default:
  130. break;
  131. }
  132. // set the destination height
  133. switch(Targ)
  134. {
  135. case FtoHnF:
  136. floor->floordestheight = P_FindHighestFloorSurrounding(sec);
  137. break;
  138. case FtoLnF:
  139. floor->floordestheight = P_FindLowestFloorSurrounding(sec);
  140. break;
  141. case FtoNnF:
  142. floor->floordestheight = Dirn?
  143. P_FindNextHighestFloor(sec,sec->floorheight) :
  144. P_FindNextLowestFloor(sec,sec->floorheight);
  145. break;
  146. case FtoLnC:
  147. floor->floordestheight = P_FindLowestCeilingSurrounding(sec);
  148. break;
  149. case FtoC:
  150. floor->floordestheight = sec->ceilingheight;
  151. break;
  152. case FbyST:
  153. floor->floordestheight = (floor->sector->floorheight>>FRACBITS) +
  154. floor->direction * (P_FindShortestTextureAround(secnum)>>FRACBITS);
  155. if (floor->floordestheight>32000) //jff 3/13/98 prevent overflow
  156. floor->floordestheight=32000; // wraparound in floor height
  157. if (floor->floordestheight<-32000)
  158. floor->floordestheight=-32000;
  159. floor->floordestheight<<=FRACBITS;
  160. break;
  161. case Fby24:
  162. floor->floordestheight = floor->sector->floorheight +
  163. floor->direction * 24*FRACUNIT;
  164. break;
  165. case Fby32:
  166. floor->floordestheight = floor->sector->floorheight +
  167. floor->direction * 32*FRACUNIT;
  168. break;
  169. default:
  170. break;
  171. }
  172. // set texture/type change properties
  173. if (ChgT) // if a texture change is indicated
  174. {
  175. if (ChgM) // if a numeric model change
  176. {
  177. sector_t *sec;
  178. //jff 5/23/98 find model with ceiling at target height if target
  179. //is a ceiling type
  180. sec = (Targ==FtoLnC || Targ==FtoC)?
  181. P_FindModelCeilingSector(floor->floordestheight,secnum) :
  182. P_FindModelFloorSector(floor->floordestheight,secnum);
  183. if (sec)
  184. {
  185. floor->texture = sec->floorpic;
  186. switch(ChgT)
  187. {
  188. case FChgZero: // zero type
  189. floor->newspecial = 0;
  190. //jff 3/14/98 change old field too
  191. floor->oldspecial = 0;
  192. floor->type = genFloorChg0;
  193. break;
  194. case FChgTyp: // copy type
  195. floor->newspecial = sec->special;
  196. //jff 3/14/98 change old field too
  197. floor->oldspecial = sec->oldspecial;
  198. floor->type = genFloorChgT;
  199. break;
  200. case FChgTxt: // leave type be
  201. floor->type = genFloorChg;
  202. break;
  203. default:
  204. break;
  205. }
  206. }
  207. }
  208. else // else if a trigger model change
  209. {
  210. floor->texture = line->frontsector->floorpic;
  211. switch (ChgT)
  212. {
  213. case FChgZero: // zero type
  214. floor->newspecial = 0;
  215. //jff 3/14/98 change old field too
  216. floor->oldspecial = 0;
  217. floor->type = genFloorChg0;
  218. break;
  219. case FChgTyp: // copy type
  220. floor->newspecial = line->frontsector->special;
  221. //jff 3/14/98 change old field too
  222. floor->oldspecial = line->frontsector->oldspecial;
  223. floor->type = genFloorChgT;
  224. break;
  225. case FChgTxt: // leave type be
  226. floor->type = genFloorChg;
  227. default:
  228. break;
  229. }
  230. }
  231. }
  232. if (manual) return rtn;
  233. }
  234. return rtn;
  235. }
  236. //
  237. // EV_DoGenCeiling()
  238. //
  239. // Handle generalized ceiling types
  240. //
  241. // Passed the linedef activating the ceiling function
  242. // Returns true if a thinker created
  243. //
  244. // jff 02/04/98 Added this routine (and file) to handle generalized
  245. // floor movers using bit fields in the line special type.
  246. //
  247. int EV_DoGenCeiling
  248. ( line_t* line )
  249. {
  250. int secnum;
  251. int rtn;
  252. boolean manual;
  253. fixed_t targheight;
  254. sector_t* sec;
  255. ceiling_t* ceiling;
  256. unsigned value = (unsigned)line->special - GenCeilingBase;
  257. // parse the bit fields in the line's special type
  258. int Crsh = (value & CeilingCrush) >> CeilingCrushShift;
  259. int ChgT = (value & CeilingChange) >> CeilingChangeShift;
  260. int Targ = (value & CeilingTarget) >> CeilingTargetShift;
  261. int Dirn = (value & CeilingDirection) >> CeilingDirectionShift;
  262. int ChgM = (value & CeilingModel) >> CeilingModelShift;
  263. int Sped = (value & CeilingSpeed) >> CeilingSpeedShift;
  264. int Trig = (value & TriggerType) >> TriggerTypeShift;
  265. rtn = 0;
  266. // check if a manual trigger, if so do just the sector on the backside
  267. manual = false;
  268. if (Trig==PushOnce || Trig==PushMany)
  269. {
  270. if (!(sec = line->backsector))
  271. return rtn;
  272. secnum = sec-sectors;
  273. manual = true;
  274. goto manual_ceiling;
  275. }
  276. secnum = -1;
  277. // if not manual do all sectors tagged the same as the line
  278. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  279. {
  280. sec = &sectors[secnum];
  281. manual_ceiling:
  282. // Do not start another function if ceiling already moving
  283. if (P_SectorActive(ceiling_special,sec)) //jff 2/22/98
  284. {
  285. if (!manual)
  286. continue;
  287. else
  288. return rtn;
  289. }
  290. // new ceiling thinker
  291. rtn = 1;
  292. ceiling = Z_Malloc (sizeof(*ceiling), PU_LEVSPEC, 0);
  293. memset(ceiling, 0, sizeof(*ceiling));
  294. P_AddThinker (&ceiling->thinker);
  295. sec->ceilingdata = ceiling; //jff 2/22/98
  296. ceiling->thinker.function = T_MoveCeiling;
  297. ceiling->crush = Crsh;
  298. ceiling->direction = Dirn? 1 : -1;
  299. ceiling->sector = sec;
  300. ceiling->texture = sec->ceilingpic;
  301. ceiling->newspecial = sec->special;
  302. //jff 3/14/98 change old field too
  303. ceiling->oldspecial = sec->oldspecial;
  304. ceiling->tag = sec->tag;
  305. ceiling->type = genCeiling;
  306. // set speed of motion
  307. switch (Sped)
  308. {
  309. case SpeedSlow:
  310. ceiling->speed = CEILSPEED;
  311. break;
  312. case SpeedNormal:
  313. ceiling->speed = CEILSPEED*2;
  314. break;
  315. case SpeedFast:
  316. ceiling->speed = CEILSPEED*4;
  317. break;
  318. case SpeedTurbo:
  319. ceiling->speed = CEILSPEED*8;
  320. break;
  321. default:
  322. break;
  323. }
  324. // set destination target height
  325. targheight = sec->ceilingheight;
  326. switch(Targ)
  327. {
  328. case CtoHnC:
  329. targheight = P_FindHighestCeilingSurrounding(sec);
  330. break;
  331. case CtoLnC:
  332. targheight = P_FindLowestCeilingSurrounding(sec);
  333. break;
  334. case CtoNnC:
  335. targheight = Dirn?
  336. P_FindNextHighestCeiling(sec,sec->ceilingheight) :
  337. P_FindNextLowestCeiling(sec,sec->ceilingheight);
  338. break;
  339. case CtoHnF:
  340. targheight = P_FindHighestFloorSurrounding(sec);
  341. break;
  342. case CtoF:
  343. targheight = sec->floorheight;
  344. break;
  345. case CbyST:
  346. targheight = (ceiling->sector->ceilingheight>>FRACBITS) +
  347. ceiling->direction * (P_FindShortestUpperAround(secnum)>>FRACBITS);
  348. if (targheight>32000) //jff 3/13/98 prevent overflow
  349. targheight=32000; // wraparound in ceiling height
  350. if (targheight<-32000)
  351. targheight=-32000;
  352. targheight<<=FRACBITS;
  353. break;
  354. case Cby24:
  355. targheight = ceiling->sector->ceilingheight +
  356. ceiling->direction * 24*FRACUNIT;
  357. break;
  358. case Cby32:
  359. targheight = ceiling->sector->ceilingheight +
  360. ceiling->direction * 32*FRACUNIT;
  361. break;
  362. default:
  363. break;
  364. }
  365. if (Dirn) ceiling->topheight = targheight;
  366. else ceiling->bottomheight = targheight;
  367. // set texture/type change properties
  368. if (ChgT) // if a texture change is indicated
  369. {
  370. if (ChgM) // if a numeric model change
  371. {
  372. sector_t *sec;
  373. //jff 5/23/98 find model with floor at target height if target
  374. //is a floor type
  375. sec = (Targ==CtoHnF || Targ==CtoF)?
  376. P_FindModelFloorSector(targheight,secnum) :
  377. P_FindModelCeilingSector(targheight,secnum);
  378. if (sec)
  379. {
  380. ceiling->texture = sec->ceilingpic;
  381. switch (ChgT)
  382. {
  383. case CChgZero: // type is zeroed
  384. ceiling->newspecial = 0;
  385. //jff 3/14/98 change old field too
  386. ceiling->oldspecial = 0;
  387. ceiling->type = genCeilingChg0;
  388. break;
  389. case CChgTyp: // type is copied
  390. ceiling->newspecial = sec->special;
  391. //jff 3/14/98 change old field too
  392. ceiling->oldspecial = sec->oldspecial;
  393. ceiling->type = genCeilingChgT;
  394. break;
  395. case CChgTxt: // type is left alone
  396. ceiling->type = genCeilingChg;
  397. break;
  398. default:
  399. break;
  400. }
  401. }
  402. }
  403. else // else if a trigger model change
  404. {
  405. ceiling->texture = line->frontsector->ceilingpic;
  406. switch (ChgT)
  407. {
  408. case CChgZero: // type is zeroed
  409. ceiling->newspecial = 0;
  410. //jff 3/14/98 change old field too
  411. ceiling->oldspecial = 0;
  412. ceiling->type = genCeilingChg0;
  413. break;
  414. case CChgTyp: // type is copied
  415. ceiling->newspecial = line->frontsector->special;
  416. //jff 3/14/98 change old field too
  417. ceiling->oldspecial = line->frontsector->oldspecial;
  418. ceiling->type = genCeilingChgT;
  419. break;
  420. case CChgTxt: // type is left alone
  421. ceiling->type = genCeilingChg;
  422. break;
  423. default:
  424. break;
  425. }
  426. }
  427. }
  428. P_AddActiveCeiling(ceiling); // add this ceiling to the active list
  429. if (manual) return rtn;
  430. }
  431. return rtn;
  432. }
  433. //
  434. // EV_DoGenLift()
  435. //
  436. // Handle generalized lift types
  437. //
  438. // Passed the linedef activating the lift
  439. // Returns true if a thinker is created
  440. //
  441. int EV_DoGenLift
  442. ( line_t* line )
  443. {
  444. plat_t* plat;
  445. int secnum;
  446. int rtn;
  447. boolean manual;
  448. sector_t* sec;
  449. unsigned value = (unsigned)line->special - GenLiftBase;
  450. // parse the bit fields in the line's special type
  451. int Targ = (value & LiftTarget) >> LiftTargetShift;
  452. int Dely = (value & LiftDelay) >> LiftDelayShift;
  453. int Sped = (value & LiftSpeed) >> LiftSpeedShift;
  454. int Trig = (value & TriggerType) >> TriggerTypeShift;
  455. secnum = -1;
  456. rtn = 0;
  457. // Activate all <type> plats that are in_stasis
  458. if (Targ==LnF2HnF)
  459. P_ActivateInStasis(line->tag);
  460. // check if a manual trigger, if so do just the sector on the backside
  461. manual = false;
  462. if (Trig==PushOnce || Trig==PushMany)
  463. {
  464. if (!(sec = line->backsector))
  465. return rtn;
  466. secnum = sec-sectors;
  467. manual = true;
  468. goto manual_lift;
  469. }
  470. // if not manual do all sectors tagged the same as the line
  471. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  472. {
  473. sec = &sectors[secnum];
  474. manual_lift:
  475. // Do not start another function if floor already moving
  476. if (P_SectorActive(floor_special,sec))
  477. {
  478. if (!manual)
  479. continue;
  480. else
  481. return rtn;
  482. }
  483. // Setup the plat thinker
  484. rtn = 1;
  485. plat = Z_Malloc( sizeof(*plat), PU_LEVSPEC, 0);
  486. memset(plat, 0, sizeof(*plat));
  487. P_AddThinker(&plat->thinker);
  488. plat->sector = sec;
  489. plat->sector->floordata = plat;
  490. plat->thinker.function = T_PlatRaise;
  491. plat->crush = false;
  492. plat->tag = line->tag;
  493. plat->type = genLift;
  494. plat->high = sec->floorheight;
  495. plat->status = down;
  496. // setup the target destination height
  497. switch(Targ)
  498. {
  499. case F2LnF:
  500. plat->low = P_FindLowestFloorSurrounding(sec);
  501. if (plat->low > sec->floorheight)
  502. plat->low = sec->floorheight;
  503. break;
  504. case F2NnF:
  505. plat->low = P_FindNextLowestFloor(sec,sec->floorheight);
  506. break;
  507. case F2LnC:
  508. plat->low = P_FindLowestCeilingSurrounding(sec);
  509. if (plat->low > sec->floorheight)
  510. plat->low = sec->floorheight;
  511. break;
  512. case LnF2HnF:
  513. plat->type = genPerpetual;
  514. plat->low = P_FindLowestFloorSurrounding(sec);
  515. if (plat->low > sec->floorheight)
  516. plat->low = sec->floorheight;
  517. plat->high = P_FindHighestFloorSurrounding(sec);
  518. if (plat->high < sec->floorheight)
  519. plat->high = sec->floorheight;
  520. plat->status = P_Random(pr_genlift)&1;
  521. break;
  522. default:
  523. break;
  524. }
  525. // setup the speed of motion
  526. switch(Sped)
  527. {
  528. case SpeedSlow:
  529. plat->speed = PLATSPEED * 2;
  530. break;
  531. case SpeedNormal:
  532. plat->speed = PLATSPEED * 4;
  533. break;
  534. case SpeedFast:
  535. plat->speed = PLATSPEED * 8;
  536. break;
  537. case SpeedTurbo:
  538. plat->speed = PLATSPEED * 16;
  539. break;
  540. default:
  541. break;
  542. }
  543. // setup the delay time before the floor returns
  544. switch(Dely)
  545. {
  546. case 0:
  547. plat->wait = 1*35;
  548. break;
  549. case 1:
  550. plat->wait = PLATWAIT*35;
  551. break;
  552. case 2:
  553. plat->wait = 5*35;
  554. break;
  555. case 3:
  556. plat->wait = 10*35;
  557. break;
  558. }
  559. S_StartSound((mobj_t *)&sec->soundorg,sfx_pstart);
  560. P_AddActivePlat(plat); // add this plat to the list of active plats
  561. if (manual)
  562. return rtn;
  563. }
  564. return rtn;
  565. }
  566. //
  567. // EV_DoGenStairs()
  568. //
  569. // Handle generalized stair building
  570. //
  571. // Passed the linedef activating the stairs
  572. // Returns true if a thinker is created
  573. //
  574. int EV_DoGenStairs
  575. ( line_t* line )
  576. {
  577. int secnum;
  578. int osecnum; //jff 3/4/98 preserve loop index
  579. int height;
  580. int i;
  581. int newsecnum;
  582. int texture;
  583. int ok;
  584. int rtn;
  585. boolean manual;
  586. sector_t* sec;
  587. sector_t* tsec;
  588. floormove_t* floor;
  589. fixed_t stairsize;
  590. fixed_t speed;
  591. unsigned value = (unsigned)line->special - GenStairsBase;
  592. // parse the bit fields in the line's special type
  593. int Igno = (value & StairIgnore) >> StairIgnoreShift;
  594. int Dirn = (value & StairDirection) >> StairDirectionShift;
  595. int Step = (value & StairStep) >> StairStepShift;
  596. int Sped = (value & StairSpeed) >> StairSpeedShift;
  597. int Trig = (value & TriggerType) >> TriggerTypeShift;
  598. rtn = 0;
  599. // check if a manual trigger, if so do just the sector on the backside
  600. manual = false;
  601. if (Trig==PushOnce || Trig==PushMany)
  602. {
  603. if (!(sec = line->backsector))
  604. return rtn;
  605. secnum = sec-sectors;
  606. manual = true;
  607. goto manual_stair;
  608. }
  609. secnum = -1;
  610. // if not manual do all sectors tagged the same as the line
  611. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  612. {
  613. sec = &sectors[secnum];
  614. manual_stair:
  615. //Do not start another function if floor already moving
  616. //jff 2/26/98 add special lockout condition to wait for entire
  617. //staircase to build before retriggering
  618. if (P_SectorActive(floor_special,sec) || sec->stairlock)
  619. {
  620. if (!manual)
  621. continue;
  622. else
  623. return rtn;
  624. }
  625. // new floor thinker
  626. rtn = 1;
  627. floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
  628. memset(floor, 0, sizeof(*floor));
  629. P_AddThinker (&floor->thinker);
  630. sec->floordata = floor;
  631. floor->thinker.function = T_MoveFloor;
  632. floor->direction = Dirn? 1 : -1;
  633. floor->sector = sec;
  634. // setup speed of stair building
  635. switch(Sped)
  636. {
  637. default:
  638. case SpeedSlow:
  639. floor->speed = FLOORSPEED/4;
  640. break;
  641. case SpeedNormal:
  642. floor->speed = FLOORSPEED/2;
  643. break;
  644. case SpeedFast:
  645. floor->speed = FLOORSPEED*2;
  646. break;
  647. case SpeedTurbo:
  648. floor->speed = FLOORSPEED*4;
  649. break;
  650. }
  651. // setup stepsize for stairs
  652. switch(Step)
  653. {
  654. default:
  655. case 0:
  656. stairsize = 4*FRACUNIT;
  657. break;
  658. case 1:
  659. stairsize = 8*FRACUNIT;
  660. break;
  661. case 2:
  662. stairsize = 16*FRACUNIT;
  663. break;
  664. case 3:
  665. stairsize = 24*FRACUNIT;
  666. break;
  667. }
  668. speed = floor->speed;
  669. height = sec->floorheight + floor->direction * stairsize;
  670. floor->floordestheight = height;
  671. texture = sec->floorpic;
  672. floor->crush = false;
  673. floor->type = genBuildStair; // jff 3/31/98 do not leave uninited
  674. sec->stairlock = -2; // jff 2/26/98 set up lock on current sector
  675. sec->nextsec = -1;
  676. sec->prevsec = -1;
  677. osecnum = secnum; //jff 3/4/98 preserve loop index
  678. // Find next sector to raise
  679. // 1. Find 2-sided line with same sector side[0]
  680. // 2. Other side is the next sector to raise
  681. do
  682. {
  683. ok = 0;
  684. for (i = 0;i < sec->linecount;i++)
  685. {
  686. if ( !((sec->lines[i])->backsector) )
  687. continue;
  688. tsec = (sec->lines[i])->frontsector;
  689. newsecnum = tsec-sectors;
  690. if (secnum != newsecnum)
  691. continue;
  692. tsec = (sec->lines[i])->backsector;
  693. newsecnum = tsec - sectors;
  694. if (!Igno && tsec->floorpic != texture)
  695. continue;
  696. /* jff 6/19/98 prevent double stepsize */
  697. if (compatibility_level < boom_202_compatibility)
  698. height += floor->direction * stairsize;
  699. //jff 2/26/98 special lockout condition for retriggering
  700. if (P_SectorActive(floor_special,tsec) || tsec->stairlock)
  701. continue;
  702. /* jff 6/19/98 increase height AFTER continue */
  703. if (compatibility_level >= boom_202_compatibility)
  704. height += floor->direction * stairsize;
  705. // jff 2/26/98
  706. // link the stair chain in both directions
  707. // lock the stair sector until building complete
  708. sec->nextsec = newsecnum; // link step to next
  709. tsec->prevsec = secnum; // link next back
  710. tsec->nextsec = -1; // set next forward link as end
  711. tsec->stairlock = -2; // lock the step
  712. sec = tsec;
  713. secnum = newsecnum;
  714. floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
  715. memset(floor, 0, sizeof(*floor));
  716. P_AddThinker (&floor->thinker);
  717. sec->floordata = floor;
  718. floor->thinker.function = T_MoveFloor;
  719. floor->direction = Dirn? 1 : -1;
  720. floor->sector = sec;
  721. floor->speed = speed;
  722. floor->floordestheight = height;
  723. floor->crush = false;
  724. floor->type = genBuildStair; // jff 3/31/98 do not leave uninited
  725. ok = 1;
  726. break;
  727. }
  728. } while(ok);
  729. if (manual)
  730. return rtn;
  731. secnum = osecnum; //jff 3/4/98 restore old loop index
  732. }
  733. // retriggerable generalized stairs build up or down alternately
  734. if (rtn)
  735. line->special ^= StairDirection; // alternate dir on succ activations
  736. return rtn;
  737. }
  738. //
  739. // EV_DoGenCrusher()
  740. //
  741. // Handle generalized crusher types
  742. //
  743. // Passed the linedef activating the crusher
  744. // Returns true if a thinker created
  745. //
  746. int EV_DoGenCrusher
  747. ( line_t* line )
  748. {
  749. int secnum;
  750. int rtn;
  751. boolean manual;
  752. sector_t* sec;
  753. ceiling_t* ceiling;
  754. unsigned value = (unsigned)line->special - GenCrusherBase;
  755. // parse the bit fields in the line's special type
  756. int Slnt = (value & CrusherSilent) >> CrusherSilentShift;
  757. int Sped = (value & CrusherSpeed) >> CrusherSpeedShift;
  758. int Trig = (value & TriggerType) >> TriggerTypeShift;
  759. //jff 2/22/98 Reactivate in-stasis ceilings...for certain types.
  760. //jff 4/5/98 return if activated
  761. rtn = P_ActivateInStasisCeiling(line);
  762. // check if a manual trigger, if so do just the sector on the backside
  763. manual = false;
  764. if (Trig==PushOnce || Trig==PushMany)
  765. {
  766. if (!(sec = line->backsector))
  767. return rtn;
  768. secnum = sec-sectors;
  769. manual = true;
  770. goto manual_crusher;
  771. }
  772. secnum = -1;
  773. // if not manual do all sectors tagged the same as the line
  774. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  775. {
  776. sec = &sectors[secnum];
  777. manual_crusher:
  778. // Do not start another function if ceiling already moving
  779. if (P_SectorActive(ceiling_special,sec)) //jff 2/22/98
  780. {
  781. if (!manual)
  782. continue;
  783. else
  784. return rtn;
  785. }
  786. // new ceiling thinker
  787. rtn = 1;
  788. ceiling = Z_Malloc (sizeof(*ceiling), PU_LEVSPEC, 0);
  789. memset(ceiling, 0, sizeof(*ceiling));
  790. P_AddThinker (&ceiling->thinker);
  791. sec->ceilingdata = ceiling; //jff 2/22/98
  792. ceiling->thinker.function = T_MoveCeiling;
  793. ceiling->crush = true;
  794. ceiling->direction = -1;
  795. ceiling->sector = sec;
  796. ceiling->texture = sec->ceilingpic;
  797. ceiling->newspecial = sec->special;
  798. ceiling->tag = sec->tag;
  799. ceiling->type = Slnt? genSilentCrusher : genCrusher;
  800. ceiling->topheight = sec->ceilingheight;
  801. ceiling->bottomheight = sec->floorheight + (8*FRACUNIT);
  802. // setup ceiling motion speed
  803. switch (Sped)
  804. {
  805. case SpeedSlow:
  806. ceiling->speed = CEILSPEED;
  807. break;
  808. case SpeedNormal:
  809. ceiling->speed = CEILSPEED*2;
  810. break;
  811. case SpeedFast:
  812. ceiling->speed = CEILSPEED*4;
  813. break;
  814. case SpeedTurbo:
  815. ceiling->speed = CEILSPEED*8;
  816. break;
  817. default:
  818. break;
  819. }
  820. ceiling->oldspeed=ceiling->speed;
  821. P_AddActiveCeiling(ceiling); // add to list of active ceilings
  822. if (manual) return rtn;
  823. }
  824. return rtn;
  825. }
  826. //
  827. // EV_DoGenLockedDoor()
  828. //
  829. // Handle generalized locked door types
  830. //
  831. // Passed the linedef activating the generalized locked door
  832. // Returns true if a thinker created
  833. //
  834. int EV_DoGenLockedDoor
  835. ( line_t* line )
  836. {
  837. int secnum,rtn;
  838. sector_t* sec;
  839. vldoor_t* door;
  840. boolean manual;
  841. unsigned value = (unsigned)line->special - GenLockedBase;
  842. // parse the bit fields in the line's special type
  843. int Kind = (value & LockedKind) >> LockedKindShift;
  844. int Sped = (value & LockedSpeed) >> LockedSpeedShift;
  845. int Trig = (value & TriggerType) >> TriggerTypeShift;
  846. rtn = 0;
  847. // check if a manual trigger, if so do just the sector on the backside
  848. manual = false;
  849. if (Trig==PushOnce || Trig==PushMany)
  850. {
  851. if (!(sec = line->backsector))
  852. return rtn;
  853. secnum = sec-sectors;
  854. manual = true;
  855. goto manual_locked;
  856. }
  857. secnum = -1;
  858. rtn = 0;
  859. // if not manual do all sectors tagged the same as the line
  860. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  861. {
  862. sec = &sectors[secnum];
  863. manual_locked:
  864. // Do not start another function if ceiling already moving
  865. if (P_SectorActive(ceiling_special,sec)) //jff 2/22/98
  866. {
  867. if (!manual)
  868. continue;
  869. else
  870. return rtn;
  871. }
  872. // new door thinker
  873. rtn = 1;
  874. door = Z_Malloc (sizeof(*door), PU_LEVSPEC, 0);
  875. memset(door, 0, sizeof(*door));
  876. P_AddThinker (&door->thinker);
  877. sec->ceilingdata = door; //jff 2/22/98
  878. door->thinker.function = T_VerticalDoor;
  879. door->sector = sec;
  880. door->topwait = VDOORWAIT;
  881. door->line = line;
  882. door->topheight = P_FindLowestCeilingSurrounding(sec);
  883. door->topheight -= 4*FRACUNIT;
  884. door->direction = 1;
  885. /* killough 10/98: implement gradual lighting */
  886. door->lighttag = !comp[comp_doorlight] &&
  887. (line->special&6) == 6 &&
  888. line->special > GenLockedBase ? line->tag : 0;
  889. // setup speed of door motion
  890. switch(Sped)
  891. {
  892. default:
  893. case SpeedSlow:
  894. door->type = Kind? genOpen : genRaise;
  895. door->speed = VDOORSPEED;
  896. break;
  897. case SpeedNormal:
  898. door->type = Kind? genOpen : genRaise;
  899. door->speed = VDOORSPEED*2;
  900. break;
  901. case SpeedFast:
  902. door->type = Kind? genBlazeOpen : genBlazeRaise;
  903. door->speed = VDOORSPEED*4;
  904. break;
  905. case SpeedTurbo:
  906. door->type = Kind? genBlazeOpen : genBlazeRaise;
  907. door->speed = VDOORSPEED*8;
  908. break;
  909. }
  910. // killough 4/15/98: fix generalized door opening sounds
  911. // (previously they always had the blazing door close sound)
  912. S_StartSound((mobj_t *)&door->sector->soundorg, // killough 4/15/98
  913. door->speed >= VDOORSPEED*4 ? sfx_bdopn : sfx_doropn);
  914. if (manual)
  915. return rtn;
  916. }
  917. return rtn;
  918. }
  919. //
  920. // EV_DoGenDoor()
  921. //
  922. // Handle generalized door types
  923. //
  924. // Passed the linedef activating the generalized door
  925. // Returns true if a thinker created
  926. //
  927. int EV_DoGenDoor
  928. ( line_t* line )
  929. {
  930. int secnum,rtn;
  931. sector_t* sec;
  932. boolean manual;
  933. vldoor_t* door;
  934. unsigned value = (unsigned)line->special - GenDoorBase;
  935. // parse the bit fields in the line's special type
  936. int Dely = (value & DoorDelay) >> DoorDelayShift;
  937. int Kind = (value & DoorKind) >> DoorKindShift;
  938. int Sped = (value & DoorSpeed) >> DoorSpeedShift;
  939. int Trig = (value & TriggerType) >> TriggerTypeShift;
  940. rtn = 0;
  941. // check if a manual trigger, if so do just the sector on the backside
  942. manual = false;
  943. if (Trig==PushOnce || Trig==PushMany)
  944. {
  945. if (!(sec = line->backsector))
  946. return rtn;
  947. secnum = sec-sectors;
  948. manual = true;
  949. goto manual_door;
  950. }
  951. secnum = -1;
  952. rtn = 0;
  953. // if not manual do all sectors tagged the same as the line
  954. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  955. {
  956. sec = &sectors[secnum];
  957. manual_door:
  958. // Do not start another function if ceiling already moving
  959. if (P_SectorActive(ceiling_special,sec)) //jff 2/22/98
  960. {
  961. if (!manual)
  962. continue;
  963. else
  964. return rtn;
  965. }
  966. // new door thinker
  967. rtn = 1;
  968. door = Z_Malloc (sizeof(*door), PU_LEVSPEC, 0);
  969. memset(door, 0, sizeof(*door));
  970. P_AddThinker (&door->thinker);
  971. sec->ceilingdata = door; //jff 2/22/98
  972. door->thinker.function = T_VerticalDoor;
  973. door->sector = sec;
  974. // setup delay for door remaining open/closed
  975. switch(Dely)
  976. {
  977. default:
  978. case 0:
  979. door->topwait = 35;
  980. break;
  981. case 1:
  982. door->topwait = VDOORWAIT;
  983. break;
  984. case 2:
  985. door->topwait = 2*VDOORWAIT;
  986. break;
  987. case 3:
  988. door->topwait = 7*VDOORWAIT;
  989. break;
  990. }
  991. // setup speed of door motion
  992. switch(Sped)
  993. {
  994. default:
  995. case SpeedSlow:
  996. door->speed = VDOORSPEED;
  997. break;
  998. case SpeedNormal:
  999. door->speed = VDOORSPEED*2;
  1000. break;
  1001. case SpeedFast:
  1002. door->speed = VDOORSPEED*4;
  1003. break;
  1004. case SpeedTurbo:
  1005. door->speed = VDOORSPEED*8;
  1006. break;
  1007. }
  1008. door->line = line; // jff 1/31/98 remember line that triggered us
  1009. /* killough 10/98: implement gradual lighting */
  1010. door->lighttag = !comp[comp_doorlight] &&
  1011. (line->special&6) == 6 &&
  1012. line->special > GenLockedBase ? line->tag : 0;
  1013. // set kind of door, whether it opens then close, opens, closes etc.
  1014. // assign target heights accordingly
  1015. switch(Kind)
  1016. {
  1017. case OdCDoor:
  1018. door->direction = 1;
  1019. door->topheight = P_FindLowestCeilingSurrounding(sec);
  1020. door->topheight -= 4*FRACUNIT;
  1021. if (door->topheight != sec->ceilingheight)
  1022. S_StartSound((mobj_t *)&door->sector->soundorg,Sped>=SpeedFast || comp[comp_sound] ? sfx_bdopn : sfx_doropn);
  1023. door->type = Sped>=SpeedFast? genBlazeRaise : genRaise;
  1024. break;
  1025. case ODoor:
  1026. door->direction = 1;
  1027. door->topheight = P_FindLowestCeilingSurrounding(sec);
  1028. door->topheight -= 4*FRACUNIT;
  1029. if (door->topheight != sec->ceilingheight)
  1030. S_StartSound((mobj_t *)&door->sector->soundorg,Sped>=SpeedFast || comp[comp_sound] ? sfx_bdopn : sfx_doropn);
  1031. door->type = Sped>=SpeedFast? genBlazeOpen : genOpen;
  1032. break;
  1033. case CdODoor:
  1034. door->topheight = sec->ceilingheight;
  1035. door->direction = -1;
  1036. S_StartSound((mobj_t *)&door->sector->soundorg,Sped>=SpeedFast && !comp[comp_sound] ? sfx_bdcls : sfx_dorcls);
  1037. door->type = Sped>=SpeedFast? genBlazeCdO : genCdO;
  1038. break;
  1039. case CDoor:
  1040. door->topheight = P_FindLowestCeilingSurrounding(sec);
  1041. door->topheight -= 4*FRACUNIT;
  1042. door->direction = -1;
  1043. S_StartSound((mobj_t *)&door->sector->soundorg,Sped>=SpeedFast && !comp[comp_sound] ? sfx_bdcls : sfx_dorcls);
  1044. door->type = Sped>=SpeedFast? genBlazeClose : genClose;
  1045. break;
  1046. default:
  1047. break;
  1048. }
  1049. if (manual)
  1050. return rtn;
  1051. }
  1052. return rtn;
  1053. }