public override void EjectContents()
        {
            List <Thing> list = new List <Thing>();

            if (!this.contentsKnown)
            {
                list.AddRange(this.innerContainer);
                list.AddRange(this.UnopenedCasketsInGroup().SelectMany((Building_AncientCryptosleepCasket c) => c.innerContainer));
            }
            bool contentsKnown = this.contentsKnown;

            base.EjectContents();
            if (!contentsKnown)
            {
                ThingDef filth_Slime = ThingDefOf.Filth_Slime;
                FilthMaker.MakeFilth(base.Position, base.Map, filth_Slime, Rand.Range(8, 12));
                this.SetFaction(null, null);
                foreach (Building_AncientCryptosleepCasket building_AncientCryptosleepCasket in this.UnopenedCasketsInGroup())
                {
                    building_AncientCryptosleepCasket.EjectContents();
                }
                List <Pawn>        source     = list.OfType <Pawn>().ToList <Pawn>();
                IEnumerable <Pawn> enumerable = from p in source
                                                where p.RaceProps.Humanlike && p.GetLord() == null && p.Faction == Faction.OfAncientsHostile
                                                select p;
                if (enumerable.Any <Pawn>())
                {
                    LordMaker.MakeNewLord(Faction.OfAncientsHostile, new LordJob_AssaultColony(Faction.OfAncientsHostile, false, false, false, false, false), base.Map, enumerable);
                }
            }
        }
        public override void EjectContents()
        {
            List <Thing> list = new List <Thing>();

            if (!base.contentsKnown)
            {
                list.AddRange(innerContainer);
                list.AddRange(UnopenedCasketsInGroup().SelectMany((Building_AncientCryptosleepCasket c) => c.innerContainer));
            }
            bool contentsKnown = base.contentsKnown;

            base.EjectContents();
            if (!contentsKnown)
            {
                ThingDef filth_Slime = ThingDefOf.Filth_Slime;
                FilthMaker.MakeFilth(base.Position, base.Map, filth_Slime, Rand.Range(8, 12));
                SetFaction(null);
                foreach (Building_AncientCryptosleepCasket item in UnopenedCasketsInGroup())
                {
                    item.EjectContents();
                }
                List <Pawn>        source     = list.OfType <Pawn>().ToList();
                IEnumerable <Pawn> enumerable = from p in source
                                                where p.RaceProps.Humanlike && p.GetLord() == null && p.Faction == Faction.OfAncientsHostile
                                                select p;
                if (enumerable.Any())
                {
                    LordMaker.MakeNewLord(Faction.OfAncientsHostile, new LordJob_AssaultColony(Faction.OfAncientsHostile, canKidnap: false, canTimeoutOrFlee: false, sappers: false, useAvoidGridSmart: false, canSteal: false), base.Map, enumerable);
                }
            }
        }
Beispiel #3
0
 public void Notify_EnteredNewCell()
 {
     if (Rand.Value < 0.05f)
     {
         this.TryDropFilth();
     }
     if (Rand.Value < 0.1f)
     {
         this.TryPickupFilth();
     }
     if (!this.pawn.RaceProps.Humanlike)
     {
         if (Rand.Value < PawnUtility.AnimalFilthChancePerCell(this.pawn.def, this.pawn.BodySize) && this.pawn.Position.GetTerrain(this.pawn.Map).acceptTerrainSourceFilth)
         {
             FilthMaker.MakeFilth(this.pawn.Position, this.pawn.Map, ThingDefOf.Filth_AnimalFilth, 1);
             FilthMonitor.Notify_FilthAnimalGenerated();
         }
     }
     else if (Rand.Value < PawnUtility.HumanFilthChancePerCell(this.pawn.def, this.pawn.BodySize) && this.pawn.Position.GetTerrain(this.pawn.Map).acceptTerrainSourceFilth)
     {
         ThingDef filth_Trash;
         if (this.lastTerrainFilthDef != null && Rand.Chance(0.66f))
         {
             filth_Trash = this.lastTerrainFilthDef;
         }
         else
         {
             filth_Trash = ThingDefOf.Filth_Trash;
         }
         FilthMaker.MakeFilth(this.pawn.Position, this.pawn.Map, filth_Trash, 1);
         FilthMonitor.Notify_FilthHumanGenerated();
     }
 }
