public LaunchSite(string sName, string sAuthor, SiteType sType, Texture sLogo, Texture sIcon,
			string sDescription, string sDevice, float fOpenCost, float fCloseValue, string sOpenCloseState, float fRefLon, 
			float fRefLat, float fRefAlt, float fLength, float fWidth, float fRefund, float fRecoveryFactor, float fRecoveryRange,
			GameObject gameObject, PSystemSetup.SpaceCenterFacility newFacility = null, string sFavourite = "No")
        {
            name = sName;
            author = sAuthor;
            type = sType;
            logo = sLogo;
            icon = sIcon;
            description = sDescription;
            category = sDevice;
            opencost = fOpenCost;
            closevalue = fCloseValue;
            openclosestate = sOpenCloseState;
            GameObject = gameObject;
            facility = newFacility;
            reflon = fRefLon;
            reflat = fRefLat;
            refalt = fRefAlt;
            sitelength = fLength;
            sitewidth = fWidth;
            launchrefund = fRefund;
            recoveryfactor = fRecoveryFactor;
            recoveryrange = fRecoveryRange;
            favouritesite = sFavourite;
        }
Пример #2
0
        public LaunchSite(string sName, string sAuthor, SiteType sType, Texture sLogo, Texture sIcon,
			string sDescription, string sDevice, float fOpenCost, float fCloseValue, string sOpenCloseState, float fRefLon, 
			float fRefLat, float fRefAlt, float fLength, float fWidth, float fRefund, float fRecoveryFactor, float fRecoveryRange,
			GameObject gameObject, PSystemSetup.SpaceCenterFacility newFacility = null, 
			string sMissionLog = "Too busy to keep this log. Signed Gene Kerman.", 
			string sNation = "United Kerbin", string sFavourite = "No", float fMissionCount = 0)
        {
            name = sName;
            author = sAuthor;
            type = sType;
            logo = sLogo;
            icon = sIcon;
            description = sDescription;
            category = sDevice;
            opencost = fOpenCost;
            closevalue = fCloseValue;
            openclosestate = sOpenCloseState;
            GameObject = gameObject;
            facility = newFacility;
            reflon = fRefLon;
            reflat = fRefLat;
            refalt = fRefAlt;
            sitelength = fLength;
            sitewidth = fWidth;
            launchrefund = fRefund;
            recoveryfactor = fRecoveryFactor;
            recoveryrange = fRecoveryRange;
            favouritesite = sFavourite;
            missioncount = fMissionCount;
            nation = sNation;
            missionlog = sMissionLog;
        }
Пример #3
0
 public LaunchSite(string sName, string sAuthor, SiteType sType, Texture sLogo, Texture sIcon,
                   string sDescription, string sDevice, float fOpenCost, float fCloseValue, string sOpenCloseState, float fRefLon,
                   float fRefLat, float fRefAlt, float fLength, float fWidth, float fRefund, float fRecoveryFactor, float fRecoveryRange,
                   GameObject gameObject, PSystemSetup.SpaceCenterFacility newFacility = null,
                   string sMissionLog = "Too busy to keep this log. Signed Gene Kerman.",
                   string sNation     = "United Kerbin", string sFavourite = "No", float fMissionCount = 0)
 {
     name           = sName;
     author         = sAuthor;
     type           = sType;
     logo           = sLogo;
     icon           = sIcon;
     description    = sDescription;
     category       = sDevice;
     opencost       = fOpenCost;
     closevalue     = fCloseValue;
     openclosestate = sOpenCloseState;
     GameObject     = gameObject;
     facility       = newFacility;
     reflon         = fRefLon;
     reflat         = fRefLat;
     refalt         = fRefAlt;
     sitelength     = fLength;
     sitewidth      = fWidth;
     launchrefund   = fRefund;
     recoveryfactor = fRecoveryFactor;
     recoveryrange  = fRecoveryRange;
     favouritesite  = sFavourite;
     missioncount   = fMissionCount;
     nation         = sNation;
     missionlog     = sMissionLog;
 }
 public LaunchSite(string sName, string sAuthor, SiteType sType, Texture sLogo, Texture sIcon,
                   string sDescription, string sDevice, float fOpenCost, float fCloseValue, string sOpenCloseState, float fRefLon,
                   float fRefLat, float fRefAlt, float fLength, float fWidth, float fRefund, float fRecoveryFactor, float fRecoveryRange,
                   GameObject gameObject, PSystemSetup.SpaceCenterFacility newFacility = null, string sFavourite = "No")
 {
     name           = sName;
     author         = sAuthor;
     type           = sType;
     logo           = sLogo;
     icon           = sIcon;
     description    = sDescription;
     category       = sDevice;
     opencost       = fOpenCost;
     closevalue     = fCloseValue;
     openclosestate = sOpenCloseState;
     GameObject     = gameObject;
     facility       = newFacility;
     reflon         = fRefLon;
     reflat         = fRefLat;
     refalt         = fRefAlt;
     sitelength     = fLength;
     sitewidth      = fWidth;
     launchrefund   = fRefund;
     recoveryfactor = fRecoveryFactor;
     recoveryrange  = fRecoveryRange;
     favouritesite  = sFavourite;
 }
