aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/server/ai_behavior_assault.cpp
blob: e02627cc60ee2547a253ea1a71a4ef64328e4991 (plain) (blame)
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//
#include "cbase.h"
#include "ai_behavior_assault.h"
#include "ai_navigator.h"
#include "ai_memory.h"
#include "ai_squad.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

ConVar ai_debug_assault("ai_debug_assault", "0");

BEGIN_DATADESC( CRallyPoint )
	DEFINE_KEYFIELD( m_AssaultPointName, FIELD_STRING, "assaultpoint" ),
	DEFINE_KEYFIELD( m_RallySequenceName, FIELD_STRING, "rallysequence" ),
	DEFINE_KEYFIELD( m_flAssaultDelay, FIELD_FLOAT, "assaultdelay" ),
	DEFINE_KEYFIELD( m_iPriority, FIELD_INTEGER, "priority" ),
	DEFINE_KEYFIELD( m_iStrictness, FIELD_INTEGER, "strict" ),
	DEFINE_KEYFIELD( m_bForceCrouch, FIELD_BOOLEAN, "forcecrouch" ),
	DEFINE_KEYFIELD( m_bIsUrgent, FIELD_BOOLEAN, "urgent" ),
	DEFINE_FIELD( m_hLockedBy, FIELD_EHANDLE ),
	DEFINE_FIELD( m_sExclusivity, FIELD_SHORT ),

	DEFINE_OUTPUT( m_OnArrival, "OnArrival" ),
END_DATADESC();

//---------------------------------------------------------
// Purpose: Communicate exclusivity
//---------------------------------------------------------
int CRallyPoint::DrawDebugTextOverlays()
{
	int		offset;

	offset = BaseClass::DrawDebugTextOverlays();
	if ( (m_debugOverlays & OVERLAY_TEXT_BIT) )
	{	
		switch( m_sExclusivity )
		{
		case RALLY_EXCLUSIVE_NOT_EVALUATED:
			EntityText( offset, "Exclusive: Not Evaluated", 0 );
			break;
		case RALLY_EXCLUSIVE_YES:
			EntityText( offset, "Exclusive: YES", 0 );
			break;
		case RALLY_EXCLUSIVE_NO:
			EntityText( offset, "Exclusive: NO", 0 );
			break;
		default:
			EntityText( offset, "Exclusive: !?INVALID?!", 0 );
			break;
		}
		offset++;

		if( IsLocked() )
			EntityText( offset, "LOCKED.", 0 );
		else
			EntityText( offset, "Available", 0 );

		offset++;
	}

	return offset;
}

//---------------------------------------------------------
// Purpose: If a rally point is 'exclusive' that means that
// anytime an NPC is anywhere on the assault chain that
// begins with this rally point, the assault is considered
// 'exclusive' and no other NPCs will be allowed to use it
// until the current NPC clears the entire assault chain
// or dies.
// 
// If exclusivity has not been determined the first time
// this function is called, it will be computed and cached
//---------------------------------------------------------
bool CRallyPoint::IsExclusive()
{
#ifndef HL2_EPISODIC // IF NOT EPISODIC
	// This 'exclusivity' concept is new to EP2. We're only willing to
	// risk causing problems in EP1, so emulate the old behavior if 
	// we are not EPISODIC. We must do this by setting m_sExclusivity
	// so that ent_text will properly report the state.
	m_sExclusivity = RALLY_EXCLUSIVE_NO;
#else
	if( m_sExclusivity == RALLY_EXCLUSIVE_NOT_EVALUATED )
	{
		// We need to evaluate! Walk the chain of assault points
		// and if *ANY* assault points  on this assault chain
		// are set to Never Time Out then set this rally point to 
		// be exclusive to stop other NPC's walking down the chain
		// and ending up clumped up at the infinite rally point.
		CAssaultPoint *pAssaultEnt = (CAssaultPoint *)gEntList.FindEntityByName( NULL, m_AssaultPointName );

		if( !pAssaultEnt )
		{
			// Well, this is awkward. Leave it up to other assault code to tattle on the missing assault point.
			// We will just assume this assault is not exclusive.
			m_sExclusivity = RALLY_EXCLUSIVE_NO;
			return false;
		}

		// Otherwise, we start by assuming this assault chain is not exclusive.
		m_sExclusivity = RALLY_EXCLUSIVE_NO;

		if( pAssaultEnt )
		{
			CAssaultPoint *pFirstAssaultEnt = pAssaultEnt; //some assault chains are circularly linked

			do
			{
				if( pAssaultEnt->m_bNeverTimeout )
				{
					// We found a never timeout assault point! That makes this whole chain exclusive.
					m_sExclusivity = RALLY_EXCLUSIVE_YES;
					break;
				}

				pAssaultEnt = (CAssaultPoint *)gEntList.FindEntityByName( NULL, pAssaultEnt->m_NextAssaultPointName );
				
			} while( (pAssaultEnt != NULL) && (pAssaultEnt != pFirstAssaultEnt) );

		}
	}
#endif// HL2_EPISODIC 

	return (m_sExclusivity == RALLY_EXCLUSIVE_YES);
}


BEGIN_DATADESC( CAssaultPoint )
	DEFINE_KEYFIELD( m_AssaultHintGroup, FIELD_STRING, "assaultgroup" ),
	DEFINE_KEYFIELD( m_NextAssaultPointName, FIELD_STRING, "nextassaultpoint" ),
	DEFINE_KEYFIELD( m_flAssaultTimeout, FIELD_FLOAT, "assaulttimeout" ),
	DEFINE_KEYFIELD( m_bClearOnContact, FIELD_BOOLEAN, "clearoncontact" ),
	DEFINE_KEYFIELD( m_bAllowDiversion, FIELD_BOOLEAN, "allowdiversion" ),
	DEFINE_KEYFIELD( m_flAllowDiversionRadius, FIELD_FLOAT, "allowdiversionradius" ),
	DEFINE_KEYFIELD( m_bNeverTimeout, FIELD_BOOLEAN, "nevertimeout" ),
	DEFINE_KEYFIELD( m_iStrictness, FIELD_INTEGER, "strict" ),
	DEFINE_KEYFIELD( m_bForceCrouch, FIELD_BOOLEAN, "forcecrouch" ),
	DEFINE_KEYFIELD( m_bIsUrgent, FIELD_BOOLEAN, "urgent" ),
	DEFINE_FIELD( m_bInputForcedClear, FIELD_BOOLEAN ),
	DEFINE_KEYFIELD( m_flAssaultPointTolerance, FIELD_FLOAT, "assaulttolerance" ),
	DEFINE_FIELD( m_flTimeLastUsed, FIELD_TIME ),

	// Inputs
	DEFINE_INPUTFUNC( FIELD_BOOLEAN, "SetClearOnContact", InputSetClearOnContact ),
	DEFINE_INPUTFUNC( FIELD_BOOLEAN, "SetAllowDiversion", InputSetAllowDiversion ),
	DEFINE_INPUTFUNC( FIELD_BOOLEAN, "SetForceClear", InputSetForceClear ),

	// Outputs
	DEFINE_OUTPUT( m_OnArrival, "OnArrival" ),
	DEFINE_OUTPUT( m_OnAssaultClear, "OnAssaultClear" ),
END_DATADESC();

LINK_ENTITY_TO_CLASS( assault_rallypoint, CRallyPoint );	// just a copy of info_target for now
LINK_ENTITY_TO_CLASS( assault_assaultpoint, CAssaultPoint ); // has its own class because it needs the entity I/O

BEGIN_DATADESC( CAI_AssaultBehavior )
	DEFINE_FIELD( m_hAssaultPoint, FIELD_EHANDLE ),
	DEFINE_FIELD( m_hRallyPoint, FIELD_EHANDLE ),
	DEFINE_FIELD( m_AssaultCue, FIELD_INTEGER ),
	DEFINE_FIELD( m_ReceivedAssaultCue, FIELD_INTEGER ),
	DEFINE_FIELD( m_bHitRallyPoint, FIELD_BOOLEAN ),
	DEFINE_FIELD( m_bHitAssaultPoint, FIELD_BOOLEAN ),
	DEFINE_FIELD( m_bDiverting, FIELD_BOOLEAN ),
	DEFINE_FIELD( m_flLastSawAnEnemyAt, FIELD_FLOAT ),
	DEFINE_FIELD( m_flTimeDeferScheduleSelection, FIELD_TIME ),
	DEFINE_FIELD( m_AssaultPointName, FIELD_STRING )
