KLF.KLFManager.writeSecondaryUpdates C# (CSharp) Method

writeSecondaryUpdates() private method

private writeSecondaryUpdates ( ) : void
return void
        private void writeSecondaryUpdates()
        {
            if (inactiveVesselsPerUpdate > 0)
            {
                //Write the inactive vessels nearest the active vessel to the file
                SortedList<float, Vessel> nearest_vessels = new SortedList<float, Vessel>();

                foreach (Vessel vessel in FlightGlobals.Vessels)
                {
                    if (vessel != FlightGlobals.ActiveVessel)
                    {
                        float distance = (float)Vector3d.Distance(vessel.GetWorldPos3D(), FlightGlobals.ActiveVessel.GetWorldPos3D());
                        if (distance < INACTIVE_VESSEL_RANGE)
                        {
                            try
                            {
                                nearest_vessels.Add(distance, vessel);
                            }
                            catch (ArgumentException)
                            {
                            }
                        }
                    }
                }

                int num_written_vessels = 0;

                //Write inactive vessels to file in order of distance from active vessel
                IEnumerator<KeyValuePair<float, Vessel>> enumerator = nearest_vessels.GetEnumerator();
                while (num_written_vessels < inactiveVesselsPerUpdate
                    && num_written_vessels < MAX_INACTIVE_VESSELS_PER_UPDATE && enumerator.MoveNext())
                {
                    byte[] update_bytes = KSP.IO.IOUtils.SerializeToBinary(getVesselUpdate(enumerator.Current.Value));
                    enqueuePluginInteropMessage(KLFCommon.PluginInteropMessageID.SECONDARY_PLUGIN_UPDATE, update_bytes);
                    num_written_vessels++;
                }
            }
        }