/// <summary> /// Find path to the target /// </summary> internal void FindPath() { double distanceToTarget = GeoUtils.GetDistance(startLatitude, startLongitude, targetLatitude, targetLongitude, mainBody.Radius); if (distanceToTarget < StepSize) { return; } double bearing = GeoUtils.InitialBearing(startLatitude, startLongitude, targetLatitude, targetLongitude); double altitude = GeoUtils.TerrainHeightAt(startLatitude, startLongitude, mainBody); int x = 0; int y = 0; Hex start = new Hex(startLatitude, startLongitude, altitude, bearing, x, y, this); tiles.Add(start); double straightPath = 0; while (straightPath < distanceToTarget) { GetNeighbours(x, y, false); x += directions[0].X; y += directions[0].Y; straightPath += StepSize; } Hex destination = tiles.Find(t => (t.X == x + directions[180].X) && (t.Y == y + directions[180].Y)); path = Path <Hex> .FindPath <Hex>(start, destination, distance, estimate); }
public double StraightPath() { double distanceToTarget = GeoUtils.GetDistance(startLatitude, startLongitude, targetLatitude, targetLongitude, mainBody.Radius); // if (distanceToTarget < 1000) return; double bearing = GeoUtils.InitialBearing(startLatitude, startLongitude, targetLatitude, targetLongitude); double altitude = GeoUtils.TerrainHeightAt(startLatitude, startLongitude, mainBody); int x = 0; int y = 0; Hex start = new Hex(startLatitude, startLongitude, altitude, bearing, x, y, this); tiles.Add(start); double straightPath = 0; // ScreenMessages.PostScreenMessage ("building straight " + DateTime.Now.ToString()); while (straightPath < distanceToTarget - 500) { GetNeighbours(x, y, false); Hex current = tiles.Find(t => (t.X == x && t.Y == y)); x += directions [0].X; y += directions [0].Y; Hex next = tiles.Find(t => (t.X == x && t.Y == y)); if (next.Altitude < 0 || ((next.Altitude - current.Altitude) > 500) || ((next.Altitude - current.Altitude) < -500)) { return(0); } straightPath += 1000; } Hex destination = tiles.Find(t => (t.X == x + directions [180].X) && (t.Y == y + directions [180].Y)); return(distanceToTarget); }
internal double GetDistance() { if (path != null) { Hex destination = path.LastStep; double appendix = GeoUtils.GetDistance(destination.Latitude, destination.Longitude, targetLatitude, targetLongitude, mainBody.Radius); return(path.TotalCost + appendix); } else { return(0); } }
public void FindPath() { double distanceToTarget = GeoUtils.GetDistance(startLatitude, startLongitude, targetLatitude, targetLongitude, mainBody.Radius); if (distanceToTarget < 1000) { return; } double bearing = GeoUtils.InitialBearing(startLatitude, startLongitude, targetLatitude, targetLongitude); double altitude = GeoUtils.TerrainHeightAt(startLatitude, startLongitude, mainBody); int x = 0; int y = 0; Hex start = new Hex(startLatitude, startLongitude, altitude, bearing, x, y, this); tiles.Add(start); double straightPath = 0; // ScreenMessages.PostScreenMessage ("building straight " + DateTime.Now.ToString()); while (straightPath < distanceToTarget - 500) { GetNeighbours(x, y, false); x += directions [0].X; y += directions [0].Y; straightPath += 1000; } Hex destination = tiles.Find(t => (t.X == x + directions [180].X) && (t.Y == y + directions [180].Y)); /* KSP.IO.File.AppendAllText<BonVoyage> ( * // String.Format("lat: {0}\nlon: {1}\nbea: {2}\n----\n", this.latitude, this.longitude, this.bearing), * String.Format("start: {0}, destination: {1}\n----\n", start.Id, destination.Id), * "path" * );*/ // ScreenMessages.PostScreenMessage ("started caclulation " + DateTime.Now.ToString()); path = Path <Hex> .FindPath <Hex> (start, destination, distance, estimate); ScreenMessages.PostScreenMessage("Path build"); }
public void SetToActive() { if (this.vessel.targetObject == null || this.vessel.situation != Vessel.Situations.LANDED) { return; } Vessel targetVessel = this.vessel.targetObject.GetVessel(); if (targetVessel == null) { ScreenMessages.PostScreenMessage("Target some suitable vessel first!"); return; } if (targetVessel.mainBody == this.vessel.mainBody && targetVessel.situation == Vessel.Situations.LANDED) { Deactivate(); this.distanceToTarget = GeoUtils.GetDistance( this.vessel.latitude, this.vessel.longitude, targetVessel.latitude, targetVessel.longitude, this.vessel.mainBody.Radius ); double bearing = GeoUtils.InitialBearing(this.vessel.latitude, this.vessel.longitude, targetVessel.latitude, targetVessel.longitude); // We don't want to spawn inside vessel if (distanceToTarget == 0) { return; } this.distanceToTarget -= 200; double[] newCoordinates = GeoUtils.GetLatitudeLongitude(this.vessel.latitude, this.vessel.longitude, bearing, distanceToTarget, this.vessel.mainBody.Radius); this.targetLatitude = newCoordinates[0]; this.targetLongitude = newCoordinates[1]; this.distanceTravelled = 0; FindPath(); } else { ScreenMessages.PostScreenMessage("Your target is out there somewhere, this won't work!"); } }
private double Estimate(Hex hex) { return(GeoUtils.GetDistance(hex.Latitude, hex.Longitude, targetLatitude, targetLongitude, mainBody.Radius)); }