コード例 #1
0
        internal static void SetTerrainRescales()
        {
            CelestialBody homeWorld = ConfigUtil.GetCelestialBody("HomeWorld");

            if (homeWorld.bodyName == "Kerbin")
            {
                planetRescale = Math.Round(homeWorld.pqsController.radius, 0) / 600000;

                foreach (var pqs in homeWorld.GetComponentsInChildren <PQSCity>(true))
                {
                    if (pqs.SurfaceObjectName == "KSC")
                    {
                        var myheight = Math.Round(homeWorld.pqsController.GetSurfaceHeight(pqs.repositionRadial) - homeWorld.pqsController.radius, 1);
                        Log.Normal("Found KSC at: " + Math.Round(myheight, 1) + "m above sealevel");
                        Log.Normal("body radius: " + Math.Round(homeWorld.pqsController.radius, 1) + "m");

                        terrainRescale = myheight / 64.8d;
                    }
                }
                globalTerrainRescale = planetRescale * terrainRescale;
            }
            else
            {
                Log.Warning("our homeworld is " + homeWorld.name + ", nothing to do");
            }
        }
コード例 #2
0
        /// <summary>
        /// Reads a property setting from a ConfigNode and writes the content to the targets field with the same name
        /// </summary>
        /// <param name="target"></param>
        /// <param name="property"></param>
        /// <param name="cfgNode"></param>
        internal static void ReadCFGNode(object target, PropertyInfo property, ConfigNode cfgNode)
        {
            if (!cfgNode.HasValue(property.Name))
            {
                return;
            }

            if (!string.IsNullOrEmpty(cfgNode.GetValue(property.Name)))
            {
                switch (property.PropertyType.ToString())
                {
                case "System.String":
                    property.SetValue(target, cfgNode.GetValue(property.Name), null);
                    break;

                case "System.Int32":
                    property.SetValue(target, int.Parse(cfgNode.GetValue(property.Name)), null);
                    break;

                case "System.Single":
                    property.SetValue(target, float.Parse(cfgNode.GetValue(property.Name)), null);
                    break;

                case "System.Double":
                    property.SetValue(target, double.Parse(cfgNode.GetValue(property.Name)), null);
                    break;

                case "System.Boolean":
                    bool result;
                    bool.TryParse(cfgNode.GetValue(property.Name), out result);
                    property.SetValue(target, result, null);
                    break;

                case "UnityEngine.Vector3":
                    property.SetValue(target, ConfigNode.ParseVector3(cfgNode.GetValue(property.Name)), null);
                    break;

                case "UnityEngine.Vector3d":
                    property.SetValue(target, ConfigNode.ParseVector3D(cfgNode.GetValue(property.Name)), null);
                    break;

                case "CelestialBody":
                    property.SetValue(target, ConfigUtil.GetCelestialBody(cfgNode.GetValue(property.Name)), null);
                    break;

                case "KerbalKonstructs.Core.SiteType":
                    SiteType value = SiteType.Any;
                    try
                    {
                        value = (SiteType)Enum.Parse(typeof(SiteType), cfgNode.GetValue(property.Name));
                    }
                    catch
                    {
                        value = SiteType.Any;
                    }
                    property.SetValue(target, value, null);
                    break;
                }
            }
        }
