Example #1
0
        protected override bool isPawnAffected(Pawn p)
        {
            float maxComfortTemp = p.ComfortableTemperatureRange().max;
            float curTemp        = 999;

            GenTemperature.TryGetAirTemperatureAroundThing(p, out curTemp);
            if (curTemp > maxComfortTemp)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        public override void CompTickRare()
        {
            base.CompTickRare();
            //Check for alcohol that is best drunk cold.
            foreach (IntVec3 cell in ((Building_Storage)parent).AllSlotCells())
            {
                foreach (Thing thing in GridsUtility.GetThingList(cell, parent.Map))
                {
                    if (drinksBestCold.Contains(thing.def.defName) && ThingCompUtility.TryGetComp <CompFrosty>(thing) == null)
                    {
                        ThingWithComps thingWithComps = thing as ThingWithComps;
                        CompFrosty     compFrosty     = new CompFrosty();
                        thingWithComps.AllComps.Add(compFrosty);
                        compFrosty.props  = CompProperties_Frosty.Beer;
                        compFrosty.parent = thingWithComps;
                        ((TickList)typeof(TickManager).GetField("tickListRare", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Find.TickManager)).RegisterThing(thingWithComps);
                    }
                }
            }
            //Get the actual temperature at the fridge, since we're patching the game's method.
            //These call the internal functions of GenTemperature.TryGetTemperatureForCell()

            IntVec3 position        = parent.Position;
            Map     map             = parent.Map;
            float   roomTemperature = 21f; // The game uses 21 as it's general default as well.

            // This bit will work for normal furniture RimFridges
            if (!GenTemperature.TryGetDirectAirTemperatureForCell(position, map, out roomTemperature))
            {
                List <Thing> list = map.thingGrid.ThingsListAtFast(position);
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].def.passability == Traversability.Impassable)
                    {
                        // This is if it's a wall-mount RimFridge and not part of a "room"
                        GenTemperature.TryGetAirTemperatureAroundThing(list[i], out roomTemperature);
                    }
                }
            }

            float changetemperature = (roomTemperature - currentTemp) * 0.01f;
            float changeEnergy      = -changetemperature;
            float powerMultiplier   = 0f;

            if (currentTemp + changetemperature > desiredTemp)
            {
                // When the RimFridge's compressor is working and it's pushing the internal temperature down, it can draw a lot of power!
                // Once it gets to temp, maintaining it isn't bad.
                float change = Mathf.Max(desiredTemp - (currentTemp + changetemperature), -3f);
                if (ShouldBeActive)  //Using this just in case someone wants to make a wood-burning RimFridge
                {
                    changetemperature += change;
                    changeEnergy      -= change * 1.25f;
                }
                powerMultiplier = change * -1f;
            }
            // Like all refrigerators, the RimFridge is insulated.  It won't instantly drop to room-temp from loss of power and things inside
            // should be good through brief power interruptions.
            currentTemp += changetemperature;
            IntVec3 pos = position + IntVec3.North.RotatedBy(parent.Rotation);

            GenTemperature.PushHeat(pos, map, changeEnergy * 1.25f);
            if (powerTrader != null)
            {
                powerTrader.PowerOutput = -((CompProperties_Power)powerTrader.props).basePowerConsumption * ((powerMultiplier * 0.9f) + 0.1f);
            }
        }