public SpawnPointLocation(LaunchSite.SpawnPoint spawnPoint, CelestialBody celestialBody)
 {
     Transform = spawnPoint.GetSpawnPointTransform();
     Latitude  = spawnPoint.latitude;
     Longitude = spawnPoint.longitude;
     Altitude  = spawnPoint.altitude;
     Body      = celestialBody;
 }
Exemple #2
0
        private void GenerateLaunchSiteCoordinates(WaypointData wpData, CelestialBody body)
        {
            LoggingUtil.LogVerbose(this, "   launch site: {0}", wpData.launchSite.name);
            LoggingUtil.LogVerbose(this, "   Generating a waypoint based on launch site {0}...", wpData.launchSite.name);

            LaunchSite.SpawnPoint spawnPoint = wpData.launchSite.GetSpawnPoint(wpData.launchSite.name);
            wpData.waypoint.latitude  = spawnPoint.latitude;
            wpData.waypoint.longitude = spawnPoint.longitude;

            LoggingUtil.LogVerbose(this, "    resulting lat, lon = ({0}, {1})", wpData.waypoint.latitude, wpData.waypoint.longitude);
        }
Exemple #3
0
        public static void RegisterMethods()
        {
            RegisterMethod(new Method <LaunchSite, string>("Name", ls => ls != null ? ls.name : null));
            RegisterMethod(new Method <LaunchSite, PQSCity>("PQSCity", ls => ls != null ? ls.pqsCity : null));
            RegisterMethod(new Method <LaunchSite, Location>("Location", ls =>
            {
                if (ls == null)
                {
                    return(null);
                }
                LaunchSite.SpawnPoint spawnPoint = ls.GetSpawnPoint(ls.name);
                return(new Location(ls.Body, spawnPoint.latitude, spawnPoint.longitude));
            }));

            RegisterGlobalFunction(new Function <List <LaunchSite> >("AllLaunchSites", () => PSystemSetup.Instance.LaunchSites));
            RegisterGlobalFunction(new Function <List <LaunchSite> >("AllEnabledLaunchSites", () => PSystemSetup.Instance.LaunchSites.Where(ls => ls.IsSetup).ToList()));
            RegisterGlobalFunction(new Function <List <LaunchSite> >("AllStockLaunchSites", () => PSystemSetup.Instance.StockLaunchSites.ToList()));
            RegisterGlobalFunction(new Function <List <LaunchSite> >("AllNonStockLaunchSites", () => PSystemSetup.Instance.NonStockLaunchSites.ToList()));
        }
