Esempio n. 1
0
        public override void OnUpdate()
        {
            #if !DEBUG
            if (IFIDebug.IsON)
            {
                DebugStatus = "Active";
            }
            else
            {
                DebugStatus = "Inactive";
            }
            #endif

            base.OnUpdate();
            int crewCount = 0;
            crewCount = this.part.protoModuleCrew.Count;
            if (crewCount > 0)
            {
                this.Fields[1].guiActive = true;
                Vessel active = this.part.vessel;
                if (active.mainBody.theName == "Kerbin" && active.altitude <= 12123)
                {
                    lifeSupportStatus = "Air Intake";
                }
                else
                {
                    lifeSupportStatus = "Active";
                }
                double ResourceAval = IFIGetAllResources("LifeSupport");
                displayRate = (float)((ResourceAval / (LifeSupportRate.GetRate() * IFIGetAllKerbals())) / HoursPerDay / 60 / 60);
            }  //end of if crew > 0
            else if (crewCount == 0)
            {
                lifeSupportStatus        = "Pod Standby";
                this.Fields[1].guiActive = false;
            }
        }
        public void Life_Support_Update()
        {
            if (HighLogic.LoadedScene == GameScenes.LOADING || HighLogic.LoadedSceneIsEditor || !HighLogic.LoadedSceneIsGame)
            {
                return; //Don't do anything while the game is loading
            }
            if (HighLogic.LoadedScene == GameScenes.MAINMENU)
            {
                Went_to_Main = true;
                return; // Don't Run at main menu and reset IFITimer
            }
            if (Went_to_Main)
            {
                IFITimer     = Convert.ToInt32(Planetarium.GetUniversalTime());
                Went_to_Main = false;
            }
            double Elapesed_Time = IFI_Get_Elasped_Time();

            IFI_Button.SetTexture(IFI_button_grn); int LS_ALERT_LEVEL = 1;
            if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedScene == GameScenes.TRACKSTATION || HighLogic.LoadedScene == GameScenes.SPACECENTER)
            {
                LS_Status_Hold       = new string[FlightGlobals.Vessels.Count(), 5];
                LS_Status_Hold_Count = 0;
                //Debug.Log("######## Looking for Ships ######");
                foreach (Vessel vessel in FlightGlobals.Vessels)
                {
                    if (vessel && (
                            vessel.vesselType == VesselType.Ship || vessel.vesselType == VesselType.Lander ||
                            vessel.vesselType == VesselType.Station || vessel.vesselType == VesselType.Rover ||
                            vessel.vesselType == VesselType.Base || vessel.vesselType == VesselType.Probe) ||
                        vessel.vesselType == VesselType.EVA)
                    {
                        //Debug.Log(" Found Vessel");//float distance = (float)Vector3d.Distance(vessel.GetWorldPos3D(), FlightGlobals.ActiveVessel.GetWorldPos3D());
                        string TVname;
                        int    IFI_Crew = 0;
                        double LSAval;
                        string IFI_Location = "";
                        double IFI_ALT      = 0.0;
                        TVname = vessel.vesselName; // vessel.name;
                        if (!vessel.loaded)
                        {
                            IFI_Crew     = vessel.protoVessel.GetVesselCrew().Count;
                            IFI_ALT      = vessel.protoVessel.altitude;
                            IFI_Location = vessel.mainBody.theName;
                        }
                        else
                        {
                            IFI_Crew     = vessel.GetCrewCount();
                            IFI_Location = vessel.mainBody.theName;
                            IFI_ALT      = vessel.altitude;
                        }
                        if (IFI_Crew > 0.0)
                        {
                            double LS_Use = LifeSupportRate.GetRate(); bool USE_Electric = true;
                            if (IFI_Location == "Kerbin" && IFI_ALT <= 12123)
                            {
                                LS_Use *= 0.20; USE_Electric = false;
                            }
                            if (IFI_Location == "Laythe" && IFI_ALT <= 6123)
                            {
                                LS_Use *= 0.75; USE_Electric = false;
                            }

                            LS_Use *= IFI_Crew;
                            LS_Use *= Elapesed_Time;
                            if (LS_Use > 0.0)
                            {
                                double rtest = IFIUSEResources("LifeSupport", vessel, vessel.loaded, LS_Use);
                                if (USE_Electric)
                                {
                                    rtest = IFIUSEResources("ElectricCharge", vessel, vessel.loaded, LS_Use * 1.5);
                                }
                            }


                            LSAval = IFIGetAllResources("LifeSupport", vessel, vessel.loaded);
                            //Debug.Log("Vessel with crew onboard Found: " + TVname + "   Crew=" + IFI_Crew +"    LifeSupport = "+ LSAval +"  Body:"+IFI_Location+"   ALT:"+IFI_ALT);
                            double days_rem = LSAval / IFI_Crew / LifeSupportRate.GetRate() / 60 / 60 / HoursPerDay;
                            LS_Status_Hold[LS_Status_Hold_Count, 0] = TVname;
                            LS_Status_Hold[LS_Status_Hold_Count, 1] = IFI_Location;
                            string H_Crew = Convert.ToString(IFI_Crew);
                            if (vessel.vesselType == VesselType.EVA)
                            {
                                H_Crew = "EVA";
                            }
                            LS_Status_Hold[LS_Status_Hold_Count, 2] = H_Crew;
                            if (vessel.vesselType == VesselType.EVA && KerbalEVARescueDetect)
                            {
                                LS_Status_Hold[LS_Status_Hold_Count, 3] = "RESCUE";
                                LS_Status_Hold[LS_Status_Hold_Count, 4] = "RESCUE";
                                LSAval   = 200.0;
                                days_rem = 10.0;
                            }
                            else
                            {
                                LS_Status_Hold[LS_Status_Hold_Count, 3] = Convert.ToString(Math.Round(LSAval, 4));
                                LS_Status_Hold[LS_Status_Hold_Count, 4] = Convert.ToString(Math.Round(days_rem, 2));
                            }
                            LS_Status_Hold_Count += 1;
                            if (vessel.loaded)
                            {
                                LSAval = IFIGetAllResources("ElectricCharge", vessel, vessel.loaded);
                                if (LSAval < 10)
                                {
                                    days_rem = 2.5;
                                    if (LSAval < 5)
                                    {
                                        days_rem = .5;
                                    }
                                }
                            }

                            if (LS_ALERT_LEVEL < 2 && days_rem < 3)
                            {
                                IFI_Button.SetTexture(IFI_button_cau); LS_ALERT_LEVEL = 2;
                                if (LifeSupportDisplay.WarpCancel && TimeWarp.CurrentRate > 1)
                                {
                                    TimeWarp.SetRate(0, false);
                                }
                            }
                            if (LS_ALERT_LEVEL < 3 && days_rem <= 1)
                            {
                                IFI_Button.SetTexture(IFI_button_danger); LS_ALERT_LEVEL = 3;
                                if (LifeSupportDisplay.WarpCancel && TimeWarp.CurrentRate > 1)
                                {
                                    TimeWarp.SetRate(0, false);
                                }
                            }
                        }
                    }
                }
            }
        }