public void TickRottables()
 {
     if (storedDef == null || Find.TickManager.TicksAbs % 250 != 0)
     {
         return;
     }
     if (StoredIsRottable)
     {
         float rotProgress        = rotProgressInt;
         float num                = 1f;
         float temperatureForCell = GenTemperature.GetTemperatureForCell(Position, Map);
         num            *= GenTemperature.RotRateAtTemperature(temperatureForCell);
         rotProgressInt += Mathf.Round(num * 250f);
         if (rotProgressInt >= storedDef.GetCompProperties <CompProperties_Rottable>().TicksToRotStart)
         {
             Messages.Message("MessageRottedAwayInStorage".Translate(storedDef.label).CapitalizeFirst(), MessageTypeDefOf.SilentInput);
             storedDef      = null;
             ThingCount     = 0;
             rotProgressInt = 1;
         }
     }
     else
     {
         rotProgressInt = 0;
     }
 }
示例#2
0
        public override void CompTickRare()
        {
            float temperature = GenTemperature.GetTemperatureForCell(this.parent.PositionHeld, this.parent.MapHeld);

            if (temperature >= 0.001f && _frozen)
            {
                _frozen = false;
                if (Props.thawDamage > 0)
                {
                    int damage = GenMath.RoundRandom(Props.thawDamage);
                    if (parent.HitPoints <= damage)
                    {
                        Messages.Message("JTFieldSurgeryFreezeDestroyed".Translate(new object [] { parent.Label }).CapitalizeFirst(), MessageTypeDefOf.SilentInput);
                    }
                    parent.TakeDamage(new DamageInfo(DamageDefOf.Deterioration, damage, -1f, null, null, null));
                }
            }
            else if (temperature < 0.001f && !_frozen)
            {
                _frozen = true;
                if (Props.freezeDamage > 0)
                {
                    int damage = GenMath.RoundRandom(Props.freezeDamage);
                    if (parent.HitPoints <= damage)
                    {
                        Messages.Message("JTFieldSurgeryThawDestroyed".Translate(new object [] { parent.Label }).CapitalizeFirst(), MessageTypeDefOf.SilentInput);
                    }
                    parent.TakeDamage(new DamageInfo(DamageDefOf.Deterioration, damage, -1f, null, null, null));
                }
            }
            else if (temperature < 0.001f)
            {
                CheckDegradation();
            }
        }
示例#3
0
        public override string CompInspectStringExtra()
        {
            StringBuilder sb = new StringBuilder();

            switch (base.Stage)
            {
            case RotStage.Fresh:
                sb.Append("RotStateFresh".Translate());
                break;

            case RotStage.Rotting:
                sb.Append("RotStateRotting".Translate());
                break;

            case RotStage.Dessicated:
                sb.Append("RotStateDessicated".Translate());
                break;
            }
            float num = (float)this.PropsRot.TicksToRotStart - base.RotProgress;

            if (num > 0f)
            {
                float        num2      = GenTemperature.GetTemperatureForCell(this.parent.PositionHeld, this.parent.Map);
                List <Thing> thingList = GridsUtility.GetThingList(this.parent.PositionHeld, this.parent.Map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    if (thingList[i] is Building_Refrigerator)
                    {
                        Building_Refrigerator building_Refrigerator = thingList[i] as Building_Refrigerator;
                        num2 = building_Refrigerator.CurrentTemp;
                        break;
                    }
                }
                num2 = (float)Mathf.RoundToInt(num2);
                float num3 = GenTemperature.RotRateAtTemperature(num2);
                int   ticksUntilRotAtCurrentTemp = base.TicksUntilRotAtCurrentTemp;
                if (num3 < 0.001f)
                {
                    sb.Append(Translator.Translate("CurrentlyFrozen") + ".");
                }
                else
                {
                    if (num3 < 0.999f)
                    {
                        sb.Append(Translator.Translate("CurrentlyRefrigerated", new object[]
                        {
                            GenDate.ToStringTicksToPeriodVague(ticksUntilRotAtCurrentTemp)
                        }) + ".");
                    }
                    else
                    {
                        sb.Append(Translator.Translate("NotRefrigerated", new object[]
                        {
                            GenDate.ToStringTicksToPeriodVague(ticksUntilRotAtCurrentTemp)
                        }) + ".");
                    }
                }
            }
            return(sb.ToString().TrimEndNewlines());
        }
