Beispiel #1
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);
        }
Beispiel #2
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;
            }
        }