-
Notifications
You must be signed in to change notification settings - Fork 5
/
p_plats.c
308 lines (260 loc) · 8.21 KB
/
p_plats.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/* Emacs style mode select -*- C++ -*-
*-----------------------------------------------------------------------------
*
*
* PrBoom: a Doom port merged with LxDoom and LSDLDoom
* based on BOOM, a modified and improved DOOM engine
* Copyright (C) 1999 by
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
* Copyright (C) 1999-2000 by
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
* Copyright 2005, 2006 by
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
* Copyright 2023, 2024 by
* Frenkel Smeijers
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* DESCRIPTION:
* Plats (i.e. elevator platforms) code, raising/lowering.
*
*-----------------------------------------------------------------------------*/
#include <stdint.h>
#include "d_player.h"
#include "m_random.h"
#include "r_main.h"
#include "p_spec.h"
#include "p_tick.h"
#include "s_sound.h"
#include "sounds.h"
#include "globdata.h"
// New limit-free plat structure -- killough
typedef struct platlist {
plat_t __far* plat;
struct platlist __far* next;
struct platlist __far*__far* prev;
} platlist_t;
static platlist_t __far* activeplats;
static void P_RemoveActivePlat(plat_t __far* plat);
//
// T_PlatRaise()
//
// Action routine to move a plat up and down
//
// Passed a plat structure containing all pertinent information about the move
// No return
//
void T_PlatRaise(plat_t __far* plat)
{
result_e res;
// handle plat moving, up, down, or waiting
switch(plat->status)
{
case up: // plat moving up
res = T_MovePlaneFloor(plat->sector,plat->speed,plat->high,1);
// if a pure raise type, make the plat moving sound
if (plat->type == raiseToNearestAndChange)
{
if (!((int16_t)_g_leveltime&7))
S_StartSound2(&plat->sector->soundorg, sfx_stnmov);
}
// if encountered an obstacle, and not a crush type, reverse direction
if (res == crushed)
{
plat->count = plat->wait;
plat->status = down;
S_StartSound2(&plat->sector->soundorg, sfx_pstart);
}
else // else handle reaching end of up stroke
{
if (res == pastdest) // end of stroke
{
// not an instant toggle type, wait, make plat stop sound
plat->count = plat->wait;
plat->status = waiting;
S_StartSound2(&plat->sector->soundorg, sfx_pstop);
// lift types and pure raise types are done at end of up stroke
// only the perpetual type waits then goes back up
switch(plat->type)
{
case downWaitUpStay:
case raiseToNearestAndChange:
P_RemoveActivePlat(plat); // killough
default:
break;
}
}
}
break;
case down: // plat moving down
res = T_MovePlaneFloor(plat->sector,plat->speed,plat->low,-1);
// handle reaching end of down stroke
if (res == pastdest)
{
// not an instant toggle, start waiting, make plat stop sound
plat->count = plat->wait;
plat->status = waiting;
S_StartSound2(&plat->sector->soundorg,sfx_pstop);
//jff 1/26/98 remove the plat if it bounced so it can be tried again
//only affects plats that raise and bounce
//killough 1/31/98: relax compatibility to demo_compatibility
switch(plat->type)
{
case raiseToNearestAndChange:
P_RemoveActivePlat(plat);
default:
break;
}
}
break;
case waiting: // plat is waiting
if (!--plat->count) // downcount and check for delay elapsed
{
if (plat->sector->floorheight == plat->low)
plat->status = up; // if at bottom, start up
else
plat->status = down; // if at top, start down
// make plat start sound
S_StartSound2(&plat->sector->soundorg,sfx_pstart);
}
break;
}
}
//
// EV_DoPlat
//
// Handle Plat linedef types
//
// Passed the linedef that activated the plat and the type of plat action.
// Returns true if a thinker is started
//
static void P_AddActivePlat(plat_t __far* plat);
boolean EV_DoPlat(const line_t __far* line, plattype_e type)
{
plat_t __far* plat;
int16_t secnum;
boolean rtn;
sector_t __far* sec;
secnum = -1;
rtn = false;
// act on all sectors tagged the same as the activating linedef
while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
{
sec = &_g_sectors[secnum];
// don't start a second floor function if already moving
if (sec->floordata != NULL) // multiple thinkers
continue;
// Create a thinker
rtn = true;
plat = Z_CallocLevSpec(sizeof(*plat));
P_AddThinker(&plat->thinker);
plat->type = type;
plat->sector = sec;
plat->sector->floordata = plat; //jff 2/23/98 multiple thinkers
plat->thinker.function = T_PlatRaise;
plat->tag = line->tag;
//jff 1/26/98 Avoid raise plat bouncing a head off a ceiling and then
//going down forever -- default low to plat height when triggered
plat->low = sec->floorheight;
// set up plat according to type
switch(type)
{
case raiseToNearestAndChange:
plat->speed = PLATSPEED/2;
sec->floorpic = _g_sides[line->sidenum[0]].sector->floorpic;
plat->high = P_FindNextHighestFloor(sec);
plat->wait = 0;
plat->status = up;
sec->special = 0;
//jff 3/14/98 clear old field as well
sec->oldspecial = 0;
S_StartSound2(&sec->soundorg,sfx_stnmov);
break;
case downWaitUpStay:
plat->speed = PLATSPEED * 4;
plat->low = P_FindLowestFloorSurrounding(sec);
if (plat->low > sec->floorheight)
plat->low = sec->floorheight;
plat->high = sec->floorheight;
plat->wait = 35*PLATWAIT;
plat->status = down;
S_StartSound2(&sec->soundorg,sfx_pstart);
break;
default:
break;
}
P_AddActivePlat(plat); // add plat to list of active plats
}
return rtn;
}
// The following were all rewritten by Lee Killough
// to use the new structure which places no limits
// on active plats. It also avoids spending as much
// time searching for active plats. Previously a
// fixed-size array was used, with NULL indicating
// empty entries, while now a doubly-linked list
// is used.
//
// P_AddActivePlat()
//
// Add a plat to the head of the active plat list
//
// Passed a pointer to the plat to add
// Returns nothing
//
static void P_AddActivePlat(plat_t __far* plat)
{
platlist_t __far* old_head = activeplats;
platlist_t __far* list = activeplats = Z_MallocLevel(sizeof *list, (void __far*__far*)&activeplats);
list->plat = plat;
plat->list = list;
if ((list->next = old_head))
list->next->prev = &list->next;
list->prev = old_head;
}
//
// P_RemoveActivePlat()
//
// Remove a plat from the active plat list
//
// Passed a pointer to the plat to remove
// Returns nothing
//
static void P_RemoveActivePlat(plat_t __far* plat)
{
platlist_t __far* list = plat->list;
plat->sector->floordata = NULL; //jff 2/23/98 multiple thinkers
P_RemoveThinker(&plat->thinker);
if (list->prev && (*list->prev = list->next))
list->next->prev = list->prev;
Z_Free(list);
}
//
// P_RemoveAllActivePlats()
//
// Remove all plats from the active plat list
//
// Passed nothing, returns nothing
//
void P_RemoveAllActivePlats(void)
{
while (activeplats)
{
platlist_t __far* next = activeplats->next;
Z_Free(activeplats);
activeplats = next;
}
}