Esempio n. 1
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);
        }
Esempio n. 2
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);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Spawns a new Instance in the Gameworld and registers itself to the Static Database
        /// </summary>
        /// <param name="editing"></param>
        /// <param name="bPreview"></param>
        internal void Orientate()
        {
            // mangle Squads statics
            CelestialBody.CBUpdate();

            InstanceUtil.CreateGroupCenterIfMissing(this);

            if (!StaticDatabase.HasGroupCenter(groupCenterName))
            {
                Log.UserWarning("cannot load " + configPath);
                return;
            }
            groupCenter = StaticDatabase.GetGroupCenter(groupCenterName);

            if (RelativePosition.Equals(Vector3.zero))
            {
                Log.Normal("LegacySpawnInstance called for " + groupCenterName + "_" + model.name);
                LegacySpawnInstance();
                gameObject.transform.parent = groupCenter.gameObject.transform;
                RelativePosition            = gameObject.transform.localPosition;
                Orientation = gameObject.transform.localEulerAngles;
            }
            else
            {
                gameObject.transform.position         = groupCenter.gameObject.transform.position + RelativePosition;;
                gameObject.transform.parent           = groupCenter.gameObject.transform;
                gameObject.transform.localEulerAngles = Orientation;
                gameObject.transform.localPosition    = RelativePosition;
            }


            RefLatitude    = (float)CelestialBody.GetLatitudeAndLongitude(gameObject.transform.position).x;
            RefLongitude   = (float)(CelestialBody.GetLatitudeAndLongitude(gameObject.transform.position).y);
            RadialPosition = radialPosition;

            StaticDatabase.AddStatic(this);

            // Add them to the bodys objectlist, so they show up as anomalies
            // After we got a new Name from StaticDatabase.AddStatic()
            if (isScanable)
            {
                var pqsObjectList = CelestialBody.pqsSurfaceObjects.ToList();
                if (!pqsObjectList.Contains((PQSSurfaceObject)groupCenter.pqsCity))
                {
                    Log.Normal("Added " + groupCenter.Group + " to scanable Objects");
                    pqsObjectList.Add(groupCenter.pqsCity as PQSSurfaceObject);
                }
                CelestialBody.pqsSurfaceObjects = pqsObjectList.ToArray();
            }
        }
Esempio n. 4
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);
        }