コード例 #3
0
        public static void AddKSC2()
        {
            CelestialBody body    = ConfigUtil.GetCelestialBody("HomeWorld");
            var           mods    = body.pqsController.transform.GetComponentsInChildren <PQSCity>(true);
            PQSCity       ksc2PQS = null;

            foreach (var m in mods)
            {
                if (m.name == "KSC2")
                {
                    ksc2PQS = m;
                    break;
                }
            }

            if (ksc2PQS == null)
            {
                return;
            }

            StaticInstance ksc2Instance = new StaticInstance();

            ksc2Instance.gameObject = ksc2PQS.gameObject;
            //ksc2Instance.gameObject = ksc2PQS.gameObject.GetComponentsInChildren<Transform>(true).Where(x => x.name.Equals("launchpad", StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault().gameObject;
            ksc2Instance.hasLauchSites = true;
            //ksc2Instance.pqsCity = ksc2PQS;
            ksc2Instance.RadialPosition = ksc2PQS.repositionRadial;
            ksc2Instance.RefLatitude    = KKMath.GetLatitudeInDeg(ksc2PQS.repositionRadial);
            ksc2Instance.RefLongitude   = KKMath.GetLongitudeInDeg(ksc2PQS.repositionRadial);
            ksc2Instance.CelestialBody  = body;
            ksc2Instance.groupCenter    = StaticDatabase.GetGroupCenter(body.name + "_KSC2_Builtin");

            ksc2.staticInstance     = ksc2Instance;
            ksc2.LaunchSiteName     = "KSC2";
            ksc2.LaunchPadTransform = "launchpad/PlatformPlane";

            ksc2.LaunchSiteAuthor      = "KerbalKonstructs";
            ksc2.logo                  = UIMain.MakeSprite("KerbalKonstructs/Assets/DefaultSiteLogo");
            ksc2.LaunchSiteType        = SiteType.VAB;
            ksc2.sitecategory          = LaunchSiteCategory.RocketPad;
            ksc2.LaunchSiteDescription = "The hidden KSC2";
            ksc2.body                  = ConfigUtil.GetCelestialBody("HomeWorld");
            ksc2.refLat                = (float)ksc2Instance.RefLatitude;
            ksc2.refLon                = (float)ksc2Instance.RefLongitude;
            ksc2.refAlt                = (float)(body.pqsController.GetSurfaceHeight(ksc2PQS.repositionRadial) - body.Radius);
            ksc2.LaunchSiteLength      = 15f;
            ksc2.LaunchSiteWidth       = 15f;
            ksc2.InitialCameraRotation = 135f;
            ksc2.staticInstance.mesh   = ksc2PQS.gameObject;
            ksc2.OpenCost              = 1f;
            ksc2.SetClosed();
            ksc2.LaunchSiteIsHidden = true;
            ksc2.isSquad            = true;

            ksc2Instance.launchSite = ksc2;
            ksc2Instance.groupCenter.launchsites.Add(ksc2);

            RegisterLaunchSite(ksc2);
        }
コード例 #4
0
        /// <summary>
        /// Set the SpaceCenterCam to the location os the current LaunchSite
        /// </summary>
        /// <param name="currentSite"></param>
        internal static void SetSpaceCenterCam(KKLaunchSite currentSite)
        {
            if (KerbalKonstructs.focusLastLaunchSite && (currentSite.body.name == ConfigUtil.GetCelestialBody("HomeWorld").name))
            {
                foreach (SpaceCenterCamera2 scCam in Resources.FindObjectsOfTypeAll <SpaceCenterCamera2>())
                {
                    Log.Normal("Restting to: " + currentSite.LaunchSiteName);
                    scCam.transform.parent             = currentSite.lsGameObject.transform;
                    scCam.transform.position           = currentSite.lsGameObject.transform.position;
                    scCam.initialPositionTransformName = currentSite.lsGameObject.transform.name;
                    scCam.pqsName         = currentSite.body.name;
                    scCam.rotationInitial = currentSite.InitialCameraRotation;
                    scCam.ResetCamera();
                    KerbalKonstructs.scCamWasAltered = true;
                }
            }
            else
            {
                foreach (SpaceCenterCamera2 scCam in Resources.FindObjectsOfTypeAll <SpaceCenterCamera2>())
                {
                    Log.Normal("Restting to KSC");
                    Upgradeables.UpgradeableObject kscRnD = Resources.FindObjectsOfTypeAll <Upgradeables.UpgradeableObject>().Where(x => x.name == "ResearchAndDevelopment").First();
                    scCam.transform.parent             = kscRnD.gameObject.transform;
                    scCam.transform.position           = kscRnD.gameObject.transform.transform.position;
                    scCam.initialPositionTransformName = kscRnD.gameObject.transform.name;
                    scCam.pqsName         = ConfigUtil.GetCelestialBody("HomeWorld").name;
                    scCam.rotationInitial = -60;
                    scCam.ResetCamera();
                    KerbalKonstructs.scCamWasAltered = false;
                }
            }

            if (currentSite.LaunchSiteName == "Runway" || currentSite.LaunchSiteName == "LaunchPad" || currentSite.body.name != ConfigUtil.GetCelestialBody("HomeWorld").name)
            {
                foreach (SpaceCenterCamera2 cam in Resources.FindObjectsOfTypeAll(typeof(SpaceCenterCamera2)))
                {
                    cam.altitudeInitial = 45f;
                    cam.ResetCamera();
                }
            }
            else
            {
                PQSCity sitePQS = currentSite.staticInstance.groupCenter.pqsCity;

                foreach (SpaceCenterCamera2 cam in Resources.FindObjectsOfTypeAll(typeof(SpaceCenterCamera2)))
                {
                    double nomHeight = currentSite.body.pqsController.GetSurfaceHeight((Vector3d)sitePQS.repositionRadial.normalized) - currentSite.body.Radius;
                    if (sitePQS.repositionToSphereSurface)
                    {
                        nomHeight += sitePQS.repositionRadiusOffset;
                    }
                    cam.altitudeInitial = 0f - (float)nomHeight;

                    cam.ResetCamera();
                    Log.Normal("fixed the Space Center camera.");
                }
            }
            SetNextMorningPoint(currentSite);
        }
