-
Notifications
You must be signed in to change notification settings - Fork 12
/
p_doors.c
440 lines (417 loc) · 10.7 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
#include "doomdef.h"
#include "p_local.h"
#include "st_main.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 normal:
door->direction = -1; /* time to go back down */
S_StartPositionedSound((void *)door->sector,sfx_dorcls,&P_SectorOrg);
break;
case blazeRaise:
door->direction = -1; /* time to go back down */
S_StartPositionedSound((void *)door->sector,sfx_bdcls,&P_SectorOrg);
break;
case close30ThenOpen:
door->direction = 1;
S_StartPositionedSound((void *)door->sector,sfx_doropn,&P_SectorOrg);
break;
default:
break;
}
break;
case 2: /* INITIAL WAIT */
if (!--door->topcountdown)
switch(door->type)
{
case raiseIn5Mins:
door->direction = 1;
door->type = normal;
S_StartPositionedSound((void *)&door->sector,sfx_doropn,&P_SectorOrg);
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 normal:
case close:
case blazeRaise:
case blazeClose:
door->sector->specialdata = NULL;
P_RemoveThinker (&door->thinker); /* unlink and free */
break;
case close30ThenOpen:
door->direction = 0;
door->topcountdown = 15*30*THINKERS_TICS;
break;
default:
break;
}
else if (res == crushed)
{
switch (door->type)
{
case blazeClose:
case close: /* DO NOT GO BACK UP! */
break;
case blazeRaise:
door->direction = 1;
S_StartPositionedSound((void *)door->sector,sfx_bdopn,&P_SectorOrg);
break;
default:
door->direction = 1;
S_StartPositionedSound((void *)door->sector,sfx_doropn,&P_SectorOrg);
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 normal:
case blazeRaise:
door->direction = 0; /* wait at top */
door->topcountdown = door->topwait;
break;
case close30ThenOpen:
case open:
case blazeOpen:
door->sector->specialdata = NULL;
P_RemoveThinker (&door->thinker); /* unlink and free */
break;
default:
break;
}
break;
}
}
/*================================================================== */
/* */
/* EV_DoDoor */
/* Move a door up/down and all around! */
/* */
/*================================================================== */
int EV_DoDoor (line_t *line, vldoor_e type)
{
int secnum,rtn;
sector_t *sec;
vldoor_t *door;
secnum = -1;
rtn = 0;
while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
{
sec = §ors[secnum];
if (sec->specialdata)
continue;
/* */
/* new door thinker */
/* */
rtn = 1;
door = Z_Malloc (sizeof(*door), PU_LEVSPEC);
P_AddThinker (&door->thinker);
sec->specialdata = door;
door->thinker.function = T_VerticalDoor;
door->sector = sec;
door->type = type;
door->speed = VDOORSPEED;
door->topwait = VDOORWAIT;
switch(type)
{
case blazeClose:
door->topheight = P_FindLowestCeilingSurrounding(sec);
door->topheight -= 4*FRACUNIT;
door->direction = -1;
door->speed = VDOORSPEED*4;
S_StartPositionedSound((void *)door->sector,sfx_bdcls,&P_SectorOrg);
break;
case close:
door->topheight = P_FindLowestCeilingSurrounding(sec);
door->topheight -= 4*FRACUNIT;
door->direction = -1;
S_StartPositionedSound((void *)door->sector,sfx_dorcls,&P_SectorOrg);
break;
case close30ThenOpen:
door->topheight = sec->ceilingheight;
door->direction = -1;
S_StartPositionedSound((void *)door->sector,sfx_dorcls,&P_SectorOrg);
break;
case blazeRaise:
case blazeOpen:
door->direction = 1;
door->topheight = P_FindLowestCeilingSurrounding(sec);
door->topheight -= 4 * FRACUNIT;
door->speed = VDOORSPEED * 4;
if (door->topheight != sec->ceilingheight)
S_StartPositionedSound((void *)door->sector,sfx_bdopn,&P_SectorOrg);
break;
case normal:
case open:
door->direction = 1;
door->topheight = P_FindLowestCeilingSurrounding(sec);
door->topheight -= 4*FRACUNIT;
if (door->topheight != sec->ceilingheight)
S_StartPositionedSound((void *)door->sector,sfx_doropn,&P_SectorOrg);
break;
default:
break;
}
}
return rtn;
}
/*================================================================== */
/* */
/* EV_VerticalDoor : open a door manually, no tag value */
/* */
/*================================================================== */
int EV_DoLockedDoor(line_t* line, vldoor_e type, mobj_t* thing)
{
player_t* player;
int pnum;
/* */
/* Check for locks */
/* */
player = thing->player ? &players[thing->player - 1] : NULL;
pnum = player ? player - players : 0;
if (!player)
return 0;
switch (line->special)
{
case 99: /* Blue Skull Lock */
case 133:
if (!player->cards[it_bluecard] && !player->cards[it_blueskull])
{
S_StartSound(thing, sfx_oof);
stbar[pnum].tryopen[it_bluecard] = true;
return 0;
}
break;
case 134: /* Red Card Lock */
case 135:
if (!player->cards[it_redcard] && !player->cards[it_redskull])
{
S_StartSound(thing, sfx_oof);
stbar[pnum].tryopen[it_redcard] = true;
return 0;
}
break;
case 136: /* Yellow Card Lock */
case 137:
if (!player->cards[it_yellowcard] && !player->cards[it_yellowskull])
{
S_StartSound(thing, sfx_oof);
stbar[pnum].tryopen[it_yellowcard] = true;
return 0;
}
break;
}
return EV_DoDoor(line, type);
}
/*================================================================== */
/* */
/* EV_VerticalDoor : open a door manually, no tag value */
/* */
/*================================================================== */
void EV_VerticalDoor (line_t *line, mobj_t *thing)
{
player_t *player;
int pnum = 0;
int secnum;
sector_t *sec;
vldoor_t *door;
int side;
side = 0; /* only front sides can be used */
/* */
/* Check for locks */
/* */
player = thing->player ? &players[thing->player - 1] : NULL;
pnum = player ? player - players : 0;
switch(line->special)
{
case 26: /* Blue Card Lock */
case 32:
if (!player)
return;
if (!player->cards[it_bluecard] && !player->cards[it_blueskull])
{
S_StartSound(thing,sfx_oof);
stbar[pnum].tryopen[it_bluecard] = true;
return;
}
break;
case 27: /* Yellow Card Lock */
case 34:
if (!player)
return;
if (!player->cards[it_yellowcard] && !player->cards[it_yellowskull])
{
S_StartSound(thing,sfx_oof);
stbar[pnum].tryopen[it_yellowcard] = true;
return;
}
break;
case 28: /* Red Card Lock */
case 33:
if (!player)
return;
if (!player->cards[it_redcard] && !player->cards[it_redskull])
{
S_StartSound(thing,sfx_oof);
stbar[pnum].tryopen[it_redcard] = true;
return;
}
break;
}
if (line->sidenum[side ^ 1] < 0)
{
I_Error("EV_VerticalDoor: DR special type on 1-sided linedef");
return;
}
/* if the sector has an active thinker, use it */
secnum = sides[ line->sidenum[side^1]] .sector;
sec = §ors[secnum];
if (sec->specialdata)
{
door = sec->specialdata;
switch(line->special)
{
case 1: /* ONLY FOR "RAISE" DOORS, NOT "OPEN"s */
case 26: /* BLUE CARD */
case 27: /* YELLOW CARD */
case 28: /* RED CARD */
case 117:
if (door->direction == -1)
door->direction = 1; /* go back up */
else
{
if (!thing->player)
return; /* JDC: bad guys never close doors */
door->direction = -1; /* start going down immediately */
}
return;
}
}
/* for proper sound */
switch(line->special)
{
case 117: /* BLAZING DOOR RAISE */
case 118: /* BLAZING DOOR OPEN */
S_StartPositionedSound((void*)sec,sfx_bdopn,&P_SectorOrg);
break;
case 1: /* NORMAL DOOR SOUND */
case 31:
S_StartPositionedSound((void*)sec,sfx_doropn,&P_SectorOrg);
break;
default: /* LOCKED DOOR SOUND */
S_StartPositionedSound((void*)sec,sfx_doropn,&P_SectorOrg);
break;
}
/* */
/* new door thinker */
/* */
door = Z_Malloc (sizeof(*door), PU_LEVSPEC);
P_AddThinker (&door->thinker);
sec->specialdata = door;
door->thinker.function = T_VerticalDoor;
door->sector = sec;
door->direction = 1;
door->speed = VDOORSPEED;
door->topwait = VDOORWAIT;
switch(line->special)
{
case 1:
case 26:
case 27:
case 28:
door->type = normal;
break;
case 31:
case 32:
case 33:
case 34:
door->type = open;
line->special = 0;
break;
case 117:
door->type = blazeRaise;
door->speed = VDOORSPEED * 4;
break;
case 118:
door->type = blazeOpen;
line->special = 0;
door->speed = VDOORSPEED * 4;
break;
}
/* */
/* 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);
P_AddThinker (&door->thinker);
sec->specialdata = door;
sec->special = 0;
door->thinker.function = T_VerticalDoor;
door->sector = sec;
door->direction = 0;
door->type = normal;
door->speed = VDOORSPEED;
door->topcountdown = 30 * 15 * THINKERS_TICS;
}
/*================================================================== */
/* */
/* 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);
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 * 15 * THINKERS_TICS;
}