Example #1
0
        public override void OnUpdate()
        {
            base.OnUpdate();
            double dElectric_Draw = 5.0 * dW_to_EC;
            double elecAvail      = part.RequestResource("ElectricCharge", dElectric_Draw) / dElectric_Draw;

            bPowered    = (elecAvail > 0.90);
            sStation_ID = "---";

            if (bPowered)
            {
                cNav_Select = null;
                foreach (Part p in vessel.Parts)
                {
                    //string sMsg1 = "VI: " + p.name;
                    //print(sMsg1);
                    foreach (PartModule m in p.Modules)
                    {
                        //string sMsg2 = "VIm: " + m.name;
                        //print(sMsg2);
                        VHF_NAV_Receiver cNav = m as VHF_NAV_Receiver;
                        if (cNav != null)
                        {
                            cNav_Select = cNav;
                        }
                    }
                }
                if (cNav_Select != null)
                {
                    //string sMsg = "DME indicator found receiver " + cNav_Select.moduleName;
                    //print(sMsg);
                    DME cDME = cNav_Select.getTunedDME();
                    if (cDME != null)
                    {
                        sStation_ID = cDME.sStation_ID;
                        if ((dLast_GS_Query_Time + 1.0) < Time.time)
                        {
                            dIndicated_Distance = cDME.getDistance(cNav_Select.getPosition());
                            if (bUnits_Mi)
                            {
                                dIndicated_Distance /= 1852.0; // convert to nm
                            }
                            else
                            {
                                dIndicated_Distance /= 1000.0; // convert to km
                            }
                            dIndicated_Groundspeed     = (dIndicated_Distance - dLast_Query_Distance) / (Time.time - dLast_GS_Query_Time) * 3600.0;
                            dIndicated_Time_To_Station = dIndicated_Distance / dIndicated_Groundspeed / 60.0;
                            dLast_Query_Distance       = dIndicated_Distance;
                            dLast_GS_Query_Time        = Time.time;
                        }
                    }
                    else
                    {
                        sStation_ID            = "---";
                        dIndicated_Distance    = -1;
                        dIndicated_Groundspeed = 0;
                        dLast_Query_Distance   = 0;
                        dLast_GS_Query_Time    = -1;
                    }
                }
                else
                {
                    sStation_ID            = "---";
                    dIndicated_Distance    = -1;
                    dIndicated_Groundspeed = 0;
                    dLast_Query_Distance   = 0;
                    dLast_GS_Query_Time    = -1;
                }
            }
        }