예제 #1
0
        private void CheckEVAKerbals()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            var vList = GetNearbyVessels(2000, false, FlightGlobals.ActiveVessel, false);

            foreach (var v in vList.Where(v => v.isEVA))
            {
                if (v.mainBody == FlightGlobals.GetHomeBody())
                {
                    if (v.altitude < LifeSupportScenario.Instance.settings.GetSettings().HomeWorldAltitude)
                    {
                        continue;
                    }
                }

                var c = v.GetVesselCrew().First();
                //Check their status.
                var k = LifeSupportManager.Instance.FetchKerbal(c);
                if (v.missionTime > LifeSupportScenario.Instance.settings.GetSettings().EVATime)
                {
                    print("Applying EVA Effect");
                    ApplyEVAEffect(k, c, v,
                                   LifeSupportManager.isVet(k.KerbalName)
                            ? LifeSupportScenario.Instance.settings.GetSettings().EVAEffectVets
                            : LifeSupportScenario.Instance.settings.GetSettings().EVAEffect);
                }
            }
        }
예제 #2
0
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight || vessel == null)
            {
                return;
            }
            if (!vessel.loaded)
            {
                return;
            }

            if (isDirty)
            {
                isDirty = false;
                UpdateVesselInfo();
                UpdateStatus();
            }

            if (_currentCrew == 0)
            {
                return;
            }

            try
            {
                bool isLongLoop = false;
                var  offKerbin  = !LifeSupportManager.IsOnKerbin(vessel);
                UnlockTins();
                CheckVesselId();

                //Check our time
                double deltaTime = GetDeltaTime();

                if (deltaTime < ResourceUtilities.FLOAT_TOLERANCE * 10)
                {
                    return;
                }

                if (Planetarium.GetUniversalTime() >= _lastProcessingTime + _checkInterval)
                {
                    isLongLoop          = true;
                    _lastProcessingTime = Planetarium.GetUniversalTime();
                }

                VesselStatus.LastUpdate = Planetarium.GetUniversalTime();
                VesselStatus.VesselName = vessel.vesselName;
                VesselStatus.NumCrew    = vessel.GetCrewCount();
                VesselStatus.CrewCap    = vessel.GetCrewCapacity();
                if (isLongLoop)
                {
                    CheckForDeadKerbals();
                }

                if (_currentCrew > 0)
                {
                    //Guard clause
                    if (_crewPart == null)
                    {
                        UpdateVesselInfo();
                    }

                    //we will add a bit of a fudge factor for supplies
                    var tolerance = deltaTime / 2f;
                    //nom nom nom!
                    ConverterResults resultSupply = ResConverter.ProcessRecipe(deltaTime, SupplyRecipe, _crewPart, null, 1f);
                    ConverterResults resultEC     = ResConverter.ProcessRecipe(deltaTime, ECRecipe, _crewPart, null, 1f);

                    foreach (var c in vessel.GetVesselCrew())
                    {
                        bool isGrouchyHab      = false;
                        bool isGrouchySupplies = false;
                        bool isGrouchyEC       = false;
                        //Fetch them from the queue
                        var k = LifeSupportManager.Instance.FetchKerbal(c);
                        //Update our stuff

                        #region Long Loop - Crew
                        if (isLongLoop)
                        {
                            //Ensure status is current
                            UpdateStatus();
                            //First - Hab effects.
                            if (LifeSupportManager.IsOnKerbin(vessel))
                            {
                                k.LastAtHome        = Planetarium.GetUniversalTime();
                                k.MaxOffKerbinTime  = 648000;
                                k.TimeEnteredVessel = Planetarium.GetUniversalTime();
                            }
                            else
                            {
                                if (vessel.id.ToString() != k.CurrentVesselId)
                                {
                                    if (vessel.id.ToString() != k.PreviousVesselId)
                                    {
                                        k.TimeEnteredVessel = Planetarium.GetUniversalTime();
                                    }

                                    k.PreviousVesselId = k.CurrentVesselId;
                                    k.CurrentVesselId  = vessel.id.ToString();
                                }
                            }
                            isGrouchyHab = CheckHabSideEffects(k);

                            //Second - Supply
                            if (offKerbin && (deltaTime - resultSupply.TimeFactor > tolerance))
                            {
                                isGrouchySupplies = CheckSupplySideEffects(k);
                            }
                            else if (deltaTime >= ResourceUtilities.FLOAT_TOLERANCE)
                            {
                                //All is well
                                k.LastMeal = LastUpdateTime;
                                VesselStatus.LastFeeding = LastUpdateTime;
                            }

                            //Third - EC
                            //Second - Supply
                            if (offKerbin && (deltaTime - resultEC.TimeFactor > tolerance))
                            {
                                isGrouchyEC = CheckECSideEffects(k);
                            }
                            else if (deltaTime >= ResourceUtilities.FLOAT_TOLERANCE)
                            {
                                //All is well
                                k.LastEC = LastUpdateTime;
                                VesselStatus.LastECCheck = LastUpdateTime;
                            }


                            k.LastUpdate = Planetarium.GetUniversalTime();

                            if (isGrouchyEC)
                            {
                                ApplyEffect(k, c,
                                            LifeSupportManager.isVet(k.KerbalName)
                                        ? LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffectVets
                                        : LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffect);
                            }
                            else if (isGrouchySupplies)
                            {
                                ApplyEffect(k, c,
                                            LifeSupportManager.isVet(k.KerbalName)
                                        ? LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffectVets
                                        : LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffect);
                            }
                            else if (isGrouchyHab)
                            {
                                ApplyEffect(k, c,
                                            LifeSupportManager.isVet(k.KerbalName)
                                        ? LifeSupportScenario.Instance.settings.GetSettings().NoHomeEffectVets
                                        : LifeSupportScenario.Instance.settings.GetSettings().NoHomeEffect);
                            }
                            else if (c.experienceTrait.Title != k.OldTrait)
                            {
                                RemoveGrouchiness(c, k);
                            }
                            LifeSupportManager.Instance.TrackKerbal(k);
                        }
                        #endregion - Crew
                        var supAmount = _resBroker.AmountAvailable(_crewPart, "Supplies", deltaTime, ResourceFlowMode.ALL_VESSEL);
                        var ecAmount  = _resBroker.AmountAvailable(_crewPart, "ElectricCharge", deltaTime, ResourceFlowMode.ALL_VESSEL);
                        VesselStatus.SuppliesLeft = supAmount / LifeSupportScenario.Instance.settings.GetSettings().SupplyAmount /
                                                    _currentCrew /
                                                    VesselStatus.RecyclerMultiplier;
                        VesselStatus.ECLeft = ecAmount / LifeSupportScenario.Instance.settings.GetSettings().ECAmount /
                                              _currentCrew;
                    }
                }
                LifeSupportManager.Instance.TrackVessel(VesselStatus);
            }
            catch (Exception ex)
            {
                print(String.Format("ERROR {0} IN ModuleLifeSupport", ex.Message));
            }
        }