Beispiel #4
0
        public static void DropFilthDueToDamage(Thing t, float damageDealt)
        {
            if (!t.def.useHitPoints || !t.Spawned || t.def.filthLeaving == null)
            {
                return;
            }
            CellRect cellRect = t.OccupiedRect().ExpandedBy(1);

            GenLeaving.tmpCellsCandidates.Clear();
            foreach (IntVec3 current in cellRect)
            {
                if (current.InBounds(t.Map) && current.Walkable(t.Map))
                {
                    GenLeaving.tmpCellsCandidates.Add(current);
                }
            }
            if (!GenLeaving.tmpCellsCandidates.Any <IntVec3>())
            {
                return;
            }
            int num = GenMath.RoundRandom(damageDealt * Mathf.Min(0.0166666675f, 1f / ((float)t.MaxHitPoints / 10f)));

            for (int i = 0; i < num; i++)
            {
                FilthMaker.MakeFilth(GenLeaving.tmpCellsCandidates.RandomElement <IntVec3>(), t.Map, t.def.filthLeaving, 1);
            }
            GenLeaving.tmpCellsCandidates.Clear();
        }
Beispiel #5
0
 public void TrySpawnFilth()
 {
     if (parent.Map != null && CellFinder.TryFindRandomReachableCellNear(parent.Position, parent.Map, Props.spawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors), (IntVec3 x) => x.Standable(parent.Map), (Region x) => true, out IntVec3 result))
     {
         FilthMaker.MakeFilth(result, parent.Map, Props.filthDef);
     }
 }
Beispiel #6
0
 public static void MakeFilth(IntVec3 c, Map map, ThingDef filthDef, int count = 1)
 {
     for (int i = 0; i < count; i++)
     {
         FilthMaker.MakeFilth(c, map, filthDef, null, true);
     }
 }
