2 //**************************************************************************
4 //** p_plats.c : Heretic 2 : Raven Software, Corp.
11 //**************************************************************************
17 plat_t *activeplats[MAXPLATS];
19 //==================================================================
21 // Move a plat up and down
23 //==================================================================
24 void T_PlatRaise(plat_t *plat)
31 res = T_MovePlane(plat->sector, plat->speed,
32 plat->high, plat->crush, 0, 1);
33 if (res == RES_CRUSHED && (!plat->crush))
35 plat->count = plat->wait;
36 plat->status = PLAT_DOWN;
37 SN_StartSequence((mobj_t *)&plat->sector->soundorg,
38 SEQ_PLATFORM+plat->sector->seqType);
41 if (res == RES_PASTDEST)
43 plat->count = plat->wait;
44 plat->status = PLAT_WAITING;
45 SN_StopSequence((mobj_t *)&plat->sector->soundorg);
48 case PLAT_DOWNWAITUPSTAY:
49 case PLAT_DOWNBYVALUEWAITUPSTAY:
50 P_RemoveActivePlat(plat);
58 res = T_MovePlane(plat->sector,plat->speed,plat->low,false,0,-1);
59 if (res == RES_PASTDEST)
61 plat->count = plat->wait;
62 plat->status = PLAT_WAITING;
65 case PLAT_UPWAITDOWNSTAY:
66 case PLAT_UPBYVALUEWAITDOWNSTAY:
67 P_RemoveActivePlat(plat);
72 SN_StopSequence((mobj_t *)&plat->sector->soundorg);
78 if (plat->sector->floorheight == plat->low)
79 plat->status = PLAT_UP;
81 plat->status = PLAT_DOWN;
82 SN_StartSequence((mobj_t *)&plat->sector->soundorg,
83 SEQ_PLATFORM+plat->sector->seqType);
85 // case PLAT_IN_STASIS:
90 //==================================================================
93 // "amount" is only used for SOME platforms.
95 //==================================================================
96 int EV_DoPlat(line_t *line, byte *args, plattype_e type, int amount)
108 // Activate all <type> plats that are in_stasis
112 case PLAT_PERPETUALRAISE:
113 P_ActivateInStasis(args[0]);
120 while ((secnum = P_FindSectorFromTag(args[0], secnum)) >= 0)
122 sec = §ors[secnum];
123 if (sec->specialdata)
127 // Find lowest & highest floors around sector
130 plat = Z_Malloc( sizeof(*plat), PU_LEVSPEC, 0);
131 P_AddThinker(&plat->thinker);
135 plat->sector->specialdata = plat;
136 plat->thinker.function = T_PlatRaise;
139 plat->speed = args[1]*(FRACUNIT/8);
142 case PLAT_DOWNWAITUPSTAY:
143 plat->low = P_FindLowestFloorSurrounding(sec)+8*FRACUNIT;
144 if (plat->low > sec->floorheight)
145 plat->low = sec->floorheight;
146 plat->high = sec->floorheight;
147 plat->wait = args[2];
148 plat->status = PLAT_DOWN;
150 case PLAT_DOWNBYVALUEWAITUPSTAY:
151 plat->low = sec->floorheight-args[3]*8*FRACUNIT;
152 if (plat->low > sec->floorheight)
153 plat->low = sec->floorheight;
154 plat->high = sec->floorheight;
155 plat->wait = args[2];
156 plat->status = PLAT_DOWN;
158 case PLAT_UPWAITDOWNSTAY:
159 plat->high = P_FindHighestFloorSurrounding(sec);
160 if (plat->high < sec->floorheight)
161 plat->high = sec->floorheight;
162 plat->low = sec->floorheight;
163 plat->wait = args[2];
164 plat->status = PLAT_UP;
166 case PLAT_UPBYVALUEWAITDOWNSTAY:
167 plat->high = sec->floorheight+args[3]*8*FRACUNIT;
168 if (plat->high < sec->floorheight)
169 plat->high = sec->floorheight;
170 plat->low = sec->floorheight;
171 plat->wait = args[2];
172 plat->status = PLAT_UP;
174 case PLAT_PERPETUALRAISE:
175 plat->low = P_FindLowestFloorSurrounding(sec)+8*FRACUNIT;
176 if (plat->low > sec->floorheight)
177 plat->low = sec->floorheight;
178 plat->high = P_FindHighestFloorSurrounding(sec);
179 if (plat->high < sec->floorheight)
180 plat->high = sec->floorheight;
181 plat->wait = args[2];
182 plat->status = P_Random()&1;
185 P_AddActivePlat(plat);
186 SN_StartSequence((mobj_t *)&sec->soundorg, SEQ_PLATFORM+sec->seqType);
192 void P_ActivateInStasis(int tag)
196 for (i = 0;i < MAXPLATS;i++)
197 if (activeplats[i] &&
198 (activeplats[i])->tag == tag &&
199 (activeplats[i])->status == PLAT_IN_STASIS)
201 (activeplats[i])->status = (activeplats[i])->oldstatus;
202 (activeplats[i])->thinker.function = T_PlatRaise;
207 void EV_StopPlat(line_t *line, byte *args)
211 for(i = 0; i < MAXPLATS; i++)
213 /* jim WRONG WRONG WRONG ! */
214 /* if((activeplats[i])->tag = args[0]) */
215 if((activeplats[i])->tag == args[0])
217 (activeplats[i])->sector->specialdata = NULL;
218 P_TagFinished((activeplats[i])->sector->tag);
219 P_RemoveThinker(&(activeplats[i])->thinker);
220 activeplats[i] = NULL;
229 for (j = 0;j < MAXPLATS;j++)
231 if (activeplats[j] && ((activeplats[j])->status != PLAT_IN_STASIS) &&
232 ((activeplats[j])->tag == args[0]))
234 (activeplats[j])->oldstatus = (activeplats[j])->status;
235 (activeplats[j])->status = PLAT_IN_STASIS;
236 (activeplats[j])->thinker.function = NULL;
237 SN_StopSequence((mobj_t *)&(activeplats[j])->sector->soundorg);
243 void P_AddActivePlat(plat_t *plat)
246 for (i = 0;i < MAXPLATS;i++)
247 if (activeplats[i] == NULL)
249 activeplats[i] = plat;
252 I_Error ("P_AddActivePlat: no more plats!");
255 void P_RemoveActivePlat(plat_t *plat)
258 for (i = 0;i < MAXPLATS;i++)
259 if (plat == activeplats[i])
261 (activeplats[i])->sector->specialdata = NULL;
262 P_TagFinished(plat->sector->tag);
263 P_RemoveThinker(&(activeplats[i])->thinker);
264 activeplats[i] = NULL;
267 I_Error ("P_RemoveActivePlat: can't find plat!");