예제 #1
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 forceScanWholeMap = 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);
                    }
                }
            }
            ThingDef     thingDef;
            ref ThingDef foodDef2   = ref thingDef;
        public override void DoCellSteadyEffects(IntVec3 c, Map map)
        {
            if (c.Roofed(map))
            {
                return;
            }
            List <Thing> thingList = c.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                Thing thing = thingList[i];
                if (thing is Plant)
                {
                    if (thing.def.plant.dieFromToxicFallout && Rand.Value < 0.0065f)
                    {
                        thing.Kill();
                    }
                }
                else if (thing.def.category == ThingCategory.Item)
                {
                    CompRottable compRottable = thing.TryGetComp <CompRottable>();
                    if (compRottable != null && (int)compRottable.Stage < 2)
                    {
                        compRottable.RotProgress += 3000f;
                    }
                }
            }
        }
예제 #3
0
 public override void DoCellSteadyEffects(IntVec3 c, Map map)
 {
     if (!c.Roofed(map))
     {
         List <Thing> thingList = c.GetThingList(map);
         for (int i = 0; i < thingList.Count; i++)
         {
             Thing thing = thingList[i];
             if (thing is Plant)
             {
                 if (Rand.Value < 0.0065f)
                 {
                     thing.Kill(null, null);
                 }
             }
             else if (thing.def.category == ThingCategory.Item)
             {
                 CompRottable compRottable = thing.TryGetComp <CompRottable>();
                 if (compRottable != null)
                 {
                     if (compRottable.Stage < RotStage.Dessicated)
                     {
                         compRottable.RotProgress += 3000f;
                     }
                 }
             }
         }
     }
 }
 private void DrawDaysUntilRot(Rect rect, TransferableOneWay trad)
 {
     if (!trad.HasAnyThing || !trad.ThingDef.IsNutritionGivingIngestible)
     {
         return;
     }
     if (!cachedTicksUntilRot.TryGetValue(trad, out var value))
     {
         value = int.MaxValue;
         for (int i = 0; i < trad.things.Count; i++)
         {
             CompRottable compRottable = trad.things[i].TryGetComp <CompRottable>();
             if (compRottable != null)
             {
                 value = Mathf.Min(value, DaysUntilRotCalculator.ApproxTicksUntilRot_AssumeTimePassesBy(compRottable, tile));
             }
         }
         cachedTicksUntilRot.Add(trad, value);
     }
     if (value < 36000000 && !((float)value >= 3.6E+07f))
     {
         Widgets.DrawHighlightIfMouseover(rect);
         float num = (float)value / 60000f;
         GUI.color = Color.yellow;
         Widgets.Label(rect, num.ToString("0.#"));
         GUI.color = Color.white;
         TooltipHandler.TipRegionByKey(rect, "DaysUntilRotTip");
     }
 }
예제 #5
0
 private void DrawDaysUntilRot(Rect rect, TransferableOneWay trad)
 {
     if (trad.HasAnyThing && trad.ThingDef.IsNutritionGivingIngestible)
     {
         int num = 2147483647;
         for (int i = 0; i < trad.things.Count; i++)
         {
             CompRottable compRottable = trad.things[i].TryGetComp <CompRottable>();
             if (compRottable != null)
             {
                 num = Mathf.Min(num, compRottable.ApproxTicksUntilRotWhenAtTempOfTile(this.drawDaysUntilRotForTile));
             }
         }
         if (num < 36000000)
         {
             if (Mouse.IsOver(rect))
             {
                 Widgets.DrawHighlight(rect);
             }
             float num2 = (float)((float)num / 60000.0);
             GUI.color = Color.yellow;
             Widgets.Label(rect, num2.ToString("0.#"));
             GUI.color = Color.white;
             TooltipHandler.TipRegion(rect, "DaysUntilRotTip".Translate());
         }
     }
 }
예제 #6
0
        private void DrawDaysUntilRot(Rect rect, TransferableOneWay trad)
        {
            if (!trad.HasAnyThing)
            {
                return;
            }
            if (!trad.ThingDef.IsNutritionGivingIngestible)
            {
                return;
            }
            int num = int.MaxValue;

            for (int i = 0; i < trad.things.Count; i++)
            {
                CompRottable compRottable = trad.things[i].TryGetComp <CompRottable>();
                if (compRottable != null)
                {
                    num = Mathf.Min(num, DaysUntilRotCalculator.ApproxTicksUntilRot_AssumeTimePassesBy(compRottable, this.tile, null));
                }
            }
            if (num >= 36000000)
            {
                return;
            }
            Widgets.DrawHighlightIfMouseover(rect);
            float num2 = (float)num / 60000f;

            GUI.color = Color.yellow;
            Widgets.Label(rect, num2.ToString("0.#"));
            GUI.color = Color.white;
            TooltipHandler.TipRegion(rect, "DaysUntilRotTip".Translate());
        }
예제 #7
0
        public override bool Matches(Thing t)
        {
            CompRottable compRottable = t.TryGetComp <CompRottable>();

            if (compRottable == null || compRottable.PropsRot.rotDestroys)
            {
                return(false);
            }
            return(compRottable.Stage != RotStage.Fresh);
        }
        public static bool IsDessicated(this Thing t)
        {
            CompRottable compRottable = t.TryGetComp <CompRottable>();

            if (compRottable != null)
            {
                return(compRottable.Stage == RotStage.Dessicated);
            }
            return(false);
        }
예제 #9
0
        public override bool Matches(Thing t)
        {
            CompRottable compRottable = t.TryGetComp <CompRottable>();

            if (compRottable == null)
            {
                return(t.def.IsIngestible);
            }
            return(compRottable.Stage == RotStage.Fresh);
        }
        public static bool IsNotFresh(this Thing t)
        {
            CompRottable compRottable = t.TryGetComp <CompRottable>();

            if (compRottable != null)
            {
                return(compRottable.Stage != RotStage.Fresh);
            }
            return(false);
        }
예제 #11
0
        public static RotStage GetRotStage(this Thing t)
        {
            CompRottable compRottable = t.TryGetComp <CompRottable>();

            if (compRottable == null)
            {
                return(RotStage.Fresh);
            }
            return(compRottable.Stage);
        }
