Exemplo n.º 1
0
        // Core changed - update window
        public void UpdateFromCore()
        {
            reentryBurnAlt         = (int)core.reentryBurnAlt;
            reentryBurnTargetSpeed = (int)core.reentryBurnTargetSpeed;
            reentryBurnAlt         = (int)core.reentryBurnAlt;
            reentryBurnTargetSpeed = (int)core.reentryBurnTargetSpeed;
            tgtLatitude            = core.tgtLatitude;
            tgtLongitude           = core.tgtLongitude;
            tgtAlt = (int)core.tgtAlt;
            // This is bit-field
            numLandingBurnEngines   = core.landingBurnEngines;
            igniteDelay             = (int)core.igniteDelay;
            noSteerHeight           = (int)core.noSteerHeight;
            deployLandingGear       = core.deployLandingGear;
            deployLandingGearHeight = (int)core.deployLandingGearHeight;
            Targets.RedrawTarget(FlightGlobals.ActiveVessel.mainBody, tgtLatitude, tgtLongitude, tgtAlt);

            // Apply limits
            core.reentryBurnSteerKp = Mathf.Clamp(core.reentryBurnSteerKp, 0, maxReentryGain);
            core.aeroDescentSteerKp = Mathf.Clamp(core.aeroDescentSteerKp, 0, maxAeroDescentGain);
            core.landingBurnSteerKp = Mathf.Clamp(core.landingBurnSteerKp, 0, maxLandingBurnGain);

            // Set MaxAoA from core - overriden
            core.reentryBurnMaxAoA = maxSteerAngle * (core.reentryBurnSteerKp / maxReentryGain);
            core.aeroDescentMaxAoA = maxSteerAngle * (core.aeroDescentSteerKp / maxAeroDescentGain);
            core.landingBurnMaxAoA = maxSteerAngle * (core.landingBurnSteerKp / maxLandingBurnGain);
        }
Exemplo n.º 2
0
        void OnPickingPositionTarget()
        {
            if (GuiUtils.MouseIsOverWindow(windowRect))
            {
                return;
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                // Previous position
                Targets.RedrawTarget(FlightGlobals.ActiveVessel.mainBody, tgtLatitude, tgtLongitude, tgtAlt);
                pickingPositionTarget = false;
            }
            RaycastHit hit;
            Vessel     vessel = FlightGlobals.ActiveVessel;
            bool       isHit  = false;

            if (!MapView.MapIsEnabled)
            {
                if (GuiUtils.GetMouseHit(vessel.mainBody, windowRect, MapView.MapIsEnabled, out hit))
                {
                    isHit = true;
                    // Moved or picked
                    vessel.mainBody.GetLatLonAlt(hit.point, out pickLat, out pickLon, out pickAlt);
                }
            }
            if (!isHit)
            {
                if (GuiUtils.GetBodyRayIntersect(vessel.mainBody, MapView.MapIsEnabled, out pickLat, out pickLon, out pickAlt))
                {
                    isHit = true;
                }
            }


            if (isHit)
            {
                Targets.RedrawTarget(vessel.mainBody, pickLat, pickLon, pickAlt);
                if ((Input.GetMouseButton(0)) && (!GuiUtils.MouseIsOverWindow(windowRect))) // Picked
                {
                    // Update GUI
                    tgtLatitude           = pickLat;
                    tgtLongitude          = pickLon;
                    tgtAlt                = (int)pickAlt;
                    pickingPositionTarget = false;
                    core.SetTarget(pickLat, pickLon, pickAlt);
                    core.Changed();
                }
            }
        }
Exemplo n.º 3
0
        void SetTargetHere()
        {
            Vessel vessel = FlightGlobals.ActiveVessel;

            if (vessel)
            {
                FlightGlobals.ActiveVessel.mainBody.GetLatLonAlt(vessel.GetWorldPos3D(), out double pickLat, out double pickLon, out double pickAlt);
                double lowestY = KSPUtils.FindLowestPointOnVessel(FlightGlobals.ActiveVessel);
                tgtLatitude  = pickLat;
                tgtLongitude = pickLon;
                tgtAlt       = (int)(pickAlt + lowestY);
                core.SetTarget(tgtLatitude, tgtLongitude, tgtAlt);
                core.Changed();
                GuiUtils.ScreenMessage(Localizer.Format("#BoosterGuidance_TargetSetToVessel"));
            }
        }
Exemplo n.º 4
0
        void WindowFunction(int windowID)
        {
            BoosterGuidanceCore core = CheckCore(FlightGlobals.ActiveVessel);

            if (core == null)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("No BoosterGuidance Core");
                GUILayout.EndHorizontal();
                return;
            }

            OnUpdate();
            SetEnabledColors(true);
            // Close button
            if (GUI.Button(new Rect(windowRect.width - 18, 2, 16, 16), ""))
            {
                Hide();
                return;
            }

            // Check for target being set
            if (core.vessel.targetObject != lastVesselTarget)
            {
                if (core.vessel.targetObject != null)
                {
                    Vessel target = core.vessel.targetObject.GetVessel();
                    tgtLatitude  = target.latitude;
                    tgtLongitude = target.longitude;
                    tgtAlt       = (int)target.altitude;
                    UpdateCore();
                    string msg = String.Format(Localizer.Format("#BoosterGuidance_TargetSetToX"), target.name);
                    GuiUtils.ScreenMessage(msg);
                }
                lastVesselTarget = core.vessel.targetObject;
            }

            // Check for navigation target
            NavWaypoint nav = NavWaypoint.fetch;

            if (nav.IsActive)
            {
                // Does current nav position differ from last one used? A hack because
                // a can't see a way to check if the nav waypoint has changed
                // Doing it this way means lat and lon in window can be edited without them
                // getting locked to the nav waypoint
                if ((lastNavLat != nav.Latitude) || (lastNavLon != nav.Longitude))
                {
                    Coordinates pos = new Coordinates(nav.Latitude, nav.Longitude);
                    Debug.Log("[BoosterGuidance] Target set to nav location " + pos.ToStringDMS());
                    tgtLatitude  = nav.Latitude;
                    tgtLongitude = nav.Longitude;
                    lastNavLat   = nav.Latitude;
                    lastNavLon   = nav.Longitude;
                    // This is VERY unreliable
                    //tgtAlt = (int)nav.Altitude;
                    tgtAlt = (int)FlightGlobals.ActiveVessel.mainBody.TerrainAltitude(tgtLatitude, tgtLongitude);
                    core.SetTarget(tgtLatitude, tgtLongitude, tgtAlt);
                    string msg = String.Format(Localizer.Format("#BoosterGuidance_TargetSetToX"), pos.ToStringDMS());
                    GuiUtils.ScreenMessage(msg);
                    UpdateCore();
                }
            }
            else
            {
                lastNavLat = 0;
                lastNavLon = 0;
            }

            // Check for unloaded vessels
            foreach (var controller in BoosterGuidanceCore.controllers)
            {
                if (!controller.vessel.loaded)
                {
                    GuiUtils.ScreenMessage("Guidance disabled for " + controller.vessel.name + " as out of physics range");
                    DisableGuidance();
                }
            }


            tab = GUILayout.Toolbar(tab, new string[] { Localizer.Format("#BoosterGuidance_Main"), Localizer.Format("Advanced") });
            bool changed = false;

            switch (tab)
            {
            case 0:
                changed = MainTab(windowID);
                break;

            case 1:
                changed = AdvancedTab(windowID);
                break;
            }

            if (changed)
            {
                UpdateCore();
            }
        }