public bool CheckVesselState(Vessel v) { Enums.VesselState currentState = Enums.ConvertVesselState(v.state); if ((currentState & vesselState) != currentState) { //Utils.Log("Prereq failed: Expected situation " + situation + ", but was " + v.situation); return(false); } return(true); }
private bool IsFlightSituationChanged() { bool changed = false; Vessel v = SoundtrackEditor.InitialLoadingComplete ? FlightGlobals.ActiveVessel : null; if (v != null) { Enums.Selector inAtmosphere = v.atmDensity > 0 ? Enums.Selector.True : Enums.Selector.False; if (SoundtrackEditor.CurrentSituation.inAtmosphere != inAtmosphere) { SoundtrackEditor.CurrentSituation.inAtmosphere = inAtmosphere; if (MonitorInAtmosphere) { Utils.Log("In atmosphere changed"); changed = true; } } // For surface velocity, orbital velocity and altitude, check if we crossed the monitored point going in either direction. if (MonitorSurfaceVelocity) { if ((v.srf_velocity.magnitude > _maxSrfVel && v.srf_velocity.magnitude < _previousSrfVel) || (v.srf_velocity.magnitude < _maxSrfVel && v.srf_velocity.magnitude > _previousSrfVel)) { changed = true; } if ((v.srf_velocity.magnitude > _minSrfVel && v.srf_velocity.magnitude < _previousSrfVel) || (v.srf_velocity.magnitude < _minSrfVel && v.srf_velocity.magnitude > _previousSrfVel)) { changed = true; } _previousSrfVel = v.srf_velocity.magnitude; } if (MonitorOrbitalVelocity) { if ((v.obt_velocity.magnitude > _maxObtVel && v.obt_velocity.magnitude < _previousObtVel) || (v.obt_velocity.magnitude < _maxObtVel && v.obt_velocity.magnitude > _previousObtVel)) { changed = true; } if ((v.obt_velocity.magnitude > _minObtVel && v.obt_velocity.magnitude < _previousObtVel) || (v.obt_velocity.magnitude < _minObtVel && v.obt_velocity.magnitude > _previousObtVel)) { changed = true; } _previousObtVel = v.obt_velocity.magnitude; } if (MonitorAltitude) { if ((v.altitude > _maxAlt && v.altitude < _previousAlt) || (v.altitude < _maxAlt && v.altitude > _previousAlt)) { changed = true; } if ((v.altitude > _minAlt && v.altitude < _previousAlt) || (v.altitude < _minAlt && v.altitude > _previousAlt)) { changed = true; } _previousAlt = v.altitude; } if (MonitorNearestVessel) { Vessel newVessel = Utils.GetNearestVessel(_minVesselDist, _maxVesselDist, v); if (newVessel != null && NearestVessel != newVessel) { NearestVessel = newVessel; changed = true; } } if (MonitorVesselState) { if (_previousVesselState != Enums.ConvertVesselState(v.state)) { Utils.Log("Vessel state changed"); _previousVesselState = Enums.ConvertVesselState(v.state); changed = true; } } if (MonitorVesselType) { if (_previousVesselType != Enums.VesselTypetoCustomVesselType(v.vesselType)) { Utils.Log("Vessel type changed"); _previousVesselType = Enums.VesselTypetoCustomVesselType(v.vesselType); changed = true; } } } return(changed); }
private void UpdateSituation() { bool changed = false; // Throws exceptions before the initial loading screen is completed. if (SoundtrackEditor.CurrentSituation.scene == Enums.Scenes.Flight) { Vessel v = SoundtrackEditor.InitialLoadingComplete ? FlightGlobals.ActiveVessel : null; if (v != null) { Enums.Selector inAtmosphere = v.atmDensity > 0 ? Enums.Selector.True : Enums.Selector.False; if (SoundtrackEditor.CurrentSituation.inAtmosphere != inAtmosphere) { SoundtrackEditor.CurrentSituation.inAtmosphere = inAtmosphere; if (MonitorInAtmosphere) { Utils.Log("In atmosphere changed"); changed = true; } } // For surface velocity, orbital velocity and altitude, check if we crossed the monitored point going in either direction. if (MonitorSurfaceVelocity) { if ((v.srf_velocity.magnitude > _maxSrfVel && v.srf_velocity.magnitude < _previousSrfVel) || (v.srf_velocity.magnitude < _maxSrfVel && v.srf_velocity.magnitude > _previousSrfVel)) { changed = true; } if ((v.srf_velocity.magnitude > _minSrfVel && v.srf_velocity.magnitude < _previousSrfVel) || (v.srf_velocity.magnitude < _minSrfVel && v.srf_velocity.magnitude > _previousSrfVel)) { changed = true; } _previousSrfVel = v.srf_velocity.magnitude; } if (MonitorOrbitalVelocity) { if ((v.obt_velocity.magnitude > _maxObtVel && v.obt_velocity.magnitude < _previousObtVel) || (v.obt_velocity.magnitude < _maxObtVel && v.obt_velocity.magnitude > _previousObtVel)) { changed = true; } if ((v.obt_velocity.magnitude > _minObtVel && v.obt_velocity.magnitude < _previousObtVel) || (v.obt_velocity.magnitude < _minObtVel && v.obt_velocity.magnitude > _previousObtVel)) { changed = true; } _previousObtVel = v.obt_velocity.magnitude; } if (MonitorAltitude) { if ((v.altitude > _maxAlt && v.altitude < _previousAlt) || (v.altitude < _maxAlt && v.altitude > _previousAlt)) { changed = true; } if ((v.altitude > _minAlt && v.altitude < _previousAlt) || (v.altitude < _minAlt && v.altitude > _previousAlt)) { changed = true; } _previousAlt = v.altitude; } if (MonitorNearestVessel) { Vessel newVessel = Utils.GetNearestVessel(_minVesselDist, _maxVesselDist, v); if (newVessel != null && NearestVessel != newVessel) { NearestVessel = newVessel; changed = true; } } if (MonitorVesselState) { if (_previousVesselState != Enums.ConvertVesselState(v.state)) { Utils.Log("Vessel state changed"); _previousVesselState = Enums.ConvertVesselState(v.state); changed = true; } } } } else if (SoundtrackEditor.CurrentSituation.scene == Enums.Scenes.SpaceCentre) { if (MonitorTimeOfDay) { if (_homeBody == null) { _homeBody = FlightGlobals.GetHomeBody(); } double localTime = Sun.Instance.GetLocalTimeAtPosition(Utils.KscLatitude, Utils.KscLongitude, _homeBody); Enums.TimesOfDay tod = Enums.TimeToTimeOfDay(localTime); if (SoundtrackEditor.CurrentSituation.timeOfDay != tod) { SoundtrackEditor.CurrentSituation.timeOfDay = tod; changed = true; } } } else { SoundtrackEditor.CurrentSituation.paused = Enums.Selector.False; } if (changed) { SoundtrackEditor.Instance.OnSituationChanged(); } }