public VesselData(VesselData vd) { name = vd.name; id = vd.id; craftURL = vd.craftURL; craftPart = vd.craftPart; flagURL = vd.flagURL; vesselType = vd.vesselType; body = vd.body; orbit = vd.orbit; latitude = vd.latitude; longitude = vd.longitude; altitude = vd.altitude; height = vd.height; orbiting = vd.orbiting; owned = vd.owned; pqsCity = vd.pqsCity; pqsOffset = vd.pqsOffset; heading = vd.heading; pitch = vd.pitch; roll = vd.roll; foreach (CrewData cd in vd.crew) { crew.Add(new CrewData(cd)); } }
private static Location KSCLocation() { CelestialBody home = FlightGlobals.Bodies.Where(cb => cb.isHomeWorld).First(); PQSCity ksc = home.GetComponentsInChildren <PQSCity>(true).Where(pqs => pqs.name == "KSC").First(); return(new Location(home, home.GetLatitude(ksc.transform.position), home.GetLongitude(ksc.transform.position))); }
public static PQSCity findKSC(CelestialBody home) { if (home != null) { if (home.pqsController != null && home.pqsController.transform != null) { Transform t = home.pqsController.transform.Find("KSC"); if (t != null) { PQSCity KSC = (PQSCity)t.GetComponent(typeof(PQSCity)); if (KSC != null) { return(KSC); } } } } PQSCity[] cities = Resources.FindObjectsOfTypeAll <PQSCity>(); foreach (PQSCity c in cities) { if (c.name == "KSC") { return(c); } } return(null); }
public WaldoAttackVesselData(WaldoAttackVesselData vd) { name = vd.name; id = vd.id; craftURL = vd.craftURL; craftPart = vd.craftPart; flagURL = vd.flagURL; vesselType = vd.vesselType; body = vd.body; orbit = vd.orbit; latitude = vd.latitude; longitude = vd.longitude; altitude = vd.altitude; height = vd.height; orbiting = vd.orbiting; owned = vd.owned; pqsCity = vd.pqsCity; pqsOffset = vd.pqsOffset; heading = vd.heading; pitch = vd.pitch; roll = vd.roll; foreach (CrewData cd in vd.crew) { crew.Add(new CrewData(cd)); } }
public WaypointData(WaypointData orig, Contract contract) { type = orig.type; names = orig.names.ToList(); waypoint.altitude = orig.waypoint.altitude; waypoint.celestialName = orig.waypoint.celestialName; waypoint.height = orig.waypoint.height; waypoint.id = orig.waypoint.id; waypoint.index = orig.waypoint.index; waypoint.isClustered = orig.waypoint.isClustered; waypoint.isExplored = orig.waypoint.isExplored; waypoint.isOnSurface = orig.waypoint.isOnSurface; waypoint.landLocked = orig.waypoint.landLocked; waypoint.latitude = orig.waypoint.latitude; waypoint.longitude = orig.waypoint.longitude; waypoint.name = orig.waypoint.name; waypoint.visible = orig.waypoint.visible; randomAltitude = orig.randomAltitude; waterAllowed = orig.waterAllowed; forceEquatorial = orig.forceEquatorial; nearIndex = orig.nearIndex; chained = orig.chained; count = orig.count; minDistance = orig.minDistance; maxDistance = orig.maxDistance; pqsCity = orig.pqsCity; pqsOffset = orig.pqsOffset; launchSite = orig.launchSite; parameter = orig.parameter.ToList(); underwater = orig.underwater; SetContract(contract); }
void GroupFixer(object mod, Vector3 REFvector) { // Moves the group Vector3 PQSposition = ((Vector3)GetPosition(mod)); Debug.Log("SigmaDimensions.City2Fixer", " > Group center position = " + REFvector + ", (LAT: " + new LatLon(REFvector).lat + ", LON: " + new LatLon(REFvector).lon + ")"); Debug.Log("SigmaDimensions.City2Fixer", " > Mod original position = " + PQSposition + ", (LAT: " + new LatLon(PQSposition).lat + ", LON: " + new LatLon(PQSposition).lon + ")"); if (body == FlightGlobals.GetHomeBody() && REFvector == new Vector3(157000, -1000, -570000)) { PQSCity KSC = body.GetComponentsInChildren <PQSCity>().FirstOrDefault(m => m.name == "KSC"); MoveGroup(mod, KSC.repositionRadial, KSC.reorientFinalAngle - (-15), 0, 64.7846885412); REFvector = KSC.repositionRadial; // Change the REFvector the the new position for Lerping } else if (body.Has("PQSCityGroupsMove")) { var MovesInfo = body.Get <Dictionary <Vector3, KeyValuePair <Vector3, NumericParser <double>[]> > >("PQSCityGroupsMove"); if (MovesInfo.ContainsKey(REFvector)) { var info = MovesInfo[REFvector]; MoveGroup(mod, info.Key, (float)info.Value[0], info.Value[1], info.Value[2]); REFvector = info.Key; // Change the REFvector the the new position for Lerping } } // Update PQSposition PQSposition = ((Vector3)GetPosition(mod)); // Spread or Shrinks the group to account for Resize Vector3 NEWvector = Vector3.LerpUnclamped(REFvector.normalized, PQSposition.normalized, (float)(resizeBuildings / resize)); SetPosition(mod, NEWvector); Debug.Log("SigmaDimensions.City2Fixer", " > Mod lerped position = " + (Vector3)GetPosition(mod) + ", (LAT: " + new LatLon((Vector3)GetPosition(mod)).lat + ", LON: " + new LatLon((Vector3)GetPosition(mod)).lon + ")"); }
public bool scanBody() { scanned = true; if (body.pqsController == null) { return(false); } PQSCity[] Cities = body.pqsController.GetComponentsInChildren <PQSCity>(); for (int i = 0; i < Cities.Length; i++) { PQSCity city = Cities[i]; if (city == null) { continue; } if (city.transform.parent.name != body.name) { continue; } DMAnomalyObject anom = new DMAnomalyObject(city); addAnomaly(anom); } return(AnomalyCount > 0); }
internal static void SetSpaceCenterCam2(KKLaunchSite currentSite) { if (KerbalKonstructs.focusLastLaunchSite) { foreach (SpaceCenterCamera2 scCam in Resources.FindObjectsOfTypeAll <SpaceCenterCamera2>()) { scCam.transform.parent = currentSite.lsGameObject.transform; scCam.transform.position = currentSite.lsGameObject.transform.position + Vector3.up * 100; scCam.initialPositionTransformName = currentSite.lsGameObject.transform.name; FieldInfo pqsField = scCam.GetType().GetField("pqs", BindingFlags.Instance | BindingFlags.NonPublic); pqsField.SetValue(scCam, currentSite.body.pqsController); scCam.pqsName = currentSite.body.name; scCam.ResetCamera(); } } else { foreach (SpaceCenterCamera2 scCam in Resources.FindObjectsOfTypeAll <SpaceCenterCamera2>()) { scCam.transform.parent = SpaceCenter.Instance.transform; scCam.transform.position = SpaceCenter.Instance.transform.position; scCam.initialPositionTransformName = "KSC/SpaceCenter/SpaceCenterCameraPosition"; scCam.pqsName = "Kerbin"; scCam.ResetCamera(); } } if (currentSite.LaunchSiteName == "Runway" || currentSite.LaunchSiteName == "LaunchPad") { foreach (SpaceCenterCamera2 cam in Resources.FindObjectsOfTypeAll(typeof(SpaceCenterCamera2))) { cam.altitudeInitial = 45f; cam.ResetCamera(); } } else { PQSCity sitePQS = currentSite.staticInstance.pqsCity; foreach (SpaceCenterCamera2 cam in Resources.FindObjectsOfTypeAll(typeof(SpaceCenterCamera2))) { if (sitePQS.repositionToSphere || sitePQS.repositionToSphereSurface) { double nomHeight = currentSite.body.pqsController.GetSurfaceHeight((Vector3d)sitePQS.repositionRadial.normalized) - currentSite.body.Radius; if (sitePQS.repositionToSphereSurface) { nomHeight += sitePQS.repositionRadiusOffset; } cam.altitudeInitial = 0f - (float)nomHeight; } else { cam.altitudeInitial = 0f - (float)sitePQS.repositionRadiusOffset; } cam.ResetCamera(); Log.Normal("fixed the Space Center camera."); } } SetNextMorningPoint(currentSite); }
public WaypointData(WaypointData orig, Contract contract) { type = orig.type; waypoint.altitude = orig.waypoint.altitude; waypoint.celestialName = orig.waypoint.celestialName; waypoint.height = orig.waypoint.height; waypoint.id = orig.waypoint.id; waypoint.index = orig.waypoint.index; waypoint.isClustered = orig.waypoint.isClustered; waypoint.isExplored = orig.waypoint.isExplored; waypoint.isOnSurface = orig.waypoint.isOnSurface; waypoint.landLocked = orig.waypoint.landLocked; waypoint.latitude = orig.waypoint.latitude; waypoint.longitude = orig.waypoint.longitude; waypoint.name = orig.waypoint.name; waypoint.visible = orig.waypoint.visible; randomAltitude = orig.randomAltitude; waterAllowed = orig.waterAllowed; forceEquatorial = orig.forceEquatorial; nearIndex = orig.nearIndex; count = orig.count; minDistance = orig.minDistance; maxDistance = orig.maxDistance; pqsCity = orig.pqsCity; pqsOffset = orig.pqsOffset; parameter = orig.parameter.ToList(); randomName = orig.randomName; underwater = orig.underwater; SetContract(contract); }
public WaypointData(WaypointData orig, Contract contract) { type = orig.type; waypoint.altitude = orig.waypoint.altitude; waypoint.celestialName = orig.waypoint.celestialName; waypoint.height = orig.waypoint.height; waypoint.id = orig.waypoint.id; waypoint.index = orig.waypoint.index; waypoint.isClustered = orig.waypoint.isClustered; waypoint.isExplored = orig.waypoint.isExplored; waypoint.isOnSurface = orig.waypoint.isOnSurface; waypoint.landLocked = orig.waypoint.landLocked; waypoint.latitude = orig.waypoint.latitude; waypoint.longitude = orig.waypoint.longitude; waypoint.name = orig.waypoint.name; randomAltitude = orig.randomAltitude; waterAllowed = orig.waterAllowed; forceEquatorial = orig.forceEquatorial; nearIndex = orig.nearIndex; count = orig.count; minDistance = orig.minDistance; maxDistance = orig.maxDistance; pqsCity = orig.pqsCity; pqsOffset = orig.pqsOffset; parameter = orig.parameter; hidden = orig.hidden; SetContract(contract); }
public void DetectAnomaly() { if (usesfilm && !LTSUseResources("CameraFilm", 1)) { ScreenMessages.PostScreenMessage("Need more Camera Film!", 6, ScreenMessageStyle.UPPER_CENTER); return; } print("Detecting anomalies!"); PQSCity[] muns = vessel.mainBody.GetComponentsInChildren <PQSCity>(true); double nearest = double.PositiveInfinity; PQSCity anomaly = null; foreach (PQSCity mun in muns) // Find the closest anomaly. { print("Anomaly " + mun.name); double dist = (mun.transform.position - part.transform.position).magnitude; if (dist < nearest) { nearest = dist; anomaly = mun; } } string ExpID = "Space"; string ExpName = ""; float ExpValue = picscival; float ExpData = picdatval; if (anomaly != null) { print("Closest anomaly is " + anomaly.name + " and " + nearest + " away!"); if (nearest < 2500) { double targetAngleTo = Vector3d.Dot(part.transform.up + cameraForward, (anomaly.transform.position - part.transform.position).normalized); print("Angle: " + targetAngleTo); if (targetAngleTo > 1) { ExpID = vessel.mainBody.name + "-" + anomaly.name; ExpValue = (float)((Math.Abs(2500 - nearest) * (targetAngleTo - 1)) / 100) * picscival; ExpName = anomaly.name; ExpData = 20f * picdatval; } } } print(ExpName + " is worth: " + ExpValue); base.experiment.id = specialExperimentName + ExpID; base.experiment.experimentTitle = specialExperimentTitle.Replace("#Anon#", ExpName); base.experiment.baseValue = ExpValue; base.experiment.dataScale = ExpData; base.DeployExperiment(); }
/// <summary> /// Set the SpaceCenterCam to the location os the current LaunchSite /// </summary> /// <param name="currentSite"></param> internal static void SetSpaceCenterCam(KKLaunchSite currentSite) { if (KerbalKonstructs.focusLastLaunchSite && (currentSite.body.name == ConfigUtil.GetCelestialBody("HomeWorld").name)) { foreach (SpaceCenterCamera2 scCam in Resources.FindObjectsOfTypeAll <SpaceCenterCamera2>()) { Log.Normal("Restting to: " + currentSite.LaunchSiteName); scCam.transform.parent = currentSite.lsGameObject.transform; scCam.transform.position = currentSite.lsGameObject.transform.position; scCam.initialPositionTransformName = currentSite.lsGameObject.transform.name; scCam.pqsName = currentSite.body.name; scCam.rotationInitial = currentSite.InitialCameraRotation; scCam.ResetCamera(); KerbalKonstructs.scCamWasAltered = true; } } else { foreach (SpaceCenterCamera2 scCam in Resources.FindObjectsOfTypeAll <SpaceCenterCamera2>()) { Log.Normal("Restting to KSC"); Upgradeables.UpgradeableObject kscRnD = Resources.FindObjectsOfTypeAll <Upgradeables.UpgradeableObject>().Where(x => x.name == "ResearchAndDevelopment").First(); scCam.transform.parent = kscRnD.gameObject.transform; scCam.transform.position = kscRnD.gameObject.transform.transform.position; scCam.initialPositionTransformName = kscRnD.gameObject.transform.name; scCam.pqsName = ConfigUtil.GetCelestialBody("HomeWorld").name; scCam.rotationInitial = -60; scCam.ResetCamera(); KerbalKonstructs.scCamWasAltered = false; } } if (currentSite.LaunchSiteName == "Runway" || currentSite.LaunchSiteName == "LaunchPad" || currentSite.body.name != ConfigUtil.GetCelestialBody("HomeWorld").name) { foreach (SpaceCenterCamera2 cam in Resources.FindObjectsOfTypeAll(typeof(SpaceCenterCamera2))) { cam.altitudeInitial = 45f; cam.ResetCamera(); } } else { PQSCity sitePQS = currentSite.staticInstance.groupCenter.pqsCity; foreach (SpaceCenterCamera2 cam in Resources.FindObjectsOfTypeAll(typeof(SpaceCenterCamera2))) { double nomHeight = currentSite.body.pqsController.GetSurfaceHeight((Vector3d)sitePQS.repositionRadial.normalized) - currentSite.body.Radius; if (sitePQS.repositionToSphereSurface) { nomHeight += sitePQS.repositionRadiusOffset; } cam.altitudeInitial = 0f - (float)nomHeight; cam.ResetCamera(); Log.Normal("fixed the Space Center camera."); } } SetNextMorningPoint(currentSite); }
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); }
private void DetectAnomaly() { if (usesFilm && !LtsUseResources("CameraFilm", 1)) { Util.DisplayScreenMsg("Need more Camera Film!"); return; } print("Detecting anomalies..."); PQSCity[] planetAnomalies = vessel.mainBody.GetComponentsInChildren <PQSCity>(true); double nearest = double.PositiveInfinity; PQSCity anomaly = null; // Find the closest anomaly foreach (PQSCity anom in planetAnomalies) { print("Anomaly: " + anom.name); double dist = (anom.transform.position - part.transform.position).magnitude; if (dist < nearest) { nearest = dist; anomaly = anom; } } string expId = "Space"; string expName = ""; float expValue = picScienceVal; float expData = picDataVal; if (anomaly != null) { print("Closest anomaly is: " + anomaly.name + " and is " + nearest + " m away!"); if (nearest < 2500) { double targetAngleTo = Vector3d.Dot(part.transform.up + cameraForward, (anomaly.transform.position - part.transform.position).normalized); print("Angle: " + targetAngleTo + " degrees"); if (targetAngleTo > 1) { expId = vessel.mainBody.name + "-" + anomaly.name; expValue = (float)(Math.Abs(2500 - nearest) * (targetAngleTo - 1) / 100) * picScienceVal; expName = anomaly.name; expData = 20f * picDataVal; } } } print(expName + " is worth: " + expValue); experiment.id = specialExperimentName + expId; experiment.experimentTitle = specialExperimentTitle.Replace("#Anon#", expName); experiment.baseValue = expValue; experiment.dataScale = expData; DeployExperiment(); }
private void FixFlags() { PQSCity KSC = FlightGlobals.GetHomeBody()?.pqsController?.GetComponentsInChildren <PQSCity>(true)?.FirstOrDefault(p => p?.name == "KSC"); SkinnedMeshRenderer[] flags = KSC?.GetComponentsInChildren <SkinnedMeshRenderer>(true)?.Where(smr => smr?.name == "Flag")?.ToArray(); for (int i = 0; i < flags?.Length; i++) { flags[i].rootBone = flags[i]?.rootBone?.parent?.gameObject?.GetChild("bn_upper_flag_a01")?.transform; } }
public override bool RequirementMet(ConfiguredContract contract) { if (pqsCity != null) { latitude = targetBody.GetLatitude(pqsCity.transform.position); longitude = targetBody.GetLongitude(pqsCity.transform.position); pqsCity = null; } return(SCANsatUtil.IsCovered(latitude, longitude, SCANsatUtil.GetSCANtype(scanType), targetBody)); }
public override void OnLoad(ConfigNode configNode) { latitude = ConfigNodeUtil.ParseValue<double>(configNode, "latitude"); longitude = ConfigNodeUtil.ParseValue<double>(configNode, "longitude"); scanType = ConfigNodeUtil.ParseValue<string>(configNode, "scanType"); string pqsCityName = ConfigNodeUtil.ParseValue<string>(configNode, "pqsCity", ""); if (!string.IsNullOrEmpty(pqsCityName)) { pqsCity = targetBody.GetComponentsInChildren<PQSCity>(true).Where(pqs => pqs.name == pqsCityName).First(); } }
public override void OnLoad(ConfigNode configNode) { latitude = ConfigNodeUtil.ParseValue <double>(configNode, "latitude"); longitude = ConfigNodeUtil.ParseValue <double>(configNode, "longitude"); scanType = ConfigNodeUtil.ParseValue <string>(configNode, "scanType"); string pqsCityName = ConfigNodeUtil.ParseValue <string>(configNode, "pqsCity", ""); if (!string.IsNullOrEmpty(pqsCityName)) { pqsCity = targetBody.GetComponentsInChildren <PQSCity>(true).Where(pqs => pqs.name == pqsCityName).First(); } }
public static PQSCity FindKSC(CelestialBody home) { Transform t = home?.pqsController?.transform?.Find("KSC"); PQSCity KSC = t?.GetComponent <PQSCity>(); if (KSC != null) { return(KSC); } PQSCity[] cities = Resources.FindObjectsOfTypeAll <PQSCity>(); return(cities.FirstOrDefault(c => c.name == "KSC")); }
public KerbalData(KerbalData k) { kerbal = new Kerbal(k.kerbal); body = k.body; orbit = k.orbit; latitude = k.latitude; longitude = k.longitude; altitude = k.altitude; landed = k.landed; owned = k.owned; addToRoster = k.addToRoster; pqsCity = k.pqsCity; pqsOffset = k.pqsOffset; heading = k.heading; }
public KerbalData(KerbalData k) { name = k.name; crewMember = k.crewMember; body = k.body; orbit = k.orbit; latitude = k.latitude; longitude = k.longitude; altitude = k.altitude; landed = k.landed; owned = k.owned; addToRoster = k.addToRoster; pqsCity = k.pqsCity; pqsOffset = k.pqsOffset; }
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); }
public override bool RequirementMet(ConfiguredContract contract) { // Perform another validation of the target body to catch late validation issues due to expressions if (!ValidateTargetBody()) { return(false); } if (pqsCity != null) { latitude = targetBody.GetLatitude(pqsCity.transform.position); longitude = targetBody.GetLongitude(pqsCity.transform.position); pqsCity = null; } return(SCANsatUtil.IsCovered(latitude, longitude, SCANsatUtil.GetSCANtype(scanType), targetBody)); }
public static void DoAirlaunch(AirlaunchParams launchParams) { CelestialBody body = FlightGlobals.currentMainBody; Vessel vessel = FlightGlobals.ActiveVessel; // SpaceCenter.Instance.transform doesn't work correctly with RSS + KSCSwitcher installed PQSCity ksc = Utilities.FindKSC(body); Vector3d kscPosition = ksc.transform.position - body.position; Vector3d kscUp = kscPosition.normalized; Vector3d kscEast = Vector3d.Cross(body.angularVelocity, kscPosition).normalized; Vector3d kscNorth = Vector3d.Cross(kscEast, kscUp); double kscAltitude = kscPosition.magnitude - body.Radius; // From https://www.movable-type.co.uk/scripts/latlong-vectors.html#midpoint var δ = launchParams.KscDistance / body.Radius; var d = kscNorth * Math.Cos(Mathf.Deg2Rad * launchParams.KscAzimuth) + kscEast * Math.Sin(Mathf.Deg2Rad * launchParams.KscAzimuth); var teleportPosition = kscPosition * Math.Cos(δ) + body.Radius * d * Math.Sin(δ); teleportPosition += teleportPosition.normalized * (launchParams.Altitude - kscAltitude); Vector3d up = teleportPosition.normalized; Vector3d east = Vector3d.Cross(body.angularVelocity, teleportPosition).normalized; Vector3d north = Vector3d.Cross(east, up); Vector3d teleportVelocity = Vector3d.Cross(body.angularVelocity, teleportPosition); teleportVelocity += (Math.Sin(Mathf.Deg2Rad * launchParams.LaunchAzimuth) * east + Math.Cos(Mathf.Deg2Rad * launchParams.LaunchAzimuth) * north) * launchParams.Velocity; // counter for the momentary fall when on rails teleportVelocity += up * (body.gravParameter / teleportPosition.sqrMagnitude / 2); teleportPosition = teleportPosition.xzy; teleportVelocity = teleportVelocity.xzy; Vector3d to = teleportPosition.xzy.normalized; Quaternion rotation = Quaternion.LookRotation(-to); rotation *= Quaternion.AngleAxis((float)launchParams.LaunchAzimuth, Vector3.back); Orbit orbit = vessel.orbitDriver.orbit.Clone(); orbit.UpdateFromStateVectors(teleportPosition, teleportVelocity, body, Planetarium.GetUniversalTime()); vessel.SetOrbit(orbit); vessel.SetRotation(rotation); ResetGroundContact(vessel); }
public override bool RequirementMet(ConfiguredContract contract) { // Perform another validation of the target body to catch late validation issues due to expressions if (!ValidateTargetBody()) { return false; } if (pqsCity != null) { latitude = targetBody.GetLatitude(pqsCity.transform.position); longitude = targetBody.GetLongitude(pqsCity.transform.position); pqsCity = null; } return SCANsatUtil.IsCovered(latitude, longitude, SCANsatUtil.GetSCANtype(scanType), targetBody); }
void CityFixer(PQSCity pqs) { // Resize the Building pqs.transform.localScale *= (float)resizeBuildings; // Fix PQSCity Groups if (body.Has("PQSCityGroups")) { Dictionary<object, Vector3> PQSList = body.Get<Dictionary<object, Vector3>>("PQSCityGroups"); if (PQSList.ContainsKey(pqs)) { GroupFixer(pqs, PQSList[pqs].normalized); } } // Fix Altitude double groundLevel = body.pqsController.GetSurfaceHeight(pqs.repositionRadial) - body.Radius; if (!pqs.repositionToSphere && !pqs.repositionToSphereSurface) { // Offset = Distance from the center of the planet double fromRadius = pqs.repositionRadiusOffset - (body.Radius / resize); double builtInOffset = fromRadius - groundLevel / (resize * landscape); pqs.repositionRadiusOffset = body.Radius + groundLevel + builtInOffset * resizeBuildings; } else if (pqs.repositionToSphere && !pqs.repositionToSphereSurface) { // Offset = Distance from the radius of the planet double builtInOffset = pqs.repositionRadiusOffset - groundLevel / (resize * landscape); pqs.repositionRadiusOffset = groundLevel + builtInOffset * resizeBuildings; } else if (pqs.repositionToSphereSurface && pqs.repositionToSphereSurfaceAddHeight) { // Offset = Distance from the surface of the planet pqs.repositionRadiusOffset *= resizeBuildings; } }
private bool isNearbyAnomaly(Vessel v, string anomalyName) { // FIXME: Can we have objects with same names, but on different bodies? // FIXME: So far I think we can. GameObject[] obj = UnityEngine.Object.FindObjectsOfType <GameObject>(); foreach (GameObject anomalyObj in obj) { Component[] c = anomalyObj.GetComponents <PQSCity> (); if (c == null || c.Length == 0) { continue; } KourageousTouristsAddOn.printDebug("has pqscity: " + anomalyObj.name); PQSCity pqscity = (PQSCity)c [0]; if (pqscity == null) { continue; } if (!pqscity.sphere.isAlive) { continue; } Transform tr = anomalyObj.GetComponent <Transform> (); if (!anomalyObj.name.Equals(anomalyName)) { continue; } if (tr == null) { return(false); } float dist1 = Vector3.Distance(v.transform.position, tr.position); KourageousTouristsAddOn.printDebug("distance: " + dist1.ToString() + "; min dist: " + minAnomalyDistance.ToString()); if (dist1 < this.minAnomalyDistance) { return(true); } } return(false); }
void Awake() { // Version Check Debug.Log("[SigmaLog] Version Check: KKtoSD v0.1.5"); // Check if KK is installed if (AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.name == "KerbalKonstructs") == null) { return; } // Get the groups from KK StaticInstance[] KKStatics = StaticDatabase.GetAllStatics(); // Send the groups to SD foreach (StaticInstance KKStatic in KKStatics) { CelestialBody planet = KKStatic?.CelestialBody; string group = KKStatic?.Group; PQSCity mod = KKStatic?.pqsCity; if (planet == null || string.IsNullOrEmpty(group) || mod == null) { continue; } if (!PQSCityGroups.ExternalExceptions.ContainsKey(planet)) { PQSCityGroups.ExternalExceptions.Add(planet, new Dictionary <string, List <object> >()); } if (!PQSCityGroups.ExternalExceptions[planet].ContainsKey(group)) { PQSCityGroups.ExternalExceptions[planet].Add(group, new List <object>()); } if (!PQSCityGroups.ExternalExceptions[planet][group].Contains(mod)) { PQSCityGroups.ExternalExceptions[planet][group].Add(mod); } } }
public DMAnomalyObject(PQSCity City) { city = City; name = city.name; try { body = FlightGlobals.Bodies.FirstOrDefault(b => b.name == city.transform.parent.name); } catch (Exception e) { DMUtils.Logging("Something Went Wrong Here: {0}", e); } if (body != null) { worldLocation = city.transform.position; lat = clampLat(body.GetLatitude(worldLocation)); lon = clampLon(body.GetLongitude(worldLocation)); } }
void FixAltitude(object mod, double terrainShift, double fixAltitude) { Debug.Log("SigmaDimensions.FixAltitude", " > Terrain Shift = " + terrainShift); string type = mod.GetType().ToString(); if (type == "PQSCity") { PQSCity pqs = (PQSCity)mod; if (!pqs.repositionToSphere && !pqs.repositionToSphereSurface) { pqs.repositionToSphereSurface = true; pqs.repositionRadiusOffset = 0; } if (pqs.repositionToSphereSurface && !pqs.repositionToSphereSurfaceAddHeight) { pqs.repositionToSphereSurfaceAddHeight = true; pqs.repositionRadiusOffset = 0; } if (!pqs.repositionToSphereSurface) { pqs.repositionRadiusOffset += terrainShift; } Debug.Log("SigmaDimensions.FixAltitude", " > Mod original repositionRadiusOffset = " + pqs.repositionRadiusOffset); pqs.repositionRadiusOffset += fixAltitude; Debug.Log("SigmaDimensions.FixAltitude", " > Fixed repositionRadiusOffset = " + pqs.repositionRadiusOffset); } else if (type == "PQSCity2") { PQSCity2 pqs = (PQSCity2)mod; if (pqs.snapToSurface) { pqs.snapHeightOffset += fixAltitude; Debug.Log("SigmaDimensions.FixAltitude", " > Fixed snapHeightOffset = " + pqs.snapHeightOffset); } else { pqs.alt += terrainShift + fixAltitude; Debug.Log("SigmaDimensions.FixAltitude", " > Fixed PQSCity2.alt = " + pqs.alt); } } }
internal static void AddPQSCenter(string tgtName) { CelestialBody body = ConfigUtil.GetCelestialBody("HomeWorld"); var mods = body.pqsController.GetComponentsInChildren <PQSCity>(true); PQSCity tgtPQS = null; foreach (var m in mods) { //Log.Normal("PQSName: " + m.name); if (m.name == tgtName) { tgtPQS = m; continue; } } if (tgtPQS == null) { Log.Normal("No BasePQS found: " + tgtName); return; } GroupCenter newGroup = new GroupCenter(); newGroup.isBuiltIn = true; newGroup.Group = tgtName + "_Builtin"; newGroup.CelestialBody = body; newGroup.RotationAngle = tgtPQS.reorientFinalAngle; newGroup.RadialPosition = tgtPQS.repositionRadial; //newGroup.RadiusOffset = (float)0; newGroup.RadiusOffset = (float)tgtPQS.repositionRadiusOffset; //newGroup.repositionToSphere = false; newGroup.SeaLevelAsReference = tgtPQS.repositionToSphere; newGroup.Spawn(); //newGroup.Update(); //Log.Normal("Added GroupCenter:" + newGroup.Group); }
public override bool Load(ConfigNode configNode) { // Before loading, verify the SCANsat version if (!SCANsatUtil.VerifySCANsatVersion()) { return(false); } // Load base class bool valid = base.Load(configNode); // Do not check the requirement on active contracts. Otherwise when they scan the // contract is invalidated, which is usually not what's meant. checkOnActiveContract = false; valid &= ConfigNodeUtil.ParseValue <string>(configNode, "scanType", x => scanType = x, this, "Anomaly", SCANsatUtil.ValidateSCANname); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "latitude", x => latitude = x, this, 0.0); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "longitude", x => longitude = x, this, 0.0); valid &= ConfigNodeUtil.MutuallyExclusive(configNode, new string[] { "latitude", "longitude" }, new string[] { "pqsCity" }, this); valid &= ValidateTargetBody(configNode); string pqsName = null; valid &= ConfigNodeUtil.ParseValue <string>(configNode, "pqsCity", x => pqsName = x, this, (string)null); if (pqsName != null) { try { CelestialBody body = FlightGlobals.Bodies.Where(b => b == targetBody).First(); pqsCity = body.GetComponentsInChildren <PQSCity>(true).Where(pqs => pqs.name == pqsName).First(); } catch (Exception e) { LoggingUtil.LogError(this, "Couldn't load PQSCity with name '" + pqsCity + "'"); LoggingUtil.LogException(e); valid = false; } } return(valid); }
public override bool Load(ConfigNode configNode) { // Before loading, verify the SCANsat version if (!SCANsatUtil.VerifySCANsatVersion()) { return false; } // Load base class bool valid = base.Load(configNode); // Do not check the requirement on active contracts. Otherwise when they scan the // contract is invalidated, which is usually not what's meant. checkOnActiveContract = false; valid &= ConfigNodeUtil.ParseValue<string>(configNode, "scanType", x => scanType = x, this, "Anomaly", SCANsatUtil.ValidateSCANname); valid &= ConfigNodeUtil.ParseValue<double>(configNode, "latitude", x => latitude = x, this, 0.0); valid &= ConfigNodeUtil.ParseValue<double>(configNode, "longitude", x => longitude = x, this, 0.0); valid &= ConfigNodeUtil.MutuallyExclusive(configNode, new string[] { "latitude", "longitude" }, new string[] { "pqsCity" }, this); valid &= ValidateTargetBody(configNode); string pqsName = null; valid &= ConfigNodeUtil.ParseValue<string>(configNode, "pqsCity", x => pqsName = x, this, (string)null); if (pqsName != null) { try { CelestialBody body = FlightGlobals.Bodies.Where(b => b == targetBody).First(); pqsCity = body.GetComponentsInChildren<PQSCity>(true).Where(pqs => pqs.name == pqsName).First(); } catch (Exception e) { LoggingUtil.LogError(this, "Couldn't load PQSCity with name '" + pqsCity + "'"); LoggingUtil.LogException(e); valid = false; } } return valid; }
private void PQSloaded(CelestialBody body, string name) { if (body == null) { return; } if (string.IsNullOrEmpty(name)) { return; } if (body.pqsController == null) { return; } PQSCity[] Cities = body.pqsController.GetComponentsInChildren <PQSCity>(); for (int i = 0; i < Cities.Length; i++) { PQSCity city = Cities[i]; if (city == null) { continue; } if (city.transform.parent.name != body.name) { continue; } if (city.name != name) { continue; } currentAnomaly = new DMAnomalyObject(city); } }
public VesselData(VesselData vd) { name = vd.name; id = vd.id; craftURL = vd.craftURL; craftPart = vd.craftPart; flagURL = vd.flagURL; vesselType = vd.vesselType; body = vd.body; orbit = vd.orbit; latitude = vd.latitude; longitude = vd.longitude; altitude = vd.altitude; height = vd.height; orbiting = vd.orbiting; owned = vd.owned; pqsCity = vd.pqsCity; pqsOffset = vd.pqsOffset; heading = vd.heading; pitch = vd.pitch; roll = vd.roll; }
// Post apply event void IParserEventSubscriber.PostApply(ConfigNode node) { // Should we remove the atmosphere if (body.celestialBody.atmosphere && removeAtmosphere.Value) { // Find atmosphere from ground and destroy the game object AtmosphereFromGround atmosphere = body.scaledVersion.GetComponentsInChildren <AtmosphereFromGround>(true)[0]; atmosphere.transform.parent = null; UnityEngine.Object.Destroy(atmosphere.gameObject); // Destroy the light controller MaterialSetDirection light = body.scaledVersion.GetComponentsInChildren <MaterialSetDirection>(true)[0]; UnityEngine.Object.Destroy(light); // No more atmosphere :( body.celestialBody.atmosphere = false; } // If we have a PQS if (body.pqsVersion != null) { Logger.Active.Log("[Kopernicus]: Configuration.Template: Using Template \"" + body.celestialBody.bodyName + "\""); // Should we remove the ocean? if (body.celestialBody.ocean && removeOcean.Value) { // Find atmosphere the ocean PQS PQS ocean = body.pqsVersion.GetComponentsInChildren <PQS>(true).Where(pqs => pqs != body.pqsVersion).First(); PQSMod_CelestialBodyTransform cbt = body.pqsVersion.GetComponentsInChildren <PQSMod_CelestialBodyTransform>(true).First(); // Destroy the ocean PQS (this could be bad - destroying the secondary fades...) cbt.planetFade.secondaryRenderers.Remove(ocean.gameObject); cbt.secondaryFades = null; ocean.transform.parent = null; UnityEngine.Object.Destroy(ocean); // No more ocean :( body.celestialBody.ocean = false; body.pqsVersion.mapOcean = false; } // Selectively remove PQS Mods if (removePQSMods != null && removePQSMods.Value.LongCount() > 0) { // We need a List with Types to remove List <Type> mods = new List <Type>(); Dictionary <String, Type> modsPerName = new Dictionary <String, Type>(); foreach (String mod in removePQSMods.Value) { // If the definition has a name specified, grab that String mType = mod; String name = ""; if (mType.EndsWith("]")) { String[] split = mType.Split('['); mType = split[0]; name = split[1].Remove(split[1].Length - 1); } // Get the mods matching the String String modName = mType; if (!mod.Contains("PQS")) { modName = "PQSMod_" + mod; } if (name == "") { //mods.Add(Type.GetType(modName + ", Assembly-CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")); Type t = Parser.ModTypes.Find(m => m.Name == modName); if (t != null) { mods.Add(t); } } else { //modsPerName.Add(name, Type.GetType(modName + ", Assembly-CSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")); Type t = Parser.ModTypes.Find(m => m.Name == modName); if (t != null) { modsPerName.Add(name, t); } } } Utility.RemoveModsOfType(mods, body.pqsVersion); foreach (KeyValuePair <String, Type> kvP in modsPerName) { Int32 index = 0; String name = kvP.Key; if (name.Contains(';')) { String[] split = name.Split(';'); name = split[0]; Int32.TryParse(split[1], out index); } PQSMod[] allMods = body.pqsVersion.GetComponentsInChildren(kvP.Value, true).Select(m => m as PQSMod).Where(m => m.name == name).ToArray(); if (allMods.Length > 0) { if (allMods[index] is PQSCity) { PQSCity city = allMods[index] as PQSCity; if (city.lod != null) { foreach (PQSCity.LODRange range in city.lod) { if (range.objects != null) { foreach (GameObject o in range.objects) { UnityEngine.Object.DestroyImmediate(o); } } if (range.renderers != null) { foreach (GameObject o in range.renderers) { UnityEngine.Object.DestroyImmediate(o); } } } } } if (allMods[index] is PQSCity2) { PQSCity2 city = allMods[index] as PQSCity2; if (city.objects != null) { foreach (PQSCity2.LodObject range in city.objects) { if (range.objects != null) { foreach (GameObject o in range.objects) { UnityEngine.Object.DestroyImmediate(o); } } } } } // If no mod is left, delete the game object too GameObject gameObject = allMods[index].gameObject; UnityEngine.Object.DestroyImmediate(allMods[index]); PQSMod[] allRemainingMods = gameObject.GetComponentsInChildren <PQSMod>(true); if (allRemainingMods.Length == 0) { UnityEngine.Object.DestroyImmediate(gameObject); } } } } if (removeAllMods != null && removeAllMods.Value) { // Remove all mods Utility.RemoveModsOfType(null, body.pqsVersion); } } // Should we remove the progress tree if (removeProgressTree.Value) { body.celestialBody.progressTree = null; } // Figure out what kind of body we are if (body.scaledVersion.GetComponentsInChildren <SunShaderController>(true).Length > 0) { type = BodyType.Star; } else if (body.celestialBody.atmosphere) { type = BodyType.Atmospheric; } else { type = BodyType.Vacuum; } // remove coronas if (type == BodyType.Star && removeCoronas) { foreach (SunCoronas corona in body.scaledVersion.GetComponentsInChildren <SunCoronas>(true)) { corona.GetComponent <Renderer>().enabled = false; // RnD hard refs Coronas, so we need to disable them } } // Event Events.OnTemplateLoaderPostApply.Fire(this, node); }
void GroupFixer(PQSCity pqs, Vector3 REFvector) { if (body == FlightGlobals.GetHomeBody()) LinkToKSC(pqs); Vector3 PQSvector = pqs.repositionRadial.normalized; Vector3 NEWvector = Vector3.LerpUnclamped(REFvector, PQSvector, (float)(resizeBuildings / resize)); pqs.repositionRadial = NEWvector; }
void LinkToKSC(PQSCity pqs) { PQSCity KSC = body.GetComponentsInChildren<PQSCity>().First(m => m.name == "KSC"); LatLon movedKSC = new LatLon(KSC.repositionRadial.normalized); Vector3 reference = body.Get<Dictionary<object, Vector3>>("PQSCityGroups")[pqs].normalized; if (reference == movedKSC.vector) { // Fix Rotation float angle = KSC.reorientFinalAngle - (-15); pqs.reorientFinalAngle += angle; // Stock Vectors (KSC, North, East) LatLon stockKSC = new LatLon(new Vector3(157000, -1000, -570000).normalized); Vector3 north = Vector3.ProjectOnPlane(Vector3.up, stockKSC.vector); Vector3 east = QuaternionD.AngleAxis(90, stockKSC.vector) * north; // PQS Vectors (PQS, North, East) Vector3 oldPQS = Vector3.ProjectOnPlane(pqs.repositionRadial.normalized, stockKSC.vector); Vector3 pqsNorth = Vector3.Project(oldPQS, north); Vector3 pqsEast = Vector3.Project(oldPQS, east); // Distance from KSC (Northward, Eastward) float northward = pqsNorth.magnitude * (1 - (Vector3.Angle(north.normalized, pqsNorth.normalized) / 90)); float eastward = pqsEast.magnitude * (1 - (Vector3.Angle(east.normalized, pqsEast.normalized) / 90)); // New KSC Vectors (North, East) Vector3 newNorth = Vector3.ProjectOnPlane(Vector3.up, movedKSC.vector).normalized; Vector3 newEast = (QuaternionD.AngleAxis(90, movedKSC.vector) * newNorth); // Account for PQSCity rotation: // PQSCity rotate when their Longitude changes angle -= (float)(stockKSC.lon - movedKSC.lon); QuaternionD rotation = QuaternionD.AngleAxis(angle, movedKSC.vector); // Calculate final position by adding the north and east distances to the movedKSC position // then rotate the new vector by as many degrees as it is necessary to account for the PQS model rotation pqs.repositionRadial = rotation * (movedKSC.vector + newNorth * northward + newEast * eastward); // Fix Altitude if (!pqs.repositionToSphereSurface) { pqs.repositionRadiusOffset += (body.pqsController.GetSurfaceHeight(movedKSC.vector) - body.Radius) / (resize * landscape) - 64.7846885412; } } }
// Apply the patches public void Start() { // Get the KSC-object from Kerbins PQS if (FlightGlobals.Bodies != null) { body = FlightGlobals.Bodies.First(b => b.isHomeWorld); ksc = body.pqsController.GetComponentsInChildren<PQSCity>(true).First(m => m.name == "KSC"); mapDecal = body.pqsController.GetComponentsInChildren<PQSMod_MapDecalTangent>(true).First(m => m.name == "KSC"); } else { CelestialBody[] bodies = Resources.FindObjectsOfTypeAll<CelestialBody>(); foreach (CelestialBody b in bodies) { if (!b.isHomeWorld) continue; if (b.pqsController == null) continue; ksc = b.pqsController.GetComponentsInChildren<PQSCity>(true).First(m => m.name == "KSC"); if (ksc != null) { body = b; mapDecal = body.pqsController.GetComponentsInChildren<PQSMod_MapDecalTangent>(true).First(m => m.name == "KSC"); break; } } } if (ksc == null) { Debug.LogError("[Kopernicus]: KSC: Unable to find homeworld body with PQSCity named KSC"); return; } if (mapDecal == null) { Debug.LogError("[Kopernicus]: KSC: Unable to find homeworld body with PQSMod_MapDecalTangent named KSC"); return; } // Load new data into the PQSCity if (latitude.HasValue && longitude.HasValue) ksc.repositionRadial = LLAtoECEF(latitude.Value, longitude.Value, 0, body.Radius); else if (repositionRadial.HasValue) ksc.repositionRadial = repositionRadial.Value; if (reorientInitialUp.HasValue) ksc.reorientInitialUp = reorientInitialUp.Value; if (repositionToSphere.HasValue) ksc.repositionToSphere = repositionToSphere.Value; if (repositionToSphereSurface.HasValue) ksc.repositionToSphereSurface = repositionToSphereSurface.Value; if (repositionToSphereSurfaceAddHeight.HasValue) ksc.repositionToSphereSurfaceAddHeight = repositionToSphereSurfaceAddHeight.Value; if (reorientToSphere.HasValue) ksc.reorientToSphere = reorientToSphere.Value; if (repositionRadiusOffset.HasValue) ksc.repositionRadiusOffset = repositionRadiusOffset.Value; if (lodvisibleRangeMult.HasValue) { foreach (PQSCity.LODRange lodRange in ksc.lod) lodRange.visibleRange *= (float)lodvisibleRangeMult.Value; } if (reorientFinalAngle.HasValue) ksc.reorientFinalAngle = reorientFinalAngle.Value; // Load new data into the MapDecal if (radius.HasValue) mapDecal.radius = radius.Value; if (heightMapDeformity.HasValue) mapDecal.heightMapDeformity = heightMapDeformity.Value; if (absoluteOffset.HasValue) mapDecal.absoluteOffset = absoluteOffset.Value; if (absolute.HasValue) mapDecal.absolute = absolute.Value; if (decalLatitude.HasValue && decalLongitude.HasValue) mapDecal.position = LLAtoECEF(decalLatitude.Value, decalLongitude.Value, 0, body.Radius); else if (position.HasValue) mapDecal.position = position.Value; // Move the SpaceCenter if (SpaceCenter.Instance != null) { SpaceCenter.Instance.transform.localPosition = ksc.transform.localPosition; SpaceCenter.Instance.transform.localRotation = ksc.transform.localRotation; // Reset the SpaceCenter SpaceCenter.Instance.Start(); } else Debug.Log("[Kopernicus]: KSC: No SpaceCenter instance!"); // Add a material fixer DontDestroyOnLoad(gameObject.AddComponent<MaterialFixer>()); }
public KerbalData(KerbalData k) { name = k.name; crewMember = k.crewMember; body = k.body; orbit = k.orbit; latitude = k.latitude; longitude = k.longitude; altitude = k.altitude; landed = k.landed; owned = k.owned; addToRoster = k.addToRoster; gender = k.gender; kerbalType = k.kerbalType; pqsCity = k.pqsCity; pqsOffset = k.pqsOffset; heading = k.heading; }
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; } }