예제 #1
0
        public void BuildRTString(CompDFoodTemperature comp, ref StringBuilder s)
        {
            DTemperatureLevels levels = comp.PropsTemp.tempLevels;

            s.AppendLine();
            s.AppendLine("Too hot: >" + GenText.ToStringTemperature(levels.okTemp));
            s.AppendLine("Ideal temperature: " + GenText.ToStringTemperature(levels.goodTemp) + " - " + GenText.ToStringTemperature(levels.okTemp));
            s.AppendLine("Too cold: >" + GenText.ToStringTemperature(levels.goodTemp));
            if (!comp.PropsTemp.okFrozen)
            {
                s.AppendLine();
                s.AppendLine("Eating this below " + GenText.ToStringTemperature(0) + " will cause significant mood penalties.");
            }
        }
예제 #2
0
        public override string GetStatDrawEntryLabel(StatDef stat, float value, ToStringNumberSense numberSense, StatRequest optionalReq, bool finalized = true)
        {
            if (!optionalReq.HasThing)
            {
                return("None");
            }
            CompDFoodTemperature comp = optionalReq.Thing.TryGetComp <CompDFoodTemperature>();

            if (comp != null)
            {
                return(comp.GetFoodType());
            }
            return("None");
        }
예제 #3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(this.ReserveFood());

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A));

            yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, this.pawn));

            Toil empty = new Toil();

            yield return(Toils_Jump.JumpIf(empty, delegate()
            {
                LocalTargetInfo food = this.job.GetTarget(TargetIndex.A);
                CompDFoodTemperature comp = food.Thing.TryGetComp <CompDFoodTemperature>();
                if (comp == null)
                {
                    return true;
                }
                if (comp.PropsTemp.likesHeat)
                {
                    return comp.curTemp >= comp.targetCookingTemp;
                }
                return comp.curTemp > 0;
            }));

            if (!HotMealsSettings.multipleHeat)
            {
                yield return(Toils_Reserve.Reserve(TargetIndex.C));

                yield return(Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.InteractionCell).FailOnDestroyedOrNull(TargetIndex.C));

                yield return(Toils_HeatMeal.HeatMeal().FailOnDespawnedNullOrForbiddenPlacedThings().FailOnCannotTouch(TargetIndex.C, PathEndMode.InteractionCell));

                yield return(Toils_Reserve.Release(TargetIndex.C));
            }
            else
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.Touch).FailOnDestroyedOrNull(TargetIndex.C));

                yield return(Toils_HeatMeal.HeatMeal().FailOnDespawnedNullOrForbiddenPlacedThings().FailOnCannotTouch(TargetIndex.C, PathEndMode.Touch));
            }
            yield return(empty);

            yield break;
        }
예제 #4
0
        public override string GetExplanationUnfinalized(StatRequest req, ToStringNumberSense numberSense)
        {
            StringBuilder s = new StringBuilder();

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

            if (comp != null)
            {
                if (comp.PropsTemp.mealType == MealTempTypes.HotMeal)
                {
                    s.AppendLine("Food meant to be eaten hot");
                    BuildHotString(comp, ref s);
                }
                else if (comp.PropsTemp.mealType == MealTempTypes.ColdMeal)
                {
                    s.AppendLine("Food meant to be eaten cold");
                    BuildColdString(comp, ref s);
                }
                else if (comp.PropsTemp.mealType == MealTempTypes.HotDrink)
                {
                    s.AppendLine("A drink that's meant to be served hot");
                    BuildHotString(comp, ref s);
                }
                else if (comp.PropsTemp.mealType == MealTempTypes.ColdDrink)
                {
                    s.AppendLine("A drink best served chilled, but not frozen");
                    BuildColdString(comp, ref s);
                }
                else if (comp.PropsTemp.mealType == MealTempTypes.RoomTempMeal)
                {
                    s.AppendLine("Food best served at room temperature - neither hot nor cold.");
                    BuildRTString(comp, ref s);
                }
                else if (comp.PropsTemp.mealType == MealTempTypes.RawResource)
                {
                    s.AppendLine("Resources meant to be cooked into something more edible.\nWill never make your colonists happy to eat, but will make them unhappy if they eat it frozen.");
                }
            }
            return(s.ToString());
        }
        public static void Postfix(Pawn pawn, TargetIndex ingestibleInd, Toil __result)
        {
            JobDriver_Ingest jdi = pawn.jobs.curDriver as JobDriver_Ingest;

            if (jdi == null)
            {
                return;
            }
            if (pawn.RaceProps.ToolUser)
            {
                LocalTargetInfo      food = jdi.job.GetTarget(ingestibleInd);
                CompDFoodTemperature comp = food.Thing.TryGetComp <CompDFoodTemperature>();
                if (comp != null &&
                    (comp.PropsTemp.likesHeat || (HotMealsSettings.thawIt && comp.curTemp < 0 && !comp.PropsTemp.okFrozen))
                    )
                {
                    Patch_PrepareToIngestToils_ToolUser_Postfix.carryToils.Add(__result);
                }
            }
        }
