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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: barnacle - stationary ceiling mounted 'fishing' monster
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "physics_prop_ragdoll.h"
#include "npc_barnacle.h"
#include "npcevent.h"
#include "gib.h"
#include "ai_default.h"
#include "activitylist.h"
#include "hl2_player.h"
#include "vstdlib/random.h"
#include "physics_saverestore.h"
#include "vcollide_parse.h"
#include "vphysics/constraints.h"
#include "studio.h"
#include "bone_setup.h"
#include "iservervehicle.h"
#include "collisionutils.h"
#include "combine_mine.h"
#include "explode.h"
#include "npc_BaseZombie.h"
#include "modelentities.h"
#if HL2_EPISODIC
#include "npc_antlion.h"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
float GetCurrentGravity( void );
ConVar sk_barnacle_health( "sk_barnacle_health","0");
static ConVar npc_barnacle_swallow( "npc_barnacle_swallow", "0", 0, "Use prototype swallow code." );
const char *CNPC_Barnacle::m_szGibNames[NUM_BARNACLE_GIBS] =
{
"models/gibs/hgibs.mdl",
"models/gibs/hgibs_scapula.mdl",
"models/gibs/hgibs_rib.mdl",
"models/gibs/hgibs_spine.mdl"
};
//-----------------------------------------------------------------------------
// Private activities.
//-----------------------------------------------------------------------------
int ACT_BARNACLE_SLURP; // Pulling the tongue up with prey on the end
int ACT_BARNACLE_BITE_HUMAN; // Biting the head of a humanoid
int ACT_BARNACLE_BITE_PLAYER; // Biting the head of the player
int ACT_BARNACLE_CHEW_HUMAN; // Slowly swallowing the humanoid
int ACT_BARNACLE_BARF_HUMAN; // Spitting out human legs & gibs
int ACT_BARNACLE_TONGUE_WRAP; // Wrapping the tongue around a target
int ACT_BARNACLE_TASTE_SPIT; // Yuck! Me no like that!
int ACT_BARNACLE_BITE_SMALL_THINGS; // Eats small things
int ACT_BARNACLE_CHEW_SMALL_THINGS; // Chews small things
//-----------------------------------------------------------------------------
// Interactions
//-----------------------------------------------------------------------------
int g_interactionBarnacleVictimDangle = 0;
int g_interactionBarnacleVictimReleased = 0;
int g_interactionBarnacleVictimGrab = 0;
int g_interactionBarnacleVictimBite = 0;
LINK_ENTITY_TO_CLASS( npc_barnacle, CNPC_Barnacle );
// Tongue Spring constants
#define BARNACLE_TONGUE_SPRING_CONSTANT_HANGING 10000
#define BARNACLE_TONGUE_SPRING_CONSTANT_LIFTING 10000
#define BARNACLE_TONGUE_SPRING_CONSTANT_LOWERING 7000
#define BARNACLE_TONGUE_SPRING_DAMPING 20
#define BARNACLE_TONGUE_TIP_MASS 100
#define BARNACLE_TONGUE_MAX_LIFT_MASS 70
#define BARNACLE_BITE_DAMAGE_TO_PLAYER 15
#define BARNACLE_DEAD_TONGUE_ALTITUDE 164
#define BARNACLE_MIN_DEAD_TONGUE_CLEARANCE 78
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
#define BARNACLE_AE_PUKEGIB 2
#define BARNACLE_AE_BITE 3
#define BARNACLE_AE_SPIT 4
int AE_BARNACLE_PUKEGIB;
int AE_BARNACLE_BITE;
int AE_BARNACLE_SPIT;
#if BARNACLE_USE_TONGUE_OFFSET
// Static variable that holds the difference between the player's
// eyepos and the tongue when he is seized -- used for offsetting
// the drawing of the tongue so that it doesn't appear to clip into
// the camera when we recenter the player.
const Vector CNPC_Barnacle::m_svPlayerHeldTipOffset(24,0,-8);
#endif
//-----------------------------------------------------------------------------
// Purpose: Constructor
// Input :
// Output :
//-----------------------------------------------------------------------------
CNPC_Barnacle::CNPC_Barnacle(void)
{
m_flRestUnitsAboveGround = 16.0f;
m_flNextBloodTime = -1.0f;
#ifndef _XBOX
m_nBloodColor = BLOOD_COLOR_YELLOW;
#endif
m_bPlayerWasStanding = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CNPC_Barnacle::~CNPC_Barnacle( void )
{
// Destroy the ragdoll->tongue tip constraint
if ( m_pConstraint )
{
physenv->DestroyConstraint( m_pConstraint );
m_pConstraint = NULL;
}
}
/*
input LetGo(void) : "Let go of anything I am holding."
output OnGrab(string) : "When I attach my tongue to something"
output OnRelease(string) : "When I let go of something"
*/
BEGIN_DATADESC( CNPC_Barnacle )
DEFINE_FIELD( m_flAltitude, FIELD_FLOAT ),
DEFINE_FIELD( m_cGibs, FIELD_INTEGER ),// barnacle loads up on gibs each time it kills something.
DEFINE_FIELD( m_bLiftingPrey, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bSwallowingPrey, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flDigestFinish, FIELD_TIME ),
DEFINE_FIELD( m_bPlayedPullSound, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bPlayerWasStanding, FIELD_BOOLEAN ),
DEFINE_FIELD( m_flVictimHeight, FIELD_FLOAT ),
DEFINE_FIELD( m_iGrabbedBoneIndex, FIELD_INTEGER ),
DEFINE_FIELD( m_vecRoot, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_vecTip, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_hTongueRoot, FIELD_EHANDLE ),
DEFINE_FIELD( m_hTongueTip, FIELD_EHANDLE ),
DEFINE_FIELD( m_hRagdoll, FIELD_EHANDLE ),
DEFINE_AUTO_ARRAY( m_pRagdollBones, FIELD_MATRIX3X4_WORLDSPACE ),
DEFINE_PHYSPTR( m_pConstraint ),
DEFINE_KEYFIELD( m_flRestUnitsAboveGround, FIELD_FLOAT, "RestDist" ),
DEFINE_FIELD( m_nSpitAttachment, FIELD_INTEGER ),
DEFINE_FIELD( m_hLastSpitEnemy, FIELD_EHANDLE ),
DEFINE_FIELD( m_nShakeCount, FIELD_INTEGER ),
DEFINE_FIELD( m_flNextBloodTime, FIELD_TIME ),
#ifndef _XBOX
DEFINE_FIELD( m_nBloodColor, FIELD_INTEGER ),
#endif
DEFINE_FIELD( m_vecBloodPos, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_flBarnaclePullSpeed, FIELD_FLOAT ),
DEFINE_FIELD( m_flLocalTimer, FIELD_TIME ),
DEFINE_FIELD( m_vLastEnemyPos, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( m_flLastPull, FIELD_FLOAT ),
DEFINE_EMBEDDED( m_StuckTimer ),
DEFINE_INPUTFUNC( FIELD_VOID, "DropTongue", InputDropTongue ),
DEFINE_INPUTFUNC( FIELD_INTEGER, "SetDropTongueSpeed", InputSetDropTongueSpeed ),
#ifdef HL2_EPISODIC
DEFINE_INPUTFUNC( FIELD_VOID, "LetGo", InputLetGo ),
DEFINE_OUTPUT( m_OnGrab, "OnGrab" ),
DEFINE_OUTPUT( m_OnRelease, "OnRelease" ),
#endif
// Function pointers
DEFINE_THINKFUNC( BarnacleThink ),
DEFINE_THINKFUNC( WaitTillDead ),
DEFINE_FIELD( m_bSwallowingBomb, FIELD_BOOLEAN ),
END_DATADESC()
IMPLEMENT_SERVERCLASS_ST( CNPC_Barnacle, DT_Barnacle )
SendPropFloat( SENDINFO( m_flAltitude ), 0, SPROP_NOSCALE),
SendPropVector( SENDINFO( m_vecRoot ), 0, SPROP_COORD ),
SendPropVector( SENDINFO( m_vecTip ), 0, SPROP_COORD ),
SendPropVector( SENDINFO( m_vecTipDrawOffset ), 0, SPROP_NOSCALE ),
END_SEND_TABLE()
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
Class_T CNPC_Barnacle::Classify ( void )
{
return CLASS_BARNACLE;
}
//-----------------------------------------------------------------------------
// Purpose: Initialize absmin & absmax to the appropriate box
//-----------------------------------------------------------------------------
void CNPC_Barnacle::ComputeWorldSpaceSurroundingBox( Vector *pVecWorldMins, Vector *pVecWorldMaxs )
{
// Extend our bounding box downwards the length of the tongue
CollisionProp()->WorldSpaceAABB( pVecWorldMins, pVecWorldMaxs );
// We really care about the tongue tip. The altitude is not really relevant.
VectorMin( *pVecWorldMins, m_vecTip, *pVecWorldMins );
VectorMax( *pVecWorldMaxs, m_vecTip, *pVecWorldMaxs );
// pVecWorldMins->z -= m_flAltitude;
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//
// Returns number of events handled, 0 if none.
//=========================================================
void CNPC_Barnacle::HandleAnimEvent( animevent_t *pEvent )
{
if ( pEvent->event== AE_BARNACLE_PUKEGIB )
{
CGib::SpawnSpecificGibs( this, 1, 50, 1, "models/gibs/hgibs_rib.mdl");
return;
}
if ( pEvent->event == AE_BARNACLE_BITE )
{
BitePrey();
return;
}
if ( pEvent->event == AE_BARNACLE_SPIT )
{
SpitPrey();
return;
}
BaseClass::HandleAnimEvent( pEvent );
}
//=========================================================
// Spawn
//=========================================================
void CNPC_Barnacle::Spawn()
{
Precache( );
SetModel( "models/barnacle.mdl" );
UTIL_SetSize( this, Vector(-16, -16, -40), Vector(16, 16, 0) );
SetSolid( SOLID_BBOX );
AddSolidFlags( FSOLID_NOT_STANDABLE );
CollisionProp()->SetSurroundingBoundsType( USE_GAME_CODE );
#if HL2_EPISODIC // the episodic barnacle is solid, so it can be sawbladed.
SetMoveType( MOVETYPE_PUSH );
#else
SetMoveType( MOVETYPE_NONE );
#endif
SetBloodColor( BLOOD_COLOR_GREEN );
m_iHealth = sk_barnacle_health.GetFloat();
m_flFieldOfView = 0.5;// indicates the width of this monster's forward view cone ( as a dotproduct result )
m_NPCState = NPC_STATE_NONE;
m_cGibs = 0;
m_bLiftingPrey = false;
m_bSwallowingPrey = false;
m_bSwallowingBomb = false;
m_flDigestFinish = 0;
m_takedamage = DAMAGE_YES;
m_pConstraint = NULL;
m_nShakeCount = 0;
#if HL2_EPISODIC // the episodic barnacle is solid, so it can be sawbladed.
IPhysicsObject *pPhys = VPhysicsInitShadow( false, false );
if (pPhys)
{
pPhys->SetMass(500);
}
#endif
InitBoneControllers();
InitTonguePosition();
// set eye position
SetDefaultEyeOffset();
// Add some variation because we're often in large bunches
SetActivity( ACT_IDLE );
SetPlaybackRate( random->RandomFloat( 0.8f, 1.2f ) );
SetThink ( &CNPC_Barnacle::BarnacleThink );
SetNextThink( gpGlobals->curtime + 0.5f );
m_flBarnaclePullSpeed = BARNACLE_PULL_SPEED;
//Do not have a shadow
AddEffects( EF_NOSHADOW );
AddFlag( FL_AIMTARGET );
}
//-----------------------------------------------------------------------------
// Sets the tongue's height
//-----------------------------------------------------------------------------
void CNPC_Barnacle::SetAltitude( float flAltitude )
{
if ( HasSpawnFlags( SF_BARNACLE_AMBUSH ) )
return;
m_flAltitude = flAltitude;
}
void CNPC_Barnacle::DropTongue( void )
{
if ( m_hTongueRoot )
return;
m_hTongueRoot = CBarnacleTongueTip::CreateTongueRoot( m_vecRoot, QAngle(90,0,0) );
m_hTongueTip = CBarnacleTongueTip::CreateTongueTip( this, m_hTongueRoot, m_vecTip, QAngle(0,0,0) );
m_nSpitAttachment = LookupAttachment( "StrikeHeadAttach" );
Assert( m_hTongueRoot && m_hTongueTip );
RemoveSpawnFlags( SF_BARNACLE_AMBUSH );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CNPC_Barnacle::Activate( void )
{
BaseClass::Activate();
if ( HasSpawnFlags( SF_BARNACLE_AMBUSH ) )
return;
// Create our tongue tips
if ( !m_hTongueRoot )
{
DropTongue();
}
else if ( GetEnemy() && IsEnemyAPlayer() && !m_pConstraint )
{
IPhysicsObject *pPlayerPhys = GetEnemy()->VPhysicsGetObject();
IPhysicsObject *pTonguePhys = m_hTongueTip->VPhysicsGetObject();
constraint_fixedparams_t fixed;
fixed.Defaults();
fixed.InitWithCurrentObjectState( pTonguePhys, pPlayerPhys );
fixed.constraint.Defaults();
m_pConstraint = physenv->CreateFixedConstraint( pTonguePhys, pPlayerPhys, NULL, fixed );
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input :
// Output :
//-----------------------------------------------------------------------------
int CNPC_Barnacle::OnTakeDamage_Alive( const CTakeDamageInfo &inputInfo )
{
CTakeDamageInfo info = inputInfo;
if ( info.GetDamageType() & DMG_CLUB )
{
info.SetDamage( m_iHealth );
}
if ( GetActivity() == ACT_IDLE )
{
SetActivity( ACT_SMALL_FLINCH );
}
if( hl2_episodic.GetBool() && info.GetAttacker() && info.GetAttacker()->Classify() == CLASS_PLAYER_ALLY_VITAL )
{
if( FClassnameIs( info.GetAttacker(), "npc_alyx" ) )
{
// Alyx does double damage to barnacles, so that she can save the
// player's life in a more timely fashion. (sjb)
info.ScaleDamage( 2.0f );
}
}
DropTongue();
return BaseClass::OnTakeDamage_Alive( info );
}
//-----------------------------------------------------------------------------
// Purpose: Player has illuminated this NPC with the flashlight
//-----------------------------------------------------------------------------
void CNPC_Barnacle::PlayerHasIlluminatedNPC( CBasePlayer *pPlayer, float flDot )
{
// Create a sound to scare friendly allies away from the base on the barnacle
if( IsAlive() )
{
CSoundEnt::InsertSound( SOUND_MOVE_AWAY | SOUND_CONTEXT_ALLIES_ONLY, m_vecTip, 60.0f, FLASHLIGHT_NPC_CHECK_INTERVAL );
}
}
//-----------------------------------------------------------------------------
// Purpose: Initialize tongue position when first spawned
// Input :
// Output :
//-----------------------------------------------------------------------------
void CNPC_Barnacle::InitTonguePosition( void )
{
CBaseEntity *pTouchEnt;
float flLength;
pTouchEnt = TongueTouchEnt( &flLength );
SetAltitude( flLength );
Vector origin;
GetAttachment( "TongueEnd", origin );
float flTongueAdj = origin.z - GetAbsOrigin().z;
m_vecRoot = origin - Vector(0,0,flTongueAdj);
m_vecTip.Set( m_vecRoot.Get() - Vector(0,0,(float)m_flAltitude) );
CollisionProp()->MarkSurroundingBoundsDirty();
}
//-----------------------------------------------------------------------------
// Purpose:
// TODO: The LostPrey(true) at the top of if ( m_hRagdoll ) isnt' quite right:
// it will make the barnacle drop anything that's shot on the way up. This is a
// quick fix for the antlions which crashed otherwise (they have somewhat anomalous
// ragdoll behaivor) but should be revisted.
//-----------------------------------------------------------------------------
void CNPC_Barnacle::BarnacleThink ( void )
{
CBaseEntity *pTouchEnt;
float flLength;
SetNextThink( gpGlobals->curtime + 0.1f );
UpdateTongue();
// AI Disabled, don't do anything?
if ( CAI_BaseNPC::m_nDebugBits & bits_debugDisableAI )
return;
// Do we have an enemy?
if ( m_hRagdoll )
{
if ( m_bLiftingPrey )
{
if ( GetEnemy() )
{
LiftPrey();
}
else
{
LostPrey(true);
}
}
else if ( m_bSwallowingPrey )
{
// Slowly swallowing the ragdoll
SwallowPrey();
}
// Stay bloated as we digest
else if ( m_flDigestFinish )
{
// Still digesting him>
if ( m_flDigestFinish > gpGlobals->curtime )
{
if ( IsActivityFinished() )
{
SetActivity( ACT_IDLE );
}
// bite prey every once in a while
if ( random->RandomInt(0,25) == 0 )
{
EmitSound( "NPC_Barnacle.Digest" );
}
}
else
{
// Finished digesting
#if HL2_EPISODIC
// have to save this off because LostPrey() resets it (and if we take damage before hitting that,
// then the dead thing will go flying)
bool poisoned = m_bSwallowingPoison;
LostPrey( true ); // Remove all evidence
m_flDigestFinish = 0;
if ( poisoned )
{ // hurt me
TakeDamage( CTakeDamageInfo( this, this, m_iHealth, DMG_ACID ) );
}
#else
LostPrey( true ); // Remove all evidence
m_flDigestFinish = 0;
#endif
}
}
}
else if ( GetEnemy() )
{
if ( m_bLiftingPrey || m_bSwallowingBomb == true )
{
LiftPrey();
}
// Stay bloated as we digest
else if ( m_flDigestFinish )
{
// Still digesting him
if ( m_flDigestFinish > gpGlobals->curtime )
{
if ( IsActivityFinished() )
{
SetActivity( ACT_IDLE );
}
// bite prey every once in a while
if ( random->RandomInt(0,25) == 0 )
{
EmitSound( "NPC_Barnacle.Digest" );
}
}
else
{
// Finished digesting
#if HL2_EPISODIC
// have to save this off because LostPrey() resets it (and if we take damage before hitting that,
// then the dead thing will go flying)
bool poisoned = m_bSwallowingPoison;
LostPrey( true ); // Remove all evidence
m_flDigestFinish = 0;
if ( poisoned )
{ // hurt me
TakeDamage( CTakeDamageInfo( this, this, m_iHealth, DMG_ACID ) );
}
#else
LostPrey( true ); // Remove all evidence
m_flDigestFinish = 0;
#endif
}
}
}
else
{
// Were we lifting prey?
if ( m_bSwallowingPrey || m_bLiftingPrey )
{
// Something removed our prey.
LostPrey( false );
}
// barnacle has no prey right now, so just idle and check to see if anything is touching the tongue.
// If idle and no nearby client, don't think so often
// NOTE: Use the surrounding bounds so that we'll think often event if the tongue
// tip is in the PVS but the body isn't
Vector vecSurroundMins, vecSurroundMaxs;
CollisionProp()->WorldSpaceSurroundingBounds( &vecSurroundMins, &vecSurroundMaxs );
if ( !UTIL_FindClientInPVS( vecSurroundMins, vecSurroundMaxs ) )
{
SetNextThink( gpGlobals->curtime + random->RandomFloat(1,1.5) ); // Stagger a bit to keep barnacles from thinking on the same frame
}
if ( IsActivityFinished() && GetActivity() != ACT_IDLE )
{
// this is done so barnacle will fidget.
// Add some variation because we're often in large bunches
SetActivity( ACT_IDLE );
SetPlaybackRate( random->RandomFloat( 0.8f, 1.2f ) );
}
if ( m_cGibs && random->RandomInt(0,99) == 1 )
{
// cough up a gib.
CGib::SpawnSpecificGibs( this, 1, 50, 1, "models/gibs/hgibs_rib.mdl");
m_cGibs--;
EmitSound( "NPC_Barnacle.Digest" );
}
pTouchEnt = TongueTouchEnt( &flLength );
// If there's something under us, lower the tongue down so we can grab it
if ( m_flAltitude < flLength )
{
float dt = gpGlobals->curtime - GetLastThink();
SetAltitude( m_flAltitude + m_flBarnaclePullSpeed * dt );
}
// NOTE: SetAltitude above will change m_flAltitude, hence the second check
if ( m_flAltitude >= flLength )
{
// If we're already low enough, try to grab.
bool bGrabbedTarget = false;
if ( ( pTouchEnt != NULL ) && ( pTouchEnt != m_hLastSpitEnemy.Get() ) )
{
// tongue is fully extended, and is touching someone.
CBaseCombatCharacter *pBCC = dynamic_cast<CBaseCombatCharacter *>(pTouchEnt);
if( CanPickup( pBCC ) )
{
Vector vecGrabPos = pTouchEnt->EyePosition();
if( !pBCC || pBCC->DispatchInteraction( g_interactionBarnacleVictimGrab, &vecGrabPos, this ) )
{
EmitSound( "NPC_Barnacle.BreakNeck" );
AttachTongueToTarget( pTouchEnt, vecGrabPos );
// Set the local timer to 60 seconds, which starts the lifting phase on
// the upshot of the sine wave which right away makes it more obvious
// that the player is being lifted.
m_flLocalTimer = 60.0f;
m_vLastEnemyPos = pTouchEnt->GetAbsOrigin();
m_flLastPull = 0;
m_StuckTimer.Set(3.0);
bGrabbedTarget = true;
// Set our touch flag so no one else tries to grab us this frame
pTouchEnt->AddEFlags( EFL_IS_BEING_LIFTED_BY_BARNACLE );
}
}
}
if ( !bGrabbedTarget )
{
// Restore the hanging spring constant
if ( m_hTongueTip )
{
m_hTongueTip->m_pSpring->SetSpringConstant( BARNACLE_TONGUE_SPRING_CONSTANT_HANGING );
}
SetAltitude( flLength );
}
}
}
// NDebugOverlay::Box( GetAbsOrigin() - Vector( 0, 0, m_flAltitude ), Vector( -2, -2, -2 ), Vector( 2, 2, 2 ), 255,255,255, 0, 0.1 );
StudioFrameAdvance();
DispatchAnimEvents( this );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
bool CNPC_Barnacle::CanPickup( CBaseCombatCharacter *pBCC )
{
// Barnacle can pick this item up because it has already passed the filters
// in TongueTouchEnt. It just isn't an NPC or player and doesn't need further inspection.
if( !pBCC )
return true;
// Don't pickup turrets
if( FClassnameIs( pBCC, "npc_turret_floor" ) )
return false;
// Don't pick up a dead player or NPC
if( !pBCC->IsAlive() )
return false;
if( pBCC->IsPlayer() )
{
CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>(pBCC);
Assert( pPlayer != NULL );
// Don't pick up a player held by another barnacle
if( pPlayer->HasPhysicsFlag(PFLAG_ONBARNACLE) )
return false;
}
else if ( pBCC->IsInAVehicle() )
{
// Don't pluck an NPC from a vehicle.
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Allows the ragdoll to settle before biting it
//-----------------------------------------------------------------------------
bool CNPC_Barnacle::WaitForRagdollToSettle( float flBiteZOffset )
{
Vector vecVictimPos = GetEnemy()->GetAbsOrigin();
Vector vecCheckPos;
QAngle vecBoneAngles;
m_hRagdoll->GetBonePosition( m_iGrabbedBoneIndex, vecCheckPos, vecBoneAngles );
// Stop sucking while we wait for the ragdoll to settle
SetActivity( ACT_IDLE );
Vector vecVelocity;
AngularImpulse angVel;
float flDelta = 4.0;
// Only bite if the target bone is in the right position.
Vector vecBitePoint = GetAbsOrigin();
vecBitePoint.z -= flBiteZOffset;
//NDebugOverlay::Box( vecBitePoint, -Vector(10,10,10), Vector(10,10,10), 0,255,0, 0, 0.1 );
//NDebugOverlay::Line( vecBitePoint, vecCheckPos, 0, 255, 0, true, 0.1 );
if ( (vecBitePoint.x - vecCheckPos.x) > flDelta || (vecBitePoint.y - vecCheckPos.y) > flDelta )
{
// I can't bite this critter because it's not lined up with me on the X/Y plane. If it is
// as close to my mouth as I can get it, I should drop it.
if( vecBitePoint.z - vecVictimPos.z < 72.0f )
{
// A man-sized target has been pulled up to my mouth, but
// is not aligned for biting. Drop it.
SpitPrey();
}
return false;
}
// Right height?
if ( (vecBitePoint.z - vecCheckPos.z) > flDelta )
{
// Slowly raise / lower the target into the right position
if ( vecBitePoint.z > vecCheckPos.z )
{
// Pull the victim towards the mouth
SetAltitude( m_flAltitude - 1 );
vecVictimPos.z += 1;
}
else
{
// We pulled 'em up too far, so lower them a little
SetAltitude( m_flAltitude + 1 );
vecVictimPos.z -= 1;
}
UTIL_SetOrigin ( GetEnemy(), vecVictimPos );
return false;
}
// Get the velocity of the bone we've grabbed, and only bite when it's not moving much
CStudioHdr *pStudioHdr = m_hRagdoll->GetModelPtr();
mstudiobone_t *pBone = pStudioHdr->pBone( m_iGrabbedBoneIndex );
int iBoneIndex = pBone->physicsbone;
ragdoll_t *pRagdoll = m_hRagdoll->GetRagdoll();
IPhysicsObject *pRagdollPhys = pRagdoll->list[iBoneIndex].pObject;
pRagdollPhys->GetVelocity( &vecVelocity, &angVel );
return ( vecVelocity.LengthSqr() < 20 );
}
//-----------------------------------------------------------------------------
// Allows the physics prop to settle before biting it
//-----------------------------------------------------------------------------
bool CNPC_Barnacle::WaitForPhysicsObjectToSettle( float flBiteZOffset )
{
--m_nShakeCount;
if ( m_nShakeCount & 0x1 )
{
SetAltitude( flBiteZOffset + 15 );
}
else
{
SetAltitude( flBiteZOffset );
}
return ( m_nShakeCount <= 0 );
/*
IPhysicsObject *pPhysicsObject = GetEnemy()->VPhysicsGetObject();
Vector vecVelocity;
AngularImpulse angVel;
pPhysicsObject->GetVelocity( &vecVelocity, &angVel );
return ( vecVelocity.LengthSqr() < 25 );
*/
}
//-----------------------------------------------------------------------------
// Purpose: Make a horrific noise before we pull the prey stuck to our tongue up towards our mouth
//-----------------------------------------------------------------------------
void CNPC_Barnacle::PlayLiftingScream( float flBiteZOffset )
{
if ( !m_bPlayedPullSound && m_flAltitude < (flBiteZOffset + 100) )
{
EmitSound( "NPC_Barnacle.Scream" );
m_bPlayedPullSound = true;
}
}
//-----------------------------------------------------------------------------
// Purpose: Lift the prey stuck to our tongue up towards our mouth
//-----------------------------------------------------------------------------
void CNPC_Barnacle::PullEnemyTorwardsMouth( bool bAdjustEnemyOrigin )
{
CBaseEntity *pEnemy = GetEnemy();
if ( pEnemy->IsPlayer() && pEnemy->GetMoveType() == MOVETYPE_NOCLIP )
{
LostPrey( false );
return;
}
// Pull the victim towards the mouth
float dt = gpGlobals->curtime - GetLastThink();
// Assumes constant frame rate :|
m_flLocalTimer += dt;
float flPull = fabs(sin( m_flLocalTimer * 5 ));
flPull *= m_flBarnaclePullSpeed * dt;
SetAltitude( m_flAltitude - flPull );
if ( bAdjustEnemyOrigin )
{
if ( m_flLastPull > 1.0 )
{
if ( (pEnemy->GetAbsOrigin() - m_vLastEnemyPos).LengthSqr() < Square( m_flLastPull - 1.0 ) )
{
if ( m_StuckTimer.Expired() )
{
LostPrey( false );
return;
}
}
else
{
m_StuckTimer.Set(3.0);
}
}
else
m_StuckTimer.Delay(dt);
m_vLastEnemyPos = pEnemy->GetAbsOrigin();
m_flLastPull = flPull;
Vector vecNewPos = m_vLastEnemyPos;
// vecNewPos.z += flPull;
#if 0
// this is an example of one somewhat crude attempt to realign objects so that they are directly underneath
// the barnacle. It introduces unacceptable oscillation.
const float MAX_CENTERING_VELOCITY = 24.0f;
float distToMove = MAX_CENTERING_VELOCITY * dt;
Vector2D vToCenter = GetAbsOrigin().AsVector2D() - GetEnemy()->GetAbsOrigin().AsVector2D();
float distFromCenter = vToCenter.NormalizeInPlace();
Msg("<%.3f,%.3f>\n",vToCenter.x,vToCenter.y);
if ( distFromCenter < distToMove )
{
vecNewPos.x = GetAbsOrigin().x;
vecNewPos.y = GetAbsOrigin().y;
}
else
{
vToCenter *= distToMove;
vecNewPos.x += vToCenter.x;
vecNewPos.y += vToCenter.y;
// GetEnemy()->Teleport( &vecNewPos, NULL, NULL );
}
#endif
// recentering the player under the barnacle was tried in the code
// below, but then disabled for Orange Box ship because the viewmodel
// jitter became unacceptably noisy after other changes to physics
// and client.
#if 0
// this technique is a little noisy and needs to be readdressed.
if (pEnemy->IsPlayer())
{
Vector playerOrigin = GetEnemy()->GetAbsOrigin();
Vector2D vToCenter = GetAbsOrigin().AsVector2D() - playerOrigin.AsVector2D();
float distFromCenter = vToCenter.NormalizeInPlace();
// if we're off by more than a few inches
if ( distFromCenter > 6.0f )
{
// get us there in a second
Vector desiredVelocity;
float distToMove = min(distFromCenter, 24.0f * dt);
desiredVelocity.x = vToCenter.x * distToMove;
desiredVelocity.y = vToCenter.y * distToMove;
desiredVelocity.z = 0;
#if 0 // here is a physical force-based way (too noisy!):
IPhysicsObject *pTonguePhys = m_hTongueTip->VPhysicsGetObject();
pTonguePhys->ApplyForceCenter(desiredVelocity);
#else
vecNewPos = playerOrigin + desiredVelocity;
// find how far we can actually transport the player
trace_t tr;
UTIL_TraceEntity( pEnemy, playerOrigin, vecNewPos, MASK_PLAYERSOLID, m_hTongueTip.Get(), pEnemy->GetCollisionGroup(), &tr );
pEnemy->Teleport(&tr.endpos, NULL, &desiredVelocity);
#endif
}
}
#endif
// GetEnemy()->Teleport( &vecNewPos, NULL, NULL );
if( pEnemy->GetFlags() & FL_ONGROUND )
{
// Try to fight OnGround
pEnemy->SetGravity( 0 );
pEnemy->RemoveFlag( FL_ONGROUND );
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CNPC_Barnacle::UpdatePlayerConstraint( void )
{
// Check to see if the player's standing/ducking state has changed.
CBasePlayer *pPlayer = static_cast<CBasePlayer*>( GetEnemy() );
bool bStanding = ( ( pPlayer->GetFlags() & FL_DUCKING ) == 0 );
if ( bStanding == m_bPlayerWasStanding )
return;
// if player is on the ladder, disengage him
if ( pPlayer->GetMoveType() == MOVETYPE_LADDER )
{
pPlayer->ExitLadder();
}
// Destroy the current constraint.
physenv->DestroyConstraint( m_pConstraint );
m_pConstraint = NULL;
if ( m_hTongueTip )
{
// Create the new constraint for the standing/ducking player physics object.
IPhysicsObject *pPlayerPhys = pPlayer->VPhysicsGetObject();
IPhysicsObject *pTonguePhys = m_hTongueTip->VPhysicsGetObject();
constraint_fixedparams_t fixed;
fixed.Defaults();
fixed.InitWithCurrentObjectState( pTonguePhys, pPlayerPhys );
fixed.constraint.Defaults();
m_pConstraint = physenv->CreateFixedConstraint( pTonguePhys, pPlayerPhys, NULL, fixed );
}
// Save state for the next check.
m_bPlayerWasStanding = bStanding;
}
//-----------------------------------------------------------------------------
// Purpose: Lift the prey stuck to our tongue up towards our mouth
//-----------------------------------------------------------------------------
void CNPC_Barnacle::LiftPlayer( float flBiteZOffset )
{
// Add an additional height for the player to avoid view clipping
flBiteZOffset += 25.0;
// Play a scream when we're almost within bite range
PlayLiftingScream( flBiteZOffset );
// Update player constraint.
UpdatePlayerConstraint();
// Figure out when the prey has reached our bite range use eye position to avoid
// clipping into the barnacle body
if ( GetAbsOrigin().z - GetEnemy()->EyePosition().z < flBiteZOffset)
{
m_bLiftingPrey = false;
// Start the bite animation. The anim event in it will finish the job.
SetActivity( (Activity)ACT_BARNACLE_BITE_PLAYER );
}
else
{
PullEnemyTorwardsMouth( true );
}
}
//-----------------------------------------------------------------------------
// Purpose: Lift the prey stuck to our tongue up towards our mouth
//-----------------------------------------------------------------------------
void CNPC_Barnacle::LiftNPC( float flBiteZOffset )
{
// Necessary to make the NPCs not do things like talk
GetEnemy()->AddEFlags( EFL_IS_BEING_LIFTED_BY_BARNACLE );
// Play a scream when we're almost within bite range
PlayLiftingScream( flBiteZOffset );
// Figure out when the prey has reached our bite range
if ( GetAbsOrigin().z - m_vecTip.Get().z < flBiteZOffset )
{
m_bLiftingPrey = false;
const Vector &vecSize = GetEnemy()->CollisionProp()->OBBSize();
if ( vecSize.z < 40 )
{
// Start the bite animation. The anim event in it will finish the job.
SetActivity( (Activity)ACT_BARNACLE_BITE_SMALL_THINGS );
}
else
{
// Start the bite animation. The anim event in it will finish the job.
SetActivity( (Activity)ACT_BARNACLE_BITE_HUMAN );
}
}
else
{
PullEnemyTorwardsMouth( true );
}
}
//-----------------------------------------------------------------------------
// Purpose: Lift the prey stuck to our tongue up towards our mouth
//-----------------------------------------------------------------------------
void CNPC_Barnacle::LiftRagdoll( float flBiteZOffset )
{
// Necessary to make the NPCs not do things like talk
GetEnemy()->AddEFlags( EFL_IS_BEING_LIFTED_BY_BARNACLE );
// Play a scream when we're almost within bite range
PlayLiftingScream( flBiteZOffset );
// Figure out when the prey has reached our bite range
if ( GetAbsOrigin().z - m_vecTip.Get().z < flBiteZOffset )
{
// If we've got a ragdoll, wait until the bone is down below the mouth.
if ( !WaitForRagdollToSettle( flBiteZOffset ) )
return;
if ( GetEnemy()->Classify() == CLASS_ZOMBIE )
{
// lifted the prey high enough to see it's a zombie. Spit it out.
if ( hl2_episodic.GetBool() )
{
m_bLiftingPrey = false;
SetActivity( (Activity)ACT_BARNACLE_BITE_SMALL_THINGS );
}
else
{
SpitPrey();
}
return;
}
m_bLiftingPrey = false;
const Vector &vecSize = GetEnemy()->CollisionProp()->OBBSize();
if ( vecSize.z < 40 )
{
// Start the bite animation. The anim event in it will finish the job.
SetActivity( (Activity)ACT_BARNACLE_BITE_SMALL_THINGS );
}
else
{
// Start the bite animation. The anim event in it will finish the job.
SetActivity( (Activity)ACT_BARNACLE_BITE_HUMAN );
}
}
else
{
// Pull the victim towards the mouth
PullEnemyTorwardsMouth( false );
// Apply forces to the attached ragdoll based upon the animations of the enemy, if the enemy is still alive.
if ( GetEnemy()->IsAlive() )
{
CBaseAnimating *pAnimating = dynamic_cast<CBaseAnimating*>( GetEnemy() );
// Get the current bone matrix
/*
Vector pos[MAXSTUDIOBONES];
Quaternion q[MAXSTUDIOBONES];
matrix3x4_t pBoneToWorld[MAXSTUDIOBONES];
CalcPoseSingle( pStudioHdr, pos, q, pAnimating->GetSequence(), pAnimating->m_flCycle, pAnimating->GetPoseParameterArray(), BONE_USED_BY_ANYTHING );
Studio_BuildMatrices( pStudioHdr, vec3_angle, vec3_origin, pos, q, -1, pBoneToWorld, BONE_USED_BY_ANYTHING );
// Apply the forces to the ragdoll
RagdollApplyAnimationAsVelocity( *(m_hRagdoll->GetRagdoll()), pBoneToWorld );
*/
// Get the current bone matrix
matrix3x4_t pBoneToWorld[MAXSTUDIOBONES];
pAnimating->SetupBones( pBoneToWorld, BONE_USED_BY_ANYTHING );
// Apply the forces to the ragdoll
RagdollApplyAnimationAsVelocity( *(m_hRagdoll->GetRagdoll()), m_pRagdollBones, pBoneToWorld, 0.2 );
// Store off the current bone matrix for next time
pAnimating->SetupBones( m_pRagdollBones, BONE_USED_BY_ANYTHING );
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Lift the prey stuck to our tongue up towards our mouth
//-----------------------------------------------------------------------------
void CNPC_Barnacle::LiftPhysicsObject( float flBiteZOffset )
{
CBaseEntity *pVictim = GetEnemy();
// Bite a little higher up, since the bits point is the tip of the tongue
flBiteZOffset -= 5.0f;
//NDebugOverlay::Box( vecCheckPos, -Vector(10,10,10), Vector(10,10,10), 255,255,255, 0, 0.1 );
// Play a scream when we're almost within bite range
PlayLiftingScream( flBiteZOffset );
// Figure out when the prey has reached our bite range
if ( GetAbsOrigin().z - m_vecTip.Get().z < flBiteZOffset ) // then yes, let's chomp
{
if ( m_hTongueTip )
{
m_hTongueTip->m_pSpring->SetSpringConstant( BARNACLE_TONGUE_SPRING_CONSTANT_HANGING );
}
// Wait until the physics object stops flailing
if ( !WaitForPhysicsObjectToSettle( flBiteZOffset ) )
return;
// Necessary for good +use interactions
pVictim->RemoveEFlags( EFL_IS_BEING_LIFTED_BY_BARNACLE );
// If we got a physics prop, wait until the thing has settled down
m_bLiftingPrey = false;
if ( hl2_episodic.GetBool() )
{
CBounceBomb *pBounce = dynamic_cast<CBounceBomb *>( pVictim );
if ( pBounce )
{
if ( m_bSwallowingBomb == true )
{
pBounce->ExplodeThink();
return;
}
SetActivity( (Activity)ACT_BARNACLE_BITE_SMALL_THINGS );
}
else
{
// Start the bite animation. The anim event in it will finish the job.
SetActivity( (Activity)ACT_BARNACLE_TASTE_SPIT );
}
}
else
{
// Start the bite animation. The anim event in it will finish the job.
SetActivity( (Activity)ACT_BARNACLE_TASTE_SPIT );
}
#ifdef HL2_EPISODIC
// if the object is a combatclass, send it a chomp interaction in case it wants to respond to that
// in some nonstandard way.
CBaseCombatCharacter *pBCC = dynamic_cast<CBaseCombatCharacter *>(pVictim);
if( pBCC )
{
Vector tipPos = m_vecTip.Get();
pBCC->DispatchInteraction( g_interactionBarnacleVictimBite, &tipPos, this );
}
#endif
}
else
{
// Necessary for good +use interactions
pVictim->AddEFlags( EFL_IS_BEING_LIFTED_BY_BARNACLE );
// Pull the victim towards the mouth
PullEnemyTorwardsMouth( false );
}
}
//-----------------------------------------------------------------------------
// Purpose: Lift the prey stuck to our tongue up towards our mouth
//-----------------------------------------------------------------------------
void CNPC_Barnacle::LiftPrey( void )
{
CBaseEntity *pVictim = GetEnemy();
Assert( pVictim );
// Drop the prey if it's been obscured by something
trace_t tr;
AI_TraceLine( WorldSpaceCenter(), pVictim->WorldSpaceCenter(), MASK_SOLID, this, COLLISION_GROUP_NONE, &tr );
bool bEnemyIsNPC = IsEnemyAnNPC() && !IsEnemyARagdoll();
if ( ( bEnemyIsNPC && !pVictim->IsAlive() ) || (tr.fraction < 1.0 && tr.m_pEnt != pVictim && tr.m_pEnt != m_hRagdoll) )
{
if ( !GetEnemy()->IsPlayer() )
{
// ignore the object so we don't get into a loop of trying to pick it up.
m_hLastSpitEnemy = GetEnemy();
}
LostPrey( false );
return;
}
// Height from the barnacle's origin to the point at which it bites
float flBiteZOffset = 60.0;
if ( IsEnemyAPlayer() )
{
LiftPlayer(flBiteZOffset);
}
else if ( IsEnemyARagdoll() )
{
LiftRagdoll(flBiteZOffset);
}
else if ( bEnemyIsNPC )
{
LiftNPC(flBiteZOffset);
}
else
{
LiftPhysicsObject(flBiteZOffset);
}
if ( m_hRagdoll )
{
QAngle newAngles( 0, m_hRagdoll->GetAbsAngles()[YAW], 0 );
Vector centerDelta = m_hRagdoll->WorldSpaceCenter() - GetEnemy()->WorldSpaceCenter();
Vector newOrigin = GetEnemy()->GetAbsOrigin() + centerDelta;
GetEnemy()->SetAbsOrigin( newOrigin );
GetEnemy()->SetAbsAngles( newAngles );
}
}
//-----------------------------------------------------------------------------
// Purpose: Attach a serverside ragdoll prop for the specified entity to our tongue
//-----------------------------------------------------------------------------
CRagdollProp *CNPC_Barnacle::AttachRagdollToTongue( CBaseAnimating *pAnimating )
{
// Find his head bone
m_iGrabbedBoneIndex = -1;
Vector vecNeckOffset;
if ( m_hTongueTip )
{
vecNeckOffset = (pAnimating->EyePosition() - m_hTongueTip->GetAbsOrigin());
}
CStudioHdr *pHdr = pAnimating->GetModelPtr();
if ( pHdr )
{
int set = pAnimating->GetHitboxSet();
for( int i = 0; i < pHdr->iHitboxCount(set); i++ )
{
mstudiobbox_t *pBox = pHdr->pHitbox( i, set );
if ( !pBox )
continue;
if ( pBox->group == HITGROUP_HEAD )
{
m_iGrabbedBoneIndex = pBox->bone;
break;
}
}
}
// HACK: Until we have correctly assigned hitgroups on our models, lookup the bones
// for the models that we know are in the barnacle maps.
//m_iGrabbedBoneIndex = pAnimating->LookupBone( "Bip01 L Foot" );
if ( m_iGrabbedBoneIndex == -1 )
{
// Citizens, Conscripts
m_iGrabbedBoneIndex = pAnimating->LookupBone( "Bip01 Head" );
}
if ( m_iGrabbedBoneIndex == -1 )
{
// Metrocops, Combine soldiers
m_iGrabbedBoneIndex = pAnimating->LookupBone( "ValveBiped.Bip01_Head1" );
}
if ( m_iGrabbedBoneIndex == -1 )
{
// Vortigaunts
m_iGrabbedBoneIndex = pAnimating->LookupBone( "ValveBiped.head" );
}
if ( m_iGrabbedBoneIndex == -1 )
{
// Bullsquids
m_iGrabbedBoneIndex = pAnimating->LookupBone( "Bullsquid.Head_Bone1" );
}
if ( m_iGrabbedBoneIndex == -1 )
{
// Just use the first bone
m_iGrabbedBoneIndex = 0;
}
// Move the tip to the bone
Vector vecBonePos;
QAngle vecBoneAngles;
pAnimating->GetBonePosition( m_iGrabbedBoneIndex, vecBonePos, vecBoneAngles );
if ( m_hTongueTip )
{
m_hTongueTip->Teleport( &vecBonePos, NULL, NULL );
}
//NDebugOverlay::Box( vecBonePos, -Vector(5,5,5), Vector(5,5,5), 255,255,255, 0, 10.0 );
// Create the ragdoll attached to tongue
IPhysicsObject *pTonguePhysObject = m_hTongueTip->VPhysicsGetObject();
CRagdollProp *pRagdoll = CreateServerRagdollAttached( pAnimating, vec3_origin, -1, COLLISION_GROUP_NONE, pTonguePhysObject, m_hTongueTip, 0, vecBonePos, m_iGrabbedBoneIndex, vec3_origin );
if ( pRagdoll )
{
#if HL2_EPISODIC
PhysEnableEntityCollisions( this, pAnimating );
PhysDisableEntityCollisions( this, pRagdoll );
#endif
pRagdoll->DisableAutoFade();
pRagdoll->SetThink( NULL );
}
return pRagdoll;
}
void CNPC_Barnacle::InputSetDropTongueSpeed( inputdata_t &inputdata )
{
m_flBarnaclePullSpeed = inputdata.value.Int();
}
void CNPC_Barnacle::InputDropTongue( inputdata_t &inputdata )
{
DropTongue();
}
//-----------------------------------------------------------------------------
// Purpose: Grab the specified target with our tongue
//-----------------------------------------------------------------------------
void CNPC_Barnacle::AttachTongueToTarget( CBaseEntity *pTouchEnt, Vector vecGrabPos )
{
#if HL2_EPISODIC
m_OnGrab.Set( pTouchEnt, this, this );
#endif
// Reset this valricue each time we attach prey. If it needs to be reduced, code below will do so.
m_flBarnaclePullSpeed = BARNACLE_PULL_SPEED;
if ( RandomFloat(0,1) > 0.5 )
{
EmitSound( "NPC_Barnacle.PullPant" );
}
else
{
EmitSound( "NPC_Barnacle.TongueStretch" );
}
SetActivity( (Activity)ACT_BARNACLE_SLURP );
// Get the player out of the vehicle he's in.
if ( pTouchEnt->IsPlayer() )
{
CBasePlayer *pPlayer = static_cast<CBasePlayer*>(pTouchEnt);
if ( pPlayer->IsInAVehicle() )
{
pPlayer->LeaveVehicle( pPlayer->GetAbsOrigin(), pPlayer->GetAbsAngles() );
// The player could have warped through the tongue while on a high-speed vehicle.
// Move him back under the barnacle.
Vector vecDelta;
VectorSubtract( pPlayer->GetAbsOrigin(), GetAbsOrigin(), vecDelta );
vecDelta.z = 0.0f;
float flDist = VectorNormalize( vecDelta );
if ( flDist > 20 )
{
Vector vecNewPos;
VectorMA( GetAbsOrigin(), 20, vecDelta, vecNewPos );
vecNewPos.z = pPlayer->GetAbsOrigin().z;
pPlayer->SetAbsOrigin( vecNewPos );
}
}
m_bPlayerWasStanding = ( ( pPlayer->GetFlags() & FL_DUCKING ) == 0 );
}
SetEnemy( pTouchEnt );
#if HL2_EPISODIC
// Disable collision between myself and the obejct I've seized.
PhysDisableEntityCollisions( this, pTouchEnt );
#endif
// teleporting the player in this way is illegitimate -- try it in third person to see the problem
if ( /* pTouchEnt->IsPlayer() || */ pTouchEnt->MyNPCPointer() )
{
Vector origin = GetAbsOrigin();
origin.z = pTouchEnt->GetAbsOrigin().z;
CTraceFilterSkipTwoEntities traceFilter( this, pTouchEnt, COLLISION_GROUP_NONE );
trace_t placementTrace;
UTIL_TraceHull( origin, origin, pTouchEnt->WorldAlignMins(), pTouchEnt->WorldAlignMaxs(), MASK_NPCSOLID, &traceFilter, &placementTrace );
if ( placementTrace.startsolid )
{
UTIL_TraceHull( origin + Vector(0, 0, 24), origin, pTouchEnt->WorldAlignMins(), pTouchEnt->WorldAlignMaxs(), MASK_NPCSOLID, &traceFilter, &placementTrace );
if ( !placementTrace.startsolid )
{
pTouchEnt->SetAbsOrigin( placementTrace.endpos );
// pTouchEnt->Teleport( &placementTrace.endpos, NULL, NULL );
}
}
else
{
pTouchEnt->SetAbsOrigin( origin );
// pTouchEnt->Teleport( &origin, NULL, NULL );
}
}
m_nShakeCount = 6;
m_bLiftingPrey = true;// indicate that we should be lifting prey.
SetAltitude( (GetAbsOrigin().z - vecGrabPos.z) );
m_bPlayedPullSound = false;
CBaseAnimating *pAnimating = dynamic_cast<CBaseAnimating*>(pTouchEnt);
if ( IsEnemyAPlayer() || IsEnemyAPhysicsObject() )
{
// The player (and phys objects) doesn't ragdoll, so just grab him and pull him up manually
IPhysicsObject *pPlayerPhys = pTouchEnt->VPhysicsGetObject();
IPhysicsObject *pTonguePhys = m_hTongueTip->VPhysicsGetObject();
Vector vecGrabPos;
if ( pTouchEnt->IsPlayer() )
{
vecGrabPos = pTouchEnt->EyePosition();
#if BARNACLE_USE_TONGUE_OFFSET
VectorRotate( m_svPlayerHeldTipOffset, pTouchEnt->EntityToWorldTransform(), m_vecTipDrawOffset.GetForModify() );
m_vecTipDrawOffset.GetForModify().z = m_svPlayerHeldTipOffset.z;
#endif
// pTonguePhys->GetPosition(&vecGrabPos,NULL);
}
else
{
VectorSubtract( m_vecTip, pTouchEnt->GetAbsOrigin(), vecGrabPos );
VectorNormalize( vecGrabPos );
vecGrabPos = physcollision->CollideGetExtent( pPlayerPhys->GetCollide(), pTouchEnt->GetAbsOrigin(), pTouchEnt->GetAbsAngles(), vecGrabPos );
#if BARNACLE_USE_TONGUE_OFFSET
m_vecTipDrawOffset.GetForModify().Zero();
#endif
}
m_hTongueTip->Teleport( &vecGrabPos, NULL, NULL );
float flDist = (vecGrabPos - GetAbsOrigin() ).Length();
float flTime = flDist / m_flBarnaclePullSpeed;
// If this object would be pulled in too quickly, change the pull speed.
if( flTime < BARNACLE_MIN_PULL_TIME )
{
m_flBarnaclePullSpeed = flDist / BARNACLE_MIN_PULL_TIME;
}
constraint_fixedparams_t fixed;
fixed.Defaults();
fixed.InitWithCurrentObjectState( pTonguePhys, pPlayerPhys );
fixed.constraint.Defaults();
/*
You can use this stanza to try to counterplace the constraint on the player's head so he gets hauled sideways to the right place on the barnacle, but it is better to just move the tongue before attachment.
if ( IsEnemyAPlayer() )
{
Vector2D vToCenter = GetAbsOrigin().AsVector2D() - pTouchEnt->EyePosition().AsVector2D();
fixed.attachedRefXform[0][3] -= vToCenter.x ;
fixed.attachedRefXform[1][3] -= vToCenter.y ;
}
*/
m_pConstraint = physenv->CreateFixedConstraint( pTonguePhys, pPlayerPhys, NULL, fixed );
// Increase the tongue's spring constant while lifting
m_hTongueTip->m_pSpring->SetSpringConstant( BARNACLE_TONGUE_SPRING_CONSTANT_LIFTING );
UpdateTongue();
return;
}
// NPC case...
pAnimating->InvalidateBoneCache();
// Make a ragdoll for the guy, and hide him.
pTouchEnt->AddSolidFlags( FSOLID_NOT_SOLID );
m_hRagdoll = AttachRagdollToTongue( pAnimating );
m_hRagdoll->SetDamageEntity( pAnimating );
// Make it try to blend out of ragdoll on the client on deletion
// NOTE: This isn't fully implemented, so disable
//m_hRagdoll->SetUnragdoll( pAnimating );
// Apply the target's current velocity to each of the ragdoll's bones
Vector vecVelocity = pAnimating->GetGroundSpeedVelocity() * 0.5;
ragdoll_t *pRagdoll = m_hRagdoll->GetRagdoll();
// barnacle might let go if ragdoll is separated - so increase the separation checking a bit
constraint_groupparams_t params;
pRagdoll->pGroup->GetErrorParams( ¶ms );
params.minErrorTicks = MIN( params.minErrorTicks, 5 );
pRagdoll->pGroup->SetErrorParams( params );
for ( int i = 0; i < pRagdoll->listCount; i++ )
{
pRagdoll->list[i].pObject->AddVelocity( &vecVelocity, NULL );
}
if ( npc_barnacle_swallow.GetBool() )
{
m_hRagdoll->SetOverlaySequence( ACT_GESTURE_BARNACLE_STRANGLE );
m_hRagdoll->SetBlendWeight( 1.0f );
}
// Now hide the actual enemy
pTouchEnt->AddEffects( EF_NODRAW );
// Increase the tongue's spring constant while lifting
m_hTongueTip->m_pSpring->SetSpringConstant( BARNACLE_TONGUE_SPRING_CONSTANT_LIFTING );
UpdateTongue();
// Store off the current bone matrix so we have it next frame
pAnimating->SetupBones( m_pRagdollBones, BONE_USED_BY_ANYTHING );
}
//-----------------------------------------------------------------------------
// Spit out the prey; add physics force!
//-----------------------------------------------------------------------------
void CNPC_Barnacle::SpitPrey()
{
if ( GetEnemy() )
{
IPhysicsObject *pObject = GetEnemy()->VPhysicsGetObject();
if (pObject)
{
Vector vecPosition, force;
GetAttachment( m_nSpitAttachment, vecPosition, &force );
force *= pObject->GetMass() * 50.0f;
pObject->ApplyForceOffset( force, vec3_origin );
}
m_hLastSpitEnemy = GetEnemy();
}
LostPrey( false );
}
//-----------------------------------------------------------------------------
// Purpose: Prey is in position, bite them and start swallowing them
//-----------------------------------------------------------------------------
void CNPC_Barnacle::BitePrey( void )
{
Assert( GetEnemy() );
CBaseCombatCharacter *pVictim = GetEnemyCombatCharacterPointer();
#ifdef HL2_EPISODIC
if ( pVictim == NULL )
{
if ( GetEnemy() )
{
CBounceBomb *pBounce = dynamic_cast<CBounceBomb *>( GetEnemy() );
if ( pBounce )
{
// Stop the ragdoll moving and start to pull the sucker up into our mouth
m_bSwallowingPrey = true;
m_bSwallowingBomb = true;
IPhysicsObject *pTonguePhys = m_hTongueTip->VPhysicsGetObject();
// Stop the tongue's spring getting in the way of swallowing
m_hTongueTip->m_pSpring->SetSpringConstant( 0 );
// Switch the tongue tip to shadow and drag it up
pTonguePhys->SetShadow( 1e4, 1e4, false, false );
pTonguePhys->UpdateShadow( m_hTongueTip->GetAbsOrigin(), m_hTongueTip->GetAbsAngles(), false, 0 );
m_hTongueTip->SetMoveType( MOVETYPE_NOCLIP );
m_hTongueTip->SetAbsVelocity( Vector(0,0,32) );
SetAltitude( (GetAbsOrigin().z - m_hTongueTip->GetAbsOrigin().z) );
}
}
return;
}
#endif
Assert( pVictim );
if ( !pVictim )
{
return;
}
EmitSound( "NPC_Barnacle.FinalBite" );
m_flVictimHeight = GetEnemy()->WorldAlignSize().z;
// Kill the victim instantly
int iDamageType = DMG_SLASH | DMG_ALWAYSGIB;
int nDamage;
if ( !pVictim->IsPlayer() )
{
iDamageType |= DMG_ALWAYSGIB;
nDamage = pVictim->m_iHealth;
}
else
{
nDamage = BARNACLE_BITE_DAMAGE_TO_PLAYER;
}
if ( m_hRagdoll )
{
// We've got a ragdoll, so prevent this creating another one
iDamageType |= DMG_REMOVENORAGDOLL;
m_hRagdoll->SetDamageEntity( NULL );
}
#if HL2_EPISODIC
m_bSwallowingPoison = IsPoisonous(pVictim);
unsigned int enemyClass = GetEnemy()->Classify();
#endif
// DMG_CRUSH because we don't wan't to impart physics forces
pVictim->TakeDamage( CTakeDamageInfo( this, this, nDamage, iDamageType | DMG_CRUSH ) );
m_cGibs = 3;
// In episodic, bite the zombie's headcrab off & drop the body
#ifdef HL2_EPISODIC
if ( enemyClass == CLASS_ZOMBIE )
{
if ( m_hRagdoll )
{
m_hRagdoll->SetBodygroup( ZOMBIE_BODYGROUP_HEADCRAB, false );
DetachAttachedRagdoll( m_hRagdoll );
m_hLastSpitEnemy = m_hRagdoll.Get();
m_hRagdoll->EmitSound( "NPC_HeadCrab.Die" );
m_hRagdoll = NULL;
}
// Create some blood to hide the vanishing headcrab
Vector vecBloodPos;
CollisionProp()->NormalizedToWorldSpace( Vector( 0.5f, 0.5f, 0.0f ), &vecBloodPos );
UTIL_BloodSpray( vecBloodPos, Vector(0,0,-1), GetEnemy()->BloodColor(), 8, FX_BLOODSPRAY_ALL );
m_flDigestFinish = gpGlobals->curtime + 10.0;
return;
}
// in episodic, where barnacles can eat antlions, vanish the ragdoll because the gibs will spray everywhere
// and hide it.
if ( enemyClass == CLASS_ANTLION )
{
#ifndef _XBOX
m_nBloodColor = pVictim->BloodColor();
#endif
m_flNextBloodTime = 0.0f;
SprayBlood();
m_flDigestFinish = gpGlobals->curtime + 10.0;
if (m_hRagdoll)
{
UTIL_Remove( m_hRagdoll );
}
if ( m_bSwallowingPoison )
{ // hurt me
TakeDamage( CTakeDamageInfo( this, this, m_iHealth, DMG_ACID ) );
}
return;
}
#endif
// Players are never swallowed, nor is anything we don't have a ragdoll for
if ( !m_hRagdoll || pVictim->IsPlayer() )
{
if ( !pVictim->IsPlayer() || pVictim->GetHealth() <= 0 )
{
LostPrey( false );
}
return;
}
// Stop the ragdoll moving and start to pull the sucker up into our mouth
m_bSwallowingPrey = true;
IPhysicsObject *pTonguePhys = m_hTongueTip->VPhysicsGetObject();
// Make it nonsolid to the world so we can pull it through the roof
PhysDisableEntityCollisions( m_hRagdoll->VPhysicsGetObject(), g_PhysWorldObject );
// Stop the tongue's spring getting in the way of swallowing
m_hTongueTip->m_pSpring->SetSpringConstant( 0 );
// Switch the tongue tip to shadow and drag it up
pTonguePhys->SetShadow( 1e4, 1e4, false, false );
pTonguePhys->UpdateShadow( m_hTongueTip->GetAbsOrigin(), m_hTongueTip->GetAbsAngles(), false, 0 );
m_hTongueTip->SetMoveType( MOVETYPE_NOCLIP );
m_hTongueTip->SetAbsVelocity( Vector(0,0,32) );
SetAltitude( (GetAbsOrigin().z - m_hTongueTip->GetAbsOrigin().z) );
if ( !npc_barnacle_swallow.GetBool() )
return;
// Because the victim is dead, remember the blood color
m_flNextBloodTime = 0.0f;
// NOTE: This was too confusing to people with the more recognizable blood -- jdw
#ifndef _XBOX
m_nBloodColor = pVictim->BloodColor();
#endif
CollisionProp()->NormalizedToWorldSpace( Vector( 0.5f, 0.5f, 0.0f ), &m_vecBloodPos );
// m_hRagdoll->SetOverlaySequence( ACT_DIE_BARNACLE_SWALLOW );
m_hRagdoll->SetBlendWeight( 0.0f );
SprayBlood();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CNPC_Barnacle::SprayBlood()
{
if ( gpGlobals->curtime < m_flNextBloodTime )
return;
m_flNextBloodTime = gpGlobals->curtime + 0.2f;
Vector bloodDir = RandomVector( -1.0f, 1.0f );
bloodDir.z = -fabs( bloodDir.z );
Vector jitterPos = RandomVector( -8, 8 );
jitterPos.z = 0.0f;
#ifndef _XBOX
UTIL_BloodSpray( m_vecBloodPos + jitterPos, Vector( 0,0,-1),
m_nBloodColor, RandomInt( 4, 8 ), RandomInt(0,2) == 0 ? FX_BLOODSPRAY_ALL : FX_BLOODSPRAY_CLOUD );
#else
UTIL_BloodSpray( m_vecBloodPos + jitterPos, Vector( 0,0,-1),
BLOOD_COLOR_YELLOW, RandomInt( 4, 8 ), RandomInt(0,2) == 0 ? FX_BLOODSPRAY_ALL : FX_BLOODSPRAY_CLOUD );
#endif
}
//-----------------------------------------------------------------------------
// Purpose: Slowly swallow the prey whole. Only used on humanoids.
//-----------------------------------------------------------------------------
void CNPC_Barnacle::SwallowPrey( void )
{
if ( IsActivityFinished() )
{
if (GetActivity() == ACT_BARNACLE_BITE_HUMAN )
{
SetActivity( (Activity)ACT_BARNACLE_CHEW_HUMAN );
}
else
{
SetActivity( (Activity)ACT_BARNACLE_CHEW_SMALL_THINGS );
}
}
// Move the body up slowly
Vector vecSwallowPos = m_hTongueTip->GetAbsOrigin();
vecSwallowPos.z -= m_flVictimHeight;
//NDebugOverlay::Box( vecSwallowPos, -Vector(5,5,5), Vector(5,5,5), 255,255,255, 0, 0.1 );
// bite prey every once in a while
if ( random->RandomInt(0,25) == 0 )
{
EmitSound( "NPC_Barnacle.Digest" );
}
// Fully swallowed it?
float flDistanceToGo = GetAbsOrigin().z - vecSwallowPos.z;
if ( flDistanceToGo <= 0 )
{
// He's dead jim
m_bSwallowingPrey = false;
m_hTongueTip->SetAbsVelocity( vec3_origin );
#if HL2_EPISODIC
// digest poisonous things for just a moment before being killed by them (it looks wierd if it's instant)
// Parentheses were probably intended around the ?: part of the expression, but putting them there now
// would change the behavior which is undesirable, so parentheses were placed around the '+' to suppress
// compiler warnings.
m_flDigestFinish = ( gpGlobals->curtime + m_bSwallowingPoison ) ? 0.48f : 10.0f;
#else
m_flDigestFinish = gpGlobals->curtime + 10.0;
#endif
}
if ( npc_barnacle_swallow.GetBool() )
{
SprayBlood();
}
}
//-----------------------------------------------------------------------------
// Purpose: Remove the fake ragdoll and bring the actual enemy back in view
//-----------------------------------------------------------------------------
void CNPC_Barnacle::RemoveRagdoll( bool bDestroyRagdoll )
{
// Destroy the tongue tip constraint
if ( m_pConstraint )
{
physenv->DestroyConstraint( m_pConstraint );
m_pConstraint = NULL;
}
// Remove the ragdoll
if ( m_hRagdoll )
{
// Only destroy the ragdoll if told to. We might be just dropping
// the ragdoll because the target was killed on the way up.
m_hRagdoll->SetDamageEntity( NULL );
if ( npc_barnacle_swallow.GetBool() )
{
m_hRagdoll->SetThink( NULL );
m_hRagdoll->SetBlendWeight( 1.0f );
}
DetachAttachedRagdoll( m_hRagdoll );
if ( bDestroyRagdoll )
{
UTIL_Remove( m_hRagdoll );
}
m_hRagdoll = NULL;
// Reduce the spring constant while we lower
m_hTongueTip->m_pSpring->SetSpringConstant( BARNACLE_TONGUE_SPRING_CONSTANT_LOWERING );
// Unhide the enemy
if ( GetEnemy() )
{
GetEnemy()->RemoveEffects( EF_NODRAW );
GetEnemy()->RemoveSolidFlags( FSOLID_NOT_SOLID );
}
}
}
//-----------------------------------------------------------------------------
// Purpose: For some reason (he was killed, etc) we lost the prey we were dragging towards our mouth.
//-----------------------------------------------------------------------------
void CNPC_Barnacle::LostPrey( bool bRemoveRagdoll )
{
#if HL2_EPISODIC
m_OnRelease.Set( GetEnemy(), this, this );
#endif
CBaseEntity * const pEnemy = GetEnemy();
if ( pEnemy )
{
#if HL2_EPISODIC
PhysEnableEntityCollisions( this, pEnemy );
#endif
//No one survives being snatched by a barnacle anymore, so leave
// this flag set so that their entity gets removed.
//GetEnemy()->RemoveEFlags( EFL_IS_BEING_LIFTED_BY_BARNACLE );
CBaseCombatCharacter *pVictim = GetEnemyCombatCharacterPointer();
if ( pVictim )
{
pVictim->DispatchInteraction( g_interactionBarnacleVictimReleased, NULL, this );
pVictim->RemoveEFlags( EFL_IS_BEING_LIFTED_BY_BARNACLE );
if ( m_hRagdoll )
{
QAngle newAngles( 0, m_hRagdoll->GetAbsAngles()[ YAW ], 0 );
Vector centerDelta = m_hRagdoll->WorldSpaceCenter() - pEnemy->WorldSpaceCenter();
Vector newOrigin = pEnemy->GetAbsOrigin() + centerDelta;
pEnemy->SetAbsOrigin( newOrigin );
pVictim->SetAbsAngles( newAngles );
}
pVictim->SetGroundEntity( NULL );
}
else if ( IsEnemyAPhysicsObject() )
{
// If we're a physics object, then we need to clear this flag
pEnemy->RemoveEFlags( EFL_IS_BEING_LIFTED_BY_BARNACLE );
}
}
RemoveRagdoll( bRemoveRagdoll );
m_bLiftingPrey = false;
m_bSwallowingPrey = false;
#if HL2_EPISODIC
m_bSwallowingPoison = false;
#endif
SetEnemy( NULL );
m_vecTipDrawOffset.GetForModify().Zero();
if ( m_hTongueTip )
{
// Remove our tongue's shadow object, in case we just finished swallowing something
IPhysicsObject *pPhysicsObject = m_hTongueTip->VPhysicsGetObject();
if ( pPhysicsObject && pPhysicsObject->GetShadowController() )
{
Vector vecCenter = WorldSpaceCenter();
m_hTongueTip->Teleport( &vecCenter, NULL, &vec3_origin );
// Reduce the spring constant while we lower
m_hTongueTip->m_pSpring->SetSpringConstant( BARNACLE_TONGUE_SPRING_CONSTANT_LOWERING );
// Start colliding with the world again
pPhysicsObject->RemoveShadowController();
m_hTongueTip->SetMoveType( MOVETYPE_VPHYSICS );
pPhysicsObject->EnableMotion( true );
pPhysicsObject->EnableGravity( true );
pPhysicsObject->RecheckCollisionFilter();
}
}
}
//-----------------------------------------------------------------------------
// The tongue's vphysics updated
//-----------------------------------------------------------------------------
void CNPC_Barnacle::OnTongueTipUpdated()
{
// Update the tip's position
const Vector &vecNewTip = m_hTongueTip->GetAbsOrigin();
if ( vecNewTip != m_vecTip )
{
m_vecTip = vecNewTip;
CollisionProp()->MarkSurroundingBoundsDirty();
}
}
//-----------------------------------------------------------------------------
// Purpose: Update the positions of the tongue points
//-----------------------------------------------------------------------------
void CNPC_Barnacle::UpdateTongue( void )
{
if ( m_hTongueTip == NULL )
return;
// Set the spring's length to that of the tongue's extension
// Compute the rest length of the tongue based on the spring.
// This occurs when mg == kx or x = mg/k
float flRestStretch = (BARNACLE_TONGUE_TIP_MASS * GetCurrentGravity()) / BARNACLE_TONGUE_SPRING_CONSTANT_HANGING;
// FIXME: HACK!!!! The code above doesn't quite make the tip end up in the right place.
// but it should. So, we're gonna hack it the rest of the way.
flRestStretch += 4;
m_hTongueTip->m_pSpring->SetSpringLength( m_flAltitude - flRestStretch );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CNPC_Barnacle::SpawnDeathGibs( void )
{
bool bDroppedAny = false;
// Drop a random number of gibs
for ( int i=0; i < ARRAYSIZE(m_szGibNames); i++ )
{
if ( random->RandomInt( 0, 1 ) )
{
CGib::SpawnSpecificGibs( this, 1, 32, 1, m_szGibNames[i] );
bDroppedAny = true;
}
}
// Make sure we at least drop something
if ( bDroppedAny == false )
{
CGib::SpawnSpecificGibs( this, 1, 32, 1, m_szGibNames[0] );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CNPC_Barnacle::Event_Killed( const CTakeDamageInfo &info )
{
m_OnDeath.FireOutput( info.GetAttacker(), this );
SendOnKilledGameEvent( info );
AddSolidFlags( FSOLID_NOT_SOLID );
m_takedamage = DAMAGE_NO;
m_lifeState = LIFE_DYING;
// Are we lifting prey?
if ( GetEnemy() )
{
// Cleanup
LostPrey( false );
}
else if ( m_bSwallowingPrey && m_hRagdoll )
{
// We're swallowing a body. Make it stick inside us.
m_hTongueTip->SetAbsVelocity( vec3_origin );
m_hRagdoll->StopFollowingEntity();
m_hRagdoll->SetMoveType( MOVETYPE_VPHYSICS );
m_hRagdoll->SetAbsOrigin( m_hTongueTip->GetAbsOrigin() );
m_hRagdoll->RemoveSolidFlags( FSOLID_NOT_SOLID );
m_hRagdoll->SetCollisionGroup( COLLISION_GROUP_DEBRIS );
m_hRagdoll->RecheckCollisionFilter();
if ( npc_barnacle_swallow.GetBool() )
{
m_hRagdoll->SetThink( NULL );
m_hRagdoll->SetBlendWeight( 1.0f );
}
}
else
{
// Destroy the ragdoll->tongue tip constraint
if ( m_pConstraint )
{
physenv->DestroyConstraint( m_pConstraint );
m_pConstraint = NULL;
}
LostPrey( true );
}
// Puke gibs unless we're told to be cheap
bool spawnGibs = ( !HasSpawnFlags( SF_BARNACLE_CHEAP_DEATH ) || random->RandomInt( 0, 1 ) );
if ( spawnGibs )
{
SpawnDeathGibs();
}
// Puke blood
#ifdef _XBOX
UTIL_BloodSpray( GetAbsOrigin(), Vector(0,0,-1), BLOOD_COLOR_YELLOW, 8, FX_BLOODSPRAY_ALL );
#else
UTIL_BloodSpray( GetAbsOrigin(), Vector(0,0,-1), BLOOD_COLOR_RED, 8, FX_BLOODSPRAY_ALL );
#endif
// Put blood on the ground if near enough
trace_t bloodTrace;
AI_TraceLine( GetAbsOrigin(), GetAbsOrigin() - Vector( 0, 0, 256 ), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &bloodTrace);
if ( bloodTrace.fraction < 1.0f )
{
#ifdef _XBOX
UTIL_BloodDecalTrace( &bloodTrace, BLOOD_COLOR_YELLOW );
#else
UTIL_BloodDecalTrace( &bloodTrace, BLOOD_COLOR_RED );
#endif
}
EmitSound( "NPC_Barnacle.Die" );
SetActivity( ACT_DIESIMPLE );
StudioFrameAdvance();
SetNextThink( gpGlobals->curtime + 0.1f );
SetThink ( &CNPC_Barnacle::WaitTillDead );
// we deliberately do not call BaseClass::EventKilled
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CNPC_Barnacle::WaitTillDead ( void )
{
SetNextThink( gpGlobals->curtime + 0.1f );
StudioFrameAdvance();
DispatchAnimEvents ( this );
if ( IsActivityFinished() )
{
// death anim finished.
StopAnimation();
}
float goalAltitude = BARNACLE_DEAD_TONGUE_ALTITUDE;
trace_t tr;
AI_TraceLine( m_vecRoot.Get(), m_vecRoot.Get() - Vector( 0, 0, 256 ), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr );
if ( tr.fraction < 1.0 )
{
float distToFloor = ( m_vecRoot.Get() - tr.endpos ).Length();
float clearance = distToFloor - goalAltitude;
if ( clearance < BARNACLE_MIN_DEAD_TONGUE_CLEARANCE )
{
if ( distToFloor - BARNACLE_MIN_DEAD_TONGUE_CLEARANCE > distToFloor * .5 )
{
goalAltitude = distToFloor - BARNACLE_MIN_DEAD_TONGUE_CLEARANCE;
}
else
{
goalAltitude = distToFloor * .5;
}
}
}
// Keep moving the tongue to its dead position
// FIXME: This stupid algorithm is necessary because
// I can't seem to get reproduceable behavior from springs
bool bTongueInPosition = false;
float flDist = m_vecRoot.Get().z - m_vecTip.Get().z;
if ( fabs(flDist - goalAltitude) > 20.0f )
{
float flNewAltitude;
float dt = gpGlobals->curtime - GetLastThink();
if ( m_flAltitude >= goalAltitude )
{
flNewAltitude = MAX( goalAltitude, m_flAltitude - m_flBarnaclePullSpeed * dt );
}
else
{
flNewAltitude = MIN( goalAltitude, m_flAltitude + m_flBarnaclePullSpeed * dt );
}
SetAltitude( flNewAltitude );
}
else
{
// Wait for settling...
IPhysicsObject *pTipObject = m_hTongueTip->VPhysicsGetObject();
Vector vecVelocity;
AngularImpulse angVel;
pTipObject->GetVelocity( &vecVelocity, &angVel );
if ( vecVelocity.LengthSqr() < 1.0f )
{
// We may need to have a heavier spring constant until we settle
// to avoid strange looking rest conditions (when the tongue is really bent from
// picking up a barrel, it looks strange to switch to the hanging constant)
m_hTongueTip->m_pSpring->SetSpringConstant( BARNACLE_TONGUE_SPRING_CONSTANT_HANGING );
if ( fabs(flDist - goalAltitude) > 1.0f )
{
float flSign = ( flDist > goalAltitude ) ? -1.0f : 1.0f;
SetAltitude( m_flAltitude + flSign );
}
else if ( vecVelocity.LengthSqr() < 0.01f )
{
bTongueInPosition = ( fabs(flDist - goalAltitude) <= 1.0f );
}
}
}
if ( IsActivityFinished() && bTongueInPosition )
{
// Remove our tongue pieces
UTIL_Remove( m_hTongueTip );
UTIL_Remove( m_hTongueRoot );
m_hTongueTip = NULL;
m_hTongueRoot = NULL;
SetThink ( NULL );
m_lifeState = LIFE_DEAD;
}
else
{
UpdateTongue();
}
}
#if HL2_EPISODIC
//=========================================================
// Some creatures are poisonous to barnacles, and the barnacle
// will die after consuming them. This determines if a given
// entity is one of those things.
// todo: could be a bit faster
//=========================================================
bool CNPC_Barnacle::IsPoisonous( CBaseEntity *pVictim )
{
if (!pVictim)
return false;
if ( FClassnameIs(pVictim,"npc_headcrab_poison") )
return true;
if ( FClassnameIs(pVictim,"npc_headcrab_black") )
return true;
if ( FClassnameIs(pVictim,"npc_antlion") &&
static_cast<CNPC_Antlion *>(pVictim)->IsWorker()
)
return true;
return false;
}
//=========================================================
// script input to immediately abandon whatever I am lifting
//=========================================================
void CNPC_Barnacle::InputLetGo( inputdata_t &inputdata )
{
if ( GetEnemy() )
{
if ( !GetEnemy()->IsPlayer() )
{
// ignore the object so we don't get into a loop of trying to pick it up.
m_hLastSpitEnemy = GetEnemy();
}
LostPrey( false );
}
}
// Barnacle has custom impact damage tables, so it can take grave damage from sawblades.
static impactentry_t barnacleLinearTable[] =
{
{ 150*150, 5 },
{ 250*250, 10 },
{ 350*350, 50 },
{ 500*500, 100 },
{ 1000*1000, 500 },
};
static impactentry_t barnacleAngularTable[] =
{
{ 100*100, 35 }, // Sawblade always kills.
{ 200*200, 50 },
{ 250*250, 500 },
};
static impactdamagetable_t gBarnacleImpactDamageTable =
{
barnacleLinearTable,
barnacleAngularTable,
ARRAYSIZE(barnacleLinearTable),
ARRAYSIZE(barnacleAngularTable),
24*24, // minimum linear speed squared
360*360, // minimum angular speed squared (360 deg/s to cause spin/slice damage)
2, // can't take damage from anything under 2kg
5, // anything less than 5kg is "small"
5, // never take more than 5 pts of damage from anything under 5kg
36*36, // <5kg objects must go faster than 36 in/s to do damage
VPHYSICS_LARGE_OBJECT_MASS, // large mass in kg
4, // large mass scale (anything over 500kg does 4X as much energy to read from damage table)
5, // large mass falling scale (emphasize falling/crushing damage over sideways impacts since the stress will kill you anyway)
0.0f, // min vel
};
const impactdamagetable_t &CNPC_Barnacle::GetPhysicsImpactDamageTable( void )
{
return gBarnacleImpactDamageTable;
}
#endif
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
void CNPC_Barnacle::Precache()
{
PrecacheModel("models/barnacle.mdl");
// Precache all gibs
for ( int i=0; i < ARRAYSIZE(m_szGibNames); i++ )
{
PrecacheModel( m_szGibNames[i] );
}
PrecacheScriptSound( "NPC_Barnacle.Digest" );
PrecacheScriptSound( "NPC_Barnacle.Scream" );
PrecacheScriptSound( "NPC_Barnacle.PullPant" );
PrecacheScriptSound( "NPC_Barnacle.TongueStretch" );
PrecacheScriptSound( "NPC_Barnacle.FinalBite" );
PrecacheScriptSound( "NPC_Barnacle.Die" );
PrecacheScriptSound( "NPC_Barnacle.BreakNeck" );
PrecacheModel( "models/props_junk/rock001a.mdl" );
BaseClass::Precache();
}
//=========================================================
// TongueTouchEnt - does a trace along the barnacle's tongue
// to see if any entity is touching it. Also stores the length
// of the trace in the int pointer provided.
//=========================================================
// enumerate entities that match a set of edict flags into a static array
class CTongueEntitiesEnum : public IPartitionEnumerator
{
public:
CTongueEntitiesEnum( CBaseEntity **pList, int listMax );
// This gets called by the enumeration methods with each element
// that passes the test.
virtual IterationRetval_t EnumElement( IHandleEntity *pHandleEntity );
int GetCount() { return m_nCount; }
bool AddToList( CBaseEntity *pEntity );
private:
CBaseEntity **m_pList;
int m_nListMax;
int m_nCount;
};
CTongueEntitiesEnum::CTongueEntitiesEnum( CBaseEntity **pList, int listMax )
{
m_pList = pList;
m_nListMax = listMax;
m_nCount = 0;
}
bool CTongueEntitiesEnum::AddToList( CBaseEntity *pEntity )
{
m_pList[m_nCount] = pEntity;
++m_nCount;
return ( m_nCount < m_nListMax );
}
IterationRetval_t CTongueEntitiesEnum::EnumElement( IHandleEntity *pHandleEntity )
{
CBaseEntity *pEntity = gEntList.GetBaseEntity( pHandleEntity->GetRefEHandle() );
if ( pEntity )
{
if ( !AddToList( pEntity ) )
return ITERATION_STOP;
}
return ITERATION_CONTINUE;
}
//-----------------------------------------------------------------------------
// Barnacle must trace against only brushes and its last enemy
//-----------------------------------------------------------------------------
class CBarnacleTongueFilter : public CTraceFilterSimple
{
DECLARE_CLASS( CBarnacleTongueFilter, CTraceFilterSimple );
public:
CBarnacleTongueFilter( CBaseEntity *pLastEnemy, const IHandleEntity *passedict, int collisionGroup ) :
CTraceFilterSimple( passedict, collisionGroup )
{
m_pLastEnemy = pLastEnemy;
m_pBarnacle = const_cast<CBaseEntity*>( EntityFromEntityHandle( passedict ) );
}
virtual bool ShouldHitEntity( IHandleEntity *pServerEntity, int contentsMask )
{
if ( pServerEntity == m_pLastEnemy )
return true;
#ifdef HL2_EPISODIC
CBaseEntity *pEntity = EntityFromEntityHandle( pServerEntity );
if ( pEntity )
{
if ( FStrEq( STRING( pEntity->m_iClassname ), "func_brush" ) )
{
CFuncBrush *pFuncBrush = assert_cast<CFuncBrush *>(pEntity);
if ( pFuncBrush->m_bInvertExclusion )
{
if ( pFuncBrush->m_iszExcludedClass == m_pBarnacle->m_iClassname )
return true;
else
return false;
}
else
{
if ( pFuncBrush->m_iszExcludedClass != m_pBarnacle->m_iClassname )
return false;
}
}
if ( pEntity->IsBSPModel() == false && pEntity->IsWorld() == false )
{
return false;
}
}
#endif
return BaseClass::ShouldHitEntity( pServerEntity, contentsMask );
}
private:
CBaseEntity *m_pLastEnemy;
CBaseEntity *m_pBarnacle;
};
#define BARNACLE_CHECK_SPACING 12
CBaseEntity *CNPC_Barnacle::TongueTouchEnt ( float *pflLength )
{
trace_t tr;
float length;
int iMask = MASK_SOLID_BRUSHONLY;
#ifdef HL2_EPISODIC
iMask = MASK_NPCSOLID;
#endif
// trace once to hit architecture and see if the tongue needs to change position.
CBarnacleTongueFilter tongueFilter( m_hLastSpitEnemy, this, COLLISION_GROUP_NONE );
AI_TraceLine ( GetAbsOrigin(), GetAbsOrigin() - Vector ( 0 , 0 , 2048 ),
iMask, &tongueFilter, &tr );
length = fabs( GetAbsOrigin().z - tr.endpos.z );
// Pull it up a tad
length = MAX(8, length - m_flRestUnitsAboveGround);
if ( pflLength )
{
*pflLength = length;
}
Vector delta = Vector( BARNACLE_CHECK_SPACING, BARNACLE_CHECK_SPACING, 0 );
Vector mins = GetAbsOrigin() - delta;
Vector maxs = GetAbsOrigin() + delta;
maxs.z = GetAbsOrigin().z;
mins.z -= length;
CBaseEntity *pList[10];
CTongueEntitiesEnum tongueEnum( pList, 10 );
partition->EnumerateElementsInBox( PARTITION_ENGINE_SOLID_EDICTS, mins, maxs, false, &tongueEnum );
int nCount = tongueEnum.GetCount();
if ( !nCount )
return NULL;
for ( int i = 0; i < nCount; i++ )
{
CBaseEntity *pTest = pList[i];
// Can't lift something that's in the process of being lifted...
// Necessary for good +use interactions
if ( pTest->IsEFlagSet( EFL_IS_BEING_LIFTED_BY_BARNACLE ) )
continue;
// Vehicles can drive so fast that players can warp through the barnacle tongue.
// Therefore, we have to do a check to ensure that doesn't happen.
if ( pTest->GetServerVehicle() )
{
CBaseEntity *pDriver = pTest->GetServerVehicle()->GetPassenger();
if ( pDriver )
{
Vector vecPrevDriverPos;
pTest->GetVelocity( &vecPrevDriverPos );
VectorMA( pDriver->GetAbsOrigin(), -0.1f, vecPrevDriverPos, vecPrevDriverPos );
Ray_t sweptDriver;
sweptDriver.Init( vecPrevDriverPos, pDriver->GetAbsOrigin(), pDriver->WorldAlignMins(), pDriver->WorldAlignMaxs() );
if ( IsBoxIntersectingRay( mins, maxs, sweptDriver ) )
{
pTest = pDriver;
}
}
}
// Deal with physics objects
if ( pTest->GetMoveType() == MOVETYPE_VPHYSICS )
{
IPhysicsObject *pObject = pTest->VPhysicsGetObject();
if ( pObject && pObject->GetMass() <= BARNACLE_TONGUE_MAX_LIFT_MASS )
{
// If this is an item, make sure it's near the tongue before lifting it.
// Weapons and other items have very large bounding boxes.
if( pTest->GetSolidFlags() & FSOLID_TRIGGER )
{
if( UTIL_DistApprox2D( WorldSpaceCenter(), pTest->WorldSpaceCenter() ) > 16 )
{
continue;
}
}
// Allow the barnacles to grab stuff while their tongue is lowering
#ifdef HL2_EPISODIC
length = fabs( GetAbsOrigin().z - pTest->WorldSpaceCenter().z );
// Pull it up a tad
length = MAX(8, length - m_flRestUnitsAboveGround);
if ( pflLength )
{
*pflLength = length;
}
#endif
return pTest;
}
}
// NPCs + players
CBaseCombatCharacter *pVictim = ToBaseCombatCharacter( pTest );
if ( !pVictim )
continue;
// only clients and monsters
if ( pTest != this &&
IRelationType( pTest ) == D_HT &&
pVictim->m_lifeState != LIFE_DEAD &&
pVictim->m_lifeState != LIFE_DYING &&
!( pVictim->GetFlags() & FL_NOTARGET ) )
{
// Allow the barnacles to grab stuff while their tongue is lowering
#ifdef HL2_EPISODIC
length = fabs( GetAbsOrigin().z - pTest->WorldSpaceCenter().z );
// Pull it up a tad
length = MAX(8, length - m_flRestUnitsAboveGround);
if ( pflLength )
{
*pflLength = length;
}
#endif
return pTest;
}
}
return NULL;
}
//===============================================================================================================================
// BARNACLE TONGUE TIP
//===============================================================================================================================
// Crane tip
LINK_ENTITY_TO_CLASS( npc_barnacle_tongue_tip, CBarnacleTongueTip );
BEGIN_DATADESC( CBarnacleTongueTip )
DEFINE_FIELD( m_hBarnacle, FIELD_EHANDLE ),
DEFINE_PHYSPTR( m_pSpring ),
END_DATADESC()
//-----------------------------------------------------------------------------
// Purpose: To by usable by vphysics, this needs to have a phys model.
//-----------------------------------------------------------------------------
void CBarnacleTongueTip::Spawn( void )
{
Precache();
SetModel( "models/props_junk/rock001a.mdl" );
AddEffects( EF_NODRAW );
// We don't want this to be solid, because we don't want it to collide with the barnacle.
SetSolid( SOLID_VPHYSICS );
AddSolidFlags( FSOLID_NOT_SOLID );
BaseClass::Spawn();
m_pSpring = NULL;
}
int CBarnacleTongueTip::UpdateTransmitState( void )
{
return SetTransmitState( FL_EDICT_PVSCHECK );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBarnacleTongueTip::Precache( void )
{
BaseClass::Precache();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBarnacleTongueTip::UpdateOnRemove( )
{
if ( m_pSpring )
{
physenv->DestroySpring( m_pSpring );
m_pSpring = NULL;
}
BaseClass::UpdateOnRemove();
}
//-----------------------------------------------------------------------------
// If the tip changes, we gotta update the barnacle's notion of his tongue
//-----------------------------------------------------------------------------
void CBarnacleTongueTip::VPhysicsUpdate( IPhysicsObject *pPhysics )
{
BaseClass::VPhysicsUpdate( pPhysics );
if ( m_hBarnacle.Get() )
{
m_hBarnacle->OnTongueTipUpdated();
}
}
//-----------------------------------------------------------------------------
// Purpose: Activate/create the spring
//-----------------------------------------------------------------------------
bool CBarnacleTongueTip::CreateSpring( CBaseAnimating *pTongueRoot )
{
IPhysicsObject *pPhysObject = VPhysicsGetObject();
IPhysicsObject *pRootPhysObject = pTongueRoot->VPhysicsGetObject();
Assert( pRootPhysObject );
Assert( pPhysObject );
// Root has huge mass, tip has little
pRootPhysObject->SetMass( VPHYSICS_MAX_MASS );
pPhysObject->SetMass( BARNACLE_TONGUE_TIP_MASS );
float damping = 3;
pPhysObject->SetDamping( &damping, &damping );
springparams_t spring;
spring.constant = BARNACLE_TONGUE_SPRING_CONSTANT_HANGING;
spring.damping = BARNACLE_TONGUE_SPRING_DAMPING;
spring.naturalLength = (GetAbsOrigin() - pTongueRoot->GetAbsOrigin()).Length();
spring.relativeDamping = 10;
spring.startPosition = GetAbsOrigin();
spring.endPosition = pTongueRoot->GetAbsOrigin();
spring.useLocalPositions = false;
m_pSpring = physenv->CreateSpring( pPhysObject, pRootPhysObject, &spring );
return true;
}
//-----------------------------------------------------------------------------
// Purpose: Create a barnacle tongue tip at the bottom of the tongue
//-----------------------------------------------------------------------------
CBarnacleTongueTip *CBarnacleTongueTip::CreateTongueTip( CNPC_Barnacle *pBarnacle, CBaseAnimating *pTongueRoot, const Vector &vecOrigin, const QAngle &vecAngles )
{
CBarnacleTongueTip *pTip = (CBarnacleTongueTip *)CBaseEntity::Create( "npc_barnacle_tongue_tip", vecOrigin, vecAngles );
if ( !pTip )
return NULL;
pTip->VPhysicsInitNormal( pTip->GetSolid(), pTip->GetSolidFlags(), false );
if ( !pTip->CreateSpring( pTongueRoot ) )
return NULL;
// Set the backpointer to the barnacle
pTip->m_hBarnacle = pBarnacle;
// Don't collide with the world
IPhysicsObject *pTipPhys = pTip->VPhysicsGetObject();
// turn off all floating / fluid simulation
pTipPhys->SetCallbackFlags( pTipPhys->GetCallbackFlags() & (~CALLBACK_DO_FLUID_SIMULATION) );
return pTip;
}
//-----------------------------------------------------------------------------
// Purpose: Create a barnacle tongue tip at the root (i.e. inside the barnacle)
//-----------------------------------------------------------------------------
CBarnacleTongueTip *CBarnacleTongueTip::CreateTongueRoot( const Vector &vecOrigin, const QAngle &vecAngles )
{
CBarnacleTongueTip *pTip = (CBarnacleTongueTip *)CBaseEntity::Create( "npc_barnacle_tongue_tip", vecOrigin, vecAngles );
if ( !pTip )
return NULL;
pTip->AddSolidFlags( FSOLID_NOT_SOLID );
// Disable movement on the root, we'll move this thing manually.
pTip->VPhysicsInitShadow( false, false );
pTip->SetMoveType( MOVETYPE_NONE );
return pTip;
}
//-----------------------------------------------------------------------------
//
// Schedules
//
//-----------------------------------------------------------------------------
AI_BEGIN_CUSTOM_NPC( npc_barnacle, CNPC_Barnacle )
// Register our interactions
DECLARE_INTERACTION( g_interactionBarnacleVictimDangle )
DECLARE_INTERACTION( g_interactionBarnacleVictimReleased )
DECLARE_INTERACTION( g_interactionBarnacleVictimGrab )
DECLARE_INTERACTION( g_interactionBarnacleVictimBite )
// Conditions
// Tasks
// Activities
DECLARE_ACTIVITY( ACT_BARNACLE_SLURP ) // Pulling the tongue up with prey on the end
DECLARE_ACTIVITY( ACT_BARNACLE_BITE_HUMAN ) // Biting the head of a humanoid
DECLARE_ACTIVITY( ACT_BARNACLE_BITE_PLAYER ) // Biting the head of a humanoid
DECLARE_ACTIVITY( ACT_BARNACLE_CHEW_HUMAN ) // Slowly swallowing the humanoid
DECLARE_ACTIVITY( ACT_BARNACLE_BARF_HUMAN ) // Spitting out human legs & gibs
DECLARE_ACTIVITY( ACT_BARNACLE_TONGUE_WRAP ) // Wrapping the tongue around a target
DECLARE_ACTIVITY( ACT_BARNACLE_TASTE_SPIT ) // Yuck! Me no like that!
DECLARE_ACTIVITY( ACT_BARNACLE_BITE_SMALL_THINGS ) // Biting small things, like a headcrab
DECLARE_ACTIVITY( ACT_BARNACLE_CHEW_SMALL_THINGS ) // Chewing small things, like a headcrab
//Adrian: events go here
DECLARE_ANIMEVENT( AE_BARNACLE_PUKEGIB )
DECLARE_ANIMEVENT( AE_BARNACLE_BITE )
DECLARE_ANIMEVENT( AE_BARNACLE_SPIT )
// Schedules
AI_END_CUSTOM_NPC()
|