예제 #1
0
 public void MapInterfaceUpdate()
 {
     if (Find.VisibleMap != null && !WorldRendererUtility.WorldRenderedNow)
     {
         this.targeter.TargeterUpdate();
         SelectionDrawer.DrawSelectionOverlays();
         EnvironmentInspectDrawer.DrawRoomOverlays();
         this.designatorManager.DesignatorManagerUpdate();
         Find.VisibleMap.roofGrid.RoofGridUpdate();
         Find.VisibleMap.exitMapGrid.ExitMapGridUpdate();
         Find.VisibleMap.deepResourceGrid.DeepResourceGridUpdate();
         if (DebugViewSettings.drawPawnDebug)
         {
             Find.VisibleMap.pawnDestinationReservationManager.DebugDrawDestinations();
             Find.VisibleMap.reservationManager.DebugDrawReservations();
         }
         if (DebugViewSettings.drawFoodSearchFromMouse)
         {
             FoodUtility.DebugFoodSearchFromMouse_Update();
         }
         if (DebugViewSettings.drawPreyInfo)
         {
             FoodUtility.DebugDrawPredatorFoodSource();
         }
         if (DebugViewSettings.drawAttackTargetScores)
         {
             AttackTargetFinder.DebugDrawAttackTargetScores_Update();
         }
         MiscDebugDrawer.DebugDrawInteractionCells();
         Find.VisibleMap.debugDrawer.DebugDrawerUpdate();
         Find.VisibleMap.regionGrid.DebugDraw();
         InfestationCellFinder.DebugDraw();
         StealAIDebugDrawer.DebugDraw();
         if (DebugViewSettings.drawRiverDebug)
         {
             Find.VisibleMap.waterInfo.DebugDrawRiver();
         }
     }
 }
 private void <ReserveFoodIfWillIngestWholeStack> m__0()
 {
     if (this.pawn.Faction != null)
     {
         Thing thing = this.job.GetTarget(TargetIndex.A).Thing;
         if (this.pawn.carryTracker.CarriedThing != thing)
         {
             int num = FoodUtility.WillIngestStackCountOf(this.pawn, thing.def, thing.GetStatValue(StatDefOf.Nutrition, true));
             if (num >= thing.stackCount)
             {
                 if (!thing.Spawned)
                 {
                     this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                 }
                 else
                 {
                     this.pawn.Reserve(thing, this.job, 1, -1, null);
                 }
             }
         }
     }
 }
예제 #3
0
 public void MapInterfaceOnGUI_BeforeMainTabs()
 {
     if (Find.CurrentMap == null)
     {
         return;
     }
     if (!WorldRendererUtility.WorldRenderedNow)
     {
         ScreenshotModeHandler screenshotMode = Find.UIRoot.screenshotMode;
         this.thingOverlays.ThingOverlaysOnGUI();
         MapComponentUtility.MapComponentOnGUI(Find.CurrentMap);
         BeautyDrawer.BeautyDrawerOnGUI();
         if (!screenshotMode.FiltersCurrentEvent)
         {
             this.colonistBar.ColonistBarOnGUI();
         }
         this.selector.dragBox.DragBoxOnGUI();
         this.designatorManager.DesignationManagerOnGUI();
         this.targeter.TargeterOnGUI();
         Find.CurrentMap.tooltipGiverList.DispenseAllThingTooltips();
         if (DebugViewSettings.drawFoodSearchFromMouse)
         {
             FoodUtility.DebugFoodSearchFromMouse_OnGUI();
         }
         if (DebugViewSettings.drawAttackTargetScores)
         {
             AttackTargetFinder.DebugDrawAttackTargetScores_OnGUI();
         }
         if (!screenshotMode.FiltersCurrentEvent)
         {
             this.globalControls.GlobalControlsOnGUI();
             this.resourceReadout.ResourceReadoutOnGUI();
         }
     }
     else
     {
         this.targeter.StopTargeting();
     }
 }
        private Toil StartFeedAnimal(TargetIndex tameeInd)
        {
            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn actor = toil.GetActor();
                Pawn pawn  = (Pawn)((Thing)actor.CurJob.GetTarget(tameeInd));
                PawnUtility.ForceWait(pawn, 270, actor, false);
                Thing thing = FoodUtility.BestFoodInInventory(actor, pawn, FoodPreferability.NeverForNutrition, FoodPreferability.RawTasty, 0f, false);
                if (thing == null)
                {
                    actor.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                    return;
                }
                actor.mindState.lastInventoryRawFoodUseTick = Find.TickManager.TicksGame;
                int   num        = FoodUtility.StackCountForNutrition(thing.def, this.feedNutritionLeft);
                int   stackCount = thing.stackCount;
                Thing thing2     = actor.inventory.innerContainer.Take(thing, Mathf.Min(num, stackCount));
                actor.carryTracker.TryStartCarry(thing2);
                actor.CurJob.SetTarget(TargetIndex.B, thing2);
                float num2 = (float)thing2.stackCount * thing2.def.ingestible.nutrition;
                this.ticksLeftThisToil = Mathf.CeilToInt(270f * (num2 / JobDriver_InteractAnimal.RequiredNutritionPerFeed(pawn)));
                if (num <= stackCount)
                {
                    this.feedNutritionLeft = 0f;
                }
                else
                {
                    this.feedNutritionLeft -= num2;
                    if (this.feedNutritionLeft < 0.001f)
                    {
                        this.feedNutritionLeft = 0f;
                    }
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            return(toil);
        }
        public override float GetPriority(Pawn pawn)
        {
            Need_Food food = pawn.needs.food;

            if (food == null)
            {
                return(0f);
            }
            if (pawn.needs.food.CurCategory < HungerCategory.Starving && FoodUtility.ShouldBeFedBySomeone(pawn))
            {
                return(0f);
            }
            if (food.CurCategory < this.minCategory)
            {
                return(0f);
            }
            if (food.CurLevelPercentage < pawn.RaceProps.FoodLevelPercentageWantEat)
            {
                return(9.5f);
            }
            return(0f);
        }
예제 #6
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Pawn pawn2 = t as Pawn;

            if (pawn2 != null && pawn2 != pawn)
            {
                if (base.def.feedHumanlikesOnly && !pawn2.RaceProps.Humanlike)
                {
                    return(false);
                }
                if (base.def.feedAnimalsOnly && !pawn2.RaceProps.Animal)
                {
                    return(false);
                }
                if (pawn2.needs.food != null && !(pawn2.needs.food.CurLevelPercentage > pawn2.needs.food.PercentageThreshHungry + 0.019999999552965164))
                {
                    if (!FeedPatientUtility.ShouldBeFed(pawn2))
                    {
                        return(false);
                    }
                    LocalTargetInfo target = t;
                    if (!pawn.CanReserve(target, 1, -1, null, forced))
                    {
                        return(false);
                    }
                    Thing    thing    = default(Thing);
                    ThingDef thingDef = default(ThingDef);
                    if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn2, pawn2.needs.food.CurCategory == HungerCategory.Starving, out thing, out thingDef, false, true, false, true, false, false))
                    {
                        JobFailReason.Is("NoFood".Translate());
                        return(false);
                    }
                    return(true);
                }
                return(false);
            }
            return(false);
        }
예제 #7
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Pawn pawn2 = t as Pawn;

            if (pawn2 == null || pawn2 == pawn)
            {
                return(false);
            }
            if (def.feedHumanlikesOnly && !pawn2.RaceProps.Humanlike)
            {
                return(false);
            }
            if (def.feedAnimalsOnly && !pawn2.RaceProps.Animal)
            {
                return(false);
            }
            if (pawn2.needs.food == null || pawn2.needs.food.CurLevelPercentage > pawn2.needs.food.PercentageThreshHungry + 0.02f)
            {
                return(false);
            }
            if (!FeedPatientUtility.ShouldBeFed(pawn2))
            {
                return(false);
            }
            LocalTargetInfo target = t;
            bool            ignoreOtherReservations = forced;

            if (!pawn.CanReserve(target, 1, -1, null, ignoreOtherReservations))
            {
                return(false);
            }
            if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn2, pawn2.needs.food.CurCategory == HungerCategory.Starving, out Thing _, out ThingDef _, canRefillDispenser: false))
            {
                JobFailReason.Is("NoFood".Translate());
                return(false);
            }
            return(true);
        }
        // Token: 0x060003E2 RID: 994 RVA: 0x000280A0 File Offset: 0x000264A0
        public override bool TryMakePreToilReservations(bool errorOnFailed)
        {
            if (this.pawn.Faction != null && !(this.IngestibleSource is Building_NutrientPasteDispenser))
            {
                Thing ingestibleSource = this.IngestibleSource;
                if (ingestibleSource == null)
                {
                    return(false);
                }
                if (ingestibleSource.def == null)
                {
                    return(false);
                }

                try
                {
                    int num = FoodUtility.WillIngestStackCountOf(this.pawn, ingestibleSource.def, ingestibleSource.GetStatValue(StatDefOf.Nutrition, true) + 1);
                    if (num >= ingestibleSource.stackCount && ingestibleSource.Spawned)
                    {
                        Pawn            pawn   = this.pawn;
                        LocalTargetInfo target = ingestibleSource;
                        Job             job    = this.job;
                        if (!pawn.Reserve(target, job, 1, -1, null, errorOnFailed))
                        {
                            return(false);
                        }
                    }
                }
                catch (Exception)
                {
                    //    Log.Message(string.Format("pawn: {0}", pawn));
                    //    Log.Message(string.Format("ingestibleSource.def: {0}", ingestibleSource.def));
                    //    Log.Message(string.Format("Nutrition: {0}", ingestibleSource.GetStatValue(StatDefOf.Nutrition, true)));
                    return(false);
                }
            }
            return(true);
        }
            internal bool <> m__0(Thing t)
            {
                if (!this.$this.IsGoodPackableFoodFor(t, this.pawn) || t.IsForbidden(this.pawn) || !this.pawn.CanReserve(t, 1, -1, null, false) || !t.IsSociallyProper(this.pawn))
                {
                    return(false);
                }
                float num = this.invNutrition + t.GetStatValue(StatDefOf.Nutrition, true) * (float)t.stackCount;

                if (num < 0.8f)
                {
                    return(false);
                }
                List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(this.pawn, t, FoodUtility.GetFinalIngestibleDef(t, false));

                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].stages[0].baseMoodEffect < 0f)
                    {
                        return(false);
                    }
                }
                return(true);
            }