Пример #5
0
        /// <summary>
        /// Registers the a created LaunchSite to the PSystemSetup and LaunchSiteManager
        /// </summary>
        /// <param name="site"></param>
        internal static void RegisterLaunchSite(LaunchSite site)
        {
            if (!string.IsNullOrEmpty(site.LaunchSiteName) && site.parentInstance.gameObject.transform.Find(site.LaunchPadTransform) != null)
            {
                site.parentInstance.gameObject.transform.name = site.LaunchSiteName;
                site.parentInstance.gameObject.name           = site.LaunchSiteName;

                List <PSystemSetup.SpaceCenterFacility> facilities = PSystemSetup.Instance.SpaceCenterFacilities.ToList();

                if (facilities.Where(fac => fac.facilityName == site.LaunchSiteName).FirstOrDefault() == null)
                {
                    //Log.Normal("Registering LaunchSite: " + site.LaunchSiteName);
                    PSystemSetup.SpaceCenterFacility newFacility = new PSystemSetup.SpaceCenterFacility();
                    newFacility.name                  = "";
                    newFacility.facilityName          = site.LaunchSiteName;
                    newFacility.facilityPQS           = site.parentInstance.CelestialBody.pqsController;
                    newFacility.facilityTransformName = site.parentInstance.gameObject.name;
                    // newFacility.facilityTransform = site.lsGameObject.transform.Find(site.LaunchPadTransform);
                    //     newFacility.facilityTransformName = instance.gameObject.transform.name;
                    newFacility.pqsName = site.body.pqsController.name;
                    PSystemSetup.SpaceCenterFacility.SpawnPoint spawnPoint = new PSystemSetup.SpaceCenterFacility.SpawnPoint();
                    spawnPoint.name = site.LaunchSiteName;
                    spawnPoint.spawnTransformURL = site.LaunchPadTransform;
                    newFacility.spawnPoints      = new PSystemSetup.SpaceCenterFacility.SpawnPoint[1];
                    newFacility.spawnPoints[0]   = spawnPoint;

                    facilities.Add(newFacility);
                    PSystemSetup.Instance.SpaceCenterFacilities = facilities.ToArray();

                    site.facility = newFacility;

                    launchSites.Add(site);
                }
                else
                {
                    Log.Error("Launch site " + site.name + " already exists.");
                }
                MethodInfo updateSitesMI = PSystemSetup.Instance.GetType().GetMethod("SetupFacilities", BindingFlags.NonPublic | BindingFlags.Instance);
                if (updateSitesMI == null)
                {
                    Log.UserError("You are screwed. Failed to find SetupFacilities().");
                }
                else
                {
                    updateSitesMI.Invoke(PSystemSetup.Instance, null);
                }

                if (site.parentInstance.gameObject != null)
                {
                    CustomSpaceCenter.CreateFromLaunchsite(site);
                }
            }
            else
            {
                Log.UserWarning("Launch pad transform \"" + site.LaunchPadTransform + "\" missing for " + site.LaunchSiteName);
            }
        }
Пример #6
0
        public static SpaceCenterFacility GetFacility(this PSystemSetup.SpaceCenterFacility spaceCenterFac)
        {
            KerbalKonstructs.instance.lastLaunchSiteUsed = spaceCenterFac.name;
            switch (spaceCenterFac.editorFacility)
            {
            case EditorFacility.VAB:
                return(SpaceCenterFacility.LaunchPad);

            case EditorFacility.SPH:
                return(SpaceCenterFacility.Runway);

            default:
                return(SpaceCenterFacility.LaunchPad);
            }
        }