示例#4
0
        public override void CompTickRare()
        {
            if (this.parent.MapHeld != null && this.parent.Map != null)
            {
                HashSet <Thing> list        = new HashSet <Thing>(this.parent.MapHeld.thingGrid.ThingsListAtFast(this.parent.PositionHeld));
                var             isMeat      = this?.parent?.def.IsMeat ?? false;
                var             isSalted    = this?.parent?.def?.defName?.ToLowerInvariant()?.Contains("salted") ?? false;
                var             pantryShelf = list.FirstOrDefault(x => x is Building_RottableFixer && x.def.defName == "LotR_PantryShelf");
                var             saltPot     = list.FirstOrDefault(x => x is Building_RottableFixer && x.def.defName == "LotR_SaltBarrel");
                if (isMeat && !isSalted && saltPot != null)
                {
                    HandleMeatThatNeedsSalting(this.parent);
                    return;
                }

                float rotProgress        = this.RotProgress;
                float num                = 1f;
                float temperatureForCell = GenTemperature.GetTemperatureForCell(this.parent.PositionHeld, this.parent.MapHeld);
                var   b = list.FirstOrDefault(x => x is Building_RottableFixer);
                if (b != null)
                {
                    if (!isMeat && b.def.defName == "LotR_PantryShelf")
                    {
                        num = 0.3f;
                    }
                    if (b.def.defName == "LotR_SaltBarrel")
                    {
                        num = 0.0666667f;
                    }
                }

                num *= GenTemperature.RotRateAtTemperature(temperatureForCell);
                this.RotProgress += Mathf.Round(num * 250f);
                if (this.Stage == RotStage.Rotting && this.PropsRot.rotDestroys)
                {
                    if (this.parent.Position.GetSlotGroup(this.parent.Map) != null)
                    {
                        Messages.Message("MessageRottedAwayInStorage".Translate(new object[]
                        {
                            this.parent.Label
                        }).CapitalizeFirst(), MessageTypeDefOf.SilentInput);
                        LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers, OpportunityType.GoodToKnow);
                    }
                    this.parent.Destroy(DestroyMode.Vanish);
                    return;
                }
                if (Mathf.FloorToInt(rotProgress / 60000f) != Mathf.FloorToInt(this.RotProgress / 60000f))
                {
                    if (this.Stage == RotStage.Rotting && this.PropsRot.rotDamagePerDay > 0f)
                    {
                        this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)GenMath.RoundRandom(this.PropsRot.rotDamagePerDay), 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
                    }
                    else if (this.Stage == RotStage.Dessicated && this.PropsRot.dessicatedDamagePerDay > 0f && this.ShouldTakeDessicateDamage())
                    {
                        this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)GenMath.RoundRandom(this.PropsRot.dessicatedDamagePerDay), 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
                    }
                }
            }
        }
        public override void CompTickRare()
        {
            if (parent.MapHeld == null || parent.Map == null)
            {
                return;
            }

            var rotProgress        = RotProgress;
            var num                = 1f;
            var temperatureForCell =
                GenTemperature.GetTemperatureForCell(parent.PositionHeld, parent.MapHeld);
            var list = parent.MapHeld.thingGrid.ThingsListAtFast(parent.PositionHeld);

            foreach (var thing in list)
            {
                if (thing is not Building_Refrigerator bf)
                {
                    continue;
                }

                temperatureForCell = bf.CurrentTemp;
                break;
            }

            num         *= GenTemperature.RotRateAtTemperature(temperatureForCell);
            RotProgress += Mathf.Round(num * 250f);
            if (Stage == RotStage.Rotting && PropsRot.rotDestroys)
            {
                if (parent.IsInAnyStorage() && parent.SpawnedOrAnyParentSpawned)
                {
                    Messages.Message("MessageRottedAwayInStorage".Translate(parent.Label).CapitalizeFirst(),
                                     new TargetInfo(parent.PositionHeld, parent.MapHeld),
                                     MessageTypeDefOf.NegativeEvent);
                    LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers,
                                                         OpportunityType.GoodToKnow);
                }

                parent.Destroy();
                return;
            }

            if (Mathf.FloorToInt(rotProgress / 60000f) == Mathf.FloorToInt(RotProgress / 60000f) ||
                !ShouldTakeRotDamage())
            {
                return;
            }

            if (Stage == RotStage.Rotting && PropsRot.rotDamagePerDay > 0f)
            {
                parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                 GenMath.RoundRandom(PropsRot.rotDamagePerDay)));
            }
            else if (Stage == RotStage.Dessicated && PropsRot.dessicatedDamagePerDay > 0f)
            {
                parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                 GenMath.RoundRandom(PropsRot.dessicatedDamagePerDay)));
            }
        }
示例#6
0
        public override void CompTickRare()
        {
            if (this.parent.MapHeld != null && this.parent.Map != null)
            {
                float rotProgress        = this.RotProgress;
                float num                = 1f;
                float temperatureForCell =
                    GenTemperature.GetTemperatureForCell(this.parent.PositionHeld, this.parent.MapHeld);
                List <Thing> list = this.parent.MapHeld.thingGrid.ThingsListAtFast(this.parent.PositionHeld);
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i] is Building_Refrigerator)
                    {
                        var bf = list[i] as Building_Refrigerator;
                        temperatureForCell = bf.CurrentTemp;
                        break;
                    }
                }

                num *= GenTemperature.RotRateAtTemperature(temperatureForCell);
                this.RotProgress += Mathf.Round(num * 250f);
                if (this.Stage == RotStage.Rotting && this.PropsRot.rotDestroys)
                {
                    if (this.parent.IsInAnyStorage() && this.parent.SpawnedOrAnyParentSpawned)
                    {
                        Messages.Message("MessageRottedAwayInStorage".Translate(new object[]
                        {
                            this.parent.Label
                        }).CapitalizeFirst(), new TargetInfo(this.parent.PositionHeld, this.parent.MapHeld, false),
                                         MessageTypeDefOf.NegativeEvent, true);
                        LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers,
                                                             OpportunityType.GoodToKnow);
                    }
                    this.parent.Destroy(DestroyMode.Vanish);
                    return;
                }
                bool flag = Mathf.FloorToInt(rotProgress / 60000f) != Mathf.FloorToInt(this.RotProgress / 60000f);
                if (flag && ShouldTakeRotDamage())
                {
                    if (this.Stage == RotStage.Rotting && this.PropsRot.rotDamagePerDay > 0f)
                    {
                        this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                              (float)GenMath.RoundRandom(this.PropsRot.rotDamagePerDay), 0f, -1f, null, null, null,
                                                              DamageInfo.SourceCategory.ThingOrUnknown, null));
                    }
                    else if (this.Stage == RotStage.Dessicated && this.PropsRot.dessicatedDamagePerDay > 0f)
                    {
                        this.parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                              (float)GenMath.RoundRandom(this.PropsRot.dessicatedDamagePerDay), 0f, -1f, null, null,
                                                              null, DamageInfo.SourceCategory.ThingOrUnknown, null));
                    }
                }
            }
        }
        private bool IsTemperatureGood()
        {
            if (!parent.Spawned || parent.Map == null)
            {
                return(false);
            }

            float tempCell = GenTemperature.GetTemperatureForCell(this.parent.PositionHeld, parent.Map);

            tempCell = Mathf.RoundToInt(tempCell);
            return(tempCell > Props.activeTempRange.min && tempCell < Props.activeTempRange.max);
        }
