public static string GetHangarSpace(StaticObject soHangar, int iMax = 2)
        {
            string sSpace = "None";

            if ((string)soHangar.getSetting("InStorage") == "None")
            {
                sSpace = "InStorage";
                if (iMax < 2)
                {
                    return(sSpace);
                }
            }
            else
            if ((string)soHangar.getSetting("TargetID") == "None")
            {
                sSpace = "TargetID";
                if (iMax == 2)
                {
                    return(sSpace);
                }
            }
            else
            if ((string)soHangar.getSetting("TargetType") == "None")
            {
                sSpace = "TargetType";
            }

            return(sSpace);
        }
示例#2
0
        /* public static void OpenRTGroundStation()
         * {
         *      bool bRTLoaded = AssemblyLoader.loadedAssemblies.Any(a => a.name == "RemoteTech");
         *      if (!bRTLoaded) return;
         *
         *      StaticObject obj = KerbalKonstructs.UI.SharedInterfaces.getStoredEventObject();
         *      if (obj == null)
         *      {
         *              Debug.Log("KK: Don't know what static object just got opened.");
         *              return;
         *      }
         *
         *      KerbalKonstructs.Utilities.PersistenceUtils.loadStaticPersistence(obj);
         *
         *      string sTSName;
         *      string sDLat;
         *      string sDLon;
         *      string sHeight;
         *
         *      if ((string)obj.getSetting("FacilityType") == "TrackingStation")
         *      {
         *              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;
         *              Guid NewGuid;
         *              Guid gGuid = (Guid)obj.getSetting("RTGuid");
         *
         *              if (gGuid == Guid.Empty)
         *              {
         *                      NewGuid = RemoteTech.API.API.AddGroundStation(sTSName, disObjectLat, disObjectLon, dHeight, iBody);
         *
         *                      if (NewGuid == Guid.Empty)
         *                      {
         *                              Debug.Log("KK: RT handed back an empty guid!");
         *                      }
         *
         *                      obj.setSetting("RTGuid", NewGuid);
         *                      Debug.Log("KK: Added RT GroundStation " + NewGuid.ToString());
         *                      KerbalKonstructs.Utilities.PersistenceUtils.saveStaticPersistence(obj);
         *                      RemoteTech.API.API.DirectConfigureStationAntenna(NewGuid, (float)obj.getSetting("TrackingShort"), 0, 1);
         *                      Debug.Log("KK: Saved station object");
         *              }
         *              else
         *              {
         *                      Debug.Log("KK: The station just opened already had a guid???");
         *              }
         *      }
         * } */

        public static string ConstructGuidString(StaticObject obj)
        {
            string sGuid = "";

            Vector3 vPos = (Vector3)obj.getSetting("RadialPosition");
            string  sPos = vPos.ToString();

            string sHeight = obj.getSetting("RadiusOffset").ToString();

            sGuid = sHeight.Replace(".", "") + sPos.Replace("@", "").Replace(",", "").Replace(".", "").Replace(";", "").Replace("'", "").Replace(" ", "").Replace("-", "").Replace("(", "").Replace(")", "");

            int iLength = sGuid.Length;
            int iNeeded = 32 - iLength;

            if (iLength > 32)
            {
                sGuid = sGuid.Substring(0, 32);
            }

            if (iNeeded > 0)
            {
                while (iNeeded > 0)
                {
                    sGuid   = sGuid + "0";
                    iNeeded = iNeeded - 1;
                }
            }

            return(sGuid);
        }
        public static string getResourceAlt(StaticObject obj, string sOriginal)
        {
            string sAlt = sOriginal;

            if (sOriginal == "LiquidFuel")
            {
                sAlt = (string)obj.getSetting("LqFAlt");
            }
            if (sOriginal == "Oxidizer")
            {
                sAlt = (string)obj.getSetting("OxFAlt");
            }
            if (sOriginal == "Monopropellant")
            {
                sAlt = (string)obj.getSetting("MoFAlt");
            }

            if (sAlt != "")
            {
                return(sAlt);
            }
            else
            {
                return(sOriginal);
            }
        }
        public float GetGateWidth(StaticObject soGate)
        {
            float        fDistance     = 0f;
            StaticObject soNearestPole = null;

            string sGroup   = (string)soGate.getSetting("Group");
            string sFacType = (string)soGate.getSetting("FacilityType");

            soNearestPole = NavUtils.GetNearestFacility(soGate.gameObject.transform.position, sFacType + "P", sGroup);

            fDistance = Vector3.Distance(soGate.gameObject.transform.position, soNearestPole.gameObject.transform.position);
            return(fDistance);
        }
        public float GetDistanceToGate(StaticObject soGate, Vector3 vPos)
        {
            float        fDistance     = 0f;
            Vector3      vCenter       = new Vector3(0, 0, 0);
            StaticObject soNearestPole = null;

            string sGroup   = (string)soGate.getSetting("Group");
            string sFacType = (string)soGate.getSetting("FacilityType");

            soNearestPole = NavUtils.GetNearestFacility(soGate.gameObject.transform.position, sFacType + "P", sGroup);

            vCenter = Vector3.Lerp(soGate.gameObject.transform.position, soNearestPole.gameObject.transform.position, 0.5f);

            fDistance = Vector3.Distance(vCenter, vPos);
            return(fDistance);
        }
        public static void RemoveCorrectCraft(Vessel vVessel, StaticObject soHangar)
        {
            string sSpace    = "InStorage";
            string sVesselID = vVessel.id.ToString();

            if (sVesselID == (string)soHangar.getSetting("TargetID"))
            {
                sSpace = "TargetID";
            }
            if (sVesselID == (string)soHangar.getSetting("TargetType"))
            {
                sSpace = "TargetType";
            }

            soHangar.setSetting(sSpace, "None");
            PersistenceUtils.saveStaticPersistence(soHangar);
        }
示例#7
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 int NumberCraftHangared(StaticObject soHangar)
        {
            int iNumber = 0;

            if ((string)soHangar.getSetting("InStorage") != "None")
            {
                iNumber = iNumber + 1;
            }
            if ((string)soHangar.getSetting("TargetID") != "None")
            {
                iNumber = iNumber + 1;
            }
            if ((string)soHangar.getSetting("TargetType") != "None")
            {
                iNumber = iNumber + 1;
            }

            return(iNumber);
        }
        public StaticObject GetNextGate(StaticObject StartLine, float fNextGate)
        {
            StaticObject soNextGate = null;
            string       sGate      = "Gate" + fNextGate.ToString();
            string       sGroup     = (string)StartLine.getSetting("Group");

            soNextGate = NavUtils.GetNearestFacility(StartLine.gameObject.transform.position, sGate, sGroup);

            return(soNextGate);
        }
        public void SpinPreview(StaticObject soObject)
        {
            if (soObject == null || currPreview == null)
            {
                return;
            }

            float fRot = (float)soObject.getSetting("RotationAngle") + 0.1f;

            if (fRot > 360)
            {
                fRot -= 360;
            }

            soObject.setSetting("RotationAngle", fRot);
            soObject.update();
        }
示例#11
0
        public static void CloseRTGroundStation(StaticObject obj)
        {
            bool bRTLoaded = AssemblyLoader.loadedAssemblies.Any(a => a.name == "RemoteTech");

            if (!bRTLoaded)
            {
                return;
            }
            if (obj == null)
            {
                return;
            }

            if ((string)obj.getSetting("FacilityType") == "TrackingStation")
            {
                string sGuid = ConstructGuidString(obj);

                if (sGuid != "")
                {
                    Debug.Log("KK: Attempting to remove RT GroundStation");
                    Guid nGuid   = new Guid(sGuid);
                    bool bRemove = RemoteTech.API.API.RemoveGroundStation(nGuid);
                    if (bRemove)
                    {
                        Debug.Log("KK: Removed RT GroundStation");
                    }
                    else
                    {
                        Debug.Log("KK: Failed to remove RT GroundStation " + sGuid);
                    }

                    KerbalKonstructs.Utilities.PersistenceUtils.saveStaticPersistence(obj);
                    RemoteTech.API.API.ReloadRTSettingsNow();
                    Debug.Log("KK: Saved station object");
                }
                else
                {
                    Debug.Log("KK: Can't remove RT GroundStation because it has no Guid");
                }
            }
        }
