コード例 #1
0
 private void UpdateStatus(VesselSupplyStatus v)
 {
     v.RecyclerMultiplier  = (float)LifeSupportManager.GetRecyclerMultiplier(vessel);
     v.ExtraHabSpace       = (float)LifeSupportManager.CalculateVesselHabExtraTime(vessel);
     v.VesselHabMultiplier = (float)LifeSupportManager.CalculateVesselHabMultiplier(vessel, _currentCrew);
     LifeSupportManager.Instance.TrackVessel(v);
 }
コード例 #2
0
        private ConversionRecipe GenerateLSRecipe()
        {
            //This is where the rubber hits the road.  Let us see if we can
            //keep our Kerbals cozy and warm.
            var recipe      = new ConversionRecipe();
            var numCrew     = part.protoModuleCrew.Count;
            var recPercent  = LifeSupportManager.GetRecyclerMultiplier(part.vessel);
            var ecAmount    = LifeSupportSetup.Instance.LSConfig.ECAmount;
            var supAmount   = LifeSupportSetup.Instance.LSConfig.SupplyAmount;
            var scrapAmount = LifeSupportSetup.Instance.LSConfig.WasteAmount;
            var repAmount   = LifeSupportSetup.Instance.LSConfig.ReplacementPartAmount;

            if (part.Resources.Contains("ReplacementParts"))
            {
                recipe.Inputs.Add(new ResourceRatio {
                    FlowMode = "ALL_VESSEL", Ratio = repAmount * numCrew, ResourceName = "ReplacementParts", DumpExcess = false
                });
            }

            var supRatio   = supAmount * numCrew * recPercent;
            var mulchRatio = scrapAmount * numCrew * recPercent;

            recipe.Inputs.Add(new ResourceRatio {
                FlowMode = "ALL_VESSEL", Ratio = ecAmount * numCrew, ResourceName = "ElectricCharge", DumpExcess = true
            });
            recipe.Inputs.Add(new ResourceRatio {
                FlowMode = "ALL_VESSEL", Ratio = supRatio, ResourceName = "Supplies", DumpExcess = true
            });
            recipe.Outputs.Add(new ResourceRatio {
                FlowMode = "ALL_VESSEL", Ratio = mulchRatio, ResourceName = "Mulch", DumpExcess = true
            });
            return(recipe);
        }
コード例 #3
0
        private void UpdateStatus(VesselSupplyStatus supplyStatus)
        {
            var now = Planetarium.GetUniversalTime();

            if (_lastUpdate < ResourceUtilities.FLOAT_TOLERANCE)
            {
                _lastUpdate = now;
            }

            // Give converters time to catch up before we start using calculated values
            bool fullRefresh = false;

            if (now > _lastUpdate + 5d)
            {
                fullRefresh = true;
                _lastUpdate = now;
            }

            var calcRecyclerMultiplier = (float)LifeSupportManager.GetRecyclerMultiplier(vessel);
            var calcHabTime            = (float)LifeSupportManager.CalculateVesselHabExtraTime(vessel);
            var calcHabMultiplier      = (float)LifeSupportManager.CalculateVesselHabMultiplier(vessel, _currentCrewCount);

            // If we're the active vessel, and we're past easing, use calculated values.
            //  Otherwise, use the cache.
            var useCalculated = fullRefresh && vessel.id == FlightGlobals.ActiveVessel.id;

            //Start with intelligent defaults.
            if (supplyStatus.RecyclerMultiplier < ResourceUtilities.FLOAT_TOLERANCE)
            {
                supplyStatus.RecyclerMultiplier = 1f;
            }
            if (calcRecyclerMultiplier < ResourceUtilities.FLOAT_TOLERANCE)
            {
                calcRecyclerMultiplier = 1f;
            }

            //And take the lowest (non-zero)
            if (useCalculated || calcRecyclerMultiplier < supplyStatus.RecyclerMultiplier)
            {
                supplyStatus.RecyclerMultiplier = calcRecyclerMultiplier;
            }

            //Hab we want the best ones.
            if (useCalculated || calcHabTime > supplyStatus.ExtraHabSpace)
            {
                supplyStatus.ExtraHabSpace = calcHabTime;
            }

            if (useCalculated || calcHabMultiplier > supplyStatus.VesselHabMultiplier)
            {
                supplyStatus.VesselHabMultiplier = calcHabMultiplier;
            }

            LifeSupportManager.Instance.TrackVessel(supplyStatus);
        }
コード例 #4
0
        private void UpdateStatus(VesselSupplyStatus v)
        {
            if (_lastUpdate < ResourceUtilities.FLOAT_TOLERANCE)
            {
                _lastUpdate = Planetarium.GetUniversalTime();
            }

            bool fullRefresh = false;

            if (Planetarium.GetUniversalTime() > _lastUpdate + 5d) //A reasonable time for easing in everything
            {
                fullRefresh = true;
                _lastUpdate = Planetarium.GetUniversalTime();
            }

            var newRecMult = (float)LifeSupportManager.GetRecyclerMultiplier(vessel);
            var newSpace   = (float)LifeSupportManager.CalculateVesselHabExtraTime(vessel);
            var newHabMult = (float)LifeSupportManager.CalculateVesselHabMultiplier(vessel, _currentCrew);
            //If we're the active vessel, and we're past easing, we always take calc values.
            //Otherwise, let's use the cache.
            var useCur = fullRefresh && vessel.id == FlightGlobals.ActiveVessel.id;

            //Start with intelligent defaults.
            if (v.RecyclerMultiplier < ResourceUtilities.FLOAT_TOLERANCE)
            {
                v.RecyclerMultiplier = 1f;
            }
            if (newRecMult < ResourceUtilities.FLOAT_TOLERANCE)
            {
                newRecMult = 1f;
            }
            //And take the lowest (non-zero)
            if (useCur || newRecMult < v.RecyclerMultiplier)
            {
                v.RecyclerMultiplier = newRecMult;
            }

            //Hab we want the best ones.
            if (useCur || newSpace > v.ExtraHabSpace)
            {
                v.ExtraHabSpace = newSpace;
            }

            if (useCur || newHabMult > v.VesselHabMultiplier)
            {
                v.VesselHabMultiplier = newHabMult;
            }

            LifeSupportManager.Instance.TrackVessel(v);
        }
コード例 #5
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);
        }
コード例 #6
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));
            }
        }