コード例 #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
 public void Load(ConfigNode node)
 {
     if (node.HasNode ("next")) {
         next = new AudioSequence ();
         next.Load(node.GetNode ("next"));
     }
     if (node.HasValue ("clip")) {
         clip = node.GetValue ("clip");
         Debug.Log ("AudioSequence"+clip);
         sound = GameDatabase.Instance.GetAudioClip (clip);
     }
 }
コード例 #3
0
ファイル: AudioSequence.cs プロジェクト: jorgeafs/RATPack
 public void Load(ConfigNode node)
 {
     if (node.HasNode("next"))
     {
         next = new AudioSequence();
         next.Load(node.GetNode("next"));
     }
     if (node.HasValue("clip"))
     {
         clip = node.GetValue("clip");
         Debug.Log("AudioSequence" + clip);
         sound = GameDatabase.Instance.GetAudioClip(clip);
     }
 }
コード例 #4
0
 /// <summary>
 /// Plays the Terrain warning if conditions are met.
 /// </summary>
 private void CheckTerrainWarning()
 {
     if (_warningActiveModule == this)
     {
         if (audioOutput && !_audioSource.isPlaying && terrainAudio != null)
         {
             if (_playing == null)
             {
                 _playing = terrainAudio;
             }
             if (_playing.sound != null)
             {
                 _audioSource.clip = _playing.sound;
                 _audioSource.Play();
             }
             if (_playing != null)
             {
                 _playing = _playing.next;
             }
         }
         ScreenMessages.PostScreenMessage("TAWS: Terrain! Pull Up!");
     }
 }
コード例 #5
0
 public override void OnStart(StartState state)
 {
     base.OnStart(state);
     _audioSource = gameObject.AddComponent <AudioSource> ();
     if (blipSound != null && blipSound.sound == null)
     {
         blipSound = part.partInfo.partPrefab.Modules.GetModules <ModuleTerrainRadar> ()[0].blipSound;
     }
     _audioSource.dopplerLevel = 0.0f;
     _audioSource.panLevel     = 0.0f;
     _audioSource.enabled      = true;
     _audioSource.Stop();
     _transform = part.transform;
     if (scanTransform.Length > 0)
     {
         Transform tempTransform = part.FindModelTransform(scanTransform);
         if (tempTransform != null)
         {
             _transform = tempTransform;
         }
     }
     GroundReference();
     _activeRadar = null;
 }
コード例 #6
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;
                }
            }
        }
コード例 #7
0
ファイル: AudioSequence.cs プロジェクト: jorgeafs/RATPack
 public AudioSequence()
 {
     next  = null;
     clip  = "";
     sound = null;
 }
コード例 #8
0
ファイル: ModuleTAWS.cs プロジェクト: Kerbas-ad-astra/RATPack
        /// <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;
            }
        }
コード例 #9
0
ファイル: ModuleTAWS.cs プロジェクト: Kerbas-ad-astra/RATPack
 /// <summary>
 /// Plays the Terrain warning if conditions are met.
 /// </summary>
 private void CheckTerrainWarning()
 {
     if (_warningActiveModule == this) {
         if (audioOutput && !_audioSource.isPlaying && terrainAudio != null) {
             if (_playing == null) {
                 _playing = terrainAudio;
             }
             if (_playing.sound != null) {
                 _audioSource.clip = _playing.sound;
                 _audioSource.Play ();
             }
             if (_playing != null) {
                 _playing = _playing.next;
             }
         }
         ScreenMessages.PostScreenMessage ("TAWS: Terrain! Pull Up!");
     }
 }
コード例 #10
0
ファイル: ModuleTAWS.cs プロジェクト: Kerbas-ad-astra/RATPack
        /// <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;
        }