コード例 #5
0
        /// <summary>
        /// Set the SpaceCenterCam to the location os the current LaunchSite
        /// </summary>
        /// <param name="currentSite"></param>
        internal static void SetSpaceCenterCam(KKLaunchSite currentSite)
        {
            //if (KerbalKonstructs.focusLastLaunchSite && (currentSite.body.name == ConfigUtil.GetCelestialBody("HomeWorld").name))
            if (KerbalKonstructs.focusLastLaunchSite && (currentSite.body == FlightGlobals.currentMainBody))
            {
                float nomHeight = 45f - (float)currentSite.body.GetAltitude(currentSite.staticInstance.transform.position);
                KerbalKonstructs.instance.FuckUpKSP();

                foreach (SpaceCenterCamera2 scCam in Resources.FindObjectsOfTypeAll <SpaceCenterCamera2>())
                {
                    Log.Normal("Resetting to: " + currentSite.LaunchSiteName);
                    scCam.transform.parent             = currentSite.staticInstance.transform;
                    scCam.transform.position           = currentSite.staticInstance.transform.position;
                    scCam.initialPositionTransformName = currentSite.staticInstance.transform.name;
                    scCam.pqsName         = currentSite.body.name;
                    scCam.rotationInitial = currentSite.InitialCameraRotation;
                    scCam.altitudeInitial = nomHeight;
                    scCam.ResetCamera();
                    KerbalKonstructs.scCamWasAltered = true;
                }
            }
            else
            {
                foreach (SpaceCenterCamera2 scCam in Resources.FindObjectsOfTypeAll <SpaceCenterCamera2>())
                {
                    Log.Normal("Resetting to KSC");
                    Upgradeables.UpgradeableObject kscRnD = Resources.FindObjectsOfTypeAll <Upgradeables.UpgradeableObject>().Where(x => x.name == "ResearchAndDevelopment").First();
                    float nomHeight = 45f - (float)ConfigUtil.GetCelestialBody("HomeWorld").GetAltitude(kscRnD.gameObject.transform.position);
                    scCam.transform.parent             = kscRnD.gameObject.transform;
                    scCam.transform.position           = kscRnD.gameObject.transform.transform.position;
                    scCam.initialPositionTransformName = kscRnD.gameObject.transform.name;
                    scCam.pqsName         = ConfigUtil.GetCelestialBody("HomeWorld").name;
                    scCam.altitudeInitial = nomHeight;
                    scCam.rotationInitial = -60;
                    scCam.ResetCamera();
                    KerbalKonstructs.scCamWasAltered = false;
                }
            }

            SetNextMorningPoint(currentSite);

            TuneSCCam();
        }
