public static Waypoint CreateWaypointAt( string name, CelestialBody body, double latitude, double longitude, string detail1 = null, string detail2 = null, string detail3 = null) { var waypoint = new Waypoint() { celestialName = body.name, name = name, nodeCaption1 = detail1, nodeCaption2 = detail2, nodeCaption3 = detail3, latitude = latitude, longitude = longitude, id = "custom", seed = 269, height = TerrainHeight(latitude, longitude, body), altitude = 0 }; ScenarioCustomWaypoints.AddWaypoint(waypoint); return(waypoint); }
public static bool RemoveWaypoint(string id) { if (TryFindWaypointById(id, out var waypoint)) { ScenarioCustomWaypoints.RemoveWaypoint(waypoint); return(true); } else { return(false); } }
/// <summary> /// Adds the waypoint to the custom waypoint list. /// </summary> /// <param name="waypoint">The waypoint to add</param> public static void AddWaypoint(Waypoint waypoint) { int seed = waypoint.seed; string id = waypoint.id; double altitude = waypoint.altitude; ScenarioCustomWaypoints.AddWaypoint(waypoint); waypoint.seed = seed; waypoint.id = id; waypoint.altitude = altitude; waypoint.index = Instance.nextIndex++; }
public static Waypoint CreateWaypointNear( string name, Vessel near, double minDistanceInMeters, double maxDistanceInMeters, double scannerNetQuality, bool waterAllowed, string detail1 = null, string detail2 = null, string detail3 = null) { Waypoint bestWaypoint = null; double bestWaypointDistance = 0; double currentMaxDistance = maxDistanceInMeters; for (int i = 0; i <= 3 * scannerNetQuality; ++i) { var waypoint = new Waypoint() { celestialName = near.mainBody.name, name = name, nodeCaption1 = detail1, nodeCaption2 = detail2, nodeCaption3 = detail3, id = "custom", seed = 269, }; waypoint.RandomizeNear(near.latitude, near.longitude, minDistanceInMeters, currentMaxDistance, waterAllowed: false, generator: new System.Random()); waypoint.height = WaypointHeight(waypoint); waypoint.altitude = 0; double thisWaypointDistance = StraightLineDistanceInMeters(near, waypoint); if (i == 0 || thisWaypointDistance < bestWaypointDistance) { bestWaypoint = waypoint; bestWaypointDistance = thisWaypointDistance; } currentMaxDistance = minDistanceInMeters + (currentMaxDistance - minDistanceInMeters) * .75; } ScenarioCustomWaypoints.AddWaypoint(bestWaypoint); return(bestWaypoint); }
public void AddWaypoint(bool challenge, string HoloKronName, Vector3 nextLocation) { waypointColor = new System.Random().Next(1, int.MaxValue) * _rColors.Count(); currentWaypoint = new Waypoint(); currentWaypoint.id = "marker"; currentWaypoint.seed = _rColors[waypointColor]; currentWaypoint.name = HoloKronName; currentWaypoint.celestialName = FlightGlobals.currentMainBody.name; currentWaypoint.longitude = nextLocation.y; currentWaypoint.longitude = nextLocation.y; currentWaypoint.latitude = nextLocation.x; currentWaypoint.altitude = nextLocation.z; currentWaypoint.height = nextLocation.z + 1; //currentWaypoint.iconSize = 1; OrXLog.instance.DebugLog("[OrX Target Manager] === ADDING WAYPOINT FOR " + HoloKronName + " ==="); waypoints.Add(currentWaypoint); ScenarioCustomWaypoints.AddWaypoint(currentWaypoint); }
public void RemoveWaypoint(string waypointName, Vector3 nextLocation) { List <Waypoint> .Enumerator w = waypoints.GetEnumerator(); while (w.MoveNext()) { if (w.Current != null) { if (w.Current.name == waypointName || w.Current.FullName == waypointName) { OrXLog.instance.DebugLog("[OrX Target Manager] === REMOVING WAYPOINT FOR " + w.Current.name + ", " + w.Current.FullName + " ==="); ScenarioCustomWaypoints.RemoveWaypoint(w.Current); waypoints.Remove(w.Current); } else { OrXLog.instance.DebugLog("[OrX Target Manager] === " + w.Current.name + " NOT FOUND ==="); } } } w.Dispose(); }
protected string setWaypoint(string resourceName, GoldStrikeLode lode) { if (this.part.vessel.situation == Vessel.Situations.LANDED || this.part.vessel.situation == Vessel.Situations.PRELAUNCH) { debugLog("Trying to set waypoint"); string location = string.Format("Lon: {0:f2} Lat: {1:f2} Alt: {2:f2}", this.part.vessel.longitude, this.part.vessel.latitude, this.part.vessel.altitude); Waypoint waypoint = new Waypoint(); waypoint.name = resourceName + " Lode"; waypoint.isExplored = true; waypoint.isNavigatable = true; waypoint.isOnSurface = true; waypoint.celestialName = this.part.vessel.mainBody.name; waypoint.longitude = this.part.vessel.longitude; waypoint.latitude = this.part.vessel.latitude; waypoint.altitude = this.part.vessel.altitude; waypoint.seed = UnityEngine.Random.Range(0, int.MaxValue); waypoint.navigationId = Guid.NewGuid(); //Add the waypoint to the custom waypoint scenario ScenarioCustomWaypoints.AddWaypoint(waypoint); //Our icon is not correct, do a quick remove, reset the icon, and add WaypointManager.RemoveWaypoint(waypoint); waypoint.id = WBIGoldStrikeScenario.kLodeIcon; waypoint.nodeCaption1 = location; WaypointManager.AddWaypoint(waypoint); //Record the waypoint info lode.navigationID = waypoint.navigationId.ToString(); //Save the game GamePersistence.SaveGame("quicksave", HighLogic.SaveFolder, SaveMode.BACKUP); //Done return(waypoint.navigationId.ToString()); } return(string.Empty); }
/// <summary> /// Removes the given waypoint from the custom list. /// </summary> /// <param name="waypoint">The waypoint to remove</param> public static void RemoveWaypoint(Waypoint waypoint) { ScenarioCustomWaypoints.RemoveWaypoint(waypoint); }
/// <summary> /// This method is called when a vessel computer awakens since the waypoint manager doesn't /// appear to be initialized before the Flight scene. This method ensures that all of the /// MAS NAVAIDS are registered in the waypoint manager. /// </summary> static internal void InitializeNavAids() { FinePrint.WaypointManager waypointManager = FinePrint.WaypointManager.Instance(); List <FinePrint.Waypoint> knownWaypoints = (waypointManager) ? waypointManager.Waypoints : null; int numNavAids = MASLoader.navaids.Count; if (MASConfig.navigation.enableNavBeacons) { bool anyAdded = false; ConfigNode master = new ConfigNode("CUSTOM_WAYPOINTS"); for (int i = 0; i < numNavAids; ++i) { // Make sure all navigation beacons are updated and added to the waypoint manager. if (MASLoader.navaids[i].maximumRange == -1.0) { MASLoader.navaids[i].UpdateHorizonDistance(); } string waypointName = MASLoader.navaids[i].waypointName; FinePrint.Waypoint wp = (knownWaypoints == null) ? null : knownWaypoints.Find(x => x.name == waypointName); if (MASConfig.ResetWaypoints && wp != null) { ScenarioCustomWaypoints.RemoveWaypoint(wp); wp = null; } if (wp == null) { FinePrint.Waypoint newwp = MASLoader.navaids[i].ToWaypoint(i); // Note: this is round-about, but it appears to be the way to register // waypoints to show up in Waypoint Manager. If I simply add the // waypoint directly using FinePrint.WaypointManager, it's present there, but // not in the Waypoint Manager mod's GUI list. So this is a simple // way to get compatibility. ConfigNode child = new ConfigNode("WAYPOINT"); child.AddValue("latitude", newwp.latitude); child.AddValue("longitude", newwp.longitude); child.AddValue("altitude", newwp.altitude); child.AddValue("celestialName", newwp.celestialName); child.AddValue("name", newwp.name); child.AddValue("id", newwp.id); child.AddValue("index", newwp.index); child.AddValue("navigationId", newwp.navigationId.ToString()); master.AddNode(child); anyAdded = true; //FinePrint.WaypointManager.AddWaypoint(newwp); } } if (anyAdded) { ScenarioCustomWaypoints.Instance.OnLoad(master); } } else if (knownWaypoints != null && knownWaypoints.Count > 0) { for (int i = 0; i < numNavAids; ++i) { // If nav beacons are disabled, remove them from the database string waypointName = MASLoader.navaids[i].waypointName; FinePrint.Waypoint wp = knownWaypoints.Find(x => x.name == waypointName); if (wp != null) { ScenarioCustomWaypoints.RemoveWaypoint(wp); knownWaypoints.Remove(wp); } } } if (MASConfig.EnableCommNetWaypoints) { CelestialBody kerbin = Planetarium.fetch.Home; int index = 0; bool anyAdded = false; ConfigNode master = new ConfigNode("CUSTOM_WAYPOINTS"); foreach (var keyValue in MASLoader.deepSpaceNetwork) { string waypointName = keyValue.Key; FinePrint.Waypoint wp = (knownWaypoints == null) ? null : knownWaypoints.Find(x => x.name == waypointName); if (MASConfig.ResetWaypoints && wp != null) { ScenarioCustomWaypoints.RemoveWaypoint(wp); wp = null; } ConfigNode child = new ConfigNode("WAYPOINT"); if (wp == null) { Guid g = Guid.NewGuid(); // Waypoint altitude keeps reporting a 0 when I query it. // I've tried using altitude above datum (TerrainAltitude) and // AGL (10 meters, here), and I keep seeing a 0 for altitude. // It looks like altitude is not actually stored in ScenarioCustomWaypoints, // so I may have to derive that value myself. //double altitude = kerbin.TerrainAltitude(keyValue.Value.x, keyValue.Value.y, false); child.AddValue("latitude", keyValue.Value.x); child.AddValue("longitude", keyValue.Value.y); child.AddValue("altitude", 10.0); //child.AddValue("altitude", altitude); // This isn't working? child.AddValue("celestialName", kerbin.name); child.AddValue("name", waypointName); child.AddValue("id", "vessel"); child.AddValue("index", ++index); child.AddValue("navigationId", g.ToString()); anyAdded = true; } master.AddNode(child); } if (anyAdded) { ScenarioCustomWaypoints.Instance.OnLoad(master); } } else if (knownWaypoints != null && knownWaypoints.Count > 0) { foreach (var keyValue in MASLoader.deepSpaceNetwork) { string waypointName = keyValue.Key; FinePrint.Waypoint wp = knownWaypoints.Find(x => x.name == waypointName); if (wp != null) { ScenarioCustomWaypoints.RemoveWaypoint(wp); knownWaypoints.Remove(wp); } } } MASConfig.ResetWaypoints = false; }