示例#8
0
 // Token: 0x0600000C RID: 12 RVA: 0x00002294 File Offset: 0x00000494
 public override void CompTick()
 {
     if (this.parent.Map != null && GenTemperature.GetTemperatureForCell(this.parent.Position, this.parent.Map) > this.minimumDryingTemp)
     {
         float num = 1f / (this.Props.DaystoDry * 60000f);
         this.dryingProgress += num;
         if (this.dryingProgress > 1f)
         {
             this.Dry();
         }
     }
 }
 public static bool Applies(ThingDef tDef, Map map, IntVec3 c)
 {
     if (map == null)
     {
         return(false);
     }
     if (tDef.building != null && tDef.building.workSpeedPenaltyTemperature)
     {
         float temperatureForCell = GenTemperature.GetTemperatureForCell(c, map);
         return(temperatureForCell < 5.0 || temperatureForCell > 35.0);
     }
     return(false);
 }
示例#10
0
        protected virtual void DoFreezeCheck()
        {
            float temp = GenTemperature.GetTemperatureForCell(parent.Position);

            if (BeltPhase == Phase.Frozen && temp > FreezeTemperature && Rand.Range(0.0f, 1.0f) < 0.50f)
            {
                _beltPhase = Phase.Offline;
            }

            if (BeltPhase != Phase.Frozen && Rand.Range(0.0f, 1.0f) < this.FreezeChance(temp))
            {
                Freeze();
            }
        }
示例#11
0
        public static IEnumerable <Rule> ExtraRules()
        {
            Pawn initiator = DialogManager.Initiator;

            if (initiator == null)
            {
                yield break;
            }

            //pawn parameters
            if (PawnCheck())
            {
                Pawn   recipient = DialogManager.Recipient;
                string initPrefix = "INITIATOR_", reciPrefix = "RECIPIENT_";
                foreach (var rule in ExtraRulesForPawn(initPrefix, initiator, recipient))
                {
                    yield return(rule);
                }
                foreach (var rule in ExtraRulesForPawn(reciPrefix, recipient, initiator))
                {
                    yield return(rule);
                }
            }

            //climate
            yield return(new Rule_String("WEATHER", initiator.Map.weatherManager.CurWeatherPerceived.label));

            //time
            yield return(new Rule_String("HOUR", GenLocalDate.HourInteger(initiator).ToString()));

            yield return(new Rule_String("DAYPERIOD", DayPeriod(initiator)));

            //temperature
            yield return(new Rule_String("TEMPERATURE", GenTemperature.GetTemperatureForCell(initiator.Position, initiator.Map).ToString()));

            //outdoor?
            yield return(new Rule_String("OUTDOORS", initiator.Position.UsesOutdoorTemperature(initiator.Map).ToStringYesNo()));

            //nearest things
            foreach (var group in subjects)
            {
                var thing = GenClosest.ClosestThing_Global(initiator.Position, initiator.Map.listerThings.ThingsInGroup(group), lookRadius);
                if (thing != null)
                {
                    yield return(new Rule_String($"NEAREST_{group.ToString().ToLower()}", $"{thing.def.label}"));
                }
            }
        }
        private void TemperatureCheck()
        {
            nextTemperatureCheck--;
            if (nextTemperatureCheck > 0)
            {
                return;
            }
            const int delay = 20;

            nextTemperatureCheck += delay;

            // Develop heat
            var temperatureForCell = GenTemperature.GetTemperatureForCell(Position);

            if (HasPower)
            {
                innerHeat += compDef.innerHeatPerSecond / 60 * delay;
            }

            // Apply cooling
            innerHeat -= cooling;
            cooling    = 0;

            if (innerHeat < temperatureForCell)
            {
                innerHeat = temperatureForCell;
            }

            if (heater != null && innerHeat > temperatureForCell)
            {
                // 5% heat loss
                heater.props.heatPerSecond = (innerHeat - temperatureForCell) * 0.05f;
                innerHeat -= heater.props.heatPerSecond / 60 * delay;
            }

            //Log.Message("Try burn " + Label + ": " + (innerHeat - compDef.criticalTemperature) + ", " + (compDef.ignitionChancePerTick *delay* innerHeat / compDef.criticalTemperature));
            if (innerHeat > compDef.criticalTemperature && Rand.Value < compDef.ignitionChance * innerHeat / compDef.criticalTemperature)
            {
                if (!Position.ContainsStaticFire())
                {
                    innerHeat           = 0;
                    power.DesirePowerOn = false;
                    GenExplosion.DoExplosion(Position, 0.5f, DamageDefOf.Flame, this);
                }
            }
        }
        public override string GetInspectString()
        {
            float temperature = GenTemperature.GetTemperatureForCell(this.Position);

            if (temperature < CavePlant.minTempToGrow)
            {
                return("Cannot grow now: too cold.");
            }
            else if (temperature > CavePlant.maxTempToGrow)
            {
                return("Cannot grow now: too hot.");
            }
            else
            {
                return("Growing.");
            }
        }
        public override string GetInspectString()
        {
            float temperature = GenTemperature.GetTemperatureForCell(this.Position);
            ThingDef_ClusterPlant clusterPlantDef = this.GetPlantDefToGrow() as ThingDef_ClusterPlant;

            if (temperature < clusterPlantDef.minGrowTemperature)
            {
                return("Cannot grow now: too cold.");
            }
            else if (temperature > clusterPlantDef.maxGrowTemperature)
            {
                return("Cannot grow now: too hot.");
            }
            else
            {
                return("Growing.");
            }
        }
示例#15
0
        public static bool Applies(ThingDef tDef, Map map, IntVec3 c)
        {
            if (map == null)
            {
                return(false);
            }
            if (tDef.building == null)
            {
                return(false);
            }
            float temperatureForCell = GenTemperature.GetTemperatureForCell(c, map);

            if (!(temperatureForCell < 9f))
            {
                return(temperatureForCell > 35f);
            }
            return(true);
        }