示例#12
0
        public SpaceCenter getSpaceCenter()
        {
            if (spaceCenter == null)
            {
                spaceCenter      = gameObject.AddComponent <SpaceCenter>();
                spaceCenter.cb   = (CelestialBody)staticObject.getSetting("CelestialBody");
                spaceCenter.name = SpaceCenterName;

                // Debug.Log("KK: getSpaceCenter set spaceCenter.name to " + SpaceCenterName);

                FieldInfo Latitude = spaceCenter.GetType().GetField("latitude", BindingFlags.NonPublic | BindingFlags.Instance);
                Latitude.SetValue(spaceCenter, spaceCenter.cb.GetLatitude(gameObject.transform.position));
                FieldInfo Longitude = spaceCenter.GetType().GetField("longitude", BindingFlags.NonPublic | BindingFlags.Instance);
                Longitude.SetValue(spaceCenter, spaceCenter.cb.GetLongitude(gameObject.transform.position));
                FieldInfo SrfNVector = spaceCenter.GetType().GetField("srfNVector", BindingFlags.NonPublic | BindingFlags.Instance);
                SrfNVector.SetValue(spaceCenter, spaceCenter.cb.GetRelSurfaceNVector(spaceCenter.Latitude, spaceCenter.Longitude));
            }
            else
            {
                // Debug.Log("KK: getSpaceCenter was not null.");
            }

            return(spaceCenter);
        }
示例#13
0
        public static void StaffingInterface(StaticObject selectedFacility)
        {
            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;

            BoxInfo = new GUIStyle(GUI.skin.box);
            BoxInfo.normal.textColor  = Color.cyan;
            BoxInfo.fontSize          = 13;
            BoxInfo.padding.top       = 2;
            BoxInfo.padding.bottom    = 1;
            BoxInfo.padding.left      = 5;
            BoxInfo.padding.right     = 5;
            BoxInfo.normal.background = null;

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

            fStaff    = (float)selectedFacility.getSetting("StaffCurrent");
            fMaxStaff = (float)selectedFacility.getSetting("StaffMax");

            bIsBarracks = false;

            if ((string)selectedFacility.getSetting("FacilityType") == "Barracks")
            {
                bIsBarracks = true;
            }
            else
            if ((string)selectedFacility.model.getSetting("DefaultFacilityType") == "Barracks")
            {
                bIsBarracks = true;
            }

            if (fMaxStaff < 1)
            {
                fMaxStaff = (float)selectedFacility.model.getSetting("DefaultStaffMax");

                if (fMaxStaff < 1)
                {
                    selectedFacility.setSetting("StaffMax", (float)0);
                    //PersistenceUtils.saveStaticPersistence(selectedFacility);
                }
                else
                {
                    selectedFacility.setSetting("StaffMax", (float)fMaxStaff);
                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                }
            }

            if (fMaxStaff > 0)
            {
                float fHireFundCost = 5000;
                float fFireRefund   = 2500;
                float fFireRepCost  = 1;

                bIsOpen = ((string)selectedFacility.getSetting("OpenCloseState") == "Open");

                if (!bIsOpen)
                {
                    iFundsOpen2 = (float)selectedFacility.model.getSetting("cost");
                    if (iFundsOpen2 == 0)
                    {
                        bIsOpen = true;
                    }
                }

                GUILayout.Space(5);

                float CountCurrent = fStaff;
                float CountEmpty   = fMaxStaff - fStaff;
                float funassigned  = (float)selectedFacility.getSetting("ProductionRateCurrent");

                scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(58));
                {
                    GUILayout.BeginHorizontal();
                    {
                        while (CountCurrent > 0)
                        {
                            GUILayout.Box(tKerbal, GUILayout.Width(23));
                            CountCurrent = CountCurrent - 1;
                        }

                        while (CountEmpty > 0)
                        {
                            GUILayout.Box(tNoKerbal, GUILayout.Width(23));
                            CountEmpty = CountEmpty - 1;
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                GUILayout.EndScrollView();

                GUI.enabled = bIsOpen;

                if (!bIsBarracks)
                {
                    GUILayout.Box("Assigned Staff: " + fStaff.ToString("#0") + "/" + fMaxStaff.ToString("#0"), BoxInfo);
                }

                if (bIsBarracks)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Staff: " + fStaff.ToString("#0") + "/" + fMaxStaff.ToString("#0"), LabelInfo);
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Unassigned: " + funassigned.ToString("#0") + "/" + fStaff.ToString("#0"), LabelInfo);
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    {
                        if (GUILayout.Button("Hire", ButtonSmallText, GUILayout.Height(20)))
                        {
                            if (fStaff == fMaxStaff)
                            {
                                MiscUtils.HUDMessage("Facility is full.", 10,
                                                     3);
                            }
                            else
                            {
                                double currentfunds = Funding.Instance.Funds;

                                if (fHireFundCost > currentfunds)
                                {
                                    MiscUtils.HUDMessage("Insufficient funds to hire staff!", 10,
                                                         3);
                                }
                                else
                                {
                                    selectedFacility.setSetting("StaffCurrent", (float)fStaff + 1);
                                    Funding.Instance.AddFunds(-fHireFundCost, TransactionReasons.Cheating);
                                    selectedFacility.setSetting("ProductionRateCurrent", (float)selectedFacility.getSetting("ProductionRateCurrent") + 1);
                                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                                }
                            }
                        }
                        if (GUILayout.Button("Fire", ButtonSmallText, GUILayout.Height(20)))
                        {
                            if (fStaff < 2)
                            {
                                MiscUtils.HUDMessage("This facility must have at least one caretaker.", 10, 3);
                            }
                            else
                            {
                                if ((float)selectedFacility.getSetting("ProductionRateCurrent") < 1)
                                {
                                    MiscUtils.HUDMessage("All staff are assigned to duties. Staff must be unassigned in order to fire them.", 10, 3);
                                }
                                else
                                {
                                    selectedFacility.setSetting("StaffCurrent", (float)fStaff - 1);
                                    selectedFacility.setSetting("ProductionRateCurrent", (float)selectedFacility.getSetting("ProductionRateCurrent") - 1);
                                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                                    Funding.Instance.AddFunds(fFireRefund, TransactionReasons.Cheating);
                                    Reputation.Instance.AddReputation(-fFireRepCost, TransactionReasons.Cheating);
                                }
                            }
                        }
                    }

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

                    string sHireTip = " Cost to hire next kerbal: " + fHireFundCost.ToString("#0") + " funds.";
                    string sFireTip = " Refund for firing: " + fFireRefund.ToString("#0") + " funds. Rep lost: " + fFireRepCost.ToString("#0") + ".";

                    GUILayout.Space(2);

                    if (fStaff < fMaxStaff)
                    {
                        GUILayout.Box(sHireTip, BoxInfo, GUILayout.Height(16));
                    }

                    if (fStaff > 1)
                    {
                        GUILayout.Box(sFireTip, BoxInfo, GUILayout.Height(16));
                    }
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    {
                        if (GUILayout.Button("Assign", ButtonSmallText, GUILayout.Height(20)))
                        {
                            if (fStaff == fMaxStaff)
                            {
                                MiscUtils.HUDMessage("Facility is fully staffed.", 10,
                                                     3);
                            }
                            else
                            {
                                float fAvailable = TotalBarracksPool(selectedFacility);

                                if (fAvailable < 1)
                                {
                                    MiscUtils.HUDMessage("No unassigned staff available.", 10, 3);
                                }
                                else
                                {
                                    StaticObject soNearestBarracks = NearestBarracks(selectedFacility);

                                    if (soNearestBarracks != null)
                                    {
                                        DrawFromBarracks(soNearestBarracks);

                                        selectedFacility.setSetting("StaffCurrent", (float)fStaff + 1);
                                        PersistenceUtils.saveStaticPersistence(selectedFacility);
                                        PersistenceUtils.saveStaticPersistence(soNearestBarracks);
                                    }
                                    else
                                    {
                                        MiscUtils.HUDMessage("No facility with available staff is nearby.", 10, 3);
                                    }
                                }
                            }
                        }

                        if (GUILayout.Button("Unassign", ButtonSmallText, GUILayout.Height(20)))
                        {
                            if (fStaff < 2)
                            {
                                MiscUtils.HUDMessage("An open facility must have one resident caretaker.", 10, 3);
                            }
                            else
                            {
                                StaticObject soAvailableSpace = NearestBarracks(selectedFacility, false);

                                if (soAvailableSpace != null)
                                {
                                    UnassignToBarracks(soAvailableSpace);
                                    selectedFacility.setSetting("StaffCurrent", (float)fStaff - 1);
                                    PersistenceUtils.saveStaticPersistence(selectedFacility);
                                    PersistenceUtils.saveStaticPersistence(soAvailableSpace);
                                }
                                else
                                {
                                    MiscUtils.HUDMessage("There's no room left in a barracks or apartment for this kerbal to go to.", 10, 3);
                                }
                            }
                        }
                    }

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

                GUILayout.Space(5);

                if (KerbalKonstructs.instance.DevMode)
                {
                    fXP = (float)selectedFacility.getSetting("FacilityXP");
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.Space(5);
                        GUILayout.Label("XP: ", LabelInfo, GUILayout.Height(23), GUILayout.Width(55));

                        float CountCurrentXP = fXP;
                        float CountEmptyXP   = 5 - fXP;

                        while (CountCurrentXP > 0)
                        {
                            GUILayout.Button(tXPGained, GUILayout.Height(23), GUILayout.Width(23));
                            CountCurrentXP = CountCurrentXP - 1;
                        }

                        while (CountEmptyXP > 0)
                        {
                            GUILayout.Button(tXPUngained, GUILayout.Height(23), GUILayout.Width(23));
                            CountEmptyXP = CountEmptyXP - 1;
                        }

                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("Spend", ButtonSmallText, GUILayout.Height(23)))
                        {
                            if (fXP < 1)
                            {
                                MiscUtils.HUDMessage("No XP to spend!", 10, 3);
                            }
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }
            else
            {
                GUILayout.FlexibleSpace();
                GUILayout.Box("This facility does not require staff assigned to it.", BoxInfo, GUILayout.Height(16));
            }
        }
示例#14
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();
        }
        public static void ProductionInterface(StaticObject selectedFacility, string sFacilityType)
        {
            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;

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

            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);
            }
        }
        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 static void loadStaticPersistence(StaticObject obj)
        {
            // Debug.Log("KK: loadStaticPersistence");
            var FacilityKey = obj.getSetting("RadialPosition");
            // Debug.Log("KK: FacilityKey is " + FacilityKey.ToString());

            string saveConfigPath = string.Format("{0}saves/{1}/KKFacilities.cfg", KSPUtil.ApplicationRootPath, HighLogic.SaveFolder);

            ConfigNode rootNode = new ConfigNode();

            if (!File.Exists(saveConfigPath))
            {
                ConfigNode GameNode     = rootNode.AddNode("GAME");
                ConfigNode ScenarioNode = GameNode.AddNode("SCENARIO");
                ScenarioNode.AddValue("Name", "KKStatics");
                rootNode.Save(saveConfigPath);
            }

            rootNode = ConfigNode.Load(saveConfigPath);
            ConfigNode rootrootNode = rootNode.GetNode("GAME");

            Boolean bMatch = false;

            foreach (ConfigNode ins in rootrootNode.GetNodes("SCENARIO"))
            {
                if (ins.GetValue("Name") == "KKStatics")
                {
                    // Debug.Log("KK: Found SCENARIO named KKStatics");
                    foreach (ConfigNode insins in ins.GetNodes("KKStatic"))
                    {
                        // Debug.Log("KK: Found a KKStatic");
                        string sRadPos = insins.GetValue("RadialPosition");
                        if (sRadPos == FacilityKey.ToString())
                        {
                            foreach (string sAtt in pStringAttributes)
                            {
                                if (insins.GetValue(sAtt) != null)
                                {
                                    obj.setSetting(sAtt, insins.GetValue(sAtt));
                                }
                            }
                            foreach (string sAtt2 in pFloatAttributes)
                            {
                                if (insins.GetValue(sAtt2) != null)
                                {
                                    obj.setSetting(sAtt2, float.Parse(insins.GetValue(sAtt2)));
                                }
                            }
                            // Debug.Log("KK: Got a KKStatic key match");
                            bMatch = true;
                            break;
                        }
                    }
                    break;
                }
            }

            if (!bMatch)
            {
                // Debug.Log("KK: KKStatic not yet persistent for this save. Initialising KKStatic");
                // Model defaults initialisation
                foreach (string sAtt5 in pDefaultAttributes)
                {
                    string sDefault = "Default" + sAtt5;

                    if (obj.model.getSetting(sDefault) == null)
                    {
                        continue;
                    }

                    obj.setSetting(sAtt5, obj.model.getSetting(sDefault));
                }

                foreach (string sAtt3 in pStringAttributes)
                {
                    if (obj.getSetting(sAtt3) == null)
                    {
                        obj.setSetting(sAtt3, "None");
                    }
                }
                foreach (string sAtt4 in pFloatAttributes)
                {
                    if (obj.getSetting(sAtt4) == null)
                    {
                        obj.setSetting(sAtt4, 0f);
                    }
                }

                // Fixed intialisation
                obj.setSetting("StaffCurrent", 1f);
                obj.setSetting("TargetID", "None");
                obj.setSetting("OpenCloseState", "Closed");

                saveStaticPersistence(obj);
            }
        }
