Exemple #1
0
        // Returns a specific Launchsite, keyed by site.name
        public static LaunchSite getLaunchSiteByName(string sSiteName, bool bRemember = false)
        {
            if (bRemember)
            {
                if (sBaseMem == sSiteName)
                {
                    return(launchsitemem);
                }
            }

            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in sites)
            {
                if (site.name == sSiteName)
                {
                    if (bRemember)
                    {
                        sBaseMem      = sSiteName;
                        launchsitemem = site;
                    }
                    return(site);
                }
            }

            return(null);
        }
        public static void setAllLaunchsitesClosed()
        {
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in sites)
            {
                site.setOpenClose("Closed");
            }
        }
Exemple #3
0
        public static void setAllLaunchsitesClosed()
        {
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in sites)
            {
                site.openclosestate = "Closed";
            }
        }
        // Get nearest base, either open or closed, and the range to it
        public static void getNearestBase(Vector3 position, out string sBase, out float flRange, out LaunchSite lSite)
        {
            SpaceCenter KSC          = SpaceCenter.Instance;
            var         smallestDist = Vector3.Distance(KSC.gameObject.transform.position, position);
            string      sNearestBase = "";
            LaunchSite  lTargetSite  = null;
            LaunchSite  lKSC         = null;

            List <LaunchSite> basesites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in basesites)
            {
                if (site.GameObject == null)
                {
                    continue;
                }
                //if (site.recoveryfactor == 0) continue;

                var radialposition = site.GameObject.transform.position;
                var dist           = Vector3.Distance(position, radialposition);

                if (site.name == "Runway" || site.name == "LaunchPad")
                {
                    lKSC = site;
                }
                else
                {
                    if ((float)dist < (float)smallestDist)
                    {
                        {
                            sNearestBase = site.name;
                            smallestDist = dist;
                            lTargetSite  = site;
                        }
                    }
                }
            }

            if (sNearestBase == "")
            {
                sNearestBase = "KSC";
                lTargetSite  = lKSC;
            }

            RangeNearestBase = (float)smallestDist;

            sBase   = sNearestBase;
            flRange = RangeNearestBase;
            lSite   = lTargetSite;
        }
        public static GameObject getSiteGameObject(string sSiteName)
        {
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in sites)
            {
                if (site.name == sSiteName)
                {
                    return(site.GameObject);
                }
            }

            return(null);
        }
Exemple #6
0
        public static bool checkLaunchSiteExists(string sSiteName)
        {
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in sites)
            {
                if (site.name == sSiteName)
                {
                    return(true);
                }
            }

            return(false);
        }
        public static void getSiteLaunchRefund(string sSiteName, out float fRefund)
        {
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in sites)
            {
                if (site.name == sSiteName)
                {
                    fRefund = site.launchrefund;
                    return;
                }
            }

            fRefund = 0;
        }
        // Open and close a launchsite
        public static void setSiteOpenCloseState(string sSiteName, string sState)
        {
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in sites)
            {
                if (site.name == sSiteName)
                {
                    site.setOpenClose(sState);
                    PersistenceFile <LaunchSite> .SaveList(sites, "LAUNCHSITES", "KK");

                    return;
                }
            }
        }
Exemple #9
0
        // Lock a launchsite so it cannot be opened or closed or launched from
        public static void setSiteLocked(string sSiteName)
        {
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in sites)
            {
                if (site.name == sSiteName)
                {
                    site.openclosestate = site.openclosestate + "Locked";
                    PersistenceFile <LaunchSite> .SaveList(sites, "LAUNCHSITES", "KK");

                    return;
                }
            }
        }
Exemple #10
0
        // Returns whether a site is closed
        public static bool getIsSiteClosed(string sSiteName)
        {
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in sites)
            {
                if (site.name == sSiteName)
                {
                    if (site.openclosestate == "Closed")
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        // Find out if a launchsite is open or closed
        public static void getSiteOpenCloseState(string sSiteName, out string sOpenCloseState, out float fOpenCost)
        {
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in sites)
            {
                if (site.name == sSiteName)
                {
                    sOpenCloseState = site.openclosestate;
                    fOpenCost       = site.opencost;
                    return;
                }
            }

            sOpenCloseState = "Open";
            fOpenCost       = 0;
        }
        public static float getDistanceToBase(Vector3 position, LaunchSite lTarget)
        {
            float flRange = 0f;

            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in sites)
            {
                if (site == lTarget)
                {
                    var radialposition = site.GameObject.transform.position;
                    var dist           = Vector3.Distance(position, radialposition);
                    flRange = dist;
                }
            }

            return(flRange);
        }
        // Get the nearest open base and range to it
        public static void getNearestOpenBase(Vector3 position, out string sBase, out float flRange, out LaunchSite lNearest)
        {
            SpaceCenter KSC             = SpaceCenter.Instance;
            var         smallestDist    = Vector3.Distance(KSC.gameObject.transform.position, position);
            string      sNearestBase    = "";
            string      sOpenCloseState = "";
            LaunchSite  lNearestBase    = null;
            LaunchSite  lKSC            = null;

            List <LaunchSite> basesites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in basesites)
            {
                sOpenCloseState = site.openclosestate;

                if (!MiscUtils.isCareerGame())
                {
                    sOpenCloseState = "Open";
                }

                //if (site.recoveryfactor == 0) continue;

                if (sOpenCloseState == "Open")
                {
                    var radialposition = site.GameObject.transform.position;
                    var dist           = Vector3.Distance(position, radialposition);

                    if (site.name == "Runway")
                    {
                        if (lNearestBase == null)
                        {
                            lNearestBase = site;
                        }
                        lKSC = site;
                    }
                    else
                    if (site.name != "LaunchPad")
                    {
                        if ((float)dist < (float)smallestDist)
                        {
                            {
                                sNearestBase = site.name;
                                lNearestBase = site;
                                smallestDist = dist;
                            }
                        }
                    }
                    else
                    {
                        lKSC = site;
                    }
                }
            }

            if (sNearestBase == "")
            {
                sNearestBase = "KSC";
                lNearestBase = lKSC;
            }

            RangeNearestOpenBase = (float)smallestDist;

            // Air traffic control messaging
            if (KerbalKonstructs.instance.enableATC)
            {
                if (sNearestBase != NearestOpenBase)
                {
                    if (RangeNearestOpenBase < 25000)
                    {
                        NearestOpenBase = sNearestBase;
                        MessageSystemButton.MessageButtonColor color = MessageSystemButton.MessageButtonColor.BLUE;
                        MessageSystem.Message m = new MessageSystem.Message("KK ATC", "You have entered the airspace of " + sNearestBase + " ATC. Please keep this channel open and obey all signal lights. Thank you. " + sNearestBase + " Air Traffic Control out.", color, MessageSystemButton.ButtonIcons.MESSAGE);
                        MessageSystem.Instance.AddMessage(m);
                    }
                    else
                    if (NearestOpenBase != "")
                    {
                        // you have left ...
                        MessageSystemButton.MessageButtonColor color = MessageSystemButton.MessageButtonColor.GREEN;
                        MessageSystem.Message m = new MessageSystem.Message("KK ATC", "You are now leaving the airspace of " + sNearestBase + ". Safe journey. " + sNearestBase + " Air Traffic Control out.", color, MessageSystemButton.ButtonIcons.MESSAGE);
                        MessageSystem.Instance.AddMessage(m);
                        NearestOpenBase = "";
                    }
                }
            }

            sBase    = sNearestBase;
            flRange  = RangeNearestOpenBase;
            lNearest = lNearestBase;
        }