Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FD] Prevent AI stationary positions unreachable code being hit #733

Open
wants to merge 2 commits into
base: gamemode_fd
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,17 @@ void function MortarSpectreSquadThink( array< entity > spectres, entity harveste
if ( spectres.len() == 0)
return

// get the closest available stationary position for mortar spectres
StationaryAIPosition ornull mortarPosition = GetClosestAvailableStationaryPosition( /* spectres[0] isnt ideal but the spectres all spawn in the same position atm */ spectres[0].GetOrigin(), MORTAR_SPECTRE_POSITION_SEARCH_RANGE, eStationaryAIPositionTypes.MORTAR_SPECTRE )
while ( mortarPosition == null )
{
// in case all stationary spectre positions are in use wait for one to become available
// incase all stationary mortar positions are in use wait for one to become available
while ( !AnyStationaryPositionsAvailable( eStationaryAIPositionTypes.MORTAR_SPECTRE ) )
wait 5
// should change this to use an average position or the start position or something but for now this is fine
mortarPosition = GetClosestAvailableStationaryPosition( spectres[0].GetOrigin(), MORTAR_SPECTRE_POSITION_SEARCH_RANGE, eStationaryAIPositionTypes.MORTAR_SPECTRE )
}

// should change this to use an average position or the start position or something but for now this is fine
StationaryAIPosition mortarPosition = GetClosestAvailableStationaryPosition( spectres[0].GetOrigin(), MORTAR_SPECTRE_POSITION_SEARCH_RANGE, eStationaryAIPositionTypes.MORTAR_SPECTRE )

// create the entity responsible for managing this squad of spectres
// note: client shows the ui thing for this entity if the y angle is not 0
// it also shows the set up time thing based on the shield frac of the entity? weird
entity squadMarker = CreatePropScript( $"models/dev/empty_model.mdl", expect StationaryAIPosition( mortarPosition ).origin + < 0, 0, 150 >, < 0, 1, 0 > )
entity squadMarker = CreatePropScript( $"models/dev/empty_model.mdl", mortarPosition.origin + < 0, 0, 150 >, < 0, 1, 0 > )
SetTargetName( squadMarker, "mortarPosition" )
squadMarker.SetShieldHealthMax( MORTAR_SPECTRE_TRACKER_SHIELD_MAX )
squadMarker.Minimap_SetCustomState( eMinimapObject_prop_script.FD_MORTAR_POSITION )
Expand All @@ -57,7 +55,7 @@ void function MortarSpectreSquadThink( array< entity > spectres, entity harveste
int i = 0
foreach( entity spectre in spectres )
{
thread MortarSpectreMoveToMortarPosition( spectre, squadMarker, OriginToGround( expect StationaryAIPosition( mortarPosition ).origin + MORTAR_SPECTRE_POSITION_OFFSETS[i] + < 0, 0, 100 > ) )
thread MortarSpectreMoveToMortarPosition( spectre, squadMarker, OriginToGround( mortarPosition.origin + MORTAR_SPECTRE_POSITION_OFFSETS[i] + < 0, 0, 100 > ) )

if ( i++ >= MORTAR_SPECTRE_POSITION_OFFSETS.len() )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,12 @@ void function MortarTitanThink( entity titan, entity generator )
WaitTillHotDropComplete( titan )

float minEngagementDuration = 5
StationaryAIPosition ornull mortarPosition = GetClosestAvailableStationaryPosition( titan.GetOrigin(), MORTAR_TITAN_POSITION_SEARCH_RANGE, eStationaryAIPositionTypes.MORTAR_TITAN )
while ( mortarPosition == null )
{
// incase all stationary titan positions are in use wait for one to become available

// incase all stationary titan positions are in use wait for one to become available
while ( !AnyStationaryPositionsAvailable( eStationaryAIPositionTypes.MORTAR_TITAN ) )
wait 5
mortarPosition = GetClosestAvailableStationaryPosition( titan.GetOrigin(), MORTAR_TITAN_POSITION_SEARCH_RANGE, eStationaryAIPositionTypes.MORTAR_TITAN )
}

expect StationaryAIPosition( mortarPosition )
StationaryAIPosition mortarPosition = GetClosestAvailableStationaryPosition( titan.GetOrigin(), MORTAR_TITAN_POSITION_SEARCH_RANGE, eStationaryAIPositionTypes.MORTAR_TITAN )

ClaimStationaryAIPosition( mortarPosition )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,12 @@ void function SniperTitanThink( entity titan, entity generator)
WaitTillHotDropComplete( titan )

float minEngagementDuration = 5
StationaryAIPosition ornull sniperPosition = GetClosestAvailableStationaryPosition( titan.GetOrigin(), SNIPER_TITAN_POSITION_SEARCH_RANGE, eStationaryAIPositionTypes.SNIPER_TITAN )
while ( sniperPosition == null )
{
// incase all stationary titan positions are in use wait for one to become available

// incase all stationary titan positions are in use wait for one to become available
while ( !AnyStationaryPositionsAvailable( eStationaryAIPositionTypes.SNIPER_TITAN ) )
wait 5
sniperPosition = GetClosestAvailableStationaryPosition( titan.GetOrigin(), SNIPER_TITAN_POSITION_SEARCH_RANGE, eStationaryAIPositionTypes.SNIPER_TITAN )
}

expect StationaryAIPosition( sniperPosition )
StationaryAIPosition sniperPosition = GetClosestAvailableStationaryPosition( titan.GetOrigin(), SNIPER_TITAN_POSITION_SEARCH_RANGE, eStationaryAIPositionTypes.SNIPER_TITAN )

ClaimStationaryAIPosition( sniperPosition )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ global function GetClosestAvailableStationaryPosition
global function ClaimStationaryAIPosition
global function ReleaseStationaryAIPosition
global function DebugDrawStationaryAiPositions
global function AnyStationaryPositionsAvailable

global enum eStationaryAIPositionTypes
{
Expand Down Expand Up @@ -137,6 +138,19 @@ void function ValidateAndFinalizePendingStationaryPositions()
}
}

bool function AnyStationaryPositionsAvailable( int type )
{
array<StationaryAIPosition> positions = file.stationaryPositions[type]

foreach ( position in positions )
{
if ( !position.inUse )
return true
}

return false
}

StationaryAIPosition function GetClosestAvailableStationaryPosition( vector origin, float maxDist, int type )
{

Expand Down
Loading