Beispiel #7
0
        private void GrowLowRockFormationFrom(IntVec3 root, Map map)
        {
            ThingDef        filth_RubbleRock = ThingDefOf.Filth_RubbleRock;
            ThingDef        mineableThing    = Find.World.NaturalRockTypesIn(map.Tile).RandomElement <ThingDef>().building.mineableThing;
            Rot4            random           = Rot4.Random;
            MapGenFloatGrid elevation        = MapGenerator.Elevation;
            IntVec3         intVec           = root;

            while (true)
            {
                Rot4 random2 = Rot4.Random;
                if (!(random2 == random))
                {
                    intVec += random2.FacingCell;
                    if (!intVec.InBounds(map) || intVec.GetEdifice(map) != null || intVec.GetFirstItem(map) != null)
                    {
                        break;
                    }
                    if (elevation[intVec] > 0.55f)
                    {
                        return;
                    }
                    if (!map.terrainGrid.TerrainAt(intVec).affordances.Contains(TerrainAffordanceDefOf.Heavy))
                    {
                        return;
                    }
                    GenSpawn.Spawn(mineableThing, intVec, map, WipeMode.Vanish);
                    IntVec3[] adjacentCellsAndInside = GenAdj.AdjacentCellsAndInside;
                    for (int i = 0; i < adjacentCellsAndInside.Length; i++)
                    {
                        IntVec3 b = adjacentCellsAndInside[i];
                        if (Rand.Value < 0.5f)
                        {
                            IntVec3 c = intVec + b;
                            if (c.InBounds(map))
                            {
                                bool         flag      = false;
                                List <Thing> thingList = c.GetThingList(map);
                                for (int j = 0; j < thingList.Count; j++)
                                {
                                    Thing thing = thingList[j];
                                    if (thing.def.category != ThingCategory.Plant && thing.def.category != ThingCategory.Item && thing.def.category != ThingCategory.Pawn)
                                    {
                                        flag = true;
                                        break;
                                    }
                                }
                                if (!flag)
                                {
                                    FilthMaker.MakeFilth(c, map, filth_RubbleRock, 1);
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #8
0
        public void TrySpawnFilth()
        {
            IntVec3 c = default(IntVec3);

            if (base.parent.Map != null && CellFinder.TryFindRandomReachableCellNear(base.parent.Position, base.parent.Map, this.Props.spawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (Predicate <IntVec3>)((IntVec3 x) => x.Standable(base.parent.Map)), (Predicate <Region>)((Region x) => true), out c, 999999))
            {
                FilthMaker.MakeFilth(c, base.parent.Map, this.Props.filthDef, 1);
            }
        }
Beispiel #9
0
        public static bool MakeFilth(IntVec3 c, Map map, ThingDef filthDef, string source, int count = 1)
        {
            bool flag = false;

            for (int i = 0; i < count; i++)
            {
                flag |= FilthMaker.MakeFilth(c, map, filthDef, Gen.YieldSingle <string>(source), true);
            }
            return(flag);
        }
Beispiel #10
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Toil to = new Toil();

            to.initAction = delegate()
            {
                this.ticksLeft = Rand.Range(300, 900);
                int     num = 0;
                IntVec3 c;
                for (;;)
                {
                    c = this.pawn.Position + GenAdj.AdjacentCellsAndInside[Rand.Range(0, 9)];
                    num++;
                    if (num > 12)
                    {
                        break;
                    }
                    if (c.InBounds(this.pawn.Map) && c.Standable(this.pawn.Map))
                    {
                        goto IL_A5;
                    }
                }
                c = this.pawn.Position;
IL_A5:
                this.job.targetA = c;
                this.pawn.pather.StopDead();
            };
            to.tickAction = delegate()
            {
                if (this.ticksLeft % 150 == 149)
                {
                    FilthMaker.MakeFilth(this.job.targetA.Cell, base.Map, ThingDefOf.Filth_Vomit, this.pawn.LabelIndefinite(), 1);
                    if (this.pawn.needs.food.CurLevelPercentage > 0.1f)
                    {
                        this.pawn.needs.food.CurLevel -= this.pawn.needs.food.MaxLevel * 0.04f;
                    }
                }
                this.ticksLeft--;
                if (this.ticksLeft <= 0)
                {
                    base.ReadyForNextToil();
                    TaleRecorder.RecordTale(TaleDefOf.Vomited, new object[]
                    {
                        this.pawn
                    });
                }
            };
            to.defaultCompleteMode = ToilCompleteMode.Never;
            to.WithEffect(EffecterDefOf.Vomit, TargetIndex.A);
            to.PlaySustainerOrSound(() => SoundDefOf.Vomit);
            yield return(to);

            yield break;
        }
Beispiel #11
0
 public void TrySpawnFilth()
 {
     if (this.parent.Map != null)
     {
         IntVec3 c;
         if (CellFinder.TryFindRandomReachableCellNear(this.parent.Position, this.parent.Map, this.Props.spawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 x) => x.Standable(this.parent.Map), (Region x) => true, out c, 999999))
         {
             FilthMaker.MakeFilth(c, this.parent.Map, this.Props.filthDef, 1);
         }
     }
 }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Toil to = new Toil
            {
                initAction = delegate
                {
                    ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0032: stateMachine*/)._0024this.ticksLeft = Rand.Range(300, 900);
                    int     num = 0;
                    IntVec3 c;
                    while (true)
                    {
                        c = ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0032: stateMachine*/)._0024this.pawn.Position + GenAdj.AdjacentCellsAndInside[Rand.Range(0, 9)];
                        num++;
                        if (num > 12)
                        {
                            c = ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0032: stateMachine*/)._0024this.pawn.Position;
                            break;
                        }
                        if (c.InBounds(((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0032: stateMachine*/)._0024this.pawn.Map) && c.Standable(((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0032: stateMachine*/)._0024this.pawn.Map))
                        {
                            break;
                        }
                    }
                    ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0032: stateMachine*/)._0024this.job.targetA = c;
                    ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0032: stateMachine*/)._0024this.pawn.pather.StopDead();
                },
                tickAction = delegate
                {
                    if (((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0049: stateMachine*/)._0024this.ticksLeft % 150 == 149)
                    {
                        FilthMaker.MakeFilth(((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0049: stateMachine*/)._0024this.job.targetA.Cell, ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0049: stateMachine*/)._0024this.Map, ThingDefOf.FilthVomit, ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0049: stateMachine*/)._0024this.pawn.LabelIndefinite(), 1);
                        if (((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0049: stateMachine*/)._0024this.pawn.needs.food.CurLevelPercentage > 0.10000000149011612)
                        {
                            ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0049: stateMachine*/)._0024this.pawn.needs.food.CurLevel -= (float)(((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0049: stateMachine*/)._0024this.pawn.needs.food.MaxLevel * 0.039999999105930328);
                        }
                    }
                    ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0049: stateMachine*/)._0024this.ticksLeft--;
                    if (((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0049: stateMachine*/)._0024this.ticksLeft <= 0)
                    {
                        ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0049: stateMachine*/)._0024this.ReadyForNextToil();
                        TaleRecorder.RecordTale(TaleDefOf.Vomited, ((_003CMakeNewToils_003Ec__Iterator0) /*Error near IL_0049: stateMachine*/)._0024this.pawn);
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Never
            };

            to.WithEffect(EffecterDefOf.Vomit, TargetIndex.A);
            to.PlaySustainerOrSound(() => SoundDef.Named("Vomit"));
            yield return(to);

            /*Error: Unable to find new state assignment for yield return*/;
        }
        private void GrowLowRockFormationFrom(IntVec3 root, Map map)
        {
            ThingDef        rockRubble    = ThingDefOf.RockRubble;
            ThingDef        mineableThing = Find.World.NaturalRockTypesIn(map.Tile).RandomElement().building.mineableThing;
            Rot4            random        = Rot4.Random;
            MapGenFloatGrid elevation     = MapGenerator.Elevation;
            IntVec3         intVec        = root;

            while (true)
            {
                Rot4 random2 = Rot4.Random;
                if (random2 == random)
                {
                    continue;
                }
                intVec += random2.FacingCell;
                if (intVec.InBounds(map) && intVec.GetEdifice(map) == null && intVec.GetFirstItem(map) == null && !(elevation[intVec] > 0.550000011920929) && map.terrainGrid.TerrainAt(intVec).affordances.Contains(TerrainAffordance.Heavy))
                {
                    GenSpawn.Spawn(mineableThing, intVec, map);
                    IntVec3[] adjacentCellsAndInside = GenAdj.AdjacentCellsAndInside;
                    foreach (IntVec3 b in adjacentCellsAndInside)
                    {
                        if (Rand.Value < 0.5)
                        {
                            IntVec3 c = intVec + b;
                            if (c.InBounds(map))
                            {
                                bool         flag      = false;
                                List <Thing> thingList = c.GetThingList(map);
                                for (int j = 0; j < thingList.Count; j++)
                                {
                                    Thing thing = thingList[j];
                                    if (thing.def.category != ThingCategory.Plant && thing.def.category != ThingCategory.Item && thing.def.category != ThingCategory.Pawn)
                                    {
                                        flag = true;
                                        break;
                                    }
                                }
                                if (!flag)
                                {
                                    FilthMaker.MakeFilth(c, map, rockRubble, 1);
                                }
                            }
                        }
                    }
                    continue;
                }
                break;
            }
        }
 public void Notify_EnteredNewCell()
 {
     if (Rand.Value < 0.05000000074505806)
     {
         this.TryDropFilth();
     }
     if (Rand.Value < 0.25)
     {
         this.TryPickupFilth();
     }
     if (!this.pawn.RaceProps.Humanlike && Rand.Value < PawnUtility.AnimalFilthChancePerCell(this.pawn.def, this.pawn.BodySize) && this.pawn.Position.GetTerrain(this.pawn.Map).acceptTerrainSourceFilth)
     {
         FilthMaker.MakeFilth(this.pawn.Position, this.pawn.Map, ThingDefOf.FilthAnimalFilth, 1);
     }
 }
        private static bool MakeFilth(IntVec3 c, Map map, ThingDef filthDef, IEnumerable <string> sources, bool shouldPropagate)
        {
            Filth filth = (Filth)(from t in c.GetThingList(map)
                                  where t.def == filthDef
                                  select t).FirstOrDefault <Thing>();
            bool result;

            if (!c.Walkable(map) || (filth != null && !filth.CanBeThickened))
            {
                if (shouldPropagate)
                {
                    List <IntVec3> list = GenAdj.AdjacentCells8WayRandomized();
                    for (int i = 0; i < 8; i++)
                    {
                        IntVec3 c2 = c + list[i];
                        if (c2.InBounds(map))
                        {
                            if (FilthMaker.MakeFilth(c2, map, filthDef, sources, false))
                            {
                                return(true);
                            }
                        }
                    }
                }
                if (filth != null)
                {
                    filth.AddSources(sources);
                }
                result = false;
            }
            else
            {
                if (filth != null)
                {
                    filth.ThickenFilth();
                    filth.AddSources(sources);
                }
                else
                {
                    Filth filth2 = (Filth)ThingMaker.MakeThing(filthDef, null);
                    filth2.AddSources(sources);
                    GenSpawn.Spawn(filth2, c, map, WipeMode.Vanish);
                }
                FilthMonitor.Notify_FilthSpawned();
                result = true;
            }
            return(result);
        }
Beispiel #16
0
 public void Hatch()
 {
     try
     {
         PawnGenerationRequest request = new PawnGenerationRequest(this.Props.hatcherPawn, this.hatcheeFaction, PawnGenerationContext.NonPlayer, -1, false, true, false, false, true, false, 1f, false, true, true, false, false, false, false, null, null, null, null, null, null, null, null);
         for (int i = 0; i < this.parent.stackCount; i++)
         {
             Pawn pawn = PawnGenerator.GeneratePawn(request);
             if (PawnUtility.TrySpawnHatchedOrBornPawn(pawn, this.parent))
             {
                 if (pawn != null)
                 {
                     if (this.hatcheeParent != null)
                     {
                         if (pawn.playerSettings != null && this.hatcheeParent.playerSettings != null && this.hatcheeParent.Faction == this.hatcheeFaction)
                         {
                             pawn.playerSettings.AreaRestriction = this.hatcheeParent.playerSettings.AreaRestriction;
                         }
                         if (pawn.RaceProps.IsFlesh)
                         {
                             pawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, this.hatcheeParent);
                         }
                     }
                     if (this.otherParent != null && (this.hatcheeParent == null || this.hatcheeParent.gender != this.otherParent.gender) && pawn.RaceProps.IsFlesh)
                     {
                         pawn.relations.AddDirectRelation(PawnRelationDefOf.Parent, this.otherParent);
                     }
                 }
                 if (this.parent.Spawned)
                 {
                     FilthMaker.MakeFilth(this.parent.Position, this.parent.Map, ThingDefOf.Filth_AmnioticFluid, 1);
                 }
             }
             else
             {
                 Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
             }
         }
     }
     finally
     {
         this.parent.Destroy(DestroyMode.Vanish);
     }
 }
        private static bool MakeFilth(IntVec3 c, Map map, ThingDef filthDef, IEnumerable <string> sources, bool shouldPropagate)
        {
            Filth filth = (Filth)(from t in c.GetThingList(map)
                                  where t.def == filthDef
                                  select t).FirstOrDefault();

            if (c.Walkable(map) && (filth == null || filth.CanBeThickened))
            {
                if (filth != null)
                {
                    filth.ThickenFilth();
                    filth.AddSources(sources);
                }
                else
                {
                    Filth filth2 = (Filth)ThingMaker.MakeThing(filthDef, null);
                    filth2.AddSources(sources);
                    GenSpawn.Spawn(filth2, c, map);
                }
                return(true);
            }
            if (shouldPropagate)
            {
                List <IntVec3> list = GenAdj.AdjacentCells8WayRandomized();
                for (int i = 0; i < 8; i++)
                {
                    IntVec3 c2 = c + list[i];
                    if (c2.InBounds(map) && FilthMaker.MakeFilth(c2, map, filthDef, sources, false))
                    {
                        return(true);
                    }
                }
            }
            if (filth != null)
            {
                filth.AddSources(sources);
            }
            return(false);
        }
 public static void DropFilthDueToDamage(Thing t, float damageDealt)
 {
     if (t.def.useHitPoints && t.Spawned && t.def.filthLeaving != null)
     {
         CellRect cellRect = t.OccupiedRect().ExpandedBy(1);
         GenLeaving.tmpCellsCandidates.Clear();
         foreach (IntVec3 item in cellRect)
         {
             if (item.InBounds(t.Map) && item.Walkable(t.Map))
             {
                 GenLeaving.tmpCellsCandidates.Add(item);
             }
         }
         if (GenLeaving.tmpCellsCandidates.Any())
         {
             int num = GenMath.RoundRandom(damageDealt * Mathf.Min(0.0166666675f, (float)(1.0 / ((float)t.MaxHitPoints / 10.0))));
             for (int i = 0; i < num; i++)
             {
                 FilthMaker.MakeFilth(GenLeaving.tmpCellsCandidates.RandomElement(), t.Map, t.def.filthLeaving, 1);
             }
         }
     }
 }
Beispiel #19
0
 public void Notify_EnteredNewCell()
 {
     if (Rand.Value < 0.05f)
     {
         TryDropFilth();
     }
     if (Rand.Value < 0.1f)
     {
         TryPickupFilth();
     }
     if (!pawn.RaceProps.Humanlike)
     {
         if (Rand.Value < PawnUtility.AnimalFilthChancePerCell(pawn.def, pawn.BodySize) && pawn.Position.GetTerrain(pawn.Map).acceptTerrainSourceFilth)
         {
             FilthMaker.MakeFilth(pawn.Position, pawn.Map, ThingDefOf.Filth_AnimalFilth);
             FilthMonitor.Notify_FilthAnimalGenerated();
         }
     }
     else if (Rand.Value < PawnUtility.HumanFilthChancePerCell(pawn.def, pawn.BodySize) && pawn.Position.GetTerrain(pawn.Map).acceptTerrainSourceFilth)
     {
         FilthMaker.MakeFilth(filthDef: (lastTerrainFilthDef == null || !Rand.Chance(0.66f)) ? ThingDefOf.Filth_Trash : lastTerrainFilthDef, c: pawn.Position, map: pawn.Map);
         FilthMonitor.Notify_FilthHumanGenerated();
     }
 }
 private void DropCarriedFilth(Filth f)
 {
     this.ThinCarriedFilth(f);
     FilthMaker.MakeFilth(this.pawn.Position, this.pawn.Map, f.def, f.sources);
 }
        public static void DoLeavingsFor(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect, Predicate <IntVec3> nearPlaceValidator = null)
        {
            if ((Current.ProgramState != ProgramState.Playing && mode != DestroyMode.Refund) || mode == DestroyMode.Vanish)
            {
                return;
            }
            if (mode == DestroyMode.KillFinalize && diedThing.def.filthLeaving != null)
            {
                for (int i = leavingsRect.minZ; i <= leavingsRect.maxZ; i++)
                {
                    for (int j = leavingsRect.minX; j <= leavingsRect.maxX; j++)
                    {
                        IntVec3 c = new IntVec3(j, 0, i);
                        FilthMaker.MakeFilth(c, map, diedThing.def.filthLeaving, Rand.RangeInclusive(1, 3));
                    }
                }
            }
            ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();

            if (mode == DestroyMode.KillFinalize && diedThing.def.killedLeavings != null)
            {
                for (int k = 0; k < diedThing.def.killedLeavings.Count; k++)
                {
                    Thing thing = ThingMaker.MakeThing(diedThing.def.killedLeavings[k].thingDef, null);
                    thing.stackCount = diedThing.def.killedLeavings[k].count;
                    thingOwner.TryAdd(thing, true);
                }
            }
            if (GenLeaving.CanBuildingLeaveResources(diedThing, mode))
            {
                Frame frame = diedThing as Frame;
                if (frame != null)
                {
                    for (int l = frame.resourceContainer.Count - 1; l >= 0; l--)
                    {
                        int num = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(frame.resourceContainer[l].stackCount);
                        if (num > 0)
                        {
                            frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[l], thingOwner, num, true);
                        }
                    }
                    frame.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish);
                }
                else
                {
                    List <ThingDefCountClass> list = diedThing.CostListAdjusted();
                    for (int m = 0; m < list.Count; m++)
                    {
                        ThingDefCountClass thingDefCountClass = list[m];
                        int num2 = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(thingDefCountClass.count);
                        if (num2 > 0 && mode == DestroyMode.KillFinalize && thingDefCountClass.thingDef.slagDef != null)
                        {
                            int count = thingDefCountClass.thingDef.slagDef.smeltProducts.First((ThingDefCountClass pro) => pro.thingDef == ThingDefOf.Steel).count;
                            int num3  = num2 / 2 / 8;
                            for (int n = 0; n < num3; n++)
                            {
                                thingOwner.TryAdd(ThingMaker.MakeThing(thingDefCountClass.thingDef.slagDef, null), true);
                            }
                            num2 -= num3 * count;
                        }
                        if (num2 > 0)
                        {
                            Thing thing2 = ThingMaker.MakeThing(thingDefCountClass.thingDef, null);
                            thing2.stackCount = num2;
                            thingOwner.TryAdd(thing2, true);
                        }
                    }
                }
            }
            List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder(null).ToList <IntVec3>();
            int            num4  = 0;

            while (thingOwner.Count > 0)
            {
                if (mode == DestroyMode.KillFinalize && !map.areaManager.Home[list2[num4]])
                {
                    thingOwner[0].SetForbidden(true, false);
                }
                ThingOwner <Thing> thingOwner2 = thingOwner;
                Thing          thing3          = thingOwner[0];
                IntVec3        dropLoc         = list2[num4];
                ThingPlaceMode mode2           = ThingPlaceMode.Near;
                Thing          thing4;
                ref Thing      lastResultingThing = ref thing4;
                if (!thingOwner2.TryDrop(thing3, dropLoc, map, mode2, out lastResultingThing, null, nearPlaceValidator))
                {
                    Log.Warning(string.Concat(new object[]
                    {
                        "Failed to place all leavings for destroyed thing ",
                        diedThing,
                        " at ",
                        leavingsRect.CenterCell
                    }), false);
                    return;
                }
                num4++;
                if (num4 >= list2.Count)
                {
                    num4 = 0;
                }
            }
Beispiel #22
0
 public static void MakeFilth(IntVec3 c, Map map, ThingDef filthDef, IEnumerable <string> sources)
 {
     FilthMaker.MakeFilth(c, map, filthDef, sources, true);
 }
Beispiel #23
0
 public override void Tick()
 {
     if (base.Spawned)
     {
         this.sustainer.Maintain();
         Vector3 vector = base.Position.ToVector3Shifted();
         IntVec3 c;
         if (Rand.MTBEventOccurs(TunnelHiveSpawner.FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(base.Position, base.Map, TunnelHiveSpawner.FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), null, null, out c, 999999))
         {
             FilthMaker.MakeFilth(c, base.Map, TunnelHiveSpawner.filthTypes.RandomElement <ThingDef>(), 1);
         }
         if (Rand.MTBEventOccurs(TunnelHiveSpawner.DustMoteSpawnMTB, 1f, 1.TicksToSeconds()))
         {
             MoteMaker.ThrowDustPuffThick(new Vector3(vector.x, 0f, vector.z)
             {
                 y = AltitudeLayer.MoteOverhead.AltitudeFor()
             }, base.Map, Rand.Range(1.5f, 3f), new Color(1f, 1f, 1f, 2.5f));
         }
         if (this.secondarySpawnTick <= Find.TickManager.TicksGame)
         {
             this.sustainer.End();
             Map     map      = base.Map;
             IntVec3 position = base.Position;
             this.Destroy(DestroyMode.Vanish);
             if (this.spawnHive)
             {
                 Hive hive = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive, null), position, map, WipeMode.Vanish);
                 hive.SetFaction(Faction.OfInsects, null);
                 foreach (CompSpawner compSpawner in hive.GetComps <CompSpawner>())
                 {
                     if (compSpawner.PropsSpawner.thingToSpawn == ThingDefOf.InsectJelly)
                     {
                         compSpawner.TryDoSpawn();
                         break;
                     }
                 }
             }
             if (this.insectsPoints > 0f)
             {
                 this.insectsPoints = Mathf.Max(this.insectsPoints, Hive.spawnablePawnKinds.Min((PawnKindDef x) => x.combatPower));
                 float       pointsLeft = this.insectsPoints;
                 List <Pawn> list       = new List <Pawn>();
                 int         num        = 0;
                 while (pointsLeft > 0f)
                 {
                     num++;
                     if (num > 1000)
                     {
                         Log.Error("Too many iterations.", false);
                         break;
                     }
                     IEnumerable <PawnKindDef> source = from x in Hive.spawnablePawnKinds
                                                        where x.combatPower <= pointsLeft
                                                        select x;
                     PawnKindDef pawnKindDef;
                     if (!source.TryRandomElement(out pawnKindDef))
                     {
                         break;
                     }
                     Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDef, Faction.OfInsects);
                     GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2, null), map, WipeMode.Vanish);
                     pawn.mindState.spawnedByInfestationThingComp = this.spawnedByInfestationThingComp;
                     list.Add(pawn);
                     pointsLeft -= pawnKindDef.combatPower;
                 }
                 if (list.Any <Pawn>())
                 {
                     LordMaker.MakeNewLord(Faction.OfInsects, new LordJob_AssaultColony(Faction.OfInsects, true, false, false, false, true), map, list);
                 }
             }
         }
     }
 }
Beispiel #24
0
 public override void Tick()
 {
     if (base.Spawned)
     {
         sustainer.Maintain();
         Vector3 vector = base.Position.ToVector3Shifted();
         if (Rand.MTBEventOccurs(FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(base.Position, base.Map, FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors), null, null, out IntVec3 result))
         {
             FilthMaker.MakeFilth(result, base.Map, filthTypes.RandomElement());
         }
         if (Rand.MTBEventOccurs(DustMoteSpawnMTB, 1f, 1.TicksToSeconds()))
         {
             Vector3 loc = new Vector3(vector.x, 0f, vector.z);
             loc.y = AltitudeLayer.MoteOverhead.AltitudeFor();
             MoteMaker.ThrowDustPuffThick(loc, base.Map, Rand.Range(1.5f, 3f), new Color(1f, 1f, 1f, 2.5f));
         }
         if (secondarySpawnTick <= Find.TickManager.TicksGame)
         {
             sustainer.End();
             Map     map      = base.Map;
             IntVec3 position = base.Position;
             Destroy();
             if (spawnHive)
             {
                 Hive hive = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive), position, map);
                 hive.SetFaction(Faction.OfInsects);
                 foreach (CompSpawner comp in hive.GetComps <CompSpawner>())
                 {
                     if (comp.PropsSpawner.thingToSpawn == ThingDefOf.InsectJelly)
                     {
                         comp.TryDoSpawn();
                         break;
                     }
                 }
             }
             if (insectsPoints > 0f)
             {
                 insectsPoints = Mathf.Max(insectsPoints, Hive.spawnablePawnKinds.Min((PawnKindDef x) => x.combatPower));
                 float       pointsLeft = insectsPoints;
                 List <Pawn> list       = new List <Pawn>();
                 int         num        = 0;
                 while (pointsLeft > 0f)
                 {
                     num++;
                     if (num > 1000)
                     {
                         Log.Error("Too many iterations.");
                         break;
                     }
                     IEnumerable <PawnKindDef> source = from x in Hive.spawnablePawnKinds
                                                        where x.combatPower <= pointsLeft
                                                        select x;
                     if (!source.TryRandomElement(out PawnKindDef result2))
                     {
                         break;
                     }
                     Pawn pawn = PawnGenerator.GeneratePawn(result2, Faction.OfInsects);
                     GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2), map);
                     pawn.mindState.spawnedByInfestationThingComp = spawnedByInfestationThingComp;
                     list.Add(pawn);
                     pointsLeft -= result2.combatPower;
                 }
                 if (list.Any())
                 {
                     LordMaker.MakeNewLord(Faction.OfInsects, new LordJob_AssaultColony(Faction.OfInsects, canKidnap: true, canTimeoutOrFlee: false), map, list);
                 }
             }
         }
     }
 }
        public static void DoLeavingsFor(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect)
        {
            if (Current.ProgramState != ProgramState.Playing && mode != DestroyMode.Refund)
            {
                return;
            }
            switch (mode)
            {
            case DestroyMode.Vanish:
                return;

            case DestroyMode.KillFinalize:
                if (diedThing.def.filthLeaving != null)
                {
                    for (int i = leavingsRect.minZ; i <= leavingsRect.maxZ; i++)
                    {
                        for (int j = leavingsRect.minX; j <= leavingsRect.maxX; j++)
                        {
                            IntVec3 c = new IntVec3(j, 0, i);
                            FilthMaker.MakeFilth(c, map, diedThing.def.filthLeaving, Rand.RangeInclusive(1, 3));
                        }
                    }
                }
                break;
            }
            ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();

            if (mode == DestroyMode.KillFinalize && diedThing.def.killedLeavings != null)
            {
                for (int k = 0; k < diedThing.def.killedLeavings.Count; k++)
                {
                    Thing thing = ThingMaker.MakeThing(diedThing.def.killedLeavings[k].thingDef, null);
                    thing.stackCount = diedThing.def.killedLeavings[k].count;
                    thingOwner.TryAdd(thing, true);
                }
            }
            if (GenLeaving.CanBuildingLeaveResources(diedThing, mode))
            {
                Frame frame = diedThing as Frame;
                if (frame != null)
                {
                    for (int num = frame.resourceContainer.Count - 1; num >= 0; num--)
                    {
                        int num2 = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(frame.resourceContainer[num].stackCount);
                        if (num2 > 0)
                        {
                            frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[num], thingOwner, num2, true);
                        }
                    }
                    frame.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish);
                }
                else
                {
                    List <ThingCountClass> list = diedThing.CostListAdjusted();
                    for (int l = 0; l < list.Count; l++)
                    {
                        ThingCountClass thingCountClass = list[l];
                        int             num3            = GenLeaving.GetBuildingResourcesLeaveCalculator(diedThing, mode)(thingCountClass.count);
                        if (num3 > 0 && mode == DestroyMode.KillFinalize && thingCountClass.thingDef.slagDef != null)
                        {
                            int count = thingCountClass.thingDef.slagDef.smeltProducts.First((ThingCountClass pro) => pro.thingDef == ThingDefOf.Steel).count;
                            int num4  = num3 / 2 / 8;
                            for (int m = 0; m < num4; m++)
                            {
                                thingOwner.TryAdd(ThingMaker.MakeThing(thingCountClass.thingDef.slagDef, null), true);
                            }
                            num3 -= num4 * count;
                        }
                        if (num3 > 0)
                        {
                            Thing thing2 = ThingMaker.MakeThing(thingCountClass.thingDef, null);
                            thing2.stackCount = num3;
                            thingOwner.TryAdd(thing2, true);
                        }
                    }
                }
            }
            List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder(null).ToList();
            int            num5  = 0;

            while (true)
            {
                if (thingOwner.Count > 0)
                {
                    if (mode == DestroyMode.KillFinalize && !((Area)map.areaManager.Home)[list2[num5]])
                    {
                        thingOwner[0].SetForbidden(true, false);
                    }
                    Thing thing3 = default(Thing);
                    if (thingOwner.TryDrop(thingOwner[0], list2[num5], map, ThingPlaceMode.Near, out thing3, (Action <Thing, int>)null))
                    {
                        num5++;
                        if (num5 >= list2.Count)
                        {
                            num5 = 0;
                        }
                        continue;
                    }
                    break;
                }
                return;
            }
            Log.Warning("Failed to place all leavings for destroyed thing " + diedThing + " at " + leavingsRect.CenterCell);
        }
