Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public static bool setSite(ConfigNode KSC)
        {
            bool          hasChanged = false;
            double        dtmp;
            float         ftmp;
            bool          btmp;
            CelestialBody Kerbin   = getKSCBody();
            var           mods     = Kerbin.pqsController.transform.GetComponentsInChildren(typeof(PQSMod), true);
            ConfigNode    pqsCity  = KSC.GetNode("PQSCity");
            ConfigNode    pqsDecal = KSC.GetNode("PQSMod_MapDecalTangent");

            if (pqsCity == null)
            {
                return(false);
            }

            foreach (var m in mods)
            {
                if (m.GetType().ToString().Equals("PQSCity"))
                {
                    PQSCity mod = m as PQSCity;
                    if (pqsCity.HasValue("KEYname"))
                    {
                        if (!(mod.name.Equals(pqsCity.GetValue("KEYname"))))
                        {
                            continue;
                        }
                    }
                    if (pqsCity.HasValue("repositionRadial"))
                    {
                        mod.repositionRadial = KSPUtil.ParseVector3(pqsCity.GetValue("repositionRadial"));
                    }
                    if (pqsCity.HasValue("latitude") && pqsCity.HasValue("longitude"))
                    {
                        double lat, lon;
                        double.TryParse(pqsCity.GetValue("latitude"), out lat);
                        double.TryParse(pqsCity.GetValue("longitude"), out lon);

                        mod.repositionRadial = RealSolarSystem.LLAtoECEF(lat, lon, 0, Kerbin.Radius);
                    }
                    if (pqsCity.HasValue("reorientInitialUp"))
                    {
                        mod.reorientInitialUp = KSPUtil.ParseVector3(pqsCity.GetValue("reorientInitialUp"));
                    }
                    if (pqsCity.HasValue("repositionToSphere"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("repositionToSphere"), out btmp))
                        {
                            mod.repositionToSphere = btmp;
                        }
                    }
                    if (pqsCity.HasValue("repositionToSphereSurface"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurface"), out btmp))
                        {
                            mod.repositionToSphereSurface = btmp;
                        }
                    }
                    if (pqsCity.HasValue("repositionToSphereSurfaceAddHeight"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurfaceAddHeight"), out btmp))
                        {
                            mod.repositionToSphereSurfaceAddHeight = btmp;
                        }
                    }
                    if (pqsCity.HasValue("reorientToSphere"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("reorientToSphere"), out btmp))
                        {
                            mod.reorientToSphere = btmp;
                        }
                    }
                    if (pqsCity.HasValue("repositionRadiusOffset"))
                    {
                        if (double.TryParse(pqsCity.GetValue("repositionRadiusOffset"), out dtmp))
                        {
                            mod.repositionRadiusOffset = dtmp;
                        }
                    }
                    if (pqsCity.HasValue("lodvisibleRangeMult"))
                    {
                        if (double.TryParse(pqsCity.GetValue("lodvisibleRangeMult"), out dtmp))
                        {
                            foreach (PQSCity.LODRange l in mod.lod)
                            {
                                l.visibleRange *= (float)dtmp;
                            }
                        }
                    }
                    if (pqsCity.HasValue("reorientFinalAngle"))
                    {
                        if (float.TryParse(pqsCity.GetValue("reorientFinalAngle"), out ftmp))
                        {
                            mod.reorientFinalAngle = ftmp;
                        }
                    }
                    print("*RSS* changed PQSCity");

                    hasChanged = true;
                    mod.OnSetup();
                    mod.OnPostSetup();
                    SpaceCenter.Instance.transform.localPosition = mod.transform.localPosition;
                    SpaceCenter.Instance.transform.localRotation = mod.transform.localRotation;
                }

                // KSC Flat area
                if (pqsDecal != null && m.GetType().ToString().Equals("PQSMod_MapDecalTangent"))
                {
                    // thanks to asmi for this!
                    PQSMod_MapDecalTangent mod = m as PQSMod_MapDecalTangent;
                    if (pqsDecal.HasValue("position"))
                    {
                        mod.position = KSPUtil.ParseVector3(pqsDecal.GetValue("position"));
                    }
                    if (pqsDecal.HasValue("radius"))
                    {
                        if (double.TryParse(pqsDecal.GetValue("radius"), out dtmp))
                        {
                            mod.radius = dtmp;
                        }
                    }
                    if (pqsDecal.HasValue("heightMapDeformity"))
                    {
                        if (double.TryParse(pqsDecal.GetValue("heightMapDeformity"), out dtmp))
                        {
                            mod.heightMapDeformity = dtmp;
                        }
                    }
                    if (pqsDecal.HasValue("absoluteOffset"))
                    {
                        if (double.TryParse(pqsDecal.GetValue("absoluteOffset"), out dtmp))
                        {
                            mod.absoluteOffset = dtmp;
                        }
                    }
                    if (pqsDecal.HasValue("absolute"))
                    {
                        if (bool.TryParse(pqsDecal.GetValue("absolute"), out btmp))
                        {
                            mod.absolute = btmp;
                        }
                    }
                    if (pqsDecal.HasValue("latitude") && pqsDecal.HasValue("longitude"))
                    {
                        double lat, lon;
                        double.TryParse(pqsDecal.GetValue("latitude"), out lat);
                        double.TryParse(pqsDecal.GetValue("longitude"), out lon);

                        mod.position = RealSolarSystem.LLAtoECEF(lat, lon, 0, Kerbin.Radius);
                    }
                    print("*RSS* changed MapDecal_Tangent");

                    hasChanged = true;
                    mod.OnSetup();
                }
            }

            if (hasChanged)
            {
                Kerbin.pqsController.RebuildSphere();
            }

            return(hasChanged);
        }
