Exemplo n.º 1
0
        // RimWorld.Planet.CaravanInventoryUtility
        public static bool TryGetBestFood(Pawn vehicle, Pawn forPawn, out Thing food, out Pawn owner)
        {
            var   list  = vehicle?.inventory?.innerContainer?.InnerListForReading;
            Thing thing = null;
            var   num   = 0f;

            for (var i = 0; i < list.Count; i++)
            {
                var thing2 = list[i];
                if (CanNowEatForNutrition(thing2, forPawn))
                {
                    var foodScore = CaravanPawnsNeedsUtility.GetFoodScore(thing2, forPawn);
                    if (thing == null || foodScore > num)
                    {
                        thing = thing2;
                        num   = foodScore;
                    }
                }
            }
            if (thing != null)
            {
                food  = thing;
                owner = forPawn; //CaravanInventoryUtility.GetOwnerOf(caravan, thing);
                return(true);
            }
            food  = null;
            owner = null;
            return(false);
        }
Exemplo n.º 2
0
        public float Ingested(Pawn ingester, float nutritionWanted)
        {
            if (this.Destroyed)
            {
                Log.Error(ingester + " ingested destroyed thing " + this);
                return(0f);
            }
            if (!this.IngestibleNow)
            {
                Log.Error(ingester + " ingested IngestibleNow=false thing " + this);
                return(0f);
            }
            ingester.mindState.lastIngestTick = Find.TickManager.TicksGame;
            if (this.def.ingestible.outcomeDoers != null)
            {
                for (int i = 0; i < this.def.ingestible.outcomeDoers.Count; i++)
                {
                    this.def.ingestible.outcomeDoers[i].DoIngestionOutcome(ingester, this);
                }
            }
            if (ingester.needs.mood != null)
            {
                List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(ingester, this, this.def);
                for (int j = 0; j < list.Count; j++)
                {
                    ingester.needs.mood.thoughts.memories.TryGainMemory(list[j], null);
                }
            }
            if (ingester.IsColonist && FoodUtility.IsHumanlikeMeatOrHumanlikeCorpse(this))
            {
                TaleRecorder.RecordTale(TaleDefOf.AteRawHumanlikeMeat, ingester);
            }
            int   num    = default(int);
            float result = default(float);

            this.IngestedCalculateAmounts(ingester, nutritionWanted, out num, out result);
            if (!ingester.Dead && ingester.needs.joy != null && Mathf.Abs(this.def.ingestible.joy) > 9.9999997473787516E-05 && num > 0)
            {
                JoyKindDef joyKind = (this.def.ingestible.joyKind == null) ? JoyKindDefOf.Gluttonous : this.def.ingestible.joyKind;
                ingester.needs.joy.GainJoy((float)num * this.def.ingestible.joy, joyKind);
            }
            if (ingester.IsCaravanMember())
            {
                CaravanPawnsNeedsUtility.Notify_CaravanMemberIngestedFood(ingester, this.def);
            }
            if (num > 0)
            {
                if (num == this.stackCount)
                {
                    this.Destroy(DestroyMode.Vanish);
                }
                else
                {
                    this.SplitOff(num);
                }
            }
            this.PostIngested(ingester);
            return(result);
        }
Exemplo n.º 3
0
        public bool AnyPawnOutOfFood(out string malnutritionHediff)
        {
            tmpInvFood.Clear();
            List <Thing> list = CaravanInventoryUtility.AllInventoryItems(caravan);

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].def.IsNutritionGivingIngestible)
                {
                    tmpInvFood.Add(list[i]);
                }
            }
            List <Pawn> pawnsListForReading = caravan.PawnsListForReading;

            for (int j = 0; j < pawnsListForReading.Count; j++)
            {
                Pawn pawn = pawnsListForReading[j];
                if (!pawn.RaceProps.EatsFood || VirtualPlantsUtility.CanEatVirtualPlantsNow(pawn))
                {
                    continue;
                }
                bool flag = false;
                for (int k = 0; k < tmpInvFood.Count; k++)
                {
                    if (CaravanPawnsNeedsUtility.CanEatForNutritionEver(tmpInvFood[k].def, pawn))
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag)
                {
                    continue;
                }
                int    num  = -1;
                string text = null;
                for (int l = 0; l < pawnsListForReading.Count; l++)
                {
                    Hediff firstHediffOfDef = pawnsListForReading[l].health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition);
                    if (firstHediffOfDef != null && (text == null || firstHediffOfDef.CurStageIndex > num))
                    {
                        num  = firstHediffOfDef.CurStageIndex;
                        text = firstHediffOfDef.LabelCap;
                    }
                }
                malnutritionHediff = text;
                tmpInvFood.Clear();
                return(true);
            }
            malnutritionHediff = null;
            tmpInvFood.Clear();
            return(false);
        }
Exemplo n.º 4
0
        private float GetFoodScore(Pawn pawn, Thing food, List <Pair <int, int> > ticksToArrive)
        {
            if (!CaravanPawnsNeedsUtility.CanEatForNutritionEver(food.def, pawn) || !food.def.ingestible.canAutoSelectAsFoodForCaravan)
            {
                return(0f);
            }
            float        num          = CaravanPawnsNeedsUtility.GetFoodScore(food.def, pawn, food.GetStatValue(StatDefOf.Nutrition));
            CompRottable compRottable = food.TryGetComp <CompRottable>();

            if (compRottable != null && compRottable.Active && DaysUntilRotCalculator.ApproxTicksUntilRot_AssumeTimePassesBy(compRottable, CurrentTile, ticksToArrive) < ticksToArrive.Last().Second)
            {
                num *= 0.1f;
            }
            return(num);
        }
