public override void TickRare()
        {
            if (this.CurrentTemp < -2000f)
            {
                this.CurrentTemp = GridsUtility.GetTemperature(base.Position, base.Map);
            }
            foreach (IntVec3 cell in this.AllSlotCells())
            {
                foreach (Thing thing in GridsUtility.GetThingList(cell, base.Map))
                {
                    CompRottable rottable = ThingCompUtility.TryGetComp <CompRottable>(thing);
                    if (rottable != null && !(rottable is CompBetterRottable))
                    {
                        ThingWithComps     thingWithComps     = thing as ThingWithComps;
                        CompBetterRottable compBetterRottable = new CompBetterRottable();
                        thingWithComps.AllComps.Remove(rottable);
                        thingWithComps.AllComps.Add(compBetterRottable);
                        compBetterRottable.props       = rottable.props;
                        compBetterRottable.parent      = thingWithComps;
                        compBetterRottable.RotProgress = rottable.RotProgress;
                    }

                    if (ThingCompUtility.TryGetComp <CompFrosty>(thing) == null && thing.def.defName == "Beer")
                    {
                        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);
                    }
                }
            }

            float roomTemperature   = GridsUtility.GetTemperature(base.Position, base.Map);
            float changetemperature = (roomTemperature - this.CurrentTemp) * 0.01f;
            float changeEnergy      = -changetemperature;
            float powerMultiplier   = 0f;

            if (this.CurrentTemp + changetemperature > this.DesiredTemp)
            {
                float change = Mathf.Max(this.DesiredTemp - (this.CurrentTemp + changetemperature), -1f);
                if (this.powerComp != null && this.powerComp.PowerOn)
                {
                    changetemperature += change;
                    changeEnergy      -= change * 1.25f;
                }
                powerMultiplier = change * -1f;
            }
            this.CurrentTemp += changetemperature;
            IntVec3 pos = base.Position + IntVec3.North.RotatedBy(base.Rotation);

            GenTemperature.PushHeat(pos, base.Map, changeEnergy * 1.25f);
            this.powerComp.PowerOutput = -((CompProperties_Power)this.powerComp.props).basePowerConsumption * (powerMultiplier * 0.9f + 0.1f);
        }
Ejemplo n.º 2
0
        public override void PostSplitOff(Thing piece)
        {
            ThingWithComps thingWithComps = piece as ThingWithComps;

            if (ThingCompUtility.TryGetComp <CompFrosty>(thingWithComps) == null)
            {
                CompFrosty compFrosty = new CompFrosty();
                thingWithComps.AllComps.Add(compFrosty);
                compFrosty.props       = CompProperties_Frosty.Beer;
                compFrosty.parent      = thingWithComps;
                compFrosty.temperature = temperature;
                ((TickList)typeof(TickManager).GetField("tickListRare", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Find.TickManager)).RegisterThing(thingWithComps);
            }
        }
Ejemplo n.º 3
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);
            }
        }