Ejemplo n.º 3
0
        public static bool setSite(ConfigNode KSC)
        {
            bool   hasChanged = false;
            double dtmp;
            float  ftmp;
            bool   btmp;

            ConfigNode pqsCity = KSC.GetNode("PQSCity");

            if (pqsCity == null)
            {
                return(false);
            }
            ConfigNode    pqsDecal = KSC.GetNode("PQSMod_MapDecalTangent");
            CelestialBody home     = getKSCBody();

            PQSCity ksc = findKSC(home);

            if (ksc != null)
            {
                if (pqsCity.HasValue("KEYname"))
                {
                    if (!(ksc.name.Equals(pqsCity.GetValue("KEYname"))))
                    {
                        Debug.Log("KSCSwitcher: Could not retrieve KSC to move, reporting failure and moving on.");
                        return(false);
                    }
                }
                if (pqsCity.HasValue("repositionRadial"))
                {
                    ksc.repositionRadial = KSPUtil.ParseVector3(pqsCity.GetValue("repositionRadial"));
                }
                if (pqsCity.HasValue("latitude") && pqsCity.HasValue("longitude"))
                {
                    double lat, lon;
                    double.TryParse(pqsCity.GetValue("latitude"), out lat);
                    double.TryParse(pqsCity.GetValue("longitude"), out lon);

                    ksc.repositionRadial = KSCSwitcher.LLAtoECEF(lat, lon, 0, home.Radius);
                }
                if (pqsCity.HasValue("reorientInitialUp"))
                {
                    ksc.reorientInitialUp = KSPUtil.ParseVector3(pqsCity.GetValue("reorientInitialUp"));
                }
                if (pqsCity.HasValue("repositionToSphere"))
                {
                    if (bool.TryParse(pqsCity.GetValue("repositionToSphere"), out btmp))
                    {
                        ksc.repositionToSphere = btmp;
                    }
                }
                if (pqsCity.HasValue("repositionToSphereSurface"))
                {
                    if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurface"), out btmp))
                    {
                        ksc.repositionToSphereSurface = btmp;
                    }
                }
                if (pqsCity.HasValue("repositionToSphereSurfaceAddHeight"))
                {
                    if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurfaceAddHeight"), out btmp))
                    {
                        ksc.repositionToSphereSurfaceAddHeight = btmp;
                    }
                }
                if (pqsCity.HasValue("reorientToSphere"))
                {
                    if (bool.TryParse(pqsCity.GetValue("reorientToSphere"), out btmp))
                    {
                        ksc.reorientToSphere = btmp;
                    }
                }
                if (pqsCity.HasValue("repositionRadiusOffset"))
                {
                    if (double.TryParse(pqsCity.GetValue("repositionRadiusOffset"), out dtmp))
                    {
                        ksc.repositionRadiusOffset = dtmp;
                    }
                }
                if (pqsCity.HasValue("lodvisibleRangeMult"))
                {
                    if (double.TryParse(pqsCity.GetValue("lodvisibleRangeMult"), out dtmp))
                    {
                        foreach (PQSCity.LODRange l in ksc.lod)
                        {
                            l.visibleRange *= (float)dtmp;
                        }
                    }
                }
                if (pqsCity.HasValue("reorientFinalAngle"))
                {
                    if (float.TryParse(pqsCity.GetValue("reorientFinalAngle"), out ftmp))
                    {
                        ksc.reorientFinalAngle = ftmp;
                    }
                }
                print("KSCSwitcher changed PQSCity");

                hasChanged = true;
                ksc.OnSetup();
                ksc.OnPostSetup();
                SpaceCenter.Instance.transform.localPosition = ksc.transform.localPosition;
                SpaceCenter.Instance.transform.localRotation = ksc.transform.localRotation;
            }
            else
            {
                Debug.LogError("KSCSwitcher: Could not retrieve KSC to move, reporting failure and moving on.");
                return(false);
            }

            PQSMod_MapDecalTangent decal = findKSCMapDecal(home);

            if (decal != null && pqsDecal != null)
            {
                // KSC Flat area
                if (pqsDecal.HasValue("position"))
                {
                    decal.position = KSPUtil.ParseVector3(pqsDecal.GetValue("position"));
                }
                if (pqsDecal.HasValue("radius"))
                {
                    if (double.TryParse(pqsDecal.GetValue("radius"), out dtmp))
                    {
                        decal.radius = dtmp;
                    }
                }
                if (pqsDecal.HasValue("heightMapDeformity"))
                {
                    if (double.TryParse(pqsDecal.GetValue("heightMapDeformity"), out dtmp))
                    {
                        decal.heightMapDeformity = dtmp;
                    }
                }
                if (pqsDecal.HasValue("absoluteOffset"))
                {
                    if (double.TryParse(pqsDecal.GetValue("absoluteOffset"), out dtmp))
                    {
                        decal.absoluteOffset = dtmp;
                    }
                }
                if (pqsDecal.HasValue("absolute"))
                {
                    if (bool.TryParse(pqsDecal.GetValue("absolute"), out btmp))
                    {
                        decal.absolute = btmp;
                    }
                }
                if (pqsDecal.HasValue("latitude") && pqsDecal.HasValue("longitude"))
                {
                    double lat, lon;
                    double.TryParse(pqsDecal.GetValue("latitude"), out lat);
                    double.TryParse(pqsDecal.GetValue("longitude"), out lon);

                    decal.position = KSCSwitcher.LLAtoECEF(lat, lon, 0, home.Radius);
                }
                print("KSCSwitcher changed MapDecal_Tangent");

                hasChanged = true;
                decal.OnSetup();
            }

            if (hasChanged)
            {
                SpaceCenter.Instance.Start();                  // 1.0.5
                if (KSC.HasValue("name"))
                {
                    KSCLoader.instance.Sites.lastSite = LastKSC.fetch.lastSite = KSC.GetValue("name");
                    print("KSCSwitcher changed MapDecal_Tangent");
                }
            }

            return(hasChanged);
        }
        public void spawnObject(Boolean editing, Boolean bPreview)
        {
            // Objects spawned at runtime should be active, ones spawned at loading not
            SetActiveRecursively(gameObject, editing);

            Transform[] gameObjectList = gameObject.GetComponentsInChildren<Transform>();
            List<GameObject> rendererList = (from t in gameObjectList where t.gameObject.renderer != null select t.gameObject).ToList();

            setLayerRecursively(gameObject, 15);

            if (bPreview) this.ToggleAllColliders(false);

            this.preview = bPreview;

            if (editing) KerbalKonstructs.instance.selectObject(this, true, true, bPreview);

            float objvisibleRange = (float)getSetting("VisibilityRange");

            if (objvisibleRange < 1) objvisibleRange = 25000f;

            PQSCity.LODRange range = new PQSCity.LODRange
            {
                renderers = rendererList.ToArray(),
                objects = new GameObject[0],
                visibleRange = objvisibleRange
            };

            pqsCity = gameObject.AddComponent<PQSCity>();
            pqsCity.lod = new[] { range };
            pqsCity.frameDelta = 1; //Unknown
            pqsCity.repositionToSphere = true; //enable repositioning
            pqsCity.repositionToSphereSurface = false; //Snap to surface?
            pqsCity.repositionRadial = (Vector3)getSetting("RadialPosition"); //position
            pqsCity.repositionRadiusOffset = (float)getSetting("RadiusOffset"); //height
            pqsCity.reorientInitialUp = (Vector3)getSetting("Orientation"); //orientation
            pqsCity.reorientFinalAngle = (float)getSetting("RotationAngle"); //rotation x axis
            pqsCity.reorientToSphere = true; //adjust rotations to match the direction of gravity
            gameObject.transform.parent = ((CelestialBody)getSetting("CelestialBody")).pqsController.transform;
            pqsCity.sphere = ((CelestialBody)getSetting("CelestialBody")).pqsController;
            pqsCity.order = 100;
            pqsCity.modEnabled = true;
            pqsCity.OnSetup();
            pqsCity.Orientate();

            foreach (StaticModule module in model.modules)
            {
                Type moduleType = AssemblyLoader.loadedAssemblies.SelectMany(asm => asm.assembly.GetTypes()).FirstOrDefault(t => t.Namespace == module.moduleNamespace && t.Name == module.moduleClassname);
                MonoBehaviour mod = gameObject.AddComponent(moduleType) as MonoBehaviour;

                if (mod != null)
                {
                    foreach (string fieldName in module.moduleFields.Keys)
                    {
                        FieldInfo field = mod.GetType().GetField(fieldName);
                        if (field != null)
                        {
                            field.SetValue(mod, Convert.ChangeType(module.moduleFields[fieldName], field.FieldType));
                        }
                        else
                        {
                            Debug.Log("KK: WARNING: Field " + fieldName + " does not exist in " + module.moduleClassname);
                        }
                    }
                }
                else
                {
                    Debug.Log("KK: WARNING: Module " + module.moduleClassname + " could not be loaded in " + gameObject.name);
                }
            }

            foreach (GameObject gorenderer in rendererList)
            {
                gorenderer.renderer.enabled = true;
            }
        }
