internal static Job _TryGiveTerminalJob(this JobGiver_GetFood obj, Pawn pawn) { Thing foodInInventory = null; if (pawn.RaceProps.ToolUser) { foodInInventory = FoodUtility.FoodInInventory(pawn, (Pawn)null, FoodPreferability.Awful, FoodPreferability.Lavish, 0.0f); if (foodInInventory != null) { if (pawn.Faction != Faction.OfColony) { return(obj.IngestJob(pawn, foodInInventory)); } var comp = foodInInventory.TryGetComp <CompRottable>(); if ( (comp != null) && (comp.TicksUntilRotAtCurrentTemp < 30000) ) { return(obj.IngestJob(pawn, foodInInventory)); } } } ThingDef foodDef; var bestFoodSource = FoodUtility.BestFoodSourceFor(pawn, pawn, false, out foodDef); if ( (foodInInventory != null) && ( (bestFoodSource == null) || (!pawn.Position.InHorDistOf(bestFoodSource.Position, 50f))) ) { return(obj.IngestJob(pawn, foodInInventory)); } if (bestFoodSource == null) { return((Job)null); } if (bestFoodSource is Building) { Building hopper = null; bool needsFilling = false; if ( (bestFoodSource is Building_NutrientPasteDispenser) && (!((Building_NutrientPasteDispenser)bestFoodSource).HasEnoughFeedstockInHoppers()) ) { hopper = ((Building_NutrientPasteDispenser)bestFoodSource).AdjacentReachableHopper(pawn); needsFilling = true; } else if ( (bestFoodSource is Building_AutomatedFactory) && (((Building_AutomatedFactory)bestFoodSource).BestProduct(FoodSynthesis.IsMeal, FoodSynthesis.SortMeal) == null) ) { hopper = ((Building_AutomatedFactory)bestFoodSource).AdjacentReachableHopper(pawn); needsFilling = true; } if (needsFilling) { if (hopper == null) { bestFoodSource = FoodUtility.BestFoodSpawnedFor(pawn, pawn, true, FoodPreferability.Lavish, true); if (bestFoodSource == null) { return((Job)null); } } else { var hopperSgp = hopper as ISlotGroupParent; var job = HopperFillFoodJob(pawn, hopperSgp, bestFoodSource); if (job != null) { return(job); } bestFoodSource = FoodUtility.BestFoodSpawnedFor(pawn, pawn, true, FoodPreferability.Lavish, true); if (bestFoodSource == null) { return((Job)null); } foodDef = bestFoodSource.def; } } } var prey = bestFoodSource as Pawn; if (prey != null) { var predatorHunt = new Job(JobDefOf.PredatorHunt, prey); predatorHunt.killIncappedTarget = true; return(predatorHunt); } var ingestJob = new Job(JobDefOf.Ingest, bestFoodSource); ingestJob.maxNumToCarry = FoodUtility.WillEatStackCountOf(pawn, foodDef); return(ingestJob); }