Advertisement
Mehni

FoodUtility.BestFoodSourceOnMapDNSpy.cs

Dec 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.86 KB | None | 0 0
  1.         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)
  2.         {
  3.             FoodUtility.<BestFoodSourceOnMap>c__AnonStorey0 <BestFoodSourceOnMap>c__AnonStorey = new FoodUtility.<BestFoodSourceOnMap>c__AnonStorey0();
  4.             <BestFoodSourceOnMap>c__AnonStorey.allowDispenserFull = allowDispenserFull;
  5.             <BestFoodSourceOnMap>c__AnonStorey.maxPref = maxPref;
  6.             <BestFoodSourceOnMap>c__AnonStorey.eater = eater;
  7.             <BestFoodSourceOnMap>c__AnonStorey.getter = getter;
  8.             <BestFoodSourceOnMap>c__AnonStorey.allowForbidden = allowForbidden;
  9.             <BestFoodSourceOnMap>c__AnonStorey.allowDispenserEmpty = allowDispenserEmpty;
  10.             <BestFoodSourceOnMap>c__AnonStorey.allowSociallyImproper = allowSociallyImproper;
  11.             <BestFoodSourceOnMap>c__AnonStorey.allowCorpse = allowCorpse;
  12.             <BestFoodSourceOnMap>c__AnonStorey.allowDrug = allowDrug;
  13.             <BestFoodSourceOnMap>c__AnonStorey.desperate = desperate;
  14.             <BestFoodSourceOnMap>c__AnonStorey.forceScanWholeMap = forceScanWholeMap;
  15.             foodDef = null;
  16.             <BestFoodSourceOnMap>c__AnonStorey.getterCanManipulate = (<BestFoodSourceOnMap>c__AnonStorey.getter.RaceProps.ToolUser && <BestFoodSourceOnMap>c__AnonStorey.getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation));
  17.             if (!<BestFoodSourceOnMap>c__AnonStorey.getterCanManipulate && <BestFoodSourceOnMap>c__AnonStorey.getter != <BestFoodSourceOnMap>c__AnonStorey.eater)
  18.             {
  19.                 Log.Error(string.Concat(new object[]
  20.                 {
  21.                     <BestFoodSourceOnMap>c__AnonStorey.getter,
  22.                     " tried to find food to bring to ",
  23.                     <BestFoodSourceOnMap>c__AnonStorey.eater,
  24.                     " but ",
  25.                     <BestFoodSourceOnMap>c__AnonStorey.getter,
  26.                     " is incapable of Manipulation."
  27.                 }), false);
  28.                 return null;
  29.             }
  30.             if (<BestFoodSourceOnMap>c__AnonStorey.eater.NonHumanlikeOrWildMan())
  31.             {
  32.                 <BestFoodSourceOnMap>c__AnonStorey.minPref = FoodPreferability.NeverForNutrition;
  33.             }
  34.             else if (<BestFoodSourceOnMap>c__AnonStorey.desperate)
  35.             {
  36.                 <BestFoodSourceOnMap>c__AnonStorey.minPref = FoodPreferability.DesperateOnly;
  37.             }
  38.             else
  39.             {
  40.                 <BestFoodSourceOnMap>c__AnonStorey.minPref = ((<BestFoodSourceOnMap>c__AnonStorey.eater.needs.food.CurCategory < HungerCategory.UrgentlyHungry) ? FoodPreferability.MealAwful : FoodPreferability.RawBad);
  41.             }
  42.             <BestFoodSourceOnMap>c__AnonStorey.foodValidator = delegate(Thing t)
  43.             {
  44.                 Building_NutrientPasteDispenser building_NutrientPasteDispenser = t as Building_NutrientPasteDispenser;
  45.                 if (building_NutrientPasteDispenser != null)
  46.                 {
  47.                     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)))
  48.                     {
  49.                         return false;
  50.                     }
  51.                 }
  52.                 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))
  53.                 {
  54.                     return false;
  55.                 }
  56.                 return true;
  57.             };
  58.             ThingRequest thingRequest;
  59.             if ((<BestFoodSourceOnMap>c__AnonStorey.eater.RaceProps.foodType & (FoodTypeFlags.Plant | FoodTypeFlags.Tree)) != FoodTypeFlags.None && allowPlant)
  60.             {
  61.                 thingRequest = ThingRequest.ForGroup(ThingRequestGroup.FoodSource);
  62.             }
  63.             else
  64.             {
  65.                 thingRequest = ThingRequest.ForGroup(ThingRequestGroup.FoodSourceNotPlantOrTree);
  66.             }
  67.             if (<BestFoodSourceOnMap>c__AnonStorey.getter.RaceProps.Humanlike)
  68.             {
  69.                 FoodUtility.<BestFoodSourceOnMap>c__AnonStorey0 <BestFoodSourceOnMap>c__AnonStorey2 = <BestFoodSourceOnMap>c__AnonStorey;
  70.                 Pawn eater2 = <BestFoodSourceOnMap>c__AnonStorey.eater;
  71.                 IntVec3 position = <BestFoodSourceOnMap>c__AnonStorey.getter.Position;
  72.                 List<Thing> searchSet = <BestFoodSourceOnMap>c__AnonStorey.getter.Map.listerThings.ThingsMatching(thingRequest);
  73.                 PathEndMode peMode = PathEndMode.ClosestTouch;
  74.                 TraverseParms traverseParams = TraverseParms.For(<BestFoodSourceOnMap>c__AnonStorey.getter, Danger.Deadly, TraverseMode.ByPawn, false);
  75.                 Predicate<Thing> validator = <BestFoodSourceOnMap>c__AnonStorey.foodValidator;
  76.                 <BestFoodSourceOnMap>c__AnonStorey2.bestThing = FoodUtility.SpawnedFoodSearchInnerScan(eater2, position, searchSet, peMode, traverseParams, 9999f, validator);
  77.                 if (allowHarvest && <BestFoodSourceOnMap>c__AnonStorey.getterCanManipulate)
  78.                 {
  79.                     int searchRegionsMax;
  80.                     if (<BestFoodSourceOnMap>c__AnonStorey.forceScanWholeMap && <BestFoodSourceOnMap>c__AnonStorey.bestThing == null)
  81.                     {
  82.                         searchRegionsMax = -1;
  83.                     }
  84.                     else
  85.                     {
  86.                         searchRegionsMax = 30;
  87.                     }
  88.                     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)
  89.                     {
  90.                         Plant plant = (Plant)x;
  91.                         if (!plant.HarvestableNow)
  92.                         {
  93.                             return false;
  94.                         }
  95.                         ThingDef harvestedThingDef = plant.def.plant.harvestedThingDef;
  96.                         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);
  97.                     }, null, 0, searchRegionsMax, false, RegionType.Set_Passable, false);
  98.                     if (thing != null)
  99.                     {
  100.                         <BestFoodSourceOnMap>c__AnonStorey.bestThing = thing;
  101.                         foodDef = FoodUtility.GetFinalIngestibleDef(thing, true);
  102.                     }
  103.                 }
  104.                 if (foodDef == null && <BestFoodSourceOnMap>c__AnonStorey.bestThing != null)
  105.                 {
  106.                     foodDef = FoodUtility.GetFinalIngestibleDef(<BestFoodSourceOnMap>c__AnonStorey.bestThing, false);
  107.                 }
  108.             }
  109.             else
  110.             {
  111.                 int maxRegionsToScan = FoodUtility.GetMaxRegionsToScan(<BestFoodSourceOnMap>c__AnonStorey.getter, <BestFoodSourceOnMap>c__AnonStorey.forceScanWholeMap);
  112.                 FoodUtility.filtered.Clear();
  113.                 foreach (Thing thing2 in GenRadial.RadialDistinctThingsAround(<BestFoodSourceOnMap>c__AnonStorey.getter.Position, <BestFoodSourceOnMap>c__AnonStorey.getter.Map, 2f, true))
  114.                 {
  115.                     Pawn pawn = thing2 as Pawn;
  116.                     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)
  117.                     {
  118.                         FoodUtility.filtered.Add(pawn.CurJob.GetTarget(TargetIndex.A).Thing);
  119.                     }
  120.                 }
  121.                 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;
  122.                 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();
  123.                 FoodUtility.<BestFoodSourceOnMap>c__AnonStorey0 <BestFoodSourceOnMap>c__AnonStorey3 = <BestFoodSourceOnMap>c__AnonStorey;
  124.                 IntVec3 position = <BestFoodSourceOnMap>c__AnonStorey.getter.Position;
  125.                 Map map = <BestFoodSourceOnMap>c__AnonStorey.getter.Map;
  126.                 ThingRequest thingReq = thingRequest;
  127.                 PathEndMode peMode = PathEndMode.ClosestTouch;
  128.                 TraverseParms traverseParams = TraverseParms.For(<BestFoodSourceOnMap>c__AnonStorey.getter, Danger.Deadly, TraverseMode.ByPawn, false);
  129.                 Predicate<Thing> validator = predicate;
  130.                 bool ignoreEntirelyForbiddenRegions = flag;
  131.                 <BestFoodSourceOnMap>c__AnonStorey3.bestThing = GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, maxRegionsToScan, false, RegionType.Set_Passable, ignoreEntirelyForbiddenRegions);
  132.                 FoodUtility.filtered.Clear();
  133.                 if (<BestFoodSourceOnMap>c__AnonStorey.bestThing == null)
  134.                 {
  135.                     <BestFoodSourceOnMap>c__AnonStorey.desperate = true;
  136.                     FoodUtility.<BestFoodSourceOnMap>c__AnonStorey0 <BestFoodSourceOnMap>c__AnonStorey4 = <BestFoodSourceOnMap>c__AnonStorey;
  137.                     position = <BestFoodSourceOnMap>c__AnonStorey.getter.Position;
  138.                     map = <BestFoodSourceOnMap>c__AnonStorey.getter.Map;
  139.                     thingReq = thingRequest;
  140.                     peMode = PathEndMode.ClosestTouch;
  141.                     traverseParams = TraverseParms.For(<BestFoodSourceOnMap>c__AnonStorey.getter, Danger.Deadly, TraverseMode.ByPawn, false);
  142.                     validator = <BestFoodSourceOnMap>c__AnonStorey.foodValidator;
  143.                     ignoreEntirelyForbiddenRegions = flag;
  144.                     <BestFoodSourceOnMap>c__AnonStorey4.bestThing = GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, maxRegionsToScan, false, RegionType.Set_Passable, ignoreEntirelyForbiddenRegions);
  145.                 }
  146.                 if (<BestFoodSourceOnMap>c__AnonStorey.bestThing != null)
  147.                 {
  148.                     foodDef = FoodUtility.GetFinalIngestibleDef(<BestFoodSourceOnMap>c__AnonStorey.bestThing, false);
  149.                 }
  150.             }
  151.             return <BestFoodSourceOnMap>c__AnonStorey.bestThing;
  152.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement