예제 #1
0
        public static bool IsGoodDropSpot(IntVec3 c, Map map, bool allowFogged, bool canRoofPunch)
        {
            if (!c.InBounds(map) || !c.Standable(map))
            {
                return(false);
            }
            if (!DropCellFinder.CanPhysicallyDropInto(c, map, canRoofPunch))
            {
                if (DebugViewSettings.drawDestSearch)
                {
                    map.debugDrawer.FlashCell(c, 0f, "phys", 50);
                }
                return(false);
            }
            if (Current.ProgramState == ProgramState.Playing && !allowFogged && c.Fogged(map))
            {
                return(false);
            }
            List <Thing> thingList = c.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                Thing thing = thingList[i];
                if (thing is IActiveDropPod || thing.def.category == ThingCategory.Skyfaller)
                {
                    return(false);
                }
                if (thing.def.category != ThingCategory.Plant && GenSpawn.SpawningWipes(ThingDefOf.ActiveDropPod, thing.def))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
        // Token: 0x060029E5 RID: 10725 RVA: 0x0013D4FC File Offset: 0x0013B8FC
        private static bool CanSpawnHiveAt(IntVec3 c, Map map, IntVec3 parentPos, ThingDef parentDef, float minDist, bool ignoreRoofedRequirement)
        {
            if ((!ignoreRoofedRequirement && !c.Roofed(map)) || (!c.Walkable(map) || (minDist != 0f && (float)c.DistanceToSquared(parentPos) < minDist * minDist)) || c.GetFirstThing(map, ThingDefOf.InsectJelly) != null || c.GetFirstThing(map, ThingDefOf.GlowPod) != null)
            {
                return(false);
            }
            for (int i = 0; i < 9; i++)
            {
                IntVec3 c2 = c + GenAdj.AdjacentCellsAndInside[i];
                if (c2.InBounds(map))
                {
                    List <Thing> thingList = c2.GetThingList(map);
                    for (int j = 0; j < thingList.Count; j++)
                    {
                        if (thingList[j] is HiveLike || thingList[j] is TunnelSpawner)
                        {
                            return(false);
                        }
                    }
                }
            }
            List <Thing> thingList2 = c.GetThingList(map);

            for (int k = 0; k < thingList2.Count; k++)
            {
                Thing thing = thingList2[k];
                bool  flag  = thing.def.category == ThingCategory.Building && thing.def.passability == Traversability.Impassable;
                if (flag && GenSpawn.SpawningWipes(parentDef, thing.def))
                {
                    return(true);
                }
            }
            return(true);
        }
예제 #3
0
        public bool IsValidPositionToSpawnShipChunk(Map map, IntVec3 position)
        {
            ThingDef chunkDef = ThingDefOf.ShipChunk;

            if ((position.InBounds(map) == false) ||
                position.Fogged(map) ||
                (position.Standable(map) == false) ||
                (position.Roofed(map) &&
                 position.GetRoof(map).isThickRoof))
            {
                return(false);
            }
            if (position.SupportsStructureType(map, chunkDef.terrainAffordanceNeeded) == false)
            {
                return(false);
            }
            List <Thing> thingList = position.GetThingList(map);

            for (var thingIndex = 0; thingIndex < thingList.Count; thingIndex++)
            {
                Thing thing = thingList[thingIndex];
                if ((thing.def.category != ThingCategory.Plant) &&
                    GenSpawn.SpawningWipes(chunkDef, thing.def))
                {
                    return(false);
                }
            }
            return(true);
        }
        public static bool BlocksConstruction(Thing constructible, Thing t)
        {
            if (t == constructible)
            {
                return(false);
            }
            ThingDef thingDef;

            if (constructible is Blueprint)
            {
                thingDef = constructible.def;
            }
            else if (constructible is Frame)
            {
                thingDef = constructible.def.entityDefToBuild.blueprintDef;
            }
            else
            {
                thingDef = constructible.def.blueprintDef;
            }
            if (t.def.category == ThingCategory.Building && GenSpawn.SpawningWipes(thingDef.entityDefToBuild, t.def))
            {
                return(true);
            }
            if (t.def.category == ThingCategory.Plant)
            {
                if (t.def.plant.harvestWork > ThingDefOf.Plant_Dandelion.plant.harvestWork)
                {
                    bool flag = thingDef.entityDefToBuild is TerrainDef && t.Spawned && t.Position.GetEdifice(t.Map) is IPlantToGrowSettable;
                    return(!flag);
                }
                return(false);
            }
            else
            {
                if (!thingDef.clearBuildingArea)
                {
                    return(false);
                }
                if (t.def == ThingDefOf.SteamGeyser && thingDef.entityDefToBuild.ForceAllowPlaceOver(t.def))
                {
                    return(false);
                }
                ThingDef thingDef2 = thingDef.entityDefToBuild as ThingDef;
                if (thingDef2 != null)
                {
                    if (thingDef2.EverTransmitsPower && t.def == ThingDefOf.PowerConduit && thingDef2 != ThingDefOf.PowerConduit)
                    {
                        return(false);
                    }
                    if (t.def == ThingDefOf.Wall && thingDef2.building != null && thingDef2.building.canPlaceOverWall)
                    {
                        return(false);
                    }
                }
                return((t.def.IsEdifice() && thingDef2.IsEdifice()) || (t.def.category == ThingCategory.Pawn || (t.def.category == ThingCategory.Item && thingDef.entityDefToBuild.passability == Traversability.Impassable)) || t.def.Fillage >= FillCategory.Partial);
            }
        }
        public static bool ToBeSmoothed(Thing thing, ThingDef constructibleDef)
        {
            ThingDef smoothedThing = thing.def.building?.smoothedThing;

            return(smoothedThing != null &&
                   !GenSpawn.SpawningWipes(GenConstruct.BuiltDefOf(constructibleDef), smoothedThing) &&
                   thing.Map.edificeGrid[thing.Position] == thing &&
                   thing.Map.designationManager.DesignationAt(thing.Position, DesignationDefOf.SmoothWall) != null);
        }
예제 #6
0
        /// <summary>
        ///     A very complicated method for finding a proper place for objects to spawn in Cthulhu Utility.
        /// </summary>
        /// <param name="def"></param>
        /// <param name="nearLoc"></param>
        /// <param name="map"></param>
        /// <param name="maxDist"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public static bool TryFindSpawnCell(ThingDef def, IntVec3 nearLoc, Map map, int maxDist, out IntVec3 pos)
        {
            return(CellFinder.TryFindRandomCellNear(nearLoc, map, maxDist, delegate(IntVec3 x)
            {
                ///Check if the entire area is safe based on the size of the object definition.
                foreach (var current in GenAdj.OccupiedRect(x, Rot4.North, new IntVec2(def.size.x + 2, def.size.z + 2)))
                {
                    if (!current.InBounds(map) || current.Fogged(map) || !current.Standable(map) ||
                        current.Roofed(map) && current.GetRoof(map).isThickRoof)
                    {
                        return false;
                    }

                    if (!current.SupportsStructureType(map, def.terrainAffordanceNeeded))
                    {
                        return false;
                    }

                    ///
                    //  If it has an interaction cell, check to see if it can be reached by colonists.
                    //
                    var intCanBeReached = true;
                    if (def.interactionCellOffset != IntVec3.Zero)
                    {
                        foreach (var colonist in map.mapPawns.FreeColonistsSpawned)
                        {
                            if (!colonist.CanReach(current + def.interactionCellOffset, PathEndMode.ClosestTouch,
                                                   Danger.Deadly))
                            {
                                intCanBeReached = false;
                            }
                        }
                    }

                    if (!intCanBeReached)
                    {
                        return false;
                    }
                    //

                    //Don't wipe existing objets...
                    var thingList = current.GetThingList(map);
                    for (var i = 0; i < thingList.Count; i++)
                    {
                        var thing = thingList[i];
                        if (thing.def.category != ThingCategory.Plant && GenSpawn.SpawningWipes(def, thing.def))
                        {
                            return false;
                        }
                    }
                }

                return true;
            }, out pos));
        }
예제 #7
0
        public static bool BlocksConstruction(Thing constructible, Thing t)
        {
            if (t == constructible)
            {
                return(false);
            }
            ThingDef thingDef = (!(constructible is Blueprint)) ? ((!(constructible is Frame)) ? constructible.def.blueprintDef : constructible.def.entityDefToBuild.blueprintDef) : constructible.def;

            if (t.def.category == ThingCategory.Building && GenSpawn.SpawningWipes(thingDef.entityDefToBuild, t.def))
            {
                return(true);
            }
            if (t.def.category == ThingCategory.Plant)
            {
                if (t.def.plant.harvestWork >= 200.0)
                {
                    return(true);
                }
                return(false);
            }
            if (!thingDef.clearBuildingArea)
            {
                return(false);
            }
            if (t.def == ThingDefOf.SteamGeyser && thingDef.entityDefToBuild.ForceAllowPlaceOver(t.def))
            {
                return(false);
            }
            ThingDef thingDef2 = thingDef.entityDefToBuild as ThingDef;

            if (thingDef2 != null)
            {
                if (thingDef2.EverTransmitsPower && t.def == ThingDefOf.PowerConduit && thingDef2 != ThingDefOf.PowerConduit)
                {
                    return(false);
                }
                if (t.def == ThingDefOf.Wall && thingDef2.building != null && thingDef2.building.canPlaceOverWall)
                {
                    return(false);
                }
            }
            if (t.def.IsEdifice() && thingDef2.IsEdifice())
            {
                return(true);
            }
            if (t.def.category != ThingCategory.Pawn && (t.def.category != ThingCategory.Item || thingDef.entityDefToBuild.passability != Traversability.Impassable))
            {
                if ((int)t.def.Fillage >= 1)
                {
                    return(true);
                }
                return(false);
            }
            return(true);
        }
예제 #8
0
        // Token: 0x0600368F RID: 13967 RVA: 0x001A1318 File Offset: 0x0019F718
        private static bool CellHasBlockingThings(IntVec3 cell, Map map)
        {
            List <Thing> thingList = cell.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                if (thingList[i] is Pawn || thingList[i] is HiveLike || thingList[i] is TunnelHiveSpawner)
                {
                    return(true);
                }
                bool flag = thingList[i].def.category == ThingCategory.Building && thingList[i].def.passability == Traversability.Impassable;
                if (flag && GenSpawn.SpawningWipes(XenomorphDefOf.RRY_Xenomorph_Hive, thingList[i].def))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #9
0
        public static bool BlocksConstruction(Thing constructible, Thing t)
        {
            if (t == constructible)
            {
                return(false);
            }
            ThingDef thingDef = !(constructible is Blueprint) ?
                                (!(constructible is Frame)
                                         ? constructible.def.blueprintDef
                                         : constructible.def.entityDefToBuild.blueprintDef)
                                    : constructible.def;

            if (t.def.category == ThingCategory.Building &&
                GenSpawn.SpawningWipes(thingDef.entityDefToBuild, (BuildableDef)t.def))
            {
                return(true);
            }
            if (t.def.category == ThingCategory.Plant)
            {
                return((double)t.def.plant.harvestWork >= 200.0);
            }
            if (!thingDef.clearBuildingArea ||
                t.def == ThingDefOf.SteamGeyser &&
                thingDef.entityDefToBuild.ForceAllowPlaceOver((BuildableDef)t.def))
            {
                return(false);
            }
            ThingDef entityDefToBuild = thingDef.entityDefToBuild as ThingDef;

            return((entityDefToBuild == null ||
                    (!entityDefToBuild.EverTransmitsPower ||
                     t.def != ThingDefOf.PowerConduit ||
                     entityDefToBuild == ThingDefOf.PowerConduit) &&
                    (!walls.Contains(t.def.defName) ||
                     entityDefToBuild.building == null ||
                     !entityDefToBuild.building.canPlaceOverWall)) &&
                   (t.def.IsEdifice() &&
                    entityDefToBuild.IsEdifice() ||
                    t.def.category == ThingCategory.Pawn ||
                    (t.def.category == ThingCategory.Item &&
                     thingDef.entityDefToBuild.passability == Traversability.Impassable ||
                     t.def.Fillage >= FillCategory.Partial)));
        }
예제 #10
0
 public static bool WipeExistingThings(IntVec3 thingPos, Rot4 thingRot, BuildableDef thingDef, Map map, DestroyMode mode)
 {
     if (thingDef?.Size != null)
     {
         foreach (IntVec3 c in GenAdj.CellsOccupiedBy(thingPos, thingRot, thingDef.Size))
         {
             foreach (Thing thing in map.thingGrid.ThingsAt(c).ToList <Thing>())
             {
                 if (thing?.def?.destroyable != null)
                 {
                     if (GenSpawn.SpawningWipes(thingDef, thing.def))
                     {
                         thing.Destroy(mode);
                     }
                 }
             }
         }
     }
     return(false);
 }
예제 #11
0
        public static bool WipeExistingThings(IntVec3 thingPos, Rot4 thingRot, BuildableDef thingDef, Map map, DestroyMode mode)
        {
            foreach (IntVec3 item in GenAdj.CellsOccupiedBy(thingPos, thingRot, thingDef.Size))
            {
                List <Thing> list = map.thingGrid.ThingsAt(item).ToList();
                for (int index = 0; index < list.Count; index++)
                {
                    Thing item2 = list[index];
                    if (item2 == null)
                    {
                        continue;
                    }
                    if (GenSpawn.SpawningWipes(thingDef, item2.def))
                    {
                        item2.Destroy(mode);
                    }
                }
            }

            return(false);
        }
예제 #12
0
        public bool Add(SketchEntity entity, bool wipeIfCollides = true)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }
            if (entities.Contains(entity))
            {
                return(true);
            }
            if (wipeIfCollides)
            {
                WipeColliding(entity);
            }
            else if (WouldCollide(entity))
            {
                return(false);
            }
            SketchTerrain sketchTerrain = entity as SketchTerrain;

            if (sketchTerrain != null && terrainAt.TryGetValue(sketchTerrain.pos, out SketchTerrain value))
            {
                Remove(value);
            }
            SketchBuildable sketchBuildable = entity as SketchBuildable;

            if (sketchBuildable != null)
            {
                for (int num = cachedBuildables.Count - 1; num >= 0; num--)
                {
                    if (sketchBuildable.OccupiedRect.Overlaps(cachedBuildables[num].OccupiedRect) && GenSpawn.SpawningWipes(sketchBuildable.Buildable, cachedBuildables[num].Buildable))
                    {
                        Remove(cachedBuildables[num]);
                    }
                }
            }
            entities.Add(entity);
            AddToCache(entity);
            return(true);
        }