示例#16
0
        public override string GetInspectString()
        {
            float temperature = GenTemperature.GetTemperatureForCell(this.Position, this.Map);
            ThingDef_ClusterPlant clusterPlantDef = this.GetPlantDefToGrow() as ThingDef_ClusterPlant;

            if (temperature < clusterPlantDef.minGrowTemperature)
            {
                return("CaveworldFlora.CannotGrowTooCold".Translate());
            }
            else if (temperature > clusterPlantDef.maxGrowTemperature)
            {
                return("CaveworldFlora.CannotGrowTooHot".Translate());
            }
            else
            {
                return("CaveworldFlora.Growing".Translate());
            }
        }
示例#17
0
        private void AutoVentControl()
        {
            int ticksGame = Find.TickManager.TicksGame;

            if ((ticksGame % (tickRareInterval * 3) != 0) && !badTemperatureOnce)
            {
                return;                                                                   //Checks only each 12,5s or if bad temperature on last cycle.
            }
            float insideTemp  = AttachedRoom.Temperature;
            float outsideTemp = GenTemperature.GetTemperatureForCell(Outside, Map);

            if (TargetTemp.Includes(insideTemp)) //Stand down if temperature is right.
            {
                if (ventComp.WantsFlick())       //If temperature is right but a command is still pending, cancel it.
                {
                    ventComp.FlickFor(venting);
                }
                if (leaks && !badTemperatureOnce && !open && TargetTemp.Includes(outsideTemp)) //If its a simple window, check if should re-open next cycle.
                {
                    ShouldReOpen();
                }
                badTemperatureRecently = badTemperatureOnce = false;
                skippedTempChecks      = 0;
                return;
            }
            if (badTemperatureRecently) //Escape if acted recently.
            {
                if (skippedTempChecks <= maxTempChecks)
                {
                    skippedTempChecks++;
                    return;
                }
                badTemperatureRecently = false;
                skippedTempChecks      = 0;
            }
            if (badTemperatureOnce) //React only if bad temperature persists from last tickRare.
            {
                badTemperatureOnce = false;
                ReactToTemperature(insideTemp, outsideTemp); //Actually evaluating the situation.
                return;
            }
            badTemperatureOnce = true;
        }
示例#18
0
        public static bool Applies(ThingDef tDef, Map map, IntVec3 c)
        {
            bool result;

            if (map == null)
            {
                result = false;
            }
            else if (tDef.building == null || !tDef.building.workSpeedPenaltyTemperature)
            {
                result = false;
            }
            else
            {
                float temperatureForCell = GenTemperature.GetTemperatureForCell(c, map);
                result = (temperatureForCell <9f || temperatureForCell> 35f);
            }
            return(result);
        }
            public static void GetOutdoorTemp(ref float __result, Map ___map)
            {
                MapParent_PocketDimension mapParent = ___map.info.parent as MapParent_PocketDimension;

                if (mapParent != null)
                {
                    Building_PocketDimensionEntranceBase box = PocketDimensionUtility.GetBox(mapParent.dimensionSeed);
                    if (box != null)
                    {
                        __result = 21.0f;

                        if (box.Spawned)
                        {
                            __result = GenTemperature.GetTemperatureForCell(box.Position, box.Map);
                        }
                        else if (box.ParentHolder != null)
                        {
                            for (IThingHolder parentHolder = box.ParentHolder; parentHolder != null; parentHolder = parentHolder.ParentHolder)
                            {
                                if (ThingOwnerUtility.TryGetFixedTemperature(parentHolder, box, out __result))
                                {
                                    return;// false;
                                }
                            }
                        }
                        else if (box.SpawnedOrAnyParentSpawned)
                        {
                            __result = GenTemperature.GetTemperatureForCell(box.PositionHeld, box.MapHeld);
                        }
                        else if (box.Tile >= 0)
                        {
                            __result = GenTemperature.GetTemperatureFromSeasonAtTile(GenTicks.TicksAbs, box.Tile);
                        }

                        // Above logic derived from the following function call. Can't call it here due to an edge case which results in infinite loop
                        //__result = box.AmbientTemperature;
                        return;// false;
                    }
                }

                //return true;
            }
