Skip to content

Commit 0f289da

Browse files
authored
fix(segfault): Correctly check if a planet is valid in AI landing logic (endless-sky#12516)
1 parent 655213f commit 0f289da

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

source/AI.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,10 +2166,19 @@ void AI::MoveIndependent(Ship &ship, Command &command)
21662166
{
21672167
MoveToPlanet(ship, command);
21682168
const StellarObject *targetStellar = ship.GetTargetStellar();
2169-
bool shouldLandOnTarget = !shouldStay;
2170-
shouldLandOnTarget &= targetStellar->HasSprite();
2171-
shouldLandOnTarget &= targetStellar->GetPlanet() && targetStellar->GetPlanet()->CanLand(ship);
2172-
shouldLandOnTarget &= (ship.Attributes().Get("fuel capacity") || targetStellar->GetPlanet()->IsWormhole());
2169+
bool shouldLandOnTarget = [shouldStay, targetStellar, ship]() {
2170+
if(shouldStay)
2171+
return false;
2172+
if(!targetStellar->HasSprite())
2173+
return false;
2174+
if(!targetStellar->GetPlanet())
2175+
return false;
2176+
if(!targetStellar->GetPlanet()->CanLand(ship))
2177+
return false;
2178+
if(!ship.Attributes().Get("fuel capacity") && !targetStellar->GetPlanet()->IsWormhole())
2179+
return false;
2180+
return true;
2181+
}();
21732182
if(shouldLandOnTarget)
21742183
command |= Command::LAND;
21752184
else if(ship.Position().Distance(ship.GetTargetStellar()->Position()) < 100.)

0 commit comments

Comments
 (0)