-
Notifications
You must be signed in to change notification settings - Fork 88
/
p_map.c
2867 lines (2326 loc) · 79.1 KB
/
p_map.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Emacs style mode select -*- C++ -*-
*-----------------------------------------------------------------------------
*
*
* PrBoom: a Doom port merged with LxDoom and LSDLDoom
* based on BOOM, a modified and improved DOOM engine
* Copyright (C) 1999 by
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
* Copyright (C) 1999-2004 by
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
* Copyright 2005, 2006 by
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* DESCRIPTION:
* Movement, collision handling.
* Shooting and aiming.
*
*-----------------------------------------------------------------------------*/
#include "doomstat.h"
#include "r_main.h"
#include "p_mobj.h"
#include "p_maputl.h"
#include "p_map.h"
#include "p_setup.h"
#include "p_spec.h"
#include "s_sound.h"
#include "sounds.h"
#include "p_inter.h"
#include "m_random.h"
#include "m_bbox.h"
#include "lprintf.h"
#include "m_argv.h"
#include "g_game.h"
#include "g_overflow.h"
#include "hu_tracers.h"
#include "e6y.h"//e6y
#include "dsda.h"
#include "heretic/def.h"
static mobj_t *tmthing;
static fixed_t tmx;
static fixed_t tmy;
static int pe_x; // Pain Elemental position for Lost Soul checks // phares
static int pe_y; // Pain Elemental position for Lost Soul checks // phares
static int ls_x; // Lost Soul position for Lost Soul checks // phares
static int ls_y; // Lost Soul position for Lost Soul checks // phares
//
// SECTOR HEIGHT CHANGING
// After modifying a sectors floor or ceiling height,
// call this routine to adjust the positions
// of all things that touch the sector.
//
// If anything doesn't fit anymore, true will be returned.
// If crunch is true, they will take damage
// as they are being crushed.
// If Crunch is false, you should set the sector height back
// the way it was and call P_ChangeSector again
// to undo the changes.
//
static dboolean crushchange, nofit;
// If "floatok" true, move would be ok
// if within "tmfloorz - tmceilingz".
dboolean floatok;
/* killough 11/98: if "felldown" true, object was pushed down ledge */
dboolean felldown;
// The tm* items are used to hold information globally, usually for
// line or object intersection checking
fixed_t tmbbox[4]; // bounding box for line intersection checks
fixed_t tmfloorz; // floor you'd hit if free to fall
fixed_t tmceilingz; // ceiling of sector you're in
fixed_t tmdropoffz; // dropoff on other side of line you're crossing
// keep track of the line that lowers the ceiling,
// so missiles don't explode against sky hack walls
line_t *ceilingline;
line_t *blockline; /* killough 8/11/98: blocking linedef */
line_t *floorline; /* killough 8/1/98: Highest touched floor */
static int tmunstuck; /* killough 8/1/98: whether to allow unsticking */
// keep track of special lines as they are hit,
// but don't process them until the move is proven valid
// 1/11/98 killough: removed limit on special lines crossed
line_t **spechit; // new code -- killough
static int spechit_max; // killough
int numspechit;
// Temporary holder for thing_sectorlist threads
msecnode_t* sector_list = NULL; // phares 3/16/98
//
// TELEPORT MOVE
//
//
// PIT_StompThing
//
static dboolean telefrag; /* killough 8/9/98: whether to telefrag at exit */
dboolean PIT_StompThing (mobj_t* thing)
{
fixed_t blockdist;
// phares 9/10/98: moved this self-check to start of routine
// don't clip against self
if (thing == tmthing)
return true;
if (!(thing->flags & MF_SHOOTABLE)) // Can't shoot it? Can't stomp it!
return true;
blockdist = thing->radius + tmthing->radius;
if (D_abs(thing->x - tmx) >= blockdist || D_abs(thing->y - tmy) >= blockdist)
return true; // didn't hit it
// monsters don't stomp things except on boss level
if (!telefrag && !(tmthing->flags2 & MF2_TELESTOMP)) // killough 8/9/98: make consistent across all levels
return false;
P_DamageMobj (thing, tmthing, tmthing, 10000); // Stomp!
return true;
}
/*
* killough 8/28/98:
*
* P_GetFriction()
*
* Returns the friction associated with a particular mobj.
*/
int P_GetFriction(const mobj_t *mo, int *frictionfactor)
{
int friction = ORIG_FRICTION;
int movefactor = ORIG_FRICTION_FACTOR;
const msecnode_t *m;
const sector_t *sec;
/* Assign the friction value to objects on the floor, non-floating,
* and clipped. Normally the object's friction value is kept at
* ORIG_FRICTION and this thinker changes it for icy or muddy floors.
*
* When the object is straddling sectors with the same
* floorheight that have different frictions, use the lowest
* friction value (muddy has precedence over icy).
*/
if (mo->flags & MF_FLY)
{
friction = FRICTION_FLY;
}
else
{
if (!(mo->flags & (MF_NOCLIP|MF_NOGRAVITY))
&& (mbf_features || (mo->player && !compatibility)) &&
variable_friction)
for (m = mo->touching_sectorlist; m; m = m->m_tnext)
if ((sec = m->m_sector)->special & FRICTION_MASK &&
(sec->friction < friction || friction == ORIG_FRICTION) &&
(mo->z <= sec->floorheight ||
(sec->heightsec != -1 &&
mo->z <= sectors[sec->heightsec].floorheight &&
mbf_features)))
friction = sec->friction, movefactor = sec->movefactor;
}
if (frictionfactor)
*frictionfactor = movefactor;
return friction;
}
/* phares 3/19/98
* P_GetMoveFactor() returns the value by which the x,y
* movements are multiplied to add to player movement.
*
* killough 8/28/98: rewritten
*/
int P_GetMoveFactor(mobj_t *mo, int *frictionp)
{
int movefactor, friction;
//e6y
if (!mbf_features && !prboom_comp[PC_PRBOOM_FRICTION].state)
{
int momentum;
movefactor = ORIG_FRICTION_FACTOR;
if (!compatibility && variable_friction &&
!(mo->flags & (MF_NOGRAVITY | MF_NOCLIP)))
{
friction = mo->friction;
if (friction == ORIG_FRICTION) // normal floor
;
else if (friction > ORIG_FRICTION) // ice
{
movefactor = mo->movefactor;
((mobj_t*)mo)->movefactor = ORIG_FRICTION_FACTOR; // reset
}
else // sludge
{
// phares 3/11/98: you start off slowly, then increase as
// you get better footing
momentum = (P_AproxDistance(mo->momx,mo->momy));
movefactor = mo->movefactor;
if (momentum > MORE_FRICTION_MOMENTUM<<2)
movefactor <<= 3;
else if (momentum > MORE_FRICTION_MOMENTUM<<1)
movefactor <<= 2;
else if (momentum > MORE_FRICTION_MOMENTUM)
movefactor <<= 1;
((mobj_t*)mo)->movefactor = ORIG_FRICTION_FACTOR; // reset
}
} // ^
return(movefactor); // |
}
// If the floor is icy or muddy, it's harder to get moving. This is where
// the different friction factors are applied to 'trying to move'. In
// p_mobj.c, the friction factors are applied as you coast and slow down.
if ((friction = P_GetFriction(mo, &movefactor)) < ORIG_FRICTION)
{
// phares 3/11/98: you start off slowly, then increase as
// you get better footing
int momentum = P_AproxDistance(mo->momx,mo->momy);
if (momentum > MORE_FRICTION_MOMENTUM<<2)
movefactor <<= 3;
else if (momentum > MORE_FRICTION_MOMENTUM<<1)
movefactor <<= 2;
else if (momentum > MORE_FRICTION_MOMENTUM)
movefactor <<= 1;
}
if (frictionp)
*frictionp = friction;
return movefactor;
}
//
// P_TeleportMove
//
dboolean P_TeleportMove (mobj_t* thing,fixed_t x,fixed_t y, dboolean boss)
{
int xl;
int xh;
int yl;
int yh;
int bx;
int by;
subsector_t* newsubsec;
/* killough 8/9/98: make telefragging more consistent, preserve compatibility */
telefrag = thing->player ||
(!comp[comp_telefrag] ? boss : (gamemap==30));
// kill anything occupying the position
tmthing = thing;
tmx = x;
tmy = y;
tmbbox[BOXTOP] = y + tmthing->radius;
tmbbox[BOXBOTTOM] = y - tmthing->radius;
tmbbox[BOXRIGHT] = x + tmthing->radius;
tmbbox[BOXLEFT] = x - tmthing->radius;
newsubsec = R_PointInSubsector (x,y);
ceilingline = NULL;
// The base floor/ceiling is from the subsector
// that contains the point.
// Any contacted lines the step closer together
// will adjust them.
tmfloorz = tmdropoffz = newsubsec->sector->floorheight;
tmceilingz = newsubsec->sector->ceilingheight;
validcount++;
numspechit = 0;
// stomp on any things contacted
xl = P_GetSafeBlockX(tmbbox[BOXLEFT] - bmaporgx - MAXRADIUS);
xh = P_GetSafeBlockX(tmbbox[BOXRIGHT] - bmaporgx + MAXRADIUS);
yl = P_GetSafeBlockY(tmbbox[BOXBOTTOM] - bmaporgy - MAXRADIUS);
yh = P_GetSafeBlockY(tmbbox[BOXTOP] - bmaporgy + MAXRADIUS);
for (bx=xl ; bx<=xh ; bx++)
for (by=yl ; by<=yh ; by++)
if (!P_BlockThingsIterator(bx,by,PIT_StompThing))
return false;
// the move is ok,
// so unlink from the old position & link into the new position
P_UnsetThingPosition (thing);
thing->floorz = tmfloorz;
thing->ceilingz = tmceilingz;
thing->dropoffz = tmdropoffz; // killough 11/98
thing->x = x;
thing->y = y;
P_SetThingPosition (thing);
thing->PrevX = x;
thing->PrevY = y;
thing->PrevZ = thing->floorz;
return true;
}
//
// MOVEMENT ITERATOR FUNCTIONS
//
// // phares
// PIT_CrossLine // |
// Checks to see if a PE->LS trajectory line crosses a blocking // V
// line. Returns false if it does.
//
// tmbbox holds the bounding box of the trajectory. If that box
// does not touch the bounding box of the line in question,
// then the trajectory is not blocked. If the PE is on one side
// of the line and the LS is on the other side, then the
// trajectory is blocked.
//
// Currently this assumes an infinite line, which is not quite
// correct. A more correct solution would be to check for an
// intersection of the trajectory and the line, but that takes
// longer and probably really isn't worth the effort.
//
static // killough 3/26/98: make static
dboolean PIT_CrossLine (line_t* ld)
{
if (!(ld->flags & ML_TWOSIDED) ||
(ld->flags & (ML_BLOCKING|ML_BLOCKMONSTERS)))
if (!(tmbbox[BOXLEFT] > ld->bbox[BOXRIGHT] ||
tmbbox[BOXRIGHT] < ld->bbox[BOXLEFT] ||
tmbbox[BOXTOP] < ld->bbox[BOXBOTTOM] ||
tmbbox[BOXBOTTOM] > ld->bbox[BOXTOP]))
if (P_PointOnLineSide(pe_x,pe_y,ld) != P_PointOnLineSide(ls_x,ls_y,ld))
return(false); // line blocks trajectory // ^
return(true); // line doesn't block trajectory // |
} // phares
/* killough 8/1/98: used to test intersection between thing and line
* assuming NO movement occurs -- used to avoid sticky situations.
*/
static int untouched(line_t *ld)
{
fixed_t x, y, tmbbox[4];
return
(tmbbox[BOXRIGHT] = (x=tmthing->x)+tmthing->radius) <= ld->bbox[BOXLEFT] ||
(tmbbox[BOXLEFT] = x-tmthing->radius) >= ld->bbox[BOXRIGHT] ||
(tmbbox[BOXTOP] = (y=tmthing->y)+tmthing->radius) <= ld->bbox[BOXBOTTOM] ||
(tmbbox[BOXBOTTOM] = y-tmthing->radius) >= ld->bbox[BOXTOP] ||
P_BoxOnLineSide(tmbbox, ld) != -1;
}
//
// PIT_CheckLine
// Adjusts tmfloorz and tmceilingz as lines are contacted
//
static // killough 3/26/98: make static
dboolean PIT_CheckLine (line_t* ld)
{
if (tmbbox[BOXRIGHT] <= ld->bbox[BOXLEFT]
|| tmbbox[BOXLEFT] >= ld->bbox[BOXRIGHT]
|| tmbbox[BOXTOP] <= ld->bbox[BOXBOTTOM]
|| tmbbox[BOXBOTTOM] >= ld->bbox[BOXTOP] )
return true; // didn't hit it
if (P_BoxOnLineSide(tmbbox, ld) != -1)
return true; // didn't hit it
// A line has been hit
// The moving thing's destination position will cross the given line.
// If this should not be allowed, return false.
// If the line is special, keep track of it
// to process later if the move is proven ok.
// NOTE: specials are NOT sorted by order,
// so two special lines that are only 8 pixels apart
// could be crossed in either order.
// killough 7/24/98: allow player to move out of 1s wall, to prevent sticking
if (!ld->backsector) // one sided line
{
if (heretic)
{
if (tmthing->flags & MF_MISSILE)
{ // Missiles can trigger impact specials
if (ld->special)
{
P_AppendSpecHit(ld);
}
}
}
blockline = ld;
return tmunstuck && !untouched(ld) &&
FixedMul(tmx-tmthing->x,ld->dy) > FixedMul(tmy-tmthing->y,ld->dx);
}
// killough 8/10/98: allow bouncing objects to pass through as missiles
if (!(tmthing->flags & (MF_MISSILE | MF_BOUNCES)))
{
// explicitly blocking everything
// or blocking player
if (ld->flags & ML_BLOCKING || (mbf21 && tmthing->player && ld->flags & ML_BLOCKPLAYERS))
return tmunstuck && !untouched(ld); // killough 8/1/98: allow escape
// killough 8/9/98: monster-blockers don't affect friends
if (
!(tmthing->flags & MF_FRIEND || tmthing->player) &&
(
ld->flags & ML_BLOCKMONSTERS ||
(mbf21 && ld->flags & ML_BLOCKLANDMONSTERS && !(tmthing->flags & MF_FLOAT))
) &&
tmthing->type != HERETIC_MT_POD
)
return false; // block monsters only
}
// set openrange, opentop, openbottom
// these define a 'window' from one sector to another across this line
P_LineOpening (ld);
// adjust floor & ceiling heights
if (opentop < tmceilingz)
{
tmceilingz = opentop;
ceilingline = ld;
blockline = ld;
}
if (openbottom > tmfloorz)
{
tmfloorz = openbottom;
floorline = ld; // killough 8/1/98: remember floor linedef
blockline = ld;
}
if (lowfloor < tmdropoffz)
tmdropoffz = lowfloor;
// if contacted a special line, add it to the list
CheckLinesCrossTracer(ld);//e6y
if (ld->special)
P_AppendSpecHit(ld);
return true;
}
//
// PIT_CheckThing
//
static dboolean P_ProjectileImmune(mobj_t *target, mobj_t *source)
{
return
( // PG_GROUPLESS means no immunity, even to own species
mobjinfo[target->type].projectile_group != PG_GROUPLESS ||
target == source
) &&
(
( // target type has default behaviour, and things are the same type
mobjinfo[target->type].projectile_group == PG_DEFAULT &&
source->type == target->type
) ||
( // target type has special behaviour, and things have the same group
mobjinfo[target->type].projectile_group != PG_DEFAULT &&
mobjinfo[target->type].projectile_group == mobjinfo[source->type].projectile_group
)
);
}
static dboolean PIT_CheckThing(mobj_t *thing) // killough 3/26/98: make static
{
fixed_t blockdist;
int damage;
// killough 11/98: add touchy things
if (!(thing->flags & (MF_SOLID|MF_SPECIAL|MF_SHOOTABLE|MF_TOUCHY)))
return true;
blockdist = thing->radius + tmthing->radius;
if (D_abs(thing->x - tmx) >= blockdist || D_abs(thing->y - tmy) >= blockdist)
return true; // didn't hit it
// killough 11/98:
//
// This test has less information content (it's almost always false), so it
// should not be moved up to first, as it adds more overhead than it removes.
// don't clip against self
if (thing == tmthing)
return true;
/* killough 11/98:
*
* TOUCHY flag, for mines or other objects which die on contact with solids.
* If a solid object of a different type comes in contact with a touchy
* thing, and the touchy thing is not the sole one moving relative to fixed
* surroundings such as walls, then the touchy thing dies immediately.
*/
if (thing->flags & MF_TOUCHY && // touchy object
tmthing->flags & MF_SOLID && // solid object touches it
thing->health > 0 && // touchy object is alive
(thing->intflags & MIF_ARMED || // Thing is an armed mine
sentient(thing)) && // ... or a sentient thing
(thing->type != tmthing->type || // only different species
thing->type == g_mt_player) && // ... or different players
thing->z + thing->height >= tmthing->z && // touches vertically
tmthing->z + tmthing->height >= thing->z &&
(thing->type ^ MT_PAIN) | // PEs and lost souls
(tmthing->type ^ MT_SKULL) && // are considered same
(thing->type ^ MT_SKULL) | // (but Barons & Knights
(tmthing->type ^ MT_PAIN)) // are intentionally not)
{
P_DamageMobj(thing, NULL, NULL, thing->health); // kill object
return true;
}
if (tmthing->flags2 & MF2_PASSMOBJ)
{ // check if a mobj passed over/under another object
if ((tmthing->type == HERETIC_MT_IMP || tmthing->type == HERETIC_MT_WIZARD)
&& (thing->type == HERETIC_MT_IMP || thing->type == HERETIC_MT_WIZARD))
{ // don't let imps/wizards fly over other imps/wizards
return false;
}
if (tmthing->z > thing->z + thing->height
&& !(thing->flags & MF_SPECIAL))
{
return (true);
}
else if (tmthing->z + tmthing->height < thing->z
&& !(thing->flags & MF_SPECIAL))
{ // under thing
return (true);
}
}
// check for skulls slamming into things
if (tmthing->flags & MF_SKULLFLY)
{
// A flying skull is smacking something.
// Determine damage amount, and the skull comes to a dead stop.
int new_state;
int damage = ((P_Random(pr_skullfly)%8)+1)*tmthing->info->damage;
P_DamageMobj (thing, tmthing, tmthing, damage);
tmthing->flags &= ~MF_SKULLFLY;
tmthing->momx = tmthing->momy = tmthing->momz = 0;
if (heretic)
new_state = tmthing->info->seestate;
else
new_state = tmthing->info->spawnstate;
P_SetMobjState (tmthing, new_state);
return false; // stop moving
}
// missiles can hit other things
// killough 8/10/98: bouncing non-solid things can hit other things too
if (tmthing->flags & MF_MISSILE ||
(tmthing->flags & MF_BOUNCES && !(tmthing->flags & MF_SOLID)))
{
// Check for passing through a ghost
if ((thing->flags & MF_SHADOW) && (tmthing->flags2 & MF2_THRUGHOST))
{
return (true);
}
// see if it went over / under
if (tmthing->z > thing->z + thing->height)
return true; // overhead
if (tmthing->z + tmthing->height < thing->z)
return true; // underneath
if (tmthing->target && P_ProjectileImmune(thing, tmthing->target))
{
if (thing == tmthing->target)
return true; // Don't hit self.
else
// e6y: Dehacked support - monsters infight
if (thing->type != g_mt_player && !monsters_infight) // Explode, but do no damage.
return false; // Let players missile other players.
}
// killough 8/10/98: if moving thing is not a missile, no damage
// is inflicted, and momentum is reduced if object hit is solid.
if (!(tmthing->flags & MF_MISSILE)) {
if (!(thing->flags & MF_SOLID))
{
return true;
}
else
{
tmthing->momx = -tmthing->momx;
tmthing->momy = -tmthing->momy;
if (!(tmthing->flags & MF_NOGRAVITY))
{
tmthing->momx >>= 2;
tmthing->momy >>= 2;
}
return false;
}
}
if (!(thing->flags & MF_SHOOTABLE))
return !(thing->flags & MF_SOLID); // didn't do any damage
if (tmthing->flags2 & MF2_RIP)
{
if (heretic)
{
if (!(thing->flags & MF_NOBLOOD))
{ // Ok to spawn some blood
P_RipperBlood(tmthing);
}
S_StartSound(tmthing, heretic_sfx_ripslop);
damage = ((P_Random(pr_heretic) & 3) + 2) * tmthing->damage;
}
else
{
damage = ((P_Random(pr_mbf21) & 3) + 2) * tmthing->info->damage;
if (!(thing->flags & MF_NOBLOOD))
P_SpawnBlood(tmthing->x, tmthing->y, tmthing->z, damage);
if (tmthing->info->ripsound)
S_StartSound(tmthing, tmthing->info->ripsound);
}
P_DamageMobj(thing, tmthing, tmthing->target, damage);
if (thing->flags2 & MF2_PUSHABLE && !(tmthing->flags2 & MF2_CANNOTPUSH))
{ // Push thing
thing->momx += tmthing->momx >> 2;
thing->momy += tmthing->momy >> 2;
}
numspechit = 0;
return (true);
}
// damage / explode
damage = heretic ? tmthing->damage : tmthing->info->damage;
damage = ((P_Random(pr_damage) % 8) + 1) * damage;
if (heretic && damage && !(thing->flags & MF_NOBLOOD) && P_Random(pr_heretic) < 192)
{
P_BloodSplatter(tmthing->x, tmthing->y, tmthing->z, thing);
}
if (!heretic || damage)
P_DamageMobj(thing, tmthing, tmthing->target, damage);
// don't traverse any more
return false;
}
if (thing->flags2 & MF2_PUSHABLE && !(tmthing->flags2 & MF2_CANNOTPUSH))
{ // Push thing
thing->momx += tmthing->momx >> 2;
thing->momy += tmthing->momy >> 2;
}
// check for special pickup
if (thing->flags & MF_SPECIAL)
{
uint_64_t solid = thing->flags & MF_SOLID;
if (tmthing->flags & MF_PICKUP)
P_TouchSpecialThing(thing, tmthing); // can remove thing
return !solid;
}
// RjY
// comperr_hangsolid, an attempt to handle blocking hanging bodies
// A solid hanging body will allow sufficiently small things underneath it.
if (comperr(comperr_hangsolid) &&
!((~thing->flags) & (MF_SOLID | MF_SPAWNCEILING)) // solid and hanging
// invert everything, then both bits should be clear
&& tmthing->z + tmthing->height <= thing->z) // head height <= base
// top of thing trying to move under the body <= bottom of body
{
tmceilingz = thing->z; // pretend ceiling height is at body's base
return true;
}
// killough 3/16/98: Allow non-solid moving objects to move through solid
// ones, by allowing the moving thing (tmthing) to move if it's non-solid,
// despite another solid thing being in the way.
// killough 4/11/98: Treat no-clipping things as not blocking
// ...but not in demo_compatibility mode
// e6y
// Correction of wrong return value with demo_compatibility.
// There is no more synch on http://www.doomworld.com/sda/dwdemo/w303-115.zip
// (with correction in setMobjInfoValue)
if (demo_compatibility && !prboom_comp[PC_TREAT_NO_CLIPPING_THINGS_AS_NOT_BLOCKING].state)
return !(thing->flags & MF_SOLID);
else
return !((thing->flags & MF_SOLID && !(thing->flags & MF_NOCLIP))
&& (tmthing->flags & MF_SOLID || demo_compatibility));
// return !(thing->flags & MF_SOLID); // old code -- killough
}
// This routine checks for Lost Souls trying to be spawned // phares
// across 1-sided lines, impassible lines, or "monsters can't // |
// cross" lines. Draw an imaginary line between the PE // V
// and the new Lost Soul spawn spot. If that line crosses
// a 'blocking' line, then disallow the spawn. Only search
// lines in the blocks of the blockmap where the bounding box
// of the trajectory line resides. Then check bounding box
// of the trajectory vs. the bounding box of each blocking
// line to see if the trajectory and the blocking line cross.
// Then check the PE and LS to see if they're on different
// sides of the blocking line. If so, return true, otherwise
// false.
dboolean Check_Sides(mobj_t* actor, int x, int y)
{
int bx,by,xl,xh,yl,yh;
pe_x = actor->x;
pe_y = actor->y;
ls_x = x;
ls_y = y;
// Here is the bounding box of the trajectory
tmbbox[BOXLEFT] = pe_x < x ? pe_x : x;
tmbbox[BOXRIGHT] = pe_x > x ? pe_x : x;
tmbbox[BOXTOP] = pe_y > y ? pe_y : y;
tmbbox[BOXBOTTOM] = pe_y < y ? pe_y : y;
// Determine which blocks to look in for blocking lines
xl = P_GetSafeBlockX(tmbbox[BOXLEFT] - bmaporgx);
xh = P_GetSafeBlockX(tmbbox[BOXRIGHT] - bmaporgx);
yl = P_GetSafeBlockY(tmbbox[BOXBOTTOM] - bmaporgy);
yh = P_GetSafeBlockY(tmbbox[BOXTOP] - bmaporgy);
// xl->xh, yl->yh determine the mapblock set to search
validcount++; // prevents checking same line twice
for (bx = xl ; bx <= xh ; bx++)
for (by = yl ; by <= yh ; by++)
if (!P_BlockLinesIterator(bx,by,PIT_CrossLine))
return true; // ^
return(false); // |
} // phares
//
// MOVEMENT CLIPPING
//
//
// P_CheckPosition
// This is purely informative, nothing is modified
// (except things picked up).
//
// in:
// a mobj_t (can be valid or invalid)
// a position to be checked
// (doesn't need to be related to the mobj_t->x,y)
//
// during:
// special things are touched if MF_PICKUP
// early out on solid lines?
//
// out:
// newsubsec
// floorz
// ceilingz
// tmdropoffz
// the lowest point contacted
// (monsters won't move to a dropoff)
// speciallines[]
// numspeciallines
//
dboolean P_CheckPosition (mobj_t* thing,fixed_t x,fixed_t y)
{
int xl;
int xh;
int yl;
int yh;
int bx;
int by;
subsector_t* newsubsec;
tmthing = thing;
tmx = x;
tmy = y;
tmbbox[BOXTOP] = y + tmthing->radius;
tmbbox[BOXBOTTOM] = y - tmthing->radius;
tmbbox[BOXRIGHT] = x + tmthing->radius;
tmbbox[BOXLEFT] = x - tmthing->radius;
newsubsec = R_PointInSubsector (x,y);
floorline = blockline = ceilingline = NULL; // killough 8/1/98
// Whether object can get out of a sticky situation:
tmunstuck = thing->player && /* only players */
thing->player->mo == thing && /* not voodoo dolls */
mbf_features; /* not under old demos */
// The base floor / ceiling is from the subsector
// that contains the point.
// Any contacted lines the step closer together
// will adjust them.
tmfloorz = tmdropoffz = newsubsec->sector->floorheight;
tmceilingz = newsubsec->sector->ceilingheight;
validcount++;
numspechit = 0;
if ( tmthing->flags & MF_NOCLIP )
return true;
// Check things first, possibly picking things up.
// The bounding box is extended by MAXRADIUS
// because mobj_ts are grouped into mapblocks
// based on their origin point, and can overlap
// into adjacent blocks by up to MAXRADIUS units.
xl = P_GetSafeBlockX(tmbbox[BOXLEFT] - bmaporgx - MAXRADIUS);
xh = P_GetSafeBlockX(tmbbox[BOXRIGHT] - bmaporgx + MAXRADIUS);
yl = P_GetSafeBlockY(tmbbox[BOXBOTTOM] - bmaporgy - MAXRADIUS);
yh = P_GetSafeBlockY(tmbbox[BOXTOP] - bmaporgy + MAXRADIUS);
for (bx=xl ; bx<=xh ; bx++)
for (by=yl ; by<=yh ; by++)
if (!P_BlockThingsIterator(bx,by,PIT_CheckThing))
return false;
// check lines
xl = P_GetSafeBlockX(tmbbox[BOXLEFT] - bmaporgx);
xh = P_GetSafeBlockX(tmbbox[BOXRIGHT] - bmaporgx);
yl = P_GetSafeBlockY(tmbbox[BOXBOTTOM] - bmaporgy);
yh = P_GetSafeBlockY(tmbbox[BOXTOP] - bmaporgy);
// heretic - this must be incremented before iterating over the lines
validcount++;
for (bx=xl ; bx<=xh ; bx++)
for (by=yl ; by<=yh ; by++)
if (!P_BlockLinesIterator (bx,by,PIT_CheckLine))
return false; // doesn't fit
ClearLinesCrossTracer();//e6y
return true;
}
//
// P_TryMove
// Attempt to move to a new position,
// crossing special lines unless MF_TELEPORT is set.
//
dboolean P_TryMove(mobj_t* thing,fixed_t x,fixed_t y,
dboolean dropoff) // killough 3/15/98: allow dropoff as option
{
fixed_t oldx;
fixed_t oldy;
felldown = floatok = false; // killough 11/98
if (!P_CheckPosition(thing, x, y))
{ // Solid wall or thing
CheckMissileImpact(thing);
return false;
}
if (!(thing->flags & MF_NOCLIP))
{
if (thing->flags & MF_FLY)
{
// When flying, slide up or down blocking lines until the actor
// is not blocked.
if (thing->z+thing->height > tmceilingz)
{
thing->momz = -8*FRACUNIT;
return false;
}
else if (thing->z < tmfloorz && tmfloorz-tmdropoffz > 24*FRACUNIT)
{
thing->momz = 8*FRACUNIT;
return false;
}
}
// killough 7/26/98: reformatted slightly
// killough 8/1/98: Possibly allow escape if otherwise stuck
if (
tmceilingz - tmfloorz < thing->height || // doesn't fit
// mobj must lower to fit
(
floatok = true,
!(thing->flags & MF_TELEPORT) &&
tmceilingz - thing->z < thing->height &&
!(thing->flags & MF_FLY) &&
!(thing->flags2 & MF2_FLY)
)
)
{
CheckMissileImpact(thing);
return tmunstuck
&& !(ceilingline && untouched(ceilingline))
&& !( floorline && untouched( floorline));
}
if (thing->flags2 & MF2_FLY)
{
if (thing->z + thing->height > tmceilingz)
{
thing->momz = -8 * FRACUNIT;
return false;
}
else if (thing->z < tmfloorz
&& tmfloorz - tmdropoffz > 24 * FRACUNIT)
{
thing->momz = 8 * FRACUNIT;
return false;
}
}
if (
!(thing->flags & MF_TELEPORT) &&