예제 #13
0
        public static bool SpawningWipesPrefix(ref bool __result, BuildableDef newEntDef, BuildableDef oldEntDef)
        {
            ThingDef thingDef  = newEntDef as ThingDef;
            ThingDef thingDef2 = oldEntDef as ThingDef;

            if (thingDef == null || thingDef2 == null)
            {
                __result = false;
                return(false);
            }
            if (thingDef.category == ThingCategory.Attachment || thingDef.category == ThingCategory.Mote || thingDef.category == ThingCategory.Filth || thingDef.category == ThingCategory.Projectile)
            {
                __result = false;
                return(false);
            }
            if (!thingDef2.destroyable)
            {
                __result = false;
                return(false);
            }
            if (thingDef.category == ThingCategory.Plant)
            {
                __result = false;
                return(false);
            }
            if (thingDef2.category == ThingCategory.Filth && thingDef.passability != Traversability.Standable)
            {
                __result = true;
                return(false);
            }
            if (thingDef2.category == ThingCategory.Item && thingDef.passability == Traversability.Impassable && thingDef.surfaceType == SurfaceType.None)
            {
                __result = true;
                return(false);
            }
            if (thingDef.EverTransmitsPower && thingDef2 == ThingDefOf.PowerConduit)
            {
                __result = true;
                return(false);
            }
            if (thingDef.IsFrame && GenSpawn.SpawningWipes(thingDef.entityDefToBuild, oldEntDef))
            {
                __result = true;
                return(false);
            }
            BuildableDef buildableDef  = GenConstruct.BuiltDefOf(thingDef);
            BuildableDef buildableDef2 = GenConstruct.BuiltDefOf(thingDef2);

            if (buildableDef == null || buildableDef2 == null)
            {
                __result = false;
                return(false);
            }
            ThingDef thingDef3 = thingDef.entityDefToBuild as ThingDef;

            if (thingDef2.IsBlueprint)
            {
                if (thingDef.IsBlueprint)
                {
                    if (thingDef3 != null && thingDef3.building != null && thingDef3.building.canPlaceOverWall && thingDef2.entityDefToBuild is ThingDef && ((ThingDef)thingDef2.entityDefToBuild == ThingDefOf.Wall || ((ThingDef)thingDef2.entityDefToBuild).thingClass == typeof(GL_Building)))
                    {
                        __result = true;
                        return(false);
                    }
                    if (thingDef2.entityDefToBuild is TerrainDef)
                    {
                        if (thingDef.entityDefToBuild is ThingDef && ((ThingDef)thingDef.entityDefToBuild).coversFloor)
                        {
                            __result = true;
                            return(false);
                        }
                        if (thingDef.entityDefToBuild is TerrainDef)
                        {
                            __result = true;
                            return(false);
                        }
                    }
                }
                __result = thingDef2.entityDefToBuild == ThingDefOf.PowerConduit && thingDef.entityDefToBuild is ThingDef && (thingDef.entityDefToBuild as ThingDef).EverTransmitsPower;
                return(false);
            }
            if ((thingDef2.IsFrame || thingDef2.IsBlueprint) && thingDef2.entityDefToBuild is TerrainDef)
            {
                ThingDef thingDef4 = buildableDef as ThingDef;
                if (thingDef4 != null && !thingDef4.CoexistsWithFloors)
                {
                    __result = true;
                    return(false);
                }
            }
            if (thingDef2 == ThingDefOf.ActiveDropPod)
            {
                __result = false;
                return(false);
            }
            if (thingDef == ThingDefOf.ActiveDropPod)
            {
                __result = thingDef2 != ThingDefOf.ActiveDropPod && (thingDef2.category == ThingCategory.Building && thingDef2.passability == Traversability.Impassable);
                return(false);
            }
            if (thingDef.IsEdifice())
            {
                if (thingDef.BlockPlanting && thingDef2.category == ThingCategory.Plant)
                {
                    __result = true;
                    return(false);
                }
                if (!(buildableDef is TerrainDef) && buildableDef2.IsEdifice())
                {
                    __result = true;
                    return(false);
                }
            }
            __result = false;
            return(false);
        }
