Esempio n. 1
0
        internal void Update()
        {
            if (pqsCity != null)
            {
                pqsCity.repositionRadial       = RadialPosition;
                pqsCity.repositionRadiusOffset = RadiusOffset;
                pqsCity.reorientInitialUp      = Orientation;

                pqsCity.reorientFinalAngle = RotationAngle;


                pqsCity.transform.localScale = origScale * ModelScale;

                RefLatitude  = KKMath.GetLatitudeInDeg(RadialPosition);
                RefLongitude = KKMath.GetLongitudeInDeg(RadialPosition);

                SetReference();

                pqsCity.Orientate();
            }
            Heading = heading;
            // Notify modules about update
            foreach (StaticModule module in gameObject.GetComponentsInChildren <StaticModule>((true)))
            {
                module.StaticObjectUpdate();
            }
        }
Esempio n. 2
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);
        }
        internal void Spawn()
        {
            if (StaticDatabase.allCenters.ContainsKey(dbKey))
            {
                string oldName = Group;
                int    index   = 0;
                while (StaticDatabase.allCenters.ContainsKey(dbKey))
                {
                    Group = oldName + "_" + index.ToString();
                    index++;
                }
            }

            gameObject      = new GameObject();
            gameObject.name = Group + "_PQS";

            pqsCity = gameObject.AddComponent <PQSCity>();

            PQSCity.LODRange range = new PQSCity.LODRange
            {
                renderers    = new GameObject[0],
                objects      = new GameObject[0],
                visibleRange = 25000
            };
            pqsCity.lod                    = new[] { range };
            pqsCity.frameDelta             = 10000;          //update interval for its own visiblility range checking. unused by KK, so set this to a high value
            pqsCity.repositionRadial       = RadialPosition; //position
            pqsCity.repositionRadiusOffset = RadiusOffset;   //height
            pqsCity.reorientInitialUp      = Orientation;    //orientation
            pqsCity.reorientFinalAngle     = RotationAngle;  //rotation x axis
            pqsCity.reorientToSphere       = true;           //adjust rotations to match the direction of gravity
            pqsCity.sphere                 = CelestialBody.pqsController;
            pqsCity.order                  = 100;
            pqsCity.modEnabled             = true;
            pqsCity.transform.parent       = CelestialBody.pqsController.transform;

            pqsCity.repositionToSphereSurface          = true; //Snap to surface?
            pqsCity.repositionToSphereSurfaceAddHeight = true;
            pqsCity.repositionToSphere = false;

            pqsCity.OnSetup();
            pqsCity.Orientate();

            RefLatitude  = KKMath.GetLatitudeInDeg(RadialPosition);
            RefLongitude = KKMath.GetLongitudeInDeg(RadialPosition);

            StaticDatabase.allCenters.Add(dbKey, this);
        }
        private void LegacySpawnInstance()
        {
            RefLatitude  = KKMath.GetLatitudeInDeg(RadialPosition);
            RefLongitude = KKMath.GetLongitudeInDeg(RadialPosition);

            double alt = RadiusOffset;

            if (heighReference == HeightReference.Terrain)
            {
                alt += surfaceHeight;
            }
            gameObject.transform.parent = CelestialBody.gameObject.transform;

            gameObject.transform.localPosition = RadialPosition.normalized * (float)(CelestialBody.Radius + alt);
            gameObject.transform.localRotation = Quaternion.FromToRotation(Orientation, gameObject.transform.localPosition.normalized) * Quaternion.AngleAxis(RotationAngle, Vector3.up);

            KerbalKonstructs.convertLegacyConfigs = true;
        }
Esempio n. 5
0
        internal void ParseLSConfig(StaticInstance instance, ConfigNode cfgNode)
        {
            staticInstance = instance;
            body = staticInstance.CelestialBody;

            if (cfgNode != null)
            {
                LaunchSiteParser.ParseConfig(this, cfgNode);
            }




            if (!string.IsNullOrEmpty(LaunchSiteLogo))
            {
                logo = UIMain.MakeSprite(LaunchSiteLogo);

                if (logo == null)
                {
                    logo = UIMain.MakeSprite(staticInstance.model.path + "/" + LaunchSiteLogo);
                }
            }
            // use default logo
            if (logo == null)
            {
                logo = UIMain.MakeSprite("KerbalKonstructs/Assets/DefaultSiteLogo");
            }

            if (!string.IsNullOrEmpty(LaunchSiteIcon))
            {

                icon = UIMain.MakeSprite(LaunchSiteIcon);
                if (icon == null)
                {
                    icon = UIMain.MakeSprite(staticInstance.model.path + "/" + LaunchSiteIcon);
                }
            }

            refLon = (float)Math.Round(KKMath.GetLongitudeInDeg(staticInstance.RadialPosition), 2);
            refLat = (float)Math.Round(KKMath.GetLatitudeInDeg(staticInstance.RadialPosition), 2);

            refAlt = (float)staticInstance.CelestialBody.GetAltitude(staticInstance.position);

        }
