/// <summary> /// Set the specified radio to the desired frequency. /// </summary> /// <param name="radioId">Radio ID (arbitrary integer)</param> /// <param name="frequency">Frequency, MHz. Set to 0.0 or less to shut down the radio.</param> /// <returns>true if at least one radio exists at that frequency, false otherwise. If sending an invalid frequency, returns true if the radio was previously set.</returns> internal bool SetRadioFrequency(int radioId, float frequency) { if (frequency <= 0.0f) { navRadioFrequency.Remove(radioId); return(navRadio.Remove(radioId)); } else { List <NavAid> navaids = MASLoader.navaids.FindAll(x => (x.celestialName == vessel.mainBody.name) && (Mathf.Abs(x.frequency - frequency) <= 0.005f)); NavRadio radio = new NavRadio(); radio.frequency = frequency; radio.beaconIndex = -1; radio.isDME = false; radio.slantDistance = 0.0; radio.bearing = -1.0; radio.vesselLoS = 0.0; radio.beacon = navaids.ToArray(); if (radio.beacon.Length == 1) { radio.beaconIndex = 0; } radio.UpdateAccessors(); navRadio[radioId] = radio; navRadioFrequency[radioId] = frequency; return(navaids.Count > 0); } }
/// <summary> /// Private method used to restore navRadio at vessel load time. Does not affect /// navRadioFrequency. /// </summary> /// <param name="radioId"></param> /// <param name="frequency"></param> private void ReloadRadio(int radioId, float frequency) { if (frequency > 0.0f) { List <NavAid> navaids = MASLoader.navaids.FindAll(x => (x.celestialName == vessel.mainBody.name) && (Mathf.Abs(x.frequency - frequency) <= 0.005f)); NavRadio radio = new NavRadio(); radio.frequency = frequency; radio.beaconIndex = -1; radio.isDME = false; radio.slantDistance = 0.0; radio.bearing = -1.0; radio.vesselLoS = 0.0; radio.beacon = navaids.ToArray(); if (radio.beacon.Length == 1) { radio.beaconIndex = 0; } radio.UpdateAccessors(); navRadio[radioId] = radio; } }