public static Thing TryGetBackpackLastItem(Pawn pawn) { Apparel_Backpack backpack = ToolsForHaulUtility.TryGetBackpack(pawn); if (backpack == null) { return(null); } Thing lastItem = null; int lastItemInd = -1; Thing foodInInventory = FoodUtility.BestFoodInInventory(pawn); if (pawn.inventory.container.Count > 0) { if (backpack.numOfSavedItems > 0) { lastItemInd = ((backpack.numOfSavedItems >= pawn.inventory.container.Count)?pawn.inventory.container.Count : backpack.numOfSavedItems) - 1; lastItem = pawn.inventory.container[lastItemInd]; } if (foodInInventory != null && backpack.numOfSavedItems < pawn.inventory.container.Count && pawn.inventory.container[lastItemInd + 1] == foodInInventory) { lastItem = foodInInventory; } } return(lastItem); }
public static Thing TryGetBackpackLastItem(Pawn pawn) { Apparel_Backpack backpack = TryGetBackpack(pawn); if (backpack == null) { return(null); } Thing lastItem = null; int lastItemInd = -1; Thing foodInInventory = FoodUtility.BestFoodInInventory(pawn); if (backpack.slotsComp.slots.Count > 0) { if (backpack.numOfSavedItems > 0) { lastItemInd = (backpack.numOfSavedItems >= backpack.MaxItem ? backpack.slotsComp.slots.Count : backpack.numOfSavedItems) - 1; lastItem = backpack.slotsComp.slots[lastItemInd]; } if (foodInInventory != null && backpack.numOfSavedItems < backpack.slotsComp.slots.Count && backpack.slotsComp.slots[lastItemInd + 1] == foodInInventory) { lastItem = foodInInventory; } } return(lastItem); }
/// <summary> /// Tries the find best food source for the given getter and eater. /// </summary> /// Tries to find the best food source for the given getter and eater, taking into account humanoids that can eat plants /// <param name="getter">The getter.</param> /// <param name="eater">The eater.</param> /// <param name="desperate">if set to <c>true</c> [desperate].</param> /// <param name="foodSource">The food source.</param> /// <param name="foodDef">The food definition.</param> /// <param name="canRefillDispenser">if set to <c>true</c> [can refill dispenser].</param> /// <param name="canUseInventory">if set to <c>true</c> [can use inventory].</param> /// <param name="allowForbidden">if set to <c>true</c> [allow forbidden].</param> /// <param name="allowCorpse">if set to <c>true</c> [allow corpse].</param> /// <param name="allowSociallyImproper">if set to <c>true</c> [allow socially improper].</param> /// <param name="allowHarvest">if set to <c>true</c> [allow harvest].</param> /// <param name="forceScanWholeMap">if set to <c>true</c> [force scan whole map].</param> /// <param name="ignoreReservations">if set to <c>true</c> [ignore reservations].</param> /// <param name="minPrefOverride">The minimum preference override.</param> /// <returns></returns> public static bool TryFindBestFoodSourceForOptimized( 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 forceScanWholeMap = false, bool ignoreReservations = false, FoodPreferability minPrefOverride = FoodPreferability.Undefined) { bool canDoManipulation = getter.IsToolUser() && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation); bool allowDrug = !eater.IsTeetotaler(); Thing thing1 = null; if (canUseInventory) { if (canDoManipulation) { thing1 = FoodUtility.BestFoodInInventory(getter, eater, minPrefOverride == FoodPreferability.Undefined ? FoodPreferability.MealAwful : minPrefOverride); } if (thing1 != null) { if (getter.Faction != Faction.OfPlayer) { foodSource = thing1; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource); return(true); } var comp = thing1.TryGetComp <CompRottable>(); if (comp != null && comp.Stage == RotStage.Fresh && comp.TicksUntilRotAtCurrentTemp < 30000) { foodSource = thing1; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource); return(true); } } } Pawn getter1 = getter; Pawn eater1 = eater; int num1 = desperate ? 1 : 0; ThingDef foodDef1 = null; ref ThingDef local = ref foodDef1;
/// <summary> /// gets the start feed animal toil /// </summary> /// <param name="tameeInd">The tamee ind.</param> /// <returns></returns> protected virtual Toil StartFeedAnimal(TargetIndex tameeInd) { var toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.GetActor(); var pawn = (Pawn)(Thing)actor.CurJob.GetTarget(tameeInd); PawnUtility.ForceWait(pawn, 270, actor); Thing thing = FoodUtility.BestFoodInInventory(actor, pawn, FoodPreferability.NeverForNutrition, FoodPreferability.RawTasty); if (thing == null) { actor.jobs.EndCurrentJob(JobCondition.Incompletable); } else { actor.mindState.lastInventoryRawFoodUseTick = Find.TickManager.TicksGame; int num = FoodUtility.StackCountForNutrition(feedNutritionLeft, thing.GetStatValue(StatDefOf.Nutrition)); int stackCount = thing.stackCount; Thing thing2 = actor.inventory.innerContainer.Take(thing, Mathf.Min(num, stackCount)); actor.carryTracker.TryStartCarry(thing2); actor.CurJob.SetTarget(TargetIndex.B, thing2); float num2 = thing2.stackCount * thing2.GetStatValue(StatDefOf.Nutrition); ticksLeftThisToil = Mathf.CeilToInt(FeedDuration * (num2 / RequiredNutritionPerFeed(pawn))); if (num <= stackCount) { feedNutritionLeft = 0f; } else { feedNutritionLeft -= num2; if (feedNutritionLeft < 0.001f) { feedNutritionLeft = 0f; } } } }; toil.defaultCompleteMode = ToilCompleteMode.Delay; return(toil); }
public static void Postfix(ref bool __result, Pawn getter, Pawn eater, ref Thing foodSource, ref ThingDef foodDef, bool canUseInventory, bool canUsePackAnimalInventory) { if (eater.IsFreeColonist && __result == false && canUseInventory && canUsePackAnimalInventory && getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { Log.Message($"There be no food for " + eater); List <Pawn> pawns = eater.Map.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer).FindAll( p => p != getter && !p.Position.IsForbidden(getter) && getter.CanReach(p, PathEndMode.OnCell, Danger.Some) ); foreach (Pawn p in pawns) { Log.Message($"Food soon rotten on " + p + "?"); Thing thing = FoodUtility.BestFoodInInventory(p, eater, FoodPreferability.MealAwful); if (thing != null && thing.TryGetComp <CompRottable>() is CompRottable compRottable && compRottable != null && compRottable.Stage == RotStage.Fresh && compRottable.TicksUntilRotAtCurrentTemp < GenDate.TicksPerDay / 2) { Log.Message($"Food is " + thing); foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); __result = true; return; } } foreach (Pawn p in pawns) { Log.Message($"Food on " + p + "?"); Thing thing = FoodUtility.BestFoodInInventory(p, eater, FoodPreferability.DesperateOnly, FoodPreferability.MealLavish, 0f, !eater.IsTeetotaler()); if (thing != null) { Log.Message($"Food is " + thing); foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); __result = true; return; } } } }
// Token: 0x0600017C RID: 380 RVA: 0x0000DB3C File Offset: 0x0000BF3C public 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 forceScanWholeMap = false) { bool flag = getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation); bool flag2 = !eater.IsTeetotaler(); Thing thing = null; ThingDef thingDef = null; ThingDef foodDef2 = thingDef; bool allowPlant = getter == eater; Thing thing2 = FoodUtility.BestFoodSourceOnMap(getter, eater, desperate, out foodDef2, FoodPreferability.Undefined, allowPlant, flag2, allowCorpse, true, canRefillDispenser, allowForbidden, allowSociallyImproper, allowHarvest, forceScanWholeMap); if (thing == null && thing2 == null) { if (canUseInventory && flag) { FoodPreferability minFoodPref = FoodPreferability.DesperateOnly; bool allowDrug = flag2; thing = FoodUtility.BestFoodInInventory(getter, eater, minFoodPref, 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() && !getter.IsPrisoner))) { Pawn pawn = BestPawnToHuntForPredator(getter, forceScanWholeMap); 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 -= 32f; if (num > num2) { foodSource = thing2; foodDef = thingDef; return(true); } foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); return(true); }
// Token: 0x060000F1 RID: 241 RVA: 0x00008A58 File Offset: 0x00006C58 public static void TryFindBestFoodSourceFor_Prefix(ref bool __result, 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 animal = getter.RaceProps.Animal; bool flag2 = !eater.IsTeetotaler(); Thing thing = null; if (canUseInventory) { bool flag3 = animal; if (flag3) { thing = FoodUtility.BestFoodInInventory(getter, eater, FoodPreferability.MealAwful, FoodPreferability.MealLavish, 0f, false); } } bool flag4 = getter == eater; ThingDef thingDef; Thing thing2 = FoodUtility.BestFoodSourceOnMap(getter, eater, desperate, out thingDef, FoodPreferability.MealLavish, flag4, flag2, allowCorpse, true, canRefillDispenser, allowForbidden, allowSociallyImproper, allowHarvest, false); bool flag5 = thing == null && thing2 == null; if (flag5) { bool flag6 = canUseInventory && animal; if (flag6) { FoodPreferability minFoodPref = FoodPreferability.DesperateOnly; bool allowDrug = flag2; thing = FoodUtility.BestFoodInInventory(getter, eater, minFoodPref, FoodPreferability.MealLavish, 0f, allowDrug); bool flag7 = thing != null; if (flag7) { foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); __result = true; } } foodSource = null; foodDef = null; __result = false; } bool flag8 = thing == null && thing2 != null; if (flag8) { foodSource = thing2; foodDef = thingDef; __result = true; } ThingDef finalIngestibleDef = FoodUtility.GetFinalIngestibleDef(thing, false); bool flag9 = thing2 == null; if (flag9) { foodSource = thing; foodDef = finalIngestibleDef; __result = 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 -= 32f; bool flag10 = num > num2; if (flag10) { foodSource = thing2; foodDef = thingDef; __result = true; } foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource, false); __result = true; }
private static bool Prefix(ref bool __result, 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 forceScanWholeMap = false) { var flag = getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation); var allowDrug = !eater.IsTeetotaler(); var thing1 = (Thing)null; if (canUseInventory) { if (flag) { thing1 = FoodUtility.BestFoodInInventory(getter, eater, FoodPreferability.MealAwful); } if (thing1 != null) { if (getter.Faction != Faction.OfPlayer) { foodSource = thing1; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource); __result = true; return(false); } var comp = thing1.TryGetComp <CompRottable>(); if ((comp != null) && (comp.Stage == RotStage.Fresh) && (comp.TicksUntilRotAtCurrentTemp < 30000)) { foodSource = thing1; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource); __result = true; return(false); } } } var getter1 = getter; var eater1 = eater; var desperate1 = desperate; var allowPlant = getter == eater; var allowDispenserEmpty = canRefillDispenser; var foodSource1 = FoodUtility.BestFoodSourceOnMap(getter1, eater1, desperate1, out var foodDef1, FoodPreferability.MealLavish, allowPlant, allowDrug, allowCorpse, true, allowDispenserEmpty, allowForbidden, allowSociallyImproper, allowHarvest, forceScanWholeMap); if ((thing1 != null) || (foodSource1 != null)) { if ((thing1 == null) && (foodSource1 != null)) { foodSource = foodSource1; foodDef = foodDef1; __result = true; return(false); } var finalIngestibleDef = FoodUtility.GetFinalIngestibleDef(thing1); if (foodSource1 == null) { foodSource = thing1; foodDef = finalIngestibleDef; __result = true; return(false); } if (FoodUtility.FoodOptimality(eater, foodSource1, foodDef1, (getter.Position - foodSource1.Position).LengthManhattan) > (double)(FoodUtility.FoodOptimality(eater, thing1, finalIngestibleDef, 0.0f) - 32f)) { foodSource = foodSource1; foodDef = foodDef1; __result = true; return(false); } foodSource = thing1; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource); __result = true; return(false); } if (canUseInventory && flag) { var thing2 = FoodUtility.BestFoodInInventory(getter, eater, FoodPreferability.DesperateOnly, FoodPreferability.MealLavish, 0.0f, allowDrug); if (thing2 != null) { foodSource = thing2; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource); __result = true; return(false); } } if ((foodSource1 == null) && (getter == eater) && (getter.RaceProps.predator || (getter.IsWildMan() && !getter.IsPrisoner))) { var huntForPredator = PrivateAccess.RimWorld_FoodUtility_BestPawnToHuntForPredator(getter, forceScanWholeMap); if (huntForPredator != null) { foodSource = huntForPredator; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource); __result = true; return(false); } } foodSource = null; foodDef = null; __result = false; return(false); }
public bool TryFindBestFoodSourceFor(Pawn getter, Pawn eater, bool desperate, out Thing foodSource, out ThingDef foodDef, bool canRefillDispenser = true, bool canUseInventory = true, bool canUsePackAnimalInventory = false, bool allowForbidden = false, bool allowCorpse = true, bool allowSociallyImproper = false, bool allowHarvest = false, bool forceScanWholeMap = false, bool ignoreReservations = false, bool calculateWantedStackCount = false, FoodPreferability minPrefOverride = FoodPreferability.Undefined) { bool allowDrug = !eater.IsTeetotaler(); Thing thing = null; Pawn packAnimal = null; Pawn getter2 = getter; Pawn eater2 = eater; bool allowPlant = getter == eater; bool allowForbidden2 = allowForbidden; ThingDef foodDef2; Thing thing2 = BestFoodSourceOnMap(getter2, eater2, desperate, out foodDef2, FoodPreferability.MealLavish, allowPlant, allowDrug, allowCorpse, allowDispenserFull: true, canRefillDispenser, allowForbidden2, allowSociallyImproper, allowHarvest, forceScanWholeMap, ignoreReservations, calculateWantedStackCount, minPrefOverride); if (thing2 == null && thing == null) { thing = FirstFoodInClosestPackAnimalInventory((minPrefOverride == FoodPreferability.Undefined) ? FoodPreferability.MealAwful : minPrefOverride); } if (thing != null || thing2 != null) { if (thing == null && thing2 != null) { foodSource = thing2; foodDef = foodDef2; return(true); } ThingDef finalIngestibleDef = FoodUtility.GetFinalIngestibleDef(thing); if (thing2 == null) { foodSource = thing; foodDef = finalIngestibleDef; return(true); } float num = FoodUtility.FoodOptimality(eater, thing2, foodDef2, (getter.Position - thing2.Position).LengthManhattan); float num2 = FoodUtility.FoodOptimality(eater, thing, finalIngestibleDef, (packAnimal != null) ? (getter.Position - packAnimal.Position).LengthManhattan : 0); num2 -= 32f; if (num > num2) { foodSource = thing2; foodDef = foodDef2; return(true); } foodSource = thing; foodDef = FoodUtility.GetFinalIngestibleDef(foodSource); return(true); } foodSource = null; foodDef = null; return(false); Thing FirstFoodInClosestPackAnimalInventory(FoodPreferability foodPref) { Thing result = null; if ((canUseInventory & canUsePackAnimalInventory) && eater.IsColonist && getter.IsColonist && getter.Map != null) { Thing thing3 = null; { foreach (Pawn spawnedColonyAnimal in getter.Map.mapPawns.SpawnedColonyAnimals) { thing3 = FoodUtility.BestFoodInInventory(spawnedColonyAnimal, eater, foodPref); if (thing3 != null && (packAnimal == null || (getter.Position - packAnimal.Position).LengthManhattan > (getter.Position - spawnedColonyAnimal.Position).LengthManhattan) && !spawnedColonyAnimal.IsForbidden(getter) && getter.CanReach(spawnedColonyAnimal, PathEndMode.OnCell, Danger.Some)) { packAnimal = spawnedColonyAnimal; result = thing3; } } return(result); } } return(result); } }