コード例 #1
0
 internal override void OnPostSetup()
 {
     if (customSpaceCenter == null)
     {
         StaticInstance staticInstance = InstanceUtil.GetStaticInstanceForGameObject(this.gameObject);
         customSpaceCenter = new CustomSpaceCenter();
         customSpaceCenter.isFromFacility  = true;
         customSpaceCenter.SpaceCenterName = FacilityName;
         customSpaceCenter.staticInstance  = staticInstance;
         customSpaceCenter.gameObject      = staticInstance.gameObject;
         SpaceCenterManager.AddSpaceCenter(customSpaceCenter);
         Log.Normal("SpaceCenter created: " + FacilityName);
     }
 }
コード例 #2
0
        public static void createLaunchSite(StaticObject obj)
        {
            if (obj.settings.ContainsKey("LaunchSiteName") && obj.gameObject.transform.Find((string)obj.getSetting("LaunchPadTransform")) != null)
            {
                // Debug.Log("KK: Creating launch site " + obj.getSetting("LaunchSiteName"));
                obj.gameObject.transform.name = (string)obj.getSetting("LaunchSiteName");
                obj.gameObject.name           = (string)obj.getSetting("LaunchSiteName");

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

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

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

                            bool RTEnabled = false;

                            Texture logo = null;
                            Texture icon = null;

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

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

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

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


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

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

                if (obj.gameObject != null)
                {
                    CustomSpaceCenter.CreateFromLaunchsite((string)obj.getSetting("LaunchSiteName"), obj.gameObject);
                }
            }
            else
            {
                Debug.Log("KK: Launch pad transform \"" + obj.getSetting("LaunchPadTransform") + "\" missing for " + obj.getSetting("LaunchSiteName"));
            }
        }
コード例 #3
0
        public 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;
        }
コード例 #4
0
 public static void addSpaceCenter(CustomSpaceCenter csc)
 {
     spaceCenters.Add(csc);
 }
コード例 #5
0
		public static void addSpaceCenter(CustomSpaceCenter csc)
		{
			spaceCenters.Add(csc);
		}