示例#18
0
 public static void UnassignToBarracks(StaticObject selectedFacility)
 {
     selectedFacility.setSetting("ProductionRateCurrent", (float)selectedFacility.getSetting("ProductionRateCurrent") + 1);
 }
        public static void doFuelIn(StaticObject selectedObject)
        {
            if (SelectedResource == null)
            {
                return;
            }
            if (SelectedTank == null)
            {
                return;
            }

            if (SelectedResource.resourceName == "MonoPropellant" && !bMoFIn)
            {
                return;
            }
            if (SelectedResource.resourceName == "LiquidFuel" && !bLqFIn)
            {
                return;
            }
            if (SelectedResource.resourceName == "Oxidizer" && !bOxFIn)
            {
                return;
            }

            if (SelectedResource.resourceName == "MonoPropellant" && fMoFCurrent >= fMoFMax)
            {
                return;
            }
            if (SelectedResource.resourceName == "LiquidFuel" && fLqFCurrent >= fLqFMax)
            {
                return;
            }
            if (SelectedResource.resourceName == "Oxidizer" && fOxFCurrent >= fOxFMax)
            {
                return;
            }

            if (SelectedResource.amount <= 0)
            {
                return;
            }

            float dStaticFuel;

            SelectedResource.amount = SelectedResource.amount - fTransferRate;
            if (SelectedResource.amount < 0)
            {
                SelectedResource.amount = 0;
            }

            if (SelectedResource.resourceName == "MonoPropellant")
            {
                dStaticFuel = ((float)selectedObject.getSetting("MoFCurrent")) + fTransferRate;
                if (dStaticFuel > fMoFMax)
                {
                    dStaticFuel = fMoFMax;
                }
                selectedObject.setSetting("MoFCurrent", dStaticFuel);
            }
            if (SelectedResource.resourceName == "LiquidFuel")
            {
                dStaticFuel = ((float)selectedObject.getSetting("LqFCurrent")) + fTransferRate;
                if (dStaticFuel > fLqFMax)
                {
                    dStaticFuel = fLqFMax;
                }
                selectedObject.setSetting("LqFCurrent", dStaticFuel);
            }
            if (SelectedResource.resourceName == "Oxidizer")
            {
                dStaticFuel = ((float)selectedObject.getSetting("OxFCurrent")) + fTransferRate;
                if (dStaticFuel > fOxFMax)
                {
                    dStaticFuel = fOxFMax;
                }
                selectedObject.setSetting("OxFCurrent", dStaticFuel);
            }
        }
