p_plats.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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 "i_system.h"
  23. #include "z_zone.h"
  24. #include "m_random.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. // Move a plat up and down
  35. //
  36. void T_PlatRaise(plat_t* plat)
  37. {
  38. result_e res;
  39. switch(plat->status)
  40. {
  41. case up:
  42. res = T_MovePlane(plat->sector,
  43. plat->speed,
  44. plat->high,
  45. plat->crush,0,1);
  46. if (plat->type == raiseAndChange
  47. || plat->type == raiseToNearestAndChange)
  48. {
  49. if (!(::g->leveltime&7))
  50. S_StartSound( &plat->sector->soundorg,
  51. sfx_stnmov);
  52. }
  53. if (res == crushed && (!plat->crush))
  54. {
  55. plat->count = plat->wait;
  56. plat->status = down;
  57. S_StartSound( &plat->sector->soundorg,
  58. sfx_pstart);
  59. }
  60. else
  61. {
  62. if (res == pastdest)
  63. {
  64. plat->count = plat->wait;
  65. plat->status = waiting;
  66. S_StartSound( &plat->sector->soundorg,
  67. sfx_pstop);
  68. switch(plat->type)
  69. {
  70. case blazeDWUS:
  71. case downWaitUpStay:
  72. P_RemoveActivePlat(plat);
  73. break;
  74. case raiseAndChange:
  75. case raiseToNearestAndChange:
  76. P_RemoveActivePlat(plat);
  77. break;
  78. default:
  79. break;
  80. }
  81. }
  82. }
  83. break;
  84. case down:
  85. res = T_MovePlane(plat->sector,plat->speed,plat->low,false,0,-1);
  86. if (res == pastdest)
  87. {
  88. plat->count = plat->wait;
  89. plat->status = waiting;
  90. S_StartSound( &plat->sector->soundorg,sfx_pstop);
  91. }
  92. break;
  93. case waiting:
  94. if (!--plat->count)
  95. {
  96. if (plat->sector->floorheight == plat->low)
  97. plat->status = up;
  98. else
  99. plat->status = down;
  100. S_StartSound( &plat->sector->soundorg,sfx_pstart);
  101. }
  102. case in_stasis:
  103. break;
  104. }
  105. }
  106. //
  107. // Do Platforms
  108. // "amount" is only used for SOME platforms.
  109. //
  110. int
  111. EV_DoPlat
  112. ( line_t* line,
  113. plattype_e type,
  114. int amount )
  115. {
  116. plat_t* plat;
  117. int secnum;
  118. int rtn;
  119. sector_t* sec;
  120. secnum = -1;
  121. rtn = 0;
  122. // Activate all <type> plats that are in_stasis
  123. switch(type)
  124. {
  125. case perpetualRaise:
  126. P_ActivateInStasis(line->tag);
  127. break;
  128. default:
  129. break;
  130. }
  131. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  132. {
  133. sec = &::g->sectors[secnum];
  134. if (sec->specialdata)
  135. continue;
  136. // Find lowest & highest floors around sector
  137. rtn = 1;
  138. plat = (plat_t*)DoomLib::Z_Malloc( sizeof(*plat), PU_LEVEL, 0);
  139. P_AddThinker(&plat->thinker);
  140. plat->type = type;
  141. plat->sector = sec;
  142. plat->sector->specialdata = plat;
  143. plat->thinker.function.acp1 = (actionf_p1) T_PlatRaise;
  144. plat->crush = false;
  145. plat->tag = line->tag;
  146. switch(type)
  147. {
  148. case raiseToNearestAndChange:
  149. plat->speed = PLATSPEED/2;
  150. sec->floorpic = ::g->sides[line->sidenum[0]].sector->floorpic;
  151. plat->high = P_FindNextHighestFloor(sec,sec->floorheight);
  152. plat->wait = 0;
  153. plat->status = up;
  154. // NO MORE DAMAGE, IF APPLICABLE
  155. sec->special = 0;
  156. S_StartSound( &sec->soundorg,sfx_stnmov);
  157. break;
  158. case raiseAndChange:
  159. plat->speed = PLATSPEED/2;
  160. sec->floorpic = ::g->sides[line->sidenum[0]].sector->floorpic;
  161. plat->high = sec->floorheight + amount*FRACUNIT;
  162. plat->wait = 0;
  163. plat->status = up;
  164. S_StartSound( &sec->soundorg,sfx_stnmov);
  165. break;
  166. case downWaitUpStay:
  167. plat->speed = PLATSPEED * 4;
  168. plat->low = P_FindLowestFloorSurrounding(sec);
  169. if (plat->low > sec->floorheight)
  170. plat->low = sec->floorheight;
  171. plat->high = sec->floorheight;
  172. plat->wait = TICRATE*PLATWAIT;
  173. plat->status = down;
  174. S_StartSound( &sec->soundorg,sfx_pstart);
  175. break;
  176. case blazeDWUS:
  177. plat->speed = PLATSPEED * 8;
  178. plat->low = P_FindLowestFloorSurrounding(sec);
  179. if (plat->low > sec->floorheight)
  180. plat->low = sec->floorheight;
  181. plat->high = sec->floorheight;
  182. plat->wait = TICRATE*PLATWAIT;
  183. plat->status = down;
  184. S_StartSound( &sec->soundorg,sfx_pstart);
  185. break;
  186. case perpetualRaise:
  187. plat->speed = PLATSPEED;
  188. plat->low = P_FindLowestFloorSurrounding(sec);
  189. if (plat->low > sec->floorheight)
  190. plat->low = sec->floorheight;
  191. plat->high = P_FindHighestFloorSurrounding(sec);
  192. if (plat->high < sec->floorheight)
  193. plat->high = sec->floorheight;
  194. plat->wait = TICRATE*PLATWAIT;
  195. plat->status = (plat_e)(P_Random()&1);
  196. S_StartSound( &sec->soundorg,sfx_pstart);
  197. break;
  198. }
  199. P_AddActivePlat(plat);
  200. }
  201. return rtn;
  202. }
  203. void P_ActivateInStasis(int tag)
  204. {
  205. int i;
  206. for (i = 0;i < MAXPLATS;i++)
  207. if (::g->activeplats[i]
  208. && (::g->activeplats[i])->tag == tag
  209. && (::g->activeplats[i])->status == in_stasis)
  210. {
  211. (::g->activeplats[i])->status = (::g->activeplats[i])->oldstatus;
  212. (::g->activeplats[i])->thinker.function.acp1
  213. = (actionf_p1) T_PlatRaise;
  214. }
  215. }
  216. void EV_StopPlat(line_t* line)
  217. {
  218. int j;
  219. for (j = 0;j < MAXPLATS;j++)
  220. if (::g->activeplats[j]
  221. && ((::g->activeplats[j])->status != in_stasis)
  222. && ((::g->activeplats[j])->tag == line->tag))
  223. {
  224. (::g->activeplats[j])->oldstatus = (::g->activeplats[j])->status;
  225. (::g->activeplats[j])->status = in_stasis;
  226. (::g->activeplats[j])->thinker.function.acv = (actionf_v)NULL;
  227. }
  228. }
  229. void P_AddActivePlat(plat_t* plat)
  230. {
  231. int i;
  232. for (i = 0;i < MAXPLATS;i++)
  233. if (::g->activeplats[i] == NULL)
  234. {
  235. ::g->activeplats[i] = plat;
  236. return;
  237. }
  238. I_Error ("P_AddActivePlat: no more plats!");
  239. }
  240. void P_RemoveActivePlat(plat_t* plat)
  241. {
  242. int i;
  243. for (i = 0;i < MAXPLATS;i++)
  244. if (plat == ::g->activeplats[i])
  245. {
  246. (::g->activeplats[i])->sector->specialdata = NULL;
  247. P_RemoveThinker(&(::g->activeplats[i])->thinker);
  248. ::g->activeplats[i] = NULL;
  249. return;
  250. }
  251. I_Error ("P_RemoveActivePlat: can't find plat!");
  252. }