Exemplo n.º 5
0
        public override string GetTipString()
        {
            string text  = base.GetTipString();
            string text2 = this.tolerances.TolerancesString();

            if (!string.IsNullOrEmpty(text2))
            {
                text = text + "\n\n" + text2;
            }
            Map mapHeld = this.pawn.MapHeld;

            if (mapHeld != null)
            {
                ExpectationDef expectationDef = ExpectationsUtility.CurrentExpectationFor(this.pawn);
                text = text + "\n\n" + "CurrentExpectationsAndRecreation".Translate(new object[]
                {
                    expectationDef.label,
                    expectationDef.joyToleranceDropPerDay.ToStringPercent(),
                    expectationDef.joyKindsNeeded
                });
                text = text + "\n\n" + JoyUtility.JoyKindsOnMapString(this.pawn.MapHeld);
            }
            else
            {
                Caravan caravan = this.pawn.GetCaravan();
                if (caravan != null)
                {
                    float num = CaravanPawnsNeedsUtility.GetCurrentJoyGainPerTick(this.pawn, caravan) * 2500f;
                    if (num > 0f)
                    {
                        string text3 = text;
                        text = string.Concat(new string[]
                        {
                            text3,
                            "\n\n",
                            "GainingJoyBecauseCaravanNotMoving".Translate(),
                            ": +",
                            num.ToStringPercent(),
                            "/",
                            "LetterHour".Translate()
                        });
                    }
                }
            }
            return(text);
        }
Exemplo n.º 6
0
        // RimWorld.Planet.CaravanInventoryUtility
        public static bool _TryGetBestFood(Caravan caravan, Pawn forPawn, out Thing food, out Pawn owner)
        {
            List <Thing> list = RimWorld.Planet.CaravanInventoryUtility.AllInventoryItems(caravan)
                                .Where(arg => CaravanPawnsNeedsUtility.CanNowEatForNutrition(arg.def, forPawn)).ToList();
            Thing thing = null;

            Policy policy       = forPawn.GetPolicyAssignedTo();
            var    foodsForPawn = FoodUtility.MakeRatedFoodListFromThingList(list, forPawn, forPawn, forPawn.GetPolicyAssignedTo())
                                  .Where(arg => RimWorld.Planet.CaravanPawnsNeedsUtility.CanNowEatForNutrition(arg.FoodSource.def, forPawn) &&
                                         policy.PolicyAllows(forPawn, arg.FoodSource)
                                         );

            var foodEntry = foodsForPawn.FirstOrDefault();

            if (foodEntry != null)
            {
                thing = foodsForPawn.FirstOrDefault().FoodSource;
            }
            else
            {
                thing = null;
            }

            if (thing != null)
            {
#if DEBUG
                Log.Message("Caravan: best food for " + forPawn + " = " + thing);
#endif
                food  = thing;
                owner = RimWorld.Planet.CaravanInventoryUtility.GetOwnerOf(caravan, thing);
                return(true);
            }
#if DEBUG
            Log.Message("Caravan: no food found for " + forPawn);
#endif
            food  = null;
            owner = null;
            return(false);
        }
Exemplo n.º 7
0
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (this.Resting)
            {
                stringBuilder.Append("CaravanResting".Translate());
            }
            else if (this.AnyPawnHasExtremeMentalBreak)
            {
                stringBuilder.Append("CaravanMemberMentalBreak".Translate(new object[]
                {
                    this.FirstPawnWithExtremeMentalBreak.LabelShort
                }));
            }
            else if (this.AllOwnersDowned)
            {
                stringBuilder.Append("AllCaravanMembersDowned".Translate());
            }
            else if (this.pather.Moving)
            {
                if (this.pather.arrivalAction != null)
                {
                    stringBuilder.Append(this.pather.arrivalAction.ReportString);
                }
                else
                {
                    stringBuilder.Append("CaravanTraveling".Translate());
                }
            }
            else
            {
                FactionBase factionBase = CaravanVisitUtility.FactionBaseVisitedNow(this);
                if (factionBase != null)
                {
                    stringBuilder.Append("CaravanVisiting".Translate(new object[]
                    {
                        factionBase.Label
                    }));
                }
                else
                {
                    stringBuilder.Append("CaravanWaiting".Translate());
                }
            }
            if (this.pather.Moving)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanEstimatedTimeToDestination".Translate(new object[]
                {
                    CaravanArrivalTimeEstimator.EstimatedTicksToArrive(this, true).ToStringTicksToPeriod(true)
                }));
            }
            if (this.ImmobilizedByMass)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanImmobilizedByMass".Translate());
            }
            string text;

            if (CaravanPawnsNeedsUtility.AnyPawnOutOfFood(this, out text))
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanOutOfFood".Translate());
                if (!text.NullOrEmpty())
                {
                    stringBuilder.Append(" ");
                    stringBuilder.Append(text);
                    stringBuilder.Append(".");
                }
            }
            else
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanDaysOfFood".Translate(new object[]
                {
                    this.DaysWorthOfFood.ToString("0.#")
                }));
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine(string.Concat(new string[]
            {
                "CaravanBaseMovementTime".Translate(),
                ": ",
                ((float)this.TicksPerMove / 2500f).ToString("0.##"),
                " ",
                "CaravanHoursPerTile".Translate()
            }));

            double actualTicksPerMove = ((double)this.TicksPerMove / 2500f) * (2500f + WorldPathGrid.CalculatedCostAt(base.Tile, false, -1f));

            stringBuilder.Append("CurrentTileMovementTime".Translate() + ": " + ((int)actualTicksPerMove).ToStringTicksToPeriod(true));
            return(stringBuilder.ToString());
        }