Пример #1
0
        // Returns whether a site is open or closed and how much it costs to open
        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);
        }
Пример #3
0
        // Unlock a launchsite so it can be opened or closed or launched from
        public static void setSiteUnlocked(string sSiteName)
        {
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            foreach (LaunchSite site in sites)
            {
                if (site.name == sSiteName)
                {
                    if (site.openclosestate == "OpenLocked")
                    {
                        site.openclosestate = "Open";
                    }
                    else
                    {
                        site.openclosestate = "Closed";
                    }

                    PersistenceFile <LaunchSite> .SaveList(sites, "LAUNCHSITES", "KK");

                    return;
                }
            }
        }
        // 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;
        }
Пример #5
0
        // Returns the nearest Launchsite to a position and range in m to the Launchsite, regardless of whether it is open or closed
        public static void getNearestBase(Vector3 position, out string sBase, out string sBase2, out float flRange, out LaunchSite lSite, out LaunchSite lSite2)
        {
            SpaceCenter KSC              = SpaceCenter.Instance;
            var         smallestDist     = Vector3.Distance(KSC.gameObject.transform.position, position);
            var         lastSmallestDist = Vector3.Distance(KSC.gameObject.transform.position, position);
            string      sNearestBase     = "";
            LaunchSite  lTargetSite      = null;
            LaunchSite  lLastSite        = null;
            LaunchSite  lKSC             = null;
            string      sLastNearest     = "";

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

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

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

                if (radialposition == position)
                {
                    continue;
                }

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

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

            RangeNearestBase = (float)smallestDist;

            sBase   = sNearestBase;
            sBase2  = sLastNearest;
            flRange = RangeNearestBase;
            lSite   = lTargetSite;
            lSite2  = lLastSite;
        }