P_PLATS.C 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //**************************************************************************
  2. //**
  3. //** p_plats.c : Heretic 2 : Raven Software, Corp.
  4. //**
  5. //** $RCSfile: p_plats.c,v $
  6. //** $Revision: 1.11 $
  7. //** $Date: 95/09/11 22:06:30 $
  8. //** $Author: cjr $
  9. //**
  10. //**************************************************************************
  11. #include "h2def.h"
  12. #include "p_local.h"
  13. #include "soundst.h"
  14. plat_t *activeplats[MAXPLATS];
  15. //==================================================================
  16. //
  17. // Move a plat up and down
  18. //
  19. //==================================================================
  20. void T_PlatRaise(plat_t *plat)
  21. {
  22. result_e res;
  23. switch(plat->status)
  24. {
  25. case PLAT_UP:
  26. res = T_MovePlane(plat->sector, plat->speed,
  27. plat->high, plat->crush, 0, 1);
  28. if (res == RES_CRUSHED && (!plat->crush))
  29. {
  30. plat->count = plat->wait;
  31. plat->status = PLAT_DOWN;
  32. SN_StartSequence((mobj_t *)&plat->sector->soundorg,
  33. SEQ_PLATFORM+plat->sector->seqType);
  34. }
  35. else
  36. if (res == RES_PASTDEST)
  37. {
  38. plat->count = plat->wait;
  39. plat->status = PLAT_WAITING;
  40. SN_StopSequence((mobj_t *)&plat->sector->soundorg);
  41. switch(plat->type)
  42. {
  43. case PLAT_DOWNWAITUPSTAY:
  44. case PLAT_DOWNBYVALUEWAITUPSTAY:
  45. P_RemoveActivePlat(plat);
  46. break;
  47. default:
  48. break;
  49. }
  50. }
  51. break;
  52. case PLAT_DOWN:
  53. res = T_MovePlane(plat->sector,plat->speed,plat->low,false,0,-1);
  54. if (res == RES_PASTDEST)
  55. {
  56. plat->count = plat->wait;
  57. plat->status = PLAT_WAITING;
  58. switch(plat->type)
  59. {
  60. case PLAT_UPWAITDOWNSTAY:
  61. case PLAT_UPBYVALUEWAITDOWNSTAY:
  62. P_RemoveActivePlat(plat);
  63. break;
  64. default:
  65. break;
  66. }
  67. SN_StopSequence((mobj_t *)&plat->sector->soundorg);
  68. }
  69. break;
  70. case PLAT_WAITING:
  71. if (!--plat->count)
  72. {
  73. if (plat->sector->floorheight == plat->low)
  74. plat->status = PLAT_UP;
  75. else
  76. plat->status = PLAT_DOWN;
  77. SN_StartSequence((mobj_t *)&plat->sector->soundorg,
  78. SEQ_PLATFORM+plat->sector->seqType);
  79. }
  80. // case PLAT_IN_STASIS:
  81. // break;
  82. }
  83. }
  84. //==================================================================
  85. //
  86. // Do Platforms
  87. // "amount" is only used for SOME platforms.
  88. //
  89. //==================================================================
  90. int EV_DoPlat(line_t *line, byte *args, plattype_e type, int amount)
  91. {
  92. plat_t *plat;
  93. int secnum;
  94. int rtn;
  95. sector_t *sec;
  96. secnum = -1;
  97. rtn = 0;
  98. /*
  99. //
  100. // Activate all <type> plats that are in_stasis
  101. //
  102. switch(type)
  103. {
  104. case PLAT_PERPETUALRAISE:
  105. P_ActivateInStasis(args[0]);
  106. break;
  107. default:
  108. break;
  109. }
  110. */
  111. while ((secnum = P_FindSectorFromTag(args[0], secnum)) >= 0)
  112. {
  113. sec = &sectors[secnum];
  114. if (sec->specialdata)
  115. continue;
  116. //
  117. // Find lowest & highest floors around sector
  118. //
  119. rtn = 1;
  120. plat = Z_Malloc( sizeof(*plat), PU_LEVSPEC, 0);
  121. P_AddThinker(&plat->thinker);
  122. plat->type = type;
  123. plat->sector = sec;
  124. plat->sector->specialdata = plat;
  125. plat->thinker.function = T_PlatRaise;
  126. plat->crush = false;
  127. plat->tag = args[0];
  128. plat->speed = args[1]*(FRACUNIT/8);
  129. switch(type)
  130. {
  131. case PLAT_DOWNWAITUPSTAY:
  132. plat->low = P_FindLowestFloorSurrounding(sec)+8*FRACUNIT;
  133. if (plat->low > sec->floorheight)
  134. plat->low = sec->floorheight;
  135. plat->high = sec->floorheight;
  136. plat->wait = args[2];
  137. plat->status = PLAT_DOWN;
  138. break;
  139. case PLAT_DOWNBYVALUEWAITUPSTAY:
  140. plat->low = sec->floorheight-args[3]*8*FRACUNIT;
  141. if (plat->low > sec->floorheight)
  142. plat->low = sec->floorheight;
  143. plat->high = sec->floorheight;
  144. plat->wait = args[2];
  145. plat->status = PLAT_DOWN;
  146. break;
  147. case PLAT_UPWAITDOWNSTAY:
  148. plat->high = P_FindHighestFloorSurrounding(sec);
  149. if (plat->high < sec->floorheight)
  150. plat->high = sec->floorheight;
  151. plat->low = sec->floorheight;
  152. plat->wait = args[2];
  153. plat->status = PLAT_UP;
  154. break;
  155. case PLAT_UPBYVALUEWAITDOWNSTAY:
  156. plat->high = sec->floorheight+args[3]*8*FRACUNIT;
  157. if (plat->high < sec->floorheight)
  158. plat->high = sec->floorheight;
  159. plat->low = sec->floorheight;
  160. plat->wait = args[2];
  161. plat->status = PLAT_UP;
  162. break;
  163. case PLAT_PERPETUALRAISE:
  164. plat->low = P_FindLowestFloorSurrounding(sec)+8*FRACUNIT;
  165. if (plat->low > sec->floorheight)
  166. plat->low = sec->floorheight;
  167. plat->high = P_FindHighestFloorSurrounding(sec);
  168. if (plat->high < sec->floorheight)
  169. plat->high = sec->floorheight;
  170. plat->wait = args[2];
  171. plat->status = P_Random()&1;
  172. break;
  173. }
  174. P_AddActivePlat(plat);
  175. SN_StartSequence((mobj_t *)&sec->soundorg, SEQ_PLATFORM+sec->seqType);
  176. }
  177. return rtn;
  178. }
  179. #if 0
  180. void P_ActivateInStasis(int tag)
  181. {
  182. int i;
  183. for (i = 0;i < MAXPLATS;i++)
  184. if (activeplats[i] &&
  185. (activeplats[i])->tag == tag &&
  186. (activeplats[i])->status == PLAT_IN_STASIS)
  187. {
  188. (activeplats[i])->status = (activeplats[i])->oldstatus;
  189. (activeplats[i])->thinker.function = T_PlatRaise;
  190. }
  191. }
  192. #endif
  193. void EV_StopPlat(line_t *line, byte *args)
  194. {
  195. int i;
  196. for(i = 0; i < MAXPLATS; i++)
  197. {
  198. if((activeplats[i])->tag = args[0])
  199. {
  200. (activeplats[i])->sector->specialdata = NULL;
  201. P_TagFinished((activeplats[i])->sector->tag);
  202. P_RemoveThinker(&(activeplats[i])->thinker);
  203. activeplats[i] = NULL;
  204. return;
  205. }
  206. }
  207. /*
  208. int j;
  209. for (j = 0;j < MAXPLATS;j++)
  210. {
  211. if (activeplats[j] && ((activeplats[j])->status != PLAT_IN_STASIS) &&
  212. ((activeplats[j])->tag == args[0]))
  213. {
  214. (activeplats[j])->oldstatus = (activeplats[j])->status;
  215. (activeplats[j])->status = PLAT_IN_STASIS;
  216. (activeplats[j])->thinker.function = NULL;
  217. SN_StopSequence((mobj_t *)&(activeplats[j])->sector->soundorg);
  218. }
  219. }
  220. */
  221. }
  222. void P_AddActivePlat(plat_t *plat)
  223. {
  224. int i;
  225. for (i = 0;i < MAXPLATS;i++)
  226. if (activeplats[i] == NULL)
  227. {
  228. activeplats[i] = plat;
  229. return;
  230. }
  231. I_Error ("P_AddActivePlat: no more plats!");
  232. }
  233. void P_RemoveActivePlat(plat_t *plat)
  234. {
  235. int i;
  236. for (i = 0;i < MAXPLATS;i++)
  237. if (plat == activeplats[i])
  238. {
  239. (activeplats[i])->sector->specialdata = NULL;
  240. P_TagFinished(plat->sector->tag);
  241. P_RemoveThinker(&(activeplats[i])->thinker);
  242. activeplats[i] = NULL;
  243. return;
  244. }
  245. I_Error ("P_RemoveActivePlat: can't find plat!");
  246. }