From 5c4d77c21b71c4c306f54dedc13325719972d3cb Mon Sep 17 00:00:00 2001 From: AMPW-german Date: Tue, 7 Oct 2025 21:53:00 +0200 Subject: [PATCH 1/5] Fixed the carrer scenario loading and don't add multiple launchsites with the same name --- src/Core/LaunchSites/LaunchSiteManager.cs | 1 + src/Modules/Career/CareerScenario.cs | 8 -------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Core/LaunchSites/LaunchSiteManager.cs b/src/Core/LaunchSites/LaunchSiteManager.cs index 526e96b..4329c3e 100644 --- a/src/Core/LaunchSites/LaunchSiteManager.cs +++ b/src/Core/LaunchSites/LaunchSiteManager.cs @@ -340,6 +340,7 @@ public static void RegisterLaunchSite(KKLaunchSite site) { Log.Error("Launch site " + site.LaunchSiteName + " already exists."); + return; } diff --git a/src/Modules/Career/CareerScenario.cs b/src/Modules/Career/CareerScenario.cs index 7f701f7..8ebb0c1 100644 --- a/src/Modules/Career/CareerScenario.cs +++ b/src/Modules/Career/CareerScenario.cs @@ -20,14 +20,6 @@ public class KerbalKonstructsSettings : ScenarioModule /// The name of the config node public override void OnLoad(ConfigNode node) { - // check if we have been in the mainmenue before (gameTime == -1) or if we saved just before we load (scene switch) - if (KerbalKonstructs.gameTime == -1d || KerbalKonstructs.gameTime > HighLogic.CurrentGame.UniversalTime) - { - } - else - { - return; - } CareerMapDecals.LoadDecals(node); From f0831414216074375a280657c964e5ccac1d770b Mon Sep 17 00:00:00 2001 From: AMPW-german Date: Thu, 9 Oct 2025 20:46:14 +0200 Subject: [PATCH 2/5] * Changed the landed vesset at prelaunch checks to use the lat/lon coordinates with a 0.2 minimum safety margin and also only check landed/splahsed vessel to not get issues with very distant planets --- src/Core/LaunchSites/LaunchSiteChecks.cs | 123 ++++++++++++++++++----- src/Core/StaticObjects/StaticInstance.cs | 5 + src/Modules/Career/CareerScenario.cs | 10 ++ 3 files changed, 112 insertions(+), 26 deletions(-) diff --git a/src/Core/LaunchSites/LaunchSiteChecks.cs b/src/Core/LaunchSites/LaunchSiteChecks.cs index ce2f4e5..3f80974 100644 --- a/src/Core/LaunchSites/LaunchSiteChecks.cs +++ b/src/Core/LaunchSites/LaunchSiteChecks.cs @@ -348,23 +348,53 @@ public static void FindVesselsLandedAtKK(FlightState flightState, string landedA } else { - //if (vessel.situation == Vessel.Situations.SPLASHED || vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.PRELAUNCH ) - // { - //// Log.Normal("Body: "+ FlightGlobals.Bodies[vessel.orbitSnapShot.ReferenceBodyIndex].name); - CelestialBody body = FlightGlobals.Bodies[vessel.orbitSnapShot.ReferenceBodyIndex]; - Vector3 position = body.GetWorldSurfacePosition(vessel.latitude, vessel.longitude, vessel.altitude); - float distance = Vector3.Distance(position, launchSite.staticInstance.gameObject.transform.position); - //Log.Normal("Vessel with distance: " + distance); - if (distance < maxDistance) + if (vessel.orbitSnapShot.ReferenceBodyIndex == launchSite.body.flightGlobalsIndex) { - Log.Normal("Found Vessel at Launchsite with distance: " + distance); - count++; - name = vessel.vesselName; - idx = vesselIndex; - vType = vessel.vesselType; - break; + if (vessel.situation == Vessel.Situations.SPLASHED || vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.PRELAUNCH) + { + CelestialBody body = FlightGlobals.Bodies[vessel.orbitSnapShot.ReferenceBodyIndex]; + + if (body == null) + { + Log.Normal("Could not find body for vessel"); + vesselIndex++; + continue; + } + + if (body != launchSite.body) + { + Log.Normal("Vessel is on different body than Launchsite"); + vesselIndex++; + continue; + } + + Vector3 position = body.GetWorldSurfacePosition(vessel.latitude, vessel.longitude, vessel.altitude); + + Vector2d tol = GetLatLonTolerance(launchSite.staticInstance.groupCenter.RefLatitude, launchSite.staticInstance.groupCenter.RefLongitude, maxDistance, body.Radius + launchSite.staticInstance.groupCenter.RadiusOffset); + + if (Math.Abs(vessel.latitude - launchSite.staticInstance.groupCenter.RefLatitude) > tol.y || Math.Abs(vessel.longitude - launchSite.staticInstance.groupCenter.RefLongitude) > tol.x) + { + Log.Normal("Vessel is outside lat/lon tolerance"); + Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); + Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); + Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); + vesselIndex++; + continue; + } + else + { + Log.Normal("Found Vessel at Launchsite with:"); + Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); + Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); + Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); + count++; + name = vessel.vesselName; + idx = vesselIndex; + vType = vessel.vesselType; + break; + } + } } - //} } vesselIndex++; } @@ -399,18 +429,30 @@ public static List FindVesselsLandedAt2(FlightState flightState, st } else { - //if (vessel.situation == Vessel.Situations.SPLASHED || vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.PRELAUNCH) - //{ - CelestialBody body = FlightGlobals.Bodies[vessel.orbitSnapShot.ReferenceBodyIndex]; - Vector3 position = body.GetWorldSurfacePosition(vessel.latitude, vessel.longitude, vessel.altitude); - float distance = Vector3.Distance(position, launchSite.staticInstance.transform.position); - - if (distance < maxDistance) + if (vessel.situation == Vessel.Situations.SPLASHED || vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.PRELAUNCH) { - Log.Normal("Found Vessel at Launchsite with distance: " + distance); - list.Add(vessel); + CelestialBody body = FlightGlobals.Bodies[vessel.orbitSnapShot.ReferenceBodyIndex]; + + Vector2d tol = GetLatLonTolerance(launchSite.staticInstance.groupCenter.RefLatitude, launchSite.staticInstance.groupCenter.RefLongitude, maxDistance, body.Radius); + + if (Math.Abs(vessel.latitude - launchSite.staticInstance.groupCenter.RefLatitude) > tol.y || Math.Abs(vessel.longitude - launchSite.staticInstance.groupCenter.RefLongitude) > tol.x) + { + Log.Normal("Vessel is outside lat/lon tolerance"); + Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); + Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); + Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); + continue; + } + else + { + Log.Normal("Found Vessel at Launchsite with:"); + Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); + Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); + Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); + + list.Add(vessel); + } } - //} } } @@ -419,8 +461,37 @@ public static List FindVesselsLandedAt2(FlightState flightState, st return list; } + public static Vector2d GetLatLonTolerance(double lat, double lon, double squareSize, double bodySize) + { + Vector2d dest(double latRad, double lonRad, double bearingRad, double angDist) + { + Vector2d res = new Vector2d(0, 0); - } + // lon = x, lat = y + res.x = Math.Asin(Math.Sin(latRad) * Math.Cos(angDist) + Math.Cos(latRad) * Math.Sin(angDist) * Math.Cos(bearingRad)); + res.y = lonRad + Math.Atan2(Math.Sin(bearingRad) * Math.Sin(angDist) * Math.Cos(latRad), Math.Cos(angDist) - Math.Sin(latRad) * Math.Sin(res.x)); + res.y = (res.y + Math.PI) % (2 * Math.PI) - Math.PI; + return res; + } + + double s = squareSize / 2d; + + double latRads = lat * Math.PI / 180d; + double lonRads = lon * Math.PI / 180d; + double delta = s / bodySize; + + Vector2d north = dest(latRads, lonRads, 0d, delta); + double deltaLat = Math.Abs(north.x - latRads) * 180d / Math.PI; + + Vector2d east = dest(latRads, lonRads, Math.PI / 2d, delta); + double deltaLon = Math.Abs(east.y - lonRads) * 180d / Math.PI; + + deltaLat = Math.Min(0.2, deltaLat); + deltaLon = Math.Min(0.2, deltaLon); + + return new Vector2d(deltaLon, deltaLat); + } + } } \ No newline at end of file diff --git a/src/Core/StaticObjects/StaticInstance.cs b/src/Core/StaticObjects/StaticInstance.cs index 0d11b50..0ce3908 100644 --- a/src/Core/StaticObjects/StaticInstance.cs +++ b/src/Core/StaticObjects/StaticInstance.cs @@ -637,6 +637,11 @@ internal void Destroy() { if (StaticsEditorGUI.selectedObject == this) StaticsEditorGUI.selectedObject = null; + if (launchSite != null) + { + LaunchSiteManager.DeleteLaunchSite(launchSite); + } + if (groupCenter != null) { groupCenter.RemoveInstance(this); diff --git a/src/Modules/Career/CareerScenario.cs b/src/Modules/Career/CareerScenario.cs index 8ebb0c1..b2d261b 100644 --- a/src/Modules/Career/CareerScenario.cs +++ b/src/Modules/Career/CareerScenario.cs @@ -20,6 +20,16 @@ public class KerbalKonstructsSettings : ScenarioModule /// The name of the config node public override void OnLoad(ConfigNode node) { + // check if we have been in the mainmenue before (gameTime == -1) or if we saved just before we load (scene switch) + //if (KerbalKonstructs.gameTime == -1d || KerbalKonstructs.gameTime > HighLogic.CurrentGame.UniversalTime) + if (KerbalKonstructs.gameTime == -1d) + { + + } + else + { + return; + } CareerMapDecals.LoadDecals(node); From a786dfb6e5cadaaecc0c63f0bc1e42eaaab2a1c7 Mon Sep 17 00:00:00 2001 From: AMPW-german Date: Wed, 26 Nov 2025 21:27:37 +0100 Subject: [PATCH 3/5] Use GPS checks only if distance = 0 because that's where floating point impreciscion is a problem and otherwise the normal distance checks are more accurate. --- src/Core/LaunchSites/LaunchSiteChecks.cs | 87 ++++++++++++++++-------- src/Properties/AssemblyInfo.cs | 6 +- 2 files changed, 61 insertions(+), 32 deletions(-) diff --git a/src/Core/LaunchSites/LaunchSiteChecks.cs b/src/Core/LaunchSites/LaunchSiteChecks.cs index 3f80974..6d0daca 100644 --- a/src/Core/LaunchSites/LaunchSiteChecks.cs +++ b/src/Core/LaunchSites/LaunchSiteChecks.cs @@ -353,6 +353,8 @@ public static void FindVesselsLandedAtKK(FlightState flightState, string landedA if (vessel.situation == Vessel.Situations.SPLASHED || vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.PRELAUNCH) { CelestialBody body = FlightGlobals.Bodies[vessel.orbitSnapShot.ReferenceBodyIndex]; + Vector3 position = body.GetWorldSurfacePosition(vessel.latitude, vessel.longitude, vessel.altitude); + float distance = Vector3.Distance(position, launchSite.staticInstance.gameObject.transform.position); if (body == null) { @@ -368,25 +370,38 @@ public static void FindVesselsLandedAtKK(FlightState flightState, string landedA continue; } - Vector3 position = body.GetWorldSurfacePosition(vessel.latitude, vessel.longitude, vessel.altitude); - - Vector2d tol = GetLatLonTolerance(launchSite.staticInstance.groupCenter.RefLatitude, launchSite.staticInstance.groupCenter.RefLongitude, maxDistance, body.Radius + launchSite.staticInstance.groupCenter.RadiusOffset); - - if (Math.Abs(vessel.latitude - launchSite.staticInstance.groupCenter.RefLatitude) > tol.y || Math.Abs(vessel.longitude - launchSite.staticInstance.groupCenter.RefLongitude) > tol.x) + //Log.Normal("Vessel with distance: " + distance); + if (distance == 0) { - Log.Normal("Vessel is outside lat/lon tolerance"); - Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); - Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); - Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); - vesselIndex++; - continue; + Log.Normal("Vessel has same position as Launchsite, probably floating point error. Using gps checks instead."); + + Vector2d tol = GetLatLonTolerance(launchSite.staticInstance.groupCenter.RefLatitude, launchSite.staticInstance.groupCenter.RefLongitude, maxDistance, body.Radius + launchSite.staticInstance.groupCenter.RadiusOffset); + + if (Math.Abs(vessel.latitude - launchSite.staticInstance.groupCenter.RefLatitude) > tol.y || Math.Abs(vessel.longitude - launchSite.staticInstance.groupCenter.RefLongitude) > tol.x) + { + Log.Normal("Vessel is outside lat/lon tolerance"); + Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); + Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); + Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); + vesselIndex++; + continue; + } + else + { + Log.Normal("Found Vessel at Launchsite with:"); + Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); + Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); + Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); + count++; + name = vessel.vesselName; + idx = vesselIndex; + vType = vessel.vesselType; + break; + } } - else + else if (distance < maxDistance) { - Log.Normal("Found Vessel at Launchsite with:"); - Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); - Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); - Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); + Log.Normal("Found Vessel at Launchsite with distance: " + distance); count++; name = vessel.vesselName; idx = vesselIndex; @@ -433,25 +448,39 @@ public static List FindVesselsLandedAt2(FlightState flightState, st { CelestialBody body = FlightGlobals.Bodies[vessel.orbitSnapShot.ReferenceBodyIndex]; - Vector2d tol = GetLatLonTolerance(launchSite.staticInstance.groupCenter.RefLatitude, launchSite.staticInstance.groupCenter.RefLongitude, maxDistance, body.Radius); + Vector3 position = body.GetWorldSurfacePosition(vessel.latitude, vessel.longitude, vessel.altitude); + float distance = Vector3.Distance(position, launchSite.staticInstance.transform.position); - if (Math.Abs(vessel.latitude - launchSite.staticInstance.groupCenter.RefLatitude) > tol.y || Math.Abs(vessel.longitude - launchSite.staticInstance.groupCenter.RefLongitude) > tol.x) + if (distance == 0) { - Log.Normal("Vessel is outside lat/lon tolerance"); - Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); - Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); - Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); - continue; + Log.Normal("Vessel has same position as Launchsite, probably floating point error. Using gps checks instead."); + Vector2d tol = GetLatLonTolerance(launchSite.staticInstance.groupCenter.RefLatitude, launchSite.staticInstance.groupCenter.RefLongitude, maxDistance, body.Radius); + + if (Math.Abs(vessel.latitude - launchSite.staticInstance.groupCenter.RefLatitude) > tol.y || Math.Abs(vessel.longitude - launchSite.staticInstance.groupCenter.RefLongitude) > tol.x) + { + Log.Normal("Vessel is outside lat/lon tolerance"); + Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); + Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); + Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); + continue; + } + else + { + Log.Normal("Found Vessel at Launchsite with:"); + Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); + Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); + Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); + + list.Add(vessel); + } } - else + if (distance < maxDistance) { - Log.Normal("Found Vessel at Launchsite with:"); - Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); - Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); - Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); - + Log.Normal("Found Vessel at Launchsite with distance: " + distance); list.Add(vessel); } + + } } diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs index b959206..d8c1776 100644 --- a/src/Properties/AssemblyInfo.cs +++ b/src/Properties/AssemblyInfo.cs @@ -41,9 +41,9 @@ [assembly: AssemblyFileVersion("@MAJOR@.@MINOR@.@PATCH@.@BUILD@")] [assembly: AssemblyInformationalVersion("@MAJOR@.@MINOR@.@PATCH@.@BUILD@")] #else -[assembly: AssemblyFileVersion("1.11.0.0")] -[assembly: AssemblyInformationalVersion("1.11.0.0")] +[assembly: AssemblyFileVersion("1.12.0.0")] +[assembly: AssemblyInformationalVersion("1.12.0.0")] #endif -[assembly: KSPAssembly("KerbalKonstructs", 1, 11, 0)] +[assembly: KSPAssembly("KerbalKonstructs", 1, 12, 0)] From 111c61f7ac2cf8684bcae7a9f9bb90c6a234a33a Mon Sep 17 00:00:00 2001 From: AMPW-german Date: Sun, 30 Nov 2025 21:10:14 +0100 Subject: [PATCH 4/5] Moved Vessel at launchsite checks into a separate method --- src/Core/LaunchSites/LaunchSiteChecks.cs | 211 +++++++++-------------- src/Modules/Career/CareerScenario.cs | 18 +- 2 files changed, 79 insertions(+), 150 deletions(-) diff --git a/src/Core/LaunchSites/LaunchSiteChecks.cs b/src/Core/LaunchSites/LaunchSiteChecks.cs index 6d0daca..7585892 100644 --- a/src/Core/LaunchSites/LaunchSiteChecks.cs +++ b/src/Core/LaunchSites/LaunchSiteChecks.cs @@ -8,7 +8,7 @@ namespace KerbalKonstructs.Core { - class LaunchSiteChecks + internal class LaunchSiteChecks { internal static AsmUtils.Detour findVesselDetour; internal static AsmUtils.Detour findVesselDetour2; @@ -58,10 +58,10 @@ public static PreFlightTests.IPreFlightTest GetPartCheck(string launchSiteName) public class KKPrelaunchSizeCheck : PreFlightTests.IPreFlightTest { - Vector3 shipSize; - KKLaunchSite launchSite; + private Vector3 shipSize; + private KKLaunchSite launchSite; - bool allowLaunch = false; + private bool allowLaunch = false; public KKPrelaunchSizeCheck(string launchSiteName) @@ -155,10 +155,10 @@ public string GetAbortOption() public class KKPrelaunchMassCheck : PreFlightTests.IPreFlightTest { - float shipMass; - KKLaunchSite launchSite; + private float shipMass; + private KKLaunchSite launchSite; - bool allowLaunch = false; + private bool allowLaunch = false; public KKPrelaunchMassCheck(string launchSiteName) @@ -238,10 +238,10 @@ public string GetAbortOption() public class KKPrelaunchPartCheck : PreFlightTests.IPreFlightTest { - int shipParts; - KKLaunchSite launchSite; + private int shipParts; + private KKLaunchSite launchSite; - bool allowLaunch = false; + private bool allowLaunch = false; public KKPrelaunchPartCheck(string launchSiteName) @@ -302,9 +302,6 @@ public string GetAbortOption() } } - - - /// /// ReplaceMent for finding vessels /// @@ -335,90 +332,19 @@ public static void FindVesselsLandedAtKK(FlightState flightState, string landedA continue; } - if (launchSite == null || launchSite.isSquad) + if (VesselAtLaunchSite(vessel, launchSite, maxDistance, landedAt)) { - if (vessel.landedAt.Contains(landedAt)) - { - count++; - name = vessel.vesselName; - idx = vesselIndex; - vType = vessel.vesselType; - break; - } - } - else - { - if (vessel.orbitSnapShot.ReferenceBodyIndex == launchSite.body.flightGlobalsIndex) - { - if (vessel.situation == Vessel.Situations.SPLASHED || vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.PRELAUNCH) - { - CelestialBody body = FlightGlobals.Bodies[vessel.orbitSnapShot.ReferenceBodyIndex]; - Vector3 position = body.GetWorldSurfacePosition(vessel.latitude, vessel.longitude, vessel.altitude); - float distance = Vector3.Distance(position, launchSite.staticInstance.gameObject.transform.position); - - if (body == null) - { - Log.Normal("Could not find body for vessel"); - vesselIndex++; - continue; - } - - if (body != launchSite.body) - { - Log.Normal("Vessel is on different body than Launchsite"); - vesselIndex++; - continue; - } - - //Log.Normal("Vessel with distance: " + distance); - if (distance == 0) - { - Log.Normal("Vessel has same position as Launchsite, probably floating point error. Using gps checks instead."); - - Vector2d tol = GetLatLonTolerance(launchSite.staticInstance.groupCenter.RefLatitude, launchSite.staticInstance.groupCenter.RefLongitude, maxDistance, body.Radius + launchSite.staticInstance.groupCenter.RadiusOffset); - - if (Math.Abs(vessel.latitude - launchSite.staticInstance.groupCenter.RefLatitude) > tol.y || Math.Abs(vessel.longitude - launchSite.staticInstance.groupCenter.RefLongitude) > tol.x) - { - Log.Normal("Vessel is outside lat/lon tolerance"); - Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); - Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); - Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); - vesselIndex++; - continue; - } - else - { - Log.Normal("Found Vessel at Launchsite with:"); - Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); - Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); - Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); - count++; - name = vessel.vesselName; - idx = vesselIndex; - vType = vessel.vesselType; - break; - } - } - else if (distance < maxDistance) - { - Log.Normal("Found Vessel at Launchsite with distance: " + distance); - count++; - name = vessel.vesselName; - idx = vesselIndex; - vType = vessel.vesselType; - break; - } - } - } + count++; + name = vessel.vesselName; + idx = vesselIndex; + vType = vessel.vesselType; + break; } vesselIndex++; } } } - - - public static List FindVesselsLandedAt2(FlightState flightState, string landedAt) { float maxDistance = 100f; @@ -434,60 +360,77 @@ public static List FindVesselsLandedAt2(FlightState flightState, st continue; } - if (launchSite == null || launchSite.isSquad) + if (VesselAtLaunchSite(vessel, launchSite, maxDistance, landedAt)) { - if (vessel.landedAt.Contains(landedAt)) - { - list.Add(vessel); + list.Add(vessel); + } + } + } + return list; + } - } + public static bool VesselAtLaunchSite(ProtoVessel vessel, KKLaunchSite launchSite, float maxDistance, string landedAt) + { + if (launchSite == null || launchSite.isSquad) + { + if (vessel.landedAt.Contains(landedAt)) + { + return true; + } + } + + if (vessel.orbitSnapShot.ReferenceBodyIndex == launchSite.body.flightGlobalsIndex) + { + if (vessel.situation == Vessel.Situations.SPLASHED || vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.PRELAUNCH) + { + CelestialBody body = FlightGlobals.Bodies[vessel.orbitSnapShot.ReferenceBodyIndex]; + Vector3 position = body.GetWorldSurfacePosition(vessel.latitude, vessel.longitude, vessel.altitude); + float distance = Vector3.Distance(position, launchSite.staticInstance.gameObject.transform.position); + + if (body == null) + { + Log.Normal("Could not find body for vessel"); + return false; } - else + + if (body != launchSite.body) { - if (vessel.situation == Vessel.Situations.SPLASHED || vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.PRELAUNCH) - { - CelestialBody body = FlightGlobals.Bodies[vessel.orbitSnapShot.ReferenceBodyIndex]; - - Vector3 position = body.GetWorldSurfacePosition(vessel.latitude, vessel.longitude, vessel.altitude); - float distance = Vector3.Distance(position, launchSite.staticInstance.transform.position); - - if (distance == 0) - { - Log.Normal("Vessel has same position as Launchsite, probably floating point error. Using gps checks instead."); - Vector2d tol = GetLatLonTolerance(launchSite.staticInstance.groupCenter.RefLatitude, launchSite.staticInstance.groupCenter.RefLongitude, maxDistance, body.Radius); - - if (Math.Abs(vessel.latitude - launchSite.staticInstance.groupCenter.RefLatitude) > tol.y || Math.Abs(vessel.longitude - launchSite.staticInstance.groupCenter.RefLongitude) > tol.x) - { - Log.Normal("Vessel is outside lat/lon tolerance"); - Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); - Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); - Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); - continue; - } - else - { - Log.Normal("Found Vessel at Launchsite with:"); - Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); - Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); - Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); - - list.Add(vessel); - } - } - if (distance < maxDistance) - { - Log.Normal("Found Vessel at Launchsite with distance: " + distance); - list.Add(vessel); - } + Log.Normal("Vessel is on different body than Launchsite"); + return false; + } + //Log.Normal("Vessel with distance: " + distance); + if (distance == 0) + { + Log.Normal("Vessel has same position as Launchsite, probably floating point error. Using gps checks instead."); + + Vector2d tol = GetLatLonTolerance(launchSite.staticInstance.groupCenter.RefLatitude, launchSite.staticInstance.groupCenter.RefLongitude, maxDistance, body.Radius + launchSite.staticInstance.groupCenter.RadiusOffset); + if (Math.Abs(vessel.latitude - launchSite.staticInstance.groupCenter.RefLatitude) > tol.y || Math.Abs(vessel.longitude - launchSite.staticInstance.groupCenter.RefLongitude) > tol.x) + { + Log.Normal("Vessel is outside lat/lon tolerance"); + Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); + Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); + Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); + return false; + } + else + { + Log.Normal("Found Vessel at Launchsite with:"); + Log.Debug($"Lat/Lon tolerance: {tol.y}, {tol.x}"); + Log.Debug($"Vessel Lat/Lon: {vessel.latitude}, {vessel.longitude}"); + Log.Debug($"Launchsite Lat/Lon: {launchSite.staticInstance.groupCenter.RefLatitude}, {launchSite.staticInstance.groupCenter.RefLongitude}"); + return true; } } - + else if (distance < maxDistance) + { + Log.Normal("Found Vessel at Launchsite with distance: " + distance); + return true; + } } - } - return list; + return false; } public static Vector2d GetLatLonTolerance(double lat, double lon, double squareSize, double bodySize) diff --git a/src/Modules/Career/CareerScenario.cs b/src/Modules/Career/CareerScenario.cs index b2d261b..7a3a0ed 100644 --- a/src/Modules/Career/CareerScenario.cs +++ b/src/Modules/Career/CareerScenario.cs @@ -20,16 +20,8 @@ public class KerbalKonstructsSettings : ScenarioModule /// The name of the config node public override void OnLoad(ConfigNode node) { - // check if we have been in the mainmenue before (gameTime == -1) or if we saved just before we load (scene switch) - //if (KerbalKonstructs.gameTime == -1d || KerbalKonstructs.gameTime > HighLogic.CurrentGame.UniversalTime) - if (KerbalKonstructs.gameTime == -1d) - { - - } - else - { - return; - } + // check if we have been in the mainmenue before (gameTime == -1) + if (KerbalKonstructs.gameTime != -1d) return; CareerMapDecals.LoadDecals(node); @@ -66,11 +58,8 @@ public override void OnLoad(ConfigNode node) KerbalKonstructs.instance.LoadKKConfig(node); - //if (CareerUtils.isCareerGame) - //{ Log.Normal("KKScenario loading facility states"); CareerState.Load(node); - //} ConnectionManager.LoadGroundStations(); @@ -94,11 +83,8 @@ public override void OnSave(ConfigNode node) KerbalKonstructs.instance.SaveKKConfig(node); - //if (CareerUtils.isCareerGame) - //{ Log.Normal("KKScenario saving career state"); CareerState.Save(node); - //} CareerMapDecals.SaveDecals(node); From 444bd3343ab47c598e758ca2ff781ef33c553197 Mon Sep 17 00:00:00 2001 From: AMPW-german Date: Sun, 30 Nov 2025 21:18:51 +0100 Subject: [PATCH 5/5] Remove commented out code from LaunchSiteChecks.cs --- src/Core/LaunchSites/LaunchSiteChecks.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Core/LaunchSites/LaunchSiteChecks.cs b/src/Core/LaunchSites/LaunchSiteChecks.cs index 7585892..1607276 100644 --- a/src/Core/LaunchSites/LaunchSiteChecks.cs +++ b/src/Core/LaunchSites/LaunchSiteChecks.cs @@ -120,7 +120,6 @@ public bool Test() retval = false; } - //Log.Normal("Ship dimensions: " + shipSize.ToString() ); return retval; } @@ -313,7 +312,6 @@ public string GetAbortOption() /// public static void FindVesselsLandedAtKK(FlightState flightState, string landedAt, out int count, out string name, out int idx, out VesselType vType) { - // Log.Normal("Called"); float maxDistance = 100f; int vesselIndex = 0; @@ -399,7 +397,6 @@ public static bool VesselAtLaunchSite(ProtoVessel vessel, KKLaunchSite launchSit return false; } - //Log.Normal("Vessel with distance: " + distance); if (distance == 0) { Log.Normal("Vessel has same position as Launchsite, probably floating point error. Using gps checks instead.");