示例#20
0
        private void AutoVentControl()
        {
            float insideTemp = AttachedRoom.Temperature;
            int   ticksGame  = Find.TickManager.TicksGame;

            if (!TargetTemp.Includes(insideTemp) && !recentlyOperated)
            {
                if (nextToleranceCheckTick == 0 || ticksGame >= nextToleranceCheckTick)
                {
                    float outsideTemp = GenTemperature.GetTemperatureForCell(Outside, Map);
                    bool
                        colderOutside = insideTemp > outsideTemp,
                        colderInside  = insideTemp <outsideTemp,
                                                    tooHotInside = insideTemp> TargetTemp.max,
                        tooColdInside = insideTemp <TargetTemp.min,
                                                    tooHotOutside = outsideTemp> TargetTemp.max,
                        tooColdOutside = outsideTemp < TargetTemp.min;
                    bool doFlick       = false;
                    if (!venting) //open if...
                    {
                        doFlick = (tooHotInside && colderOutside) || (tooColdInside && colderInside && !tooColdOutside);
                    }
                    else //close if...
                    {
                        doFlick = (tooHotInside && tooHotOutside) || (tooColdInside && tooColdOutside);
                    }
                    if (doFlick)
                    {
                        recentlyOperated = true;
                        ventComp.AutoFlickRequest();
                    }
                    nextToleranceCheckTick = ticksGame + toleranceCheckInterval;
                }
            }
            else if (ticksGame >= nextToleranceCheckTick + (toleranceCheckInterval * intervalMultiplierAfterAttempts) || TargetTemp.Includes(insideTemp))
            {
                if (recentlyOperated)
                {
                    recentlyOperated = false;
                }
            }
        }
        internal static string              _CompInspectStringExtra(this CompRottable obj)
        {
            var stringBuilder = new StringBuilder();

            switch (obj.Stage)
            {
            case RotStage.Fresh:
                stringBuilder.AppendLine("RotStateFresh".Translate());
                break;

            case RotStage.Rotting:
                stringBuilder.AppendLine("RotStateRotting".Translate());
                break;

            case RotStage.Dessicated:
                stringBuilder.AppendLine("RotStateDessicated".Translate());
                break;
            }
            if (obj.InRefrigerator())
            {
                stringBuilder.AppendLine("RefrigeratedStorage".Translate());
            }
            else if ((obj.PropsRot().TicksToRotStart - obj.rotProgress) > 0.0f)
            {
                float num = GenTemperature.RotRateAtTemperature(Mathf.RoundToInt(GenTemperature.GetTemperatureForCell(obj.parent.Position)));
                int   rotAtCurrentTemp = obj.TicksUntilRotAtCurrentTemp;
                if (num < 1.0f / 1000.0f)
                {
                    stringBuilder.AppendLine("CurrentlyFrozen".Translate());
                }
                else if (num < 0.999000012874603f)
                {
                    stringBuilder.AppendLine("CurrentlyRefrigerated".Translate(rotAtCurrentTemp.TickstoDaysString()));
                }
                else
                {
                    stringBuilder.AppendLine("NotRefrigerated".Translate(rotAtCurrentTemp.TickstoDaysString()));
                }
            }
            return(stringBuilder.ToString());
        }
        public static bool Applies(ThingDef tDef, Map map, IntVec3 c, Pawn pawn)
        {
            if (map == null)
            {
                return(false);
            }
            if (tDef.building == null)
            {
                return(false);
            }
            float temperatureForCell = GenTemperature.GetTemperatureForCell(c, map);
            float min = pawn.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMin, null);
            float max = pawn.def.GetStatValueAbstract(StatDefOf.ComfyTemperatureMax, null);
            bool  result = temperatureForCell <min || temperatureForCell> max;

            if (result)
            {
                Log.Message($"Bad temperature for {pawn}");
            }
            return(result);
        }
        private void CoolingCheck()
        {
            nextCoolingCheck--;
            if (neighbors == null || neighbors.Count == 0 || nextCoolingCheck > 0)
            {
                return;
            }
            const int delay = 20;

            nextCoolingCheck += delay;

            var temperatureHere = GenTemperature.GetTemperatureForCell(Position);
            var totalHeat       = 0f;

            foreach (var neighbor in neighbors)
            {
                if (neighbor.innerHeat > temperatureHere)
                {
                    neighbor.cooling += CoolingPerSecond / 60 * delay;
                    totalHeat        += CoolingPerSecond / 60 * delay;
                }
            }
            GenTemperature.PushHeat(Position, totalHeat);
        }
示例#24
0
        public override string CompInspectStringExtra()
        {
            StringBuilder sb = new StringBuilder();

            switch (base.Stage)
            {
            case RotStage.Fresh:
                sb.AppendLine("RotStateFresh".Translate());
                break;

            case RotStage.Rotting:
                sb.AppendLine("RotStateRotting".Translate());
                break;

            case RotStage.Dessicated:
                sb.AppendLine("RotStateDessicated".Translate());
                break;
            }
            float num = (float)this.PropsRot.TicksToRotStart - base.RotProgress;

            if (num > 0f)
            {
                float        num2      = GenTemperature.GetTemperatureForCell(this.parent.PositionHeld, this.parent.Map);
                List <Thing> thingList = GridsUtility.GetThingList(this.parent.PositionHeld, this.parent.Map);
                var          factor    = 1f;
                for (int i = 0; i < thingList.Count; i++)
                {
                    if (thingList[i] is Building_RottableFixer)
                    {
                        var b      = thingList[i] as Building_RottableFixer;
                        var isMeat = this?.parent?.def.IsMeat ?? false;
                        if (!isMeat && b.def.defName == "LotR_PantryShelf")
                        {
                            factor = 3f;
                        }
                        if (b.def.defName == "LotR_SaltBarrel")
                        {
                            factor = 15f;
                        }
                        //num2 = building_Refrigerator.CurrentTemp;
                        break;
                    }
                }
                num2 = (float)Mathf.RoundToInt(num2);
                float num3 = GenTemperature.RotRateAtTemperature(num2);
                int   ticksUntilRotAtCurrentTemp = (int)(base.TicksUntilRotAtCurrentTemp * factor);
                if (num3 < 0.001f)
                {
                    sb.Append("CurrentlyFrozen".Translate() + ".");
                }
                else
                {
                    if (num3 < 0.999f)
                    {
                        sb.Append("CurrentlyRefrigerated".Translate(new object[]
                        {
                            ticksUntilRotAtCurrentTemp.ToStringTicksToPeriodVague()
                        }) + ".");
                    }
                    else
                    {
                        sb.Append("NotRefrigerated".Translate(new object[]
                        {
                            ticksUntilRotAtCurrentTemp.ToStringTicksToPeriodVague()
                        }) + ".");
                    }
                }
            }
            return(sb.ToString().TrimEndNewlines());
        }