コード例 #11
0
        public void Update()
        {
            if (vessel == null)
            {
                return;
            }
            if (_dirty)
            {
                for (int y = 0; y < _terrain.height; y++)
                {
                    for (int x = 0; x < _terrain.width; x++)
                    {
                        _terrain.SetPixel(x, y, Color.black);
                    }
                }
                foreach (KeyValuePair <Vector2, float> kvp in _radarSamples)
                {
                    SetPixel(kvp.Key.x, kvp.Key.y, kvp.Value, scanRadius);
                }
                _terrain.Apply();

                float prevDist = 0f;
                for (int y = 0; y < _scaleGraph.height; y++)
                {
                    float eqDist = _scale * (float)y / _scaleGraph.height;

                    for (int x = 0; x < _scaleGraph.width; x++)
                    {
                        _scaleGraph.SetPixel(x, y, GetColorForDistance(_reference - eqDist));
                    }
                    if (Math.Floor(prevDist) != Math.Floor(eqDist))
                    {
                        for (int x = 0; x < _scaleGraph.width / 2; x++)
                        {
                            _scaleGraph.SetPixel(x, y, Color.black);
                            _scaleGraph.SetPixel(x, y - 1, Color.black);
                        }
                    }
                    prevDist = eqDist;
                }
                _scaleGraph.Apply();
                for (int y = 0; y < _terrainLateral.height; y++)
                {
                    for (int x = 0; x < _terrainLateral.width; x++)
                    {
                        _terrainLateral.SetPixel(x, y, Color.black);
                    }
                }
                float radiusInc = scanRadius / 10f;

                Vector2 start = _minCoord.normalized * scanRadius;
                Vector2 end   = -_minCoord.normalized * scanRadius;
                for (int x = 0; x < _terrainLateral.width; x++)
                {
                    Vector2 lateralCoord = Vector2.Lerp(start, end, (float)x / _terrainLateral.width);
                    foreach (KeyValuePair <Vector2, float> kvp in _radarSamples)
                    {
                        if (Math.Abs(kvp.Key.x - lateralCoord.x) < radiusInc &&
                            Math.Abs(kvp.Key.y - lateralCoord.y) < radiusInc)
                        {
                            if (kvp.Value < _reference - _scale)
                            {
                                _terrainLateral.SetPixel(x, _terrainLateral.height - 1, GetColorForDistance(kvp.Value));
                                continue;
                            }
                            if (kvp.Value > _reference)
                            {
                                _terrainLateral.SetPixel(x, 0, GetColorForDistance(kvp.Value));
                                continue;
                            }
                            float adjustedY = -(kvp.Value - _reference);
                            int   y         = (int)(adjustedY * (float)_terrainLateral.height / _scale);
                            _terrainLateral.SetPixel(x, y, GetColorForDistance(kvp.Value));
                            break;
                        }
                    }
                }

                _terrainLateral.Apply();
                _dirty = false;
            }
            double ut = Planetarium.GetUniversalTime();

            if (audioOutput && vessel.heightFromTerrain > 0f && vessel.heightFromTerrain < 1000f && vessel.situation != Vessel.Situations.LANDED)
            {
                if (ut - _blipTime > (double)altitudeCurve.Evaluate(vessel.heightFromTerrain) && !_audioSource.isPlaying)
                {
                    if (_activeRadar == this || _activeRadar == null || !_activeRadar.isActiveAndEnabled ||
                        _activeRadar.vessel != FlightGlobals.ActiveVessel && vessel == FlightGlobals.ActiveVessel)
                    {
                        _activeRadar = this;
                        if (!_audioSource.isPlaying && blipSound != null)
                        {
                            if (_playing == null)
                            {
                                _playing = blipSound;
                            }
                            if (_playing.sound != null)
                            {
                                _audioSource.clip = _playing.sound;
                                _audioSource.Play();
                            }
                            if (_playing != null)
                            {
                                _playing = _playing.next;
                            }
                        }
                    }
                    _blipTime = ut;
                }
            }
            else if (_activeRadar == this)
            {
                _activeRadar = null;
            }
        }
コード例 #12
0
 public override void OnStart(StartState state)
 {
     base.OnStart (state);
     _audioSource = gameObject.AddComponent<AudioSource> ();
     if (blipSound != null && blipSound.sound == null) {
         blipSound = part.partInfo.partPrefab.Modules.GetModules<ModuleTerrainRadar> ()[0].blipSound;
     }
     _audioSource.dopplerLevel = 0.0f;
     _audioSource.panLevel = 0.0f;
     _audioSource.enabled = true;
     _audioSource.Stop ();
     _transform = part.transform;
     if (scanTransform.Length > 0) {
         Transform tempTransform = part.FindModelTransform (scanTransform);
         if (tempTransform != null) {
             _transform = tempTransform;
         }
     }
     GroundReference ();
     _activeRadar = null;
 }
