コード例 #1
0
        internal static bool Internal(Pawn getter, Pawn eater, bool desperate, out Thing foodSource, out ThingDef foodDef, bool canRefillDispenser = true, bool canUseInventory = true, bool allowForbidden = false, bool allowCorpse = true, Policy forcedPolicy = null)
        {
            List <FoodSourceRating> FoodListForPawn;

            FoodSearchCache.PawnEntry pawnEntry;

            if (!FoodSearchCache.TryGetEntryForPawn(getter, eater, out pawnEntry, allowForbidden))
            {
                Policy policy;

                if (forcedPolicy != null)
                {
                    policy = forcedPolicy;
                }
                else
                {
                    policy = PolicyUtils.GetPolicyAssignedTo(eater, getter);
                }

                bool foundFood = FoodUtils.MakeRatedFoodListForPawn(getter.Map, eater, getter, policy, out FoodListForPawn, canUseInventory, allowForbidden);

                pawnEntry = FoodSearchCache.AddPawnEntry(getter, eater, FoodListForPawn);
            }

            bool flagAllowHunt  = (getter == eater && eater.RaceProps.predator && !eater.health.hediffSet.HasTendableInjury());
            bool flagAllowPlant = (getter == eater);

            // C# 5 :'(
            var foodSourceRating = pawnEntry.GetBestFoodEntry(flagAllowPlant, allowCorpse, flagAllowHunt);

            if (foodSourceRating != null)
            {
                foodSource = foodSourceRating.FoodSource;
            }
            else
            {
                foodSource = null;
            }

            if (foodSource == null)              // ** If no food source is found set food Definition to null and return
            {
                foodDef = null;
                return(false);
            }

            foodDef = RimWorld.FoodUtility.GetFinalIngestibleDef(foodSource);             // ** Set food definition of food source and return
            return(true);

            //bool flag = getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation);
            //Thing thing = null;
            //if (canUseInventory)
            //{
            //	if (flag)
            //	{
            //		thing = RimWorld.FoodUtility.BestFoodInInventory(getter, null, FoodPreferability.MealAwful, FoodPreferability.MealLavish, 0f, false);
            //	}
            //	if (thing != null)
            //	{
            //		if (getter.Faction != Faction.OfPlayer)
            //		{
            //			foodSource = thing;
            //			foodDef = RimWorld.FoodUtility.GetFinalIngestibleDef(foodSource);
            //			return true;
            //		}
            //		CompRottable compRottable = thing.TryGetComp<CompRottable>();
            //		if (compRottable != null && compRottable.Stage == RotStage.Fresh && compRottable.TicksUntilRotAtCurrentTemp < 30000)
            //		{
            //			foodSource = thing;
            //			foodDef = RimWorld.FoodUtility.GetFinalIngestibleDef(foodSource);
            //			return true;
            //		}
            //	}
            //}
            //bool allowPlant = getter == eater;
        }
コード例 #2
0
        // RimWorld.FoodUtility
        private 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, Policy forcedPolicy = null)
        {
#if DEBUG
            Log.Message("_TryFindBestFoodSourceFor() getter=" + getter + " eater=" + eater + " desperate=" + desperate + " canUseInventory=" + canUseInventory + " allowForbidden=" + allowForbidden);
#endif
            Policy policy;

            //taming ? TODO: check for bug free
            if (forcedPolicy != null)
            {
                policy = forcedPolicy;
            }
            else
            {
                policy = eater.GetPolicyAssignedTo(getter);
            }

            if (getter.isWildAnimal() || getter.isInsectFaction() || policy.unrestricted || getter.InMentalState || Config.ControlDisabledForPawn(eater))
            {
                return(Original.FoodUtility.TryFindBestFoodSourceFor(getter, eater, desperate, out foodSource, out foodDef, canRefillDispenser, canUseInventory, allowForbidden, allowCorpse));
            }

            List <FoodSourceRating> FoodListForPawn;

            FoodSearchCache.PawnEntry pawnEntry;

            if (!FoodSearchCache.TryGetEntryForPawn(getter, eater, out pawnEntry, allowForbidden))
            {
                bool foundFood = MakeRatedFoodListForPawn(getter.Map, eater, getter, policy, out FoodListForPawn, canUseInventory, allowForbidden);

                pawnEntry = FoodSearchCache.AddPawnEntry(getter, eater, FoodListForPawn);
            }

            bool flagAllowHunt  = (getter == eater && eater.RaceProps.predator && !eater.health.hediffSet.HasTendableInjury());
            bool flagAllowPlant = (getter == eater);

            // C# 5 :'(
            var foodSourceRating = pawnEntry.GetBestFoodEntry(flagAllowPlant, allowCorpse, flagAllowHunt);
            if (foodSourceRating != null)
            {
                foodSource = foodSourceRating.FoodSource;
            }
            else
            {
                foodSource = null;
            }

            if (foodSource == null)
            {
                foodDef = null;
                return(false);
            }

            foodDef = RimWorld.FoodUtility.GetFinalIngestibleDef(foodSource);
            return(true);

            //bool flag = getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation);
            //Thing thing = null;
            //if (canUseInventory)
            //{
            //	if (flag)
            //	{
            //		thing = RimWorld.FoodUtility.BestFoodInInventory(getter, null, FoodPreferability.MealAwful, FoodPreferability.MealLavish, 0f, false);
            //	}
            //	if (thing != null)
            //	{
            //		if (getter.Faction != Faction.OfPlayer)
            //		{
            //			foodSource = thing;
            //			foodDef = RimWorld.FoodUtility.GetFinalIngestibleDef(foodSource);
            //			return true;
            //		}
            //		CompRottable compRottable = thing.TryGetComp<CompRottable>();
            //		if (compRottable != null && compRottable.Stage == RotStage.Fresh && compRottable.TicksUntilRotAtCurrentTemp < 30000)
            //		{
            //			foodSource = thing;
            //			foodDef = RimWorld.FoodUtility.GetFinalIngestibleDef(foodSource);
            //			return true;
            //		}
            //	}
            //}
            //bool allowPlant = getter == eater;
        }