8 plat_t *activeplats[MAXPLATS];
10 //==================================================================
12 // Move a plat up and down
14 //==================================================================
15 void T_PlatRaise(plat_t *plat)
22 res = T_MovePlane(plat->sector,plat->speed,
23 plat->high,plat->crush,0,1);
26 S_StartSound((mobj_t *)&plat->sector->soundorg,
29 if(plat->type == raiseAndChange
30 || plat->type == raiseToNearestAndChange)
34 S_StartSound((mobj_t *)&plat->sector->soundorg,
38 if (res == crushed && (!plat->crush))
40 plat->count = plat->wait;
42 S_StartSound((mobj_t *)&plat->sector->soundorg, sfx_pstart);
47 plat->count = plat->wait;
48 plat->status = waiting;
49 S_StartSound((mobj_t *)&plat->sector->soundorg, sfx_pstop);
53 P_RemoveActivePlat(plat);
56 P_RemoveActivePlat(plat);
64 res = T_MovePlane(plat->sector,plat->speed,plat->low,false,0,-1);
67 plat->count = plat->wait;
68 plat->status = waiting;
69 S_StartSound((mobj_t *)&plat->sector->soundorg, sfx_pstop);
75 S_StartSound((mobj_t *)&plat->sector->soundorg,
83 if (plat->sector->floorheight == plat->low)
87 S_StartSound((mobj_t *)&plat->sector->soundorg, sfx_pstart);
94 //==================================================================
97 // "amount" is only used for SOME platforms.
99 //==================================================================
100 int EV_DoPlat(line_t *line,plattype_e type,int amount)
111 // Activate all <type> plats that are in_stasis
116 P_ActivateInStasis(line->tag);
122 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
124 sec = §ors[secnum];
125 if (sec->specialdata)
129 // Find lowest & highest floors around sector
132 plat = Z_Malloc( sizeof(*plat), PU_LEVSPEC, 0);
133 P_AddThinker(&plat->thinker);
137 plat->sector->specialdata = plat;
138 plat->thinker.function = T_PlatRaise;
140 plat->tag = line->tag;
143 case raiseToNearestAndChange:
144 plat->speed = PLATSPEED/2;
145 sec->floorpic = sides[line->sidenum[0]].sector->floorpic;
146 plat->high = P_FindNextHighestFloor(sec,sec->floorheight);
149 sec->special = 0; // NO MORE DAMAGE, IF APPLICABLE
150 S_StartSound((mobj_t *)&sec->soundorg, sfx_stnmov);
153 plat->speed = PLATSPEED/2;
154 sec->floorpic = sides[line->sidenum[0]].sector->floorpic;
155 plat->high = sec->floorheight + amount*FRACUNIT;
158 S_StartSound((mobj_t *)&sec->soundorg, sfx_stnmov);
161 plat->speed = PLATSPEED * 4;
162 plat->low = P_FindLowestFloorSurrounding(sec);
163 if (plat->low > sec->floorheight)
164 plat->low = sec->floorheight;
165 plat->high = sec->floorheight;
166 plat->wait = 35*PLATWAIT;
168 S_StartSound((mobj_t *)&sec->soundorg, sfx_pstart);
171 plat->speed = PLATSPEED;
172 plat->low = P_FindLowestFloorSurrounding(sec);
173 if (plat->low > sec->floorheight)
174 plat->low = sec->floorheight;
175 plat->high = P_FindHighestFloorSurrounding(sec);
176 if (plat->high < sec->floorheight)
177 plat->high = sec->floorheight;
178 plat->wait = 35*PLATWAIT;
179 plat->status = P_Random()&1;
180 S_StartSound((mobj_t *)&sec->soundorg, sfx_pstart);
183 P_AddActivePlat(plat);
188 void P_ActivateInStasis(int tag)
192 for (i = 0;i < MAXPLATS;i++)
193 if (activeplats[i] &&
194 (activeplats[i])->tag == tag &&
195 (activeplats[i])->status == in_stasis)
197 (activeplats[i])->status = (activeplats[i])->oldstatus;
198 (activeplats[i])->thinker.function = T_PlatRaise;
202 void EV_StopPlat(line_t *line)
206 for (j = 0;j < MAXPLATS;j++)
207 if (activeplats[j] && ((activeplats[j])->status != in_stasis) &&
208 ((activeplats[j])->tag == line->tag))
210 (activeplats[j])->oldstatus = (activeplats[j])->status;
211 (activeplats[j])->status = in_stasis;
212 (activeplats[j])->thinker.function = NULL;
216 void P_AddActivePlat(plat_t *plat)
219 for (i = 0;i < MAXPLATS;i++)
220 if (activeplats[i] == NULL)
222 activeplats[i] = plat;
225 I_Error ("P_AddActivePlat: no more plats!");
228 void P_RemoveActivePlat(plat_t *plat)
231 for (i = 0;i < MAXPLATS;i++)
232 if (plat == activeplats[i])
234 (activeplats[i])->sector->specialdata = NULL;
235 P_RemoveThinker(&(activeplats[i])->thinker);
236 activeplats[i] = NULL;
239 I_Error ("P_RemoveActivePlat: can't find plat!");