예제 #12
0
        public static float FoodOptimality(Pawn eater, Thing foodSource, ThingDef foodDef, float dist, bool takingToInventory = false)
        {
            float num = 300f;

            num -= dist;
            switch (foodDef.ingestible.preferability)
            {
            case FoodPreferability.NeverForNutrition:
                return(-9999999f);

            case FoodPreferability.DesperateOnly:
                num = (float)(num - 150.0);
                break;

            case FoodPreferability.DesperateOnlyForHumanlikes:
                if (eater.RaceProps.Humanlike)
                {
                    num = (float)(num - 150.0);
                }
                break;
            }
            CompRottable compRottable = foodSource.TryGetComp <CompRottable>();

            if (compRottable != null)
            {
                if (compRottable.Stage == RotStage.Dessicated)
                {
                    return(-9999999f);
                }
                if (!takingToInventory && compRottable.Stage == RotStage.Fresh && compRottable.TicksUntilRotAtCurrentTemp < 30000)
                {
                    num = (float)(num + 12.0);
                }
            }
            if (eater.needs != null && eater.needs.mood != null)
            {
                List <ThoughtDef> list = FoodUtility.ThoughtsFromIngesting(eater, foodSource, foodDef);
                for (int i = 0; i < list.Count; i++)
                {
                    num += FoodUtility.FoodOptimalityEffectFromMoodCurve.Evaluate(list[i].stages[0].baseMoodEffect);
                }
            }
            if (foodDef.ingestible != null)
            {
                if (eater.RaceProps.Humanlike)
                {
                    num += foodDef.ingestible.optimalityOffsetHumanlikes;
                }
                else if (eater.RaceProps.Animal)
                {
                    num += foodDef.ingestible.optimalityOffsetFeedingAnimals;
                }
            }
            return(num);
        }
        public override bool Matches(Thing t)
        {
            ThingWithComps thingWithComps = t as ThingWithComps;

            if (thingWithComps == null)
            {
                return(false);
            }
            CompRottable comp = thingWithComps.GetComp <CompRottable>();

            return(comp != null && !((CompProperties_Rottable)comp.props).rotDestroys && comp.Stage != RotStage.Fresh);
        }
예제 #14
0
        public static RotStage GetRotStage(this Thing t)
        {
            CompRottable compRottable = t.TryGetComp <CompRottable>();
            RotStage     result;

            if (compRottable == null)
            {
                result = RotStage.Fresh;
            }
            else
            {
                result = compRottable.Stage;
            }
            return(result);
        }
예제 #15
0
        public override bool Matches(Thing t)
        {
            CompRottable compRottable = t.TryGetComp <CompRottable>();
            bool         result;

            if (compRottable == null)
            {
                result = t.def.IsIngestible;
            }
            else
            {
                result = (compRottable.Stage == RotStage.Fresh);
            }
            return(result);
        }
예제 #16
0
        private float GetFoodScore(Pawn pawn, Thing food, List <Pair <int, int> > ticksToArrive)
        {
            if (!CaravanPawnsNeedsUtility.CanEatForNutritionEver(food.def, pawn) || !food.def.ingestible.canAutoSelectAsFoodForCaravan)
            {
                return(0f);
            }
            float        num          = CaravanPawnsNeedsUtility.GetFoodScore(food.def, pawn, food.GetStatValue(StatDefOf.Nutrition));
            CompRottable compRottable = food.TryGetComp <CompRottable>();

            if (compRottable != null && compRottable.Active && DaysUntilRotCalculator.ApproxTicksUntilRot_AssumeTimePassesBy(compRottable, CurrentTile, ticksToArrive) < ticksToArrive.Last().Second)
            {
                num *= 0.1f;
            }
            return(num);
        }
        public static bool TransferAsOne(Thing a, Thing b, TransferAsOneMode mode)
        {
            bool result;

            if (a == b)
            {
                result = true;
            }
            else if (a.def != b.def)
            {
                result = false;
            }
            else
            {
                a = a.GetInnerIfMinified();
                b = b.GetInnerIfMinified();
                if (a.def.tradeNeverStack || b.def.tradeNeverStack)
                {
                    result = false;
                }
                else if (!TransferableUtility.CanStack(a) || !TransferableUtility.CanStack(b))
                {
                    result = false;
                }
                else if (a.def != b.def || a.Stuff != b.Stuff)
                {
                    result = false;
                }
                else
                {
                    if (mode == TransferAsOneMode.PodsOrCaravanPacking)
                    {
                        float        num          = -1f;
                        CompRottable compRottable = a.TryGetComp <CompRottable>();
                        if (compRottable != null)
                        {
                            num = compRottable.RotProgressPct;
                        }
                        float        num2          = -1f;
                        CompRottable compRottable2 = b.TryGetComp <CompRottable>();
                        if (compRottable2 != null)
                        {
                            num2 = compRottable2.RotProgressPct;
                        }
                        if (Mathf.Abs(num - num2) > 0.1f)
                        {
                            return(false);
                        }
                    }
                    if (a is Corpse && b is Corpse)
                    {
                        Pawn innerPawn  = ((Corpse)a).InnerPawn;
                        Pawn innerPawn2 = ((Corpse)b).InnerPawn;
                        result = (innerPawn.def == innerPawn2.def && innerPawn.kindDef == innerPawn2.kindDef && !innerPawn.RaceProps.Humanlike && !innerPawn2.RaceProps.Humanlike && (innerPawn.Name == null || innerPawn.Name.Numerical) && (innerPawn2.Name == null || innerPawn2.Name.Numerical));
                    }
                    else if (a.def.category == ThingCategory.Pawn)
                    {
                        if (b.def != a.def)
                        {
                            result = false;
                        }
                        else
                        {
                            Pawn pawn  = (Pawn)a;
                            Pawn pawn2 = (Pawn)b;
                            result = (pawn.kindDef == pawn2.kindDef && pawn.gender == pawn2.gender && pawn.ageTracker.CurLifeStageIndex == pawn2.ageTracker.CurLifeStageIndex && Mathf.Abs(pawn.ageTracker.AgeBiologicalYearsFloat - pawn2.ageTracker.AgeBiologicalYearsFloat) <= 1f);
                        }
                    }
                    else
                    {
                        Apparel apparel  = a as Apparel;
                        Apparel apparel2 = b as Apparel;
                        if (apparel != null && apparel2 != null)
                        {
                            if (apparel.WornByCorpse != apparel2.WornByCorpse)
                            {
                                return(false);
                            }
                        }
                        if (mode != TransferAsOneMode.InactiveTradeable && a.def.useHitPoints && Mathf.Abs(a.HitPoints - b.HitPoints) >= 10)
                        {
                            result = false;
                        }
                        else
                        {
                            QualityCategory qualityCategory;
                            QualityCategory qualityCategory2;
                            if (a.TryGetQuality(out qualityCategory) && b.TryGetQuality(out qualityCategory2))
                            {
                                if (qualityCategory != qualityCategory2)
                                {
                                    return(false);
                                }
                            }
                            if (a.def.category == ThingCategory.Item)
                            {
                                result = a.CanStackWith(b);
                            }
                            else if (a.def.category == ThingCategory.Building)
                            {
                                result = true;
                            }
                            else
                            {
                                Log.Error(string.Concat(new object[]
                                {
                                    "Unknown TransferAsOne pair: ",
                                    a,
                                    ", ",
                                    b
                                }), false);
                                result = false;
                            }
                        }
                    }
                }
            }
            return(result);
        }
