Exemplo n.º 1
0
        /// <summary>
        /// Adds the waypoint to the custom waypoint list.
        /// </summary>
        /// <param name="waypoint">The waypoint to add</param>
        public static void AddWaypoint(Waypoint waypoint)
        {
            waypoint.isOnSurface = true;
            waypoint.isNavigatable = true;
            waypoint.index = Instance.nextIndex++;

            Instance.waypoints.Add(waypoint);
            WaypointManager.AddWaypoint(waypoint);
        }
Exemplo n.º 2
0
		internal SCANwaypoint(Waypoint p)
		{
			way = p;
			band = FlightBand.NONE;
			root = p.contractReference;
			param = null;
			name = way.name;
			longitude = SCANUtil.fixLonShift(way.longitude);
			latitude = SCANUtil.fixLatShift(way.latitude);
			landingTarget = false;
		}
Exemplo n.º 3
0
        public WaypointValue(Waypoint wayPoint, SharedObjects shared)
        {
            WrappedWaypoint = wayPoint;
            Shared = shared;
            InitializeSuffixes();

            // greekMap is static, so whichever waypoint instance's constructor happens to
            // get called first will make it, and from then on other waypoints don't need to
            // keep re-initializing it:
            if (greekMap == null)
                InitializeGreekMap();
        }
Exemplo n.º 4
0
        //Add a waypoint and handle attaching automatically.
        public static void AddWaypoint(Waypoint wp)
        {
            WaypointManager me = MapView.MapCamera.gameObject.GetComponent<WaypointManager>();

            if (me)
                me.waypoints.Add(wp);
            else
            {
                me = MapView.MapCamera.gameObject.AddComponent<WaypointManager>();
                me.waypoints.Add(wp);
            }
        }
