예제 #1
0
 public void UpdateCore()
 {
     core.debug = debug;
     core.SetTarget(tgtLatitude, tgtLongitude, tgtAlt);
     // Set Angle - of - Attack from gains
     core.reentryBurnMaxAoA = maxSteerAngle * (core.reentryBurnSteerKp / maxReentryGain);
     core.aeroDescentMaxAoA = maxSteerAngle * (core.aeroDescentSteerKp / maxAeroDescentGain);
     core.landingBurnMaxAoA = maxSteerAngle * (core.landingBurnSteerKp / maxLandingBurnGain);
     // Other
     core.touchdownMargin         = touchdownMargin;
     core.touchdownSpeed          = (float)touchdownSpeed;
     core.deployLandingGear       = deployLandingGear;
     core.deployLandingGearHeight = deployLandingGearHeight;
     core.Changed();
     Targets.RedrawTarget(FlightGlobals.ActiveVessel.mainBody, tgtLatitude, tgtLongitude, tgtAlt);
 }
예제 #2
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();
            }
        }