-
Notifications
You must be signed in to change notification settings - Fork 0
/
P_DOORS.C
368 lines (350 loc) · 8.08 KB
/
P_DOORS.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
// P_doors.c
#include "DoomDef.h"
#include "P_local.h"
#include "soundst.h"
//==================================================================
//==================================================================
//
// VERTICAL DOORS
//
//==================================================================
//==================================================================
//==================================================================
//
// T_VerticalDoor
//
//==================================================================
void T_VerticalDoor(vldoor_t *door)
{
result_e res;
switch (door->direction)
{
case 0: // WAITING
if (!--door->topcountdown)
switch (door->type)
{
case doornormal:
door->direction = -1; // time to go back down
S_StartSound((mobj_t *)
&door->sector->soundorg, sfx_doropn);
break;
case close30ThenOpen:
door->direction = 1;
S_StartSound((mobj_t *)
&door->sector->soundorg, sfx_doropn);
break;
default:
break;
}
break;
case 2: // INITIAL WAIT
if (!--door->topcountdown)
{
switch (door->type)
{
case raiseIn5Mins:
door->direction = 1;
door->type = doornormal;
S_StartSound((mobj_t *)
&door->sector->soundorg, sfx_doropn);
break;
default:
break;
}
}
break;
case -1: // DOWN
res = T_MovePlane(door->sector, door->speed,
door->sector->floorheight, false, 1, door->direction);
if (res == pastdest)
{
switch (door->type)
{
case doornormal:
case doorclose:
door->sector->specialdata = NULL;
P_RemoveThinker(&door->thinker); // unlink and free
S_StartSound((mobj_t *)
&door->sector->soundorg, sfx_dorcls);
break;
case close30ThenOpen:
door->direction = 0;
door->topcountdown = 35 * 30;
break;
default:
break;
}
}
else if (res == crushed)
{
switch (door->type)
{
case doorclose: // DON'T GO BACK UP!
break;
default:
door->direction = 1;
S_StartSound((mobj_t *)
&door->sector->soundorg, sfx_doropn);
break;
}
}
break;
case 1: // UP
res = T_MovePlane(door->sector, door->speed,
door->topheight, false, 1, door->direction);
if (res == pastdest)
{
switch (door->type)
{
case doornormal:
door->direction = 0; // wait at top
door->topcountdown = door->topwait;
break;
case close30ThenOpen:
case dooropen:
door->sector->specialdata = NULL;
P_RemoveThinker (&door->thinker); // unlink and free
S_StopSound((mobj_t *)&door->sector->soundorg);
break;
default:
break;
}
}
break;
}
}
//----------------------------------------------------------------------------
//
// EV_DoDoor
//
// Move a door up/down
//
//----------------------------------------------------------------------------
int EV_DoDoor(line_t *line, vldoor_e type, fixed_t speed)
{
int secnum;
int retcode;
sector_t *sec;
vldoor_t *door;
secnum = -1;
retcode = 0;
while ((secnum = P_FindSectorFromLineTag(line, secnum)) >= 0)
{
sec = §ors[secnum];
if (sec->specialdata)
{
continue;
}
// Add new door thinker
retcode = 1;
door = Z_Malloc(sizeof(*door), PU_LEVSPEC, 0);
P_AddThinker(&door->thinker);
sec->specialdata = door;
door->thinker.function = T_VerticalDoor;
door->sector = sec;
switch (type)
{
case doorclose:
door->topheight = P_FindLowestCeilingSurrounding(sec);
door->topheight -= 4 * FRACUNIT;
door->direction = -1;
S_StartSound((mobj_t *)&door->sector->soundorg, sfx_doropn);
break;
case close30ThenOpen:
door->topheight = sec->ceilingheight;
door->direction = -1;
S_StartSound((mobj_t *)&door->sector->soundorg, sfx_doropn);
break;
case doornormal:
case dooropen:
door->direction = 1;
door->topheight = P_FindLowestCeilingSurrounding(sec);
door->topheight -= 4 * FRACUNIT;
if (door->topheight != sec->ceilingheight)
{
S_StartSound((mobj_t *)&door->sector->soundorg,
sfx_doropn);
}
break;
default:
break;
}
door->type = type;
door->speed = speed;
door->topwait = VDOORWAIT;
}
return(retcode);
}
//==================================================================
//
// EV_VerticalDoor : open a door manually, no tag value
//
//==================================================================
void EV_VerticalDoor(line_t *line, mobj_t *thing)
{
player_t *player;
int secnum;
sector_t *sec;
vldoor_t *door;
int side;
side = 0; // only front sides can be used
//
// Check for locks
//
player = thing->player;
switch (line->special)
{
case 26: // Blue Lock
case 32:
if (!player)
{
return;
}
if (!player->keys[key_blue])
{
P_SetMessage(player, TXT_NEEDBLUEKEY, false);
S_StartSound(player->mo, sfx_plroof); // FS: was NULL
return;
}
break;
case 27: // Yellow Lock
case 34:
if (!player)
{
return;
}
if (!player->keys[key_yellow])
{
P_SetMessage(player, TXT_NEEDYELLOWKEY, false);
S_StartSound(player->mo, sfx_plroof); // FS: was NULL
return;
}
break;
case 28: // Green Lock
case 33:
if (!player)
{
return;
}
if (!player->keys[key_green])
{
P_SetMessage(player, TXT_NEEDGREENKEY, false);
S_StartSound(player->mo, sfx_plroof); // FS: was NULL
return;
}
break;
}
// if the sector has an active thinker, use it
sec = sides[line->sidenum[side ^ 1]].sector;
secnum = sec - sectors;
if (sec->specialdata)
{
door = sec->specialdata;
switch (line->special)
{
case 1: // ONLY FOR "RAISE" DOORS, NOT "OPEN"s
case 26:
case 27:
case 28:
if (door->direction == -1)
{
door->direction = 1; // go back up
}
else
{
if (!thing->player)
{ // Monsters don't close doors
return;
}
door->direction = -1; // start going down immediately
}
return;
}
}
// for proper sound
switch (line->special)
{
case 1: // NORMAL DOOR SOUND
case 31:
S_StartSound((mobj_t *)&sec->soundorg, sfx_doropn);
//S_StartSound((mobj_t *)&sec->soundorg, sfx_dormov);
break;
default: // LOCKED DOOR SOUND
S_StartSound((mobj_t *)&sec->soundorg, sfx_doropn);
//S_StartSound((mobj_t *)&sec->soundorg, sfx_dormov);
break;
}
//
// new door thinker
//
door = Z_Malloc (sizeof(*door), PU_LEVSPEC, 0);
P_AddThinker(&door->thinker);
sec->specialdata = door;
door->thinker.function = T_VerticalDoor;
door->sector = sec;
door->direction = 1;
switch (line->special)
{
case 1:
case 26:
case 27:
case 28:
door->type = doornormal;
break;
case 31:
case 32:
case 33:
case 34:
door->type = dooropen;
line->special = 0;
break;
}
door->speed = VDOORSPEED;
door->topwait = VDOORWAIT;
//
// find the top and bottom of the movement range
//
door->topheight = P_FindLowestCeilingSurrounding(sec);
door->topheight -= 4 * FRACUNIT;
}
//==================================================================
//
// Spawn a door that closes after 30 seconds
//
//==================================================================
void P_SpawnDoorCloseIn30(sector_t *sec)
{
vldoor_t *door;
door = Z_Malloc(sizeof(*door), PU_LEVSPEC, 0);
P_AddThinker(&door->thinker);
sec->specialdata = door;
sec->special = 0;
door->thinker.function = T_VerticalDoor;
door->sector = sec;
door->direction = 0;
door->type = doornormal;
door->speed = VDOORSPEED;
door->topcountdown = 30 * 35;
}
//==================================================================
//
// Spawn a door that opens after 5 minutes
//
//==================================================================
void P_SpawnDoorRaiseIn5Mins(sector_t *sec, int secnum)
{
vldoor_t *door;
door = Z_Malloc(sizeof(*door), PU_LEVSPEC, 0);
P_AddThinker(&door->thinker);
sec->specialdata = door;
sec->special = 0;
door->thinker.function = T_VerticalDoor;
door->sector = sec;
door->direction = 2;
door->type = raiseIn5Mins;
door->speed = VDOORSPEED;
door->topheight = P_FindLowestCeilingSurrounding(sec);
door->topheight -= 4 * FRACUNIT;
door->topwait = VDOORWAIT;
door->topcountdown = 5 * 60 * 35;
}