Beispiel #26
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    to            = new Toil();
                    to.initAction = delegate()
                    {
                        this.ticksLeft = Rand.Range(300, 900);
                        int     num2 = 0;
                        IntVec3 c;
                        for (;;)
                        {
                            c = this.pawn.Position + GenAdj.AdjacentCellsAndInside[Rand.Range(0, 9)];
                            num2++;
                            if (num2 > 12)
                            {
                                break;
                            }
                            if (c.InBounds(this.pawn.Map) && c.Standable(this.pawn.Map))
                            {
                                goto IL_A5;
                            }
                        }
                        c = this.pawn.Position;
IL_A5:
                        this.job.targetA = c;
                        this.pawn.pather.StopDead();
                    };
                    to.tickAction = delegate()
                    {
                        if (this.ticksLeft % 150 == 149)
                        {
                            FilthMaker.MakeFilth(this.job.targetA.Cell, base.Map, ThingDefOf.Filth_Vomit, this.pawn.LabelIndefinite(), 1);
                            if (this.pawn.needs.food.CurLevelPercentage > 0.1f)
                            {
                                this.pawn.needs.food.CurLevel -= this.pawn.needs.food.MaxLevel * 0.04f;
                            }
                        }
                        this.ticksLeft--;
                        if (this.ticksLeft <= 0)
                        {
                            base.ReadyForNextToil();
                            TaleRecorder.RecordTale(TaleDefOf.Vomited, new object[]
                            {
                                this.pawn
                            });
                        }
                    };
                    to.defaultCompleteMode = ToilCompleteMode.Never;
                    to.WithEffect(EffecterDefOf.Vomit, TargetIndex.A);
                    to.PlaySustainerOrSound(() => SoundDefOf.Vomit);
                    this.$current = to;
                    if (!this.$disposing)
                    {
                        this.$PC = 1;
                    }
                    return(true);

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