예제 #3
0
        public void FixedUpdate()
        {
            if (part.protoModuleCrew.Count == 0)
            {
                return;
            }

            if (Planetarium.GetUniversalTime() < _lastProcessingTime + _checkInterval)
            {
                return;
            }

            _lastProcessingTime = Planetarium.GetUniversalTime();

            UnlockTins();
            //Check our time
            double deltaTime = GetDeltaTime();

            if (deltaTime < ResourceUtilities.FLOAT_TOLERANCE)
            {
                return;
            }

            ConverterResults result = ResConverter.ProcessRecipe(deltaTime, LifeSupportRecipe, part, this, 1f);

            var v = LifeSupportManager.Instance.FetchVessel(part.vessel.id.ToString());

            v.LastUpdate         = Planetarium.GetUniversalTime();
            v.VesselName         = part.vessel.vesselName;
            v.NumCrew            = part.vessel.GetCrewCount();
            v.RecyclerMultiplier = (float)LifeSupportManager.GetRecyclerMultiplier(part.vessel);
            v.CrewCap            = part.vessel.GetCrewCapacity();

            CheckForDeadKerbals();

            //Update Hab info
            var habMulti = 0d;
            var habTime  = 0d;
            var totParts = 0d;
            var maxParts = 0d;
            var habMods  = part.vessel.FindPartModulesImplementing <ModuleHabitation>();

            foreach (var hab in habMods)
            {
                //Next.  Certain modules, in addition to crew capacity, have living space.
                habTime += hab.KerbalMonths;
                //Lastly.  Some modules act more as 'multipliers', dramatically extending a hab's workable lifespan.
                habMulti += (hab.HabMultiplier * Math.Min(1, hab.CrewCapacity / v.NumCrew));
            }

            v.ExtraHabSpace       = habTime;
            v.VesselHabMultiplier = habMulti;
            //We also have to temper this with whether or not these parts are worn out.
            if (part.Resources.Contains("ReplacementParts"))
            {
                var res = part.Resources["ReplacementParts"];
                totParts = res.amount;
                maxParts = res.maxAmount;
            }
            //Worn out parts have a corresponding negative effect.
            if (maxParts > 0)
            {
                v.VesselHabMultiplier *= (totParts / maxParts);
                v.ExtraHabSpace       *= (totParts / maxParts);
                if (totParts < 1)
                {
                    wearPercent = "Broken!";
                }
                else
                {
                    wearPercent = String.Format("{0:0.00}%", (1d - (totParts / maxParts)) * 100);
                }
            }
            else
            {
                wearPercent = "Like New";
            }

            //we will add a bit of a fudge factor for supplies
            var tolerance = deltaTime / 2f;


            foreach (var c in part.protoModuleCrew)
            {
                bool isGrouchyHab      = false;
                bool isGrouchySupplies = false;

                //Fetch them from the queue
                var k = LifeSupportManager.Instance.FetchKerbal(c);
                //Update our stuff

                //First - Hab effects.
                if (LifeSupportManager.IsOnKerbin(part.vessel))
                {
                    k.LastOnKerbin      = Planetarium.GetUniversalTime();
                    k.MaxOffKerbinTime  = Planetarium.GetUniversalTime() + 972000000;
                    k.TimeEnteredVessel = Planetarium.GetUniversalTime();
                }
                else
                {
                    if (part.vessel.id.ToString() != k.LastVesselId)
                    {
                        k.LastVesselId      = part.vessel.id.ToString();
                        k.TimeEnteredVessel = Planetarium.GetUniversalTime();
                    }
                }
                isGrouchyHab = CheckHabSideEffects(k, v);

                //Second - Supply
                if (!LifeSupportManager.IsOnKerbin(part.vessel) && (deltaTime - result.TimeFactor > tolerance))
                {
                    isGrouchySupplies = CheckSupplySideEffects(k);
                }
                else
                {
                    //All is well
                    k.LastMeal    = lastUpdateTime;
                    v.LastFeeding = lastUpdateTime;
                }

                k.LastUpdate = Planetarium.GetUniversalTime();
                if (!isGrouchyHab && !isGrouchySupplies)
                {
                    RemoveGrouchiness(c, k);
                }

                if (deltaTime < _checkInterval * 2)
                {
                    if (isGrouchyHab)
                    {
                        ApplyEffect(k, c,
                                    LifeSupportManager.isVet(k.KerbalName)
                                ? LifeSupportSetup.Instance.LSConfig.NoHomeEffectVets
                                : LifeSupportSetup.Instance.LSConfig.NoHomeEffect);
                    }
                    if (isGrouchySupplies)
                    {
                        ApplyEffect(k, c,
                                    LifeSupportManager.isVet(k.KerbalName)
                                ? LifeSupportSetup.Instance.LSConfig.NoSupplyEffectVets
                                : LifeSupportSetup.Instance.LSConfig.NoSupplyEffect);
                    }
                }


                LifeSupportManager.Instance.TrackKerbal(k);
                var supAmpunt = _resBroker.AmountAvailable(part, "Supplies", deltaTime, "ALL_VESSEL");
                v.SuppliesLeft = supAmpunt / LifeSupportSetup.Instance.LSConfig.SupplyAmount /
                                 part.vessel.GetCrewCount() /
                                 LifeSupportManager.GetRecyclerMultiplier(vessel);
            }

            LifeSupportManager.Instance.TrackVessel(v);
        }
