private static void TrySatisfyFoodNeed(Pawn pawn, Need_Food food, Caravan caravan)
 {
     if ((int)food.CurCategory >= 1)
     {
         Thing thing = default(Thing);
         Pawn  pawn2 = default(Pawn);
         if (VirtualPlantsUtility.CanEatVirtualPlantsNow(pawn))
         {
             VirtualPlantsUtility.EatVirtualPlants(pawn);
         }
         else if (CaravanInventoryUtility.TryGetBestFood(caravan, pawn, out thing, out pawn2))
         {
             food.CurLevel += thing.Ingested(pawn, food.NutritionWanted);
             if (thing.Destroyed)
             {
                 if (pawn2 != null)
                 {
                     pawn2.inventory.innerContainer.Remove(thing);
                     caravan.RecacheImmobilizedNow();
                     caravan.RecacheDaysWorthOfFood();
                 }
                 if (!CaravanInventoryUtility.TryGetBestFood(caravan, pawn, out thing, out pawn2))
                 {
                     Messages.Message("MessageCaravanRunOutOfFood".Translate(caravan.LabelCap, pawn.Label), caravan, MessageTypeDefOf.ThreatBig);
                 }
             }
         }
     }
 }
Example #2
0
 private void TrySatisfyFoodNeed(Pawn pawn, Need_Food food)
 {
     if ((int)food.CurCategory >= 1)
     {
         Thing food2;
         Pawn  owner;
         if (VirtualPlantsUtility.CanEatVirtualPlantsNow(pawn))
         {
             VirtualPlantsUtility.EatVirtualPlants(pawn);
         }
         else if (CaravanInventoryUtility.TryGetBestFood(caravan, pawn, out food2, out owner))
         {
             food.CurLevel += food2.Ingested(pawn, food.NutritionWanted);
             if (food2.Destroyed)
             {
                 if (owner != null)
                 {
                     owner.inventory.innerContainer.Remove(food2);
                     caravan.RecacheImmobilizedNow();
                     caravan.RecacheDaysWorthOfFood();
                 }
                 if (!caravan.notifiedOutOfFood && !CaravanInventoryUtility.TryGetBestFood(caravan, pawn, out food2, out owner))
                 {
                     Messages.Message("MessageCaravanRanOutOfFood".Translate(caravan.LabelCap, pawn.Label, pawn.Named("PAWN")), caravan, MessageTypeDefOf.ThreatBig);
                     caravan.notifiedOutOfFood = true;
                 }
             }
         }
     }
 }
Example #3
0
        private void TrySatisfyFoodNeed(Pawn pawn, Need_Food food)
        {
            if (food.CurCategory < HungerCategory.Hungry)
            {
                return;
            }
            if (VirtualPlantsUtility.CanEatVirtualPlantsNow(pawn))
            {
                VirtualPlantsUtility.EatVirtualPlants(pawn);
                return;
            }
            Thing thing;
            Pawn  pawn2;

            if (CaravanInventoryUtility.TryGetBestFood(this.caravan, pawn, out thing, out pawn2))
            {
                food.CurLevel += thing.Ingested(pawn, food.NutritionWanted);
                if (thing.Destroyed)
                {
                    if (pawn2 != null)
                    {
                        pawn2.inventory.innerContainer.Remove(thing);
                        this.caravan.RecacheImmobilizedNow();
                        this.caravan.RecacheDaysWorthOfFood();
                    }
                    if (!this.caravan.notifiedOutOfFood && !CaravanInventoryUtility.TryGetBestFood(this.caravan, pawn, out thing, out pawn2))
                    {
                        Messages.Message("MessageCaravanRanOutOfFood".Translate(this.caravan.LabelCap, pawn.Label, pawn.Named("PAWN")), this.caravan, MessageTypeDefOf.ThreatBig, true);
                        this.caravan.notifiedOutOfFood = true;
                    }
                }
            }
        }
        public bool AnyPawnOutOfFood(out string malnutritionHediff)
        {
            tmpInvFood.Clear();
            List <Thing> list = CaravanInventoryUtility.AllInventoryItems(caravan);

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].def.IsNutritionGivingIngestible)
                {
                    tmpInvFood.Add(list[i]);
                }
            }
            List <Pawn> pawnsListForReading = caravan.PawnsListForReading;

            for (int j = 0; j < pawnsListForReading.Count; j++)
            {
                Pawn pawn = pawnsListForReading[j];
                if (!pawn.RaceProps.EatsFood || VirtualPlantsUtility.CanEatVirtualPlantsNow(pawn))
                {
                    continue;
                }
                bool flag = false;
                for (int k = 0; k < tmpInvFood.Count; k++)
                {
                    if (CaravanPawnsNeedsUtility.CanEatForNutritionEver(tmpInvFood[k].def, pawn))
                    {
                        flag = true;
                        break;
                    }
                }
                if (flag)
                {
                    continue;
                }
                int    num  = -1;
                string text = null;
                for (int l = 0; l < pawnsListForReading.Count; l++)
                {
                    Hediff firstHediffOfDef = pawnsListForReading[l].health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition);
                    if (firstHediffOfDef != null && (text == null || firstHediffOfDef.CurStageIndex > num))
                    {
                        num  = firstHediffOfDef.CurStageIndex;
                        text = firstHediffOfDef.LabelCap;
                    }
                }
                malnutritionHediff = text;
                tmpInvFood.Clear();
                return(true);
            }
            malnutritionHediff = null;
            tmpInvFood.Clear();
            return(false);
        }
        public static bool AnyPawnOutOfFood(Caravan c, out string malnutritionHediff)
        {
            CaravanPawnsNeedsUtility.tmpInvFood.Clear();
            List <Thing> list = CaravanInventoryUtility.AllInventoryItems(c);

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].def.IsNutritionGivingIngestible)
                {
                    CaravanPawnsNeedsUtility.tmpInvFood.Add(list[i]);
                }
            }
            List <Pawn> pawnsListForReading = c.PawnsListForReading;

            for (int j = 0; j < pawnsListForReading.Count; j++)
            {
                Pawn pawn = pawnsListForReading[j];
                if (pawn.RaceProps.EatsFood && !VirtualPlantsUtility.CanEatVirtualPlantsNow(pawn))
                {
                    bool flag = false;
                    int  num  = 0;
                    while (num < CaravanPawnsNeedsUtility.tmpInvFood.Count)
                    {
                        if (!CaravanPawnsNeedsUtility.CanEverEatForNutrition(CaravanPawnsNeedsUtility.tmpInvFood[num].def, pawn))
                        {
                            num++;
                            continue;
                        }
                        flag = true;
                        break;
                    }
                    if (!flag)
                    {
                        int    num2 = -1;
                        string text = null;
                        for (int k = 0; k < pawnsListForReading.Count; k++)
                        {
                            Hediff firstHediffOfDef = pawnsListForReading[k].health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition, false);
                            if (firstHediffOfDef != null && (text == null || firstHediffOfDef.CurStageIndex > num2))
                            {
                                num2 = firstHediffOfDef.CurStageIndex;
                                text = firstHediffOfDef.LabelCap;
                            }
                        }
                        malnutritionHediff = text;
                        return(true);
                    }
                }
            }
            malnutritionHediff = null;
            return(false);
        }