p_ceilng.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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: Ceiling aninmation (lowering, crushing, raising)
  20. //
  21. //-----------------------------------------------------------------------------
  22. static const char
  23. rcsid[] = "$Id: p_ceilng.c,v 1.4 1997/02/03 16:47:53 b1 Exp $";
  24. #include "z_zone.h"
  25. #include "doomdef.h"
  26. #include "p_local.h"
  27. #include "s_sound.h"
  28. // State.
  29. #include "doomstat.h"
  30. #include "r_state.h"
  31. // Data.
  32. #include "sounds.h"
  33. //
  34. // CEILINGS
  35. //
  36. ceiling_t* activeceilings[MAXCEILINGS];
  37. //
  38. // T_MoveCeiling
  39. //
  40. void T_MoveCeiling (ceiling_t* ceiling)
  41. {
  42. result_e res;
  43. switch(ceiling->direction)
  44. {
  45. case 0:
  46. // IN STASIS
  47. break;
  48. case 1:
  49. // UP
  50. res = T_MovePlane(ceiling->sector,
  51. ceiling->speed,
  52. ceiling->topheight,
  53. false,1,ceiling->direction);
  54. if (!(leveltime&7))
  55. {
  56. switch(ceiling->type)
  57. {
  58. case silentCrushAndRaise:
  59. break;
  60. default:
  61. S_StartSound((mobj_t *)&ceiling->sector->soundorg,
  62. sfx_stnmov);
  63. // ?
  64. break;
  65. }
  66. }
  67. if (res == pastdest)
  68. {
  69. switch(ceiling->type)
  70. {
  71. case raiseToHighest:
  72. P_RemoveActiveCeiling(ceiling);
  73. break;
  74. case silentCrushAndRaise:
  75. S_StartSound((mobj_t *)&ceiling->sector->soundorg,
  76. sfx_pstop);
  77. case fastCrushAndRaise:
  78. case crushAndRaise:
  79. ceiling->direction = -1;
  80. break;
  81. default:
  82. break;
  83. }
  84. }
  85. break;
  86. case -1:
  87. // DOWN
  88. res = T_MovePlane(ceiling->sector,
  89. ceiling->speed,
  90. ceiling->bottomheight,
  91. ceiling->crush,1,ceiling->direction);
  92. if (!(leveltime&7))
  93. {
  94. switch(ceiling->type)
  95. {
  96. case silentCrushAndRaise: break;
  97. default:
  98. S_StartSound((mobj_t *)&ceiling->sector->soundorg,
  99. sfx_stnmov);
  100. }
  101. }
  102. if (res == pastdest)
  103. {
  104. switch(ceiling->type)
  105. {
  106. case silentCrushAndRaise:
  107. S_StartSound((mobj_t *)&ceiling->sector->soundorg,
  108. sfx_pstop);
  109. case crushAndRaise:
  110. ceiling->speed = CEILSPEED;
  111. case fastCrushAndRaise:
  112. ceiling->direction = 1;
  113. break;
  114. case lowerAndCrush:
  115. case lowerToFloor:
  116. P_RemoveActiveCeiling(ceiling);
  117. break;
  118. default:
  119. break;
  120. }
  121. }
  122. else // ( res != pastdest )
  123. {
  124. if (res == crushed)
  125. {
  126. switch(ceiling->type)
  127. {
  128. case silentCrushAndRaise:
  129. case crushAndRaise:
  130. case lowerAndCrush:
  131. ceiling->speed = CEILSPEED / 8;
  132. break;
  133. default:
  134. break;
  135. }
  136. }
  137. }
  138. break;
  139. }
  140. }
  141. //
  142. // EV_DoCeiling
  143. // Move a ceiling up/down and all around!
  144. //
  145. int
  146. EV_DoCeiling
  147. ( line_t* line,
  148. ceiling_e type )
  149. {
  150. int secnum;
  151. int rtn;
  152. sector_t* sec;
  153. ceiling_t* ceiling;
  154. secnum = -1;
  155. rtn = 0;
  156. // Reactivate in-stasis ceilings...for certain types.
  157. switch(type)
  158. {
  159. case fastCrushAndRaise:
  160. case silentCrushAndRaise:
  161. case crushAndRaise:
  162. P_ActivateInStasisCeiling(line);
  163. default:
  164. break;
  165. }
  166. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  167. {
  168. sec = &sectors[secnum];
  169. if (sec->specialdata)
  170. continue;
  171. // new door thinker
  172. rtn = 1;
  173. ceiling = Z_Malloc (sizeof(*ceiling), PU_LEVSPEC, 0);
  174. P_AddThinker (&ceiling->thinker);
  175. sec->specialdata = ceiling;
  176. ceiling->thinker.function.acp1 = (actionf_p1)T_MoveCeiling;
  177. ceiling->sector = sec;
  178. ceiling->crush = false;
  179. switch(type)
  180. {
  181. case fastCrushAndRaise:
  182. ceiling->crush = true;
  183. ceiling->topheight = sec->ceilingheight;
  184. ceiling->bottomheight = sec->floorheight + (8*FRACUNIT);
  185. ceiling->direction = -1;
  186. ceiling->speed = CEILSPEED * 2;
  187. break;
  188. case silentCrushAndRaise:
  189. case crushAndRaise:
  190. ceiling->crush = true;
  191. ceiling->topheight = sec->ceilingheight;
  192. case lowerAndCrush:
  193. case lowerToFloor:
  194. ceiling->bottomheight = sec->floorheight;
  195. if (type != lowerToFloor)
  196. ceiling->bottomheight += 8*FRACUNIT;
  197. ceiling->direction = -1;
  198. ceiling->speed = CEILSPEED;
  199. break;
  200. case raiseToHighest:
  201. ceiling->topheight = P_FindHighestCeilingSurrounding(sec);
  202. ceiling->direction = 1;
  203. ceiling->speed = CEILSPEED;
  204. break;
  205. }
  206. ceiling->tag = sec->tag;
  207. ceiling->type = type;
  208. P_AddActiveCeiling(ceiling);
  209. }
  210. return rtn;
  211. }
  212. //
  213. // Add an active ceiling
  214. //
  215. void P_AddActiveCeiling(ceiling_t* c)
  216. {
  217. int i;
  218. for (i = 0; i < MAXCEILINGS;i++)
  219. {
  220. if (activeceilings[i] == NULL)
  221. {
  222. activeceilings[i] = c;
  223. return;
  224. }
  225. }
  226. }
  227. //
  228. // Remove a ceiling's thinker
  229. //
  230. void P_RemoveActiveCeiling(ceiling_t* c)
  231. {
  232. int i;
  233. for (i = 0;i < MAXCEILINGS;i++)
  234. {
  235. if (activeceilings[i] == c)
  236. {
  237. activeceilings[i]->sector->specialdata = NULL;
  238. P_RemoveThinker (&activeceilings[i]->thinker);
  239. activeceilings[i] = NULL;
  240. break;
  241. }
  242. }
  243. }
  244. //
  245. // Restart a ceiling that's in-stasis
  246. //
  247. void P_ActivateInStasisCeiling(line_t* line)
  248. {
  249. int i;
  250. for (i = 0;i < MAXCEILINGS;i++)
  251. {
  252. if (activeceilings[i]
  253. && (activeceilings[i]->tag == line->tag)
  254. && (activeceilings[i]->direction == 0))
  255. {
  256. activeceilings[i]->direction = activeceilings[i]->olddirection;
  257. activeceilings[i]->thinker.function.acp1
  258. = (actionf_p1)T_MoveCeiling;
  259. }
  260. }
  261. }
  262. //
  263. // EV_CeilingCrushStop
  264. // Stop a ceiling from crushing!
  265. //
  266. int EV_CeilingCrushStop(line_t *line)
  267. {
  268. int i;
  269. int rtn;
  270. rtn = 0;
  271. for (i = 0;i < MAXCEILINGS;i++)
  272. {
  273. if (activeceilings[i]
  274. && (activeceilings[i]->tag == line->tag)
  275. && (activeceilings[i]->direction != 0))
  276. {
  277. activeceilings[i]->olddirection = activeceilings[i]->direction;
  278. activeceilings[i]->thinker.function.acv = (actionf_v)NULL;
  279. activeceilings[i]->direction = 0; // in-stasis
  280. rtn = 1;
  281. }
  282. }
  283. return rtn;
  284. }