Пример #1
0
        public override void FinalizeInit()
        {
            base.FinalizeInit();
            Tools.UpdateStoryTellerDifficulty();

            var grid = map.GetGrid();

            grid.IterateCellsQuick(cell => cell.zombieCount = 0);

            RecalculateVisibleMap();

            var destinations  = GetterSetters.reservedDestinationsByRef(map.pawnDestinationReservationManager);
            var zombieFaction = Find.FactionManager.FirstFactionOfDef(ZombieDefOf.Zombies);

            if (!destinations.ContainsKey(zombieFaction))
            {
                map.pawnDestinationReservationManager.RegisterFaction(zombieFaction);
            }

            if (ZombieSettings.Values.betterZombieAvoidance)
            {
                var specs = AllZombies().Select(zombie => new ZombieCostSpecs()
                {
                    position = zombie.Position,
                    radius   = Tools.ZombieAvoidRadius(zombie),
                    maxCosts = ZombieMaxCosts(zombie)
                }).ToList();

                avoidGrid = Tools.avoider.UpdateZombiePositionsImmediately(map, specs);
            }
            else
            {
                avoidGrid = new AvoidGrid(map);
            }
        }
Пример #2
0
        public static void Dialog_Checkbox(this Listing_Standard list, string desc, ref bool forBool, bool addGap = true)
        {
            var label  = desc.SafeTranslate();
            var indent = 24 + "_".GetWidthCached();
            var height = Math.Max(Text.LineHeight, Text.CalcHeight(label, list.ColumnWidth - indent));

            var rect = list.GetRect(height);

            rect.xMin += inset;

            var oldValue = forBool;
            var butRect  = rect;

            butRect.xMin += 24f;
            if (Widgets.ButtonInvisible(butRect, false))
            {
                forBool = !forBool;
            }
            if (forBool != oldValue)
            {
                SoundDefOf.RadioButtonClicked.PlayOneShotOnCamera(null);
            }

            Widgets.Checkbox(new Vector2(rect.x, rect.y - 1f), ref forBool);

            var curX = GetterSetters.curXByRef(list);

            GetterSetters.curXByRef(list) = curX + indent;

            var anchor = Text.Anchor;

            Text.Anchor = TextAnchor.UpperLeft;
            rect.xMin  += indent;
            var color = GUI.color;

            GUI.color = contentColor;
            Widgets.Label(rect, label);
            GUI.color   = color;
            Text.Anchor = anchor;

            GetterSetters.curXByRef(list) = curX;

            if (addGap)
            {
                list.Gap(2 * list.verticalSpacing);
            }
        }
Пример #3
0
        public static void EnableTwinkie(bool enable)
        {
            var def = ThingDefOf.MealSurvivalPack;

            if (mealLabel == null)
            {
                mealLabel = def.label;
            }
            if (mealDescription == null)
            {
                mealDescription = def.description;
            }
            if (mealGraphic == null)
            {
                mealGraphic = GetterSetters.cachedGraphicByRef(def.graphicData);
            }

            if (enable)
            {
                def.label       = "Twinkie";
                def.description = "A Twinkie is an American snack cake, marketed as a \"Golden Sponge Cake with Creamy Filling\".";
                GetterSetters.cachedGraphicByRef(def.graphicData) = GraphicsDatabase.twinkieGraphic;
            }
            else
            {
                def.label       = mealLabel;
                def.description = mealDescription;
                GetterSetters.cachedGraphicByRef(def.graphicData) = mealGraphic;
            }

            def.graphic = def.graphicData.Graphic;
            GenLabel.ClearCache();

            var game = Current.Game;

            if (game != null)
            {
                game.Maps
                .SelectMany(map => map.listerThings.ThingsOfDef(def))
                .Do(meal => GetterSetters.graphicIntByRef(meal) = null);
            }
        }
