Esempio n. 1
0
    private IEnumerator WipeToNotBlocked()
    {
        yield return(new WaitForSeconds(transitionAnim.GetCurrentAnimatorStateInfo(0).length + transitionAnim.GetCurrentAnimatorStateInfo(0).length));

        isDone   = true;
        wipeMode = WipeMode.NotBlocked;
    }
Esempio n. 2
0
 private void WipeToBlocked()
 {
     wipeProgress    += Time.deltaTime * (1f / wipeSpeed);
     image.fillAmount = wipeProgress;
     if (wipeProgress >= 1f)
     {
         isDone   = true;
         wipeMode = WipeMode.Blocked;
     }
 }
Esempio n. 3
0
 private void WipeToNotBlocked()
 {
     wipeProgress    -= Time.deltaTime * (1f / wipeSpeed);
     image.fillAmount = wipeProgress;
     if (wipeProgress <= 0)
     {
         isDone   = true;
         wipeMode = WipeMode.NotBlocked;
     }
 }
Esempio n. 4
0
    private IEnumerator WipeToBlocked()
    {
        transitionAnim.SetBool("Start", true);
        yield return(new WaitForSeconds(transitionAnim.GetCurrentAnimatorStateInfo(0).length + transitionAnim.GetCurrentAnimatorStateInfo(0).length / 2f));

        isDone   = true;
        wipeMode = WipeMode.Blocked;
        yield return(new WaitForSeconds(transitionAnim.GetCurrentAnimatorStateInfo(0).length + transitionAnim.GetCurrentAnimatorStateInfo(0).length));

        transitionAnim.SetBool("Start", false);
    }
Esempio n. 5
0
 static bool Prefix(ref Thing newThing, ref WipeMode wipeMode, bool respawningAfterLoad)
 {
     if (newThing is Building_TurretGun && respawningAfterLoad)
     {
         if (newThing.TryGetComp <CompMountable>() is CompMountable comp && comp.Active)
         {
             comp.mountedTo.inventory.innerContainer.TryAdd(newThing, 1);
             return(false);
         }
     }
     return(true);
 }
Esempio n. 6
0
 public void ToggleWipe(bool blockScreen)
 {
     isDone = false;
     if (blockScreen)
     {
         wipeMode = WipeMode.WipingToBlocked;
     }
     else
     {
         wipeMode = WipeMode.WipingToNotBlocked;
     }
 }
