// 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); }
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); }