-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathp_floor.c
536 lines (461 loc) · 14.7 KB
/
p_floor.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
/* Emacs style mode select -*- C++ -*-
*-----------------------------------------------------------------------------
*
*
* PrBoom: a Doom port merged with LxDoom and LSDLDoom
* based on BOOM, a modified and improved DOOM engine
* Copyright (C) 1999 by
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
* Copyright (C) 1999-2000 by
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
* Copyright 2005, 2006 by
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
* Copyright 2023, 2024 by
* Frenkel Smeijers
*
* 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.
*
* DESCRIPTION:
* General plane mover and floor mover action routines
* Floor motion, pure changer types, raising stairs. donuts, elevators
*
*-----------------------------------------------------------------------------*/
#include "d_player.h"
#include "r_main.h"
#include "m_random.h"
#include "p_inter.h"
#include "p_map.h"
#include "p_spec.h"
#include "p_tick.h"
#include "sounds.h"
#include "globdata.h"
static boolean nofit;
//
// P_ThingHeightClip
// Takes a valid thing and adjusts the thing->floorz,
// thing->ceilingz, and possibly thing->z.
// This is called for all nearby monsters
// whenever a sector changes height.
// If the thing doesn't fit,
// the z will be set to the lowest value
// and false will be returned.
//
static boolean P_ThingHeightClip(mobj_t __far* thing)
{
boolean onfloor;
onfloor = (thing->z == thing->floorz);
P_CheckPosition (thing, thing->x, thing->y);
/* what about stranding a monster partially off an edge?
* killough 11/98: Answer: see below (upset balance if hanging off ledge)
*/
thing->floorz = _g_tmfloorz;
thing->ceilingz = _g_tmceilingz;
thing->dropoffz = _g_tmdropoffz; /* killough 11/98: remember dropoffs */
if (onfloor)
{
// walking monsters rise and fall with the floor
thing->z = thing->floorz;
}
else
{
// don't adjust a floating monster unless forced to
if (thing->z+thing->height > thing->ceilingz)
thing->z = thing->ceilingz - thing->height;
}
return thing->ceilingz - thing->floorz >= thing->height;
}
//
// SECTOR HEIGHT CHANGING
// After modifying a sectors floor or ceiling height,
// call this routine to adjust the positions
// of all things that touch the sector.
//
// If anything doesn't fit anymore, true will be returned.
// If crunch is true, they will take damage
// as they are being crushed.
// If Crunch is false, you should set the sector height back
// the way it was and call P_ChangeSector again
// to undo the changes.
//
//
// PIT_ChangeSector
//
static void PIT_ChangeSector(mobj_t __far* thing)
{
if (P_ThingHeightClip (thing))
return;
// crunch bodies to giblets
if (thing->health <= 0)
{
P_SetMobjState (thing, S_GIBS);
thing->flags &= ~MF_SOLID;
thing->height = 0;
thing->radius = 0;
return;
}
// crunch dropped items
if (thing->flags & MF_DROPPED)
{
P_RemoveMobj (thing);
return;
}
if (! (thing->flags & MF_SHOOTABLE) )
{
// assume it is bloody gibs or something
return;
}
nofit = true;
}
//
// P_CheckSector
// jff 3/19/98 added to just check monsters on the periphery
// of a moving sector instead of all in bounding box of the
// sector. Both more accurate and faster.
//
static boolean P_CheckSector(sector_t __far* sector)
{
msecnode_t *n;
nofit = false;
// killough 4/4/98: scan list front-to-back until empty or exhausted,
// restarting from beginning after each thing is processed. Avoids
// crashes, and is sure to examine all things in the sector, and only
// the things which are in the sector, until a steady-state is reached.
// Things can arbitrarily be inserted and removed and it won't mess up.
//
// killough 4/7/98: simplified to avoid using complicated counter
// Mark all things invalid
for (n=sector->touching_thinglist; n; n=n->m_snext)
n->visited = false;
do
for (n=sector->touching_thinglist; n; n=n->m_snext) // go through list
if (!n->visited) // unprocessed thing found
{
n->visited = true; // mark thing as processed
if (!(n->m_thing->flags & MF_NOBLOCKMAP)) //jff 4/7/98 don't do these
PIT_ChangeSector(n->m_thing); // process it
break; // exit and start over
}
while (n); // repeat from scratch until all things left are marked valid
return nofit;
}
///////////////////////////////////////////////////////////////////////
//
// Plane (floor or ceiling), Floor motion and Elevator action routines
//
///////////////////////////////////////////////////////////////////////
//
// T_MovePlane()
//
// Move a plane (floor or ceiling) and check for crushing. Called
// every tick by all actions that move floors or ceilings.
//
// Passed the sector to move a plane in, the speed to move it at,
// the dest height it is to achieve, whether it crushes obstacles,
// whether it moves a floor or ceiling, and the direction up or down
// to move.
//
// Returns a result_e:
// ok - plane moved normally, has not achieved destination yet
// pastdest - plane moved normally and is now at destination height
// crushed - plane encountered an obstacle, is holding until removed
//
result_e T_MovePlaneFloor(sector_t __far* sector, fixed_t speed, fixed_t dest, int16_t direction)
{
boolean flag;
fixed_t lastpos;
fixed_t destheight; //jff 02/04/98 used to keep floors/ceilings
// from moving thru each other
switch(direction)
{
case -1:
// Moving a floor down
if (sector->floorheight - speed < dest)
{
lastpos = sector->floorheight;
sector->floorheight = dest;
flag = P_CheckSector(sector);
if (flag == true)
{
sector->floorheight =lastpos;
P_CheckSector(sector);
}
return pastdest;
}
else
{
lastpos = sector->floorheight;
sector->floorheight -= speed;
flag = P_CheckSector(sector);
/* cph - make more compatible with original Doom, by
* reintroducing this code. This means floors can't lower
* if objects are stuck in the ceiling */
}
break;
case 1:
// Moving a floor up
// jff 02/04/98 keep floor from moving thru ceilings
// jff 2/22/98 weaken check to demo_compatibility
destheight = (dest<sector->ceilingheight)?
dest : sector->ceilingheight;
if (sector->floorheight + speed > destheight)
{
lastpos = sector->floorheight;
sector->floorheight = destheight;
flag = P_CheckSector(sector);
if (flag == true)
{
sector->floorheight = lastpos;
P_CheckSector(sector);
}
return pastdest;
}
else
{
// crushing is possible
lastpos = sector->floorheight;
sector->floorheight += speed;
flag = P_CheckSector(sector);
if (flag == true)
{
sector->floorheight = lastpos;
P_CheckSector(sector);
return crushed;
}
}
break;
}
return ok;
}
result_e T_MovePlaneCeiling(sector_t __far* sector, fixed_t speed, fixed_t dest, int16_t direction)
{
boolean flag;
fixed_t lastpos;
fixed_t destheight; //jff 02/04/98 used to keep floors/ceilings
// from moving thru each other
switch(direction)
{
case -1:
// moving a ceiling down
// jff 02/04/98 keep ceiling from moving thru floors
// jff 2/22/98 weaken check to demo_compatibility
destheight = (dest>sector->floorheight)?
dest : sector->floorheight;
if (sector->ceilingheight - speed < destheight)
{
lastpos = sector->ceilingheight;
sector->ceilingheight = destheight;
flag = P_CheckSector(sector);
if (flag == true)
{
sector->ceilingheight = lastpos;
P_CheckSector(sector);
}
return pastdest;
}
else
{
// crushing is possible
lastpos = sector->ceilingheight;
sector->ceilingheight -= speed;
flag = P_CheckSector(sector);
if (flag == true)
{
sector->ceilingheight = lastpos;
P_CheckSector(sector);
return crushed;
}
}
break;
case 1:
// moving a ceiling up
if (sector->ceilingheight + speed > dest)
{
lastpos = sector->ceilingheight;
sector->ceilingheight = dest;
flag = P_CheckSector(sector);
if (flag == true)
{
sector->ceilingheight = lastpos;
P_CheckSector(sector);
}
return pastdest;
}
else
{
lastpos = sector->ceilingheight;
sector->ceilingheight += speed;
flag = P_CheckSector(sector);
}
break;
}
return ok;
}
//
// T_MoveFloor()
//
// Move a floor to it's destination (up or down).
// Called once per tick for each moving floor.
//
// Passed a floormove_t structure that contains all pertinent info about the
// move.
// No return.
//
// jff 02/08/98 all cases with labels beginning with gen added to support
// generalized line type behaviors.
typedef struct
{
thinker_t thinker;
floor_e type;
sector_t __far* sector;
int16_t direction;
int16_t texture;
fixed_t floordestheight;
fixed_t speed;
} floormove_t;
static void T_MoveFloor(floormove_t __far* floor)
{
result_e res;
// move the floor
res = T_MovePlaneFloor(floor->sector, floor->speed, floor->floordestheight, floor->direction);
if (res == pastdest) // if destination height is reached
{
if (floor->direction == 1) // going up
{
switch(floor->type) // handle texture/type changes
{
case donutRaise:
floor->sector->special = 0;
floor->sector->floorpic = floor->texture;
break;
default:
break;
}
}
floor->sector->floordata = NULL; //jff 2/22/98
P_RemoveThinker(&floor->thinker);//remove this floor from list of movers
}
}
//
// P_FindNextHighestFloor()
//
// Passed a sector, returns the fixed point value
// of the smallest floor height in a surrounding sector larger than
// the floor height passed. If no such height exists the floorheight
// of the passed sector is returned.
//
// Rewritten by Lee Killough to avoid fixed array and to be faster
//
fixed_t P_FindNextHighestFloor(sector_t __far* sec)
{
fixed_t currentheight = sec->floorheight;
sector_t __far* other;
int16_t i;
for (i=0 ;i < sec->linecount ; i++)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->floorheight > currentheight)
{
fixed_t height = other->floorheight;
while (++i < sec->linecount)
if ((other = getNextSector(sec->lines[i],sec)) &&
other->floorheight < height &&
other->floorheight > currentheight)
height = other->floorheight;
return height;
}
/* cph - my guess at doom v1.2 - 1.4beta compatibility here.
* If there are no higher neighbouring sectors, Heretic just returned
* heightlist[0] (local variable), i.e. noise off the stack. 0 is right for
* RETURN01 E1M2, so let's take that. */
return currentheight;
}
///////////////////////////////////////////////////////////////////////
//
// Floor motion linedef handlers
//
///////////////////////////////////////////////////////////////////////
//
// EV_DoFloor()
//
// Handle regular and extended floor types
//
// Passed the line that activated the floor and the type of floor motion
// Returns true if a thinker was created.
//
boolean EV_DoFloor(const line_t __far* line, floor_e floortype)
{
int16_t secnum;
boolean rtn;
sector_t __far* sec;
floormove_t __far* floor;
secnum = -1;
rtn = false;
// move all floors with the same tag as the linedef
while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
{
sec = &_g_sectors[secnum];
// Don't start a second thinker on the same floor
if (sec->floordata != NULL)
continue;
// new floor thinker
rtn = true;
floor = Z_CallocLevSpec(sizeof(*floor));
P_AddThinker (&floor->thinker);
sec->floordata = floor; //jff 2/22/98
floor->thinker.function = T_MoveFloor;
floor->type = floortype;
// setup the thinker according to the linedef type
switch(floortype)
{
case lowerFloor:
floor->direction = -1;
floor->sector = sec;
floor->speed = FLOORSPEED;
floor->floordestheight = P_FindHighestFloorSurrounding(sec);
break;
case lowerFloorToLowest:
floor->direction = -1;
floor->sector = sec;
floor->speed = FLOORSPEED;
floor->floordestheight = P_FindLowestFloorSurrounding(sec);
break;
case turboLower:
floor->direction = -1;
floor->sector = sec;
floor->speed = FLOORSPEED * 4;
floor->floordestheight = P_FindHighestFloorSurrounding(sec);
if (floor->floordestheight != sec->floorheight)
floor->floordestheight += 8*FRACUNIT;
break;
case raiseFloor:
floor->direction = 1;
floor->sector = sec;
floor->speed = FLOORSPEED;
floor->floordestheight = P_FindLowestCeilingSurrounding(sec);
if (floor->floordestheight > sec->ceilingheight)
floor->floordestheight = sec->ceilingheight;
break;
case raiseFloorToNearest:
floor->direction = 1;
floor->sector = sec;
floor->speed = FLOORSPEED;
floor->floordestheight = P_FindNextHighestFloor(sec);
break;
default:
break;
}
}
return rtn;
}