/
p_ceiling.c
562 lines (499 loc) · 15.2 KB
/
p_ceiling.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
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
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2009 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2009 Daniel Swanson <danij@dengine.net>
*\author Copyright © 2006 Martin Eyre <martineyre@btinternet.com>
*\author Copyright © 2003-2005 Samuel Villarreal <svkaiser@gmail.com>
*\author Copyright © 1999 by Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman (PrBoom 2.2.6)
*\author Copyright © 1999-2000 by Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze (PrBoom 2.2.6)
*\author Copyright © 1993-1996 by id Software, Inc.
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/**
* p_ceilings.c : Moving ceilings (lowering, crushing, raising).
*/
// HEADER FILES ------------------------------------------------------------
#if __JDOOM__
# include "jdoom.h"
#elif __JDOOM64__
# include "jdoom64.h"
#elif __JHERETIC__
# include "jheretic.h"
#elif __JHEXEN__
# include "jhexen.h"
#endif
#include "dmu_lib.h"
#include "p_mapspec.h"
#include "p_start.h"
#include "p_tick.h"
#include "p_ceiling.h"
// MACROS ------------------------------------------------------------------
// Sounds played by the ceilings when changing state or moving.
// jHexen uses sound sequences, so it's are defined as 'SFX_NONE'.
#if __JDOOM__
# define SFX_CEILINGMOVE (SFX_STNMOV)
# define SFX_CEILINGSTOP (SFX_PSTOP)
#elif __JDOOM64__
# define SFX_CEILINGMOVE (SFX_STNMOV)
# define SFX_CEILINGSTOP (SFX_PSTOP)
#elif __JHERETIC__
# define SFX_CEILINGMOVE (SFX_DORMOV)
# define SFX_CEILINGSTOP (SFX_NONE)
#elif __JHEXEN__
# define SFX_CEILINGMOVE (SFX_NONE)
# define SFX_CEILINGSTOP (SFX_NONE)
#endif
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
// PRIVATE DATA DEFINITIONS ------------------------------------------------
// CODE --------------------------------------------------------------------
/**
* Called when a moving ceiling needs to be removed.
*
* @param ceiling Ptr to the ceiling to be stopped.
*/
static void stopCeiling(ceiling_t* ceiling)
{
P_ToXSector(ceiling->sector)->specialData = NULL;
#if __JHEXEN__
P_TagFinished(P_ToXSector(ceiling->sector)->tag);
#endif
DD_ThinkerRemove(&ceiling->thinker);
}
void T_MoveCeiling(ceiling_t* ceiling)
{
result_e res;
switch(ceiling->state)
{
case CS_UP: // Going up.
res =
T_MovePlane(ceiling->sector, ceiling->speed, ceiling->topHeight,
false, 1, 1);
// Play a "while-moving" sound?
#if !__JHEXEN__
if(!(mapTime & 7))
{
# if __JHERETIC__
S_SectorSound(ceiling->sector, SORG_CEILING, SFX_CEILINGMOVE);
# else
switch(ceiling->type)
{
case CT_SILENTCRUSHANDRAISE:
break;
default:
S_SectorSound(ceiling->sector, SORG_CEILING, SFX_CEILINGMOVE);
break;
}
# endif
}
#endif
if(res == pastdest)
{
#if __JHEXEN__
SN_StopSequence(P_SectorSoundOrigin(ceiling->sector));
#endif
switch(ceiling->type)
{
#if !__JHEXEN__
case CT_RAISETOHIGHEST:
# if __JDOOM64__
case CT_CUSTOM: //jd64
# endif
stopCeiling(ceiling);
break;
# if !__JHERETIC__
case CT_SILENTCRUSHANDRAISE:
S_SectorSound(ceiling->sector, SORG_CEILING, SFX_CEILINGSTOP);
# endif
case CT_CRUSHANDRAISEFAST:
#endif
case CT_CRUSHANDRAISE:
ceiling->state = CS_DOWN;
#if __JHEXEN__
ceiling->speed *= 2;
#endif
break;
default:
#if __JHEXEN__
stopCeiling(ceiling);
#endif
break;
}
}
break;
case CS_DOWN: // Going down.
res =
T_MovePlane(ceiling->sector, ceiling->speed, ceiling->bottomHeight,
ceiling->crush, 1, -1);
// Play a "while-moving" sound?
#if !__JHEXEN__
if(!(mapTime & 7))
{
# if __JHERETIC__
S_SectorSound(ceiling->sector, SORG_CEILING, SFX_CEILINGMOVE);
# else
switch(ceiling->type)
{
case CT_SILENTCRUSHANDRAISE:
break;
default:
S_SectorSound(ceiling->sector, SORG_CEILING, SFX_CEILINGMOVE);
}
# endif
}
#endif
if(res == pastdest)
{
#if __JHEXEN__
SN_StopSequence(P_SectorSoundOrigin(ceiling->sector));
#endif
switch(ceiling->type)
{
#if __JDOOM__ || __JDOOM64__
case CT_SILENTCRUSHANDRAISE:
S_SectorSound(ceiling->sector, SORG_CEILING, SFX_CEILINGSTOP);
ceiling->speed = CEILSPEED;
ceiling->state = CS_UP;
break;
#endif
case CT_CRUSHANDRAISE:
#if __JHEXEN__
case CT_CRUSHRAISEANDSTAY:
#endif
#if __JHEXEN__
ceiling->speed = ceiling->speed * .5;
#else
ceiling->speed = CEILSPEED;
#endif
ceiling->state = CS_UP;
break;
#if !__JHEXEN__
case CT_CRUSHANDRAISEFAST:
ceiling->state = CS_UP;
break;
case CT_LOWERANDCRUSH:
case CT_LOWERTOFLOOR:
# if __JDOOM64__
case CT_CUSTOM: //jd64
# endif
stopCeiling(ceiling);
break;
#endif
default:
#if __JHEXEN__
stopCeiling(ceiling);
#endif
break;
}
}
else // ( res != pastdest )
{
if(res == crushed)
{
switch(ceiling->type)
{
#if __JDOOM__ || __JDOOM64__
case CT_SILENTCRUSHANDRAISE:
#endif
case CT_CRUSHANDRAISE:
case CT_LOWERANDCRUSH:
#if __JHEXEN__
case CT_CRUSHRAISEANDSTAY:
#endif
#if !__JHEXEN__
ceiling->speed = CEILSPEED * .125;
#endif
break;
default:
break;
}
}
}
break;
}
}
#if __JDOOM64__
static int EV_DoCeiling2(linedef_t* line, int tag, float basespeed,
ceilingtype_e type)
#elif __JHEXEN__
static int EV_DoCeiling2(byte* arg, int tag, float basespeed, ceilingtype_e type)
#else
static int EV_DoCeiling2(int tag, float basespeed, ceilingtype_e type)
#endif
{
int rtn = 0;
xsector_t* xsec;
sector_t* sec = NULL;
ceiling_t* ceiling;
iterlist_t* list;
list = P_GetSectorIterListForTag(tag, false);
if(!list)
return rtn;
P_IterListResetIterator(list, true);
while((sec = P_IterListIterator(list)) != NULL)
{
xsec = P_ToXSector(sec);
if(xsec->specialData)
continue;
// new door thinker
rtn = 1;
ceiling = Z_Calloc(sizeof(*ceiling), PU_MAP, 0);
ceiling->thinker.function = T_MoveCeiling;
DD_ThinkerAdd(&ceiling->thinker);
xsec->specialData = ceiling;
ceiling->sector = sec;
ceiling->crush = false;
ceiling->speed = basespeed;
switch(type)
{
#if __JDOOM__ || __JHERETIC__ || __JDOOM64__
case CT_CRUSHANDRAISEFAST:
ceiling->crush = true;
ceiling->topHeight = P_GetFloatp(sec, DMU_CEILING_HEIGHT);
ceiling->bottomHeight =
P_GetFloatp(sec, DMU_FLOOR_HEIGHT) + 8;
ceiling->state = CS_DOWN;
ceiling->speed *= 2;
break;
#endif
#if __JHEXEN__
case CT_CRUSHRAISEANDSTAY:
ceiling->crush = (int) arg[2]; // arg[2] = crushing value
ceiling->topHeight = P_GetFloatp(sec, DMU_CEILING_HEIGHT);
ceiling->bottomHeight = P_GetFloatp(sec, DMU_FLOOR_HEIGHT) + 8;
ceiling->state = CS_DOWN;
break;
#endif
#if __JDOOM__ || __JDOOM64__
case CT_SILENTCRUSHANDRAISE:
#endif
case CT_CRUSHANDRAISE:
#if !__JHEXEN__
ceiling->crush = true;
#endif
ceiling->topHeight = P_GetFloatp(sec, DMU_CEILING_HEIGHT);
case CT_LOWERANDCRUSH:
#if __JHEXEN__
ceiling->crush = (int) arg[2]; // arg[2] = crushing value
#endif
case CT_LOWERTOFLOOR:
ceiling->bottomHeight = P_GetFloatp(sec, DMU_FLOOR_HEIGHT);
if(type != CT_LOWERTOFLOOR)
ceiling->bottomHeight += 8;
ceiling->state = CS_DOWN;
#if __JDOOM64__
ceiling->speed *= 8; // jd64
#endif
break;
case CT_RAISETOHIGHEST:
P_FindSectorSurroundingHighestCeiling(sec, 0, &ceiling->topHeight);
#if __JDOOM64__
ceiling->topHeight -= 8; // jd64
#endif
ceiling->state = CS_UP;
break;
#if __JDOOM64__
case CT_CUSTOM: // jd64
{
//bitmip? wha?
sidedef_t *front = P_GetPtrp(line, DMU_SIDEDEF0);
sidedef_t *back = P_GetPtrp(line, DMU_SIDEDEF1);
float bitmipL = 0, bitmipR = 0;
bitmipL = P_GetFloatp(front, DMU_MIDDLE_MATERIAL_OFFSET_X);
if(back)
bitmipR = P_GetFloatp(back, DMU_MIDDLE_MATERIAL_OFFSET_X);
if(bitmipR > 0)
{
P_FindSectorSurroundingHighestCeiling(sec, 0, &ceiling->topHeight);
ceiling->state = CS_UP;
ceiling->speed *= bitmipL;
ceiling->topHeight -= bitmipR;
}
else
{
ceiling->bottomHeight = P_GetFloatp(sec, DMU_FLOOR_HEIGHT);
ceiling->bottomHeight -= bitmipR;
ceiling->state = CS_DOWN;
ceiling->speed *= bitmipL;
}
}
#endif
#if __JHEXEN__
case CT_LOWERBYVALUE:
ceiling->bottomHeight =
P_GetFloatp(sec, DMU_CEILING_HEIGHT) - (float) arg[2];
ceiling->state = CS_DOWN;
break;
case CT_RAISEBYVALUE:
ceiling->topHeight =
P_GetFloatp(sec, DMU_CEILING_HEIGHT) + (float) arg[2];
ceiling->state = CS_UP;
break;
case CT_MOVETOVALUEMUL8:
{
float destHeight = (float) arg[2] * 8;
if(arg[3]) // Going down?
destHeight = -destHeight;
if(P_GetFloatp(sec, DMU_CEILING_HEIGHT) <= destHeight)
{
ceiling->state = CS_UP;
ceiling->topHeight = destHeight;
if(P_GetFloatp(sec, DMU_CEILING_HEIGHT) == destHeight)
rtn = 0;
}
else if(P_GetFloatp(sec, DMU_CEILING_HEIGHT) > destHeight)
{
ceiling->state = CS_DOWN;
ceiling->bottomHeight = destHeight;
}
break;
}
#endif
default:
#if __JHEXEN__
rtn = 0;
#endif
break;
}
ceiling->tag = xsec->tag;
ceiling->type = type;
#if __JHEXEN__
if(rtn)
{
SN_StartSequence(P_SectorSoundOrigin(ceiling->sector),
SEQ_PLATFORM + P_ToXSector(ceiling->sector)->seqType);
}
#endif
}
return rtn;
}
/**
* Move a ceiling up/down.
*/
#if __JHEXEN__
int EV_DoCeiling(linedef_t *line, byte *args, ceilingtype_e type)
#else
int EV_DoCeiling(linedef_t *line, ceilingtype_e type)
#endif
{
#if __JHEXEN__
return EV_DoCeiling2(args, (int) args[0], (float) args[1] * (1.0 / 8),
type);
#else
int rtn = 0;
// Reactivate in-stasis ceilings...for certain types.
switch(type)
{
case CT_CRUSHANDRAISEFAST:
# if __JDOOM__ || __JDOOM64__
case CT_SILENTCRUSHANDRAISE:
# endif
case CT_CRUSHANDRAISE:
rtn = P_CeilingActivate(P_ToXLine(line)->tag);
break;
default:
break;
}
# if __JDOOM64__
return EV_DoCeiling2(line, P_ToXLine(line)->tag, CEILSPEED, type) || rtn;
# else
return EV_DoCeiling2(P_ToXLine(line)->tag, CEILSPEED, type) || rtn;
# endif
#endif
}
#if !__JHEXEN__
typedef struct {
short tag;
int count;
} activateceilingparams_t;
static boolean activateCeiling(thinker_t* th, void* context)
{
ceiling_t* ceiling = (ceiling_t*) th;
activateceilingparams_t* params = (activateceilingparams_t*) context;
if(ceiling->tag == (int) params->tag && ceiling->thinker.inStasis)
{
ceiling->state = ceiling->oldState;
DD_ThinkerSetStasis(&ceiling->thinker, false);
params->count++;
}
return true; // Continue iteration.
}
/**
* Reactivates all stopped crushers with the right tag.
*
* @param tag Tag of ceilings to activate.
*
* @return @c true, if a ceiling is activated.
*/
int P_CeilingActivate(short tag)
{
activateceilingparams_t params;
params.tag = tag;
params.count = 0;
DD_IterateThinkers(T_MoveCeiling, activateCeiling, ¶ms);
return params.count;
}
#endif
typedef struct {
short tag;
int count;
} deactivateceilingparams_t;
static boolean deactivateCeiling(thinker_t* th, void* context)
{
ceiling_t* ceiling = (ceiling_t*) th;
deactivateceilingparams_t* params =
(deactivateceilingparams_t*) context;
#if __JHEXEN__
if(ceiling->tag == (int) params->tag)
{ // Destroy it.
SN_StopSequence(P_SectorSoundOrigin(ceiling->sector));
stopCeiling(ceiling);
params->count++;
return false; // Stop iteration.
}
#else
if(!ceiling->thinker.inStasis && ceiling->tag == (int) params->tag)
{ // Put it into stasis.
ceiling->oldState = ceiling->state;
DD_ThinkerSetStasis(&ceiling->thinker, true);
params->count++;
}
#endif
return true; // Continue iteration.
}
/**
* Stops all active ceilings with the right tag.
*
* @param tag Tag of ceilings to stop.
*
* @return @c true, if a ceiling put in stasis.
*/
int P_CeilingDeactivate(short tag)
{
deactivateceilingparams_t params;
params.tag = tag;
params.count = 0;
DD_IterateThinkers(T_MoveCeiling, deactivateCeiling, ¶ms);
return params.count;
}