예제 #10
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Pawn     pawn2 = (Pawn)t;
            Thing    thing;
            ThingDef thingDef;
            Job      result;

            if (FoodUtility.TryFindBestFoodSourceFor(pawn, pawn2, pawn2.needs.food.CurCategory == HungerCategory.Starving, out thing, out thingDef, false, true, false, true, false, false, false))
            {
                float nutrition = FoodUtility.GetNutrition(thing, thingDef);
                result = new Job(JobDefOf.FeedPatient)
                {
                    targetA = thing,
                    targetB = pawn2,
                    count   = FoodUtility.WillIngestStackCountOf(pawn2, thingDef, nutrition)
                };
            }
            else
            {
                result = null;
            }
            return(result);
        }
예제 #11
0
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Job result;

            if (!base.ShouldTakeCareOfPrisoner(pawn, t))
            {
                result = null;
            }
            else
            {
                Pawn     pawn2 = (Pawn)t;
                Thing    thing;
                ThingDef thingDef;
                if (!WardenFeedUtility.ShouldBeFed(pawn2))
                {
                    result = null;
                }
                else if (pawn2.needs.food.CurLevelPercentage >= pawn2.needs.food.PercentageThreshHungry + 0.02f)
                {
                    result = null;
                }
                else if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn2, pawn2.needs.food.CurCategory == HungerCategory.Starving, out thing, out thingDef, false, true, false, false, false, false, false))
                {
                    JobFailReason.Is("NoFood".Translate(), null);
                    result = null;
                }
                else
                {
                    float nutrition = FoodUtility.GetNutrition(thing, thingDef);
                    result = new Job(JobDefOf.FeedPatient, thing, pawn2)
                    {
                        count = FoodUtility.WillIngestStackCountOf(pawn2, thingDef, nutrition)
                    };
                }
            }
            return(result);
        }
예제 #12
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            PawnDuty duty = pawn.mindState.duty;

            if (duty == null)
            {
                return(null);
            }
            if ((double)pawn.needs.food.CurLevelPercentage > 0.9)
            {
                return(null);
            }
            IntVec3 cell  = duty.focus.Cell;
            Thing   thing = FindFood(pawn, cell);

            if (thing == null)
            {
                return(null);
            }
            Job job = JobMaker.MakeJob(JobDefOf.Ingest, thing);

            job.count = FoodUtility.WillIngestStackCountOf(pawn, thing.def, thing.def.GetStatValueAbstract(StatDefOf.Nutrition));
            return(job);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            Job result;

            if (pawn.inventory == null)
            {
                result = null;
            }
            else
            {
                float invNutrition = this.GetInventoryPackableFoodNutrition(pawn);
                if (invNutrition > 0.4f)
                {
                    result = null;
                }
                else if (pawn.Map.resourceCounter.TotalHumanEdibleNutrition < (float)pawn.Map.mapPawns.ColonistsSpawnedCount * 1.5f)
                {
                    result = null;
                }
                else
                {
                    Thing thing = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(pawn.Position, pawn.Map, ThingRequest.ForGroup(ThingRequestGroup.FoodSourceNotPlantOrTree), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 20f, delegate(Thing t)
                    {
                        bool result2;
                        if (!this.IsGoodPackableFoodFor(t, pawn) || t.IsForbidden(pawn) || !pawn.CanReserve(t, 1, -1, null, false) || !t.IsSociallyProper(pawn))
                        {
                            result2 = false;
                        }
                        else
                        {
                            float num3 = invNutrition + t.GetStatValue(StatDefOf.Nutrition, true) * (float)t.stackCount;
                            if (num3 < 0.8f)
                            {
                                result2 = false;
                            }
                            else
                            {
                                List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(pawn, t, FoodUtility.GetFinalIngestibleDef(t, false));
                                for (int i = 0; i < list.Count; i++)
                                {
                                    if (list[i].stages[0].baseMoodEffect < 0f)
                                    {
                                        return(false);
                                    }
                                }
                                result2 = true;
                            }
                        }
                        return(result2);
                    }, (Thing x) => FoodUtility.FoodOptimality(pawn, x, FoodUtility.GetFinalIngestibleDef(x, false), 0f, false), 24, 30);
                    if (thing == null)
                    {
                        result = null;
                    }
                    else
                    {
                        float num  = pawn.needs.food.MaxLevel - invNutrition;
                        int   num2 = Mathf.FloorToInt(num / thing.GetStatValue(StatDefOf.Nutrition, true));
                        num2   = Mathf.Min(num2, thing.stackCount);
                        num2   = Mathf.Max(num2, 1);
                        result = new Job(JobDefOf.TakeInventory, thing)
                        {
                            count = num2
                        };
                    }
                }
            }
            return(result);
        }
예제 #14
0
        private static Pawn BestPawnToHuntForPredator(Pawn predator)
        {
            if (predator.meleeVerbs.TryGetMeleeVerb() == null)
            {
                return(null);
            }
            bool  flag = false;
            float summaryHealthPercent = predator.health.summaryHealth.SummaryHealthPercent;

            if (summaryHealthPercent < 0.25)
            {
                flag = true;
            }
            List <Pawn> allPawnsSpawned = predator.Map.mapPawns.AllPawnsSpawned;
            Pawn        pawn            = null;
            float       num             = 0f;
            bool        tutorialMode    = TutorSystem.TutorialMode;

            for (int i = 0; i < allPawnsSpawned.Count; i++)
            {
                Pawn pawn2 = allPawnsSpawned[i];
                if (predator.GetRoom(RegionType.Set_Passable) == pawn2.GetRoom(RegionType.Set_Passable) && predator != pawn2 && (!flag || pawn2.Downed) && FoodUtility.IsAcceptablePreyFor(predator, pawn2) && predator.CanReach(pawn2, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn) && !pawn2.IsForbidden(predator) && (!tutorialMode || pawn2.Faction != Faction.OfPlayer))
                {
                    float preyScoreFor = FoodUtility.GetPreyScoreFor(predator, pawn2);
                    if (preyScoreFor > num || pawn == null)
                    {
                        num  = preyScoreFor;
                        pawn = pawn2;
                    }
                }
            }
            return(pawn);
        }
 internal float <> m__1(Thing x)
 {
     return(FoodUtility.FoodOptimality(this.pawn, x, FoodUtility.GetFinalIngestibleDef(x, false), 0f, false));
 }
예제 #16
0
        public static Thing BestFoodSourceOnMap(Pawn getter, Pawn eater, bool desperate, out ThingDef foodDef, FoodPreferability maxPref = FoodPreferability.MealLavish, bool allowPlant = true, bool allowDrug = true, bool allowCorpse = true, bool allowDispenserFull = true, bool allowDispenserEmpty = true, bool allowForbidden = false, bool allowSociallyImproper = false, bool allowHarvest = false)
        {
            foodDef = null;
            bool getterCanManipulate = getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation);

            if (!getterCanManipulate && getter != eater)
            {
                Log.Error(getter + " tried to find food to bring to " + eater + " but " + getter + " is incapable of Manipulation.");
                return(null);
            }
            FoodPreferability minPref;

            if (eater.NonHumanlikeOrWildMan())
            {
                minPref = FoodPreferability.NeverForNutrition;
            }
            else if (desperate)
            {
                minPref = FoodPreferability.DesperateOnly;
            }
            else
            {
                minPref = (FoodPreferability)(((int)eater.needs.food.CurCategory <= 2) ? 4 : 6);
            }
            Predicate <Thing> foodValidator = delegate(Thing t)
            {
                if (!allowForbidden && t.IsForbidden(getter))
                {
                    return(false);
                }
                Building_NutrientPasteDispenser building_NutrientPasteDispenser = t as Building_NutrientPasteDispenser;
                if (building_NutrientPasteDispenser != null)
                {
                    if (allowDispenserFull && (int)ThingDefOf.MealNutrientPaste.ingestible.preferability >= (int)minPref && (int)ThingDefOf.MealNutrientPaste.ingestible.preferability <= (int)maxPref && getterCanManipulate && !getter.IsWildMan() && (t.Faction == getter.Faction || t.Faction == getter.HostFaction) && building_NutrientPasteDispenser.powerComp.PowerOn && (allowDispenserEmpty || building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers()) && FoodUtility.IsFoodSourceOnMapSociallyProper(t, getter, eater, allowSociallyImproper) && t.InteractionCell.Standable(t.Map) && getter.Map.reachability.CanReachNonLocal(getter.Position, new TargetInfo(t.InteractionCell, t.Map, false), PathEndMode.OnCell, TraverseParms.For(getter, Danger.Some, TraverseMode.ByPawn, false)))
                    {
                        goto IL_025e;
                    }
                    return(false);
                }
                if ((int)t.def.ingestible.preferability < (int)minPref)
                {
                    return(false);
                }
                if ((int)t.def.ingestible.preferability > (int)maxPref)
                {
                    return(false);
                }
                if (t.IngestibleNow && t.def.IsNutritionGivingIngestible && (allowCorpse || !(t is Corpse)) && (allowDrug || !t.def.IsDrug) && (desperate || !t.IsNotFresh()) && !t.IsDessicated() && eater.RaceProps.WillAutomaticallyEat(t) && FoodUtility.IsFoodSourceOnMapSociallyProper(t, getter, eater, allowSociallyImproper) && getter.AnimalAwareOf(t) && getter.CanReserve(t, 1, -1, null, false))
                {
                    goto IL_025e;
                }
                return(false);

IL_025e:
                return(true);
            };
            ThingRequest thingRequest = ((eater.RaceProps.foodType & (FoodTypeFlags.Plant | FoodTypeFlags.Tree)) == FoodTypeFlags.None || !allowPlant) ? ThingRequest.ForGroup(ThingRequestGroup.FoodSourceNotPlantOrTree) : ThingRequest.ForGroup(ThingRequestGroup.FoodSource);
            Thing        bestThing;

            if (getter.RaceProps.Humanlike)
            {
                Pawn              eater2         = eater;
                IntVec3           position       = getter.Position;
                List <Thing>      searchSet      = getter.Map.listerThings.ThingsMatching(thingRequest);
                PathEndMode       peMode         = PathEndMode.ClosestTouch;
                TraverseParms     traverseParams = TraverseParms.For(getter, Danger.Deadly, TraverseMode.ByPawn, false);
                Predicate <Thing> validator      = foodValidator;
                bestThing = FoodUtility.SpawnedFoodSearchInnerScan(eater2, position, searchSet, peMode, traverseParams, 9999f, validator);
                if (allowHarvest && getterCanManipulate)
                {
                    Thing thing = GenClosest.ClosestThingReachable(getter.Position, getter.Map, ThingRequest.ForGroup(ThingRequestGroup.HarvestablePlant), PathEndMode.Touch, TraverseParms.For(getter, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, delegate(Thing x)
                    {
                        Plant plant = (Plant)x;
                        if (!plant.HarvestableNow)
                        {
                            return(false);
                        }
                        ThingDef harvestedThingDef = plant.def.plant.harvestedThingDef;
                        if (!harvestedThingDef.IsNutritionGivingIngestible)
                        {
                            return(false);
                        }
                        if (!getter.CanReserve(plant, 1, -1, null, false))
                        {
                            return(false);
                        }
                        if (!allowForbidden && plant.IsForbidden(getter))
                        {
                            return(false);
                        }
                        if (bestThing != null && (int)FoodUtility.GetFinalIngestibleDef(bestThing, false).ingestible.preferability >= (int)harvestedThingDef.ingestible.preferability)
                        {
                            return(false);
                        }
                        return(true);
                    }, null, 0, 30, false, RegionType.Set_Passable, false);
                    if (thing != null)
                    {
                        bestThing = thing;
                        foodDef   = FoodUtility.GetFinalIngestibleDef(thing, true);
                    }
                }
                if (foodDef == null && bestThing != null)
                {
                    foodDef = FoodUtility.GetFinalIngestibleDef(bestThing, false);
                }
            }
            else
            {
                int searchRegionsMax = 30;
                if (getter.Faction == Faction.OfPlayer)
                {
                    searchRegionsMax = 100;
                }
                FoodUtility.filtered.Clear();
                foreach (Thing item in GenRadial.RadialDistinctThingsAround(getter.Position, getter.Map, 2f, true))
                {
                    Pawn pawn = item as Pawn;
                    if (pawn != null && pawn != getter && pawn.RaceProps.Animal && pawn.CurJob != null && pawn.CurJob.def == JobDefOf.Ingest && pawn.CurJob.GetTarget(TargetIndex.A).HasThing)
                    {
                        FoodUtility.filtered.Add(pawn.CurJob.GetTarget(TargetIndex.A).Thing);
                    }
                }
                bool flag = !allowForbidden && ForbidUtility.CaresAboutForbidden(getter, true) && getter.playerSettings != null && getter.playerSettings.EffectiveAreaRestrictionInPawnCurrentMap != null;
                Predicate <Thing> predicate = delegate(Thing t)
                {
                    if (!foodValidator(t))
                    {
                        return(false);
                    }
                    if (FoodUtility.filtered.Contains(t))
                    {
                        return(false);
                    }
                    if (!(t is Building_NutrientPasteDispenser) && (int)t.def.ingestible.preferability <= 2)
                    {
                        return(false);
                    }
                    if (t.IsNotFresh())
                    {
                        return(false);
                    }
                    return(true);
                };
                IntVec3           position       = getter.Position;
                Map               map            = getter.Map;
                ThingRequest      thingReq       = thingRequest;
                PathEndMode       peMode         = PathEndMode.ClosestTouch;
                TraverseParms     traverseParams = TraverseParms.For(getter, Danger.Deadly, TraverseMode.ByPawn, false);
                Predicate <Thing> validator      = predicate;
                bool              ignoreEntirelyForbiddenRegions = flag;
                bestThing = GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, searchRegionsMax, false, RegionType.Set_Passable, ignoreEntirelyForbiddenRegions);
                FoodUtility.filtered.Clear();
                if (bestThing == null)
                {
                    desperate      = true;
                    position       = getter.Position;
                    map            = getter.Map;
                    thingReq       = thingRequest;
                    peMode         = PathEndMode.ClosestTouch;
                    traverseParams = TraverseParms.For(getter, Danger.Deadly, TraverseMode.ByPawn, false);
                    validator      = foodValidator;
                    ignoreEntirelyForbiddenRegions = flag;
                    bestThing = GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, searchRegionsMax, false, RegionType.Set_Passable, ignoreEntirelyForbiddenRegions);
                }
                if (bestThing != null)
                {
                    foodDef = FoodUtility.GetFinalIngestibleDef(bestThing, false);
                }
            }
            return(bestThing);
        }