Exemplo n.º 5
0
        //Remove a waypoint and handle detaching automatically.
        public static void RemoveWaypoint(Waypoint wp)
        {
            WaypointManager me = MapView.MapCamera.gameObject.GetComponent<WaypointManager>();

            if (me)
            {
                me.waypoints.Remove(wp);

                if (me.waypoints.Count == 0)
                    Destroy(me);
            }
        }
        /// <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++;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds the given waypoint to the list of waypoints
        /// </summary>
        /// <param name="waypoint">The waypoint to add</param>
        public static void AddWaypoint(Waypoint waypoint)
        {
            if (ContractSystem.Instance == null)
            {
                waypoints.Add(waypoint);

                // Need to check if we need to activate the FinePrint WaypointManager
                WaypointManager component = MapView.MapCamera.gameObject.GetComponent<WaypointManager>();
                if (component == null)
                {
                    MapView.MapCamera.gameObject.AddComponent<WaypointManager>();
                }
            }
            else
            {
                // First remove it to prevent duplicates
                FinePrint.WaypointManager.AddWaypoint(waypoint);
            }
        }
        /// <summary>
        /// Gets the  distance in meters from the activeVessel to the given waypoint.
        /// </summary>
        /// <param name="wpd">Activated waypoint</param>
        /// <returns>Distance in meters</returns>
        public static double GetDistanceToWaypoint(Vessel vessel, Waypoint waypoint, ref double height)
        {
            CelestialBody celestialBody = vessel.mainBody;

            // Figure out the terrain height
            if (height == double.MaxValue)
            {
                double latRads = Math.PI / 180.0 * waypoint.latitude;
                double lonRads = Math.PI / 180.0 * waypoint.longitude;
                Vector3d radialVector = new Vector3d(Math.Cos(latRads) * Math.Cos(lonRads), Math.Sin(latRads), Math.Cos(latRads) * Math.Sin(lonRads));
                height = celestialBody.pqsController.GetSurfaceHeight(radialVector) - celestialBody.pqsController.radius;

                // Clamp to zero for ocean worlds
                if (celestialBody.ocean)
                {
                    height = Math.Max(height, 0.0);
                }
            }

            // Use the haversine formula to calculate great circle distance.
            double sin1 = Math.Sin(Math.PI / 180.0 * (vessel.latitude - waypoint.latitude) / 2);
            double sin2 = Math.Sin(Math.PI / 180.0 * (vessel.longitude - waypoint.longitude) / 2);
            double cos1 = Math.Cos(Math.PI / 180.0 * waypoint.latitude);
            double cos2 = Math.Cos(Math.PI / 180.0 * vessel.latitude);

            double lateralDist = 2 * (celestialBody.Radius + height + waypoint.altitude) *
                Math.Asin(Math.Sqrt(sin1 * sin1 + cos1 * cos2 * sin2 * sin2));
            double heightDist = Math.Abs(waypoint.altitude + height - vessel.altitude);

            if (heightDist <= lateralDist / 2.0)
            {
                return lateralDist;
            }
            else
            {
                // Get the ratio to use in our formula
                double x = (heightDist - lateralDist / 2.0) / lateralDist;

                // x / (x + 1) starts at 0 when x = 0, and increases to 1
                return (x / (x + 1)) * heightDist + lateralDist;
            }
        }
		public parameterContainer(contractContainer Root, ContractParameter cP, int Level)
		{
			root = Root;
			cParam = cP;

			try
			{
				title = cParam.Title;
			}
			catch (Exception e)
			{
				Debug.LogError("[Contract Parser] Contract Parameter Title not set, using type name...\n" + e);
				title = cParam.GetType().Name;
			}

			try
			{
				notes = cParam.Notes;
			}
			catch (Exception e)
			{
				Debug.LogError("[Contract Parser] Contract Parameter Notes not set, blank notes used...\n" + e);
				notes = "";
			}

			level = Level;	
			paramRewards();
			paramPenalties();

			waypoint = checkForWaypoint();

			customNotes = setCustomNotes();

			if (level < 4)
			{
				for (int i = 0; i < cParam.ParameterCount; i++)
				{
					ContractParameter param = cParam.GetParameter(i);
					addSubParam(param, level + 1);
				}
			}
		}
        public void UpdateWaypoint()
        {
            // Get the vessel to use
            Vessel vessel = ContractVesselTracker.Instance.GetAssociatedVessel(vesselKey);
            if (vessel == null)
            {
                if (waypoint != null)
                {
                    WaypointManager.RemoveWaypoint(waypoint);
                    waypoint = null;
                }

                return;
            }

            if (waypoint == null)
            {
                waypoint = new Waypoint();
                waypoint.seed = contract.MissionSeed;
                waypoint.index = 0;
                waypoint.landLocked = false;
                waypoint.id = "vessel";
                waypoint.size = new Vector2(32f, 32f);
                waypoint.isNavigatable = false;
                waypoint.enableTooltip = false;
                waypoint.enableMarker = false;
                waypoint.contractReference = contract;
                WaypointManager.AddWaypoint(waypoint);
            }

            waypoint.name = vessel.loaded ? vessel.vesselName : vessel.protoVessel.vesselName;
            waypoint.celestialName = vessel.mainBody.GetName();
            waypoint.latitude = vessel.loaded ? vessel.latitude : vessel.protoVessel.latitude;
            waypoint.longitude = vessel.loaded ? vessel.longitude : vessel.protoVessel.longitude;
            waypoint.altitude = vessel.loaded ? vessel.altitude : vessel.protoVessel.altitude;

            Orbit orbit = vessel.loaded ? vessel.orbit : vessel.protoVessel.orbitSnapShot.Load();
            waypoint.SetFadeRange(orbit.ApR);
            waypoint.orbitPosition = orbit.getPositionAtUT(Planetarium.GetUniversalTime());
            waypoint.isOnSurface = vessel.LandedOrSplashed;
        }
        public void HandleClick(WaypointData wpd)
        {
            // Translate to screen position
            Vector3d localSpacePoint = wpd.celestialBody.GetWorldSurfacePosition(wpd.waypoint.latitude, wpd.waypoint.longitude, wpd.waypoint.altitude);
            Vector3d scaledSpacePoint = ScaledSpace.LocalToScaledSpace(localSpacePoint);
            Vector3 screenPos = MapView.MapCamera.camera.WorldToScreenPoint(new Vector3((float)scaledSpacePoint.x, (float)scaledSpacePoint.y, (float)scaledSpacePoint.z));

            Rect markerRect = new Rect(screenPos.x - 15f, (float)Screen.height - screenPos.y - 45.0f, 30f, 45f);

            if (markerRect.Contains(Event.current.mousePosition))
            {
                selectedWaypoint = wpd.waypoint;
                windowPos = new Rect(markerRect.xMin - 97, markerRect.yMax + 12, 224, 60);
                waypointName = wpd.waypoint.name + (wpd.waypoint.isClustered ? (" " + StringUtilities.IntegerToGreek(wpd.waypoint.index)) : "");
                newClick = false;
            }
            else if (newClick)
            {
                selectedWaypoint = null;
            }
        }
