-
Notifications
You must be signed in to change notification settings - Fork 5
/
p_doors.pas
566 lines (514 loc) · 15.3 KB
/
p_doors.pas
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
//------------------------------------------------------------------------------
//
// FPCDoom - Port of Doom to Free Pascal Compiler
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 2004-2007 by Jim Valavanis
// Copyright (C) 2017-2022 by Jim Valavanis
//
// 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.
//
//------------------------------------------------------------------------------
// E-Mail: [email protected]
// Site : https://sourceforge.net/projects/fpcdoom/
//------------------------------------------------------------------------------
{$I FPCDoom.inc}
unit p_doors;
interface
uses
z_memory,
doomdef,
p_mobj_h,
p_spec,
r_defs,
s_sound,
// Data.
d_english,
sounds;
//==============================================================================
//
// T_VerticalDoor
//
//==============================================================================
procedure T_VerticalDoor(door: Pvldoor_t);
//==============================================================================
//
// EV_DoLockedDoor
//
//==============================================================================
function EV_DoLockedDoor(line: Pline_t; _type: vldoor_e; thing: Pmobj_t): integer;
//==============================================================================
//
// EV_DoDoor
//
//==============================================================================
function EV_DoDoor(line: Pline_t; _type: vldoor_e): integer;
//==============================================================================
//
// EV_VerticalDoor
//
//==============================================================================
procedure EV_VerticalDoor(line: Pline_t; thing: Pmobj_t);
//==============================================================================
//
// P_SpawnDoorCloseIn30
//
//==============================================================================
procedure P_SpawnDoorCloseIn30(sec: Psector_t);
//==============================================================================
//
// P_SpawnDoorRaiseIn5Mins
//
//==============================================================================
procedure P_SpawnDoorRaiseIn5Mins(sec: Psector_t; secnum: integer);
implementation
uses
m_fixed,
d_player,
p_tick,
p_setup,
p_floor;
//==============================================================================
//
// VERTICAL DOORS
//
// T_VerticalDoor
//
//==============================================================================
procedure T_VerticalDoor(door: Pvldoor_t);
var
res: result_e;
begin
case door.direction of
0:
begin
// WAITING
dec(door.topcountdown);
if door.topcountdown = 0 then
begin
case door._type of
blazeRaise:
begin
door.direction := -1; // time to go back down
S_StartSound(Pmobj_t(@door.sector.soundorg), Ord(sfx_bdcls));
end;
normal:
begin
door.direction := -1; // time to go back down
S_StartSound(Pmobj_t(@door.sector.soundorg), Ord(sfx_dorcls));
end;
close30ThenOpen:
begin
door.direction := 1;
S_StartSound(Pmobj_t(@door.sector.soundorg), Ord(sfx_doropn));
end;
end;
end;
end;
2:
begin
// INITIAL WAIT
dec(door.topcountdown);
if door.topcountdown = 0 then
begin
case door._type of
raiseIn5Mins:
begin
door.direction := 1;
door._type := normal;
S_StartSound(Pmobj_t(@door.sector.soundorg), Ord(sfx_doropn));
end;
end;
end;
end;
-1:
begin
// DOWN
res := T_MovePlane(door.sector, door.speed, door.sector.floorheight,
false, 1, door.direction);
if res = pastdest then
begin
case door._type of
blazeRaise,
blazeClose:
begin
door.sector.specialdata := nil;
P_RemoveThinker(@door.thinker); // unlink and free
S_StartSound(Pmobj_t(@door.sector.soundorg), Ord(sfx_bdcls));
end;
normal,
close:
begin
door.sector.specialdata := nil;
P_RemoveThinker(@door.thinker); // unlink and free
end;
close30ThenOpen:
begin
door.direction := 0;
door.topcountdown := TICRATE * 30;
end;
end;
end
else if res = crushed then
begin
case door._type of
blazeClose,
close: // DO NOT GO BACK UP!
begin
end;
else
begin
door.direction := 1;
S_StartSound(Pmobj_t(@door.sector.soundorg), Ord(sfx_doropn));
end;
end;
end;
end;
1:
begin
// UP
res := T_MovePlane(door.sector, door.speed, door.topheight,
false, 1, door.direction);
if res = pastdest then
begin
case door._type of
blazeRaise,
normal:
begin
door.direction := 0; // wait at top
door.topcountdown := door.topwait;
end;
close30ThenOpen,
blazeOpen,
open:
begin
door.sector.specialdata := nil;
P_RemoveThinker(@door.thinker); // unlink and free
end;
end;
end;
end;
end;
end;
//==============================================================================
//
// EV_DoLockedDoor
// Move a locked door up/down
//
//==============================================================================
function EV_DoLockedDoor(line: Pline_t; _type: vldoor_e; thing: Pmobj_t): integer;
var
p: Pplayer_t;
begin
p := thing.player;
if p = nil then
begin
result := 0;
exit;
end;
case line.special of
99, // Blue Lock
133:
begin
if not p.cards[Ord(it_bluecard)] and
not p.cards[Ord(it_blueskull)] then
begin
p._message := PD_BLUEO;
S_StartSound(nil, Ord(sfx_oof));
result := 0;
exit;
end;
end;
134, // Red Lock
135:
begin
if not p.cards[Ord(it_redcard)] and
not p.cards[Ord(it_redskull)] then
begin
p._message := PD_REDO;
S_StartSound(nil, Ord(sfx_oof));
result := 0;
exit;
end;
end;
136, // Yellow Lock
137:
begin
if not p.cards[Ord(it_yellowcard)] and
not p.cards[Ord(it_yellowskull)] then
begin
p._message := PD_YELLOWO;
S_StartSound(nil, Ord(sfx_oof));
result := 0;
exit;
end;
end;
end;
result := EV_DoDoor(line, _type);
end;
//==============================================================================
//
// EV_DoDoor
//
//==============================================================================
function EV_DoDoor(line: Pline_t; _type: vldoor_e): integer;
var
initial: boolean;
secnum: integer;
sec: Psector_t;
door: Pvldoor_t;
begin
secnum := -1;
result := 0;
initial := true;
while (secnum >= 0) or initial do
begin
initial := false;
secnum := P_FindSectorFromLineTag(line, secnum);
if secnum < 0 then
break;
sec := @sectors[secnum];
if sec.specialdata <> nil then
continue;
// new door thinker
result := 1;
door := Z_Malloc(SizeOf(vldoor_t), PU_LEVSPEC, nil);
P_AddThinker(@door.thinker);
sec.specialdata := door;
door.thinker._function.acp1 := @T_VerticalDoor;
door.sector := sec;
door._type := _type;
door.topwait := VDOORWAIT;
door.speed := VDOORSPEED;
case _type of
blazeClose:
begin
door.topheight := P_FindLowestCeilingSurrounding(sec);
door.topheight := door.topheight - 4 * FRACUNIT;
door.direction := -1;
door.speed := VDOORSPEED * 4;
S_StartSound(Pmobj_t(@door.sector.soundorg), Ord(sfx_bdcls));
end;
close:
begin
door.topheight := P_FindLowestCeilingSurrounding(sec);
door.topheight := door.topheight - 4 * FRACUNIT;
door.direction := -1;
S_StartSound(Pmobj_t(@door.sector.soundorg), Ord(sfx_dorcls));
end;
close30ThenOpen:
begin
door.topheight := sec.ceilingheight;
door.direction := -1;
S_StartSound(Pmobj_t(@door.sector.soundorg), Ord(sfx_dorcls));
end;
blazeRaise,
blazeOpen:
begin
door.direction := 1;
door.topheight := P_FindLowestCeilingSurrounding(sec);
door.topheight := door.topheight - 4 * FRACUNIT;
door.speed := VDOORSPEED * 4;
if door.topheight <> sec.ceilingheight then
S_StartSound(Pmobj_t(@door.sector.soundorg), Ord(sfx_bdopn));
end;
normal,
open:
begin
door.direction := 1;
door.topheight := P_FindLowestCeilingSurrounding(sec);
door.topheight := door.topheight - 4 * FRACUNIT;
if door.topheight <> sec.ceilingheight then
S_StartSound(Pmobj_t(@door.sector.soundorg), Ord(sfx_doropn));
end;
end;
end;
end;
//==============================================================================
//
// EV_VerticalDoor : open a door manually, no tag value
//
//==============================================================================
procedure EV_VerticalDoor(line: Pline_t; thing: Pmobj_t);
var
player: Pplayer_t;
sec: Psector_t;
door: Pvldoor_t;
side: integer;
begin
side := 0; // only front sides can be used
// Check for locks
player := thing.player;
case line.special of
26, // Blue Lock
32:
begin
if player = nil then
exit;
if (not player.cards[Ord(it_bluecard)]) and
(not player.cards[Ord(it_blueskull)]) then
begin
player._message := PD_BLUEK;
S_StartSound(nil, Ord(sfx_oof));
exit;
end;
end;
27, // Yellow Lock
34:
begin
if player = nil then
exit;
if (not player.cards[Ord(it_yellowcard)]) and
(not player.cards[Ord(it_yellowskull)]) then
begin
player._message := PD_YELLOWK;
S_StartSound(nil, Ord(sfx_oof));
exit;
end;
end;
28, // Red Lock
33:
begin
if player = nil then
exit;
if (not player.cards[Ord(it_redcard)]) and
(not player.cards[Ord(it_redskull)]) then
begin
player._message := PD_REDK;
S_StartSound(nil, Ord(sfx_oof));
exit;
end;
end;
end;
// if the sector has an active thinker, use it
sec := sides[line.sidenum[side xor 1]].sector;
if sec.specialdata <> nil then
begin
door := sec.specialdata;
case line.special of
1, // ONLY FOR "RAISE" DOORS, NOT "OPEN"s
26,
27,
28,
117:
begin
if door.direction = -1 then
door.direction := 1 // go back up
else
begin
if thing.player = nil then
exit; // JDC: bad guys never close doors
door.direction := -1; // start going down immediately
end;
exit;
end;
end;
end;
// for proper sound
case line.special of
117, // BLAZING DOOR RAISE
118: // BLAZING DOOR OPEN
S_StartSound(Pmobj_t(@sec.soundorg), Ord(sfx_bdopn));
1, // NORMAL DOOR SOUND
31:
S_StartSound(Pmobj_t(@sec.soundorg), Ord(sfx_doropn));
else // LOCKED DOOR SOUND
S_StartSound(Pmobj_t(@sec.soundorg), Ord(sfx_doropn));
end;
// new door thinker
door := Z_Malloc(SizeOf(vldoor_t), PU_LEVSPEC, nil);
P_AddThinker(@door.thinker);
sec.specialdata := door;
door.thinker._function.acp1 := @T_VerticalDoor;
door.sector := sec;
door.direction := 1;
door.speed := VDOORSPEED;
door.topwait := VDOORWAIT;
case line.special of
1,
26,
27,
28:
door._type := normal;
31,
32,
33,
34:
begin
door._type := open;
line.special := 0;
end;
117: // blazing door raise
begin
door._type := blazeRaise;
door.speed := VDOORSPEED * 4;
end;
118: // blazing door open
begin
door._type := blazeOpen;
line.special := 0;
door.speed := VDOORSPEED * 4;
end;
end;
// find the top and bottom of the movement range
door.topheight := P_FindLowestCeilingSurrounding(sec);
door.topheight := door.topheight - 4 * FRACUNIT;
end;
//==============================================================================
// P_SpawnDoorCloseIn30
//
// Spawn a door that closes after 30 seconds
//
//==============================================================================
procedure P_SpawnDoorCloseIn30(sec: Psector_t);
var
door: Pvldoor_t;
begin
door := Z_Malloc(SizeOf(vldoor_t), PU_LEVSPEC, nil);
P_AddThinker(@door.thinker);
sec.specialdata := door;
sec.special := 0;
door.thinker._function.acp1 := @T_VerticalDoor;
door.sector := sec;
door.direction := 0;
door._type := normal;
door.speed := VDOORSPEED;
door.topcountdown := 30 * TICRATE;
end;
//==============================================================================
// P_SpawnDoorRaiseIn5Mins
//
// Spawn a door that opens after 5 minutes
//
//==============================================================================
procedure P_SpawnDoorRaiseIn5Mins(sec: Psector_t; secnum: integer);
var
door: Pvldoor_t;
begin
door := Z_Malloc(SizeOf(vldoor_t), PU_LEVSPEC, nil);
P_AddThinker(@door.thinker);
sec.specialdata := door;
sec.special := 0;
door.thinker._function.acp1 := @T_VerticalDoor;
door.sector := sec;
door.direction := 2;
door._type := raiseIn5Mins;
door.speed := VDOORSPEED;
door.topheight := P_FindLowestCeilingSurrounding(sec);
door.topheight := door.topheight - 4 * FRACUNIT;
door.topwait := VDOORWAIT;
door.topcountdown := 5 * 60 * TICRATE;
end;
end.