public virtual void ChangeHeat(int ticks)
        {
            if (!IsActive())
            {
                return;
            }

            float targetTemp = GetTargetTemp();

            foreach (Thing thing in base.slotGroup.HeldThings)
            {
                CompDTemperature comp = thing.TryGetComp <CompDTemperature>();
                if (comp != null && comp.curTemp < targetTemp)
                {
                    comp.Diffuse(targetTemp * 2f, ticks);
                }

                if (ThermodynamicsSettings.warmersSlowRot)
                {
                    CompRottable rot = thing.TryGetComp <CompRottable>();
                    if (rot != null && GenTemperature.RotRateAtTemperature(thing.AmbientTemperature) == unrefrigeratedRotRate)
                    {
                        rot.RotProgress = rot.RotProgress - ticks * slowRotRateAmount;
                    }
                }
            }
        }
예제 #2
0
        public static bool Prefix(ref float __result, Thing __instance)
        {
            CompDTemperature comp = __instance.TryGetComp <CompDTemperature>();

            if (comp != null)
            {
                __result = comp.GetCurTemp();
                return(false);
            }
            return(true);
        }
        public override float GetValueUnfinalized(StatRequest req, bool applyPostProcess = true)
        {
            if (!req.HasThing)
            {
                return(-9999);
            }
            CompDTemperature comp = req.Thing.TryGetComp <CompDTemperature>();

            if (comp != null)
            {
                return((float)comp.curTemp);
            }
            return(-9999);
        }
        public override string GetStatDrawEntryLabel(StatDef stat, float value, ToStringNumberSense numberSense, StatRequest optionalReq, bool finalized = true)
        {
            string s = GenText.ToStringTemperature(value);

            if (!optionalReq.HasThing)
            {
                return(s);
            }
            CompDTemperature comp = optionalReq.Thing.TryGetComp <CompDTemperature>();

            if (comp != null)
            {
                s += ", " + comp.GetState(comp.curTemp);
            }
            return(s);
        }
