Beispiel #1
0
        public static bool TryGetBestFood(Caravan caravan, Pawn forPawn, out Thing food, out Pawn owner)
        {
            List <Thing> list  = AllInventoryItems(caravan);
            Thing        thing = null;
            float        num   = 0f;

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing2 = list[i];
                if (CaravanPawnsNeedsUtility.CanEatForNutritionNow(thing2, forPawn))
                {
                    float foodScore = CaravanPawnsNeedsUtility.GetFoodScore(thing2, forPawn);
                    if (thing == null || foodScore > num)
                    {
                        thing = thing2;
                        num   = foodScore;
                    }
                }
            }
            if (thing != null)
            {
                food  = thing;
                owner = GetOwnerOf(caravan, thing);
                return(true);
            }
            food  = null;
            owner = null;
            return(false);
        }
 private static void TrySatisfyPawnNeeds(Pawn pawn, Caravan caravan)
 {
     if (!pawn.Dead)
     {
         List <Need> allNeeds = pawn.needs.AllNeeds;
         for (int i = 0; i < allNeeds.Count; i++)
         {
             Need          need          = allNeeds[i];
             Need_Rest     need_Rest     = need as Need_Rest;
             Need_Food     need_Food     = need as Need_Food;
             Need_Chemical need_Chemical = need as Need_Chemical;
             if (need_Rest != null)
             {
                 CaravanPawnsNeedsUtility.TrySatisfyRestNeed(pawn, need_Rest, caravan);
             }
             else if (need_Food != null)
             {
                 CaravanPawnsNeedsUtility.TrySatisfyFoodNeed(pawn, need_Food, caravan);
             }
             else if (need_Chemical != null)
             {
                 CaravanPawnsNeedsUtility.TrySatisfyChemicalNeed(pawn, need_Chemical, caravan);
             }
         }
     }
 }
Beispiel #3
0
        private static int BestEverEdibleFoodIndexFor(Pawn pawn, List <ThingDefCount> food)
        {
            int   num  = -1;
            float num2 = 0f;
            int   i    = 0;

            for (int count = food.Count; i < count; i++)
            {
                if (food[i].Count <= 0)
                {
                    continue;
                }
                ThingDef thingDef = food[i].ThingDef;
                if (CaravanPawnsNeedsUtility.CanEatForNutritionEver(thingDef, pawn))
                {
                    float foodScore = CaravanPawnsNeedsUtility.GetFoodScore(thingDef, pawn, thingDef.ingestible.CachedNutrition);
                    if (num < 0 || foodScore > num2)
                    {
                        num  = i;
                        num2 = foodScore;
                    }
                }
            }
            return(num);
        }
Beispiel #4
0
        private static void TrySatisfyJoyNeed(Pawn pawn, Need_Joy joy, Caravan caravan)
        {
            float currentJoyGainPerTick = CaravanPawnsNeedsUtility.GetCurrentJoyGainPerTick(pawn, caravan);

            if (currentJoyGainPerTick > 0f)
            {
                joy.GainJoy(currentJoyGainPerTick, JoyKindDefOf.Social);
            }
        }
        public static void TrySatisfyPawnsNeeds(Caravan caravan)
        {
            List <Pawn> pawnsListForReading = caravan.PawnsListForReading;

            for (int num = pawnsListForReading.Count - 1; num >= 0; num--)
            {
                CaravanPawnsNeedsUtility.TrySatisfyPawnNeeds(pawnsListForReading[num], caravan);
            }
        }
        private static void TrySatisfyChemicalNeed(Pawn pawn, Need_Chemical chemical, Caravan caravan)
        {
            Thing drug      = default(Thing);
            Pawn  drugOwner = default(Pawn);

            if ((int)chemical.CurCategory < 2 && CaravanInventoryUtility.TryGetBestDrug(caravan, pawn, chemical, out drug, out drugOwner))
            {
                CaravanPawnsNeedsUtility.IngestDrug(pawn, drug, drugOwner, caravan);
            }
        }
 public static bool CanNowEatForNutrition(Thing food, Pawn pawn)
 {
     if (!food.IngestibleNow)
     {
         return(false);
     }
     if (!CaravanPawnsNeedsUtility.CanNowEatForNutrition(food.def, pawn))
     {
         return(false);
     }
     return(true);
 }
 public static bool CanNowEatForNutrition(ThingDef food, Pawn pawn)
 {
     if (!CaravanPawnsNeedsUtility.CanEverEatForNutrition(food, pawn))
     {
         return(false);
     }
     if (pawn.RaceProps.Humanlike && (int)pawn.needs.food.CurCategory < 3 && (int)food.ingestible.preferability <= 3)
     {
         return(false);
     }
     return(true);
 }
