예제 #1
0
        public static void OpenRTGroundStation(StaticObject obj)
        {
            bool bRTLoaded = AssemblyLoader.loadedAssemblies.Any(a => a.name == "RemoteTech");

            if (!bRTLoaded)
            {
                return;
            }

            string sTSName;
            string sDLat;
            string sDLon;
            string sHeight;

            if ((string)obj.getSetting("FacilityType") == "TrackingStation")
            {
                Vector3       vPos         = (Vector3)obj.getSetting("RadialPosition");
                string        sPos         = vPos.ToString();
                CelestialBody CelBody      = (CelestialBody)obj.getSetting("CelestialBody");
                var           objectpos    = CelBody.transform.InverseTransformPoint(obj.gameObject.transform.position);
                var           dObjectLat   = NavUtils.GetLatitude(objectpos);
                var           dObjectLon   = NavUtils.GetLongitude(objectpos);
                double        disObjectLat = dObjectLat * 180 / Math.PI;
                double        disObjectLon = dObjectLon * 180 / Math.PI;

                sDLat   = disObjectLat.ToString("#0.00");
                sDLon   = disObjectLon.ToString("#0.00");
                sTSName = "Stn Lt " + sDLat + " Ln " + sDLon;
                sHeight = obj.getSetting("RadiusOffset").ToString();

                float  fHeight = (float)obj.getSetting("RadiusOffset");
                double dHeight = (double)fHeight;
                int    iBody   = 1;

                string sGuid = ConstructGuidString(obj);

                Debug.Log("KK: Attempting adding RT GroundStation " + sGuid);
                RemoteTech.API.API.AddGroundStation(sGuid, sTSName, disObjectLat, disObjectLon, dHeight, iBody);

                Debug.Log("KK: Added RT GroundStation " + sGuid);
                KerbalKonstructs.Utilities.PersistenceUtils.saveStaticPersistence(obj);
                RemoteTech.API.API.ReloadRTSettingsNow();
                Debug.Log("KK: Saved station object");
            }
        }
        public static void createLaunchSite(StaticObject obj)
        {
            if (obj.settings.ContainsKey("LaunchSiteName") && obj.gameObject.transform.Find((string)obj.getSetting("LaunchPadTransform")) != null)
            {
                // Debug.Log("KK: Creating launch site " + obj.getSetting("LaunchSiteName"));
                obj.gameObject.transform.name = (string)obj.getSetting("LaunchSiteName");
                obj.gameObject.name           = (string)obj.getSetting("LaunchSiteName");

                // Debug.Log("KK: Get CelBody");
                CelestialBody CelBody = (CelestialBody)obj.getSetting("CelestialBody");
                // Debug.Log("KK: CelBody is " + CelBody);
                var objectpos    = CelBody.transform.InverseTransformPoint(obj.gameObject.transform.position);
                var dObjectLat   = NavUtils.GetLatitude(objectpos);
                var dObjectLon   = NavUtils.GetLongitude(objectpos);
                var disObjectLat = dObjectLat * 180 / Math.PI;
                var disObjectLon = dObjectLon * 180 / Math.PI;

                if (disObjectLon < 0)
                {
                    disObjectLon = disObjectLon + 360;
                }
                // Debug.Log("KK: disObjectLat is " + disObjectLat);
                // Debug.Log("KK: disObjecton is " + disObjectLon);
                obj.setSetting("RefLatitude", (float)disObjectLat);
                obj.setSetting("RefLongitude", (float)disObjectLon);
                // Debug.Log("KK: RefLatitude and RefLongitude set");

                foreach (FieldInfo fi in PSystemSetup.Instance.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
                {
                    if (fi.FieldType.Name == "SpaceCenterFacility[]")
                    {
                        PSystemSetup.SpaceCenterFacility[] facilities = (PSystemSetup.SpaceCenterFacility[])fi.GetValue(PSystemSetup.Instance);
                        if (PSystemSetup.Instance.GetSpaceCenterFacility((string)obj.getSetting("LaunchSiteName")) == null)
                        {
                            PSystemSetup.SpaceCenterFacility newFacility = new PSystemSetup.SpaceCenterFacility();
                            newFacility.name                  = "FacilityName";
                            newFacility.facilityName          = (string)obj.getSetting("LaunchSiteName");
                            newFacility.facilityPQS           = ((CelestialBody)obj.getSetting("CelestialBody")).pqsController;
                            newFacility.facilityTransformName = obj.gameObject.name;
                            newFacility.pqsName               = ((CelestialBody)obj.getSetting("CelestialBody")).pqsController.name;
                            PSystemSetup.SpaceCenterFacility.SpawnPoint spawnPoint = new PSystemSetup.SpaceCenterFacility.SpawnPoint();
                            spawnPoint.name = (string)obj.getSetting("LaunchSiteName");
                            spawnPoint.spawnTransformURL = (string)obj.getSetting("LaunchPadTransform");
                            newFacility.spawnPoints      = new PSystemSetup.SpaceCenterFacility.SpawnPoint[1];
                            newFacility.spawnPoints[0]   = spawnPoint;
                            PSystemSetup.SpaceCenterFacility[] newFacilities = new PSystemSetup.SpaceCenterFacility[facilities.Length + 1];
                            for (int i = 0; i < facilities.Length; ++i)
                            {
                                newFacilities[i] = facilities[i];
                            }
                            newFacilities[newFacilities.Length - 1] = newFacility;
                            fi.SetValue(PSystemSetup.Instance, newFacilities);
                            facilities = newFacilities;

                            bool RTEnabled = false;

                            Texture logo = null;
                            Texture icon = null;

                            if (obj.settings.ContainsKey("LaunchSiteLogo"))
                            {
                                logo = GameDatabase.Instance.GetTexture(obj.model.path + "/" + obj.getSetting("LaunchSiteLogo"), false);
                            }

                            if (logo == null)
                            {
                                logo = defaultLaunchSiteLogo;
                            }

                            if (obj.settings.ContainsKey("LaunchSiteIcon"))
                            {
                                icon = GameDatabase.Instance.GetTexture(obj.model.path + "/" + obj.getSetting("LaunchSiteIcon"), false);
                            }

                            if (obj.settings.ContainsKey("RemoteTechGroundstation"))
                            {
                                RTEnabled = Convert.ToBoolean(obj.getSetting("RemoteTechGroundstation"));
                            }


                            // TODO This is still hard-code and needs to use the API properly
                            // ASH 12112014 - Added career open close costs
                            launchSites.Add(new LaunchSite((string)obj.getSetting("LaunchSiteName"),
                                                           (obj.settings.ContainsKey("LaunchSiteAuthor")) ? (string)obj.getSetting("LaunchSiteAuthor") : (string)obj.model.getSetting("author"),
                                                           (SiteType)obj.getSetting("LaunchSiteType"),
                                                           logo,
                                                           icon,
                                                           (string)obj.getSetting("LaunchSiteDescription"),
                                                           (string)obj.getSetting("Category"),
                                                           (float)obj.getSetting("OpenCost"),
                                                           (float)obj.getSetting("CloseValue"),
                                                           "Closed",
                                                           (float)obj.getSetting("RefLongitude"),
                                                           (float)obj.getSetting("RefLatitude"),
                                                           (float)obj.getSetting("RadiusOffset"),
                                                           (obj.settings.ContainsKey("LaunchSiteLength")) ?
                                                           (float)obj.getSetting("LaunchSiteLength") : (float)obj.model.getSetting("DefaultLaunchSiteLength"),
                                                           (obj.settings.ContainsKey("LaunchSiteWidth")) ?
                                                           (float)obj.getSetting("LaunchSiteWidth") : (float)obj.model.getSetting("DefaultLaunchSiteWidth"),
                                                           (float)obj.getSetting("LaunchRefund"),
                                                           (float)obj.getSetting("RecoveryFactor"),
                                                           (float)obj.getSetting("RecoveryRange"),
                                                           obj.gameObject,
                                                           RTEnabled,
                                                           newFacility
                                                           ));
                            // Debug.Log("KK: Created launch site \"" + newFacility.name + "\" with transform " + obj.getSetting("LaunchSiteName") + "/" + obj.getSetting("LaunchPadTransform"));
                        }
                        else
                        {
                            Debug.Log("KK: Launch site " + obj.getSetting("LaunchSiteName") + " already exists.");
                        }
                    }
                }

                MethodInfo updateSitesMI = PSystemSetup.Instance.GetType().GetMethod("SetupFacilities", BindingFlags.NonPublic | BindingFlags.Instance);
                if (updateSitesMI == null)
                {
                    Debug.Log("KK: You are screwed. Failed to find SetupFacilities().");
                }
                else
                {
                    updateSitesMI.Invoke(PSystemSetup.Instance, null);
                }

                if (obj.gameObject != null)
                {
                    CustomSpaceCenter.CreateFromLaunchsite((string)obj.getSetting("LaunchSiteName"), obj.gameObject);
                }
            }
            else
            {
                Debug.Log("KK: Launch pad transform \"" + obj.getSetting("LaunchPadTransform") + "\" missing for " + obj.getSetting("LaunchSiteName"));
            }
        }
예제 #3
0
        public void drawIcons()
        {
            displayingTooltip = false;
            MapObject target = PlanetariumCamera.fetch.target;

            if (target.type == MapObject.MapObjectType.CELESTIALBODY)
            {
                // Do tracking stations first
                foreach (StaticObject obj in KerbalKonstructs.instance.getStaticDB().getAllStatics())
                {
                    bool display2 = false;
                    if ((string)obj.getSetting("FacilityType") == "TrackingStation")
                    {
                        if (!isOccluded(obj.gameObject.transform.position, target.celestialBody))
                        {
                            if (MiscUtils.isCareerGame())
                            {
                                //PersistenceUtils.loadStaticPersistence(obj);
                                string openclosed2 = (string)obj.getSetting("OpenCloseState");
                                // To do manage open and close state of tracking stations
                                if (KerbalKonstructs.instance.mapShowOpenT)                                 // && openclosed == "Open")
                                {
                                    display2 = true;
                                }
                                if (!KerbalKonstructs.instance.mapShowClosed && openclosed2 == "Closed")
                                {
                                    display2 = false;
                                }
                                if (!KerbalKonstructs.instance.mapShowOpen && openclosed2 == "Open")
                                {
                                    display2 = false;
                                }
                            }
                            else
                            {                             // Not a career game
                            }

                            if (display2)
                            {
                                Vector3 pos         = MapView.MapCamera.camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(obj.gameObject.transform.position));
                                Rect    screenRect2 = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16);
                                Graphics.DrawTexture(screenRect2, TrackingStationIcon);

                                if (screenRect2.Contains(Event.current.mousePosition) && !displayingTooltip)
                                {
                                    CelestialBody cPlanetoid = (CelestialBody)obj.getSetting("CelestialBody");

                                    var objectpos2    = cPlanetoid.transform.InverseTransformPoint(obj.gameObject.transform.position);
                                    var dObjectLat2   = NavUtils.GetLatitude(objectpos2);
                                    var dObjectLon2   = NavUtils.GetLongitude(objectpos2);
                                    var disObjectLat2 = dObjectLat2 * 180 / Math.PI;
                                    var disObjectLon2 = dObjectLon2 * 180 / Math.PI;

                                    if (disObjectLon2 < 0)
                                    {
                                        disObjectLon2 = disObjectLon2 + 360;
                                    }

                                    //Only display one tooltip at a time
                                    displayMapIconToolTip("Tracking Station " + "\n(Lat." + disObjectLat2.ToString("#0.00") + "/ Lon." + disObjectLon2.ToString("#0.00") + ")", pos);
                                    // TO DO Display Lat and Lon in tooltip too

                                    if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
                                    {
                                        //MiscUtils.HUDMessage("Selected base is " + sToolTip + ".", 5f, 3);
                                        Debug.Log("KK: Selected station in map");
                                        float sTrackAngle = (float)obj.getSetting("TrackingAngle");
                                        Debug.Log("KK: Before save load " + sTrackAngle.ToString());
                                        float sTrackRange = (float)obj.getSetting("TrackingShort");
                                        Debug.Log("KK: Before save load " + sTrackRange.ToString());

                                        //PersistenceUtils.saveStaticPersistence(obj);
                                        PersistenceUtils.loadStaticPersistence(obj);

                                        float sTrackAngle2 = (float)obj.getSetting("TrackingAngle");
                                        Debug.Log("KK: After save load " + sTrackAngle2.ToString());
                                        float sTrackRange2 = (float)obj.getSetting("TrackingShort");
                                        Debug.Log("KK: After save load " + sTrackRange2.ToString());

                                        selectedFacility = obj;
                                        FacilityManager.setSelectedFacility(obj);
                                        KerbalKonstructs.instance.showFacilityManager = true;
                                        //EditorGUI.setTargetSite(selectedSite);
                                    }
                                }
                                else
                                {                                 // Mouse is not over tooltip
                                }
                            }
                            else
                            {                             // Filter set to not display
                            }
                        }
                        else
                        {                         // is occluded
                        }
                    }
                    else
                    {             // Not a tracking station
                    }
                }                 //end foreach

                // Then do launchsites
                List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();
                foreach (LaunchSite site in sites)
                {
                    bool display = false;
                    PSystemSetup.SpaceCenterFacility facility = PSystemSetup.Instance.GetSpaceCenterFacility(site.name);
                    if (facility != null)
                    {
                        PSystemSetup.SpaceCenterFacility.SpawnPoint sp = facility.GetSpawnPoint(site.name);
                        if (sp != null)
                        {
                            if (facility.facilityPQS == target.celestialBody.pqsController)
                            {
                                if (!isOccluded(sp.GetSpawnPointTransform().position, target.celestialBody))
                                {
                                    Vector3 pos        = MapView.MapCamera.camera.WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(sp.GetSpawnPointTransform().position));
                                    Rect    screenRect = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16);

                                    string openclosed = site.openclosestate;
                                    string category   = site.category;

                                    if (KerbalKonstructs.instance.mapShowHelipads && category == "Helipad")
                                    {
                                        display = true;
                                    }
                                    if (KerbalKonstructs.instance.mapShowOther && category == "Other")
                                    {
                                        display = true;
                                    }
                                    if (KerbalKonstructs.instance.mapShowRocketbases && category == "RocketPad")
                                    {
                                        display = true;
                                    }
                                    if (KerbalKonstructs.instance.mapShowRunways && category == "Runway")
                                    {
                                        display = true;
                                    }

                                    if (display && MiscUtils.isCareerGame())
                                    {
                                        if (!KerbalKonstructs.instance.mapShowOpen && openclosed == "Open")
                                        {
                                            display = false;
                                        }
                                        if (!KerbalKonstructs.instance.mapShowClosed && openclosed == "Closed")
                                        {
                                            display = false;
                                        }
                                        if (KerbalKonstructs.instance.disableDisplayClosed && openclosed == "Closed")
                                        {
                                            display = false;
                                        }
                                    }

                                    if (display)
                                    {
                                        if (site.icon != null)
                                        {
                                            Graphics.DrawTexture(screenRect, site.icon);
                                        }
                                        else
                                        {
                                            switch (site.type)
                                            {
                                            case SiteType.VAB:
                                                Graphics.DrawTexture(screenRect, VABIcon);
                                                break;

                                            case SiteType.SPH:
                                                Graphics.DrawTexture(screenRect, SPHIcon);
                                                break;

                                            default:
                                                Graphics.DrawTexture(screenRect, ANYIcon);
                                                break;
                                            }
                                        }

                                        // Tooltip
                                        if (screenRect.Contains(Event.current.mousePosition) && !displayingTooltip)
                                        {
                                            //Only display one tooltip at a time
                                            string sToolTip = "";
                                            sToolTip = site.name;
                                            if (site.name == "Runway")
                                            {
                                                sToolTip = "KSC Runway";
                                            }
                                            if (site.name == "LaunchPad")
                                            {
                                                sToolTip = "KSC LaunchPad";
                                            }
                                            displayMapIconToolTip(sToolTip, pos);

                                            // Select a base by clicking on the icon
                                            if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
                                            {
                                                MiscUtils.HUDMessage("Selected base is " + sToolTip + ".", 5f, 3);
                                                BaseManager.setSelectedSite(site);
                                                selectedSite = site;
                                                NavGuidanceSystem.setTargetSite(selectedSite);
                                                KerbalKonstructs.instance.showBaseManager = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        void drawFacilityManagerWindow(int windowID)
        {
            DeadButton = new GUIStyle(GUI.skin.button);
            DeadButton.normal.background  = null;
            DeadButton.hover.background   = null;
            DeadButton.active.background  = null;
            DeadButton.focused.background = null;
            DeadButton.normal.textColor   = Color.white;
            DeadButton.hover.textColor    = Color.white;
            DeadButton.active.textColor   = Color.white;
            DeadButton.focused.textColor  = Color.white;
            DeadButton.fontSize           = 14;
            DeadButton.fontStyle          = FontStyle.Bold;

            DeadButtonRed = new GUIStyle(GUI.skin.button);
            DeadButtonRed.normal.background  = null;
            DeadButtonRed.hover.background   = null;
            DeadButtonRed.active.background  = null;
            DeadButtonRed.focused.background = null;
            DeadButtonRed.normal.textColor   = Color.red;
            DeadButtonRed.hover.textColor    = Color.yellow;
            DeadButtonRed.active.textColor   = Color.red;
            DeadButtonRed.focused.textColor  = Color.red;
            DeadButtonRed.fontSize           = 12;
            DeadButtonRed.fontStyle          = FontStyle.Bold;

            BoxNoBorder = new GUIStyle(GUI.skin.box);
            BoxNoBorder.normal.background = null;
            BoxNoBorder.normal.textColor  = Color.white;

            Yellowtext = new GUIStyle(GUI.skin.box);
            Yellowtext.normal.textColor  = Color.yellow;
            Yellowtext.normal.background = null;

            LabelInfo = new GUIStyle(GUI.skin.label);
            LabelInfo.normal.background = null;
            LabelInfo.normal.textColor  = Color.white;
            LabelInfo.fontSize          = 13;
            LabelInfo.fontStyle         = FontStyle.Bold;
            LabelInfo.padding.left      = 3;
            LabelInfo.padding.top       = 0;
            LabelInfo.padding.bottom    = 0;

            ButtonSmallText           = new GUIStyle(GUI.skin.button);
            ButtonSmallText.fontSize  = 12;
            ButtonSmallText.fontStyle = FontStyle.Normal;

            GUILayout.BeginHorizontal();
            {
                GUI.enabled = false;
                GUILayout.Button("-KK-", DeadButton, GUILayout.Height(16));

                GUILayout.FlexibleSpace();

                GUILayout.Button("Facility Manager", DeadButton, GUILayout.Height(16));

                GUILayout.FlexibleSpace();

                GUI.enabled = true;

                if (GUILayout.Button("X", DeadButtonRed, GUILayout.Height(16)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                    selectedFacility = null;
                    KerbalKonstructs.instance.showFacilityManager = false;
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));

            GUILayout.Space(2);

            if (selectedFacility != null)
            {
                sFacilityType = (string)selectedFacility.getSetting("FacilityType");

                if (sFacilityType == "TrackingStation")
                {
                    sFacilityName = "Tracking Station";
                    bHalfwindow   = true;
                }
                else
                {
                    sFacilityName = (string)selectedFacility.model.getSetting("title");
                }

                GUILayout.Box("" + sFacilityName, Yellowtext);
                GUILayout.Space(5);

                fAlt = (float)selectedFacility.getSetting("RadiusOffset");

                ObjectPos    = KerbalKonstructs.instance.getCurrentBody().transform.InverseTransformPoint(selectedFacility.gameObject.transform.position);
                dObjectLat   = NavUtils.GetLatitude(ObjectPos);
                dObjectLon   = NavUtils.GetLongitude(ObjectPos);
                disObjectLat = dObjectLat * 180 / Math.PI;
                disObjectLon = dObjectLon * 180 / Math.PI;

                if (disObjectLon < 0)
                {
                    disObjectLon = disObjectLon + 360;
                }

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(5);
                    GUILayout.Label("Alt. " + fAlt.ToString("#0.0") + "m", LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Lat. " + disObjectLat.ToString("#0.000"), LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Lon. " + disObjectLon.ToString("#0.000"), LabelInfo);
                    GUILayout.Space(5);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(5);

                string sPurpose = "";

                if (sFacilityType == "Hangar")
                {
                    sPurpose    = "Craft can be stored in this building for launching from the base at a later date. The building has limited space.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "RocketAssembly")
                {
                    sPurpose    = "This facility can construct craft that have been designed in KSC's VAB and can store a constructed craft for launching from the base at a later date.";
                    bHalfwindow = false;
                }
                else
                if (sFacilityType == "PlaneAssembly")
                {
                    sPurpose    = "This facility can construct craft that have been designed in KSC's SPH and can store a constructed craft for launching from the base at a later date.";
                    bHalfwindow = false;
                }
                else
                if (sFacilityType == "ControlTower")
                {
                    sPurpose = "This facility manages incoming and outgoing air-traffic to and from the base, as well as administrating most other base operations.";
                }
                else
                if (sFacilityType == "Barracks")
                {
                    sPurpose    = "This facility provides a temporary home for base-staff. Other facilities can draw staff from the pool available at this facility.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "RadarStation")
                {
                    sPurpose    = "This facility tracks craft in the planet's atmosphere at a limited range. It provides bonuses for recovery operations by the nearest open base.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "Research")
                {
                    sPurpose    = "This facility carries out research and generates Science.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "Mining")
                {
                    sPurpose = "This facility excavates useful minerals and materials and thus generates Ore.";
                }
                else
                if (sFacilityType == "Refining")
                {
                    sPurpose = "This facility converts Ore into fuels.";
                }
                else
                if (sFacilityType == "Manufacturing")
                {
                    sPurpose = "This facility converts Ore into Processed Ore, for use in manufacturing craft in lieu of Funds, constructing and upgrading facilities.";
                }
                else
                if (sFacilityType == "Business")
                {
                    sPurpose    = "This facility carries out business related to the space program in order to generate Funds.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "Training")
                {
                    sPurpose = "This facility can provide professional skills and experience to rookie Kerbonauts.";
                }
                else
                if (sFacilityType == "Medical")
                {
                    sPurpose = "This facility can aid Kerbonaut recovery after long missions or injury.";
                }
                else
                if (sFacilityType == "TrackingStation")
                {
                    sPurpose    = "This facility can track a variety of off-Kerbin targets, including spacecraft, celestial bodies and asteroids.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "FuelTanks")
                {
                    sPurpose    = "This facility stores fuel for craft.";
                    bHalfwindow = false;
                }
                else
                if (sFacilityType == "Storage")
                {
                    sPurpose = "This facility stores construction materials (Processed Ore).";
                }
                else
                if (sFacilityType == "CraftAssembly")
                {
                    sPurpose    = "This facility can construct craft that have been designed in KSC's VAB or SPH and can store a constructed craft for launching from the base at a later date.";
                    bHalfwindow = false;
                }

                GUILayout.Label(sPurpose, LabelInfo);
                GUILayout.Space(2);
                GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                GUILayout.Space(3);

                SharedInterfaces.OpenCloseFacility(selectedFacility);

                iFundsOpen2 = (float)selectedFacility.getSetting("OpenCost");
                isOpen2     = ((string)selectedFacility.getSetting("OpenCloseState") == "Open");
                float iFundsDefaultCost = (float)selectedFacility.model.getSetting("cost");
                if (iFundsOpen2 == 0)
                {
                    iFundsOpen2 = iFundsDefaultCost;
                }

                if (iFundsOpen2 == 0)
                {
                    isOpen2 = true;
                }

                GUILayout.Space(2);
                GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                GUILayout.Space(3);

                GUI.enabled = isOpen2;

                if (sFacilityType == "TrackingStation")
                {
                    TrackingStationGUI.TrackingInterface(selectedFacility);
                }

                if (sFacilityType == "Hangar" || sFacilityType == "RocketAssembly" || sFacilityType == "PlaneAssembly" || sFacilityType == "CraftAssembly")
                {
                    sInStorage  = (string)selectedFacility.getSetting("InStorage");
                    sInStorage2 = (string)selectedFacility.getSetting("TargetID");
                    sInStorage3 = (string)selectedFacility.getSetting("TargetType");

                    float fMaxMass = (float)selectedFacility.model.getSetting("DefaultFacilityMassCapacity");
                    if (fMaxMass < 1)
                    {
                        fMaxMass = 25f;
                    }
                    float fMaxCrafts = (float)selectedFacility.model.getSetting("DefaultFacilityCraftCapacity");
                    if (fMaxCrafts < 1 || fMaxCrafts > 3)
                    {
                        fMaxCrafts = 2;
                    }

                    GUILayout.Space(2);
                    GUILayout.Label("Where necessary craft are disassembled for storage or re-assembled before being rolled out. Please note that for game purposes, this procedure is instantaneous.", LabelInfo);
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Max Craft: " + fMaxCrafts.ToString("#0"), LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Max Mass/Craft: " + fMaxMass.ToString("#0") + " T", LabelInfo);
                    GUILayout.EndHorizontal();

                    if (sInStorage == null || sInStorage == "")
                    {
                        sInStorage = "None";
                        selectedFacility.setSetting("InStorage", "None");
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }
                    if (sInStorage2 == null || sInStorage2 == "")
                    {
                        sInStorage2 = "None";
                        selectedFacility.setSetting("TargetID", "None");
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }
                    if (sInStorage3 == null || sInStorage3 == "")
                    {
                        sInStorage3 = "None";
                        selectedFacility.setSetting("TargetType", "None");
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }

                    if (sInStorage == "None" && sInStorage2 == "None" && sInStorage3 == "None")
                    {
                        GUILayout.Label("No craft currently held in this facility.", LabelInfo);
                    }
                    else
                    {
                        int iNumberCrafts = NumberCraftHangared(selectedFacility);

                        GUILayout.Box("Stored Craft (" + iNumberCrafts.ToString() + "/" + fMaxCrafts.ToString("#0") + ")", Yellowtext);

                        List <Vessel> lVessels = FlightGlobals.Vessels;

                        foreach (Vessel vVesselStored in lVessels)
                        {
                            if (vVesselStored.id.ToString() == sInStorage)
                            {
                                if (GUILayout.Button("" + vVesselStored.vesselName, ButtonSmallText, GUILayout.Height(20)))
                                {
                                    // Empty the hangar
                                    if (HangarwayIsClear(selectedFacility))
                                    {
                                        sInStorage = "None";
                                        UnhangarCraft(vVesselStored, selectedFacility);
                                        sInStorage = "None";
                                    }
                                    else
                                    {
                                        ScreenMessages.PostScreenMessage("Cannot roll craft out. Clear the way first!", 10,
                                                                         ScreenMessageStyle.LOWER_CENTER);
                                    }
                                }
                                break;
                            }
                        }

                        foreach (Vessel vVesselStored in lVessels)
                        {
                            if (vVesselStored.id.ToString() == sInStorage2)
                            {
                                if (GUILayout.Button("" + vVesselStored.vesselName, ButtonSmallText, GUILayout.Height(20)))
                                {
                                    // Empty the hangar
                                    if (HangarwayIsClear(selectedFacility))
                                    {
                                        sInStorage2 = "None";
                                        UnhangarCraft(vVesselStored, selectedFacility);
                                        sInStorage2 = "None";
                                    }
                                    else
                                    {
                                        ScreenMessages.PostScreenMessage("Cannot roll craft out. Clear the way first!", 10,
                                                                         ScreenMessageStyle.LOWER_CENTER);
                                    }
                                }
                                break;
                            }
                        }

                        foreach (Vessel vVesselStored in lVessels)
                        {
                            if (vVesselStored.id.ToString() == sInStorage3)
                            {
                                if (GUILayout.Button("" + vVesselStored.vesselName, ButtonSmallText, GUILayout.Height(20)))
                                {
                                    // Empty the hangar
                                    if (HangarwayIsClear(selectedFacility))
                                    {
                                        sInStorage3 = "None";
                                        UnhangarCraft(vVesselStored, selectedFacility);
                                        sInStorage3 = "None";
                                    }
                                    else
                                    {
                                        ScreenMessages.PostScreenMessage("Cannot roll craft out. Clear the way first!", 10,
                                                                         ScreenMessageStyle.LOWER_CENTER);
                                    }
                                }
                                break;
                            }
                        }
                    }

                    GUILayout.Space(5);

                    scrollNearbyCraft = GUILayout.BeginScrollView(scrollNearbyCraft);

                    GUILayout.Box("Nearby Craft", Yellowtext);

                    bool bNearbyCraft = false;

                    foreach (Vessel vVessel in FlightGlobals.Vessels)
                    {
                        if (vVessel == null)
                        {
                            continue;
                        }
                        if (!vVessel.loaded)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.SpaceObject)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.Debris)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.EVA)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.Flag)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.Unknown)
                        {
                            continue;
                        }
                        if (vVessel == FlightGlobals.ActiveVessel)
                        {
                            continue;
                        }
                        if (vVessel.situation != Vessel.Situations.LANDED)
                        {
                            continue;
                        }
                        if (vVessel.GetCrewCount() > 0)
                        {
                            continue;
                        }

                        var vDistToCraft = Vector3.Distance(vVessel.gameObject.transform.position, selectedFacility.gameObject.transform.position);
                        if (vDistToCraft > 250)
                        {
                            continue;
                        }

                        bNearbyCraft = true;

                        if (GUILayout.Button(" " + vVessel.vesselName + " ", ButtonSmallText, GUILayout.Height(20)))
                        {
                            float fMass = vVessel.GetTotalMass();

                            if (fMass > fMaxMass)
                            {
                                ScreenMessages.PostScreenMessage("Craft too heavy for this facility. Max " + fMaxMass.ToString("#0") + "T per craft.", 10,
                                                                 ScreenMessageStyle.LOWER_CENTER);
                            }
                            else
                            {
                                float fMaxCraft = (float)selectedFacility.model.getSetting("DefaultFacilityCraftCapacity");
                                if (fMaxCraft < 1 || fMaxCraft > 3)
                                {
                                    fMaxCraft = 2;
                                }

                                int iNumberCraft = NumberCraftHangared(selectedFacility);

                                if (iNumberCraft < (int)fMaxCraft)
                                {
                                    HangarCraft(vVessel, selectedFacility, (int)fMaxCraft);
                                }
                                else
                                {
                                    ScreenMessages.PostScreenMessage("This facility is full. Max craft: " + fMaxCraft.ToString("#0"), 10,
                                                                     ScreenMessageStyle.LOWER_CENTER);
                                }
                            }
                        }
                    }

                    if (!bNearbyCraft)
                    {
                        GUILayout.Label("There are no craft close enough to store in this facility.", LabelInfo);
                    }

                    GUILayout.EndScrollView();

                    GUILayout.FlexibleSpace();
                }

/*				if (sFacilityType == "RocketAssembly" || sFacilityType == "PlaneAssembly" || sFacilityType == "CraftAssembly")
 *                              {
 *                                      string sProducing = (string)selectedFacility.getSetting("Producing");
 *
 *                                      if (sProducing == null || sProducing == "")
 *                                      {
 *                                              sProducing = "None";
 *                                              selectedFacility.setSetting("Producing", "None");
 *                                              PersistenceUtils.saveStaticPersistence(selectedFacility);
 *                                      }
 *
 *                                      if (GUILayout.Button("Construct a Craft", ButtonSmallText, GUILayout.Height(20)))
 *                                      {
 *                                              if (sProducing != "None")
 *                                                      ScreenMessages.PostScreenMessage("Only one craft can be constructed at a time.", 10,
 *                                                              ScreenMessageStyle.LOWER_CENTER);
 *                                      }
 *
 *                                      GUILayout.Space(3);
 *                                      if (sProducing == "None")
 *                                              GUILayout.Label("No craft currently under construction in this facility.", LabelInfo);
 *                                      else
 *                                      {
 *                                              GUILayout.Label("Craft Under Construction: ", LabelInfo);
 *
 *                                              // TO DO List of craft
 *                                              GUILayout.Label("Cost of Construction: X Funds / X Materials", LabelInfo);
 *                                              GUILayout.Label("Total Construction Time: X hours", LabelInfo);
 *                                              GUILayout.Label("Time to Completion: X hours", LabelInfo);
 *                                              if (GUILayout.Button("Assign a Kerbonaut Engineer", ButtonSmallText, GUILayout.Height(20)))
 *                                              { }
 *                                      }
 *
 *                                      if (GUILayout.Button("Upgrade Production", ButtonSmallText, GUILayout.Height(20)))
 *                                      { }
 *
 *                                      float fAvailableMaterials;
 *
 *                                      fAvailableMaterials = (float)selectedFacility.getSetting("PrOreCurrent");
 *
 *                                      GUILayout.Space(3);
 *                                      GUILayout.Label("Available Materials (Processed Ore): " + fAvailableMaterials.ToString("#0.0"), LabelInfo);
 *                              } */

                float fStaffing       = 0;
                float fProductionRate = 0;
                float fLastCheck      = 0;

                if (sFacilityType == "Research" || sFacilityType == "Business" || sFacilityType == "Mining" ||
                    sFacilityType == "RocketAssembly" || sFacilityType == "PlaneAssembly" || sFacilityType == "CraftAssembly")
                {
                    // Check production since last check
                    fStaffing       = (float)selectedFacility.getSetting("StaffCurrent");
                    fProductionRate = (float)selectedFacility.getSetting("ProductionRateCurrent") * (fStaffing / 2f);

                    if (fProductionRate < 0.01f)
                    {
                        float fDefaultRate = 0.01f;

                        if (sFacilityType == "Business")
                        {
                            fDefaultRate = 0.10f;
                        }
                        if (sFacilityType == "Mining")
                        {
                            fDefaultRate = 0.05f;
                        }

                        selectedFacility.setSetting("ProductionRateCurrent", fDefaultRate);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                        fProductionRate = fDefaultRate * (fStaffing / 2f);
                    }

                    fLastCheck = (float)selectedFacility.getSetting("LastCheck");

                    if (fLastCheck == 0)
                    {
                        fLastCheck = (float)Planetarium.GetUniversalTime();
                        selectedFacility.setSetting("LastCheck", fLastCheck);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }
                }

                if (sFacilityType == "Research" || sFacilityType == "Business" || sFacilityType == "Mining")
                {
                    string sProduces = "";
                    float  fMax      = 0f;
                    float  fCurrent  = 0f;

                    if (sFacilityType == "Research")
                    {
                        sProduces = "Science";
                        fMax      = (float)selectedFacility.getSetting("ScienceOMax");

                        if (fMax < 1)
                        {
                            fMax = (float)selectedFacility.model.getSetting("DefaultScienceOMax");

                            if (fMax < 1)
                            {
                                fMax = 10f;
                            }

                            selectedFacility.setSetting("ScienceOMax", fMax);
                            PersistenceUtils.saveStaticPersistence(selectedFacility);
                        }

                        fCurrent = (float)selectedFacility.getSetting("ScienceOCurrent");
                    }
                    if (sFacilityType == "Business")
                    {
                        sProduces = "Funds";
                        fMax      = (float)selectedFacility.getSetting("FundsOMax");

                        if (fMax < 1)
                        {
                            fMax = (float)selectedFacility.model.getSetting("DefaultFundsOMax");

                            if (fMax < 1)
                            {
                                fMax = 10000f;
                            }

                            selectedFacility.setSetting("FundsOMax", fMax);
                            PersistenceUtils.saveStaticPersistence(selectedFacility);
                        }

                        fCurrent = (float)selectedFacility.getSetting("FundsOCurrent");
                    }
                    if (sFacilityType == "Mining")
                    {
                        sProduces = "Ore";
                        fMax      = (float)selectedFacility.model.getSetting("OreMax");

                        if (fMax < 1)
                        {
                            fMax = 500f;
                        }

                        fCurrent = (float)selectedFacility.getSetting("OreCurrent");
                    }

                    double dTime = Planetarium.GetUniversalTime();

                    // Deal with revert exploits
                    if (fLastCheck > (float)dTime)
                    {
                        selectedFacility.setSetting("LastCheck", (float)dTime);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }

                    if ((float)dTime - fLastCheck > 43200)
                    {
                        float fDays = (((float)dTime - fLastCheck) / 43200);

                        float fProduced = fDays * fProductionRate;

                        fCurrent = fCurrent + fProduced;
                        if (fCurrent > fMax)
                        {
                            fCurrent = fMax;
                        }

                        if (sFacilityType == "Research")
                        {
                            selectedFacility.setSetting("ScienceOCurrent", fCurrent);
                        }
                        if (sFacilityType == "Business")
                        {
                            selectedFacility.setSetting("FundsOCurrent", fCurrent);
                        }
                        if (sFacilityType == "Mining")
                        {
                            selectedFacility.setSetting("OreCurrent", fCurrent);
                        }

                        selectedFacility.setSetting("LastCheck", (float)dTime);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Produces: " + sProduces, LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Current: " + fCurrent.ToString("#0") + " | Max: " + fMax.ToString("#0"), LabelInfo);
                    GUILayout.EndHorizontal();
                    //if (GUILayout.Button("Upgrade Max Capacity", ButtonSmallText, GUILayout.Height(20)))
                    //{ }

                    if (sFacilityType == "Research")
                    {
                        if (GUILayout.Button("Transfer Science to KSC R&D", ButtonSmallText, GUILayout.Height(20)))
                        {
                            ResearchAndDevelopment.Instance.AddScience(fCurrent, TransactionReasons.Cheating);
                            selectedFacility.setSetting("ScienceOCurrent", 0f);
                            PersistenceUtils.saveStaticPersistence(selectedFacility);
                        }

                        /* GUILayout.BeginHorizontal();
                         * {
                         *      if (GUILayout.Button("Assign a Special Project", ButtonSmallText, GUILayout.Height(20)))
                         *      { }
                         *      if (GUILayout.Button("Deliver Research Materials", ButtonSmallText, GUILayout.Height(20)))
                         *      { }
                         * }
                         * GUILayout.EndHorizontal();
                         * if (GUILayout.Button("Assign a Kerbonaut Scientist", ButtonSmallText, GUILayout.Height(20)))
                         * { } */
                    }
                    if (sFacilityType == "Business")
                    {
                        if (GUILayout.Button("Transfer Funds to KSC Account", ButtonSmallText, GUILayout.Height(20)))
                        {
                            Funding.Instance.AddFunds((double)fCurrent, TransactionReasons.Cheating);
                            selectedFacility.setSetting("FundsOCurrent", 0f);
                            PersistenceUtils.saveStaticPersistence(selectedFacility);
                        }
                    }

                    /* if (sFacilityType == "Mining")
                     * {
                     *      if (GUILayout.Button("Transfer Ore to/from Craft", ButtonSmallText, GUILayout.Height(20)))
                     *      {
                     *              if (bTransferOreToC) bTransferOreToC = false;
                     *              else bTransferOreToC = true;
                     *      }
                     *
                     *      if (bTransferOreToC)
                     *      {
                     *              // Ore transfer to craft GUI
                     *              GUILayout.Label("Select Craft & Container", LabelInfo);
                     *              scrollOreTransfer = GUILayout.BeginScrollView(scrollOreTransfer);
                     *              GUILayout.Label("Select Craft & Container", LabelInfo);
                     *              GUILayout.Label("Select Craft & Container", LabelInfo);
                     *              GUILayout.Label("Select Craft & Container", LabelInfo);
                     *              GUILayout.EndScrollView();
                     *              GUILayout.BeginHorizontal();
                     *              if (GUILayout.Button("Into Craft", GUILayout.Height(23)))
                     *              {
                     *
                     *              }
                     *              if (GUILayout.Button("Out of Craft", GUILayout.Height(23)))
                     *              {
                     *
                     *              }
                     *              GUILayout.EndHorizontal();
                     *              GUILayout.BeginHorizontal();
                     *              GUILayout.Label("Amount: ", LabelInfo);
                     *              sOreTransferAmount = GUILayout.TextField(sOreTransferAmount, 7, GUILayout.Width(120));
                     *              if (GUILayout.Button("Max", GUILayout.Height(23)))
                     *              {
                     *
                     *              }
                     *              GUILayout.EndHorizontal();
                     *              if (GUILayout.Button("Proceed", GUILayout.Height(23)))
                     *              {
                     *
                     *              }
                     *
                     *              GUILayout.FlexibleSpace();
                     *      }
                     *
                     *      if (GUILayout.Button("Transfer Ore to Facility", ButtonSmallText, GUILayout.Height(20)))
                     *      {
                     *              if (bTransferOreToF) bTransferOreToF = false;
                     *              else bTransferOreToF = true;
                     *
                     *      }
                     *
                     *      if (bTransferOreToF)
                     *      {
                     *              // Ore transfer to Facility GUI
                     *              GUILayout.Label("Select Destination Facility", LabelInfo);
                     *              scrollOreTransfer2 = GUILayout.BeginScrollView(scrollOreTransfer2);
                     *              GUILayout.Label("Select Destination Facility", LabelInfo);
                     *              GUILayout.Label("Select Destination Facility", LabelInfo);
                     *              GUILayout.Label("Select Destination Facility", LabelInfo);
                     *              GUILayout.EndScrollView();
                     *
                     *              GUILayout.BeginHorizontal();
                     *              GUILayout.Label("Amount: ", LabelInfo);
                     *              sOreTransferAmount = GUILayout.TextField(sOreTransferAmount, 7, GUILayout.Width(120));
                     *              if (GUILayout.Button("Max", GUILayout.Height(23)))
                     *              {
                     *
                     *              }
                     *              GUILayout.EndHorizontal();
                     *              GUILayout.BeginHorizontal();
                     *              GUILayout.Label("Transfer Cost: X Funds");
                     *              if (GUILayout.Button("Proceed", GUILayout.Height(23)))
                     *              {
                     *
                     *              }
                     *              GUILayout.EndHorizontal();
                     *              GUILayout.FlexibleSpace();
                     *      }
                     *
                     *      if (GUILayout.Button("Assign a Kerbonaut Engineer", ButtonSmallText, GUILayout.Height(20)))
                     *      { }
                     * } */

                    GUILayout.Space(5);
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Label("Production Rate: Up to " + fProductionRate.ToString("#0.00") + " per 12 hrs", LabelInfo);
                        GUILayout.FlexibleSpace();
                        //if (GUILayout.Button(" Upgrade ", ButtonSmallText, GUILayout.Height(20)))
                        //{ }
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.Space(3);
                }

                fLqFMax = (float)selectedFacility.model.getSetting("LqFMax");
                fOxFMax = (float)selectedFacility.model.getSetting("OxFMax");
                fMoFMax = (float)selectedFacility.model.getSetting("MoFMax");

                if (fLqFMax > 0 || fOxFMax > 0 || fMoFMax > 0)
                {
                    FuelTanksGUI.FuelTanksInterface(selectedFacility);
                }

                GUI.enabled = true;

                GUILayout.Space(2);
                GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                GUILayout.Space(2);

                GUI.enabled = isOpen2;
                StaffGUI.StaffingInterface(selectedFacility);
                GUI.enabled = true;
            }

            GUILayout.FlexibleSpace();
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(3);

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
        public void drawTrackingStations()
        {
            displayingTooltip2 = false;
            CelestialBody body = PlanetariumCamera.fetch.target.GetReferenceBody();

            // Do tracking stations first
            foreach (StaticObject obj in KerbalKonstructs.instance.getStaticDB().getAllStatics())
            {
                if (!MiscUtils.isCareerGame())
                {
                    break;
                }

                bool   display2    = false;
                string openclosed3 = "Closed";

                if ((string)obj.getSetting("FacilityType") != "TrackingStation")
                {
                    continue;
                }

                if (isOccluded(obj.gameObject.transform.position, body))
                {
                    if (KerbalKonstructs.instance.mapHideIconsBehindBody)
                    {
                        continue;
                    }
                }

                openclosed3 = (string)obj.getSetting("OpenCloseState");

                if ((float)obj.getSetting("OpenCost") == 0)
                {
                    openclosed3 = "Open";
                }

                if (KerbalKonstructs.instance.mapShowOpenT)
                {
                    display2 = true;
                }
                if (!KerbalKonstructs.instance.mapShowClosed && openclosed3 == "Closed")
                {
                    display2 = false;
                }
                if (!KerbalKonstructs.instance.mapShowOpen && openclosed3 == "Open")
                {
                    display2 = false;
                }

                if (!display2)
                {
                    continue;
                }

                Vector3 pos         = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(obj.gameObject.transform.position));
                Rect    screenRect6 = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16);
                // Distance between camera and spawnpoint sort of
                float fPosZ        = pos.z;
                float fRadarRadius = 12800 / fPosZ;

                if (fRadarRadius > 15)
                {
                    GUI.DrawTexture(screenRect6, UIMain.TrackingStationIcon, ScaleMode.ScaleToFit, true);
                }

                string sTarget  = (string)obj.getSetting("TargetID");
                float  fStRange = (float)obj.getSetting("TrackingShort");
                float  fStAngle = (float)obj.getSetting("TrackingAngle");

                if (openclosed3 == "Open" && KerbalKonstructs.instance.mapShowGroundComms)
                {
                    drawGroundComms(obj);
                }

                if ((string)obj.getSetting("TargetType") == "Craft" && sTarget != "None")
                {
                    Vessel vTargetVessel = TrackingStationGUI.GetTargetVessel(sTarget);
                    if (vTargetVessel == null)
                    {
                    }
                    else
                    {
                        if (vTargetVessel.state == Vessel.State.DEAD)
                        {
                        }
                        else
                        {
                            CelestialBody cbTStation = (CelestialBody)obj.getSetting("CelestialBody");
                            CelestialBody cbTCraft   = vTargetVessel.mainBody;

                            if (cbTStation == cbTCraft && openclosed3 == "Open" && KerbalKonstructs.instance.mapShowUplinks)
                            {
                                Vector3 vCraftPos = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(vTargetVessel.gameObject.transform.position));

                                float fRangeToTarget = TrackingStationGUI.GetRangeToCraft(obj, vTargetVessel);
                                int   iUplink        = TrackingStationGUI.GetUplinkQuality(fStRange, fRangeToTarget);
                                float fUplink        = (float)iUplink / 100;

                                float fRed   = 1f;
                                float fGreen = 0f;
                                float fBlue  = fUplink;
                                float fAlpha = 1f;

                                if (iUplink > 45)
                                {
                                    fRed   = 1f;
                                    fGreen = 0.65f + (fUplink / 10);
                                    fBlue  = 0f;
                                }

                                if (iUplink > 85)
                                {
                                    fRed   = 0f;
                                    fGreen = fUplink;
                                    fBlue  = 0f;
                                }

                                float fStationLOS = TrackingStationGUI.StationHasLOS(obj, vTargetVessel);

                                if (fStationLOS > fStAngle)
                                {
                                    fRed   = 1f;
                                    fGreen = 0f;
                                    fBlue  = 0f;
                                    fAlpha = 0.5f;
                                }

                                NavUtils.CreateLineMaterial(3);

                                GL.Begin(GL.LINES);
                                NavUtils.lineMaterial3.SetPass(0);
                                GL.Color(new Color(fRed, fGreen, fBlue, fAlpha));
                                GL.Vertex3(pos.x - Screen.width / 2, pos.y - Screen.height / 2, pos.z);
                                GL.Vertex3(vCraftPos.x - Screen.width / 2, vCraftPos.y - Screen.height / 2, vCraftPos.z);
                                GL.End();
                            }
                        }
                    }
                }

                if (screenRect6.Contains(Event.current.mousePosition) && !displayingTooltip2)
                {
                    CelestialBody cPlanetoid = (CelestialBody)obj.getSetting("CelestialBody");

                    var objectpos2    = cPlanetoid.transform.InverseTransformPoint(obj.gameObject.transform.position);
                    var dObjectLat2   = NavUtils.GetLatitude(objectpos2);
                    var dObjectLon2   = NavUtils.GetLongitude(objectpos2);
                    var disObjectLat2 = dObjectLat2 * 180 / Math.PI;
                    var disObjectLon2 = dObjectLon2 * 180 / Math.PI;

                    if (disObjectLon2 < 0)
                    {
                        disObjectLon2 = disObjectLon2 + 360;
                    }

                    //Only display one tooltip at a time
                    displayMapIconToolTip("Tracking Station " + "\n(Lat." + disObjectLat2.ToString("#0.00") + "/ Lon." + disObjectLon2.ToString("#0.00") + ")", pos);

                    if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
                    {
                        float sTrackAngle = (float)obj.getSetting("TrackingAngle");
                        float sTrackRange = (float)obj.getSetting("TrackingShort");

                        PersistenceUtils.loadStaticPersistence(obj);

                        float sTrackAngle2 = (float)obj.getSetting("TrackingAngle");
                        float sTrackRange2 = (float)obj.getSetting("TrackingShort");

                        selectedFacility = obj;
                        FacilityManager.setSelectedFacility(obj);
                        WindowManager.instance.OpenWindow(KerbalKonstructs.instance.GUI_FacilityManager.drawFacilityManager);
                    }
                }
            }
        }
예제 #6
0
        void drawFacilityManagerWindow(int windowID)
        {
            DeadButton = new GUIStyle(GUI.skin.button);
            DeadButton.normal.background  = null;
            DeadButton.hover.background   = null;
            DeadButton.active.background  = null;
            DeadButton.focused.background = null;
            DeadButton.normal.textColor   = Color.white;
            DeadButton.hover.textColor    = Color.white;
            DeadButton.active.textColor   = Color.white;
            DeadButton.focused.textColor  = Color.white;
            DeadButton.fontSize           = 14;
            DeadButton.fontStyle          = FontStyle.Bold;

            DeadButtonRed = new GUIStyle(GUI.skin.button);
            DeadButtonRed.normal.background  = null;
            DeadButtonRed.hover.background   = null;
            DeadButtonRed.active.background  = null;
            DeadButtonRed.focused.background = null;
            DeadButtonRed.normal.textColor   = Color.red;
            DeadButtonRed.hover.textColor    = Color.yellow;
            DeadButtonRed.active.textColor   = Color.red;
            DeadButtonRed.focused.textColor  = Color.red;
            DeadButtonRed.fontSize           = 12;
            DeadButtonRed.fontStyle          = FontStyle.Bold;

            BoxNoBorder = new GUIStyle(GUI.skin.box);
            BoxNoBorder.normal.background = null;
            BoxNoBorder.normal.textColor  = Color.white;

            Yellowtext = new GUIStyle(GUI.skin.box);
            Yellowtext.normal.textColor  = Color.yellow;
            Yellowtext.normal.background = null;

            LabelInfo = new GUIStyle(GUI.skin.label);
            LabelInfo.normal.background = null;
            LabelInfo.normal.textColor  = Color.white;
            LabelInfo.fontSize          = 13;
            LabelInfo.fontStyle         = FontStyle.Bold;
            LabelInfo.padding.left      = 3;
            LabelInfo.padding.top       = 0;
            LabelInfo.padding.bottom    = 0;

            ButtonSmallText           = new GUIStyle(GUI.skin.button);
            ButtonSmallText.fontSize  = 12;
            ButtonSmallText.fontStyle = FontStyle.Normal;

            GUILayout.BeginHorizontal();
            {
                GUI.enabled = false;
                GUILayout.Button("-KK-", DeadButton, GUILayout.Height(16));

                GUILayout.FlexibleSpace();

                GUILayout.Button("Facility Manager", DeadButton, GUILayout.Height(16));

                GUILayout.FlexibleSpace();

                GUI.enabled = true;

                if (GUILayout.Button("X", DeadButtonRed, GUILayout.Height(16)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                    selectedFacility = null;
                    WindowManager.instance.CloseWindow(KerbalKonstructs.instance.GUI_FacilityManager.drawFacilityManager);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(1);
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));

            GUILayout.Space(2);

            if (selectedFacility != null)
            {
                sFacilityType = (string)selectedFacility.getSetting("FacilityType");

                if (sFacilityType == "TrackingStation")
                {
                    sFacilityName = "Tracking Station";
                    bHalfwindow   = true;
                }
                else
                {
                    sFacilityName = (string)selectedFacility.model.getSetting("title");
                }

                GUILayout.Box("" + sFacilityName, Yellowtext);
                GUILayout.Space(5);

                fAlt = (float)selectedFacility.getSetting("RadiusOffset");

                ObjectPos    = KerbalKonstructs.instance.getCurrentBody().transform.InverseTransformPoint(selectedFacility.gameObject.transform.position);
                dObjectLat   = NavUtils.GetLatitude(ObjectPos);
                dObjectLon   = NavUtils.GetLongitude(ObjectPos);
                disObjectLat = dObjectLat * 180 / Math.PI;
                disObjectLon = dObjectLon * 180 / Math.PI;

                if (disObjectLon < 0)
                {
                    disObjectLon = disObjectLon + 360;
                }

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(5);
                    GUILayout.Label("Alt. " + fAlt.ToString("#0.0") + "m", LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Lat. " + disObjectLat.ToString("#0.000"), LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Lon. " + disObjectLon.ToString("#0.000"), LabelInfo);
                    GUILayout.Space(5);
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(5);

                string sPurpose = "";

                if (sFacilityType == "Hangar")
                {
                    sPurpose    = "Craft can be stored in this building for launching from the base at a later date. The building has limited space.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "RocketAssembly")
                {
                    sPurpose    = "This facility can construct craft that have been designed in KSC's VAB and can store a constructed craft for launching from the base at a later date.";
                    bHalfwindow = false;
                }
                else
                if (sFacilityType == "PlaneAssembly")
                {
                    sPurpose    = "This facility can construct craft that have been designed in KSC's SPH and can store a constructed craft for launching from the base at a later date.";
                    bHalfwindow = false;
                }
                else
                if (sFacilityType == "ControlTower")
                {
                    sPurpose = "This facility manages incoming and outgoing air-traffic to and from the base, as well as administrating most other base operations.";
                }
                else
                if (sFacilityType == "Barracks")
                {
                    sPurpose    = "This facility provides a temporary home for base-staff. Other facilities can draw staff from the pool available at this facility.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "RadarStation")
                {
                    sPurpose    = "This facility tracks craft in the planet's atmosphere at a limited range. It provides bonuses for recovery operations by the nearest open base.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "Research")
                {
                    sPurpose    = "This facility carries out research and generates Science.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "Mining")
                {
                    sPurpose = "This facility excavates useful minerals and materials and thus generates Ore.";
                }
                else
                if (sFacilityType == "Refining")
                {
                    sPurpose = "This facility converts Ore into fuels.";
                }
                else
                if (sFacilityType == "Manufacturing")
                {
                    sPurpose = "This facility converts Ore into Processed Ore, for use in manufacturing craft in lieu of Funds, constructing and upgrading facilities.";
                }
                else
                if (sFacilityType == "Business")
                {
                    sPurpose    = "This facility carries out business related to the space program in order to generate Funds.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "Training")
                {
                    sPurpose = "This facility can provide professional skills and experience to rookie Kerbonauts.";
                }
                else
                if (sFacilityType == "Medical")
                {
                    sPurpose = "This facility can aid Kerbonaut recovery after long missions or injury.";
                }
                else
                if (sFacilityType == "TrackingStation")
                {
                    sPurpose    = "This facility can track a variety of off-Kerbin targets, including spacecraft, celestial bodies and asteroids.";
                    bHalfwindow = true;
                }
                else
                if (sFacilityType == "FuelTanks")
                {
                    sPurpose    = "This facility stores fuel for craft.";
                    bHalfwindow = false;
                }
                else
                if (sFacilityType == "Storage")
                {
                    sPurpose = "This facility stores construction materials (Processed Ore).";
                }
                else
                if (sFacilityType == "CraftAssembly")
                {
                    sPurpose    = "This facility can construct craft that have been designed in KSC's VAB or SPH and can store a constructed craft for launching from the base at a later date.";
                    bHalfwindow = false;
                }

                GUILayout.Label(sPurpose, LabelInfo);
                GUILayout.Space(2);
                GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                GUILayout.Space(3);

                SharedInterfaces.OpenCloseFacility(selectedFacility);

                iFundsOpen2 = (float)selectedFacility.getSetting("OpenCost");
                isOpen2     = ((string)selectedFacility.getSetting("OpenCloseState") == "Open");
                float iFundsDefaultCost = (float)selectedFacility.model.getSetting("cost");
                if (iFundsOpen2 == 0)
                {
                    iFundsOpen2 = iFundsDefaultCost;
                }

                if (iFundsOpen2 == 0)
                {
                    isOpen2 = true;
                }

                GUILayout.Space(2);
                GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                GUILayout.Space(3);

                GUI.enabled = isOpen2;

                if (sFacilityType == "TrackingStation")
                {
                    TrackingStationGUI.TrackingInterface(selectedFacility);
                }

                if (sFacilityType == "Hangar" || sFacilityType == "RocketAssembly" || sFacilityType == "PlaneAssembly" || sFacilityType == "CraftAssembly")
                {
                    HangarGUI.HangarInterface(selectedFacility);
                }

                // WIP

                /* if (sFacilityType == "RocketAssembly" || sFacilityType == "PlaneAssembly" || sFacilityType == "CraftAssembly")
                 * {
                 *      CraftConstructionGUI.CraftConstructionInterface(selectedFacility);
                 * } */

                if (sFacilityType == "Research" || sFacilityType == "Business" || sFacilityType == "Mining" ||
                    sFacilityType == "RocketAssembly" || sFacilityType == "PlaneAssembly" || sFacilityType == "CraftAssembly")
                {
                    ProductionGUI.ProductionInterface(selectedFacility, sFacilityType);
                }

                fLqFMax = (float)selectedFacility.model.getSetting("LqFMax");
                fOxFMax = (float)selectedFacility.model.getSetting("OxFMax");
                fMoFMax = (float)selectedFacility.model.getSetting("MoFMax");

                if (fLqFMax > 0 || fOxFMax > 0 || fMoFMax > 0 || sFacilityType == "FuelTanks")
                {
                    FuelTanksGUI.FuelTanksInterface(selectedFacility);
                }

                GUI.enabled = true;

                GUILayout.Space(2);
                GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
                GUILayout.Space(2);

                GUI.enabled = isOpen2;
                StaffGUI.StaffingInterface(selectedFacility);
                GUI.enabled = true;
            }

            GUILayout.FlexibleSpace();
            GUILayout.Box(tHorizontalSep, BoxNoBorder, GUILayout.Height(4));
            GUILayout.Space(3);

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
예제 #7
0
        public static void TargetSelector(string sTargetTypeSelected, StaticObject selectedFacility = null)
        {
            scrollPos = GUILayout.BeginScrollView(scrollPos);
            {
                if (sTargetTypeSelected == "Station")
                {
                    sSelectedTrackingTarget = "None";

                    foreach (StaticObject obj in KerbalKonstructs.instance.getStaticDB().getAllStatics())
                    {
                        if ((string)obj.getSetting("FacilityType") == "TrackingStation")
                        {
                            if ((string)obj.getSetting("OpenCloseState") == "Closed")
                            {
                                continue;
                            }

                            GUILayout.BeginHorizontal();
                            {
                                fAlt = (float)obj.getSetting("RadiusOffset");

                                cPlanetoid = (CelestialBody)obj.getSetting("CelestialBody");

                                ObjectPos    = cPlanetoid.transform.InverseTransformPoint(obj.gameObject.transform.position);
                                dObjectLat   = NavUtils.GetLatitude(ObjectPos);
                                dObjectLon   = NavUtils.GetLongitude(ObjectPos);
                                disObjectLat = dObjectLat * 180 / Math.PI;
                                disObjectLon = dObjectLon * 180 / Math.PI;

                                if (disObjectLon < 0)
                                {
                                    disObjectLon = disObjectLon + 360;
                                }

                                sButtonText = cPlanetoid.name + " Station\nAltitude: " + fAlt.ToString("#0") + "m\nLat. "
                                              + disObjectLat.ToString("#0.000") + " Lon. " + disObjectLon.ToString("#0.000");

                                GUI.enabled = (obj != selectedStation);
                                //GUILayout.Box(sButtonText, GUILayout.Height(50));

                                ButtonSmallText           = new GUIStyle(GUI.skin.button);
                                ButtonSmallText.fontSize  = 12;
                                ButtonSmallText.fontStyle = FontStyle.Normal;

                                if (GUILayout.Button("" + sButtonText, ButtonSmallText, GUILayout.Height(55)))
                                {
                                    selectedStation = obj;
                                }

                                GUI.enabled = true;
                            }
                            GUILayout.EndHorizontal();
                        }
                    }
                }

                if (sTargetTypeSelected == "Craft")
                {
                    selectedStation = null;

                    foreach (Vessel vVessel in FlightGlobals.Vessels)
                    {
                        if (vVessel.vesselType == VesselType.SpaceObject)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.Debris)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.EVA)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.Flag)
                        {
                            continue;
                        }
                        if (vVessel.vesselType == VesselType.Unknown)
                        {
                            continue;
                        }
                        if (vVessel == FlightGlobals.ActiveVessel)
                        {
                            continue;
                        }

                        int iU = vVessel.name.IndexOf("(");
                        if (iU < 2)
                        {
                            iU = vVessel.name.Length + 1;
                        }
                        string sDisplayTarget = vVessel.name.Substring(0, iU - 1);

                        GUI.enabled = (sSelectedTrackingTarget != vVessel.name + "_" + vVessel.id.ToString());
                        if (GUILayout.Button(sDisplayTarget, GUILayout.Height(20)))
                        {
                            sSelectedTrackingTarget = vVessel.name + "_" + vVessel.id.ToString();
                        }
                        GUI.enabled = true;
                    }
                }

                if (sTargetTypeSelected == "Celestial Body")
                {
                    foreach (CelestialBody cBody in FlightGlobals.Bodies)
                    {
                        GUI.enabled = (sSelectedTrackingTarget != cBody.name);
                        if (GUILayout.Button(cBody.name, GUILayout.Height(20)))
                        {
                            sSelectedTrackingTarget = cBody.name;
                        }
                        GUI.enabled = true;
                    }
                }

                if (sTargetTypeSelected == "Asteroid")
                {
                    foreach (Vessel vVessel in FlightGlobals.Vessels)
                    {
                        if (vVessel.vesselType != VesselType.SpaceObject && vVessel.vesselType != VesselType.Unknown)
                        {
                            continue;
                        }

                        int iU = vVessel.name.IndexOf("(");
                        if (iU < 2)
                        {
                            iU = vVessel.name.Length + 1;
                        }
                        string sDisplayTarget = vVessel.name.Substring(0, iU - 1);

                        GUI.enabled = (sSelectedTrackingTarget != vVessel.name + "_" + vVessel.id.ToString());
                        if (GUILayout.Button(sDisplayTarget, GUILayout.Height(20)))
                        {
                            sSelectedTrackingTarget = vVessel.name + "_" + vVessel.id.ToString();
                        }
                        GUI.enabled = true;
                    }
                }

                if (sTargetTypeSelected == "Station's Discretion")
                {
                    GUILayout.Box("Target is selected by the station.");
                }

                if (sTargetTypeSelected == "None")
                {
                    GUILayout.Box("Select a target type.");
                }
            }
            GUILayout.EndScrollView();

            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();
            {
                if (sSelectedTrackingTarget != "None")
                {
                    bGUIenabled = true;
                }
                if (selectedStation != null)
                {
                    bGUIenabled = true;
                }

                GUI.enabled = bGUIenabled;
                if (GUILayout.Button("Select", GUILayout.Height(25)))
                {
                    sTarget = sSelectedTrackingTarget;
                    if (selectedFacility != null)
                    {
                        selectedFacility.setSetting("TargetID", sTarget);
                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                    }
                    else
                    {
                        if (selectedStation != null)
                        {
                            DownlinkGUI.soTargetStation = selectedStation;
                            var FacilityKey = selectedStation.getSetting("RadialPosition");
                            DownlinkGUI.sStationRadial = FacilityKey.ToString();
                        }
                        else
                        {
                            DownlinkGUI.sTarget = sTarget;
                        }

                        DownlinkGUI.SaveCommsState();
                    }
                }
                GUI.enabled = true;

                if (GUILayout.Button("Close", GUILayout.Height(25)))
                {
                    if (selectedFacility != null)
                    {
                        FacilityManager.changeTarget(false);
                    }
                    else
                    {
                        DownlinkGUI.changeTarget(false);
                    }
                }
            }
            GUILayout.EndHorizontal();
        }
        void prepNGS()
        {
            if (lTargetSite != null)
            {
                sTargetSiteName = lTargetSite.name;

                fRangeToTarget = LaunchSiteManager.getDistanceToBase(FlightGlobals.ActiveVessel.GetTransform().position, lTargetSite);
                if (fRangeToTarget > fOldRange)
                {
                    bClosing = false;
                }
                if (fRangeToTarget < fOldRange)
                {
                    bClosing = true;
                }

                var basepos  = KerbalKonstructs.instance.getCurrentBody().transform.InverseTransformPoint(lTargetSite.GameObject.transform.position);
                var dBaseLat = NavUtils.GetLatitude(basepos);
                var dBaseLon = NavUtils.GetLongitude(basepos);
                disBaseLat = dBaseLat * 180 / Math.PI;
                disBaseLon = dBaseLon * 180 / Math.PI;

                fOldRange = fRangeToTarget;

                if (bClosing)
                {
                    tTextureMiddle = tIconOpen;
                }
                else
                {
                    tTextureMiddle = tIconClosed;
                }

                Vector3 vcraftpos = FlightGlobals.ActiveVessel.GetTransform().position;
                vCrft = vcraftpos;
                Vector3 vsitepos = lTargetSite.GameObject.transform.position;
                vSPos = vsitepos;
                Vector3 vHeading = FlightGlobals.ActiveVessel.transform.up;
                vHead = vHeading;

                disLat = FlightGlobals.ActiveVessel.latitude;
                var dLat = disLat / 180 * Math.PI;
                disLon = FlightGlobals.ActiveVessel.longitude;
                var dLon = disLon / 180 * Math.PI;

                var y = Math.Sin(dBaseLon - dLon) * Math.Cos(dBaseLat);
                var x = (Math.Cos(dLat) * Math.Sin(dBaseLat)) - (Math.Sin(dLat) * Math.Cos(dBaseLat) * Math.Cos(dBaseLon - dLon));
                var requiredHeading = Math.Atan2(y, x) * 180 / Math.PI;
                dreqheading = (requiredHeading + 360) % 360;

                var diff = (360 + 180 + requiredHeading - FlightGlobals.ship_heading) % 360 - 180;
                dshipheading = (FlightGlobals.ship_heading + 360) % 360;

                if (diff > 5)
                {
                    iCorrection = 2;
                }
                else if (diff < -5)
                {
                    iCorrection = 1;
                }
                else
                {
                    iCorrection = 0;
                }

                if (bClosing)
                {
                    tTextureLeft  = tLeftOff;
                    tTextureRight = tRightOff;
                }
                else
                {
                    tTextureLeft  = tLeftOn;
                    tTextureRight = tRightOn;
                }

                if (iCorrection == 1)
                {
                    tTextureLeft  = tLeftOn;
                    tTextureRight = tRightOff;
                }
                if (iCorrection == 2)
                {
                    tTextureLeft  = tLeftOff;
                    tTextureRight = tRightOn;
                }
            }
            else
            {
                tTextureMiddle = tIconClosed;
                tTextureLeft   = tLeftOff;
                tTextureRight  = tRightOff;
            }
        }