예제 #1
0
        /// <summary>
        /// Called when the flight starts, or when the part is created in the editor. OnStart will be called
        ///  before OnUpdate or OnFixedUpdate are ever called.
        /// </summary>
        /// <param name="state">Some information about what situation the vessel is starting in.</param>
        public override void OnStart(StartState state)
        {
            _audioSource = gameObject.AddComponent <AudioSource> ();
            if (terrainAudio != null && terrainAudio.sound == null)
            {
                terrainAudio = part.partInfo.partPrefab.Modules.GetModules <ModuleTAWS> ()[0].terrainAudio;
            }
            _audioSource.dopplerLevel = 0.0f;
            _audioSource.panLevel     = 0.0f;
            _audioSource.enabled      = true;
            _audioSource.Stop();
            _winID = GUIUtility.GetControlID(FocusType.Passive);

            _prevTime = Planetarium.GetUniversalTime() + 2.0d;
            if (!forwardLookingRadar)
            {
                Fields ["fltrRadar"].guiActive       = false;
                Fields ["fltrRadar"].guiActiveEditor = false;
                fltrRadar = false;
            }

            _transform = part.transform;
            if (scanTransform.Length > 0)
            {
                Transform tempTransform = part.FindModelTransform(scanTransform);
                if (tempTransform != null)
                {
                    _transform = tempTransform;
                }
            }
            _warningActiveModule = null;
        }
예제 #2
0
 /// <summary>
 /// Sets the Terrain warning.
 /// </summary>
 private void TerrainWarning()
 {
     if (_warningActiveModule != null && _warningActiveModule != this)
     {
         return;
     }
     else
     {
         _warningActiveModule = this;
     }
 }
예제 #3
0
        /// <summary>
        /// Called on physics update. Determine if we should issue a warning.
        /// </summary>
        public void FixedUpdate()
        {
            if (vessel == null)
            {
                return;
            }

            double ut = Planetarium.GetUniversalTime();

            radarAltitude = FlightHistSample.GetRadarAltitude(vessel);
            if (ut - _prevTime >= SAMPLE_INTERVAL)
            {
                double deltaTime = ut - _prevTime;
                _prevTime = ut;
                FlightHistSample sample = new FlightHistSample(vessel);
                if (fltrRadar && radarAltitude < warnAltitudeMax * 1.2f && vessel.situation != Vessel.Situations.LANDED)
                {
                    part.RequestResource("ElectricCharge", deltaTime * fltrChargeRate);
                    sample.RadarContact = ForwardRadar(Math.PI / 4);
                }
                radarDistance = sample.RadarContact;
                _flightHist.Add(sample);

                while (_flightHist.Count > 2 && (sample.UT - _flightHist [0].UT) > sampleWindow)
                {
                    _flightHist.RemoveAt(0);
                }
            }
            if (_flightHist.Count < 2)
            {
                return;
            }

            FlightHistSample oldest = _flightHist [0];
            FlightHistSample newest = _flightHist [_flightHist.Count - 1];

            double descentRate = (oldest.RadarHeight - newest.RadarHeight) / (newest.UT - oldest.UT);

            if (descentRate < -vessel.verticalSpeed)
            {
                descentRate = -vessel.verticalSpeed;
            }
            measuredDescentRate = (float)descentRate;

            bool overHeight = newest.RadarHeight > warnAltitudeMax && newest.RadarContact > warnAltitudeMax;

            double tolerance = 1.0d;
            bool   gearDown  = IsGearDown();

            if (gearDown)
            {
                tolerance = (double)landingTolerance;
            }

            double descentRateThreshold = (warnApproachVelMax - warnApproachVelMin) * (newest.RadarHeight / warnAltitudeMax) * tolerance +
                                          warnApproachVelMin;
            double approachRateThreshold = 0.0d;

            if (!float.IsNaN(newest.RadarContact))
            {
                approachRateThreshold = (warnApproachVelMax - warnApproachVelMin) * (newest.RadarContact / warnAltitudeMax) * tolerance +
                                        warnApproachVelMin;
            }

            if (!overHeight && descentRate > descentRateThreshold)
            {
                if (!_warningActive)
                {
                    _warningActive = true;
                    _warningTime   = ut;
                    Debug.Log("TAWS - Descent Rate:" + descentRate + " Gear Down:" + gearDown);
                }
                TerrainWarning();
            }
            else if (!overHeight && !float.IsNaN(newest.RadarContact) && newest.RadarContact < warnAltitudeMax &&
                     Vector3.Dot(vessel.srf_velocity, _transform.forward) > approachRateThreshold)
            {
                if (!_warningActive)
                {
                    _warningActive = true;
                    _warningTime   = ut;
                    Debug.Log("TAWS - Approach Rate:" + Vector3.Dot(vessel.srf_velocity, _transform.forward) + " Gear Down:" + gearDown);
                }
                TerrainWarning();
            }
            else
            {
                _playing = null;
                _audioSource.Stop();
                _warningActive = false;
                if (_warningActiveModule == this)
                {
                    _warningActiveModule = null;
                }
            }
        }