예제 #14
0
        private bool CanSpawnHiveAt(IntVec3 c, float minDist, bool ignoreRoofedRequirement)
        {
            if ((!ignoreRoofedRequirement && !c.Roofed(this.parent.Map)) || !c.Standable(this.parent.Map) || (minDist != 0f && (float)c.DistanceToSquared(this.parent.Position) < minDist * minDist))
            {
                return(false);
            }
            for (int i = 0; i < 8; i++)
            {
                IntVec3 c2 = c + GenAdj.AdjacentCells[i];
                if (c2.InBounds(this.parent.Map))
                {
                    List <Thing> thingList = c2.GetThingList(this.parent.Map);
                    for (int j = 0; j < thingList.Count; j++)
                    {
                        if (thingList[j] is Hive)
                        {
                            return(false);
                        }
                    }
                }
            }
            List <Thing> thingList2 = c.GetThingList(this.parent.Map);

            for (int k = 0; k < thingList2.Count; k++)
            {
                Thing thing = thingList2[k];
                if ((thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Building) && GenSpawn.SpawningWipes(this.parent.def, thing.def))
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #15
0
        public static bool BlocksConstruction(Thing constructible, Thing t)
        {
            bool result;

            if (t == constructible)
            {
                result = false;
            }
            else
            {
                ThingDef thingDef;
                if (constructible is Blueprint)
                {
                    thingDef = constructible.def;
                }
                else if (constructible is Frame)
                {
                    thingDef = constructible.def.entityDefToBuild.blueprintDef;
                }
                else
                {
                    thingDef = constructible.def.blueprintDef;
                }
                if (t.def.category == ThingCategory.Building && GenSpawn.SpawningWipes(thingDef.entityDefToBuild, t.def))
                {
                    result = true;
                }
                else if (t.def.category == ThingCategory.Plant)
                {
                    result = (t.def.plant.harvestWork >= 200f);
                }
                else if (!thingDef.clearBuildingArea)
                {
                    result = false;
                }
                else if (t.def == ThingDefOf.SteamGeyser && thingDef.entityDefToBuild.ForceAllowPlaceOver(t.def))
                {
                    result = false;
                }
                else
                {
                    ThingDef thingDef2 = thingDef.entityDefToBuild as ThingDef;
                    if (thingDef2 != null)
                    {
                        if (thingDef2.EverTransmitsPower)
                        {
                            if (t.def == ThingDefOf.PowerConduit && thingDef2 != ThingDefOf.PowerConduit)
                            {
                                return(false);
                            }
                        }
                        if (t.def == ThingDefOf.Wall && thingDef2.building != null && thingDef2.building.canPlaceOverWall)
                        {
                            return(false);
                        }
                    }
                    result = ((t.def.IsEdifice() && thingDef2.IsEdifice()) || (t.def.category == ThingCategory.Pawn || (t.def.category == ThingCategory.Item && thingDef.entityDefToBuild.passability == Traversability.Impassable)) || t.def.Fillage >= FillCategory.Partial);
                }
            }
            return(result);
        }
예제 #16
0
        public void Transfer(CoverageMap coverageMap)
        {
            //Planting blueprint
            float totalCost           = 0;
            int   transferredTerrains = 0;
            int   transferredTiles    = 0;
            int   totalTerrains       = 0;
            int   totalItems          = 0;

            //update rect to actual placement rect using width and height
            rp.rect = new CellRect(mapOriginX, mapOriginZ, blueprint.width, blueprint.height);

            Debug.Extra(Debug.BlueprintTransfer, "Clearing map...");

            for (int z = 0; z < blueprint.height; z++)
            {
                for (int x = 0; x < blueprint.width; x++)
                {
                    try {
                        IntVec3 mapLocation = new IntVec3(x + mapOriginX, 0, z + mapOriginZ);
                        //Check if thepoint is in allowed bounds of the map
                        if (!mapLocation.InBounds(map) || mapLocation.InNoBuildEdgeArea(map))
                        {
                            continue; //ignore invalid cells
                        }

                        if (options.overwritesEverything || Rand.Chance(0.6f))
                        {
                            if (blueprint.terrainMap[x, z] != null ||
                                blueprint.itemsMap[x, z].Count > 0 ||
                                blueprint.wallMap[x, z] > 1)
                            {
                                ClearCell(mapLocation, map, true);
                            }
                        }
                    } catch (Exception e) {
                        Debug.Warning(Debug.BlueprintTransfer, "Failed to clean cell at {0}, {1} because of {2}", x, z, e);
                    }
                }
            }

            Debug.Extra(Debug.BlueprintTransfer, "Transferring map objects");
            for (int z = 0; z < blueprint.height; z++)
            {
                for (int x = 0; x < blueprint.width; x++)
                {
                    IntVec3 mapLocation = new IntVec3(x + mapOriginX, 0, z + mapOriginZ);
                    if (coverageMap != null)
                    {
                        if (coverageMap.isMarked(mapLocation.x, mapLocation.z) == true) //cell was used earlier
                        {
                            continue;                                                   //skip already covered tiles
                        }
                        else
                        {
                            if (blueprint.wallMap[x, z] > 1 || blueprint.wallMap[x, z] == -1)
                            {
                                coverageMap.Mark(mapLocation.x, mapLocation.z);                                                               //mark cell as used
                            }
                        }
                    }


                    //Check if thepoint is in allowed bounds of the map
                    if (!mapLocation.InBounds(map) || mapLocation.InNoBuildEdgeArea(map))
                    {
                        continue; //ignore invalid cells
                    }

                    try {
                        //Construct terrain if some specific terrain stored in the blueprint
                        if (blueprint.terrainMap[x, z] != null)
                        {
                            totalTerrains++;
                            TerrainDef blueprintTerrain = TerrainDef.Named(blueprint.terrainMap[x, z].defName);
                            if (!map.terrainGrid.TerrainAt(mapLocation).IsWater)
                            {
                                map.terrainGrid.SetTerrain(mapLocation, blueprintTerrain);
                                totalCost += blueprint.terrainMap[x, z].cost;
                                transferredTerrains++;
                            }
                        }


                        //construct roof evetywhere if we doing complete transfer (ignoring outside: room with index 1).
                        if (blueprint.roofMap[x, z] == true && options.overwritesEverything && blueprint.wallMap[x, z] != 1)
                        {
                            map.roofGrid.SetRoof(mapLocation, RoofDefOf.RoofConstructed);
                        }


                        Debug.Extra(Debug.BlueprintTransfer, "Transferred terrain and roof at cell ({0}, {1})", x, z);
                    } catch (Exception e) {
                        Debug.Warning(Debug.BlueprintTransfer, "Failed to transfer terrain {0} at {1}, {2} because of {3}", blueprint.terrainMap[x, z].defName, x, z, e);
                    }

                    //Add items
                    if (blueprint.itemsMap[x, z] != null && blueprint.itemsMap[x, z].Count > 0 /* && cellUsed[mapLocation.x, mapLocation.z] == false*/)
                    {
                        totalItems += blueprint.itemsMap[x, z].Count;


                        foreach (ItemTile itemTile in blueprint.itemsMap[x, z])
                        {
                            Debug.Extra(Debug.BlueprintTransfer, "Creating thing {2} at cell ({0}, {1})", x, z, itemTile.defName);
                            Thing thing = MakeThingFromItemTile(itemTile);
                            if (thing != null)
                            {
                                try {
                                    Rot4 rotation = new Rot4(itemTile.rot);
                                    //check if there is anything we have to despawn in order to spawn our new item
                                    //we have to do this, because many dubs bad hygiene items enter endless cycle when removed during mapgen.
                                    foreach (IntVec3 occupiedCell in GenAdj.CellsOccupiedBy(mapLocation, rotation, thing.def.Size))
                                    {
                                        foreach (Thing existingItem in map.thingGrid.ThingsAt(occupiedCell).ToList())
                                        {
                                            if (GenSpawn.SpawningWipes(thing.def, existingItem.def))
                                            {
                                                if (thing.def.thingClass.ToString().Contains("DubsBadHygiene"))
                                                {
                                                    throw new Exception("Can't spawn item because it will destroy Dubs Bad Hygiene Item and it will lead to app freeze.");
                                                }
                                                existingItem.Destroy(DestroyMode.Vanish);
                                            }
                                        }
                                    }



                                    GenSpawn.Spawn(thing, mapLocation, map, rotation);
                                    Debug.Extra(Debug.BlueprintTransfer, "Spawned");
                                    try {
                                        switch (thing.def.tickerType)
                                        {
                                        case TickerType.Never:
                                            break;

                                        case TickerType.Normal:
                                            thing.Tick();
                                            break;

                                        case TickerType.Long:
                                            thing.TickLong();
                                            break;

                                        case TickerType.Rare:
                                            thing.TickRare();
                                            break;
                                        }
                                        //Debug.Message("Ticked");
                                    } catch (Exception e) {
                                        Debug.Log(Debug.BlueprintTransfer, "Exception while tried to perform tick for {0} of cost {1}, retrhrowing...", thing.def.defName, itemTile.cost);
                                        thing.Destroy();
                                        throw e;
                                    }

                                    //Debug.Message("Setting up props");
                                    //Breakdown breakdownables: it't yet impossible to silently breakdown an item which is not spawned.
                                    CompBreakdownable b = thing.TryGetComp <CompBreakdownable>();
                                    if (b != null && options.enableDeterioration)
                                    {
                                        if (Rand.Chance(0.8f))
                                        {
                                            b.DoBreakdown();
                                        }
                                    }

                                    //reduce HP for haulable things in water
                                    if (thing.def.EverHaulable)
                                    {
                                        TerrainDef t = map.terrainGrid.TerrainAt(mapLocation);
                                        if (t != null && t.IsWater)
                                        {
                                            thing.HitPoints = (thing.HitPoints - 10) / Rand.Range(5, 20) + Rand.Range(1, 10); //things in marsh or river are really in bad condition
                                        }
                                    }
                                    Debug.Extra(Debug.BlueprintTransfer, "Item completed");

                                    transferredTiles++;
                                    totalCost += itemTile.cost;
                                } catch (Exception e) {
                                    Debug.Warning(Debug.BlueprintTransfer, "Failed to spawn item {0} of cost {1} because of exception {2}", thing, itemTile.cost, e.Message);
                                    //ignore
                                }
                            }
                        }
                    }
                }
            }

            Debug.Log(Debug.BlueprintTransfer, "Finished transferring");
            if (options.shouldKeepDefencesAndPower)
            {
                RestoreDefencesAndPower();
            }
            options.uncoveredCost = totalCost;
            Debug.Log(Debug.BlueprintTransfer, "Transferred blueprint of size {0}x{1}, age {2}, total cost of approximately {3}. Items: {4}/{5}, terrains: {6}/{7}", blueprint.width, blueprint.height, -blueprint.dateShift, totalCost, transferredTiles, totalItems, transferredTerrains, totalTerrains);
        }
예제 #17
0
        public void Spawn(Map map, IntVec3 pos, Faction faction, SpawnPosType posType = SpawnPosType.Unchanged, SpawnMode spawnMode = SpawnMode.Normal, bool wipeIfCollides = false, bool clearEdificeWhereFloor = false, List <Thing> spawnedThings = null, bool dormant = false, bool buildRoofsInstantly = false, Func <SketchEntity, IntVec3, bool> canSpawnThing = null, Action <IntVec3, SketchEntity> onFailedToSpawnThing = null)
        {
            IntVec3 offset = GetOffset(pos, posType);

            if (clearEdificeWhereFloor)
            {
                for (int i = 0; i < cachedTerrain.Count; i++)
                {
                    if (cachedTerrain[i].def.layerable)
                    {
                        (cachedTerrain[i].pos + offset).GetEdifice(map)?.Destroy();
                    }
                }
            }
            foreach (SketchEntity item in entities.OrderBy((SketchEntity x) => x.SpawnOrder))
            {
                IntVec3 intVec = item.pos + offset;
                if ((canSpawnThing == null || canSpawnThing(item, intVec)) && !item.Spawn(intVec, map, faction, spawnMode, wipeIfCollides, spawnedThings, dormant))
                {
                    onFailedToSpawnThing?.Invoke(intVec, item);
                }
            }
            if (spawnedThings != null && spawnMode == SpawnMode.TransportPod && !wipeIfCollides)
            {
                bool flag = false;
                for (int j = 0; j < spawnedThings.Count; j++)
                {
                    for (int k = j + 1; k < spawnedThings.Count; k++)
                    {
                        CellRect cellRect = GenAdj.OccupiedRect(spawnedThings[j].Position, spawnedThings[j].Rotation, spawnedThings[j].def.size);
                        CellRect other    = GenAdj.OccupiedRect(spawnedThings[k].Position, spawnedThings[k].Rotation, spawnedThings[k].def.size);
                        if (cellRect.Overlaps(other) && (GenSpawn.SpawningWipes(spawnedThings[j].def, spawnedThings[k].def) || GenSpawn.SpawningWipes(spawnedThings[k].def, spawnedThings[j].def)))
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (flag)
                    {
                        break;
                    }
                }
                if (flag)
                {
                    for (int l = 0; l < spawnedThings.Count; l++)
                    {
                        ActiveDropPodInfo activeDropPodInfo;
                        if ((activeDropPodInfo = (spawnedThings[l].ParentHolder as ActiveDropPodInfo)) != null)
                        {
                            activeDropPodInfo.spawnWipeMode = null;
                        }
                    }
                }
            }
            if (buildRoofsInstantly && spawnMode == SpawnMode.Normal)
            {
                foreach (IntVec3 suggestedRoofCell in GetSuggestedRoofCells())
                {
                    IntVec3 c = suggestedRoofCell + offset;
                    if (c.InBounds(map) && !c.Roofed(map))
                    {
                        map.roofGrid.SetRoof(c, RoofDefOf.RoofConstructed);
                    }
                }
            }
        }
예제 #18
0
        public static bool SpawningWipes(BuildableDef newEntDef, BuildableDef oldEntDef)
        {
            ThingDef thingDef  = newEntDef as ThingDef;
            ThingDef thingDef2 = oldEntDef as ThingDef;

            if (thingDef == null || thingDef2 == null)
            {
                return(false);
            }
            if (thingDef.category == ThingCategory.Attachment || thingDef.category == ThingCategory.Mote || thingDef.category == ThingCategory.Filth || thingDef.category == ThingCategory.Projectile)
            {
                return(false);
            }
            if (!thingDef2.destroyable)
            {
                return(false);
            }
            if (thingDef.category == ThingCategory.Plant)
            {
                return(false);
            }
            if (thingDef2.category == ThingCategory.Filth && thingDef.passability != Traversability.Standable)
            {
                return(true);
            }
            //if (thingDef.EverTransmitsPower && thingDef2 == ThingDefOf.PowerConduit)
            if (thingDef.EverTransmitsPower && GenConstruct_JT.conduits.Contains(thingDef2.defName))
            {
                return(true);
            }
            if (thingDef.IsFrame && GenSpawn.SpawningWipes(thingDef.entityDefToBuild, oldEntDef))
            {
                return(true);
            }
            BuildableDef buildableDef  = GenConstruct.BuiltDefOf(thingDef);
            BuildableDef buildableDef2 = GenConstruct.BuiltDefOf(thingDef2);

            if (buildableDef == null || buildableDef2 == null)
            {
                return(false);
            }
            ThingDef thingDef3 = thingDef.entityDefToBuild as ThingDef;

            if (thingDef2.IsBlueprint)
            {
                if (thingDef.IsBlueprint)
                {
                    if (thingDef3 != null && thingDef3.building != null && thingDef3.building.canPlaceOverWall && thingDef2.entityDefToBuild is ThingDef && (ThingDef)thingDef2.entityDefToBuild == ThingDefOf.Wall)
                    {
                        return(true);
                    }
                    if (thingDef2.entityDefToBuild is TerrainDef)
                    {
                        if (thingDef.entityDefToBuild is ThingDef && ((ThingDef)thingDef.entityDefToBuild).coversFloor)
                        {
                            return(true);
                        }
                        if (thingDef.entityDefToBuild is TerrainDef)
                        {
                            return(true);
                        }
                    }
                }
                return(thingDef2.entityDefToBuild == ThingDefOf.PowerConduit && thingDef.entityDefToBuild is ThingDef && (thingDef.entityDefToBuild as ThingDef).EverTransmitsPower);
            }
            if ((thingDef2.IsFrame || thingDef2.IsBlueprint) && thingDef2.entityDefToBuild is TerrainDef)
            {
                ThingDef thingDef4 = buildableDef as ThingDef;
                if (thingDef4 != null && !thingDef4.CoexistsWithFloors)
                {
                    return(true);
                }
            }
            if (thingDef2 == ThingDefOf.ActiveDropPod)
            {
                return(false);
            }
            if (thingDef == ThingDefOf.ActiveDropPod)
            {
                return(thingDef2 != ThingDefOf.ActiveDropPod && (thingDef2.category == ThingCategory.Building && thingDef2.passability == Traversability.Impassable));
            }
            if (thingDef.IsEdifice())
            {
                if (thingDef.BlockPlanting && thingDef2.category == ThingCategory.Plant)
                {
                    return(true);
                }
                if (!(buildableDef is TerrainDef) && buildableDef2.IsEdifice())
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #19
0
        private static bool CellHasBlockingThings(IntVec3 cell, Map map)
        {
            List <Thing> thingList = cell.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                if (thingList[i] is Pawn)
                {
                    return(true);
                }
                if ((thingList[i].def.category == ThingCategory.Building || thingList[i].def.category == ThingCategory.Item) && GenSpawn.SpawningWipes(ThingDefOf.Hive, thingList[i].def))
                {
                    return(true);
                }
            }
            return(false);
        }