Beispiel #9
0
 private static void TrySatisfyChemicalNeed(Pawn pawn, Need_Chemical chemical, Caravan caravan)
 {
     if (chemical.CurCategory < DrugDesireCategory.Satisfied)
     {
         Thing drug;
         Pawn  drugOwner;
         if (CaravanInventoryUtility.TryGetDrugToSatisfyChemicalNeed(caravan, pawn, chemical, out drug, out drugOwner))
         {
             CaravanPawnsNeedsUtility.IngestDrug(pawn, drug, drugOwner, caravan);
         }
     }
 }
        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);
        }
        public static float GetFoodScore(Thing food, Pawn pawn)
        {
            float num = CaravanPawnsNeedsUtility.GetFoodScore(food.def, pawn, food.GetStatValue(StatDefOf.Nutrition, true));

            if (pawn.RaceProps.Humanlike)
            {
                CompRottable compRottable = food.TryGetComp <CompRottable>();
                int          a            = (compRottable == null) ? int.MaxValue : compRottable.TicksUntilRotAtCurrentTemp;
                float        a2           = 1f - (float)Mathf.Min(a, 3600000) / 3600000f;
                num += Mathf.Min(a2, 0.999f);
            }
            return(num);
        }
        public static float GetFoodScore(Thing food, Pawn pawn)
        {
            float num = CaravanPawnsNeedsUtility.GetFoodScore(food.def, pawn);

            if (pawn.RaceProps.Humanlike)
            {
                CompRottable compRottable = food.TryGetComp <CompRottable>();
                int          a            = (compRottable == null) ? 2147483647 : compRottable.TicksUntilRotAtCurrentTemp;
                float        a2           = (float)(1.0 - (float)Mathf.Min(a, 3600000) / 3600000.0);
                num += Mathf.Min(a2, 0.999f);
            }
            return(num);
        }
Beispiel #14
0
 public override void Tick()
 {
     base.Tick();
     this.CheckAnyNonWorldPawns();
     this.pather.PatherTick();
     this.tweener.TweenerTick();
     CaravanPawnsNeedsUtility.TrySatisfyPawnsNeeds(this);
     if (this.IsHashIntervalTick(120))
     {
         CaravanDrugPolicyUtility.TryTakeScheduledDrugs(this);
     }
     if (this.IsHashIntervalTick(2000))
     {
         CaravanTendUtility.TryTendToRandomPawn(this);
     }
 }
Beispiel #15
0
 private static void TryTakeScheduledDrugs(Pawn pawn, Caravan caravan)
 {
     if (pawn.drugs != null)
     {
         DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy;
         for (int i = 0; i < currentPolicy.Count; i++)
         {
             Thing drug      = default(Thing);
             Pawn  drugOwner = default(Pawn);
             if (pawn.drugs.ShouldTryToTakeScheduledNow(currentPolicy[i].drug) && CaravanInventoryUtility.TryGetThingOfDef(caravan, currentPolicy[i].drug, out drug, out drugOwner))
             {
                 CaravanPawnsNeedsUtility.IngestDrug(pawn, drug, drugOwner, caravan);
             }
         }
     }
 }
        private static int BestEverEdibleFoodIndexFor(Pawn pawn, List <ThingCount> food)
        {
            int   num  = -1;
            float num2 = 0f;

            for (int i = 0; i < food.Count; i++)
            {
                if (food[i].Count > 0)
                {
                    ThingDef thingDef = food[i].ThingDef;
                    if (CaravanPawnsNeedsUtility.CanEverEatForNutrition(thingDef, pawn))
                    {
                        float foodScore = CaravanPawnsNeedsUtility.GetFoodScore(thingDef, pawn);
                        if (num < 0 || foodScore > num2)
                        {
                            num  = i;
                            num2 = foodScore;
                        }
                    }
                }
            }
            return(num);
        }
 public static bool CanNowEatForNutrition(Thing food, Pawn pawn)
 {
     return(food.IngestibleNow && CaravanPawnsNeedsUtility.CanNowEatForNutrition(food.def, pawn));
 }
 public static bool CanNowEatForNutrition(ThingDef food, Pawn pawn)
 {
     return(CaravanPawnsNeedsUtility.CanEverEatForNutrition(food, pawn) && (!pawn.RaceProps.Humanlike || pawn.needs.food.CurCategory >= HungerCategory.Starving || food.ingestible.preferability > FoodPreferability.DesperateOnlyForHumanlikes));
 }