예제 #5
0
        public static float HoursToTargetTemp(CompDTemperature comp, double target, double tolerance = 0.5)
        {
            const double interval      = 250;
            double       ambient       = comp.AmbientTemperature;
            double       curtemp       = comp.curTemp;
            bool         goUp          = curtemp < target;
            double       minStepScaled = CompDTemperature.minStep * interval;
            double       diffusionTime = comp.PropsTemp.diffusionTime;
            int          count         = 0;

            while (goUp ? (curtemp + tolerance < target) : (curtemp > target + tolerance) && count < 1000)
            {
                double shift     = ambient - curtemp;
                double changeMag = Math.Abs(interval * shift / diffusionTime);
                double step      = (Math.Abs(shift) < minStepScaled || changeMag > CompDTemperature.minStep) ? changeMag : minStepScaled;
                curtemp += Math.Sign(shift) * step * ThermodynamicsSettings.diffusionModifier;
                //curtemp += CompDTemperature.CalcTempChange(ambient, curtemp, interval, diffusionTime, minStepScaled);
                count++;
            }
            return((float)count / 10f);
        }
            public static bool Prefix(ref CompDTemperature __instance, ref double __result)
            {
                if (!__instance.parent.Spawned)
                {
                    return(true);
                }

                var thingList = __instance.parent.PositionHeld.GetThingList(__instance.parent.MapHeld);

                foreach (var thing in thingList)
                {
                    var compRefrigerator = thing.TryGetComp <CompRefrigerator>();
                    if (compRefrigerator == null)
                    {
                        continue;
                    }

                    __result = compRefrigerator.currentTemp;
                    //Log.Message($"Current temp: {__result}");
                    return(false);
                }

                return(true);
            }
        public override string GetExplanationUnfinalized(StatRequest req, ToStringNumberSense numberSense)
        {
            string s = "";

            if (!req.HasThing)
            {
                return(s);
            }
            CompDTemperature comp = req.Thing.TryGetComp <CompDTemperature>();

            if (comp != null)
            {
                double interval      = 2500;
                double ambient       = comp.AmbientTemperature;
                double shift         = ambient - comp.curTemp;
                double changeMag     = Math.Abs(interval * shift / comp.PropsTemp.diffusionTime);
                double minStepScaled = CompDTemperature.minStep * interval;
                double step          = (Math.Abs(shift) < minStepScaled || changeMag > CompDTemperature.minStep) ? changeMag : minStepScaled;
                if (step == minStepScaled)
                {
                    s += "Currently coming to equilibrium at " + GenText.ToStringTemperatureOffset((float)ambient);
                }
                else
                {
                    double result = Math.Sign(shift) * step * ThermodynamicsSettings.diffusionModifier;
                    s += "Currently diffusing at a rate of " + GenText.ToStringTemperatureOffset((float)result) + " per hour.";
                    s += HoursToAmbient(comp);
                    CompDTemperatureIngestible comp2 = comp as CompDTemperatureIngestible;
                    if (comp2 != null)
                    {
                        s += "\n";

                        if (comp2.PropsTemp.roomTemperature)
                        {
                            if (comp2.curTemp > comp2.PropsTemp.tempLevels.goodTemp && comp2.curTemp < comp2.PropsTemp.tempLevels.okTemp)
                            {
                                if (ambient < comp2.PropsTemp.tempLevels.goodTemp)
                                {
                                    s += HoursInIdeal(comp2, comp2.PropsTemp.tempLevels.goodTemp);
                                }
                                else if (ambient > comp2.PropsTemp.tempLevels.okTemp)
                                {
                                    s += HoursInIdeal(comp2, comp2.PropsTemp.tempLevels.okTemp);
                                }
                                else
                                {
                                    s += InIdealRange();
                                }
                            }
                            else if (comp2.curTemp < comp2.PropsTemp.tempLevels.goodTemp && ambient > comp2.PropsTemp.tempLevels.goodTemp)
                            {
                                s += HoursToIdeal(comp2, comp2.PropsTemp.tempLevels.goodTemp);
                            }
                            else if (comp2.curTemp > comp2.PropsTemp.tempLevels.okTemp && ambient < comp2.PropsTemp.tempLevels.okTemp)
                            {
                                s += HoursToIdeal(comp2, comp2.PropsTemp.tempLevels.okTemp);
                            }
                            else
                            {
                                s += WillNeverReach();
                            }
                        }
                        else if (comp2.PropsTemp.likesHeat)
                        {
                            if (comp2.curTemp > comp2.PropsTemp.tempLevels.goodTemp)
                            {
                                if (ambient < comp2.PropsTemp.tempLevels.goodTemp)
                                {
                                    s += HoursInIdeal(comp2, comp2.PropsTemp.tempLevels.goodTemp);
                                }
                                else
                                {
                                    s += InIdealRange();
                                }
                            }
                            else if (ambient > comp2.PropsTemp.tempLevels.goodTemp)
                            {
                                s += HoursToIdeal(comp2, comp2.PropsTemp.tempLevels.goodTemp);
                            }
                            else
                            {
                                s += WillNeverReach();
                            }
                        }
                        else
                        {
                            if (comp2.curTemp < 0f && !comp2.PropsTemp.okFrozen)
                            {
                                if (comp2.AmbientTemperature > 0f)
                                {
                                    s += HoursToIdeal(comp2, 0);
                                }
                                else if (comp2.AmbientTemperature <= 0f)
                                {
                                    s += WillNeverReach();
                                }
                            }
                            else if (comp2.curTemp < comp2.PropsTemp.tempLevels.goodTemp)
                            {
                                if (ambient > comp2.PropsTemp.tempLevels.goodTemp)
                                {
                                    s += HoursInIdeal(comp2, comp2.PropsTemp.tempLevels.goodTemp);
                                }
                                else
                                {
                                    s += InIdealRange();
                                }
                            }
                            else if (ambient < comp2.PropsTemp.tempLevels.goodTemp)
                            {
                                s += HoursToIdeal(comp2, comp2.PropsTemp.tempLevels.goodTemp);
                            }
                            else
                            {
                                s += WillNeverReach();
                            }
                        }
                    }
                }
            }
            return(s);
        }
 public static string HoursToAmbient(CompDTemperature comp)
 {
     return("\nWill reach ambient temperature of " + GenText.ToStringTemperature((float)comp.AmbientTemperature) + " in around " + ThermodynamicsBase.HoursToTargetTemp(comp, comp.AmbientTemperature, 2).ToString("f1") + " hour(s).");
 }