Esempio n. 6
0
        internal override KKFacility ParseConfig(ConfigNode node)
        {
            LaunchSite launchSite = base.ParseConfig(node) as LaunchSite;

            launchSite.lsGameObject = launchSite.gameObject;
            // this is might be slow
            launchSite.parentInstance = InstanceUtil.GetStaticInstanceForGameObject(lsGameObject);
            launchSite.body           = parentInstance.CelestialBody;

            if (!string.IsNullOrEmpty(LaunchSiteLogo))
            {
                logo = GameDatabase.Instance.GetTexture(LaunchSiteLogo, false);

                if (logo == null)
                {
                    logo = GameDatabase.Instance.GetTexture(launchSite.parentInstance.model.path + "/" + launchSite.LaunchSiteLogo, false);
                }
            }
            // use default logo
            if (logo == null)
            {
                logo = GameDatabase.Instance.GetTexture("KerbalKonstructs/Assets/DefaultSiteLogo", false);
            }

            if (!string.IsNullOrEmpty(LaunchSiteIcon))
            {
                icon = GameDatabase.Instance.GetTexture(LaunchSiteIcon, false);

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


            refLon = (float)Math.Round(KKMath.GetLongitudeInDeg(launchSite.parentInstance.RadialPosition), 2);
            refLat = (float)Math.Round(KKMath.GetLatitudeInDeg(launchSite.parentInstance.RadialPosition), 2);

            refAlt = launchSite.parentInstance.RadiusOffset;


            return(launchSite);
        }
Esempio n. 7
0
        internal void ParseLSConfig(StaticInstance instance, ConfigNode cfgNode)
        {
            if (cfgNode != null)
            {
                LaunchSiteParser.ParseConfig(this, cfgNode);
            }

            lsGameObject = instance.gameObject;
            // this is might be slow
            staticInstance = instance;
            body           = staticInstance.CelestialBody;

            if (!string.IsNullOrEmpty(LaunchSiteLogo))
            {
                logo = GameDatabase.Instance.GetTexture(LaunchSiteLogo, false);

                if (logo == null)
                {
                    logo = GameDatabase.Instance.GetTexture(staticInstance.model.path + "/" + LaunchSiteLogo, false);
                }
            }
            // use default logo
            if (logo == null)
            {
                logo = GameDatabase.Instance.GetTexture("KerbalKonstructs/Assets/DefaultSiteLogo", false);
            }

            if (!string.IsNullOrEmpty(LaunchSiteIcon))
            {
                icon = GameDatabase.Instance.GetTexture(LaunchSiteIcon, false);

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

            refLon = (float)Math.Round(KKMath.GetLongitudeInDeg(staticInstance.RadialPosition), 2);
            refLat = (float)Math.Round(KKMath.GetLatitudeInDeg(staticInstance.RadialPosition), 2);

            refAlt = staticInstance.RadiusOffset;
            AttachSelector();
        }
Esempio n. 8
0
        internal static GroupCenter CheckForClosesCenter(StaticInstance instance)
        {
            GroupCenter closestCenter = null;

            Vector3 groupPostion     = StaticDatabase.GetGroupCenter(instance.groupCenterName).gameObject.transform.position;
            Vector3 instancePosition = instance.CelestialBody.GetWorldSurfacePosition(KKMath.GetLatitudeInDeg(instance.RadialPosition), KKMath.GetLongitudeInDeg(instance.RadialPosition), (instance.CelestialBody.pqsController.GetSurfaceHeight(instance.RadialPosition) - instance.CelestialBody.Radius));
            float   distance         = Vector3.Distance(groupPostion, instancePosition);
            float   oldDistance      = KerbalKonstructs.localGroupRange * 2;


            if (distance > KerbalKonstructs.localGroupRange)
            {
                // Check if we have a similar named GC somewhere
                int index = 0;
                while (StaticDatabase.HasGroupCenter(instance.CelestialBody.name + "_" + instance.Group + "_" + index.ToString()))
                {
                    groupPostion = StaticDatabase.GetGroupCenter(instance.CelestialBody.name + "_" + instance.Group + "_" + index.ToString()).gameObject.transform.position;
                    distance     = Vector3.Distance(groupPostion, instancePosition);

                    if (distance < KerbalKonstructs.localGroupRange)
                    {
                        if (closestCenter == null || distance < oldDistance)
                        {
                            oldDistance   = distance;
                            closestCenter = StaticDatabase.GetGroupCenter(instance.CelestialBody.name + "_" + instance.Group + "_" + index.ToString());
                        }
                    }
                    index++;
                }
            }
            else
            {
                closestCenter = StaticDatabase.GetGroupCenter(instance.groupCenterName);
            }
            return(closestCenter);
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a GroupCenter if needed
        /// </summary>
        /// <param name="instance"></param>
        internal static void CreateGroupCenterIfMissing(StaticInstance instance)
        {
            if (!StaticDatabase.HasGroupCenter(instance.groupCenterName))
            {
                if (instance.RadialPosition.Equals(Vector3.zero))
                {
                    Log.UserError("No Group Found and no position found to create a Group: " + instance.configPath);
                    return;
                }

                Log.Normal("Creating a new Group Center: " + instance.groupCenterName);

                GroupCenter center = new GroupCenter();
                center.Group          = instance.Group;
                center.RadialPosition = instance.RadialPosition;
                center.CelestialBody  = instance.CelestialBody;
                center.isInSavegame   = instance.isInSavegame;
                center.Spawn();
                instance.Group = center.Group;
            }
            else
            {
                // we have a GroupCenter and a legacy Object we might regroup now
                if ((instance.RelativePosition.Equals(Vector3.zero)) && (!instance.RadialPosition.Equals(Vector3.zero)))
                {
                    Vector3 groupPostion     = StaticDatabase.GetGroupCenter(instance.groupCenterName).gameObject.transform.position;
                    Vector3 instancePosition = instance.CelestialBody.GetWorldSurfacePosition(KKMath.GetLatitudeInDeg(instance.RadialPosition), KKMath.GetLongitudeInDeg(instance.RadialPosition), (instance.CelestialBody.pqsController.GetSurfaceHeight(instance.RadialPosition) - instance.CelestialBody.Radius));

                    if (Vector3.Distance(groupPostion, instancePosition) > KerbalKonstructs.localGroupRange)
                    {
                        // Check if we have a similar named GC somewhere
                        GroupCenter closestCenter = CheckForClosesCenter(instance);
                        if (closestCenter != null)
                        {
                            instance.Group = closestCenter.Group;
                        }
                        else
                        {
                            Log.Normal("Creating a new local GroupCenter on: " + instance.CelestialBody.name + " for " + instance.Group);

                            GroupCenter center = new GroupCenter();
                            // we use index keys for new Group Names
                            center.Group          = instance.Group;
                            center.RadialPosition = instance.RadialPosition;
                            center.CelestialBody  = instance.CelestialBody;
                            center.isInSavegame   = instance.isInSavegame;
                            center.Spawn();
                            instance.Group = center.Group;
                            Log.Normal("New GroupCenter Created: " + instance.groupCenterName);
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        internal void Spawn()
        {
            if (StaticDatabase.HasGroupCenter(dbKey))
            {
                string oldName = Group;
                int    index   = 0;
                while (StaticDatabase.HasGroupCenter(dbKey))
                {
                    Group = oldName + "_" + index.ToString();
                    index++;
                }
            }

            gameObject = new GameObject();
            GameObject.DontDestroyOnLoad(gameObject);

            CelestialBody.CBUpdate();


            gameObject.name = Group;
            //gameObject.name = "SpaceCenter";

            pqsCity = gameObject.AddComponent <PQSCity>();

            PQSCity.LODRange range = new PQSCity.LODRange
            {
                renderers    = new GameObject[0],
                objects      = new GameObject[0],
                visibleRange = 25000
            };
            pqsCity.lod        = new[] { range };
            pqsCity.frameDelta = 10000; //update interval for its own visiblility range checking. unused by KK, so set this to a high value

            if (RadialPosition == Vector3.zero)
            {
                if ((RefLatitude != 361d) && (RefLongitude != 361d))
                {
                    RadialPosition = KKMath.GetRadiadFromLatLng(CelestialBody, RefLatitude, RefLongitude);
                }
                else
                {
                    Log.UserError("No Valid Position found for Group: " + Group);
                }
            }
            else
            if ((RefLatitude == 361d) || (RefLongitude == 361d))
            {
                {
                    RefLatitude  = KKMath.GetLatitudeInDeg(RadialPosition);
                    RefLongitude = KKMath.GetLongitudeInDeg(RadialPosition);
                }
            }

            pqsCity.reorientFinalAngle = 0;
            pqsCity.repositionRadial   = RadialPosition;   //position

            pqsCity.repositionRadiusOffset = RadiusOffset; //height
            pqsCity.reorientInitialUp      = Orientation;  //orientation
            pqsCity.reorientToSphere       = true;         //adjust rotations to match the direction of gravity
            pqsCity.sphere           = CelestialBody.pqsController;
            pqsCity.order            = 100;
            pqsCity.modEnabled       = true;
            pqsCity.transform.parent = CelestialBody.pqsController.transform;

            pqsCity.repositionToSphereSurfaceAddHeight = false;
            pqsCity.repositionToSphereSurface          = false;
            SetReference();

            pqsCity.OnSetup();
            pqsCity.Orientate();

            UpdateRotation2Heading();

            StaticDatabase.AddGroupCenter(this);
        }
Esempio n. 11
0
        /// <summary>
        /// Creates a GroupCenter if needed
        /// </summary>
        /// <param name="instance"></param>
        internal static void CreateGroupCenterIfMissing(StaticInstance instance)
        {
            if (instance.Group == "Ungrouped" || instance.Group == "Career")
            {
                if (!StaticDatabase.allCenters.ContainsKey(instance.groupCenterName))
                {
                    if (instance.RadialPosition.Equals(Vector3.zero))
                    {
                        Log.UserError("No Group Found and no position found to create a Group: " + instance.configPath);
                        return;
                    }

                    Log.Normal("Creating a new Group Center: " + instance.groupCenterName);

                    GroupCenter center = new GroupCenter();
                    center.Group          = instance.Group;
                    center.RadialPosition = instance.RadialPosition;
                    center.CelestialBody  = instance.CelestialBody;
                    center.Spawn();
                }
                else
                {
                    // we have a GroupCenter and a legacy Object we might regroup now
                    if ((instance.RelativePosition.Equals(Vector3.zero)) && (!instance.RadialPosition.Equals(Vector3.zero)))
                    {
                        Vector3 groupPostion     = StaticDatabase.allCenters[instance.groupCenterName].gameObject.transform.position;
                        Vector3 instancePosition = instance.CelestialBody.GetWorldSurfacePosition(KKMath.GetLatitudeInDeg(instance.RadialPosition), KKMath.GetLongitudeInDeg(instance.RadialPosition), (instance.CelestialBody.pqsController.GetSurfaceHeight(instance.RadialPosition) - instance.CelestialBody.Radius));

                        if (Vector3.Distance(groupPostion, instancePosition) > KerbalKonstructs.localGroupRange)
                        {
                            Log.Normal("Creating a new local Group on: " + instance.CelestialBody.name + " for " + instance.Group);
                            {
                                GroupCenter center = new GroupCenter();
                                center.Group          = Guid.NewGuid().ToString();
                                center.RadialPosition = instance.RadialPosition;
                                center.CelestialBody  = instance.CelestialBody;
                                center.Spawn();
                                instance.Group = center.Group;
                                Log.Normal("New GroupCenter Created: " + instance.groupCenterName);
                            }
                        }
                    }
                }
            }


            if (!StaticDatabase.allCenters.ContainsKey(instance.groupCenterName))
            {
                if (instance.RadialPosition.Equals(Vector3.zero))
                {
                    Log.UserError("No Group Found and no position found to create a Group: " + instance.configPath);
                    return;
                }

                Log.Normal("Creating a new Group Center: " + instance.groupCenterName);

                GroupCenter center = new GroupCenter();
                center.Group          = instance.Group;
                center.RadialPosition = instance.RadialPosition;
                center.CelestialBody  = instance.CelestialBody;
                center.Spawn();
            }
        }