@@ -47,6 +47,7 @@ public class ModuleShipController : PartModule
4747 private List < ModuleWeaponController > interceptors ;
4848 private List < ModuleWeaponController > weaponsToIntercept ;
4949 private float lastFired = 0 ;
50+ public ModuleWeaponController currentWeapon ;
5051
5152 internal float maxDetectionRange ;
5253 internal float maxWeaponRange ;
@@ -316,13 +317,14 @@ private IEnumerator StatusChecker()
316317 continue ;
317318 }
318319
320+ bool wasAlive = alive ;
319321 CheckStatus ( ) ;
320- if ( ! alive )
322+
323+ if ( ! alive && wasAlive )
321324 {
322325 DeathMessage ( ) ;
323326 StopAI ( ) ;
324327 vessel . ActionGroups . SetGroup ( KSPActionGroup . Abort , true ) ;
325- yield break ;
326328 }
327329
328330 CalculateHeatSignature ( ) ;
@@ -551,7 +553,7 @@ private IEnumerator UpdateBehaviour()
551553 // Deploy combat robotics.
552554 UpdateFlightRobotics ( true ) ;
553555
554- ModuleWeaponController currentWeapon = GetPreferredWeapon ( target , weapons ) ;
556+ currentWeapon = GetPreferredWeapon ( target , weapons ) ;
555557 float minRange = currentWeapon . MinMaxRange . x ;
556558 float minRangeProjectile = currentWeapon . MinMaxRange . x * 0.25f ;
557559 float maxRange = Mathf . Min ( currentWeapon . MinMaxRange . y , TargetLockRange ( ) ) ;
@@ -935,10 +937,9 @@ private bool CanFireProjectile(Vessel target)
935937
936938 public bool CheckStatus ( )
937939 {
938- bool hasRCSFore = vessel . FindPartModulesImplementing < ModuleRCSFX > ( ) . FindAll ( e => e . rcsEnabled && ! e . flameout && e . useThrottle ) . Count > 0 ;
939-
940- hasPropulsion = hasRCSFore || vessel . FindPartModulesImplementing < ModuleEngines > ( ) . FindAll ( e => e . EngineIgnited && e . isOperational ) . Count > 0 ;
941- hasWeapons = vessel . FindPartModulesImplementing < ModuleWeaponController > ( ) . FindAll ( w => w . canFire ) . Count > 0 ;
940+ bool hasRCSFore = vessel . FindPartModulesImplementing < ModuleRCSFX > ( ) . FindIndex ( e => e . rcsEnabled && ! e . flameout && e . useThrottle ) > - 1 ;
941+ hasPropulsion = hasRCSFore || vessel . FindPartModulesImplementing < ModuleEngines > ( ) . FindIndex ( e => e . EngineIgnited && e . isOperational ) > - 1 ;
942+ hasWeapons = vessel . FindPartModulesImplementing < ModuleWeaponController > ( ) . FindIndex ( w => w . canFire ) > - 1 ;
942943
943944 bool spunOut = false ;
944945 if ( vessel . angularVelocity . magnitude > 50 )
0 commit comments