Пример #7
0
		public LaunchSite(string sName, string sAuthor, SiteType sType, Texture sLogo, Texture sIcon, string sDescription, string sDevice, float fOpenCost, float fCloseValue, string sOpenCloseState, GameObject gameObject, PSystemSetup.SpaceCenterFacility newFacility = null)
		{
			name = sName;
			author = sAuthor;
			type = sType;
			logo = sLogo;
			icon = sIcon;
			description = sDescription;
			category = sDevice;
			opencost = fOpenCost;
			closevalue = fCloseValue;
			openclosestate = sOpenCloseState;
			GameObject = gameObject;
			facility = newFacility;
		}
        /// <summary>
        /// Removes the launchSite from the facilities
        /// </summary>
        /// <param name="site"></param>
        internal static void UnregisterLaunchSite(KKLaunchSite site)
        {
            if (site.isOpen)
            {
                CloseLaunchSite(site);
            }

            List <PSystemSetup.SpaceCenterFacility> spaceCenters = PSystemSetup.Instance.SpaceCenterFacilities.ToList();

            PSystemSetup.SpaceCenterFacility spaceToDel = spaceCenters.Where(x => x.facilityName == site.LaunchSiteName).FirstOrDefault();

            if (spaceToDel != null)
            {
                spaceCenters.Remove(spaceToDel);
                PSystemSetup.Instance.SpaceCenterFacilities = spaceCenters.ToArray();
                Log.Normal("Launchsite: " + site.LaunchSiteName + " sucessfully unregistered");
            }

            KKFacilities.Remove(site.spaceCenterFacility);
        }
        // Add a launchsite to the KK launchsite and custom space centre database
        // Please note there's some near hackery here to get KSP to recognise additional launchsites and space centres
        public static void createLaunchSite(StaticObject obj)
        {
            if (obj.settings.ContainsKey("LaunchSiteName") && obj.gameObject.transform.Find((string) obj.getSetting("LaunchPadTransform")) != null)
            {
                obj.gameObject.transform.name = (string) obj.getSetting("LaunchSiteName");
                obj.gameObject.name = (string) obj.getSetting("LaunchSiteName");

                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);
                var disObjectLat = dObjectLat * 180 / Math.PI;
                var disObjectLon = dObjectLon * 180 / Math.PI;

                if (disObjectLon < 0) disObjectLon = disObjectLon + 360;
                obj.setSetting("RefLatitude", (float)disObjectLat);
                obj.setSetting("RefLongitude", (float)disObjectLon);

                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;

                            Texture logo = null;
                            Texture icon = null;

                            if (obj.settings.ContainsKey("LaunchSiteLogo"))
                            {
                                string sLogoPath = (string)obj.getSetting("LaunchSiteLogo");
                                logo = GameDatabase.Instance.GetTexture(sLogoPath, false);

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

                            if (logo == null)
                                logo = defaultLaunchSiteLogo;

                            if(obj.settings.ContainsKey("LaunchSiteIcon"))
                            {
                                string sIconPath = (string)obj.getSetting("LaunchSiteIcon");
                                icon = GameDatabase.Instance.GetTexture(sIconPath, false);

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

                            // TODO This is still hard-code and needs to use an API properly
                            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,
                                newFacility,
                                "No log",
                                (string)obj.getSetting("LaunchSiteNation")
                                ));
                        }
                        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 void drawLaunchsites()
        {
            displayingTooltip = false;
            int           iPulseRate = 180;
            CelestialBody body       = PlanetariumCamera.fetch.target.GetReferenceBody();

            iRadarCounter = iRadarCounter + 1;
            if (iRadarCounter > iPulseRate)
            {
                iRadarCounter = 0;
            }

            // Then do launchsites
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            for (int index = 0; index < sites.Count; index++)
            {
                LaunchSite site = sites[index];

                // don't spam the logfile for the KSC. doesn't work roght now.
                if (site.name == "Runway" || site.name == "LaunchPad")
                {
                    continue;
                }

                // check if we should display the site or not this is the fastst check, so it shoud be first
                string openclosed = site.openclosestate;
                string category   = site.category;

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

                if (MiscUtils.isCareerGame())
                {
                    if (!KerbalKonstructs.instance.mapShowOpen && openclosed == "Open")
                    {
                        continue;
                    }
                    if (!KerbalKonstructs.instance.mapShowClosed && openclosed == "Closed")
                    {
                        continue;
                    }
                    if (KerbalKonstructs.instance.disableDisplayClosed && openclosed == "Closed")
                    {
                        continue;
                    }
                    if (openclosed == "OpenLocked" || openclosed == "ClosedLocked")
                    {
                        continue;
                    }
                }


                PSystemSetup.SpaceCenterFacility facility = PSystemSetup.Instance.GetSpaceCenterFacility(site.name);
                if (facility == null)
                {
                    continue;
                }

                PSystemSetup.SpaceCenterFacility.SpawnPoint sp = facility.GetSpawnPoint(site.name);
                if (sp == null)
                {
                    Log.Error("No Spawn Point found for: " + site.name);
                    continue;
                }

                if (facility.facilityPQS != body.pqsController)
                {
                    Log.Error("No PQS found for: " + site.name);
                    continue;
                }
                ;

                Transform spawnPointTransform = sp.GetSpawnPointTransform();
                if (spawnPointTransform == null)
                {
                    Log.Error("No Spawn PointTransform found for: " + site.name);
                    continue;
                }

                if (isOccluded((spawnPointTransform.position), body))
                {
                    if (KerbalKonstructs.instance.mapHideIconsBehindBody)
                    {
                        continue;
                    }
                }

                Vector3 pos = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(spawnPointTransform.position));

                Rect screenRect = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16);

                // Distance between camera and spawnpoint sort of
                float fPosZ = pos.z;

                float fRadarRadius = 12800 / fPosZ;
                //      Log.Warning("fRadarRadius = " + Math.Round(fRadarRadius,2));
                float fRadarOffset = fRadarRadius / 2;



                if (KerbalKonstructs.instance.mapShowRadar)
                {
                    drawRadar(pos, category, openclosed);
                }

                if (openclosed == "Open" && KerbalKonstructs.instance.mapShowGroundComms)
                {
                    drawGroundComms(null, site);
                }

                if (site.icon != null)
                {
                    if (fRadarRadius > 15)
                    {
                        GUI.DrawTexture(screenRect, site.icon, ScaleMode.ScaleToFit, true);
                    }
                }
                else
                {
                    if (fRadarRadius > 15)
                    {
                        switch (site.type)
                        {
                        case SiteType.VAB:
                            GUI.DrawTexture(screenRect, UIMain.VABIcon, ScaleMode.ScaleToFit, true);
                            break;

                        case SiteType.SPH:
                            GUI.DrawTexture(screenRect, UIMain.SPHIcon, ScaleMode.ScaleToFit, true);
                            break;

                        default:
                            GUI.DrawTexture(screenRect, UIMain.ANYIcon, ScaleMode.ScaleToFit, true);
                            break;
                        }
                    }
                }

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

                    // Select a base by clicking on the icon
                    if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
                    {
                        MiscUtils.HUDMessage("Selected base is " + sToolTip + ".", 5f, 3);
                        BaseManager.setSelectedSite(site);
                        selectedSite = site;
                        NavGuidanceSystem.setTargetSite(selectedSite);
                        WindowManager.instance.OpenWindow(KerbalKonstructs.instance.GUI_BaseManager.drawBaseManager);
                    }
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Registers the a created LaunchSite to the PSystemSetup and LaunchSiteManager
        /// </summary>
        /// <param name="site"></param>
        internal static void RegisterLaunchSite(KKLaunchSite site)
        {
            if (string.IsNullOrEmpty(site.LaunchSiteName))
            {
                Log.UserWarning("No LaunchSiteName specified:" + site);
                return;
            }


            if (site.isSquad)
            {
                if (site.staticInstance.mesh.transform.Find(site.LaunchPadTransform) == null)
                {
                    Log.UserWarning("Launch pad transform \"" + site.LaunchPadTransform + "\" missing for " + site.LaunchSiteName);
                    return;
                }
            }
            else
            {
                if (site.staticInstance.model.prefab.transform.Find(site.LaunchPadTransform) == null)
                {
                    Log.UserWarning("Launch pad transform \"" + site.LaunchPadTransform + "\" missing for " + site.LaunchSiteName);
                    return;
                }
            }

            KKFacilities = PSystemSetup.Instance.SpaceCenterFacilities.ToList();
            if (KKFacilities.Where(fac => fac.facilityName == site.LaunchSiteName).FirstOrDefault() != null)
            {
                Log.Error("Launch site " + site.LaunchSiteName + " already exists.");
            }


            //site.staticInstance.gameObject.transform.name = site.LaunchSiteName;
            //site.staticInstance.gameObject.name = site.LaunchSiteName;
            Log.Normal("Registering LaunchSite: " + site.LaunchSiteName + " isHidden: " + site.LaunchSiteIsHidden);
            PSystemSetup.SpaceCenterFacility spaceCenterFacility = new PSystemSetup.SpaceCenterFacility();
            spaceCenterFacility.name = site.LaunchSiteName;
            spaceCenterFacility.facilityDisplayName = site.LaunchSiteName;
            spaceCenterFacility.facilityName        = site.LaunchSiteName;
            spaceCenterFacility.facilityPQS         = site.staticInstance.CelestialBody.pqsController;
            spaceCenterFacility.hostBody            = site.staticInstance.CelestialBody;
            spaceCenterFacility.facilityTransform   = site.staticInstance.mesh.transform;
            if (site.LaunchSiteType == SiteType.VAB)
            {
                spaceCenterFacility.editorFacility = EditorFacility.VAB;
            }
            else
            {
                spaceCenterFacility.editorFacility = EditorFacility.SPH;
            }
            spaceCenterFacility.pqsName = site.body.pqsController.name;


            //if (site.staticInstance.groupCenter == null)
            //{
            //    spaceCenterFacility.facilityTransformName = site.staticInstance.gameObject.name;
            //}
            //else
            //{
            //    spaceCenterFacility.facilityTransformName = site.staticInstance.groupCenter.gameObject.name + "/" + site.staticInstance.gameObject.name + "/Mesh";
            //}
            // newFacility.facilityTransform = site.lsGameObject.transform.Find(site.LaunchPadTransform);
            //     newFacility.facilityTransformName = instance.gameObject.transform.name;

            PSystemSetup.SpaceCenterFacility.SpawnPoint spawnPoint = new PSystemSetup.SpaceCenterFacility.SpawnPoint
            {
                name = site.LaunchSiteName,
                spawnTransformURL = site.LaunchPadTransform
            };
            spawnPoint.Setup(spaceCenterFacility);
            spawnPoint.SetSpawnPointLatLonAlt();
            spaceCenterFacility.spawnPoints = new PSystemSetup.SpaceCenterFacility.SpawnPoint[] { spawnPoint };

            //spaceCenterFacility.Setup(new PQS[] { site.staticInstance.CelestialBody.pqsController });

            KKFacilities.Add(spaceCenterFacility);
            KKFacilities.Sort(delegate(PSystemSetup.SpaceCenterFacility a, PSystemSetup.SpaceCenterFacility b)
            {
                if (a.editorFacility == EditorFacility.None)
                {
                    return(1);
                }
                return((a.facilityDisplayName).CompareTo(b.facilityDisplayName));
            });

            PSystemSetup.Instance.SpaceCenterFacilities = KKFacilities.ToArray();
            site.spaceCenterFacility = spaceCenterFacility;

            if (site.staticInstance.destructible != null)
            {
                ScenarioDestructibles.RegisterDestructible(site.staticInstance.destructible, site.LaunchSiteName);
            }

            AddLaunchSite(site);

            if (site.staticInstance.gameObject != null)
            {
                CustomSpaceCenter.CreateFromLaunchsite(site);
            }


            //if (PSystemSetup.Instance.SpaceCenterFacilities.ToList().Where(fac => fac.facilityName == site.LaunchSiteName).FirstOrDefault() != null)
            //{
            //    Log.Normal("LaunchSite registered: " + site.LaunchSiteName);
            //}
            //else
            //{
            //    Log.Normal("LaunchSite registration failed: " + site.LaunchSiteName);
            //}
        }
		// KerbTown legacy code - TODO Review and update?
		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");
				// var x = obj.gameObject.AddComponent(typeof(UpgradeableFacility)) as UpgradeableFacility;
				// x.SetLevel(0);
				// x.setNormLevel(0);

				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;
							
							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);
							
							// 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", /*(Vector3)obj.getSetting("RadialPosition"), */obj.gameObject, 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: 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"));
			}
		}
