p_ceilng.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "Precompiled.h"
  21. #include "globaldata.h"
  22. #include "z_zone.h"
  23. #include "doomdef.h"
  24. #include "p_local.h"
  25. #include "s_sound.h"
  26. // State.
  27. #include "doomstat.h"
  28. #include "r_state.h"
  29. // Data.
  30. #include "sounds.h"
  31. //
  32. // CEILINGS
  33. //
  34. //
  35. // T_MoveCeiling
  36. //
  37. void T_MoveCeiling (ceiling_t* ceiling)
  38. {
  39. result_e res;
  40. switch(ceiling->direction)
  41. {
  42. case 0:
  43. // IN STASIS
  44. break;
  45. case 1:
  46. // UP
  47. res = T_MovePlane(ceiling->sector,
  48. ceiling->speed,
  49. ceiling->topheight,
  50. false,1,ceiling->direction);
  51. if (!(::g->leveltime&7))
  52. {
  53. switch(ceiling->type)
  54. {
  55. case silentCrushAndRaise:
  56. break;
  57. default:
  58. S_StartSound( &ceiling->sector->soundorg,
  59. sfx_stnmov);
  60. // ?
  61. break;
  62. }
  63. }
  64. if (res == pastdest)
  65. {
  66. switch(ceiling->type)
  67. {
  68. case raiseToHighest:
  69. P_RemoveActiveCeiling(ceiling);
  70. break;
  71. case silentCrushAndRaise:
  72. S_StartSound( &ceiling->sector->soundorg,
  73. sfx_pstop);
  74. case fastCrushAndRaise:
  75. case crushAndRaise:
  76. ceiling->direction = -1;
  77. break;
  78. default:
  79. break;
  80. }
  81. }
  82. break;
  83. case -1:
  84. // DOWN
  85. res = T_MovePlane(ceiling->sector,
  86. ceiling->speed,
  87. ceiling->bottomheight,
  88. ceiling->crush,1,ceiling->direction);
  89. if (!(::g->leveltime&7))
  90. {
  91. switch(ceiling->type)
  92. {
  93. case silentCrushAndRaise: break;
  94. default:
  95. S_StartSound( &ceiling->sector->soundorg,
  96. sfx_stnmov);
  97. }
  98. }
  99. if (res == pastdest)
  100. {
  101. switch(ceiling->type)
  102. {
  103. case silentCrushAndRaise:
  104. S_StartSound( &ceiling->sector->soundorg,
  105. sfx_pstop);
  106. case crushAndRaise:
  107. ceiling->speed = CEILSPEED;
  108. case fastCrushAndRaise:
  109. ceiling->direction = 1;
  110. break;
  111. case lowerAndCrush:
  112. case lowerToFloor:
  113. P_RemoveActiveCeiling(ceiling);
  114. break;
  115. default:
  116. break;
  117. }
  118. }
  119. else // ( res != pastdest )
  120. {
  121. if (res == crushed)
  122. {
  123. switch(ceiling->type)
  124. {
  125. case silentCrushAndRaise:
  126. case crushAndRaise:
  127. case lowerAndCrush:
  128. ceiling->speed = CEILSPEED / 8;
  129. break;
  130. default:
  131. break;
  132. }
  133. }
  134. }
  135. break;
  136. }
  137. }
  138. //
  139. // EV_DoCeiling
  140. // Move a ceiling up/down and all around!
  141. //
  142. int
  143. EV_DoCeiling
  144. ( line_t* line,
  145. ceiling_e type )
  146. {
  147. int secnum;
  148. int rtn;
  149. sector_t* sec;
  150. ceiling_t* ceiling;
  151. secnum = -1;
  152. rtn = 0;
  153. // Reactivate in-stasis ceilings...for certain types.
  154. switch(type)
  155. {
  156. case fastCrushAndRaise:
  157. case silentCrushAndRaise:
  158. case crushAndRaise:
  159. P_ActivateInStasisCeiling(line);
  160. default:
  161. break;
  162. }
  163. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  164. {
  165. sec = &::g->sectors[secnum];
  166. if (sec->specialdata)
  167. continue;
  168. // new door thinker
  169. rtn = 1;
  170. ceiling = (ceiling_t*)DoomLib::Z_Malloc(sizeof(*ceiling), PU_LEVEL, 0);
  171. P_AddThinker (&ceiling->thinker);
  172. sec->specialdata = ceiling;
  173. ceiling->thinker.function.acp1 = (actionf_p1)T_MoveCeiling;
  174. ceiling->sector = sec;
  175. ceiling->crush = false;
  176. switch(type)
  177. {
  178. case fastCrushAndRaise:
  179. ceiling->crush = true;
  180. ceiling->topheight = sec->ceilingheight;
  181. ceiling->bottomheight = sec->floorheight + (8*FRACUNIT);
  182. ceiling->direction = -1;
  183. ceiling->speed = CEILSPEED * 2;
  184. break;
  185. case silentCrushAndRaise:
  186. case crushAndRaise:
  187. ceiling->crush = true;
  188. ceiling->topheight = sec->ceilingheight;
  189. case lowerAndCrush:
  190. case lowerToFloor:
  191. ceiling->bottomheight = sec->floorheight;
  192. if (type != lowerToFloor)
  193. ceiling->bottomheight += 8*FRACUNIT;
  194. ceiling->direction = -1;
  195. ceiling->speed = CEILSPEED;
  196. break;
  197. case raiseToHighest:
  198. ceiling->topheight = P_FindHighestCeilingSurrounding(sec);
  199. ceiling->direction = 1;
  200. ceiling->speed = CEILSPEED;
  201. break;
  202. }
  203. ceiling->tag = sec->tag;
  204. ceiling->type = type;
  205. P_AddActiveCeiling(ceiling);
  206. }
  207. return rtn;
  208. }
  209. //
  210. // Add an active ceiling
  211. //
  212. void P_AddActiveCeiling(ceiling_t* c)
  213. {
  214. int i;
  215. for (i = 0; i < MAXCEILINGS;i++)
  216. {
  217. if (::g->activeceilings[i] == NULL)
  218. {
  219. ::g->activeceilings[i] = c;
  220. return;
  221. }
  222. }
  223. }
  224. //
  225. // Remove a ceiling's thinker
  226. //
  227. void P_RemoveActiveCeiling(ceiling_t* c)
  228. {
  229. int i;
  230. for (i = 0;i < MAXCEILINGS;i++)
  231. {
  232. if (::g->activeceilings[i] == c)
  233. {
  234. ::g->activeceilings[i]->sector->specialdata = NULL;
  235. P_RemoveThinker (&::g->activeceilings[i]->thinker);
  236. ::g->activeceilings[i] = NULL;
  237. break;
  238. }
  239. }
  240. }
  241. //
  242. // Restart a ceiling that's in-stasis
  243. //
  244. void P_ActivateInStasisCeiling(line_t* line)
  245. {
  246. int i;
  247. for (i = 0;i < MAXCEILINGS;i++)
  248. {
  249. if (::g->activeceilings[i]
  250. && (::g->activeceilings[i]->tag == line->tag)
  251. && (::g->activeceilings[i]->direction == 0))
  252. {
  253. ::g->activeceilings[i]->direction = ::g->activeceilings[i]->olddirection;
  254. ::g->activeceilings[i]->thinker.function.acp1
  255. = (actionf_p1)T_MoveCeiling;
  256. }
  257. }
  258. }
  259. //
  260. // EV_CeilingCrushStop
  261. // Stop a ceiling from crushing!
  262. //
  263. int EV_CeilingCrushStop(line_t *line)
  264. {
  265. int i;
  266. int rtn;
  267. rtn = 0;
  268. for (i = 0;i < MAXCEILINGS;i++)
  269. {
  270. if (::g->activeceilings[i]
  271. && (::g->activeceilings[i]->tag == line->tag)
  272. && (::g->activeceilings[i]->direction != 0))
  273. {
  274. ::g->activeceilings[i]->olddirection = ::g->activeceilings[i]->direction;
  275. ::g->activeceilings[i]->thinker.function.acv = (actionf_v)NULL;
  276. ::g->activeceilings[i]->direction = 0; // in-stasis
  277. rtn = 1;
  278. }
  279. }
  280. return rtn;
  281. }