public static void DebugDrawPredatorFoodSource() { Pawn pawn = Find.Selector.SingleSelectedThing as Pawn; Thing thing = default(Thing); ThingDef thingDef = default(ThingDef); if (pawn != null && FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, true, out thing, out thingDef, false, false, false, true, false, false)) { GenDraw.DrawLineBetween(pawn.Position.ToVector3Shifted(), thing.Position.ToVector3Shifted()); if (!(thing is Pawn)) { Pawn pawn2 = FoodUtility.BestPawnToHuntForPredator(pawn); if (pawn2 != null) { GenDraw.DrawLineBetween(pawn.Position.ToVector3Shifted(), pawn2.Position.ToVector3Shifted()); } } } }
public static bool TryFindBestFoodSourceFor(Pawn getter, Pawn eater, bool desperate, out Thing foodSource, out ThingDef foodDef, bool canRefillDispenser = true, bool canUseInventory = true, bool allowForbidden = false, bool allowCorpse = true, bool allowSociallyImproper = false, bool allowHarvest = false) { bool flag = getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation); bool allowDrug = !eater.IsTeetotaler(); Thing thing = null; if (canUseInventory) { if (flag) { thing = FoodUtility.BestFoodInInventory(getter, null, FoodPreferability.MealAwful, FoodPreferability.MealLavish, 0f, false); } if (thing != null) { if (getter.Faction != Faction.OfPlayer) { foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); } CompRottable compRottable = thing.TryGetComp <CompRottable>(); if (compRottable != null && compRottable.Stage == RotStage.Fresh && compRottable.TicksUntilRotAtCurrentTemp < 30000) { foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); } } } bool allowPlant = getter == eater; ThingDef thingDef = default(ThingDef); Thing thing2 = FoodUtility.BestFoodSourceOnMap(getter, eater, desperate, out thingDef, FoodPreferability.MealLavish, allowPlant, allowDrug, allowCorpse, true, canRefillDispenser, allowForbidden, allowSociallyImproper, allowHarvest); if (thing == null && thing2 == null) { if (canUseInventory && flag) { thing = FoodUtility.BestFoodInInventory(getter, null, FoodPreferability.DesperateOnly, FoodPreferability.MealLavish, 0f, allowDrug); if (thing != null) { foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); } } if (thing2 == null && getter == eater && (getter.RaceProps.predator || getter.IsWildMan())) { Pawn pawn = FoodUtility.BestPawnToHuntForPredator(getter); if (pawn != null) { foodSource = pawn; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); } } foodSource = null; foodDef = null; return(false); } if (thing == null && thing2 != null) { foodSource = thing2; foodDef = thingDef; return(true); } ThingDef finalIngestibleDef = FoodUtility.GetFinalIngestibleDef(thing, false); if (thing2 == null) { foodSource = thing; foodDef = finalIngestibleDef; return(true); } float num = FoodUtility.FoodOptimality(eater, thing2, thingDef, (float)(getter.Position - thing2.Position).LengthManhattan, false); float num2 = FoodUtility.FoodOptimality(eater, thing, finalIngestibleDef, 0f, false); num2 = (float)(num2 - 32.0); if (num > num2) { foodSource = thing2; foodDef = thingDef; return(true); } foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); }