Пример #13
0
        public void toggle()
        {
            // TODO: When leaving flight mode - revert back to normal launch site.
              // TODO: We also need to revert the launch site name if the launch fails (e.g. nothing in the editor)
              print(">>>>" + EditorLogic.fetch.launchSiteName);

              // could try:
              //SpaceTracking.GoToAndFocusVessel(v);

              // or
              //FlightDriver.StartWithNewLaunch(string fullFilePath, string missionFlagURL, string launchSiteName, VesselCrewManifest manifest);

              // or even: and we can store the previous state so that we can revert easily
              //FlightDriver.StartAndFocusVessel(Game stateToLoad, int vesselToFocusIdx);
              // See also all the other stuff in there, looks prime for it! Maybe even hack CanRevert via reflection for hardcore modes?

            #if false
              // need a game object with a transform called "SimulationLaunchSite_Spawn"

              GameObject go = new GameObject("go");

              PSystemSetup.SpaceCenterFacility newFacility = new PSystemSetup.SpaceCenterFacility();
              newFacility.name = "SimulationLaunchSite";
              newFacility.facilityName = "SimulationLaunchSite";
              newFacility.facilityPQS = ((CelestialBody)obj.getSetting("CelestialBody")).pqsController;
              newFacility.facilityTransformName = "SimulationLaunchSiteXForm";
              newFacility.pqsName = ((CelestialBody)obj.getSetting("CelestialBody")).pqsController.name;
              PSystemSetup.SpaceCenterFacility.SpawnPoint spawnPoint = new PSystemSetup.SpaceCenterFacility.SpawnPoint();
              spawnPoint.name = "SimulationLaunchSite";
              spawnPoint.spawnTransformURL = "SimulationLaunchSite_Spawn";
              newFacility.spawnPoints = new PSystemSetup.SpaceCenterFacility.SpawnPoint[1];
              newFacility.spawnPoints[0] = spawnPoint;

              // Find and hack the array of facilities via reflection
              foreach (FieldInfo fi in PSystemSetup.Instance.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
              {
            if (fi.FieldType.Name == "SpaceCenterFacility[]")
            {
              // Make a copy of the existing facilities array and append another entry at the end.
              PSystemSetup.SpaceCenterFacility[] facilities = (PSystemSetup.SpaceCenterFacility[])fi.GetValue(PSystemSetup.Instance);
              facilities.AddUnique(newFacility);
              /*
              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;
              */
            }
              }
            #endif

              // Configure the simulation

              EditorLogic.fetch.launchSiteName = "KSPSim_LaunchSite";
              EditorLogic.fetch.launchVessel();
              //SpaceTracking.GoToAndFocusVessel(FlightGlobals.fetch.activeVessel);
        }
Пример #14
0
        public void drawLaunchsites(MapObject target)
        {
            displayingTooltip = false;
            int iPulseRate = 180;

            iRadarCounter = iRadarCounter + 1;
            if (iRadarCounter > iPulseRate)
            {
                iRadarCounter = 0;
            }

            // Then do launchsites
            List <LaunchSite> sites = LaunchSiteManager.getLaunchSites();

            for (int index = 0; index < sites.Count; index++)
            {
                LaunchSite site = sites[index];

                PSystemSetup.SpaceCenterFacility facility = PSystemSetup.Instance.GetSpaceCenterFacility(site.name);

                if (facility == null)
                {
                    continue;
                }

                PSystemSetup.SpaceCenterFacility.SpawnPoint sp = facility.GetSpawnPoint(site.name);

                if (sp == null)
                {
                    continue;
                }

                if (facility.facilityPQS != target.celestialBody.pqsController)
                {
                    continue;
                }

                Transform spawnPointTransform = sp.GetSpawnPointTransform();
                if (spawnPointTransform == null)
                {
                    continue;
                }

                if (isOccluded(spawnPointTransform.position, target.celestialBody))
                {
                    if (KerbalKonstructs.instance.mapHideIconsBehindBody)
                    {
                        continue;
                    }
                }

                Vector3 pos        = MapView.MapCamera.GetComponent <Camera>().WorldToScreenPoint(ScaledSpace.LocalToScaledSpace(spawnPointTransform.position));
                Rect    screenRect = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16);

                // Distance between camera and spawnpoint sort of
                float fPosZ = pos.z;

                float fRadarRadius = 12800 / fPosZ;
                float fRadarOffset = fRadarRadius / 2;

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

                bool display = true;

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

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

                if (!display)
                {
                    continue;
                }

                if (KerbalKonstructs.instance.mapShowRadar)
                {
                    drawRadar(pos, category, openclosed);
                }

                if (openclosed == "Open" && KerbalKonstructs.instance.mapShowGroundComms)
                {
                    drawGroundComms(null, site);
                }

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

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

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

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

                    // Select a base by clicking on the icon
                    if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
                    {
                        MiscUtils.HUDMessage("Selected base is " + sToolTip + ".", 5f, 3);
                        BaseManager.setSelectedSite(site);
                        selectedSite = site;
                        NavGuidanceSystem.setTargetSite(selectedSite);
                        KerbalKonstructs.instance.showBaseManager = true;
                    }
                }
            }
        }