示例#20
0
 public static void DrawFromBarracks(StaticObject selectedFacility)
 {
     selectedFacility.setSetting("ProductionRateCurrent", (float)selectedFacility.getSetting("ProductionRateCurrent") - 1);
 }
示例#21
0
        public static void TrackingInterface(StaticObject soStation)
        {
            fRange      = (float)soStation.getSetting("TrackingShort");
            sTargetType = (string)soStation.getSetting("TargetType");
            sTarget     = (string)soStation.getSetting("TargetID");
            fMaxAngle   = (float)soStation.getSetting("TrackingAngle");

            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;

            BoxInfo = new GUIStyle(GUI.skin.box);
            BoxInfo.normal.textColor  = Color.cyan;
            BoxInfo.fontSize          = 13;
            BoxInfo.padding.top       = 2;
            BoxInfo.padding.bottom    = 1;
            BoxInfo.padding.left      = 5;
            BoxInfo.padding.right     = 5;
            BoxInfo.normal.background = null;

            GUILayout.Space(2);

            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(5);
                GUILayout.Label("Short Range: " + (fRange / 1000f).ToString("#0") + "km", LabelInfo, GUILayout.Height(25));
                GUILayout.FlexibleSpace();
                GUILayout.Label("Max Angle: " + fMaxAngle.ToString("#0") + "°", LabelInfo, GUILayout.Height(25));

                if (KerbalKonstructs.instance.DevMode)
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Upgrade", GUILayout.Height(20), GUILayout.Width(70)))
                    {
                        ScreenMessages.PostScreenMessage("Unable to upgrade this facility. Insufficient materials.", 10, ScreenMessageStyle.LOWER_CENTER);
                    }
                }
            }
            GUILayout.EndHorizontal();

            if (KerbalKonstructs.instance.DevMode)
            {
                GUILayout.Space(1);
                GUILayout.Box("To upgrade a kerbonaut Scientist and Engineer must be at the station. Then processed ore can be ordered for delivery to the station.", BoxInfo);
            }

            GUILayout.Space(2);

            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(5);
                GUILayout.Label("Target Type: " + sTargetType, LabelInfo, GUILayout.Height(25));
                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Change", GUILayout.Height(20), GUILayout.Width(70)))
                {
                    bChangeTargetType = true;
                    sTarget           = "None";

                    if (sTargetType == "None")
                    {
                        sTargetType = "Craft";
                    }
                    else
                    if (sTargetType == "Craft")
                    {
                        sTargetType = "Celestial Body";
                    }
                    else
                    if (sTargetType == "Celestial Body")
                    {
                        sTargetType = "Asteroid";
                    }
                    else
                    if (sTargetType == "Asteroid")
                    {
                        sTargetType = "Station's Discretion";
                    }
                    else
                    if (sTargetType == "Station's Discretion")
                    {
                        sTargetType = "None";
                    }

                    FacilityManager.changeTargetType(sTargetType);

                    soStation.setSetting("TargetID", sTarget);
                    soStation.setSetting("TargetType", sTargetType);
                    PersistenceUtils.saveStaticPersistence(soStation);
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(5);

                int iU = sTarget.IndexOf("(");
                if (iU < 2)
                {
                    iU = sTarget.Length + 1;
                }

                sDisplayTarget = sTarget.Substring(0, iU - 1);

                GUILayout.Label("Tracking: " + sDisplayTarget + " ", LabelInfo, GUILayout.Height(25));
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Change", GUILayout.Height(20), GUILayout.Width(70)))
                {
                    if (sTargetType == "None" || sTargetType == "Station's Discretion")
                    {
                        ScreenMessages.PostScreenMessage("Please select a target type first.", 10, ScreenMessageStyle.LOWER_CENTER);
                    }
                    else
                    {
                        sSelectedTrackingTarget = "None";
                        FacilityManager.changeTarget(true);
                    }
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(5);

                GUILayout.Label("Status: ", LabelInfo, GUILayout.Height(25));
                string sStationStatus = "Offline";

                if (sTarget != "None")
                {
                    sStationStatus = "Error. Please reset";

                    if (sTargetType == "Craft")
                    {
                        Vessel vTargetVessel = GetTargetVessel(sTarget);

                        if (vTargetVessel == null)
                        {
                            sStationStatus = "Cannot find craft";
                        }
                        else
                        {
                            if (vTargetVessel.state == Vessel.State.DEAD)
                            {
                                sStationStatus = "Cannot find craft";
                            }
                            else
                            {
                                StationLOS = StationHasLOS(soStation, vTargetVessel);

                                if (StationLOS <= fMaxAngle)
                                {
                                    sDisplayRange = "0m";
                                    float fRangeToTarget = GetRangeToCraft(soStation, vTargetVessel);

                                    if (fRangeToTarget > 100000f)
                                    {
                                        sDisplayRange = (fRangeToTarget / 1000f).ToString("#0") + " km";
                                    }
                                    else
                                    {
                                        sDisplayRange = fRangeToTarget.ToString("#0") + "m";
                                    }

                                    if (fRangeToTarget > fRange)
                                    {
                                        sStationStatus = "Lock " + StationLOS.ToString("#0")
                                                         + "° " + sDisplayRange;
                                    }
                                    else
                                    {
                                        sStationStatus = "Lock " + StationLOS.ToString("#0") + "° " + sDisplayRange;
                                    }
                                }
                                else
                                {
                                    sStationStatus = "No lock";
                                }
                            }
                        }
                    }

                    if (sTargetType == "Asteroid")
                    {
                        Vessel vTargetVessel = GetTargetVessel(sTarget);

                        bool bAsteroidDetected = true;
                        if (vTargetVessel == null)
                        {
                            bAsteroidDetected = false;
                        }
                        else
                        {
                            if (vTargetVessel.state == Vessel.State.DEAD)
                            {
                                bAsteroidDetected = false;
                            }
                        }

                        if (!bAsteroidDetected)
                        {
                            sStationStatus = "Cannot find asteroid";
                        }
                        else
                        {
                            StationLOS = StationHasLOS(soStation, vTargetVessel);

                            vTargetVessel.DiscoveryInfo.SetLastObservedTime(Planetarium.GetUniversalTime());
                            vTargetVessel.DiscoveryInfo.SetLevel((DiscoveryLevels)29);

                            if (StationLOS <= fMaxAngle)
                            {
                                sDisplayRange = "0m";
                                float fRangeToTarget = GetRangeToCraft(soStation, vTargetVessel);

                                if (fRangeToTarget > 100000f)
                                {
                                    sDisplayRange = (fRangeToTarget / 1000f).ToString("#0") + " km";
                                }
                                else
                                {
                                    sDisplayRange = fRangeToTarget.ToString("#0") + "m";
                                }

                                if (fRangeToTarget > fRange)
                                {
                                    sStationStatus = "Lock " + StationLOS.ToString("#0") + "° " + sDisplayRange;
                                }
                                else
                                {
                                    sStationStatus = "Lock " + StationLOS.ToString("#0") + "° " + sDisplayRange;
                                }
                            }
                            else
                            {
                                sStationStatus = "No lock";
                            }
                        }
                    }

                    if (sTargetType == "Celestial Body")
                    {
                        CelestialBody cTargetPlanet = GetTargetPlanet(sTarget);

                        if (cTargetPlanet == null)
                        {
                            sStationStatus = "Cannot find body";
                        }
                        else
                        {
                            StationLOS = StationHasLOStoPlanet(soStation, cTargetPlanet);

                            if (StationLOS <= fMaxAngle)
                            {
                                sDisplayRange = "0m";
                                float fRangeToTarget = GetRangeToPlanet(soStation, cTargetPlanet);

                                sDisplayRange  = (fRangeToTarget / 1000f).ToString("#0") + "km";
                                sStationStatus = "Sighted " + StationLOS.ToString("#0") + "° " + sDisplayRange;
                            }
                            else
                            {
                                sStationStatus = "No sighting";
                            }
                        }
                    }
                }

                if (sTargetType == "Station's Discretion")
                {
                    sStationStatus = " Busy ";
                }

                GUILayout.Label(sStationStatus, LabelInfo, GUILayout.Height(30));
                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Stop", GUILayout.Height(20), GUILayout.Width(70)))
                {
                    sTargetType = "None";
                    sTarget     = "None";
                    soStation.setSetting("TargetType", sTargetType);
                    soStation.setSetting("TargetID", sTarget);
                    PersistenceUtils.saveStaticPersistence(soStation);
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(5);
        }
示例#22
0
        public static void getClosestSpaceCenter(Vector3 position, out SpaceCenter ClosestCenter, out float ClosestDistance,
                                                 out float RecoveryFactor, out float RecoveryRange, out string BaseName)
        {
            CustomSpaceCenter closest = null;

            float smallestDist = Vector3.Distance(KSC.gameObject.transform.position, position);
            // Debug.Log("KK: Distance to KSC is " + smallestDist);

            bool isCareer = false;

            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                if (!KerbalKonstructs.instance.disableCareerStrategyLayer)
                {
                    isCareer = true;
                    PersistenceFile <LaunchSite> .LoadList(LaunchSiteManager.AllLaunchSites, "LAUNCHSITES", "KK");
                }
            }

            string sOpenCloseState  = "Closed";
            string sBaseName        = "";
            float  fMyBaseRecovFact = 0f;
            float  fMyBaseRecovRang = 0f;

            foreach (CustomSpaceCenter csc in spaceCenters)
            {
                if (isCareer)
                {
                    string OpenCloseState;
                    float  OpenCost;
                    // ASH Get openclosestate of launchsite with same name as space centre
                    LaunchSiteManager.getSiteOpenCloseState(csc.SpaceCenterName, out OpenCloseState, out OpenCost);
                    sOpenCloseState = OpenCloseState;
                }

                StaticObject myBase = csc.getStaticObject();
                if ((float)myBase.getSetting("RecoveryFactor") == 0)
                {
                    continue;
                }

                float dist = Vector3.Distance(position, csc.getStaticObject().gameObject.transform.position);

                if (dist < smallestDist)
                {
                    bool bBaseIsOpen = true;
                    if (sOpenCloseState == "Closed" || sOpenCloseState == "ClosedLocked" || sOpenCloseState == "OpenLocked")
                    {
                        bBaseIsOpen = false;
                    }

                    if (isCareer && !bBaseIsOpen)
                    {
                    }
                    else
                    {
                        closest          = csc;
                        smallestDist     = dist;
                        fMyBaseRecovFact = (float)myBase.getSetting("RecoveryFactor");
                        fMyBaseRecovRang = (float)myBase.getSetting("RecoveryRange");
                        sBaseName        = (string)myBase.getSetting("LaunchSiteName");
                        // Debug.Log("KK: closest updated to " + closest.SpaceCenterName + ", distance " + smallestDist);
                    }
                }
            }

            SpaceCenter sc;

            if (closest == null)
            {
                sc = null;
            }
            else
            {
                // Debug.Log("KK: closest is " + closest.SpaceCenterName);
                sc = closest.getSpaceCenter();
            }

            // Debug.Log("KK: smallestDist is " + smallestDist);
            // Debug.Log("KK: returning closest space centre: " + sc.name);


            if (smallestDist < 1)
            {
                smallestDist = 0;
            }
            if (sc == null)
            {
                sc = KSC;
                fMyBaseRecovFact = 100;
                sBaseName        = "KSC";
            }

            ClosestCenter   = sc;
            ClosestDistance = smallestDist;
            RecoveryFactor  = fMyBaseRecovFact;
            RecoveryRange   = fMyBaseRecovRang;
            BaseName        = sBaseName;
        }
示例#23
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));
        }
        public static void HangarInterface(StaticObject selectedFacility)
        {
            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;

            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
                            {
                                MiscUtils.HUDMessage("Cannot roll craft out. Clear the way first!", 10,
                                                     3);
                            }
                        }
                        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
                            {
                                MiscUtils.HUDMessage("Cannot roll craft out. Clear the way first!", 10,
                                                     3);
                            }
                        }
                        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
                            {
                                MiscUtils.HUDMessage("Cannot roll craft out. Clear the way first!", 10,
                                                     3);
                            }
                        }
                        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)
                    {
                        MiscUtils.HUDMessage("Craft too heavy for this facility. Max " + fMaxMass.ToString("#0") + "T per craft.", 10,
                                             3);
                    }
                    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
                        {
                            MiscUtils.HUDMessage("This facility is full. Max craft: " + fMaxCraft.ToString("#0"), 10,
                                                 3);
                        }
                    }
                }
            }

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

            GUILayout.EndScrollView();

            GUILayout.FlexibleSpace();
        }
        public static void CacheHangaredCraft(StaticObject obj)
        {
            string sInStorage  = (string)obj.getSetting("InStorage");
            string sInStorage2 = (string)obj.getSetting("TargetID");
            string sInStorage3 = (string)obj.getSetting("TargetType");

            foreach (Vessel vVesselStored in FlightGlobals.Vessels)
            {
                if (vVesselStored == null)
                {
                    continue;
                }
                if (!vVesselStored.loaded)
                {
                    continue;
                }
                if (vVesselStored.vesselType == VesselType.SpaceObject)
                {
                    continue;
                }
                if (vVesselStored.vesselType == VesselType.Debris)
                {
                    continue;
                }
                if (vVesselStored.vesselType == VesselType.EVA)
                {
                    continue;
                }
                if (vVesselStored.vesselType == VesselType.Flag)
                {
                    continue;
                }
                if (vVesselStored.vesselType == VesselType.Unknown)
                {
                    continue;
                }

                string sHangarSpace = "None";
                // If a vessel is hangared
                if (vVesselStored.id.ToString() == sInStorage)
                {
                    sHangarSpace = "InStorage";
                }
                if (vVesselStored.id.ToString() == sInStorage2)
                {
                    sHangarSpace = "TargetID";
                }
                if (vVesselStored.id.ToString() == sInStorage3)
                {
                    sHangarSpace = "TargetType";
                }

                if (sHangarSpace != "None")
                {
                    if (vVesselStored == FlightGlobals.ActiveVessel)
                    {
                        // Craft has been taken control
                        // Empty the hangar
                        obj.setSetting(sHangarSpace, "None");
                        PersistenceUtils.saveStaticPersistence(obj);
                    }
                    else
                    {
                        // Hide the vessel - it is in the hangar
                        if (vVesselStored != null)
                        {
                            foreach (Part p in vVesselStored.Parts)
                            {
                                if (p != null && p.gameObject != null)
                                {
                                    p.gameObject.SetActive(false);
                                }
                                else
                                {
                                    continue;
                                }
                            }

                            vVesselStored.MakeInactive();
                            vVesselStored.enabled = false;

                            if (vVesselStored.loaded)
                            {
                                vVesselStored.Unload();
                            }
                        }
                    }
                }
            }
        }
        public static void OpenCloseFacility(StaticObject selectedFacility)
        {
            BoxInfo = new GUIStyle(GUI.skin.box);
            BoxInfo.normal.textColor  = Color.white;
            BoxInfo.fontSize          = 12;
            BoxInfo.padding.top       = 2;
            BoxInfo.padding.bottom    = 1;
            BoxInfo.padding.left      = 5;
            BoxInfo.padding.right     = 5;
            BoxInfo.normal.background = null;

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

            float iFundsOpen2       = (float)selectedFacility.getSetting("OpenCost");
            float iFundsClose2      = (float)selectedFacility.getSetting("CloseValue");
            float iFundsDefaultCost = (float)selectedFacility.model.getSetting("cost");

            bool isAlwaysOpen2   = false;
            bool cannotBeClosed2 = false;

            // Career mode
            // If a launchsite is 0 to open it is always open
            if (iFundsOpen2 == 0 && iFundsDefaultCost == 0)
            {
                isAlwaysOpen2 = true;
            }

            // If it is 0 to close you cannot close it
            if (iFundsClose2 == 0 && iFundsDefaultCost == 0)
            {
                cannotBeClosed2 = true;
            }

            if (MiscUtils.isCareerGame())
            {
                bool isOpen2 = ((string)selectedFacility.getSetting("OpenCloseState") == "Open");

                GUILayout.BeginHorizontal();
                {
                    if (!isAlwaysOpen2)
                    {
                        GUI.enabled = !isOpen2;

                        if (iFundsOpen2 == 0)
                        {
                            iFundsOpen2 = iFundsDefaultCost;
                        }

                        if (GUILayout.Button("Open for \n" + iFundsOpen2 + " funds", ButtonSmallText, GUILayout.Height(30)))
                        {
                            double currentfunds2 = Funding.Instance.Funds;

                            if (iFundsOpen2 > currentfunds2)
                            {
                                MiscUtils.HUDMessage("Insufficient funds to open this facility!", 10, 0);
                            }
                            else
                            {
                                // Open the site - save to instance
                                selectedFacility.setSetting("OpenCloseState", "Open");

                                // Charge some funds
                                Funding.Instance.AddFunds(-iFundsOpen2, TransactionReasons.Cheating);

                                // Save new state to persistence
                                PersistenceUtils.saveStaticPersistence(selectedFacility);

                                storedEventso = selectedFacility;
                                if (evFacilityOpened != null)
                                {
                                    evFacilityOpened();
                                }

                                //PersistenceUtils.saveRTCareerBackup();
                            }
                        }
                        GUI.enabled = true;
                    }
                    else
                    {
                        // GUILayout.Box("This facility is always open.", BoxInfo);
                    }

                    if (!cannotBeClosed2)
                    {
                        GUI.enabled = isOpen2;

                        if (iFundsClose2 == 0)
                        {
                            iFundsClose2 = iFundsDefaultCost / 4;
                        }

                        if (GUILayout.Button("Close for \n" + iFundsClose2 + " funds", ButtonSmallText, GUILayout.Height(30)))
                        {
                            // Close the site - save to instance
                            // Pay back some funds
                            Funding.Instance.AddFunds(iFundsClose2, TransactionReasons.Cheating);
                            selectedFacility.setSetting("OpenCloseState", "Closed");

                            // Save new state to persistence
                            PersistenceUtils.saveStaticPersistence(selectedFacility);

                            storedEventso = selectedFacility;
                            if (evFacilityClosed != null)
                            {
                                evFacilityClosed();
                            }
                            //PersistenceUtils.saveRTCareerBackup();
                        }
                        GUI.enabled = true;
                    }
                    else
                    {
                        // GUILayout.Box("This facility cannot be closed.", BoxInfo);
                    }
                }
                GUILayout.EndHorizontal();
            }
        }
        public static void FuelTanksInterface(StaticObject selectedObject)
        {
            string smessage = "";

            string sFacilityName = (string)selectedObject.model.getSetting("title");
            string sFacilityRole = (string)selectedObject.getSetting("FacilityType");

            fLqFMax     = (float)selectedObject.model.getSetting("LqFMax");
            fLqFCurrent = (float)selectedObject.getSetting("LqFCurrent");
            fOxFMax     = (float)selectedObject.model.getSetting("OxFMax");
            fOxFCurrent = (float)selectedObject.getSetting("OxFCurrent");
            fMoFMax     = (float)selectedObject.model.getSetting("MoFMax");
            fMoFCurrent = (float)selectedObject.getSetting("MoFCurrent");

            float fPurchaseRate = fTransferRate * 100f;

            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;

            BoxInfo = new GUIStyle(GUI.skin.box);
            BoxInfo.normal.textColor  = Color.cyan;
            BoxInfo.fontSize          = 13;
            BoxInfo.padding.top       = 2;
            BoxInfo.padding.bottom    = 1;
            BoxInfo.padding.left      = 5;
            BoxInfo.padding.right     = 5;
            BoxInfo.normal.background = null;

            if (!FlightGlobals.ActiveVessel.Landed)
            {
                GUILayout.Box("A vessel must be landed to use this facility.", BoxInfo);
                LockFuelTank();
            }

            var vDist = Vector3.Distance(selectedObject.gameObject.transform.position, FlightGlobals.ActiveVessel.transform.position);

            if ((double)vDist < KerbalKonstructs.instance.facilityUseRange)
            {
            }
            else
            {
                GUILayout.Box("A vessel must be in range to use this facility.", BoxInfo);
                LockFuelTank();
            }

            GUILayout.Space(3);
            GUILayout.Label("Fuel Stores", LabelInfo);
            scrollPos4 = GUILayout.BeginScrollView(scrollPos4);
            if (fLqFMax > 0)
            {
                GUILayout.Label("LiquidFuel", LabelInfo);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(string.Format("{0}", fLqFMax), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.Label("Current ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(fLqFCurrent.ToString("#0.00"), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Order", GUILayout.Height(18)))
                {
                    LockFuelTank();
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedLqF = true;
                }
                GUI.enabled = !bLqFIn;
                if (GUILayout.Button("In", GUILayout.Height(18)))
                {
                    bLqFIn  = true;
                    bLqFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = !bLqFOut;
                if (GUILayout.Button("Out", GUILayout.Height(18)))
                {
                    bLqFOut = true;
                    bLqFIn  = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = bLqFIn || bLqFOut;
                if (GUILayout.Button("Stop", GUILayout.Height(18)))
                {
                    bLqFIn  = false;
                    bLqFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer stopped";
                    MiscUtils.HUDMessage(smessage, 10, 2);
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();
            }

            if (bOrderedLqF)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.RepeatButton("-", GUILayout.Height(18)))
                {
                    fLqFAmount = (float.Parse(fLqFAmount) - fPurchaseRate).ToString();
                    if ((float.Parse(fLqFAmount)) < 0f)
                    {
                        fLqFAmount = "0.00";
                    }
                }
                GUI.enabled = false;
                GUILayout.TextField(fLqFAmount, GUILayout.Height(18));
                GUI.enabled = true;
                if (GUILayout.RepeatButton("+", GUILayout.Height(18)))
                {
                    fLqFAmount = (float.Parse(fLqFAmount) + fPurchaseRate).ToString();
                    if ((float.Parse(fLqFAmount)) > (fLqFMax - fLqFCurrent))
                    {
                        fLqFAmount = (fLqFMax - fLqFCurrent).ToString();
                    }
                }

                if (GUILayout.Button("Max", GUILayout.Height(18)))
                {
                    fLqFAmount = (fLqFMax - fLqFCurrent).ToString();
                    if ((float.Parse(fLqFAmount)) < 0f)
                    {
                        fLqFAmount = "0.00";
                    }
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }

                float flqFPrice = 0.5f;

                float fLqFCost = (float.Parse(fLqFAmount)) * flqFPrice;
                GUILayout.Label("Cost: " + fLqFCost.ToString("#0") + " \\F", LabelInfo);
                if (GUILayout.Button("Buy", GUILayout.Height(18)))
                {
                    if ((float)selectedObject.getSetting("LqFCurrent") + (float.Parse(fLqFAmount)) > fLqFMax)
                    {
                        MiscUtils.HUDMessage("Insufficient fuel capacity!", 10, 0);
                        fLqFAmount = "0.00";
                    }
                    else
                    {
                        if (MiscUtils.isCareerGame())
                        {
                            double currentfunds = Funding.Instance.Funds;

                            if (fLqFCost > currentfunds)
                            {
                                MiscUtils.HUDMessage("Insufficient funds!", 10, 0);
                            }
                            else
                            {
                                Funding.Instance.AddFunds(-fLqFCost, TransactionReasons.Cheating);
                                selectedObject.setSetting("LqFCurrent", (float)selectedObject.getSetting("LqFCurrent") + (float.Parse(fLqFAmount)));
                            }
                        }
                        else
                        {
                            selectedObject.setSetting("LqFCurrent", (float)selectedObject.getSetting("LqFCurrent") + (float.Parse(fLqFAmount)));
                        }
                    }

                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                if (GUILayout.Button("Done", GUILayout.Height(18)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedLqF = false;
                }
                GUILayout.EndHorizontal();
            }

            if (fOxFMax > 0)
            {
                GUILayout.Label("Oxidizer", LabelInfo);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(string.Format("{0}", fOxFMax), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.Label("Current ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(fOxFCurrent.ToString("#0.00"), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Order", GUILayout.Height(18)))
                {
                    LockFuelTank();
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedOxF = true;
                }
                GUI.enabled = !bOxFIn;
                if (GUILayout.Button("In", GUILayout.Height(18)))
                {
                    bOxFIn  = true;
                    bOxFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = !bOxFOut;
                if (GUILayout.Button("Out", GUILayout.Height(18)))
                {
                    bOxFOut = true;
                    bOxFIn  = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = bOxFIn || bOxFOut;
                if (GUILayout.Button("Stop", GUILayout.Height(18)))
                {
                    bOxFIn  = false;
                    bOxFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer stopped";
                    MiscUtils.HUDMessage(smessage, 10, 2);
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();
            }

            if (bOrderedOxF)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.RepeatButton("-", GUILayout.Height(18)))
                {
                    fOxFAmount = (float.Parse(fOxFAmount) - fPurchaseRate).ToString();
                    if ((float.Parse(fOxFAmount)) < 0f)
                    {
                        fOxFAmount = "0.00";
                    }
                }
                GUI.enabled = false;
                GUILayout.TextField(fOxFAmount, GUILayout.Height(18));
                GUI.enabled = true;
                if (GUILayout.RepeatButton("+", GUILayout.Height(18)))
                {
                    fOxFAmount = (float.Parse(fOxFAmount) + fPurchaseRate).ToString();
                    if ((float.Parse(fOxFAmount)) > (fOxFMax - fOxFCurrent))
                    {
                        fOxFAmount = (fOxFMax - fOxFCurrent).ToString();
                    }
                }

                if (GUILayout.Button("Max", GUILayout.Height(18)))
                {
                    fOxFAmount = (fOxFMax - fOxFCurrent).ToString();
                    if ((float.Parse(fOxFAmount)) < 0f)
                    {
                        fOxFAmount = "0.00";
                    }
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }

                float fOxFPrice = 1.5f;

                float fOxFCost = (float.Parse(fOxFAmount)) * fOxFPrice;
                GUILayout.Label("Cost: " + fOxFCost.ToString("#0") + " \\F", LabelInfo);
                if (GUILayout.Button("Buy", GUILayout.Height(18)))
                {
                    if ((float)selectedObject.getSetting("OxFCurrent") + (float.Parse(fOxFAmount)) > fOxFMax)
                    {
                        MiscUtils.HUDMessage("Insufficient fuel capacity!", 10, 0);
                        fOxFAmount = "0.00";
                    }
                    else
                    {
                        if (MiscUtils.isCareerGame())
                        {
                            double currentfunds = Funding.Instance.Funds;

                            if (fOxFCost > currentfunds)
                            {
                                MiscUtils.HUDMessage("Insufficient funds!", 10, 0);
                            }
                            else
                            {
                                Funding.Instance.AddFunds(-fOxFCost, TransactionReasons.Cheating);
                                selectedObject.setSetting("OxFCurrent", (float)selectedObject.getSetting("OxFCurrent") + (float.Parse(fOxFAmount)));
                            }
                        }
                        else
                        {
                            selectedObject.setSetting("OxFCurrent", (float)selectedObject.getSetting("OxFCurrent") + (float.Parse(fOxFAmount)));
                        }
                    }

                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                if (GUILayout.Button("Done", GUILayout.Height(18)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedOxF = false;
                }
                GUILayout.EndHorizontal();
            }

            if (fMoFMax > 0)
            {
                GUILayout.Label("Monopropellant", LabelInfo);

                GUILayout.BeginHorizontal();
                GUILayout.Label("Max ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(string.Format("{0}", fMoFMax), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.Label("Current ", LabelInfo);
                GUI.enabled = false;
                GUILayout.TextField(fMoFCurrent.ToString("#0.00"), GUILayout.Height(18));
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Order", GUILayout.Height(18)))
                {
                    LockFuelTank();
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedMoF = true;
                }
                GUI.enabled = !bMoFIn;
                if (GUILayout.Button("In", GUILayout.Height(18)))
                {
                    bMoFIn  = true;
                    bMoFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = !bMoFOut;
                if (GUILayout.Button("Out", GUILayout.Height(18)))
                {
                    bMoFOut = true;
                    bMoFIn  = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                GUI.enabled = bMoFIn || bMoFOut;
                if (GUILayout.Button("Stop", GUILayout.Height(18)))
                {
                    bMoFIn  = false;
                    bMoFOut = false;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer stopped";
                    MiscUtils.HUDMessage(smessage, 10, 2);
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();
            }

            if (bOrderedMoF)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.RepeatButton("-", GUILayout.Height(18)))
                {
                    fMoFAmount = (float.Parse(fMoFAmount) - fPurchaseRate).ToString();
                    if ((float.Parse(fMoFAmount)) < 0f)
                    {
                        fMoFAmount = "0.00";
                    }
                }
                GUI.enabled = false;
                GUILayout.TextField(fMoFAmount, GUILayout.Height(18));
                GUI.enabled = true;
                if (GUILayout.RepeatButton("+", GUILayout.Height(18)))
                {
                    fMoFAmount = (float.Parse(fMoFAmount) + fPurchaseRate).ToString();
                    if ((float.Parse(fMoFAmount)) > (fMoFMax - fMoFCurrent))
                    {
                        fMoFAmount = (fMoFMax - fMoFCurrent).ToString();
                    }
                }

                if (GUILayout.Button("Max", GUILayout.Height(18)))
                {
                    fMoFAmount = (fMoFMax - fMoFCurrent).ToString();
                    if ((float.Parse(fMoFAmount)) < 0f)
                    {
                        fMoFAmount = "0.00";
                    }
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }

                float fMoFPrice = 1.2f;

                float fMoFCost = (float.Parse(fMoFAmount)) * fMoFPrice;
                GUILayout.Label("Cost: " + fMoFCost.ToString("#0") + " \\F", LabelInfo);
                if (GUILayout.Button("Buy", GUILayout.Height(18)))
                {
                    if ((float)selectedObject.getSetting("MoFCurrent") + (float.Parse(fMoFAmount)) > fMoFMax)
                    {
                        MiscUtils.HUDMessage("Insufficient fuel capacity!", 10, 0);
                        fMoFAmount = "0.00";
                    }
                    else
                    {
                        if (MiscUtils.isCareerGame())
                        {
                            double currentfunds = Funding.Instance.Funds;

                            if (fMoFCost > currentfunds)
                            {
                                MiscUtils.HUDMessage("Insufficient funds!", 10, 0);
                            }
                            else
                            {
                                Funding.Instance.AddFunds(-fMoFCost, TransactionReasons.Cheating);
                                selectedObject.setSetting("MoFCurrent", (float)selectedObject.getSetting("MoFCurrent") + (float.Parse(fMoFAmount)));
                            }
                        }
                        else
                        {
                            selectedObject.setSetting("MoFCurrent", (float)selectedObject.getSetting("MoFCurrent") + (float.Parse(fMoFAmount)));
                        }
                    }

                    PersistenceUtils.saveStaticPersistence(selectedObject);
                }
                if (GUILayout.Button("Done", GUILayout.Height(18)))
                {
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    bOrderedMoF = false;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();

            if (fOxFMax > 0 || fLqFMax > 0 || fMoFMax > 0)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Transfer Rate", LabelInfo);

                GUI.enabled = (fTransferRate != 0.01f);
                if (GUILayout.Button(" x1", GUILayout.Height(18)))
                {
                    fTransferRate = 0.01f;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer rate set to x1";
                    MiscUtils.HUDMessage(smessage, 10, 2);
                }
                GUI.enabled = (fTransferRate != 0.04f);
                if (GUILayout.Button(" x4", GUILayout.Height(18)))
                {
                    fTransferRate = 0.04f;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer rate set to x4";
                    MiscUtils.HUDMessage(smessage, 10, 2);
                }
                GUI.enabled = (fTransferRate != 0.1f);
                if (GUILayout.Button("x10", GUILayout.Height(18)))
                {
                    fTransferRate = 0.1f;
                    PersistenceUtils.saveStaticPersistence(selectedObject);
                    smessage = "Fuel transfer rate set to x10";
                    MiscUtils.HUDMessage(smessage, 10, 2);
                }
                GUI.enabled = true;
                GUILayout.EndHorizontal();

                if (!FlightGlobals.ActiveVessel.isEVA && FlightGlobals.ActiveVessel.Landed)
                {
                    GUILayout.Label(FlightGlobals.ActiveVessel.vesselName + "'s Tanks", LabelInfo);

                    scrollPos3 = GUILayout.BeginScrollView(scrollPos3);
                    foreach (Part fTank in FlightGlobals.ActiveVessel.parts)
                    {
                        foreach (PartResource rResource in fTank.Resources)
                        {
                            if (rResource.resourceName == "LiquidFuel" || rResource.resourceName == "Oxidizer" || rResource.resourceName == "MonoPropellant")
                            {
                                if (SelectedTank == fTank && SelectedResource == rResource)
                                {
                                    PartSelected = true;
                                }
                                else
                                {
                                    PartSelected = false;
                                }

                                GUILayout.BeginHorizontal();
                                GUILayout.Box("" + fTank.gameObject.name, GUILayout.Height(18));
                                GUILayout.Box("" + rResource.resourceName, GUILayout.Height(18));
                                GUILayout.EndHorizontal();

                                GUILayout.BeginHorizontal();
                                GUILayout.Label("Fuel", LabelInfo);
                                GUI.enabled = false;
                                GUILayout.TextField("" + rResource.amount.ToString("#0.00"), GUILayout.Height(18));
                                GUI.enabled = true;

                                GUI.enabled = !PartSelected;
                                if (GUILayout.Button(" Select ", GUILayout.Height(18)))
                                {
                                    SelectedResource = rResource;
                                    SelectedTank     = fTank;
                                    PersistenceUtils.saveStaticPersistence(selectedObject);
                                }

                                GUI.enabled = PartSelected;
                                if (GUILayout.Button("Deselect", GUILayout.Height(18)))
                                {
                                    SelectedResource = null;
                                    SelectedTank     = null;
                                    PersistenceUtils.saveStaticPersistence(selectedObject);
                                }
                                GUI.enabled = true;
                                GUILayout.EndHorizontal();
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    GUILayout.EndScrollView();

                    GUI.enabled = true;

                    if (SelectedResource != null && SelectedTank != null)
                    {
                        if (bMoFOut || bOxFOut || bLqFOut)
                        {
                            doFuelOut(selectedObject);
                        }
                        if (bMoFIn || bOxFIn || bLqFIn)
                        {
                            doFuelIn(selectedObject);
                        }
                    }
                }
            }

            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
        public static void saveStaticPersistence(StaticObject obj)
        {
            Boolean bFoundStatic = false;

            // Debug.Log("KK: saveStaticPersistence");
            var FacilityKey = obj.getSetting("RadialPosition");
            // Debug.Log("KK: FacilityKey is " + FacilityKey.ToString());

            string saveConfigPath = string.Format("{0}saves/{1}/KKFacilities.cfg", KSPUtil.ApplicationRootPath, HighLogic.SaveFolder);

            ConfigNode rootNode = new ConfigNode();

            if (!File.Exists(saveConfigPath))
            {
                ConfigNode GameNode     = rootNode.AddNode("GAME");
                ConfigNode ScenarioNode = GameNode.AddNode("SCENARIO");
                ScenarioNode.AddValue("Name", "KKStatics");
                rootNode.Save(saveConfigPath);
            }

            rootNode = ConfigNode.Load(saveConfigPath);

            ConfigNode rootrootNode = rootNode.GetNode("GAME");
            ConfigNode cnHolder     = new ConfigNode();

            foreach (ConfigNode ins in rootrootNode.GetNodes("SCENARIO"))
            {
                cnHolder = ins;
                foreach (ConfigNode insins in ins.GetNodes("KKStatic"))
                {
                    // Debug.Log("KK: Found a KKStatic");
                    string sRadPos = insins.GetValue("RadialPosition");

                    if (sRadPos == null)
                    {
                        Debug.Log("KK: Got a KKStatic but it has no key! WTF?????");
                        continue;
                    }

                    if (sRadPos == FacilityKey.ToString())
                    {
                        // Debug.Log("KK: Got a KKStatic key match - editing the node");
                        foreach (string sAtt in pAttributes)
                        {
                            if (insins.HasValue(sAtt))
                            {
                                insins.RemoveValue(sAtt);
                            }

                            if (obj.getSetting(sAtt) != null)
                            {
                                insins.AddValue(sAtt, obj.getSetting(sAtt).ToString());
                            }
                        }

                        bFoundStatic = true;
                        break;
                    }
                }
            }

            if (!bFoundStatic)
            {
                // Debug.Log("KK: No KKStatic found. Creating a new node.");
                ConfigNode newStatic = new ConfigNode("KKStatic");

                foreach (string sAtt in pAttributes)
                {
                    if (obj.getSetting(sAtt) != null)
                    {
                        newStatic.AddValue(sAtt, obj.getSetting(sAtt).ToString());
                    }
                }

                cnHolder.AddNode(newStatic);
            }

            // Debug.Log("KK: rootNode.save");
            rootNode.Save(saveConfigPath);
        }
        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"));
            }
        }
        public static void doFuelOut(StaticObject selectedObject)
        {
            if (SelectedResource == null)
            {
                return;
            }
            if (SelectedTank == null)
            {
                return;
            }

            if (SelectedResource.resourceName == "MonoPropellant" && !bMoFOut)
            {
                return;
            }
            if (SelectedResource.resourceName == "LiquidFuel" && !bLqFOut)
            {
                return;
            }
            if (SelectedResource.resourceName == "Oxidizer" && !bOxFOut)
            {
                return;
            }

            if (SelectedResource.resourceName == "MonoPropellant" && fMoFCurrent <= 0)
            {
                return;
            }
            if (SelectedResource.resourceName == "LiquidFuel" && fLqFCurrent <= 0)
            {
                return;
            }
            if (SelectedResource.resourceName == "Oxidizer" && fOxFCurrent <= 0)
            {
                return;
            }

            if (SelectedResource.amount >= SelectedResource.maxAmount)
            {
                return;
            }

            float dStaticFuel;

            SelectedResource.amount = SelectedResource.amount + fTransferRate;
            if (SelectedResource.amount > SelectedResource.maxAmount)
            {
                SelectedResource.amount = SelectedResource.maxAmount;
            }

            if (SelectedResource.resourceName == "MonoPropellant")
            {
                dStaticFuel = ((float)selectedObject.getSetting("MoFCurrent")) - fTransferRate;
                if (dStaticFuel < 0)
                {
                    dStaticFuel = 0;
                }
                selectedObject.setSetting("MoFCurrent", dStaticFuel);
            }
            if (SelectedResource.resourceName == "LiquidFuel")
            {
                dStaticFuel = ((float)selectedObject.getSetting("LqFCurrent")) - fTransferRate;
                if (dStaticFuel < 0)
                {
                    dStaticFuel = 0;
                }
                selectedObject.setSetting("LqFCurrent", dStaticFuel);
            }
            if (SelectedResource.resourceName == "Oxidizer")
            {
                dStaticFuel = ((float)selectedObject.getSetting("OxFCurrent")) - fTransferRate;
                if (dStaticFuel < 0)
                {
                    dStaticFuel = 0;
                }
                selectedObject.setSetting("OxFCurrent", dStaticFuel);
            }
        }