예제 #17
0
        public 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, bool allowSociallyImproper = false, bool allowHarvest = false)
        {
            bool  flag      = getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation);
            bool  allowDrug = !eater.IsTeetotaler();
            Thing thing     = null;

            if (canUseInventory)
            {
                if (flag)
                {
                    thing = FoodUtility.BestFoodInInventory(getter, null, FoodPreferability.MealAwful, FoodPreferability.MealLavish, 0f, false);
                }
                if (thing != null)
                {
                    if (getter.Faction != Faction.OfPlayer)
                    {
                        foodSource = thing;
                        foodDef    = FoodUtility.GetFinalIngestibleDef(foodSource, false);
                        return(true);
                    }
                    CompRottable compRottable = thing.TryGetComp <CompRottable>();
                    if (compRottable != null && compRottable.Stage == RotStage.Fresh && compRottable.TicksUntilRotAtCurrentTemp < 30000)
                    {
                        foodSource = thing;
                        foodDef    = FoodUtility.GetFinalIngestibleDef(foodSource, false);
                        return(true);
                    }
                }
            }
            bool     allowPlant = getter == eater;
            ThingDef thingDef   = default(ThingDef);
            Thing    thing2     = FoodUtility.BestFoodSourceOnMap(getter, eater, desperate, out thingDef, FoodPreferability.MealLavish, allowPlant, allowDrug, allowCorpse, true, canRefillDispenser, allowForbidden, allowSociallyImproper, allowHarvest);

            if (thing == null && thing2 == null)
            {
                if (canUseInventory && flag)
                {
                    thing = FoodUtility.BestFoodInInventory(getter, null, FoodPreferability.DesperateOnly, 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()))
                {
                    Pawn pawn = FoodUtility.BestPawnToHuntForPredator(getter);
                    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 = (float)(num2 - 32.0);
            if (num > num2)
            {
                foodSource = thing2;
                foodDef    = thingDef;
                return(true);
            }
            foodSource = thing;
            foodDef    = FoodUtility.GetFinalIngestibleDef(foodSource, false);
            return(true);
        }
예제 #18
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Need_Food food = pawn.needs.food;

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

            if (pawn.AnimalOrWildMan())
            {
                flag = true;
            }
            else
            {
                Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition, false);
                flag = (firstHediffOfDef != null && firstHediffOfDef.Severity > 0.4f);
            }
            bool     flag2              = pawn.needs.food.CurCategory == HungerCategory.Starving;
            bool     desperate          = flag2;
            bool     canRefillDispenser = true;
            bool     canUseInventory    = true;
            bool     allowCorpse        = flag;
            bool     flag3              = this.forceScanWholeMap;
            Thing    thing;
            ThingDef thingDef;

            if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out thing, out thingDef, canRefillDispenser, canUseInventory, false, allowCorpse, false, pawn.IsWildMan(), flag3))
            {
                return(null);
            }
            Pawn pawn2 = thing as Pawn;

            if (pawn2 != null)
            {
                return(new Job(JobDefOf.PredatorHunt, pawn2)
                {
                    killIncappedTarget = true
                });
            }
            if (thing is Plant && thing.def.plant.harvestedThingDef == thingDef)
            {
                return(new Job(JobDefOf.Harvest, thing));
            }
            Building_NutrientPasteDispenser building_NutrientPasteDispenser = thing as Building_NutrientPasteDispenser;

            if (building_NutrientPasteDispenser != null && !building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers())
            {
                Building building = building_NutrientPasteDispenser.AdjacentReachableHopper(pawn);
                if (building != null)
                {
                    ISlotGroupParent hopperSgp = building as ISlotGroupParent;
                    Job job = WorkGiver_CookFillHopper.HopperFillFoodJob(pawn, hopperSgp);
                    if (job != null)
                    {
                        return(job);
                    }
                }
                thing = FoodUtility.BestFoodSourceOnMap(pawn, pawn, flag2, out thingDef, FoodPreferability.MealLavish, false, !pawn.IsTeetotaler(), false, false, false, false, false, false, this.forceScanWholeMap);
                if (thing == null)
                {
                    return(null);
                }
            }
            float nutrition = FoodUtility.GetNutrition(thing, thingDef);

            return(new Job(JobDefOf.Ingest, thing)
            {
                count = FoodUtility.WillIngestStackCountOf(pawn, thingDef, nutrition)
            });
        }