예제 #4
0
 public override void OnInactive()
 {
     base.OnInactive();
     _warningActiveModule = null;
 }
예제 #5
0
        /// <summary>
        /// Called on physics update. Determine if we should issue a warning.
        /// </summary>
        public void FixedUpdate()
        {
            if (vessel == null) {
                return;
            }

            double ut = Planetarium.GetUniversalTime ();
            radarAltitude = FlightHistSample.GetRadarAltitude (vessel);
            if (ut - _prevTime >= SAMPLE_INTERVAL) {
                double deltaTime = ut - _prevTime;
                _prevTime = ut;
                FlightHistSample sample = new FlightHistSample (vessel);
                if (fltrRadar && radarAltitude <  warnAltitudeMax * 1.2f && vessel.situation != Vessel.Situations.LANDED) {
                    part.RequestResource ("ElectricCharge", deltaTime * fltrChargeRate);
                    sample.RadarContact = ForwardRadar (Math.PI / 4);
                }
                radarDistance = sample.RadarContact;
                _flightHist.Add (sample);

                while (_flightHist.Count > 2 && (sample.UT - _flightHist [0].UT) > sampleWindow) {
                    _flightHist.RemoveAt (0);
                }
            }
            if (_flightHist.Count < 2)
                return;

            FlightHistSample oldest = _flightHist [0];
            FlightHistSample newest = _flightHist [_flightHist.Count - 1];

            double descentRate = (oldest.RadarHeight - newest.RadarHeight) / (newest.UT - oldest.UT);
            if (descentRate < -vessel.verticalSpeed)
                descentRate = -vessel.verticalSpeed;
            measuredDescentRate = (float)descentRate;

            bool overHeight = newest.RadarHeight > warnAltitudeMax && newest.RadarContact > warnAltitudeMax;

            double tolerance = 1.0d;
            bool gearDown = IsGearDown ();
            if (gearDown)
                tolerance = (double)landingTolerance;

            double descentRateThreshold = (warnApproachVelMax - warnApproachVelMin) * (newest.RadarHeight / warnAltitudeMax) * tolerance +
                warnApproachVelMin;
            double approachRateThreshold = 0.0d;
            if (!float.IsNaN (newest.RadarContact)) {
                approachRateThreshold = (warnApproachVelMax - warnApproachVelMin) * (newest.RadarContact / warnAltitudeMax) * tolerance +
                    warnApproachVelMin;
            }

            if (!overHeight && descentRate > descentRateThreshold ) {
                if (!_warningActive) {
                    _warningActive = true;
                    _warningTime = ut;
                    Debug.Log("TAWS - Descent Rate:" + descentRate + " Gear Down:"+gearDown);
                }
                TerrainWarning ();
            } else if (!overHeight &&  !float.IsNaN(newest.RadarContact) && newest.RadarContact < warnAltitudeMax &&
                Vector3.Dot(vessel.srf_velocity,_transform.forward) > approachRateThreshold) {
                if (!_warningActive) {
                    _warningActive = true;
                    _warningTime = ut;
                    Debug.Log("TAWS - Approach Rate:" + Vector3.Dot(vessel.srf_velocity,_transform.forward)+ " Gear Down:"+gearDown);
                }
                TerrainWarning ();
            } else {
                _playing = null;
                _audioSource.Stop ();
                _warningActive = false;
                if (_warningActiveModule == this)
                    _warningActiveModule = null;
            }
        }
예제 #6
0
 /// <summary>
 /// Sets the Terrain warning.
 /// </summary>
 private void TerrainWarning()
 {
     if (_warningActiveModule != null && _warningActiveModule != this) {
         return;
     } else {
         _warningActiveModule = this;
     }
 }
예제 #7
0
        /// <summary>
        /// Called when the flight starts, or when the part is created in the editor. OnStart will be called
        ///  before OnUpdate or OnFixedUpdate are ever called.
        /// </summary>
        /// <param name="state">Some information about what situation the vessel is starting in.</param>
        public override void OnStart(StartState state)
        {
            _audioSource = gameObject.AddComponent<AudioSource> ();
            if (terrainAudio != null && terrainAudio.sound == null) {
                terrainAudio = part.partInfo.partPrefab.Modules.GetModules<ModuleTAWS> ()[0].terrainAudio;
            }
            _audioSource.dopplerLevel = 0.0f;
            _audioSource.panLevel = 0.0f;
            _audioSource.enabled = true;
            _audioSource.Stop ();
            _winID = GUIUtility.GetControlID (FocusType.Passive);

            _prevTime = Planetarium.GetUniversalTime () + 2.0d;
            if (!forwardLookingRadar) {
                Fields ["fltrRadar"].guiActive = false;
                Fields ["fltrRadar"].guiActiveEditor = false;
                fltrRadar = false;
            }

            _transform = part.transform;
            if (scanTransform.Length > 0) {
                Transform tempTransform = part.FindModelTransform (scanTransform);
                if (tempTransform != null) {
                    _transform = tempTransform;
                }
            }
            _warningActiveModule = null;
        }
예제 #8
0
 public override void OnInactive()
 {
     base.OnInactive ();
     _warningActiveModule = null;
 }