Beispiel #1
0
        /// <summary>
        /// Returns a list of TileObjects that will be destroyed if an object on the given layer is destroyed.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="layer"></param>
        /// <param name="position"></param>
        /// <returns></returns>
        public static List <TileObject> GetToBeDestroyedObjects(TileMap map, TileLayer layer, Vector3 position)
        {
            List <TileObject> toBeDestroyedList = new List <TileObject>();

            // Remove everything when the plenum is missing
            if (layer == TileLayer.Plenum)
            {
                foreach (TileLayer layerToCheck in TileHelper.GetTileLayers())
                {
                    if (layerToCheck == TileLayer.Plenum)
                    {
                        continue;
                    }

                    toBeDestroyedList.Add(map.GetTileObject(layerToCheck, position));
                }
            }

            // Remove any wall fixtures when the turf is missing
            else if (layer == TileLayer.Turf)
            {
                toBeDestroyedList.Add(map.GetTileObject(TileLayer.HighWallMount, position));
                toBeDestroyedList.Add(map.GetTileObject(TileLayer.LowWallMount, position));
            }

            // Remove furniture top is furniture base is missing
            else if (layer == TileLayer.FurnitureBase)
            {
                toBeDestroyedList.Add(map.GetTileObject(TileLayer.FurnitureTop, position));
            }

            return(toBeDestroyedList);
        }
Beispiel #2
0
        /// <summary>
        /// Create empty grids for all layers.
        /// </summary>
        private void CreateAllGrids()
        {
            tileGridList = new List <TileGrid>();

            foreach (TileLayer layer in TileHelper.GetTileLayers())
            {
                tileGridList.Add(CreateGrid(layer));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Main function for verifying if a tileObjectSO can be placed at a given location.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="position"></param>
        /// <param name="subLayerIndex"></param>
        /// <param name="tileObjectSO"></param>
        /// <param name="dir"></param>
        /// <returns></returns>
        public static bool CanBuild(TileMap map, Vector3 position, int subLayerIndex, TileObjectSO tileObjectSO, Direction dir)
        {
            TileManager tileManager = TileManager.Instance;
            TileLayer   placedLayer = tileObjectSO.layer;

            TileObject[] tileObjects = new TileObject[TileHelper.GetTileLayers().Length];

            foreach (TileLayer layer in TileHelper.GetTileLayers())
            {
                tileObjects[(int)layer] = map.GetTileObject(layer, position);
            }

            // Cannot build anything unless a plenum is placed
            if (placedLayer != TileLayer.Plenum && !CanBuildOnPlenum(map, position, tileObjectSO, dir))
            {
                return(false);
            }

            // No wall mounts on non-walls
            if (tileObjects[(int)TileLayer.Turf].IsCompletelyEmpty() &&
                (placedLayer == TileLayer.LowWallMount || placedLayer == TileLayer.HighWallMount))
            {
                return(false);
            }

            if (placedLayer == TileLayer.LowWallMount || placedLayer == TileLayer.HighWallMount)
            {
                if (!CanBuildWallAttachment(map, position, tileObjectSO, dir))
                {
                    return(false);
                }
            }

            // No furniture inside walls
            if (placedLayer == TileLayer.FurnitureBase || placedLayer == TileLayer.FurnitureTop ||
                placedLayer == TileLayer.Overlay)
            {
                TileObject wallObject = map.GetTileObject(TileLayer.Turf, position);
                if (!wallObject.IsCompletelyEmpty() && wallObject.GetPlacedObject(0).GetGenericType().Contains("wall"))
                {
                    return(false);
                }
            }

            // No walls on furniture
            if (placedLayer == TileLayer.Turf && tileObjectSO.genericType.Contains("wall") &&
                (!tileObjects[(int)TileLayer.FurnitureBase].IsCompletelyEmpty() ||
                 !tileObjects[(int)TileLayer.FurnitureTop].IsCompletelyEmpty() ||
                 !tileObjects[(int)TileLayer.Overlay].IsCompletelyEmpty()))
            {
                return(false);
            }


            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Determines if all layers in the chunk are completely empty.
        /// </summary>
        /// <returns></returns>
        public bool IsEmpty()
        {
            bool empty = true;

            foreach (TileLayer layer in TileHelper.GetTileLayers())
            {
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        TileObject tileObject = GetTileObject(layer, x, y);
                        if (!tileObject.IsCompletelyEmpty())
                        {
                            empty = false;
                        }
                    }
                }
            }

            return(empty);
        }