Skip to content

Commit

Permalink
Fixed and optimised status check
Browse files Browse the repository at this point in the history
  • Loading branch information
Halbann committed Jan 9, 2023
1 parent 5ec9543 commit c9a7975
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Source/KerbalCombatSystems/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ private void DrawDebugText()
+ "\n Intercept Time: "
+ ship.nearInterceptApproachTime.ToString("0.00")
+ "\n Throttle: "
+ ship.fc.throttleLerped.ToString("0.00"),
+ ship.fc.throttleLerped.ToString("0.00")
+ "\n Current Weapon: "
+ ((ship.currentWeapon?.weaponCode) == "" ? (ship.currentWeapon?.weaponType) : (ship.currentWeapon?.weaponCode)),
ship.vessel);
}
}
Expand Down
15 changes: 8 additions & 7 deletions Source/KerbalCombatSystems/ShipController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class ModuleShipController : PartModule
private List<ModuleWeaponController> interceptors;
private List<ModuleWeaponController> weaponsToIntercept;
private float lastFired = 0;
public ModuleWeaponController currentWeapon;

internal float maxDetectionRange;
internal float maxWeaponRange;
Expand Down Expand Up @@ -316,13 +317,14 @@ private IEnumerator StatusChecker()
continue;
}

bool wasAlive = alive;
CheckStatus();
if (!alive)

if (!alive && wasAlive)
{
DeathMessage();
StopAI();
vessel.ActionGroups.SetGroup(KSPActionGroup.Abort, true);
yield break;
}

CalculateHeatSignature();
Expand Down Expand Up @@ -551,7 +553,7 @@ private IEnumerator UpdateBehaviour()
// Deploy combat robotics.
UpdateFlightRobotics(true);

ModuleWeaponController currentWeapon = GetPreferredWeapon(target, weapons);
currentWeapon = GetPreferredWeapon(target, weapons);
float minRange = currentWeapon.MinMaxRange.x;
float minRangeProjectile = currentWeapon.MinMaxRange.x * 0.25f;
float maxRange = Mathf.Min(currentWeapon.MinMaxRange.y, TargetLockRange());
Expand Down Expand Up @@ -935,10 +937,9 @@ private bool CanFireProjectile(Vessel target)

public bool CheckStatus()
{
bool hasRCSFore = vessel.FindPartModulesImplementing<ModuleRCSFX>().FindAll(e => e.rcsEnabled && !e.flameout && e.useThrottle).Count > 0;

hasPropulsion = hasRCSFore || vessel.FindPartModulesImplementing<ModuleEngines>().FindAll(e => e.EngineIgnited && e.isOperational).Count > 0;
hasWeapons = vessel.FindPartModulesImplementing<ModuleWeaponController>().FindAll(w => w.canFire).Count > 0;
bool hasRCSFore = vessel.FindPartModulesImplementing<ModuleRCSFX>().FindIndex(e => e.rcsEnabled && !e.flameout && e.useThrottle) > -1;
hasPropulsion = hasRCSFore || vessel.FindPartModulesImplementing<ModuleEngines>().FindIndex(e => e.EngineIgnited && e.isOperational) > -1;
hasWeapons = vessel.FindPartModulesImplementing<ModuleWeaponController>().FindIndex(w => w.canFire) > -1;

bool spunOut = false;
if (vessel.angularVelocity.magnitude > 50)
Expand Down

0 comments on commit c9a7975

Please sign in to comment.