internal static Job TakeFoodForAnimalInteractJob(this WorkGiver_InteractAnimal _this, Pawn pawn, Pawn tamee)
        {
            float reqNutrition = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f;
            Thing thing        = FoodUtility.BestFoodSourceOnMap(pawn, tamee, false, FoodPreferability.RawTasty, false, false, false, false, false, false);

            if (thing == null)
            {
                return(null);
            }

            // Check for inventory space
            int           numToCarry = Mathf.CeilToInt(reqNutrition / thing.def.ingestible.nutrition);
            CompInventory inventory  = pawn.TryGetComp <CompInventory>();

            if (inventory != null)
            {
                int maxCount;
                if (inventory.CanFitInInventory(thing, out maxCount))
                {
                    numToCarry = Mathf.Min(numToCarry, maxCount);
                }
                else
                {
                    Messages.Message("CR_TamerInventoryFull".Translate(), pawn, MessageSound.RejectInput);
                    return(null);
                }
            }

            return(new Job(JobDefOf.TakeInventory, thing)
            {
                count = numToCarry
            });
        }
        private Job TakeFoodForAnimalInteractJob(Pawn pawn, Pawn tamee)
        {
            FoodUtility.bestFoodSourceOnMap_minNutrition_NewTemp = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f;
            ThingDef foodDef;
            Thing    thing = FoodUtility.BestFoodSourceOnMap(pawn, tamee, false, out foodDef, FoodPreferability.RawTasty, allowPlant: false, allowDrug: false, allowCorpse: false, allowDispenserFull: false, allowDispenserEmpty: false);

            FoodUtility.bestFoodSourceOnMap_minNutrition_NewTemp = null;
            if (thing == null)
            {
                return(null);
            }
            float num       = JobDriver_InteractAnimal.RequiredNutritionPerFeed(tamee) * 2f * 4f;
            float nutrition = FoodUtility.GetNutrition(thing, foodDef);
            int   count     = Mathf.CeilToInt(num / nutrition);
            Job   job       = JobMaker.MakeJob(JobDefOf.TakeInventory, thing);

            job.count = count;
            return(job);
        }
Esempio n. 3
0
        // 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);
        }
Esempio n. 4
0
        // 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;
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        internal static Job _TryGiveJob(this JobGiver_GetFood obj, Pawn pawn)
        {
            bool     desperate = pawn.needs.food.CurCategory == HungerCategory.Starving;
            Thing    foodSource;
            ThingDef foodDef;

            //CCL_Log.Message( "JobGiver_GetFood for " + pawn.LabelShort );

            // Find an appropriate food source for the pawn
            if (!FoodUtility.TryFindBestFoodSourceFor(
                    pawn,
                    pawn,
                    desperate,
                    out foodSource,
                    out foodDef,
                    true,
                    true,
                    false,
                    true)
                )
            {
                return(null);
            }

            //CCL_Log.Message( string.Format( "Found {0} ({1}) for {2}", foodSource.ThingID, foodDef.defName, pawn.LabelShort ) );

            // Predator-Prey
            var prey = foodSource as Pawn;

            if (prey != null)
            {
                var hunterJob = new Job(JobDefOf.PredatorHunt, prey);
                hunterJob.killIncappedTarget = true;
                return(hunterJob);
            }

            // Nutrient Paste Dispensers and Food Synthesizers (Building_AutomatedFactory)
            if (foodSource is Building)
            {
                var hopperNeedsFilling = false;
                var hopper             = (Building)null;
                if (foodSource is Building_NutrientPasteDispenser)
                {
                    var NPD = foodSource as Building_NutrientPasteDispenser;
                    if (!NPD.HasEnoughFeedstockInHoppers())
                    {
                        //CCL_Log.Message( string.Format( "Hopper for {0} needs filling", foodSource.ThingID ) );
                        hopperNeedsFilling = true;
                        hopper             = NPD.AdjacentReachableHopper(pawn);
                    }
                }
                if (foodSource is Building_AutomatedFactory)
                {
                    var FS = foodSource as Building_AutomatedFactory;
                    if (foodDef == null)
                    {
                        //CCL_Log.Message( string.Format( "Hopper for {0} needs filling", foodSource.ThingID ) );
                        hopperNeedsFilling = true;
                        hopper             = FS.AdjacentReachableHopper(pawn);
                    }
                }
                if (hopperNeedsFilling)
                {
                    if (hopper != null)
                    {
                        //CCL_Log.Message( string.Format( "Found hopper {0} for {1} that needs filling", hopper.ThingID, foodSource.ThingID ) );
                        return(HopperFillFoodJob(pawn, hopper, foodSource));
                    }
                    else
                    {   // Find an alternate source that isn't an NPD or FS
                        //CCL_Log.Message( "Searching for non-machine food for " + pawn.LabelShort );
                        foodSource = FoodUtility.BestFoodSourceOnMap(
                            pawn,
                            pawn,
                            desperate,
                            FoodPreferability.MealLavish,
                            false,
                            false,
                            false,
                            false,
                            false,
                            false);
                        if (foodSource == null)
                        {
                            return(null);
                        }
                        foodDef = FoodUtility.GetFoodDef(foodSource);
                    }
                }
            }

            //CCL_Log.Message( string.Format( "Giving JobDriver_Ingest to {0} using {1}", pawn.LabelShort, foodSource.ThingID ) );
            // Ingest job for found food source
            var ingestJob = new Job(JobDefOf.Ingest, foodSource);

            ingestJob.maxNumToCarry = FoodUtility.WillEatStackCountOf(pawn, foodDef);
            return(ingestJob);
        }