コード例 #6
0
        /// <summary>
        /// prefills LaunchSiteManager with the runway and the KSC
        /// </summary>
        private static void AddKSC()
        {
            runway.LaunchSiteName        = "Runway";
            runway.LaunchSiteAuthor      = "Squad";
            runway.LaunchSiteType        = SiteType.SPH;
            runway.Category              = "Runway";
            runway.logo                  = GameDatabase.Instance.GetTexture("KerbalKonstructs/Assets/KSCRunway", false);
            runway.LaunchSiteDescription = "The KSC runway is a concrete runway measuring about 2.5km long and 70m wide, on a magnetic heading of 90/270. It is not uncommon to see burning chunks of metal sliding across the surface.";
            runway.OpenCloseState        = "Open";
            runway.body                  = ConfigUtil.GetCelestialBody("HomeWorld");
            runway.refLat                = getKSCLat;
            runway.refLon                = getKSCLon;
            runway.refAlt                = 69f;
            runway.LaunchSiteLength      = 2500f;
            runway.LaunchSiteWidth       = 75f;
            runway.RecoveryFactor        = 100f;
            runway.RecoveryRange         = 0f;
            runway.lsGameObject          = SpaceCenter.Instance.gameObject;

            launchpad.LaunchSiteName        = "LaunchPad";
            launchpad.LaunchSiteAuthor      = "Squad";
            launchpad.LaunchSiteType        = SiteType.VAB;
            launchpad.Category              = "RocketPad";
            launchpad.logo                  = GameDatabase.Instance.GetTexture("KerbalKonstructs/Assets/KSCLaunchpad", false);
            launchpad.LaunchSiteDescription = "The KSC launchpad is a platform used to fire screaming Kerbals into the kosmos. There was a tower here at one point but for some reason nobody seems to know where it went...";
            launchpad.OpenCloseState        = "Open";
            launchpad.body                  = ConfigUtil.GetCelestialBody("HomeWorld");
            launchpad.refLat                = getKSCLat;
            launchpad.refLon                = getKSCLon;
            launchpad.refAlt                = 72;
            launchpad.LaunchSiteLength      = 20f;
            launchpad.LaunchSiteWidth       = 20f;
            launchpad.RecoveryFactor        = 100f;
            launchpad.RecoveryRange         = 0f;
            launchpad.lsGameObject          = SpaceCenter.Instance.gameObject;


            launchSites.Add(runway);
            launchSites.Add(launchpad);
        }
