Example #1
0
        // RimWorld.Planet.CaravanInventoryUtility
        public static bool TryGetBestFood(Pawn vehicle, Pawn forPawn, out Thing food, out Pawn owner)
        {
            List <Thing> list  = vehicle?.inventory?.innerContainer?.InnerListForReading;
            Thing        thing = null;
            float        num   = 0f;

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing2 = list[i];
                if (CompVehicleUtility.CanNowEatForNutrition(thing2, forPawn))
                {
                    float foodScore = CaravanPawnsNeedsUtility.GetFoodScore(thing2, forPawn);
                    if (thing == null || foodScore > num)
                    {
                        thing = thing2;
                        num   = foodScore;
                    }
                }
            }
            if (thing != null)
            {
                food  = thing;
                owner = forPawn; //CaravanInventoryUtility.GetOwnerOf(caravan, thing);
                return(true);
            }
            food  = null;
            owner = null;
            return(false);
        }
Example #2
0
        // RimWorld.Planet.CaravanPawnsNeedsUtility
        public static void TrySatisfyFoodNeed(Pawn pawn, Need_Food food, Pawn vehicle)
        {
            if (food.CurCategory < HungerCategory.Hungry)
            {
                return;
            }
            Thing thing;
            Pawn  pawn2;

            if (VirtualPlantsUtility.CanEatVirtualPlantsNow(pawn))
            {
                VirtualPlantsUtility.EatVirtualPlants(pawn);
            }
            else if (CompVehicleUtility.TryGetBestFood(vehicle, pawn, out thing, out pawn2))
            {
                food.CurLevel += thing.Ingested(pawn, food.NutritionWanted);
                if (thing.Destroyed)
                {
                    if (pawn2 != null)
                    {
                        vehicle.inventory.innerContainer.Remove(thing);
                        //caravan.RecacheImmobilizedNow();
                        //caravan.RecacheDaysWorthOfFood();
                    }
                    //if (!CompVehicleUtility.TryGetBestFood(vehicle, pawn, out thing, out pawn2))
                    //{
                    //    Messages.Message("MessageCaravanRunOutOfFood".Translate(new object[]
                    //    {
                    //caravan.LabelCap,
                    //pawn.Label
                    //    }), caravan, MessageSound.SeriousAlert);
                    //}
                }
            }
        }
Example #3
0
        // RimWorld.Planet.CaravanPawnsNeedsUtility
        public static void TrySatisfyChemicalNeed(Pawn pawn, Need_Chemical chemical, Pawn vehicle)
        {
            if (chemical.CurCategory >= DrugDesireCategory.Satisfied)
            {
                return;
            }
            Thing drug;
            Pawn  drugOwner;

            if (CompVehicleUtility.TryGetBestDrug(vehicle, pawn, chemical, out drug, out drugOwner))
            {
                CompVehicleUtility.IngestDrug(pawn, drug, drugOwner, vehicle);
            }
        }
Example #4
0
 // ------ Additions made by Swenzi ------
 //Purpose: Reduce the needs of pawns while in the vehicle
 //Logic: Prevent cryosleep gimmicks by storing pawns in vehicles forever
 //To prevent unneccessary patching of game methods, needs are modified by this function
 //Improvements: Mood modifiers if they stay too long? Traits effecting mood? Driving Experience?
 //
 //Addendum by Jecrell:
 //-Added the ability for some pawns to resolve needs inside the vehicle.
 //-Prevent needs from falling while resting.
 public void ResolveNeeds()
 {
     //Player only, NPC factions is weird unless better logic is make them go back to vehicles after being ejected
     if (Pawn.Faction.IsPlayer)
     {
         if (handlers != null && handlers.Count > 0)
         {
             foreach (var group in handlers)
             {
                 if ((group?.handlers?.Count ?? 0) > 0)
                 {
                     for (var i = 0; i < group.handlers.Count; i++)
                     {
                         var pawn = group.handlers[i];
                         //Don't change needs while a caravan member.
                         if (pawn.IsCaravanMember())
                         {
                             continue;
                         }
                         var pawn_needs = pawn.needs.AllNeeds;
                         //These needs are major and should change
                         for (var j = 0; j < pawn_needs.Count; j++)
                         {
                             if (pawn_needs[j] is Need_Rest need_Rest)
                             {
                                 pawn_needs[j].CurLevel -= Props.restNeedRate;
                                 CompVehicleUtility.TrySatisfyRestNeed(pawn, need_Rest, Pawn);
                             }
                             if (pawn_needs[j] is Need_Food need_Food)
                             {
                                 pawn_needs[j].CurLevel -= Props.foodNeedRate;
                                 CompVehicleUtility.TrySatisfyFoodNeed(pawn, need_Food, Pawn);
                             }
                             if (pawn_needs[j] is Need_Chemical need_Chemical)
                             {
                                 pawn_needs[j].CurLevel -= Props.foodNeedRate;
                                 CompVehicleUtility.TrySatisfyChemicalNeed(pawn, need_Chemical, Pawn);
                             }
                             if (pawn_needs[j].def == NeedDefOf.Joy)
                             {
                                 pawn_needs[j].CurLevel -= Props.joyNeedRate;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Example #5
0
 // RimWorld.Planet.CaravanPawnsNeedsUtility
 public static bool CanNowEatForNutrition(Thing food, Pawn pawn)
 {
     return(food.IngestibleNow && CompVehicleUtility.CanNowEatForNutrition(food.def, pawn));
 }
Example #6
0
 // RimWorld.Planet.CaravanPawnsNeedsUtility
 public static bool CanNowEatForNutrition(ThingDef food, Pawn pawn)
 {
     return(CompVehicleUtility.CanEverEatForNutrition(food, pawn) && (pawn.needs.food.CurCategory >= HungerCategory.Starving || food.ingestible.preferability > FoodPreferability.DesperateOnly));
 }