public void LoadBeacons(string beaconFile, bool createIfNotExists = false) { beacons.Clear(); if (System.IO.File.Exists(beaconFile)) { ConfigNode beaconsNode = ConfigNode.Load(beaconFile); foreach (ConfigNode beacon in beaconsNode.GetNodes("Beacon")) { beacons.Add(new Beacon(beacon)); } } else if (createIfNotExists) { //Set the defaults and save the file Beacon KSC = new Beacon("KSC", SpaceCenter.Instance.Latitude, SpaceCenter.Instance.Longitude, 100000); beacons.Add(KSC); ConfigNode beaconsNode = new ConfigNode("Beacons"); beaconsNode.AddNode(KSC.AsNode()); beaconsNode.Save(beaconFile); } }
protected void NewRecoveryFunction(Vessel vessel) { Debug.Log("!!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 Beacon closestBeacon = null; //Used for if we're not in range of any beacons double shortestDistance = double.PositiveInfinity; foreach (Beacon beacon in beacons) { double distance = beacon.GreatCircleDistance(vessel); if (distance < beacon.range) { originalCallback.Invoke(); return; } else { if (distance < shortestDistance) { shortestDistance = distance; closestBeacon = beacon; } } } //No beacons in range //popup "error" Debug.Log("!!Too far to recover!"); PopupDialog.SpawnPopupDialog(new Vector2(), new Vector2(), "Vessel Too Far", $"Vessel is too far from any Recovery Beacons to recover. Closest Recovery Beacon is {closestBeacon.name} and is {(shortestDistance/1000).ToString("N2")}km away.", "OK", false, HighLogic.UISkin); }