예제 #19
0
        // RimWorld.FoodUtility
        private static Pawn BestPawnToHuntForPredator(Pawn predator, bool forceScanWholeMap)
        {
            if (predator.meleeVerbs.TryGetMeleeVerb(null) == null)
            {
                return(null);
            }
            bool  flag = false;
            float summaryHealthPercent = predator.health.summaryHealth.SummaryHealthPercent;

            if (summaryHealthPercent < 0.25f)
            {
                flag = true;
            }
            tmpPredatorCandidates.Clear();
            int maxRegionsToScan = GetMaxRegionsToScan(predator, forceScanWholeMap);

            if (maxRegionsToScan < 0)
            {
                tmpPredatorCandidates.AddRange(predator.Map.mapPawns.AllPawnsSpawned);
            }
            else
            {
                TraverseParms traverseParms = TraverseParms.For(predator, Danger.Deadly, TraverseMode.ByPawn, false);
                RegionTraverser.BreadthFirstTraverse(predator.Position, predator.Map, (Region from, Region to) => to.Allows(traverseParms, true), delegate(Region x)
                {
                    List <Thing> list = x.ListerThings.ThingsInGroup(ThingRequestGroup.Pawn);
                    for (int j = 0; j < list.Count; j++)
                    {
                        bool XenoInfection = (((Pawn)list[j]).health.hediffSet.HasHediff(XenomorphDefOf.RRY_FaceHuggerInfection) || ((Pawn)list[j]).health.hediffSet.HasHediff(XenomorphDefOf.RRY_HiddenXenomorphImpregnation) || ((Pawn)list[j]).health.hediffSet.HasHediff(XenomorphDefOf.RRY_XenomorphImpregnation)) ? true : false;
                        bool IsXenos       = (((Pawn)list[j]).kindDef == XenomorphDefOf.RRY_Xenomorph_Drone || ((Pawn)list[j]).kindDef == XenomorphDefOf.RRY_Xenomorph_FaceHugger || ((Pawn)list[j]).kindDef == XenomorphDefOf.RRY_Xenomorph_Queen || ((Pawn)list[j]).kindDef == XenomorphDefOf.RRY_Xenomorph_Runner || ((Pawn)list[j]).kindDef == XenomorphDefOf.RRY_Xenomorph_Warrior) ? true : false;

                        if (!XenoInfection && !IsXenos)
                        {
                            tmpPredatorCandidates.Add((Pawn)list[j]);
                        }
                        else
                        {
                            //    Log.Message(string.Format("{0} cannae hunt {2} XenoInfection:{1} IsXenos:{3}", predator.Label, XenoInfection, ((Pawn)list[j]).Label, IsXenos));
                        }
                    }
                    return(false);
                }, 999999, RegionType.Set_Passable);
            }
            Pawn  pawn         = null;
            float num          = 0f;
            bool  tutorialMode = TutorSystem.TutorialMode;

            for (int i = 0; i < tmpPredatorCandidates.Count; i++)
            {
                Pawn pawn2 = tmpPredatorCandidates[i];
                if (predator.GetRoom(RegionType.Set_Passable) == pawn2.GetRoom(RegionType.Set_Passable))
                {
                    if (predator != pawn2)
                    {
                        if (!flag || pawn2.Downed)
                        {
                            if (IsAcceptablePreyFor(predator, pawn2))
                            {
                                if (predator.CanReach(pawn2, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn))
                                {
                                    if (!pawn2.IsForbidden(predator) && !(XenoInfection(pawn2)))
                                    {
                                        if (!tutorialMode || pawn2.Faction != Faction.OfPlayer)
                                        {
                                            float preyScoreFor = FoodUtility.GetPreyScoreFor(predator, pawn2);
                                            if (preyScoreFor > num || pawn == null)
                                            {
                                                num  = preyScoreFor;
                                                pawn = pawn2;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            tmpPredatorCandidates.Clear();
            return(pawn);
        }
        // RimWorld.FoodUtility
        private static Pawn BestPawnToHuntForPredator(Pawn predator, bool forceScanWholeMap)
        {
            if (predator.meleeVerbs.TryGetMeleeVerb(null) == null)
            {
                return(null);
            }
            bool  flag = false;
            float summaryHealthPercent = predator.health.summaryHealth.SummaryHealthPercent;

            if (summaryHealthPercent < 0.25f)
            {
                flag = true;
            }
            tmpPredatorCandidates.Clear();
            int maxRegionsToScan = GetMaxRegionsToScan(predator, forceScanWholeMap);

            if (maxRegionsToScan < 0)
            {
                tmpPredatorCandidates.AddRange(predator.Map.mapPawns.AllPawnsSpawned);
            }
            else
            {
                TraverseParms traverseParms = TraverseParms.For(predator, Danger.Deadly, TraverseMode.ByPawn, false);
                RegionTraverser.BreadthFirstTraverse(predator.Position, predator.Map, (Region from, Region to) => to.Allows(traverseParms, true), delegate(Region x)
                {
                    List <Thing> list = x.ListerThings.ThingsInGroup(ThingRequestGroup.Pawn);
                    for (int j = 0; j < list.Count; j++)
                    {
                        Pawn p = ((Pawn)list[j]);
                        if (p.isPotentialHost())
                        {
                            tmpPredatorCandidates.Add(p);
                        }
                        else
                        {
                            if (predator.jobs.debugLog)
                            {
                                predator.jobs.DebugLogEvent(string.Format("{0} cannae hunt {2} XenoInfection:{1} IsXenos:{3}", predator.Label, XenomorphUtil.IsInfectedPawn(p), ((Pawn)list[j]).Label, XenomorphUtil.IsXenomorph(p)));
                            }
                        }
                    }
                    return(false);
                }, 999999, RegionType.Set_Passable);
            }
            Pawn  pawn         = null;
            float num          = 0f;
            bool  tutorialMode = TutorSystem.TutorialMode;

            for (int i = 0; i < tmpPredatorCandidates.Count; i++)
            {
                Pawn pawn2 = tmpPredatorCandidates[i];
                if (predator.GetRoom(RegionType.Set_Passable) == pawn2.GetRoom(RegionType.Set_Passable))
                {
                    if (predator != pawn2)
                    {
                        if (!flag || pawn2.Downed)
                        {
                            if (IsAcceptablePreyFor(predator, pawn2))
                            {
                                if (predator.CanReach(pawn2, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn))
                                {
                                    if (!pawn2.IsForbidden(predator))
                                    {
                                        if (!tutorialMode || pawn2.Faction != Faction.OfPlayer)
                                        {
                                            float preyScoreFor = FoodUtility.GetPreyScoreFor(predator, pawn2);
                                            if (preyScoreFor > num || pawn == null)
                                            {
                                                num  = preyScoreFor;
                                                pawn = pawn2;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            tmpPredatorCandidates.Clear();
            return(pawn);
        }
예제 #21
0
 private static void DoDebugOptions(Rect rightRect, Pawn pawn)
 {
     Widgets.CheckboxLabeled(new Rect(rightRect.x, rightRect.y - 25f, 110f, 30f), "Dev: AllDiffs", ref showAllHediffs);
     Widgets.CheckboxLabeled(new Rect(rightRect.x + 115f, rightRect.y - 25f, 120f, 30f), "DiffsDebugInfo", ref showHediffsDebugInfo);
     if (Widgets.ButtonText(new Rect(rightRect.x + 240f, rightRect.y - 27f, 115f, 25f), "Debug info"))
     {
         List <FloatMenuOption> list = new List <FloatMenuOption>();
         list.Add(new FloatMenuOption("Parts hit chance (this part or any child node)", delegate
         {
             StringBuilder stringBuilder13 = new StringBuilder();
             foreach (BodyPartRecord item2 in from x in pawn.RaceProps.body.AllParts
                      orderby x.coverageAbsWithChildren descending
                      select x)
             {
                 stringBuilder13.AppendLine(item2.LabelCap + " " + item2.coverageAbsWithChildren.ToStringPercent());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder13.ToString()));
         }));
         list.Add(new FloatMenuOption("Parts hit chance (exactly this part)", delegate
         {
             StringBuilder stringBuilder12 = new StringBuilder();
             float num8 = 0f;
             foreach (BodyPartRecord item3 in from x in pawn.RaceProps.body.AllParts
                      orderby x.coverageAbs descending
                      select x)
             {
                 stringBuilder12.AppendLine(item3.LabelCap + " " + item3.coverageAbs.ToStringPercent());
                 num8 += item3.coverageAbs;
             }
             stringBuilder12.AppendLine();
             stringBuilder12.AppendLine("Total " + num8.ToStringPercent());
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder12.ToString()));
         }));
         list.Add(new FloatMenuOption("Per-part efficiency", delegate
         {
             StringBuilder stringBuilder11 = new StringBuilder();
             foreach (BodyPartRecord allPart in pawn.RaceProps.body.AllParts)
             {
                 stringBuilder11.AppendLine(allPart.LabelCap + " " + PawnCapacityUtility.CalculatePartEfficiency(pawn.health.hediffSet, allPart).ToStringPercent());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder11.ToString()));
         }));
         list.Add(new FloatMenuOption("BodyPartGroup efficiency (of only natural parts)", delegate
         {
             StringBuilder stringBuilder10 = new StringBuilder();
             foreach (BodyPartGroupDef item4 in from x in DefDatabase <BodyPartGroupDef> .AllDefs
                      where pawn.RaceProps.body.AllParts.Any((BodyPartRecord y) => y.groups.Contains(x))
                      select x)
             {
                 stringBuilder10.AppendLine(item4.LabelCap + " " + PawnCapacityUtility.CalculateNaturalPartsAverageEfficiency(pawn.health.hediffSet, item4).ToStringPercent());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder10.ToString()));
         }));
         list.Add(new FloatMenuOption("IsSolid", delegate
         {
             StringBuilder stringBuilder9 = new StringBuilder();
             foreach (BodyPartRecord notMissingPart in pawn.health.hediffSet.GetNotMissingParts())
             {
                 stringBuilder9.AppendLine(notMissingPart.LabelCap + " " + notMissingPart.def.IsSolid(notMissingPart, pawn.health.hediffSet.hediffs));
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder9.ToString()));
         }));
         list.Add(new FloatMenuOption("IsSkinCovered", delegate
         {
             StringBuilder stringBuilder8 = new StringBuilder();
             foreach (BodyPartRecord notMissingPart2 in pawn.health.hediffSet.GetNotMissingParts())
             {
                 stringBuilder8.AppendLine(notMissingPart2.LabelCap + " " + notMissingPart2.def.IsSkinCovered(notMissingPart2, pawn.health.hediffSet));
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder8.ToString()));
         }));
         list.Add(new FloatMenuOption("does have added parts", delegate
         {
             StringBuilder stringBuilder7 = new StringBuilder();
             foreach (BodyPartRecord notMissingPart3 in pawn.health.hediffSet.GetNotMissingParts())
             {
                 stringBuilder7.AppendLine(notMissingPart3.LabelCap + " " + pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(notMissingPart3));
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder7.ToString()));
         }));
         list.Add(new FloatMenuOption("GetNotMissingParts", delegate
         {
             StringBuilder stringBuilder6 = new StringBuilder();
             foreach (BodyPartRecord notMissingPart4 in pawn.health.hediffSet.GetNotMissingParts())
             {
                 stringBuilder6.AppendLine(notMissingPart4.LabelCap);
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder6.ToString()));
         }));
         list.Add(new FloatMenuOption("GetCoverageOfNotMissingNaturalParts", delegate
         {
             StringBuilder stringBuilder5 = new StringBuilder();
             foreach (BodyPartRecord item5 in from x in pawn.RaceProps.body.AllParts
                      orderby pawn.health.hediffSet.GetCoverageOfNotMissingNaturalParts(x) descending
                      select x)
             {
                 stringBuilder5.AppendLine(item5.LabelCap + ": " + pawn.health.hediffSet.GetCoverageOfNotMissingNaturalParts(item5).ToStringPercent());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder5.ToString()));
         }));
         list.Add(new FloatMenuOption("parts nutrition (assuming adult)", delegate
         {
             StringBuilder stringBuilder4 = new StringBuilder();
             float totalCorpseNutrition   = StatDefOf.Nutrition.Worker.GetValueAbstract(pawn.RaceProps.corpseDef);
             foreach (BodyPartRecord item6 in from x in pawn.RaceProps.body.AllParts
                      orderby FoodUtility.GetBodyPartNutrition(totalCorpseNutrition, pawn, x) descending
                      select x)
             {
                 stringBuilder4.AppendLine(item6.LabelCap + ": " + FoodUtility.GetBodyPartNutrition(totalCorpseNutrition, pawn, item6));
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder4.ToString()));
         }));
         list.Add(new FloatMenuOption("test permanent injury pain factor probability", delegate
         {
             StringBuilder stringBuilder3 = new StringBuilder();
             int num2   = 0;
             int num3   = 0;
             int num4   = 0;
             float num5 = 0f;
             int num6   = 10000;
             for (int k = 0; k < num6; k++)
             {
                 float num7 = Mathf.Max(0f, Rand.ByCurve(HealthTuning.PermanentInjuryPainFactorRandomCurve));
                 if (num7 < 0f)
                 {
                     Log.Error("Pain factor < 0");
                 }
                 if (num7 == 0f)
                 {
                     num2++;
                 }
                 if (num7 < 1f)
                 {
                     num3++;
                 }
                 if (num7 < 5f)
                 {
                     num4++;
                 }
                 if (num7 > num5)
                 {
                     num5 = num7;
                 }
             }
             stringBuilder3.AppendLine("total: " + num6);
             stringBuilder3.AppendLine("0: " + num2 + " (" + ((float)num2 / (float)num6).ToStringPercent() + ")");
             stringBuilder3.AppendLine("< 1: " + num3 + " (" + ((float)num3 / (float)num6).ToStringPercent() + ")");
             stringBuilder3.AppendLine("< 5: " + num4 + " (" + ((float)num4 / (float)num6).ToStringPercent() + ")");
             stringBuilder3.AppendLine("max: " + num5);
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder3.ToString()));
         }));
         HediffGiver_Birthday hLocal;
         list.Add(new FloatMenuOption("HediffGiver_Birthday chance at age", delegate
         {
             List <FloatMenuOption> list2 = new List <FloatMenuOption>();
             foreach (HediffGiverSetDef hediffGiverSet in pawn.RaceProps.hediffGiverSets)
             {
                 foreach (HediffGiver_Birthday item7 in hediffGiverSet.hediffGivers.OfType <HediffGiver_Birthday>())
                 {
                     hLocal = item7;
                     FloatMenuOption item = new FloatMenuOption(hediffGiverSet.defName + " - " + item7.hediff.defName, delegate
                     {
                         StringBuilder stringBuilder2 = new StringBuilder();
                         stringBuilder2.AppendLine("% of pawns which will have at least 1 " + hLocal.hediff.label + " at age X:");
                         stringBuilder2.AppendLine();
                         for (int j = 1; (float)j < pawn.RaceProps.lifeExpectancy + 20f; j++)
                         {
                             stringBuilder2.AppendLine(j + ": " + hLocal.DebugChanceToHaveAtAge(pawn, j).ToStringPercent());
                         }
                         Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder2.ToString()));
                     });
                     list2.Add(item);
                 }
             }
             Find.WindowStack.Add(new FloatMenu(list2));
         }));
         list.Add(new FloatMenuOption("HediffGiver_Birthday count at age", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             stringBuilder.AppendLine("Average hediffs count (from HediffGiver_Birthday) at age X:");
             stringBuilder.AppendLine();
             for (int i = 1; (float)i < pawn.RaceProps.lifeExpectancy + 20f; i++)
             {
                 float num = 0f;
                 foreach (HediffGiverSetDef hediffGiverSet2 in pawn.RaceProps.hediffGiverSets)
                 {
                     foreach (HediffGiver_Birthday item8 in hediffGiverSet2.hediffGivers.OfType <HediffGiver_Birthday>())
                     {
                         num += item8.DebugChanceToHaveAtAge(pawn, i);
                     }
                 }
                 stringBuilder.AppendLine(i + ": " + num.ToStringDecimalIfSmall());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString()));
         }));
         Find.WindowStack.Add(new FloatMenu(list));
     }
 }
예제 #22
0
        private static void DoDebugOptions(Rect rightRect, Pawn pawn)
        {
            Widgets.CheckboxLabeled(new Rect(rightRect.x, rightRect.y - 25f, 110f, 30f), "Dev: AllDiffs", ref showAllHediffs);
            Widgets.CheckboxLabeled(new Rect(rightRect.x + 115f, rightRect.y - 25f, 120f, 30f), "DiffsDebugInfo", ref showHediffsDebugInfo);
            if (!Widgets.ButtonText(new Rect(rightRect.x + 240f, rightRect.y - 27f, 115f, 25f), "Debug info"))
            {
                return;
            }
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            list.Add(new FloatMenuOption("Parts hit chance (this part or any child node)", delegate
            {
                StringBuilder stringBuilder13 = new StringBuilder();
                foreach (BodyPartRecord item2 in pawn.RaceProps.body.AllParts.OrderByDescending((BodyPartRecord x) => x.coverageAbsWithChildren))
                {
                    stringBuilder13.AppendLine(item2.LabelCap + " " + item2.coverageAbsWithChildren.ToStringPercent());
                }
                Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder13.ToString()));
            }));
            list.Add(new FloatMenuOption("Parts hit chance (exactly this part)", delegate
            {
                StringBuilder stringBuilder12 = new StringBuilder();
                float num2 = 0f;
                foreach (BodyPartRecord item3 in pawn.RaceProps.body.AllParts.OrderByDescending((BodyPartRecord x) => x.coverageAbs))
                {
                    stringBuilder12.AppendLine(item3.LabelCap + " " + item3.coverageAbs.ToStringPercent());
                    num2 += item3.coverageAbs;
                }
                stringBuilder12.AppendLine();
                stringBuilder12.AppendLine("Total " + num2.ToStringPercent());
                Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder12.ToString()));
            }));
            list.Add(new FloatMenuOption("Per-part efficiency", delegate
            {
                StringBuilder stringBuilder11 = new StringBuilder();
                foreach (BodyPartRecord allPart in pawn.RaceProps.body.AllParts)
                {
                    stringBuilder11.AppendLine(allPart.LabelCap + " " + PawnCapacityUtility.CalculatePartEfficiency(pawn.health.hediffSet, allPart).ToStringPercent());
                }
                Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder11.ToString()));
            }));
            list.Add(new FloatMenuOption("BodyPartGroup efficiency (of only natural parts)", delegate
            {
                StringBuilder stringBuilder10 = new StringBuilder();
                foreach (BodyPartGroupDef item4 in DefDatabase <BodyPartGroupDef> .AllDefs.Where((BodyPartGroupDef x) => pawn.RaceProps.body.AllParts.Any((BodyPartRecord y) => y.groups.Contains(x))))
                {
                    stringBuilder10.AppendLine(item4.LabelCap + " " + PawnCapacityUtility.CalculateNaturalPartsAverageEfficiency(pawn.health.hediffSet, item4).ToStringPercent());
                }
                Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder10.ToString()));
            }));
            list.Add(new FloatMenuOption("IsSolid", delegate
            {
                StringBuilder stringBuilder9 = new StringBuilder();
                foreach (BodyPartRecord notMissingPart in pawn.health.hediffSet.GetNotMissingParts())
                {
                    stringBuilder9.AppendLine(notMissingPart.LabelCap + " " + notMissingPart.def.IsSolid(notMissingPart, pawn.health.hediffSet.hediffs));
                }
                Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder9.ToString()));
            }));
            list.Add(new FloatMenuOption("IsSkinCovered", delegate
            {
                StringBuilder stringBuilder8 = new StringBuilder();
                foreach (BodyPartRecord notMissingPart2 in pawn.health.hediffSet.GetNotMissingParts())
                {
                    stringBuilder8.AppendLine(notMissingPart2.LabelCap + " " + notMissingPart2.def.IsSkinCovered(notMissingPart2, pawn.health.hediffSet));
                }
                Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder8.ToString()));
            }));
            list.Add(new FloatMenuOption("Immunities", delegate
            {
                StringBuilder stringBuilder7 = new StringBuilder();
                foreach (HediffDef item5 in DefDatabase <HediffDef> .AllDefsListForReading)
                {
                    ImmunityRecord immunityRecord = pawn.health.immunity.GetImmunityRecord(item5);
                    if (immunityRecord != null)
                    {
                        stringBuilder7.AppendLine(string.Concat("Hediff: ", immunityRecord.hediffDef, ", Source: ", immunityRecord.source, ", Immunity: ", immunityRecord.immunity));
                    }
                }
                Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder7.ToString()));
            }));
            list.Add(new FloatMenuOption("does have added parts", delegate
            {
                StringBuilder stringBuilder6 = new StringBuilder();
                foreach (BodyPartRecord notMissingPart3 in pawn.health.hediffSet.GetNotMissingParts())
                {
                    stringBuilder6.AppendLine(notMissingPart3.LabelCap + " " + pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(notMissingPart3));
                }
                Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder6.ToString()));
            }));
            list.Add(new FloatMenuOption("GetNotMissingParts", delegate
            {
                StringBuilder stringBuilder5 = new StringBuilder();
                foreach (BodyPartRecord notMissingPart4 in pawn.health.hediffSet.GetNotMissingParts())
                {
                    stringBuilder5.AppendLine(notMissingPart4.LabelCap);
                }
                Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder5.ToString()));
            }));
            list.Add(new FloatMenuOption("GetCoverageOfNotMissingNaturalParts", delegate
            {
                StringBuilder stringBuilder4 = new StringBuilder();
                foreach (BodyPartRecord item6 in pawn.RaceProps.body.AllParts.OrderByDescending((BodyPartRecord x) => pawn.health.hediffSet.GetCoverageOfNotMissingNaturalParts(x)))
                {
                    stringBuilder4.AppendLine(item6.LabelCap + ": " + pawn.health.hediffSet.GetCoverageOfNotMissingNaturalParts(item6).ToStringPercent());
                }
                Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder4.ToString()));
            }));
            list.Add(new FloatMenuOption("parts nutrition (assuming adult)", delegate
            {
                StringBuilder stringBuilder3 = new StringBuilder();
                float totalCorpseNutrition   = StatDefOf.Nutrition.Worker.GetValueAbstract(pawn.RaceProps.corpseDef);
                foreach (BodyPartRecord item7 in pawn.RaceProps.body.AllParts.OrderByDescending((BodyPartRecord x) => FoodUtility.GetBodyPartNutrition(totalCorpseNutrition, pawn, x)))
                {
                    stringBuilder3.AppendLine(item7.LabelCap + ": " + FoodUtility.GetBodyPartNutrition(totalCorpseNutrition, pawn, item7));
                }
                Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder3.ToString()));
            }));
            list.Add(new FloatMenuOption("HediffGiver_Birthday chance at age", delegate
            {
                List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                HediffGiver_Birthday hLocal  = default(HediffGiver_Birthday);
                foreach (HediffGiverSetDef hediffGiverSet in pawn.RaceProps.hediffGiverSets)
                {
                    foreach (HediffGiver_Birthday item8 in hediffGiverSet.hediffGivers.OfType <HediffGiver_Birthday>())
                    {
                        hLocal = item8;
                        FloatMenuOption item = new FloatMenuOption(hediffGiverSet.defName + " - " + item8.hediff.defName, delegate
                        {
                            StringBuilder stringBuilder2 = new StringBuilder();
                            stringBuilder2.AppendLine("% of pawns which will have at least 1 " + hLocal.hediff.label + " at age X:");
                            stringBuilder2.AppendLine();
                            for (int j = 1; (float)j < pawn.RaceProps.lifeExpectancy + 20f; j++)
                            {
                                stringBuilder2.AppendLine(j + ": " + hLocal.DebugChanceToHaveAtAge(pawn, j).ToStringPercent());
                            }
                            Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder2.ToString()));
                        });
                        list2.Add(item);
                    }
                }
                Find.WindowStack.Add(new FloatMenu(list2));
            }));
            list.Add(new FloatMenuOption("HediffGiver_Birthday count at age", delegate
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine("Average hediffs count (from HediffGiver_Birthday) at age X:");
                stringBuilder.AppendLine();
                for (int i = 1; (float)i < pawn.RaceProps.lifeExpectancy + 20f; i++)
                {
                    float num = 0f;
                    foreach (HediffGiverSetDef hediffGiverSet2 in pawn.RaceProps.hediffGiverSets)
                    {
                        foreach (HediffGiver_Birthday item9 in hediffGiverSet2.hediffGivers.OfType <HediffGiver_Birthday>())
                        {
                            num += item9.DebugChanceToHaveAtAge(pawn, i);
                        }
                    }
                    stringBuilder.AppendLine(i + ": " + num.ToStringDecimalIfSmall());
                }
                Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString()));
            }));
            Find.WindowStack.Add(new FloatMenu(list));
        }
        // Token: 0x060004FD RID: 1277 RVA: 0x000321F8 File Offset: 0x000305F8
        protected override Job TryGiveJob(Pawn pawn)
        {
            bool         selected           = Find.Selector.SelectedObjects.Contains(pawn) && Prefs.DevMode;
            Need_Food    food               = pawn.needs.food;
            LifeStageDef stage              = pawn.ageTracker.CurLifeStage;
            bool         desperate          = food.CurCategory >= HungerCategory.Starving;
            bool         canRefillDispenser = false;
            bool         canUseInventory    = false;
            bool         allowCorpse        = true;
            bool         flag3              = this.forceScanWholeMap;

            if (stage == pawn.RaceProps.lifeStageAges[pawn.RaceProps.lifeStageAges.Count - 1].def)
            {
                if (selected)
                {
                    Log.Message(string.Format("adult {0} @ {1}", pawn, pawn.Position));
                }
                if (food.CurCategory == HungerCategory.Fed)
                {
                    return(null);
                }
            }
            else
            {
                if (selected)
                {
                    Log.Message(string.Format("young {0} @ {1}", pawn, pawn.Position));
                }

                /*
                 * if (food.CurCategory == HungerCategory.Fed)
                 * {
                 *  return null;
                 * }
                 */
            }

            float nutrition;

            if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out Thing thing, out ThingDef thingDef, canRefillDispenser, canUseInventory, true, allowCorpse, true, pawn.IsWildMan(), flag3))
            {
                return(null);
            }
            if (thing is Corpse corpse)
            {
                if (selected)
                {
                    Log.Message(string.Format("{0} is corpse @ {1}", thing, thing.Position));
                }
                nutrition = FoodUtility.GetNutrition(thing, thingDef);
                return(new Job(XenomorphDefOf.RRY_Neomorph_Ingest, thing)
                {
                    count = FoodUtility.WillIngestStackCountOf(pawn, thingDef, nutrition)
                });
            }
            if (thing is Pawn pawn2)
            {
                if (selected)
                {
                    Log.Message(string.Format("{0} is pawn @ {1}", thing, thing.Position));
                }
                if (pawn2 != null)
                {
                    return(new Job(JobDefOf.PredatorHunt, pawn2)
                    {
                        killIncappedTarget = true
                    });
                }
            }
            nutrition = FoodUtility.GetNutrition(thing, thingDef);
            if (selected)
            {
                Log.Message(string.Format("{0} is thing @ {1}", thing, thing.Position));
            }
            return(new Job(XenomorphDefOf.RRY_Neomorph_Ingest, thing)
            {
                count = FoodUtility.WillIngestStackCountOf(pawn, thingDef, nutrition)
            });
        }
