/
p_map.c
3172 lines (2662 loc) · 89.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
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2009 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2009 Daniel Swanson <danij@dengine.net>
*\author Copyright © 1993-1996 by id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/**
* p_map.c: Common map routines.
*/
// HEADER FILES ------------------------------------------------------------
#include <math.h>
#include <stdio.h>
#include <string.h>
#if __JDOOM__
# include "jdoom.h"
#elif __JDOOM64__
# include "jdoom64.h"
#elif __JHERETIC__
# include "jheretic.h"
#elif __JHEXEN__
# include "jhexen.h"
#elif __JSTRIFE__
# include "jstrife.h"
#endif
#include "d_net.h"
#include "g_common.h"
#include "dmu_lib.h"
#include "p_mapspec.h"
#include "p_terraintype.h"
#include "p_tick.h"
#include "p_actor.h"
#include "p_player.h"
#include "p_mapsetup.h"
// MACROS ------------------------------------------------------------------
#if __JHEXEN__
#define USE_PUZZLE_ITEM_SPECIAL 129
#endif
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
#if __JDOOM64__
static void CheckMissileImpact(mobj_t* mobj);
#endif
#if __JHERETIC__
static void CheckMissileImpact(mobj_t* mobj);
#elif __JHEXEN__
static void P_FakeZMovement(mobj_t* mo);
static void checkForPushSpecial(linedef_t* line, int side, mobj_t* mobj);
#endif
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
float tmBBox[4];
mobj_t* tmThing;
// If "floatOk" true, move would be ok if within "tmFloorZ - tmCeilingZ".
boolean floatOk;
float tmFloorZ;
float tmCeilingZ;
#if __JHEXEN__
material_t* tmFloorMaterial;
#endif
boolean fellDown; // $dropoff_fix
// The following is used to keep track of the linedefs that clip the open
// height range e.g. PIT_CheckLine. They in turn are used with the &unstuck
// logic and to prevent missiles from exploding against sky hack walls.
linedef_t* ceilingLine;
linedef_t* floorLine;
mobj_t* lineTarget; // Who got hit (or NULL).
linedef_t* blockLine; // $unstuck: blocking linedef
float attackRange;
#if __JHEXEN__
mobj_t* puffSpawned;
mobj_t* blockingMobj;
#endif
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static float tm[3];
static float tmHeight;
static linedef_t* tmHitLine;
static float tmDropoffZ;
static float bestSlideFrac, secondSlideFrac;
static linedef_t* bestSlideLine, *secondSlideLine;
static mobj_t* slideMo;
static float tmMove[3];
static mobj_t* shootThing;
// Height if not aiming up or down.
static float shootZ;
static int lineAttackDamage;
static float aimSlope;
// slopes to top and bottom of target
static float topSlope, bottomSlope;
static mobj_t* useThing;
static mobj_t* bombSource, *bombSpot;
static int bombDamage;
static int bombDistance;
static boolean crushChange;
static boolean noFit;
static float startPos[3]; // start position for trajectory line checks
static float endPos[3]; // end position for trajectory checks
#if __JHEXEN__
static mobj_t* tsThing;
static boolean damageSource;
static mobj_t* onMobj; // generic global onMobj...used for landing on pods/players
static mobj_t* puzzleItemUser;
static int puzzleItemType;
static boolean puzzleActivated;
#endif
#if !__JHEXEN__
static int tmUnstuck; // $unstuck: used to check unsticking
#endif
static byte* rejectMatrix = NULL; // For fast sight rejection.
// CODE --------------------------------------------------------------------
float P_GetGravity(void)
{
if(IS_NETGAME && cfg.netGravity != -1)
return (float) cfg.netGravity / 100;
return *((float*) DD_GetVariable(DD_GRAVITY));
}
/**
* Checks the reject matrix to find out if the two sectors are visible
* from each other.
*/
static boolean checkReject(subsector_t* a, subsector_t* b)
{
if(rejectMatrix != NULL)
{
uint s1, s2, pnum, bytenum, bitnum;
sector_t* sec1 = P_GetPtrp(a, DMU_SECTOR);
sector_t* sec2 = P_GetPtrp(b, DMU_SECTOR);
// Determine subsector entries in REJECT table.
s1 = P_ToIndex(sec1);
s2 = P_ToIndex(sec2);
pnum = s1 * numsectors + s2;
bytenum = pnum >> 3;
bitnum = 1 << (pnum & 7);
// Check in REJECT table.
if(rejectMatrix[bytenum] & bitnum)
{
// Can't possibly be connected.
return false;
}
}
return true;
}
/**
* Look from eyes of t1 to any part of t2 (start from middle of t1).
*
* @param from The mobj doing the looking.
* @param to The mobj being looked at.
*
* @return @c true if a straight line between t1 and t2 is
* unobstructed.
*/
boolean P_CheckSight(const mobj_t* from, const mobj_t* to)
{
float fPos[3];
// If either is unlinked, they can't see each other.
if(!from->subsector || !to->subsector)
return false;
if(to->dPlayer && (to->dPlayer->flags & DDPF_CAMERA))
return false; // Cameramen don't exist!
// Check for trivial rejection.
if(!checkReject(from->subsector, to->subsector))
return false;
fPos[VX] = from->pos[VX];
fPos[VY] = from->pos[VY];
fPos[VZ] = from->pos[VZ];
if(!P_MobjIsCamera(from))
fPos[VZ] += from->height + -(from->height / 4);
return P_CheckLineSight(fPos, to->pos, 0, to->height);
}
boolean PIT_StompThing(mobj_t* mo, void* data)
{
int stompAnyway;
float blockdist;
if(!(mo->flags & MF_SHOOTABLE))
return true;
blockdist = mo->radius + tmThing->radius;
if(fabs(mo->pos[VX] - tm[VX]) >= blockdist ||
fabs(mo->pos[VY] - tm[VY]) >= blockdist)
return true; // Didn't hit it.
if(mo == tmThing)
return true; // Don't clip against self.
stompAnyway = *(int*) data;
// Should we stomp anyway? unless self.
if(mo != tmThing && stompAnyway)
{
P_DamageMobj(mo, tmThing, tmThing, 10000, true);
return true;
}
#if __JDOOM64__
// monsters don't stomp things
if(!tmThing->player)
return false;
#elif __JDOOM__
// Monsters don't stomp things except on a boss map.
if(!tmThing->player && gameMap != 30)
return false;
#endif
if(!(tmThing->flags2 & MF2_TELESTOMP))
return false; // Not allowed to stomp things.
// Do stomp damage (unless self).
if(mo != tmThing)
P_DamageMobj(mo, tmThing, tmThing, 10000, true);
return true;
}
boolean P_TeleportMove(mobj_t* thing, float x, float y, boolean alwaysStomp)
{
int stomping;
subsector_t* newSSec;
float box[4];
// Kill anything occupying the position.
tmThing = thing;
stomping = alwaysStomp;
tm[VX] = x;
tm[VY] = y;
tmBBox[BOXTOP] = tm[VY] + tmThing->radius;
tmBBox[BOXBOTTOM] = tm[VY] - tmThing->radius;
tmBBox[BOXRIGHT] = tm[VX] + tmThing->radius;
tmBBox[BOXLEFT] = tm[VX] - tmThing->radius;
newSSec = R_PointInSubsector(tm[VX], tm[VY]);
ceilingLine = floorLine = NULL;
#if !__JHEXEN__
blockLine = NULL;
tmUnstuck = thing->dPlayer && thing->dPlayer->mo == thing;
#endif
// The base floor / ceiling is from the subsector that contains the
// point. Any contacted lines the step closer together will adjust them.
tmFloorZ = tmDropoffZ = P_GetFloatp(newSSec, DMU_FLOOR_HEIGHT);
tmCeilingZ = P_GetFloatp(newSSec, DMU_CEILING_HEIGHT);
#if __JHEXEN__
tmFloorMaterial = P_GetPtrp(newSSec, DMU_FLOOR_MATERIAL);
#endif
P_EmptyIterList(spechit);
box[BOXLEFT] = tmBBox[BOXLEFT] - MAXRADIUS;
box[BOXRIGHT] = tmBBox[BOXRIGHT] + MAXRADIUS;
box[BOXBOTTOM] = tmBBox[BOXBOTTOM] - MAXRADIUS;
box[BOXTOP] = tmBBox[BOXTOP] + MAXRADIUS;
// Stomp on any things contacted.
VALIDCOUNT++;
if(!P_MobjsBoxIterator(box, PIT_StompThing, &stomping))
return false;
// The move is ok, so link the thing into its new position.
P_MobjUnsetPosition(thing);
thing->floorZ = tmFloorZ;
thing->ceilingZ = tmCeilingZ;
#if !__JHEXEN__
thing->dropOffZ = tmDropoffZ;
#endif
thing->pos[VX] = x;
thing->pos[VY] = y;
P_MobjSetPosition(thing);
P_MobjClearSRVO(thing);
return true;
}
/**
* Checks to see if a start->end trajectory line crosses a blocking 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 start is on one side of the line and the end 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.
*
* @param data Unused.
*/
boolean PIT_CrossLine(linedef_t* ld, void* data)
{
int flags = P_GetIntp(ld, DMU_FLAGS);
if((flags & DDLF_BLOCKING) ||
(P_ToXLine(ld)->flags & ML_BLOCKMONSTERS) ||
(!P_GetPtrp(ld, DMU_FRONT_SECTOR) || !P_GetPtrp(ld, DMU_BACK_SECTOR)))
{
float bbox[4];
P_GetFloatpv(ld, DMU_BOUNDING_BOX, bbox);
if(!(tmBBox[BOXLEFT] > bbox[BOXRIGHT] ||
tmBBox[BOXRIGHT] < bbox[BOXLEFT] ||
tmBBox[BOXTOP] < bbox[BOXBOTTOM] ||
tmBBox[BOXBOTTOM] > bbox[BOXTOP]))
{
if(P_PointOnLinedefSide(startPos[VX], startPos[VY], ld) !=
P_PointOnLinedefSide(endPos[VX], endPos[VY], ld))
// Line blocks trajectory.
return false;
}
}
// Line doesn't block trajectory.
return true;
}
/**
* This routine checks for Lost Souls trying to be spawned across 1-sided
* lines, impassible lines, or "monsters can't cross" lines.
*
* Draw an imaginary line between the PE 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 are on
* different sides of the blocking line. If so, return true otherwise
* false.
*/
boolean P_CheckSides(mobj_t* actor, float x, float y)
{
startPos[VX] = actor->pos[VX];
startPos[VY] = actor->pos[VY];
startPos[VZ] = actor->pos[VZ];
endPos[VX] = x;
endPos[VY] = y;
endPos[VZ] = DDMINFLOAT; // Initialize with *something*.
// The bounding box of the trajectory
tmBBox[BOXLEFT] = (startPos[VX] < endPos[VX]? startPos[VX] : endPos[VX]);
tmBBox[BOXRIGHT] = (startPos[VX] > endPos[VX]? startPos[VX] : endPos[VX]);
tmBBox[BOXTOP] = (startPos[VY] > endPos[VY]? startPos[VY] : endPos[VY]);
tmBBox[BOXBOTTOM] = (startPos[VY] < endPos[VY]? startPos[VY] : endPos[VY]);
VALIDCOUNT++;
return !P_AllLinesBoxIterator(tmBBox, PIT_CrossLine, 0);
}
/**
* $unstuck: used to test intersection between thing and line assuming NO
* movement occurs -- used to avoid sticky situations.
*/
static int untouched(linedef_t* ld)
{
float x, y, box[4];
float bbox[4];
float radius;
P_GetFloatpv(ld, DMU_BOUNDING_BOX, bbox);
x = tmThing->pos[VX];
y = tmThing->pos[VY];
radius = tmThing->radius;
if(((box[BOXRIGHT] = x + radius) <= bbox[BOXLEFT]) ||
((box[BOXLEFT] = x - radius) >= bbox[BOXRIGHT]) ||
((box[BOXTOP] = y + radius) <= bbox[BOXBOTTOM]) ||
((box[BOXBOTTOM] = y - radius) >= bbox[BOXTOP]) ||
P_BoxOnLineSide(box, ld) != -1)
return true;
return false;
}
boolean PIT_CheckThing(mobj_t* thing, void* data)
{
int damage;
float blockdist;
boolean solid;
#if !__JHEXEN__
boolean overlap = false;
#endif
// Don't clip against self.
if(thing == tmThing)
return true;
if(!(thing->flags & (MF_SOLID | MF_SPECIAL | MF_SHOOTABLE)) ||
P_MobjIsCamera(thing) || P_MobjIsCamera(tmThing))
return true;
#if !__JHEXEN__
// Player only.
if(tmThing->player && tm[VZ] != DDMAXFLOAT &&
(cfg.moveCheckZ || (tmThing->flags2 & MF2_PASSMOBJ)))
{
if((thing->pos[VZ] > tm[VZ] + tmHeight) ||
(thing->pos[VZ] + thing->height < tm[VZ]))
return true; // Under or over it.
overlap = true;
}
#endif
blockdist = thing->radius + tmThing->radius;
if(fabs(thing->pos[VX] - tm[VX]) >= blockdist ||
fabs(thing->pos[VY] - tm[VY]) >= blockdist)
return true; // Didn't hit thing.
#if __JHEXEN__
// Stop here if we are a client.
if(IS_CLIENT)
return false;
#endif
#if !__JHEXEN__
if(!tmThing->player && (tmThing->flags2 & MF2_PASSMOBJ))
#else
blockingMobj = thing;
if(tmThing->flags2 & MF2_PASSMOBJ)
#endif
{ // Check if a mobj passed over/under another object.
#if __JHERETIC__
if((tmThing->type == MT_IMP || tmThing->type == MT_WIZARD) &&
(thing->type == MT_IMP || thing->type == MT_WIZARD))
{
return false; // Don't let imps/wizards fly over other imps/wizards.
}
#elif __JHEXEN__
if(tmThing->type == MT_BISHOP && thing->type == MT_BISHOP)
return false; // Don't let bishops fly over other bishops.
#endif
if(!(thing->flags & MF_SPECIAL))
{
if(tmThing->pos[VZ] > thing->pos[VZ] + thing->height ||
tmThing->pos[VZ] + tmThing->height < thing->pos[VZ])
return true; // Over/under thing.
}
}
// Check for skulls slamming into things.
if((tmThing->flags & MF_SKULLFLY) && (thing->flags & MF_SOLID))
{
#if __JHEXEN__
blockingMobj = NULL;
if(tmThing->type == MT_MINOTAUR)
{
// Slamming minotaurs shouldn't move non-creatures.
if(!(thing->flags & MF_COUNTKILL))
{
return false;
}
}
else if(tmThing->type == MT_HOLY_FX)
{
if((thing->flags & MF_SHOOTABLE) && thing != tmThing->target)
{
if(IS_NETGAME && !deathmatch && thing->player)
return true; // don't attack other co-op players
if((thing->flags2 & MF2_REFLECTIVE) &&
(thing->player || (thing->flags2 & MF2_BOSS)))
{
tmThing->tracer = tmThing->target;
tmThing->target = thing;
return true;
}
if(thing->flags & MF_COUNTKILL || thing->player)
{
tmThing->tracer = thing;
}
if(P_Random() < 96)
{
damage = 12;
if(thing->player || (thing->flags2 & MF2_BOSS))
{
damage = 3;
// Ghost burns out faster when attacking players/bosses.
tmThing->health -= 6;
}
P_DamageMobj(thing, tmThing, tmThing->target, damage, false);
if(P_Random() < 128)
{
P_SpawnMobj3fv(MT_HOLY_PUFF, tmThing->pos,
P_Random() << 24, 0);
S_StartSound(SFX_SPIRIT_ATTACK, tmThing);
if((thing->flags & MF_COUNTKILL) && P_Random() < 128 &&
!S_IsPlaying(SFX_PUPPYBEAT, thing))
{
if((thing->type == MT_CENTAUR) ||
(thing->type == MT_CENTAURLEADER) ||
(thing->type == MT_ETTIN))
{
S_StartSound(SFX_PUPPYBEAT, thing);
}
}
}
}
if(thing->health <= 0)
tmThing->tracer = NULL;
}
return true;
}
#endif
#if __JDOOM__
if(tmThing->damage == DDMAXINT) //// \kludge to support old save games.
damage = tmThing->info->damage;
else
#endif
damage = tmThing->damage;
damage *= (P_Random() % 8) + 1;
P_DamageMobj(thing, tmThing, tmThing, damage, false);
tmThing->flags &= ~MF_SKULLFLY;
tmThing->mom[MX] = tmThing->mom[MY] = tmThing->mom[MZ] = 0;
P_MobjChangeState(tmThing, P_GetState(tmThing->type, SN_SPAWN));
return false; // Stop moving.
}
#if __JHEXEN__
// Check for blasted thing running into another
if((tmThing->flags2 & MF2_BLASTED) && (thing->flags & MF_SHOOTABLE))
{
if(!(thing->flags2 & MF2_BOSS) && (thing->flags & MF_COUNTKILL))
{
thing->mom[MX] += tmThing->mom[MX];
thing->mom[MY] += tmThing->mom[MY];
if(thing->dPlayer)
thing->dPlayer->flags |= DDPF_FIXMOM;
if((thing->mom[MX] + thing->mom[MY]) > 3)
{
damage = (tmThing->info->mass / 100) + 1;
P_DamageMobj(thing, tmThing, tmThing, damage, false);
damage = (thing->info->mass / 100) + 1;
P_DamageMobj(tmThing, thing, thing, damage >> 2, false);
}
return false;
}
}
#endif
// Missiles can hit other things.
if(tmThing->flags & MF_MISSILE)
{
#if __JHEXEN__
// Check for a non-shootable mobj.
if(thing->flags2 & MF2_NONSHOOTABLE)
return true;
#else
// Check for passing through a ghost.
if((thing->flags & MF_SHADOW) && (tmThing->flags2 & MF2_THRUGHOST))
return true;
#endif
// See if it went over / under.
if(tmThing->pos[VZ] > thing->pos[VZ] + thing->height)
return true; // Overhead.
if(tmThing->pos[VZ] + tmThing->height < thing->pos[VZ])
return true; // Underneath.
#if __JHEXEN__
if(tmThing->flags2 & MF2_FLOORBOUNCE)
{
if(tmThing->target == thing || !(thing->flags & MF_SOLID))
return true;
else
return false;
}
if(tmThing->type == MT_LIGHTNING_FLOOR ||
tmThing->type == MT_LIGHTNING_CEILING)
{
if((thing->flags & MF_SHOOTABLE) && thing != tmThing->target)
{
if(thing->info->mass != DDMAXINT)
{
thing->mom[MX] += tmThing->mom[MX] / 16;
thing->mom[MY] += tmThing->mom[MY] / 16;
if(thing->dPlayer)
thing->dPlayer->flags |= DDPF_FIXMOM;
}
if((!thing->player && !(thing->flags2 & MF2_BOSS)) ||
!(mapTime & 1))
{
if(thing->type == MT_CENTAUR ||
thing->type == MT_CENTAURLEADER)
{ // Lightning does more damage to centaurs.
P_DamageMobj(thing, tmThing, tmThing->target, 9, false);
}
else
{
P_DamageMobj(thing, tmThing, tmThing->target, 3, false);
}
if(!(S_IsPlaying(SFX_MAGE_LIGHTNING_ZAP, tmThing)))
{
S_StartSound(SFX_MAGE_LIGHTNING_ZAP, tmThing);
}
if((thing->flags & MF_COUNTKILL) && P_Random() < 64 &&
!S_IsPlaying(SFX_PUPPYBEAT, thing))
{
if((thing->type == MT_CENTAUR) ||
(thing->type == MT_CENTAURLEADER) ||
(thing->type == MT_ETTIN))
{
S_StartSound(SFX_PUPPYBEAT, thing);
}
}
}
tmThing->health--;
if(tmThing->health <= 0 || thing->health <= 0)
{
return false;
}
if(tmThing->type == MT_LIGHTNING_FLOOR)
{
if(tmThing->lastEnemy &&
!tmThing->lastEnemy->tracer)
{
tmThing->lastEnemy->tracer = thing;
}
}
else if(!tmThing->tracer)
{
tmThing->tracer = thing;
}
}
return true; // Lightning zaps through all sprites.
}
else if(tmThing->type == MT_LIGHTNING_ZAP)
{
mobj_t *lmo;
if((thing->flags & MF_SHOOTABLE) && thing != tmThing->target)
{
lmo = tmThing->lastEnemy;
if(lmo)
{
if(lmo->type == MT_LIGHTNING_FLOOR)
{
if(lmo->lastEnemy &&
!lmo->lastEnemy->tracer)
{
lmo->lastEnemy->tracer = thing;
}
}
else if(!lmo->tracer)
{
lmo->tracer = thing;
}
if(!(mapTime & 3))
{
lmo->health--;
}
}
}
}
else if(tmThing->type == MT_MSTAFF_FX2 && thing != tmThing->target)
{
if(!thing->player && !(thing->flags2 & MF2_BOSS))
{
switch(thing->type)
{
case MT_FIGHTER_BOSS: // these not flagged boss
case MT_CLERIC_BOSS: // so they can be blasted
case MT_MAGE_BOSS:
break;
default:
P_DamageMobj(thing, tmThing, tmThing->target, 10, false);
return true;
break;
}
}
}
#endif
// Don't hit same species as originator.
#if __JDOOM__ || __JDOOM64__
if(tmThing->target &&
(tmThing->target->type == thing->type ||
(tmThing->target->type == MT_KNIGHT && thing->type == MT_BRUISER) ||
(tmThing->target->type == MT_BRUISER && thing->type == MT_KNIGHT)))
#else
if(tmThing->target && tmThing->target->type == thing->type)
#endif
{
if(thing == tmThing->target)
return true;
#if __JHEXEN__
if(!thing->player)
return false; // Hit same species as originator, explode, no damage
#else
if(!monsterInfight && thing->type != MT_PLAYER)
{
// Explode, but do no damage.
// Let players missile other players.
return false;
}
#endif
}
if(!(thing->flags & MF_SHOOTABLE))
{
return !(thing->flags & MF_SOLID); // Didn't do any damage.
}
if(tmThing->flags2 & MF2_RIP)
{
#if __JHEXEN__
if(!(thing->flags & MF_NOBLOOD) &&
!(thing->flags2 & MF2_REFLECTIVE) &&
!(thing->flags2 & MF2_INVULNERABLE))
#else
if(!(thing->flags & MF_NOBLOOD))
#endif
{ // Ok to spawn some blood.
P_RipperBlood(tmThing);
}
#if __JHERETIC__
S_StartSound(SFX_RIPSLOP, tmThing);
#endif
#if __JDOOM__
if(tmThing->damage == DDMAXINT) //// \kludge to support old save games.
damage = tmThing->info->damage;
else
#endif
damage = tmThing->damage;
damage *= (P_Random() & 3) + 2;
P_DamageMobj(thing, tmThing, tmThing->target, damage, false);
if((thing->flags2 & MF2_PUSHABLE) &&
!(tmThing->flags2 & MF2_CANNOTPUSH))
{ // Push thing
thing->mom[MX] += tmThing->mom[MX] / 4;
thing->mom[MY] += tmThing->mom[MY] / 4;
if(thing->dPlayer)
thing->dPlayer->flags |= DDPF_FIXMOM;
}
P_EmptyIterList(spechit);
return true;
}
// Do damage
#if __JDOOM__
if(tmThing->damage == DDMAXINT) //// \kludge to support old save games.
damage = tmThing->info->damage;
else
#endif
damage = tmThing->damage;
damage *= (P_Random() % 8) + 1;
#if __JDOOM__ || __JDOOM64__
P_DamageMobj(thing, tmThing, tmThing->target, damage, false);
#else
if(damage)
{
# if __JHERETIC__
if(!(thing->flags & MF_NOBLOOD) && P_Random() < 192)
# else //__JHEXEN__
if(!(thing->flags & MF_NOBLOOD) &&
!(thing->flags2 & MF2_REFLECTIVE) &&
!(thing->flags2 & MF2_INVULNERABLE) &&
!(tmThing->type == MT_TELOTHER_FX1) &&
!(tmThing->type == MT_TELOTHER_FX2) &&
!(tmThing->type == MT_TELOTHER_FX3) &&
!(tmThing->type == MT_TELOTHER_FX4) &&
!(tmThing->type == MT_TELOTHER_FX5) && (P_Random() < 192))
# endif
P_SpawnBloodSplatter(tmThing->pos[VX], tmThing->pos[VY], tmThing->pos[VZ], thing);
P_DamageMobj(thing, tmThing, tmThing->target, damage, false);
}
#endif
// Don't traverse anymore.
return false;
}
if((thing->flags2 & MF2_PUSHABLE) && !(tmThing->flags2 & MF2_CANNOTPUSH))
{ // Push thing
thing->mom[MX] += tmThing->mom[MX] / 4;
thing->mom[MY] += tmThing->mom[MY] / 4;
if(thing->dPlayer)
thing->dPlayer->flags |= DDPF_FIXMOM;
}
// \kludge: Always treat blood as a solid.
if(tmThing->type == MT_BLOOD)
solid = true;
else
solid = (thing->flags & MF_SOLID) && !(thing->flags & MF_NOCLIP) &&
(tmThing->flags & MF_SOLID);
// \kludge: end.
// Check for special pickup.
if((thing->flags & MF_SPECIAL) && (tmThing->flags & MF_PICKUP))
{
P_TouchSpecialMobj(thing, tmThing); // Can remove thing.
}
#if !__JHEXEN__
else if(overlap && solid)
{
// How are we positioned?
if(tm[VZ] > thing->pos[VZ] + thing->height - 24)
{
tmThing->onMobj = thing;
if(thing->pos[VZ] + thing->height > tmFloorZ)
tmFloorZ = thing->pos[VZ] + thing->height;
return true;
}
}
#endif
return !solid;
}
/**
* Adjusts tmFloorZ and tmCeilingZ as lines are contacted.
*/
boolean PIT_CheckLine(linedef_t* ld, void* data)
{
float bbox[4];
xline_t* xline;
P_GetFloatpv(ld, DMU_BOUNDING_BOX, bbox);
if(tmBBox[BOXRIGHT] <= bbox[BOXLEFT] ||
tmBBox[BOXLEFT] >= bbox[BOXRIGHT] ||
tmBBox[BOXTOP] <= bbox[BOXBOTTOM] ||
tmBBox[BOXBOTTOM] >= bbox[BOXTOP])
return true;
if(P_BoxOnLineSide(tmBBox, ld) != -1)
return true;
// A line has been hit
xline = P_ToXLine(ld);
#if !__JHEXEN__
tmThing->wallHit = true;
// A Hit event will be sent to special lines.
if(xline->special)
tmHitLine = ld;
#endif
if(!P_GetPtrp(ld, DMU_BACK_SECTOR)) // One sided line.
{
#if __JHEXEN__
if(tmThing->flags2 & MF2_BLASTED)
P_DamageMobj(tmThing, NULL, NULL, tmThing->info->mass >> 5, false);
checkForPushSpecial(ld, 0, tmThing);
return false;
#else
float d1[2];
P_GetFloatpv(ld, DMU_DXY, d1);
/**
* $unstuck: allow player to move out of 1s wall, to prevent
* sticking. 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 units apart could be crossed in either order.
*/
blockLine = ld;
return tmUnstuck && !untouched(ld) &&
((tm[VX] - tmThing->pos[VX]) * d1[1]) >
((tm[VY] - tmThing->pos[VY]) * d1[0]);
#endif
}
// \fixme Will never pass this test due to above. Is the previous check
// supposed to qualify player mobjs only?
#if __JHERETIC__
if(!P_GetPtrp(ld, DMU_BACK_SECTOR)) // one sided line
{ // One sided line
if(tmThing->flags & MF_MISSILE)
{ // Missiles can trigger impact specials
if(xline->special)
P_AddObjectToIterList(spechit, ld);
}
return false;
}
#endif
if(!(tmThing->flags & MF_MISSILE))
{
// Explicitly blocking everything?
if(P_GetIntp(ld, DMU_FLAGS) & DDLF_BLOCKING)
{
#if __JHEXEN__
if(tmThing->flags2 & MF2_BLASTED)
P_DamageMobj(tmThing, NULL, NULL, tmThing->info->mass >> 5, false);
checkForPushSpecial(ld, 0, tmThing);
return false;
#else