コード例 #7
0
        /// <summary>
        /// prefills LaunchSiteManager with the runway and the KSC
        /// </summary>
        private static void AddKSC()
        {
            runway.LaunchSiteName        = "Runway";
            runway.LaunchSiteAuthor      = "Squad";
            runway.LaunchSiteType        = SiteType.SPH;
            runway.sitecategory          = LaunchSiteCategory.Runway;
            runway.logo                  = GameDatabase.Instance.GetTexture("KerbalKonstructs/Assets/KSCRunway", false);
            runway.LaunchSiteDescription = "The KSC runway is a concrete runway measuring about 2.5km long and 70m wide, on a magnetic heading of 90/270. It is not uncommon to see burning chunks of metal sliding across the surface.";
            runway.body                  = ConfigUtil.GetCelestialBody("HomeWorld");
            runway.refLat                = getKSCLat;
            runway.refLon                = getKSCLon;
            runway.refAlt                = 69f;
            runway.LaunchSiteLength      = 2500f;
            runway.LaunchSiteWidth       = 75f;
            runway.InitialCameraRotation = -60f;
            runway.lsGameObject          = Resources.FindObjectsOfTypeAll <Upgradeables.UpgradeableObject>().Where(x => x.name == "ResearchAndDevelopment").First().gameObject;
            runway.SetOpen();

            launchpad.LaunchSiteName        = "LaunchPad";
            launchpad.LaunchSiteAuthor      = "Squad";
            launchpad.LaunchSiteType        = SiteType.VAB;
            launchpad.sitecategory          = LaunchSiteCategory.RocketPad;
            launchpad.logo                  = GameDatabase.Instance.GetTexture("KerbalKonstructs/Assets/KSCLaunchpad", false);
            launchpad.LaunchSiteDescription = "The KSC launchpad is a platform used to fire screaming Kerbals into the kosmos. There was a tower here at one point but for some reason nobody seems to know where it went...";
            launchpad.body                  = ConfigUtil.GetCelestialBody("HomeWorld");
            launchpad.refLat                = getKSCLat;
            launchpad.refLon                = getKSCLon;
            launchpad.refAlt                = 72;
            launchpad.LaunchSiteLength      = 20f;
            launchpad.LaunchSiteWidth       = 20f;
            launchpad.InitialCameraRotation = -60f;
            launchpad.lsGameObject          = Resources.FindObjectsOfTypeAll <Upgradeables.UpgradeableObject>().Where(x => x.name == "ResearchAndDevelopment").First().gameObject;
            launchpad.SetOpen();


            AddLaunchSite(runway);
            AddLaunchSite(launchpad);
        }