Ejemplo n.º 5
0
        static bool PatchPQS(CelestialBody body, ConfigNode node, double origRadius)
        {
            List <string> PQSs     = new List <string>();
            bool          modified = false;
            bool          custom   = false;

            if (node != null && node.HasNode("PQS"))
            {
                foreach (ConfigNode n in node.GetNode("PQS").nodes)
                {
                    PQSs.Add(n.name);
                }
                custom = true;
            }
            else
            {
                if (body.Radius != origRadius)
                {
                    PQSs.Add(body.bodyName);
                    PQSs.Add(body.bodyName + "Ocean");
                }
            }
            foreach (string pName in PQSs)
            {
                print("**Patching PQS " + pName);
                // yeah, slow, but juuuuuuuuust in case.
                foreach (PQS p in Resources.FindObjectsOfTypeAll(typeof(PQS)))
                {
                    if (p.name.Equals(pName))
                    {
                        /*if (body.pqsController != p)
                         *  if (body.pqsController != p.parentSphere)
                         *      continue;*/
                        if (p.radius != body.Radius)
                        {
                            modified = true;
                        }

                        p.radius = body.Radius;
                        // do nothing yet, because I don't want to copy-paste all my code
                        var mods = p.transform.GetComponentsInChildren(typeof(PQSMod), true);
                        // rebuilding should catch it, but...
                        foreach (var m in mods)
                        {
                            if (m is PQSCity)
                            {
                                PQSCity mod = (PQSCity)m;
                                try
                                {
                                    mod.OnSetup();
                                    mod.OnPostSetup();
                                }
                                catch
                                {
                                }
                                //SpaceCenter.Instance.transform.localPosition = mod.transform.localPosition;
                                //SpaceCenter.Instance.transform.localRotation = mod.transform.localRotation;
                            }
                            if (m is PQSMod_MapDecal)
                            {
                                PQSMod_MapDecal mod = (PQSMod_MapDecal)m;
                                mod.radius   *= globalRescale;
                                mod.position *= (float)globalRescale;
                                try
                                {
                                    mod.OnSetup();
                                    mod.OnPostSetup();
                                }
                                catch
                                {
                                }
                            }
                            if (m is PQSMod_MapDecalTangent)
                            {
                                PQSMod_MapDecalTangent mod = (PQSMod_MapDecalTangent)m;
                                mod.radius   *= globalRescale;
                                mod.position *= (float)globalRescale;
                                try
                                {
                                    mod.OnSetup();
                                    mod.OnPostSetup();
                                }
                                catch
                                {
                                }
                            }
                        }
                        try
                        {
                            p.RebuildSphere();
                        }
                        catch (Exception e)
                        {
                            print("Rebuild sphere for " + node.name + " failed: " + e.Message);
                        }
                    }
                }
            }
            return(modified);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        /// <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 spawnObject(Boolean editing, Boolean bPreview)
        {
            // mangle Squads statics
            if (model.isSquad)
            {
                InstanceUtil.MangleSquadStatic(gameObject);
            }

            // Objects spawned at runtime should be active, ones spawned at loading not
            InstanceUtil.SetActiveRecursively(this, editing);

            Transform[]       gameObjectList = gameObject.GetComponentsInChildren <Transform>();
            List <GameObject> rendererList   = (from t in gameObjectList where t.gameObject.GetComponent <Renderer>() != null select t.gameObject).ToList();

            setLayerRecursively(gameObject, 15);

            if (bPreview)
            {
                this.ToggleAllColliders(false);
            }

            this.preview = bPreview;

            if (editing)
            {
                KerbalKonstructs.instance.selectObject(this, true, true, bPreview);
            }

            float objvisibleRange = VisibilityRange;

            if (objvisibleRange < 1)
            {
                objvisibleRange = 25000f;
            }

            PQSCity.LODRange range = new PQSCity.LODRange
            {
                renderers    = new GameObject[0],
                objects      = new GameObject[0],
                visibleRange = objvisibleRange
            };

            pqsCity                           = gameObject.AddComponent <PQSCity>();
            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
            gameObject.transform.parent       = CelestialBody.pqsController.transform;
            pqsCity.sphere                    = CelestialBody.pqsController;
            origScale                         = pqsCity.transform.localScale; // save the original scale for later use
            pqsCity.transform.localScale     *= ModelScale;
            pqsCity.order                     = 100;
            pqsCity.modEnabled                = true;
            pqsCity.repositionToSphere        = true;  //enable repositioning
            pqsCity.repositionToSphereSurface = false; //Snap to surface?



            CelestialBody.pqsController.GetSurfaceHeight(RadialPosition);

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



            //PQSCity2.LodObject lodObject = new PQSCity2.LodObject();
            //lodObject.visibleRange = VisibilityRange;
            //lodObject.objects = new GameObject[] { };
            //pqsCity2 = gameObject.AddComponent<PQSCity2>();
            //pqsCity2.objects = new [] { lodObject } ;
            //pqsCity2.objectName = "";
            //pqsCity2.lat = RefLatitude;
            //pqsCity2.lon = RefLongitude;
            //pqsCity2.alt = RadiusOffset;
            //pqsCity2.up = Orientation;
            //pqsCity2.rotation = RotationAngle;
            //pqsCity2.sphere = CelestialBody.pqsController;


            //pqsCity2.OnSetup();
            //pqsCity2.Orientate();


            foreach (StaticModule module in model.modules)
            {
                Type          moduleType = AssemblyLoader.loadedAssemblies.SelectMany(asm => asm.assembly.GetTypes()).FirstOrDefault(t => t.Namespace == module.moduleNamespace && t.Name == module.moduleClassname);
                MonoBehaviour mod        = gameObject.AddComponent(moduleType) as MonoBehaviour;

                if (mod != null)
                {
                    foreach (string fieldName in module.moduleFields.Keys)
                    {
                        FieldInfo field = mod.GetType().GetField(fieldName);
                        if (field != null)
                        {
                            field.SetValue(mod, Convert.ChangeType(module.moduleFields[fieldName], field.FieldType));
                        }
                        else
                        {
                            Log.UserWarning("Field " + fieldName + " does not exist in " + module.moduleClassname);
                        }
                    }
                }
                else
                {
                    Log.UserError("Module " + module.moduleClassname + " could not be loaded in " + gameObject.name);
                }
            }

            foreach (GameObject gorenderer in rendererList)
            {
                gorenderer.GetComponent <Renderer>().enabled = true;
            }

            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)
            {
                Log.Normal("Added " + gameObject.name + " to scanable Objects");
                var pqsObjectList = CelestialBody.pqsSurfaceObjects.ToList();
                pqsObjectList.Add(pqsCity as PQSSurfaceObject);
                CelestialBody.pqsSurfaceObjects = pqsObjectList.ToArray();
            }
        }
        public void spawnObject(Boolean editing, Boolean bPreview)
        {
            // Objects spawned at runtime should be active, ones spawned at loading not
            SetActiveRecursively(gameObject, editing);

            Transform[]       gameObjectList = gameObject.GetComponentsInChildren <Transform>();
            List <GameObject> rendererList   = (from t in gameObjectList where t.gameObject.GetComponent <Renderer>() != null select t.gameObject).ToList();

            setLayerRecursively(gameObject, 15);

            if (bPreview)
            {
                this.ToggleAllColliders(false);
            }

            this.preview = bPreview;

            if (editing)
            {
                KerbalKonstructs.instance.selectObject(this, true, true, bPreview);
            }

            float objvisibleRange = (float)getSetting("VisibilityRange");

            if (objvisibleRange < 1)
            {
                objvisibleRange = 25000f;
            }

            PQSCity.LODRange range = new PQSCity.LODRange
            {
                renderers    = rendererList.ToArray(),
                objects      = new GameObject[0],
                visibleRange = objvisibleRange
            };

            pqsCity                           = gameObject.AddComponent <PQSCity>();
            pqsCity.lod                       = new[] { range };
            pqsCity.frameDelta                = 1;                                     //Unknown
            pqsCity.repositionToSphere        = true;                                  //enable repositioning
            pqsCity.repositionToSphereSurface = false;                                 //Snap to surface?
            pqsCity.repositionRadial          = (Vector3)getSetting("RadialPosition"); //position
            pqsCity.repositionRadiusOffset    = (float)getSetting("RadiusOffset");     //height
            pqsCity.reorientInitialUp         = (Vector3)getSetting("Orientation");    //orientation
            pqsCity.reorientFinalAngle        = (float)getSetting("RotationAngle");    //rotation x axis
            pqsCity.reorientToSphere          = true;                                  //adjust rotations to match the direction of gravity
            gameObject.transform.parent       = ((CelestialBody)getSetting("CelestialBody")).pqsController.transform;
            pqsCity.sphere                    = ((CelestialBody)getSetting("CelestialBody")).pqsController;
            pqsCity.order                     = 100;
            pqsCity.modEnabled                = true;
            pqsCity.OnSetup();
            pqsCity.Orientate();

            foreach (StaticModule module in model.modules)
            {
                Type          moduleType = AssemblyLoader.loadedAssemblies.SelectMany(asm => asm.assembly.GetTypes()).FirstOrDefault(t => t.Namespace == module.moduleNamespace && t.Name == module.moduleClassname);
                MonoBehaviour mod        = gameObject.AddComponent(moduleType) as MonoBehaviour;

                if (mod != null)
                {
                    foreach (string fieldName in module.moduleFields.Keys)
                    {
                        FieldInfo field = mod.GetType().GetField(fieldName);
                        if (field != null)
                        {
                            field.SetValue(mod, Convert.ChangeType(module.moduleFields[fieldName], field.FieldType));
                        }
                        else
                        {
                            Debug.Log("KK: WARNING: Field " + fieldName + " does not exist in " + module.moduleClassname);
                        }
                    }
                }
                else
                {
                    Debug.Log("KK: WARNING: Module " + module.moduleClassname + " could not be loaded in " + gameObject.name);
                }
            }

            foreach (GameObject gorenderer in rendererList)
            {
                gorenderer.GetComponent <Renderer>().enabled = true;
            }
        }
        private void LegacySpawnInstance()
        {
            float objvisibleRange = VisibilityRange;

            if (objvisibleRange < 1)
            {
                objvisibleRange = KerbalKonstructs.localGroupRange;
            }

            pqsCity = gameObject.AddComponent <PQSCity>();

            PQSCity.LODRange range = new PQSCity.LODRange
            {
                renderers    = new GameObject[0],
                objects      = new GameObject[0],
                visibleRange = objvisibleRange
            };
            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
            gameObject.transform.parent    = CelestialBody.pqsController.transform;
            pqsCity.sphere                 = CelestialBody.pqsController;
            pqsCity.order                  = 100;
            pqsCity.modEnabled             = true;
            pqsCity.repositionToSphere     = true; //enable repositioning


            switch (heighReference)
            {
            case HeightReference.Sphere:
                pqsCity.repositionToSphereSurface = false;     //Snap to surface?

                break;

            case HeightReference.Terrain:

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

            default:
                // we try to descide which one is the best to take
                string biome = ScienceUtil.GetExperimentBiome(CelestialBody, RefLatitude, RefLongitude);
                float  heightAboveTerrain = SDRescale.GetSurfaceRefereceHeight(this);

                if ((biome == "Water" || biome == "Shores") && ((Math.Abs(RadiusOffset) < 5) && heightAboveTerrain > 5))     // most likely at ocean surface
                {
                    Log.Normal("Found a swimming object: " + this.gameObject.name);
                    pqsCity.repositionToSphereSurface = false;     //Snap to surface?
                    heighReference = HeightReference.Sphere;
                }
                else
                {
                    {
                        //    Log.Normal("found new Radiusffset: " + heightAboveTerrain);
                        RadiusOffset = heightAboveTerrain;
                        pqsCity.repositionToSphereSurface          = true; //Snap to surface?#
                        pqsCity.repositionToSphereSurfaceAddHeight = true;
                        pqsCity.repositionRadiusOffset             = heightAboveTerrain;
                        pqsCity.repositionToSphere = false;

                        heighReference = HeightReference.Terrain;
                    }
                }
                break;
            }
            pqsCity.OnSetup();
            pqsCity.Orientate();

            KerbalKonstructs.convertLegacyConfigs = true;
        }
