-
Notifications
You must be signed in to change notification settings - Fork 5
/
p_map.c
1485 lines (1134 loc) · 37.3 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
* Copyright 2023, 2024 by
* Frenkel Smeijers
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* DESCRIPTION:
* Movement, collision handling.
* Shooting and aiming.
*
*-----------------------------------------------------------------------------*/
#include "d_player.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 "p_user.h"
#include "m_random.h"
#include "i_system.h"
#include "globdata.h"
static mobj_t __far* tmthing;
static fixed_t tmx;
static fixed_t tmy;
// The tm* items are used to hold information globally, usually for
// line or object intersection checking
fixed_t _g_tmbbox[4]; // bounding box for line intersection checks
fixed_t _g_tmfloorz; // floor you'd hit if free to fall
fixed_t _g_tmceilingz; // ceiling of sector you're in
fixed_t _g_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
const line_t __far* _g_ceilingline;
static const line_t __far* blockline; /* blocking linedef */
static boolean 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 __far* _g_spechit[4];
int16_t _g_numspechit;
// Temporary holder for thing_sectorlist threads
static msecnode_t __far* _s_sector_list;
mobj_t __far* _g_linetarget; // who got hit (or NULL)
static mobj_t __far* shootthing;
// Height if not aiming up or down
static fixed_t shootz;
static int16_t la_damage;
static fixed_t attackrange;
// slopes to top and bottom of target
static fixed_t topslope;
static fixed_t bottomslope;
static mobj_t __far* bombsource;
static mobj_t __far* bombspot;
static int16_t bombdamage;
static mobj_t __far* usething;
static boolean telefrag; /* killough 8/9/98: whether to telefrag at exit */
// MAXRADIUS is for precalculated sector block boxes
#define MAXRADIUS (32*FRACUNIT)
boolean P_IsAttackRangeMeleeRange(void)
{
return attackrange == MELEERANGE;
}
//
// TELEPORT MOVE
//
//
// PIT_StompThing
//
static boolean PIT_StompThing(mobj_t __far* 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) // killough 8/9/98: make consistent across all levels
return false;
P_DamageMobj (thing, tmthing, tmthing, 10000); // Stomp!
return true;
}
//
// P_TeleportMove
//
boolean P_TeleportMove(mobj_t __far* thing, fixed_t x, fixed_t y, boolean boss)
{
int16_t xl;
int16_t xh;
int16_t yl;
int16_t yh;
int16_t bx;
int16_t by;
subsector_t __far* newsubsec;
/* killough 8/9/98: make telefragging more consistent, preserve compatibility */
telefrag = P_MobjIsPlayer(thing) || boss;
// kill anything occupying the position
tmthing = thing;
tmx = x;
tmy = y;
_g_tmbbox[BOXTOP] = y + tmthing->radius;
_g_tmbbox[BOXBOTTOM] = y - tmthing->radius;
_g_tmbbox[BOXRIGHT] = x + tmthing->radius;
_g_tmbbox[BOXLEFT] = x - tmthing->radius;
newsubsec = R_PointInSubsector (x,y);
_g_ceilingline = NULL;
// The base floor/ceiling is from the subsector
// that contains the point.
// Any contacted lines the step closer together
// will adjust them.
_g_tmfloorz = _g_tmdropoffz = newsubsec->sector->floorheight;
_g_tmceilingz = newsubsec->sector->ceilingheight;
validcount++;
_g_numspechit = 0;
// stomp on any things contacted
xl = (_g_tmbbox[BOXLEFT] - _g_bmaporgx - MAXRADIUS)>>MAPBLOCKSHIFT;
xh = (_g_tmbbox[BOXRIGHT] - _g_bmaporgx + MAXRADIUS)>>MAPBLOCKSHIFT;
yl = (_g_tmbbox[BOXBOTTOM] - _g_bmaporgy - MAXRADIUS)>>MAPBLOCKSHIFT;
yh = (_g_tmbbox[BOXTOP] - _g_bmaporgy + MAXRADIUS)>>MAPBLOCKSHIFT;
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 = _g_tmfloorz;
thing->ceilingz = _g_tmceilingz;
thing->dropoffz = _g_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
//
/* killough 8/1/98: used to test intersection between thing and line
* assuming NO movement occurs -- used to avoid sticky situations.
*/
static boolean untouched(const line_t __far* ld)
{
fixed_t x, y, tmbbox[4];
return
(tmbbox[BOXRIGHT] = (x=tmthing->x)+tmthing->radius) <= (fixed_t)ld->bbox[BOXLEFT]<<FRACBITS ||
(tmbbox[BOXLEFT] = x-tmthing->radius) >= (fixed_t)ld->bbox[BOXRIGHT]<<FRACBITS ||
(tmbbox[BOXTOP] = (y=tmthing->y)+tmthing->radius) <= (fixed_t)ld->bbox[BOXBOTTOM]<<FRACBITS ||
(tmbbox[BOXBOTTOM] = y-tmthing->radius) >= (fixed_t)ld->bbox[BOXTOP]<<FRACBITS ||
P_BoxOnLineSide(tmbbox, ld) != -1;
}
//
// PIT_CheckLine
// Adjusts tmfloorz and tmceilingz as lines are contacted
//
static boolean PIT_CheckLine (line_t __far* ld)
{
if (_g_tmbbox[BOXRIGHT] <= (fixed_t)ld->bbox[BOXLEFT] << FRACBITS
|| _g_tmbbox[BOXLEFT] >= (fixed_t)ld->bbox[BOXRIGHT] << FRACBITS
|| _g_tmbbox[BOXTOP] <= (fixed_t)ld->bbox[BOXBOTTOM] << FRACBITS
|| _g_tmbbox[BOXBOTTOM] >= (fixed_t)ld->bbox[BOXTOP] << FRACBITS)
return true; // didn't hit it
if (P_BoxOnLineSide(_g_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 (!LN_BACKSECTOR(ld)) // one sided line
{
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)))
{
if (ld->flags & ML_BLOCKING) // explicitly blocking everything
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 || P_MobjIsPlayer(tmthing))
&& ld->flags & ML_BLOCKMONSTERS)
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 (_g_opentop < _g_tmceilingz)
{
_g_tmceilingz = _g_opentop;
_g_ceilingline = ld;
blockline = ld;
}
if (_g_openbottom > _g_tmfloorz)
{
_g_tmfloorz = _g_openbottom;
blockline = ld;
}
if (_g_lowfloor < _g_tmdropoffz)
_g_tmdropoffz = _g_lowfloor;
// if contacted a special line, add it to the list
if (LN_SPECIAL(ld))
{
// 1/11/98 killough: remove limit on lines hit, by array doubling
if (_g_numspechit < 4)
{
_g_spechit[_g_numspechit++] = ld;
}
}
return true;
}
//
// PIT_CheckThing
//
static boolean PIT_CheckThing(mobj_t __far* thing)
{
fixed_t blockdist;
int16_t damage;
// killough 11/98: add touchy things
if (!(thing->flags & (MF_SOLID|MF_SPECIAL|MF_SHOOTABLE)))
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;
// missiles can hit other things
// killough 8/10/98: bouncing non-solid things can hit other things too
if (tmthing->flags & MF_MISSILE)
{
// 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 && (tmthing->target->type == thing->type))
{
if (thing == tmthing->target)
return true; // Don't hit same species as originator.
else
if (thing->type != MT_PLAYER) // 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
// damage / explode
damage = ((P_Random()%8)+1)*mobjinfo[tmthing->type].damage;
P_DamageMobj (thing, tmthing, tmthing->target, damage);
// don't traverse any more
return false;
}
// check for special pickup
if (thing->flags & MF_SPECIAL)
{
boolean solid = thing->flags & MF_SOLID;
if (tmthing->flags & MF_PICKUP)
P_TouchSpecialThing(thing, tmthing); // can remove thing
return !solid;
}
return !(thing->flags & MF_SOLID);
}
//
// 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
//
boolean P_CheckPosition(mobj_t __far* thing, fixed_t x, fixed_t y)
{
int16_t xl;
int16_t xh;
int16_t yl;
int16_t yh;
int16_t bx;
int16_t by;
subsector_t __far* newsubsec;
tmthing = thing;
tmx = x;
tmy = y;
_g_tmbbox[BOXTOP] = y + tmthing->radius;
_g_tmbbox[BOXBOTTOM] = y - tmthing->radius;
_g_tmbbox[BOXRIGHT] = x + tmthing->radius;
_g_tmbbox[BOXLEFT] = x - tmthing->radius;
newsubsec = R_PointInSubsector (x,y);
blockline = _g_ceilingline = NULL;
// Whether object can get out of a sticky situation:
tmunstuck = P_MobjIsPlayer(thing) && /* only players */
P_MobjIsPlayer(thing)->mo == thing; /* 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.
_g_tmfloorz = _g_tmdropoffz = newsubsec->sector->floorheight;
_g_tmceilingz = newsubsec->sector->ceilingheight;
validcount++;
_g_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 = (_g_tmbbox[BOXLEFT] - _g_bmaporgx - MAXRADIUS)>>MAPBLOCKSHIFT;
xh = (_g_tmbbox[BOXRIGHT] - _g_bmaporgx + MAXRADIUS)>>MAPBLOCKSHIFT;
yl = (_g_tmbbox[BOXBOTTOM] - _g_bmaporgy - MAXRADIUS)>>MAPBLOCKSHIFT;
yh = (_g_tmbbox[BOXTOP] - _g_bmaporgy + MAXRADIUS)>>MAPBLOCKSHIFT;
for (bx=xl ; bx<=xh ; bx++)
for (by=yl ; by<=yh ; by++)
if (!P_BlockThingsIterator(bx,by,PIT_CheckThing))
return false;
// check lines
xl = (_g_tmbbox[BOXLEFT] - _g_bmaporgx)>>MAPBLOCKSHIFT;
xh = (_g_tmbbox[BOXRIGHT] - _g_bmaporgx)>>MAPBLOCKSHIFT;
yl = (_g_tmbbox[BOXBOTTOM] - _g_bmaporgy)>>MAPBLOCKSHIFT;
yh = (_g_tmbbox[BOXTOP] - _g_bmaporgy)>>MAPBLOCKSHIFT;
for (bx=xl ; bx<=xh ; bx++)
for (by=yl ; by<=yh ; by++)
if (!P_BlockLinesIterator (bx,by,PIT_CheckLine))
return false; // doesn't fit
return true;
}
//
// P_CrossSpecialLine - Walkover Trigger Dispatcher
//
// Called every time a thing origin is about
// to cross a line with a non 0 special, whether a walkover type or not.
//
// jff 02/12/98 all W1 lines were fixed to check the result from the EV_
// function before clearing the special. This avoids losing the function
// of the line, should the sector already be active when the line is
// crossed. Change is qualified by demo_compatibility.
//
// CPhipps - take a line_t pointer instead of a line number, as in MBF
static void P_CrossSpecialLine(line_t __far* line, int16_t side, mobj_t __far* thing)
{
boolean ok;
// Things that should never trigger lines
if (!P_MobjIsPlayer(thing))
{
// Things that should NOT trigger specials...
switch(thing->type)
{
case MT_ROCKET:
case MT_TROOPSHOT:
case MT_BRUISERSHOT:
return;
default: break;
}
}
if (!P_MobjIsPlayer(thing))
{
ok = false;
switch(LN_SPECIAL(line))
{
case 97: // teleport retrigger
case 88: // plat down-wait-up-stay retrigger
ok = true;
break;
}
if (!ok)
return;
}
if (!P_CheckTag(line)) //jff 2/27/98 disallow zero tag on some types
return;
// Dispatch on the line special value to the line's action routine
// If a once only function, and successful, clear the line special
switch (LN_SPECIAL(line))
{
// Regular walk once triggers
case 2:
// Open Door
if (EV_DoDoor(line,dopen))
LN_SPECIAL(line) = 0;
break;
case 5:
// Raise Floor
if (EV_DoFloor(line,raiseFloor))
LN_SPECIAL(line) = 0;
break;
case 8:
// Build Stairs
if (EV_BuildStairs(line))
LN_SPECIAL(line) = 0;
break;
case 16:
// Close Door 30
if (EV_DoDoor(line,close30ThenOpen))
LN_SPECIAL(line) = 0;
break;
case 22:
// Raise floor to nearest height and change texture
if (EV_DoPlat(line,raiseToNearestAndChange))
LN_SPECIAL(line) = 0;
break;
case 35:
// Lights Very Dark
EV_LightTurnOn(line,35);
LN_SPECIAL(line) = 0;
break;
case 36:
// Lower Floor (TURBO)
if (EV_DoFloor(line,turboLower))
LN_SPECIAL(line) = 0;
break;
// Regular walk many retriggerable
case 76:
// Close Door 30
EV_DoDoor(line,close30ThenOpen);
break;
case 82:
// Lower Floor To Lowest
EV_DoFloor( line, lowerFloorToLowest );
break;
case 86:
// Open Door
EV_DoDoor(line,dopen);
break;
case 88:
// PlatDownWaitUp
EV_DoPlat(line,downWaitUpStay);
break;
case 90:
// Raise Door
EV_DoDoor(line,normal);
break;
case 91:
// Raise Floor
EV_DoFloor(line,raiseFloor);
break;
case 97:
// TELEPORT!
EV_Teleport( line, side, thing );
break;
case 98:
// Lower Floor (TURBO)
EV_DoFloor(line,turboLower);
break;
}
}
//
// P_TryMove
// Attempt to move to a new position,
// crossing special lines.
//
boolean P_TryMove(mobj_t __far* thing, fixed_t x, fixed_t y)
{
fixed_t oldx;
fixed_t oldy;
if (!P_CheckPosition (thing, x, y))
return false; // solid wall or thing
if ( !(thing->flags & MF_NOCLIP) )
{
if (_g_tmceilingz - _g_tmfloorz < thing->height)
return false; // doesn't fit
if (_g_tmceilingz - thing->z < thing->height)
return false; // mobj must lower itself to fit
if (_g_tmfloorz - thing->z > 24*FRACUNIT )
return false; // too big a step up
if ( !(thing->flags & MF_DROPOFF)
&& _g_tmfloorz - _g_tmdropoffz > 24*FRACUNIT )
return false; // don't stand over a dropoff
}
// the move is ok,
// so unlink from the old position and link into the new position
P_UnsetThingPosition (thing);
oldx = thing->x;
oldy = thing->y;
thing->floorz = _g_tmfloorz;
thing->ceilingz = _g_tmceilingz;
thing->dropoffz = _g_tmdropoffz; // killough 11/98: keep track of dropoffs
thing->x = x;
thing->y = y;
P_SetThingPosition (thing);
// if any special lines were hit, do the effect
if (!(thing->flags & MF_NOCLIP))
while (_g_numspechit--)
if (LN_SPECIAL(_g_spechit[_g_numspechit])) // see if the line was crossed
{
int16_t oldside;
if ((oldside = P_PointOnLineSide(oldx, oldy, _g_spechit[_g_numspechit])) !=
P_PointOnLineSide(thing->x, thing->y, _g_spechit[_g_numspechit]))
P_CrossSpecialLine(_g_spechit[_g_numspechit], oldside, thing);
}
return true;
}
// for more intelligent autoaiming
static uint32_t aim_flags_mask;
static fixed_t aimslope;
//
// PTR_AimTraverse
// Sets linetaget and aimslope when a target is aimed at.
//
static boolean PTR_AimTraverse (intercept_t* in)
{
const line_t __far* li;
mobj_t __far* th;
fixed_t slope;
fixed_t thingtopslope;
fixed_t thingbottomslope;
fixed_t dist;
if (in->isaline)
{
li = in->d.line;
if ( !(li->flags & ML_TWOSIDED) )
return false; // stop
// Crosses a two sided line.
// A two sided line will restrict
// the possible target ranges.
P_LineOpening (li);
if (_g_openbottom >= _g_opentop)
return false; // stop
dist = FixedMul(attackrange, in->frac);
if (LN_FRONTSECTOR(li)->floorheight != LN_BACKSECTOR(li)->floorheight)
{
slope = dist != 0 ? FixedApproxDiv(_g_openbottom - shootz, dist) : INT32_MAX;
if (slope > bottomslope)
bottomslope = slope;
}
if (LN_FRONTSECTOR(li)->ceilingheight != LN_BACKSECTOR(li)->ceilingheight)
{
slope = dist != 0 ? FixedApproxDiv(_g_opentop - shootz, dist) : INT32_MAX;
if (slope < topslope)
topslope = slope;
}
if (topslope <= bottomslope)
return false; // stop
return true; // shot continues
}
// shoot a thing
th = in->d.thing;
if (th == shootthing)
return true; // can't shoot self
if (!(th->flags&MF_SHOOTABLE))
return true; // corpse or something
/* killough 7/19/98, 8/2/98:
* friends don't aim at friends (except players), at least not first
*/
if (th->flags & shootthing->flags & aim_flags_mask && !P_MobjIsPlayer(th))
return true;
// check angles to see if the thing can be aimed at
dist = FixedMul (attackrange, in->frac);
thingtopslope = dist != 0 ? FixedApproxDiv(th->z + th->height - shootz, dist) : INT32_MAX;
if (thingtopslope < bottomslope)
return true; // shot over the thing
thingbottomslope = dist != 0 ? FixedApproxDiv(th->z - shootz, dist) : INT32_MAX;
if (thingbottomslope > topslope)
return true; // shot under the thing
// this thing can be hit!
if (thingtopslope > topslope)
thingtopslope = topslope;
if (thingbottomslope < bottomslope)
thingbottomslope = bottomslope;
aimslope = (thingtopslope + thingbottomslope) / 2;
_g_linetarget = th;
return false; // don't go any farther
}
//
// P_ShootSpecialLine - Gun trigger special dispatcher
//
// Called when a thing shoots a special line with bullet, shell, saw, or fist.
//
// jff 02/12/98 all G1 lines were fixed to check the result from the EV_
// function before clearing the special. This avoids losing the function
// of the line, should the sector already be in motion when the line is
// impacted. Change is qualified by demo_compatibility.
//
static void P_ShootSpecialLine(mobj_t __far* thing, line_t __far* line)
{
// Impacts that other things can activate.
if (!P_MobjIsPlayer(thing))
{
boolean ok = false;
switch(LN_SPECIAL(line))
{
case 46:
// 46 GR Open door on impact weapon is monster activatable
ok = true;
break;
}
if (!ok)
return;
}
if (!P_CheckTag(line)) //jff 2/27/98 disallow zero tag on some types
return;
switch(LN_SPECIAL(line))
{
case 46:
// 46 GR open door, stay open
EV_DoDoor(line,dopen);
P_ChangeSwitchTexture(line,true);
break;
}
}
static fixed_t FixedMul3(fixed_t a, fixed_t b, fixed_t c)
{
if (a == 0)
return 0;
fixed_t bc = FixedMul(c, b);
return FixedMul(bc, a);
}
//
// PTR_ShootTraverse
//
static boolean PTR_ShootTraverse (intercept_t* in)
{
fixed_t x;
fixed_t y;
fixed_t z;
fixed_t frac;
mobj_t __far* th;
fixed_t dist;
fixed_t thingtopslope;
fixed_t thingbottomslope;
if (in->isaline)
{
line_t __far* li = in->d.line;
if (LN_SPECIAL(li))
P_ShootSpecialLine (shootthing, li);
if (li->flags & ML_TWOSIDED)
{ // crosses a two sided (really 2s) line
P_LineOpening (li);
fixed_t t = FixedMul3(aimslope, in->frac, attackrange) + shootz;
if ((LN_FRONTSECTOR(li)->floorheight == LN_BACKSECTOR(li)->floorheight || _g_openbottom <= t) &&
(LN_FRONTSECTOR(li)->ceilingheight == LN_BACKSECTOR(li)->ceilingheight || _g_opentop >= t))
return true; // shot continues
}
// hit line
// position a bit closer
frac = in->frac - 4 * FixedReciprocal(attackrange);
x = _g_trace.x + FixedMul(_g_trace.dx, frac);
y = _g_trace.y + FixedMul(_g_trace.dy, frac);
z = shootz + FixedMul3(aimslope, frac, attackrange);
if (LN_FRONTSECTOR(li)->ceilingpic == skyflatnum)
{
// don't shoot the sky!
if (z > LN_FRONTSECTOR(li)->ceilingheight)
return false;
// it's a sky hack wall
if (LN_BACKSECTOR(li) && LN_BACKSECTOR(li)->ceilingpic == skyflatnum)
// fix bullet-eaters -- killough:
// WARNING: Almost all demos will lose sync without this
// demo_compatibility flag check!!! killough 1/18/98
if (LN_BACKSECTOR(li)->ceilingheight < z)
return false;
}
// Spawn bullet puffs.
P_SpawnPuff (x,y,z);
// don't go any farther
return false;
}
// shoot a thing
th = in->d.thing;
if (th == shootthing)
return true; // can't shoot self
if (!(th->flags&MF_SHOOTABLE))
return true; // corpse or something
// check angles to see if the thing can be aimed at
dist = FixedMul (attackrange, in->frac);
thingtopslope = FixedApproxDiv (th->z+th->height - shootz , dist);
if (thingtopslope < aimslope)
return true; // shot over the thing
thingbottomslope = FixedApproxDiv (th->z - shootz, dist);
if (thingbottomslope > aimslope)
return true; // shot under the thing
// hit thing
// position a bit closer
frac = in->frac - 10 * FixedReciprocal(attackrange);
x = _g_trace.x + FixedMul(_g_trace.dx, frac);
y = _g_trace.y + FixedMul(_g_trace.dy, frac);
z = shootz + FixedMul3(aimslope, frac, attackrange);
// Spawn bullet puffs or blod spots,
// depending on target type.
if (in->d.thing->flags & MF_NOBLOOD)
P_SpawnPuff (x,y,z);
else
P_SpawnBlood (x,y,z, la_damage);
if (la_damage)
P_DamageMobj (th, shootthing, shootthing, la_damage);
// don't go any farther
return false;
}