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
18 // Revision 1.1 2000/02/29 18:21:04 stegerg
19 // Doom port based on ADoomPPC. Read README.AROS!
23 // Plats (i.e. elevator platforms) code, raising/lowering.
25 //-----------------------------------------------------------------------------
48 plat_t
* activeplats
[MAXPLATS
];
53 // Move a plat up and down
55 void T_PlatRaise(plat_t
* plat
)
62 res
= T_MovePlane(plat
->sector
,
67 if (plat
->type
== raiseAndChange
68 || plat
->type
== raiseToNearestAndChange
)
71 S_StartSound((mobj_t
*)&plat
->sector
->soundorg
,
76 if (res
== crushed
&& (!plat
->crush
))
78 plat
->count
= plat
->wait
;
80 S_StartSound((mobj_t
*)&plat
->sector
->soundorg
,
87 plat
->count
= plat
->wait
;
88 plat
->status
= waiting
;
89 S_StartSound((mobj_t
*)&plat
->sector
->soundorg
,
96 P_RemoveActivePlat(plat
);
100 case raiseToNearestAndChange
:
101 P_RemoveActivePlat(plat
);
112 res
= T_MovePlane(plat
->sector
,plat
->speed
,plat
->low
,false,0,-1);
116 plat
->count
= plat
->wait
;
117 plat
->status
= waiting
;
118 S_StartSound((mobj_t
*)&plat
->sector
->soundorg
,sfx_pstop
);
125 if (plat
->sector
->floorheight
== plat
->low
)
129 S_StartSound((mobj_t
*)&plat
->sector
->soundorg
,sfx_pstart
);
139 // "amount" is only used for SOME platforms.
156 // Activate all <type> plats that are in_stasis
160 P_ActivateInStasis(line
->tag
);
167 while ((secnum
= P_FindSectorFromLineTag(line
,secnum
)) >= 0)
169 sec
= §ors
[secnum
];
171 if (sec
->specialdata
)
174 // Find lowest & highest floors around sector
176 plat
= Z_Malloc( sizeof(*plat
), PU_LEVSPEC
, 0);
177 P_AddThinker(&plat
->thinker
);
181 plat
->sector
->specialdata
= plat
;
182 plat
->thinker
.function
.acp1
= (actionf_p1
) T_PlatRaise
;
184 plat
->tag
= line
->tag
;
188 case raiseToNearestAndChange
:
189 plat
->speed
= PLATSPEED
/2;
190 sec
->floorpic
= sides
[line
->sidenum
[0]].sector
->floorpic
;
191 plat
->high
= P_FindNextHighestFloor(sec
,sec
->floorheight
);
194 // NO MORE DAMAGE, IF APPLICABLE
197 S_StartSound((mobj_t
*)&sec
->soundorg
,sfx_stnmov
);
201 plat
->speed
= PLATSPEED
/2;
202 sec
->floorpic
= sides
[line
->sidenum
[0]].sector
->floorpic
;
203 plat
->high
= sec
->floorheight
+ amount
*FRACUNIT
;
207 S_StartSound((mobj_t
*)&sec
->soundorg
,sfx_stnmov
);
211 plat
->speed
= PLATSPEED
* 4;
212 plat
->low
= P_FindLowestFloorSurrounding(sec
);
214 if (plat
->low
> sec
->floorheight
)
215 plat
->low
= sec
->floorheight
;
217 plat
->high
= sec
->floorheight
;
218 plat
->wait
= 35*PLATWAIT
;
220 S_StartSound((mobj_t
*)&sec
->soundorg
,sfx_pstart
);
224 plat
->speed
= PLATSPEED
* 8;
225 plat
->low
= P_FindLowestFloorSurrounding(sec
);
227 if (plat
->low
> sec
->floorheight
)
228 plat
->low
= sec
->floorheight
;
230 plat
->high
= sec
->floorheight
;
231 plat
->wait
= 35*PLATWAIT
;
233 S_StartSound((mobj_t
*)&sec
->soundorg
,sfx_pstart
);
237 plat
->speed
= PLATSPEED
;
238 plat
->low
= P_FindLowestFloorSurrounding(sec
);
240 if (plat
->low
> sec
->floorheight
)
241 plat
->low
= sec
->floorheight
;
243 plat
->high
= P_FindHighestFloorSurrounding(sec
);
245 if (plat
->high
< sec
->floorheight
)
246 plat
->high
= sec
->floorheight
;
248 plat
->wait
= 35*PLATWAIT
;
249 plat
->status
= P_Random()&1;
251 S_StartSound((mobj_t
*)&sec
->soundorg
,sfx_pstart
);
254 P_AddActivePlat(plat
);
261 void P_ActivateInStasis(int tag
)
265 for (i
= 0;i
< MAXPLATS
;i
++)
267 && (activeplats
[i
])->tag
== tag
268 && (activeplats
[i
])->status
== in_stasis
)
270 (activeplats
[i
])->status
= (activeplats
[i
])->oldstatus
;
271 (activeplats
[i
])->thinker
.function
.acp1
272 = (actionf_p1
) T_PlatRaise
;
276 void EV_StopPlat(line_t
* line
)
280 for (j
= 0;j
< MAXPLATS
;j
++)
282 && ((activeplats
[j
])->status
!= in_stasis
)
283 && ((activeplats
[j
])->tag
== line
->tag
))
285 (activeplats
[j
])->oldstatus
= (activeplats
[j
])->status
;
286 (activeplats
[j
])->status
= in_stasis
;
287 (activeplats
[j
])->thinker
.function
.acv
= (actionf_v
)NULL
;
291 void P_AddActivePlat(plat_t
* plat
)
295 for (i
= 0;i
< MAXPLATS
;i
++)
296 if (activeplats
[i
] == NULL
)
298 activeplats
[i
] = plat
;
301 I_Error ("P_AddActivePlat: no more plats!");
304 void P_RemoveActivePlat(plat_t
* plat
)
307 for (i
= 0;i
< MAXPLATS
;i
++)
308 if (plat
== activeplats
[i
])
310 (activeplats
[i
])->sector
->specialdata
= NULL
;
311 P_RemoveThinker(&(activeplats
[i
])->thinker
);
312 activeplats
[i
] = NULL
;
316 I_Error ("P_RemoveActivePlat: can't find plat!");