Beispiel #1
0
        public void DequeuAndSpawnZombies()
        {
            var result = Tools.generator.TryGetNextGeneratedZombie(map);

            if (result == null)
            {
                return;
            }
            if (ZombieCount() >= GetMaxZombieCount())
            {
                return;
            }

            if (Tools.IsValidSpawnLocation(result.cell, result.map) == false)
            {
                return;
            }

            var existingZombies = result.map.thingGrid.ThingsListAtFast(result.cell).OfType <Zombie>();

            if (existingZombies.Any(zombie => zombie.state == ZombieState.Emerging))
            {
                Tools.generator.RequeueZombie(result);
                return;
            }

            ZombieGenerator.FinalizeZombieGeneration(result.zombie);
            GenPlace.TryPlaceThing(result.zombie, result.cell, result.map, ThingPlaceMode.Direct);
            result.map.GetGrid().ChangeZombieCount(result.cell, 1);
        }
        public void ConvertToZombie()
        {
            var pos = pawn.Position;
            var map = pawn.Map;
            var rot = pawn.Rotation;

            var zombie = ZombieGenerator.GeneratePawn();

            zombie.Name   = pawn.Name;
            zombie.gender = pawn.gender;

            var apparelToTransfer = new List <Apparel>();

            pawn.apparel.WornApparelInDrawOrder.Do(apparel =>
            {
                Apparel newApparel;
                if (pawn.apparel.TryDrop(apparel, out newApparel))
                {
                    apparelToTransfer.Add(newApparel);
                }
            });

            zombie.ageTracker.AgeBiologicalTicks    = pawn.ageTracker.AgeBiologicalTicks;
            zombie.ageTracker.AgeChronologicalTicks = pawn.ageTracker.AgeChronologicalTicks;
            zombie.ageTracker.BirthAbsTicks         = pawn.ageTracker.BirthAbsTicks;

            zombie.story.childhood = pawn.story.childhood;
            zombie.story.adulthood = pawn.story.adulthood;
            zombie.story.melanin   = pawn.story.melanin;
            zombie.story.crownType = pawn.story.crownType;
            zombie.story.hairDef   = pawn.story.hairDef;
            zombie.story.bodyType  = pawn.story.bodyType;

            var zTweener = Traverse.Create(zombie.Drawer.tweener);
            var pTweener = Traverse.Create(pawn.Drawer.tweener);

            zTweener.Field("tweenedPos").SetValue(pTweener.Field("tweenedPos").GetValue());
            zTweener.Field("lastDrawFrame").SetValue(pTweener.Field("lastDrawFrame").GetValue());
            zTweener.Field("lastTickSpringPos").SetValue(pTweener.Field("lastTickSpringPos").GetValue());

            ZombieGenerator.AssignNewCustomGraphics(zombie);
            ZombieGenerator.FinalizeZombieGeneration(zombie);
            GenPlace.TryPlaceThing(zombie, pos, map, ThingPlaceMode.Direct, null);
            map.GetGrid().ChangeZombieCount(pos, 1);

            pawn.Kill(null);
            pawn.Corpse.Destroy();

            apparelToTransfer.ForEach(apparel => zombie.apparel.Wear(apparel));
            zombie.Rotation      = rot;
            zombie.rubbleCounter = Constants.RUBBLE_AMOUNT;
            zombie.state         = ZombieState.Wandering;
            zombie.wasColonist   = true;

            string text = "ColonistBecameAZombieDesc".Translate(new object[] { zombie.NameStringShort });

            Find.LetterStack.ReceiveLetter("ColonistBecameAZombieLabel".Translate(), text, LetterDefOf.BadUrgent, zombie);
        }
        public void DequeuAndSpawnZombies()
        {
            if (dequeedSpawnCounter-- < 0)
            {
                dequeedSpawnCounter = Rand.Range(10, 51);

                var result = Tools.generator.TryGetNextGeneratedZombie(map);
                if (result == null)
                {
                    return;
                }
                if (result.isEvent == false && ZombieCount() >= GetMaxZombieCount())
                {
                    Tools.generator.RequeueZombie(result);
                    return;
                }

                // TODO: if zombie cannot spawn at location, we are wasting it here.
                // to solve this, we need to find a better location and only if we find
                // none, we can discard it
                //
                if (Tools.IsValidSpawnLocation(result.cell, result.map) == false)
                {
                    return;
                }

                var existingZombies = result.map.thingGrid.ThingsListAtFast(result.cell).OfType <Zombie>();
                if (existingZombies.Any(zombie => zombie.state == ZombieState.Emerging))
                {
                    Tools.generator.RequeueZombie(result);
                    return;
                }

                ZombieGenerator.FinalizeZombieGeneration(result.zombie);
                GenPlace.TryPlaceThing(result.zombie, result.cell, result.map, ThingPlaceMode.Direct);
            }
        }