Пример #4
0
        public static bool Dialog_RadioButton(this Listing_Standard list, bool active, string desc)
        {
            var label  = desc.SafeTranslate();
            var indent = 24 + "_".GetWidthCached();
            var height = Math.Max(Text.LineHeight, Text.CalcHeight(label, list.ColumnWidth - indent));

            var rect = list.GetRect(height);

            rect.xMin += inset;
            var line   = new Rect(rect);
            var result = Widgets.RadioButton(line.xMin, line.yMin, active);

            var curX = GetterSetters.curXByRef(list);

            GetterSetters.curXByRef(list) = curX + indent;

            var anchor = Text.Anchor;

            Text.Anchor = TextAnchor.UpperLeft;
            line.xMin  += indent;
            var color = GUI.color;

            GUI.color = contentColor;
            Widgets.Label(line, label);
            GUI.color   = color;
            Text.Anchor = anchor;

            GetterSetters.curXByRef(list) = curX;

            result |= Widgets.ButtonInvisible(rect, false);
            if (result && !active)
            {
                SoundDefOf.RadioButtonClicked.PlayOneShotOnCamera(null);
            }

            list.Gap(list.verticalSpacing * 2);
            return(result);
        }
Пример #5
0
 private static int DamageFlashTicksLeft(DamageFlasher damageFlasher)
 {
     // copied from DamageFlasher.DamageFlashTicksLeft
     return(GetterSetters.lastDamageTickByRef(damageFlasher) + 16 - Find.TickManager.TicksGame);
 }
Пример #6
0
        public static Zombie GeneratePawn(ZombieType overwriteType)
        {
            var thing  = ThingMaker.MakeThing(ZombieDefOf.Zombie.race, null);
            var zombie = thing as Zombie;

            if (zombie == null)
            {
                Log.Error("ThingMaker.MakeThing(ZombieDefOf.Zombie.race, null) unexpectedly returned " + thing);
                return(null);
            }

            var bodyType = PrepareZombieType(zombie, overwriteType);

            zombie.kindDef = ZombieDefOf.Zombie;
            zombie.SetFactionDirect(FactionUtility.DefaultFactionFrom(ZombieDefOf.Zombies));

            PawnComponentsUtility.CreateInitialComponents(zombie);
            zombie.health.hediffSet.Clear();

            var ageInYears = (long)Rand.Range(14, 130);

            zombie.ageTracker.AgeBiologicalTicks    = (ageInYears * 3600000);
            zombie.ageTracker.AgeChronologicalTicks = zombie.ageTracker.AgeBiologicalTicks;
            zombie.ageTracker.BirthAbsTicks         = GenTicks.TicksAbs - zombie.ageTracker.AgeBiologicalTicks;
            var idx = zombie.ageTracker.CurLifeStageIndex;             // trigger calculations

            zombie.needs.SetInitialLevels();
            zombie.needs.mood = new Need_Mood(zombie);

            var name = PawnNameDatabaseSolid.GetListForGender((zombie.gender == Gender.Female) ? GenderPossibility.Female : GenderPossibility.Male).RandomElement();
            var n1   = name.First.Replace('s', 'z').Replace('S', 'Z');
            var n2   = name.Last.Replace('s', 'z').Replace('S', 'Z');
            var n3   = name.Nick.Replace('s', 'z').Replace('S', 'Z');

            zombie.Name = new NameTriple(n1, n3, n2);

            zombie.story.childhood = BackstoryDatabase.allBackstories
                                     .Where(kvp => kvp.Value.slot == BackstorySlot.Childhood)
                                     .RandomElement().Value;
            if (zombie.ageTracker.AgeBiologicalYearsFloat >= 20f)
            {
                zombie.story.adulthood = BackstoryDatabase.allBackstories
                                         .Where(kvp => kvp.Value.slot == BackstorySlot.Adulthood)
                                         .RandomElement().Value;
            }

            zombie.story.melanin   = 0.01f * Rand.Range(10, 91);
            zombie.story.bodyType  = bodyType;
            zombie.story.crownType = Rand.Bool ? CrownType.Average : CrownType.Narrow;

            zombie.story.hairColor = HairColor();
            zombie.story.hairDef   = PawnHairChooser.RandomHairDefFor(zombie, ZombieDefOf.Zombies);

            if (ZombieSettings.Values.useCustomTextures)
            {
                var it = AssignNewGraphics(zombie);
                while (it.MoveNext())
                {
                    ;
                }
            }

            zombie.Drawer.leaner = new ZombieLeaner(zombie);

            if (zombie.pather == null)
            {
                zombie.pather = new Pawn_PathFollower(zombie);
            }
            GetterSetters.destinationByRef(zombie.pather) = IntVec3.Invalid;

            return(zombie);
        }