示例#25
0
            public static Job SeekSafeTemperature(JobDef def, Pawn pawn, FloatRange tempRange)
            {
                var map = pawn.Map;

                if (pawn.Position.UsesOutdoorTemperature(map) && proxyHeatManagers.TryGetValue(map, out ProxyHeatManager proxyHeatManager))
                {
                    var candidates = new List <IntVec3>();
                    foreach (var tempSource in proxyHeatManager.temperatureSources)
                    {
                        var result = proxyHeatManager.GetTemperatureOutcomeFor(tempSource.Key, GenTemperature.GetTemperatureForCell(tempSource.Key, map));
                        if (tempRange.Includes(result))
                        {
                            candidates.Add(tempSource.Key);
                        }
                    }
                    candidates = candidates.OrderBy(x => pawn.Position.DistanceTo(x)).ToList();
                    foreach (var cell in candidates)
                    {
                        if (cell.GetFirstPawn(map) is null && pawn.Map.pawnDestinationReservationManager.FirstReserverOf(cell, pawn.Faction) is null &&
                            pawn.CanReserveAndReach(cell, PathEndMode.OnCell, Danger.Deadly))
                        {
                            var job = JobMaker.MakeJob(def, cell);
                            pawn.Reserve(cell, job);
                            return(job);
                        }
                    }

                    foreach (var cell in candidates)
                    {
                        if (pawn.CanReserveAndReach(cell, PathEndMode.OnCell, Danger.Deadly))
                        {
                            var job = JobMaker.MakeJob(def, cell);
                            pawn.Reserve(cell, job);
                            return(job);
                        }
                    }
                }
                return(null);
            }