コード例 #8
0
        /// <summary>
        /// Reads a setting from a ConfigNode and writes the content to the targets field with the same name
        /// </summary>
        /// <param name="target"></param>
        /// <param name="field"></param>
        /// <param name="cfgNode"></param>
        internal static void ReadCFGNode(object target, FieldInfo field, ConfigNode cfgNode)
        {
            if (!cfgNode.HasValue(field.Name))
            {
                return;
            }

            if (!string.IsNullOrEmpty(cfgNode.GetValue(field.Name)))
            {
                switch (field.FieldType.ToString())
                {
                case "System.String":
                    field.SetValue(target, cfgNode.GetValue(field.Name));
                    break;

                case "System.Int32":
                    field.SetValue(target, int.Parse(cfgNode.GetValue(field.Name)));
                    break;

                case "System.Single":
                    field.SetValue(target, float.Parse(cfgNode.GetValue(field.Name)));
                    break;

                case "System.Double":
                    field.SetValue(target, double.Parse(cfgNode.GetValue(field.Name)));
                    break;

                case "System.Boolean":
                    bool result;
                    bool.TryParse(cfgNode.GetValue(field.Name), out result);
                    field.SetValue(target, result);
                    break;

                case "UnityEngine.Vector3":
                    field.SetValue(target, ConfigNode.ParseVector3(cfgNode.GetValue(field.Name)));
                    break;

                case "UnityEngine.Vector3d":
                    field.SetValue(target, ConfigNode.ParseVector3D(cfgNode.GetValue(field.Name)));
                    break;

                case "UnityEngine.Color":
                    field.SetValue(target, ConfigNode.ParseColor(cfgNode.GetValue(field.Name)));
                    break;

                case "CelestialBody":
                    field.SetValue(target, ConfigUtil.GetCelestialBody(cfgNode.GetValue(field.Name)));
                    break;

                case "KerbalKonstructs.Core.SiteType":
                    SiteType value = SiteType.Any;
                    try
                    {
                        value = (SiteType)Enum.Parse(typeof(SiteType), cfgNode.GetValue(field.Name));
                    } catch
                    {
                        value = SiteType.Any;
                    }
                    field.SetValue(target, value);
                    break;

                case "KerbalKonstructs.Core.LaunchSiteCategory":
                    LaunchSiteCategory category = LaunchSiteCategory.Other;
                    try
                    {
                        category = (LaunchSiteCategory)Enum.Parse(typeof(LaunchSiteCategory), cfgNode.GetValue(field.Name));
                    }
                    catch
                    {
                        category = LaunchSiteCategory.Other;
                    }
                    field.SetValue(target, category);
                    break;
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// prefills LaunchSiteManager with the runway and the KSC
        /// </summary>
        private static void AddKSC()
        {
            StaticInstance rwInstance = new StaticInstance();

            rwInstance.gameObject     = Resources.FindObjectsOfTypeAll <Upgradeables.UpgradeableFacility>().Where(x => x.name == "ResearchAndDevelopment").First().gameObject;
            rwInstance.RefLatitude    = getKSCLat;
            rwInstance.RefLongitude   = getKSCLon;
            rwInstance.CelestialBody  = ConfigUtil.GetCelestialBody("HomeWorld");
            rwInstance.RadialPosition = rwInstance.radialPosition;
            rwInstance.hasLauchSites  = true;
            rwInstance.launchSite     = runway;

            StaticInstance padInstance = new StaticInstance();

            padInstance.gameObject     = Resources.FindObjectsOfTypeAll <Upgradeables.UpgradeableFacility>().Where(x => x.name == "ResearchAndDevelopment").First().gameObject;
            padInstance.RefLatitude    = getKSCLat;
            padInstance.RefLongitude   = getKSCLon;
            padInstance.CelestialBody  = ConfigUtil.GetCelestialBody("HomeWorld");
            padInstance.RadialPosition = rwInstance.radialPosition;
            padInstance.hasLauchSites  = true;
            padInstance.launchSite     = launchpad;

            runway.staticInstance        = rwInstance;
            runway.isSquad               = true;
            runway.LaunchSiteName        = "Runway";
            runway.LaunchSiteAuthor      = "Squad";
            runway.LaunchSiteType        = SiteType.SPH;
            runway.sitecategory          = LaunchSiteCategory.Runway;
            runway.logo                  = UIMain.MakeSprite("KerbalKonstructs/Assets/KSCRunway");
            runway.LaunchSiteDescription = "The KSC runway is a concrete runway measuring about 2.5km long and 70m wide, on a magnetic heading of 90/270. It is not uncommon to see burning chunks of metal sliding across the surface.";
            runway.body                  = ConfigUtil.GetCelestialBody("HomeWorld");
            runway.refLat                = (float)rwInstance.RefLatitude;
            runway.refLon                = (float)rwInstance.RefLongitude;
            runway.refAlt                = 69f;
            runway.LaunchSiteLength      = 2500f;
            runway.LaunchSiteWidth       = 0f;
            runway.InitialCameraRotation = -60f;
            runway.staticInstance.mesh   = rwInstance.gameObject;
            runway.SetOpen();

            launchpad.staticInstance        = padInstance;
            launchpad.isSquad               = true;
            launchpad.LaunchSiteName        = "LaunchPad";
            launchpad.LaunchSiteAuthor      = "Squad";
            launchpad.LaunchSiteType        = SiteType.VAB;
            launchpad.sitecategory          = LaunchSiteCategory.RocketPad;
            launchpad.logo                  = UIMain.MakeSprite("KerbalKonstructs/Assets/KSCLaunchpad");
            launchpad.LaunchSiteDescription = "The KSC launchpad is a platform used to fire screaming Kerbals into the kosmos. There was a tower here at one point but for some reason nobody seems to know where it went...";
            launchpad.body                  = ConfigUtil.GetCelestialBody("HomeWorld");
            launchpad.refLat                = getKSCLat;
            launchpad.refLon                = getKSCLon;
            launchpad.refAlt                = 72;
            launchpad.LaunchSiteLength      = 0f;
            launchpad.LaunchSiteWidth       = 0f;
            launchpad.InitialCameraRotation = -60f;
            launchpad.staticInstance.mesh   = Resources.FindObjectsOfTypeAll <Upgradeables.UpgradeableFacility>().Where(x => x.name == "ResearchAndDevelopment").First().gameObject;
            launchpad.SetOpen();


            AddLaunchSite(runway);
            AddLaunchSite(launchpad);
        }