コード例 #13
0
        public void Update()
        {
            if (vessel == null)
                return;
            if (_dirty) {
                for (int y = 0; y < _terrain.height; y++) {
                    for (int x = 0; x < _terrain.width; x++) {
                        _terrain.SetPixel (x, y, Color.black);
                    }
                }
                foreach (KeyValuePair<Vector2,float> kvp in _radarSamples) {
                    SetPixel (kvp.Key.x, kvp.Key.y, kvp.Value, scanRadius);
                }
                _terrain.Apply ();

                float prevDist = 0f;
                for (int y = 0; y < _scaleGraph.height; y++) {
                    float eqDist = _scale * (float)y / _scaleGraph.height;

                    for (int x = 0; x < _scaleGraph.width; x++) {
                        _scaleGraph.SetPixel (x, y, GetColorForDistance (_reference - eqDist));
                    }
                    if (Math.Floor (prevDist) != Math.Floor (eqDist)) {
                        for (int x = 0; x < _scaleGraph.width / 2; x++) {
                            _scaleGraph.SetPixel (x, y, Color.black);
                            _scaleGraph.SetPixel (x, y - 1, Color.black);
                        }
                    }
                    prevDist = eqDist;
                }
                _scaleGraph.Apply ();
                for (int y = 0; y < _terrainLateral.height; y++) {
                    for (int x = 0; x < _terrainLateral.width; x++) {
                        _terrainLateral.SetPixel (x, y, Color.black);
                    }
                }
                float radiusInc = scanRadius / 10f;

                Vector2 start = _minCoord.normalized * scanRadius;
                Vector2 end = -_minCoord.normalized * scanRadius;
                for (int x = 0; x < _terrainLateral.width; x++) {
                    Vector2 lateralCoord = Vector2.Lerp (start, end, (float)x / _terrainLateral.width);
                    foreach (KeyValuePair<Vector2,float> kvp in _radarSamples) {
                        if (Math.Abs (kvp.Key.x - lateralCoord.x) < radiusInc &&
                            Math.Abs (kvp.Key.y - lateralCoord.y) < radiusInc) {
                            if (kvp.Value < _reference - _scale) {
                                _terrainLateral.SetPixel (x, _terrainLateral.height - 1, GetColorForDistance (kvp.Value));
                                continue;
                            }
                            if (kvp.Value > _reference) {
                                _terrainLateral.SetPixel (x, 0, GetColorForDistance (kvp.Value));
                                continue;
                            }
                            float adjustedY = -(kvp.Value - _reference);
                            int y = (int)(adjustedY * (float)_terrainLateral.height / _scale);
                            _terrainLateral.SetPixel (x, y, GetColorForDistance (kvp.Value));
                            break;
                        }
                    }
                }

                _terrainLateral.Apply ();
                _dirty = false;
            }
            double ut = Planetarium.GetUniversalTime ();
            if (audioOutput && vessel.heightFromTerrain > 0f && vessel.heightFromTerrain < 1000f && vessel.situation != Vessel.Situations.LANDED) {
                if (ut - _blipTime > (double)altitudeCurve.Evaluate (vessel.heightFromTerrain) && !_audioSource.isPlaying) {
                    if (_activeRadar == this || _activeRadar == null || !_activeRadar.isActiveAndEnabled ||
                        _activeRadar.vessel != FlightGlobals.ActiveVessel && vessel == FlightGlobals.ActiveVessel) {
                        _activeRadar = this;
                        if (!_audioSource.isPlaying && blipSound != null) {
                            if (_playing == null) {
                                _playing = blipSound;
                            }
                            if (_playing.sound != null) {
                                _audioSource.clip = _playing.sound;
                                _audioSource.Play ();
                            }
                            if (_playing != null) {
                                _playing = _playing.next;
                            }
                        }
                    }
                    _blipTime = ut;
                }
            } else if (_activeRadar == this) {
                _activeRadar = null;
            }
        }
コード例 #14
0
 public AudioSequence()
 {
     next = null;
     clip = "";
     sound = null;
 }