예제 #18
0
        public static void MakeColony(params ColonyMakerFlag[] flags)
        {
            bool godMode = DebugSettings.godMode;

            DebugSettings.godMode            = true;
            Thing.allowDestroyNonDestroyable = true;
            if (Autotests_ColonyMaker.usedCells == null)
            {
                Autotests_ColonyMaker.usedCells = new BoolGrid(Autotests_ColonyMaker.Map);
            }
            else
            {
                Autotests_ColonyMaker.usedCells.ClearAndResizeTo(Autotests_ColonyMaker.Map);
            }
            Autotests_ColonyMaker.overRect = new CellRect(Autotests_ColonyMaker.Map.Center.x - 50, Autotests_ColonyMaker.Map.Center.z - 50, 100, 100);
            Autotests_ColonyMaker.DeleteAllSpawnedPawns();
            GenDebug.ClearArea(Autotests_ColonyMaker.overRect, Find.VisibleMap);
            if (flags.Contains(ColonyMakerFlag.Animals))
            {
                foreach (PawnKindDef current in from k in DefDatabase <PawnKindDef> .AllDefs
                         where k.RaceProps.Animal
                         select k)
                {
                    CellRect cellRect;
                    if (!Autotests_ColonyMaker.TryGetFreeRect(6, 3, out cellRect))
                    {
                        return;
                    }
                    cellRect = cellRect.ContractedBy(1);
                    foreach (IntVec3 current2 in cellRect)
                    {
                        Autotests_ColonyMaker.Map.terrainGrid.SetTerrain(current2, TerrainDefOf.Concrete);
                    }
                    GenSpawn.Spawn(PawnGenerator.GeneratePawn(current, null), cellRect.Cells.ElementAt(0), Autotests_ColonyMaker.Map);
                    IntVec3 intVec = cellRect.Cells.ElementAt(1);
                    Pawn    p      = (Pawn)GenSpawn.Spawn(PawnGenerator.GeneratePawn(current, null), intVec, Autotests_ColonyMaker.Map);
                    HealthUtility.DamageUntilDead(p);
                    Corpse       thing        = (Corpse)intVec.GetThingList(Find.VisibleMap).First((Thing t) => t is Corpse);
                    CompRottable compRottable = thing.TryGetComp <CompRottable>();
                    if (compRottable != null)
                    {
                        compRottable.RotProgress += 1200000f;
                    }
                    if (current.RaceProps.leatherDef != null)
                    {
                        GenSpawn.Spawn(current.RaceProps.leatherDef, cellRect.Cells.ElementAt(2), Autotests_ColonyMaker.Map);
                    }
                    if (current.RaceProps.meatDef != null)
                    {
                        GenSpawn.Spawn(current.RaceProps.meatDef, cellRect.Cells.ElementAt(3), Autotests_ColonyMaker.Map);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ConduitGrid))
            {
                Designator_Build designator_Build = new Designator_Build(ThingDefOf.PowerConduit);
                for (int i = Autotests_ColonyMaker.overRect.minX; i < Autotests_ColonyMaker.overRect.maxX; i++)
                {
                    for (int j = Autotests_ColonyMaker.overRect.minZ; j < Autotests_ColonyMaker.overRect.maxZ; j += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(i, 0, j));
                    }
                }
                for (int k2 = Autotests_ColonyMaker.overRect.minZ; k2 < Autotests_ColonyMaker.overRect.maxZ; k2++)
                {
                    for (int l = Autotests_ColonyMaker.overRect.minX; l < Autotests_ColonyMaker.overRect.maxX; l += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(l, 0, k2));
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.PowerPlants))
            {
                List <ThingDef> list = new List <ThingDef>
                {
                    ThingDefOf.SolarGenerator,
                    ThingDefOf.WindTurbine
                };
                for (int m = 0; m < 8; m++)
                {
                    if (Autotests_ColonyMaker.TryMakeBuilding(list[m % list.Count]) == null)
                    {
                        Log.Message("Could not make solar generator.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Batteries))
            {
                for (int n = 0; n < 6; n++)
                {
                    Thing thing2 = Autotests_ColonyMaker.TryMakeBuilding(ThingDefOf.Battery);
                    if (thing2 == null)
                    {
                        Log.Message("Could not make battery.");
                        break;
                    }
                    ((Building_Battery)thing2).GetComp <CompPowerBattery>().AddEnergy(999999f);
                }
            }
            if (flags.Contains(ColonyMakerFlag.WorkTables))
            {
                IEnumerable <ThingDef> enumerable = from def in DefDatabase <ThingDef> .AllDefs
                                                    where typeof(Building_WorkTable).IsAssignableFrom(def.thingClass)
                                                    select def;
                foreach (ThingDef current3 in enumerable)
                {
                    Thing thing3 = Autotests_ColonyMaker.TryMakeBuilding(current3);
                    if (thing3 == null)
                    {
                        Log.Message("Could not make worktable: " + current3.defName);
                        break;
                    }
                    Building_WorkTable building_WorkTable = thing3 as Building_WorkTable;
                    if (building_WorkTable != null)
                    {
                        foreach (RecipeDef current4 in building_WorkTable.def.AllRecipes)
                        {
                            building_WorkTable.billStack.AddBill(current4.MakeNewBill());
                        }
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.AllBuildings))
            {
                IEnumerable <ThingDef> enumerable2 = from def in DefDatabase <ThingDef> .AllDefs
                                                     where def.category == ThingCategory.Building && def.designationCategory != null
                                                     select def;
                foreach (ThingDef current5 in enumerable2)
                {
                    if (current5 != ThingDefOf.PowerConduit)
                    {
                        if (Autotests_ColonyMaker.TryMakeBuilding(current5) == null)
                        {
                            Log.Message("Could not make building: " + current5.defName);
                            break;
                        }
                    }
                }
            }
            CellRect rect;

            if (!Autotests_ColonyMaker.TryGetFreeRect(33, 33, out rect))
            {
                Log.Error("Could not get wallable rect");
            }
            rect = rect.ContractedBy(1);
            if (flags.Contains(ColonyMakerFlag.AllItems))
            {
                List <ThingDef> itemDefs = (from def in DefDatabase <ThingDef> .AllDefs
                                            where DebugThingPlaceHelper.IsDebugSpawnable(def) && def.category == ThingCategory.Item
                                            select def).ToList <ThingDef>();
                Autotests_ColonyMaker.FillWithItems(rect, itemDefs);
            }
            else if (flags.Contains(ColonyMakerFlag.ItemsRawFood))
            {
                List <ThingDef> list2 = new List <ThingDef>();
                list2.Add(ThingDefOf.RawPotatoes);
                Autotests_ColonyMaker.FillWithItems(rect, list2);
            }
            if (flags.Contains(ColonyMakerFlag.Filth))
            {
                foreach (IntVec3 current6 in rect)
                {
                    GenSpawn.Spawn(ThingDefOf.FilthDirt, current6, Autotests_ColonyMaker.Map);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ItemsWall))
            {
                CellRect         cellRect2         = rect.ExpandedBy(1);
                Designator_Build designator_Build2 = new Designator_Build(ThingDefOf.Wall);
                designator_Build2.SetStuffDef(ThingDefOf.WoodLog);
                foreach (IntVec3 current7 in cellRect2.EdgeCells)
                {
                    designator_Build2.DesignateSingleCell(current7);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsMany))
            {
                Autotests_ColonyMaker.MakeColonists(15, Autotests_ColonyMaker.overRect.CenterCell);
            }
            else if (flags.Contains(ColonyMakerFlag.ColonistOne))
            {
                Autotests_ColonyMaker.MakeColonists(1, Autotests_ColonyMaker.overRect.CenterCell);
            }
            if (flags.Contains(ColonyMakerFlag.Fire))
            {
                CellRect cellRect3;
                if (!Autotests_ColonyMaker.TryGetFreeRect(30, 30, out cellRect3))
                {
                    Log.Error("Could not get free rect for fire.");
                }
                ThingDef plantTreeOak = ThingDefOf.PlantTreeOak;
                foreach (IntVec3 current8 in cellRect3)
                {
                    GenSpawn.Spawn(plantTreeOak, current8, Autotests_ColonyMaker.Map);
                }
                foreach (IntVec3 current9 in cellRect3)
                {
                    if (current9.x % 7 == 0 && current9.z % 7 == 0)
                    {
                        GenExplosion.DoExplosion(current9, Find.VisibleMap, 3.9f, DamageDefOf.Flame, null, -1, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsHungry))
            {
                Autotests_ColonyMaker.DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.food.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsTired))
            {
                Autotests_ColonyMaker.DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.rest.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsInjured))
            {
                Autotests_ColonyMaker.DoToColonists(0.4f, delegate(Pawn col)
                {
                    DamageDef def = (from d in DefDatabase <DamageDef> .AllDefs
                                     where d.externalViolence
                                     select d).RandomElement <DamageDef>();
                    col.TakeDamage(new DamageInfo(def, 10, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsDiseased))
            {
                foreach (HediffDef current10 in from d in DefDatabase <HediffDef> .AllDefs
                         where d.hediffClass != typeof(Hediff_AddedPart) && (d.HasComp(typeof(HediffComp_Immunizable)) || d.HasComp(typeof(HediffComp_GrowthMode)))
                         select d)
                {
                    Pawn     pawn = PawnGenerator.GeneratePawn(Faction.OfPlayer.def.basicMemberKind, Faction.OfPlayer);
                    CellRect cellRect4;
                    Autotests_ColonyMaker.TryGetFreeRect(1, 1, out cellRect4);
                    GenSpawn.Spawn(pawn, cellRect4.CenterCell, Autotests_ColonyMaker.Map);
                    pawn.health.AddHediff(current10, null, null);
                }
            }
            if (flags.Contains(ColonyMakerFlag.Beds))
            {
                IEnumerable <ThingDef> source = from def in DefDatabase <ThingDef> .AllDefs
                                                where def.thingClass == typeof(Building_Bed)
                                                select def;
                int freeColonistsCount = Autotests_ColonyMaker.Map.mapPawns.FreeColonistsCount;
                for (int num = 0; num < freeColonistsCount; num++)
                {
                    if (Autotests_ColonyMaker.TryMakeBuilding(source.RandomElement <ThingDef>()) == null)
                    {
                        Log.Message("Could not make beds.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Stockpiles))
            {
                Designator_ZoneAddStockpile_Resources designator_ZoneAddStockpile_Resources = new Designator_ZoneAddStockpile_Resources();
                foreach (StoragePriority priority in Enum.GetValues(typeof(StoragePriority)))
                {
                    CellRect cellRect5;
                    Autotests_ColonyMaker.TryGetFreeRect(7, 7, out cellRect5);
                    cellRect5 = cellRect5.ContractedBy(1);
                    designator_ZoneAddStockpile_Resources.DesignateMultiCell(cellRect5.Cells);
                    Zone_Stockpile zone_Stockpile = (Zone_Stockpile)Autotests_ColonyMaker.Map.zoneManager.ZoneAt(cellRect5.CenterCell);
                    zone_Stockpile.settings.Priority = priority;
                }
            }
            if (flags.Contains(ColonyMakerFlag.GrowingZones))
            {
                Zone_Growing dummyZone = new Zone_Growing(Autotests_ColonyMaker.Map.zoneManager);
                foreach (ThingDef current11 in from d in DefDatabase <ThingDef> .AllDefs
                         where d.plant != null && GenPlant.CanSowOnGrower(d, dummyZone)
                         select d)
                {
                    CellRect cellRect6;
                    if (!Autotests_ColonyMaker.TryGetFreeRect(6, 6, out cellRect6))
                    {
                        Log.Error("Could not get growing zone rect.");
                    }
                    cellRect6 = cellRect6.ContractedBy(1);
                    foreach (IntVec3 current12 in cellRect6)
                    {
                        Autotests_ColonyMaker.Map.terrainGrid.SetTerrain(current12, TerrainDefOf.Soil);
                    }
                    Designator_ZoneAdd_Growing designator_ZoneAdd_Growing = new Designator_ZoneAdd_Growing();
                    designator_ZoneAdd_Growing.DesignateMultiCell(cellRect6.Cells);
                    Zone_Growing zone_Growing = (Zone_Growing)Autotests_ColonyMaker.Map.zoneManager.ZoneAt(cellRect6.CenterCell);
                    zone_Growing.SetPlantDefToGrow(current11);
                }
                dummyZone.Delete();
            }
            Autotests_ColonyMaker.ClearAllHomeArea();
            Autotests_ColonyMaker.FillWithHomeArea(Autotests_ColonyMaker.overRect);
            DebugSettings.godMode            = godMode;
            Thing.allowDestroyNonDestroyable = false;
        }
예제 #19
0
        public static bool TransferAsOne(Thing a, Thing b, TransferAsOneMode mode)
        {
            if (a == b)
            {
                return(true);
            }
            if (a.def != b.def)
            {
                return(false);
            }
            a = a.GetInnerIfMinified();
            b = b.GetInnerIfMinified();
            if (a.def.tradeNeverStack || b.def.tradeNeverStack)
            {
                return(false);
            }
            if (!CanStack(a) || !CanStack(b))
            {
                return(false);
            }
            if (a.def != b.def || a.Stuff != b.Stuff)
            {
                return(false);
            }
            if (mode == TransferAsOneMode.PodsOrCaravanPacking)
            {
                float        num          = -1f;
                CompRottable compRottable = a.TryGetComp <CompRottable>();
                if (compRottable != null)
                {
                    num = compRottable.RotProgressPct;
                }
                float        num2          = -1f;
                CompRottable compRottable2 = b.TryGetComp <CompRottable>();
                if (compRottable2 != null)
                {
                    num2 = compRottable2.RotProgressPct;
                }
                if (Mathf.Abs(num - num2) > 0.1f)
                {
                    return(false);
                }
            }
            if (a is Corpse && b is Corpse)
            {
                Pawn innerPawn  = ((Corpse)a).InnerPawn;
                Pawn innerPawn2 = ((Corpse)b).InnerPawn;
                if (innerPawn.def != innerPawn2.def)
                {
                    return(false);
                }
                if (innerPawn.kindDef != innerPawn2.kindDef)
                {
                    return(false);
                }
                if (innerPawn.RaceProps.Humanlike || innerPawn2.RaceProps.Humanlike)
                {
                    return(false);
                }
                if ((innerPawn.Name != null && !innerPawn.Name.Numerical) || (innerPawn2.Name != null && !innerPawn2.Name.Numerical))
                {
                    return(false);
                }
                return(true);
            }
            if (a.def.category == ThingCategory.Pawn)
            {
                if (b.def != a.def)
                {
                    return(false);
                }
                Pawn pawn  = (Pawn)a;
                Pawn pawn2 = (Pawn)b;
                if (pawn.kindDef != pawn2.kindDef)
                {
                    return(false);
                }
                if (pawn.gender != pawn2.gender)
                {
                    return(false);
                }
                if (pawn.ageTracker.CurLifeStageIndex != pawn2.ageTracker.CurLifeStageIndex)
                {
                    return(false);
                }
                if (Mathf.Abs(pawn.ageTracker.AgeBiologicalYearsFloat - pawn2.ageTracker.AgeBiologicalYearsFloat) > 1f)
                {
                    return(false);
                }
                return(true);
            }
            Apparel apparel  = a as Apparel;
            Apparel apparel2 = b as Apparel;

            if (apparel != null && apparel2 != null && apparel.WornByCorpse != apparel2.WornByCorpse)
            {
                return(false);
            }
            if (mode != TransferAsOneMode.InactiveTradeable && a.def.useHitPoints && Mathf.Abs(a.HitPoints - b.HitPoints) >= 10)
            {
                return(false);
            }
            QualityCategory qc;
            QualityCategory qc2;

            if (a.TryGetQuality(out qc) && b.TryGetQuality(out qc2) && qc != qc2)
            {
                return(false);
            }
            if (a.def.category == ThingCategory.Item)
            {
                return(a.CanStackWith(b));
            }
            if (a.def.category == ThingCategory.Building)
            {
                return(true);
            }
            Log.Error("Unknown TransferAsOne pair: " + a + ", " + b);
            return(false);
        }
예제 #20
0
        public static bool TransferAsOne(Thing a, Thing b)
        {
            if (a == b)
            {
                return(true);
            }
            if (a.def.tradeNeverStack || b.def.tradeNeverStack)
            {
                return(false);
            }
            float        num          = -1f;
            CompRottable compRottable = a.TryGetComp <CompRottable>();

            if (compRottable != null)
            {
                num = compRottable.RotProgressPct;
            }
            float        num2          = -1f;
            CompRottable compRottable2 = b.TryGetComp <CompRottable>();

            if (compRottable2 != null)
            {
                num2 = compRottable2.RotProgressPct;
            }
            if (Mathf.Abs(num - num2) > 0.1f)
            {
                return(false);
            }
            if (a is Corpse && b is Corpse)
            {
                Pawn innerPawn  = ((Corpse)a).InnerPawn;
                Pawn innerPawn2 = ((Corpse)b).InnerPawn;
                return(innerPawn.def == innerPawn2.def && innerPawn.kindDef == innerPawn2.kindDef && !innerPawn.RaceProps.Humanlike && !innerPawn2.RaceProps.Humanlike && (innerPawn.Name == null || innerPawn.Name.Numerical) && (innerPawn2.Name == null || innerPawn2.Name.Numerical));
            }
            if (a.def.category == ThingCategory.Pawn)
            {
                if (b.def != a.def)
                {
                    return(false);
                }
                if (a.def.race.Humanlike || b.def.race.Humanlike)
                {
                    return(false);
                }
                Pawn pawn  = (Pawn)a;
                Pawn pawn2 = (Pawn)b;
                return(pawn.kindDef == pawn2.kindDef && pawn.health.summaryHealth.SummaryHealthPercent >= 0.9999f && pawn2.health.summaryHealth.SummaryHealthPercent >= 0.9999f && pawn.gender == pawn2.gender && (pawn.Name == null || pawn.Name.Numerical) && (pawn2.Name == null || pawn2.Name.Numerical) && pawn.ageTracker.CurLifeStageIndex == pawn2.ageTracker.CurLifeStageIndex && Mathf.Abs(pawn.ageTracker.AgeBiologicalYearsFloat - pawn2.ageTracker.AgeBiologicalYearsFloat) <= 1f);
            }
            else
            {
                Apparel apparel  = a as Apparel;
                Apparel apparel2 = b as Apparel;
                if (apparel != null && apparel2 != null && apparel.WornByCorpse != apparel2.WornByCorpse)
                {
                    return(false);
                }
                if (a.def.useHitPoints && Mathf.Abs(a.HitPoints - b.HitPoints) >= 10)
                {
                    return(false);
                }
                QualityCategory qualityCategory;
                QualityCategory qualityCategory2;
                if (a.TryGetQuality(out qualityCategory) && b.TryGetQuality(out qualityCategory2) && qualityCategory != qualityCategory2)
                {
                    return(false);
                }
                if (a.def.category == ThingCategory.Item)
                {
                    return(a.CanStackWith(b));
                }
                Log.Error(string.Concat(new object[]
                {
                    "Unknown TransferAsOne pair: ",
                    a,
                    ", ",
                    b
                }));
                return(false);
            }
        }
예제 #21
0
        public override bool Matches(Thing t)
        {
            CompRottable compRottable = t.TryGetComp <CompRottable>();

            return(compRottable != null && !compRottable.PropsRot.rotDestroys && compRottable.Stage != RotStage.Fresh);
        }
        public static void ResurrectWithSideEffects(Pawn pawn)
        {
            Corpse corpse = pawn.Corpse;
            float  num;
            bool   flag;

            if (corpse != null)
            {
                CompRottable comp = corpse.GetComp <CompRottable>();
                num  = (float)(comp.RotProgress / 60000.0);
                flag = (comp.Stage == RotStage.Fresh);
            }
            else
            {
                num  = 0f;
                flag = true;
            }
            ResurrectionUtility.Resurrect(pawn);
            BodyPartRecord brain  = pawn.health.hediffSet.GetBrain();
            float          chance = Mathf.Max((float)(0.20000000298023224 * num), 0.08f);

            if (Rand.Chance(chance) && brain != null)
            {
                int a = Rand.RangeInclusive(1, 5);
                int b = Mathf.FloorToInt(pawn.health.hediffSet.GetPartHealth(brain)) - 1;
                a = Mathf.Min(a, b);
                if (a > 0 && !pawn.health.WouldDieAfterAddingHediff(HediffDefOf.Burn, brain, (float)a))
                {
                    DamageDef      burn    = DamageDefOf.Burn;
                    int            amount  = a;
                    BodyPartRecord hitPart = brain;
                    pawn.TakeDamage(new DamageInfo(burn, amount, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown));
                }
            }
            float chance2 = Mathf.Max((float)(0.11999999731779099 * num), 0.04f);

            if (Rand.Chance(chance2))
            {
                IEnumerable <BodyPartRecord> enumerable = from x in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined)
                                                          where x.def == BodyPartDefOf.LeftEye || x.def == BodyPartDefOf.RightEye
                                                          select x;
                foreach (BodyPartRecord item in enumerable)
                {
                    Hediff hediff = HediffMaker.MakeHediff(HediffDefOf.Blindness, pawn, item);
                    pawn.health.AddHediff(hediff, null, null);
                }
            }
            Hediff hediff2 = HediffMaker.MakeHediff(HediffDefOf.ResurrectionSickness, pawn, null);

            if (!pawn.health.WouldDieAfterAddingHediff(hediff2))
            {
                pawn.health.AddHediff(hediff2, null, null);
            }
            if ((!flag || Rand.Chance(0.3f)) && brain != null)
            {
                Hediff hediff3 = HediffMaker.MakeHediff(HediffDefOf.ResurrectionPsychosis, pawn, brain);
                if (!pawn.health.WouldDieAfterAddingHediff(hediff3))
                {
                    pawn.health.AddHediff(hediff3, null, null);
                }
            }
            if (pawn.Dead)
            {
                Log.Error("The pawn has died while being resurrected.");
                ResurrectionUtility.Resurrect(pawn);
            }
        }
예제 #23
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 forceScanWholeMap = false, bool ignoreReservations = false, FoodPreferability minPrefOverride = FoodPreferability.Undefined)
        {
            bool  flag      = getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation);
            bool  allowDrug = !eater.IsTeetotaler();
            Thing thing     = null;

            if (canUseInventory)
            {
                if (flag)
                {
                    thing = BestFoodInInventory(getter, eater, (minPrefOverride == FoodPreferability.Undefined) ? FoodPreferability.MealAwful : minPrefOverride);
                }
                if (thing != null)
                {
                    if (getter.Faction != Faction.OfPlayer)
                    {
                        foodSource = thing;
                        foodDef    = GetFinalIngestibleDef(foodSource);
                        return(true);
                    }
                    CompRottable compRottable = thing.TryGetComp <CompRottable>();
                    if (compRottable != null && compRottable.Stage == RotStage.Fresh && compRottable.TicksUntilRotAtCurrentTemp < 30000)
                    {
                        foodSource = thing;
                        foodDef    = GetFinalIngestibleDef(foodSource);
                        return(true);
                    }
                }
            }
            bool     allowPlant      = getter == eater;
            bool     allowForbidden2 = allowForbidden;
            ThingDef foodDef2;
            Thing    thing2 = BestFoodSourceOnMap(getter, eater, desperate, out foodDef2, FoodPreferability.MealLavish, allowPlant, allowDrug, allowCorpse, allowDispenserFull: true, canRefillDispenser, allowForbidden2, allowSociallyImproper, allowHarvest, forceScanWholeMap, ignoreReservations, minPrefOverride);

            if (thing != null || thing2 != null)
            {
                if (thing == null && thing2 != null)
                {
                    foodSource = thing2;
                    foodDef    = foodDef2;
                    return(true);
                }
                ThingDef finalIngestibleDef = GetFinalIngestibleDef(thing);
                if (thing2 == null)
                {
                    foodSource = thing;
                    foodDef    = finalIngestibleDef;
                    return(true);
                }
                float num  = FoodOptimality(eater, thing2, foodDef2, (getter.Position - thing2.Position).LengthManhattan);
                float num2 = FoodOptimality(eater, thing, finalIngestibleDef, 0f);
                num2 -= 32f;
                if (num > num2)
                {
                    foodSource = thing2;
                    foodDef    = foodDef2;
                    return(true);
                }
                foodSource = thing;
                foodDef    = GetFinalIngestibleDef(foodSource);
                return(true);
            }
            if (canUseInventory && flag)
            {
                thing = BestFoodInInventory(getter, eater, FoodPreferability.DesperateOnly, FoodPreferability.MealLavish, 0f, allowDrug);
                if (thing != null)
                {
                    foodSource = thing;
                    foodDef    = GetFinalIngestibleDef(foodSource);
                    return(true);
                }
            }
            if (thing2 == null && getter == eater && (getter.RaceProps.predator || (getter.IsWildMan() && !getter.IsPrisoner && !getter.WorkTypeIsDisabled(WorkTypeDefOf.Hunting))))
            {
                Pawn pawn = BestPawnToHuntForPredator(getter, forceScanWholeMap);
                if (pawn != null)
                {
                    foodSource = pawn;
                    foodDef    = GetFinalIngestibleDef(foodSource);
                    return(true);
                }
            }
            foodSource = null;
            foodDef    = null;
            return(false);
        }
        public static bool TransferAsOne(Thing a, Thing b)
        {
            if (a == b)
            {
                return(true);
            }
            if (!a.def.tradeNeverStack && !b.def.tradeNeverStack)
            {
                float        num          = -1f;
                CompRottable compRottable = a.TryGetComp <CompRottable>();
                if (compRottable != null)
                {
                    num = compRottable.RotProgressPct;
                }
                float        num2          = -1f;
                CompRottable compRottable2 = b.TryGetComp <CompRottable>();
                if (compRottable2 != null)
                {
                    num2 = compRottable2.RotProgressPct;
                }
                if (Mathf.Abs(num - num2) > 0.10000000149011612)
                {
                    return(false);
                }
                if (a is Corpse && b is Corpse)
                {
                    Pawn innerPawn  = ((Corpse)a).InnerPawn;
                    Pawn innerPawn2 = ((Corpse)b).InnerPawn;
                    if (innerPawn.def != innerPawn2.def)
                    {
                        return(false);
                    }
                    if (innerPawn.kindDef != innerPawn2.kindDef)
                    {
                        return(false);
                    }
                    if (!innerPawn.RaceProps.Humanlike && !innerPawn2.RaceProps.Humanlike)
                    {
                        if (innerPawn.Name != null && !innerPawn.Name.Numerical)
                        {
                            goto IL_012b;
                        }
                        if (innerPawn2.Name != null && !innerPawn2.Name.Numerical)
                        {
                            goto IL_012b;
                        }
                        return(true);
                    }
                    return(false);
                }
                if (a.def.category == ThingCategory.Pawn)
                {
                    if (b.def != a.def)
                    {
                        return(false);
                    }
                    if (!a.def.race.Humanlike && !b.def.race.Humanlike)
                    {
                        Pawn pawn  = (Pawn)a;
                        Pawn pawn2 = (Pawn)b;
                        if (pawn.kindDef != pawn2.kindDef)
                        {
                            return(false);
                        }
                        if (!(pawn.health.summaryHealth.SummaryHealthPercent < 0.99989998340606689) && !(pawn2.health.summaryHealth.SummaryHealthPercent < 0.99989998340606689))
                        {
                            if (pawn.gender != pawn2.gender)
                            {
                                return(false);
                            }
                            if (pawn.Name != null && !pawn.Name.Numerical)
                            {
                                goto IL_022b;
                            }
                            if (pawn2.Name != null && !pawn2.Name.Numerical)
                            {
                                goto IL_022b;
                            }
                            if (pawn.ageTracker.CurLifeStageIndex != pawn2.ageTracker.CurLifeStageIndex)
                            {
                                return(false);
                            }
                            if (Mathf.Abs(pawn.ageTracker.AgeBiologicalYearsFloat - pawn2.ageTracker.AgeBiologicalYearsFloat) > 1.0)
                            {
                                return(false);
                            }
                            return(true);
                        }
                        return(false);
                    }
                    return(false);
                }
                Apparel apparel  = a as Apparel;
                Apparel apparel2 = b as Apparel;
                if (apparel != null && apparel2 != null && apparel.WornByCorpse != apparel2.WornByCorpse)
                {
                    return(false);
                }
                if (a.def.useHitPoints && Mathf.Abs(a.HitPoints - b.HitPoints) >= 10)
                {
                    return(false);
                }
                QualityCategory qualityCategory  = default(QualityCategory);
                QualityCategory qualityCategory2 = default(QualityCategory);
                if (a.TryGetQuality(out qualityCategory) && b.TryGetQuality(out qualityCategory2) && qualityCategory != qualityCategory2)
                {
                    return(false);
                }
                if (a.def.category == ThingCategory.Item)
                {
                    return(a.CanStackWith(b));
                }
                Log.Error("Unknown TransferAsOne pair: " + a + ", " + b);
                return(false);
            }
            return(false);

IL_022b:
            return(false);

IL_012b:
            return(false);
        }
예제 #25
0
        public static void MakeColony(params ColonyMakerFlag[] flags)
        {
            bool godMode = DebugSettings.godMode;

            DebugSettings.godMode            = true;
            Thing.allowDestroyNonDestroyable = true;
            if (usedCells == null)
            {
                usedCells = new BoolGrid(Map);
            }
            else
            {
                usedCells.ClearAndResizeTo(Map);
            }
            IntVec3 center  = Map.Center;
            int     minX    = center.x - 50;
            IntVec3 center2 = Map.Center;

            overRect = new CellRect(minX, center2.z - 50, 100, 100);
            DeleteAllSpawnedPawns();
            GenDebug.ClearArea(overRect, Find.CurrentMap);
            if (flags.Contains(ColonyMakerFlag.Animals))
            {
                foreach (PawnKindDef item in from k in DefDatabase <PawnKindDef> .AllDefs
                         where k.RaceProps.Animal
                         select k)
                {
                    if (!TryGetFreeRect(6, 3, out CellRect result))
                    {
                        return;
                    }
                    result = result.ContractedBy(1);
                    foreach (IntVec3 item2 in result)
                    {
                        Map.terrainGrid.SetTerrain(item2, TerrainDefOf.Concrete);
                    }
                    GenSpawn.Spawn(PawnGenerator.GeneratePawn(item), result.Cells.ElementAt(0), Map);
                    IntVec3 intVec = result.Cells.ElementAt(1);
                    Pawn    p      = (Pawn)GenSpawn.Spawn(PawnGenerator.GeneratePawn(item), intVec, Map);
                    HealthUtility.DamageUntilDead(p);
                    Corpse       thing        = (Corpse)intVec.GetThingList(Find.CurrentMap).First((Thing t) => t is Corpse);
                    CompRottable compRottable = thing.TryGetComp <CompRottable>();
                    if (compRottable != null)
                    {
                        compRottable.RotProgress += 1200000f;
                    }
                    if (item.RaceProps.leatherDef != null)
                    {
                        GenSpawn.Spawn(item.RaceProps.leatherDef, result.Cells.ElementAt(2), Map);
                    }
                    if (item.RaceProps.meatDef != null)
                    {
                        GenSpawn.Spawn(item.RaceProps.meatDef, result.Cells.ElementAt(3), Map);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ConduitGrid))
            {
                Designator_Build designator_Build = new Designator_Build(ThingDefOf.PowerConduit);
                for (int i = overRect.minX; i < overRect.maxX; i++)
                {
                    for (int j = overRect.minZ; j < overRect.maxZ; j += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(i, 0, j));
                    }
                }
                for (int l = overRect.minZ; l < overRect.maxZ; l++)
                {
                    for (int m = overRect.minX; m < overRect.maxX; m += 7)
                    {
                        designator_Build.DesignateSingleCell(new IntVec3(m, 0, l));
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.PowerPlants))
            {
                List <ThingDef> list = new List <ThingDef>();
                list.Add(ThingDefOf.SolarGenerator);
                list.Add(ThingDefOf.WindTurbine);
                List <ThingDef> list2 = list;
                for (int n = 0; n < 8; n++)
                {
                    if (TryMakeBuilding(list2[n % list2.Count]) == null)
                    {
                        Log.Message("Could not make solar generator.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Batteries))
            {
                for (int num = 0; num < 6; num++)
                {
                    Thing thing2 = TryMakeBuilding(ThingDefOf.Battery);
                    if (thing2 == null)
                    {
                        Log.Message("Could not make battery.");
                        break;
                    }
                    ((Building_Battery)thing2).GetComp <CompPowerBattery>().AddEnergy(999999f);
                }
            }
            if (flags.Contains(ColonyMakerFlag.WorkTables))
            {
                IEnumerable <ThingDef> enumerable = from def in DefDatabase <ThingDef> .AllDefs
                                                    where typeof(Building_WorkTable).IsAssignableFrom(def.thingClass)
                                                    select def;
                foreach (ThingDef item3 in enumerable)
                {
                    Thing thing3 = TryMakeBuilding(item3);
                    if (thing3 == null)
                    {
                        Log.Message("Could not make worktable: " + item3.defName);
                        break;
                    }
                    Building_WorkTable building_WorkTable = thing3 as Building_WorkTable;
                    if (building_WorkTable != null)
                    {
                        foreach (RecipeDef allRecipe in building_WorkTable.def.AllRecipes)
                        {
                            building_WorkTable.billStack.AddBill(allRecipe.MakeNewBill());
                        }
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.AllBuildings))
            {
                IEnumerable <ThingDef> enumerable2 = from def in DefDatabase <ThingDef> .AllDefs
                                                     where def.category == ThingCategory.Building && def.BuildableByPlayer
                                                     select def;
                foreach (ThingDef item4 in enumerable2)
                {
                    if (item4 != ThingDefOf.PowerConduit)
                    {
                        Thing thing4 = TryMakeBuilding(item4);
                        if (thing4 == null)
                        {
                            Log.Message("Could not make building: " + item4.defName);
                            break;
                        }
                    }
                }
            }
            if (!TryGetFreeRect(33, 33, out CellRect result2))
            {
                Log.Error("Could not get wallable rect");
            }
            result2 = result2.ContractedBy(1);
            if (flags.Contains(ColonyMakerFlag.AllItems))
            {
                List <ThingDef> itemDefs = (from def in DefDatabase <ThingDef> .AllDefs
                                            where DebugThingPlaceHelper.IsDebugSpawnable(def) && def.category == ThingCategory.Item
                                            select def).ToList();
                FillWithItems(result2, itemDefs);
            }
            else if (flags.Contains(ColonyMakerFlag.ItemsRawFood))
            {
                List <ThingDef> list3 = new List <ThingDef>();
                list3.Add(ThingDefOf.RawPotatoes);
                FillWithItems(result2, list3);
            }
            if (flags.Contains(ColonyMakerFlag.Filth))
            {
                foreach (IntVec3 item5 in result2)
                {
                    GenSpawn.Spawn(ThingDefOf.Filth_Dirt, item5, Map);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ItemsWall))
            {
                CellRect         cellRect          = result2.ExpandedBy(1);
                Designator_Build designator_Build2 = new Designator_Build(ThingDefOf.Wall);
                designator_Build2.SetStuffDef(ThingDefOf.WoodLog);
                foreach (IntVec3 edgeCell in cellRect.EdgeCells)
                {
                    designator_Build2.DesignateSingleCell(edgeCell);
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsMany))
            {
                MakeColonists(15, overRect.CenterCell);
            }
            else if (flags.Contains(ColonyMakerFlag.ColonistOne))
            {
                MakeColonists(1, overRect.CenterCell);
            }
            if (flags.Contains(ColonyMakerFlag.Fire))
            {
                if (!TryGetFreeRect(30, 30, out CellRect result3))
                {
                    Log.Error("Could not get free rect for fire.");
                }
                ThingDef plant_TreeOak = ThingDefOf.Plant_TreeOak;
                foreach (IntVec3 item6 in result3)
                {
                    GenSpawn.Spawn(plant_TreeOak, item6, Map);
                }
                foreach (IntVec3 item7 in result3)
                {
                    IntVec3 current9 = item7;
                    if (current9.x % 7 == 0 && current9.z % 7 == 0)
                    {
                        GenExplosion.DoExplosion(current9, Find.CurrentMap, 3.9f, DamageDefOf.Flame, null);
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsHungry))
            {
                DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.food.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsTired))
            {
                DoToColonists(0.4f, delegate(Pawn col)
                {
                    col.needs.rest.CurLevel = Mathf.Max(0f, Rand.Range(-0.05f, 0.05f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsInjured))
            {
                DoToColonists(0.4f, delegate(Pawn col)
                {
                    DamageDef def2 = (from d in DefDatabase <DamageDef> .AllDefs
                                      where d.ExternalViolenceFor(null)
                                      select d).RandomElement();
                    col.TakeDamage(new DamageInfo(def2, 10f));
                });
            }
            if (flags.Contains(ColonyMakerFlag.ColonistsDiseased))
            {
                foreach (HediffDef item8 in from d in DefDatabase <HediffDef> .AllDefs
                         where d.hediffClass != typeof(Hediff_AddedPart) && (d.HasComp(typeof(HediffComp_Immunizable)) || d.HasComp(typeof(HediffComp_GrowthMode)))
                         select d)
                {
                    Pawn pawn = PawnGenerator.GeneratePawn(Faction.OfPlayer.def.basicMemberKind, Faction.OfPlayer);
                    TryGetFreeRect(1, 1, out CellRect result4);
                    GenSpawn.Spawn(pawn, result4.CenterCell, Map);
                    pawn.health.AddHediff(item8);
                }
            }
            if (flags.Contains(ColonyMakerFlag.Beds))
            {
                IEnumerable <ThingDef> source = from def in DefDatabase <ThingDef> .AllDefs
                                                where def.thingClass == typeof(Building_Bed)
                                                select def;
                int freeColonistsCount = Map.mapPawns.FreeColonistsCount;
                for (int num2 = 0; num2 < freeColonistsCount; num2++)
                {
                    if (TryMakeBuilding(source.RandomElement()) == null)
                    {
                        Log.Message("Could not make beds.");
                        break;
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.Stockpiles))
            {
                Designator_ZoneAddStockpile_Resources designator_ZoneAddStockpile_Resources = new Designator_ZoneAddStockpile_Resources();
                IEnumerator enumerator11 = Enum.GetValues(typeof(StoragePriority)).GetEnumerator();
                try
                {
                    while (enumerator11.MoveNext())
                    {
                        StoragePriority priority = (StoragePriority)enumerator11.Current;
                        TryGetFreeRect(7, 7, out CellRect result5);
                        result5 = result5.ContractedBy(1);
                        designator_ZoneAddStockpile_Resources.DesignateMultiCell(result5.Cells);
                        Zone_Stockpile zone_Stockpile = (Zone_Stockpile)Map.zoneManager.ZoneAt(result5.CenterCell);
                        zone_Stockpile.settings.Priority = priority;
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator11 as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            if (flags.Contains(ColonyMakerFlag.GrowingZones))
            {
                Zone_Growing dummyZone = new Zone_Growing(Map.zoneManager);
                Map.zoneManager.RegisterZone(dummyZone);
                foreach (ThingDef item9 in from d in DefDatabase <ThingDef> .AllDefs
                         where d.plant != null && PlantUtility.CanSowOnGrower(d, dummyZone)
                         select d)
                {
                    if (!TryGetFreeRect(6, 6, out CellRect result6))
                    {
                        Log.Error("Could not get growing zone rect.");
                    }
                    result6 = result6.ContractedBy(1);
                    foreach (IntVec3 item10 in result6)
                    {
                        Map.terrainGrid.SetTerrain(item10, TerrainDefOf.Soil);
                    }
                    Designator_ZoneAdd_Growing designator_ZoneAdd_Growing = new Designator_ZoneAdd_Growing();
                    designator_ZoneAdd_Growing.DesignateMultiCell(result6.Cells);
                    (Map.zoneManager.ZoneAt(result6.CenterCell) as Zone_Growing)?.SetPlantDefToGrow(item9);
                }
                dummyZone.Delete();
            }
            ClearAllHomeArea();
            FillWithHomeArea(overRect);
            DebugSettings.godMode            = godMode;
            Thing.allowDestroyNonDestroyable = false;
        }
예제 #26
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);
        }
예제 #27
0
        public static void ResurrectWithSideEffects(Pawn pawn)
        {
            Corpse corpse = pawn.Corpse;
            float  x2;

            if (corpse != null)
            {
                CompRottable comp = corpse.GetComp <CompRottable>();
                x2 = comp.RotProgress / 60000f;
            }
            else
            {
                x2 = 0f;
            }
            ResurrectionUtility.Resurrect(pawn);
            BodyPartRecord brain  = pawn.health.hediffSet.GetBrain();
            Hediff         hediff = HediffMaker.MakeHediff(HediffDefOf.ResurrectionSickness, pawn, null);

            if (!pawn.health.WouldDieAfterAddingHediff(hediff))
            {
                pawn.health.AddHediff(hediff, null, null, null);
            }
            float chance = ResurrectionUtility.DementiaChancePerRotDaysCurve.Evaluate(x2);

            if (Rand.Chance(chance) && brain != null)
            {
                Hediff hediff2 = HediffMaker.MakeHediff(HediffDefOf.Dementia, pawn, brain);
                if (!pawn.health.WouldDieAfterAddingHediff(hediff2))
                {
                    pawn.health.AddHediff(hediff2, null, null, null);
                }
            }
            float chance2 = ResurrectionUtility.BlindnessChancePerRotDaysCurve.Evaluate(x2);

            if (Rand.Chance(chance2))
            {
                IEnumerable <BodyPartRecord> enumerable = from x in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null)
                                                          where x.def == BodyPartDefOf.Eye
                                                          select x;
                foreach (BodyPartRecord current in enumerable)
                {
                    Hediff hediff3 = HediffMaker.MakeHediff(HediffDefOf.Blindness, pawn, current);
                    pawn.health.AddHediff(hediff3, null, null, null);
                }
            }
            if (brain != null)
            {
                float chance3 = ResurrectionUtility.ResurrectionPsychosisChancePerRotDaysCurve.Evaluate(x2);
                if (Rand.Chance(chance3))
                {
                    Hediff hediff4 = HediffMaker.MakeHediff(HediffDefOf.ResurrectionPsychosis, pawn, brain);
                    if (!pawn.health.WouldDieAfterAddingHediff(hediff4))
                    {
                        pawn.health.AddHediff(hediff4, null, null, null);
                    }
                }
            }
            if (pawn.Dead)
            {
                Log.Error("The pawn has died while being resurrected.", false);
                ResurrectionUtility.Resurrect(pawn);
            }
        }