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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
// tf_nav_mesh.cpp
// TF specific nav mesh
// Michael Booth, February 2009
#include "cbase.h"
#include "tf_nav_mesh.h"
#include "bot/tf_bot.h"
#include "bot/tf_bot_manager.h"
#include "tf_obj.h"
#include "tf_obj_sentrygun.h"
#include "team_control_point_master.h"
#include "team_train_watcher.h"
#include "tf_gamerules.h"
#include "func_respawnroom.h"
#include "doors.h"
#include "props.h"
#include "filters.h"
#include "NextBotUtil.h"
// NOTE: nav_debug_blocked ConVar is also use for debugging NAV_MESH_NAV_BLOCKER and TF_NAV_BLOCKED...
ConVar tf_show_in_combat_areas( "tf_show_in_combat_areas", "0", FCVAR_CHEAT );
ConVar tf_show_enemy_invasion_areas( "tf_show_enemy_invasion_areas", "0", FCVAR_CHEAT, "Highlight areas where the enemy team enters the visible environment of the local player" );
ConVar tf_show_blocked_areas( "tf_show_blocked_areas", "0", FCVAR_CHEAT, "Highlight areas that are considered blocked for TF-specific reasons" );
ConVar tf_show_incursion_flow( "tf_show_incursion_flow", "0", FCVAR_CHEAT );
ConVar tf_show_incursion_flow_range( "tf_show_incursion_flow_range", "150", FCVAR_CHEAT, "1 = red, 2 = blue" );
ConVar tf_show_incursion_flow_gradient( "tf_show_incursion_flow_gradient", "0", FCVAR_CHEAT, "1 = red, 2 = blue" );
ConVar tf_show_mesh_decoration( "tf_show_mesh_decoration", "0", FCVAR_CHEAT, "Highlight special areas" );
ConVar tf_show_mesh_decoration_manual( "tf_show_mesh_decoration_manual", "0", FCVAR_CHEAT, "Highlight special areas marked by hand" );
// Method 1 & 2 should be exactly the same for tf_show_sentry_danger.
ConVar tf_show_sentry_danger( "tf_show_sentry_danger", "0", FCVAR_CHEAT, "Show sentry danger areas. 1:Use m_sentryAreas. 2:Check all nav areas." );
ConVar tf_show_actor_potential_visibility( "tf_show_actor_potential_visibility", "0", FCVAR_CHEAT );
ConVar tf_show_control_points( "tf_show_control_points", "0", FCVAR_CHEAT );
ConVar tf_show_bomb_drop_areas( "tf_show_bomb_drop_areas", "0", FCVAR_CHEAT );
ConVar tf_bot_min_setup_gate_defend_range( "tf_bot_min_setup_gate_defend_range", "750", FCVAR_CHEAT, "How close from the setup gate(s) defending bots can take up positions. Areas closer than this will be in cover to ambush." );
ConVar tf_bot_max_setup_gate_defend_range( "tf_bot_max_setup_gate_defend_range", "2000", FCVAR_CHEAT, "How far from the setup gate(s) defending bots can take up positions" );
ConVar tf_bot_min_setup_gate_sniper_defend_range( "tf_bot_min_setup_gate_sniper_defend_range", "1500", FCVAR_CHEAT, "How far from the setup gate(s) a defending sniper will take up position" );
ConVar tf_show_gate_defense_areas( "tf_show_gate_defense_areas", "0", FCVAR_CHEAT );
ConVar tf_show_point_defense_areas( "tf_show_point_defense_areas", "0", FCVAR_CHEAT );
extern ConVar tf_bot_debug_select_defense_area;
extern ConVar tf_nav_in_combat_duration;
extern ConVar mp_teams_unbalance_limit;
extern ConVar mp_autoteambalance;
extern ConVar sv_alltalk;
extern ConVar mp_timelimit;
//--------------------------------------------------------------------------------------------------------------
ConVar tf_select_ambush_areas_radius( "tf_select_ambush_areas_radius", "750", FCVAR_CHEAT );
ConVar tf_select_ambush_areas_close_range( "tf_select_ambush_areas_close_range", "300", FCVAR_CHEAT );
ConVar tf_select_ambush_areas_max_enemy_exposure_area( "tf_select_ambush_areas_max_enemy_exposure_area", "500000", FCVAR_CHEAT );
class ScanSelectAmbushAreas
{
public:
ScanSelectAmbushAreas( CUtlVector< CTFNavArea * > *ambushAreaVector, int teamToAmbush, float enemyIncursionLimit )
{
m_ambushAreaVector = ambushAreaVector;
m_teamToAmbush = teamToAmbush;
m_enemyIncursionLimit = enemyIncursionLimit;
}
bool operator() ( CNavArea *baseArea )
{
CTFNavArea *area = static_cast< CTFNavArea * >( baseArea );
// no drop-downs or jumps
if ( area->GetParent() && !area->GetParent()->IsContiguous( area ) )
return false;
float enemyIncursionDistanceAtArea = area->GetIncursionDistance( m_teamToAmbush );
if ( enemyIncursionDistanceAtArea > m_enemyIncursionLimit )
return false;
int wallCount = 0;
int dir;
for( dir=0; dir<NUM_DIRECTIONS; ++dir )
{
if ( area->GetAdjacentCount( (NavDirType)dir ) == 0 )
{
// wall (or dropoff) on this side
++wallCount;
}
}
if ( wallCount >= 1 )
{
// good cover, are we also right next to enemy incursion areas?
const CUtlVector< CTFNavArea * > &invasionVector = area->GetEnemyInvasionAreaVector( GetEnemyTeam( m_teamToAmbush ) );
// don't use areas that are in plain sight of large amounts of incoming enemy space
NavAreaCollector collector( true );
area->ForAllPotentiallyVisibleAreas( collector );
float totalVisibleThreatArea = 0.0f;
FOR_EACH_VEC( collector.m_area, it )
{
CTFNavArea *visArea = static_cast< CTFNavArea * >( collector.m_area[ it ] );
if ( visArea->GetIncursionDistance( m_teamToAmbush ) < enemyIncursionDistanceAtArea )
{
totalVisibleThreatArea += visArea->GetSizeX() * visArea->GetSizeY();
}
}
if ( totalVisibleThreatArea > tf_select_ambush_areas_max_enemy_exposure_area.GetFloat() )
{
// too exposed
return true;
}
float nearRangeSq = tf_select_ambush_areas_close_range.GetFloat();
nearRangeSq *= nearRangeSq;
FOR_EACH_VEC( invasionVector, it )
{
CTFNavArea *invasionArea = invasionVector[ it ];
if ( invasionArea->GetIncursionDistance( m_teamToAmbush ) < enemyIncursionDistanceAtArea )
{
// the enemy will go through invasionArea before they reach the candidate area
float rangeSq = ( invasionArea->GetCenter() - area->GetCenter() ).LengthSqr();
if ( rangeSq < nearRangeSq )
{
// there is at least one nearby invasion area
m_ambushAreaVector->AddToTail( area );
break;
}
}
}
}
return true;
}
int m_teamToAmbush;
float m_enemyIncursionLimit;
CUtlVector< CTFNavArea * > *m_ambushAreaVector;
};
void CMD_SelectAmbushAreas( void )
{
CBasePlayer *player = UTIL_GetListenServerHost();
if ( player == NULL )
return;
CTFNavArea *searchSourceArea = static_cast< CTFNavArea * >( player->GetLastKnownArea() );
int teamToAmbush = GetEnemyTeam( player->GetTeamNumber() );
CUtlVector< CTFNavArea * > ambushAreaVector;
ScanSelectAmbushAreas selector( &ambushAreaVector, teamToAmbush, searchSourceArea->GetIncursionDistance( teamToAmbush ) + 300.0f );
SearchSurroundingAreas( searchSourceArea, searchSourceArea->GetCenter(), selector, tf_select_ambush_areas_radius.GetFloat() );
FOR_EACH_VEC( ambushAreaVector, it )
{
TheNavMesh->AddToSelectedSet( ambushAreaVector[ it ] );
}
}
static ConCommand tf_select_ambush_areas( "tf_select_ambush_areas", CMD_SelectAmbushAreas, "Add good ambush spots to the selected set. For debugging.", FCVAR_GAMEDLL | FCVAR_CHEAT );
#ifdef SKIPME
//-------------------------------------------------------------------------
void CMD_SelectIncursionZone( void )
{
CBasePlayer *player = UTIL_GetListenServerHost();
if ( player == NULL )
return;
const CUtlVector< CTFNavArea * > *pointAreaVector = TheTFNavMesh()->GetControlPointAreas();
if ( !pointAreaVector )
return;
int i;
float incursionAtPoint = 0.0f;
float maxInvaderTravelDistance = 2000.0f;
for( i=0; i<pointAreaVector->Count(); ++i )
{
if ( pointAreaVector->Element(i)->GetIncursionDistance( TF_TEAM_BLUE ) > incursionAtPoint )
{
incursionAtPoint = pointAreaVector->Element(i)->GetIncursionDistance( TF_TEAM_BLUE );
}
}
for( i=0; i<TheNavAreas.Count(); ++i )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ i ] );
float inc = area->GetIncursionDistance( TF_TEAM_BLUE );
if ( inc > 0.0f && inc < incursionAtPoint && inc > incursionAtPoint - maxInvaderTravelDistance )
{
NDebugOverlay::Cross3D( area->GetCenter(), 5.0f, 255, 255, 0, true, 99999.9f );
//TheNavMesh->AddToSelectedSet( area );
}
}
}
static ConCommand tf_select_incursion_zone( "tf_select_incursion_zone", CMD_SelectIncursionZone, "Select areas where invading team approaches the objective. For debugging.", FCVAR_GAMEDLL | FCVAR_CHEAT );
//-------------------------------------------------------------------------
void CMD_SelectControlPointIncursionAreas( void )
{
CBasePlayer *player = UTIL_GetListenServerHost();
if ( player == NULL )
return;
const CUtlVector< CTFNavArea * > *pointAreaVector = TheTFNavMesh()->GetControlPointAreas();
for( int i=0; i<pointAreaVector->Count(); ++i )
{
CTFNavArea *pointArea = (CTFNavArea *)pointAreaVector->Element(i);
for( i=0; i<TheNavAreas.Count(); ++i )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ i ] );
if ( area->GetIncursionDistance( TF_TEAM_BLUE ) > pointArea->GetIncursionDistance( TF_TEAM_BLUE ) )
continue;
if ( pointArea->IsPotentiallyVisible( area ) )
{
// the point is visible from this area
// if no prior areas can see the point, we have a point incursion area
CUtlVector< CTFNavArea * > priorVector;
area->CollectPriorIncursionAreas( TF_TEAM_BLUE, &priorVector );
int j;
for( j=0; j<priorVector.Count(); ++j )
{
if ( pointArea->IsPotentiallyVisible( priorVector[j] ) )
{
break;
}
}
if ( j == priorVector.Count() && j > 0 )
{
// no prior areas can see the point
TheNavMesh->AddToSelectedSet( area );
}
}
}
}
}
static ConCommand tf_select_control_point_incursion_areas( "tf_select_control_point_incursion_areas", CMD_SelectControlPointIncursionAreas, "Select areas where invading team leaves cover near the objective. For debugging.", FCVAR_GAMEDLL | FCVAR_CHEAT );
//-------------------------------------------------------------------------
CON_COMMAND_F( tf_assign_territory, "Divvy up the mesh into red and blue territories. For debugging.", FCVAR_GAMEDLL )
{
// Listenserver host or rcon access only!
if ( !UTIL_IsCommandIssuedByServerAdmin() )
return;
int i;
// clear all territory markings
for( i=0; i<TheNavAreas.Count(); ++i )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ i ] );
area->ClearAttributeTF( TF_NAV_RED_TERRITORY | TF_NAV_BLUE_TERRITORY );
area->SetParent( NULL );
}
const CUtlVector< CTFNavArea * > *pointAreaVector = TheTFNavMesh()->GetControlPointAreas();
if ( !pointAreaVector || pointAreaVector->Count() <= 0 )
return;
// find centermost point area, and mark all contested point areas as owned by red
Vector center = vec3_origin;
for( i=0; i<pointAreaVector->Count(); ++i )
{
center += pointAreaVector->Element(i)->GetCenter();
pointAreaVector->Element(i)->SetAttributeTF( TF_NAV_RED_TERRITORY );
}
center /= pointAreaVector->Count();
CTFNavArea *pointArea = pointAreaVector->Element(0);
for( i=0; i<pointAreaVector->Count(); ++i )
{
if ( pointAreaVector->Element(i)->IsOverlapping( center ) )
{
pointArea = pointAreaVector->Element(i);
break;
}
}
// spread red's territory to surround the contested area a bit
const float surroundRange = 1000.0f;
CUtlVector< CNavArea * > surroundingVector;
CollectSurroundingAreas( &surroundingVector, pointArea, surroundRange );
for( int t=0; t<surroundingVector.Count(); ++t )
{
CTFNavArea *area = (CTFNavArea *)surroundingVector[t];
area->ClearAttributeTF( TF_NAV_BLUE_TERRITORY );
area->SetAttributeTF( TF_NAV_RED_TERRITORY );
}
// do a breadth first search out from control point center
// when a spawn room is reached, mark it and all its parent areas as belonging to the team of the spawn room
CNavArea::ClearSearchLists();
pointArea->AddToOpenList();
pointArea->Mark();
pointArea->SetParent( NULL );
CUtlVectorFixedGrowable< const NavConnect *, 64 > adjAreaVector;
while( !CNavArea::IsOpenListEmpty() )
{
// get next area to check
CTFNavArea *area = static_cast< CTFNavArea * >( CNavArea::PopOpenList() );
// ignore setup gates, since they will be open after the setup time
if ( !area->HasAttributeTF( TF_NAV_BLUE_SETUP_GATE | TF_NAV_RED_SETUP_GATE ) && ( area->IsBlocked( TF_TEAM_RED ) || area->IsBlocked( TF_TEAM_BLUE ) ) )
{
// don't pass through blocked areas
continue;
}
// explore adjacent floor areas
adjAreaVector.RemoveAll();
for( int dir=0; dir<NUM_DIRECTIONS; ++dir )
{
// collect all OUTGOING links from this area to adjacent areas
const NavConnectVector *adjVector = area->GetAdjacentAreas( (NavDirType)dir );
FOR_EACH_VEC( (*adjVector), bit )
{
adjAreaVector.AddToTail( &(*adjVector)[ bit ] );
}
}
FOR_EACH_VEC( adjAreaVector, vit )
{
const NavConnect *connect = adjAreaVector[ vit ];
CTFNavArea *adjArea = static_cast< CTFNavArea * >( connect->area );
if ( adjArea->ComputeAdjacentConnectionHeightChange( area ) > TF_PLAYER_JUMP_HEIGHT ||
area->ComputeAdjacentConnectionHeightChange( adjArea ) > TF_PLAYER_JUMP_HEIGHT )
{
// don't go up ledges too high to jump
continue;
}
if ( !adjArea->IsMarked() )
{
adjArea->Mark();
adjArea->SetParent( area );
// if this area is in a spawn room, mark path we took to get here as the appropriate team's territory
if ( adjArea->HasAttributeTF( TF_NAV_SPAWN_ROOM_RED ) )
{
for( CTFNavArea *pathArea = adjArea; pathArea; pathArea = (CTFNavArea *)pathArea->GetParent() )
{
pathArea->SetAttributeTF( TF_NAV_RED_TERRITORY );
}
}
else if ( adjArea->HasAttributeTF( TF_NAV_SPAWN_ROOM_BLUE ) )
{
for( CTFNavArea *pathArea = adjArea; pathArea; pathArea = (CTFNavArea *)pathArea->GetParent() )
{
pathArea->SetAttributeTF( TF_NAV_BLUE_TERRITORY );
}
}
adjArea->AddToOpenListTail();
}
}
}
if ( args.ArgC() == 1 )
{
return;
}
// iterate over all areas, spreading territory out from found routes into unclaimed areas
CUtlVector< CTFNavArea * > spreadVector;
while( true )
{
spreadVector.RemoveAll();
for( int i=0; i<TheNavAreas.Count(); ++i )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ i ] );
CTFNavArea *parent = (CTFNavArea *)area->GetParent();
// if this area has no territory affiliation but its parent does, inherit it and iterate again
if ( !area->HasAttributeTF( TF_NAV_RED_TERRITORY | TF_NAV_BLUE_TERRITORY ) && parent && parent->HasAttributeTF( TF_NAV_RED_TERRITORY | TF_NAV_BLUE_TERRITORY ) )
{
spreadVector.AddToTail( area );
}
}
if ( spreadVector.Count() == 0 )
{
// finished spreading
break;
}
// spread the territory influence one step out
for( int j=0; j<spreadVector.Count(); ++j )
{
CTFNavArea *area = spreadVector[j];
CTFNavArea *parent = (CTFNavArea *)area->GetParent();
if ( parent->HasAttributeTF( TF_NAV_RED_TERRITORY ) )
{
area->SetAttributeTF( TF_NAV_RED_TERRITORY );
}
if ( parent->HasAttributeTF( TF_NAV_BLUE_TERRITORY ) )
{
area->SetAttributeTF( TF_NAV_BLUE_TERRITORY );
}
}
}
}
#endif // SKIPME
//-------------------------------------------------------------------------
CTFNavMesh::CTFNavMesh( void )
{
for( int j=0; j<MAX_CONTROL_POINTS; ++j )
{
m_controlPointAreaVector[j].RemoveAll();
m_controlPointCenterAreaVector[j] = NULL;
}
ListenForGameEvent( "teamplay_setup_finished" );
ListenForGameEvent( "teamplay_point_captured" );
ListenForGameEvent( "teamplay_point_unlocked" );
ListenForGameEvent( "player_builtobject" );
ListenForGameEvent( "player_dropobject" );
ListenForGameEvent( "player_carryobject" );
ListenForGameEvent( "object_detonated" );
ListenForGameEvent( "object_destroyed" );
m_priorBotCount = 0;
m_recomputeInternalDataTimer.Invalidate();
}
//-------------------------------------------------------------------------
CTFNavArea *CTFNavMesh::CreateArea( void ) const
{
return new CTFNavArea;
}
//-------------------------------------------------------------------------
/**
* Invoked on each game frame
*/
void CTFNavMesh::Update( void )
{
CNavMesh::Update();
if ( !TheNavAreas.Count() )
return;
UpdateDebugDisplay();
if ( TheNextBots().GetNextBotCount() > 0 )
{
if ( m_priorBotCount == 0 )
{
// the first bot was just added
ScheduleRecomputationOfInternalData( RESET );
}
// we use a timer here to give the map logic a few moments to settle out before inspecting it
if ( m_recomputeInternalDataTimer.HasStarted() && m_recomputeInternalDataTimer.IsElapsed() )
{
m_recomputeInternalDataTimer.Invalidate();
RecomputeInternalData();
}
if ( TFGameRules()->GetGameType() == TF_GAMETYPE_ESCORT && m_watchCartTimer.IsElapsed() )
{
// the cart may have moved, recompute new sniper spots
m_watchCartTimer.Start( 3.0f );
}
}
m_priorBotCount = TheNextBots().GetNextBotCount();
}
//-------------------------------------------------------------------------
/**
* (EXTEND) invoked when server loads a new map
*/
void CTFNavMesh::OnServerActivate( void )
{
CNavMesh::OnServerActivate();
m_sentryAreas.RemoveAll();
ResetMeshAttributes( true );
m_priorBotCount = 0;
m_setupGateDefenseAreaVector.RemoveAll();
m_redSpawnRoomAreaVector.RemoveAll();
m_blueSpawnRoomAreaVector.RemoveAll();
m_redSpawnRoomExitAreaVector.RemoveAll();
m_blueSpawnRoomExitAreaVector.RemoveAll();
for( int i=0; i<MAX_CONTROL_POINTS; ++i )
{
m_controlPointAreaVector[i].RemoveAll();
m_controlPointCenterAreaVector[i] = NULL;
}
}
//-------------------------------------------------------------------------
/**
* Invoked when a game round restarts
*/
void CTFNavMesh::OnRoundRestart( void )
{
CNavMesh::OnRoundRestart();
ResetMeshAttributes( true );
// nasty hack
TheTFBots().OnRoundRestart();
if ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() )
{
RecomputeInternalData();
}
DevMsg( "CTFNavMesh: %d nav areas in mesh.\n", GetNavAreaCount() );
}
//-------------------------------------------------------------------------
/**
* One or more areas may have become blocked or are no longer blocked.
* Recompute dependent mesh data.
*/
void CTFNavMesh::OnBlockedAreasChanged( void )
{
VPROF_BUDGET( "CTFNavMesh::OnBlockedAreasChanged", "NextBot" );
if ( TheNextBots().GetNextBotCount() == 0 )
return;
ScheduleRecomputationOfInternalData( BLOCKED_STATUS_CHANGED );
}
//-------------------------------------------------------------------------
void TestAndBlockOverlappingAreas( CBaseEntity *entity )
{
Ray_t ray;
trace_t trace;
NextBotTraceFilterIgnoreActors filter( NULL, COLLISION_GROUP_NONE );
const float crouchHeight = 30.0f;
Vector hullMin, hullMax;
Vector traceFrom, traceTo;
Extent extent;
extent.Init( entity );
CUtlVector< CNavArea * > overlapVector;
TheNavMesh->CollectAreasOverlappingExtent( extent, &overlapVector );
for( int i=0; i<overlapVector.Count(); ++i )
{
CTFNavArea *area = (CTFNavArea *)overlapVector[i];
const float tolerance = 1.0f;
if ( fabs( area->GetCorner( NORTH_WEST ).z - area->GetCorner( NORTH_EAST ).z ) < tolerance )
{
// flat along X, potentially varies along Y
hullMin.x = 0.0f;
hullMin.y = 0.0f;
hullMin.z = StepHeight;
hullMax.x = area->GetSizeX();
hullMax.y = 0.0f;
hullMax.z = crouchHeight;
traceFrom = area->GetCorner( NORTH_WEST );
traceTo = area->GetCorner( SOUTH_WEST );
}
else if ( fabs( area->GetCorner( NORTH_WEST ).z - area->GetCorner( SOUTH_WEST ).z ) < tolerance )
{
// flat along Y, potentially varies along X
hullMin.x = 0.0f;
hullMin.y = 0.0f;
hullMin.z = StepHeight;
hullMax.x = 0.0f;
hullMax.y = area->GetSizeY();
hullMax.z = crouchHeight;
traceFrom = area->GetCorner( NORTH_WEST );
traceTo = area->GetCorner( NORTH_EAST );
}
else
{
// varies along both X and Y
hullMin.x = 0.0f;
hullMin.y = 0.0f;
hullMin.z = StepHeight;
hullMax.x = 1.0f;
hullMax.y = 1.0f;
hullMax.z = crouchHeight;
traceFrom = area->GetCorner( NORTH_WEST );
traceTo = area->GetCorner( SOUTH_EAST );
}
// need to trace from high to low to avoid interpenetration
if ( traceFrom.z < traceTo.z )
{
Vector tmp = traceFrom;
traceFrom = traceTo;
traceTo = tmp;
}
ray.Init( traceFrom, traceTo, hullMin, hullMax );
enginetrace->TraceRay( ray, MASK_PLAYERSOLID, &filter, &trace );
// NDebugOverlay::SweptBox( traceFrom, traceTo, hullMin, hullMax, vec3_angle, 255, 255, 0, 255, 99999.9f );
if ( trace.DidHit() )
{
if ( trace.m_pEnt && trace.m_pEnt->ShouldBlockNav() )
{
area->MarkAsBlocked( TEAM_ANY, entity );
}
}
}
}
//-------------------------------------------------------------------------
void CTFNavMesh::ComputeBlockedAreas( void )
{
// clear all blocked state
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
area->UnblockArea();
}
#ifdef TF_CREEP_MODE
if ( TFGameRules()->IsCreepWaveMode() )
{
// no blocking for creeps
return;
}
#endif
// block mesh under solid brushes
CFuncBrush *brush = NULL;
while( ( brush = (CFuncBrush *)gEntList.FindEntityByClassname( brush, "func_brush" ) ) != NULL )
{
if ( brush->IsSolid() ) // && !brush->m_iDisabled ) // "disabled" seems to be overridden by solidity
{
// this brush is potentially blocking navigation
TestAndBlockOverlappingAreas( brush );
}
}
// Find all func_doors in the map. If a func_door is surrounded by a trigger_multiple,
// the trigger controls access to the door. If the func_door is bare, the door itself
// determines access.
CBaseDoor *door = NULL;
while( ( door = (CBaseDoor *)gEntList.FindEntityByClassname( door, "func_door*" ) ) != NULL )
{
// if a closed door is not controlled by a trigger assume it doesn't open at all until the scenario changes and map logic opens it
bool isDoorClosed = ( door->m_toggle_state == TS_AT_BOTTOM || door->m_toggle_state == TS_GOING_DOWN );
int doorOwnedByTeam = TEAM_UNASSIGNED;
bool isDoorTriggerControlled = false;
Extent triggerExtent, doorExtent;
doorExtent.Init( door );
CTriggerMultiple *trigger = NULL;
while( ( trigger = (CTriggerMultiple *)gEntList.FindEntityByClassname( trigger, "trigger_multiple" ) ) != NULL )
{
triggerExtent.Init( trigger );
// just check overlapping, not encompassing, since some door triggers only are player height tall (cp_gravelpit)
if ( triggerExtent.IsOverlapping( doorExtent ) )
{
if ( !trigger->m_bDisabled )
{
// this trigger contains this door, and thus controls it
isDoorTriggerControlled = true;
// look for a filter attached to this trigger that limits access to one team
if ( trigger->m_hFilter != NULL && FClassnameIs( trigger->m_hFilter, "filter_activator_tfteam" ) )
{
doorOwnedByTeam = trigger->m_hFilter->GetTeamNumber();
}
}
}
}
// is this door acting like a wall?
bool isDoorWall = isDoorTriggerControlled ? false : isDoorClosed;
// set the blocked status of all areas overlapping this door
NavAreaCollector doorAreas;
TheNavMesh->ForAllAreasOverlappingExtent( doorAreas, doorExtent );
int blockedTeam = ( doorOwnedByTeam == TEAM_UNASSIGNED ) ? TEAM_ANY : ( ( doorOwnedByTeam == TF_TEAM_RED ) ? TF_TEAM_BLUE : TF_TEAM_RED );
for( int i=0; i<doorAreas.m_area.Count(); ++i )
{
CTFNavArea *area = (CTFNavArea *)doorAreas.m_area[i];
bool isDoorBlocking;
if ( area->HasAttributeTF( TF_NAV_DOOR_ALWAYS_BLOCKS ) )
{
// closed doors always block
isDoorBlocking = isDoorClosed;
}
else
{
// untriggered closed doors, or team-owned doors block
isDoorBlocking = ( isDoorWall || doorOwnedByTeam != TEAM_UNASSIGNED );
}
if ( isDoorBlocking )
{
// this door is blocking navigation for at least one team
if ( !area->HasAttributeTF( TF_NAV_DOOR_NEVER_BLOCKS ) )
{
area->MarkAsBlocked( blockedTeam, door );
}
}
else
{
// we need to UN-block these areas to account for legacy func_brushes
// used inside of cosmetic doors as a collision proxy that have marked
// these areas as blocked
area->UnblockArea( blockedTeam );
}
}
}
#ifdef DONT_USE_BLOCKS_TOO_MUCH
// Find all prop_dynamic entities in the map and block areas they overlap
CDynamicProp *prop = NULL;
while( ( prop = (CDynamicProp *)gEntList.FindEntityByClassname( prop, "prop_dynamic" ) ) != NULL )
{
if ( prop->IsSolid() )
{
// if this prop is parented to a door, ignore it - it has already been handled by the door code above
CBaseDoor *parentDoor = dynamic_cast< CBaseDoor * >( prop->GetParent() );
if ( !parentDoor )
{
// this prop is potentially blocking navigation
TestAndBlockOverlappingAreas( prop );
}
}
}
#endif // DONT_USE_BLOCKS_TOO_MUCH
}
//-------------------------------------------------------------------------
void CTFNavMesh::CollectControlPointAreas( void )
{
for( int i=0; i<MAX_CONTROL_POINTS; ++i )
{
m_controlPointAreaVector[i].RemoveAll();
m_controlPointCenterAreaVector[i] = NULL;
}
CTeamControlPointMaster *pMaster = g_hControlPointMasters.Count() ? g_hControlPointMasters[0] : NULL;
if ( pMaster )
{
CBaseEntity *trigger = NULL;
while( ( trigger = gEntList.FindEntityByClassname( trigger, "trigger_capture_area*" ) ) != NULL )
{
CTeamControlPoint *point = ((CTriggerAreaCapture *)trigger)->GetControlPoint();
if ( point )
{
Extent extent;
extent.Init( trigger );
// expand extent a bit to make sure it intersects ground below (koth_viaduct)
extent.lo.z -= HalfHumanHeight;
extent.hi.z += HalfHumanHeight;
CUtlVector< CTFNavArea * > *pointAreaVector = &m_controlPointAreaVector[ point->GetPointIndex() ];
TheNavMesh->CollectAreasOverlappingExtent< CTFNavArea >( extent, pointAreaVector );
// find area closest to the control point's center
m_controlPointCenterAreaVector[ point->GetPointIndex() ] = NULL;
float closeRangeSq = FLT_MAX;
for( int i=0; i<pointAreaVector->Count(); ++i )
{
CTFNavArea *area = pointAreaVector->Element(i);
float rangeSq = ( area->GetCenter() - trigger->WorldSpaceCenter() ).Length2DSqr();
if ( rangeSq < closeRangeSq )
{
m_controlPointCenterAreaVector[ point->GetPointIndex() ] = area;
closeRangeSq = rangeSq;
}
}
}
}
}
}
//-------------------------------------------------------------------------
// For MvM mode. Mark all nav areas where the bomb can drop and the invaders can reach it.
void CTFNavMesh::ComputeLegalBombDropAreas( void )
{
if ( !TFGameRules()->IsMannVsMachineMode() )
{
return;
}
CTFNavArea *startArea = NULL;
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
if ( area->HasAttributeTF( TF_NAV_SPAWN_ROOM_BLUE ) )
{
startArea = area;
}
area->ClearAttributeTF( TF_NAV_BOMB_CAN_DROP_HERE );
}
if ( startArea == NULL )
{
Warning( "Can't find blue spawn room nav areas. No legal bomb drop areas are marked" );
return;
}
CNavArea::ClearSearchLists();
startArea->AddToOpenList();
startArea->Mark();
startArea->SetParent( NULL );
CUtlVectorFixedGrowable< const NavConnect *, 64 > adjAreaVector;
while( !CNavArea::IsOpenListEmpty() )
{
// get next area to check
CTFNavArea *area = static_cast< CTFNavArea * >( CNavArea::PopOpenList() );
// explore adjacent floor areas
adjAreaVector.RemoveAll();
for( int dir=0; dir<NUM_DIRECTIONS; ++dir )
{
// collect all OUTGOING links from this area to adjacent areas
const NavConnectVector *adjVector = area->GetAdjacentAreas( (NavDirType)dir );
FOR_EACH_VEC( (*adjVector), bit )
{
adjAreaVector.AddToTail( &(*adjVector)[ bit ] );
}
}
FOR_EACH_VEC( adjAreaVector, vit )
{
const NavConnect *connect = adjAreaVector[ vit ];
CTFNavArea *adjArea = static_cast< CTFNavArea * >( connect->area );
if ( adjArea->IsMarked() )
{
continue;
}
if ( area->ComputeAdjacentConnectionHeightChange( adjArea ) > StepHeight )
{
// don't go up ledges higher than a legal step
continue;
}
if ( !adjArea->HasAttributeTF( TF_NAV_SPAWN_ROOM_BLUE | TF_NAV_SPAWN_ROOM_RED ) )
{
// this area can be reached by walking from the spawn, so it's legal to drop the bomb here
adjArea->SetAttributeTF( TF_NAV_BOMB_CAN_DROP_HERE );
}
adjArea->Mark();
adjArea->SetParent( area );
if ( !adjArea->IsOpen() )
{
// Since we're doing a breadth-first search, this area will end up at the end of the list.
// Adding it to the tail explicitly saves us a bunch of list traversals.
adjArea->AddToOpenListTail();
}
}
}
}
//-------------------------------------------------------------------------
// For MvM mode. Mark all nav areas where the bomb can drop and the invaders can reach it.
void CTFNavMesh::ComputeBombTargetDistance()
{
if ( !TFGameRules()->IsMannVsMachineMode() )
{
return;
}
CCaptureZone *zone = NULL;
for( int i=0; i<ICaptureZoneAutoList::AutoList().Count(); ++i )
{
zone = static_cast< CCaptureZone* >( ICaptureZoneAutoList::AutoList()[i] );
if ( zone->GetTeamNumber() == TF_TEAM_PVE_INVADERS )
{
break;
}
}
if ( zone == NULL )
{
Warning( "Can't find bomb delivery zone." );
return;
}
CTFNavArea *zoneArea = (CTFNavArea *)TheTFNavMesh()->GetNearestNavArea( zone->WorldSpaceCenter(), false, 500.0f, true );
if ( !zoneArea )
{
Warning( "No nav area for bomb delivery zone." );
return;
}
// invalidate all travel distances
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
area->m_distanceToBombTarget = -1.0f;
}
CNavArea::ClearSearchLists();
zoneArea->AddToOpenList();
zoneArea->Mark();
zoneArea->SetParent( NULL );
zoneArea->m_distanceToBombTarget = 0.0f;
CUtlVectorFixedGrowable< const NavConnect *, 64 > adjAreaVector;
while( !CNavArea::IsOpenListEmpty() )
{
// get next area to check
CTFNavArea *area = static_cast< CTFNavArea * >( CNavArea::PopOpenList() );
// explore adjacent floor areas
adjAreaVector.RemoveAll();
for( int dir=0; dir<NUM_DIRECTIONS; ++dir )
{
// collect all OUTGOING links from this area to adjacent areas
const NavConnectVector *adjVector = area->GetAdjacentAreas( (NavDirType)dir );
FOR_EACH_VEC( (*adjVector), bit )
{
adjAreaVector.AddToTail( &(*adjVector)[ bit ] );
}
}
FOR_EACH_VEC( adjAreaVector, vit )
{
const NavConnect *connect = adjAreaVector[ vit ];
CTFNavArea *adjArea = static_cast< CTFNavArea * >( connect->area );
if ( area->ComputeAdjacentConnectionHeightChange( adjArea ) > TF_PLAYER_JUMP_HEIGHT )
{
// don't go up ledges too high to jump
continue;
}
// compute travel distance
float newTravelDistance = 0.0f;
float between = connect->length;
newTravelDistance = area->m_distanceToBombTarget + between;
float adjacentTravelDistance = adjArea->m_distanceToBombTarget;
// Found a shortcut to our neighbor passing through this area?
// Use a tolernace. Without it, floating point math can make this loop go on forever,
// because intermediate results are stored at a different precision
float flTol = .001f;
if ( adjacentTravelDistance < 0.0f || adjacentTravelDistance > newTravelDistance + flTol )
{
adjArea->m_distanceToBombTarget = newTravelDistance;
adjArea->Mark();
adjArea->SetParent( area );
if ( !adjArea->IsOpen() )
{
// Since we're doing a breadth-first search, this area will end up at the end of the list.
// Adding it to the tail explicitly saves us a bunch of list traversals.
adjArea->AddToOpenListTail();
}
}
else
{
// Found a shortcut this area that passes through the neighbor?
float newTravelDistanceFromAdjacent = adjacentTravelDistance + between;
if ( newTravelDistanceFromAdjacent + flTol < area->m_distanceToBombTarget )
{
// check if the reverse direction is cheaper (for the case of jumping off edges)
area->m_distanceToBombTarget = newTravelDistanceFromAdjacent;
area->Mark();
area->SetParent( adjArea );
if ( !area->IsOpen() )
{
// found a cheaper path, try to traverse backward
area->AddToOpenListTail();
}
}
}
}
}
}
//-------------------------------------------------------------------------
void CTFNavMesh::RecomputeInternalData( void )
{
CollectControlPointAreas();
RemoveAllMeshDecoration();
DecorateMesh();
ComputeBlockedAreas(); // relies on DecorateMesh() being complete
ComputeIncursionDistances();
ComputeInvasionAreas();
ComputeLegalBombDropAreas();
ComputeBombTargetDistance(); // for MvM
if ( m_recomputeReason == RESET || m_recomputeReason == SETUP_FINISHED )
{
// update point-conditionally blocked areas
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
if ( area->HasAttributeTF( TF_NAV_BLOCKED_UNTIL_POINT_CAPTURE ) )
{
area->SetAttributeTF( TF_NAV_BLOCKED );
}
}
}
if ( m_recomputeReason == POINT_CAPTURED )
{
// update point-conditionally blocked areas
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
if ( area->HasAttributeTF( TF_NAV_BLOCKED_UNTIL_POINT_CAPTURE ) )
{
// which point unblocks us?
// if no modifier given, unblock after first capture
bool isUnblocked = true;
if ( area->HasAttributeTF( TF_NAV_WITH_SECOND_POINT ) )
{
isUnblocked = (m_recomputeReasonWhichPoint >= 1);
}
else if ( area->HasAttributeTF( TF_NAV_WITH_THIRD_POINT ) )
{
isUnblocked = (m_recomputeReasonWhichPoint >= 2);
}
else if ( area->HasAttributeTF( TF_NAV_WITH_FOURTH_POINT ) )
{
isUnblocked = (m_recomputeReasonWhichPoint >= 3);
}
else if ( area->HasAttributeTF( TF_NAV_WITH_FIFTH_POINT ) )
{
isUnblocked = (m_recomputeReasonWhichPoint >= 4);
}
if ( isUnblocked )
{
area->ClearAttributeTF( TF_NAV_BLOCKED );
}
}
else if ( area->HasAttributeTF( TF_NAV_BLOCKED_AFTER_POINT_CAPTURE ) )
{
// which point blocks us?
// if no modifier given, block after first capture
bool isBlocked = true;
if ( area->HasAttributeTF( TF_NAV_WITH_SECOND_POINT ) )
{
isBlocked = ( m_recomputeReasonWhichPoint >= 1 );
}
else if ( area->HasAttributeTF( TF_NAV_WITH_THIRD_POINT ) )
{
isBlocked = ( m_recomputeReasonWhichPoint >= 2 );
}
else if ( area->HasAttributeTF( TF_NAV_WITH_FOURTH_POINT ) )
{
isBlocked = ( m_recomputeReasonWhichPoint >= 3 );
}
else if ( area->HasAttributeTF( TF_NAV_WITH_FIFTH_POINT ) )
{
isBlocked = ( m_recomputeReasonWhichPoint >= 4 );
}
if ( isBlocked )
{
area->SetAttributeTF( TF_NAV_BLOCKED );
}
}
}
}
m_recomputeInternalDataTimer.Invalidate();
}
//-------------------------------------------------------------------------
// Re-calculate sentry danger attributes.
void CTFNavMesh::OnObjectChanged()
{
// Clear all sentry danger attributes.
ResetMeshAttributes( false );
CUtlVector< CBaseObject * > ActiveSentries;
ActiveSentries.EnsureCapacity( 16 );
// Get a list of all sentries that aren't being carried or dying.
for ( int oit = 0; oit < IBaseObjectAutoList::AutoList().Count(); ++oit )
{
CBaseObject* obj = static_cast< CBaseObject* >( IBaseObjectAutoList::AutoList()[ oit ] );
if ( obj->ObjectType() == OBJ_SENTRYGUN )
{
if ( !obj->IsDying() && !obj->IsCarried() )
ActiveSentries.AddToTail( obj );
}
}
// Only go through the NavAreas if we found some live sentries. Hopefully some of these
// sentries will be able to shoot some spies in the face.
if ( ActiveSentries.Count() )
{
// We must iterate all of the nav areas because we're testing visibility
// and arbitrary switchback routes make the use of SearchSurroundingAreas
// not useful.
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea *>( TheNavAreas[ it ] );
// Check all active sentries against this area.
FOR_EACH_VEC( ActiveSentries, oit )
{
const CBaseObject* obj = ActiveSentries[ oit ];
// If this area in range of this sentry?
Vector close;
area->GetClosestPointOnArea( obj->GetAbsOrigin(), &close );
if ( ( obj->GetAbsOrigin() - close ).IsLengthLessThan( SENTRY_MAX_RANGE ) )
{
// Can this sentry reach this area?
if ( area->IsPartiallyVisible( obj->GetAbsOrigin() + Vector( 0, 0, 30.0f ), obj ) )
{
// If this area wasn't already added to m_sentryAreas, do it now.
if ( !area->HasAttributeTF( TF_NAV_BLUE_SENTRY_DANGER | TF_NAV_RED_SENTRY_DANGER ) )
m_sentryAreas.AddToTail( area );
// Mark this area as being potentially dangerous.
area->SetAttributeTF( ( obj->GetTeamNumber() == TF_TEAM_RED ) ? TF_NAV_RED_SENTRY_DANGER : TF_NAV_BLUE_SENTRY_DANGER );
}
}
}
}
}
if ( tf_show_sentry_danger.GetBool() )
DevMsg( "%s: sentries:%d areas count:%d\n", __FUNCTION__, ActiveSentries.Count(), m_sentryAreas.Count() );
}
//--------------------------------------------------------------------------------------------------------
/**
* Return true if a Sentry Gun has been built in the given area
*/
bool CTFNavMesh::IsSentryGunHere( CTFNavArea *area ) const
{
// Check to see if the area is on the highway to the danger zone.
// If it isn't then there shouldn't be a sentry gun here.
if ( area->HasAttributeTF( TF_NAV_BLUE_SENTRY_DANGER | TF_NAV_RED_SENTRY_DANGER ) )
{
// Walk through all the objects built by players
for ( int oit = 0; oit < IBaseObjectAutoList::AutoList().Count(); ++oit )
{
CBaseObject* obj = static_cast< CBaseObject* >( IBaseObjectAutoList::AutoList()[ oit ] );
if ( obj->ObjectType() == OBJ_SENTRYGUN )
{
// If this object is a sentry gun, and it's in this nav area, return true.
if ( GetNearestNavArea( obj ) == area )
return true;
}
}
}
return false;
}
//-------------------------------------------------------------------------
// Fill given vector will all objects on the given team
void CTFNavMesh::CollectBuiltObjects( CUtlVector< CBaseObject * > *collectionVector, int team )
{
collectionVector->RemoveAll();
// check all active sentries against this area
for ( int oit = 0; oit < IBaseObjectAutoList::AutoList().Count(); ++oit )
{
CBaseObject* obj = static_cast< CBaseObject* >( IBaseObjectAutoList::AutoList()[ oit ] );
if ( team == TEAM_ANY || obj->GetTeamNumber() == team )
{
collectionVector->AddToTail( obj );
}
}
}
//-------------------------------------------------------------------------
void CTFNavMesh::FireGameEvent( IGameEvent *event )
{
CNavMesh::FireGameEvent( event );
const CUtlString eventName( event->GetName() );
if ( eventName == "teamplay_point_captured" )
{
int whichPoint = event->GetInt( "cp" );
ScheduleRecomputationOfInternalData( POINT_CAPTURED, whichPoint );
}
else if ( eventName == "teamplay_setup_finished" )
{
ScheduleRecomputationOfInternalData( SETUP_FINISHED );
}
else if ( eventName == "teamplay_point_unlocked" )
{
// recompute since doors may have opened/etc (koth_nucleus)
int whichPoint = event->GetInt( "cp" );
ScheduleRecomputationOfInternalData( POINT_UNLOCKED, whichPoint );
}
else if ( eventName == "player_builtobject" ||
eventName == "player_carryobject" ||
eventName == "object_detonated" ||
eventName == "object_destroyed" )
{
// We don't need "player_dropobject" as "player_builtobject" is sent right after.
// Some message have "object", some have "objectid" - use the one that is set.
int objecttype = !event->IsEmpty( "objecttype" ) ? event->GetInt( "objecttype" ) : event->GetInt( "object" );
if ( objecttype == OBJ_SENTRYGUN )
{
if ( tf_show_sentry_danger.GetBool() )
DevMsg( "%s: Got sentrygun %s event\n", __FUNCTION__, eventName.Get() );
OnObjectChanged();
}
}
}
//-------------------------------------------------------------------------
void CTFNavMesh::BeginCustomAnalysis( bool bIncremental )
{
}
//-------------------------------------------------------------------------
// invoked when custom analysis step is complete
void CTFNavMesh::PostCustomAnalysis( void )
{
}
//-------------------------------------------------------------------------
void CTFNavMesh::EndCustomAnalysis()
{
}
//-------------------------------------------------------------------------
/**
* Returns sub-version number of data format used by derived classes
*/
unsigned int CTFNavMesh::GetSubVersionNumber( void ) const
{
// 1: initial implementation
// 2: added TF-specific attribute flags
return 2;
}
//-------------------------------------------------------------------------
/**
* Store custom mesh data for derived classes
*/
void CTFNavMesh::SaveCustomData( CUtlBuffer &fileBuffer ) const
{
}
//-------------------------------------------------------------------------
/**
* Load custom mesh data for derived classes
*/
void CTFNavMesh::LoadCustomData( CUtlBuffer &fileBuffer, unsigned int subVersion )
{
}
//-------------------------------------------------------------------------
/**
* Recompute travel distance from each team's spawn room for each nav area
*/
void CTFNavMesh::ComputeIncursionDistances( void )
{
VPROF_BUDGET( "CTFNavMesh::ComputeIncursionDistances", "NextBot" );
// invalidate all travel distances
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
for( int i=0; i<TF_TEAM_COUNT; ++i )
{
area->m_distanceFromSpawnRoom[i] = -1.0f;
}
}
bool isRedComputed = false;
bool isBlueComputed = false;
for ( int i=0; i<IFuncRespawnRoomAutoList::AutoList().Count(); ++i )
{
CFuncRespawnRoom *spawnRoom = static_cast< CFuncRespawnRoom* >( IFuncRespawnRoomAutoList::AutoList()[i] );
if ( !spawnRoom->GetActive() )
continue;
if ( spawnRoom->m_bDisabled )
continue;
// find a spawn point inside this room
for ( int i=0; i<ITFTeamSpawnAutoList::AutoList().Count(); ++i )
{
CTFTeamSpawn *spawnSpot = static_cast< CTFTeamSpawn* >( ITFTeamSpawnAutoList::AutoList()[i] );
if ( !spawnSpot->IsTriggered( NULL ) )
continue;
if ( spawnSpot->IsDisabled() )
continue;
if ( spawnSpot->GetTeamNumber() == TF_TEAM_RED && isRedComputed )
continue;
if ( spawnSpot->GetTeamNumber() == TF_TEAM_BLUE && isBlueComputed )
continue;
if ( spawnRoom->PointIsWithin( spawnSpot->GetAbsOrigin() ) )
{
// found a valid spawn spot in an active spawn room, compute travel distances throughout the nav mesh
CTFNavArea *spawnArea = static_cast< CTFNavArea * >( TheTFNavMesh()->GetNearestNavArea( spawnSpot ) );
if ( spawnArea )
{
ComputeIncursionDistances( spawnArea, spawnSpot->GetTeamNumber() );
if ( spawnSpot->GetTeamNumber() == TF_TEAM_RED )
{
isRedComputed = true;
}
else
{
isBlueComputed = true;
}
break;
}
}
}
}
if ( !isRedComputed )
{
Warning( "Can't compute incursion distances from the Red spawn room(s). Bots will perform poorly. This is caused by either a missing func_respawnroom, or missing info_player_teamspawn entities within the func_respawnroom.\n" );
}
if ( !isBlueComputed )
{
Warning( "Can't compute incursion distances from the Blue spawn room(s). Bots will perform poorly. This is caused by either a missing func_respawnroom, or missing info_player_teamspawn entities within the func_respawnroom.\n" );
}
if ( !TFGameRules()->IsMannVsMachineMode() )
{
// In Raid mode, the Red (bot) team has no spawn room.
// So, we'll assume the Red incursion distance is the inverse of the Blue incursion distance for now.
// @TODO: Use the Boss battle room as the anchor for computing Red incursion distances
float maxBlueIncursionDistance = 0.0f;
for( int i=0; i<TheNavAreas.Count(); ++i )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ i ] );
if ( area->GetIncursionDistance( TF_TEAM_BLUE ) > maxBlueIncursionDistance )
{
maxBlueIncursionDistance = area->GetIncursionDistance( TF_TEAM_BLUE );
}
}
for( int i=0; i<TheNavAreas.Count(); ++i )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ i ] );
if ( area->GetIncursionDistance( TF_TEAM_BLUE ) >= 0.0f )
{
area->m_distanceFromSpawnRoom[ TF_TEAM_RED ] = maxBlueIncursionDistance - area->GetIncursionDistance( TF_TEAM_BLUE );
}
}
}
}
//--------------------------------------------------------------------------------------------------------
/**
* Flood-fill outwards, marking flow distance as we go.
* When we reach an area, stop if it already has a lesser travel distance
*/
void CTFNavMesh::ComputeIncursionDistances( CTFNavArea *spawnArea, int team )
{
if ( spawnArea == NULL || team < 0 || team >= TF_TEAM_COUNT )
{
return;
}
CNavArea::ClearSearchLists();
spawnArea->m_distanceFromSpawnRoom[ team ] = 0.0f;
spawnArea->AddToOpenList();
spawnArea->Mark();
spawnArea->SetParent( NULL );
CUtlVectorFixedGrowable< const NavConnect *, 64 > adjAreaVector;
//TFNavAttributeType teamSpawnRoom = ( team == TF_TEAM_RED ) ? TF_NAV_SPAWN_ROOM_RED : TF_NAV_SPAWN_ROOM_BLUE;
while( !CNavArea::IsOpenListEmpty() )
{
// get next area to check
CTFNavArea *area = static_cast< CTFNavArea * >( CNavArea::PopOpenList() );
bool bIgnoreBlockedAreas = false;
#ifdef TF_RAID_MODE
// TODO: Raid mode ignores blocked areas for now (cap gates break this)
if ( TFGameRules()->IsRaidMode() )
{
bIgnoreBlockedAreas = true;
}
#endif // TF_RAID_MODE
// TODO: Ditto for Mann Vs Machine mode
if ( TFGameRules()->IsMannVsMachineMode() )
{
bIgnoreBlockedAreas = true;
}
if ( !bIgnoreBlockedAreas )
{
// ignore spawn room exits, since they presumably will be open
// ignore setup gates, since they will be open after the setup time
if ( !area->HasAttributeTF( TF_NAV_SPAWN_ROOM_EXIT | TF_NAV_BLUE_SETUP_GATE | TF_NAV_RED_SETUP_GATE ) && area->IsBlocked( team ) )
{
// don't pass through blocked areas
continue;
}
}
// explore adjacent floor areas
adjAreaVector.RemoveAll();
for( int dir=0; dir<NUM_DIRECTIONS; ++dir )
{
// collect all OUTGOING links from this area to adjacent areas
const NavConnectVector *adjVector = area->GetAdjacentAreas( (NavDirType)dir );
FOR_EACH_VEC( (*adjVector), bit )
{
adjAreaVector.AddToTail( &(*adjVector)[ bit ] );
}
}
FOR_EACH_VEC( adjAreaVector, vit )
{
const NavConnect *connect = adjAreaVector[ vit ];
CTFNavArea *adjArea = static_cast< CTFNavArea * >( connect->area );
if ( area->ComputeAdjacentConnectionHeightChange( adjArea ) > TF_PLAYER_JUMP_HEIGHT )
{
// don't go up ledges too high to jump
continue;
}
// compute travel distance
float newTravelDistance = 0.0f;
// travel distance is zero in all areas of our spawn room
// if ( !adjArea->HasAttributeTF( teamSpawnRoom ) )
{
float between = connect->length;
newTravelDistance = area->m_distanceFromSpawnRoom[ team ] + between;
}
float adjacentTravelDistance = adjArea->m_distanceFromSpawnRoom[ team ];
if ( adjacentTravelDistance < 0.0f || adjacentTravelDistance > newTravelDistance )
{
adjArea->m_distanceFromSpawnRoom[ team ] = newTravelDistance;
adjArea->Mark();
adjArea->SetParent( area );
if ( !adjArea->IsOpen() )
{
// Since we're doing a breadth-first search, this area will end up at the end of the list.
// Adding it to the tail explicitly saves us a bunch of list traversals.
adjArea->AddToOpenListTail();
}
}
}
}
}
//--------------------------------------------------------------------------------------------------------
void CTFNavMesh::ComputeInvasionAreas( void )
{
VPROF_BUDGET( "CTFNavMesh::ComputeInvasionAreas", "NextBot" );
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
area->ComputeInvasionAreaVectors();
}
}
//--------------------------------------------------------------------------------------------------------
class CCollectAndLabelSpawnRoomAreas
{
public:
CCollectAndLabelSpawnRoomAreas( void )
{
m_room = NULL;
}
void Init( CFuncRespawnRoom *room, int team, CUtlVector< CTFNavArea * > *areaVector )
{
m_room = room;
m_team = team;
m_areaVector = areaVector;
}
bool operator() ( CNavArea *baseArea )
{
static Vector stepHeight( 0.0f, 0.0f, 18.0f );
if ( !m_room )
return true;
if ( m_room->PointIsWithin( baseArea->GetCenter() + stepHeight ) ||
m_room->PointIsWithin( baseArea->GetCorner( NORTH_WEST ) + stepHeight ) ||
m_room->PointIsWithin( baseArea->GetCorner( NORTH_EAST ) + stepHeight ) ||
m_room->PointIsWithin( baseArea->GetCorner( SOUTH_WEST ) + stepHeight ) ||
m_room->PointIsWithin( baseArea->GetCorner( SOUTH_EAST ) + stepHeight ) )
{
CTFNavArea *area = (CTFNavArea *)baseArea;
area->SetAttributeTF( ( m_team == TF_TEAM_RED ) ? TF_NAV_SPAWN_ROOM_RED : TF_NAV_SPAWN_ROOM_BLUE );
m_areaVector->AddToTail( area );
}
return true;
}
CFuncRespawnRoom *m_room;
int m_team;
CUtlVector< CTFNavArea * > *m_areaVector;
};
//--------------------------------------------------------------------------------------------------------
void CTFNavMesh::CollectAndMarkSpawnRoomExits( CTFNavArea *area, CUtlVector< CTFNavArea * > *exitAreaVector )
{
for( int dir=0; dir<NUM_DIRECTIONS; ++dir )
{
const NavConnectVector *connect = area->GetAdjacentAreas( (NavDirType)dir );
if ( connect )
{
FOR_EACH_VEC( (*connect), cit )
{
CTFNavArea *adjArea = (CTFNavArea *)connect->Element(cit).area;
if ( !adjArea->HasAttributeTF( TF_NAV_SPAWN_ROOM_BLUE | TF_NAV_SPAWN_ROOM_RED ) )
{
// adjacent area leads out of spawn room - this is an exit
area->SetAttributeTF( TF_NAV_SPAWN_ROOM_EXIT );
exitAreaVector->AddToTail( area );
return;
}
}
}
}
}
//--------------------------------------------------------------------------------------------------------
void CTFNavMesh::DecorateMesh( void )
{
VPROF_BUDGET( "CTFNavMesh::DecorateMesh", "NextBot" );
CBaseEntity *entity = NULL;
CCollectAndLabelSpawnRoomAreas collectAndLabel;
Extent extent;
// mark spawn rooms
m_redSpawnRoomAreaVector.RemoveAll();
m_blueSpawnRoomAreaVector.RemoveAll();
for ( int iFuncRespawnRoom=0; iFuncRespawnRoom<IFuncRespawnRoomAutoList::AutoList().Count(); ++iFuncRespawnRoom )
{
CFuncRespawnRoom *respawnRoom = static_cast< CFuncRespawnRoom* >( IFuncRespawnRoomAutoList::AutoList()[iFuncRespawnRoom] );
if ( !respawnRoom->GetActive() )
continue;
if ( respawnRoom->m_bDisabled )
continue;
// func_respawn rooms only enforce spawn room rules. We need to search for enabled
// info_player_teamspawn entities contained within an active func_respawnroom in
// order to locate the current set of active spawn rooms
// find a spawn point inside this room
for ( int iTFTeamSpawn=0; iTFTeamSpawn<ITFTeamSpawnAutoList::AutoList().Count(); ++iTFTeamSpawn )
{
CTFTeamSpawn *spawnSpot = static_cast< CTFTeamSpawn* >( ITFTeamSpawnAutoList::AutoList()[iTFTeamSpawn] );
if ( !spawnSpot->IsTriggered( NULL ) )
continue;
if ( spawnSpot->IsDisabled() )
continue;
if ( respawnRoom->PointIsWithin( spawnSpot->GetAbsOrigin() ) )
{
// found a valid spawn spot in an active spawn room
collectAndLabel.Init( respawnRoom, spawnSpot->GetTeamNumber(), spawnSpot->GetTeamNumber() == TF_TEAM_RED ? &m_redSpawnRoomAreaVector : &m_blueSpawnRoomAreaVector );
extent.Init( respawnRoom );
TheNavMesh->ForAllAreasOverlappingExtent( collectAndLabel, extent );
}
}
}
// mark each spawn room area adjacent to a non-spawn room area as an exit
m_redSpawnRoomExitAreaVector.RemoveAll();
m_blueSpawnRoomExitAreaVector.RemoveAll();
FOR_EACH_VEC( m_redSpawnRoomAreaVector, rit )
{
CollectAndMarkSpawnRoomExits( m_redSpawnRoomAreaVector[ rit ], &m_redSpawnRoomExitAreaVector );
}
FOR_EACH_VEC( m_blueSpawnRoomAreaVector, bit )
{
CollectAndMarkSpawnRoomExits( m_blueSpawnRoomAreaVector[ bit ], &m_blueSpawnRoomExitAreaVector );
}
// mark ammo areas
entity = NULL;
while( ( entity = gEntList.FindEntityByClassname( entity, "item_ammopack*" ) ) != NULL )
{
CTFNavArea *area = (CTFNavArea *)TheTFNavMesh()->GetNearestNavArea( entity->GetAbsOrigin() );
if ( area )
{
area->SetAttributeTF( TF_NAV_HAS_AMMO );
}
}
// mark health areas
entity = NULL;
while( ( entity = gEntList.FindEntityByClassname( entity, "item_healthkit*" ) ) != NULL )
{
CTFNavArea *area = (CTFNavArea *)TheTFNavMesh()->GetNearestNavArea( entity->GetAbsOrigin() );
if ( area )
{
area->SetAttributeTF( TF_NAV_HAS_HEALTH );
}
}
// mark control points
for( int p=0; p<MAX_CONTROL_POINTS; ++p )
{
CUtlVector< CTFNavArea * > *pointAreaVector = &m_controlPointAreaVector[ p ];
for( int i=0; i<pointAreaVector->Count(); ++i )
{
pointAreaVector->Element(i)->SetAttributeTF( TF_NAV_CONTROL_POINT );
}
}
}
//--------------------------------------------------------------------------------------------------------
void CTFNavMesh::RemoveAllMeshDecoration( void )
{
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
// wipe all non-persistent attributes
area->ClearAttributeTF( (TFNavAttributeType)( ~TF_NAV_PERSISTENT_ATTRIBUTES ) );
}
// We just cleared all our SENTRY_DANGER attributes. Wipe m_sentryAreas and recompute.
m_sentryAreas.RemoveAll();
OnObjectChanged();
}
//--------------------------------------------------------------------------------------------------------
void CTFNavMesh::ResetMeshAttributes( bool bScheduleRecomputation )
{
// Clear all sentry danger attributes.
FOR_EACH_VEC( m_sentryAreas, nit )
{
// One of the sentry danger attributes should be set.
Assert( bScheduleRecomputation || m_sentryAreas[ nit ]->HasAttributeTF( TF_NAV_BLUE_SENTRY_DANGER | TF_NAV_RED_SENTRY_DANGER ) );
m_sentryAreas[ nit ]->ClearAttributeTF( TF_NAV_BLUE_SENTRY_DANGER | TF_NAV_RED_SENTRY_DANGER );
}
m_sentryAreas.RemoveAll();
#ifdef DBGFLAG_ASSERT
FOR_EACH_VEC( TheNavAreas, it )
{
// Sentry danger attributes should not be set anywhere.
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
Assert( !area->HasAttributeTF( TF_NAV_BLUE_SENTRY_DANGER | TF_NAV_RED_SENTRY_DANGER ) );
}
#endif
if ( bScheduleRecomputation )
{
ScheduleRecomputationOfInternalData( RESET );
}
}
//--------------------------------------------------------------------------------------------------------
class DrawIncursionFlow
{
public:
bool operator() ( CNavArea *baseArea )
{
CTFNavArea *area = static_cast< CTFNavArea * >( baseArea );
int team = ( tf_show_incursion_flow.GetInt() == 1 ) ? TF_TEAM_RED : TF_TEAM_BLUE;
const float cycleRange = 2500.0f;
const float cycleRate = 0.333f; // cycles/sec
float baseFlow = area->GetIncursionDistance( team );
for( int dir=0; dir<NUM_DIRECTIONS; ++dir )
{
const NavConnectVector *adjVector = area->GetAdjacentAreas( (NavDirType)dir );
FOR_EACH_VEC( (*adjVector), bit )
{
CTFNavArea *adjArea = static_cast< CTFNavArea * >( (*adjVector)[ bit ].area );
if ( area->ComputeAdjacentConnectionHeightChange( adjArea ) > TF_PLAYER_JUMP_HEIGHT )
{
// don't go up ledges too high to jump
continue;
}
float adjFlow = adjArea->GetIncursionDistance( team );
if ( adjFlow > baseFlow )
{
float cycle = fmod( adjFlow - ( gpGlobals->curtime * cycleRate * cycleRange ), cycleRange );
float t = 2.0f * cycle / cycleRange;
if ( t > 1.0f )
{
t = 2.0f - t;
}
int r, g, b;
if ( team == TF_TEAM_RED )
{
r = 255 * t;
g = 0;
b = 0;
}
else
{
r = 0;
g = 0;
b = 255 * t;
}
NDebugOverlay::HorzArrow( area->GetCenter(), adjArea->GetCenter(), 5.0f, r, g, b, 255, true, NDEBUG_PERSIST_TILL_NEXT_SERVER );
}
}
}
return true;
}
};
void CTFNavMesh::UpdateDebugDisplay( void ) const
{
// avoid Warning() spam from UTIL_GetListenServerHost when on a dedicated server
if ( engine->IsDedicatedServer() )
return;
CBasePlayer *player = UTIL_GetListenServerHost();
if ( player == NULL )
return;
if ( tf_show_in_combat_areas.GetBool() )
{
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
if ( area->IsInCombat() )
{
float t = area->GetCombatIntensity();
area->DrawFilled( t * 255, 0, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
}
}
}
if ( tf_show_enemy_invasion_areas.GetBool() )
{
CTFNavArea *myArea = static_cast< CTFNavArea * >( player->GetLastKnownArea() );
if ( myArea )
{
const CUtlVector< CTFNavArea * > &invasionAreaVector = myArea->GetEnemyInvasionAreaVector( player->GetTeamNumber() );
FOR_EACH_VEC( invasionAreaVector, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( invasionAreaVector[ it ] );
area->DrawFilled( 255, 0, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
}
}
}
if ( tf_show_bomb_drop_areas.GetBool() )
{
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
if ( area->HasAttributeTF( TF_NAV_BOMB_CAN_DROP_HERE ) )
{
area->DrawFilled( 0, 255, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
}
}
}
if ( tf_show_blocked_areas.GetBool() )
{
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
const char *describe = "";
if ( area->HasAttributeTF( TF_NAV_BLOCKED ) )
{
area->DrawFilled( 255, 0, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true, 0.0f );
}
if ( area->IsBlocked( TF_TEAM_RED ) )
{
if ( area->IsBlocked( TF_TEAM_BLUE ) )
{
area->DrawFilled( 100, 0, 100, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Blocked for All";
}
else
{
area->DrawFilled( 100, 0, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Blocked for Red";
}
}
else if ( area->IsBlocked( TF_TEAM_BLUE ) )
{
area->DrawFilled( 0, 0, 100, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Blocked for Blue";
}
if ( describe && TheNavMesh->GetSelectedArea() == area )
{
NDebugOverlay::Text( area->GetCenter(), describe, false, NDEBUG_PERSIST_TILL_NEXT_SERVER );
}
}
}
if ( tf_show_incursion_flow.GetInt() > 0 || tf_show_incursion_flow_gradient.GetInt() > 0 )
{
Vector forward;
AngleVectors( player->EyeAngles() + player->GetPunchAngle(), &forward );
float maxRange = 2000.0f;
Vector to = player->EyePosition() + maxRange * forward;
trace_t result;
CTraceFilterWalkableEntities filter( NULL, COLLISION_GROUP_NONE, WALK_THRU_EVERYTHING );
UTIL_TraceLine( player->EyePosition(), to, MASK_NPCSOLID, &filter, &result );
CTFNavArea *selectedArea = static_cast< CTFNavArea * >( TheNavMesh->GetNearestNavArea( result.endpos, false, 500.0f ) );
if ( selectedArea )
{
if ( tf_show_incursion_flow.GetInt() > 0 )
{
DrawIncursionFlow draw;
SearchSurroundingAreas( selectedArea, selectedArea->GetCenter(), draw, tf_show_incursion_flow_range.GetFloat() );
}
else if ( tf_show_incursion_flow_gradient.GetInt() > 0 )
{
int myTeam;
int r,g,b;
if ( tf_show_incursion_flow_gradient.GetInt() == 1 )
{
myTeam = TF_TEAM_RED;
r = 255;
g = 0;
b = 0;
}
else
{
myTeam = TF_TEAM_BLUE;
r = 0;
g = 0;
b = 255;
}
selectedArea->DrawFilled( r, g, b, 255 );
CUtlVector< CTFNavArea * > areaVector;
selectedArea->CollectPriorIncursionAreas( myTeam, &areaVector );
FOR_EACH_VEC( areaVector, p )
{
areaVector[p]->DrawFilled( r/2, g/2, b/2, 255 );
}
selectedArea->CollectNextIncursionAreas( myTeam, &areaVector );
FOR_EACH_VEC( areaVector, n )
{
areaVector[n]->DrawFilled( MIN( r+100, 255 ), MIN( g+100, 255 ), MIN( b+100, 255 ), 255 );
}
}
}
}
if ( tf_show_mesh_decoration.GetBool() && !tf_show_mesh_decoration_manual.GetBool() )
{
// render these from cached vectors to verify their data
int i;
const CUtlVector< CTFNavArea * > *areaVector;
areaVector = GetSpawnRoomAreas( TF_TEAM_BLUE );
if ( areaVector )
{
for( i=0; i<areaVector->Count(); ++i )
{
CTFNavArea *area = areaVector->Element(i);
if ( !area->HasAttributeTF( TF_NAV_SPAWN_ROOM_EXIT ) )
{
area->DrawFilled( 0, 0, 255, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
if ( TheNavMesh->GetSelectedArea() == area )
{
NDebugOverlay::Text( area->GetCenter(), "Blue Spawn Room", false, NDEBUG_PERSIST_TILL_NEXT_SERVER );
}
}
}
}
areaVector = GetSpawnRoomExitAreas( TF_TEAM_BLUE );
if ( areaVector )
{
for( i=0; i<areaVector->Count(); ++i )
{
CTFNavArea *area = areaVector->Element(i);
area->DrawFilled( 150, 150, 255, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
if ( TheNavMesh->GetSelectedArea() == area )
{
NDebugOverlay::Text( area->GetCenter(), "Blue Spawn Exit", false, NDEBUG_PERSIST_TILL_NEXT_SERVER );
}
}
}
areaVector = GetSpawnRoomAreas( TF_TEAM_RED );
if ( areaVector )
{
for( i=0; i<areaVector->Count(); ++i )
{
CTFNavArea *area = areaVector->Element(i);
if ( !area->HasAttributeTF( TF_NAV_SPAWN_ROOM_EXIT ) )
{
area->DrawFilled( 255, 0, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
if ( TheNavMesh->GetSelectedArea() == area )
{
NDebugOverlay::Text( area->GetCenter(), "Red Spawn Room", false, NDEBUG_PERSIST_TILL_NEXT_SERVER );
}
}
}
}
areaVector = GetSpawnRoomExitAreas( TF_TEAM_RED );
if ( areaVector )
{
for( i=0; i<areaVector->Count(); ++i )
{
CTFNavArea *area = areaVector->Element(i);
area->DrawFilled( 255, 150, 150, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
if ( TheNavMesh->GetSelectedArea() == area )
{
NDebugOverlay::Text( area->GetCenter(), "Red Spawn Exit", false, NDEBUG_PERSIST_TILL_NEXT_SERVER );
}
}
}
}
if ( tf_show_mesh_decoration.GetBool() || tf_show_mesh_decoration_manual.GetBool() )
{
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
const char *describe = "";
if ( !tf_show_mesh_decoration_manual.GetBool() )
{
if ( area->HasAttributeTF( TF_NAV_HAS_AMMO ) && area->HasAttributeTF( TF_NAV_HAS_HEALTH ) )
{
area->DrawFilled( 255, 0, 255, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Health & Ammo";
}
else
{
if ( area->HasAttributeTF( TF_NAV_HAS_AMMO ) )
{
area->DrawFilled( 100, 100, 100, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Ammo";
}
else if ( area->HasAttributeTF( TF_NAV_HAS_HEALTH ) )
{
area->DrawFilled( 255, 150, 150, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Health";
}
}
if ( area->HasAttributeTF( TF_NAV_CONTROL_POINT ) )
{
area->DrawFilled( 0, 255, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Control Point";
}
if ( area->HasAttributeTF( TF_NAV_BLUE_ONE_WAY_DOOR ) )
{
area->DrawFilled( 100, 100, 255, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
}
if ( area->HasAttributeTF( TF_NAV_RED_ONE_WAY_DOOR ) )
{
area->DrawFilled( 255, 100, 100, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
}
}
if ( area->HasAttributeTF( TF_NAV_SNIPER_SPOT ) )
{
area->DrawFilled( 255, 255, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Sniper Spot";
}
if ( area->HasAttributeTF( TF_NAV_SENTRY_SPOT ) )
{
area->DrawFilled( 255, 100, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Sentry Spot";
}
if ( area->HasAttributeTF( TF_NAV_NO_SPAWNING ) )
{
area->DrawFilled( 100, 100, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "No Spawning";
}
if ( area->HasAttributeTF( TF_NAV_RESCUE_CLOSET ) )
{
area->DrawFilled( 0, 255, 255, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Rescue Closet";
}
if ( area->HasAttributeTF( TF_NAV_BLOCKED_UNTIL_POINT_CAPTURE ) )
{
area->DrawFilled( 0, 255, 255, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
if ( area->HasAttributeTF( TF_NAV_WITH_SECOND_POINT ) )
{
describe = "Blocked Until Second Point Captured";
}
else if ( area->HasAttributeTF( TF_NAV_WITH_THIRD_POINT ) )
{
describe = "Blocked Until Third Point Captured";
}
else if ( area->HasAttributeTF( TF_NAV_WITH_FOURTH_POINT ) )
{
describe = "Blocked Until Fourth Point Captured";
}
else if ( area->HasAttributeTF( TF_NAV_WITH_FIFTH_POINT ) )
{
describe = "Blocked Until Fifth Point Captured";
}
else
{
describe = "Blocked Until First Point Captured";
}
}
if ( area->HasAttributeTF( TF_NAV_BLOCKED_AFTER_POINT_CAPTURE ) )
{
area->DrawFilled( 255, 255, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
if ( area->HasAttributeTF( TF_NAV_WITH_SECOND_POINT ) )
{
describe = "Blocked After Second Point Captured";
}
else if ( area->HasAttributeTF( TF_NAV_WITH_THIRD_POINT ) )
{
describe = "Blocked After Third Point Captured";
}
else if ( area->HasAttributeTF( TF_NAV_WITH_FOURTH_POINT ) )
{
describe = "Blocked After Fourth Point Captured";
}
else if ( area->HasAttributeTF( TF_NAV_WITH_FIFTH_POINT ) )
{
describe = "Blocked After Fifth Point Captured";
}
else
{
describe = "Blocked After First Point Captured";
}
}
if ( area->HasAttributeTF( TF_NAV_BLUE_SETUP_GATE ) )
{
area->DrawFilled( 0, 0, 100, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Blue Setup Gate";
}
if ( area->HasAttributeTF( TF_NAV_RED_SETUP_GATE ) )
{
area->DrawFilled( 100, 0, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Red Setup Gate";
}
if ( area->HasAttributeTF( TF_NAV_DOOR_ALWAYS_BLOCKS ) )
{
area->DrawFilled( 100, 0, 100, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Door Always Blocks";
}
if ( area->HasAttributeTF( TF_NAV_DOOR_NEVER_BLOCKS ) )
{
area->DrawFilled( 0, 100, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Door Never Blocks";
}
if ( area->HasAttributeTF( TF_NAV_UNBLOCKABLE ) )
{
area->DrawFilled( 0, 200, 100, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
describe = "Unblockable";
}
if ( describe && TheNavMesh->GetSelectedArea() == area )
{
NDebugOverlay::Text( area->GetCenter(), describe, false, NDEBUG_PERSIST_TILL_NEXT_SERVER );
}
}
}
if ( tf_show_sentry_danger.GetBool() )
{
if ( tf_show_sentry_danger.GetInt() == 2 )
{
// Walk all TheNavAreas entries. Left this code in to help debug in case
// TheNavAreas is never not _exactly_ the same as m_sentryAreas.
FOR_EACH_VEC( TheNavAreas, it )
{
const CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
int r = area->HasAttributeTF( TF_NAV_RED_SENTRY_DANGER ) * 255;
int b = area->HasAttributeTF( TF_NAV_BLUE_SENTRY_DANGER ) * 255;
if ( r || b )
{
area->DrawFilled( r, 0, b, 80, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
}
}
}
else
{
// Only go through the m_SentryAreas entries. Should be the same as walking the
// entire TheNavAreas, but a lot faster.
FOR_EACH_VEC( m_sentryAreas, nit )
{
const CTFNavArea *area = m_sentryAreas[ nit ];
int r = area->HasAttributeTF( TF_NAV_RED_SENTRY_DANGER ) * 255;
int b = area->HasAttributeTF( TF_NAV_BLUE_SENTRY_DANGER ) * 255;
if ( r || b )
{
area->DrawFilled( r, 0, b, 80, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
}
}
}
}
if ( tf_show_actor_potential_visibility.GetBool() )
{
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
if ( area->IsPotentiallyVisibleToTeam( TF_TEAM_BLUE ) )
{
if ( area->IsPotentiallyVisibleToTeam( TF_TEAM_RED ) )
{
area->DrawFilled( 255, 0, 255, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
}
else
{
area->DrawFilled( 0, 0, 255, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
}
}
else if ( area->IsPotentiallyVisibleToTeam( TF_TEAM_RED ) )
{
area->DrawFilled( 255, 0, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
}
}
}
/*
if ( tf_show_gate_defense_areas.GetBool() )
{
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
if ( area->HasAttributeTF( TF_NAV_DEFEND_SETUP_GATES ) )
{
if ( area->HasAttributeTF( TF_NAV_DEFEND_VIA_SNIPING ) )
area->DrawFilled( 0, 255, 255, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
else if ( area->HasAttributeTF( TF_NAV_DEFEND_VIA_AMBUSH ) )
area->DrawFilled( 255, 0, 255, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
else
area->DrawFilled( 0, 0, 255, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
}
}
}
if ( tf_show_point_defense_areas.GetBool() )
{
FOR_EACH_VEC( TheNavAreas, it )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ it ] );
if ( area->HasAttributeTF( TF_NAV_DEFEND_POINT ) )
{
if ( area->HasAttributeTF( TF_NAV_DEFEND_VIA_SNIPING ) )
area->DrawFilled( 0, 255, 100, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
else if ( area->HasAttributeTF( TF_NAV_DEFEND_VIA_AMBUSH ) )
area->DrawFilled( 255, 150, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
else
area->DrawFilled( 0, 150, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER, true );
}
}
}
*/
if ( tf_show_control_points.GetBool() )
{
for( int which=0; which<MAX_CONTROL_POINTS; ++which )
{
for( int i=0; i<m_controlPointAreaVector[ which ].Count(); ++i )
{
CTFNavArea *area = m_controlPointAreaVector[ which ][ i ];
if ( m_controlPointCenterAreaVector[ which ] == area )
{
area->DrawFilled( 255, 255, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER );
}
else
{
area->DrawFilled( 255, 150, 0, 255, NDEBUG_PERSIST_TILL_NEXT_SERVER );
}
}
}
}
}
//--------------------------------------------------------------------------------------------------------
/**
* Populate the given "ambushVector" with good areas to lurk in ambush for the invading enemy team
*/
void CTFNavMesh::CollectAmbushAreas( CUtlVector< CTFNavArea * > *ambushVector, CTFNavArea *startArea, int teamToAmbush, float searchRadius, float incursionTolerance ) const
{
ScanSelectAmbushAreas selector( ambushVector, teamToAmbush, startArea->GetIncursionDistance( teamToAmbush ) + incursionTolerance );
SearchSurroundingAreas( startArea, startArea->GetCenter(), selector, searchRadius );
}
//--------------------------------------------------------------------------------------------------------
/**
* Populate the given vector with areas that are just outside of the given team's spawn room(s)
*/
void CTFNavMesh::CollectSpawnRoomThresholdAreas( CUtlVector< CTFNavArea * > *spawnExitAreaVector, int team ) const
{
const CUtlVector< CTFNavArea * > *exitAreaVector = GetSpawnRoomExitAreas( team );
if ( !exitAreaVector )
return;
for( int i=0; i<exitAreaVector->Count(); ++i )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ i ] );
// find largest non-spawn-room area connected to this exit
CTFNavArea *exitArea = NULL;
float exitAreaSize = 0.0f;
for( int dir=0; dir<NUM_DIRECTIONS; ++dir )
{
const NavConnectVector *adjConnect = area->GetAdjacentAreas( (NavDirType)dir );
for( int j=0; j<adjConnect->Count(); ++j )
{
CTFNavArea *adjArea = (CTFNavArea *)adjConnect->Element(j).area;
if ( !adjArea->HasAttributeTF( TF_NAV_SPAWN_ROOM_RED | TF_NAV_SPAWN_ROOM_BLUE | TF_NAV_SPAWN_ROOM_EXIT ) )
{
// this area is outside of the spawn room
float size = adjArea->GetSizeX() * adjArea->GetSizeY();
if ( size > exitAreaSize )
{
exitArea = adjArea;
exitAreaSize = size;
}
}
}
}
if ( exitArea )
{
spawnExitAreaVector->AddToTail( exitArea );
}
}
}
//--------------------------------------------------------------------------------------------------------
// Populate the given vector with areas that have a bomb travel distance within the given range
void CTFNavMesh::CollectAreaWithinBombTravelRange( CUtlVector< CTFNavArea * > *spawnExitAreaVector, float minTravel, float maxTravel ) const
{
for( int i=0; i<TheNavAreas.Count(); ++i )
{
CTFNavArea *area = static_cast< CTFNavArea * >( TheNavAreas[ i ] );
float travelDistance = area->GetTravelDistanceToBombTarget();
if ( travelDistance >= minTravel && travelDistance <= maxTravel )
{
spawnExitAreaVector->AddToTail( area );
}
}
}
|