Esempio n. 7
0
    protected override Job TryGiveJob(Pawn pawn)
    {
        var food = pawn.needs.food;

        if (food == null || food.CurCategory < minCategory)
        {
            return(null);
        }

        if (!pawn.RaceProps.Animal)
        {
            return(null);
        }

        var localCocoons = Utility.CocoonsFor(pawn.Map, pawn);

        if (localCocoons != null && localCocoons.Count > 0)
        {
            Building_Cocoon closestCocoon    = null;
            var             shortestDistance = 9999f;
            foreach (var thing1 in localCocoons)
            {
                var cocoon = (Building_Cocoon)thing1;
                //Log.Message("1");
                if (cocoon?.isConsumableBy(pawn) != true || cocoon.CurrentDrinker != null)
                {
                    continue;
                }

                //Log.Message("2");
                if (closestCocoon == null)
                {
                    closestCocoon = cocoon;
                    continue;
                }

                var thisDistance = (float)(cocoon.Position - pawn.Position).LengthHorizontalSquared;
                if (!(thisDistance < shortestDistance))
                {
                    continue;
                }

                shortestDistance = thisDistance;
                closestCocoon    = cocoon;
            }

            if (closestCocoon != null)
            {
                //Log.Message("3");
                closestCocoon.CurrentDrinker = pawn as PawnWebSpinner;
                var newJob = new Job(ROMADefOf.ROMA_ConsumeCocoon, closestCocoon);
                //pawn.Reserve(closestCocoon, newJob);
                return(newJob);
            }
        }


        var desperate = pawn.needs.food.CurCategory == HungerCategory.Starving;

        if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out var thing, out var def))
        {
            return(null);
        }

        if (thing is Pawn pawn2)
        {
            var jobToDo = new Job(ROMADefOf.ROMA_SpinPrey, pawn2)
            {
                count = 1
            };
            return(jobToDo);
        }

        if (thing is Building_NutrientPasteDispenser building_NutrientPasteDispenser &&
            !building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers())
        {
            var building = building_NutrientPasteDispenser.AdjacentReachableHopper(pawn);
            if (building != null)
            {
                var hopperSgp = building as ISlotGroupParent;
                var job       = WorkGiver_CookFillHopper.HopperFillFoodJob(pawn, hopperSgp);
                if (job != null)
                {
                    return(job);
                }
            }

            thing = FoodUtility.BestFoodSourceOnMap(pawn, pawn, desperate, out var thingDef,
                                                    FoodPreferability.MealLavish, false, !pawn.IsTeetotaler(), false, false, false);
            if (thing == null)
            {
                return(null);
            }

            def = thingDef;
        }

        var nutrition = FoodUtility.GetNutrition(thing, def);

        return(new Job(JobDefOf.Ingest, thing)
        {
            count = FoodUtility.WillIngestStackCountOf(pawn, def, nutrition)
        });
    }