Ejemplo n.º 10
0
        public void setSite(string name)
        {
            ConfigNode site = getSite(name);

            if (site == null)
            {
                return;
            }

            bool          hasChanged = false;
            double        dtmp;
            float         ftmp;
            bool          btmp;
            CelestialBody Kerbin = FlightGlobals.Bodies.Find(body => body.name == "Kerbin");

            if (Kerbin == null)
            {
                Kerbin = FlightGlobals.Bodies.Find(body => body.name == "Earth"); // temp fix
            }
            var        mods     = Kerbin.pqsController.transform.GetComponentsInChildren(typeof(PQSMod), true);
            ConfigNode pqsCity  = site.GetNode("PQSCity");
            ConfigNode pqsDecal = site.GetNode("PQSMod_MapDecalTangent");

            if (pqsCity == null)
            {
                return;
            }

            foreach (var m in mods)
            {
                if (m.GetType().ToString().Equals("PQSCity"))
                {
                    PQSCity mod = m as PQSCity;
                    if (pqsCity.HasValue("KEYname"))
                    {
                        if (!(mod.name.Equals(pqsCity.GetValue("KEYname"))))
                        {
                            continue;
                        }
                    }
                    if (pqsCity.HasValue("repositionRadial"))
                    {
                        mod.repositionRadial = KSPUtil.ParseVector3(pqsCity.GetValue("repositionRadial"));
                    }
                    if (pqsCity.HasValue("latitude") && pqsCity.HasValue("longitude"))
                    {
                        double lat, lon;
                        double.TryParse(pqsCity.GetValue("latitude"), out lat);
                        double.TryParse(pqsCity.GetValue("longitude"), out lon);

                        mod.repositionRadial = RealSolarSystem.LLAtoECEF(lat, lon, 0, Kerbin.Radius);
                    }
                    if (pqsCity.HasValue("reorientInitialUp"))
                    {
                        mod.reorientInitialUp = KSPUtil.ParseVector3(pqsCity.GetValue("reorientInitialUp"));
                    }
                    if (pqsCity.HasValue("repositionToSphere"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("repositionToSphere"), out btmp))
                        {
                            mod.repositionToSphere = btmp;
                        }
                    }
                    if (pqsCity.HasValue("repositionToSphereSurface"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurface"), out btmp))
                        {
                            mod.repositionToSphereSurface = btmp;
                        }
                    }
                    if (pqsCity.HasValue("repositionToSphereSurfaceAddHeight"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("repositionToSphereSurfaceAddHeight"), out btmp))
                        {
                            mod.repositionToSphereSurfaceAddHeight = btmp;
                        }
                    }
                    if (pqsCity.HasValue("reorientToSphere"))
                    {
                        if (bool.TryParse(pqsCity.GetValue("reorientToSphere"), out btmp))
                        {
                            mod.reorientToSphere = btmp;
                        }
                    }
                    if (pqsCity.HasValue("repositionRadiusOffset"))
                    {
                        if (double.TryParse(pqsCity.GetValue("repositionRadiusOffset"), out dtmp))
                        {
                            mod.repositionRadiusOffset = dtmp;
                        }
                    }
                    if (pqsCity.HasValue("lodvisibleRangeMult"))
                    {
                        if (double.TryParse(pqsCity.GetValue("lodvisibleRangeMult"), out dtmp))
                        {
                            foreach (PQSCity.LODRange l in mod.lod)
                            {
                                l.visibleRange *= (float)dtmp;
                            }
                        }
                    }
                    if (pqsCity.HasValue("reorientFinalAngle"))
                    {
                        if (float.TryParse(pqsCity.GetValue("reorientFinalAngle"), out ftmp))
                        {
                            mod.reorientFinalAngle = ftmp;
                        }
                    }
                    print("*RSS* changed PQSCity");

                    hasChanged = true;
                    mod.OnSetup();
                }

                // KSC Flat area
                if (pqsDecal != null && m.GetType().ToString().Equals("PQSMod_MapDecalTangent"))
                {
                    // thanks to asmi for this!
                    PQSMod_MapDecalTangent mod = m as PQSMod_MapDecalTangent;
                    if (pqsDecal.HasValue("position"))
                    {
                        mod.position = KSPUtil.ParseVector3(pqsDecal.GetValue("position"));
                    }
                    if (pqsDecal.HasValue("radius"))
                    {
                        if (double.TryParse(pqsDecal.GetValue("radius"), out dtmp))
                        {
                            mod.radius = dtmp;
                        }
                    }
                    if (pqsDecal.HasValue("heightMapDeformity"))
                    {
                        if (double.TryParse(pqsDecal.GetValue("heightMapDeformity"), out dtmp))
                        {
                            mod.heightMapDeformity = dtmp;
                        }
                    }
                    if (pqsDecal.HasValue("absoluteOffset"))
                    {
                        if (double.TryParse(pqsDecal.GetValue("absoluteOffset"), out dtmp))
                        {
                            mod.absoluteOffset = dtmp;
                        }
                    }
                    if (pqsDecal.HasValue("absolute"))
                    {
                        if (bool.TryParse(pqsDecal.GetValue("absolute"), out btmp))
                        {
                            mod.absolute = btmp;
                        }
                    }
                    if (pqsDecal.HasValue("latitude") && pqsDecal.HasValue("longitude"))
                    {
                        double lat, lon;
                        double.TryParse(pqsDecal.GetValue("latitude"), out lat);
                        double.TryParse(pqsDecal.GetValue("longitude"), out lon);

                        mod.position = RealSolarSystem.LLAtoECEF(lat, lon, 0, Kerbin.Radius);
                    }
                    print("*RSS* changed MapDecal_Tangent");

                    hasChanged = true;
                    mod.OnSetup();
                }

                if (hasChanged)
                {
                    print("*RSS* Rebuilding");
                    Kerbin.pqsController.RebuildSphere();
                    ScreenMessages.PostScreenMessage("Launch site changed to " + name, 2.5f, ScreenMessageStyle.LOWER_CENTER);
                    showWindow = false;
                    print("*RSS* Launch site change DONE");
                }
            }
        }