[go: up one dir, main page]

Menu

[904618]: / src / p_doors.c  Maximize  Restore  History

Download this file

620 lines (522 with data), 16.8 kB

  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
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
// -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-
// ----------------------------------------------------------------------------
// :oCCCCOCoc.
// .cCO8OOOOOOOOO8Oo:
// .oOO8OOOOOOOOOOOOOOOCc
// cO8888: .:oOOOOC. TM
// :888888: :CCCc .oOOOOC. ### ### #########
// C888888: .ooo: .C######## ##### ##### ###### ###### ##########
// O888888: .oO### ### ##### ##### ######## ######## #### ###
// C888888: :8O. .C########## ### #### ### ## ## ## ## #### ###
// :8@@@@8: :888c o### ### #### ### ######## ######## ##########
// :8@@@@C C@@@@ oo######## ### ## ### ###### ###### #########
// cO@@@@@@@@@@@@@@@@@Oc0
// :oO8@@@@@@@@@@Oo.
// .oCOOOOOCc. http://remood.org/
// ----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
// Copyright (C) 2008-2013 GhostlyDeath <ghostlydeath@remood.org>
// <ghostlydeath@gmail.com>
// ----------------------------------------------------------------------------
// 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 3
// 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.
// ----------------------------------------------------------------------------
// DESCRIPTION:
// Door animation code (opening/closing)
#include "p_spec.h"
#include "s_sound.h"
#include "z_zone.h"
#include "p_demcmp.h"
#include "p_nwline.h"
#include "p_local.h"
#if 0
//
// Sliding door frame information
//
slidename_t slideFrameNames[MAXSLIDEDOORS] =
{
{
"GDOORF1", "GDOORF2", "GDOORF3", "GDOORF4", // front
"GDOORB1", "GDOORB2", "GDOORB3", "GDOORB4"
}
, // back
{"\0", "\0", "\0", "\0"}
};
#endif
// =========================================================================
// VERTICAL DOORS
// =========================================================================
int doorclosesound = sfx_dorcls;
//
// T_VerticalDoor
//
void T_VerticalDoor(vldoor_t* door)
{
result_e res;
int32_t LightArg;
switch (door->direction)
{
case 0:
// WAITING
if (!--door->topcountdown)
{
switch (door->type)
{
case blazeRaise:
case genBlazeRaise: //SoM: 3/6/2000
door->direction = -1; // time to go back down
S_StartSound((mobj_t*)&door->sector->soundorg, sfx_bdcls);
break;
case normalDoor:
case genRaise: //SoM: 3/6/2000
door->direction = -1; // time to go back down
S_StartSound((mobj_t*)&door->sector->soundorg, doorclosesound);
break;
case close30ThenOpen:
case genCdO: //SoM: 3/6/2000
door->direction = 1;
S_StartSound((mobj_t*)&door->sector->soundorg, sfx_doropn);
break;
//SoM: 3/6/2000
case genBlazeCdO:
door->direction = 1; // time to go back up
S_StartSound((mobj_t*)&door->sector->soundorg, sfx_bdopn);
break;
default:
break;
}
}
break;
case 2:
// INITIAL WAIT
if (!--door->topcountdown)
{
switch (door->type)
{
case raiseIn5Mins:
door->direction = 1;
door->type = normalDoor;
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 blazeRaise:
case blazeClose:
case genBlazeRaise:
case genBlazeClose:
door->sector->ceilingdata = NULL; // SoM: 3/6/2000
P_RemoveThinker(&door->thinker); // unlink and free
if (P_XGSVal(PGS_COBOOMSUPPORT)) //SoM: Removes the double closing sound of doors.
S_StartSound((mobj_t*)&door->sector->soundorg, sfx_bdcls);
break;
case normalDoor:
case doorclose:
case genRaise:
case genClose:
door->sector->ceilingdata = NULL; //SoM: 3/6/2000
P_RemoveThinker(&door->thinker); // unlink and free
break;
case close30ThenOpen:
door->direction = 0;
door->topcountdown = 35 * 30;
break;
//SoM: 3/6/2000: General door stuff
case genCdO:
case genBlazeCdO:
door->direction = 0;
door->topcountdown = door->topwait;
break;
default:
break;
}
//SoM: 3/6/2000: Code to turn lighting off in tagged sectors.
// Hurdler: FIXME: there is a bug in map27 with door->line not being correct
// after a save game / load game
if (P_XGSVal(PGS_COBOOMSUPPORT) && door->line && door->line->tag)
if ((door->line->special > GenLockedBase && (door->line->special & 6) == 6) || (P_NLSpecialXProp(door->line) & PNLXP_DOORLIGHT))
EV_TurnTagLightsOff(door->line);
}
else if (res == crushed)
{
switch (door->type)
{
case genClose: //SoM: 3/6/2000
case genBlazeClose: //SoM: 3/6/2000
case blazeClose:
case doorclose: // DO NOT 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 blazeRaise:
case normalDoor:
case genRaise: //SoM: 3/6/2000
case genBlazeRaise: //SoM: 3/6/2000
door->direction = 0; // wait at top
door->topcountdown = door->topwait;
break;
case close30ThenOpen:
case blazeOpen:
case dooropen:
case genBlazeOpen:
case genOpen:
case genCdO:
case genBlazeCdO:
door->sector->ceilingdata = NULL;
P_RemoveThinker(&door->thinker); // unlink and free
break;
default:
break;
}
//SoM: 3/6/2000: turn lighting on in tagged sectors of manual doors
LightArg = 0;
if (P_XGSVal(PGS_COBOOMSUPPORT) && door->line && door->line->tag)
if ((door->line->special > GenLockedBase && (door->line->special & 6) == 6) || (P_NLSpecialXProp(door->line) & PNLXP_DOORLIGHT)) //jff 3/9/98 all manual doors
EV_LightTurnOn(door->line, -1, NULL, LAT_FROMLINE, 0, NULL, 1, &LightArg);
}
break;
}
}
//
// EV_OpenDoor
// Generic function to open a door (used by FraggleScript)
void EV_OpenDoor(int sectag, int speed, int wait_time)
{
vldoor_e door_type;
int secnum = -1;
vldoor_t* door;
if (speed < 1)
speed = 1;
// find out door type first
if (wait_time) // door closes afterward
{
if (speed >= 4) // blazing ?
door_type = blazeRaise;
else
door_type = normalDoor;
}
else
{
if (speed >= 4) // blazing ?
door_type = blazeOpen;
else
door_type = dooropen;
}
// open door in all the sectors with the specified tag
while ((secnum = P_FindSectorFromTag(sectag, secnum)) >= 0)
{
sector_t* sec = &sectors[secnum];
// if the ceiling already moving, don't start the door action
if (P_SectorActive(ceiling_special, sec))
continue;
// new door thinker
door = Z_Malloc(sizeof(*door), PU_LEVSPEC, 0);
P_AddThinker(&door->thinker, PTT_VERTICALDOOR);
sec->ceilingdata = door;
door->thinker.function.acp1 = (actionf_p1) T_VerticalDoor;
door->sector = sec;
door->type = door_type;
door->topwait = wait_time;
door->speed = VDOORSPEED * speed;
door->line = NULL; // not triggered by a line
door->topheight = P_FindLowestCeilingSurrounding(sec) - 4 * FRACUNIT;
door->direction = 1;
if (door->topheight != sec->ceilingheight)
S_StartSound((mobj_t*)&door->sector->soundorg, speed >= 4 ? sfx_bdopn : sfx_doropn);
}
}
//
// EV_CloseDoor
//
// Used by FraggleScript
void EV_CloseDoor(int sectag, int speed)
{
vldoor_e door_type;
int secnum = -1;
vldoor_t* door;
if (speed < 1)
speed = 1;
// find out door type first
if (speed >= 4) // blazing ?
door_type = blazeClose;
else
door_type = doorclose;
// open door in all the sectors with the specified tag
while ((secnum = P_FindSectorFromTag(sectag, secnum)) >= 0)
{
sector_t* sec = &sectors[secnum];
// if the ceiling already moving, don't start the door action
if (P_SectorActive(ceiling_special, sec)) //jff 2/22/98
continue;
// new door thinker
door = Z_Malloc(sizeof(*door), PU_LEVSPEC, 0);
P_AddThinker(&door->thinker, PTT_VERTICALDOOR);
sec->ceilingdata = door;
door->thinker.function.acp1 = (actionf_p1) T_VerticalDoor;
door->sector = sec;
door->type = door_type;
door->speed = VDOORSPEED * speed;
door->line = NULL; // not triggered by a line
door->topheight = P_FindLowestCeilingSurrounding(sec) - 4 * FRACUNIT;
door->direction = -1;
S_StartSound((mobj_t*)&door->sector->soundorg, speed >= 4 ? sfx_bdcls : sfx_dorcls);
}
}
//
// Spawn a door that closes after 30 seconds
//
vldoor_t* P_SpawnDoorCloseIn(sector_t* sec, const uint32_t a_Tics, const uint32_t a_Type)
{
vldoor_t* door;
door = Z_Malloc(sizeof(*door), PU_LEVSPEC, 0);
P_AddThinker(&door->thinker, PTT_VERTICALDOOR);
sec->ceilingdata = door; //SoM: 3/6/2000
sec->special = 0;
door->thinker.function.acp1 = (actionf_p1) T_VerticalDoor;
door->sector = sec;
door->direction = 0;
door->type = a_Type;
door->speed = VDOORSPEED;
door->topcountdown = a_Tics;
door->line = NULL; //SoM: Remember the line that triggered the door.
return door;
}
void P_SpawnDoorCloseIn30(sector_t* sec)
{
P_SpawnDoorCloseIn(sec, 30 * 35, normalDoor);
}
//
// Spawn a door that opens after 5 minutes
//
vldoor_t* P_SpawnDoorRaiseIn(sector_t* sec, const bool_t a_InitWait, const uint32_t a_Tics, const uint32_t a_Type)
{
vldoor_t* door;
door = Z_Malloc(sizeof(*door), PU_LEVSPEC, 0);
P_AddThinker(&door->thinker, PTT_VERTICALDOOR);
sec->ceilingdata = door; //SoM: 3/6/2000
sec->special = 0;
door->thinker.function.acp1 = (actionf_p1) T_VerticalDoor;
door->sector = sec;
door->direction = (a_InitWait ? 2 : 1);
door->type = a_Type;
door->speed = VDOORSPEED;
door->topheight = P_FindLowestCeilingSurrounding(sec);
door->topheight -= 4 * FRACUNIT;
door->topwait = VDOORWAIT;
door->topcountdown = a_Tics;
door->line = NULL; //SoM: 3/6/2000: You know....
return door;
}
void P_SpawnDoorRaiseIn5Mins(sector_t* sec, int secnum)
{
P_SpawnDoorRaiseIn(sec, true, 5 * 60 * 35, raiseIn5Mins);
}
// ==========================================================================
// SLIDE DOORS, UNUSED
// ==========================================================================
#if 0 // ABANDONED TO THE MISTS OF TIME!!!
//
// EV_SlidingDoor : slide a door horizontally
// (animate midtexture, then set noblocking line)
//
/*slideframe_t slideFrames[MAXSLIDEDOORS];
void P_InitSlidingDoorFrames(void)
{
int i;
int f1;
int f2;
int f3;
int f4;
// DOOM II ONLY...
if ( gamemode != commercial)
return;
for (i = 0;i < MAXSLIDEDOORS; i++)
{
if (!slideFrameNames[i].frontFrame1[0])
break;
f1 = R_TextureNumForName(slideFrameNames[i].frontFrame1);
f2 = R_TextureNumForName(slideFrameNames[i].frontFrame2);
f3 = R_TextureNumForName(slideFrameNames[i].frontFrame3);
f4 = R_TextureNumForName(slideFrameNames[i].frontFrame4);
slideFrames[i].frontFrames[0] = f1;
slideFrames[i].frontFrames[1] = f2;
slideFrames[i].frontFrames[2] = f3;
slideFrames[i].frontFrames[3] = f4;
f1 = R_TextureNumForName(slideFrameNames[i].backFrame1);
f2 = R_TextureNumForName(slideFrameNames[i].backFrame2);
f3 = R_TextureNumForName(slideFrameNames[i].backFrame3);
f4 = R_TextureNumForName(slideFrameNames[i].backFrame4);
slideFrames[i].backFrames[0] = f1;
slideFrames[i].backFrames[1] = f2;
slideFrames[i].backFrames[2] = f3;
slideFrames[i].backFrames[3] = f4;
}
}
//
// Return index into "slideFrames" array
// for which door type to use
//
int P_FindSlidingDoorType(line_t* line)
{
int i;
int val;
for (i = 0;i < MAXSLIDEDOORS;i++)
{
val = sides[line->sidenum[0]].midtexture;
if (val == slideFrames[i].frontFrames[0])
return i;
}
return -1;
}
void T_SlidingDoor (slidedoor_t* door)
{
switch(door->status)
{
case sd_opening:
if (!door->timer--)
{
if (++door->frame == SNUMFRAMES)
{
// IF DOOR IS DONE OPENING...
sides[door->line->sidenum[0]].midtexture = 0;
sides[door->line->sidenum[1]].midtexture = 0;
door->line->flags &= ML_BLOCKING^0xff;
if (door->type == sdt_openOnly)
{
door->frontsector->ceilingdata = NULL;
P_RemoveThinker (&door->thinker);
break;
}
door->timer = SDOORWAIT;
door->status = sd_waiting;
}
else
{
// IF DOOR NEEDS TO ANIMATE TO NEXT FRAME...
door->timer = SWAITTICS;
sides[door->line->sidenum[0]].midtexture =
slideFrames[door->whichDoorIndex].
frontFrames[door->frame];
sides[door->line->sidenum[1]].midtexture =
slideFrames[door->whichDoorIndex].
backFrames[door->frame];
}
}
break;
case sd_waiting:
// IF DOOR IS DONE WAITING...
if (!door->timer--)
{
// CAN DOOR CLOSE?
if (door->frontsector->thinglist != NULL ||
door->backsector->thinglist != NULL)
{
door->timer = SDOORWAIT;
break;
}
//door->frame = SNUMFRAMES-1;
door->status = sd_closing;
door->timer = SWAITTICS;
}
break;
case sd_closing:
if (!door->timer--)
{
if (--door->frame < 0)
{
// IF DOOR IS DONE CLOSING...
door->line->flags |= ML_BLOCKING;
door->frontsector->specialdata = NULL;
P_RemoveThinker (&door->thinker);
break;
}
else
{
// IF DOOR NEEDS TO ANIMATE TO NEXT FRAME...
door->timer = SWAITTICS;
sides[door->line->sidenum[0]].midtexture =
slideFrames[door->whichDoorIndex].
frontFrames[door->frame];
sides[door->line->sidenum[1]].midtexture =
slideFrames[door->whichDoorIndex].
backFrames[door->frame];
}
}
break;
}
}
void
EV_SlidingDoor
( line_t* line,
mobj_t* thing )
{
sector_t* sec;
slidedoor_t* door;
// DOOM II ONLY...
if (gamemode != commercial)
return;
// Make sure door isn't already being animated
sec = line->frontsector;
door = NULL;
if (sec->specialdata)
{
if (!thing->player)
return;
door = sec->specialdata;
if (door->type == sdt_openAndClose)
{
if (door->status == sd_waiting)
door->status = sd_closing;
}
else
return;
}
// Init sliding door vars
if (!door)
{
door = Z_Malloc (sizeof(*door), PU_LEVSPEC, 0);
P_AddThinker (&door->thinker);
sec->specialdata = door;
door->type = sdt_openAndClose;
door->status = sd_opening;
door->whichDoorIndex = P_FindSlidingDoorType(line);
if (door->whichDoorIndex < 0)
I_Error("EV_SlidingDoor: Can't use texture for sliding door!");
door->frontsector = sec;
door->backsector = line->backsector;
door->thinker.function = T_SlidingDoor;
door->timer = SWAITTICS;
door->frame = 0;
door->line = line;
}
}*/
#endif