예제 #24
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    this.FailOnDespawnedNullOrForbidden(TargetIndex.B);
                    this.FailOn(() => !FoodUtility.ShouldBeFedBySomeone(base.Deliveree));
                    if (this.pawn.inventory != null && this.pawn.inventory.Contains(base.TargetThingA))
                    {
                        this.$current = Toils_Misc.TakeItemFromInventoryToCarrier(this.pawn, TargetIndex.A);
                        if (!this.$disposing)
                        {
                            this.$PC = 1;
                        }
                        return(true);
                    }
                    if (base.TargetThingA is Building_NutrientPasteDispenser)
                    {
                        this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell).FailOnForbidden(TargetIndex.A);
                        if (!this.$disposing)
                        {
                            this.$PC = 2;
                        }
                        return(true);
                    }
                    this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnForbidden(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 4;
                    }
                    return(true);

                case 1u:
                    break;

                case 2u:
                    this.$current = Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, this.pawn);
                    if (!this.$disposing)
                    {
                        this.$PC = 3;
                    }
                    return(true);

                case 3u:
                    break;

                case 4u:
                    this.$current = Toils_Ingest.PickupIngestible(TargetIndex.A, base.Deliveree);
                    if (!this.$disposing)
                    {
                        this.$PC = 5;
                    }
                    return(true);

                case 5u:
                    break;

                case 6u:
                    this.$current = Toils_Ingest.ChewIngestible(base.Deliveree, 1.5f, TargetIndex.A, TargetIndex.None).FailOnCannotTouch(TargetIndex.B, PathEndMode.Touch);
                    if (!this.$disposing)
                    {
                        this.$PC = 7;
                    }
                    return(true);

                case 7u:
                    this.$current = Toils_Ingest.FinalizeIngest(base.Deliveree, TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 8;
                    }
                    return(true);

                case 8u:
                    this.$PC = -1;
                    return(false);

                default:
                    return(false);
                }
                this.$current = Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch);
                if (!this.$disposing)
                {
                    this.$PC = 6;
                }
                return(true);
            }