Пример #7
0
        public static IEnumerator SpawnZombieIterativ(IntVec3 cell, Map map, ZombieType zombieType, Action <Zombie> callback)
        {
            ZombiesSpawning++;
            var thing = ThingMaker.MakeThing(ZombieDefOf.Zombie.race, null);

            yield return(null);

            var zombie   = thing as Zombie;
            var bodyType = PrepareZombieType(zombie, zombieType);

            zombie.kindDef = ZombieDefOf.Zombie;
            zombie.SetFactionDirect(FactionUtility.DefaultFactionFrom(ZombieDefOf.Zombies));
            yield return(null);

            PawnComponentsUtility.CreateInitialComponents(zombie);
            yield return(null);

            zombie.health.hediffSet.Clear();
            var ageInYears = (long)Rand.Range(14, 130);

            zombie.ageTracker.AgeBiologicalTicks    = (ageInYears * 3600000);
            zombie.ageTracker.AgeChronologicalTicks = zombie.ageTracker.AgeBiologicalTicks;
            zombie.ageTracker.BirthAbsTicks         = GenTicks.TicksAbs - zombie.ageTracker.AgeBiologicalTicks;
            var idx = zombie.ageTracker.CurLifeStageIndex;             // trigger calculations

            yield return(null);

            zombie.needs.SetInitialLevels();
            yield return(null);

            zombie.needs.mood = new Need_Mood(zombie);
            yield return(null);

            var name = PawnNameDatabaseSolid.GetListForGender((zombie.gender == Gender.Female) ? GenderPossibility.Female : GenderPossibility.Male).RandomElement();

            yield return(null);

            var n1 = name.First.Replace('s', 'z').Replace('S', 'Z');
            var n2 = name.Last.Replace('s', 'z').Replace('S', 'Z');
            var n3 = name.Nick.Replace('s', 'z').Replace('S', 'Z');

            zombie.Name = new NameTriple(n1, n3, n2);
            yield return(null);

            zombie.story.childhood = BackstoryDatabase.allBackstories
                                     .Where(kvp => kvp.Value.slot == BackstorySlot.Childhood)
                                     .RandomElement().Value;
            yield return(null);

            if (zombie.ageTracker.AgeBiologicalYearsFloat >= 20f)
            {
                zombie.story.adulthood = BackstoryDatabase.allBackstories
                                         .Where(kvp => kvp.Value.slot == BackstorySlot.Adulthood)
                                         .RandomElement().Value;
            }
            yield return(null);

            zombie.story.melanin   = 0.01f * Rand.Range(10, 91);
            zombie.story.bodyType  = bodyType;
            zombie.story.crownType = Rand.Bool ? CrownType.Average : CrownType.Narrow;
            zombie.story.hairColor = HairColor();
            zombie.story.hairDef   = PawnHairChooser.RandomHairDefFor(zombie, ZombieDefOf.Zombies);
            yield return(null);

            var it = AssignNewGraphics(zombie);

            while (it.MoveNext())
            {
                yield return(null);
            }
            zombie.Drawer.leaner = new ZombieLeaner(zombie);
            if (zombie.pather == null)
            {
                zombie.pather = new Pawn_PathFollower(zombie);
            }
            GetterSetters.destinationByRef(zombie.pather) = IntVec3.Invalid;
            yield return(null);

            if (zombie.IsTanky == false)
            {
                var it2 = GenerateStartingApparelFor(zombie);
                while (it2.MoveNext())
                {
                    yield return(null);
                }
            }
            if (zombie.IsSuicideBomber)
            {
                zombie.lastBombTick = Find.TickManager.TicksAbs + Rand.Range(0, (int)zombie.bombTickingInterval);
            }
            GenPlace.TryPlaceThing(zombie, cell, map, ThingPlaceMode.Direct);
            yield return(null);

            if (callback != null)
            {
                callback(zombie);
            }
            ZombiesSpawning--;
            switch (Find.TickManager.CurTimeSpeed)
            {
            case TimeSpeed.Paused:
                break;

            case TimeSpeed.Normal:
                yield return(new WaitForSeconds(0.1f));

                break;

            case TimeSpeed.Fast:
                yield return(new WaitForSeconds(0.25f));

                break;

            case TimeSpeed.Superfast:
                yield return(new WaitForSeconds(0.5f));

                break;

            case TimeSpeed.Ultrafast:
                yield return(new WaitForSeconds(1f));

                break;
            }
        }