示例#26
0
        public static bool GenNewRRJobPrefix(ref Job __result, JobDef def, Region reg)
        {
            if (pawnToLookUp != null)
            {
                var map       = reg.Map;
                var tempRange = pawnToLookUp.ComfortableTemperatureRange();
                if (reg.Room.UsesOutdoorTemperature && proxyHeatManagers.TryGetValue(map, out ProxyHeatManager proxyHeatManager))
                {
                    var candidates = new List <IntVec3>();
                    foreach (var tempSource in proxyHeatManager.temperatureSources)
                    {
                        if (reg.Room.ContainsCell(tempSource.Key))
                        {
                            var result = proxyHeatManager.GetTemperatureOutcomeFor(tempSource.Key, GenTemperature.GetTemperatureForCell(tempSource.Key, map));
                            if (tempRange.Includes(result))
                            {
                                candidates.Add(tempSource.Key);
                            }
                        }
                    }
                    candidates = candidates.OrderBy(x => pawnToLookUp.Position.DistanceTo(x)).ToList();

                    foreach (var cell in candidates)
                    {
                        if (cell.GetFirstPawn(map) is null && pawnToLookUp.Map.pawnDestinationReservationManager.FirstReserverOf(cell, pawnToLookUp.Faction) is null &&
                            pawnToLookUp.CanReserveAndReach(cell, PathEndMode.OnCell, Danger.Deadly))
                        {
                            __result = JobMaker.MakeJob(def, cell);
                            pawnToLookUp.Reserve(cell, __result);
                            return(false);
                        }
                    }

                    foreach (var cell in candidates)
                    {
                        if (pawnToLookUp.CanReserveAndReach(cell, PathEndMode.OnCell, Danger.Deadly))
                        {
                            __result = JobMaker.MakeJob(def, cell);
                            pawnToLookUp.Reserve(cell, __result);
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
示例#27
0
        // stats recalculation routine
        public void updateColonistStats(Pawn colonist)
        {
            if (!stats_dict.ContainsKey(colonist))
            {
                stats_dict.Add(colonist, new PawnStats());
            }
            PawnStats pawnStats = stats_dict[colonist];

            ///////////////////////////////////////////////////////////////

            pawnStats.isNudist = false;

            foreach (Trait trait in colonist.story.traits.allTraits)
            {
                switch (trait.def.defName)
                {
                case "Nudist":
                    pawnStats.isNudist = true;
                    break;
                }
            }

            // efficiency
            float efficiency = 10;

            foreach (PawnCapacityDef act in pawnCapacities)
            {
                if (act != PawnCapacityDefOf.Consciousness)
                {
                    efficiency = Math.Min(efficiency, colonist.health.capacities.GetEfficiency(act));
                }
            }

            if (efficiency < 0)
            {
                efficiency = 0;
            }
            pawnStats.total_efficiency = efficiency;

            // target
            pawnStats.targetPos = Vector3.zero;

            if (colonist.jobs.curJob != null)
            {
                JobDriver  curDriver = colonist.jobs.curDriver;
                Job        curJob    = colonist.jobs.curJob;
                TargetInfo tp        = curJob.targetA;

                if (curDriver is JobDriver_HaulToContainer || curDriver is JobDriver_HaulToCell ||
                    curDriver is JobDriver_FoodDeliver || curDriver is JobDriver_FoodFeedPatient ||
                    curDriver is JobDriver_TakeToBed)
                {
                    tp = curJob.targetB;
                }

                if (curDriver is JobDriver_DoBill)
                {
                    JobDriver_DoBill bill = (JobDriver_DoBill)curDriver;
                    if (bill.workLeft == 0.0f)
                    {
                        tp = curJob.targetA;
                    }
                    else if (bill.workLeft <= 0.01f)
                    {
                        tp = curJob.targetB;
                    }

                    //Log.Message("" + ((JobDriver_DoBill)colonist.jobs.curDriver).workLeft);
                }

                if (curDriver is JobDriver_Hunt)
                {
                    if (colonist.carryHands != null && colonist.carryHands.CarriedThing != null)
                    {
                        tp = curJob.targetB;
                    }
                }

                if (curJob.def == JobDefOf.Wait)
                {
                    tp = null;
                }
                if (curDriver is JobDriver_Ingest)
                {
                    tp = null;
                }
                if (curJob.def == JobDefOf.LayDown && colonist.InBed())
                {
                    tp = null;
                }
                if (!curJob.playerForced && curJob.def == JobDefOf.Goto)
                {
                    tp = null;
                }

                //Log.Message(colonist.jobs.curJob.def.ToString()+" "+colonist.jobs.curDriver.GetType().ToString());

                if (tp != null && tp.Cell != null)
                {
                    Vector3 pos = tp.Cell.ToVector3Shifted();
                    pawnStats.targetPos = pos + new Vector3(0.0f, 3.0f, 0.0f);
                }
            }

            // temperature

            float temper = GenTemperature.GetTemperatureForCell(colonist.Position);

            pawnStats.tooCold = (colonist.ComfortableTemperatureRange().min - settings.limit_tempComfortOffset - temper) / 10.0f;
            pawnStats.tooHot  = (temper - colonist.ComfortableTemperatureRange().max - settings.limit_tempComfortOffset) / 10.0f;

            pawnStats.tooCold = Mathf.Clamp(pawnStats.tooCold, 0, 2);
            pawnStats.tooHot  = Mathf.Clamp(pawnStats.tooHot, 0, 2);

            // diseases

            pawnStats.diseaseDisappearance = 1;
            pawnStats.drunkness            = DrugUtility.DrunknessPercent(colonist);

            using (IEnumerator <Hediff_Staged> enumerator = colonist.health.hediffSet.GetDiseases().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Hediff_Staged disease = enumerator.Current;
                    if (disease == null || disease.FullyImmune || !disease.Visible)
                    {
                        continue;
                    }
                    if (disease.CurStage != null && !disease.CurStage.everVisible)
                    {
                        continue;
                    }
                    if (!disease.def.Treatable && !disease.def.naturallyHealed)
                    {
                        continue;
                    }

                    pawnStats.diseaseDisappearance = Math.Min(pawnStats.diseaseDisappearance, disease.Immunity);
                }
            }

            // apparel problems

            float worstApparel = 999f;

            List <Apparel> apparelListForReading = colonist.apparel.WornApparel;

            for (int index = 0; index < apparelListForReading.Count; ++index)
            {
                float curApparel = (float)apparelListForReading[index].HitPoints / (float)apparelListForReading[index].MaxHitPoints;
                if (curApparel >= 0 && curApparel < worstApparel)
                {
                    worstApparel = curApparel;
                }
            }

            pawnStats.apparelHealth = worstApparel;

            // bloodloss

            pawnStats.bleedRate = Mathf.Clamp01(colonist.health.hediffSet.BleedingRate * settings.limit_bleedMult);

            ////////////////////////////////////////////////////
            stats_dict[colonist] = pawnStats;
        }
示例#28
0
        public override string CompInspectStringExtra()
        {
            var sb = new StringBuilder();

            switch (Stage)
            {
            case RotStage.Fresh:
                sb.AppendLine("RotStateFresh".Translate());
                break;

            case RotStage.Rotting:
                sb.AppendLine("RotStateRotting".Translate());
                break;

            case RotStage.Dessicated:
                sb.AppendLine("RotStateDessicated".Translate());
                break;
            }

            var num = PropsRot.TicksToRotStart - RotProgress;

            if (!(num > 0f))
            {
                return(sb.ToString().TrimEndNewlines());
            }

            var num2      = GenTemperature.GetTemperatureForCell(parent.PositionHeld, parent.Map);
            var thingList = parent.PositionHeld.GetThingList(parent.Map);
            var factor    = 1f;

            foreach (var thing in thingList)
            {
                if (!(thing is Building_RottableFixer fixer))
                {
                    continue;
                }

                var isMeat = parent?.def.IsMeat ?? false;
                if (!isMeat && fixer.def.defName == "LotR_PantryShelf")
                {
                    factor = 3f;
                }

                if (fixer.def.defName == "LotR_SaltBarrel")
                {
                    factor = 15f;
                }

                //num2 = building_Refrigerator.CurrentTemp;
                break;
            }

            num2 = Mathf.RoundToInt(num2);
            var num3 = GenTemperature.RotRateAtTemperature(num2);
            var ticksUntilRotAtCurrentTemp = (int)(TicksUntilRotAtCurrentTemp * factor);

            if (num3 < 0.001f)
            {
                sb.Append("CurrentlyFrozen".Translate() + ".");
            }
            else
            {
                if (num3 < 0.999f)
                {
                    sb.Append(
                        "CurrentlyRefrigerated".Translate(ticksUntilRotAtCurrentTemp.ToStringTicksToPeriodVague()) +
                        ".");
                }
                else
                {
                    sb.Append(
                        "NotRefrigerated".Translate(ticksUntilRotAtCurrentTemp.ToStringTicksToPeriodVague()) + ".");
                }
            }

            return(sb.ToString().TrimEndNewlines());
        }
示例#29
0
        public override void CompTickRare()
        {
            if (parent.MapHeld == null || parent.Map == null)
            {
                return;
            }

            var list     = new HashSet <Thing>(parent.MapHeld.thingGrid.ThingsListAtFast(parent.PositionHeld));
            var isMeat   = parent?.def.IsMeat ?? false;
            var isSalted = parent?.def?.defName?.ToLowerInvariant().Contains("salted") ?? false;
            var saltPot  =
                list.FirstOrDefault(x => x is Building_RottableFixer && x.def.defName == "LotR_SaltBarrel");

            if (isMeat && !isSalted && saltPot != null)
            {
                HandleMeatThatNeedsSalting(parent);
                return;
            }

            var rotProgress        = RotProgress;
            var num                = 1f;
            var temperatureForCell = GenTemperature.GetTemperatureForCell(parent.PositionHeld, parent.MapHeld);
            var b = list.FirstOrDefault(x => x is Building_RottableFixer);

            if (b != null)
            {
                if (!isMeat && b.def.defName == "LotR_PantryShelf")
                {
                    num = 0.3f;
                }

                if (b.def.defName == "LotR_SaltBarrel")
                {
                    num = 0.0666667f;
                }
            }

            num         *= GenTemperature.RotRateAtTemperature(temperatureForCell);
            RotProgress += Mathf.Round(num * 250f);
            if (Stage == RotStage.Rotting && PropsRot.rotDestroys)
            {
                if (parent.Position.GetSlotGroup(parent.Map) != null)
                {
                    Messages.Message("MessageRottedAwayInStorage".Translate(parent.Label).CapitalizeFirst(),
                                     MessageTypeDefOf.SilentInput);
                    LessonAutoActivator.TeachOpportunity(ConceptDefOf.SpoilageAndFreezers,
                                                         OpportunityType.GoodToKnow);
                }

                parent.Destroy();
                return;
            }

            if (Mathf.FloorToInt(rotProgress / 60000f) == Mathf.FloorToInt(RotProgress / 60000f))
            {
                return;
            }

            if (Stage == RotStage.Rotting && PropsRot.rotDamagePerDay > 0f)
            {
                parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                 GenMath.RoundRandom(PropsRot.rotDamagePerDay)));
            }
            else if (Stage == RotStage.Dessicated && PropsRot.dessicatedDamagePerDay > 0f &&
                     ShouldTakeDessicateDamage())
            {
                parent.TakeDamage(new DamageInfo(DamageDefOf.Rotting,
                                                 GenMath.RoundRandom(PropsRot.dessicatedDamagePerDay)));
            }
        }
示例#30
0
        private static void UpdateColonistStats(Pawn colonist)
        {
            if (!_statsDict.ContainsKey(colonist))
            {
                _statsDict.Add(colonist, new PawnStats());
            }

            var pawnStats = _statsDict[colonist];

            // Efficiency
            var efficiency = (from activity in _pawnCapacities where activity != PawnCapacityDefOf.Consciousness select colonist.health.capacities.GetEfficiency(activity)).Concat(new[] { 10f }).Min();

            if (efficiency < 0.0)
            {
                efficiency = 0.0f;
            }

            pawnStats.pawn_TotalEfficiency = efficiency;

            // Target
            pawnStats.TargetPos = Vector3.zero;

            if (colonist.jobs.curJob != null)
            {
                var jobDriver  = colonist.jobs.curDriver;
                var job        = colonist.jobs.curJob;
                var targetInfo = job.targetA;

                if (jobDriver is JobDriver_HaulToContainer || jobDriver is JobDriver_HaulToCell || (jobDriver is JobDriver_FoodDeliver || jobDriver is JobDriver_FoodFeedPatient) || jobDriver is JobDriver_TakeToBed)
                {
                    targetInfo = job.targetB;
                }

                var doBill = jobDriver as JobDriver_DoBill;
                if (doBill != null)
                {
                    var jobDriverDoBill = doBill;
                    // ReSharper disable once CompareOfFloatsByEqualityOperator
                    if (jobDriverDoBill.workLeft == 0.0)
                    {
                        targetInfo = job.targetA;
                    }
                    else if (jobDriverDoBill.workLeft <= 0.00999999977648258)
                    {
                        targetInfo = job.targetB;
                    }
                }

                if (jobDriver is JobDriver_Hunt && colonist.carrier?.CarriedThing != null)
                {
                    targetInfo = job.targetB;
                }

                if (job.def == JobDefOf.Wait)
                {
                    targetInfo = null;
                }

                if (jobDriver is JobDriver_Ingest)
                {
                    targetInfo = null;
                }

                if (job.def == JobDefOf.LayDown && colonist.InBed())
                {
                    targetInfo = null;
                }

                if (!job.playerForced && job.def == JobDefOf.Goto)
                {
                    targetInfo = null;
                }

                var flag = targetInfo == null;
                if (!flag)
                {
                    var vector3 = targetInfo.Cell.ToVector3Shifted();
                    pawnStats.TargetPos = vector3 + new Vector3(0.0f, 3f, 0.0f);
                }
            }

            // Temperature
            var temperatureForCell = GenTemperature.GetTemperatureForCell(colonist.Position);

            pawnStats.pawn_TooCold = (float)((colonist.ComfortableTemperatureRange().min - (double)Settings.limit_TempComfortOffset - temperatureForCell) / 10.0);
            pawnStats.pawn_TooHot  = (float)((temperatureForCell - (double)colonist.ComfortableTemperatureRange().max - Settings.limit_TempComfortOffset) / 10.0);
            pawnStats.pawn_TooCold = Mathf.Clamp(pawnStats.pawn_TooCold, 0.0f, 2f);
            pawnStats.pawn_TooHot  = Mathf.Clamp(pawnStats.pawn_TooHot, 0.0f, 2f);


            // Health Calc
            pawnStats.DiseaseDisappearance = 1f;
            pawnStats.pawn_Drunkness       = DrugUtility.DrunknessPercent(colonist);


            foreach (var hediff in colonist.health.hediffSet.hediffs)
            {
                var hediffWithComps = (HediffWithComps)hediff;
                if (hediffWithComps != null &&
                    !hediffWithComps.FullyImmune() &&
                    hediffWithComps.Visible &&
                    !hediffWithComps.IsOld() &&
                    (hediffWithComps.CurStage == null ||
                     hediffWithComps.CurStage.everVisible) &&
                    (hediffWithComps.def.tendable ||
                     hediffWithComps.def.naturallyHealed) &&
                    hediffWithComps.def.PossibleToDevelopImmunity())
                {
                    pawnStats.DiseaseDisappearance = Math.Min(pawnStats.DiseaseDisappearance, colonist.health.immunity.GetImmunity(hediffWithComps.def));
                }
            }

            // Apparel Calc
            var num1        = 999f;
            var wornApparel = colonist.apparel.WornApparel;

            foreach (var apparel in wornApparel)
            {
                var num2 = apparel.HitPoints / (float)apparel.MaxHitPoints;
                if (num2 >= 0.0 && num2 < (double)num1)
                {
                    num1 = num2;
                }
            }

            pawnStats.pawn_ApparelHealth = num1;

            pawnStats.pawn_BleedRate = Mathf.Clamp01(colonist.health.hediffSet.BleedingRate * Settings.limit_BleedMult);

            _statsDict[colonist] = pawnStats;
        }