fix remapping behavior. Remapping is only necessary if we are rendering on the workbe...
[AROS-Contrib.git] / Games / Doom / p_plats.c
blobb6c5e7ee17c3a8054e8afd96dbdde0382c07666b
1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // $Id$
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 //
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
15 // for more details.
17 // $Log$
18 // Revision 1.1 2000/02/29 18:21:04 stegerg
19 // Doom port based on ADoomPPC. Read README.AROS!
22 // DESCRIPTION:
23 // Plats (i.e. elevator platforms) code, raising/lowering.
25 //-----------------------------------------------------------------------------
27 static const char
28 rcsid[] = "$Id$";
31 #include "i_system.h"
32 #include "z_zone.h"
33 #include "m_random.h"
35 #include "doomdef.h"
36 #include "p_local.h"
38 #include "s_sound.h"
40 // State.
41 #include "doomstat.h"
42 #include "r_state.h"
44 // Data.
45 #include "sounds.h"
48 plat_t* activeplats[MAXPLATS];
53 // Move a plat up and down
55 void T_PlatRaise(plat_t* plat)
57 result_e res;
59 switch(plat->status)
61 case up:
62 res = T_MovePlane(plat->sector,
63 plat->speed,
64 plat->high,
65 plat->crush,0,1);
67 if (plat->type == raiseAndChange
68 || plat->type == raiseToNearestAndChange)
70 if (!(leveltime&7))
71 S_StartSound((mobj_t *)&plat->sector->soundorg,
72 sfx_stnmov);
76 if (res == crushed && (!plat->crush))
78 plat->count = plat->wait;
79 plat->status = down;
80 S_StartSound((mobj_t *)&plat->sector->soundorg,
81 sfx_pstart);
83 else
85 if (res == pastdest)
87 plat->count = plat->wait;
88 plat->status = waiting;
89 S_StartSound((mobj_t *)&plat->sector->soundorg,
90 sfx_pstop);
92 switch(plat->type)
94 case blazeDWUS:
95 case downWaitUpStay:
96 P_RemoveActivePlat(plat);
97 break;
99 case raiseAndChange:
100 case raiseToNearestAndChange:
101 P_RemoveActivePlat(plat);
102 break;
104 default:
105 break;
109 break;
111 case down:
112 res = T_MovePlane(plat->sector,plat->speed,plat->low,false,0,-1);
114 if (res == pastdest)
116 plat->count = plat->wait;
117 plat->status = waiting;
118 S_StartSound((mobj_t *)&plat->sector->soundorg,sfx_pstop);
120 break;
122 case waiting:
123 if (!--plat->count)
125 if (plat->sector->floorheight == plat->low)
126 plat->status = up;
127 else
128 plat->status = down;
129 S_StartSound((mobj_t *)&plat->sector->soundorg,sfx_pstart);
131 case in_stasis:
132 break;
138 // Do Platforms
139 // "amount" is only used for SOME platforms.
142 EV_DoPlat
143 ( line_t* line,
144 plattype_e type,
145 int amount )
147 plat_t* plat;
148 int secnum;
149 int rtn;
150 sector_t* sec;
152 secnum = -1;
153 rtn = 0;
156 // Activate all <type> plats that are in_stasis
157 switch(type)
159 case perpetualRaise:
160 P_ActivateInStasis(line->tag);
161 break;
163 default:
164 break;
167 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
169 sec = &sectors[secnum];
171 if (sec->specialdata)
172 continue;
174 // Find lowest & highest floors around sector
175 rtn = 1;
176 plat = Z_Malloc( sizeof(*plat), PU_LEVSPEC, 0);
177 P_AddThinker(&plat->thinker);
179 plat->type = type;
180 plat->sector = sec;
181 plat->sector->specialdata = plat;
182 plat->thinker.function.acp1 = (actionf_p1) T_PlatRaise;
183 plat->crush = false;
184 plat->tag = line->tag;
186 switch(type)
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);
192 plat->wait = 0;
193 plat->status = up;
194 // NO MORE DAMAGE, IF APPLICABLE
195 sec->special = 0;
197 S_StartSound((mobj_t *)&sec->soundorg,sfx_stnmov);
198 break;
200 case raiseAndChange:
201 plat->speed = PLATSPEED/2;
202 sec->floorpic = sides[line->sidenum[0]].sector->floorpic;
203 plat->high = sec->floorheight + amount*FRACUNIT;
204 plat->wait = 0;
205 plat->status = up;
207 S_StartSound((mobj_t *)&sec->soundorg,sfx_stnmov);
208 break;
210 case downWaitUpStay:
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;
219 plat->status = down;
220 S_StartSound((mobj_t *)&sec->soundorg,sfx_pstart);
221 break;
223 case blazeDWUS:
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;
232 plat->status = down;
233 S_StartSound((mobj_t *)&sec->soundorg,sfx_pstart);
234 break;
236 case perpetualRaise:
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);
252 break;
254 P_AddActivePlat(plat);
256 return rtn;
261 void P_ActivateInStasis(int tag)
263 int i;
265 for (i = 0;i < MAXPLATS;i++)
266 if (activeplats[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)
278 int j;
280 for (j = 0;j < MAXPLATS;j++)
281 if (activeplats[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)
293 int i;
295 for (i = 0;i < MAXPLATS;i++)
296 if (activeplats[i] == NULL)
298 activeplats[i] = plat;
299 return;
301 I_Error ("P_AddActivePlat: no more plats!");
304 void P_RemoveActivePlat(plat_t* plat)
306 int i;
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;
314 return;
316 I_Error ("P_RemoveActivePlat: can't find plat!");