Skip to content

Commit 7680448

Browse files
WhakomaticWhakomatic
authored andcommitted
Refactor: Replace bNeedsHazardEscape var with NeedsHazardEscape() function
Cannot add variables to native classes, so converted the hazard escape check from a class variable to a helper function. The function performs the same check: empty tile cache + unit in hazard = needs escape.
1 parent 82ec365 commit 7680448

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

X2WOTCCommunityHighlander/Src/XComGame/Classes/XGAIBehavior.uc

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,6 @@ struct native DebugAoEResult
431431
var array<DebugAoEResult> DebugAoEList;
432432
var int CurrAoEIndex;
433433

434-
// HL-Docs: ref:AIHazardEscape; issue:1559; tags:tactical
435-
var bool bNeedsHazardEscape;
436434

437435
// Generic ability selector for units that cannot be given a custom behavior tree.
438436
// This should be used when the AI has no idea what abilities this unit has. (Shadow/Clone units, etc)
@@ -1531,13 +1529,6 @@ simulated function BT_StartGetDestinations(bool bFiltered=false, bool bSkipBuild
15311529

15321530
m_kUnit.m_kReachableTilesCache.UpdateTileCacheIfNeeded();
15331531

1534-
// HL-Docs: feature:AIHazardEscape; issue:1559
1535-
// Allows AI units to escape when surrounded by hazardous world effects (poison, fire, acid).
1536-
// When the normal pathfinding cache is empty due to hazards blocking all tiles,
1537-
// the AI gathers nearby non-hazardous tiles (3-5 tiles away), scores them using the standard tactical scoring system,
1538-
// and paths through hazards using BuildNonUnitPath to reach the best-scoring safe destination.
1539-
bNeedsHazardEscape = (m_kUnit.m_kReachableTilesCache.CoverDestinations.Length == 0 && class'XComPath'.static.TileContainsHazard(UnitState, UnitState.TileLocation));
1540-
15411532
// Special case for grapple movement.
15421533
if ( m_kCurrMoveRestriction.bIsGrappleMove )
15431534
{
@@ -1568,10 +1559,10 @@ simulated function BT_StartGetDestinations(bool bFiltered=false, bool bSkipBuild
15681559
AddTileToProcess(kTileScore);
15691560
}
15701561
}
1571-
else if (bNeedsHazardEscape)
1562+
// HL-Docs: ref:AIHazardEscape; issue:1559
1563+
// placed before CoverDestinations check because m_kReachableTilesCache will be empty
1564+
else if (NeedsHazardEscape())
15721565
{
1573-
// HL-Docs: ref:AIHazardEscape; issue:1559
1574-
// placed before CoverDestinations check because m_kReachableTilesCache will be empty
15751566
AllTiles = GatherHazardEscapeTiles();
15761567
foreach AllTiles(kTile)
15771568
{
@@ -1818,6 +1809,16 @@ function BT_IgnoreHazards( bool bIgnore=true )
18181809
bIgnoreHazards = bIgnore;
18191810
}
18201811

1812+
// HL-Docs: feature:AIHazardEscape; issue:1559; tags:tactical
1813+
// Allows AI units to escape when surrounded by hazardous world effects (poison, fire, acid).
1814+
// When the normal pathfinding cache is empty due to hazards blocking all tiles,
1815+
// the AI gathers nearby non-hazardous tiles (3-5 tiles away), scores them using the standard tactical scoring system,
1816+
// and paths through hazards using BuildNonUnitPath to reach the best-scoring safe destination.
1817+
function bool NeedsHazardEscape()
1818+
{
1819+
return (m_kUnit.m_kReachableTilesCache.CoverDestinations.Length == 0 && class'XComPath'.static.TileContainsHazard(UnitState, UnitState.TileLocation));
1820+
}
1821+
18211822
// HL-Docs: ref:AIHazardEscape; issue:1559
18221823
// Gather nearby non-hazardous tiles for escape pathing then let BT_StepProcessDestinations score them
18231824
function array<TTile> GatherHazardEscapeTiles()
@@ -1992,7 +1993,7 @@ simulated function BT_StepProcessDestinations()
19921993
// HL-Docs: ref:AIHazardEscape; issue:1559
19931994
// m_kReachableTilesCache will be empty if we are surrounded by a hazard
19941995
//See if this tile is reachable
1995-
if ( bValid && !bNeedsHazardEscape && !m_kCurrMoveRestriction.bIsGrappleMove && !m_kUnit.m_kReachableTilesCache.IsTileReachable(kTileData.kTile) )
1996+
if ( bValid && !NeedsHazardEscape() && !m_kCurrMoveRestriction.bIsGrappleMove && !m_kUnit.m_kReachableTilesCache.IsTileReachable(kTileData.kTile) )
19961997
{
19971998
if (bLogTacticalDestinationIteration)
19981999
{
@@ -8651,7 +8652,7 @@ simulated function bool MoveToPoint(vector vDestination, optional out string Fai
86518652
86528653
// HL-Docs: ref:AIHazardEscape; issue:1559
86538654
// IsTileReachable will always return false if surrounded by hazards
8654-
if (!bPathFailed && !bNeedsHazardEscape)
8655+
if (!bPathFailed && !NeedsHazardEscape())
86558656
{
86568657
bPathFailed = !m_kUnit.m_kReachableTilesCache.IsTileReachable(kTileDest);
86578658
if (bPathFailed)
@@ -8660,7 +8661,7 @@ simulated function bool MoveToPoint(vector vDestination, optional out string Fai
86608661
}
86618662
}
86628663
8663-
if( !bPathFailed || bForcePathIfUnreachable || bNeedsHazardEscape )
8664+
if( !bPathFailed || bForcePathIfUnreachable || NeedsHazardEscape() )
86648665
{
86658666
if (XGAIBehavior_Civilian(self) != none)
86668667
{
@@ -8669,7 +8670,7 @@ simulated function bool MoveToPoint(vector vDestination, optional out string Fai
86698670
86708671
// HL-Docs: ref:AIHazardEscape; issue:1559
86718672
// Use BuildNonUnitPath for hazard escape to ensure the unit can path out of hazards
8672-
if (bNeedsHazardEscape)
8673+
if (NeedsHazardEscape())
86738674
{
86748675
// Build allowed traversals from unit's character template
86758676
if (UnitState.GetMyTemplate().bCanUse_eTraversal_Normal) AllowedTraversals.AddItem(eTraversal_Normal);

0 commit comments

Comments
 (0)