예제 #4
0
        public void FixedUpdate()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            try
            {
                bool isLongLoop = false;
                var  offKerbin  = !LifeSupportManager.IsOnKerbin(part.vessel);
                UnlockTins();
                CheckVesselId();

                //Check our time
                double deltaTime = GetDeltaTime();

                if (deltaTime < ResourceUtilities.FLOAT_TOLERANCE * 10)
                {
                    return;
                }

                if (Planetarium.GetUniversalTime() >= _lastProcessingTime + _checkInterval)
                {
                    isLongLoop          = true;
                    _lastProcessingTime = Planetarium.GetUniversalTime();
                }



                var v = LifeSupportManager.Instance.FetchVessel(part.vessel.id.ToString());
                v.LastUpdate = Planetarium.GetUniversalTime();
                v.VesselName = part.vessel.vesselName;
                v.NumCrew    = part.vessel.GetCrewCount();
                v.CrewCap    = part.vessel.GetCrewCapacity();
                if (isLongLoop)
                {
                    v.RecyclerMultiplier = (float)LifeSupportManager.GetRecyclerMultiplier(part.vessel);
                    CheckForDeadKerbals();
                }

                if (part.protoModuleCrew.Count > 0)
                {
                    #region Long loop - Vessel
                    //Only check effects periodically, this is for performance reasons.
                    if (isLongLoop)
                    {
                        //Update Hab info

                        var habMulti = CalculateVesselHabMultiplier(part.vessel, v.NumCrew);
                        var habTime  = CalculateVesselHabExtraTime(part.vessel);
                        var totParts = 0d;
                        var maxParts = 0d;


                        v.ExtraHabSpace       = habTime;
                        v.VesselHabMultiplier = habMulti;
                        //We also have to temper this with whether or not these parts are worn out.
                        if (part.Resources.Contains("ReplacementParts"))
                        {
                            var res = part.Resources["ReplacementParts"];
                            totParts = res.amount;
                            maxParts = res.maxAmount;
                        }

                        //Worn out parts have a corresponding negative effect.
                        if (maxParts > 0)
                        {
                            v.VesselHabMultiplier *= (totParts / maxParts);
                            v.ExtraHabSpace       *= (totParts / maxParts);
                            if (totParts < 1)
                            {
                                wearPercent = "Broken!";
                            }
                            else
                            {
                                wearPercent = String.Format("{0:0.00}%", (1d - (totParts / maxParts)) * 100);
                            }
                        }
                        else
                        {
                            wearPercent = "Like New";
                        }
                    }
                    #endregion
                    //we will add a bit of a fudge factor for supplies
                    var tolerance = deltaTime / 2f;
                    //nom nom nom!
                    ConverterResults resultSupply = ResConverter.ProcessRecipe(deltaTime, SupplyRecipe, part, this, 1f);
                    ConverterResults resultEC     = ResConverter.ProcessRecipe(deltaTime, ECRecipe, part, this, 1f);

                    foreach (var c in part.protoModuleCrew)
                    {
                        bool isGrouchyHab      = false;
                        bool isGrouchySupplies = false;
                        bool isGrouchyEC       = false;
                        //Fetch them from the queue
                        var k = LifeSupportManager.Instance.FetchKerbal(c);
                        //Update our stuff

                        #region Long Loop - Crew
                        if (isLongLoop)
                        {
                            //First - Hab effects.
                            if (LifeSupportManager.IsOnKerbin(part.vessel))
                            {
                                k.LastAtHome        = Planetarium.GetUniversalTime();
                                k.MaxOffKerbinTime  = 648000;
                                k.TimeEnteredVessel = Planetarium.GetUniversalTime();
                            }
                            else
                            {
                                if (part.vessel.id.ToString() != k.CurrentVesselId)
                                {
                                    if (part.vessel.id.ToString() != k.PreviousVesselId)
                                    {
                                        k.TimeEnteredVessel = Planetarium.GetUniversalTime();
                                    }

                                    k.PreviousVesselId = k.CurrentVesselId;
                                    k.CurrentVesselId  = part.vessel.id.ToString();
                                }
                            }
                            isGrouchyHab = CheckHabSideEffects(k, v);

                            //Second - Supply
                            if (offKerbin && (deltaTime - resultSupply.TimeFactor > tolerance))
                            {
                                isGrouchySupplies = CheckSupplySideEffects(k);
                            }
                            else if (deltaTime >= ResourceUtilities.FLOAT_TOLERANCE)
                            {
                                //All is well
                                k.LastMeal    = lastUpdateTime;
                                v.LastFeeding = lastUpdateTime;
                            }

                            //Third - EC
                            //Second - Supply
                            if (offKerbin && (deltaTime - resultEC.TimeFactor > tolerance))
                            {
                                isGrouchyEC = CheckECSideEffects(k);
                            }
                            else if (deltaTime >= ResourceUtilities.FLOAT_TOLERANCE)
                            {
                                //All is well
                                k.LastEC      = lastUpdateTime;
                                v.LastECCheck = lastUpdateTime;
                            }


                            k.LastUpdate = Planetarium.GetUniversalTime();

                            if (isGrouchyEC)
                            {
                                ApplyEffect(k, c,
                                            LifeSupportManager.isVet(k.KerbalName)
                                        ? LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffectVets
                                        : LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffect);
                            }
                            else if (isGrouchySupplies)
                            {
                                ApplyEffect(k, c,
                                            LifeSupportManager.isVet(k.KerbalName)
                                        ? LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffectVets
                                        : LifeSupportScenario.Instance.settings.GetSettings().NoSupplyEffect);
                            }
                            else if (isGrouchyHab)
                            {
                                ApplyEffect(k, c,
                                            LifeSupportManager.isVet(k.KerbalName)
                                        ? LifeSupportScenario.Instance.settings.GetSettings().NoHomeEffectVets
                                        : LifeSupportScenario.Instance.settings.GetSettings().NoHomeEffect);
                            }
                            else if (c.experienceTrait.Title != k.OldTrait)
                            {
                                RemoveGrouchiness(c, k);
                            }
                            LifeSupportManager.Instance.TrackKerbal(k);
                        }
                        #endregion - Crew
                        var supAmount = _resBroker.AmountAvailable(part, "Supplies", deltaTime, ResourceFlowMode.ALL_VESSEL);
                        var ecAmount  = _resBroker.AmountAvailable(part, "ElectricCharge", deltaTime, ResourceFlowMode.ALL_VESSEL);
                        v.SuppliesLeft = supAmount / LifeSupportScenario.Instance.settings.GetSettings().SupplyAmount /
                                         part.vessel.GetCrewCount() /
                                         v.RecyclerMultiplier;
                        v.ECLeft = ecAmount / LifeSupportScenario.Instance.settings.GetSettings().ECAmount /
                                   part.vessel.GetCrewCount();
                    }
                }
                LifeSupportManager.Instance.TrackVessel(v);
            }
            catch (Exception ex)
            {
                print(String.Format("ERROR {0} IN ModuleLifeSupport", ex.Message));
            }
        }