// Returns whether a site is open or closed and how much it costs to open public static void getSiteOpenCloseState(string sSiteName, out string sOpenCloseState, out float fOpenCost) { List <LaunchSite> sites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in sites) { if (site.LaunchSiteName == sSiteName) { sOpenCloseState = site.OpenCloseState; fOpenCost = site.OpenCost; return; } } sOpenCloseState = "Open"; fOpenCost = 0; }
public static void ResetLauncsite() { if (currentLaunchSite == "Runway" || currentLaunchSite == "LaunchPad" || currentLaunchSite == "KSC" || currentLaunchSite.Length == 0) { return; } // reset the name to the site, so it can be fetched again KKLaunchSite lastSite = LaunchSiteManager.GetCurrentLaunchSite(); if (lastSite != null) { lastSite.spaceCenterFacility.name = lastSite.LaunchSiteName; } else { // do nothing } }
//// Closes all launchsites. Necessary when leaving a career game and going to the main menu //public static void setAllLaunchsitesClosed() //{ // List<LaunchSite> sites = LaunchSiteManager.getLaunchSites(); // foreach (LaunchSite site in sites) // { // site.OpenCloseState = "Closed"; // } //} // Returns the distance in m from a position to a specified Launchsite public static float getDistanceToBase(Vector3 position, LaunchSite lTarget) { float flRange = 0f; List <LaunchSite> sites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in sites) { if (site == lTarget) { var radialposition = site.lsGameObject.transform.position; var dist = Vector3.Distance(position, radialposition); flRange = dist; } } return(flRange); }
public static List <ProtoVessel> FindVesselsLandedAt2(FlightState flightState, string landedAt) { float maxDistance = 100f; List <ProtoVessel> list = new List <ProtoVessel>(); if (flightState != null) { KKLaunchSite launchSite = LaunchSiteManager.GetLaunchSiteByName(landedAt); foreach (ProtoVessel vessel in flightState.protoVessels) { if (vessel == null) { continue; } if (launchSite == null || launchSite.isSquad) { if (vessel.landedAt.Contains(landedAt)) { list.Add(vessel); } } else { //if (vessel.situation == Vessel.Situations.SPLASHED || vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.PRELAUNCH) //{ CelestialBody body = FlightGlobals.Bodies[vessel.orbitSnapShot.ReferenceBodyIndex]; Vector3 position = body.GetWorldSurfacePosition(vessel.latitude, vessel.longitude, vessel.altitude); float distance = Vector3.Distance(position, launchSite.staticInstance.transform.position); if (distance < maxDistance) { Log.Normal("Found Vessel at Launchsite with distance: " + distance); list.Add(vessel); } //} } } } return(list); }
// Unlock a launchsite so it can be opened or closed or launched from public static void setSiteUnlocked(string sSiteName) { List <LaunchSite> sites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in sites) { if (site.LaunchSiteName == sSiteName) { if (site.OpenCloseState == "OpenLocked") { site.OpenCloseState = "Open"; } else { site.OpenCloseState = "Closed"; } return; } } }
public void LauchVessel() { LaunchSiteManager.setLaunchSite(LaunchSiteManager.GetLaunchSiteByName(siteName)); EditorLogic.fetch.launchVessel(); }
// Returns the nearest Launchsite to a position and range in m to the Launchsite, regardless of whether it is open or closed public static void getNearestBase(Vector3 position, out string sBase, out string sBase2, out float flRange, out LaunchSite lSite, out LaunchSite lSite2) { SpaceCenter KSC = SpaceCenter.Instance; var smallestDist = Vector3.Distance(KSC.gameObject.transform.position, position); var lastSmallestDist = Vector3.Distance(KSC.gameObject.transform.position, position); string sNearestBase = ""; LaunchSite lTargetSite = null; LaunchSite lLastSite = null; LaunchSite lKSC = null; string sLastNearest = ""; List <LaunchSite> basesites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in basesites) { if (site.lsGameObject == null) { continue; } var radialposition = site.lsGameObject.transform.position; var dist = Vector3.Distance(position, radialposition); if (radialposition == position) { continue; } if (site.LaunchSiteName == "Runway" || site.LaunchSiteName == "LaunchPad") { lKSC = site; } else { if ((float)dist < (float)smallestDist) { sLastNearest = sNearestBase; lLastSite = lTargetSite; lastSmallestDist = smallestDist; sNearestBase = site.LaunchSiteName; smallestDist = dist; lTargetSite = site; } else if (dist < lastSmallestDist) { sLastNearest = site.LaunchSiteName; lastSmallestDist = dist; lLastSite = site; } } } if (sNearestBase == "") { sNearestBase = "KSC"; lTargetSite = lKSC; } if (sLastNearest == "") { sLastNearest = "KSC"; lLastSite = lKSC; } rangeNearestBase = (float)smallestDist; sBase = sNearestBase; sBase2 = sLastNearest; flRange = rangeNearestBase; lSite = lTargetSite; lSite2 = lLastSite; }
// Returns the nearest open Launchsite to a position and range to the Launchsite in m // The basic ATC feature is in here for now public static void GetNearestOpenBase(Vector3 position, out string sBase, out float flRange, out LaunchSite lNearest) { SpaceCenter KSC = SpaceCenter.Instance; var smallestDist = Vector3.Distance(KSC.gameObject.transform.position, position); string sNearestBase = ""; LaunchSite lNearestBase = null; LaunchSite lKSC = null; List <LaunchSite> basesites = LaunchSiteManager.getLaunchSites(); foreach (LaunchSite site in basesites) { if (site.isOpen) { var radialposition = site.lsGameObject.transform.position; var dist = Vector3.Distance(position, radialposition); if (site.LaunchSiteName == "Runway") { if (lNearestBase == null) { lNearestBase = site; } lKSC = site; } else if (site.LaunchSiteName != "LaunchPad") { if ((float)dist < (float)smallestDist) { { sNearestBase = site.LaunchSiteName; lNearestBase = site; smallestDist = dist; } } } else { lKSC = site; } } } if (sNearestBase == "") { sNearestBase = "KSC"; lNearestBase = lKSC; } rangeNearestOpenBase = (float)smallestDist; // Air traffic control messaging if (LandingGuideUI.instance.IsOpen()) { if (sNearestBase != nearestOpenBase) { if (rangeNearestOpenBase < 25000) { nearestOpenBase = sNearestBase; MessageSystemButton.MessageButtonColor color = MessageSystemButton.MessageButtonColor.BLUE; MessageSystem.Message m = new MessageSystem.Message("KK ATC", "You have entered the airspace of " + sNearestBase + " ATC. Please keep this channel open and obey all signal lights. Thank you. " + sNearestBase + " Air Traffic Control out.", color, MessageSystemButton.ButtonIcons.MESSAGE); MessageSystem.Instance.AddMessage(m); } else if (nearestOpenBase != "") { // you have left ... MessageSystemButton.MessageButtonColor color = MessageSystemButton.MessageButtonColor.GREEN; MessageSystem.Message m = new MessageSystem.Message("KK ATC", "You are now leaving the airspace of " + sNearestBase + ". Safe journey. " + sNearestBase + " Air Traffic Control out.", color, MessageSystemButton.ButtonIcons.MESSAGE); MessageSystem.Instance.AddMessage(m); nearestOpenBase = ""; } } } sBase = sNearestBase; flRange = rangeNearestOpenBase; lNearest = lNearestBase; }