/// <summary> /// Return the vessel ids of the OTHER vessels that are far, dead, in safety bubble, and being updated by us. /// We use this list to relase the locks as we shouldn't update them /// </summary> /// <returns></returns> private static IEnumerable <Guid> GetSecondaryVesselIdsThatShouldBeReleased() { return(FlightGlobals.Vessels .Where(v => v.id != FlightGlobals.ActiveVessel.id && SystemsContainer.Get <LockSystem>().LockIsOurs($"update-{v.id}") && (!v.loaded || v.state == Vessel.State.DEAD || VesselCommon.IsInSafetyBubble(v))) .Select(v => v.id)); }
/// <summary> /// Return the OTHER vessel ids of the vessels that are loaded (close to us) not dead and not in safety bubble. /// </summary> /// <returns></returns> private static IEnumerable <Guid> GetValidSecondaryVesselIds() { return(FlightGlobals.Vessels .Where(v => v.loaded && v.state != Vessel.State.DEAD && (v.id != FlightGlobals.ActiveVessel.id) && !VesselCommon.IsInSafetyBubble(v) && !LockSystem.Singleton.LockExists("update-" + v.id)) .Select(v => v.id)); }
/// <summary> /// Return the OTHER vessel ids of the vessels that are loaded (close to us) not dead and not in safety bubble. /// </summary> /// <returns></returns> private static IEnumerable <Guid> GetValidSecondaryVesselIds() { return(FlightGlobals.Vessels .Where(v => v.loaded && v.state != Vessel.State.DEAD && v.id != FlightGlobals.ActiveVessel.id && !VesselCommon.IsInSafetyBubble(v) && !SystemsContainer.Get <LockSystem>().LockExists($"update-{v.id}")) .Select(v => v.id)); }
/// <summary> /// Return the vessel ids of the OTHER vessels that are far, dead, in safety bubble, and being updated by us. /// We use this list to relase the locks as we shouldn't update them /// </summary> /// <returns></returns> private static IEnumerable <Guid> GetSecondaryVesselIdsThatShouldBeReleased() { return(FlightGlobals.Vessels .Where(v => v.id != FlightGlobals.ActiveVessel.id && LockSystem.LockQuery.UpdateLockBelongsToPlayer(v.id, SettingsSystem.CurrentSettings.PlayerName) && (!v.loaded || v.state == Vessel.State.DEAD || VesselCommon.IsInSafetyBubble(v))) .Select(v => v.id)); }
/// <summary> /// Return the OTHER vessel ids of the vessels that are unloadedloaded not dead, not in safety bubble /// and that nobody has the unloaded update or update lock /// </summary> private static IEnumerable <Guid> GetValidUnloadedVesselIds() { return(FlightGlobals.Vessels .Where(v => v != null && v.state != Vessel.State.DEAD && !v.loaded && v.vesselType != VesselType.Flag && v.id != FlightGlobals.ActiveVessel?.id && !VesselCommon.IsInSafetyBubble(v) && !LockSystem.LockQuery.UnloadedUpdateLockExists(v.id) && !LockSystem.LockQuery.UpdateLockExists(v.id)) .Select(v => v.id)); }
/// <summary> /// Removes the vessels that are inside the safety bubble /// </summary> public void RemoveVesselsInSafetyBubble() { foreach (var vessel in FlightGlobals.Vessels.ToArray()) { if (vessel != null && VesselCommon.IsInSafetyBubble(vessel) && FlightGlobals.ActiveVessel?.id != vessel.id) { LunaLog.Log($"[LMP]: Killing vessel {vessel.id} because it's inside safety bubble"); UnloadVesselFromGame(vessel); KillGivenVessel(vessel); UnloadVesselFromScenario(vessel); } } }
/// <summary> /// Return the OTHER vessel ids of the vessels that are loaded (close to us) not dead and not in safety bubble. /// </summary> /// <returns></returns> private static IEnumerable <Guid> GetValidSecondaryVesselIds() { //An spectator should never have Update/UnloadedUpdate locks if (VesselCommon.IsSpectating) { return(new Guid[0]); } return(FlightGlobals.VesselsLoaded .Where(v => v != null && v.state != Vessel.State.DEAD && v.id != FlightGlobals.ActiveVessel?.id && !VesselCommon.IsInSafetyBubble(v) && !LockSystem.LockQuery.UpdateLockExists(v.id)) .Select(v => v.id)); }
/// <summary> /// Return the vessel ids of the OTHER vessels that are far, dead, in safety bubble, and being updated by us. /// We use this list to relase the locks as we shouldn't update them /// </summary> /// <returns></returns> private static IEnumerable <Guid> GetSecondaryVesselIdsThatShouldBeReleased() { //An spectator should never have Update/UnloadedUpdate locks if (VesselCommon.IsSpectating) { return(LockSystem.LockQuery.GetAllUpdateLocks(SettingsSystem.CurrentSettings.PlayerName) .Select(l => l.VesselId) .Union(LockSystem.LockQuery.GetAllUnloadedUpdateLocks(SettingsSystem.CurrentSettings.PlayerName) .Select(l => l.VesselId))); } return(FlightGlobals.Vessels .Where(v => v.id != FlightGlobals.ActiveVessel?.id && LockSystem.LockQuery.UpdateLockBelongsToPlayer(v.id, SettingsSystem.CurrentSettings.PlayerName) && (!v.loaded || v.state == Vessel.State.DEAD || VesselCommon.IsInSafetyBubble(v))) .Select(v => v.id)); }
private static string GetCurrentShipStatus() { var bodyName = VesselCommon.IsInSafetyBubble(FlightGlobals.ActiveVessel) ? "safety bubble" : FlightGlobals.ActiveVessel.mainBody.bodyName; switch (FlightGlobals.ActiveVessel.situation) { case Vessel.Situations.DOCKED: return($"Docked above {bodyName}"); case Vessel.Situations.ESCAPING: if (FlightGlobals.ActiveVessel.orbit.timeToPe < 0) { return($"Escaping {bodyName}"); } return($"Encountering {bodyName}"); case Vessel.Situations.FLYING: return($"Flying above {bodyName}"); case Vessel.Situations.LANDED: return($"Landed on {bodyName}"); case Vessel.Situations.ORBITING: return($"Orbiting {bodyName}"); case Vessel.Situations.PRELAUNCH: return($"Launching from {bodyName}"); case Vessel.Situations.SPLASHED: return($"Splashed on {bodyName}"); case Vessel.Situations.SUB_ORBITAL: if (FlightGlobals.ActiveVessel.verticalSpeed > 0) { return($"Ascending from {bodyName}"); } return($"Descending to {bodyName}"); default: return("Error"); } }
/// <summary> /// The debris that is on the safety bubble SHOULD NEVER be synced with the server and at the same time /// it won't exist for any other player so here we just remove it in a routine /// </summary> private void RemoveSafetyBubbleDebris() { if (!HighLogic.LoadedSceneIsFlight) { return; } DebrisInSafetyBubbleToRemove.Clear(); DebrisInSafetyBubbleToRemove.AddRange(FlightGlobals.Vessels.Where(v => v != null && v.state == Vessel.State.INACTIVE && v.vesselType != VesselType.Flag && v.id != FlightGlobals.ActiveVessel?.id && VesselCommon.IsInSafetyBubble(v))); foreach (var vessel in DebrisInSafetyBubbleToRemove) { if (vessel == null) { continue; } LunaLog.Log($"[LMP]: Vessel {vessel.id} name {vessel.vesselName} it's an inactive vessel inside the safety bubble."); KillVessel(vessel.id); } }