Debian Codegraph @

prboom2/src/p_map.c

raw
1 /* Emacs style mode select -*- C -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
5 * PrBoom: a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2004 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
11 * Copyright 2005, 2006 by
12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 * 02111-1307, USA.
28 *
29 * DESCRIPTION:
30 * Movement, collision handling.
31 * Shooting and aiming.
32 *
33 *-----------------------------------------------------------------------------*/
34
35 #include "doomstat.h"
36 #include "r_main.h"
37 #include "p_mobj.h"
38 #include "p_maputl.h"
39 #include "p_map.h"
40 #include "p_setup.h"
41 #include "p_spec.h"
42 #include "s_sound.h"
43 #include "sounds.h"
44 #include "p_inter.h"
45 #include "m_random.h"
46 #include "m_bbox.h"
47 #include "lprintf.h"
48 #include "g_game.h"
49 #include "p_tick.h"
50 #include "g_overflow.h"
51 #include "am_map.h"
52
53 #include "e6y.h"//e6y
54
55 #include "dsda.h"
56 #include "dsda/destructible.h"
57 #include "dsda/excmd.h"
58 #include "dsda/map_format.h"
59 #include "dsda/mapinfo.h"
60
61 #include "heretic/def.h"
62
63 static mobj_t *tmthing;
64 static mobj_t *tsthing; // hexen
65 static fixed_t tmx;
66 static fixed_t tmy;
67 static int pe_x; // Pain Elemental position for Lost Soul checks // phares
68 static int pe_y; // Pain Elemental position for Lost Soul checks // phares
69 static int ls_x; // Lost Soul position for Lost Soul checks // phares
70 static int ls_y; // Lost Soul position for Lost Soul checks // phares
71
72 //
73 // SECTOR HEIGHT CHANGING
74 // After modifying a sectors floor or ceiling height,
75 // call this routine to adjust the positions
76 // of all things that touch the sector.
77 //
78 // If anything doesn't fit anymore, true will be returned.
79 // If crunch is true, they will take damage
80 // as they are being crushed.
81 // If Crunch is false, you should set the sector height back
82 // the way it was and call P_ChangeSector again
83 // to undo the changes.
84 //
85
86 static int crushchange;
87 static dboolean nofit;
88
89 // If "floatok" true, move would be ok
90 // if within "tmfloorz - tmceilingz".
91
92 dboolean floatok;
93
94 /* killough 11/98: if "felldown" true, object was pushed down ledge */
95 dboolean felldown;
96
97 // The tm* items are used to hold information globally, usually for
98 // line or object intersection checking
99
100 fixed_t tmbbox[4]; // bounding box for line intersection checks
101 fixed_t tmfloorz; // floor you'd hit if free to fall
102 fixed_t tmceilingz; // ceiling of sector you're in
103 fixed_t tmdropoffz; // dropoff on other side of line you're crossing
104
105 // heretic
106 int tmflags;
107
108 // hexen
109 int tmfloorpic;
110 mobj_t *BlockingMobj;
111
112 // keep track of the line that lowers the ceiling,
113 // so missiles don't explode against sky hack walls
114
115 line_t *ceilingline;
116 line_t *blockline; /* killough 8/11/98: blocking linedef */
117 line_t *floorline; /* killough 8/1/98: Highest touched floor */
118 static int tmunstuck; /* killough 8/1/98: whether to allow unsticking */
119
120 // keep track of special lines as they are hit,
121 // but don't process them until the move is proven valid
122
123 // 1/11/98 killough: removed limit on special lines crossed
124 line_t **spechit; // new code -- killough
125 static int spechit_max; // killough
126
127 int numspechit;
128
129 // Temporary holder for thing_sectorlist threads
130 msecnode_t* sector_list = NULL; // phares 3/16/98
131
132 //
133 // TELEPORT MOVE
134 //
135
136 //
137 // PIT_StompThing
138 //
139
140 static dboolean telefrag; /* killough 8/9/98: whether to telefrag at exit */
141
142 dboolean PIT_StompThing (mobj_t* thing)
143 {
144 fixed_t blockdist;
145
146 // phares 9/10/98: moved this self-check to start of routine
147
148 // don't clip against self
149
150 if (thing == tmthing)
151 return true;
152
153 if (!(thing->flags & MF_SHOOTABLE)) // Can't shoot it? Can't stomp it!
154 return true;
155
156 blockdist = thing->radius + tmthing->radius;
157
158 if (D_abs(thing->x - tmx) >= blockdist || D_abs(thing->y - tmy) >= blockdist)
159 return true; // didn't hit it
160
161 // monsters don't stomp things except on boss level
162 // killough 8/9/98: make consistent across all levels
163 if (!telefrag &&
164 !(map_info.flags & MI_ALLOW_MONSTER_TELEFRAGS) &&
165 !(tmthing->flags2 & MF2_TELESTOMP))
166 return false;
167
168 P_DamageMobj (thing, tmthing, tmthing, 10000); // Stomp!
169
170 return true;
171 }
172
173
174 /*
175 * killough 8/28/98:
176 *
177 * P_GetFriction()
178 *
179 * Returns the friction associated with a particular mobj.
180 */
181
182 int P_GetFriction(const mobj_t *mo, int *frictionfactor)
183 {
184 int friction = ORIG_FRICTION;
185 int movefactor = ORIG_FRICTION_FACTOR;
186 const msecnode_t *m;
187 const sector_t *sec;
188
189 /* Assign the friction value to objects on the floor, non-floating,
190 * and clipped. Normally the object's friction value is kept at
191 * ORIG_FRICTION and this thinker changes it for icy or muddy floors.
192 *
193 * When the object is straddling sectors with the same
194 * floorheight that have different frictions, use the lowest
195 * friction value (muddy has precedence over icy).
196 */
197
198 if (mo->flags & MF_FLY)
199 {
200 friction = FRICTION_FLY;
201 }
202 else
203 {
204 if (
205 !(mo->flags & (MF_NOCLIP | MF_NOGRAVITY)) &&
206 (mbf_features || (mo->player && !compatibility)) &&
207 variable_friction
208 )
209 for (m = mo->touching_sectorlist; m; m = m->m_tnext)
210 if (
211 (sec = m->m_sector)->flags & SECF_FRICTION &&
212 (sec->friction < friction || friction == ORIG_FRICTION) &&
213 (
214 mo->z <= sec->floorheight ||
215 (
216 sec->heightsec != -1 &&
217 mo->z <= sectors[sec->heightsec].floorheight &&
218 mbf_features
219 )
220 )
221 )
222 {
223 friction = sec->friction;
224 movefactor = sec->movefactor;
225 }
226 }
227
228 if (frictionfactor)
229 *frictionfactor = movefactor;
230
231 return friction;
232 }
233
234 /* phares 3/19/98
235 * P_GetMoveFactor() returns the value by which the x,y
236 * movements are multiplied to add to player movement.
237 *
238 * killough 8/28/98: rewritten
239 */
240
241 int P_GetMoveFactor(mobj_t *mo, int *frictionp)
242 {
243 int movefactor, friction;
244
245 //e6y
246 if (!mbf_features && !prboom_comp[PC_PRBOOM_FRICTION].state)
247 {
248 int momentum;
249
250 movefactor = ORIG_FRICTION_FACTOR;
251
252 if (!compatibility && variable_friction &&
253 !(mo->flags & (MF_NOGRAVITY | MF_NOCLIP)))
254 {
255 friction = mo->friction;
256 if (friction == ORIG_FRICTION) // normal floor
257 ;
258 else if (friction > ORIG_FRICTION) // ice
259 {
260 movefactor = mo->movefactor;
261 ((mobj_t*)mo)->movefactor = ORIG_FRICTION_FACTOR; // reset
262 }
263 else // sludge
264 {
265
266 // phares 3/11/98: you start off slowly, then increase as
267 // you get better footing
268
269 momentum = (P_AproxDistance(mo->momx,mo->momy));
270 movefactor = mo->movefactor;
271 if (momentum > MORE_FRICTION_MOMENTUM<<2)
272 movefactor <<= 3;
273
274 else if (momentum > MORE_FRICTION_MOMENTUM<<1)
275 movefactor <<= 2;
276
277 else if (momentum > MORE_FRICTION_MOMENTUM)
278 movefactor <<= 1;
279
280 ((mobj_t*)mo)->movefactor = ORIG_FRICTION_FACTOR; // reset
281 }
282 } // ^
283
284 return(movefactor); // |
285 }
286
287 // If the floor is icy or muddy, it's harder to get moving. This is where
288 // the different friction factors are applied to 'trying to move'. In
289 // p_mobj.c, the friction factors are applied as you coast and slow down.
290
291 if ((friction = P_GetFriction(mo, &movefactor)) < ORIG_FRICTION)
292 {
293 // phares 3/11/98: you start off slowly, then increase as
294 // you get better footing
295
296 int momentum = P_AproxDistance(mo->momx,mo->momy);
297
298 if (momentum > MORE_FRICTION_MOMENTUM<<2)
299 movefactor <<= 3;
300 else if (momentum > MORE_FRICTION_MOMENTUM<<1)
301 movefactor <<= 2;
302 else if (momentum > MORE_FRICTION_MOMENTUM)
303 movefactor <<= 1;
304 }
305
306 if (frictionp)
307 *frictionp = friction;
308
309 return movefactor;
310 }
311
312 dboolean P_MoveThing(mobj_t *thing, fixed_t x, fixed_t y, fixed_t z, dboolean fog)
313 {
314 sector_t *newsec;
315 fixed_t oldx, oldy, oldz;
316 fixed_t oldfloorz, oldceilingz, olddropoffz;
317
318 oldx = thing->x;
319 oldy = thing->y;
320 oldz = thing->z;
321 oldfloorz = thing->floorz;
322 oldceilingz = thing->ceilingz;
323 olddropoffz = thing->dropoffz;
324
325 newsec = R_PointInSector(x, y);
326
327 thing->x = x;
328 thing->y = y;
329 thing->z = z;
330 thing->floorz = newsec->floorheight;
331 thing->ceilingz = newsec->ceilingheight;
332 thing->dropoffz = thing->floorz;
333
334 if (P_TestMobjLocation(thing))
335 {
336 P_UnsetThingPosition(thing);
337 P_SetThingPosition(thing);
338
339 if (fog)
340 {
341 mobj_t *telefog;
342
343 telefog = P_SpawnMobj(oldx,
344 oldy,
345 oldfloorz + g_telefog_height,
346 g_mt_tfog);
347 S_StartMobjSound(telefog, g_sfx_telept);
348 telefog = P_SpawnMobj(thing->x,
349 thing->y,
350 thing->floorz + g_telefog_height,
351 g_mt_tfog);
352 S_StartMobjSound(telefog, g_sfx_telept);
353 }
354
355 thing->PrevX = x;
356 thing->PrevY = y;
357 thing->PrevZ = z;
358
359 return true;
360 }
361 else
362 {
363 thing->x = oldx;
364 thing->y = oldy;
365 thing->z = oldz;
366 thing->floorz = oldfloorz;
367 thing->ceilingz = oldceilingz;
368 thing->dropoffz = olddropoffz;
369
370 return false;
371 }
372 }
373
374 void P_UnqualifiedMove(mobj_t *thing, fixed_t x, fixed_t y)
375 {
376 sector_t *sector;
377
378 P_UnsetThingPosition(thing);
379 thing->x = x;
380 thing->y = y;
381 sector = R_PointInSector(thing->x, thing->y);
382 thing->z = thing->floorz = sector->floorheight;
383 thing->ceilingz = sector->ceilingheight;
384 P_SetThingPosition(thing);
385 }
386
387 //
388 // P_TeleportMove
389 //
390
391 dboolean P_TeleportMove (mobj_t* thing,fixed_t x,fixed_t y, dboolean boss)
392 {
393 int xl;
394 int xh;
395 int yl;
396 int yh;
397 int bx;
398 int by;
399
400 sector_t* newsec;
401
402 /* killough 8/9/98: make telefragging more consistent, preserve compatibility */
403 telefrag = !raven &&
404 (thing->player || (!comp[comp_telefrag] ? boss : (gamemap==30)));
405
406 // kill anything occupying the position
407
408 tmthing = thing;
409 tmflags = thing->flags;
410
411 tmx = x;
412 tmy = y;
413
414 tmbbox[BOXTOP] = y + tmthing->radius;
415 tmbbox[BOXBOTTOM] = y - tmthing->radius;
416 tmbbox[BOXRIGHT] = x + tmthing->radius;
417 tmbbox[BOXLEFT] = x - tmthing->radius;
418
419 newsec = R_PointInSector (x,y);
420 ceilingline = NULL;
421
422 // The base floor/ceiling is from the sector
423 // that contains the point.
424 // Any contacted lines the step closer together
425 // will adjust them.
426
427 tmfloorz = tmdropoffz = newsec->floorheight;
428 tmceilingz = newsec->ceilingheight;
429 tmfloorpic = newsec->floorpic;
430
431 validcount++;
432 numspechit = 0;
433
434 // stomp on any things contacted
435
436 xl = P_GetSafeBlockX(tmbbox[BOXLEFT] - bmaporgx - MAXRADIUS);
437 xh = P_GetSafeBlockX(tmbbox[BOXRIGHT] - bmaporgx + MAXRADIUS);
438 yl = P_GetSafeBlockY(tmbbox[BOXBOTTOM] - bmaporgy - MAXRADIUS);
439 yh = P_GetSafeBlockY(tmbbox[BOXTOP] - bmaporgy + MAXRADIUS);
440
441 for (bx=xl ; bx<=xh ; bx++)
442 for (by=yl ; by<=yh ; by++)
443 if (!P_BlockThingsIterator(bx,by,PIT_StompThing))
444 return false;
445
446 // the move is ok,
447 // so unlink from the old position & link into the new position
448
449 P_UnsetThingPosition (thing);
450
451 thing->floorz = tmfloorz;
452 thing->ceilingz = tmceilingz;
453 thing->dropoffz = tmdropoffz; // killough 11/98
454
455 thing->x = x;
456 thing->y = y;
457
458 P_SetThingPosition (thing);
459
460 thing->PrevX = x;
461 thing->PrevY = y;
462 thing->PrevZ = thing->floorz;
463
464 return true;
465 }
466
467
468 //
469 // MOVEMENT ITERATOR FUNCTIONS
470 //
471
472 // // phares
473 // PIT_CrossLine // |
474 // Checks to see if a PE->LS trajectory line crosses a blocking // V
475 // line. Returns false if it does.
476 //
477 // tmbbox holds the bounding box of the trajectory. If that box
478 // does not touch the bounding box of the line in question,
479 // then the trajectory is not blocked. If the PE is on one side
480 // of the line and the LS is on the other side, then the
481 // trajectory is blocked.
482 //
483 // Currently this assumes an infinite line, which is not quite
484 // correct. A more correct solution would be to check for an
485 // intersection of the trajectory and the line, but that takes
486 // longer and probably really isn't worth the effort.
487 //
488
489 static // killough 3/26/98: make static
490 dboolean PIT_CrossLine (line_t* ld)
491 {
492 if (!(ld->flags & ML_TWOSIDED) ||
493 (ld->flags & (ML_BLOCKING|ML_BLOCKMONSTERS)))
494 if (!(tmbbox[BOXLEFT] > ld->bbox[BOXRIGHT] ||
495 tmbbox[BOXRIGHT] < ld->bbox[BOXLEFT] ||
496 tmbbox[BOXTOP] < ld->bbox[BOXBOTTOM] ||
497 tmbbox[BOXBOTTOM] > ld->bbox[BOXTOP]))
498 if (P_PointOnLineSide(pe_x,pe_y,ld) != P_PointOnLineSide(ls_x,ls_y,ld))
499 return(false); // line blocks trajectory // ^
500 return(true); // line doesn't block trajectory // |
501 } // phares
502
503
504 /* killough 8/1/98: used to test intersection between thing and line
505 * assuming NO movement occurs -- used to avoid sticky situations.
506 */
507
508 static int untouched(line_t *ld)
509 {
510 fixed_t x, y, tmbbox[4];
511 return
512 (tmbbox[BOXRIGHT] = (x=tmthing->x)+tmthing->radius) <= ld->bbox[BOXLEFT] ||
513 (tmbbox[BOXLEFT] = x-tmthing->radius) >= ld->bbox[BOXRIGHT] ||
514 (tmbbox[BOXTOP] = (y=tmthing->y)+tmthing->radius) <= ld->bbox[BOXBOTTOM] ||
515 (tmbbox[BOXBOTTOM] = y-tmthing->radius) >= ld->bbox[BOXTOP] ||
516 P_BoxOnLineSide(tmbbox, ld) != -1;
517 }
518
519 //
520 // PIT_CheckLine
521 // Adjusts tmfloorz and tmceilingz as lines are contacted
522 //
523
524 static void CheckForDamageSpecial(line_t *line, mobj_t *mo)
525 {
526 int damage;
527
528 // TODO: bouncing against a damage line
529 // TODO: lost souls don't damage walls in gzdoom
530 if (
531 !line->health ||
532 !(mo->flags & (/* MF_SKULLFLY |*/ MF_MISSILE /*| MF_BOUNCES */)) ||
533 !mo->info->damage
534 )
535 {
536 return;
537 }
538
539 damage = ((P_Random(pr_damage) % 8) + 1) * mo->info->damage;
540 dsda_DamageLinedef(line, mo->target, damage);
541 }
542
543 static void CheckForPushSpecial(line_t * line, int side, mobj_t * mobj);
544
545 static // killough 3/26/98: make static
546 dboolean PIT_CheckLine (line_t* ld)
547 {
548 dboolean rail = false;
549
550 if (tmbbox[BOXRIGHT] <= ld->bbox[BOXLEFT]
551 || tmbbox[BOXLEFT] >= ld->bbox[BOXRIGHT]
552 || tmbbox[BOXTOP] <= ld->bbox[BOXBOTTOM]
553 || tmbbox[BOXBOTTOM] >= ld->bbox[BOXTOP] )
554 return true; // didn't hit it
555
556 if (P_BoxOnLineSide(tmbbox, ld) != -1)
557 return true; // didn't hit it
558
559 // A line has been hit
560
561 // The moving thing's destination position will cross the given line.
562 // If this should not be allowed, return false.
563 // If the line is special, keep track of it
564 // to process later if the move is proven ok.
565 // NOTE: specials are NOT sorted by order,
566 // so two special lines that are only 8 pixels apart
567 // could be crossed in either order.
568
569 // killough 7/24/98: allow player to move out of 1s wall, to prevent sticking
570 if (!ld->backsector) // one sided line
571 {
572 if (heretic)
573 {
574 if (tmthing->flags & MF_MISSILE)
575 { // Missiles can trigger impact specials
576 if (ld->special)
577 {
578 P_AppendSpecHit(ld);
579 }
580 }
581 }
582 else if (map_format.hexen)
583 {
584 if (tmthing->flags2 & MF2_BLASTED)
585 {
586 P_DamageMobj(tmthing, NULL, NULL, tmthing->info->mass >> 5);
587 }
588 CheckForPushSpecial(ld, 0, tmthing);
589 CheckForDamageSpecial(ld, tmthing);
590 }
591 blockline = ld;
592 return tmunstuck && !untouched(ld) &&
593 FixedMul(tmx-tmthing->x,ld->dy) > FixedMul(tmy-tmthing->y,ld->dx);
594 }
595
596 // killough 8/10/98: allow bouncing objects to pass through as missiles
597 if (!(tmthing->flags & (MF_MISSILE | MF_BOUNCES)) ||
598 ld->flags & (ML_BLOCKPROJECTILES | ML_BLOCKEVERYTHING))
599 {
600 if (ld->flags & ML_JUMPOVER)
601 {
602 rail = true;
603 }
604 else
605 {
606 // explicitly blocking everything
607 // or blocking player
608 // or blocking projectile
609 if (
610 ld->flags & ML_BLOCKING ||
611 (mbf21 && tmthing->player && ld->flags & ML_BLOCKPLAYERS) ||
612 tmthing->flags & (MF_MISSILE | MF_BOUNCES)
613 )
614 {
615 if (map_format.hexen)
616 {
617 if (tmthing->flags2 & MF2_BLASTED)
618 {
619 P_DamageMobj(tmthing, NULL, NULL, tmthing->info->mass >> 5);
620 }
621 CheckForPushSpecial(ld, 0, tmthing);
622 CheckForDamageSpecial(ld, tmthing);
623 }
624 return tmunstuck && !untouched(ld); // killough 8/1/98: allow escape
625 }
626
627 // killough 8/9/98: monster-blockers don't affect friends
628 if (
629 !(tmthing->flags & MF_FRIEND || tmthing->player) &&
630 (
631 ld->flags & ML_BLOCKMONSTERS ||
632 (mbf21 && ld->flags & ML_BLOCKLANDMONSTERS && !(tmthing->flags & MF_FLOAT)) ||
633 (ld->flags & ML_BLOCKFLOATERS && tmthing->flags & MF_FLOAT)
634 ) &&
635 (!heretic || tmthing->type != HERETIC_MT_POD)
636 )
637 {
638 if (tmthing->flags2 & MF2_BLASTED)
639 {
640 P_DamageMobj(tmthing, NULL, NULL, tmthing->info->mass >> 5);
641 }
642 return false; // block monsters only
643 }
644 }
645 }
646
647 // defines a 'window' from one sector to another across this line
648
649 P_LineOpening (ld, tmthing);
650
651 if (rail && line_opening.bottom == tmfloorz)
652 {
653 line_opening.bottom += (32 << FRACBITS);
654 }
655
656 // adjust floor & ceiling heights
657
658 if (line_opening.top < tmceilingz)
659 {
660 tmceilingz = line_opening.top;
661 ceilingline = ld;
662 blockline = ld;
663 }
664
665 if (line_opening.bottom > tmfloorz)
666 {
667 tmfloorz = line_opening.bottom;
668 floorline = ld; // killough 8/1/98: remember floor linedef
669 blockline = ld;
670 }
671
672 if (line_opening.lowfloor < tmdropoffz)
673 tmdropoffz = line_opening.lowfloor;
674
675 // if contacted a special line, add it to the list
676 if (ld->special)
677 P_AppendSpecHit(ld);
678
679 return true;
680 }
681
682 //
683 // PIT_CheckThing
684 //
685
686 static dboolean P_ProjectileImmune(mobj_t *target, mobj_t *source)
687 {
688 return
689 ( // PG_GROUPLESS means no immunity, even to own species
690 mobjinfo[target->type].projectile_group != PG_GROUPLESS ||
691 target == source
692 ) &&
693 (
694 ( // target type has default behaviour, and things are the same type
695 mobjinfo[target->type].projectile_group == PG_DEFAULT &&
696 source->type == target->type
697 ) ||
698 ( // target type has special behaviour, and things have the same group
699 mobjinfo[target->type].projectile_group != PG_DEFAULT &&
700 mobjinfo[target->type].projectile_group == mobjinfo[source->type].projectile_group
701 )
702 );
703 }
704
705 static dboolean PIT_CheckThing(mobj_t *thing) // killough 3/26/98: make static
706 {
707 fixed_t blockdist;
708 int damage;
709
710 // killough 11/98: add touchy things
711 if (!(thing->flags & (MF_SOLID|MF_SPECIAL|MF_SHOOTABLE|MF_TOUCHY)))
712 return true;
713
714 blockdist = thing->radius + tmthing->radius;
715
716 if (D_abs(thing->x - tmx) >= blockdist || D_abs(thing->y - tmy) >= blockdist)
717 return true; // didn't hit it
718
719 // killough 11/98:
720 //
721 // This test has less information content (it's almost always false), so it
722 // should not be moved up to first, as it adds more overhead than it removes.
723
724 // don't clip against self
725
726 if (thing == tmthing)
727 return true;
728
729 if (map_format.hexen)
730 BlockingMobj = thing;
731
732 /* killough 11/98:
733 *
734 * TOUCHY flag, for mines or other objects which die on contact with solids.
735 * If a solid object of a different type comes in contact with a touchy
736 * thing, and the touchy thing is not the sole one moving relative to fixed
737 * surroundings such as walls, then the touchy thing dies immediately.
738 */
739
740 if (thing->flags & MF_TOUCHY && // touchy object
741 tmthing->flags & MF_SOLID && // solid object touches it
742 thing->health > 0 && // touchy object is alive
743 (thing->intflags & MIF_ARMED || // Thing is an armed mine
744 sentient(thing)) && // ... or a sentient thing
745 (thing->type != tmthing->type || // only different species
746 thing->type == g_mt_player) && // ... or different players
747 thing->z + thing->height >= tmthing->z && // touches vertically
748 tmthing->z + tmthing->height >= thing->z &&
749 (thing->type ^ MT_PAIN) | // PEs and lost souls
750 (tmthing->type ^ MT_SKULL) && // are considered same
751 (thing->type ^ MT_SKULL) | // (but Barons & Knights
752 (tmthing->type ^ MT_PAIN)) // are intentionally not)
753 {
754 P_DamageMobj(thing, NULL, NULL, thing->health); // kill object
755 return true;
756 }
757
758 if (tmthing->flags2 & MF2_PASSMOBJ)
759 { // check if a mobj passed over/under another object
760 if (raven)
761 {
762 if ((tmthing->type == HERETIC_MT_IMP || tmthing->type == HERETIC_MT_WIZARD)
763 && (thing->type == HERETIC_MT_IMP || thing->type == HERETIC_MT_WIZARD))
764 { // don't let imps/wizards fly over other imps/wizards
765 return false;
766 }
767
768 if (tmthing->type == HEXEN_MT_BISHOP && thing->type == HEXEN_MT_BISHOP)
769 { // don't let bishops fly over other bishops
770 return false;
771 }
772 }
773
774 if (
775 (map_format.hexen ? tmthing->z >= thing->z + thing->height
776 : tmthing->z > thing->z + thing->height)
777 && !(thing->flags & MF_SPECIAL)
778 )
779 {
780 return (true);
781 }
782 else if (
783 (map_format.zdoom ? tmthing->z + tmthing->height <= thing->z
784 : tmthing->z + tmthing->height < thing->z)
785 && !(thing->flags & MF_SPECIAL))
786 { // under thing
787 return (true);
788 }
789 }
790
791 // check for skulls slamming into things
792
793 if (tmthing->flags & MF_SKULLFLY)
794 {
795 // A flying skull is smacking something.
796 // Determine damage amount, and the skull comes to a dead stop.
797
798 int new_state;
799 int damage;
800
801 if (hexen)
802 {
803 if (tmthing->type == HEXEN_MT_MINOTAUR)
804 {
805 // Slamming minotaurs shouldn't move non-creatures
806 if (!(thing->flags & MF_COUNTKILL))
807 {
808 return (false);
809 }
810 }
811 else if (tmthing->type == HEXEN_MT_HOLY_FX)
812 {
813 if (thing->flags & MF_SHOOTABLE && thing != tmthing->target)
814 {
815 if (netgame && !deathmatch && thing->player)
816 { // don't attack other co-op players
817 return true;
818 }
819 if (thing->flags2 & MF2_REFLECTIVE
820 && (thing->player || thing->flags2 & MF2_BOSS))
821 {
822 P_SetTarget(&tmthing->special1.m, tmthing->target);
823 P_SetTarget(&tmthing->target, thing);
824 return true;
825 }
826 if (thing->flags & MF_COUNTKILL || thing->player)
827 {
828 P_SetTarget(&tmthing->special1.m, thing);
829 }
830 if (P_Random(pr_hexen) < 96)
831 {
832 damage = 12;
833 if (thing->player || thing->flags2 & MF2_BOSS)
834 {
835 damage = 3;
836 // ghost burns out faster when attacking players/bosses
837 tmthing->health -= 6;
838 }
839 P_DamageMobj(thing, tmthing, tmthing->target, damage);
840 if (P_Random(pr_hexen) < 128)
841 {
842 P_SpawnMobj(tmthing->x, tmthing->y, tmthing->z,
843 HEXEN_MT_HOLY_PUFF);
844 S_StartMobjSound(tmthing, hexen_sfx_spirit_attack);
845 if (thing->flags & MF_COUNTKILL && P_Random(pr_hexen) < 128
846 && !S_GetSoundPlayingInfo(thing, hexen_sfx_puppybeat))
847 {
848 if ((thing->type == HEXEN_MT_CENTAUR) ||
849 (thing->type == HEXEN_MT_CENTAURLEADER) ||
850 (thing->type == HEXEN_MT_ETTIN))
851 {
852 S_StartMobjSound(thing, hexen_sfx_puppybeat);
853 }
854 }
855 }
856 }
857 if (thing->health <= 0)
858 {
859 tmthing->special1.i = 0;
860 P_SetTarget(&tmthing->special1.m, NULL);
861 }
862 }
863 return true;
864 }
865 }
866
867 damage = ((P_Random(pr_skullfly) % 8) + 1) * tmthing->info->damage;
868
869 P_DamageMobj (thing, tmthing, tmthing, damage);
870
871 tmthing->flags &= ~MF_SKULLFLY;
872 tmthing->momx = tmthing->momy = tmthing->momz = 0;
873
874 if (raven)
875 new_state = tmthing->info->seestate;
876 else
877 new_state = tmthing->info->spawnstate;
878
879 P_SetMobjState (tmthing, new_state);
880
881 return false; // stop moving
882 }
883
884 // Check for blasted thing running into another
885 if (tmthing->flags2 & MF2_BLASTED && thing->flags & MF_SHOOTABLE)
886 {
887 if (!(thing->flags2 & MF2_BOSS) && (thing->flags & MF_COUNTKILL))
888 {
889 thing->momx += tmthing->momx;
890 thing->momy += tmthing->momy;
891 if ((thing->momx + thing->momy) > 3 * FRACUNIT)
892 {
893 damage = (tmthing->info->mass / 100) + 1;
894 P_DamageMobj(thing, tmthing, tmthing, damage);
895 damage = (thing->info->mass / 100) + 1;
896 P_DamageMobj(tmthing, thing, thing, damage >> 2);
897 }
898 return (false);
899 }
900 }
901
902 // missiles can hit other things
903 // killough 8/10/98: bouncing non-solid things can hit other things too
904
905 if (tmthing->flags & MF_MISSILE ||
906 (tmthing->flags & MF_BOUNCES && !(tmthing->flags & MF_SOLID)))
907 {
908 // Check for a non-shootable mobj
909 if (thing->flags2 & MF2_NONSHOOTABLE)
910 {
911 return true;
912 }
913
914 // Check for passing through a ghost
915 if ((thing->flags & MF_SHADOW) && (tmthing->flags2 & MF2_THRUGHOST))
916 {
917 return (true);
918 }
919
920 // see if it went over / under
921
922 if (tmthing->z > thing->z + thing->height)
923 return true; // overhead
924
925 if (tmthing->z + tmthing->height < thing->z)
926 return true; // underneath
927
928 if (hexen)
929 {
930 if (tmthing->flags2 & MF2_FLOORBOUNCE)
931 {
932 if (tmthing->target == thing || !(thing->flags & MF_SOLID))
933 {
934 return true;
935 }
936 else
937 {
938 return false;
939 }
940 }
941
942 if (tmthing->type == HEXEN_MT_LIGHTNING_FLOOR
943 || tmthing->type == HEXEN_MT_LIGHTNING_CEILING)
944 {
945 if (thing->flags & MF_SHOOTABLE && thing != tmthing->target)
946 {
947 if (thing->info->mass != INT_MAX)
948 {
949 thing->momx += tmthing->momx >> 4;
950 thing->momy += tmthing->momy >> 4;
951 }
952 if ((!thing->player && !(thing->flags2 & MF2_BOSS))
953 || !(leveltime & 1))
954 {
955 if (thing->type == HEXEN_MT_CENTAUR
956 || thing->type == HEXEN_MT_CENTAURLEADER)
957 { // Lightning does more damage to centaurs
958 P_DamageMobj(thing, tmthing, tmthing->target, 9);
959 }
960 else
961 {
962 P_DamageMobj(thing, tmthing, tmthing->target, 3);
963 }
964 if (!(S_GetSoundPlayingInfo(tmthing,
965 hexen_sfx_mage_lightning_zap)))
966 {
967 S_StartMobjSound(tmthing, hexen_sfx_mage_lightning_zap);
968 }
969 if (thing->flags & MF_COUNTKILL && P_Random(pr_hexen) < 64
970 && !S_GetSoundPlayingInfo(thing, hexen_sfx_puppybeat))
971 {
972 if ((thing->type == HEXEN_MT_CENTAUR) ||
973 (thing->type == HEXEN_MT_CENTAURLEADER) ||
974 (thing->type == HEXEN_MT_ETTIN))
975 {
976 S_StartMobjSound(thing, hexen_sfx_puppybeat);
977 }
978 }
979 }
980 tmthing->health--;
981 if (tmthing->health <= 0 || thing->health <= 0)
982 {
983 return false;
984 }
985 if (tmthing->type == HEXEN_MT_LIGHTNING_FLOOR)
986 {
987 if (tmthing->special2.m
988 && !tmthing->special2.m->special1.m)
989 {
990 P_SetTarget(&tmthing->special2.m->special1.m, thing);
991 }
992 }
993 else if (!tmthing->special1.m)
994 {
995 P_SetTarget(&tmthing->special1.m, thing);
996 }
997 }
998 return true; // lightning zaps through all sprites
999 }
1000 else if (tmthing->type == HEXEN_MT_LIGHTNING_ZAP)
1001 {
1002 mobj_t *lmo;
1003
1004 if (thing->flags & MF_SHOOTABLE && thing != tmthing->target)
1005 {
1006 lmo = tmthing->special2.m;
1007 if (lmo)
1008 {
1009 if (lmo->type == HEXEN_MT_LIGHTNING_FLOOR)
1010 {
1011 if (lmo->special2.m
1012 && !lmo->special2.m->special1.m)
1013 {
1014 P_SetTarget(&lmo->special2.m->special1.m, thing);
1015 }
1016 }
1017 else if (!lmo->special1.m)
1018 {
1019 P_SetTarget(&lmo->special1.m, thing);
1020 }
1021 if (!(leveltime & 3))
1022 {
1023 lmo->health--;
1024 }
1025 }
1026 }
1027 }
1028 else if (tmthing->type == HEXEN_MT_MSTAFF_FX2 && thing != tmthing->target)
1029 {
1030 if (!thing->player && !(thing->flags2 & MF2_BOSS))
1031 {
1032 switch (thing->type)
1033 {
1034 case HEXEN_MT_FIGHTER_BOSS: // these not flagged boss
1035 case HEXEN_MT_CLERIC_BOSS: // so they can be blasted
1036 case HEXEN_MT_MAGE_BOSS:
1037 break;
1038 default:
1039 P_DamageMobj(thing, tmthing, tmthing->target, 10);
1040 return true;
1041 break;
1042 }
1043 }
1044 }
1045 }
1046
1047 if (tmthing->target && P_ProjectileImmune(thing, tmthing->target))
1048 {
1049 if (thing == tmthing->target)
1050 return true; // Don't hit self.
1051 else
1052 // e6y: Dehacked support - monsters infight
1053 if (thing->type != g_mt_player && !monsters_infight) // Explode, but do no damage.
1054 return false; // Let players missile other players.
1055 }
1056
1057 // killough 8/10/98: if moving thing is not a missile, no damage
1058 // is inflicted, and momentum is reduced if object hit is solid.
1059
1060 if (!(tmthing->flags & MF_MISSILE)) {
1061 if (!(thing->flags & MF_SOLID))
1062 {
1063 return true;
1064 }
1065 else
1066 {
1067 tmthing->momx = -tmthing->momx;
1068 tmthing->momy = -tmthing->momy;
1069 if (!(tmthing->flags & MF_NOGRAVITY))
1070 {
1071 tmthing->momx >>= 2;
1072 tmthing->momy >>= 2;
1073 }
1074 return false;
1075 }
1076 }
1077
1078 if (!(thing->flags & MF_SHOOTABLE))
1079 return !(thing->flags & MF_SOLID); // didn't do any damage
1080
1081 if (tmthing->flags2 & MF2_RIP)
1082 {
1083 if (raven)
1084 {
1085 if (!(thing->flags & MF_NOBLOOD) &&
1086 !(thing->flags2 & MF2_REFLECTIVE) &&
1087 !(thing->flags2 & MF2_INVULNERABLE))
1088 { // Ok to spawn some blood
1089 P_RipperBlood(tmthing, thing);
1090 }
1091 if (heretic) S_StartMobjSound(tmthing, heretic_sfx_ripslop);
1092 damage = ((P_Random(pr_heretic) & 3) + 2) * tmthing->damage;
1093 }
1094 else
1095 {
1096 damage = ((P_Random(pr_mbf21) & 3) + 2) * tmthing->info->damage;
1097 if (!(thing->flags & MF_NOBLOOD))
1098 P_SpawnBlood(tmthing->x, tmthing->y, tmthing->z, damage, thing);
1099 if (tmthing->info->ripsound)
1100 S_StartMobjSound(tmthing, tmthing->info->ripsound);
1101 }
1102
1103 P_DamageMobj(thing, tmthing, tmthing->target, damage);
1104 if (thing->flags2 & MF2_PUSHABLE && !(tmthing->flags2 & MF2_CANNOTPUSH))
1105 { // Push thing
1106 thing->momx += tmthing->momx >> 2;
1107 thing->momy += tmthing->momy >> 2;
1108 }
1109 numspechit = 0;
1110 return (true);
1111 }
1112
1113 // damage / explode
1114
1115 damage = raven ? tmthing->damage : tmthing->info->damage;
1116 damage = ((P_Random(pr_damage) % 8) + 1) * damage;
1117 if (
1118 raven &&
1119 damage &&
1120 !(thing->flags & MF_NOBLOOD) &&
1121 !(thing->flags2 & MF2_REFLECTIVE) &&
1122 !(thing->flags2 & MF2_INVULNERABLE) &&
1123 !(tmthing->type == HEXEN_MT_TELOTHER_FX1) &&
1124 !(tmthing->type == HEXEN_MT_TELOTHER_FX2) &&
1125 !(tmthing->type == HEXEN_MT_TELOTHER_FX3) &&
1126 !(tmthing->type == HEXEN_MT_TELOTHER_FX4) &&
1127 !(tmthing->type == HEXEN_MT_TELOTHER_FX5) &&
1128 P_Random(pr_heretic) < 192
1129 )
1130 {
1131 P_BloodSplatter(tmthing->x, tmthing->y, tmthing->z, thing);
1132 }
1133 if (!raven || damage)
1134 P_DamageMobj(thing, tmthing, tmthing->target, damage);
1135
1136 // don't traverse any more
1137 return false;
1138 }
1139
1140 if (thing->flags2 & MF2_PUSHABLE && !(tmthing->flags2 & MF2_CANNOTPUSH))
1141 { // Push thing
1142 thing->momx += tmthing->momx >> 2;
1143 thing->momy += tmthing->momy >> 2;
1144 }
1145
1146 // check for special pickup
1147
1148 if (thing->flags & MF_SPECIAL)
1149 {
1150 uint64_t solid = thing->flags & MF_SOLID;
1151 if (tmthing->flags & MF_PICKUP) // hexen_note: can probably use tmflags here?
1152 P_TouchSpecialThing(thing, tmthing); // can remove thing
1153 return !solid;
1154 }
1155
1156 // RjY
1157 // comperr_hangsolid, an attempt to handle blocking hanging bodies
1158 // A solid hanging body will allow sufficiently small things underneath it.
1159 if (comperr(comperr_hangsolid) &&
1160 !((~thing->flags) & (MF_SOLID | MF_SPAWNCEILING)) // solid and hanging
1161 // invert everything, then both bits should be clear
1162 && tmthing->z + tmthing->height <= thing->z) // head height <= base
1163 // top of thing trying to move under the body <= bottom of body
1164 {
1165 tmceilingz = thing->z; // pretend ceiling height is at body's base
1166 return true;
1167 }
1168
1169 // killough 3/16/98: Allow non-solid moving objects to move through solid
1170 // ones, by allowing the moving thing (tmthing) to move if it's non-solid,
1171 // despite another solid thing being in the way.
1172 // killough 4/11/98: Treat no-clipping things as not blocking
1173 // ...but not in demo_compatibility mode
1174
1175 // e6y
1176 // Correction of wrong return value with demo_compatibility.
1177 // There is no more synch on http://www.doomworld.com/sda/dwdemo/w303-115.zip
1178 // (with correction in setMobjInfoValue)
1179 if (demo_compatibility && !prboom_comp[PC_TREAT_NO_CLIPPING_THINGS_AS_NOT_BLOCKING].state)
1180 return !(thing->flags & MF_SOLID);
1181 else
1182 return !((thing->flags & MF_SOLID && !(thing->flags & MF_NOCLIP))
1183 && (tmthing->flags & MF_SOLID || demo_compatibility));
1184
1185 // return !(thing->flags & MF_SOLID); // old code -- killough
1186 }
1187
1188 // This routine checks for Lost Souls trying to be spawned // phares
1189 // across 1-sided lines, impassible lines, or "monsters can't // |
1190 // cross" lines. Draw an imaginary line between the PE // V
1191 // and the new Lost Soul spawn spot. If that line crosses
1192 // a 'blocking' line, then disallow the spawn. Only search
1193 // lines in the blocks of the blockmap where the bounding box
1194 // of the trajectory line resides. Then check bounding box
1195 // of the trajectory vs. the bounding box of each blocking
1196 // line to see if the trajectory and the blocking line cross.
1197 // Then check the PE and LS to see if they're on different
1198 // sides of the blocking line. If so, return true, otherwise
1199 // false.
1200
1201 dboolean Check_Sides(mobj_t* actor, int x, int y)
1202 {
1203 int bx,by,xl,xh,yl,yh;
1204
1205 pe_x = actor->x;
1206 pe_y = actor->y;
1207 ls_x = x;
1208 ls_y = y;
1209
1210 // Here is the bounding box of the trajectory
1211
1212 tmbbox[BOXLEFT] = pe_x < x ? pe_x : x;
1213 tmbbox[BOXRIGHT] = pe_x > x ? pe_x : x;
1214 tmbbox[BOXTOP] = pe_y > y ? pe_y : y;
1215 tmbbox[BOXBOTTOM] = pe_y < y ? pe_y : y;
1216
1217 // Determine which blocks to look in for blocking lines
1218
1219 xl = P_GetSafeBlockX(tmbbox[BOXLEFT] - bmaporgx);
1220 xh = P_GetSafeBlockX(tmbbox[BOXRIGHT] - bmaporgx);
1221 yl = P_GetSafeBlockY(tmbbox[BOXBOTTOM] - bmaporgy);
1222 yh = P_GetSafeBlockY(tmbbox[BOXTOP] - bmaporgy);
1223
1224 // xl->xh, yl->yh determine the mapblock set to search
1225
1226 validcount++; // prevents checking same line twice
1227 for (bx = xl ; bx <= xh ; bx++)
1228 for (by = yl ; by <= yh ; by++)
1229 if (!P_BlockLinesIterator(bx,by,PIT_CrossLine))
1230 return true; // ^
1231 return(false); // |
1232 } // phares
1233
1234 //
1235 // MOVEMENT CLIPPING
1236 //
1237
1238 //
1239 // P_CheckPosition
1240 // This is purely informative, nothing is modified
1241 // (except things picked up).
1242 //
1243 // in:
1244 // a mobj_t (can be valid or invalid)
1245 // a position to be checked
1246 // (doesn't need to be related to the mobj_t->x,y)
1247 //
1248 // during:
1249 // special things are touched if MF_PICKUP
1250 // early out on solid lines?
1251 //
1252 // out:
1253 // newsubsec
1254 // floorz
1255 // ceilingz
1256 // tmdropoffz
1257 // the lowest point contacted
1258 // (monsters won't move to a dropoff)
1259 // speciallines[]
1260 // numspeciallines
1261 //
1262
1263 dboolean P_CheckPosition (mobj_t* thing,fixed_t x,fixed_t y)
1264 {
1265 int xl;
1266 int xh;
1267 int yl;
1268 int yh;
1269 int bx;
1270 int by;
1271 sector_t* newsec;
1272
1273 tmthing = thing;
1274 tmflags = thing->flags;
1275
1276 tmx = x;
1277 tmy = y;
1278
1279 tmbbox[BOXTOP] = y + tmthing->radius;
1280 tmbbox[BOXBOTTOM] = y - tmthing->radius;
1281 tmbbox[BOXRIGHT] = x + tmthing->radius;
1282 tmbbox[BOXLEFT] = x - tmthing->radius;
1283
1284 newsec = R_PointInSector (x,y);
1285 floorline = blockline = ceilingline = NULL; // killough 8/1/98
1286
1287 // Whether object can get out of a sticky situation:
1288 tmunstuck = thing->player && /* only players */
1289 thing->player->mo == thing && /* not voodoo dolls */
1290 mbf_features; /* not under old demos */
1291
1292 // The base floor / ceiling is from the sector
1293 // that contains the point.
1294 // Any contacted lines the step closer together
1295 // will adjust them.
1296
1297 tmfloorz = tmdropoffz = newsec->floorheight;
1298 tmceilingz = newsec->ceilingheight;
1299 tmfloorpic = newsec->floorpic;
1300 validcount++;
1301 numspechit = 0;
1302
1303 if (tmflags & MF_NOCLIP && (!hexen || !(tmflags & MF_SKULLFLY)))
1304 return true;
1305
1306 // Check things first, possibly picking things up.
1307 // The bounding box is extended by MAXRADIUS
1308 // because mobj_ts are grouped into mapblocks
1309 // based on their origin point, and can overlap
1310 // into adjacent blocks by up to MAXRADIUS units.
1311
1312 xl = P_GetSafeBlockX(tmbbox[BOXLEFT] - bmaporgx - MAXRADIUS);
1313 xh = P_GetSafeBlockX(tmbbox[BOXRIGHT] - bmaporgx + MAXRADIUS);
1314 yl = P_GetSafeBlockY(tmbbox[BOXBOTTOM] - bmaporgy - MAXRADIUS);
1315 yh = P_GetSafeBlockY(tmbbox[BOXTOP] - bmaporgy + MAXRADIUS);
1316
1317 BlockingMobj = NULL;
1318
1319 for (bx=xl ; bx<=xh ; bx++)
1320 for (by=yl ; by<=yh ; by++)
1321 if (!P_BlockThingsIterator(bx,by,PIT_CheckThing))
1322 return false;
1323
1324 if (hexen && tmflags & MF_NOCLIP)
1325 {
1326 return true;
1327 }
1328
1329 BlockingMobj = NULL;
1330
1331 // check lines
1332
1333 xl = P_GetSafeBlockX(tmbbox[BOXLEFT] - bmaporgx);
1334 xh = P_GetSafeBlockX(tmbbox[BOXRIGHT] - bmaporgx);
1335 yl = P_GetSafeBlockY(tmbbox[BOXBOTTOM] - bmaporgy);
1336 yh = P_GetSafeBlockY(tmbbox[BOXTOP] - bmaporgy);
1337
1338 // Fixes a vanilla bug where this is incremented in the wrong place
1339 // Prevents edge cases where lines aren't checked when they should be
1340 if (mbf21)
1341 {
1342 validcount++;
1343 }
1344
1345 for (bx=xl ; bx<=xh ; bx++)
1346 for (by=yl ; by<=yh ; by++)
1347 if (!P_BlockLinesIterator (bx,by,PIT_CheckLine))
1348 return false; // doesn't fit
1349
1350 return true;
1351 }
1352
1353 void P_AdjustZLimits(mobj_t *thing)
1354 {
1355 int xl, xh;
1356 int yl, yh;
1357 int bx, by;
1358 fixed_t bbox[4];
1359
1360 bbox[BOXTOP] = thing->y + thing->radius;
1361 bbox[BOXBOTTOM] = thing->y - thing->radius;
1362 bbox[BOXRIGHT] = thing->x + thing->radius;
1363 bbox[BOXLEFT] = thing->x - thing->radius;
1364
1365 validcount++;
1366
1367 xl = P_GetSafeBlockX(bbox[BOXLEFT] - bmaporgx);
1368 xh = P_GetSafeBlockX(bbox[BOXRIGHT] - bmaporgx);
1369 yl = P_GetSafeBlockY(bbox[BOXBOTTOM] - bmaporgy);
1370 yh = P_GetSafeBlockY(bbox[BOXTOP] - bmaporgy);
1371
1372 for (bx = xl; bx <= xh; ++bx)
1373 for (by = yl; by <= yh; ++by)
1374 {
1375 int offset;
1376 const int *list;
1377
1378 if (bx < 0 || by < 0 || bx >= bmapwidth || by >= bmapheight)
1379 continue;
1380
1381 offset = by * bmapwidth + bx;
1382 offset = *(blockmap + offset);
1383 list = blockmaplump + offset;
1384
1385 if (skipblstart)
1386 list++;
1387
1388 for (; *list != -1; list++)
1389 {
1390 line_t *ld;
1391
1392 ld = &lines[*list];
1393 if (ld->validcount == validcount)
1394 continue; // line has already been checked
1395 ld->validcount = validcount;
1396
1397 if (bbox[BOXRIGHT] <= ld->bbox[BOXLEFT]
1398 || bbox[BOXLEFT] >= ld->bbox[BOXRIGHT]
1399 || bbox[BOXTOP] <= ld->bbox[BOXBOTTOM]
1400 || bbox[BOXBOTTOM] >= ld->bbox[BOXTOP])
1401 continue; // didn't hit it
1402
1403 if (P_BoxOnLineSide(bbox, ld) != -1)
1404 continue; // didn't hit it
1405
1406 if (!ld->backsector || !ld->frontsector || !(ld->flags & ML_3DMIDTEX))
1407 continue; // not relevant
1408
1409 P_LineOpening(ld, thing);
1410
1411 if (line_opening.bottom > thing->floorz)
1412 thing->floorz = line_opening.bottom;
1413
1414 if (line_opening.top < thing->ceilingz)
1415 thing->ceilingz = line_opening.top;
1416 }
1417 }
1418 }
1419
1420 //
1421 // P_TryMove
1422 // Attempt to move to a new position,
1423 // crossing special lines unless MF_TELEPORT is set.
1424 //
1425
1426 static dboolean Hexen_P_TryMove(mobj_t* thing, fixed_t x, fixed_t y);
1427
1428 void P_CheckCompatibleImpact(mobj_t *thing)
1429 {
1430 // nothing in doom
1431 }
1432
1433 void P_CheckHereticImpact(mobj_t *thing)
1434 {
1435 int i;
1436
1437 if (!numspechit || !(thing->flags & MF_MISSILE) || !thing->target || !thing->target->player)
1438 {
1439 return;
1440 }
1441
1442 for (i = numspechit - 1; i >= 0; i--)
1443 {
1444 map_format.shoot_special_line(thing->target, spechit[i]);
1445 }
1446 }
1447
1448 void P_CheckZDoomImpact(mobj_t *thing)
1449 {
1450 if (!(thing->flags & (MF_TELEPORT | MF_NOCLIP)))
1451 {
1452 int i, side;
1453 line_t *ld;
1454
1455 if (tmthing->flags2 & MF2_BLASTED)
1456 {
1457 P_DamageMobj(tmthing, NULL, NULL, tmthing->info->mass >> 5);
1458 }
1459
1460 for (i = numspechit - 1; i >= 0; i--)
1461 {
1462 // see if the line was crossed
1463 ld = spechit[i];
1464 side = P_PointOnLineSide(thing->x, thing->y, ld);
1465 CheckForPushSpecial(ld, side, thing);
1466 CheckForDamageSpecial(ld, tmthing);
1467 }
1468 }
1469 }
1470
1471 void P_IterateCompatibleSpecHit(mobj_t *thing, fixed_t oldx, fixed_t oldy)
1472 {
1473 while (numspechit--)
1474 if (spechit[numspechit]->special) // see if the line was crossed
1475 {
1476 int oldside = P_PointOnLineSide(oldx, oldy, spechit[numspechit]);
1477 if (oldside != P_PointOnLineSide(thing->x, thing->y, spechit[numspechit]))
1478 map_format.cross_special_line(spechit[numspechit], oldside, thing, false);
1479 }
1480 }
1481
1482 void P_IterateZDoomSpecHit(mobj_t *thing, fixed_t oldx, fixed_t oldy)
1483 {
1484 // In hexen format, crossing a special line can trigger a missile spawn,
1485 // which will trigger a check that resets numspechit.
1486 // We must store the index separately in order to check everything
1487 int tempnumspechit = numspechit;
1488
1489 while (tempnumspechit--)
1490 if (spechit[tempnumspechit]->special) // see if the line was crossed
1491 {
1492 int oldside = P_PointOnLineSide(oldx, oldy, spechit[tempnumspechit]);
1493 if (oldside != P_PointOnLineSide(thing->x, thing->y, spechit[tempnumspechit]))
1494 map_format.cross_special_line(spechit[tempnumspechit], oldside, thing, false);
1495 }
1496 }
1497
1498 dboolean P_TryMove(mobj_t* thing,fixed_t x,fixed_t y,
1499 dboolean dropoff) // killough 3/15/98: allow dropoff as option
1500 {
1501 fixed_t oldx;
1502 fixed_t oldy;
1503
1504 if (map_trail_mode == map_trail_mode_include_collisions &&
1505 thing->player && thing->player->mo == thing)
1506 {
1507 AM_updatePlayerTrail(x, y);
1508 }
1509
1510 if (hexen) return Hexen_P_TryMove(thing, x, y);
1511
1512 felldown = floatok = false; // killough 11/98
1513
1514 if (!P_CheckPosition(thing, x, y))
1515 { // Solid wall or thing
1516 if (heretic || !BlockingMobj || BlockingMobj->player || !thing->player)
1517 map_format.check_impact(thing);
1518 return false;
1519 }
1520
1521 if (!(thing->flags & MF_NOCLIP))
1522 {
1523 if (thing->flags & MF_FLY)
1524 {
1525 // When flying, slide up or down blocking lines until the actor
1526 // is not blocked.
1527 if (thing->z+thing->height > tmceilingz)
1528 {
1529 thing->momz = -8*FRACUNIT;
1530 return false;
1531 }
1532 else if (thing->z < tmfloorz && tmfloorz-tmdropoffz > 24*FRACUNIT)
1533 {
1534 thing->momz = 8*FRACUNIT;
1535 return false;
1536 }
1537 }
1538 // killough 7/26/98: reformatted slightly
1539 // killough 8/1/98: Possibly allow escape if otherwise stuck
1540
1541 if (
1542 tmceilingz - tmfloorz < thing->height || // doesn't fit
1543 // mobj must lower to fit
1544 (
1545 floatok = true,
1546 !(thing->flags & MF_TELEPORT) &&
1547 tmceilingz - thing->z < thing->height &&
1548 !(thing->flags & MF_FLY) &&
1549 !(thing->flags2 & MF2_FLY)
1550 )
1551 )
1552 {
1553 map_format.check_impact(thing);
1554 return tmunstuck
1555 && !(ceilingline && untouched(ceilingline))
1556 && !( floorline && untouched( floorline));
1557 }
1558
1559 if (thing->flags2 & MF2_FLY)
1560 {
1561 if (thing->z + thing->height > tmceilingz)
1562 {
1563 thing->momz = -8 * FRACUNIT;
1564 map_format.check_impact(thing);
1565 return false;
1566 }
1567 else if (thing->z < tmfloorz
1568 && tmfloorz - tmdropoffz > 24 * FRACUNIT)
1569 {
1570 thing->momz = 8 * FRACUNIT;
1571 map_format.check_impact(thing);
1572 return false;
1573 }
1574 }
1575
1576 if (
1577 !(thing->flags & MF_TELEPORT) &&
1578 (!heretic || thing->type != HERETIC_MT_MNTRFX2) &&
1579 tmfloorz - thing->z > 24*FRACUNIT
1580 )
1581 {
1582 dsda_WatchLedgeImpact(thing, tmfloorz);
1583
1584 map_format.check_impact(thing);
1585 return tmunstuck
1586 && !(ceilingline && untouched(ceilingline))
1587 && !( floorline && untouched( floorline));
1588 }
1589
1590 if (heretic && tmfloorz > thing->z)
1591 {
1592 map_format.check_impact(thing);
1593 }
1594
1595 /* killough 3/15/98: Allow certain objects to drop off
1596 * killough 7/24/98, 8/1/98:
1597 * Prevent monsters from getting stuck hanging off ledges
1598 * killough 10/98: Allow dropoffs in controlled circumstances
1599 * killough 11/98: Improve symmetry of clipping on stairs
1600 */
1601 if (!(thing->flags & (MF_DROPOFF|MF_FLOAT)))
1602 {
1603 dboolean ledgeblock = comp[comp_ledgeblock] &&
1604 !(mbf21 && thing->intflags & MIF_SCROLLING);
1605
1606 if (comp[comp_dropoff] || ledgeblock)
1607 {
1608 // e6y
1609 // Fix demosync bug in mbf compatibility mode
1610 // There is no more desync on v2-2822.lmp/vrack2.wad
1611 // -force_no_dropoff command-line switch is for mbf_compatibility demos
1612 // recorded with prboom 2.2.2 - 2.4.7
1613 // Links:
1614 // http://competn.doom2.net/pub/sda/t-z/v2-2822.zip
1615 // http://www.doomworld.com/idgames/index.php?id=11138
1616 if (
1617 (
1618 ledgeblock ||
1619 !dropoff ||
1620 (
1621 !prboom_comp[PC_NO_DROPOFF].state &&
1622 mbf_features &&
1623 compatibility_level <= prboom_2_compatibility
1624 )
1625 ) &&
1626 (tmfloorz - tmdropoffz > 24*FRACUNIT)
1627 )
1628 return false; // don't stand over a dropoff
1629 }
1630 else
1631 if (!dropoff || (dropoff==2 && // large jump down (e.g. dogs)
1632 (tmfloorz-tmdropoffz > 128*FRACUNIT ||
1633 !thing->target || thing->target->z >tmdropoffz)))
1634 {
1635 if (!monkeys || !mbf_features ?
1636 tmfloorz - tmdropoffz > 24*FRACUNIT :
1637 thing->floorz - tmfloorz > 24*FRACUNIT ||
1638 thing->dropoffz - tmdropoffz > 24*FRACUNIT)
1639 return false;
1640 }
1641 else
1642 { /* dropoff allowed -- check for whether it fell more than 24 */
1643 felldown = !(thing->flags & MF_NOGRAVITY) && thing->z - tmfloorz > 24*FRACUNIT;
1644 }
1645 }
1646
1647 if (thing->flags & MF_BOUNCES && // killough 8/13/98
1648 !(thing->flags & (MF_MISSILE|MF_NOGRAVITY)) &&
1649 !sentient(thing) && tmfloorz - thing->z > 16*FRACUNIT)
1650 return false; // too big a step up for bouncers under gravity
1651
1652 // killough 11/98: prevent falling objects from going up too many steps
1653 if (thing->intflags & MIF_FALLING && tmfloorz - thing->z >
1654 FixedMul(thing->momx, thing->momx) + FixedMul(thing->momy, thing->momy))
1655 return false;
1656 }
1657
1658 // the move is ok,
1659 // so unlink from the old position and link into the new position
1660
1661 P_UnsetThingPosition (thing);
1662
1663 oldx = thing->x;
1664 oldy = thing->y;
1665 thing->floorz = tmfloorz;
1666 thing->ceilingz = tmceilingz;
1667 thing->dropoffz = tmdropoffz; // killough 11/98: keep track of dropoffs
1668 thing->x = x;
1669 thing->y = y;
1670
1671 P_SetThingPosition (thing);
1672
1673 if (thing->flags2 & MF2_FOOTCLIP
1674 && P_GetThingFloorType(thing) != FLOOR_SOLID)
1675 {
1676 thing->flags2 |= MF2_FEETARECLIPPED;
1677 }
1678 else if (thing->flags2 & MF2_FEETARECLIPPED)
1679 {
1680 thing->flags2 &= ~MF2_FEETARECLIPPED;
1681 }
1682
1683 if (map_trail_mode == map_trail_mode_ignore_collisions &&
1684 thing->player && thing->player->mo == thing)
1685 {
1686 AM_updatePlayerTrail(x, y);
1687 }
1688
1689 // if any special lines were hit, do the effect
1690
1691 if (!(thing->flags & (MF_TELEPORT | MF_NOCLIP)))
1692 {
1693 map_format.iterate_spechit(thing, oldx, oldy);
1694 }
1695
1696 return true;
1697 }
1698
1699 /*
1700 * killough 9/12/98:
1701 *
1702 * Apply "torque" to objects hanging off of ledges, so that they
1703 * fall off. It's not really torque, since Doom has no concept of
1704 * rotation, but it's a convincing effect which avoids anomalies
1705 * such as lifeless objects hanging more than halfway off of ledges,
1706 * and allows objects to roll off of the edges of moving lifts, or
1707 * to slide up and then back down stairs, or to fall into a ditch.
1708 * If more than one linedef is contacted, the effects are cumulative,
1709 * so balancing is possible.
1710 */
1711
1712 static dboolean PIT_ApplyTorque(line_t *ld)
1713 {
1714 if (ld->backsector && // If thing touches two-sided pivot linedef
1715 (ld->dx || ld->dy) && // Torque is undefined if the line has no length
1716 tmbbox[BOXRIGHT] > ld->bbox[BOXLEFT] &&
1717 tmbbox[BOXLEFT] < ld->bbox[BOXRIGHT] &&
1718 tmbbox[BOXTOP] > ld->bbox[BOXBOTTOM] &&
1719 tmbbox[BOXBOTTOM] < ld->bbox[BOXTOP] &&
1720 P_BoxOnLineSide(tmbbox, ld) == -1)
1721 {
1722 mobj_t *mo = tmthing;
1723
1724 fixed_t dist = // lever arm
1725 + (ld->dx >> FRACBITS) * (mo->y >> FRACBITS)
1726 - (ld->dy >> FRACBITS) * (mo->x >> FRACBITS)
1727 - (ld->dx >> FRACBITS) * (ld->v1->y >> FRACBITS)
1728 + (ld->dy >> FRACBITS) * (ld->v1->x >> FRACBITS);
1729
1730 if (dist < 0 ? // dropoff direction
1731 ld->frontsector->floorheight < mo->z &&
1732 ld->backsector->floorheight >= mo->z :
1733 ld->backsector->floorheight < mo->z &&
1734 ld->frontsector->floorheight >= mo->z)
1735 {
1736 /* At this point, we know that the object straddles a two-sided
1737 * linedef, and that the object's center of mass is above-ground.
1738 */
1739
1740 fixed_t x = D_abs(ld->dx), y = D_abs(ld->dy);
1741
1742 if (y > x)
1743 {
1744 fixed_t t = x;
1745 x = y;
1746 y = t;
1747 }
1748
1749 y = finesine[(tantoangle[FixedDiv(y,x)>>DBITS] + ANG90) >> ANGLETOFINESHIFT];
1750
1751 /* Momentum is proportional to distance between the
1752 * object's center of mass and the pivot linedef.
1753 *
1754 * It is scaled by 2^(OVERDRIVE - gear). When gear is
1755 * increased, the momentum gradually decreases to 0 for
1756 * the same amount of pseudotorque, so that oscillations
1757 * are prevented, yet it has a chance to reach equilibrium.
1758 */
1759 dist = FixedDiv(FixedMul(dist, (mo->gear < OVERDRIVE) ?
1760 y << -(mo->gear - OVERDRIVE) :
1761 y >> +(mo->gear - OVERDRIVE)), x);
1762
1763 /* Apply momentum away from the pivot linedef. */
1764
1765 x = FixedMul(ld->dy, dist);
1766 y = FixedMul(ld->dx, dist);
1767
1768 /* Avoid moving too fast all of a sudden (step into "overdrive") */
1769
1770 dist = FixedMul(x,x) + FixedMul(y,y);
1771
1772 while (dist > FRACUNIT*4 && mo->gear < MAXGEAR)
1773 ++mo->gear, x >>= 1, y >>= 1, dist >>= 1;
1774
1775 mo->momx -= x;
1776 mo->momy += y;
1777 }
1778 }
1779 return true;
1780 }
1781
1782 /*
1783 * killough 9/12/98
1784 *
1785 * Applies "torque" to objects, based on all contacted linedefs
1786 */
1787
1788 void P_ApplyTorque(mobj_t *mo)
1789 {
1790 int xl = P_GetSafeBlockX((tmbbox[BOXLEFT] =
1791 mo->x - mo->radius) - bmaporgx);
1792 int xh = P_GetSafeBlockX((tmbbox[BOXRIGHT] =
1793 mo->x + mo->radius) - bmaporgx);
1794 int yl = P_GetSafeBlockY((tmbbox[BOXBOTTOM] =
1795 mo->y - mo->radius) - bmaporgy);
1796 int yh = P_GetSafeBlockY((tmbbox[BOXTOP] =
1797 mo->y + mo->radius) - bmaporgy);
1798 int bx,by,flags = mo->intflags; //Remember the current state, for gear-change
1799
1800 tmthing = mo;
1801 validcount++; /* prevents checking same line twice */
1802
1803 for (bx = xl ; bx <= xh ; bx++)
1804 for (by = yl ; by <= yh ; by++)
1805 P_BlockLinesIterator(bx, by, PIT_ApplyTorque);
1806
1807 /* If any momentum, mark object as 'falling' using engine-internal flags */
1808 if (mo->momx | mo->momy)
1809 mo->intflags |= MIF_FALLING;
1810 else // Clear the engine-internal flag indicating falling object.
1811 mo->intflags &= ~MIF_FALLING;
1812
1813 /* If the object has been moving, step up the gear.
1814 * This helps reach equilibrium and avoid oscillations.
1815 *
1816 * Doom has no concept of potential energy, much less
1817 * of rotation, so we have to creatively simulate these
1818 * systems somehow :)
1819 */
1820
1821 if (!((mo->intflags | flags) & MIF_FALLING)) // If not falling for a while,
1822 mo->gear = 0; // Reset it to full strength
1823 else
1824 if (mo->gear < MAXGEAR) // Else if not at max gear,
1825 mo->gear++; // move up a gear
1826 }
1827
1828 //
1829 // P_ThingHeightClip
1830 // Takes a valid thing and adjusts the thing->floorz,
1831 // thing->ceilingz, and possibly thing->z.
1832 // This is called for all nearby monsters
1833 // whenever a sector changes height.
1834 // If the thing doesn't fit,
1835 // the z will be set to the lowest value
1836 // and false will be returned.
1837 //
1838
1839 dboolean P_ThingHeightClip (mobj_t* thing)
1840 {
1841 dboolean onfloor;
1842
1843 onfloor = (thing->z == thing->floorz);
1844
1845 P_CheckPosition (thing, thing->x, thing->y);
1846
1847 /* what about stranding a monster partially off an edge?
1848 * killough 11/98: Answer: see below (upset balance if hanging off ledge)
1849 */
1850
1851 thing->floorz = tmfloorz;
1852 thing->ceilingz = tmceilingz;
1853 thing->dropoffz = tmdropoffz; /* killough 11/98: remember dropoffs */
1854 thing->floorpic = tmfloorpic;
1855
1856 if (onfloor)
1857 {
1858 // walking monsters rise and fall with the floor
1859 if (
1860 !hexen ||
1861 (thing->z - thing->floorz < 9 * FRACUNIT) ||
1862 (thing->flags & MF_NOGRAVITY)
1863 )
1864 thing->z = thing->floorz;
1865
1866 /* killough 11/98: Possibly upset balance of objects hanging off ledges */
1867 if (thing->intflags & MIF_FALLING && thing->gear >= MAXGEAR)
1868 thing->gear = 0;
1869 }
1870 else
1871 {
1872 // don't adjust a floating monster unless forced to
1873
1874 if (thing->z+thing->height > thing->ceilingz)
1875 thing->z = thing->ceilingz - thing->height;
1876 }
1877
1878 return thing->ceilingz - thing->floorz >= thing->height;
1879 }
1880
1881
1882 //
1883 // SLIDE MOVE
1884 // Allows the player to slide along any angled walls.
1885 //
1886
1887 /* killough 8/2/98: make variables static */
1888 static fixed_t bestslidefrac;
1889 static line_t* bestslideline;
1890 static mobj_t* slidemo;
1891 static fixed_t tmxmove;
1892 static fixed_t tmymove;
1893
1894 //
1895 // P_HitSlideLine
1896 // Adjusts the xmove / ymove
1897 // so that the next move will slide along the wall.
1898 // If the floor is icy, then you can bounce off a wall. // phares
1899 //
1900
1901 void P_HitSlideLine (line_t* ld)
1902 {
1903 int side;
1904 angle_t lineangle;
1905 angle_t moveangle;
1906 angle_t deltaangle;
1907 fixed_t movelen;
1908 fixed_t newlen;
1909 dboolean icyfloor; // is floor icy? // phares
1910 // |
1911 // Under icy conditions, if the angle of approach to the wall // V
1912 // is more than 45 degrees, then you'll bounce and lose half
1913 // your momentum. If less than 45 degrees, you'll slide along
1914 // the wall. 45 is arbitrary and is believable.
1915
1916 // Check for the special cases of horz or vert walls.
1917
1918 /* killough 10/98: only bounce if hit hard (prevents wobbling)
1919 * cph - DEMOSYNC - should only affect players in Boom demos? */
1920
1921 //e6y
1922 if (mbf_features || prboom_comp[PC_PRBOOM_FRICTION].state)
1923 {
1924 icyfloor =
1925 P_AproxDistance(tmxmove, tmymove) > 4*FRACUNIT &&
1926 variable_friction && // killough 8/28/98: calc friction on demand
1927 slidemo->z <= slidemo->floorz &&
1928 P_GetFriction(slidemo, NULL) > ORIG_FRICTION;
1929 }
1930 else
1931 {
1932 extern dboolean onground;
1933 icyfloor = !compatibility &&
1934 variable_friction &&
1935 slidemo->player &&
1936 onground &&
1937 slidemo->friction > ORIG_FRICTION;
1938 }
1939
1940 if (ld->slopetype == ST_HORIZONTAL)
1941 {
1942 if (icyfloor && (D_abs(tmymove) > D_abs(tmxmove)))
1943 {
1944 tmxmove /= 2; // absorb half the momentum
1945 tmymove = -tmymove/2;
1946 S_StartMobjSound(slidemo,sfx_oof); // oooff!
1947 }
1948 else
1949 tmymove = 0; // no more movement in the Y direction
1950 return;
1951 }
1952
1953 if (ld->slopetype == ST_VERTICAL)
1954 {
1955 if (icyfloor && (D_abs(tmxmove) > D_abs(tmymove)))
1956 {
1957 tmxmove = -tmxmove/2; // absorb half the momentum
1958 tmymove /= 2;
1959 S_StartMobjSound(slidemo,sfx_oof); // oooff! // ^
1960 } // |
1961 else // phares
1962 tmxmove = 0; // no more movement in the X direction
1963 return;
1964 }
1965
1966 // The wall is angled. Bounce if the angle of approach is // phares
1967 // less than 45 degrees. // phares
1968
1969 side = P_PointOnLineSide (slidemo->x, slidemo->y, ld);
1970
1971 lineangle = R_PointToAngle2 (0,0, ld->dx, ld->dy);
1972 if (side == 1)
1973 lineangle += ANG180;
1974 moveangle = R_PointToAngle2 (0,0, tmxmove, tmymove);
1975
1976 // killough 3/2/98:
1977 // The moveangle+=10 breaks v1.9 demo compatibility in
1978 // some demos, so it needs demo_compatibility switch.
1979
1980 if (!demo_compatibility)
1981 moveangle += 10; // prevents sudden path reversal due to // phares
1982 // rounding error // |
1983 deltaangle = moveangle-lineangle; // V
1984 movelen = P_AproxDistance (tmxmove, tmymove);
1985 if (icyfloor && (deltaangle > ANG45) && (deltaangle < ANG90+ANG45))
1986 {
1987 moveangle = lineangle - deltaangle;
1988 movelen /= 2; // absorb
1989 S_StartMobjSound(slidemo,sfx_oof); // oooff!
1990 moveangle >>= ANGLETOFINESHIFT;
1991 tmxmove = FixedMul (movelen, finecosine[moveangle]);
1992 tmymove = FixedMul (movelen, finesine[moveangle]);
1993 } // ^
1994 else // |
1995 { // phares
1996 if (deltaangle > ANG180)
1997 deltaangle += ANG180;
1998
1999 lineangle >>= ANGLETOFINESHIFT;
2000 deltaangle >>= ANGLETOFINESHIFT;
2001 newlen = FixedMul (movelen, finecosine[deltaangle]);
2002 tmxmove = FixedMul (newlen, finecosine[lineangle]);
2003 tmymove = FixedMul (newlen, finesine[lineangle]);
2004 } // phares
2005 }
2006
2007
2008 //
2009 // PTR_SlideTraverse
2010 //
2011
2012 dboolean PTR_SlideTraverse (intercept_t* in)
2013 {
2014 line_t* li;
2015
2016 if (!in->isaline)
2017 I_Error ("PTR_SlideTraverse: not a line?");
2018
2019 li = in->d.line;
2020
2021 if ( ! (li->flags & ML_TWOSIDED) )
2022 {
2023 if (P_PointOnLineSide (slidemo->x, slidemo->y, li))
2024 return true; // don't hit the back side
2025 goto isblocking;
2026 }
2027
2028 // defines a 'window' from one sector to another across a line
2029
2030 P_LineOpening (li, slidemo);
2031
2032 if (line_opening.range < slidemo->height)
2033 goto isblocking; // doesn't fit
2034
2035 if (line_opening.top - slidemo->z < slidemo->height)
2036 goto isblocking; // mobj is too high
2037
2038 if (line_opening.bottom - slidemo->z > 24*FRACUNIT )
2039 goto isblocking; // too big a step up
2040
2041 // this line doesn't block movement
2042
2043 return true;
2044
2045 // the line does block movement,
2046 // see if it is closer than best so far
2047
2048 isblocking:
2049
2050 if (in->frac < bestslidefrac)
2051 {
2052 bestslidefrac = in->frac;
2053 bestslideline = li;
2054 }
2055
2056 return false; // stop
2057 }
2058
2059
2060 //
2061 // P_SlideMove
2062 // The momx / momy move is bad, so try to slide
2063 // along a wall.
2064 // Find the first line hit, move flush to it,
2065 // and slide along it
2066 //
2067 // This is a kludgy mess.
2068 //
2069 // killough 11/98: reformatted
2070
2071 void P_SlideMove(mobj_t *mo)
2072 {
2073 int hitcount = 3;
2074
2075 slidemo = mo; // the object that's sliding
2076
2077 do
2078 {
2079 fixed_t leadx, leady, trailx, traily;
2080
2081 if (!--hitcount)
2082 goto stairstep; // don't loop forever
2083
2084 // trace along the three leading corners
2085
2086 if (mo->momx > 0)
2087 leadx = mo->x + mo->radius, trailx = mo->x - mo->radius;
2088 else
2089 leadx = mo->x - mo->radius, trailx = mo->x + mo->radius;
2090
2091 if (mo->momy > 0)
2092 leady = mo->y + mo->radius, traily = mo->y - mo->radius;
2093 else
2094 leady = mo->y - mo->radius, traily = mo->y + mo->radius;
2095
2096 bestslidefrac = FRACUNIT+1;
2097
2098 P_PathTraverse(leadx, leady, leadx+mo->momx, leady+mo->momy,
2099 PT_ADDLINES, PTR_SlideTraverse);
2100 P_PathTraverse(trailx, leady, trailx+mo->momx, leady+mo->momy,
2101 PT_ADDLINES, PTR_SlideTraverse);
2102 P_PathTraverse(leadx, traily, leadx+mo->momx, traily+mo->momy,
2103 PT_ADDLINES, PTR_SlideTraverse);
2104
2105 // move up to the wall
2106
2107 if (bestslidefrac == FRACUNIT+1)
2108 {
2109 // the move must have hit the middle, so stairstep
2110
2111 stairstep:
2112
2113 /* killough 3/15/98: Allow objects to drop off ledges
2114 *
2115 * phares 5/4/98: kill momentum if you can't move at all
2116 * This eliminates player bobbing if pressed against a wall
2117 * while on ice.
2118 *
2119 * killough 10/98: keep buggy code around for old Boom demos
2120 *
2121 * cph 2000/09//23: buggy code was only in Boom v2.01
2122 */
2123
2124 if (!P_TryMove(mo, mo->x, mo->y + mo->momy, true))
2125 if (!P_TryMove(mo, mo->x + mo->momx, mo->y, true))
2126 if (compatibility_level == boom_201_compatibility)
2127 mo->momx = mo->momy = 0;
2128
2129 break;
2130 }
2131
2132 // fudge a bit to make sure it doesn't hit
2133
2134 if ((bestslidefrac -= 0x800) > 0)
2135 {
2136 fixed_t newx = FixedMul(mo->momx, bestslidefrac);
2137 fixed_t newy = FixedMul(mo->momy, bestslidefrac);
2138
2139 // killough 3/15/98: Allow objects to drop off ledges
2140
2141 if (!P_TryMove(mo, mo->x+newx, mo->y+newy, true))
2142 goto stairstep;
2143 }
2144
2145 // Now continue along the wall.
2146 // First calculate remainder.
2147
2148 bestslidefrac = FRACUNIT-(bestslidefrac+0x800);
2149
2150 if (bestslidefrac > FRACUNIT)
2151 bestslidefrac = FRACUNIT;
2152
2153 if (bestslidefrac <= 0)
2154 break;
2155
2156 tmxmove = FixedMul(mo->momx, bestslidefrac);
2157 tmymove = FixedMul(mo->momy, bestslidefrac);
2158
2159 P_HitSlideLine(bestslideline); // clip the moves
2160
2161 mo->momx = tmxmove;
2162 mo->momy = tmymove;
2163
2164 /* killough 10/98: affect the bobbing the same way (but not voodoo dolls)
2165 * cph - DEMOSYNC? */
2166 if (!raven && mo->player && mo->player->mo == mo)
2167 {
2168 if (D_abs(mo->player->momx) > D_abs(tmxmove))
2169 mo->player->momx = tmxmove;
2170 if (D_abs(mo->player->momy) > D_abs(tmymove))
2171 mo->player->momy = tmymove;
2172 }
2173 } // killough 3/15/98: Allow objects to drop off ledges:
2174 while (!P_TryMove(mo, mo->x+tmxmove, mo->y+tmymove, true));
2175 }
2176
2177 //
2178 // P_LineAttack
2179 //
2180 mobj_t* linetarget; // who got hit (or NULL)
2181 mobj_t* crosshair_target;
2182 static mobj_t* shootthing;
2183
2184 /* killough 8/2/98: for more intelligent autoaiming */
2185 static uint64_t aim_flags_mask;
2186
2187 // Height if not aiming up or down
2188 fixed_t shootz;
2189
2190 int la_damage;
2191 fixed_t attackrange;
2192
2193 static fixed_t aimslope;
2194
2195 // slopes to top and bottom of target
2196 // killough 4/20/98: make static instead of using ones in p_sight.c
2197
2198 static fixed_t topslope;
2199 static fixed_t bottomslope;
2200
2201
2202 //
2203 // PTR_AimTraverse
2204 // Sets linetaget and aimslope when a target is aimed at.
2205 //
2206 dboolean PTR_AimTraverse (intercept_t* in)
2207 {
2208 line_t* li;
2209 mobj_t* th;
2210 fixed_t slope;
2211 fixed_t thingtopslope;
2212 fixed_t thingbottomslope;
2213 fixed_t dist;
2214
2215 if (in->isaline)
2216 {
2217 li = in->d.line;
2218
2219 if ( !(li->flags & (ML_TWOSIDED | ML_BLOCKEVERYTHING)) )
2220 return false; // stop
2221
2222 // Crosses a two sided line.
2223 // A two sided line will restrict
2224 // the possible target ranges.
2225
2226 P_LineOpening (li, NULL);
2227
2228 if (line_opening.bottom >= line_opening.top)
2229 return false; // stop
2230
2231 dist = FixedMul (attackrange, in->frac);
2232
2233 // e6y: emulation of missed back side on two-sided lines.
2234 // backsector can be NULL if overrun_missedbackside_emulate is 1
2235 if (!li->backsector || li->frontsector->floorheight != li->backsector->floorheight)
2236 {
2237 slope = FixedDiv (line_opening.bottom - shootz , dist);
2238 if (slope > bottomslope)
2239 bottomslope = slope;
2240 }
2241
2242 // e6y: emulation of missed back side on two-sided lines.
2243 if (!li->backsector || li->frontsector->ceilingheight != li->backsector->ceilingheight)
2244 {
2245 slope = FixedDiv (line_opening.top - shootz , dist);
2246 if (slope < topslope)
2247 topslope = slope;
2248 }
2249
2250 if (topslope <= bottomslope)
2251 return false; // stop
2252
2253 return true; // shot continues
2254 }
2255
2256 // shoot a thing
2257
2258 th = in->d.thing;
2259 if (th == shootthing)
2260 return true; // can't shoot self
2261
2262 if (!(th->flags&MF_SHOOTABLE))
2263 return true; // corpse or something
2264
2265 if (heretic && th->type == HERETIC_MT_POD)
2266 return true; // Can't auto-aim at pods
2267
2268 if (hexen && th->player && netgame && !deathmatch)
2269 { // don't aim at fellow co-op players
2270 return true;
2271 }
2272
2273 /* killough 7/19/98, 8/2/98:
2274 * friends don't aim at friends (except players), at least not first
2275 */
2276 if (th->flags & shootthing->flags & aim_flags_mask && !th->player)
2277 return true;
2278
2279 // check angles to see if the thing can be aimed at
2280
2281 dist = FixedMul (attackrange, in->frac);
2282 thingtopslope = FixedDiv (th->z+th->height - shootz , dist);
2283
2284 if (thingtopslope < bottomslope)
2285 return true; // shot over the thing
2286
2287 thingbottomslope = FixedDiv (th->z - shootz, dist);
2288
2289 if (thingbottomslope > topslope)
2290 return true; // shot under the thing
2291
2292 // this thing can be hit!
2293
2294 if (thingtopslope > topslope)
2295 thingtopslope = topslope;
2296
2297 if (thingbottomslope < bottomslope)
2298 thingbottomslope = bottomslope;
2299
2300 aimslope = (thingtopslope+thingbottomslope)/2;
2301 linetarget = th;
2302
2303 return false; // don't go any farther
2304 }
2305
2306 // heretic
2307 extern mobjtype_t PuffType;
2308
2309 //
2310 // PTR_ShootTraverse
2311 //
2312 dboolean PTR_ShootTraverse (intercept_t* in)
2313 {
2314 fixed_t x;
2315 fixed_t y;
2316 fixed_t z;
2317 fixed_t frac;
2318
2319 mobj_t* th;
2320
2321 fixed_t slope;
2322 fixed_t dist;
2323 fixed_t thingtopslope;
2324 fixed_t thingbottomslope;
2325
2326 if (in->isaline)
2327 {
2328 line_t *li = in->d.line;
2329
2330 if (li->special)
2331 map_format.shoot_special_line(shootthing, li);
2332
2333 if (li->flags & ML_TWOSIDED &&
2334 !(li->flags & (ML_BLOCKEVERYTHING | ML_BLOCKHITSCAN)))
2335 { // crosses a two sided (really 2s) line
2336 P_LineOpening (li, NULL);
2337 dist = FixedMul(attackrange, in->frac);
2338
2339 // killough 11/98: simplify
2340
2341 // e6y: emulation of missed back side on two-sided lines.
2342 // backsector can be NULL if overrun_missedbackside_emulate is 1
2343 if (!li->backsector)
2344 {
2345 if ((slope = FixedDiv(line_opening.bottom - shootz , dist)) <= aimslope &&
2346 (slope = FixedDiv(line_opening.top - shootz , dist)) >= aimslope)
2347 return true; // shot continues
2348 }
2349 else
2350 if ((li->frontsector->floorheight==li->backsector->floorheight ||
2351 (slope = FixedDiv(line_opening.bottom - shootz , dist)) <= aimslope) &&
2352 (li->frontsector->ceilingheight==li->backsector->ceilingheight ||
2353 (slope = FixedDiv (line_opening.top - shootz , dist)) >= aimslope))
2354 return true; // shot continues
2355 }
2356
2357 // hit line
2358 // position a bit closer
2359
2360 if (dsda_FreeAim())
2361 {
2362 int64_t real_z;
2363 int side = P_PointOnLineSide(trace.x, trace.y, li);
2364 sector_t *sec = side ? li->backsector : li->frontsector;
2365
2366 real_z = (int64_t) shootz + FixedMul64(aimslope, FixedMul(in->frac, attackrange));
2367 z = real_z > INT_MAX ? INT_MAX :
2368 real_z < INT_MIN ? INT_MIN :
2369 real_z;
2370
2371 if (sec && sec->floorheight > z)
2372 {
2373 fixed_t dist;
2374
2375 if (sec->floorpic == skyflatnum)
2376 return false;
2377
2378 z = sec->floorheight;
2379 dist = FixedDiv(z - shootz, aimslope);
2380 frac = FixedDiv(dist, attackrange);
2381 }
2382 else if (sec && sec->ceilingheight < z)
2383 {
2384 fixed_t dist;
2385
2386 if (sec->ceilingpic == skyflatnum)
2387 return false;
2388
2389 // puff spawn height is +/- (255 << 10)
2390 z = sec->ceilingheight - mobjinfo[MT_PUFF].height - (255 << 10);
2391 dist = FixedDiv(z - shootz, aimslope);
2392 frac = FixedDiv(dist, attackrange);
2393 }
2394 else
2395 {
2396 frac = in->frac - FixedDiv(4 * FRACUNIT, attackrange);
2397 z = shootz + FixedMul (aimslope, FixedMul(frac, attackrange));
2398 }
2399 }
2400 else
2401 {
2402 frac = in->frac - FixedDiv(4 * FRACUNIT, attackrange);
2403 z = shootz + FixedMul (aimslope, FixedMul(frac, attackrange));
2404
2405 if (li->frontsector->ceilingpic == skyflatnum)
2406 {
2407 // don't shoot the sky!
2408
2409 if (z > li->frontsector->ceilingheight)
2410 return false;
2411
2412 // it's a sky hack wall
2413
2414 if (li->backsector && li->backsector->ceilingpic == skyflatnum)
2415
2416 // fix bullet-eaters -- killough:
2417 // WARNING: Almost all demos will lose sync without this
2418 // demo_compatibility flag check!!! killough 1/18/98
2419 if (demo_compatibility || li->backsector->ceilingheight < z)
2420 return false;
2421 }
2422 }
2423
2424 x = trace.x + FixedMul (trace.dx, frac);
2425 y = trace.y + FixedMul (trace.dy, frac);
2426
2427 if (li->health)
2428 {
2429 dsda_DamageLinedef(li, shootthing, la_damage);
2430 }
2431
2432 // Spawn bullet puffs.
2433
2434 P_SpawnPuff (x,y,z);
2435
2436 // don't go any farther
2437
2438 return false;
2439 }
2440
2441 // shoot a thing
2442
2443 th = in->d.thing;
2444 if (th == shootthing)
2445 return true; // can't shoot self
2446
2447 if (!(th->flags&MF_SHOOTABLE))
2448 return true; // corpse or something
2449
2450 if (heretic && th->flags & MF_SHADOW && shootthing->player->readyweapon == wp_staff)
2451 return true;
2452
2453 // check angles to see if the thing can be aimed at
2454
2455 dist = FixedMul (attackrange, in->frac);
2456 thingtopslope = FixedDiv (th->z+th->height - shootz , dist);
2457
2458 if (thingtopslope < aimslope)
2459 return true; // shot over the thing
2460
2461 thingbottomslope = FixedDiv (th->z - shootz, dist);
2462
2463 if (thingbottomslope > aimslope)
2464 return true; // shot under the thing
2465
2466 // hit thing
2467 // position a bit closer
2468
2469 frac = in->frac - FixedDiv (10*FRACUNIT,attackrange);
2470
2471 x = trace.x + FixedMul (trace.dx, frac);
2472 y = trace.y + FixedMul (trace.dy, frac);
2473 z = shootz + FixedMul (aimslope, FixedMul(frac, attackrange));
2474
2475 // Spawn bullet puffs or blod spots,
2476 // depending on target type.
2477 if (heretic && PuffType == HERETIC_MT_BLASTERPUFF1)
2478 { // Make blaster big puff
2479 mobj_t* mo;
2480 mo = P_SpawnMobj(x, y, z, HERETIC_MT_BLASTERPUFF2);
2481 S_StartMobjSound(mo, heretic_sfx_blshit);
2482 }
2483 else
2484 {
2485 if (raven || in->d.thing->flags & MF_NOBLOOD)
2486 P_SpawnPuff (x,y,z);
2487 else
2488 P_SpawnBlood (x,y,z, la_damage, th);
2489 }
2490
2491 if (la_damage)
2492 {
2493 if (
2494 raven &&
2495 !(in->d.thing->flags & MF_NOBLOOD) &&
2496 !(in->d.thing->flags2 & MF2_INVULNERABLE)
2497 )
2498 {
2499 if (PuffType == HEXEN_MT_AXEPUFF || PuffType == HEXEN_MT_AXEPUFF_GLOW)
2500 {
2501 P_BloodSplatter2(x, y, z, in->d.thing);
2502 }
2503 if (P_Random(pr_heretic) < 192)
2504 {
2505 P_BloodSplatter(x, y, z, in->d.thing);
2506 }
2507 }
2508
2509 if (hexen && PuffType == HEXEN_MT_FLAMEPUFF2)
2510 { // Cleric FlameStrike does fire damage
2511 extern mobj_t LavaInflictor;
2512
2513 P_DamageMobj(th, &LavaInflictor, shootthing, la_damage);
2514 }
2515 else
2516 {
2517 P_DamageMobj(th, shootthing, shootthing, la_damage);
2518 }
2519 }
2520
2521 // don't go any farther
2522 return false;
2523 }
2524
2525
2526 //
2527 // P_AimLineAttack
2528 //
2529 fixed_t P_AimLineAttack(mobj_t* t1,angle_t angle,fixed_t distance, uint64_t mask)
2530 {
2531 fixed_t x2;
2532 fixed_t y2;
2533
2534 t1 = P_SubstNullMobj(t1);
2535
2536 angle >>= ANGLETOFINESHIFT;
2537 shootthing = t1;
2538
2539 x2 = t1->x + (distance>>FRACBITS)*finecosine[angle];
2540 y2 = t1->y + (distance>>FRACBITS)*finesine[angle];
2541 shootz = t1->z + (t1->height>>1) + 8*FRACUNIT;
2542
2543 // can't shoot outside view angles
2544
2545 topslope = 100*FRACUNIT/160;
2546 bottomslope = -100*FRACUNIT/160;
2547
2548 attackrange = distance;
2549 linetarget = NULL;
2550
2551 /* killough 8/2/98: prevent friends from aiming at friends */
2552 aim_flags_mask = mask;
2553
2554 P_PathTraverse(t1->x,t1->y,x2,y2,PT_ADDLINES|PT_ADDTHINGS,PTR_AimTraverse);
2555
2556 if (linetarget)
2557 return aimslope;
2558
2559 return 0;
2560 }
2561
2562
2563 //
2564 // P_LineAttack
2565 // If damage == 0, it is just a test trace
2566 // that will leave linetarget set.
2567 //
2568
2569 void P_LineAttack(mobj_t* t1, angle_t angle, fixed_t distance, fixed_t slope,
2570 int damage)
2571 {
2572 fixed_t x2;
2573 fixed_t y2;
2574
2575 angle >>= ANGLETOFINESHIFT;
2576 shootthing = t1;
2577 la_damage = damage;
2578 x2 = t1->x + (distance>>FRACBITS)*finecosine[angle];
2579 y2 = t1->y + (distance>>FRACBITS)*finesine[angle];
2580 shootz = t1->z + (t1->height>>1) + 8*FRACUNIT;
2581 if (hexen)
2582 {
2583 shootz -= t1->floorclip;
2584 }
2585 else if (t1->flags2 & MF2_FEETARECLIPPED)
2586 {
2587 shootz -= FOOTCLIPSIZE;
2588 }
2589 attackrange = distance;
2590 aimslope = slope;
2591
2592 if (P_PathTraverse(t1->x,t1->y,x2,y2,PT_ADDLINES|PT_ADDTHINGS,PTR_ShootTraverse))
2593 {
2594 if (hexen)
2595 {
2596 switch (PuffType)
2597 {
2598 case HEXEN_MT_PUNCHPUFF:
2599 S_StartMobjSound(t1, hexen_sfx_fighter_punch_miss);
2600 break;
2601 case HEXEN_MT_HAMMERPUFF:
2602 case HEXEN_MT_AXEPUFF:
2603 case HEXEN_MT_AXEPUFF_GLOW:
2604 S_StartMobjSound(t1, hexen_sfx_fighter_hammer_miss);
2605 break;
2606 case HEXEN_MT_FLAMEPUFF:
2607 P_SpawnPuff(x2, y2, shootz + FixedMul(slope, distance));
2608 break;
2609 default:
2610 break;
2611 }
2612 }
2613 }
2614 }
2615
2616
2617 //
2618 // USE LINES
2619 //
2620
2621 mobj_t* usething;
2622
2623 dboolean PTR_UseTraverse (intercept_t* in)
2624 {
2625 int side;
2626
2627 if (!in->d.line->special)
2628 {
2629 int sound;
2630
2631 if (in->d.line->flags & (ML_BLOCKEVERYTHING | ML_BLOCKUSE))
2632 {
2633 line_opening.range = 0;
2634 }
2635 else
2636 {
2637 P_LineOpening (in->d.line, NULL);
2638 }
2639
2640 if (line_opening.range <= 0)
2641 {
2642 if (hexen && usething->player)
2643 {
2644 switch (usething->player->pclass)
2645 {
2646 case PCLASS_FIGHTER:
2647 sound = hexen_sfx_player_fighter_failed_use;
2648 break;
2649 case PCLASS_CLERIC:
2650 sound = hexen_sfx_player_cleric_failed_use;
2651 break;
2652 case PCLASS_MAGE:
2653 sound = hexen_sfx_player_mage_failed_use;
2654 break;
2655 case PCLASS_PIG:
2656 sound = hexen_sfx_pig_active1;
2657 break;
2658 default:
2659 sound = hexen_sfx_None;
2660 break;
2661 }
2662 S_StartMobjSound(usething, sound);
2663 }
2664 else if (!heretic)
2665 {
2666 S_StartSound (usething, sfx_noway);
2667 }
2668
2669 // can't use through a wall
2670 return false;
2671 }
2672
2673 if (hexen && usething->player)
2674 {
2675 fixed_t pheight = usething->z + (usething->height / 2);
2676 if ((line_opening.top < pheight) || (line_opening.bottom > pheight))
2677 {
2678 switch (usething->player->pclass)
2679 {
2680 case PCLASS_FIGHTER:
2681 sound = hexen_sfx_player_fighter_failed_use;
2682 break;
2683 case PCLASS_CLERIC:
2684 sound = hexen_sfx_player_cleric_failed_use;
2685 break;
2686 case PCLASS_MAGE:
2687 sound = hexen_sfx_player_mage_failed_use;
2688 break;
2689 case PCLASS_PIG:
2690 sound = hexen_sfx_pig_active1;
2691 break;
2692 default:
2693 sound = hexen_sfx_None;
2694 break;
2695 }
2696 S_StartMobjSound(usething, sound);
2697 }
2698 }
2699
2700 // not a special line, but keep checking
2701
2702 return true;
2703 }
2704
2705 side = 0;
2706 if (P_PointOnLineSide (usething->x, usething->y, in->d.line) == 1)
2707 side = 1;
2708
2709 // return false; // don't use back side
2710
2711 P_UseSpecialLine (usething, in->d.line, side, false);
2712
2713 //WAS can't use for than one special line in a row
2714 //jff 3/21/98 NOW multiple use allowed with enabling line flag
2715
2716 return (!demo_compatibility && ((in->d.line->flags&ML_PASSUSE) || comperr(comperr_passuse)))?//e6y
2717 true : false;
2718 }
2719
2720 // Returns false if a "oof" sound should be made because of a blocking
2721 // linedef. Makes 2s middles which are impassable, as well as 2s uppers
2722 // and lowers which block the player, cause the sound effect when the
2723 // player tries to activate them. Specials are excluded, although it is
2724 // assumed that all special linedefs within reach have been considered
2725 // and rejected already (see P_UseLines).
2726 //
2727 // by Lee Killough
2728 //
2729
2730 dboolean PTR_NoWayTraverse(intercept_t* in)
2731 {
2732 line_t *ld = in->d.line;
2733 // This linedef
2734 return ld->special || !( // Ignore specials
2735 ld->flags & ML_BLOCKING || ( // Always blocking
2736 P_LineOpening(ld, NULL), // Find openings
2737 line_opening.range <= 0 || // No opening
2738 line_opening.bottom > usething->z+24*FRACUNIT || // Too high it blocks
2739 line_opening.top < usething->z+usething->height // Too low it blocks
2740 )
2741 );
2742 }
2743
2744 //
2745 // P_UseLines
2746 // Looks for special lines in front of the player to activate.
2747 //
2748 void P_UseLines (player_t* player)
2749 {
2750 int angle;
2751 fixed_t x1;
2752 fixed_t y1;
2753 fixed_t x2;
2754 fixed_t y2;
2755
2756 usething = player->mo;
2757
2758 angle = player->mo->angle >> ANGLETOFINESHIFT;
2759
2760 x1 = player->mo->x;
2761 y1 = player->mo->y;
2762 x2 = x1 + (USERANGE>>FRACBITS)*finecosine[angle];
2763 y2 = y1 + (USERANGE>>FRACBITS)*finesine[angle];
2764
2765 // old code:
2766 //
2767 // P_PathTraverse ( x1, y1, x2, y2, PT_ADDLINES, PTR_UseTraverse );
2768 //
2769 // This added test makes the "oof" sound work on 2s lines -- killough:
2770
2771 if (P_PathTraverse ( x1, y1, x2, y2, PT_ADDLINES, PTR_UseTraverse ))
2772 if (!comp[comp_sound] && !P_PathTraverse ( x1, y1, x2, y2, PT_ADDLINES, PTR_NoWayTraverse ))
2773 S_StartSound (usething, sfx_noway);
2774 }
2775
2776
2777 //
2778 // RADIUS ATTACK
2779 //
2780
2781 bomb_t bomb;
2782
2783 //
2784 // PIT_RadiusAttack
2785 // "bomb.source" is the creature
2786 // that caused the explosion at "bomb.spot".
2787 //
2788
2789 static dboolean P_SplashImmune(mobj_t *target, mobj_t *spot)
2790 {
2791 return // not default behaviour and same group
2792 mobjinfo[target->type].splash_group != SG_DEFAULT &&
2793 mobjinfo[target->type].splash_group == mobjinfo[spot->type].splash_group;
2794 }
2795
2796 int P_SplashDamage(fixed_t dist)
2797 {
2798 int damage;
2799
2800 // [XA] independent damage/distance calculation.
2801 // same formula as eternity; thanks Quas :P
2802 if (!hexen && bomb.damage == bomb.distance)
2803 damage = bomb.damage - dist;
2804 else
2805 damage = (bomb.damage * (bomb.distance - dist) / bomb.distance) + 1;
2806
2807 return damage;
2808 }
2809
2810 dboolean PIT_RadiusAttack (mobj_t* thing)
2811 {
2812 fixed_t dx;
2813 fixed_t dy;
2814 fixed_t dist;
2815 int damage;
2816
2817 /* killough 8/20/98: allow bouncers to take damage
2818 * (missile bouncers are already excluded with MF_NOBLOCKMAP)
2819 */
2820
2821 if (!(thing->flags & (MF_SHOOTABLE | MF_BOUNCES)))
2822 return true;
2823
2824 if (P_SplashImmune(thing, bomb.spot))
2825 return true;
2826
2827 if (hexen)
2828 {
2829 if (!(bomb.flags & BF_DAMAGESOURCE) && thing == bomb.source)
2830 { // don't damage the source of the explosion
2831 return true;
2832 }
2833 if (D_abs((thing->z - bomb.spot->z) >> FRACBITS) > 2 * bomb.distance)
2834 { // too high/low
2835 return true;
2836 }
2837 }
2838 else
2839 {
2840 // Boss spider and cyborg
2841 // take no damage from concussion.
2842
2843 // killough 8/10/98: allow grenades to hurt anyone, unless
2844 // fired by Cyberdemons, in which case it won't hurt Cybers.
2845
2846 if (bomb.spot->flags & MF_BOUNCES ?
2847 thing->type == MT_CYBORG && bomb.source->type == MT_CYBORG :
2848 thing->flags2 & (MF2_NORADIUSDMG | MF2_BOSS) &&
2849 !(bomb.spot->flags2 & MF2_FORCERADIUSDMG))
2850 return true;
2851 }
2852
2853 dx = D_abs(thing->x - bomb.spot->x);
2854 dy = D_abs(thing->y - bomb.spot->y);
2855
2856 dist = dx > dy ? dx : dy;
2857
2858 if (map_info.flags & MI_EXPLODE_IN_3D &&
2859 (bomb.spot->z < thing->z || bomb.spot->z >= thing->z + thing->height))
2860 {
2861 fixed_t dz;
2862
2863 if (bomb.spot->z > thing->z)
2864 {
2865 dz = bomb.spot->z - thing->z - thing->height;
2866 }
2867 else
2868 {
2869 dz = thing->z - bomb.spot->z;
2870 }
2871
2872 if (dist <= thing->radius)
2873 {
2874 dist = dz;
2875 }
2876 else
2877 {
2878 dist -= thing->radius;
2879 dist = P_AproxDistance(dist, dz);
2880 }
2881 }
2882 else
2883 {
2884 dist -= thing->radius;
2885
2886 if (dist < 0)
2887 dist = 0;
2888 }
2889
2890 dist >>= FRACBITS;
2891
2892 if (dist >= bomb.distance)
2893 return true; // out of range
2894
2895 if ( P_CheckSight (thing, bomb.spot) )
2896 {
2897 // must be in direct path
2898
2899 damage = P_SplashDamage(dist);
2900
2901 if (hexen && thing->player)
2902 {
2903 damage >>= 2;
2904 }
2905
2906 P_DamageMobj (thing, bomb.spot, bomb.source, damage);
2907
2908 if (map_info.flags & MI_VERTICAL_EXPLOSION_THRUST && !(bomb.flags & BF_HORIZONTAL))
2909 {
2910 fixed_t thrust;
2911 fixed_t dxy, dz;
2912 angle_t an;
2913
2914 dxy = P_AproxDistance(dx, dy);
2915 dz = thing->z + thing->height / 2 - bomb.spot->z;
2916 an = R_PointToAngle2(0, 0, dxy, dz);
2917
2918 thrust = damage * (FRACUNIT >> 3) * g_thrust_factor / thing->info->mass;
2919
2920 thing->momz += FixedMul(thrust, finesine[an >> ANGLETOFINESHIFT]);
2921 }
2922 }
2923
2924 return true;
2925 }
2926
2927 //
2928 // P_RadiusAttack
2929 // Source is the creature that caused the explosion at spot.
2930 //
2931 void P_RadiusAttack(mobj_t* spot,mobj_t* source, int damage, int distance, int flags)
2932 {
2933 int x;
2934 int y;
2935
2936 int xl;
2937 int xh;
2938 int yl;
2939 int yh;
2940
2941 fixed_t dist;
2942
2943 dist = (distance+MAXRADIUS)<<FRACBITS;
2944 yh = P_GetSafeBlockY(spot->y + dist - bmaporgy);
2945 yl = P_GetSafeBlockY(spot->y - dist - bmaporgy);
2946 xh = P_GetSafeBlockX(spot->x + dist - bmaporgx);
2947 xl = P_GetSafeBlockX(spot->x - dist - bmaporgx);
2948
2949 bomb.spot = spot;
2950 if (heretic && spot->type == HERETIC_MT_POD && spot->target)
2951 {
2952 bomb.source = spot->target;
2953 }
2954 else
2955 {
2956 bomb.source = source;
2957 }
2958 bomb.damage = damage;
2959 bomb.distance = distance;
2960 bomb.flags = flags;
2961
2962 for (y=yl ; y<=yh ; y++)
2963 for (x=xl ; x<=xh ; x++)
2964 P_BlockThingsIterator (x, y, PIT_RadiusAttack );
2965
2966 if (map_format.zdoom)
2967 {
2968 dsda_RadiusAttackDestructibles(xl, xh, yl, yh);
2969 }
2970 }
2971
2972
2973 //
2974 // PIT_ChangeSector
2975 //
2976
2977 dboolean PIT_ChangeSector (mobj_t* thing)
2978 {
2979 mobj_t* mo;
2980
2981 if (P_ThingHeightClip (thing))
2982 return true; // keep checking
2983
2984 // crunch bodies to giblets
2985
2986 if (thing->health <= 0)
2987 {
2988 if (hexen)
2989 {
2990 if ((thing->flags & MF_CORPSE))
2991 {
2992 if (thing->flags & MF_NOBLOOD)
2993 {
2994 P_RemoveMobj(thing);
2995 }
2996 else
2997 {
2998 if (thing->state != &states[HEXEN_S_GIBS1])
2999 {
3000 P_SetMobjState(thing, HEXEN_S_GIBS1);
3001 thing->height = 0;
3002 thing->radius = 0;
3003 S_StartMobjSound(thing, hexen_sfx_player_falling_splat);
3004 }
3005 }
3006 return true; // keep checking
3007 }
3008 }
3009 else
3010 {
3011 if (!heretic) P_SetMobjState (thing, S_GIBS);
3012
3013 if (compatibility_level != doom_12_compatibility)
3014 {
3015 thing->flags &= ~MF_SOLID;
3016 }
3017 thing->height = 0;
3018 thing->radius = 0;
3019 thing->color = thing->info->bloodcolor;
3020 return true; // keep checking
3021 }
3022 }
3023
3024 // crunch dropped items
3025
3026 if (thing->flags & MF_DROPPED)
3027 {
3028 P_RemoveMobj (thing);
3029
3030 // keep checking
3031 return true;
3032 }
3033
3034 /* killough 11/98: kill touchy things immediately */
3035 if (thing->flags & MF_TOUCHY &&
3036 (thing->intflags & MIF_ARMED || sentient(thing)))
3037 {
3038 P_DamageMobj(thing, NULL, NULL, thing->health); // kill object
3039 return true; // keep checking
3040 }
3041
3042 if (! (thing->flags & MF_SHOOTABLE) )
3043 {
3044 // assume it is bloody gibs or something
3045 return true;
3046 }
3047
3048 nofit = true;
3049
3050 if (crushchange > 0 && !(leveltime & 3)) {
3051 int t;
3052
3053 P_DamageMobj(thing, NULL, NULL, crushchange);
3054 dsda_WatchCrush(thing, crushchange);
3055
3056 if (
3057 !hexen ||
3058 (
3059 !(thing->flags & MF_NOBLOOD) &&
3060 !(thing->flags2 & MF2_INVULNERABLE)
3061 )
3062 )
3063 {
3064 // spray blood in a random direction
3065 mo = P_SpawnMobj (thing->x,
3066 thing->y,
3067 thing->z + thing->height / 2, g_mt_blood);
3068 mo->color = thing->info->bloodcolor;
3069
3070 /* killough 8/10/98: remove dependence on order of evaluation */
3071 t = P_Random(pr_crush);
3072 mo->momx = (t - P_Random (pr_crush)) << 12;
3073 t = P_Random(pr_crush);
3074 mo->momy = (t - P_Random (pr_crush)) << 12;
3075 }
3076 }
3077
3078 // keep checking (crush other things)
3079 return true;
3080 }
3081
3082
3083 //
3084 // P_ChangeSector
3085 //
3086 dboolean P_ChangeSector(sector_t* sector, int crunch)
3087 {
3088 int x;
3089 int y;
3090
3091 nofit = false;
3092 crushchange = crunch;
3093
3094 if (crushchange == STAIRS_UNINITIALIZED_CRUSH_FIELD_VALUE)
3095 crushchange = DOOM_CRUSH;
3096
3097 // ARRGGHHH!!!!
3098 // This is horrendously slow!!!
3099 // killough 3/14/98
3100
3101 // re-check heights for all things near the moving sector
3102
3103 for (x=sector->blockbox[BOXLEFT] ; x<= sector->blockbox[BOXRIGHT] ; x++)
3104 for (y=sector->blockbox[BOXBOTTOM];y<= sector->blockbox[BOXTOP] ; y++)
3105 P_BlockThingsIterator (x, y, PIT_ChangeSector);
3106
3107 return nofit;
3108 }
3109
3110 void P_InitSectorSearch(mobj_in_sector_t *data, sector_t *sector)
3111 {
3112 data->sector = sector;
3113
3114 for (data->node = data->sector->touching_thinglist;
3115 data->node;
3116 data->node = data->node->m_snext)
3117 data->node->visited = false;
3118
3119 data->node = data->sector->touching_thinglist;
3120 }
3121
3122 mobj_t *P_FindMobjInSector(mobj_in_sector_t *data)
3123 {
3124 while (data->node && data->node->visited)
3125 data->node = data->node->m_snext;
3126
3127 if (!data->node)
3128 return NULL;
3129
3130 data->node->visited = true;
3131
3132 return data->node->m_thing;
3133 }
3134
3135 //
3136 // P_CheckSector
3137 // jff 3/19/98 added to just check monsters on the periphery
3138 // of a moving sector instead of all in bounding box of the
3139 // sector. Both more accurate and faster.
3140 //
3141
3142 dboolean P_CheckSector(sector_t* sector, int crunch)
3143 {
3144 msecnode_t *n;
3145
3146 if (comp[comp_floors]) /* use the old routine for old demos though */
3147 return P_ChangeSector(sector,crunch);
3148
3149 nofit = false;
3150 crushchange = crunch;
3151
3152 if (crushchange == STAIRS_UNINITIALIZED_CRUSH_FIELD_VALUE)
3153 crushchange = DOOM_CRUSH;
3154
3155 // killough 4/4/98: scan list front-to-back until empty or exhausted,
3156 // restarting from beginning after each thing is processed. Avoids
3157 // crashes, and is sure to examine all things in the sector, and only
3158 // the things which are in the sector, until a steady-state is reached.
3159 // Things can arbitrarily be inserted and removed and it won't mess up.
3160 //
3161 // killough 4/7/98: simplified to avoid using complicated counter
3162
3163 // Mark all things invalid
3164
3165 for (n=sector->touching_thinglist; n; n=n->m_snext)
3166 n->visited = false;
3167
3168 do
3169 for (n=sector->touching_thinglist; n; n=n->m_snext) // go through list
3170 if (!n->visited) // unprocessed thing found
3171 {
3172 n->visited = true; // mark thing as processed
3173 if (!(n->m_thing->flags & MF_NOBLOCKMAP)) //jff 4/7/98 don't do these
3174 PIT_ChangeSector(n->m_thing); // process it
3175 break; // exit and start over
3176 }
3177 while (n); // repeat from scratch until all things left are marked valid
3178
3179 return nofit;
3180 }
3181
3182
3183 #define USE_BLOCK_MEMORY_ALLOCATOR
3184 #ifdef USE_BLOCK_MEMORY_ALLOCATOR
3185 // CPhipps -
3186 // Use block memory allocator here
3187
3188 #include "z_bmalloc.h"
3189
3190 IMPLEMENT_BLOCK_MEMORY_ALLOC_ZONE(secnodezone, sizeof(msecnode_t), 256, "SecNodes");
3191
3192 //
3193 // P_FreeSecNodeList
3194 //
3195 void P_FreeSecNodeList(void)
3196 {
3197 DECLARE_BLOCK_MEMORY_ALLOC_ZONE(secnodezone);
3198 NULL_BLOCK_MEMORY_ALLOC_ZONE(secnodezone);
3199 }
3200
3201 msecnode_t* P_GetSecnode(void)
3202 {
3203 return (msecnode_t*)Z_BMalloc(&secnodezone);
3204 }
3205
3206 // P_PutSecnode() returns a node to the freelist.
3207
3208 inline static void P_PutSecnode(msecnode_t* node)
3209 {
3210 Z_BFree(&secnodezone, node);
3211 }
3212 #else // USE_BLOCK_MEMORY_ALLOCATOR
3213 // phares 3/21/98
3214 //
3215 // Maintain a freelist of msecnode_t's to reduce memory allocs and frees.
3216
3217 msecnode_t *headsecnode = NULL;
3218
3219 //
3220 // P_FreeSecNodeList
3221 //
3222 void P_FreeSecNodeList(void)
3223 {
3224 headsecnode = NULL; // this is all thats needed to fix the bug
3225 }
3226
3227 //
3228 // P_GetSecnode
3229 //
3230 // Retrieves a node from the freelist. The calling routine should make sure it
3231 // sets all fields properly.
3232 //
3233 // killough 11/98: reformatted
3234 //
3235 msecnode_t *P_GetSecnode(void)
3236 {
3237 msecnode_t *node;
3238
3239 return headsecnode ?
3240 node = headsecnode, headsecnode = node->m_snext, node :
3241 (msecnode_t *)(Z_MallocLevel(sizeof *node));
3242 }
3243
3244 //
3245 // P_PutSecnode
3246 //
3247 // Returns a node to the freelist.
3248 //
3249 static void P_PutSecnode(msecnode_t *node)
3250 {
3251 node->m_snext = headsecnode;
3252 headsecnode = node;
3253 }
3254 #endif // USE_BLOCK_MEMORY_ALLOCATOR
3255
3256 // phares 3/16/98
3257 //
3258 // P_AddSecnode() searches the current list to see if this sector is
3259 // already there. If not, it adds a sector node at the head of the list of
3260 // sectors this object appears in. This is called when creating a list of
3261 // nodes that will get linked in later. Returns a pointer to the new node.
3262
3263 msecnode_t* P_AddSecnode(sector_t* s, mobj_t* thing, msecnode_t* nextnode)
3264 {
3265 msecnode_t* node;
3266
3267 node = nextnode;
3268 while (node)
3269 {
3270 if (node->m_sector == s) // Already have a node for this sector?
3271 {
3272 node->m_thing = thing; // Yes. Setting m_thing says 'keep it'.
3273 return(nextnode);
3274 }
3275 node = node->m_tnext;
3276 }
3277
3278 // Couldn't find an existing node for this sector. Add one at the head
3279 // of the list.
3280
3281 node = P_GetSecnode();
3282
3283 // killough 4/4/98, 4/7/98: mark new nodes unvisited.
3284 node->visited = 0;
3285
3286 node->m_sector = s; // sector
3287 node->m_thing = thing; // mobj
3288 node->m_tprev = NULL; // prev node on Thing thread
3289 node->m_tnext = nextnode; // next node on Thing thread
3290 if (nextnode)
3291 nextnode->m_tprev = node; // set back link on Thing
3292
3293 // Add new node at head of sector thread starting at s->touching_thinglist
3294
3295 node->m_sprev = NULL; // prev node on sector thread
3296 node->m_snext = s->touching_thinglist; // next node on sector thread
3297 if (s->touching_thinglist)
3298 node->m_snext->m_sprev = node;
3299 s->touching_thinglist = node;
3300 return(node);
3301 }
3302
3303
3304 // P_DelSecnode() deletes a sector node from the list of
3305 // sectors this object appears in. Returns a pointer to the next node
3306 // on the linked list, or NULL.
3307
3308 msecnode_t* P_DelSecnode(msecnode_t* node)
3309 {
3310 msecnode_t* tp; // prev node on thing thread
3311 msecnode_t* tn; // next node on thing thread
3312 msecnode_t* sp; // prev node on sector thread
3313 msecnode_t* sn; // next node on sector thread
3314
3315 if (node)
3316 {
3317
3318 // Unlink from the Thing thread. The Thing thread begins at
3319 // sector_list and not from mobj_t->touching_sectorlist.
3320
3321 tp = node->m_tprev;
3322 tn = node->m_tnext;
3323 if (tp)
3324 tp->m_tnext = tn;
3325 if (tn)
3326 tn->m_tprev = tp;
3327
3328 // Unlink from the sector thread. This thread begins at
3329 // sector_t->touching_thinglist.
3330
3331 sp = node->m_sprev;
3332 sn = node->m_snext;
3333 if (sp)
3334 sp->m_snext = sn;
3335 else
3336 node->m_sector->touching_thinglist = sn;
3337 if (sn)
3338 sn->m_sprev = sp;
3339
3340 // Return this node to the freelist
3341
3342 P_PutSecnode(node);
3343 return(tn);
3344 }
3345 return(NULL);
3346 } // phares 3/13/98
3347
3348 // Delete an entire sector list
3349
3350 void P_DelSeclist(msecnode_t* node)
3351
3352 {
3353 while (node)
3354 node = P_DelSecnode(node);
3355 }
3356
3357
3358 // phares 3/14/98
3359 //
3360 // PIT_GetSectors
3361 // Locates all the sectors the object is in by looking at the lines that
3362 // cross through it. You have already decided that the object is allowed
3363 // at this location, so don't bother with checking impassable or
3364 // blocking lines.
3365
3366 dboolean PIT_GetSectors(line_t* ld)
3367 {
3368 if (tmbbox[BOXRIGHT] <= ld->bbox[BOXLEFT] ||
3369 tmbbox[BOXLEFT] >= ld->bbox[BOXRIGHT] ||
3370 tmbbox[BOXTOP] <= ld->bbox[BOXBOTTOM] ||
3371 tmbbox[BOXBOTTOM] >= ld->bbox[BOXTOP])
3372 return true;
3373
3374 if (P_BoxOnLineSide(tmbbox, ld) != -1)
3375 return true;
3376
3377 // This line crosses through the object.
3378
3379 // Collect the sector(s) from the line and add to the
3380 // sector_list you're examining. If the Thing ends up being
3381 // allowed to move to this position, then the sector_list
3382 // will be attached to the Thing's mobj_t at touching_sectorlist.
3383
3384 sector_list = P_AddSecnode(ld->frontsector,tmthing,sector_list);
3385
3386 /* Don't assume all lines are 2-sided, since some Things
3387 * like MT_TFOG are allowed regardless of whether their radius takes
3388 * them beyond an impassable linedef.
3389 *
3390 * killough 3/27/98, 4/4/98:
3391 * Use sidedefs instead of 2s flag to determine two-sidedness.
3392 * killough 8/1/98: avoid duplicate if same sector on both sides
3393 * cph - DEMOSYNC? */
3394
3395 if (ld->backsector && ld->backsector != ld->frontsector)
3396 sector_list = P_AddSecnode(ld->backsector, tmthing, sector_list);
3397
3398 return true;
3399 }
3400
3401
3402 // phares 3/14/98
3403 //
3404 // P_CreateSecNodeList alters/creates the sector_list that shows what sectors
3405 // the object resides in.
3406
3407 void P_CreateSecNodeList(mobj_t* thing,fixed_t x,fixed_t y)
3408 {
3409 int xl;
3410 int xh;
3411 int yl;
3412 int yh;
3413 int bx;
3414 int by;
3415 msecnode_t* node;
3416 mobj_t* saved_tmthing = tmthing; /* cph - see comment at func end */
3417 fixed_t saved_tmx = tmx, saved_tmy = tmy; /* ditto */
3418
3419 // First, clear out the existing m_thing fields. As each node is
3420 // added or verified as needed, m_thing will be set properly. When
3421 // finished, delete all nodes where m_thing is still NULL. These
3422 // represent the sectors the Thing has vacated.
3423
3424 node = sector_list;
3425 while (node)
3426 {
3427 node->m_thing = NULL;
3428 node = node->m_tnext;
3429 }
3430
3431 tmthing = thing;
3432
3433 tmx = x;
3434 tmy = y;
3435
3436 tmbbox[BOXTOP] = y + tmthing->radius;
3437 tmbbox[BOXBOTTOM] = y - tmthing->radius;
3438 tmbbox[BOXRIGHT] = x + tmthing->radius;
3439 tmbbox[BOXLEFT] = x - tmthing->radius;
3440
3441 validcount2++; // used to make sure we only process a line once
3442
3443 xl = P_GetSafeBlockX(tmbbox[BOXLEFT] - bmaporgx);
3444 xh = P_GetSafeBlockX(tmbbox[BOXRIGHT] - bmaporgx);
3445 yl = P_GetSafeBlockY(tmbbox[BOXBOTTOM] - bmaporgy);
3446 yh = P_GetSafeBlockY(tmbbox[BOXTOP] - bmaporgy);
3447
3448 for (bx=xl ; bx<=xh ; bx++)
3449 for (by=yl ; by<=yh ; by++)
3450 P_BlockLinesIterator2(bx,by,PIT_GetSectors);
3451
3452 // Add the sector of the (x,y) point to sector_list.
3453
3454 sector_list = P_AddSecnode(thing->subsector->sector,thing,sector_list);
3455
3456 // Now delete any nodes that won't be used. These are the ones where
3457 // m_thing is still NULL.
3458
3459 node = sector_list;
3460 while (node)
3461 {
3462 if (node->m_thing == NULL)
3463 {
3464 if (node == sector_list)
3465 sector_list = node->m_tnext;
3466 node = P_DelSecnode(node);
3467 }
3468 else
3469 node = node->m_tnext;
3470 }
3471
3472 /* cph -
3473 * This is the strife we get into for using global variables. tmthing
3474 * is being used by several different functions calling
3475 * P_BlockThingIterator, including functions that can be called *from*
3476 * P_BlockThingIterator. Using a global tmthing is not reentrant.
3477 * OTOH for Boom/MBF demos we have to preserve the buggy behavior.
3478 * Fun. We restore its previous value unless we're in a Boom/MBF demo.
3479 */
3480 if (!prboom_comp[PC_FORCE_LXDOOM_DEMO_COMPATIBILITY].state)
3481 if ((compatibility_level < boom_compatibility_compatibility) ||
3482 (compatibility_level >= prboom_3_compatibility))
3483 tmthing = saved_tmthing;
3484 /* And, duh, the same for tmx/y - cph 2002/09/22
3485 * And for tmbbox - cph 2003/08/10 */
3486 if ((compatibility_level < boom_compatibility_compatibility) /* ||
3487 (compatibility_level >= prboom_4_compatibility) */) {
3488 tmx = saved_tmx, tmy = saved_tmy;
3489 if (tmthing) {
3490 tmbbox[BOXTOP] = tmy + tmthing->radius;
3491 tmbbox[BOXBOTTOM] = tmy - tmthing->radius;
3492 tmbbox[BOXRIGHT] = tmx + tmthing->radius;
3493 tmbbox[BOXLEFT] = tmx - tmthing->radius;
3494 }
3495 }
3496 }
3497
3498 /* cphipps 2004/08/30 -
3499 * Must clear tmthing at tic end, as it might contain a pointer to a removed thinker, or the level might have ended/been ended and we clear the objects it was pointing too. Hopefully we don't need to carry this between tics for sync. */
3500 void P_MapStart(void) {
3501 if (tmthing) I_Error("P_MapStart: tmthing set!");
3502 }
3503 void P_MapEnd(void) {
3504 tmthing = NULL;
3505 }
3506
3507 // heretic
3508
3509 mobj_t *onmobj; // generic global onmobj...used for landing on pods/players
3510
3511 dboolean P_TestMobjLocation(mobj_t * mobj)
3512 {
3513 int flags;
3514
3515 flags = mobj->flags;
3516 mobj->flags &= ~MF_PICKUP;
3517 if (P_CheckPosition(mobj, mobj->x, mobj->y))
3518 { // XY is ok, now check Z
3519 mobj->flags = flags;
3520 if ((mobj->z < mobj->floorz)
3521 || (mobj->z + mobj->height > mobj->ceilingz))
3522 { // Bad Z
3523 return (false);
3524 }
3525 return (true);
3526 }
3527 mobj->flags = flags;
3528 return (false);
3529 }
3530
3531 dboolean PIT_CheckOnmobjZ(mobj_t * thing)
3532 {
3533 fixed_t blockdist;
3534
3535 if (!(thing->flags & (MF_SOLID | MF_SPECIAL | MF_SHOOTABLE)))
3536 { // Can't hit thing
3537 return (true);
3538 }
3539 blockdist = thing->radius + tmthing->radius;
3540 if (abs(thing->x - tmx) >= blockdist || abs(thing->y - tmy) >= blockdist)
3541 { // Didn't hit thing
3542 return (true);
3543 }
3544 if (thing == tmthing)
3545 { // Don't clip against self
3546 return (true);
3547 }
3548 if (tmthing->z > thing->z + thing->height)
3549 {
3550 return (true);
3551 }
3552 else if (tmthing->z + tmthing->height < thing->z)
3553 { // under thing
3554 return (true);
3555 }
3556 if (thing->flags & MF_SOLID)
3557 {
3558 onmobj = thing;
3559 }
3560 return (!(thing->flags & MF_SOLID));
3561 }
3562
3563 // Checks if the new Z position is legal
3564 mobj_t *P_CheckOnmobj(mobj_t * thing)
3565 {
3566 int xl, xh, yl, yh, bx, by;
3567 sector_t *newsec;
3568 fixed_t x;
3569 fixed_t y;
3570 mobj_t oldmo;
3571
3572 x = thing->x;
3573 y = thing->y;
3574 tmthing = thing;
3575 tmflags = thing->flags;
3576 oldmo = *thing; // save the old mobj before the fake zmovement
3577 P_FakeZMovement(tmthing);
3578
3579 tmx = x;
3580 tmy = y;
3581
3582 tmbbox[BOXTOP] = y + tmthing->radius;
3583 tmbbox[BOXBOTTOM] = y - tmthing->radius;
3584 tmbbox[BOXRIGHT] = x + tmthing->radius;
3585 tmbbox[BOXLEFT] = x - tmthing->radius;
3586
3587 newsec = R_PointInSector(x, y);
3588 ceilingline = NULL;
3589
3590 //
3591 // the base floor / ceiling is from the subsector that contains the
3592 // point. Any contacted lines the step closer together will adjust them
3593 //
3594 tmfloorz = tmdropoffz = newsec->floorheight;
3595 tmceilingz = newsec->ceilingheight;
3596 tmfloorpic = newsec->floorpic;
3597
3598 validcount++;
3599 numspechit = 0;
3600
3601 if (tmflags & MF_NOCLIP)
3602 return NULL;
3603
3604 //
3605 // check things first, possibly picking things up
3606 // the bounding box is extended by MAXRADIUS because mobj_ts are grouped
3607 // into mapblocks based on their origin point, and can overlap into adjacent
3608 // blocks by up to MAXRADIUS units
3609 //
3610 xl = (tmbbox[BOXLEFT] - bmaporgx - MAXRADIUS) >> MAPBLOCKSHIFT;
3611 xh = (tmbbox[BOXRIGHT] - bmaporgx + MAXRADIUS) >> MAPBLOCKSHIFT;
3612 yl = (tmbbox[BOXBOTTOM] - bmaporgy - MAXRADIUS) >> MAPBLOCKSHIFT;
3613 yh = (tmbbox[BOXTOP] - bmaporgy + MAXRADIUS) >> MAPBLOCKSHIFT;
3614
3615 for (bx = xl; bx <= xh; bx++)
3616 for (by = yl; by <= yh; by++)
3617 if (!P_BlockThingsIterator(bx, by, PIT_CheckOnmobjZ))
3618 {
3619 *tmthing = oldmo;
3620 return onmobj;
3621 }
3622 *tmthing = oldmo;
3623 return NULL;
3624 }
3625
3626 void P_FakeZMovement(mobj_t * mo)
3627 {
3628 int dist;
3629 int delta;
3630 //
3631 // adjust height
3632 //
3633 mo->z += mo->momz;
3634 if (mo->flags & MF_FLOAT && mo->target)
3635 { // float down towards target if too close
3636 if (!(mo->flags & MF_SKULLFLY) && !(mo->flags & MF_INFLOAT))
3637 {
3638 dist =
3639 P_AproxDistance(mo->x - mo->target->x, mo->y - mo->target->y);
3640 delta = (mo->target->z + (mo->height >> 1)) - mo->z;
3641 if (delta < 0 && dist < -(delta * 3))
3642 mo->z -= FLOATSPEED;
3643 else if (delta > 0 && dist < (delta * 3))
3644 mo->z += FLOATSPEED;
3645 }
3646 }
3647 if (mo->player && mo->flags2 & MF2_FLY && !(mo->z <= mo->floorz)
3648 && leveltime & 2)
3649 {
3650 mo->z += finesine[(FINEANGLES / 20 * leveltime >> 2) & FINEMASK];
3651 }
3652
3653 //
3654 // clip movement
3655 //
3656 if (mo->z <= mo->floorz)
3657 { // Hit the floor
3658 mo->z = mo->floorz;
3659 if (mo->momz < 0)
3660 {
3661 mo->momz = 0;
3662 }
3663 if (mo->flags & MF_SKULLFLY)
3664 { // The skull slammed into something
3665 mo->momz = -mo->momz;
3666 }
3667 if (mo->info->crashstate && (mo->flags & MF_CORPSE))
3668 {
3669 return;
3670 }
3671 }
3672 else if (mo->flags2 & MF2_LOGRAV)
3673 {
3674 fixed_t gravity = P_MobjGravity(mo);
3675
3676 if (mo->momz == 0)
3677 mo->momz = -(gravity >> 3) * 2;
3678 else
3679 mo->momz -= gravity >> 3;
3680 }
3681 else if (!(mo->flags & MF_NOGRAVITY))
3682 {
3683 fixed_t gravity = P_MobjGravity(mo);
3684
3685 if (mo->momz == 0)
3686 mo->momz = -gravity * 2;
3687 else
3688 mo->momz -= gravity;
3689 }
3690
3691 if (mo->z + mo->height > mo->ceilingz)
3692 { // hit the ceiling
3693 if (mo->momz > 0)
3694 mo->momz = 0;
3695 mo->z = mo->ceilingz - mo->height;
3696 if (mo->flags & MF_SKULLFLY)
3697 { // the skull slammed into something
3698 mo->momz = -mo->momz;
3699 }
3700 }
3701 }
3702
3703 void P_AppendSpecHit(line_t * ld)
3704 {
3705 // 1/11/98 killough: remove limit on lines hit, by array doubling
3706 if (numspechit >= spechit_max) {
3707 spechit_max = spechit_max ? spechit_max*2 : 8;
3708 spechit = Z_Realloc(spechit,sizeof *spechit*spechit_max); // killough
3709 }
3710 spechit[numspechit++] = ld;
3711 // e6y: Spechits overrun emulation code
3712 if (numspechit > 8 && demo_compatibility)
3713 {
3714 static spechit_overrun_param_t spechit_overrun_param = {
3715 NULL, // line_t *line;
3716
3717 &spechit, // line_t **spechit;
3718 &numspechit, // int *numspechit;
3719
3720 tmbbox, // fixed_t *tmbbox[4];
3721 &tmfloorz, // fixed_t *tmfloorz;
3722 &tmceilingz, // fixed_t *tmceilingz;
3723
3724 &crushchange, // int *crushchange;
3725 &nofit, // dboolean *nofit;
3726 };
3727 spechit_overrun_param.line = ld;
3728 SpechitOverrun(&spechit_overrun_param);
3729 }
3730 }
3731
3732 // hexen
3733
3734 dboolean PTR_BounceTraverse(intercept_t * in)
3735 {
3736 line_t *li;
3737
3738 if (!in->isaline)
3739 I_Error("PTR_BounceTraverse: not a line?");
3740
3741 li = in->d.line;
3742
3743 if (li->flags & ML_BLOCKEVERYTHING)
3744 goto bounceblocking;
3745
3746 if (!(li->flags & ML_TWOSIDED))
3747 {
3748 if (P_PointOnLineSide(slidemo->x, slidemo->y, li))
3749 return true; // don't hit the back side
3750 goto bounceblocking;
3751 }
3752
3753 P_LineOpening(li, slidemo); // set open
3754 if (line_opening.range < slidemo->height)
3755 goto bounceblocking; // doesn't fit
3756
3757 if (line_opening.top - slidemo->z < slidemo->height)
3758 goto bounceblocking; // mobj is too high
3759 return true; // this line doesn't block movement
3760
3761 // the line does block movement, see if it is closer than best so far
3762 bounceblocking:
3763 if (in->frac < bestslidefrac)
3764 {
3765 bestslidefrac = in->frac;
3766 bestslideline = li;
3767 }
3768 return false; // stop
3769 }
3770
3771 void P_BounceWall(mobj_t * mo)
3772 {
3773 fixed_t leadx, leady;
3774 int side;
3775 angle_t lineangle, moveangle, deltaangle;
3776 fixed_t movelen;
3777
3778 slidemo = mo;
3779
3780 //
3781 // trace along the three leading corners
3782 //
3783 if (mo->momx > 0)
3784 {
3785 leadx = mo->x + mo->radius;
3786 }
3787 else
3788 {
3789 leadx = mo->x - mo->radius;
3790 }
3791 if (mo->momy > 0)
3792 {
3793 leady = mo->y + mo->radius;
3794 }
3795 else
3796 {
3797 leady = mo->y - mo->radius;
3798 }
3799 bestslidefrac = FRACUNIT + 1;
3800 P_PathTraverse(leadx, leady, leadx + mo->momx, leady + mo->momy,
3801 PT_ADDLINES, PTR_BounceTraverse);
3802
3803 side = P_PointOnLineSide(mo->x, mo->y, bestslideline);
3804 lineangle = R_PointToAngle2(0, 0, bestslideline->dx, bestslideline->dy);
3805 if (side == 1)
3806 lineangle += ANG180;
3807 moveangle = R_PointToAngle2(0, 0, mo->momx, mo->momy);
3808 deltaangle = (2 * lineangle) - moveangle;
3809
3810 lineangle >>= ANGLETOFINESHIFT;
3811 deltaangle >>= ANGLETOFINESHIFT;
3812
3813 movelen = P_AproxDistance(mo->momx, mo->momy);
3814 movelen = FixedMul(movelen, 0.75 * FRACUNIT); // friction
3815 if (movelen < FRACUNIT)
3816 movelen = 2 * FRACUNIT;
3817 mo->momx = FixedMul(movelen, finecosine[deltaangle]);
3818 mo->momy = FixedMul(movelen, finesine[deltaangle]);
3819 }
3820
3821 dboolean PIT_ThrustStompThing(mobj_t * thing)
3822 {
3823 fixed_t blockdist;
3824
3825 if (!(thing->flags & MF_SHOOTABLE))
3826 return true;
3827
3828 blockdist = thing->radius + tsthing->radius;
3829 if (abs(thing->x - tsthing->x) >= blockdist ||
3830 abs(thing->y - tsthing->y) >= blockdist ||
3831 (thing->z > tsthing->z + tsthing->height))
3832 return true; // didn't hit it
3833
3834 if (thing == tsthing)
3835 return true; // don't clip against self
3836
3837 P_DamageMobj(thing, tsthing, tsthing, 10001);
3838 tsthing->special_args[1] = 1; // Mark thrust thing as bloody
3839
3840 return true;
3841 }
3842
3843 void PIT_ThrustSpike(mobj_t * actor)
3844 {
3845 int xl, xh, yl, yh, bx, by;
3846 int x0, x2, y0, y2;
3847
3848 tsthing = actor;
3849
3850 x0 = actor->x - actor->info->radius;
3851 x2 = actor->x + actor->info->radius;
3852 y0 = actor->y - actor->info->radius;
3853 y2 = actor->y + actor->info->radius;
3854
3855 xl = (x0 - bmaporgx - MAXRADIUS) >> MAPBLOCKSHIFT;
3856 xh = (x2 - bmaporgx + MAXRADIUS) >> MAPBLOCKSHIFT;
3857 yl = (y0 - bmaporgy - MAXRADIUS) >> MAPBLOCKSHIFT;
3858 yh = (y2 - bmaporgy + MAXRADIUS) >> MAPBLOCKSHIFT;
3859
3860 // stomp on any things contacted
3861 for (bx = xl; bx <= xh; bx++)
3862 for (by = yl; by <= yh; by++)
3863 P_BlockThingsIterator(bx, by, PIT_ThrustStompThing);
3864 }
3865
3866 static void CheckForPushSpecial(line_t * line, int side, mobj_t * mobj)
3867 {
3868 if (line->special)
3869 {
3870 if (mobj->flags2 & MF2_PUSHWALL)
3871 {
3872 P_ActivateLine(line, mobj, side, SPAC_PUSH);
3873 }
3874 else if (mobj->flags2 & MF2_IMPACT)
3875 {
3876 if (map_info.flags & MI_MISSILES_ACTIVATE_IMPACT_LINES ||
3877 !(mobj->flags & MF_MISSILE) ||
3878 !mobj->target)
3879 {
3880 P_ActivateLine(line, mobj, side, SPAC_IMPACT);
3881 }
3882 else
3883 {
3884 P_ActivateLine(line, mobj->target, side, SPAC_IMPACT);
3885 }
3886 }
3887 }
3888 }
3889
3890 static dboolean Hexen_P_TryMove(mobj_t* thing, fixed_t x, fixed_t y)
3891 {
3892 fixed_t oldx, oldy;
3893 int side, oldside;
3894 line_t *ld;
3895
3896 floatok = false;
3897 if (!P_CheckPosition(thing, x, y))
3898 { // Solid wall or thing
3899 if (!BlockingMobj || BlockingMobj->player || !thing->player)
3900 {
3901 goto pushline;
3902 }
3903 else if (BlockingMobj->z + BlockingMobj->height - thing->z
3904 > 24 * FRACUNIT
3905 || (BlockingMobj->subsector->sector->ceilingheight
3906 - (BlockingMobj->z + BlockingMobj->height) <
3907 thing->height)
3908 || (tmceilingz - (BlockingMobj->z + BlockingMobj->height) <
3909 thing->height))
3910 {
3911 goto pushline;
3912 }
3913 }
3914 if (!(thing->flags & MF_NOCLIP))
3915 {
3916 if (tmceilingz - tmfloorz < thing->height)
3917 { // Doesn't fit
3918 goto pushline;
3919 }
3920 floatok = true;
3921 if (!(thing->flags & MF_TELEPORT)
3922 && tmceilingz - thing->z < thing->height
3923 && thing->type != HEXEN_MT_LIGHTNING_CEILING
3924 && !(thing->flags2 & MF2_FLY))
3925 { // mobj must lower itself to fit
3926 goto pushline;
3927 }
3928 if (thing->flags2 & MF2_FLY)
3929 {
3930 if (thing->z + thing->height > tmceilingz)
3931 {
3932 thing->momz = -8 * FRACUNIT;
3933 goto pushline;
3934 }
3935 else if (thing->z < tmfloorz
3936 && tmfloorz - tmdropoffz > 24 * FRACUNIT)
3937 {
3938 thing->momz = 8 * FRACUNIT;
3939 goto pushline;
3940 }
3941 }
3942 if (!(thing->flags & MF_TELEPORT)
3943 // The Minotaur floor fire (HEXEN_MT_MNTRFX2) can step up any amount
3944 && thing->type != HEXEN_MT_MNTRFX2 && thing->type != HEXEN_MT_LIGHTNING_FLOOR
3945 && tmfloorz - thing->z > 24 * FRACUNIT)
3946 {
3947 goto pushline;
3948 }
3949 if (!(thing->flags & (MF_DROPOFF | MF_FLOAT)) &&
3950 (tmfloorz - tmdropoffz > 24 * FRACUNIT) &&
3951 !(thing->flags2 & MF2_BLASTED))
3952 { // Can't move over a dropoff unless it's been blasted
3953 return (false);
3954 }
3955 if (thing->flags2 & MF2_CANTLEAVEFLOORPIC
3956 && (tmfloorpic != thing->subsector->sector->floorpic
3957 || tmfloorz - thing->z != 0))
3958 { // must stay within a sector of a certain floor type
3959 return false;
3960 }
3961 }
3962
3963 //
3964 // the move is ok, so link the thing into its new position
3965 //
3966 P_UnsetThingPosition(thing);
3967
3968 oldx = thing->x;
3969 oldy = thing->y;
3970 thing->floorz = tmfloorz;
3971 thing->ceilingz = tmceilingz;
3972 thing->floorpic = tmfloorpic;
3973 thing->x = x;
3974 thing->y = y;
3975
3976 P_SetThingPosition(thing);
3977
3978 if (thing->flags2 & MF2_FOOTCLIP)
3979 {
3980 if (thing->z == thing->subsector->sector->floorheight
3981 && P_GetThingFloorType(thing) >= FLOOR_LIQUID)
3982 {
3983 thing->floorclip = 10 * FRACUNIT;
3984 }
3985 else
3986 {
3987 thing->floorclip = 0;
3988 }
3989 }
3990
3991 //
3992 // if any special lines were hit, do the effect
3993 //
3994 if (!(thing->flags & (MF_TELEPORT | MF_NOCLIP)))
3995 {
3996 while (numspechit > 0)
3997 {
3998 numspechit--;
3999 // see if the line was crossed
4000 ld = spechit[numspechit];
4001 side = P_PointOnLineSide(thing->x, thing->y, ld);
4002 oldside = P_PointOnLineSide(oldx, oldy, ld);
4003 if (side != oldside)
4004 {
4005 if (ld->special)
4006 {
4007 map_format.cross_special_line(ld, oldside, thing, false);
4008 }
4009 }
4010 }
4011 }
4012 return true;
4013
4014 pushline:
4015 if (!(thing->flags & (MF_TELEPORT | MF_NOCLIP)))
4016 {
4017 int numSpecHitTemp;
4018
4019 if (tmthing->flags2 & MF2_BLASTED)
4020 {
4021 P_DamageMobj(tmthing, NULL, NULL, tmthing->info->mass >> 5);
4022 }
4023 numSpecHitTemp = numspechit;
4024 while (numSpecHitTemp > 0)
4025 {
4026 numSpecHitTemp--;
4027 // see if the line was crossed
4028 ld = spechit[numSpecHitTemp];
4029 side = P_PointOnLineSide(thing->x, thing->y, ld);
4030 CheckForPushSpecial(ld, side, thing);
4031 }
4032 }
4033 return false;
4034 }
4035
4036 #define USE_PUZZLE_ITEM_SPECIAL 129
4037
4038 static mobj_t *PuzzleItemUser;
4039 static int PuzzleItemType;
4040 static dboolean PuzzleActivated;
4041
4042 #include "hexen/p_acs.h"
4043
4044 dboolean PTR_PuzzleItemTraverse(intercept_t * in)
4045 {
4046 mobj_t *mobj;
4047 byte args[3];
4048 int sound;
4049
4050 if (in->isaline)
4051 { // Check line
4052 if (in->d.line->special != USE_PUZZLE_ITEM_SPECIAL)
4053 {
4054 P_LineOpening(in->d.line, NULL);
4055 if (line_opening.range <= 0)
4056 {
4057 sound = hexen_sfx_None;
4058 if (PuzzleItemUser->player)
4059 {
4060 switch (PuzzleItemUser->player->pclass)
4061 {
4062 case PCLASS_FIGHTER:
4063 sound = hexen_sfx_puzzle_fail_fighter;
4064 break;
4065 case PCLASS_CLERIC:
4066 sound = hexen_sfx_puzzle_fail_cleric;
4067 break;
4068 case PCLASS_MAGE:
4069 sound = hexen_sfx_puzzle_fail_mage;
4070 break;
4071 default:
4072 sound = hexen_sfx_None;
4073 break;
4074 }
4075 }
4076 S_StartMobjSound(PuzzleItemUser, sound);
4077 return false; // can't use through a wall
4078 }
4079 return true; // Continue searching
4080 }
4081 if (P_PointOnLineSide(PuzzleItemUser->x, PuzzleItemUser->y,
4082 in->d.line) == 1)
4083 { // Don't use back sides
4084 return false;
4085 }
4086 if (PuzzleItemType != in->d.line->special_args[0])
4087 { // Item type doesn't match
4088 return false;
4089 }
4090
4091 // Construct an args[] array that would contain the values from
4092 // the line that would be passed by Vanilla Hexen.
4093 args[0] = in->d.line->special_args[2];
4094 args[1] = in->d.line->special_args[3];
4095 args[2] = in->d.line->special_args[4];
4096
4097 P_StartACS(in->d.line->special_args[1], 0, args, PuzzleItemUser, in->d.line, 0);
4098 in->d.line->special = 0;
4099 PuzzleActivated = true;
4100 return false; // Stop searching
4101 }
4102 // Check thing
4103 mobj = in->d.thing;
4104 if (mobj->special != USE_PUZZLE_ITEM_SPECIAL)
4105 { // Wrong special
4106 return true;
4107 }
4108 if (PuzzleItemType != mobj->special_args[0])
4109 { // Item type doesn't match
4110 return true;
4111 }
4112
4113 args[0] = mobj->special_args[2];
4114 args[1] = mobj->special_args[3];
4115 args[2] = mobj->special_args[4];
4116
4117 P_StartACS(mobj->special_args[1], 0, args, PuzzleItemUser, NULL, 0);
4118 mobj->special = 0;
4119 PuzzleActivated = true;
4120 return false; // Stop searching
4121 }
4122
4123 dboolean P_UsePuzzleItem(player_t * player, int itemType)
4124 {
4125 int angle;
4126 fixed_t x1, y1, x2, y2;
4127
4128 PuzzleItemType = itemType;
4129 PuzzleItemUser = player->mo;
4130 PuzzleActivated = false;
4131 angle = player->mo->angle >> ANGLETOFINESHIFT;
4132 x1 = player->mo->x;
4133 y1 = player->mo->y;
4134 x2 = x1 + (USERANGE >> FRACBITS) * finecosine[angle];
4135 y2 = y1 + (USERANGE >> FRACBITS) * finesine[angle];
4136 P_PathTraverse(x1, y1, x2, y2, PT_ADDLINES | PT_ADDTHINGS,
4137 PTR_PuzzleItemTraverse);
4138 return PuzzleActivated;
4139 }