protected void NewRecoveryFunction(Vessel vessel) { Debug.Log("[NIMBY] Our recovery function is being called!"); //check the distance to the KSC, if within 100km then recover, else pop up a message //We might be able to (temporarily) change the location of the KSC to the closest Beacon, which would also change the amount of funds we recover due to distance IBeacon closestBeacon = null; //Used for if we're not in range of any beacons double shortestDistance = double.PositiveInfinity; foreach (IBeacon beacon in GetAllBeacons()) { if (!beacon.Active || beacon.Range <= 0) { continue; } double distance = beacon.GreatCircleDistance(vessel); double adjustedDistance = distance - beacon.Range; Debug.Log($"[NIMBY] {beacon.Name} is {(distance / 1000).ToString("N2")}({(adjustedDistance / 1000).ToString("N2")})km away."); if (beacon.CanRecoverVessel(vessel)) { originalCallback.Invoke(); return; } else { if (distance > 0 && adjustedDistance < shortestDistance) //the > 0 checks that it isn't the active vessel { shortestDistance = adjustedDistance; closestBeacon = beacon; } } } //No beacons in range //popup "error" Debug.Log("[NIMBY] Too far to recover!"); string closestMessage = "There are no Recovery Beacons nearby."; if (closestBeacon != null) { double dist = closestBeacon.GreatCircleDistance(vessel) / 1000; closestMessage = $"Closest Recovery Beacon is {closestBeacon.Name} and is {(dist).ToString("N2")}km away ({(dist-closestBeacon.Range/1000).ToString("N2")}km to edge of Beacon's range)."; } PopupDialog.SpawnPopupDialog(new Vector2(), new Vector2(), "tooFarPopup", "No Beacons In Range", $"Vessel is too far from any Recovery Beacons to recover. {closestMessage}", "OK", false, HighLogic.UISkin); }
protected void NewRecoveryFunction(Vessel vessel) { //(severedsolo) Originally the mod checked for beacons only, but now we can "tag" need to handle it elsewhere too. bool recoveryAllowed = false; Debug.Log("[NIMBY] Our recovery function is being called!"); //check the distance to the KSC, if within 100km then recover, else pop up a message //We might be able to (temporarily) change the location of the KSC to the closest Beacon, which would also change the amount of funds we recover due to distance //(severedsolo) I don't see the need to try to move KSC. //Kerbal Konstructs just uses normal recovery values unless you are on the pad/runway, that's good enough. //The new plugin will create beacons for KK bases anyway. IBeacon closestBeacon = null; //Used for if we're not in range of any beacons double shortestDistance = double.PositiveInfinity; foreach (IBeacon beacon in GetAllBeacons()) { if (!beacon.Active || beacon.Range <= 0) { continue; } double distance = beacon.GreatCircleDistance(vessel); double adjustedDistance = distance - beacon.Range; Debug.Log($"[NIMBY] {beacon.Name} is {(distance / 1000).ToString("N2")}({(adjustedDistance / 1000).ToString("N2")})km away."); if (beacon.CanRecoverVessel(vessel)) { recoveryAllowed = true; break; } if (distance > 0 && adjustedDistance < shortestDistance) //the > 0 checks that it isn't the active vessel { shortestDistance = adjustedDistance; closestBeacon = beacon; } } if (NIMBYEvent.Instance.taggedVessels.Contains(vessel.id)) { recoveryAllowed = true; } if (recoveryAllowed) { NIMBYEvent.Instance.taggedVessels.Remove(vessel.id); originalCallback.Invoke(); return; } //No beacons in range (severedsolo)Or vessel not tagged. //popup "error" Debug.Log("[NIMBY] Too far to recover!"); string closestMessage = "There are no Recovery Beacons nearby."; if (closestBeacon != null) { double dist = closestBeacon.GreatCircleDistance(vessel) / 1000; closestMessage = $"Closest Recovery Beacon is {closestBeacon.Name} and is {(dist).ToString("N2")}km away ({(dist-closestBeacon.Range/1000).ToString("N2")}km to edge of Beacon's range)."; } PopupDialog.SpawnPopupDialog(new Vector2(), new Vector2(), "tooFarPopup", "No Beacons In Range", $"Vessel is too far from any Recovery Beacons to recover. {closestMessage}", "OK", false, HighLogic.UISkin); }