예제 #1
0
        private void PodOpen()
        {
            Map map = base.Map;

            if (contents.despawnPodBeforeSpawningThing)
            {
                DeSpawn();
            }
            for (int num = contents.innerContainer.Count - 1; num >= 0; num--)
            {
                Thing thing = contents.innerContainer[num];
                Rot4  rot   = contents.setRotation.HasValue ? contents.setRotation.Value : Rot4.North;
                if (contents.moveItemsAsideBeforeSpawning)
                {
                    GenSpawn.CheckMoveItemsAside(base.Position, rot, thing.def, map);
                }
                Thing lastResultingThing = default(Thing);
                if (contents.spawnWipeMode.HasValue)
                {
                    lastResultingThing = ((!contents.setRotation.HasValue) ? GenSpawn.Spawn(thing, base.Position, map, contents.spawnWipeMode.Value) : GenSpawn.Spawn(thing, base.Position, map, contents.setRotation.Value, contents.spawnWipeMode.Value));
                }
                else
                {
                    GenPlace.TryPlaceThing(thing, base.Position, map, ThingPlaceMode.Near, out lastResultingThing, delegate(Thing placedThing, int count)
                    {
                        if (Find.TickManager.TicksGame < 1200 && TutorSystem.TutorialMode && placedThing.def.category == ThingCategory.Item)
                        {
                            Find.TutorialState.AddStartingItem(placedThing);
                        }
                    }, null, rot);
                }
                Pawn pawn = lastResultingThing as Pawn;
                if (pawn != null)
                {
                    if (pawn.RaceProps.Humanlike)
                    {
                        TaleRecorder.RecordTale(TaleDefOf.LandedInPod, pawn);
                    }
                    if (pawn.drafter != null && ((pawn.IsColonist && pawn.Spawned && !map.IsPlayerHome) || draftFlag))
                    {
                        pawn.drafter.Drafted = true;
                    }
                    if (pawn.guest != null && pawn.guest.IsPrisoner)
                    {
                        pawn.guest.WaitInsteadOfEscapingForDefaultTicks();
                    }
                }
            }
            contents.innerContainer.ClearAndDestroyContents();
            if (contents.leaveSlag)
            {
                for (int i = 0; i < 1; i++)
                {
                    GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.ChunkSlagSteel), base.Position, map, ThingPlaceMode.Near);
                }
            }
            SoundDefOf.DropPod_Open.PlayOneShot(new TargetInfo(base.Position, map));
            Destroy();
        }
예제 #2
0
        public static bool Spawn(ref Thing __result,
                                 Thing newThing,
                                 IntVec3 loc,
                                 Map map,
                                 Rot4 rot,
                                 WipeMode wipeMode        = WipeMode.Vanish,
                                 bool respawningAfterLoad = false)
        {
            if (map == null)
            {
                Log.Error("Tried to spawn " + newThing.ToStringSafe <Thing>() + " in a null map.", false);
                __result = (Thing)null;
                return(false);
            }
            if (!loc.InBounds(map))
            {
                Log.Error("Tried to spawn " + newThing.ToStringSafe <Thing>() + " out of bounds at " + (object)loc + ".", false);
                __result = (Thing)null;
                return(false);
            }
            if (null != newThing)
            {
                if (null != newThing.def)
                {
                    if (newThing.def.randomizeRotationOnSpawn)
                    {
                        rot = Rot4.Random;
                    }
                    CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size);
                    if (!occupiedRect.InBounds(map))
                    {
                        Log.Error("Tried to spawn " + newThing.ToStringSafe <Thing>() + " out of bounds at " + (object)loc + " (out of bounds because size is " + (object)newThing.def.Size + ").", false);
                        __result = (Thing)null;
                        return(false);
                    }
                    if (newThing.Spawned)
                    {
                        Log.Error("Tried to spawn " + (object)newThing + " but it's already spawned.", false);
                        __result = newThing;
                        return(false);
                    }
                    switch (wipeMode)
                    {
                    case WipeMode.Vanish:
                        GenSpawn.WipeExistingThings(loc, rot, (BuildableDef)newThing.def, map, DestroyMode.Vanish);
                        break;

                    case WipeMode.FullRefund:
                        GenSpawn.WipeAndRefundExistingThings(loc, rot, (BuildableDef)newThing.def, map);
                        break;

                    case WipeMode.VanishOrMoveAside:
                        GenSpawn.CheckMoveItemsAside(loc, rot, newThing.def, map);
                        GenSpawn.WipeExistingThings(loc, rot, (BuildableDef)newThing.def, map, DestroyMode.Vanish);
                        break;
                    }
                    if (newThing.def.category == ThingCategory.Item)
                    {
                        foreach (IntVec3 intVec3 in occupiedRect)
                        {
                            foreach (Thing thing in intVec3.GetThingList(map).ToList <Thing>())
                            {
                                if (thing != newThing && thing.def.category == ThingCategory.Item)
                                {
                                    thing.DeSpawn(DestroyMode.Vanish);
                                    if (!GenPlace.TryPlaceThing(thing, intVec3, map, ThingPlaceMode.Near, (Action <Thing, int>)null, (Predicate <IntVec3>)(x => !occupiedRect.Contains(x)), new Rot4()))
                                    {
                                        thing.Destroy(DestroyMode.Vanish);
                                    }
                                }
                            }
                        }
                    }
                    newThing.Rotation = rot;
                    newThing.Position = loc;
                    if (newThing.holdingOwner != null)
                    {
                        newThing.holdingOwner.Remove(newThing);
                    }
                    newThing.SpawnSetup(map, respawningAfterLoad);
                    if (newThing.Spawned && newThing.stackCount == 0)
                    {
                        Log.Error("Spawned thing with 0 stackCount: " + (object)newThing, false);
                        newThing.Destroy(DestroyMode.Vanish);
                        __result = (Thing)null;
                        return(false);
                    }
                    if (newThing.def.passability == Traversability.Impassable)
                    {
                        foreach (IntVec3 c in occupiedRect)
                        {
                            foreach (Thing thing in c.GetThingList(map).ToList <Thing>())
                            {
                                if (thing != newThing && thing is Pawn pawn)
                                {
                                    pawn.pather.TryRecoverFromUnwalkablePosition(false);
                                }
                            }
                        }
                    }
                }
            }
            __result = newThing;
            return(false);
        }