Skip to content

Commit c9a7975

Browse files
committed
Fixed and optimised status check
1 parent 5ec9543 commit c9a7975

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Source/KerbalCombatSystems/Debug.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ private void DrawDebugText()
170170
+ "\n Intercept Time: "
171171
+ ship.nearInterceptApproachTime.ToString("0.00")
172172
+ "\n Throttle: "
173-
+ ship.fc.throttleLerped.ToString("0.00"),
173+
+ ship.fc.throttleLerped.ToString("0.00")
174+
+ "\n Current Weapon: "
175+
+ ((ship.currentWeapon?.weaponCode) == "" ? (ship.currentWeapon?.weaponType) : (ship.currentWeapon?.weaponCode)),
174176
ship.vessel);
175177
}
176178
}

Source/KerbalCombatSystems/ShipController.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)