1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
6 // Copyright (C) 1993-1996 by id Software, Inc.
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.
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
20 // Plats (i.e. elevator platforms) code, raising/lowering.
22 //-----------------------------------------------------------------------------
25 rcsid[] = "$Id: p_plats.c,v 1.5 1997/02/03 22:45:12 b1 Exp $";
45 plat_t* activeplats[MAXPLATS];
50 // Move a plat up and down
52 void T_PlatRaise(void *_plat, void*)
54 plat_t *plat = (plat_t*)_plat;
60 res = T_MovePlane(plat->sector,
65 if (plat->type == raiseAndChange
66 || plat->type == raiseToNearestAndChange)
69 S_StartSound((mobj_t *)&plat->sector->soundorg,
74 if (res == crushed && (!plat->crush))
76 plat->count = plat->wait;
78 S_StartSound((mobj_t *)&plat->sector->soundorg,
85 plat->count = plat->wait;
86 plat->status = waiting;
87 S_StartSound((mobj_t *)&plat->sector->soundorg,
94 P_RemoveActivePlat(plat);
98 case raiseToNearestAndChange:
99 P_RemoveActivePlat(plat);
110 res = T_MovePlane(plat->sector,plat->speed,plat->low,false,0,-1);
114 plat->count = plat->wait;
115 plat->status = waiting;
116 S_StartSound((mobj_t *)&plat->sector->soundorg,sfx_pstop);
123 if (plat->sector->floorheight == plat->low)
127 S_StartSound((mobj_t *)&plat->sector->soundorg,sfx_pstart);
137 // "amount" is only used for SOME platforms.
154 // Activate all <type> plats that are in_stasis
158 P_ActivateInStasis(line->tag);
165 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
167 sec = §ors[secnum];
169 if (sec->specialdata)
172 // Find lowest & highest floors around sector
174 plat = Z_Malloc( sizeof(*plat), PU_LEVSPEC, 0);
175 P_AddThinker(&plat->thinker);
179 plat->sector->specialdata = plat;
180 plat->thinker.function = T_PlatRaise;
182 plat->tag = line->tag;
186 case raiseToNearestAndChange:
187 plat->speed = PLATSPEED/2;
188 sec->floorpic = sides[line->sidenum[0]].sector->floorpic;
189 plat->high = P_FindNextHighestFloor(sec,sec->floorheight);
192 // NO MORE DAMAGE, IF APPLICABLE
195 S_StartSound((mobj_t *)&sec->soundorg,sfx_stnmov);
199 plat->speed = PLATSPEED/2;
200 sec->floorpic = sides[line->sidenum[0]].sector->floorpic;
201 plat->high = sec->floorheight + amount*FRACUNIT;
205 S_StartSound((mobj_t *)&sec->soundorg,sfx_stnmov);
209 plat->speed = PLATSPEED * 4;
210 plat->low = P_FindLowestFloorSurrounding(sec);
212 if (plat->low > sec->floorheight)
213 plat->low = sec->floorheight;
215 plat->high = sec->floorheight;
216 plat->wait = 35*PLATWAIT;
218 S_StartSound((mobj_t *)&sec->soundorg,sfx_pstart);
222 plat->speed = PLATSPEED * 8;
223 plat->low = P_FindLowestFloorSurrounding(sec);
225 if (plat->low > sec->floorheight)
226 plat->low = sec->floorheight;
228 plat->high = sec->floorheight;
229 plat->wait = 35*PLATWAIT;
231 S_StartSound((mobj_t *)&sec->soundorg,sfx_pstart);
235 plat->speed = PLATSPEED;
236 plat->low = P_FindLowestFloorSurrounding(sec);
238 if (plat->low > sec->floorheight)
239 plat->low = sec->floorheight;
241 plat->high = P_FindHighestFloorSurrounding(sec);
243 if (plat->high < sec->floorheight)
244 plat->high = sec->floorheight;
246 plat->wait = 35*PLATWAIT;
247 plat->status = P_Random()&1;
249 S_StartSound((mobj_t *)&sec->soundorg,sfx_pstart);
252 P_AddActivePlat(plat);
259 void P_ActivateInStasis(int tag)
263 for (i = 0;i < MAXPLATS;i++)
265 && (activeplats[i])->tag == tag
266 && (activeplats[i])->status == in_stasis)
268 (activeplats[i])->status = (activeplats[i])->oldstatus;
269 (activeplats[i])->thinker.function = T_PlatRaise;
273 void EV_StopPlat(line_t* line)
277 for (j = 0;j < MAXPLATS;j++)
279 && ((activeplats[j])->status != in_stasis)
280 && ((activeplats[j])->tag == line->tag))
282 (activeplats[j])->oldstatus = (activeplats[j])->status;
283 (activeplats[j])->status = in_stasis;
284 (activeplats[j])->thinker.function = NULL;
288 void P_AddActivePlat(plat_t* plat)
292 for (i = 0;i < MAXPLATS;i++)
293 if (activeplats[i] == NULL)
295 activeplats[i] = plat;
298 I_Error ("P_AddActivePlat: no more plats!");
301 void P_RemoveActivePlat(plat_t* plat)
304 for (i = 0;i < MAXPLATS;i++)
305 if (plat == activeplats[i])
307 (activeplats[i])->sector->specialdata = NULL;
308 P_RemoveThinker(&(activeplats[i])->thinker);
309 activeplats[i] = NULL;
313 I_Error ("P_RemoveActivePlat: can't find plat!");