Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Thing BestFoodSourceOnMap(Pawn getter, Pawn eater, bool desperate, out ThingDef foodDef, FoodPreferability maxPref = FoodPreferability.MealLavish, bool allowPlant = true, bool allowDrug = true, bool allowCorpse = true, bool allowDispenserFull = true, bool allowDispenserEmpty = true, bool allowForbidden = false, bool allowSociallyImproper = false, bool allowHarvest = false, bool forceScanWholeMap = false)
- {
- FoodUtility.<BestFoodSourceOnMap>c__AnonStorey0 <BestFoodSourceOnMap>c__AnonStorey = new FoodUtility.<BestFoodSourceOnMap>c__AnonStorey0();
- <BestFoodSourceOnMap>c__AnonStorey.allowDispenserFull = allowDispenserFull;
- <BestFoodSourceOnMap>c__AnonStorey.maxPref = maxPref;
- <BestFoodSourceOnMap>c__AnonStorey.eater = eater;
- <BestFoodSourceOnMap>c__AnonStorey.getter = getter;
- <BestFoodSourceOnMap>c__AnonStorey.allowForbidden = allowForbidden;
- <BestFoodSourceOnMap>c__AnonStorey.allowDispenserEmpty = allowDispenserEmpty;
- <BestFoodSourceOnMap>c__AnonStorey.allowSociallyImproper = allowSociallyImproper;
- <BestFoodSourceOnMap>c__AnonStorey.allowCorpse = allowCorpse;
- <BestFoodSourceOnMap>c__AnonStorey.allowDrug = allowDrug;
- <BestFoodSourceOnMap>c__AnonStorey.desperate = desperate;
- <BestFoodSourceOnMap>c__AnonStorey.forceScanWholeMap = forceScanWholeMap;
- foodDef = null;
- <BestFoodSourceOnMap>c__AnonStorey.getterCanManipulate = (<BestFoodSourceOnMap>c__AnonStorey.getter.RaceProps.ToolUser && <BestFoodSourceOnMap>c__AnonStorey.getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation));
- if (!<BestFoodSourceOnMap>c__AnonStorey.getterCanManipulate && <BestFoodSourceOnMap>c__AnonStorey.getter != <BestFoodSourceOnMap>c__AnonStorey.eater)
- {
- Log.Error(string.Concat(new object[]
- {
- <BestFoodSourceOnMap>c__AnonStorey.getter,
- " tried to find food to bring to ",
- <BestFoodSourceOnMap>c__AnonStorey.eater,
- " but ",
- <BestFoodSourceOnMap>c__AnonStorey.getter,
- " is incapable of Manipulation."
- }), false);
- return null;
- }
- if (<BestFoodSourceOnMap>c__AnonStorey.eater.NonHumanlikeOrWildMan())
- {
- <BestFoodSourceOnMap>c__AnonStorey.minPref = FoodPreferability.NeverForNutrition;
- }
- else if (<BestFoodSourceOnMap>c__AnonStorey.desperate)
- {
- <BestFoodSourceOnMap>c__AnonStorey.minPref = FoodPreferability.DesperateOnly;
- }
- else
- {
- <BestFoodSourceOnMap>c__AnonStorey.minPref = ((<BestFoodSourceOnMap>c__AnonStorey.eater.needs.food.CurCategory < HungerCategory.UrgentlyHungry) ? FoodPreferability.MealAwful : FoodPreferability.RawBad);
- }
- <BestFoodSourceOnMap>c__AnonStorey.foodValidator = delegate(Thing t)
- {
- Building_NutrientPasteDispenser building_NutrientPasteDispenser = t as Building_NutrientPasteDispenser;
- if (building_NutrientPasteDispenser != null)
- {
- if (!<BestFoodSourceOnMap>c__AnonStorey.allowDispenserFull || !<BestFoodSourceOnMap>c__AnonStorey.getterCanManipulate || ThingDefOf.MealNutrientPaste.ingestible.preferability < <BestFoodSourceOnMap>c__AnonStorey.minPref || ThingDefOf.MealNutrientPaste.ingestible.preferability > <BestFoodSourceOnMap>c__AnonStorey.maxPref || !<BestFoodSourceOnMap>c__AnonStorey.eater.WillEat(ThingDefOf.MealNutrientPaste, <BestFoodSourceOnMap>c__AnonStorey.getter) || (t.Faction != <BestFoodSourceOnMap>c__AnonStorey.getter.Faction && t.Faction != <BestFoodSourceOnMap>c__AnonStorey.getter.HostFaction) || (!<BestFoodSourceOnMap>c__AnonStorey.allowForbidden && t.IsForbidden(<BestFoodSourceOnMap>c__AnonStorey.getter)) || (!building_NutrientPasteDispenser.powerComp.PowerOn || (!<BestFoodSourceOnMap>c__AnonStorey.allowDispenserEmpty && !building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers())) || !t.InteractionCell.Standable(t.Map) || !FoodUtility.IsFoodSourceOnMapSociallyProper(t, <BestFoodSourceOnMap>c__AnonStorey.getter, <BestFoodSourceOnMap>c__AnonStorey.eater, <BestFoodSourceOnMap>c__AnonStorey.allowSociallyImproper) || <BestFoodSourceOnMap>c__AnonStorey.getter.IsWildMan() || !<BestFoodSourceOnMap>c__AnonStorey.getter.Map.reachability.CanReachNonLocal(<BestFoodSourceOnMap>c__AnonStorey.getter.Position, new TargetInfo(t.InteractionCell, t.Map, false), PathEndMode.OnCell, TraverseParms.For(<BestFoodSourceOnMap>c__AnonStorey.getter, Danger.Some, TraverseMode.ByPawn, false)))
- {
- return false;
- }
- }
- else if (t.def.ingestible.preferability < <BestFoodSourceOnMap>c__AnonStorey.minPref || t.def.ingestible.preferability > <BestFoodSourceOnMap>c__AnonStorey.maxPref || !<BestFoodSourceOnMap>c__AnonStorey.eater.WillEat(t, <BestFoodSourceOnMap>c__AnonStorey.getter) || !t.def.IsNutritionGivingIngestible || !t.IngestibleNow || (!<BestFoodSourceOnMap>c__AnonStorey.allowCorpse && t is Corpse) || (!<BestFoodSourceOnMap>c__AnonStorey.allowDrug && t.def.IsDrug) || (!<BestFoodSourceOnMap>c__AnonStorey.allowForbidden && t.IsForbidden(<BestFoodSourceOnMap>c__AnonStorey.getter)) || (!<BestFoodSourceOnMap>c__AnonStorey.desperate && t.IsNotFresh()) || (t.IsDessicated() || !FoodUtility.IsFoodSourceOnMapSociallyProper(t, <BestFoodSourceOnMap>c__AnonStorey.getter, <BestFoodSourceOnMap>c__AnonStorey.eater, <BestFoodSourceOnMap>c__AnonStorey.allowSociallyImproper) || (!<BestFoodSourceOnMap>c__AnonStorey.getter.AnimalAwareOf(t) && !<BestFoodSourceOnMap>c__AnonStorey.forceScanWholeMap)) || !<BestFoodSourceOnMap>c__AnonStorey.getter.CanReserve(t, 1, -1, null, false))
- {
- return false;
- }
- return true;
- };
- ThingRequest thingRequest;
- if ((<BestFoodSourceOnMap>c__AnonStorey.eater.RaceProps.foodType & (FoodTypeFlags.Plant | FoodTypeFlags.Tree)) != FoodTypeFlags.None && allowPlant)
- {
- thingRequest = ThingRequest.ForGroup(ThingRequestGroup.FoodSource);
- }
- else
- {
- thingRequest = ThingRequest.ForGroup(ThingRequestGroup.FoodSourceNotPlantOrTree);
- }
- if (<BestFoodSourceOnMap>c__AnonStorey.getter.RaceProps.Humanlike)
- {
- FoodUtility.<BestFoodSourceOnMap>c__AnonStorey0 <BestFoodSourceOnMap>c__AnonStorey2 = <BestFoodSourceOnMap>c__AnonStorey;
- Pawn eater2 = <BestFoodSourceOnMap>c__AnonStorey.eater;
- IntVec3 position = <BestFoodSourceOnMap>c__AnonStorey.getter.Position;
- List<Thing> searchSet = <BestFoodSourceOnMap>c__AnonStorey.getter.Map.listerThings.ThingsMatching(thingRequest);
- PathEndMode peMode = PathEndMode.ClosestTouch;
- TraverseParms traverseParams = TraverseParms.For(<BestFoodSourceOnMap>c__AnonStorey.getter, Danger.Deadly, TraverseMode.ByPawn, false);
- Predicate<Thing> validator = <BestFoodSourceOnMap>c__AnonStorey.foodValidator;
- <BestFoodSourceOnMap>c__AnonStorey2.bestThing = FoodUtility.SpawnedFoodSearchInnerScan(eater2, position, searchSet, peMode, traverseParams, 9999f, validator);
- if (allowHarvest && <BestFoodSourceOnMap>c__AnonStorey.getterCanManipulate)
- {
- int searchRegionsMax;
- if (<BestFoodSourceOnMap>c__AnonStorey.forceScanWholeMap && <BestFoodSourceOnMap>c__AnonStorey.bestThing == null)
- {
- searchRegionsMax = -1;
- }
- else
- {
- searchRegionsMax = 30;
- }
- Thing thing = GenClosest.ClosestThingReachable(<BestFoodSourceOnMap>c__AnonStorey.getter.Position, <BestFoodSourceOnMap>c__AnonStorey.getter.Map, ThingRequest.ForGroup(ThingRequestGroup.HarvestablePlant), PathEndMode.Touch, TraverseParms.For(<BestFoodSourceOnMap>c__AnonStorey.getter, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, delegate(Thing x)
- {
- Plant plant = (Plant)x;
- if (!plant.HarvestableNow)
- {
- return false;
- }
- ThingDef harvestedThingDef = plant.def.plant.harvestedThingDef;
- return harvestedThingDef.IsNutritionGivingIngestible && <BestFoodSourceOnMap>c__AnonStorey.eater.WillEat(harvestedThingDef, <BestFoodSourceOnMap>c__AnonStorey.getter) && <BestFoodSourceOnMap>c__AnonStorey.getter.CanReserve(plant, 1, -1, null, false) && (<BestFoodSourceOnMap>c__AnonStorey.allowForbidden || !plant.IsForbidden(<BestFoodSourceOnMap>c__AnonStorey.getter)) && (<BestFoodSourceOnMap>c__AnonStorey.bestThing == null || FoodUtility.GetFinalIngestibleDef(<BestFoodSourceOnMap>c__AnonStorey.bestThing, false).ingestible.preferability < harvestedThingDef.ingestible.preferability);
- }, null, 0, searchRegionsMax, false, RegionType.Set_Passable, false);
- if (thing != null)
- {
- <BestFoodSourceOnMap>c__AnonStorey.bestThing = thing;
- foodDef = FoodUtility.GetFinalIngestibleDef(thing, true);
- }
- }
- if (foodDef == null && <BestFoodSourceOnMap>c__AnonStorey.bestThing != null)
- {
- foodDef = FoodUtility.GetFinalIngestibleDef(<BestFoodSourceOnMap>c__AnonStorey.bestThing, false);
- }
- }
- else
- {
- int maxRegionsToScan = FoodUtility.GetMaxRegionsToScan(<BestFoodSourceOnMap>c__AnonStorey.getter, <BestFoodSourceOnMap>c__AnonStorey.forceScanWholeMap);
- FoodUtility.filtered.Clear();
- foreach (Thing thing2 in GenRadial.RadialDistinctThingsAround(<BestFoodSourceOnMap>c__AnonStorey.getter.Position, <BestFoodSourceOnMap>c__AnonStorey.getter.Map, 2f, true))
- {
- Pawn pawn = thing2 as Pawn;
- if (pawn != null && pawn != <BestFoodSourceOnMap>c__AnonStorey.getter && pawn.RaceProps.Animal && pawn.CurJob != null && pawn.CurJob.def == JobDefOf.Ingest && pawn.CurJob.GetTarget(TargetIndex.A).HasThing)
- {
- FoodUtility.filtered.Add(pawn.CurJob.GetTarget(TargetIndex.A).Thing);
- }
- }
- bool flag = !<BestFoodSourceOnMap>c__AnonStorey.allowForbidden && ForbidUtility.CaresAboutForbidden(<BestFoodSourceOnMap>c__AnonStorey.getter, true) && <BestFoodSourceOnMap>c__AnonStorey.getter.playerSettings != null && <BestFoodSourceOnMap>c__AnonStorey.getter.playerSettings.EffectiveAreaRestrictionInPawnCurrentMap != null;
- Predicate<Thing> predicate = (Thing t) => <BestFoodSourceOnMap>c__AnonStorey.foodValidator(t) && !FoodUtility.filtered.Contains(t) && (t is Building_NutrientPasteDispenser || t.def.ingestible.preferability > FoodPreferability.DesperateOnly) && !t.IsNotFresh();
- FoodUtility.<BestFoodSourceOnMap>c__AnonStorey0 <BestFoodSourceOnMap>c__AnonStorey3 = <BestFoodSourceOnMap>c__AnonStorey;
- IntVec3 position = <BestFoodSourceOnMap>c__AnonStorey.getter.Position;
- Map map = <BestFoodSourceOnMap>c__AnonStorey.getter.Map;
- ThingRequest thingReq = thingRequest;
- PathEndMode peMode = PathEndMode.ClosestTouch;
- TraverseParms traverseParams = TraverseParms.For(<BestFoodSourceOnMap>c__AnonStorey.getter, Danger.Deadly, TraverseMode.ByPawn, false);
- Predicate<Thing> validator = predicate;
- bool ignoreEntirelyForbiddenRegions = flag;
- <BestFoodSourceOnMap>c__AnonStorey3.bestThing = GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, maxRegionsToScan, false, RegionType.Set_Passable, ignoreEntirelyForbiddenRegions);
- FoodUtility.filtered.Clear();
- if (<BestFoodSourceOnMap>c__AnonStorey.bestThing == null)
- {
- <BestFoodSourceOnMap>c__AnonStorey.desperate = true;
- FoodUtility.<BestFoodSourceOnMap>c__AnonStorey0 <BestFoodSourceOnMap>c__AnonStorey4 = <BestFoodSourceOnMap>c__AnonStorey;
- position = <BestFoodSourceOnMap>c__AnonStorey.getter.Position;
- map = <BestFoodSourceOnMap>c__AnonStorey.getter.Map;
- thingReq = thingRequest;
- peMode = PathEndMode.ClosestTouch;
- traverseParams = TraverseParms.For(<BestFoodSourceOnMap>c__AnonStorey.getter, Danger.Deadly, TraverseMode.ByPawn, false);
- validator = <BestFoodSourceOnMap>c__AnonStorey.foodValidator;
- ignoreEntirelyForbiddenRegions = flag;
- <BestFoodSourceOnMap>c__AnonStorey4.bestThing = GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, maxRegionsToScan, false, RegionType.Set_Passable, ignoreEntirelyForbiddenRegions);
- }
- if (<BestFoodSourceOnMap>c__AnonStorey.bestThing != null)
- {
- foodDef = FoodUtility.GetFinalIngestibleDef(<BestFoodSourceOnMap>c__AnonStorey.bestThing, false);
- }
- }
- return <BestFoodSourceOnMap>c__AnonStorey.bestThing;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement