P_SWITCH.C 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. #include "DoomDef.h"
  2. #include "P_local.h"
  3. #include "soundst.h"
  4. //==================================================================
  5. //
  6. // CHANGE THE TEXTURE OF A WALL SWITCH TO ITS OPPOSITE
  7. //
  8. //==================================================================
  9. switchlist_t alphSwitchList[] =
  10. {
  11. {"SW1OFF", "SW1ON", 1},
  12. {"SW2OFF", "SW2ON", 1},
  13. /*
  14. {"SW1CTY", "SW2CTY", 1},
  15. {"SW1ORGRY", "SW2ORGRY", 1},
  16. {"SW1GRSTN", "SW2GRSTN", 1},
  17. {"SW1SNDP", "SW2SNDP", 1},
  18. {"SW1SPINE", "SW2SPINE", 1},
  19. {"SW1SQPEB", "SW2SQPEB", 1},
  20. {"SW1TRST1", "SW2TRST1", 1},
  21. {"SW1CSTL", "SW2CSTL", 1},
  22. {"SW1MOSS", "SW2MOSS", 1},
  23. {"SW1SNDSQ", "SW2SNDSQ", 1},
  24. {"SW1RED", "SW2RED", 1},
  25. {"SW1WOOD", "SW2WOOD", 1},
  26. {"SW1BROWN", "SW2BROWN", 1},
  27. {"SW1TRST2", "SW2TRST2", 2},
  28. {"SW1MSC", "SW2MSC", 2},
  29. {"SW1MSC2", "SW2MSC2", 2},
  30. {"SW1GRDMD", "SW2GRDMD", 2},
  31. */
  32. #if 0
  33. {"SW1BRCOM", "SW2BRCOM", 1},
  34. {"SW1BRN1", "SW2BRN1", 1},
  35. {"SW1BRN2", "SW2BRN2", 1},
  36. {"SW1BRNGN", "SW2BRNGN", 1},
  37. {"SW1BROWN", "SW2BROWN", 1},
  38. {"SW1COMM", "SW2COMM", 1},
  39. {"SW1COMP", "SW2COMP", 1},
  40. {"SW1DIRT", "SW2DIRT", 1},
  41. {"SW1EXIT", "SW2EXIT", 1},
  42. {"SW1GRAY", "SW2GRAY", 1},
  43. {"SW1GRAY1", "SW2GRAY1", 1},
  44. {"SW1METAL", "SW2METAL", 1},
  45. {"SW1PIPE", "SW2PIPE", 1},
  46. {"SW1SLAD", "SW2SLAD", 1},
  47. {"SW1STARG", "SW2STARG", 1},
  48. {"SW1STON1", "SW2STON1", 1},
  49. {"SW1STON2", "SW2STON2", 1},
  50. {"SW1STONE", "SW2STONE", 1},
  51. {"SW1STRTN", "SW2STRTN", 1},
  52. {"SW1BLUE", "SW2BLUE", 2},
  53. {"SW1CMT", "SW2CMT", 2},
  54. {"SW1GARG", "SW2GARG", 2},
  55. {"SW1GSTON", "SW2GSTON", 2},
  56. {"SW1HOT", "SW2HOT", 2},
  57. {"SW1LION", "SW2LION", 2},
  58. {"SW1SATYR", "SW2SATYR", 2},
  59. {"SW1SKIN", "SW2SKIN", 2},
  60. {"SW1VINE", "SW2VINE", 2},
  61. {"SW1WOOD", "SW2WOOD", 2},
  62. #endif
  63. {"\0", "\0", 0}
  64. };
  65. int switchlist[MAXSWITCHES * 2];
  66. int numswitches;
  67. button_t buttonlist[MAXBUTTONS];
  68. /*
  69. ===============
  70. =
  71. = P_InitSwitchList
  72. =
  73. = Only called at game initialization
  74. =
  75. ===============
  76. */
  77. void P_InitSwitchList(void)
  78. {
  79. int i;
  80. int index;
  81. int episode;
  82. episode = 1;
  83. if (!shareware)
  84. episode = 2;
  85. for (index = 0,i = 0;i < MAXSWITCHES;i++)
  86. {
  87. if (!alphSwitchList[i].episode)
  88. {
  89. numswitches = index/2;
  90. switchlist[index] = -1;
  91. break;
  92. }
  93. if (alphSwitchList[i].episode <= episode)
  94. {
  95. switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name1);
  96. switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name2);
  97. }
  98. }
  99. }
  100. //==================================================================
  101. //
  102. // Start a button counting down till it turns off.
  103. //
  104. //==================================================================
  105. void P_StartButton(line_t *line,bwhere_e w,int texture,int time)
  106. {
  107. int i;
  108. for (i = 0;i < MAXBUTTONS;i++)
  109. if (!buttonlist[i].btimer)
  110. {
  111. buttonlist[i].line = line;
  112. buttonlist[i].where = w;
  113. buttonlist[i].btexture = texture;
  114. buttonlist[i].btimer = time;
  115. buttonlist[i].soundorg = (mobj_t *)&line->frontsector->soundorg;
  116. return;
  117. }
  118. I_Error("P_StartButton: no button slots left!");
  119. }
  120. //==================================================================
  121. //
  122. // Function that changes wall texture.
  123. // Tell it if switch is ok to use again (1=yes, it's a button).
  124. //
  125. //==================================================================
  126. void P_ChangeSwitchTexture(line_t *line,int useAgain)
  127. {
  128. int texTop;
  129. int texMid;
  130. int texBot;
  131. int i;
  132. int sound;
  133. if (!useAgain)
  134. line->special = 0;
  135. texTop = sides[line->sidenum[0]].toptexture;
  136. texMid = sides[line->sidenum[0]].midtexture;
  137. texBot = sides[line->sidenum[0]].bottomtexture;
  138. sound = sfx_switch;
  139. //if (line->special == 11) // EXIT SWITCH?
  140. // sound = sfx_swtchx;
  141. for (i = 0;i < numswitches*2;i++)
  142. if (switchlist[i] == texTop)
  143. {
  144. S_StartSound(buttonlist->soundorg,sound);
  145. sides[line->sidenum[0]].toptexture = switchlist[i^1];
  146. if (useAgain)
  147. P_StartButton(line,top,switchlist[i],BUTTONTIME);
  148. return;
  149. }
  150. else
  151. if (switchlist[i] == texMid)
  152. {
  153. S_StartSound(buttonlist->soundorg,sound);
  154. sides[line->sidenum[0]].midtexture = switchlist[i^1];
  155. if (useAgain)
  156. P_StartButton(line, middle,switchlist[i],BUTTONTIME);
  157. return;
  158. }
  159. else
  160. if (switchlist[i] == texBot)
  161. {
  162. S_StartSound(buttonlist->soundorg,sound);
  163. sides[line->sidenum[0]].bottomtexture = switchlist[i^1];
  164. if (useAgain)
  165. P_StartButton(line, bottom,switchlist[i],BUTTONTIME);
  166. return;
  167. }
  168. }
  169. /*
  170. ==============================================================================
  171. =
  172. = P_UseSpecialLine
  173. =
  174. = Called when a thing uses a special line
  175. = Only the front sides of lines are usable
  176. ===============================================================================
  177. */
  178. boolean P_UseSpecialLine ( mobj_t *thing, line_t *line)
  179. {
  180. //
  181. // Switches that other things can activate
  182. //
  183. if (!thing->player)
  184. {
  185. if (line->flags & ML_SECRET)
  186. return false; // never open secret doors
  187. switch(line->special)
  188. {
  189. case 1: // MANUAL DOOR RAISE
  190. case 32: // MANUAL BLUE
  191. case 33: // MANUAL RED
  192. case 34: // MANUAL YELLOW
  193. break;
  194. default:
  195. return false;
  196. }
  197. }
  198. //
  199. // do something
  200. //
  201. switch (line->special)
  202. {
  203. //===============================================
  204. // MANUALS
  205. //===============================================
  206. case 1: // Vertical Door
  207. case 26: // Blue Door/Locked
  208. case 27: // Yellow Door /Locked
  209. case 28: // Red Door /Locked
  210. case 31: // Manual door open
  211. case 32: // Blue locked door open
  212. case 33: // Red locked door open
  213. case 34: // Yellow locked door open
  214. EV_VerticalDoor (line, thing);
  215. break;
  216. //===============================================
  217. // SWITCHES
  218. //===============================================
  219. case 7: // Switch_Build_Stairs (8 pixel steps)
  220. if(EV_BuildStairs(line, 8*FRACUNIT))
  221. {
  222. P_ChangeSwitchTexture(line, 0);
  223. }
  224. break;
  225. case 107: // Switch_Build_Stairs_16 (16 pixel steps)
  226. if(EV_BuildStairs(line, 16*FRACUNIT))
  227. {
  228. P_ChangeSwitchTexture(line, 0);
  229. }
  230. break;
  231. case 9: // Change Donut
  232. if (EV_DoDonut(line))
  233. P_ChangeSwitchTexture(line,0);
  234. break;
  235. case 11: // Exit level
  236. G_ExitLevel ();
  237. P_ChangeSwitchTexture(line,0);
  238. break;
  239. case 14: // Raise Floor 32 and change texture
  240. if (EV_DoPlat(line,raiseAndChange,32))
  241. P_ChangeSwitchTexture(line,0);
  242. break;
  243. case 15: // Raise Floor 24 and change texture
  244. if (EV_DoPlat(line,raiseAndChange,24))
  245. P_ChangeSwitchTexture(line,0);
  246. break;
  247. case 18: // Raise Floor to next highest floor
  248. if (EV_DoFloor(line, raiseFloorToNearest))
  249. P_ChangeSwitchTexture(line,0);
  250. break;
  251. case 20: // Raise Plat next highest floor and change texture
  252. if (EV_DoPlat(line,raiseToNearestAndChange,0))
  253. P_ChangeSwitchTexture(line,0);
  254. break;
  255. case 21: // PlatDownWaitUpStay
  256. if (EV_DoPlat(line,downWaitUpStay,0))
  257. P_ChangeSwitchTexture(line,0);
  258. break;
  259. case 23: // Lower Floor to Lowest
  260. if (EV_DoFloor(line,lowerFloorToLowest))
  261. P_ChangeSwitchTexture(line,0);
  262. break;
  263. case 29: // Raise Door
  264. if (EV_DoDoor(line,normal,VDOORSPEED))
  265. P_ChangeSwitchTexture(line,0);
  266. break;
  267. case 41: // Lower Ceiling to Floor
  268. if (EV_DoCeiling(line,lowerToFloor))
  269. P_ChangeSwitchTexture(line,0);
  270. break;
  271. case 71: // Turbo Lower Floor
  272. if (EV_DoFloor(line,turboLower))
  273. P_ChangeSwitchTexture(line,0);
  274. break;
  275. case 49: // Lower Ceiling And Crush
  276. if (EV_DoCeiling(line,lowerAndCrush))
  277. P_ChangeSwitchTexture(line,0);
  278. break;
  279. case 50: // Close Door
  280. if (EV_DoDoor(line,close,VDOORSPEED))
  281. P_ChangeSwitchTexture(line,0);
  282. break;
  283. case 51: // Secret EXIT
  284. G_SecretExitLevel ();
  285. P_ChangeSwitchTexture(line,0);
  286. break;
  287. case 55: // Raise Floor Crush
  288. if (EV_DoFloor(line,raiseFloorCrush))
  289. P_ChangeSwitchTexture(line,0);
  290. break;
  291. case 101: // Raise Floor
  292. if (EV_DoFloor(line,raiseFloor))
  293. P_ChangeSwitchTexture(line,0);
  294. break;
  295. case 102: // Lower Floor to Surrounding floor height
  296. if (EV_DoFloor(line,lowerFloor))
  297. P_ChangeSwitchTexture(line,0);
  298. break;
  299. case 103: // Open Door
  300. if (EV_DoDoor(line,open,VDOORSPEED))
  301. P_ChangeSwitchTexture(line,0);
  302. break;
  303. //===============================================
  304. // BUTTONS
  305. //===============================================
  306. case 42: // Close Door
  307. if (EV_DoDoor(line,close,VDOORSPEED))
  308. P_ChangeSwitchTexture(line,1);
  309. break;
  310. case 43: // Lower Ceiling to Floor
  311. if (EV_DoCeiling(line,lowerToFloor))
  312. P_ChangeSwitchTexture(line,1);
  313. break;
  314. case 45: // Lower Floor to Surrounding floor height
  315. if (EV_DoFloor(line,lowerFloor))
  316. P_ChangeSwitchTexture(line,1);
  317. break;
  318. case 60: // Lower Floor to Lowest
  319. if (EV_DoFloor(line,lowerFloorToLowest))
  320. P_ChangeSwitchTexture(line,1);
  321. break;
  322. case 61: // Open Door
  323. if (EV_DoDoor(line,open,VDOORSPEED))
  324. P_ChangeSwitchTexture(line,1);
  325. break;
  326. case 62: // PlatDownWaitUpStay
  327. if (EV_DoPlat(line,downWaitUpStay,1))
  328. P_ChangeSwitchTexture(line,1);
  329. break;
  330. case 63: // Raise Door
  331. if (EV_DoDoor(line,normal,VDOORSPEED))
  332. P_ChangeSwitchTexture(line,1);
  333. break;
  334. case 64: // Raise Floor to ceiling
  335. if (EV_DoFloor(line,raiseFloor))
  336. P_ChangeSwitchTexture(line,1);
  337. break;
  338. case 66: // Raise Floor 24 and change texture
  339. if (EV_DoPlat(line,raiseAndChange,24))
  340. P_ChangeSwitchTexture(line,1);
  341. break;
  342. case 67: // Raise Floor 32 and change texture
  343. if (EV_DoPlat(line,raiseAndChange,32))
  344. P_ChangeSwitchTexture(line,1);
  345. break;
  346. case 65: // Raise Floor Crush
  347. if (EV_DoFloor(line,raiseFloorCrush))
  348. P_ChangeSwitchTexture(line,1);
  349. break;
  350. case 68: // Raise Plat to next highest floor and change texture
  351. if (EV_DoPlat(line,raiseToNearestAndChange,0))
  352. P_ChangeSwitchTexture(line,1);
  353. break;
  354. case 69: // Raise Floor to next highest floor
  355. if (EV_DoFloor(line, raiseFloorToNearest))
  356. P_ChangeSwitchTexture(line,1);
  357. break;
  358. case 70: // Turbo Lower Floor
  359. if (EV_DoFloor(line,turboLower))
  360. P_ChangeSwitchTexture(line,1);
  361. break;
  362. }
  363. return true;
  364. }