예제 #6
0
        public static IEnumerable <Toil> Heat(JobDriver jd, TargetIndex foodIndex = TargetIndex.A, TargetIndex finalLocation = TargetIndex.C, TargetIndex tableIndex = TargetIndex.None)
        {
            LocalTargetInfo oldFinal = jd.job.GetTarget(finalLocation);

            Toil empty = new Toil();

            yield return(Toils_Jump.JumpIf(empty, delegate()
            {
                Pawn actor = empty.actor;
                Job curJob = actor.jobs.curJob;
                LocalTargetInfo food = curJob.GetTarget(foodIndex).Thing;
                if (food.Thing == null)
                {
                    return true;
                }
                CompDFoodTemperature comp = food.Thing.TryGetComp <CompDFoodTemperature>();
                if (comp == null)
                {
                    return true;
                }
                if (comp.PropsTemp.likesHeat)
                {
                    return comp.curTemp >= comp.PropsTemp.tempLevels.goodTemp;
                }
                else if (HotMealsSettings.thawIt && !comp.PropsTemp.okFrozen)
                {
                    return comp.curTemp > 0;
                }
                return true;
            }));

            Toil getHeater = new Toil();

            getHeater.initAction = delegate()
            {
                Pawn  actor      = getHeater.actor;
                Job   curJob     = actor.jobs.curJob;
                Thing foodToHeat = curJob.GetTarget(foodIndex).Thing;
                Thing table      = null;
                if (tableIndex != TargetIndex.None)
                {
                    table = curJob.GetTarget(tableIndex).Thing;
                }
                Thing heater = Toils_HeatMeal.FindPlaceToHeatFood(foodToHeat, actor, searchNear: table);
                if (heater != null)
                {
                    curJob.SetTarget(finalLocation, heater);
                }
            };
            yield return(getHeater);

            yield return(Toils_Jump.JumpIf(empty, delegate()
            {
                Pawn actor = getHeater.actor;
                Job curJob = actor.jobs.curJob;
                Thing heater = curJob.GetTarget(finalLocation).Thing;
                return (heater == null);
            }));

            if (!HotMealsSettings.multipleHeat)
            {
                yield return(Toils_Reserve.Reserve(finalLocation));

                yield return(Toils_Goto.GotoThing(finalLocation, PathEndMode.InteractionCell));

                yield return(Toils_HeatMeal.HeatMeal(foodIndex, finalLocation).FailOnDespawnedNullOrForbiddenPlacedThings().FailOnCannotTouch(finalLocation, PathEndMode.InteractionCell));

                yield return(Toils_Reserve.Release(finalLocation));
            }
            else
            {
                yield return(Toils_Goto.GotoThing(finalLocation, PathEndMode.Touch));

                yield return(Toils_HeatMeal.HeatMeal(foodIndex, finalLocation).FailOnDespawnedNullOrForbiddenPlacedThings().FailOnCannotTouch(finalLocation, PathEndMode.Touch));
            }
            yield return(empty);

            if (oldFinal != LocalTargetInfo.Invalid)
            {
                Toil resetC = new Toil();
                resetC.initAction = delegate()
                {
                    Pawn actor  = resetC.actor;
                    Job  curJob = actor.jobs.curJob;
                    curJob.SetTarget(finalLocation, oldFinal);
                };
                yield return(resetC);
            }
        }
예제 #7
0
        public static Toil HeatMeal(TargetIndex foodIndex = TargetIndex.A, TargetIndex heaterIndex = TargetIndex.C)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn  actor  = toil.actor;
                Job   curJob = actor.jobs.curJob;
                Thing food   = curJob.GetTarget(foodIndex).Thing;
                CompDFoodTemperature comp = food.TryGetComp <CompDFoodTemperature>();
                if (comp == null)
                {
                    Log.Error("Tried to heat food with no temperatureingestible comp");
                    return;
                }
                Thing heater = curJob.GetTarget(heaterIndex).Thing;
                comp.initialHeatingTemp = comp.curTemp;
                comp.SetHeatUpRate(heater);
            };

            toil.tickAction = delegate()
            {
                Pawn  actor  = toil.actor;
                Job   curJob = actor.jobs.curJob;
                Thing food   = curJob.GetTarget(foodIndex).Thing;
                CompDFoodTemperature comp = food.TryGetComp <CompDFoodTemperature>();
                if (comp == null)
                {
                    Log.Error("Tried to heat food with no temperature ingestible comp");
                    actor.jobs.curDriver.ReadyForNextToil();
                    return;
                }

                if (comp.curTemp >= comp.targetCookingTemp)
                {
                    actor.jobs.curDriver.ReadyForNextToil();
                    return;
                }
                IBillGiverWithTickAction billGiverWithTickAction = toil.actor.CurJob.GetTarget(heaterIndex).Thing as IBillGiverWithTickAction;
                if (billGiverWithTickAction != null)
                {
                    billGiverWithTickAction.UsedThisTick();
                }
                actor.GainComfortFromCellIfPossible(true);
                comp.HeatUp();
            };
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            EffecterDef cook = DefDatabase <EffecterDef> .GetNamed("Cook");

            toil.WithEffect(() => cook, foodIndex);
            SoundDef cooking = DefDatabase <SoundDef> .GetNamed("Recipe_CookMeal");

            toil.PlaySustainerOrSound(() => cooking);
            toil.WithProgressBar(foodIndex, delegate
            {
                Pawn actor = toil.actor;
                Job curJob = actor.CurJob;
                Thing food = curJob.GetTarget(foodIndex).Thing;
                CompDFoodTemperature comp = food.TryGetComp <CompDFoodTemperature>();
                if (comp == null)
                {
                    return(1f);
                }
                double target   = comp.targetCookingTemp - comp.initialHeatingTemp;
                double progress = comp.curTemp - comp.initialHeatingTemp;
                return((float)(progress / target));
            }, false, -0.5f);
            toil.activeSkill = (() => SkillDefOf.Cooking);
            return(toil);
        }