예제 #25
0
        // Token: 0x060004FD RID: 1277 RVA: 0x000321F8 File Offset: 0x000305F8
        protected override Job TryGiveJob(Pawn pawn)
        {
            Need_Food    food  = pawn.needs.food;
            LifeStageDef stage = pawn.ageTracker.CurLifeStage;

            if (stage == pawn.RaceProps.lifeStageAges[pawn.RaceProps.lifeStageAges.Count - 1].def)
            {
                return(null);
            }

            bool flag;

            if (pawn.AnimalOrWildMan())
            {
                flag = true;
            }
            else
            {
                Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition, false);
                flag = (firstHediffOfDef != null && firstHediffOfDef.Severity > 0.4f);
            }
            bool     flag2     = pawn.needs.food.CurCategory == HungerCategory.Starving;
            bool     desperate = flag2;
            Thing    thing;
            ThingDef thingDef;
            bool     canRefillDispenser = false;
            bool     canUseInventory    = false;
            bool     allowCorpse        = true;
            bool     flag3 = false;

            if (pawn.GetLord() != null && pawn.GetLord() is Lord L)
            {
                if (L.CurLordToil is LordToil_DefendAndExpandHiveLike Hivelord)
                {
                    if (Hivelord.Data.assignedHiveLikes.TryGetValue(pawn) != null)
                    {
                        if (!Hivelord.Data.assignedHiveLikes.TryGetValue(pawn).active)
                        {
                            return(null);
                        }
                    }
                }
            }
            if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out thing, out thingDef, canRefillDispenser, canUseInventory, true, allowCorpse, true, pawn.IsWildMan(), flag3))
            {
                return(null);
            }
            if (thing.GetType() != typeof(Corpse))
            {
                return(null);
            }
            Pawn pawn2 = thing as Pawn;

            if (pawn2 != null && pawn.CanSee(pawn2) && pawn.isXenomorph())
            {
                return(new Job(JobDefOf.PredatorHunt, pawn2)
                {
                    killIncappedTarget = true
                });
            }
            float nutrition = FoodUtility.GetNutrition(thing, thingDef);

            return(new Job(XenomorphDefOf.RRY_Neomorph_Ingest, thing)
            {
                count = FoodUtility.WillIngestStackCountOf(pawn, thingDef, nutrition)
            });
        }