Пример #15
0
 public Facility(PSystemSetup.SpaceCenterFacility facility, SharedObjects shared)
 {
     Shared     = shared;
     m_facility = facility;
     RegisterInitializer(InitializeSuffixes);
 }
Пример #16
0
        public void drawIcons()
        {
            displayingTooltip = false;
            MapObject target = PlanetariumCamera.fetch.target;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                            // Select a base by clicking on the icon
                                            if (Event.current.type == EventType.mouseDown && Event.current.button == 0)
                                            {
                                                MiscUtils.HUDMessage("Selected base is " + sToolTip + ".", 5f, 3);
                                                BaseManager.setSelectedSite(site);
                                                selectedSite = site;
                                                NavGuidanceSystem.setTargetSite(selectedSite);
                                                KerbalKonstructs.instance.showBaseManager = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        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"));
            }
        }
        /// <summary>
        /// Registers the a created LaunchSite to the PSystemSetup and LaunchSiteManager
        /// </summary>
        /// <param name="site"></param>
        internal static void RegisterLaunchSite(KKLaunchSite site, bool isSquad = false)
        {
            if (!string.IsNullOrEmpty(site.LaunchSiteName) && site.lsGameObject.transform.Find(site.LaunchPadTransform) != null)
            {
                site.lsGameObject.transform.name = site.LaunchSiteName;
                site.lsGameObject.name           = site.LaunchSiteName;

                if (KKFacilities == null)
                {
                    KKFacilities = PSystemSetup.Instance.SpaceCenterFacilities.ToList();
                }

                if (KKFacilities.Where(fac => fac.facilityName == site.LaunchSiteName).FirstOrDefault() == null)
                {
                    //Log.Normal("Registering LaunchSite: " + site.LaunchSiteName);
                    PSystemSetup.SpaceCenterFacility spaceCenterFacility = new PSystemSetup.SpaceCenterFacility();
                    spaceCenterFacility.name = site.LaunchSiteName;
                    spaceCenterFacility.facilityDisplayName   = site.LaunchSiteName;
                    spaceCenterFacility.facilityName          = site.LaunchSiteName;
                    spaceCenterFacility.facilityPQS           = site.staticInstance.CelestialBody.pqsController;
                    spaceCenterFacility.facilityTransformName = site.staticInstance.gameObject.name;
                    // newFacility.facilityTransform = site.lsGameObject.transform.Find(site.LaunchPadTransform);
                    //     newFacility.facilityTransformName = instance.gameObject.transform.name;
                    spaceCenterFacility.pqsName = site.body.pqsController.name;
                    PSystemSetup.SpaceCenterFacility.SpawnPoint spawnPoint = new PSystemSetup.SpaceCenterFacility.SpawnPoint();
                    spawnPoint.name = site.LaunchSiteName;
                    spawnPoint.spawnTransformURL       = site.LaunchPadTransform;
                    spaceCenterFacility.spawnPoints    = new PSystemSetup.SpaceCenterFacility.SpawnPoint[1];
                    spaceCenterFacility.spawnPoints[0] = spawnPoint;
                    if (site.LaunchSiteType == SiteType.VAB)
                    {
                        spaceCenterFacility.editorFacility = EditorFacility.VAB;
                    }
                    else
                    {
                        spaceCenterFacility.editorFacility = EditorFacility.SPH;
                    }

                    KKFacilities.Add(spaceCenterFacility);
                    site.spaceCenterFacility = spaceCenterFacility;

                    AddLaunchSite(site);
                }
                else
                {
                    Log.Error("Launch site " + site.LaunchSiteName + " already exists.");
                }

                RegisterLaunchSitesStock(site);


                if (site.staticInstance.gameObject != null)
                {
                    CustomSpaceCenter.CreateFromLaunchsite(site);
                }
            }
            else
            {
                Log.UserWarning("Launch pad transform \"" + site.LaunchPadTransform + "\" missing for " + site.LaunchSiteName);
            }
        }