protected Job TakeFoodForAnimalInteractJob(Pawn pawn, Pawn tamee) { float num = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f; ThingDef thingDef; Thing thing = FoodUtility.BestFoodSourceOnMap(pawn, tamee, false, out thingDef, FoodPreferability.RawTasty, false, false, false, false, false, false, false, false); if (thing == null) { return(null); } return(new Job(JobDefOf.TakeInventory, thing) { count = Mathf.CeilToInt(num / thingDef.ingestible.nutrition) }); }
protected Job TakeFoodForAnimalInteractJob(Pawn pawn, Pawn tamee) { float num = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f; ThingDef foodDef; Thing thing = FoodUtility.BestFoodSourceOnMap(pawn, tamee, desperate: false, out foodDef, FoodPreferability.RawTasty, allowPlant: false, allowDrug: false, allowCorpse: false, allowDispenserFull: false, allowDispenserEmpty: false); if (thing == null) { return(null); } float nutrition = FoodUtility.GetNutrition(thing, foodDef); Job job = new Job(JobDefOf.TakeInventory, thing); job.count = Mathf.CeilToInt(num / nutrition); return(job); }
protected Job TakeFoodForAnimalInteractJob(Pawn pawn, Pawn tamee) { float num = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f; ThingDef foodDef; Thing thing = FoodUtility.BestFoodSourceOnMap(pawn, tamee, false, out foodDef, FoodPreferability.RawTasty, false, false, false, false, false, false, false, false, false); Job result; if (thing == null) { result = null; } else { float nutrition = FoodUtility.GetNutrition(thing, foodDef); result = new Job(JobDefOf.TakeInventory, thing) { count = Mathf.CeilToInt(num / nutrition) }; } return(result); }
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); }
protected override Job TryGiveJob(Pawn pawn) { Need_Food food = pawn.needs.food; if (food == null || food.CurCategory < this.minCategory) { return(null); } bool flag; if (pawn.AnimalOrWildMan()) { flag = true; } else { Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition, false); flag = (firstHediffOfDef != null && firstHediffOfDef.Severity > 0.4f); } bool flag2 = pawn.needs.food.CurCategory == HungerCategory.Starving; bool desperate = flag2; bool canRefillDispenser = true; bool canUseInventory = true; bool allowCorpse = flag; bool flag3 = this.forceScanWholeMap; Thing thing; ThingDef thingDef; if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out thing, out thingDef, canRefillDispenser, canUseInventory, false, allowCorpse, false, pawn.IsWildMan(), flag3)) { return(null); } Pawn pawn2 = thing as Pawn; if (pawn2 != null) { return(new Job(JobDefOf.PredatorHunt, pawn2) { killIncappedTarget = true }); } if (thing is Plant && thing.def.plant.harvestedThingDef == thingDef) { return(new Job(JobDefOf.Harvest, thing)); } Building_NutrientPasteDispenser building_NutrientPasteDispenser = thing as Building_NutrientPasteDispenser; if (building_NutrientPasteDispenser != null && !building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers()) { Building building = building_NutrientPasteDispenser.AdjacentReachableHopper(pawn); if (building != null) { ISlotGroupParent hopperSgp = building as ISlotGroupParent; Job job = WorkGiver_CookFillHopper.HopperFillFoodJob(pawn, hopperSgp); if (job != null) { return(job); } } thing = FoodUtility.BestFoodSourceOnMap(pawn, pawn, flag2, out thingDef, FoodPreferability.MealLavish, false, !pawn.IsTeetotaler(), false, false, false, false, false, false, this.forceScanWholeMap); if (thing == null) { return(null); } } float nutrition = FoodUtility.GetNutrition(thing, thingDef); return(new Job(JobDefOf.Ingest, thing) { count = FoodUtility.WillIngestStackCountOf(pawn, thingDef, nutrition) }); }
protected override Job TryGiveJob(Pawn pawn) { Need_Food food = pawn.needs.food; if (food == null || (int)food.CurCategory < (int)minCategory) { return(null); } bool flag; if (pawn.AnimalOrWildMan()) { flag = true; } else { Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition); flag = (firstHediffOfDef != null && firstHediffOfDef.Severity > 0.4f); } bool flag2 = pawn.needs.food.CurCategory == HungerCategory.Starving; bool desperate = flag2; bool canRefillDispenser = true; bool canUseInventory = true; bool allowCorpse = flag; bool flag3 = forceScanWholeMap; Thing foodSource = default(Thing); ThingDef foodDef = default(ThingDef); if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out foodSource, out foodDef, canRefillDispenser, canUseInventory, allowForbidden: false, allowCorpse, allowSociallyImproper: false, pawn.IsWildMan(), flag3)) { return(null); } Pawn pawn2 = foodSource as Pawn; if (pawn2 != null) { Job job = new Job(JobDefOf.PredatorHunt, pawn2); job.killIncappedTarget = true; return(job); } if (foodSource is Plant && foodSource.def.plant.harvestedThingDef == foodDef) { return(new Job(JobDefOf.Harvest, foodSource)); } Building_NutrientPasteDispenser building_NutrientPasteDispenser = foodSource as Building_NutrientPasteDispenser; if (building_NutrientPasteDispenser != null && !building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers()) { Building building = building_NutrientPasteDispenser.AdjacentReachableHopper(pawn); if (building != null) { ISlotGroupParent hopperSgp = building as ISlotGroupParent; Job job2 = WorkGiver_CookFillHopper.HopperFillFoodJob(pawn, hopperSgp); if (job2 != null) { return(job2); } } foodSource = FoodUtility.BestFoodSourceOnMap(pawn, pawn, flag2, out foodDef, FoodPreferability.MealLavish, allowPlant: false, !pawn.IsTeetotaler(), allowCorpse: false, allowDispenserFull: false, allowDispenserEmpty: false, allowForbidden: false, allowSociallyImproper: false, allowHarvest: false, forceScanWholeMap); if (foodSource == null) { return(null); } } float nutrition = FoodUtility.GetNutrition(foodSource, foodDef); Job job3 = new Job(JobDefOf.Ingest, foodSource); job3.count = FoodUtility.WillIngestStackCountOf(pawn, foodDef, nutrition); return(job3); }