Exemple #4
0
        void Awake()
        {
            // get Kerbins PQS
            PQS bodyPQS = FlightGlobals.GetHomeBody().pqsController;

            // search for the KSC2 object and check it exists
            Transform KSC2 = bodyPQS.transform.Find("KSC2");

            if (KSC2 == null)
            {
                return;
            }

            // try setting the launch platform convex
            // this is needed as the concave collider causes vessels to bug on physics load
            // an alternative solution would be ideal
            Transform platform = KSC2.Find("launchpad/Launchpad Platform");

            if (platform != null)
            {
                platform.GetComponent <MeshCollider>().convex = true;
            }

            // create the spawnpoint
            LaunchSite.SpawnPoint spawnPoint = new LaunchSite.SpawnPoint();
            spawnPoint.name = "Baikerbanur";

            // create the launchsite
            LaunchSite launchSite = new LaunchSite("Baikerbanur", bodyPQS.name, KSP.Localization.Localizer.GetStringByTag("#autoLOC_6002142"), new LaunchSite.SpawnPoint[] { spawnPoint }, "KSC2/launchpad/PlatformPlane", EditorFacility.VAB);

            launchSite.nodeType = KSP.UI.Screens.Mapview.MapNode.SiteType.LaunchSite;

            // finalize the LaunchSite
            launchSite.Setup(KSC2.gameObject.GetComponent <PQSCity>(), new PQS[] { bodyPQS });
            PSystemSetup.Instance.AddLaunchSite(launchSite);
        }
        void Awake()
        {
            foreach (ConfigNode city in GameDatabase.Instance.GetConfigNodes("CITY"))
            {
                // check for a name, we need one
                if (!city.HasValue("name"))
                {
                    continue;
                }

                // create the new city
                GameObject cityObject = new GameObject();
                cityObject.name = city.GetValue("name");
                PQSCity2 pqsCity = cityObject.AddComponent <PQSCity2>();
                pqsCity.objectName = cityObject.name;

                // read and set values, using defaults when none are defined
                if (city.HasValue("verticalOffset"))
                {
                    pqsCity.alt = double.Parse(city.GetValue("verticalOffset"));
                    pqsCity.snapHeightOffset = double.Parse(city.GetValue("verticalOffset"));
                }
                CelestialBody body = FlightGlobals.GetHomeBody();
                if (city.HasValue("body"))
                {
                    body = FlightGlobals.GetBodyByName(city.GetValue("body"));
                }
                pqsCity.sphere = body.pqsController;
                if (city.HasValue("lat"))
                {
                    pqsCity.lat = double.Parse(city.GetValue("lat"));
                }
                if (city.HasValue("lon"))
                {
                    pqsCity.lon = double.Parse(city.GetValue("lon"));
                }
                if (city.HasValue("rotation"))
                {
                    pqsCity.rotation = double.Parse(city.GetValue("rotation"));
                }
                if (city.HasValue("snapToSurface"))
                {
                    pqsCity.snapToSurface = city.GetValue("snapToSurface").Equals("true", StringComparison.OrdinalIgnoreCase);
                }
                if (city.HasValue("displayName"))
                {
                    pqsCity.displayobjectName = city.GetValue("displayName");
                }
                else
                {
                    pqsCity.displayobjectName = cityObject.name;
                }

                // all the subnodes
                ConfigNode[] lods           = city.GetNodes("LOD");
                String[]     flagTransforms = city.GetValues("flagTransform");
                ConfigNode[] launchSites    = city.GetNodes("LAUNCHSITE");

                // load the LODs and models
                List <PQSCity2.LodObject> lodObjects = new List <PQSCity2.LodObject>();
                foreach (ConfigNode lod in lods)
                {
                    // create a new LodObject
                    PQSCity2.LodObject lodObject = new PQSCity2.LodObject();

                    // define the distance to stop rendering
                    if (lod.HasValue("visibleRange"))
                    {
                        lodObject.visibleRange = float.Parse(lod.GetValue("visibleRange"));
                    }
                    else
                    {
                        lodObject.visibleRange = 25000;
                    }

                    // read the models attached to this LOD
                    ConfigNode[]      models  = lod.GetNodes("MODEL");
                    List <GameObject> objects = new List <GameObject>();
                    foreach (ConfigNode model in models)
                    {
                        // make sure the model exists
                        if (!model.HasValue("model") | !GameDatabase.Instance.ExistsModel(model.GetValue("model")))
                        {
                            continue;
                        }

                        // get an instance of the model
                        GameObject modelInstance = GameDatabase.Instance.GetModel(model.GetValue("model"));

                        // attach it to the city
                        modelInstance.transform.parent = cityObject.transform;

                        // set the transform values if defined
                        if (model.HasValue("position"))
                        {
                            modelInstance.transform.localPosition = ConfigNode.ParseVector3(model.GetValue("position"));
                        }
                        if (model.HasValue("rotation"))
                        {
                            modelInstance.transform.localEulerAngles = ConfigNode.ParseVector3(model.GetValue("rotation"));
                        }
                        if (model.HasValue("scale"))
                        {
                            modelInstance.transform.localScale = ConfigNode.ParseVector3(model.GetValue("scale"));
                        }

                        // move to the local scenery layer
                        modelInstance.SetLayerRecursive(15);

                        // add the model to the list
                        //objects.Add(modelInstance);
                        modelInstance.SetActive(true);

                        // force all colliders to be concave
                        MeshCollider[] mColliders = modelInstance.GetComponentsInChildren <MeshCollider>(true);
                        foreach (MeshCollider collider in mColliders)
                        {
                            collider.convex = false;
                        }
                    }

                    // add the object list to the lodObject
                    lodObject.objects = objects.ToArray();

                    // add the lodObject to the lodObject list
                    lodObjects.Add(lodObject);
                }

                // add the LODs to the PQSCity
                pqsCity.objects = lodObjects.ToArray();

                // set the flag transforms
                if (flagTransforms.Length != 0)
                {
                    // add the flag handler component
                    CityFlag cityFlag = cityObject.AddComponent <CityFlag>();

                    // add each transform to the handler
                    foreach (string flagTransform in flagTransforms)
                    {
                        cityFlag.flagObjects.Add(CityUtils.FindChild(flagTransform, cityObject));
                    }
                }

                // finalize the PQSCity
                cityObject.transform.parent = body.pqsController.transform;
                pqsCity.Orientate();

                // add a CommNet antenna if defined
                if (city.HasNode("COMMNET"))
                {
                    // reference the confignode for future reference
                    ConfigNode commNet = city.GetNode("COMMNET");

                    // create the CommNetHome
                    CommNet.CommNetHome cNetHome = cityObject.AddComponent <CommNet.CommNetHome>();

                    // set the internal name
                    cNetHome.nodeName = cityObject.name;

                    // get the values from the config
                    if (commNet.HasValue("nodeName"))
                    {
                        cNetHome.displaynodeName = commNet.GetValue("nodeName");
                    }
                    else
                    {
                        cNetHome.displaynodeName = pqsCity.displayobjectName;
                    }
                    if (commNet.HasValue("antennaPower"))
                    {
                        cNetHome.antennaPower = double.Parse(commNet.GetValue("antennaPower"));
                    }
                    if (commNet.HasValue("isKSC"))
                    {
                        cNetHome.isKSC = commNet.GetValue("isKSC").Equals("true", StringComparison.OrdinalIgnoreCase);
                    }
                    if (commNet.HasValue("isPermanent"))
                    {
                        cNetHome.isPermanent = commNet.GetValue("isPermanent").Equals("true", StringComparison.OrdinalIgnoreCase);
                    }
                    if (city.HasValue("commNetTransform"))
                    {
                        cNetHome.nodeTransform = CityUtils.FindChild(city.GetValue("commNetTransform"), cityObject).transform;
                    }
                    else
                    {
                        cNetHome.nodeTransform = cityObject.transform;
                    }
                }

                // setup the launch sites (Making History required)
                foreach (ConfigNode site in launchSites)
                {
                    // we need a name
                    if (!site.HasValue("name"))
                    {
                        continue;
                    }

                    // create the spawnpoint
                    LaunchSite.SpawnPoint spawnPoint = new LaunchSite.SpawnPoint();
                    spawnPoint.name = site.GetValue("name");

                    // select the facility
                    EditorFacility facility = EditorFacility.VAB;
                    if (site.HasValue("facility") && site.GetValue("facility") == "SPH")
                    {
                        facility = EditorFacility.SPH;
                    }

                    // find and reparent the spawnTransform
                    // reparenting is done to ensure that it works
                    Transform spawnTransform = CityUtils.FindChild(site.GetValue("transform"), cityObject).transform;
                    spawnTransform.SetParent(cityObject.transform);

                    // create the launchsite
                    LaunchSite launchSite = new LaunchSite(site.GetValue("name"), body.pqsController.name, site.GetValue("title"), new LaunchSite.SpawnPoint[] { spawnPoint }, cityObject.name + "/" + spawnTransform.name, facility);

                    // change the mapIcon
                    // todo: remove mapIcon
                    if (facility == EditorFacility.VAB)
                    {
                        launchSite.nodeType = KSP.UI.Screens.Mapview.MapNode.SiteType.LaunchSite;
                    }
                    else
                    {
                        launchSite.nodeType = KSP.UI.Screens.Mapview.MapNode.SiteType.Runway;
                    }

                    // finalize the LaunchSite
                    launchSite.Setup(pqsCity, new PQS[] { body.pqsController });
                    PSystemSetup.Instance.AddLaunchSite(launchSite);
                }
            }
        }
        private void InitLandingSitesList()
        {
            landingSites = new List <LandingSite>();

            // Import landing sites from users createded .cfg
            foreach (var mjConf in GameDatabase.Instance.GetConfigs("MechJeb2Landing"))
            {
                foreach (ConfigNode site in mjConf.config.GetNode("LandingSites").GetNodes("Site"))
                {
                    print("site " + site);
                    string launchSiteName = site.GetValue("name");
                    string lat            = site.GetValue("latitude");
                    string lon            = site.GetValue("longitude");

                    if (launchSiteName == null || lat == null || lon == null)
                    {
                        print("Ignore landing site with null value");
                        continue;
                    }

                    double.TryParse(lat, out double latitude);
                    double.TryParse(lon, out double longitude);

                    string        bodyName = site.GetValue("body");
                    CelestialBody body     = bodyName != null?FlightGlobals.Bodies.Find(b => b.bodyName == bodyName) : Planetarium.fetch.Home;

                    if (landingSites.All(p => p.name != launchSiteName))
                    {
                        print("Adding " + launchSiteName);
                        landingSites.Add(new LandingSite()
                        {
                            name      = launchSiteName,
                            latitude  = latitude,
                            longitude = longitude,
                            body      = body
                        });
                    }
                }
            }

            // Import KSP launch sites
            foreach (LaunchSite site in PSystemSetup.Instance.LaunchSites)
            {
                if (site.spawnPoints.Length > 0)
                {
                    LaunchSite.SpawnPoint point = site.spawnPoints[0];
                    landingSites.Add(new LandingSite()
                    {
                        name      = point.name.Replace("_", " "),
                        latitude  = point.latitude,
                        longitude = point.longitude,
                        body      = site.Body
                    });
                }
            }

            // Import KerbTown/Kerbal-Konstructs launch site
            foreach (var config in GameDatabase.Instance.GetConfigs("STATIC"))
            {
                foreach (ConfigNode instances in config.config.GetNodes("Instances"))
                {
                    string bodyName       = instances.GetValue("CelestialBody");
                    string radialPos      = instances.GetValue("RadialPosition");
                    string launchSiteName = instances.GetValue("LaunchSiteName");
                    string launchSiteType = instances.GetValue("LaunchSiteType");

                    if (bodyName == null || radialPos == null || launchSiteName == null || launchSiteType == null ||
                        launchSiteType != "VAB")
                    {
                        continue;
                    }

                    Vector3d      pos  = ConfigNode.ParseVector3D(radialPos).normalized;
                    CelestialBody body = FlightGlobals.Bodies.Find(b => b.bodyName == bodyName);

                    double latitude  = Math.Asin(pos.y) * UtilMath.Rad2Deg;
                    double longitude = Math.Atan2(pos.z, pos.x) * UtilMath.Rad2Deg;

                    if (body != null && landingSites.All(p => p.name != launchSiteName))
                    {
                        landingSites.Add(new LandingSite()
                        {
                            name      = launchSiteName,
                            latitude  = !double.IsNaN(latitude) ? latitude : 0,
                            longitude = !double.IsNaN(longitude) ? longitude : 0,
                            body      = body
                        });
                    }
                }
            }

            // Import RSS Launch sites
            UrlDir.UrlConfig rssSites = GameDatabase.Instance.GetConfigs("KSCSWITCHER").FirstOrDefault();
            if (rssSites != null)
            {
                ConfigNode launchSites = rssSites.config.GetNode("LaunchSites");
                if (launchSites != null)
                {
                    foreach (ConfigNode site in launchSites.GetNodes("Site"))
                    {
                        string     launchSiteName = site.GetValue("displayName");
                        ConfigNode pqsCity        = site.GetNode("PQSCity");
                        if (pqsCity == null)
                        {
                            continue;
                        }

                        string lat = pqsCity.GetValue("latitude");
                        string lon = pqsCity.GetValue("longitude");

                        if (launchSiteName == null || lat == null || lon == null)
                        {
                            continue;
                        }

                        double latitude, longitude;
                        double.TryParse(lat, out latitude);
                        double.TryParse(lon, out longitude);

                        if (landingSites.All(p => p.name != launchSiteName))
                        {
                            landingSites.Add(new LandingSite()
                            {
                                name      = launchSiteName,
                                latitude  = latitude,
                                longitude = longitude,
                                body      = Planetarium.fetch.Home
                            });
                        }
                    }
                }
            }

            if (landingSiteIdx > landingSites.Count)
            {
                landingSiteIdx = 0;
            }
        }