p_spec.c 24 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  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:
  20. // Implements special effects:
  21. // Texture animation, height or lighting changes
  22. // according to adjacent sectors, respective
  23. // utility functions, etc.
  24. // Line Tag handling. Line and Sector triggers.
  25. //
  26. //-----------------------------------------------------------------------------
  27. static const char
  28. rcsid[] = "$Id: p_spec.c,v 1.6 1997/02/03 22:45:12 b1 Exp $";
  29. #include <stdlib.h>
  30. #include "doomdef.h"
  31. #include "doomstat.h"
  32. #include "i_system.h"
  33. #include "z_zone.h"
  34. #include "m_argv.h"
  35. #include "m_random.h"
  36. #include "w_wad.h"
  37. #include "r_local.h"
  38. #include "p_local.h"
  39. #include "g_game.h"
  40. #include "s_sound.h"
  41. // State.
  42. #include "r_state.h"
  43. // Data.
  44. #include "sounds.h"
  45. //
  46. // Animating textures and planes
  47. // There is another anim_t used in wi_stuff, unrelated.
  48. //
  49. typedef struct
  50. {
  51. boolean istexture;
  52. int picnum;
  53. int basepic;
  54. int numpics;
  55. int speed;
  56. } anim_t;
  57. //
  58. // source animation definition
  59. //
  60. typedef struct
  61. {
  62. boolean istexture; // if false, it is a flat
  63. char endname[9];
  64. char startname[9];
  65. int speed;
  66. } animdef_t;
  67. #define MAXANIMS 32
  68. extern anim_t anims[MAXANIMS];
  69. extern anim_t* lastanim;
  70. //
  71. // P_InitPicAnims
  72. //
  73. // Floor/ceiling animation sequences,
  74. // defined by first and last frame,
  75. // i.e. the flat (64x64 tile) name to
  76. // be used.
  77. // The full animation sequence is given
  78. // using all the flats between the start
  79. // and end entry, in the order found in
  80. // the WAD file.
  81. //
  82. animdef_t animdefs[] =
  83. {
  84. {false, "NUKAGE3", "NUKAGE1", 8},
  85. {false, "FWATER4", "FWATER1", 8},
  86. {false, "SWATER4", "SWATER1", 8},
  87. {false, "LAVA4", "LAVA1", 8},
  88. {false, "BLOOD3", "BLOOD1", 8},
  89. // DOOM II flat animations.
  90. {false, "RROCK08", "RROCK05", 8},
  91. {false, "SLIME04", "SLIME01", 8},
  92. {false, "SLIME08", "SLIME05", 8},
  93. {false, "SLIME12", "SLIME09", 8},
  94. {true, "BLODGR4", "BLODGR1", 8},
  95. {true, "SLADRIP3", "SLADRIP1", 8},
  96. {true, "BLODRIP4", "BLODRIP1", 8},
  97. {true, "FIREWALL", "FIREWALA", 8},
  98. {true, "GSTFONT3", "GSTFONT1", 8},
  99. {true, "FIRELAVA", "FIRELAV3", 8},
  100. {true, "FIREMAG3", "FIREMAG1", 8},
  101. {true, "FIREBLU2", "FIREBLU1", 8},
  102. {true, "ROCKRED3", "ROCKRED1", 8},
  103. {true, "BFALL4", "BFALL1", 8},
  104. {true, "SFALL4", "SFALL1", 8},
  105. {true, "WFALL4", "WFALL1", 8},
  106. {true, "DBRAIN4", "DBRAIN1", 8},
  107. {-1}
  108. };
  109. anim_t anims[MAXANIMS];
  110. anim_t* lastanim;
  111. //
  112. // Animating line specials
  113. //
  114. #define MAXLINEANIMS 64
  115. extern short numlinespecials;
  116. extern line_t* linespeciallist[MAXLINEANIMS];
  117. void P_InitPicAnims (void)
  118. {
  119. int i;
  120. // Init animation
  121. lastanim = anims;
  122. for (i=0 ; animdefs[i].istexture != -1 ; i++)
  123. {
  124. if (animdefs[i].istexture)
  125. {
  126. // different episode ?
  127. if (R_CheckTextureNumForName(animdefs[i].startname) == -1)
  128. continue;
  129. lastanim->picnum = R_TextureNumForName (animdefs[i].endname);
  130. lastanim->basepic = R_TextureNumForName (animdefs[i].startname);
  131. }
  132. else
  133. {
  134. if (W_CheckNumForName(animdefs[i].startname) == -1)
  135. continue;
  136. lastanim->picnum = R_FlatNumForName (animdefs[i].endname);
  137. lastanim->basepic = R_FlatNumForName (animdefs[i].startname);
  138. }
  139. lastanim->istexture = animdefs[i].istexture;
  140. lastanim->numpics = lastanim->picnum - lastanim->basepic + 1;
  141. if (lastanim->numpics < 2)
  142. I_Error ("P_InitPicAnims: bad cycle from %s to %s",
  143. animdefs[i].startname,
  144. animdefs[i].endname);
  145. lastanim->speed = animdefs[i].speed;
  146. lastanim++;
  147. }
  148. }
  149. //
  150. // UTILITIES
  151. //
  152. //
  153. // getSide()
  154. // Will return a side_t*
  155. // given the number of the current sector,
  156. // the line number, and the side (0/1) that you want.
  157. //
  158. side_t*
  159. getSide
  160. ( int currentSector,
  161. int line,
  162. int side )
  163. {
  164. return &sides[ (sectors[currentSector].lines[line])->sidenum[side] ];
  165. }
  166. //
  167. // getSector()
  168. // Will return a sector_t*
  169. // given the number of the current sector,
  170. // the line number and the side (0/1) that you want.
  171. //
  172. sector_t*
  173. getSector
  174. ( int currentSector,
  175. int line,
  176. int side )
  177. {
  178. return sides[ (sectors[currentSector].lines[line])->sidenum[side] ].sector;
  179. }
  180. //
  181. // twoSided()
  182. // Given the sector number and the line number,
  183. // it will tell you whether the line is two-sided or not.
  184. //
  185. int
  186. twoSided
  187. ( int sector,
  188. int line )
  189. {
  190. return (sectors[sector].lines[line])->flags & ML_TWOSIDED;
  191. }
  192. //
  193. // getNextSector()
  194. // Return sector_t * of sector next to current.
  195. // NULL if not two-sided line
  196. //
  197. sector_t*
  198. getNextSector
  199. ( line_t* line,
  200. sector_t* sec )
  201. {
  202. if (!(line->flags & ML_TWOSIDED))
  203. return NULL;
  204. if (line->frontsector == sec)
  205. return line->backsector;
  206. return line->frontsector;
  207. }
  208. //
  209. // P_FindLowestFloorSurrounding()
  210. // FIND LOWEST FLOOR HEIGHT IN SURROUNDING SECTORS
  211. //
  212. fixed_t P_FindLowestFloorSurrounding(sector_t* sec)
  213. {
  214. int i;
  215. line_t* check;
  216. sector_t* other;
  217. fixed_t floor = sec->floorheight;
  218. for (i=0 ;i < sec->linecount ; i++)
  219. {
  220. check = sec->lines[i];
  221. other = getNextSector(check,sec);
  222. if (!other)
  223. continue;
  224. if (other->floorheight < floor)
  225. floor = other->floorheight;
  226. }
  227. return floor;
  228. }
  229. //
  230. // P_FindHighestFloorSurrounding()
  231. // FIND HIGHEST FLOOR HEIGHT IN SURROUNDING SECTORS
  232. //
  233. fixed_t P_FindHighestFloorSurrounding(sector_t *sec)
  234. {
  235. int i;
  236. line_t* check;
  237. sector_t* other;
  238. fixed_t floor = -500*FRACUNIT;
  239. for (i=0 ;i < sec->linecount ; i++)
  240. {
  241. check = sec->lines[i];
  242. other = getNextSector(check,sec);
  243. if (!other)
  244. continue;
  245. if (other->floorheight > floor)
  246. floor = other->floorheight;
  247. }
  248. return floor;
  249. }
  250. //
  251. // P_FindNextHighestFloor
  252. // FIND NEXT HIGHEST FLOOR IN SURROUNDING SECTORS
  253. // Note: this should be doable w/o a fixed array.
  254. // 20 adjoining sectors max!
  255. #define MAX_ADJOINING_SECTORS 20
  256. fixed_t
  257. P_FindNextHighestFloor
  258. ( sector_t* sec,
  259. int currentheight )
  260. {
  261. int i;
  262. int h;
  263. int min;
  264. line_t* check;
  265. sector_t* other;
  266. fixed_t height = currentheight;
  267. fixed_t heightlist[MAX_ADJOINING_SECTORS];
  268. for (i=0, h=0 ;i < sec->linecount ; i++)
  269. {
  270. check = sec->lines[i];
  271. other = getNextSector(check,sec);
  272. if (!other)
  273. continue;
  274. if (other->floorheight > height)
  275. heightlist[h++] = other->floorheight;
  276. // Check for overflow. Exit.
  277. if ( h >= MAX_ADJOINING_SECTORS )
  278. {
  279. fprintf( stderr,
  280. "Sector with more than 20 adjoining sectors\n" );
  281. break;
  282. }
  283. }
  284. // Find lowest height in list
  285. if (!h)
  286. return currentheight;
  287. min = heightlist[0];
  288. // Range checking?
  289. for (i = 1;i < h;i++)
  290. if (heightlist[i] < min)
  291. min = heightlist[i];
  292. return min;
  293. }
  294. //
  295. // FIND LOWEST CEILING IN THE SURROUNDING SECTORS
  296. //
  297. fixed_t
  298. P_FindLowestCeilingSurrounding(sector_t* sec)
  299. {
  300. int i;
  301. line_t* check;
  302. sector_t* other;
  303. fixed_t height = MAXINT;
  304. for (i=0 ;i < sec->linecount ; i++)
  305. {
  306. check = sec->lines[i];
  307. other = getNextSector(check,sec);
  308. if (!other)
  309. continue;
  310. if (other->ceilingheight < height)
  311. height = other->ceilingheight;
  312. }
  313. return height;
  314. }
  315. //
  316. // FIND HIGHEST CEILING IN THE SURROUNDING SECTORS
  317. //
  318. fixed_t P_FindHighestCeilingSurrounding(sector_t* sec)
  319. {
  320. int i;
  321. line_t* check;
  322. sector_t* other;
  323. fixed_t height = 0;
  324. for (i=0 ;i < sec->linecount ; i++)
  325. {
  326. check = sec->lines[i];
  327. other = getNextSector(check,sec);
  328. if (!other)
  329. continue;
  330. if (other->ceilingheight > height)
  331. height = other->ceilingheight;
  332. }
  333. return height;
  334. }
  335. //
  336. // RETURN NEXT SECTOR # THAT LINE TAG REFERS TO
  337. //
  338. int
  339. P_FindSectorFromLineTag
  340. ( line_t* line,
  341. int start )
  342. {
  343. int i;
  344. for (i=start+1;i<numsectors;i++)
  345. if (sectors[i].tag == line->tag)
  346. return i;
  347. return -1;
  348. }
  349. //
  350. // Find minimum light from an adjacent sector
  351. //
  352. int
  353. P_FindMinSurroundingLight
  354. ( sector_t* sector,
  355. int max )
  356. {
  357. int i;
  358. int min;
  359. line_t* line;
  360. sector_t* check;
  361. min = max;
  362. for (i=0 ; i < sector->linecount ; i++)
  363. {
  364. line = sector->lines[i];
  365. check = getNextSector(line,sector);
  366. if (!check)
  367. continue;
  368. if (check->lightlevel < min)
  369. min = check->lightlevel;
  370. }
  371. return min;
  372. }
  373. //
  374. // EVENTS
  375. // Events are operations triggered by using, crossing,
  376. // or shooting special lines, or by timed thinkers.
  377. //
  378. //
  379. // P_CrossSpecialLine - TRIGGER
  380. // Called every time a thing origin is about
  381. // to cross a line with a non 0 special.
  382. //
  383. void
  384. P_CrossSpecialLine
  385. ( int linenum,
  386. int side,
  387. mobj_t* thing )
  388. {
  389. line_t* line;
  390. int ok;
  391. line = &lines[linenum];
  392. // Triggers that other things can activate
  393. if (!thing->player)
  394. {
  395. // Things that should NOT trigger specials...
  396. switch(thing->type)
  397. {
  398. case MT_ROCKET:
  399. case MT_PLASMA:
  400. case MT_BFG:
  401. case MT_TROOPSHOT:
  402. case MT_HEADSHOT:
  403. case MT_BRUISERSHOT:
  404. return;
  405. break;
  406. default: break;
  407. }
  408. ok = 0;
  409. switch(line->special)
  410. {
  411. case 39: // TELEPORT TRIGGER
  412. case 97: // TELEPORT RETRIGGER
  413. case 125: // TELEPORT MONSTERONLY TRIGGER
  414. case 126: // TELEPORT MONSTERONLY RETRIGGER
  415. case 4: // RAISE DOOR
  416. case 10: // PLAT DOWN-WAIT-UP-STAY TRIGGER
  417. case 88: // PLAT DOWN-WAIT-UP-STAY RETRIGGER
  418. ok = 1;
  419. break;
  420. }
  421. if (!ok)
  422. return;
  423. }
  424. // Note: could use some const's here.
  425. switch (line->special)
  426. {
  427. // TRIGGERS.
  428. // All from here to RETRIGGERS.
  429. case 2:
  430. // Open Door
  431. EV_DoDoor(line,open);
  432. line->special = 0;
  433. break;
  434. case 3:
  435. // Close Door
  436. EV_DoDoor(line,close);
  437. line->special = 0;
  438. break;
  439. case 4:
  440. // Raise Door
  441. EV_DoDoor(line,normal);
  442. line->special = 0;
  443. break;
  444. case 5:
  445. // Raise Floor
  446. EV_DoFloor(line,raiseFloor);
  447. line->special = 0;
  448. break;
  449. case 6:
  450. // Fast Ceiling Crush & Raise
  451. EV_DoCeiling(line,fastCrushAndRaise);
  452. line->special = 0;
  453. break;
  454. case 8:
  455. // Build Stairs
  456. EV_BuildStairs(line,build8);
  457. line->special = 0;
  458. break;
  459. case 10:
  460. // PlatDownWaitUp
  461. EV_DoPlat(line,downWaitUpStay,0);
  462. line->special = 0;
  463. break;
  464. case 12:
  465. // Light Turn On - brightest near
  466. EV_LightTurnOn(line,0);
  467. line->special = 0;
  468. break;
  469. case 13:
  470. // Light Turn On 255
  471. EV_LightTurnOn(line,255);
  472. line->special = 0;
  473. break;
  474. case 16:
  475. // Close Door 30
  476. EV_DoDoor(line,close30ThenOpen);
  477. line->special = 0;
  478. break;
  479. case 17:
  480. // Start Light Strobing
  481. EV_StartLightStrobing(line);
  482. line->special = 0;
  483. break;
  484. case 19:
  485. // Lower Floor
  486. EV_DoFloor(line,lowerFloor);
  487. line->special = 0;
  488. break;
  489. case 22:
  490. // Raise floor to nearest height and change texture
  491. EV_DoPlat(line,raiseToNearestAndChange,0);
  492. line->special = 0;
  493. break;
  494. case 25:
  495. // Ceiling Crush and Raise
  496. EV_DoCeiling(line,crushAndRaise);
  497. line->special = 0;
  498. break;
  499. case 30:
  500. // Raise floor to shortest texture height
  501. // on either side of lines.
  502. EV_DoFloor(line,raiseToTexture);
  503. line->special = 0;
  504. break;
  505. case 35:
  506. // Lights Very Dark
  507. EV_LightTurnOn(line,35);
  508. line->special = 0;
  509. break;
  510. case 36:
  511. // Lower Floor (TURBO)
  512. EV_DoFloor(line,turboLower);
  513. line->special = 0;
  514. break;
  515. case 37:
  516. // LowerAndChange
  517. EV_DoFloor(line,lowerAndChange);
  518. line->special = 0;
  519. break;
  520. case 38:
  521. // Lower Floor To Lowest
  522. EV_DoFloor( line, lowerFloorToLowest );
  523. line->special = 0;
  524. break;
  525. case 39:
  526. // TELEPORT!
  527. EV_Teleport( line, side, thing );
  528. line->special = 0;
  529. break;
  530. case 40:
  531. // RaiseCeilingLowerFloor
  532. EV_DoCeiling( line, raiseToHighest );
  533. EV_DoFloor( line, lowerFloorToLowest );
  534. line->special = 0;
  535. break;
  536. case 44:
  537. // Ceiling Crush
  538. EV_DoCeiling( line, lowerAndCrush );
  539. line->special = 0;
  540. break;
  541. case 52:
  542. // EXIT!
  543. G_ExitLevel ();
  544. break;
  545. case 53:
  546. // Perpetual Platform Raise
  547. EV_DoPlat(line,perpetualRaise,0);
  548. line->special = 0;
  549. break;
  550. case 54:
  551. // Platform Stop
  552. EV_StopPlat(line);
  553. line->special = 0;
  554. break;
  555. case 56:
  556. // Raise Floor Crush
  557. EV_DoFloor(line,raiseFloorCrush);
  558. line->special = 0;
  559. break;
  560. case 57:
  561. // Ceiling Crush Stop
  562. EV_CeilingCrushStop(line);
  563. line->special = 0;
  564. break;
  565. case 58:
  566. // Raise Floor 24
  567. EV_DoFloor(line,raiseFloor24);
  568. line->special = 0;
  569. break;
  570. case 59:
  571. // Raise Floor 24 And Change
  572. EV_DoFloor(line,raiseFloor24AndChange);
  573. line->special = 0;
  574. break;
  575. case 104:
  576. // Turn lights off in sector(tag)
  577. EV_TurnTagLightsOff(line);
  578. line->special = 0;
  579. break;
  580. case 108:
  581. // Blazing Door Raise (faster than TURBO!)
  582. EV_DoDoor (line,blazeRaise);
  583. line->special = 0;
  584. break;
  585. case 109:
  586. // Blazing Door Open (faster than TURBO!)
  587. EV_DoDoor (line,blazeOpen);
  588. line->special = 0;
  589. break;
  590. case 100:
  591. // Build Stairs Turbo 16
  592. EV_BuildStairs(line,turbo16);
  593. line->special = 0;
  594. break;
  595. case 110:
  596. // Blazing Door Close (faster than TURBO!)
  597. EV_DoDoor (line,blazeClose);
  598. line->special = 0;
  599. break;
  600. case 119:
  601. // Raise floor to nearest surr. floor
  602. EV_DoFloor(line,raiseFloorToNearest);
  603. line->special = 0;
  604. break;
  605. case 121:
  606. // Blazing PlatDownWaitUpStay
  607. EV_DoPlat(line,blazeDWUS,0);
  608. line->special = 0;
  609. break;
  610. case 124:
  611. // Secret EXIT
  612. G_SecretExitLevel ();
  613. break;
  614. case 125:
  615. // TELEPORT MonsterONLY
  616. if (!thing->player)
  617. {
  618. EV_Teleport( line, side, thing );
  619. line->special = 0;
  620. }
  621. break;
  622. case 130:
  623. // Raise Floor Turbo
  624. EV_DoFloor(line,raiseFloorTurbo);
  625. line->special = 0;
  626. break;
  627. case 141:
  628. // Silent Ceiling Crush & Raise
  629. EV_DoCeiling(line,silentCrushAndRaise);
  630. line->special = 0;
  631. break;
  632. // RETRIGGERS. All from here till end.
  633. case 72:
  634. // Ceiling Crush
  635. EV_DoCeiling( line, lowerAndCrush );
  636. break;
  637. case 73:
  638. // Ceiling Crush and Raise
  639. EV_DoCeiling(line,crushAndRaise);
  640. break;
  641. case 74:
  642. // Ceiling Crush Stop
  643. EV_CeilingCrushStop(line);
  644. break;
  645. case 75:
  646. // Close Door
  647. EV_DoDoor(line,close);
  648. break;
  649. case 76:
  650. // Close Door 30
  651. EV_DoDoor(line,close30ThenOpen);
  652. break;
  653. case 77:
  654. // Fast Ceiling Crush & Raise
  655. EV_DoCeiling(line,fastCrushAndRaise);
  656. break;
  657. case 79:
  658. // Lights Very Dark
  659. EV_LightTurnOn(line,35);
  660. break;
  661. case 80:
  662. // Light Turn On - brightest near
  663. EV_LightTurnOn(line,0);
  664. break;
  665. case 81:
  666. // Light Turn On 255
  667. EV_LightTurnOn(line,255);
  668. break;
  669. case 82:
  670. // Lower Floor To Lowest
  671. EV_DoFloor( line, lowerFloorToLowest );
  672. break;
  673. case 83:
  674. // Lower Floor
  675. EV_DoFloor(line,lowerFloor);
  676. break;
  677. case 84:
  678. // LowerAndChange
  679. EV_DoFloor(line,lowerAndChange);
  680. break;
  681. case 86:
  682. // Open Door
  683. EV_DoDoor(line,open);
  684. break;
  685. case 87:
  686. // Perpetual Platform Raise
  687. EV_DoPlat(line,perpetualRaise,0);
  688. break;
  689. case 88:
  690. // PlatDownWaitUp
  691. EV_DoPlat(line,downWaitUpStay,0);
  692. break;
  693. case 89:
  694. // Platform Stop
  695. EV_StopPlat(line);
  696. break;
  697. case 90:
  698. // Raise Door
  699. EV_DoDoor(line,normal);
  700. break;
  701. case 91:
  702. // Raise Floor
  703. EV_DoFloor(line,raiseFloor);
  704. break;
  705. case 92:
  706. // Raise Floor 24
  707. EV_DoFloor(line,raiseFloor24);
  708. break;
  709. case 93:
  710. // Raise Floor 24 And Change
  711. EV_DoFloor(line,raiseFloor24AndChange);
  712. break;
  713. case 94:
  714. // Raise Floor Crush
  715. EV_DoFloor(line,raiseFloorCrush);
  716. break;
  717. case 95:
  718. // Raise floor to nearest height
  719. // and change texture.
  720. EV_DoPlat(line,raiseToNearestAndChange,0);
  721. break;
  722. case 96:
  723. // Raise floor to shortest texture height
  724. // on either side of lines.
  725. EV_DoFloor(line,raiseToTexture);
  726. break;
  727. case 97:
  728. // TELEPORT!
  729. EV_Teleport( line, side, thing );
  730. break;
  731. case 98:
  732. // Lower Floor (TURBO)
  733. EV_DoFloor(line,turboLower);
  734. break;
  735. case 105:
  736. // Blazing Door Raise (faster than TURBO!)
  737. EV_DoDoor (line,blazeRaise);
  738. break;
  739. case 106:
  740. // Blazing Door Open (faster than TURBO!)
  741. EV_DoDoor (line,blazeOpen);
  742. break;
  743. case 107:
  744. // Blazing Door Close (faster than TURBO!)
  745. EV_DoDoor (line,blazeClose);
  746. break;
  747. case 120:
  748. // Blazing PlatDownWaitUpStay.
  749. EV_DoPlat(line,blazeDWUS,0);
  750. break;
  751. case 126:
  752. // TELEPORT MonsterONLY.
  753. if (!thing->player)
  754. EV_Teleport( line, side, thing );
  755. break;
  756. case 128:
  757. // Raise To Nearest Floor
  758. EV_DoFloor(line,raiseFloorToNearest);
  759. break;
  760. case 129:
  761. // Raise Floor Turbo
  762. EV_DoFloor(line,raiseFloorTurbo);
  763. break;
  764. }
  765. }
  766. //
  767. // P_ShootSpecialLine - IMPACT SPECIALS
  768. // Called when a thing shoots a special line.
  769. //
  770. void
  771. P_ShootSpecialLine
  772. ( mobj_t* thing,
  773. line_t* line )
  774. {
  775. int ok;
  776. // Impacts that other things can activate.
  777. if (!thing->player)
  778. {
  779. ok = 0;
  780. switch(line->special)
  781. {
  782. case 46:
  783. // OPEN DOOR IMPACT
  784. ok = 1;
  785. break;
  786. }
  787. if (!ok)
  788. return;
  789. }
  790. switch(line->special)
  791. {
  792. case 24:
  793. // RAISE FLOOR
  794. EV_DoFloor(line,raiseFloor);
  795. P_ChangeSwitchTexture(line,0);
  796. break;
  797. case 46:
  798. // OPEN DOOR
  799. EV_DoDoor(line,open);
  800. P_ChangeSwitchTexture(line,1);
  801. break;
  802. case 47:
  803. // RAISE FLOOR NEAR AND CHANGE
  804. EV_DoPlat(line,raiseToNearestAndChange,0);
  805. P_ChangeSwitchTexture(line,0);
  806. break;
  807. }
  808. }
  809. //
  810. // P_PlayerInSpecialSector
  811. // Called every tic frame
  812. // that the player origin is in a special sector
  813. //
  814. void P_PlayerInSpecialSector (player_t* player)
  815. {
  816. sector_t* sector;
  817. sector = player->mo->subsector->sector;
  818. // Falling, not all the way down yet?
  819. if (player->mo->z != sector->floorheight)
  820. return;
  821. // Has hitten ground.
  822. switch (sector->special)
  823. {
  824. case 5:
  825. // HELLSLIME DAMAGE
  826. if (!player->powers[pw_ironfeet])
  827. if (!(leveltime&0x1f))
  828. P_DamageMobj (player->mo, NULL, NULL, 10);
  829. break;
  830. case 7:
  831. // NUKAGE DAMAGE
  832. if (!player->powers[pw_ironfeet])
  833. if (!(leveltime&0x1f))
  834. P_DamageMobj (player->mo, NULL, NULL, 5);
  835. break;
  836. case 16:
  837. // SUPER HELLSLIME DAMAGE
  838. case 4:
  839. // STROBE HURT
  840. if (!player->powers[pw_ironfeet]
  841. || (P_Random()<5) )
  842. {
  843. if (!(leveltime&0x1f))
  844. P_DamageMobj (player->mo, NULL, NULL, 20);
  845. }
  846. break;
  847. case 9:
  848. // SECRET SECTOR
  849. player->secretcount++;
  850. sector->special = 0;
  851. break;
  852. case 11:
  853. // EXIT SUPER DAMAGE! (for E1M8 finale)
  854. player->cheats &= ~CF_GODMODE;
  855. if (!(leveltime&0x1f))
  856. P_DamageMobj (player->mo, NULL, NULL, 20);
  857. if (player->health <= 10)
  858. G_ExitLevel();
  859. break;
  860. default:
  861. I_Error ("P_PlayerInSpecialSector: "
  862. "unknown special %i",
  863. sector->special);
  864. break;
  865. };
  866. }
  867. //
  868. // P_UpdateSpecials
  869. // Animate planes, scroll walls, etc.
  870. //
  871. boolean levelTimer;
  872. int levelTimeCount;
  873. void P_UpdateSpecials (void)
  874. {
  875. anim_t* anim;
  876. int pic;
  877. int i;
  878. line_t* line;
  879. // LEVEL TIMER
  880. if (levelTimer == true)
  881. {
  882. levelTimeCount--;
  883. if (!levelTimeCount)
  884. G_ExitLevel();
  885. }
  886. // ANIMATE FLATS AND TEXTURES GLOBALLY
  887. for (anim = anims ; anim < lastanim ; anim++)
  888. {
  889. for (i=anim->basepic ; i<anim->basepic+anim->numpics ; i++)
  890. {
  891. pic = anim->basepic + ( (leveltime/anim->speed + i)%anim->numpics );
  892. if (anim->istexture)
  893. texturetranslation[i] = pic;
  894. else
  895. flattranslation[i] = pic;
  896. }
  897. }
  898. // ANIMATE LINE SPECIALS
  899. for (i = 0; i < numlinespecials; i++)
  900. {
  901. line = linespeciallist[i];
  902. switch(line->special)
  903. {
  904. case 48:
  905. // EFFECT FIRSTCOL SCROLL +
  906. sides[line->sidenum[0]].textureoffset += FRACUNIT;
  907. break;
  908. }
  909. }
  910. // DO BUTTONS
  911. for (i = 0; i < MAXBUTTONS; i++)
  912. if (buttonlist[i].btimer)
  913. {
  914. buttonlist[i].btimer--;
  915. if (!buttonlist[i].btimer)
  916. {
  917. switch(buttonlist[i].where)
  918. {
  919. case top:
  920. sides[buttonlist[i].line->sidenum[0]].toptexture =
  921. buttonlist[i].btexture;
  922. break;
  923. case middle:
  924. sides[buttonlist[i].line->sidenum[0]].midtexture =
  925. buttonlist[i].btexture;
  926. break;
  927. case bottom:
  928. sides[buttonlist[i].line->sidenum[0]].bottomtexture =
  929. buttonlist[i].btexture;
  930. break;
  931. }
  932. S_StartSound((mobj_t *)&buttonlist[i].soundorg,sfx_swtchn);
  933. memset(&buttonlist[i],0,sizeof(button_t));
  934. }
  935. }
  936. }
  937. //
  938. // Special Stuff that can not be categorized
  939. //
  940. int EV_DoDonut(line_t* line)
  941. {
  942. sector_t* s1;
  943. sector_t* s2;
  944. sector_t* s3;
  945. int secnum;
  946. int rtn;
  947. int i;
  948. floormove_t* floor;
  949. secnum = -1;
  950. rtn = 0;
  951. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  952. {
  953. s1 = &sectors[secnum];
  954. // ALREADY MOVING? IF SO, KEEP GOING...
  955. if (s1->specialdata)
  956. continue;
  957. rtn = 1;
  958. s2 = getNextSector(s1->lines[0],s1);
  959. for (i = 0;i < s2->linecount;i++)
  960. {
  961. if ((!s2->lines[i]->flags & ML_TWOSIDED) ||
  962. (s2->lines[i]->backsector == s1))
  963. continue;
  964. s3 = s2->lines[i]->backsector;
  965. // Spawn rising slime
  966. floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
  967. P_AddThinker (&floor->thinker);
  968. s2->specialdata = floor;
  969. floor->thinker.function.acp1 = (actionf_p1) T_MoveFloor;
  970. floor->type = donutRaise;
  971. floor->crush = false;
  972. floor->direction = 1;
  973. floor->sector = s2;
  974. floor->speed = FLOORSPEED / 2;
  975. floor->texture = s3->floorpic;
  976. floor->newspecial = 0;
  977. floor->floordestheight = s3->floorheight;
  978. // Spawn lowering donut-hole
  979. floor = Z_Malloc (sizeof(*floor), PU_LEVSPEC, 0);
  980. P_AddThinker (&floor->thinker);
  981. s1->specialdata = floor;
  982. floor->thinker.function.acp1 = (actionf_p1) T_MoveFloor;
  983. floor->type = lowerFloor;
  984. floor->crush = false;
  985. floor->direction = -1;
  986. floor->sector = s1;
  987. floor->speed = FLOORSPEED / 2;
  988. floor->floordestheight = s3->floorheight;
  989. break;
  990. }
  991. }
  992. return rtn;
  993. }
  994. //
  995. // SPECIAL SPAWNING
  996. //
  997. //
  998. // P_SpawnSpecials
  999. // After the map has been loaded, scan for specials
  1000. // that spawn thinkers
  1001. //
  1002. short numlinespecials;
  1003. line_t* linespeciallist[MAXLINEANIMS];
  1004. // Parses command line parameters.
  1005. void P_SpawnSpecials (void)
  1006. {
  1007. sector_t* sector;
  1008. int i;
  1009. int episode;
  1010. episode = 1;
  1011. if (W_CheckNumForName("texture2") >= 0)
  1012. episode = 2;
  1013. // See if -TIMER needs to be used.
  1014. levelTimer = false;
  1015. i = M_CheckParm("-avg");
  1016. if (i && deathmatch)
  1017. {
  1018. levelTimer = true;
  1019. levelTimeCount = 20 * 60 * 35;
  1020. }
  1021. i = M_CheckParm("-timer");
  1022. if (i && deathmatch)
  1023. {
  1024. int time;
  1025. time = atoi(myargv[i+1]) * 60 * 35;
  1026. levelTimer = true;
  1027. levelTimeCount = time;
  1028. }
  1029. // Init special SECTORs.
  1030. sector = sectors;
  1031. for (i=0 ; i<numsectors ; i++, sector++)
  1032. {
  1033. if (!sector->special)
  1034. continue;
  1035. switch (sector->special)
  1036. {
  1037. case 1:
  1038. // FLICKERING LIGHTS
  1039. P_SpawnLightFlash (sector);
  1040. break;
  1041. case 2:
  1042. // STROBE FAST
  1043. P_SpawnStrobeFlash(sector,FASTDARK,0);
  1044. break;
  1045. case 3:
  1046. // STROBE SLOW
  1047. P_SpawnStrobeFlash(sector,SLOWDARK,0);
  1048. break;
  1049. case 4:
  1050. // STROBE FAST/DEATH SLIME
  1051. P_SpawnStrobeFlash(sector,FASTDARK,0);
  1052. sector->special = 4;
  1053. break;
  1054. case 8:
  1055. // GLOWING LIGHT
  1056. P_SpawnGlowingLight(sector);
  1057. break;
  1058. case 9:
  1059. // SECRET SECTOR
  1060. totalsecret++;
  1061. break;
  1062. case 10:
  1063. // DOOR CLOSE IN 30 SECONDS
  1064. P_SpawnDoorCloseIn30 (sector);
  1065. break;
  1066. case 12:
  1067. // SYNC STROBE SLOW
  1068. P_SpawnStrobeFlash (sector, SLOWDARK, 1);
  1069. break;
  1070. case 13:
  1071. // SYNC STROBE FAST
  1072. P_SpawnStrobeFlash (sector, FASTDARK, 1);
  1073. break;
  1074. case 14:
  1075. // DOOR RAISE IN 5 MINUTES
  1076. P_SpawnDoorRaiseIn5Mins (sector, i);
  1077. break;
  1078. case 17:
  1079. P_SpawnFireFlicker(sector);
  1080. break;
  1081. }
  1082. }
  1083. // Init line EFFECTs
  1084. numlinespecials = 0;
  1085. for (i = 0;i < numlines; i++)
  1086. {
  1087. switch(lines[i].special)
  1088. {
  1089. case 48:
  1090. // EFFECT FIRSTCOL SCROLL+
  1091. linespeciallist[numlinespecials] = &lines[i];
  1092. numlinespecials++;
  1093. break;
  1094. }
  1095. }
  1096. // Init other misc stuff
  1097. for (i = 0;i < MAXCEILINGS;i++)
  1098. activeceilings[i] = NULL;
  1099. for (i = 0;i < MAXPLATS;i++)
  1100. activeplats[i] = NULL;
  1101. for (i = 0;i < MAXBUTTONS;i++)
  1102. memset(&buttonlist[i],0,sizeof(button_t));
  1103. // UNUSED: no horizonal sliders.
  1104. // P_InitSlidingDoorFrames();
  1105. }