Esempio n. 7
0
        private static void SpawnThingWithWipeMode()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            WipeMode[] array = (WipeMode[])Enum.GetValues(typeof(WipeMode));
            for (int i = 0; i < array.Length; i++)
            {
                WipeMode wipeMode      = array[i];
                WipeMode localWipeMode = wipeMode;
                list.Add(new DebugMenuOption(wipeMode.ToString(), DebugMenuOptionMode.Action, delegate
                {
                    Find.WindowStack.Add(new Dialog_DebugOptionListLister(DebugThingPlaceHelper.SpawnOptions(localWipeMode)));
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
        }
        public static List <DebugMenuOption> SpawnOptions(WipeMode wipeMode)
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (ThingDef item in DefDatabase <ThingDef> .AllDefs.Where((ThingDef def) => IsDebugSpawnable(def, allowPlayerBuildable: true)))
            {
                ThingDef localDef = item;
                list.Add(new DebugMenuOption(localDef.LabelCap, DebugMenuOptionMode.Tool, delegate
                {
                    Thing thing = ThingMaker.MakeThing(localDef, GenStuff.RandomStuffFor(localDef));
                    thing.TryGetComp <CompQuality>()?.SetQuality(QualityUtility.GenerateQualityRandomEqualChance(), ArtGenerationContext.Colony);
                    GenSpawn.Spawn(thing, UI.MouseCell(), Find.CurrentMap, wipeMode);
                }));
            }
            return(list);
        }
Esempio n. 9
0
 public static bool Spawn(ref Thing __result,
                          Thing newThing,
                          IntVec3 loc,
                          Map map,
                          Rot4 rot,
                          WipeMode wipeMode        = WipeMode.Vanish,
                          bool respawningAfterLoad = false)
 {
     if (null != newThing)
     {
         if (null != newThing.def)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 10
0
        public static List <DebugMenuOption> SpawnOptions(WipeMode wipeMode)
        {
            List <DebugMenuOption> list       = new List <DebugMenuOption>();
            IEnumerable <ThingDef> enumerable = from def in DefDatabase <ThingDef> .AllDefs
                                                where DebugThingPlaceHelper.IsDebugSpawnable(def, true)
                                                select def;

            foreach (ThingDef current in enumerable)
            {
                ThingDef localDef = current;
                list.Add(new DebugMenuOption(localDef.LabelCap, DebugMenuOptionMode.Tool, delegate
                {
                    Thing thing             = ThingMaker.MakeThing(localDef, GenStuff.RandomStuffFor(localDef));
                    CompQuality compQuality = thing.TryGetComp <CompQuality>();
                    if (compQuality != null)
                    {
                        compQuality.SetQuality(QualityUtility.GenerateQualityRandomEqualChance(), ArtGenerationContext.Colony);
                    }
                    GenSpawn.Spawn(thing, UI.MouseCell(), Find.CurrentMap, wipeMode);
                }));
            }
            return(list);
        }
Esempio n. 11
0
 public static Thing Spawn(ThingDef def, IntVec3 loc, Map map, WipeMode wipeMode = WipeMode.Vanish)
 {
     return(GenSpawn.Spawn(ThingMaker.MakeThing(def, null), loc, map, wipeMode));
 }
Esempio n. 12
0
        public static Thing Spawn(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);
                return(null);
            }
            if (!loc.InBounds(map))
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to spawn ",
                    newThing.ToStringSafe <Thing>(),
                    " out of bounds at ",
                    loc,
                    "."
                }), false);
                return(null);
            }
            if (newThing.def.randomizeRotationOnSpawn)
            {
                rot = Rot4.Random;
            }
            CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size);

            if (!occupiedRect.InBounds(map))
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to spawn ",
                    newThing.ToStringSafe <Thing>(),
                    " out of bounds at ",
                    loc,
                    " (out of bounds because size is ",
                    newThing.def.Size,
                    ")."
                }), false);
                return(null);
            }
            if (newThing.Spawned)
            {
                Log.Error("Tried to spawn " + newThing + " but it's already spawned.", false);
                return(newThing);
            }
            if (wipeMode == WipeMode.Vanish)
            {
                GenSpawn.WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish);
            }
            else if (wipeMode == WipeMode.FullRefund)
            {
                GenSpawn.WipeAndRefundExistingThings(loc, rot, newThing.def, map);
            }
            if (newThing.def.category == ThingCategory.Item)
            {
                foreach (IntVec3 current in occupiedRect)
                {
                    foreach (Thing current2 in current.GetThingList(map).ToList <Thing>())
                    {
                        if (current2 != newThing)
                        {
                            if (current2.def.category == ThingCategory.Item)
                            {
                                current2.DeSpawn(DestroyMode.Vanish);
                                if (!GenPlace.TryPlaceThing(current2, current, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x)))
                                {
                                    current2.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: " + newThing, false);
                newThing.Destroy(DestroyMode.Vanish);
                return(null);
            }
            if (newThing.def.passability == Traversability.Impassable)
            {
                foreach (IntVec3 current3 in occupiedRect)
                {
                    foreach (Thing current4 in current3.GetThingList(map).ToList <Thing>())
                    {
                        if (current4 != newThing)
                        {
                            Pawn pawn = current4 as Pawn;
                            if (pawn != null)
                            {
                                pawn.pather.TryRecoverFromUnwalkablePosition(false);
                            }
                        }
                    }
                }
            }
            return(newThing);
        }
Esempio n. 13
0
 public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, WipeMode wipeMode = WipeMode.Vanish)
 {
     return(GenSpawn.Spawn(newThing, loc, map, Rot4.North, wipeMode, false));
 }
        //public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false)
        public static Thing CheckForRevival(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false)
        {
            Log.Message($"Checking {newThing} for revival");
            Thing thing = GenSpawn.Spawn(newThing, loc, map, rot, wipeMode, respawningAfterLoad);

            DestroyedBuildings.ReviveBuilding(thing, loc, map);                 //After spawn so SpawnSetup is called, comps created.
            return(thing);
        }
Esempio n. 15
0
        public static Thing Spawn(Thing thing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false)
        {
            if (thing.Spawned)
            {
                Log.Error("Tried to spawn " + thing.ToStringSafe <Thing>() + " but it's already spawned.");
                return(thing);
            }

            if (map == null)
            {
                Log.Error("Tried to spawn " + thing.ToStringSafe <Thing>() + " in a null map.", false);
                return(null);
            }

            if (!loc.InBounds(map))
            {
                Log.Error("Tried to spawn " + thing.ToStringSafe <Thing>() + " out of bounds at " + loc + ".", false);
                return(null);
            }

            var occupiedRect = GenAdj.OccupiedRect(loc, rot, thing.def.Size);

            if (!occupiedRect.InBounds(map))
            {
                Log.Error("Tried to spawn " + thing.ToStringSafe <Thing>() + " out of bounds at " + loc + " (out of bounds because size is " + thing.def.Size + ").", false);
                return(null);
            }

            if (thing.def.randomizeRotationOnSpawn)
            {
                rot = Rot4.Random;
            }

            switch (wipeMode)
            {
            case WipeMode.Vanish:
                GenSpawn.WipeExistingThings(loc, rot, thing.def, map, DestroyMode.Vanish);
                break;

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

            if (thing.holdingOwner != null)
            {
                thing.holdingOwner.Remove(thing);
            }

            thing.Position = loc;
            thing.Rotation = rot;
            thing.SpawnSetup(map, respawningAfterLoad);

            if (
                thing.Spawned &&
                thing.stackCount == 0
                )
            {
                Log.Error("Spawned thing with 0 stackCount: " + thing, false);
                thing.Destroy(DestroyMode.Vanish);
                return(null);
            }

            if (thing.def.passability == Traversability.Impassable)
            {
                foreach (var cell in occupiedRect)
                {
                    foreach (var existingThing in cell.GetThingList(map).ToList <Thing>())
                    {
                        if (existingThing != thing)
                        {
                            (existingThing as Pawn)?.pather.TryRecoverFromUnwalkablePosition(false);
                        }
                    }
                }
            }

            return(thing);
        }
Esempio n. 16
0
        /// <summary>
        /// Catch All for vehicle related Things spawned in. Handles GodMode placing of vehicle buildings, corrects immovable spawn locations, and registers air defenses
        /// </summary>
        /// <param name="newThing"></param>
        /// <param name="loc"></param>
        /// <param name="map"></param>
        /// <param name="rot"></param>
        /// <param name="__result"></param>
        /// <param name="wipeMode"></param>
        /// <param name="respawningAfterLoad"></param>
        /// <returns></returns>
        public static bool RegisterThingSpawned(Thing newThing, ref IntVec3 loc, Map map, Rot4 rot, Thing __result, WipeMode wipeMode, bool respawningAfterLoad)
        {
            if (newThing.def is VehicleBuildDef def)
            {
                if (!VehicleMod.settings.debug.debugSpawnVehicleBuildingGodMode && newThing.HitPoints == newThing.MaxHitPoints)
                {
                    VehiclePawn vehiclePawn = VehicleSpawner.GenerateVehicle(def.thingToSpawn, newThing.Faction);                    // (VehiclePawn)PawnGenerator.GeneratePawn(def.thingToSpawn);

                    if (def.soundBuilt != null)
                    {
                        def.soundBuilt.PlayOneShot(new TargetInfo(loc, map, false));
                    }
                    VehiclePawn vehicleSpawned = (VehiclePawn)GenSpawn.Spawn(vehiclePawn, loc, map, rot, WipeMode.FullRefund, false);
                    vehicleSpawned.Rename();
                    __result = vehicleSpawned;
                    AchievementsHelper.TriggerVehicleConstructionEvent(vehicleSpawned);
                    return(false);
                }
            }
            else if (newThing is VehiclePawn vehicle)
            {
                bool standable = true;
                foreach (IntVec3 c in vehicle.PawnOccupiedCells(loc, rot))
                {
                    if (!c.InBounds(map) || (vehicle.IsBoat() ? GenGridVehicles.Impassable(c, map) : GenGrid.Impassable(c, map)))
                    {
                        standable = false;
                        break;
                    }
                }
                bool validator(IntVec3 c)
                {
                    foreach (IntVec3 c2 in vehicle.PawnOccupiedCells(c, rot))
                    {
                        if (vehicle.IsBoat() ? GenGridVehicles.Impassable(c, map) : GenGrid.Impassable(c, map))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }

                if (standable)
                {
                    return(true);
                }
                if (!CellFinder.TryFindRandomCellNear(loc, map, 20, validator, out IntVec3 newLoc, 100))
                {
                    Log.Error($"Unable to find location to spawn {newThing.LabelShort} after 100 attempts. Aborting spawn.");
                    return(false);
                }
                loc = newLoc;
            }
            else if (newThing is Pawn pawn && !pawn.Dead)
            {
                try
                {
                    var positionManager = map.GetCachedMapComponent <VehiclePositionManager>();
                    if (positionManager.PositionClaimed(loc))
                    {
                        VehiclePawn inPlaceVehicle = positionManager.ClaimedBy(loc);
                        CellRect    occupiedRect   = inPlaceVehicle.OccupiedRect().ExpandedBy(1);
                        Rand.PushState();
                        for (int i = 0; i < 3; i++)
                        {
                            IntVec3 newLoc = occupiedRect.EdgeCells.Where(c => GenGrid.InBounds(c, map) && GenGrid.Standable(c, map)).RandomElementWithFallback(inPlaceVehicle.Position);
                            if (occupiedRect.EdgeCells.Contains(newLoc))
                            {
                                loc = newLoc;
                                break;
                            }
                            occupiedRect = occupiedRect.ExpandedBy(1);
                        }
                        Rand.PopState();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error($"Pawn {newThing.Label} could not be readjusted for spawn location. Exception={ex.Message}");
                }
            }
Esempio n. 17
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);
        }
Esempio n. 18
0
 private static void GenSpawn_Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode, bool respawningAfterLoad)
 {
     HandleNewThing(newThing);
 }
Esempio n. 19
0
 /// <summary>
 /// Spawn event for Buildings
 /// </summary>
 /// <param name="newThing"></param>
 /// <param name="loc"></param>
 /// <param name="map"></param>
 /// <param name="rot"></param>
 /// <param name="wipeMode"></param>
 /// <param name="respawningAfterLoad"></param>
 public static void ThingBuildingSpawned(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false)
 {
     if (newThing is Building building && building.Faction == Faction.OfPlayer && Current.ProgramState == ProgramState.Playing)
     {
         foreach (var card in AchievementPointManager.GetCards <BuildingTracker>())
         {
             try
             {
                 if ((card.tracker as BuildingTracker).Trigger(building))
                 {
                     card.UnlockCard();
                 }
             }
             catch (Exception ex)
             {
                 Log.Error($"Unable to trigger event for card validation. To avoid further errors {card.def.LabelCap} has been automatically unlocked.\n\nException={ex.Message}");
                 card.UnlockCard();
             }
         }
     }
 }
Esempio n. 20
0
        public static bool SCP_SpawnCheck(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode, bool respawningAfterLoad)
        {
            if (newThing is SCP newPawn && newPawn.kindDef is CustomPawnKindDef newPkd && newPkd.isUnique)
            {
                //SCPs should not be spawned as mechanoids in shrines.
                //Spawn lancers instead.
                if (Find.TickManager.TicksGame < 500) //(int)(DefDatabase<DevSettings>.AllDefs.First().daysUntilSCPArrival.min * GenDate.TicksPerDay))
                {
                    newThing = PawnGenerator.GeneratePawn(CustomPawnKindDef.Named("Mech_Lancer"));
                    Log.Message(newPkd.label + " attempted to spawn before arrival time in dev settings. Denied");
                    return(true);
                }

                var worldComp = Find.World.GetComponent <WorldComponent_UniqueTracker>();
                if (worldComp == null)
                {
                    return(true);
                }

                if (worldComp.uniquePawnTypes == null)
                {
                    worldComp.uniquePawnTypes = new List <CustomPawnKindDef>();
                }

                //Check to see if the unique pawn type has already been spawned.
                if (worldComp.uniquePawnTypes.Count != 0 &&
                    worldComp.uniquePawnTypes.Contains(newPkd))
                {
                    //If the pawn is a newly created or different pawn, it will not be spawned.
                    if (worldComp.uniquePawns == null)
                    {
                        worldComp.uniquePawns = new List <Pawn>();
                    }

                    if (worldComp.uniquePawns.Count != 0 &&
                        !worldComp.uniquePawns.Contains(newPawn))
                    {
                        Log.Warning("SCP attempted to reappear without permissions. SCP Spawning Denied.");
                        return(false);
                    }
                }
                else
                {
                    worldComp.uniquePawnTypes.Add(newPkd);
                    worldComp.uniquePawns.Add(newPawn);
                }
            }
            return(true);
        }
Esempio n. 21
0
        public static bool PatchedSpawn(out Thing __result, Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false)
        {
            __result = null;
            if (!respawningAfterLoad)
            {
                __result = newThing;
                return(true);
            }

            __result = Utils.Spawn(newThing, loc, map, rot, wipeMode, respawningAfterLoad);
            return(false);
        }
Esempio n. 22
0
        public static Thing Spawn(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() + " in a null map.");
                return(null);
            }
            if (!loc.InBounds(map))
            {
                Log.Error("Tried to spawn " + newThing.ToStringSafe() + " out of bounds at " + loc + ".");
                return(null);
            }
            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() + " out of bounds at " + loc + " (out of bounds because size is " + newThing.def.Size + ").");
                return(null);
            }
            if (newThing.Spawned)
            {
                Log.Error("Tried to spawn " + newThing + " but it's already spawned.");
                return(newThing);
            }
            switch (wipeMode)
            {
            case WipeMode.Vanish:
                WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish);
                break;

            case WipeMode.FullRefund:
                WipeAndRefundExistingThings(loc, rot, newThing.def, map);
                break;
            }
            if (newThing.def.category == ThingCategory.Item)
            {
                foreach (IntVec3 item in occupiedRect)
                {
                    foreach (Thing item2 in item.GetThingList(map).ToList())
                    {
                        if (item2 != newThing && item2.def.category == ThingCategory.Item)
                        {
                            item2.DeSpawn();
                            if (!GenPlace.TryPlaceThing(item2, item, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x)))
                            {
                                item2.Destroy();
                            }
                        }
                    }
                }
            }
            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: " + newThing);
                newThing.Destroy();
                return(null);
            }
            if (newThing.def.passability == Traversability.Impassable)
            {
                foreach (IntVec3 item3 in occupiedRect)
                {
                    foreach (Thing item4 in item3.GetThingList(map).ToList())
                    {
                        if (item4 != newThing)
                        {
                            (item4 as Pawn)?.pather.TryRecoverFromUnwalkablePosition(error: false);
                        }
                    }
                }
                return(newThing);
            }
            return(newThing);
        }