Exemplo n.º 12
0
        static public void setupNavPoint(Waypoint wp)
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                linkNavPoint();

                if (navWaypoint != null)
                {
                    CelestialBody body = Planetarium.fetch.Home;

                    foreach (CelestialBody cb in FlightGlobals.Bodies)
                    {
                        if (cb.GetName() == wp.celestialName)
                            body = cb;
                    }

                    HSBColor brighterRandom = HSBColor.FromColor(RandomColor(wp.seed));
                    brighterRandom.b = 1.0f;
                    navWaypoint.SetupNavWaypoint(body, wp.latitude, wp.longitude, wp.altitude, wp.waypointType, brighterRandom.ToColor());
                    trackWP = wp;
                }
            }
        }
        private void AddWayPoint(Waypoint waypoint)
        {
            // No contract, no waypoint
            if (waypoint.contractReference == null)
            {
                return;
            }

            // Always surface and navigatable
            waypoint.isOnSurface = true;
            waypoint.isNavigatable = true;

            // Show only active waypoints in flight, but show offered as well in the tracking station
            if (HighLogic.LoadedScene == GameScenes.FLIGHT && contract.ContractState == Contract.State.Active ||
                HighLogic.LoadedScene == GameScenes.TRACKSTATION &&
                (contract.ContractState == Contract.State.Offered || contract.ContractState == Contract.State.Active))
            {
                WaypointManager.AddWaypoint(waypoint);
            }
        }
        private void NavigationWindow(int windowID)
        {
            if (selectedWaypoint == null)
            {
                return;
            }

            GUILayout.BeginVertical();
            if (!Util.IsNavPoint(selectedWaypoint))
            {
                if (GUILayout.Button("Activate Navigation", HighLogic.Skin.button, GUILayout.ExpandWidth(true)))
                {
                    FinePrint.WaypointManager.setupNavPoint(selectedWaypoint);
                    FinePrint.WaypointManager.activateNavPoint();
                    selectedWaypoint = null;
                }
            }
            else
            {
                if (GUILayout.Button("Deactivate Navigation", HighLogic.Skin.button, GUILayout.ExpandWidth(true)))
                {
                    FinePrint.WaypointManager.clearNavPoint();
                    selectedWaypoint = null;
                }

            }
            if (CustomWaypoints.Instance.IsCustom(selectedWaypoint))
            {
                if (GUILayout.Button("Edit Custom Waypoint", HighLogic.Skin.button, GUILayout.ExpandWidth(true)))
                {
                    CustomWaypointGUI.EditWaypoint(selectedWaypoint);
                    selectedWaypoint = null;
                }
                if (GUILayout.Button("Delete Custom Waypoint", HighLogic.Skin.button, GUILayout.ExpandWidth(true)))
                {
                    CustomWaypointGUI.DeleteWaypoint(selectedWaypoint);
                    selectedWaypoint = null;
                }
            }
            GUILayout.EndVertical();
        }
        protected void DrawWaypoint(WaypointData wpd)
        {
            // Not our planet
            CelestialBody celestialBody = FlightGlobals.currentMainBody;
            if (celestialBody == null || wpd.waypoint.celestialName != celestialBody.name)
            {
                return;
            }

            // Check if the waypoint should be visible
            if (!wpd.waypoint.visible)
            {
                return;
            }

            // Figure out waypoint label
            string label = wpd.waypoint.name + (wpd.waypoint.isClustered ? (" " + StringUtilities.IntegerToGreek(wpd.waypoint.index)) : "");

            // Set the alpha and do a nice fade
            wpd.SetAlpha();

            // Decide whether to actually draw the waypoint
            if (FlightGlobals.ActiveVessel != null)
            {
                // Figure out the distance to the waypoint
                Vessel v = FlightGlobals.ActiveVessel;

                // Only change alpha if the waypoint isn't the nav point
                if (!Util.IsNavPoint(wpd.waypoint))
                {
                    // Get the distance to the waypoint at the current speed
                    double speed = v.srfSpeed < MIN_SPEED ? MIN_SPEED : v.srfSpeed;
                    double directTime = Util.GetStraightDistance(wpd) / speed;

                    // More than two minutes away
                    if (directTime > MIN_TIME || Config.waypointDisplay != Config.WaypointDisplay.ALL)
                    {
                        return;
                    }
                    else if (directTime >= MIN_TIME - FADE_TIME)
                    {
                        wpd.currentAlpha = (float)((MIN_TIME - directTime) / FADE_TIME) * Config.opacity;
                    }
                }
                // Draw the distance information to the nav point
                else
                {
                    // Draw the distance to waypoint text
                    if (Event.current.type == EventType.Repaint)
                    {
                        if (asb == null)
                        {
                            asb = UnityEngine.Object.FindObjectOfType<AltimeterSliderButtons>();
                        }

                        if (referenceUISize != ScreenSafeUI.VerticalRatio || !referenceSet)
                        {
                            referencePos = ScreenSafeUI.referenceCam.ViewportToScreenPoint(asb.transform.position).y;
                            referenceUISize = ScreenSafeUI.VerticalRatio;

                            // Need two consistent numbers in a row to set the reference
                            if (lastPos == referencePos)
                            {
                                referenceSet = true;
                            }
                            else
                            {
                                lastPos = referencePos;
                            }
                        }

                        float ybase = (referencePos - ScreenSafeUI.referenceCam.ViewportToScreenPoint(asb.transform.position).y + Screen.height / 11.67f) / ScreenSafeUI.VerticalRatio;

                        string timeToWP = GetTimeToWaypoint(wpd);
                        if (Config.hudDistance)
                        {
                            GUI.Label(new Rect((float)Screen.width / 2.0f - 188f, ybase, 240f, 20f), "Distance to " + label + ":", nameStyle);
                            GUI.Label(new Rect((float)Screen.width / 2.0f + 60f, ybase, 120f, 20f),
                                v.state != Vessel.State.DEAD ? Util.PrintDistance(wpd) : "N/A", valueStyle);
                            ybase += 18f;
                        }

                        if (timeToWP != null && Config.hudTime)
                        {
                            GUI.Label(new Rect((float)Screen.width / 2.0f - 188f, ybase, 240f, 20f), "ETA to " + label + ":", nameStyle);
                            GUI.Label(new Rect((float)Screen.width / 2.0f + 60f, ybase, 120f, 20f),
                                v.state != Vessel.State.DEAD ? timeToWP : "N/A", valueStyle);
                            ybase += 18f;
                        }

                        if (Config.hudHeading)
                        {
                            GUI.Label(new Rect((float)Screen.width / 2.0f - 188f, ybase, 240f, 20f), "Heading to " + label + ":", nameStyle);
                            GUI.Label(new Rect((float)Screen.width / 2.0f + 60f, ybase, 120f, 20f),
                                v.state != Vessel.State.DEAD ? wpd.heading.ToString("N1") : "N/A", valueStyle);
                            ybase += 18f;
                        }

                        if (Config.hudAngle && v.mainBody == wpd.celestialBody)
                        {
                            double distance = Util.GetLateralDistance(wpd);
                            double heightDist = wpd.waypoint.altitude + wpd.waypoint.height - v.altitude;
                            double angle = Math.Atan2(heightDist, distance) * 180.0 / Math.PI;

                            GUI.Label(new Rect((float)Screen.width / 2.0f - 188f, ybase, 240f, 20f), "Angle to " + label + ":", nameStyle);
                            GUI.Label(new Rect((float)Screen.width / 2.0f + 60f, ybase, 120f, 20f),
                                v.state != Vessel.State.DEAD ? angle.ToString("N2") : "N/A", valueStyle);
                            ybase += 18f;

                            if (v.srfSpeed >= 0.1)
                            {
                                double velAngle = 90 - Math.Acos(Vector3d.Dot(v.srf_velocity.normalized, v.upAxis)) * 180.0 / Math.PI;

                                GUI.Label(new Rect((float)Screen.width / 2.0f - 188f, ybase, 240f, 20f), "Velocity pitch angle:", nameStyle);
                                GUI.Label(new Rect((float)Screen.width / 2.0f + 60f, ybase, 120f, 20f),
                                    v.state != Vessel.State.DEAD ? velAngle.ToString("N2") : "N/A", valueStyle);
                                ybase += 18f;
                            }
                        }
                        if(Config.hudCoordinates&&v.mainBody==wpd.celestialBody)
                        {
                            ybase += 9;
                            GUI.Label(new Rect((float)Screen.width / 2.0f - 188f, ybase, 240f, 38f), "Coordinates of " + label + ":", nameStyle);
                            GUI.Label(new Rect((float)Screen.width / 2.0f + 60f, ybase, 120f, 38f),
                                v.state != Vessel.State.DEAD ? string.Format("{0}\r\n{1}", Util.DecimalDegreesToDMS(wpd.waypoint.latitude,true), Util.DecimalDegreesToDMS(wpd.waypoint.longitude,false)) : "N/A", valueStyle);
                            ybase += 18f;
                        }
                    }
                }
            }

            // Don't draw the waypoint
            if (Config.waypointDisplay == Config.WaypointDisplay.NONE)
            {
                return;
            }

            // Translate to scaled space
            Vector3d localSpacePoint = celestialBody.GetWorldSurfacePosition(wpd.waypoint.latitude, wpd.waypoint.longitude, wpd.waypoint.height + wpd.waypoint.altitude);
            Vector3d scaledSpacePoint = ScaledSpace.LocalToScaledSpace(localSpacePoint);

            // Don't draw if it's behind the camera
            if (Vector3d.Dot(MapView.MapCamera.camera.transform.forward, scaledSpacePoint.normalized) < 0.0)
            {
                return;
            }

            // Translate to screen position
            Vector3 screenPos = MapView.MapCamera.camera.WorldToScreenPoint(new Vector3((float)scaledSpacePoint.x, (float)scaledSpacePoint.y, (float)scaledSpacePoint.z));

            // Draw the marker at half-resolution (30 x 45) - that seems to match the one in the map view
            Rect markerRect = new Rect(screenPos.x - 15f, (float)Screen.height - screenPos.y - 45.0f, 30f, 45f);

            // Set the window position relative to the selected waypoint
            if (selectedWaypoint == wpd.waypoint)
            {
                windowPos = new Rect(markerRect.xMin - 97, markerRect.yMax + 12, 224, 60);
            }

            // Handling clicking on the waypoint
            if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
            {
                if (markerRect.Contains(Event.current.mousePosition))
                {
                    selectedWaypoint = wpd.waypoint;
                    windowPos = new Rect(markerRect.xMin - 97, markerRect.yMax + 12, 224, 60);
                    waypointName = label;
                    newClick = false;
                }
                else if (newClick)
                {
                    selectedWaypoint = null;
                }
            }

            // Only handle on repaint events
            if (Event.current.type == EventType.Repaint)
            {
                // Half-res for the icon too (16 x 16)
                Rect iconRect = new Rect(screenPos.x - 8f, (float)Screen.height - screenPos.y - 39.0f, 16f, 16f);

                // Draw the marker
                Graphics.DrawTexture(markerRect, GameDatabase.Instance.GetTexture("Squad/Contracts/Icons/marker", false), new Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0, new Color(0.5f, 0.5f, 0.5f, 0.5f * (wpd.currentAlpha - 0.3f) / 0.7f));

                // Draw the icon, but support blinking
                if (!Util.IsNavPoint(wpd.waypoint) || !FinePrint.WaypointManager.navWaypoint.blinking || (int)((Time.fixedTime - (int)Time.fixedTime) * 4) % 2 == 0)
                {
                    Graphics.DrawTexture(iconRect, ContractDefs.textures[wpd.waypoint.id], new Rect(0.0f, 0.0f, 1f, 1f), 0, 0, 0, 0, SystemUtilities.RandomColor(wpd.waypoint.seed, wpd.currentAlpha));
                }

                // Hint text!
                if (iconRect.Contains(Event.current.mousePosition))
                {
                    // Add agency to label
                    if (wpd.waypoint.contractReference != null)
                    {
                        label += "\n" + wpd.waypoint.contractReference.Agent.Name;
                    }
                    float width = 240f;
                    float height = hintTextStyle.CalcHeight(new GUIContent(label), width);
                    float yoffset = height + 48.0f;
                    GUI.Box(new Rect(screenPos.x - width/2.0f, (float)Screen.height - screenPos.y - yoffset, width, height), label, hintTextStyle);
                }
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Checks if the given waypoint is one of our custom waypoints.
        /// </summary>
        /// <param name="waypoint">The waypoint to check.</param>
        /// <returns>True if the waypoint is a custom waypoint.</returns>
        public bool IsCustom(Waypoint waypoint)
        {
            if (waypoint == null)
            {
                return false;
            }

            return waypoint.contractReference == null && waypoints.Contains(waypoint);
        }
Exemplo n.º 17
0
        public void UpdateWaypoint(Waypoint wp)
        {
            if (MapView.MapIsEnabled)
            {
                foreach (CelestialBody body in FlightGlobals.Bodies)
                {
                    if (wp.isOnSurface)
                    {
                        if (body.GetName() == wp.celestialName)
                        {
                            if (body.pqsController != null)
                            {
                                Vector3d pqsRadialVector = QuaternionD.AngleAxis(wp.longitude, Vector3d.down) * QuaternionD.AngleAxis(wp.latitude, Vector3d.forward) * Vector3d.right;
                                wp.height = body.pqsController.GetSurfaceHeight(pqsRadialVector) - body.pqsController.radius;

                                if (wp.height < 0)
                                    wp.height = 0;
                            }

                            Vector3d surfacePos = body.GetWorldSurfacePosition(wp.latitude, wp.longitude, wp.height + wp.altitude);
                            Vector3d scaledPos = ScaledSpace.LocalToScaledSpace(surfacePos);
                            wp.worldPosition = new Vector3((float)scaledPos.x, (float)scaledPos.y, (float)scaledPos.z);
                            wp.isOccluded = IsOccluded(surfacePos, body);
                        }
                    }
                    else
                    {
                        wp.worldPosition = ScaledSpace.LocalToScaledSpace(wp.orbitPosition);
                    }
                }
            }
        }
        /// <summary>
        /// Checks if the given waypoint is one of our custom waypoints.
        /// </summary>
        /// <param name="waypoint">The waypoint to check.</param>
        /// <returns>True if the waypoint is a custom waypoint.</returns>
        public bool IsCustom(Waypoint waypoint)
        {
            if (waypoint == null)
            {
                return false;
            }

            return waypoint.isCustom;
        }
 /// <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);
 }
Exemplo n.º 20
0
 public WaypointValue(Waypoint wayPoint, SharedObjects shared)
 {
     WrappedWaypoint = wayPoint;
     Shared = shared;
     InitializeSuffixes();
 }
Exemplo n.º 21
0
        static public void deactivateNavPoint(Waypoint wp)
        {
            if (HighLogic.LoadedSceneIsFlight)
            {
                linkNavPoint();

                if (navWaypoint != null)
                {
                    if (navWaypoint.latitude == wp.latitude && navWaypoint.longitude == wp.longitude && navWaypoint.altitude == wp.altitude)
                        navWaypoint.Deactivate();
                }
            }
        }
Exemplo n.º 22
0
        public float LateralDistanceToVessel(Waypoint wp)
        {
            //A version if DistanceToVessel that ignores altitude.
            if (HighLogic.LoadedSceneIsFlight)
            {
                Vessel v = FlightGlobals.ActiveVessel;

                if (v.mainBody.GetName() == wp.celestialName)
                    return Distance(v.latitude, v.longitude, v.altitude, wp.latitude, wp.longitude, v.altitude, v.mainBody);
                else
                    return float.PositiveInfinity;
            }
            else
                return float.PositiveInfinity;
        }
        private static void WindowGUI(int windowID)
        {
            GUILayout.BeginVertical();

            template.name = GUILayout.TextField(template.name);

            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            GUILayout.Label("Latitude", GUILayout.Width(68));
            GUILayout.Label("Longitude", GUILayout.Width(68));
            GUILayout.EndVertical();

            GUILayout.Space(4);

            string val;
            float floatVal;
            GUILayout.BeginVertical();
            val = GUILayout.TextField(latitude, GUILayout.Width(140));
            if (float.TryParse(val, out floatVal))
            {
                latitude = val;
                recalcAltitude = true;
            }
            val = GUILayout.TextField(longitude, GUILayout.Width(140));
            if (float.TryParse(val, out floatVal))
            {
                longitude = val;
                recalcAltitude = true;
            }

            GUILayout.EndVertical();

            GUILayout.Space(4);

            GUILayout.BeginVertical();
            if (GUILayout.Button(Util.GetContractIcon(template.id, template.seed)))
            {
                showIconPicker = !showIconPicker;

                selectedIcon = Array.IndexOf(icons, icons.Where(c => c.tooltip == template.id).First());
                selectedColor = Array.IndexOf(seeds, template.seed);
                if (selectedIcon == -1)
                {
                    selectedIcon = 0;
                }
                if (selectedColor == -1)
                {
                    selectedColor = 0;
                }
            }
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(80);
            if (GUILayout.Toggle(useTerrainHeight, new GUIContent("Use terrain height for altitude", "Automatically set the altitude to ground level.")) != useTerrainHeight)
            {
                useTerrainHeight = !useTerrainHeight;
                recalcAltitude = true;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            GUILayout.Label("Altitude", GUILayout.Width(72));
            val = GUILayout.TextField(altitude, useTerrainHeight ? disabledText : GUI.skin.textField, GUILayout.Width(140));
            if (!useTerrainHeight && float.TryParse(val, out floatVal))
            {
                altitude = val;
            }
            GUILayout.EndHorizontal();

            if (HighLogic.LoadedScene == GameScenes.FLIGHT)
            {
                if (GUILayout.Button(new GUIContent("Use Active Vessel Location", "Set the location parameters to that of the currently active vessel.")))
                {
                    latitude = FlightGlobals.ActiveVessel.latitude.ToString();
                    longitude = FlightGlobals.ActiveVessel.longitude.ToString();
                    altitude = FlightGlobals.ActiveVessel.altitude.ToString();
                    recalcAltitude = true;
                }
            }

            if (HighLogic.LoadedScene == GameScenes.FLIGHT && MapView.MapIsEnabled || HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                string label = mapLocationMode ? "Cancel Set Location" : "Set Location on Map";
                if (GUILayout.Button(new GUIContent(label, "Set the location by clicking on the map.")))
                {
                    mapLocationMode = !mapLocationMode;
                }
            }
            else
            {
                mapLocationMode = false;
            }

            GUILayout.BeginHorizontal();
            bool save = GUILayout.Button("Save");
            bool apply = GUILayout.Button("Apply");
            bool cancel = GUILayout.Button("Cancel");
            if (save || apply)
            {
                template.latitude = double.Parse(latitude);
                template.longitude = double.Parse(longitude);
                template.height = Util.WaypointHeight(template, targetBody);
                template.altitude = double.Parse(altitude) - template.height;
                if (windowMode == WindowMode.Add)
                {
                    CustomWaypoints.AddWaypoint(template);
                    selectedWaypoint = template;
                    template = new Waypoint();
                }
                else
                {
                    selectedWaypoint.id = template.id;
                    selectedWaypoint.name = template.name;
                    selectedWaypoint.latitude = template.latitude;
                    selectedWaypoint.longitude = template.longitude;
                    selectedWaypoint.altitude = template.altitude;
                    selectedWaypoint.height = template.height;
                    selectedWaypoint.seed = template.seed;
                }
            }
            if (save || cancel)
            {
                windowMode = WindowMode.None;
            }
            else if (apply)
            {
                EditWaypoint(selectedWaypoint);
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            GUI.DragWindow();

            if (useTerrainHeight && recalcAltitude)
            {
                recalcAltitude = false;
                altitude = Util.TerrainHeight(double.Parse(latitude), double.Parse(longitude), targetBody).ToString();
            }

            WaypointManager.Instance.SetToolTip(windowID - typeof(WaypointManager).FullName.GetHashCode());
        }
Exemplo n.º 24
0
        /// <summary>
        /// Checks if the given waypoint is the nav waypoint.
        /// </summary>
        /// <param name="waypoint"></param>
        /// <returns></returns>
        public static bool IsNavPoint(Waypoint waypoint)
        {
            NavWaypoint navPoint = FinePrint.WaypointManager.navWaypoint;
            if (navPoint == null || !FinePrint.WaypointManager.navIsActive())
            {
                return false;
            }

            return navPoint.latitude == waypoint.latitude && navPoint.longitude == waypoint.longitude;
        }
Exemplo n.º 25
0
 /// <summary>
 /// Removes the given waypoing from the list of waypoints
 /// </summary>
 /// <param name="waypoint">The waypoint to remove</param>
 public static void RemoveWaypoint(Waypoint waypoint)
 {
     if (FinePrint.WaypointManager.Instance() == null)
     {
         waypoints.Remove(waypoint);
     }
     else
     {
         FinePrint.WaypointManager.RemoveWaypoint(waypoint);
     }
 }
Exemplo n.º 26
0
 /// <summary>
 /// Removes the given waypoint from the custom list.
 /// </summary>
 /// <param name="waypoint">The waypoint to remove</param>
 public static void RemoveWaypoint(Waypoint waypoint)
 {
     WaypointManager.RemoveWaypoint(waypoint);
     if (!Instance.waypoints.Remove(waypoint))
     {
         Debug.LogWarning("Couldn't remove custom waypoint '" + waypoint.name + "' - No such waypoint!");
     }
     else
     {
         if (waypoint.index == Instance.nextIndex - 1)
         {
             Instance.nextIndex--;
         }
     }
 }
Exemplo n.º 27
0
        /// <summary>
        /// Checks if the given waypoint is the nav waypoint.
        /// </summary>
        /// <param name="waypoint"></param>
        /// <returns></returns>
        public static bool IsNavPoint(Waypoint waypoint)
        {
            NavWaypoint navPoint = NavWaypoint.fetch;
            if (navPoint == null || !NavWaypoint.fetch.IsActive)
            {
                return false;
            }

            return navPoint.Latitude == waypoint.latitude && navPoint.Longitude == waypoint.longitude;
        }
Exemplo n.º 28
0
        public override void OnLoad(ConfigNode node)
        {
            if (!customLoad)
            {
                base.OnLoad(node);
            }

            foreach (ConfigNode child in node.GetNodes("WAYPOINT"))
            {
                Waypoint waypoint = new Waypoint();
                waypoint.name = child.GetValue("name");
                waypoint.celestialName = child.GetValue("celestialName");
                waypoint.id = child.GetValue("icon");
                waypoint.latitude = Convert.ToDouble(child.GetValue("latitude"));
                waypoint.longitude = Convert.ToDouble(child.GetValue("longitude"));
                waypoint.altitude = Convert.ToDouble(child.GetValue("altitude"));
                waypoint.index = Convert.ToInt32(child.GetValue("index"));
                waypoint.seed = Convert.ToInt32(child.GetValue("seed"));
                waypoint.isOnSurface = true;
                waypoint.isNavigatable = true;

                // For a custom load, check for duplicates
                if (customLoad)
                {
                    foreach (Waypoint wp in waypoints.ToList())
                    {
                        if (wp.celestialName == waypoint.celestialName &&
                            Math.Abs(wp.latitude - waypoint.latitude) < 0.000001 &&
                            Math.Abs(wp.longitude - waypoint.longitude) < 0.000001 &&
                            Math.Abs(wp.altitude - waypoint.altitude) < 0.1)
                        {
                            waypoints.Remove(wp);
                            WaypointManager.RemoveWaypoint(wp);
                        }
                    }
                }

                waypoints.Add(waypoint);
                WaypointManager.AddWaypoint(waypoint);

                nextIndex = Math.Max(nextIndex, waypoint.index + 1);
            }
        }
Exemplo n.º 29
0
 public static double WaypointHeight(Waypoint w, CelestialBody body)
 {
     return TerrainHeight(w.latitude, w.longitude, body);
 }
Exemplo n.º 30
0
		public void RandomizeNearWaypoint(Waypoint center, double searchRadius, bool waterAllowed = true)
		{
			RandomizeNear(center.latitude, center.longitude, center.celestialName, searchRadius, waterAllowed);
		}
Exemplo n.º 31
0
 public void RandomizeNearWaypoint(Waypoint center, double searchRadius, bool waterAllowed = true)
 {
     RandomizeNear(center.latitude, center.longitude, center.celestialName, searchRadius, waterAllowed);
 }