Beispiel #19
0
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(base.GetInspectString());
            if (stringBuilder.Length != 0)
            {
                stringBuilder.AppendLine();
            }
            if (this.Resting)
            {
                stringBuilder.Append("CaravanResting".Translate());
            }
            else if (this.AnyPawnHasExtremeMentalBreak)
            {
                stringBuilder.Append("CaravanMemberMentalBreak".Translate(new object[]
                {
                    this.FirstPawnWithExtremeMentalBreak.LabelShort
                }));
            }
            else if (this.AllOwnersDowned)
            {
                stringBuilder.Append("AllCaravanMembersDowned".Translate());
            }
            else if (this.AllOwnersHaveMentalBreak)
            {
                stringBuilder.Append("AllCaravanMembersMentalBreak".Translate());
            }
            else if (this.pather.Moving)
            {
                if (this.pather.arrivalAction != null)
                {
                    stringBuilder.Append(this.pather.arrivalAction.ReportString);
                }
                else
                {
                    stringBuilder.Append("CaravanTraveling".Translate());
                }
            }
            else
            {
                Settlement settlement = CaravanVisitUtility.SettlementVisitedNow(this);
                if (settlement != null)
                {
                    stringBuilder.Append("CaravanVisiting".Translate(new object[]
                    {
                        settlement.Label
                    }));
                }
                else
                {
                    stringBuilder.Append("CaravanWaiting".Translate());
                }
            }
            if (this.pather.Moving)
            {
                float num = (float)CaravanArrivalTimeEstimator.EstimatedTicksToArrive(this, true) / 60000f;
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanEstimatedTimeToDestination".Translate(new object[]
                {
                    num.ToString("0.#")
                }));
            }
            if (this.ImmobilizedByMass)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanImmobilizedByMass".Translate());
            }
            string text;

            if (CaravanPawnsNeedsUtility.AnyPawnOutOfFood(this, out text))
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanOutOfFood".Translate());
                if (!text.NullOrEmpty())
                {
                    stringBuilder.Append(" ");
                    stringBuilder.Append(text);
                    stringBuilder.Append(".");
                }
            }
            else if (this.DaysWorthOfFood.First < 1000f)
            {
                Pair <float, float> daysWorthOfFood = this.DaysWorthOfFood;
                stringBuilder.AppendLine();
                if (daysWorthOfFood.Second < 1000f)
                {
                    stringBuilder.Append("CaravanDaysOfFoodRot".Translate(new object[]
                    {
                        daysWorthOfFood.First.ToString("0.#"),
                        daysWorthOfFood.Second.ToString("0.#")
                    }));
                }
                else
                {
                    stringBuilder.Append("CaravanDaysOfFood".Translate(new object[]
                    {
                        daysWorthOfFood.First.ToString("0.#")
                    }));
                }
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine(string.Concat(new string[]
            {
                "CaravanBaseMovementTime".Translate(),
                ": ",
                ((float)this.TicksPerMove / 2500f).ToString("0.##"),
                " ",
                "CaravanHoursPerTile".Translate()
            }));
            stringBuilder.AppendLine("CurrentTileMovementTime".Translate() + ": " + Caravan_PathFollower.CostToDisplay(this, base.Tile, this.pather.nextTile, -1f).ToStringTicksToPeriod(true, false, true));
            stringBuilder.Append("StealthFactor".Translate() + ": " + CaravanIncidentUtility.CalculateCaravanStealthFactor(this.PawnsListForReading.Count).ToString("F1"));
            return(stringBuilder.ToString());
        }