예제 #26
0
 private static void DoDebugOptions(Rect rightRect, Pawn pawn)
 {
     Widgets.CheckboxLabeled(new Rect(rightRect.x, (float)(rightRect.y - 25.0), 110f, 30f), "Dev: AllDiffs", ref HealthCardUtility.showAllHediffs, false);
     Widgets.CheckboxLabeled(new Rect((float)(rightRect.x + 115.0), (float)(rightRect.y - 25.0), 120f, 30f), "DiffsDebugInfo", ref HealthCardUtility.showHediffsDebugInfo, false);
     if (Widgets.ButtonText(new Rect((float)(rightRect.x + 240.0), (float)(rightRect.y - 27.0), 115f, 25f), "Debug info", true, false, true))
     {
         List <FloatMenuOption> list = new List <FloatMenuOption>();
         list.Add(new FloatMenuOption("Parts hit chance (this part or any child node)", delegate
         {
             StringBuilder stringBuilder13 = new StringBuilder();
             foreach (BodyPartRecord item2 in from x in pawn.RaceProps.body.AllParts
                      orderby x.coverageAbsWithChildren descending
                      select x)
             {
                 stringBuilder13.AppendLine(item2.def.LabelCap + " " + item2.coverageAbsWithChildren.ToStringPercent());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder13.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("Parts hit chance (exactly this part)", delegate
         {
             StringBuilder stringBuilder12 = new StringBuilder();
             float num9 = 0f;
             foreach (BodyPartRecord item3 in from x in pawn.RaceProps.body.AllParts
                      orderby x.coverageAbs descending
                      select x)
             {
                 stringBuilder12.AppendLine(item3.def.LabelCap + " " + item3.coverageAbs.ToStringPercent());
                 num9 += item3.coverageAbs;
             }
             stringBuilder12.AppendLine();
             stringBuilder12.AppendLine("Total " + num9.ToStringPercent());
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder12.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("Per-part efficiency", delegate
         {
             StringBuilder stringBuilder11 = new StringBuilder();
             foreach (BodyPartRecord allPart in pawn.RaceProps.body.AllParts)
             {
                 stringBuilder11.AppendLine(allPart.def.LabelCap + " " + PawnCapacityUtility.CalculatePartEfficiency(pawn.health.hediffSet, allPart, false, null).ToStringPercent());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder11.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("BodyPartGroup efficiency (of only natural parts)", delegate
         {
             StringBuilder stringBuilder10 = new StringBuilder();
             foreach (BodyPartGroupDef item4 in from x in DefDatabase <BodyPartGroupDef> .AllDefs
                      where pawn.RaceProps.body.AllParts.Any((BodyPartRecord y) => y.groups.Contains(x))
                      select x)
             {
                 stringBuilder10.AppendLine(item4.LabelCap + " " + PawnCapacityUtility.CalculateNaturalPartsAverageEfficiency(pawn.health.hediffSet, item4).ToStringPercent());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder10.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("IsSolid", delegate
         {
             StringBuilder stringBuilder9 = new StringBuilder();
             foreach (BodyPartRecord notMissingPart in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined))
             {
                 stringBuilder9.AppendLine(notMissingPart.def.LabelCap + " " + notMissingPart.def.IsSolid(notMissingPart, pawn.health.hediffSet.hediffs));
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder9.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("IsSkinCovered", delegate
         {
             StringBuilder stringBuilder8 = new StringBuilder();
             foreach (BodyPartRecord notMissingPart2 in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined))
             {
                 stringBuilder8.AppendLine(notMissingPart2.def.LabelCap + " " + notMissingPart2.def.IsSkinCovered(notMissingPart2, pawn.health.hediffSet));
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder8.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("does have added parts", delegate
         {
             StringBuilder stringBuilder7 = new StringBuilder();
             foreach (BodyPartRecord notMissingPart3 in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined))
             {
                 stringBuilder7.AppendLine(notMissingPart3.def.LabelCap + " " + pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(notMissingPart3));
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder7.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("GetNotMissingParts", delegate
         {
             StringBuilder stringBuilder6 = new StringBuilder();
             foreach (BodyPartRecord notMissingPart4 in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined))
             {
                 stringBuilder6.AppendLine(notMissingPart4.def.LabelCap);
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder6.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("GetCoverageOfNotMissingNaturalParts", delegate
         {
             StringBuilder stringBuilder5 = new StringBuilder();
             foreach (BodyPartRecord item5 in from x in pawn.RaceProps.body.AllParts
                      orderby pawn.health.hediffSet.GetCoverageOfNotMissingNaturalParts(x) descending
                      select x)
             {
                 stringBuilder5.AppendLine(item5.def.LabelCap + ": " + pawn.health.hediffSet.GetCoverageOfNotMissingNaturalParts(item5).ToStringPercent());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder5.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("parts nutrition", delegate
         {
             StringBuilder stringBuilder4 = new StringBuilder();
             foreach (BodyPartRecord item6 in from x in pawn.RaceProps.body.AllParts
                      orderby FoodUtility.GetBodyPartNutrition(pawn, x) descending
                      select x)
             {
                 stringBuilder4.AppendLine(item6.def.LabelCap + ": " + FoodUtility.GetBodyPartNutrition(pawn, item6));
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder4.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("test old injury pain factor probability", delegate
         {
             StringBuilder stringBuilder3 = new StringBuilder();
             int num4   = 0;
             int num5   = 0;
             int num6   = 0;
             float num7 = 0f;
             int num8   = 10000;
             for (int i = 0; i < num8; i++)
             {
                 float randomPainFactor = OldInjuryUtility.GetRandomPainFactor();
                 if (randomPainFactor < 0.0)
                 {
                     Log.Error("Pain factor < 0");
                 }
                 if (randomPainFactor == 0.0)
                 {
                     num4++;
                 }
                 if (randomPainFactor < 1.0)
                 {
                     num5++;
                 }
                 if (randomPainFactor < 5.0)
                 {
                     num6++;
                 }
                 if (randomPainFactor > num7)
                 {
                     num7 = randomPainFactor;
                 }
             }
             stringBuilder3.AppendLine("total: " + num8);
             stringBuilder3.AppendLine("0: " + num4 + " (" + ((float)num4 / (float)num8).ToStringPercent() + ")");
             stringBuilder3.AppendLine("< 1: " + num5 + " (" + ((float)num5 / (float)num8).ToStringPercent() + ")");
             stringBuilder3.AppendLine("< 5: " + num6 + " (" + ((float)num6 / (float)num8).ToStringPercent() + ")");
             stringBuilder3.AppendLine("max: " + num7);
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder3.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         HediffGiver_Birthday hLocal;
         list.Add(new FloatMenuOption("HediffGiver_Birthday chance at age", delegate
         {
             List <FloatMenuOption> list2 = new List <FloatMenuOption>();
             foreach (HediffGiverSetDef hediffGiverSet in pawn.RaceProps.hediffGiverSets)
             {
                 foreach (HediffGiver_Birthday item7 in hediffGiverSet.hediffGivers.OfType <HediffGiver_Birthday>())
                 {
                     hLocal = item7;
                     FloatMenuOption item = new FloatMenuOption(hediffGiverSet.defName + " - " + item7.hediff.defName, delegate
                     {
                         StringBuilder stringBuilder2 = new StringBuilder();
                         stringBuilder2.AppendLine("% of pawns which will have at least 1 " + hLocal.hediff.label + " at age X:");
                         stringBuilder2.AppendLine();
                         int num3 = 1;
                         while ((float)num3 < pawn.RaceProps.lifeExpectancy + 20.0)
                         {
                             stringBuilder2.AppendLine(num3 + ": " + hLocal.DebugChanceToHaveAtAge(pawn, num3).ToStringPercent());
                             num3++;
                         }
                         Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder2.ToString(), null, null, null, null, null, false));
                     }, MenuOptionPriority.Default, null, null, 0f, null, null);
                     list2.Add(item);
                 }
             }
             Find.WindowStack.Add(new FloatMenu(list2));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("HediffGiver_Birthday count at age", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             stringBuilder.AppendLine("Average hediffs count (from HediffGiver_Birthday) at age X:");
             stringBuilder.AppendLine();
             int num = 1;
             while ((float)num < pawn.RaceProps.lifeExpectancy + 20.0)
             {
                 float num2 = 0f;
                 foreach (HediffGiverSetDef hediffGiverSet2 in pawn.RaceProps.hediffGiverSets)
                 {
                     foreach (HediffGiver_Birthday item8 in hediffGiverSet2.hediffGivers.OfType <HediffGiver_Birthday>())
                     {
                         num2 += item8.DebugChanceToHaveAtAge(pawn, num);
                     }
                 }
                 stringBuilder.AppendLine(num + ": " + num2.ToStringDecimalIfSmall());
                 num++;
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         Find.WindowStack.Add(new FloatMenu(list));
     }
 }
        private void DrawThingRow(ref float y, float width, Thing thing, bool inventory = false)
        {
            Rect rect = new Rect(0f, y, width, 28f);

            Widgets.InfoCardButton(rect.width - 24f, y, thing);
            rect.width -= 24f;
            bool flag = false;

            if (CanControl && (inventory || CanControlColonist || (SelPawnForGear.Spawned && !SelPawnForGear.Map.IsPlayerHome)))
            {
                Rect rect2 = new Rect(rect.width - 24f, y, 24f, 24f);
                bool flag2 = false;
                if (SelPawnForGear.IsQuestLodger())
                {
                    flag2 = inventory || !EquipmentUtility.QuestLodgerCanUnequip(thing, SelPawnForGear);
                }
                Apparel apparel;
                bool    flag3 = (apparel = thing as Apparel) != null && SelPawnForGear.apparel != null && SelPawnForGear.apparel.IsLocked(apparel);
                flag = flag2 || flag3;
                if (Mouse.IsOver(rect2))
                {
                    if (flag3)
                    {
                        TooltipHandler.TipRegion(rect2, "DropThingLocked".Translate());
                    }
                    else if (flag2)
                    {
                        TooltipHandler.TipRegion(rect2, "DropThingLodger".Translate());
                    }
                    else
                    {
                        TooltipHandler.TipRegion(rect2, "DropThing".Translate());
                    }
                }
                Color color          = (flag ? Color.grey : Color.white);
                Color mouseoverColor = (flag ? color : GenUI.MouseoverColor);
                if (Widgets.ButtonImage(rect2, TexButton.Drop, color, mouseoverColor, !flag) && !flag)
                {
                    SoundDefOf.Tick_High.PlayOneShotOnCamera();
                    InterfaceDrop(thing);
                }
                rect.width -= 24f;
            }
            if (CanControlColonist)
            {
                if (FoodUtility.WillIngestFromInventoryNow(SelPawnForGear, thing))
                {
                    Rect rect3 = new Rect(rect.width - 24f, y, 24f, 24f);
                    TooltipHandler.TipRegionByKey(rect3, "ConsumeThing", thing.LabelNoCount, thing);
                    if (Widgets.ButtonImage(rect3, TexButton.Ingest))
                    {
                        SoundDefOf.Tick_High.PlayOneShotOnCamera();
                        FoodUtility.IngestFromInventoryNow(SelPawnForGear, thing);
                    }
                }
                rect.width -= 24f;
            }
            Rect rect4 = rect;

            rect4.xMin = rect4.xMax - 60f;
            CaravanThingsTabUtility.DrawMass(thing, rect4);
            rect.width -= 60f;
            if (Mouse.IsOver(rect))
            {
                GUI.color = HighlightColor;
                GUI.DrawTexture(rect, TexUI.HighlightTex);
            }
            if (thing.def.DrawMatSingle != null && thing.def.DrawMatSingle.mainTexture != null)
            {
                Widgets.ThingIcon(new Rect(4f, y, 28f, 28f), thing);
            }
            Text.Anchor = TextAnchor.MiddleLeft;
            GUI.color   = ThingLabelColor;
            Rect    rect5    = new Rect(36f, y, rect.width - 36f, rect.height);
            string  text     = thing.LabelCap;
            Apparel apparel2 = thing as Apparel;

            if (apparel2 != null && SelPawnForGear.outfits != null && SelPawnForGear.outfits.forcedHandler.IsForced(apparel2))
            {
                text += ", " + "ApparelForcedLower".Translate();
            }
            if (flag)
            {
                text += " (" + "ApparelLockedLower".Translate() + ")";
            }
            Text.WordWrap = false;
            Widgets.Label(rect5, text.Truncate(rect5.width));
            Text.WordWrap = true;
            if (Mouse.IsOver(rect))
            {
                string text2 = thing.DescriptionDetailed;
                if (thing.def.useHitPoints)
                {
                    text2 = text2 + "\n" + thing.HitPoints + " / " + thing.MaxHitPoints;
                }
                TooltipHandler.TipRegion(rect, text2);
            }
            y += 28f;
        }
예제 #28
0
 private static void DoDebugOptions(Rect rightRect, Pawn pawn)
 {
     Widgets.CheckboxLabeled(new Rect(rightRect.x, rightRect.y - 25f, 110f, 30f), "Dev: AllDiffs", ref HealthCardUtility.showAllHediffs, false);
     Widgets.CheckboxLabeled(new Rect(rightRect.x + 115f, rightRect.y - 25f, 120f, 30f), "DiffsDebugInfo", ref HealthCardUtility.showHediffsDebugInfo, false);
     if (Widgets.ButtonText(new Rect(rightRect.x + 240f, rightRect.y - 27f, 115f, 25f), "Debug info", true, false, true))
     {
         List <FloatMenuOption> list = new List <FloatMenuOption>();
         list.Add(new FloatMenuOption("Parts hit chance (this part or any child node)", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             foreach (BodyPartRecord current in from x in pawn.RaceProps.body.AllParts
                      orderby x.coverageAbsWithChildren descending
                      select x)
             {
                 stringBuilder.AppendLine(current.def.LabelCap + " " + current.coverageAbsWithChildren.ToStringPercent());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("Parts hit chance (exactly this part)", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             float num = 0f;
             foreach (BodyPartRecord current in from x in pawn.RaceProps.body.AllParts
                      orderby x.coverageAbs descending
                      select x)
             {
                 stringBuilder.AppendLine(current.def.LabelCap + " " + current.coverageAbs.ToStringPercent());
                 num += current.coverageAbs;
             }
             stringBuilder.AppendLine();
             stringBuilder.AppendLine("Total " + num.ToStringPercent());
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("Per-part efficiency", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             foreach (BodyPartRecord current in pawn.RaceProps.body.AllParts)
             {
                 stringBuilder.AppendLine(current.def.LabelCap + " " + PawnCapacityUtility.CalculatePartEfficiency(pawn.health.hediffSet, current, false, null).ToStringPercent());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("BodyPartGroup efficiency (of only natural parts)", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             foreach (BodyPartGroupDef current in from x in DefDatabase <BodyPartGroupDef> .AllDefs
                      where pawn.RaceProps.body.AllParts.Any((BodyPartRecord y) => y.groups.Contains(x))
                      select x)
             {
                 stringBuilder.AppendLine(current.LabelCap + " " + PawnCapacityUtility.CalculateNaturalPartsAverageEfficiency(pawn.health.hediffSet, current).ToStringPercent());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("IsSolid", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             foreach (BodyPartRecord current in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined))
             {
                 stringBuilder.AppendLine(current.def.LabelCap + " " + current.def.IsSolid(current, pawn.health.hediffSet.hediffs));
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("IsSkinCovered", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             foreach (BodyPartRecord current in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined))
             {
                 stringBuilder.AppendLine(current.def.LabelCap + " " + current.def.IsSkinCovered(current, pawn.health.hediffSet));
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("does have added parts", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             foreach (BodyPartRecord current in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined))
             {
                 stringBuilder.AppendLine(current.def.LabelCap + " " + pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(current));
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("GetNotMissingParts", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             foreach (BodyPartRecord current in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined))
             {
                 stringBuilder.AppendLine(current.def.LabelCap);
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("GetCoverageOfNotMissingNaturalParts", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             foreach (BodyPartRecord current in from x in pawn.RaceProps.body.AllParts
                      orderby pawn.health.hediffSet.GetCoverageOfNotMissingNaturalParts(x) descending
                      select x)
             {
                 stringBuilder.AppendLine(current.def.LabelCap + ": " + pawn.health.hediffSet.GetCoverageOfNotMissingNaturalParts(current).ToStringPercent());
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("parts nutrition", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             foreach (BodyPartRecord current in from x in pawn.RaceProps.body.AllParts
                      orderby FoodUtility.GetBodyPartNutrition(pawn, x) descending
                      select x)
             {
                 stringBuilder.AppendLine(current.def.LabelCap + ": " + FoodUtility.GetBodyPartNutrition(pawn, current));
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("test old injury pain factor probability", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             int num    = 0;
             int num2   = 0;
             int num3   = 0;
             float num4 = 0f;
             int num5   = 10000;
             for (int i = 0; i < num5; i++)
             {
                 float randomPainFactor = OldInjuryUtility.GetRandomPainFactor();
                 if (randomPainFactor < 0f)
                 {
                     Log.Error("Pain factor < 0");
                 }
                 if (randomPainFactor == 0f)
                 {
                     num++;
                 }
                 if (randomPainFactor < 1f)
                 {
                     num2++;
                 }
                 if (randomPainFactor < 5f)
                 {
                     num3++;
                 }
                 if (randomPainFactor > num4)
                 {
                     num4 = randomPainFactor;
                 }
             }
             stringBuilder.AppendLine("total: " + num5);
             stringBuilder.AppendLine(string.Concat(new object[]
             {
                 "0: ",
                 num,
                 " (",
                 ((float)num / (float)num5).ToStringPercent(),
                 ")"
             }));
             stringBuilder.AppendLine(string.Concat(new object[]
             {
                 "< 1: ",
                 num2,
                 " (",
                 ((float)num2 / (float)num5).ToStringPercent(),
                 ")"
             }));
             stringBuilder.AppendLine(string.Concat(new object[]
             {
                 "< 5: ",
                 num3,
                 " (",
                 ((float)num3 / (float)num5).ToStringPercent(),
                 ")"
             }));
             stringBuilder.AppendLine("max: " + num4);
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("HediffGiver_Birthday chance at age", delegate
         {
             List <FloatMenuOption> list2 = new List <FloatMenuOption>();
             foreach (HediffGiverSetDef current in pawn.RaceProps.hediffGiverSets)
             {
                 foreach (HediffGiver_Birthday current2 in current.hediffGivers.OfType <HediffGiver_Birthday>())
                 {
                     HediffGiver_Birthday hLocal = current2;
                     FloatMenuOption item        = new FloatMenuOption(current.defName + " - " + current2.hediff.defName, delegate
                     {
                         StringBuilder stringBuilder = new StringBuilder();
                         stringBuilder.AppendLine("% of pawns which will have at least 1 " + hLocal.hediff.label + " at age X:");
                         stringBuilder.AppendLine();
                         int num = 1;
                         while ((float)num < pawn.RaceProps.lifeExpectancy + 20f)
                         {
                             stringBuilder.AppendLine(num + ": " + hLocal.DebugChanceToHaveAtAge(pawn, num).ToStringPercent());
                             num++;
                         }
                         Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
                     }, MenuOptionPriority.Default, null, null, 0f, null, null);
                     list2.Add(item);
                 }
             }
             Find.WindowStack.Add(new FloatMenu(list2));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         list.Add(new FloatMenuOption("HediffGiver_Birthday count at age", delegate
         {
             StringBuilder stringBuilder = new StringBuilder();
             stringBuilder.AppendLine("Average hediffs count (from HediffGiver_Birthday) at age X:");
             stringBuilder.AppendLine();
             int num = 1;
             while ((float)num < pawn.RaceProps.lifeExpectancy + 20f)
             {
                 float num2 = 0f;
                 foreach (HediffGiverSetDef current in pawn.RaceProps.hediffGiverSets)
                 {
                     foreach (HediffGiver_Birthday current2 in current.hediffGivers.OfType <HediffGiver_Birthday>())
                     {
                         num2 += current2.DebugChanceToHaveAtAge(pawn, num);
                     }
                 }
                 stringBuilder.AppendLine(num + ": " + num2.ToStringDecimalIfSmall());
                 num++;
             }
             Find.WindowStack.Add(new Dialog_MessageBox(stringBuilder.ToString(), null, null, null, null, null, false));
         }, MenuOptionPriority.Default, null, null, 0f, null, null));
         Find.WindowStack.Add(new FloatMenu(list));
     }
 }
 private void InterfaceIngest(Thing t)
 {
     FoodUtility.IngestFromInventoryNow(SelPawnForGear, t);
 }
예제 #30
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Need_Food food = pawn.needs.food;

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

            if (pawn.AnimalOrWildMan())
            {
                flag = true;
            }
            else
            {
                Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Malnutrition);
                flag = (firstHediffOfDef != null && firstHediffOfDef.Severity > 0.4f);
            }
            bool     flag2              = pawn.needs.food.CurCategory == HungerCategory.Starving;
            bool     desperate          = flag2;
            bool     canRefillDispenser = true;
            bool     canUseInventory    = true;
            bool     allowCorpse        = flag;
            bool     flag3              = forceScanWholeMap;
            Thing    foodSource         = default(Thing);
            ThingDef foodDef            = default(ThingDef);

            if (!FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, desperate, out foodSource, out foodDef, canRefillDispenser, canUseInventory, allowForbidden: false, allowCorpse, allowSociallyImproper: false, pawn.IsWildMan(), flag3))
            {
                return(null);
            }
            Pawn pawn2 = foodSource as Pawn;

            if (pawn2 != null)
            {
                Job job = new Job(JobDefOf.PredatorHunt, pawn2);
                job.killIncappedTarget = true;
                return(job);
            }
            if (foodSource is Plant && foodSource.def.plant.harvestedThingDef == foodDef)
            {
                return(new Job(JobDefOf.Harvest, foodSource));
            }
            Building_NutrientPasteDispenser building_NutrientPasteDispenser = foodSource as Building_NutrientPasteDispenser;

            if (building_NutrientPasteDispenser != null && !building_NutrientPasteDispenser.HasEnoughFeedstockInHoppers())
            {
                Building building = building_NutrientPasteDispenser.AdjacentReachableHopper(pawn);
                if (building != null)
                {
                    ISlotGroupParent hopperSgp = building as ISlotGroupParent;
                    Job job2 = WorkGiver_CookFillHopper.HopperFillFoodJob(pawn, hopperSgp);
                    if (job2 != null)
                    {
                        return(job2);
                    }
                }
                foodSource = FoodUtility.BestFoodSourceOnMap(pawn, pawn, flag2, out foodDef, FoodPreferability.MealLavish, allowPlant: false, !pawn.IsTeetotaler(), allowCorpse: false, allowDispenserFull: false, allowDispenserEmpty: false, allowForbidden: false, allowSociallyImproper: false, allowHarvest: false, forceScanWholeMap);
                if (foodSource == null)
                {
                    return(null);
                }
            }
            float nutrition = FoodUtility.GetNutrition(foodSource, foodDef);
            Job   job3      = new Job(JobDefOf.Ingest, foodSource);

            job3.count = FoodUtility.WillIngestStackCountOf(pawn, foodDef, nutrition);
            return(job3);
        }