END_DATADESC();

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CAI_AssaultBehavior::CanRunAScriptedNPCInteraction( bool bForced )
{
	if ( m_AssaultCue == CUE_NO_ASSAULT )
	{
		// It's OK with the assault behavior, so leave it up to the base class.
		return BaseClass::CanRunAScriptedNPCInteraction( bForced );
	}

	return false;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CAI_AssaultBehavior::CAI_AssaultBehavior()
{
	m_AssaultCue = CUE_NO_ASSAULT;
}

//-----------------------------------------------------------------------------
// Purpose: Draw any text overlays
// Input  : Previous text offset from the top
// Output : Current text offset from the top
//-----------------------------------------------------------------------------
int CAI_AssaultBehavior::DrawDebugTextOverlays( int text_offset )
{
	char	tempstr[ 512 ];
	int		offset;

	offset = BaseClass::DrawDebugTextOverlays( text_offset );
	if ( GetOuter()->m_debugOverlays & OVERLAY_TEXT_BIT )
	{	
		Q_snprintf( tempstr, sizeof(tempstr), "Assault Point: %s %s", STRING( m_AssaultPointName ), VecToString( m_hAssaultPoint->GetAbsOrigin() ) );
		GetOuter()->EntityText( offset, tempstr, 0 );
		offset++;
	}

	return offset;
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : cue - 
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::ReceiveAssaultCue( AssaultCue_t cue )
{
	if ( GetOuter() )
		GetOuter()->ForceDecisionThink();

	m_ReceivedAssaultCue = cue;

	SetCondition( COND_PROVOKED );
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
bool CAI_AssaultBehavior::AssaultHasBegun()
{
	if( m_AssaultCue == CUE_DONT_WAIT && IsRunning() && m_bHitRallyPoint )
	{
		return true;
	}

	return m_ReceivedAssaultCue == m_AssaultCue;
}

//-----------------------------------------------------------------------------
// Purpose: Find an assaultpoint matching the iszAssaultPointName. 
//			If more than one assault point of this type is found, randomly
//			use any of them EXCEPT the one most recently used.
//-----------------------------------------------------------------------------
CAssaultPoint *CAI_AssaultBehavior::FindAssaultPoint( string_t iszAssaultPointName )
{
	CUtlVector<CAssaultPoint*>pAssaultPoints;
	CUtlVector<CAssaultPoint*>pClearAssaultPoints;

	CAssaultPoint *pAssaultEnt = (CAssaultPoint *)gEntList.FindEntityByName( NULL, iszAssaultPointName );

	while( pAssaultEnt != NULL )
	{
		pAssaultPoints.AddToTail( pAssaultEnt );
		pAssaultEnt = (CAssaultPoint *)gEntList.FindEntityByName( pAssaultEnt, iszAssaultPointName );
	}

	// Didn't find any?!
	if( pAssaultPoints.Count() < 1 )
		return NULL;

	// Only found one, just return it.
	if( pAssaultPoints.Count() == 1 )
		return pAssaultPoints[0];

	// Throw out any nodes that I cannot fit my bounding box on.
	for( int i = 0 ; i < pAssaultPoints.Count() ; i++ )
	{
		trace_t tr;
		CAI_BaseNPC *pNPC = GetOuter();
		CAssaultPoint *pAssaultPoint = pAssaultPoints[i];

		AI_TraceHull ( pAssaultPoint->GetAbsOrigin(), pAssaultPoint->GetAbsOrigin(), pNPC->WorldAlignMins(), pNPC->WorldAlignMaxs(), MASK_SOLID, pNPC, COLLISION_GROUP_NONE, &tr );

		if ( tr.fraction == 1.0 )
		{
			// Copy this into the list of clear points.
			pClearAssaultPoints.AddToTail(pAssaultPoint);
		}
	}

	// Only one clear assault point left!
	if( pClearAssaultPoints.Count() == 1 )
		return pClearAssaultPoints[0];

	// NONE left. Just return a random assault point, knowing that it's blocked. This is the old behavior, anyway.
	if( pClearAssaultPoints.Count() < 1 )
		return pAssaultPoints[ random->RandomInt(0, (pAssaultPoints.Count() - 1)) ];

	// We found several! First throw out the one most recently used.
	// This prevents picking the same point at this branch twice in a row.
	float flMostRecentTime = -1.0f; // Impossibly old
	int iMostRecentIndex = -1;
	for( int i = 0 ; i < pClearAssaultPoints.Count() ; i++ )
	{
		if( pClearAssaultPoints[i]->m_flTimeLastUsed > flMostRecentTime )
		{
			flMostRecentTime = pClearAssaultPoints[i]->m_flTimeLastUsed;
			iMostRecentIndex = i;
		}
	}

	Assert( iMostRecentIndex > -1 );

	// Remove the most recently used 
	pClearAssaultPoints.Remove( iMostRecentIndex );
	return pClearAssaultPoints[ random->RandomInt(0, (pClearAssaultPoints.Count() - 1)) ];
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::SetAssaultPoint( CAssaultPoint *pAssaultPoint )
{
	m_hAssaultPoint = pAssaultPoint;
	pAssaultPoint->m_flTimeLastUsed = gpGlobals->curtime;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::ClearAssaultPoint( void )
{
	// To announce clear means that this NPC hasn't seen any live targets in
	// the assault area for the length of time the level designer has 
	// specified that they should be vigilant. This effectively deactivates
	// the assault behavior.
	// This can also be happen if an assault point has ClearOnContact set, and
	// an NPC assaulting to this point has seen an enemy.

	// keep track of the name of the assault point
	m_AssaultPointName = m_hAssaultPoint->m_NextAssaultPointName;

	// Do we need to move to another assault point?
	if( m_hAssaultPoint->m_NextAssaultPointName != NULL_STRING )
	{
		CAssaultPoint *pNextPoint = FindAssaultPoint( m_hAssaultPoint->m_NextAssaultPointName );
		
		if( pNextPoint )
		{
			SetAssaultPoint( pNextPoint );
			
			// Send our NPC to the next assault point!
			m_bHitAssaultPoint = false;

			return;
		}
		else
		{
			DevMsg("**ERROR: Can't find next assault point: %s\n", STRING(m_hAssaultPoint->m_NextAssaultPointName) );

			// Bomb out of assault behavior.
			m_AssaultCue = CUE_NO_ASSAULT;
			ClearSchedule( "Can't find next assault point" );

			return;
		}
	}

	// Just set the cue back to NO_ASSAULT. This disables the behavior.
	m_AssaultCue = CUE_NO_ASSAULT;

	// Exclusive or not, we unlock here. The assault is done.
	UnlockRallyPoint();

	// If this assault behavior has changed the NPC's hint group,
	// slam that NPC's hint group back to null.
	// !!!TODO: if the NPC had a different hint group before the 
	// assault began, we're slamming that, too! We might want
	// to cache it off if this becomes a problem (sjb)
	if( m_hAssaultPoint->m_AssaultHintGroup != NULL_STRING )
	{
		GetOuter()->SetHintGroup( NULL_STRING );
	}

	m_hAssaultPoint->m_OnAssaultClear.FireOutput( GetOuter(), GetOuter(), 0 );
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::OnHitAssaultPoint( void )
{
	GetOuter()->SpeakSentence( ASSAULT_SENTENCE_HIT_ASSAULT_POINT );
	m_bHitAssaultPoint = true;
	m_hAssaultPoint->m_OnArrival.FireOutput( GetOuter(), m_hAssaultPoint, 0 );

	// Set the assault hint group
	if( m_hAssaultPoint->m_AssaultHintGroup != NULL_STRING )
	{
		SetHintGroup( m_hAssaultPoint->m_AssaultHintGroup );
	}
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::GatherConditions( void )
{
	BaseClass::GatherConditions();

	// If this NPC is moving towards an assault point which
	//		a) Has a Next Assault Point, and 
	//		b) Is flagged to Clear On Arrival,
	// then hit and clear the assault point (fire all entity I/O) and move on to the next one without
	// interrupting the NPC's schedule. This provides a more fluid movement from point to point.
	if( IsCurSchedule( SCHED_MOVE_TO_ASSAULT_POINT ) && hl2_episodic.GetBool() )
	{
		if( m_hAssaultPoint && m_hAssaultPoint->HasSpawnFlags(SF_ASSAULTPOINT_CLEARONARRIVAL) && m_hAssaultPoint->m_NextAssaultPointName != NULL_STRING )
		{
			float flDist = GetAbsOrigin().DistTo( m_hAssaultPoint->GetAbsOrigin() );

			if( flDist <= GetOuter()->GetMotor()->MinStoppingDist() )
			{
				OnHitAssaultPoint();
				ClearAssaultPoint();

				AI_NavGoal_t goal( m_hAssaultPoint->GetAbsOrigin() );
				goal.pTarget = m_hAssaultPoint;
				
				if ( GetNavigator()->SetGoal( goal ) == false )
				{
					TaskFail( "Can't refresh assault path" );
				}
			}
		}
	}

	if ( IsForcingCrouch() && GetOuter()->IsCrouching() )
	{
		ClearCondition( COND_HEAR_BULLET_IMPACT );
	}

	if( OnStrictAssault() )
	{
		// Don't get distracted. Die trying if you have to.
		ClearCondition( COND_HEAR_DANGER );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pTask - 
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::StartTask( const Task_t *pTask )
{
	switch( pTask->iTask )
	{
	case TASK_RANGE_ATTACK1:
		BaseClass::StartTask( pTask );
		break;

	case TASK_ASSAULT_DEFER_SCHEDULE_SELECTION:
		m_flTimeDeferScheduleSelection = gpGlobals->curtime + pTask->flTaskData;
		TaskComplete();
		break;

	case TASK_ASSAULT_MOVE_AWAY_PATH:
		break;

	case TASK_ANNOUNCE_CLEAR:
		{
			// If we're at an assault point that can never be cleared, keep waiting forever (if it's the last point in the assault)
			if ( m_hAssaultPoint && 
				 !m_hAssaultPoint->HasSpawnFlags( SF_ASSAULTPOINT_CLEARONARRIVAL ) &&
				 m_hAssaultPoint->m_bNeverTimeout && 
				 m_hAssaultPoint->m_NextAssaultPointName == NULL_STRING )
			{
				TaskComplete();
				return;
			}

			ClearAssaultPoint();
			TaskComplete();
		}
		break;

	case TASK_WAIT_ASSAULT_DELAY:
		{
			if( m_hRallyPoint )
			{
				GetOuter()->SetWait( m_hRallyPoint->m_flAssaultDelay );
			}
			else
			{
				TaskComplete();
			}
		}
		break;

	case TASK_AWAIT_ASSAULT_TIMEOUT:
		// Maintain vigil for as long as the level designer has asked. Wait
		// and look for targets.
		GetOuter()->SetWait( m_hAssaultPoint->m_flAssaultTimeout );
		break;

	case TASK_GET_PATH_TO_RALLY_POINT:
		{
			AI_NavGoal_t goal( m_hRallyPoint->GetAbsOrigin() );
			goal.pTarget = m_hRallyPoint;
			if ( GetNavigator()->SetGoal( goal ) == false )
			{
				// Try and get as close as possible otherwise
				AI_NavGoal_t nearGoal( GOALTYPE_LOCATION_NEAREST_NODE, m_hRallyPoint->GetAbsOrigin(), AIN_DEF_ACTIVITY, 256 );
				if ( GetNavigator()->SetGoal( nearGoal, AIN_CLEAR_PREVIOUS_STATE ) )
				{
					//FIXME: HACK! The internal pathfinding is setting this without our consent, so override it!
					ClearCondition( COND_TASK_FAILED );
					GetNavigator()->SetArrivalDirection( m_hRallyPoint->GetAbsAngles() );
					TaskComplete();
					return;
				}
			}
			GetNavigator()->SetArrivalDirection( m_hRallyPoint->GetAbsAngles() );
		}
		break;

	case TASK_FACE_RALLY_POINT:
		{
			UpdateForceCrouch();
			
			GetMotor()->SetIdealYaw( m_hRallyPoint->GetAbsAngles().y );
			GetOuter()->SetTurnActivity(); 
		}
		break;

	case TASK_GET_PATH_TO_ASSAULT_POINT:
		{
			AI_NavGoal_t goal( m_hAssaultPoint->GetAbsOrigin() );
			goal.pTarget = m_hAssaultPoint;
			if ( GetNavigator()->SetGoal( goal ) == false )
			{
				// Try and get as close as possible otherwise
				AI_NavGoal_t nearGoal( GOALTYPE_LOCATION_NEAREST_NODE, m_hAssaultPoint->GetAbsOrigin(), AIN_DEF_ACTIVITY, 256 );
				if ( GetNavigator()->SetGoal( nearGoal, AIN_CLEAR_PREVIOUS_STATE ) )
				{
					//FIXME: HACK! The internal pathfinding is setting this without our consent, so override it!
					ClearCondition( COND_TASK_FAILED );
					GetNavigator()->SetArrivalDirection( m_hAssaultPoint->GetAbsAngles() );
					TaskComplete();
					return;
				}
			}
			GetNavigator()->SetArrivalDirection( m_hAssaultPoint->GetAbsAngles() );
		}
		break;

	case TASK_FACE_ASSAULT_POINT:
		{
			UpdateForceCrouch();

			if( HasCondition( COND_CAN_RANGE_ATTACK1 ) )
			{
				// If I can already fight when I arrive, don't bother running any facing code. Let
				// The combat AI do that. Turning here will only make the NPC look dumb in a combat
				// situation because it will take time to turn before attacking.
				TaskComplete();
			}
			else
			{
				GetMotor()->SetIdealYaw( m_hAssaultPoint->GetAbsAngles().y );
				GetOuter()->SetTurnActivity(); 
			}
		}
		break;

	case TASK_HIT_ASSAULT_POINT:
		OnHitAssaultPoint();
		TaskComplete();
		break;

	case TASK_HIT_RALLY_POINT:
		// Once we're stading on it and facing the correct direction,
		// we have arrived at rally point.
		GetOuter()->SpeakSentence( ASSAULT_SENTENCE_HIT_RALLY_POINT );

		m_bHitRallyPoint = true;
		m_hRallyPoint->m_OnArrival.FireOutput( GetOuter(), m_hRallyPoint, 0 );

		TaskComplete();
		break;

	case TASK_AWAIT_CUE:
		if( PollAssaultCue() )
		{
			TaskComplete();
		}
		else
		{
			// Don't do anything if we've been told to crouch
			if ( IsForcingCrouch() )
				break;

			else if( m_hRallyPoint->m_RallySequenceName != NULL_STRING )
			{
				// The cue hasn't been given yet, so set to the rally sequence.
				int sequence = GetOuter()->LookupSequence( STRING( m_hRallyPoint->m_RallySequenceName ) );
				if( sequence != -1 )
				{
					GetOuter()->ResetSequence( sequence );
					GetOuter()->SetIdealActivity( ACT_DO_NOT_DISTURB );
				}
			}
			else
			{
				// Only chain this task if I'm not playing a custom animation
				if( GetOuter()->GetEnemy() )
				{
					ChainStartTask( TASK_FACE_ENEMY, 0 );
				}
			}
		}
		break;

	default:
		BaseClass::StartTask( pTask );
		break;
	}
}


//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pTask - 
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::RunTask( const Task_t *pTask )
{
	switch( pTask->iTask )
	{
	case TASK_WAIT_ASSAULT_DELAY:
	case TASK_AWAIT_ASSAULT_TIMEOUT:
		if ( m_hAssaultPoint )
		{
			if ( m_hAssaultPoint->m_bInputForcedClear || (m_hAssaultPoint->m_bClearOnContact && HasCondition( COND_SEE_ENEMY )) )
			{
				// If we're on an assault that should clear on contact, clear when we see an enemy
				TaskComplete();
			}
		}

		if( GetOuter()->IsWaitFinished() && ( pTask->iTask == TASK_WAIT_ASSAULT_DELAY || !m_hAssaultPoint->m_bNeverTimeout ) )
		{
			TaskComplete();
		}
		break;

	case TASK_FACE_RALLY_POINT:
	case TASK_FACE_ASSAULT_POINT:
		GetMotor()->UpdateYaw();

		if( HasCondition( COND_CAN_RANGE_ATTACK1 ) )
		{
			// Out early if the NPC can attack.
			TaskComplete();
		}

		if ( GetOuter()->FacingIdeal() )
		{
			TaskComplete();
		}
		break;

	case TASK_AWAIT_CUE:
		// If we've lost our rally point, abort
		if ( !m_hRallyPoint )
		{
			TaskFail("No rally point.");
			break;
		}

		if( PollAssaultCue() )
		{
			TaskComplete();
		}

		if ( IsForcingCrouch() )
			break;

		if( GetOuter()->GetEnemy() && m_hRallyPoint->m_RallySequenceName == NULL_STRING && !HasCondition(COND_ENEMY_OCCLUDED) )
		{
			// I have an enemy and I'm NOT playing a custom animation.
			ChainRunTask( TASK_FACE_ENEMY, 0 );
		}
		break;

	case TASK_WAIT_FOR_MOVEMENT:
		if ( ai_debug_assault.GetBool() )
		{
			if ( IsCurSchedule( SCHED_MOVE_TO_ASSAULT_POINT ) )
			{
				NDebugOverlay::Line( WorldSpaceCenter(), GetNavigator()->GetGoalPos(), 255,0,0, true,0.1);
				NDebugOverlay::Box( GetNavigator()->GetGoalPos(), -Vector(10,10,10), Vector(10,10,10), 255,0,0, 8, 0.1 );
			}
			else if ( IsCurSchedule( SCHED_MOVE_TO_RALLY_POINT ) )
			{
				NDebugOverlay::Line( WorldSpaceCenter(), GetNavigator()->GetGoalPos(), 0,255,0, true,0.1);
				NDebugOverlay::Box( GetNavigator()->GetGoalPos(), -Vector(10,10,10), Vector(10,10,10), 0,255,0, 8, 0.1 );
			}
		}

		if ( m_hAssaultPoint && (m_hAssaultPoint->m_bInputForcedClear || (m_hAssaultPoint->m_bClearOnContact && HasCondition( COND_SEE_ENEMY ))) )
		{
			DevMsg( "Assault Cleared due to Contact or Input!\n" );
			ClearAssaultPoint();
			TaskComplete();
			return;
		}

		if ( ( ( !GetOuter()->DidChooseEnemy() && gpGlobals->curtime - GetOuter()->GetTimeEnemyAcquired() > 1 ) || !GetOuter()->GetEnemy() ) )
		{
			CBaseEntity *pNewEnemy = GetOuter()->BestEnemy();

			if( pNewEnemy != NULL && pNewEnemy != GetOuter()->GetEnemy() )
			{
				GetOuter()->SetEnemy( pNewEnemy );
				GetOuter()->SetState( NPC_STATE_COMBAT );
			}
		}

		BaseClass::RunTask( pTask );
		break;

	default:
		BaseClass::RunTask( pTask );
		break;
	}
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
CRallyPoint *CAI_AssaultBehavior::FindBestRallyPointInRadius( const Vector &vecCenter, float flRadius )
{
	VPROF_BUDGET( "CAI_AssaultBehavior::FindBestRallyPointInRadius", VPROF_BUDGETGROUP_NPCS );

	const int RALLY_SEARCH_ENTS	= 30;
	CBaseEntity *pEntities[RALLY_SEARCH_ENTS];
	int iNumEntities = UTIL_EntitiesInSphere( pEntities, RALLY_SEARCH_ENTS, vecCenter, flRadius, 0 );

	CRallyPoint *pBest = NULL;
	int iBestPriority = -1;

	for ( int i = 0; i < iNumEntities; i++ )
	{
		CRallyPoint *pRallyEnt = dynamic_cast<CRallyPoint *>(pEntities[i]);

		if( pRallyEnt )
		{
			if( !pRallyEnt->IsLocked() )
			{
				// Consider this point.
				if( pRallyEnt->m_iPriority > iBestPriority )
				{
					pBest = pRallyEnt;
					iBestPriority = pRallyEnt->m_iPriority;
				}
			}
		}
	}

	return pBest;
}


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
bool CAI_AssaultBehavior::IsValidShootPosition( const Vector &vLocation, CAI_Node *pNode, CAI_Hint const *pHint )
{
	CBaseEntity *pCuePoint = NULL;
	float flTolerance = 0.0f;

	if( m_bHitRallyPoint && !m_bHitAssaultPoint && !AssaultHasBegun() )
	{
		if( m_hRallyPoint != NULL )
		{
			pCuePoint = m_hRallyPoint;
			flTolerance = CUE_POINT_TOLERANCE;
		}
	}
	else if( m_bHitAssaultPoint )
	{
		if( m_hAssaultPoint != NULL )
		{
			pCuePoint = m_hAssaultPoint;
			flTolerance = m_hAssaultPoint->m_flAssaultPointTolerance;
		}
	}

	if ( pCuePoint && (vLocation - pCuePoint->GetAbsOrigin()).Length2DSqr() > Square( flTolerance - 0.1 ) )
		return false;

	return BaseClass::IsValidShootPosition( vLocation, pNode, pHint );
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
float CAI_AssaultBehavior::GetMaxTacticalLateralMovement( void )
{
	return CUE_POINT_TOLERANCE - 0.1;
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::UpdateOnRemove()
{
	// Ignore exclusivity. Our NPC just died.
	UnlockRallyPoint();
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CAI_AssaultBehavior::OnStrictAssault( void )
{ 
	return (m_hAssaultPoint && m_hAssaultPoint->m_iStrictness); 
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CAI_AssaultBehavior::UpdateForceCrouch( void )
{
	if ( IsForcingCrouch() )
	{
		// Only force crouch when we're near the point we're supposed to crouch at
		float flDistanceToTargetSqr = GetOuter()->GetAbsOrigin().DistToSqr( AssaultHasBegun() ? m_hAssaultPoint->GetAbsOrigin() : m_hRallyPoint->GetAbsOrigin() );
		if ( flDistanceToTargetSqr < (64*64) )
		{
			GetOuter()->ForceCrouch();
		}
		else
		{
			GetOuter()->ClearForceCrouch();
		}
		return true;
	}

	return false;
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CAI_AssaultBehavior::IsForcingCrouch( void )
{
	if ( AssaultHasBegun() )
		return (m_hAssaultPoint && m_hAssaultPoint->m_bForceCrouch);

	return (m_hRallyPoint && m_hRallyPoint->m_bForceCrouch);
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CAI_AssaultBehavior::IsUrgent( void )
{
	if ( AssaultHasBegun() )
		return (m_hAssaultPoint && m_hAssaultPoint->m_bIsUrgent);

	return (m_hRallyPoint && m_hRallyPoint->m_bIsUrgent);
}

//-----------------------------------------------------------------------------
// Purpose: Unlock any rally points the behavior is currently locking
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::UnlockRallyPoint( void )
{
	CAI_AssaultBehavior *pBehavior;
	if ( GetOuter()->GetBehavior( &pBehavior ) )
	{
		if( pBehavior->m_hRallyPoint )
		{
			pBehavior->m_hRallyPoint->Unlock( GetOuter() );
		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pRallyPoint - 
//			assaultcue - 
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::SetParameters( CBaseEntity *pRallyEnt, AssaultCue_t assaultcue )
{
	VPROF_BUDGET( "CAI_AssaultBehavior::SetParameters", VPROF_BUDGETGROUP_NPCS );

	// Clean up any soon to be dangling rally points
	UnlockRallyPoint();

	// Firstly, find a rally point. 
	CRallyPoint *pRallyPoint = dynamic_cast<CRallyPoint *>(pRallyEnt);

	if( pRallyPoint )
	{
		if( !pRallyPoint->IsLocked() )
		{
			// Claim it.
			m_hRallyPoint = pRallyPoint;
			m_hRallyPoint->Lock( GetOuter() );
			
			m_AssaultCue = assaultcue;
			InitializeBehavior();
			return;
		}
		else
		{
			DevMsg("**ERROR: Specified a rally point that is LOCKED!\n" );
		}
	}
	else
	{
		DevMsg("**ERROR: Bad RallyPoint in SetParameters\n" );

		// Bomb out of assault behavior.
		m_AssaultCue = CUE_NO_ASSAULT;
		ClearSchedule( "Bad rally point" );
	}

}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : rallypointname - 
//			assaultcue - 
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::SetParameters( string_t rallypointname, AssaultCue_t assaultcue, int rallySelectMethod )
{
	VPROF_BUDGET( "CAI_AssaultBehavior::SetParameters", VPROF_BUDGETGROUP_NPCS );

	// Clean up any soon to be dangling rally points
	UnlockRallyPoint();

	// Firstly, find a rally point. 
	CRallyPoint *pRallyEnt = dynamic_cast<CRallyPoint *>(gEntList.FindEntityByName( NULL, rallypointname ) );

	CRallyPoint *pBest = NULL;
	int iBestPriority = -1;

	switch( rallySelectMethod )
	{
	case RALLY_POINT_SELECT_DEFAULT:
		{
			while( pRallyEnt )
			{
				if( !pRallyEnt->IsLocked() )
				{
					// Consider this point.
					if( pRallyEnt->m_iPriority > iBestPriority )
					{
						// This point is higher priority. I must take it.
						pBest = pRallyEnt;
						iBestPriority = pRallyEnt->m_iPriority;
					}
					else if ( pRallyEnt->m_iPriority == iBestPriority )
					{
						// This point is the same priority as my current best. 
						// I must take it if it is closer.
						Vector vecStart = GetOuter()->GetAbsOrigin();

						float flNewDist, flBestDist;

						flNewDist = ( pRallyEnt->GetAbsOrigin() - vecStart ).LengthSqr();
						flBestDist = ( pBest->GetAbsOrigin() - vecStart ).LengthSqr();

						if( flNewDist < flBestDist )
						{
							// Priority is already identical. Just take this point.
							pBest = pRallyEnt;
						}
					}
				}

				pRallyEnt = dynamic_cast<CRallyPoint *>(gEntList.FindEntityByName( pRallyEnt, rallypointname, NULL ) );
			}
		}
		break;

	case RALLY_POINT_SELECT_RANDOM:
		{
			// Gather all available points into a utilvector, then pick one at random.
			
			CUtlVector<CRallyPoint *> rallyPoints; // List of rally points that are available to choose from.

			while( pRallyEnt )
			{
				if( !pRallyEnt->IsLocked() )
				{
					rallyPoints.AddToTail( pRallyEnt );
				}

				pRallyEnt = dynamic_cast<CRallyPoint *>(gEntList.FindEntityByName( pRallyEnt, rallypointname ) );
			}

			if( rallyPoints.Count() > 0 )
			{
				pBest = rallyPoints[ random->RandomInt(0, rallyPoints.Count()- 1) ];
			}
		}
		break;

	default:
		DevMsg( "ERROR: INVALID RALLY POINT SELECTION METHOD. Assault will not function.\n");
		break;
	}

	if( !pBest )
	{
		DevMsg("%s Didn't find a best rally point!\n", GetOuter()->GetEntityName().ToCStr() );
		return;
	}

	pBest->Lock( GetOuter() );
	m_hRallyPoint = pBest;

	if( !m_hRallyPoint )
	{
		DevMsg("**ERROR: Can't find a rally point named '%s'\n", STRING( rallypointname ));

		// Bomb out of assault behavior.
		m_AssaultCue = CUE_NO_ASSAULT;
		ClearSchedule( "Can't find rally point" );
		return;
	}

	m_AssaultCue = assaultcue;
	InitializeBehavior();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::InitializeBehavior()
{
	// initialize the variables that track whether the NPC has reached (hit)
	// his rally and assault points already. Be advised, having hit the point
	// only means you have been to it at some point. Doesn't mean you're standing
	// there still. Mainly used to understand which 'phase' of the assault an NPC
	// is in.
	m_bHitRallyPoint = false;
	m_bHitAssaultPoint = false;

	m_hAssaultPoint = 0;

	m_bDiverting = false;
	m_flLastSawAnEnemyAt = 0;

	// Also reset the status of externally received assault cues
	m_ReceivedAssaultCue = CUE_NO_ASSAULT;

	CAssaultPoint *pAssaultEnt = FindAssaultPoint( m_hRallyPoint->m_AssaultPointName );

	if( pAssaultEnt )
	{
		SetAssaultPoint(pAssaultEnt);
	}
	else
	{
		DevMsg("**ERROR: Can't find any assault points named: %s\n", STRING( m_hRallyPoint->m_AssaultPointName ));

		// Bomb out of assault behavior.
		m_AssaultCue = CUE_NO_ASSAULT;
		ClearSchedule( "Can't find assault point" );
		return;
	}

	// Slam the NPC's schedule so that he starts picking Assault schedules right now.
	ClearSchedule( "Initializing assault behavior" );
}

//-----------------------------------------------------------------------------
// Purpose: Check conditions and see if the cue to being an assault has come.
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CAI_AssaultBehavior::PollAssaultCue( void )
{
	// right now, always go when the commander says.
	if( m_ReceivedAssaultCue == CUE_COMMANDER )
	{
		return true;
	}

	switch( m_AssaultCue )
	{
	case CUE_NO_ASSAULT:
		// NO_ASSAULT never ever triggers.
		return false;
		break;

	case CUE_ENTITY_INPUT:
		return m_ReceivedAssaultCue == CUE_ENTITY_INPUT;
		break;

	case CUE_PLAYER_GUNFIRE:
		// Any gunfire will trigger this right now (sjb)
		if( HasCondition( COND_HEAR_COMBAT ) )
		{
			return true;
		}
		break;

	case CUE_DONT_WAIT:
		// Just keep going!
		m_ReceivedAssaultCue = CUE_DONT_WAIT;
		return true;
		break;

	case CUE_COMMANDER:
		// Player told me to go, so go!
		return m_ReceivedAssaultCue == CUE_COMMANDER;
		break;
	}

	return false;
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::OnRestore()
{
	if ( !m_hAssaultPoint || !m_hRallyPoint )
	{
		Disable();
		NotifyChangeBehaviorStatus();
	}

}


//-----------------------------------------------------------------------------
// Purpose: 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CAI_AssaultBehavior::CanSelectSchedule()
{
	if ( !GetOuter()->IsInterruptable() )
		return false;

	if ( GetOuter()->HasCondition( COND_RECEIVED_ORDERS ) )
		return false;

	// We're letting other AI run for a little while because the assault AI failed recently.
	if ( m_flTimeDeferScheduleSelection > gpGlobals->curtime )
		return false;

	// No schedule selection if no assault is being conducted.
	if( m_AssaultCue == CUE_NO_ASSAULT )
		return false;

	if ( !m_hAssaultPoint || !m_hRallyPoint )
	{
		Disable();
		return false;
	}

	// Remember when we last saw an enemy
	if ( GetEnemy() )
	{
		m_flLastSawAnEnemyAt = gpGlobals->curtime;
	}

	// If we've seen an enemy in the last few seconds, and we're allowed to divert,
	// let the base AI decide what I should do.
	if ( IsAllowedToDivert() )
	{
		// Return true, but remember that we're actually allowing them to divert
		// This is done because we don't want the assault behaviour to think it's finished with the assault.
		m_bDiverting = true;
	}
	else if ( m_bDiverting )
	{
		// If we were diverting, provoke us to make a new schedule selection
		SetCondition( COND_PROVOKED );

		m_bDiverting = false;
	}

	// If we're diverting, let the base AI decide everything
	if ( m_bDiverting )
		return false;

	return true;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::BeginScheduleSelection()
{
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::EndScheduleSelection()
{
	m_bHitAssaultPoint = false;

	if( m_hRallyPoint != NULL )
	{
		if( !m_hRallyPoint->IsExclusive() )
			m_bHitRallyPoint = false;

		if( !hl2_episodic.GetBool() || !m_hRallyPoint->IsExclusive() || !GetOuter()->IsAlive() )
		{
			// Here we unlock the rally point if it is NOT EXCLUSIVE
			// -OR- the Outer is DEAD. (This gives us a head-start on 
			// preparing the point to take new NPCs right away. Otherwise
			// we have to wait two seconds until the behavior is destroyed.)
			// NOTICE that the legacy (non-episodic) support calls UnlockRallyPoint
			// unconditionally on EndScheduleSelection()
			UnlockRallyPoint();
		}
	}

	GetOuter()->ClearForceCrouch();
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : scheduleType - 
// Output : int
//-----------------------------------------------------------------------------
int CAI_AssaultBehavior::TranslateSchedule( int scheduleType )
{
	switch( scheduleType )
	{
	case SCHED_ESTABLISH_LINE_OF_FIRE_FALLBACK:
		// This nasty schedule can allow the NPC to violate their position near
		// the assault point. Translate it away to something stationary. (sjb)
		return SCHED_COMBAT_FACE;
		break;

	case SCHED_RANGE_ATTACK1:
		if ( GetOuter()->GetShotRegulator()->IsInRestInterval() )				
		{
			if ( GetOuter()->HasStrategySlotRange( SQUAD_SLOT_ATTACK1, SQUAD_SLOT_ATTACK2 ) )
				GetOuter()->VacateStrategySlot();
			return SCHED_COMBAT_FACE; // @TODO (toml 07-02-03): Should do something more tactically sensible
		}
		break;

	case SCHED_MOVE_TO_WEAPON_RANGE:
	case SCHED_CHASE_ENEMY:
		if( m_bHitAssaultPoint )
		{
			return SCHED_WAIT_AND_CLEAR;
		}
		else
		{
			return SCHED_MOVE_TO_ASSAULT_POINT;
		}
		break;

	case SCHED_HOLD_RALLY_POINT:
		if( HasCondition(COND_NO_PRIMARY_AMMO) | HasCondition(COND_LOW_PRIMARY_AMMO) )
		{
			return SCHED_RELOAD;
		}
		break;

	case SCHED_MOVE_TO_ASSAULT_POINT:
		{
		float flDist = ( m_hAssaultPoint->GetAbsOrigin() - GetAbsOrigin() ).Length();
		if ( flDist <= 12.0f )
			return SCHED_AT_ASSAULT_POINT;
		}
		break;
	}

	return BaseClass::TranslateSchedule( scheduleType );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::OnStartSchedule( int scheduleType )
{
	if ( scheduleType == SCHED_HIDE_AND_RELOAD ) //!!!HACKHACK
	{
		// Dirty the assault point flag so that we return to assault point
		m_bHitAssaultPoint = false;
	}
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::ClearSchedule( const char *szReason )
{
	// HACKHACK: In reality, we shouldn't be clearing the schedule ever if the assault
	// behavior isn't actually in charge of the NPC. Fix after ship. For now, hacking
	// a fix to Grigori failing to make it over the fence of the graveyard in d1_town_02a
	if ( GetOuter()->ClassMatches( "npc_monk" ) && GetOuter()->GetState() == NPC_STATE_SCRIPT )
		return;

	// Don't allow it if we're in a vehicle
	if ( GetOuter()->IsInAVehicle() )
		return;

	GetOuter()->ClearSchedule( szReason );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CAI_AssaultBehavior::IsAllowedToDivert( void )
{
	if ( m_hAssaultPoint && m_hAssaultPoint->m_bAllowDiversion )
	{
		if ( m_hAssaultPoint->m_flAllowDiversionRadius == 0.0f || (m_bHitAssaultPoint && GetEnemy() != NULL && GetEnemy()->GetAbsOrigin().DistToSqr(m_hAssaultPoint->GetAbsOrigin()) <= Square(m_hAssaultPoint->m_flAllowDiversionRadius)) ) 
		{
			if ( m_flLastSawAnEnemyAt && ((gpGlobals->curtime - m_flLastSawAnEnemyAt) < ASSAULT_DIVERSION_TIME) )
				return true;
		}
	}

	return false;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::BuildScheduleTestBits()
{
	BaseClass::BuildScheduleTestBits();

	// If we're allowed to divert, add the appropriate interrupts to our movement schedules
	if ( IsAllowedToDivert() )
	{
		if ( IsCurSchedule( SCHED_MOVE_TO_ASSAULT_POINT ) ||
			IsCurSchedule( SCHED_MOVE_TO_RALLY_POINT ) || 
			IsCurSchedule( SCHED_HOLD_RALLY_POINT ) )
		{
			GetOuter()->SetCustomInterruptCondition( COND_NEW_ENEMY );
			GetOuter()->SetCustomInterruptCondition( COND_SEE_ENEMY );
		}
	}
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CAI_AssaultBehavior::OnScheduleChange()
{
	if( IsCurSchedule(SCHED_WAIT_AND_CLEAR, false) )
	{
		if( m_hAssaultPoint && m_hAssaultPoint->m_bClearOnContact )
		{
			if( HasCondition(COND_SEE_ENEMY) )
			{
				ClearAssaultPoint();
			}
		}
	}

	BaseClass::OnScheduleChange();
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : int
//-----------------------------------------------------------------------------
int CAI_AssaultBehavior::SelectSchedule()
{
	if ( !OnStrictAssault() )
	{
		if( HasCondition( COND_PLAYER_PUSHING ) )
			return SCHED_ASSAULT_MOVE_AWAY; 

		if( HasCondition( COND_HEAR_DANGER ) )
			return SCHED_TAKE_COVER_FROM_BEST_SOUND;
	}

	if( HasCondition( COND_CAN_MELEE_ATTACK1 ) )
		return SCHED_MELEE_ATTACK1;

	// If you're empty, reload before trying to carry out any assault functions.
	if( HasCondition( COND_NO_PRIMARY_AMMO ) )
		return SCHED_RELOAD;

	if( m_bHitRallyPoint && !m_bHitAssaultPoint && !AssaultHasBegun() )
	{
		// If I have hit my rally point, but I haven't hit my assault point yet, 
		// Make sure I'm still on my rally point, cause another behavior may have moved me.
		// 2D check to be within 32 units of my rallypoint.
		Vector vecDiff = GetAbsOrigin() - m_hRallyPoint->GetAbsOrigin();
		vecDiff.z = 0.0;

		if( vecDiff.LengthSqr() > Square(CUE_POINT_TOLERANCE) )
		{
			// Someone moved me away. Get back to rally point.
			m_bHitRallyPoint = false;
			return SCHED_MOVE_TO_RALLY_POINT;
		}
	}
	else if( m_bHitAssaultPoint )
	{
		// Likewise. If I have hit my assault point, make sure I'm still there. Another
		// behavior (hide and reload) may have moved me away. 
		Vector vecDiff = GetAbsOrigin() - m_hAssaultPoint->GetAbsOrigin();
		vecDiff.z = 0.0;

		if( vecDiff.LengthSqr() > Square(CUE_POINT_TOLERANCE) )
		{
			// Someone moved me away.
			m_bHitAssaultPoint = false;
		}
	}

	// Go to my rally point, unless the assault's begun.
	if( !m_bHitRallyPoint && !AssaultHasBegun() )
	{
		GetOuter()->SpeakSentence( ASSAULT_SENTENCE_SQUAD_ADVANCE_TO_RALLY );
		return SCHED_MOVE_TO_RALLY_POINT;
	}

	if( !m_bHitAssaultPoint )
	{
		if( m_ReceivedAssaultCue == m_AssaultCue || m_ReceivedAssaultCue == CUE_COMMANDER || m_AssaultCue == CUE_DONT_WAIT )
		{
			GetOuter()->SpeakSentence( ASSAULT_SENTENCE_SQUAD_ADVANCE_TO_ASSAULT );

			if ( m_hRallyPoint && !m_hRallyPoint->IsExclusive() )
			{
				// If this assault chain is not exclusive, then free up the rallypoint so that others can follow me
				// Otherwise, we do not unlock this rally point until we are FINISHED or DEAD. It's exclusively our chain of assault
				UnlockRallyPoint();// Here we go! Free up the rally point since I'm moving to assault.
			}

			if ( !UpdateForceCrouch() )
			{
				GetOuter()->ClearForceCrouch();
			}

			return SCHED_MOVE_TO_ASSAULT_POINT;
		}
		else if( HasCondition( COND_CAN_RANGE_ATTACK1 ) )
		{
			return SCHED_RANGE_ATTACK1;
		}
		else if( HasCondition( COND_NO_PRIMARY_AMMO ) )
		{
			// Don't run off to reload.
			return SCHED_RELOAD;
		}
		else if( HasCondition( COND_LIGHT_DAMAGE ) || HasCondition( COND_HEAVY_DAMAGE ) )
		{
			GetOuter()->SpeakSentence( ASSAULT_SENTENCE_UNDER_ATTACK );
			return SCHED_ALERT_FACE;
		}
		else if( GetOuter()->GetEnemy() && !HasCondition( COND_CAN_RANGE_ATTACK1 ) && !HasCondition( COND_CAN_RANGE_ATTACK2) && !HasCondition(COND_ENEMY_OCCLUDED) )
		{
			return SCHED_COMBAT_FACE;
		}
		else
		{
			UpdateForceCrouch();
			return SCHED_HOLD_RALLY_POINT;
		}
	}

	if( HasCondition( COND_NO_PRIMARY_AMMO ) )
	{
		GetOuter()->SpeakSentence( ASSAULT_SENTENCE_COVER_NO_AMMO );
		return SCHED_HIDE_AND_RELOAD;
	}

	if( m_hAssaultPoint->HasSpawnFlags( SF_ASSAULTPOINT_CLEARONARRIVAL ) )
	{
		return SCHED_CLEAR_ASSAULT_POINT;
	}

	if ( (!GetEnemy() || HasCondition(COND_ENEMY_OCCLUDED)) && !GetOuter()->HasConditionsToInterruptSchedule( SCHED_WAIT_AND_CLEAR ) )
	{
		// Don't have an enemy. Just keep an eye on things.
		return SCHED_WAIT_AND_CLEAR;
	}

	if ( OnStrictAssault() )
	{
		// Don't allow the base class to select a schedule cause it will probably move the NPC.
		if( !HasCondition(COND_CAN_RANGE_ATTACK1)	&&
			!HasCondition(COND_CAN_RANGE_ATTACK2)	&&
			!HasCondition(COND_CAN_MELEE_ATTACK1)	&&
			!HasCondition(COND_CAN_MELEE_ATTACK2)	&&
			!HasCondition(COND_TOO_CLOSE_TO_ATTACK)	&&
			!HasCondition(COND_NOT_FACING_ATTACK) )
		{
			return SCHED_WAIT_AND_CLEAR;
		}
	}

#ifdef HL2_EPISODIC
	// This ugly patch fixes a bug where Combine Soldiers on an assault would not shoot through glass, because of the way
	// that shooting through glass is implemented in their AI. (sjb)
	if( HasCondition(COND_SEE_ENEMY) && HasCondition(COND_WEAPON_SIGHT_OCCLUDED) && !HasCondition(COND_LOW_PRIMARY_AMMO) )
	{	
		// If they are hiding behind something that we can destroy, start shooting at it.
		CBaseEntity *pBlocker = GetOuter()->GetEnemyOccluder();
		if ( pBlocker && pBlocker->GetHealth() > 0 )
		{
			if( GetOuter()->Classify() == CLASS_COMBINE && FClassnameIs(GetOuter(), "npc_combine_s") )
			{
				return SCHED_SHOOT_ENEMY_COVER;
			}
		}
	}
#endif//HL2_EPISODIC
	
	return BaseClass::SelectSchedule();
}

//-----------------------------------------------------------------------------
//
// CAI_AssaultGoal
//
// Purpose: 
//			
//
//-----------------------------------------------------------------------------
class CAI_AssaultGoal : public CAI_GoalEntity
{
	typedef CAI_GoalEntity BaseClass;

	virtual void EnableGoal( CAI_BaseNPC *pAI );
	virtual void DisableGoal( CAI_BaseNPC *pAI );

	string_t		m_RallyPoint;
	int				m_AssaultCue;
	int				m_RallySelectMethod;

	void InputBeginAssault( inputdata_t &inputdata );

	DECLARE_DATADESC();
};

BEGIN_DATADESC( CAI_AssaultGoal )
	DEFINE_KEYFIELD( m_RallyPoint, FIELD_STRING, "rallypoint" ),
	DEFINE_KEYFIELD( m_AssaultCue, FIELD_INTEGER, "AssaultCue" ),
	DEFINE_KEYFIELD( m_RallySelectMethod, FIELD_INTEGER, "RallySelectMethod" ),

	DEFINE_INPUTFUNC( FIELD_VOID, "BeginAssault", InputBeginAssault ),
END_DATADESC();


//-------------------------------------
LINK_ENTITY_TO_CLASS( ai_goal_assault, CAI_AssaultGoal );
//-------------------------------------

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CAI_AssaultGoal::EnableGoal( CAI_BaseNPC *pAI )
{
	CAI_AssaultBehavior *pBehavior;

	if ( !pAI->GetBehavior( &pBehavior ) )
		return;

	pBehavior->SetParameters( m_RallyPoint, (AssaultCue_t)m_AssaultCue, m_RallySelectMethod );

	// Duplicate the output
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CAI_AssaultGoal::DisableGoal( CAI_BaseNPC *pAI )
{ 
	CAI_AssaultBehavior *pBehavior;

	if ( pAI->GetBehavior( &pBehavior ) )
	{
		pBehavior->Disable();
	
		// Don't leave any hanging rally points locked.
		pBehavior->UnlockRallyPoint();

		pBehavior->ClearSchedule( "Assault goal disabled" );
	}
}

//-----------------------------------------------------------------------------
// Purpose: ENTITY I/O method for telling the assault behavior to cue assault
// Input  : &inputdata - 
//-----------------------------------------------------------------------------
void CAI_AssaultGoal::InputBeginAssault( inputdata_t &inputdata )
{
	int i;

	for( i = 0 ; i < NumActors() ; i++ )
	{
		CAI_BaseNPC *pActor = GetActor( i );

		if( pActor )
		{
			// Now use this actor to lookup the Behavior
			CAI_AssaultBehavior *pBehavior;

			if( pActor->GetBehavior( &pBehavior ) )
			{
				// GOT IT! Now tell the behavior that entity i/o wants to cue the assault.
				pBehavior->ReceiveAssaultCue( CUE_ENTITY_INPUT );
			}
		}
	}
}


AI_BEGIN_CUSTOM_SCHEDULE_PROVIDER(CAI_AssaultBehavior)

	DECLARE_TASK(TASK_GET_PATH_TO_RALLY_POINT)
	DECLARE_TASK(TASK_FACE_RALLY_POINT)
	DECLARE_TASK(TASK_GET_PATH_TO_ASSAULT_POINT)
	DECLARE_TASK(TASK_FACE_ASSAULT_POINT)
	DECLARE_TASK(TASK_AWAIT_CUE)
	DECLARE_TASK(TASK_AWAIT_ASSAULT_TIMEOUT)
	DECLARE_TASK(TASK_ANNOUNCE_CLEAR)
	DECLARE_TASK(TASK_WAIT_ASSAULT_DELAY)
	DECLARE_TASK(TASK_HIT_ASSAULT_POINT)
	DECLARE_TASK(TASK_HIT_RALLY_POINT)
	DECLARE_TASK(TASK_ASSAULT_DEFER_SCHEDULE_SELECTION)
	
	//=========================================================
	//=========================================================
	DEFINE_SCHEDULE 
	(
		SCHED_MOVE_TO_RALLY_POINT,

		"	Tasks"
		"		TASK_SET_FAIL_SCHEDULE					SCHEDULE:SCHED_ASSAULT_FAILED_TO_MOVE"
		"		TASK_GET_PATH_TO_RALLY_POINT			0"
		"		TASK_RUN_PATH							0"
		"		TASK_WAIT_FOR_MOVEMENT					0"
		"		TASK_STOP_MOVING						0"
		"		TASK_FACE_RALLY_POINT					0"
		"		TASK_HIT_RALLY_POINT					0"
		"		TASK_SET_SCHEDULE						SCHEDULE:SCHED_HOLD_RALLY_POINT"
		"	"
		"	Interrupts"
		"		COND_HEAR_DANGER"
		"		COND_PROVOKED"
		"		COND_NO_PRIMARY_AMMO"
		"		COND_PLAYER_PUSHING"
	)

	//=========================================================
	//=========================================================
	DEFINE_SCHEDULE
	(
		SCHED_ASSAULT_FAILED_TO_MOVE,

		"	Tasks"
		"		TASK_ASSAULT_DEFER_SCHEDULE_SELECTION	1"
		"	"
		"	Interrupts"
	)

	//=========================================================
	//=========================================================
	DEFINE_SCHEDULE
	(
		SCHED_FAIL_MOVE_TO_RALLY_POINT,

		"	Tasks"
		"		TASK_WAIT			1"
		"	"
		"	Interrupts"
		"		COND_HEAR_DANGER"
		"		COND_CAN_RANGE_ATTACK1"
		"		COND_CAN_MELEE_ATTACK1"
	)


#ifdef HL2_EPISODIC
	//=========================================================
	//=========================================================
	DEFINE_SCHEDULE 
	(
		SCHED_HOLD_RALLY_POINT,

		"	Tasks"
		"		TASK_FACE_RALLY_POINT					0"
		"		TASK_AWAIT_CUE							0"
		"		TASK_WAIT_ASSAULT_DELAY					0"
		"	"
		"	Interrupts"
		//"		COND_NEW_ENEMY"
		"		COND_CAN_RANGE_ATTACK1"
		"		COND_CAN_MELEE_ATTACK1"
		"		COND_LIGHT_DAMAGE"
		"		COND_HEAVY_DAMAGE"
		"		COND_PLAYER_PUSHING"
		"		COND_HEAR_DANGER"
		"		COND_HEAR_BULLET_IMPACT"
		"		COND_NO_PRIMARY_AMMO"
	)
#else
	//=========================================================
	//=========================================================
	DEFINE_SCHEDULE 
	(
	SCHED_HOLD_RALLY_POINT,

	"	Tasks"
	"		TASK_FACE_RALLY_POINT					0"
	"		TASK_AWAIT_CUE							0"
	"		TASK_WAIT_ASSAULT_DELAY					0"
	"	"
	"	Interrupts"
	"		COND_NEW_ENEMY"
	"		COND_CAN_RANGE_ATTACK1"
	"		COND_CAN_MELEE_ATTACK1"
	"		COND_LIGHT_DAMAGE"
	"		COND_HEAVY_DAMAGE"
	"		COND_PLAYER_PUSHING"
	"		COND_HEAR_DANGER"
	"		COND_HEAR_BULLET_IMPACT"
	"		COND_NO_PRIMARY_AMMO"
	"		COND_TOO_CLOSE_TO_ATTACK"
	)
#endif//HL2_EPISODIC

	//=========================================================
	//=========================================================
	DEFINE_SCHEDULE 
	(
		SCHED_HOLD_ASSAULT_POINT,

		"	Tasks"
		"		TASK_SET_ACTIVITY			ACTIVITY:ACT_IDLE"
		"		TASK_WAIT					3"
		""
		"	Interrupts"
		"		COND_NEW_ENEMY"
		"		COND_ENEMY_DEAD"
		"		COND_CAN_RANGE_ATTACK1"
		"		COND_CAN_MELEE_ATTACK1"
		"		COND_CAN_RANGE_ATTACK2"
		"		COND_CAN_MELEE_ATTACK2"
		"		COND_TOO_CLOSE_TO_ATTACK"
		"		COND_LOST_ENEMY"
		"		COND_HEAR_DANGER"
		"		COND_HEAR_BULLET_IMPACT"
		"		COND_NO_PRIMARY_AMMO"
	)

	//=========================================================
	//=========================================================
	DEFINE_SCHEDULE 
	(
		SCHED_MOVE_TO_ASSAULT_POINT,

		"	Tasks"
		"		TASK_SET_FAIL_SCHEDULE					SCHEDULE:SCHED_ASSAULT_FAILED_TO_MOVE"
		"		TASK_GATHER_CONDITIONS					0"
		"		TASK_GET_PATH_TO_ASSAULT_POINT			0"
		"		TASK_RUN_PATH							0"
		"		TASK_WAIT_FOR_MOVEMENT					0"
		"		TASK_FACE_ASSAULT_POINT					0"
		"		TASK_HIT_ASSAULT_POINT					0"
		"	"
		"	Interrupts"
		"		COND_NO_PRIMARY_AMMO"
		"		COND_HEAR_DANGER"
	)

	//=========================================================
	//=========================================================
	DEFINE_SCHEDULE 
	(
	SCHED_AT_ASSAULT_POINT,

	"	Tasks"
	"		TASK_FACE_ASSAULT_POINT					0"
	"		TASK_HIT_ASSAULT_POINT					0"
	"	"
	"	Interrupts"
	"		COND_NO_PRIMARY_AMMO"
	"		COND_HEAR_DANGER"
	)

	//=========================================================
	//=========================================================
	DEFINE_SCHEDULE 
	(
		SCHED_WAIT_AND_CLEAR,

		"	Tasks"
		"		TASK_FACE_ASSAULT_POINT		0"
		"		TASK_SET_ACTIVITY			ACTIVITY:ACT_IDLE"
		"		TASK_AWAIT_ASSAULT_TIMEOUT	0"
		"		TASK_ANNOUNCE_CLEAR			0"
		"	"
		"	Interrupts"
		"		COND_NEW_ENEMY"
		"		COND_LIGHT_DAMAGE"
		"		COND_HEAVY_DAMAGE"
		"		COND_CAN_RANGE_ATTACK1"
		"		COND_CAN_MELEE_ATTACK1"
		"		COND_CAN_RANGE_ATTACK2"
		"		COND_CAN_MELEE_ATTACK2"
		"		COND_HEAR_DANGER"
		"		COND_HEAR_BULLET_IMPACT"
		"		COND_TOO_CLOSE_TO_ATTACK"
		"		COND_NOT_FACING_ATTACK"
		"		COND_PLAYER_PUSHING"
	)

	//=========================================================
	//=========================================================
	DEFINE_SCHEDULE 
	(
		SCHED_CLEAR_ASSAULT_POINT,

		"	Tasks"
		"		TASK_ANNOUNCE_CLEAR			0"
		"	"
		"	Interrupts"
	)

	//=========================================================
	//=========================================================
	DEFINE_SCHEDULE 
	(
		SCHED_ASSAULT_MOVE_AWAY,

		"	Tasks"
		"		TASK_MOVE_AWAY_PATH						120"
		"		TASK_RUN_PATH							0"
		"		TASK_WAIT_FOR_MOVEMENT					0"
		"	"
		"	Interrupts"
	)

AI_END_CUSTOM_SCHEDULE_PROVIDER()