-
Notifications
You must be signed in to change notification settings - Fork 266
/
Copy pathcollide.cpp
2719 lines (2364 loc) · 87.1 KB
/
collide.cpp
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
/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
--- HISTORICAL COMMENTS FOLLOW ---
* $Logfile: /DescentIII/Main/physics/Collide.cpp $
* $Revision: 239 $
* $Date: 9/20/01 5:33p $
* $Author: Matt $
*
* Descent III collision code
*
* $Log: /DescentIII/Main/physics/Collide.cpp $
*
* 239 9/20/01 5:33p Matt
* Fixed weird omega cannon bugs (I hope) by only letting the omega
* particles collide from inside AquireElectricalTarget().
*
* 238 11/04/99 5:35p Chris
* Levels with forcefields with a custom bouce sound don't cause damage
*
* 237 10/20/99 5:40p Chris
* Added the Red Guidebot
*
* 236 10/08/99 4:29p Chris
* Added the forcefield and glass breaking override options
*
* 235 5/24/99 1:26a Matt
* Correctly deal with hit_info == NULL being passed to collision
* routines.
*
* 234 5/21/99 2:55a Matt
* When an object is bounced-out and needs to be killed, call
* DestroyObject() if it's already dying. Before the code just set the
* dead flag, which caused robots to disappear if they bumped into
* something while dying.
*
* 233 5/20/99 9:03p Matt
* Changed trigger system so that collisions with rendered portals don't
* set off triggers on the portals.
*
* 232 5/19/99 1:23p Matt
* Fixed (hopefully) yet more collision problems introduced by my recent
* changes.
*
* 231 5/18/99 10:15p Matt
* Fixed bug with weapon spawning that I introduced last night.
*
* 230 5/18/99 10:57a Chris
* Various bug fixes
*
* 229 5/17/99 9:09p Matt
* Made objects with lava behave like walls with lava; flares don't stick,
* player catches on fire.
*
* 228 5/17/99 6:07p Chris
* GB doesn't damage players - PF_LOCK_MASK objects always do...
*
* 227 5/11/99 5:50p Chris
* Buildings don't collide with each other
*
* 226 5/08/99 4:27p Chris
* Hearing code
*
* 225 5/08/99 3:31p Matt
* Deal with weapons hitting water.
*
* 224 5/07/99 10:56p Chris
* GB avoids forcefields, lava, and volatile surfaces... If he accidently
* hits one of these, he ignores the collision (i.e. no effects). It make
* him look smarter.
*
* 223 4/30/99 3:28p Matt
* Weapons now make a special sound when colliding with lava & volatile
* surfaces, instead of the standard hit-wall sound.
*
* 222 4/29/99 6:48p Matt
* Made volatile surfaces apply damage and lava surfaces catch the player
* on fire. Both now generate the steam puff effect.
*
* 221 4/29/99 2:17a Samir
* adjusted some sound priority stuff
*
* 220 4/23/99 6:44p Matt
* Changed weapons to keep going after breaking glass.
*
* 219 4/21/99 4:27p Chris
*
* 218 4/21/99 3:45p Chris
*
* 217 4/21/99 3:43p Chris
*
* 216 4/21/99 2:56p Chris
* Made player-player collisions almost complete in-elastic
*
* 215 4/21/99 1:30p Matt
* Make breakable glass use the new breakable flag, instead of
* piggybacking on the destroyable flag.
*
* 214 4/21/99 11:06a Kevin
* new ps_rand and ps_srand to replace rand & srand
*
* 213 4/21/99 10:12a Chris
* Tweaked robot/player damage
*
* 212 4/21/99 3:33a Chris
* Collisions between robots and players cause damage to both robots and
* players (robots get more damage)
*
* 211 4/19/99 12:03p Jason
* added checking for fireball collisions
*
* 210 4/19/99 4:02a Jeff
* fixed min/max for Linux
*
* 209 4/18/99 10:55p Chris
* Added ignore own concussive blasts
*
* 208 4/16/99 8:18p Jason
* make impact spawning weapons work with doors
*
* 207 4/14/99 1:42a Jeff
* fixed case mismatched #includes
*
* 206 4/12/99 6:15p Samir
* Sound priorities pass 1
*
* 205 4/06/99 6:24p Jason
* various fixes for multiplayer
*
* 204 3/23/99 4:10p Jason
* more tweaks for line sparks
*
* 203 3/23/99 12:50p Jason
* added line sparks
*
* 202 3/22/99 6:41p Jason
* fixed client side weapons not reacting correctly to bouncing code
*
* 201 3/22/99 1:47p Matt
* Moved breaking glass code from collide.cpp to damage.cpp
*
* 200 3/16/99 4:16p Matt
* Made mass driver spin the victim more. (Jason had reduced it from 0.25
* to 0.05; I've moved it back up to 0.12 at Andy's request.)
*
* 199 3/12/99 7:46p Jeff
* record wall hit collisions to demo file
*
* 198 3/11/99 5:55p Jason
* fixed player spin with mass driver
*
* 197 3/05/99 2:12p Matt
* Fixed bug (in a slightly hacky way) where energy weapons would cause
* glass to switch to the damaged texture. For a real fix, we need a
* separate breakable glass flag for textures.
*
* 196 3/03/99 10:52a Chris
* Energy weapons push again
*
* 195 3/03/99 5:44a Chris
* Max secondary burn time of 10 seconds
*
* 194 3/01/99 3:18p Jason
* made powerups work correctly in multiplayer
*
* 193 2/28/99 11:29p Chris
* Improved robot-wall reactions
*
* 192 2/22/99 2:03p Jason
* added different damages for players and generics
*
* 191 2/21/99 4:35p Chris
* Improving the level goal system... Not done.
*
* 190 2/20/99 10:31a Kevin
* OEM Beta 1 fixs
*
* 189 2/19/99 12:35p Chris
* Player can fly through markers
*
* 188 2/17/99 4:50p Jason
* fixed destroyable face/breakable glass bug
*
* 187 2/17/99 1:26p Matt
* Fixed the die angle system for weapons (changing it around a little in
* the process: now all non-weapons (which don't use the system) should
* have dot == -1, weapons that die at any angle have dot == 0, and
* setting dot == 1 means it never dies).
*
* 186 2/16/99 8:16a Chris
* Fixed a bug - THANKS!
*
* 185 2/10/99 1:48p Matt
* Changed object handle symbolic constants
*
* 184 2/09/99 2:38p Jason
* added destroyable faces
*
* 183 2/02/99 8:44a Chris
* I made buildings with AI work correctly (ie really big robots should be
* buildings)
* anim to and from states are now shorts instead of bytes
*
* 182 1/31/99 7:26p Matt
* Renamed a bunch of functions to have HUD capitalized
*
* 181 1/29/99 5:09p Chris
* Made changes for ROCKS
*
* 180 1/28/99 6:17p Jason
* added markers
*
* 179 1/26/99 6:39p Jason
* added wall effects code
*
* 178 1/25/99 5:59p Matt
* Patched the masses of objects
*
* 177 1/24/99 8:18p Chris
* Updated AI and OSIRIS. Externalized fireball constants for spew and
* sparks. Added CreateRandomSparks to OSIRIS, renamed a bunch of AI
* Notify names to use underscores. Fixed a memory access leak in the
* matcen effect code.
*
* 176 1/23/99 5:16p Chris
* Bounds fixed acos and asin stuff (-1.0000000000001 could cause really
* bad things to happen with rot. vels)
*
* 175 1/20/99 10:50a Jason
* added new terrain
*
* 174 1/20/99 2:13a Chris
* It is now possible for robots to have special immunities, resistances,
* and vunerabilities
*
* 173 1/18/99 12:12a Jeff
* removed weapon collide event, combined it in general collide event.
* general collide event handles more collides. Added a room collide
* event
*
* 172 1/15/99 3:59a Jeff
* added two new multiplayer DLL events for weapon collisions. Added two
* new fields to DLLInfo data, point and normal, which are filled out for
* collision events.
*
* 170 1/10/99 7:35p Matt
* Added missing break to DO_COLLISION macor
*
* 169 1/10/99 6:49a Jeff
* Some initial work to get linux version to compile
*
* 168 1/08/99 2:56p Samir
* Ripped out OSIRIS1.
*
* 167 1/01/99 4:10p Chris
* Added some const parameters, improved ray cast object collide/rejection
* code
*
* 166 12/21/98 10:50a Chris
* You can now push walking objects
*
* 165 12/17/98 12:08p Jeff
* first checkin of new implementation of OSIRIS (old OSIRIS no longer
* works)
*
* 164 11/19/98 3:54p Chris
*
* 163 11/19/98 3:51p Chris
* Shooting dying robots makes them blow up faster (but now not as
* quickly)
*
* 162 11/13/98 4:25p Jason
* changes for better weapon effects
*
* 161 11/13/98 1:00p Chris
* Fixed a math problem with the new collision response code. Zero rad
* particles where causing i1 or i2 to be zero. c1 = c1/i1 -> it was
* going to infinity. So, I made a floor threshold for i1 and i2
*
* 160 11/11/98 2:46p Kevin
* Demo recording system work
*
* 159 11/10/98 5:17p Jeff
* peppered in some more forcefeedback effects
*
* 158 10/30/98 5:17p Chris
* Players only get 1/4 the rotational velocity of an impulse
*
* 157 10/29/98 1:45p Chris
* Checked in the better collision response code
*
* 156 10/22/98 12:57p Chris
* Added sounds to player/player and player/robot collisions
*
* 155 10/20/98 1:26p Jason
* took out spawning on direct hits
*
* 154 10/20/98 12:10p Chris
*
* 153 10/19/98 8:38p Matt
* Don't make a sound when colliding with lava, since the lava will start
* you on fire, which will make sound.
*
* 152 10/19/98 7:19p Matt
* Added system to support different types of damage to the player and
* have these different types make different sounds.
*
* 151 10/18/98 2:09p Matt
* Made the backquote/flare thing go away in release versions, and made it
* work for terrain cells.
*
* 150 10/17/98 12:25p Chris
* Fixed attached flares
*
* 149 10/16/98 5:25p Chris
* Fixed sticky code
*
* 148 10/16/98 4:33p Chris
*
* 147 10/16/98 4:18p Chris
* Fixed the 'flare thing'
*
* 146 10/16/98 3:39p Chris
* Improved the object linking system and AI and physics
*
* 145 10/15/98 4:51p Chris
* Speed up dying for player too
*
* 144 10/15/98 4:49p Chris
* Speed up dying if the robot is getting hit
*
* 143 10/12/98 2:27p Matt
* Fixed code to print room:face when backquote/tilde held down and flare
* hits the wall.
*
* 142 10/12/98 10:04a Chris
* Wall hits cannot kill the player
*
* 141 10/09/98 7:57p Chris
* Added the flare room/wall cheat
*
* 140 10/09/98 7:47p Chris
* Added ObjSetDeadFlag
*
* 139 10/08/98 12:00p Kevin
* Demo system work
*
* 138 10/05/98 7:23p Jason
* implemented destroyable lights (first draft)
*
* 137 10/01/98 6:56p Jason
* turned off energy weapon hit effects if the object getting hit is the
* viewer - this helps cut down on the general clutter in heavy combat
*
* 136 9/29/98 4:48p Chris
* Working on multiplayer collisions
*
* 135 9/23/98 5:04p Chris
* Raised the collide wall damage threshold
*
* 134 9/23/98 3:47p Chris
* Increased the speed to cause damage from wall hits
*
* 133 9/22/98 12:23p Chris
* Further improvements to wall hitting
*
* 132 9/21/98 8:32p Chris
* Another improvement to the forcefield stuff
*
* 131 9/21/98 8:19p Chris
* Improved volatile and forcefield hits
*
* 130 9/21/98 1:08p Chris
* Improved lava handling
*
* 129 9/21/98 1:04p Chris
*
* 128 9/21/98 1:03p Chris
*
* 127 9/21/98 1:01p Chris
* Fixed more volatile problems
*
* 126 9/21/98 11:44a Chris
* Fixed the volatile terrain crash bug
*
* 125 9/18/98 7:45p Chris
* Lava works - needs tweaking.
*
* 124 8/25/98 7:27p Chris
* Improved the scorch code
*
* 123 8/25/98 7:23p Chris
* Made weapons explode even if they break glass
*
* 122 8/25/98 12:35p Chris
* Fixed a small reversed normal bug
*
* 121 8/19/98 2:48p Jason
* fixed some weapon firing and weapon exploding bugs
*
* 120 8/18/98 7:12p Chris
* Improved FUSION behavior.
*
* 119 8/12/98 12:26p Chris
*
* 118 8/05/98 11:16a Matt
* Added trigger checks when weapons and the player collide with walls.
*
* 117 8/03/98 5:56p Jason
* got fusion cannon working correctly
*
* 116 7/31/98 11:52a Chris
* Weapons can be persistent. Added ability for objects to be manually
* set for no object collisions.
*
* 115 7/30/98 11:09a Jason
* added weapons that freeze and deform terrain
*
* 114 7/22/98 4:36p Jason
* took out bugs from observer mode
*
* 113 7/17/98 10:12a Chris
*
* 112 7/01/98 12:56p Jason
* more changes for countermeasures
*
* 111 7/01/98 12:12p Jason
* added countermeasures
*
* 110 6/24/98 3:56p Jason
* added code for new omega cannon
*
* 109 6/15/98 3:23p Chris
* Single point walker update
*
* 108 6/15/98 7:53a Chris
* Fixed a comment'ed out variable
*
* 107 6/15/98 7:52a Chris
* Removed the new "cool" physics
*
* 106 6/11/98 12:48p Jason
* added better spewing weapons
*
* 105 6/04/98 12:00p Matt
* Took out Napalm Rocket hack that I added for the E3 demo.
*
* 104 6/02/98 10:43p Chris
* Multipoint collision detection enabled
*
* 103 6/01/98 9:23p Chris
* Fixed a bunch of collision problems
*
* 102 5/27/98 6:18p Matt
* Super hack to reduce impact damage of napalm rocket (for E3 only)
*
* 101 5/27/98 6:08p Chris
* Added weapon to generic sound
*
* 100 5/26/98 4:17p Jason
* made scripts/dlls not collide every single frame
*
* 99 5/26/98 3:58p Matt
* Only matter weapons now break glass.
*
* 98 5/25/98 8:36p Matt
* Added code to set different sizes for different weapon scorch marks.
* Also, don't leave scorch marks on lights.
*
* 97 5/22/98 12:34p Matt
* Added scorch mark/bullet hole system.
*
* 96 5/22/98 11:59a Chris
* Fixed improper uses of FindSoundName and made the proper static sounds
*
* 95 5/19/98 4:42a Chris
* Added shockwave's -- enjoy. :)
*
* 94 5/07/98 2:52p Chris
* Removed a bounce mprintf
*
* 93 5/07/98 2:40p Chris
* Added death_dot and bounce sound for weapons
*
* 92 5/07/98 2:22p Chris
* Hit die dot
*
* 91 5/06/98 7:07p Samir
* when player is completely dead, don't call script too.
*
* 90 5/05/98 3:42p Chris
* Code cleanup and fixed the collide_XXX_with_wall code. The wall_normal
* was know by fvi; so, it is passed to the function (instead of
* generating it again)
*
* 89 5/04/98 3:51p Matt
* Finished (for now) with breaking glass.
*
* 88 5/04/98 1:00p Jason
* changed the way weapon explosions work
*
* 87 5/04/98 12:47p Matt
* Improvements to the breaking glass system, though I don't consider it
* anywhere near done yet.
*
* 86 5/03/98 10:24p Matt
* Partially completed breaking glass code, checked in so Chris can fix a
* bug
*
* 85 4/23/98 7:14p Chris
* Changed non-moving objects to player collisions
*
* 84 4/22/98 9:43p Chris
* More AI improvements
*
* 83 4/22/98 3:25p Jason
* changes for multiplayer debugging
*
* 82 4/20/98 4:47p Chris
* Made collision stuff more accurate
*
* 81 4/17/98 2:00p Jason
* added cool object effects
*
* 80 4/15/98 12:56p Chris
* Reformatted some code
*
* 79 4/09/98 5:18p Jason
* got guided working in multiplayer
*
* 78 4/09/98 12:05p Chris
* Added parenting for all object types. :)
*
* 77 4/08/98 11:16a Chris
* Fixed powerup pickup bug
*
* 76 4/07/98 4:25p Chris
* Added support for buddy bot
*
* 75 4/06/98 11:59a Chris
* Fixed powerup/powerup hack
*
* 74 3/31/98 5:56p Jason
* changes for multiplay
*
* 73 3/30/98 5:12p Jason
* more changes for game/dll integration
*
* 72 3/20/98 9:34p Jason
* added SetObjectDeadFlag inlined function
*
* 71 3/20/98 6:39p Jason
* 100.0 to 1.0 for volume
*
* 70 3/20/98 3:54p Chris
* Working on adding sounds to the game. :)
*
* 69 3/20/98 3:21p Chris
* Added player hit by weapon sound.
*
* 68 3/20/98 2:59p Chris
* Added a wall hit sound for the player and added support for a base
* volume for 3d sounds
*
* 67 3/19/98 7:15p Jason
* more changes for multiplayer
*
* 66 3/19/98 3:44p Chris
* Multiplayer enchancement for collisions
*
* 65 3/19/98 3:27p Chris
* Did some collision code for multiplayer.
*
* 64 3/18/98 5:45p Jason
* more multiplayer script integration
*
* 63 3/17/98 6:17p Jason
* added gamemode collide stuff
*
* 62 3/17/98 11:27a Chris
* Added object bump notifies for AI
*
* 61 3/13/98 5:55p Chris
* Added the new collision spheres
*
* 60 2/23/98 5:46p Chris
* Removed some old code.
*
* 59 2/18/98 11:48a Craig
*
* 58 2/11/98 4:10p Jason
* got spawning impact weapons working
*
* 57 2/05/98 2:54p Jason
* changes for explosions
*
* 56 2/05/98 2:02p Chris
* Fixed the hitseg and hitwall in collide_object_with_wall and
* scrape_object_with_wall
*
* 55 2/04/98 6:09p Matt
* Changed object room number to indicate a terrain cell via a flag. Got
* rid of the object flag which used to indicate terrain.
*
* 54 1/30/98 2:54p Matt
* Took script calls out of bump_two_objects, since they alread existed in
* collide_two_objects
*
* 53 1/29/98 5:48p Matt
* Got rid of marker objects
*
* 52 1/29/98 4:16p Matt
* Fixed some problems from my last changes
*
* 51 1/29/98 3:11p Matt
* Clean up a bit: deleted commented-out code, removed leftover D1/D2
* stuff, removed references to hostage objects
*
* 50 1/28/98 12:00p Jason
* more changes for multiplayer
*
* 49 1/26/98 11:01a Jason
* incremental checkin for multiplayer
*
* 48 1/23/98 11:21a Jason
* incremental multiplayer checkin
*
* 47 1/21/98 6:09p Jason
* Got player deaths working in multiplayer
*
* 46 1/21/98 3:05p Samir
* Changed a function call to StartPlayerExplosion
*
* 45 1/21/98 1:11p Jason
* incremental checkin for multiplayer
*
* 44 1/20/98 12:10p Jason
* implemented vis effect system
*
* 43 1/19/98 10:04a Matt
* Added new object handle system
*
* 42 1/14/98 7:57p Chris
* Improving the awareness system
*
* 41 1/14/98 1:23p Jason
* made ApplyDamageToGeneric send the weapons parent as the killer
*
* 40 1/09/98 4:13p Chris
* Reformatted some code
*
* 39 1/09/98 4:11p Chris
* Removed a mprintf
*
* 38 12/22/97 6:19p Chris
* Moved weapon battery firing sound off the projectile (weapon) and into
* the weapon battery.
*
* 37 12/15/97 11:03a Jason
* make sparks only when successfully hit
*
* 36 12/12/97 6:13p Jason
* added sparks
*
* 35 12/10/97 2:36p Jason
* added random small explosions
*
* 34 12/04/97 12:15p Jason
* gave designers the ability to set their own weapon-to-wall hit vclips
*
* 33 12/01/97 9:54a Chris
* Added support for concussive forces, generalized robot collisions to
* generic collisions
*
* 32 11/20/97 1:38p Chris
* No rotation is applied to player objects
*
* 31 11/13/97 5:06p Chris
* Added support for clutter to weapon collisions
*
* 30 11/05/97 6:42p Jason
* took out stupid blast ring
*
* 29 10/29/97 1:29p Chris
* Added PF_STICK for weapons
*
* 28 10/24/97 2:30p Jason
* more changes for explosions
*
* 27 10/23/97 11:14a Jason
* changed some fireball DEFINEs
*
* 26 10/22/97 7:26p Samir
* Player death mostly working. Damn hangup still occurs. Freaky.
*
* 25 10/22/97 4:30p Chris
* We can now slew between the mine and the terrain
*
* 24 10/22/97 11:44a Jason
* changes for explosion system
*
* 23 10/21/97 4:15p Chris
* Incremental integration of the fvi/physics/collide code
*
* 22 10/20/97 4:46p Jason
* changes for explosions
*
* 21 10/20/97 11:55a Chris
* Added some support for the new collide system.
*
* 20 10/16/97 3:46p Chris
* Incremental improvements
*
* 19 10/03/97 3:47p Chris
* Moved script calls to bump two objects (so building can have scripts)
*
* 18 10/03/97 3:45p Chris
* Added some bumping force by weapons
*
* 17 10/03/97 3:18p Samir
* Added script hook to bump_this_object
*
* 16 10/02/97 11:34a Chris
* Added support for external room collisions
*
* 15 10/01/97 4:51p Samir
* Include damage.h
*
* 14 9/19/97 9:37p Chris
* Attempted to fix door collisions -- almost there, but not quite
*
* 13 9/15/97 5:17a Chris
* Removed the Explosion Vclips since they do not play correctly in
* Hardware
* Added support for building collisons.
* working on SPhere to non-moving sphere collisions
*
* 12 9/12/97 6:36p Chris
* Added building collisions
*
* 11 9/05/97 12:27p Samir
* Player takes damage and set death if needed.
*
* 10 9/04/97 12:03p Matt
* Got rid of warnings
*
* 9 9/03/97 2:13p Chris
* Working on improving the debris system and partical explosions
*
* 8 8/21/97 7:53p Chris
*
* 7 8/21/97 7:52p Chris
*
* 6 8/18/97 1:46a Chris
* Allowed for robot damage and destoyable objects.
* Also, allowed weapons to bounce
*
* 5 8/14/97 11:44a Samir
* Don't kill powerups. Let script do it.
*
* 4 8/12/97 3:32p Samir
* collisions call script code now too.
*
* 3 8/11/97 1:54p Matt
* Ripped out robot & powerup pages, and added generic page
*
* 2 7/28/97 1:16p Chris
* Allow for player and robots to be hit by weapons and correct parenting
* of weapons.
*
* 16 5/19/97 5:39 PM Jeremy
* removed "we hit a robot" mprintf
*
* 15 5/15/97 6:09p Chris
*
* 14 5/13/97 5:52p Chris
* Added ability to exit and enter mine. Also did some
* incremental improvements.
*
* 13 5/05/97 5:41a Chris
* Added some better polygon collision code. It is still rough though.
*
* 12 4/29/97 8:03a Chris
* Improved the sound code. High-level sound now
* fully uses the flags in the sound page and it
* resulted in a simpilier coding interface :)
*
* 11 4/24/97 5:42p Jason
* got fireball vclips working
*
* 10 4/24/97 12:28p Jason
* added sound when weapon hits a wall
*
* 9 4/24/97 3:25a Chris
* // Added some more support for 3d sounds
*
* 8 4/23/97 6:34p Chris
* // Incremental collision stuff.
*
* 7 4/23/97 6:06p Jason
* made player ship and weapons work correctly together (first pass)
*
* 6 4/17/97 3:10p Chris
* Added edge of world object delete. Also did some incremental
* improvements.
*
* 5 4/11/97 3:05a Chris
* Allowed robot sphere collision
*
* 4 3/15/97 1:29p Chris
*
* $NoKeywords: $
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include "AIMain.h"
#include "collide.h"
#include "D3ForceFeedback.h"
#include "ddio_common.h"
#include "damage.h"
#include "demofile.h"
#include "fireball.h"
#include "game.h"
#include "game2dll.h"
#include "hlsoundlib.h"
#include "hud.h"
#include "levelgoal.h"
#include "lighting.h"
#include "marker.h"
#include "log.h"
#include "multi.h"
#include "object.h"
#include "osiris_dll.h"
#include "physics.h"
#include "player.h"
#include "polymodel.h"
#include "pserror.h"
#include "psrand.h"
#include "scorch.h"
#include "sounds.h"
#include "trigger.h"
#include "vecmat.h"
#include "weapon.h"
#define PLAYER_ROTATION_BY_FORCE_SCALAR 0.12f
#define NONPLAYER_ROTATION_BY_FORCE_SCALAR 1.0f
uint8_t CollisionResult[MAX_OBJECT_TYPES][MAX_OBJECT_TYPES];
uint8_t CollisionRayResult[MAX_OBJECT_TYPES];
static bool IsOKToApplyForce(object *objp);
//! Creates some effects where a weapon has collided with a wall.
static void DoWallEffects(object *weapon, int surface_tmap);
//! Check for lava, volatile, or water surface. If contact, make special sound & kill the weapon.
static void check_for_special_surface(object *weapon, int surface_tmap, vector *surface_normal, float hit_dot);
/// Process a collision between a weapon and a wall.
/// - Returns: true if the weapon hits the wall, and false if should keep going though the wall (for breakable glass).
static bool collide_weapon_and_wall(object *weapon, fix hitspeed, int hitseg, int hitwall, vector *hitpnt,
vector *wall_normal, float hit_dot);
/// Prints out a marker hud message if needed.
static void collide_player_and_marker(object *playerobj, object *marker_obj, vector *collision_point,
vector *collision_normal, bool f_reverse_normal, fvi_info *hit_info);
static void collide_player_and_wall(object *playerobj, float hitspeed, int hitseg, int hitwall, vector *hitpt,
vector *wall_normal, float hit_dot);
static void collide_generic_and_wall(object *genericobj, float hitspeed, int hitseg, int hitwall, vector *hitpt,
vector *wall_normal, float hit_dot);
static void CollideAnglesToMatrix(matrix *m, float p, float h, float b);
static vector *CollideExtractAnglesFromMatrix(vector *a, matrix *m);
static void bump_two_objects(object *object0, object *object1, vector *collision_point, vector *collision_normal,
int damage_flag);
static void collide_player_and_player(object *p1, object *p2, vector *collision_point, vector *collision_normal,
bool f_reverse_normal, fvi_info *hit_info);
static void collide_generic_and_player(object *robotobj, object *playerobj, vector *collision_point,
vector *collision_normal, bool f_reverse_normal, fvi_info *hit_info);
static void MakeWeaponStick(object *weapon, object *parent, fvi_info *hit_info);
static void check_lg_inform(object *A, object *B);
bool IsOKToApplyForce(object *objp) {
if (Game_mode & GM_MULTI) {
if (objp->type == OBJ_PLAYER) {
if (objp != Player_object)
return false;
} else {
if (objp->type != OBJ_WEAPON && objp->type != OBJ_POWERUP && Netgame.local_role != LR_SERVER)
return false;
}
}
if (objp->mtype.phys_info.mass == 0.0)
return false;
if (objp->movement_type != MT_PHYSICS && objp->movement_type != MT_WALKING)
return false;
if (objp->mtype.phys_info.flags & PF_PERSISTENT)
return false;
if (objp->mtype.phys_info.flags & PF_LOCK_MASK) // Not done!
return false;
return true;
}
struct vec2d {
float i, j;
};
#define cross(v0, v1) (((v0)->i * (v1)->j) - ((v0)->j * (v1)->i))
// finds the uv coords of the given point on the given seg & side
// fills in u & v. if l is non-NULL fills it in also
void FindHitpointUV(float *u, float *v, vector *point, room *rp, int facenum) {
face *fp = &rp->faces[facenum];
int ii, jj;
vec2d pnt[3], checkp, vec0, vec1;
float *t;
float k0, k1;
int i;
// 1. find what plane to project this wall onto to make it a 2d case
GetIJ(&fp->normal, &ii, &jj);
// 2. compute u,v of intersection point
// Copy face points into 2d verts array
for (i = 0; i < 3; i++) {
t = &rp->verts[fp->face_verts[i]].x;
pnt[i].i = t[ii];
pnt[i].j = t[jj];
}
t = &point->x;
checkp.i = t[ii];
checkp.j = t[jj];
// vec from 1 -> 0
vec0.i = pnt[0].i - pnt[1].i;
vec0.j = pnt[0].j - pnt[1].j;
// vec from 1 -> 2
vec1.i = pnt[2].i - pnt[1].i;
vec1.j = pnt[2].j - pnt[1].j;
k1 = -((cross(&checkp, &vec0) + cross(&vec0, &pnt[1])) / cross(&vec0, &vec1));
if (fabsf(vec0.i) > fabsf(vec0.j))
k0 = ((-k1 * vec1.i) + checkp.i - pnt[1].i) / vec0.i;
else
k0 = ((-k1 * vec1.j) + checkp.j - pnt[1].j) / vec0.j;
// mprintf(0," k0,k1 = %x,%x\n",k0,k1);
*u = fp->face_uvls[1].u + (k0 * (fp->face_uvls[0].u - fp->face_uvls[1].u)) +
(k1 * (fp->face_uvls[2].u - fp->face_uvls[1].u));
*v = fp->face_uvls[1].v + (k0 * (fp->face_uvls[0].v - fp->face_uvls[1].v)) +
(k1 * (fp->face_uvls[2].v - fp->face_uvls[1].v));
// mprintf(0," u,v = %x,%x\n",*u,*v);
}
// Creates some effects where a weapon has collided with a wall
void DoWallEffects(object *weapon, int surface_tmap) {
texture *texp = &GameTextures[surface_tmap];
if (texp->flags & (TF_VOLATILE + TF_LAVA + TF_WATER)) {
// Create some lava steam
if ((texp->flags & TF_WATER) || ((ps_rand() % 4) == 0)) {
int visnum = VisEffectCreate(VIS_FIREBALL, MED_SMOKE_INDEX, weapon->roomnum, &weapon->pos);
if (visnum >= 0) {
vis_effect *vis = &VisEffects[visnum];
vis->lifetime = .9f;
vis->lifeleft = .9f;
vis->movement_type = MT_PHYSICS;
vis->size = 3.0;
vm_MakeZero(&vis->velocity);
vis->velocity.y = 10;
}
}
} else if (texp->flags & TF_RUBBLE) {
if ((ps_rand() % 4) == 0) {
int num_rubble = (ps_rand() % 3) + 1;