예제 #1
0
    public void DisableOverlappingWallPieces()
    {
        Logger.Log(Logger.Locomotion, "Disable double wall pieces");

        //get wall pieces with overlap. Then wall pieces against edge tiles of all other rooms
        List <BuildingTile> edgeTileClustersWithOverlap = RoomEdgeTilesPerCluster.Where(tile => tile.BuildingTileRooms.Count > 1).ToList();

        for (int i = 0; i < edgeTileClustersWithOverlap.Count; i++)
        {
            BuildingTile tileWithOverlap = edgeTileClustersWithOverlap[i];
            for (int j = 0; j < tileWithOverlap.BuildingTileRooms.Count; j++)
            {
                Room otherRoom = tileWithOverlap.BuildingTileRooms[j];
                if (otherRoom == this)
                {
                    continue;
                }

                for (int k = 0; k < otherRoom.RoomEdgeTilesPerCluster.Count; k++)
                {
                    BuildingTile otherRoomTile = otherRoom.RoomEdgeTilesPerCluster[k];
                    // the tile in this room and the same tile in the other room. Now find the common wall pieces
                    if (otherRoomTile.StartingPoint.x == tileWithOverlap.StartingPoint.x)
                    {
                        DisableWallpiece(tileWithOverlap.StartingPoint, this, otherRoom);
                        DisableWallpiece(new Vector2(tileWithOverlap.StartingPoint.x + 5, tileWithOverlap.StartingPoint.y + 2.5f), this, otherRoom);
                        DisableWallpiece(new Vector2(tileWithOverlap.StartingPoint.x + 10, tileWithOverlap.StartingPoint.y + 5f), this, otherRoom);
                        DisableWallpiece(new Vector2(tileWithOverlap.StartingPoint.x + 5, tileWithOverlap.StartingPoint.y - 2.5f), this, otherRoom);
                        DisableWallpiece(new Vector2(tileWithOverlap.StartingPoint.x + 10, tileWithOverlap.StartingPoint.y - 5f), this, otherRoom);
                    }
                }
            }
        }
    }
예제 #2
0
    public List <BuildingTile> CreateTileRing(List <BuildingTile> tileRing, List <BuildingTile> surroundingSquareTiles)
    {
        List <BuildingTile> newTiles = new List <BuildingTile>();

        for (int k = 0; k < tileRing.Count; k++)
        {
            //Logger.Log(Logger.Building, "tile ring tile {0}", tileRing[k].StartingPoint);
            BuildingTile upRight = CreateNeighbourTile(tileRing[k].StartingPoint, 3, 3, surroundingSquareTiles);
            if (upRight != null)
            {
                newTiles.Add(upRight);
            }

            BuildingTile upLeft = CreateNeighbourTile(tileRing[k].StartingPoint, -3, 3, surroundingSquareTiles);
            if (upLeft != null)
            {
                newTiles.Add(upLeft);
            }

            BuildingTile downRight = CreateNeighbourTile(tileRing[k].StartingPoint, 3, -3, surroundingSquareTiles);
            if (downRight != null)
            {
                newTiles.Add(downRight);
            }

            BuildingTile downLeft = CreateNeighbourTile(tileRing[k].StartingPoint, -3, -3, surroundingSquareTiles);
            if (downLeft != null)
            {
                newTiles.Add(downLeft);
            }
        }
        return(newTiles);
    }
예제 #3
0
    private BuildingTile GetBuildingTileForAvailability(int rightUpAxisFromStartingPoint, int leftUpAxisFromStartingPoint, Vector2 plotLocationStartingPoint, List <BuildingTile> roomSquareTiles)
    {
        Vector2 location = GridHelper.GridToVectorLocation(plotLocationStartingPoint, rightUpAxisFromStartingPoint, -leftUpAxisFromStartingPoint);

        BuildingTile tile = roomSquareTiles.FirstOrDefault(t => t.StartingPoint == location);

        return(tile);
    }
    public List <Room> BuildingTileRooms = new List <Room>(); // the rooms of which this tile is a part

    public static BuildingTile CreateBuildingTile(int rightUpStartPosition, int leftUpStartPosition, Availability availability)
    {
        BuildingTile buildingTile = new BuildingTile();

        buildingTile.StartingPoint = GridHelper.GridToVectorLocation(rightUpStartPosition, leftUpStartPosition);
        buildingTile.IsAvailable   = availability;
        BuilderManager.Instance.BuildingTileLocations.Add(buildingTile.StartingPoint);
        return(buildingTile);
    }
    public static BuildingTile CreateBuildingTile(Vector2 newTilePosition, Availability availability)
    {
        BuildingTile buildingTile = new BuildingTile();

        buildingTile.StartingPoint = newTilePosition;
        buildingTile.IsAvailable   = availability;
        BuilderManager.Instance.BuildingTileLocations.Add(buildingTile.StartingPoint);
        return(buildingTile);
    }
예제 #6
0
    // check all tiles where the plot would be drawn if the building tile is available. Only draw a plot when all tiles are available
    public bool GetPlotIsAvailable(RoomBlueprint roomBlueprint, Vector2 roomStartingPoint, ObjectRotation roomRotation)
    {
        int rightUpAxisLength = roomRotation == ObjectRotation.Rotation0 || roomRotation == ObjectRotation.Rotation180 ?
                                roomBlueprint.RightUpAxisLength : roomBlueprint.LeftUpAxisLength;
        int leftUpAxisLength = roomRotation == ObjectRotation.Rotation0 || roomRotation == ObjectRotation.Rotation180 ?
                               roomBlueprint.LeftUpAxisLength : roomBlueprint.RightUpAxisLength;
        Vector2 plotLocationStartingPoint = GridHelper.GridToVectorLocation(roomStartingPoint, 0, 0);
        Vector2 point1 = GridHelper.GridToVectorLocation(plotLocationStartingPoint, rightUpAxisLength, 0);
        Vector2 point2 = GridHelper.GridToVectorLocation(point1, 0, -leftUpAxisLength);
        Vector2 point3 = GridHelper.GridToVectorLocation(point2, -rightUpAxisLength, 0);

        List <BuildingTile> roomSquareTiles = _builderManager.BuildingTiles.FindAll(tile =>
                                                                                    tile.StartingPoint.x >= point3.x &&
                                                                                    tile.StartingPoint.x <= point1.x &&
                                                                                    tile.StartingPoint.y <= point2.y &&
                                                                                    tile.StartingPoint.y >= plotLocationStartingPoint.y
                                                                                    );

        BuildingTile startingTile = roomSquareTiles.FirstOrDefault(t => t.StartingPoint == plotLocationStartingPoint);

        if (startingTile.IsAvailable == Availability.Unavailable)
        {
            return(false);
        }

        bool isAvailable = true;

        for (int i = 0; i <= rightUpAxisLength - 3; i += 3)
        {
            for (int j = 0; j <= leftUpAxisLength - 3; j += 3)
            {
                BuildingTile tile = GetBuildingTileForAvailability(i, j, plotLocationStartingPoint, roomSquareTiles);

                //if (i == 0 || i == rightUpAxisLength || j == 0 || j == leftUpAxisLength)
                //{
                //    // skip tiles that are at the edge because they may overlap with the walls of adjacent rooms
                //    continue;
                //}

                if (tile == null)
                {
                    Logger.Error(Logger.Building, "Could not find tile at {0}", GridHelper.GridToVectorLocation(plotLocationStartingPoint, i, -j));
                }

                if (tile.IsAvailable == Availability.Unavailable)
                {
                    isAvailable = false;
                    break;
                }
            }
        }

        return(isAvailable);
    }
예제 #7
0
    public override void SetTile(Vector3Int location, GridTile tile)
    {
        BuildingTile buildingTile = (BuildingTile)tile;

        tiles[location] = buildingTile;

        buildingTile.transform.SetParent(this.transform);
        // if (buildingTile.name.IndexOf("(Clone)") > -1) {
        //     buildingTile.name = buildingTile.name.Substring(0, buildingTile.name.IndexOf("(Clone)")) + location;
        // }
    }
예제 #8
0
 public void SetupInitialBuildingTiles()
 {
     _builderManager.BuildingTiles.Add(BuildingTile.CreateBuildingTile(0, 0, Availability.Available));
     _builderManager.BuildingTiles.Add(BuildingTile.CreateBuildingTile(3, 0, Availability.Available));
     _builderManager.BuildingTiles.Add(BuildingTile.CreateBuildingTile(6, 0, Availability.Available));
     _builderManager.BuildingTiles.Add(BuildingTile.CreateBuildingTile(9, 0, Availability.Available));
     _builderManager.BuildingTiles.Add(BuildingTile.CreateBuildingTile(0, 3, Availability.Available));
     _builderManager.BuildingTiles.Add(BuildingTile.CreateBuildingTile(3, 3, Availability.Available));
     _builderManager.BuildingTiles.Add(BuildingTile.CreateBuildingTile(6, 3, Availability.Available));
     _builderManager.BuildingTiles.Add(BuildingTile.CreateBuildingTile(9, 3, Availability.Available));
     _builderManager.BuildingTiles.Add(BuildingTile.CreateBuildingTile(0, 6, Availability.Available));
     _builderManager.BuildingTiles.Add(BuildingTile.CreateBuildingTile(3, 6, Availability.Available));
     _builderManager.BuildingTiles.Add(BuildingTile.CreateBuildingTile(6, 6, Availability.Available));
     _builderManager.BuildingTiles.Add(BuildingTile.CreateBuildingTile(9, 6, Availability.Available));
 }
예제 #9
0
        private void Update()
        {
            transform.position = Input.mousePosition;

            if (Input.GetMouseButtonUp(0))
            {
                Core.Data.UI.BuildingPicker.IsBuildingPlacerVisible.Set(false);
                BuildingTile tile = Core.Instance.BuildingsArea.GetClosestTile(transform.position);
                if (tile != null)
                {
                    Core.Instance.BuildingsArea.BuyBuilding(building, tile);
                    GetNewBuilding();
                }
            }
        }
    public static void LowerWallPieces(Room room)
    {
        // Make wall pieces transparent in this room
        if (room.CharactersInRoom.Count > 0)
        {
            for (int i = 0; i < room.WallPieces.Count; i++)
            {
                if (room.WallPieces[i].WallPieceType == WallPieceType.DownLeft || room.WallPieces[i].WallPieceType == WallPieceType.DownRight)
                {
                    if (!room.WallPieces[i].gameObject.activeSelf)
                    {
                        continue;
                    }
                    room.WallPieces[i].SetWallSprite(WallPieceDisplayMode.Transparent);
                }
            }
        }

        //get all wall tile clusters with overlap. Then compare the direction of the wall pieces with those of other rooms and lower correct wall pieces
        List <BuildingTile> edgeTileClustersWithOverlap = room.RoomEdgeTilesPerCluster.Where(tile => tile.BuildingTileRooms.Count > 1).ToList();

        for (int j = 0; j < edgeTileClustersWithOverlap.Count; j++)
        {
            BuildingTile tileWithOverlap = edgeTileClustersWithOverlap[j];
            for (int k = 0; k < tileWithOverlap.BuildingTileRooms.Count; k++)
            {
                Room otherRoom = tileWithOverlap.BuildingTileRooms[k];
                if (otherRoom == room)
                {
                    continue;
                }

                for (int m = 0; m < otherRoom.RoomEdgeTilesPerCluster.Count; m++)
                {
                    BuildingTile otherRoomTile = otherRoom.RoomEdgeTilesPerCluster[m];
                    // the tile in this room and the same tile in the other room. Now find the common wall pieces
                    if (otherRoomTile.StartingPoint.x == tileWithOverlap.StartingPoint.x)
                    {
                        LowerWallPiece(tileWithOverlap.StartingPoint, room, otherRoom);
                        LowerWallPiece(new Vector2(tileWithOverlap.StartingPoint.x + 5, tileWithOverlap.StartingPoint.y + 2.5f), room, otherRoom);
                        LowerWallPiece(new Vector2(tileWithOverlap.StartingPoint.x + 10, tileWithOverlap.StartingPoint.y + 5f), room, otherRoom);
                        LowerWallPiece(new Vector2(tileWithOverlap.StartingPoint.x + 5, tileWithOverlap.StartingPoint.y - 2.5f), room, otherRoom);
                        LowerWallPiece(new Vector2(tileWithOverlap.StartingPoint.x + 10, tileWithOverlap.StartingPoint.y - 5f), room, otherRoom);
                    }
                }
            }
        }
    }
예제 #11
0
    public List <BuildingTile> GetRoomEdgeTiles()
    {
        // Get all building tiles in the location of the room and make them UNAVAILABLE
        List <BuildingTile> roomSquareTiles = BuilderManager.Instance.BuildingTiles.FindAll(tile =>
                                                                                            tile.StartingPoint.x >= RoomCorners[Direction.Left].x &&
                                                                                            tile.StartingPoint.x <= RoomCorners[Direction.Right].x &&
                                                                                            tile.StartingPoint.y <= RoomCorners[Direction.Up].y &&
                                                                                            tile.StartingPoint.y >= RoomCorners[Direction.Down].y
                                                                                            );

        int rightUpAxisLength = GetRightUpAxisLengthForRoomRotation();
        int leftUpAxisLength  = GetLeftUpAxisLengthForRoomRotation();

        for (int i = 0; i <= rightUpAxisLength; i += 3)
        {
            for (int j = leftUpAxisLength; j >= 0; j -= 3)
            {
                Vector2      location = GridHelper.GridToVectorLocation(RoomCorners[Direction.Down], i, -j);
                BuildingTile tile     = roomSquareTiles.FirstOrDefault(t => t.StartingPoint == location);

                tile.BuildingTileRooms.Add(this);
                if ((i == 0 && j < leftUpAxisLength) || (j == 0 && i < rightUpAxisLength))
                {
                    RoomEdgeTilesPerCluster.Add(tile);
                    tile.IsAvailable = Availability.Unavailable;
                }
                else if (i == rightUpAxisLength || j == leftUpAxisLength)
                {
                    RoomEdgeTilesPerCluster.Add(tile);
                    if (tile.IsAvailable == Availability.Available)
                    {
                        tile.IsAvailable = Availability.UpperEdge;
                    }
                }
                else
                {
                    tile.IsAvailable = Availability.Unavailable;
                }
            }
        }

        return(RoomEdgeTilesPerCluster);
    }
예제 #12
0
    public void PlaceBuilding(BuildingTile building, Vector3Int position)
    {
        if (building)
        {
            tilemap.SetTile(position, building.centerTile);

            if (building.ring1Tile.Length != 0)
            {
                var ring = HexagonalTile.GetHexagonalRing(position, 1);
                foreach (Vector3Int t in ring)
                {
                    if (Random.Range(0f, 1f) < building.ring1Probability)
                    {
                        tilemap.SetTile(t, building.ring1Tile[Random.Range(0, building.ring1Tile.Length)]);
                        if (building.flipAllowed && Random.Range(0, 2) != 0)
                        {
                            Matrix4x4 matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 180f, 0f), Vector3.one);
                            tilemap.SetTransformMatrix(t, matrix);
                        }
                    }
                }
            }

            if (building.ring2Tile.Length != 0)
            {
                var ring = HexagonalTile.GetHexagonalRing(position, 2);
                foreach (Vector3Int t in ring)
                {
                    if (Random.Range(0f, 1f) < building.ring2Probability)
                    {
                        tilemap.SetTile(t, building.ring2Tile[Random.Range(0, building.ring2Tile.Length)]);
                        if (building.flipAllowed && Random.Range(0, 2) != 0)
                        {
                            Matrix4x4 matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0f, 180f, 0f), Vector3.one);
                            tilemap.SetTransformMatrix(t, matrix);
                        }
                    }
                }
            }
        }
    }
예제 #13
0
    public BuildingTile CreateNeighbourTile(Vector2 startingPoint, int rightUpAxisLength, int leftUpAxisLength, List <BuildingTile> surroundingSquareTiles)
    {
        Vector2 neighbourLocation = GridHelper.GridToVectorLocation(startingPoint, rightUpAxisLength, leftUpAxisLength);

        if (!_builderManager.BuildingTileLocations.Contains(neighbourLocation))
        {
            BuildingTile tile = BuildingTile.CreateBuildingTile(neighbourLocation, Availability.Available);
            _builderManager.BuildingTiles.Add(tile);

            return(tile);
        }

        BuildingTile existingTile = surroundingSquareTiles.Find(surroundingSquareTile => surroundingSquareTile.StartingPoint == neighbourLocation);

        //Some tiles at the direct edge may already exist, but the tile one row further still needs to be created. Therefore, also add this tile to the list.
        if (existingTile != null && existingTile.IsAvailable == Availability.Available)
        {
            return(existingTile);
        }
        return(null);
    }
    public void Initialize(TerrainManager terrainManager)
    {
        // Load in cities from a texture map.
        for (var row = 0; row < tiles.GetLength(0); row++)
        {
            for (var col = 0; col < tiles.GetLength(1); col++)
            {
                var          pxl  = data.zoningMap.GetPixel(col, row);
                BuildingType type = BuildingType.Residential;
                if (pxl.r > 0)                   // this is a residential tile
                {
                    type = BuildingType.Residential;
                }
                else if (pxl.g > 0)                     // this is a commercial tile
                {
                    type = BuildingType.Commerce;
                }
                else if (pxl.b > 0)                     // this is a industiral tile
                {
                    type = BuildingType.Industrial;
                }
                else
                {
                    continue;
                }

                var density = (Density)((pxl.r + pxl.g + pxl.b) * 2);

                var tile = new BuildingTile();
                tile.buildingManager = this;
                tile.density         = density;
                tile.type            = type;
                tile.location        = new Location();
                tile.location.row    = row;
                tile.location.col    = col;
                tile.height          = terrainManager.GetWorldHeightAtLocation(tile.location);
                tiles[row, col]      = tile;
            }
        }
    }
예제 #15
0
    public bool CheckLocomotionTargetAvailability()
    {
        Vector2 target   = PlayerLocomotion.Target;
        float   modulusX = target.x % 15;
        float   modulusY = target.y % 7.5f;

        GridLocation trueGridLocation            = GridHelper.VectorToGridLocation(target);
        GridLocation closestGridTileGridLocation = GridHelper.FindClosestGridTile(trueGridLocation);

        Vector2      buildingTileCoordinates = GridHelper.GridToVectorLocation(closestGridTileGridLocation);
        BuildingTile buildingTile            = BuilderManager.Instance.BuildingTiles.SingleOrDefault(tile => tile.StartingPoint == buildingTileCoordinates);

        if (buildingTile != null)
        {
            // if a tile is unavailable, it means a room is built on it
            if (buildingTile.IsAvailable != Availability.Unavailable)
            {
                return(false);
            }
        }

        return(true);
    }
    public static void ReenableWallpiecesFromAdjacentRooms(Room room)
    {
        // after a neighbour room is deleted, go over all wallpieces in this room to check if any wallpieces now do not overlap but are disabled. Reenable these
        List <BuildingTile> edgeTileClustersWithOverlap = room.RoomEdgeTilesPerCluster.Where(tile => tile.BuildingTileRooms.Count > 1).ToList();

        List <Room> roomsStartingOnEdgeTile = new List <Room>();

        for (int j = 0; j < edgeTileClustersWithOverlap.Count; j++)
        {
            BuildingTile edgeTileClusterWithOverlap = edgeTileClustersWithOverlap[j];
            for (int p = 0; p < edgeTileClusterWithOverlap.BuildingTileRooms.Count; p++)
            {
                Room overlappingRoom = edgeTileClusterWithOverlap.BuildingTileRooms[p];
                if (overlappingRoom.RoomCorners[Direction.Down].x == edgeTileClusterWithOverlap.StartingPoint.x && overlappingRoom.RoomCorners[Direction.Down].y == edgeTileClusterWithOverlap.StartingPoint.y)
                {
                    roomsStartingOnEdgeTile.Add(overlappingRoom);
                }
            }
        }

        // rooms that have the down corner on along the edge of this room
        for (int i = 0; i < edgeTileClustersWithOverlap.Count; i++)
        {
            BuildingTile tileWithOverlap = edgeTileClustersWithOverlap[i];

            List <WallPiece> wallPiecesAllRooms = new List <WallPiece>();
            for (int k = 0; k < tileWithOverlap.BuildingTileRooms.Count; k++)
            {
                Room otherRoom = tileWithOverlap.BuildingTileRooms[k];
                wallPiecesAllRooms.AddRange(Room.GetWallpiecesByAnyBuildingTile(tileWithOverlap.StartingPoint, otherRoom));
            }
            List <WallPiece> activeWallPiecesFromThisRoom = wallPiecesAllRooms.Where(wallPiece => wallPiece.Room.Id == room.Id).ToList();
            if (activeWallPiecesFromThisRoom.Count == 0)
            {
                continue;
            }

            for (int j = 0; j < activeWallPiecesFromThisRoom.Count; j++)
            {
                WallPiece activeWallPiece = activeWallPiecesFromThisRoom[j];

                if (activeWallPiece.WallPieceType == WallPieceType.UpLeft || activeWallPiece.WallPieceType == WallPieceType.DownLeft) // UpLeft for continuing wall parts, DownLeft at the bottom corner
                {
                    if (activeWallPiece.transform.position.x == 0)
                    {
                        Logger.Log("For this tile at {0},{1} the type is {2}", activeWallPiece.transform.position.x, activeWallPiece.transform.position.y, activeWallPiece.WallPieceType);
                        Logger.Log("This room downside is {0},{1}, with the id {2}", room.RoomCorners[Direction.Down].x, room.RoomCorners[Direction.Down].y, room.Id);
                    }

                    List <WallPiece> oppositeWallPieces = wallPiecesAllRooms.Where(wallPiece => wallPiece.WallPieceType == WallPieceType.DownRight).ToList();

                    for (int k = 0; k < oppositeWallPieces.Count; k++)
                    {
                        WallPiece oppositeWallPiece = oppositeWallPieces[k];
                        if (activeWallPiece.transform.position.x == 0)
                        {
                            Logger.Log("oppositeWallPiece at {0},{1} the type is {2}", oppositeWallPiece.transform.position.x, oppositeWallPiece.transform.position.y, oppositeWallPiece.WallPieceType);
                        }
                        // only if not corner piece
                        if (!wallPiecesAllRooms.Any(wallPiece => wallPiece.WallPieceType == WallPieceType.UpRight && wallPiece.Room.Id != room.Id))
                        {
                            oppositeWallPiece.gameObject.SetActive(true);
                            if (oppositeWallPiece.Room.CharactersInRoom.Count > 0)
                            {
                                oppositeWallPiece.SetWallSprite(WallPieceDisplayMode.Transparent);
                            }
                        }

                        oppositeWallPiece.Room.WallPieces.Where(
                            wallPiece => wallPiece.WallPieceType == WallPieceType.DownRight &&
                            wallPiece.transform.position.x == tileWithOverlap.StartingPoint.x + 5 &&
                            wallPiece.transform.position.y == tileWithOverlap.StartingPoint.y + 2.5f &&
                            room.WallPieces.Any(wallPieceThisRoom =>
                                                wallPieceThisRoom.transform.position.x == tileWithOverlap.StartingPoint.x + 5 &&
                                                wallPieceThisRoom.transform.position.y == tileWithOverlap.StartingPoint.y + 2.5f))
                        .ToList()
                        .ForEach(wallPiece => {
                            wallPiece.gameObject.SetActive(true);
                            if (wallPiece.Room.CharactersInRoom.Count > 0)
                            {
                                wallPiece.SetWallSprite(WallPieceDisplayMode.Transparent);
                            }
                        });
                        oppositeWallPiece.Room.WallPieces.Where(
                            wallPiece => wallPiece.WallPieceType == WallPieceType.DownRight &&
                            wallPiece.transform.position.x == tileWithOverlap.StartingPoint.x + 10 &&
                            wallPiece.transform.position.y == tileWithOverlap.StartingPoint.y + 5f &&
                            room.WallPieces.Any(wallPieceThisRoom =>
                                                wallPieceThisRoom.transform.position.x == tileWithOverlap.StartingPoint.x + 10 &&
                                                wallPieceThisRoom.transform.position.y == tileWithOverlap.StartingPoint.y + 5f))
                        .ToList()
                        .ForEach(wallPiece => {
                            wallPiece.gameObject.SetActive(true);
                            if (wallPiece.Room.CharactersInRoom.Count > 0)
                            {
                                wallPiece.SetWallSprite(WallPieceDisplayMode.Transparent);
                            }
                        });
                    }

                    //for dealing with corners
                    for (int l = 0; l < roomsStartingOnEdgeTile.Count; l++)
                    {
                        Room    roomStartingOnEdgeTile         = roomsStartingOnEdgeTile[l];
                        Vector2 roomStartingOnEdgeTileLocation = roomStartingOnEdgeTile.RoomCorners[Direction.Down];
                        // check if there is a wallpiece intersecting the corner
                        if (activeWallPiece.transform.position.x == roomStartingOnEdgeTileLocation.x &&
                            activeWallPiece.transform.position.y == roomStartingOnEdgeTileLocation.y &&
                            (activeWallPiece.transform.position.x != room.RoomCorners[Direction.Up].x &&
                             activeWallPiece.transform.position.y != room.RoomCorners[Direction.Up].y))
                        {
                            for (int n = 0; n < roomStartingOnEdgeTile.WallPieces.Count; n++)
                            {
                                WallPiece wallPiece = roomStartingOnEdgeTile.WallPieces[n];
                                if ((wallPiece.transform.position.x == roomStartingOnEdgeTileLocation.x + 5 &&
                                     wallPiece.transform.position.y == roomStartingOnEdgeTileLocation.y + 2.5f) ||
                                    (wallPiece.transform.position.x == roomStartingOnEdgeTileLocation.x + 10 &&
                                     wallPiece.transform.position.y == roomStartingOnEdgeTileLocation.y + 5f))
                                {
                                    wallPiece.gameObject.SetActive(true);
                                    if (wallPiece.Room.CharactersInRoom.Count > 0)
                                    {
                                        wallPiece.SetWallSprite(WallPieceDisplayMode.Transparent);
                                    }
                                }
                            }
                            Logger.Log("There is something on the corner");
                        }
                    }
                }
                if (activeWallPiece.WallPieceType == WallPieceType.UpRight)
                {
                    List <WallPiece> oppositeWallPieces = wallPiecesAllRooms.Where(wallPiece => wallPiece.WallPieceType == WallPieceType.DownLeft).ToList();

                    for (int k = 0; k < oppositeWallPieces.Count; k++)
                    {
                        WallPiece oppositeWallPiece = oppositeWallPieces[k];

                        oppositeWallPiece.gameObject.SetActive(true);

                        if (oppositeWallPiece.Room.CharactersInRoom.Count > 0)
                        {
                            oppositeWallPiece.SetWallSprite(WallPieceDisplayMode.Transparent);
                        }

                        oppositeWallPiece.Room.WallPieces.Where(
                            wallPiece => wallPiece.WallPieceType == WallPieceType.DownLeft &&
                            wallPiece.transform.position.x == tileWithOverlap.StartingPoint.x + 5 &&
                            wallPiece.transform.position.y == tileWithOverlap.StartingPoint.y - 2.5f
                            )
                        .ToList()
                        .ForEach(wallPiece => {
                            wallPiece.gameObject.SetActive(true);
                            if (wallPiece.Room.CharactersInRoom.Count > 0)
                            {
                                wallPiece.SetWallSprite(WallPieceDisplayMode.Transparent);
                            }
                        });
                        oppositeWallPiece.Room.WallPieces.Where(
                            wallPiece => wallPiece.WallPieceType == WallPieceType.DownLeft &&
                            wallPiece.transform.position.x == tileWithOverlap.StartingPoint.x + 10 &&
                            wallPiece.transform.position.y == tileWithOverlap.StartingPoint.y - 5f
                            )
                        .ToList()
                        .ForEach(wallPiece => {
                            wallPiece.gameObject.SetActive(true);
                            if (wallPiece.Room.CharactersInRoom.Count > 0)
                            {
                                wallPiece.SetWallSprite(WallPieceDisplayMode.Transparent);
                            }
                        });
                    }
                }
            }
        }
    }
    // this room is the room that is left
    public static void RaiseWallPieces(Room room)
    {
        List <BuildingTile> edgeTileClustersWithOverlap = room.RoomEdgeTilesPerCluster.Where(tile => tile.BuildingTileRooms.Count > 1).ToList();

        for (int i = 0; i < room.WallPieces.Count; i++)
        {
            WallPiece wallPiece = room.WallPieces[i];
            if (wallPiece.WallPieceType == WallPieceType.DownLeft || wallPiece.WallPieceType == WallPieceType.DownRight)
            {
                if (wallPiece.gameObject.activeSelf)
                {
                    wallPiece.SetWallSprite(WallPieceDisplayMode.Visible);
                }
                else
                {
                    //find the corresponding wall piece in the other room and activate that
                    List <WallPiece> overlappingOtherRoomWallPieces = new List <WallPiece>();
                    for (int j = 0; j < room.AdjacentRooms.Count; j++)
                    {
                        overlappingOtherRoomWallPieces.AddRange(room.AdjacentRooms[j].WallPieces.Where(otherWallPiece => otherWallPiece.transform.position == wallPiece.transform.position).ToList());
                    }
                    for (int k = 0; k < overlappingOtherRoomWallPieces.Count; k++)
                    {
                        WallPiece overlappingOtherRoomWallPiece = overlappingOtherRoomWallPieces[k];
                        if (wallPiece.transform.position.x == 30 && wallPiece.transform.position.y == 0)
                        {
                            Logger.Log("RAISE wall pieces for {0}, {1}", wallPiece.transform.position.x, wallPiece.transform.position.y);
                            Logger.Log("wallPiece type {0}", wallPiece.WallPieceType);
                            Logger.Log("overlappingOtherRoomWallPiece type {0}", overlappingOtherRoomWallPiece.WallPieceType);
                        }
                        if (overlappingOtherRoomWallPiece.gameObject.activeSelf)
                        {
                            if (wallPiece.WallPieceType == WallPieceType.DownLeft)
                            {
                                if (overlappingOtherRoomWallPiece.WallPieceType == WallPieceType.UpLeft)
                                {
                                    if (overlappingOtherRoomWallPiece.Room.CharactersInRoom.Count > 0)
                                    {
                                        continue;
                                    }
                                    WallPiece downRightWallPiece = overlappingOtherRoomWallPieces.FirstOrDefault(overlappingWallPiece => overlappingWallPiece.WallPieceType == WallPieceType.DownRight);
                                    if (downRightWallPiece && downRightWallPiece.Room.CharactersInRoom.Count > 0)
                                    {
                                        continue;
                                    }
                                }
                            }
                            if (wallPiece.WallPieceType == WallPieceType.DownRight)
                            {
                                if (overlappingOtherRoomWallPiece.WallPieceType == WallPieceType.UpRight)
                                {
                                    if (overlappingOtherRoomWallPiece.Room.CharactersInRoom.Count > 0)
                                    {
                                        continue;
                                    }
                                    WallPiece downLeftWallPiece = overlappingOtherRoomWallPieces.FirstOrDefault(overlappingWallPiece => overlappingWallPiece.WallPieceType == WallPieceType.DownLeft);
                                    if (downLeftWallPiece && downLeftWallPiece.Room.CharactersInRoom.Count > 0)
                                    {
                                        continue;
                                    }
                                }
                            }
                            overlappingOtherRoomWallPiece.SetWallSprite(WallPieceDisplayMode.Visible);
                        }
                    }
                }
            }

            List <BuildingTile> overlappingTileClusters = edgeTileClustersWithOverlap.Where(edgeTile => (edgeTile.StartingPoint == new Vector2(wallPiece.transform.position.x, wallPiece.transform.position.y))).ToList();

            if (overlappingTileClusters.Count == 0)
            {
                continue;
            }

            BuildingTile overlappingTile = overlappingTileClusters[0]; // take any tile, because the starting positions should be the same

            List <WallPiece> overlappingWallPieces = new List <WallPiece>();
            for (int k = 0; k < overlappingTile.BuildingTileRooms.Count; k++)
            {
                Room otherRoom = overlappingTile.BuildingTileRooms[k];
                if (otherRoom == room)
                {
                    continue;
                }
                overlappingWallPieces.AddRange(Room.GetWallpiecesByAnyBuildingTile(overlappingTile.StartingPoint, otherRoom));
            }

            for (int j = 0; j < overlappingWallPieces.Count; j++)
            {
                WallPiece overlappingWallPiece = overlappingWallPieces[j];
                if (overlappingWallPiece == wallPiece)
                {
                    continue;
                }

                // it is a corner, intersecting downleft in a corner to the right
                if (wallPiece.WallPieceType == WallPieceType.DownLeft)
                {
                    //Logger.Warning("we found the common tile!!  {0},{1}. Make it visible DownLeft", wallPiece.transform.position.x, wallPiece.transform.position.y);
                    if ((overlappingWallPiece.WallPieceType == WallPieceType.DownRight) &&
                        overlappingWallPiece.Room.CharactersInRoom.Count == 0
                        )
                    {
                        //get wall pieces from 1 tile up right. Check if there is a DownRight wallpiece which more than 1 person in the room. If so, continuel
                        Room corneringRoom = RoomManager.Rooms.FirstOrDefault(r => r.RoomCorners[Direction.Down].x == wallPiece.transform.position.x && r.RoomCorners[Direction.Down].y == wallPiece.transform.position.y);
                        if (corneringRoom && corneringRoom.CharactersInRoom.Count > 0)
                        {
                            continue;
                        }

                        RaiseWallPiece(new Vector2(wallPiece.transform.position.x + 5, wallPiece.transform.position.y + 2.5f), room);
                        RaiseWallPiece(new Vector2(wallPiece.transform.position.x + 10, wallPiece.transform.position.y + 5f), room);
                    }
                }
                if (wallPiece.WallPieceType == WallPieceType.UpLeft)
                {
                    if ((overlappingWallPiece.WallPieceType == WallPieceType.DownRight) &&
                        overlappingWallPiece.Room.CharactersInRoom.Count == 0
                        )
                    {
                        WallPiece downRightWallPiece = overlappingWallPieces.FirstOrDefault(
                            w => w.WallPieceType == WallPieceType.DownRight &&
                            w.Room.Id != overlappingWallPiece.Room.Id);
                        if (downRightWallPiece && downRightWallPiece.Room.CharactersInRoom.Count > 0)
                        {
                            continue;
                        }

                        Room corneringRoom = RoomManager.Rooms.FirstOrDefault(r => r.RoomCorners[Direction.Down].x == wallPiece.transform.position.x && r.RoomCorners[Direction.Down].y == wallPiece.transform.position.y);
                        if (corneringRoom && corneringRoom.CharactersInRoom.Count > 0)
                        {
                            continue;
                        }

                        wallPiece.SetWallSprite(WallPieceDisplayMode.Visible);
                        RaiseWallPiece(new Vector2(wallPiece.transform.position.x + 5, wallPiece.transform.position.y + 2.5f), room);
                        RaiseWallPiece(new Vector2(wallPiece.transform.position.x + 10, wallPiece.transform.position.y + 5f), room);

                        //if there is no cornering piece of type UpRight at same location
                        if (!room.WallPieces.Any(piece => piece.transform.position == wallPiece.transform.position && piece.WallPieceType == WallPieceType.UpRight))
                        {
                            RaiseWallPiece(new Vector2(wallPiece.transform.position.x + 5, wallPiece.transform.position.y - 2.5f), room);
                            RaiseWallPiece(new Vector2(wallPiece.transform.position.x + 10, wallPiece.transform.position.y - 5f), room);
                        }
                    }
                }
            }
        }
    }
예제 #18
0
    // Make tiles available again for building
    public void CleanUpDeletedRoomTiles()
    {
        List <BuildingTile> roomLargerSquareTiles = BuilderManager.Instance.BuildingTiles.FindAll(tile =>
                                                                                                  tile.StartingPoint.x >= RoomCorners[Direction.Left].x - 15 &&
                                                                                                  tile.StartingPoint.x <= RoomCorners[Direction.Right].x + 15 &&
                                                                                                  tile.StartingPoint.y <= RoomCorners[Direction.Up].y + 10 &&
                                                                                                  tile.StartingPoint.y >= RoomCorners[Direction.Down].y - 10
                                                                                                  );

        List <BuildingTile> roomSquareTiles = roomLargerSquareTiles.FindAll(tile =>
                                                                            tile.StartingPoint.x >= RoomCorners[Direction.Left].x &&
                                                                            tile.StartingPoint.x <= RoomCorners[Direction.Right].x &&
                                                                            tile.StartingPoint.y <= RoomCorners[Direction.Up].y &&
                                                                            tile.StartingPoint.y >= RoomCorners[Direction.Down].y
                                                                            );

        int rightUpAxisLength = GetRightUpAxisLengthForRoomRotation();
        int leftUpAxisLength  = GetLeftUpAxisLengthForRoomRotation();

        for (int i = 0; i <= rightUpAxisLength; i += 3)
        {
            List <BuildingTile> tilesThatIncludeDeletedRoom = new List <BuildingTile>(); // all tiles that the deleted room was built on
            for (int j = leftUpAxisLength; j >= 0; j -= 3)
            {
                Vector2      location = GridHelper.GridToVectorLocation(RoomCorners[Direction.Down], i, -j);
                BuildingTile tile     = roomSquareTiles.FirstOrDefault(t => t.StartingPoint == location);
                if (tile.BuildingTileRooms.Count == 1)
                {
                    if (tile.BuildingTileRooms[0].Id == Id) // check if this room is part of the found tile
                    {
                        tile.IsAvailable = Availability.Available;
                        tilesThatIncludeDeletedRoom.Add(tile);
                    }
                }
                else if (tile.BuildingTileRooms.Count > 1)
                {
                    for (int p = 0; p < tile.BuildingTileRooms.Count; p++)
                    {
                        if (tile.BuildingTileRooms[p].Id == Id)  // check if this room is part of the found tile
                        {
                            tilesThatIncludeDeletedRoom.Add(tile);

                            // complicated if statements to make sure the edges of remaining rooms get the correct availability status
                            if (tile.BuildingTileRooms.Count == 2 &&
                                (i == 0 || j == 0))
                            {
                                if (i == rightUpAxisLength)
                                {
                                    Vector2      location1 = GridHelper.GridToVectorLocation(RoomCorners[Direction.Down], i, -j - 3);
                                    BuildingTile tile1     = roomLargerSquareTiles.FirstOrDefault(t => t.StartingPoint == location);
                                    Vector2      location2 = GridHelper.GridToVectorLocation(RoomCorners[Direction.Down], i, -j + 3);
                                    BuildingTile tile2     = roomLargerSquareTiles.FirstOrDefault(t => t.StartingPoint == location);

                                    if (tile1.IsAvailable != Availability.Unavailable && tile2.IsAvailable != Availability.Unavailable)
                                    {
                                        tile.IsAvailable = Availability.UpperEdge;
                                    }
                                }
                                else if (j == leftUpAxisLength)
                                {
                                    Vector2      location1 = GridHelper.GridToVectorLocation(RoomCorners[Direction.Down], i - 3, -j);
                                    BuildingTile tile1     = roomLargerSquareTiles.FirstOrDefault(t => t.StartingPoint == location);
                                    Vector2      location2 = GridHelper.GridToVectorLocation(RoomCorners[Direction.Down], i + 3, -j);
                                    BuildingTile tile2     = roomLargerSquareTiles.FirstOrDefault(t => t.StartingPoint == location);

                                    if (tile1.IsAvailable != Availability.Unavailable && tile2.IsAvailable != Availability.Unavailable)
                                    {
                                        tile.IsAvailable = Availability.UpperEdge;
                                    }
                                }
                                else
                                {
                                    tile.IsAvailable = Availability.UpperEdge;
                                }
                            }
                            else if (tile.BuildingTileRooms.Count == 3 &&
                                     (i == 0 || j == 0))
                            {
                                if (i > 0)
                                {
                                    Vector2      location1 = GridHelper.GridToVectorLocation(RoomCorners[Direction.Down], i, -j + 3);
                                    BuildingTile tile1     = roomLargerSquareTiles.FirstOrDefault(t => t.StartingPoint == location1);
                                    Vector2      location2 = GridHelper.GridToVectorLocation(RoomCorners[Direction.Down], i, -j - 3);
                                    BuildingTile tile2     = roomLargerSquareTiles.FirstOrDefault(t => t.StartingPoint == location2);

                                    if (tile1 == null)
                                    {
                                        Logger.Error("Error during tile clean up. Tried to find tile at location {0},{1}", location1.x, location1.y);
                                    }
                                    if (tile2 == null)
                                    {
                                        Logger.Error("Error during tile clean up. Tried to find tile at location {0},{1}", location2.x, location2.y);
                                    }

                                    if (tile1.IsAvailable != Availability.Available && tile2.BuildingTileRooms.Count == 1)
                                    {
                                        tile.IsAvailable = Availability.UpperEdge;
                                    }
                                }
                                else if (j > 0)
                                {
                                    Vector2      location1 = GridHelper.GridToVectorLocation(RoomCorners[Direction.Down], i - 3, -j);
                                    BuildingTile tile1     = roomLargerSquareTiles.FirstOrDefault(t => t.StartingPoint == location1);
                                    Vector2      location2 = GridHelper.GridToVectorLocation(RoomCorners[Direction.Down], i + 3, -j);
                                    BuildingTile tile2     = roomLargerSquareTiles.FirstOrDefault(t => t.StartingPoint == location2);

                                    if (tile1 == null)
                                    {
                                        Logger.Error("Error during tile clean up. Tried to find tile at location {0},{1}", location1.x, location1.y);
                                    }
                                    if (tile2 == null)
                                    {
                                        Logger.Error("Error during tile clean up. Tried to find tile at location {0},{1}", location2.x, location2.y);
                                    }

                                    if (tile1.IsAvailable != Availability.Available && tile2.BuildingTileRooms.Count == 1)
                                    {
                                        tile.IsAvailable = Availability.UpperEdge;
                                    }
                                }
                                else
                                {
                                    tile.IsAvailable = Availability.UpperEdge;
                                }
                            }
                            else if (tile.BuildingTileRooms.Count == 4)
                            {
                                Vector2      location1 = GridHelper.GridToVectorLocation(RoomCorners[Direction.Down], i + 3, -j - 3);
                                BuildingTile tile1     = roomLargerSquareTiles.FirstOrDefault(t => t.StartingPoint == location1);
                                if (leftUpAxisLength == 3 &&
                                    rightUpAxisLength == 3 &&
                                    location == new Vector2(RoomCorners[Direction.Down].x, RoomCorners[Direction.Down].y)
                                    )
                                {
                                    tile.IsAvailable = Availability.UpperEdge;
                                }
                                else if (location == new Vector2(RoomCorners[Direction.Down].x, RoomCorners[Direction.Down].y) &&
                                         tile1.BuildingTileRooms.Count == 1 && tile1.BuildingTileRooms[0].Id == Id)
                                {
                                    tile.IsAvailable = Availability.UpperEdge;
                                }
                            }
                            continue;
                        }
                    }
                }
            }
            for (int k = 0; k < tilesThatIncludeDeletedRoom.Count; k++)
            {
                BuildingTile tile = tilesThatIncludeDeletedRoom[k];
                List <Room>  tempBuildingTileRooms = new List <Room>();

                for (int l = 0; l < tile.BuildingTileRooms.Count; l++)
                {
                    if (tile.BuildingTileRooms[l].Id != Id)
                    {
                        tempBuildingTileRooms.Add(tile.BuildingTileRooms[l]);
                    }
                }
                tile.BuildingTileRooms = tempBuildingTileRooms;
            }
        }
    }
예제 #19
0
    public BuildingTile[,] makeBuildingsFromMaps(GroundTile[,] groundTiles, float[,] urban, HeightColor[] urbanColors, float[,] village, HeightColor[] villageColors)
    {
        BuildingTile[,] buildings = new BuildingTile[groundTiles.GetLength(0), groundTiles.GetLength(1)];
        int buildingCount = 0;

        for (int i = 0; i < groundTiles.GetLength(0); i++)
        {
            for (int c = 0; c < groundTiles.GetLength(1); c++)
            {
                foreach (HeightColor hc in urbanColors)
                {
                    if (urban[c, i] <= hc.terrainHeight)
                    {
                        ///Debug.Log(hc.terrainColor);
                        if (hc.tileID != 0)
                        {
                            buildingCount++;
                            buildings[c, i].tileID = hc.tileID;
                        }
                        else
                        {
                            buildings[c, i].tileID = 0;
                        }
                        break;
                    }
                    else
                    {
                        buildings[c, i].tileID = 0;
                    }
                }

                foreach (HeightColor hc in villageColors)
                {
                    if (village[c, i] <= hc.terrainHeight)
                    {
                        if (hc.tileID == 1)
                        {
                            if (Random.Range(0.0f, 1.0f) >= 0.8f)
                            {
                                buildings[c, i].tileID = 1;
                            }
                        }
                        else if (hc.tileID == 2)
                        {
                            if (Random.Range(0.0f, 1.0f) >= 0.6f)
                            {
                                buildings[c, i].tileID = 1;
                            }
                        }
                        else
                        {
                            buildings[c, i].tileID = 0;
                        }
                        break;
                    }
                    else
                    {
                        buildings[c, i].tileID = 0;
                    }
                }
            }
        }
        Debug.Log(buildingCount);

        return(buildings);
    }
예제 #20
0
    public BuildingTile[,] makeDungeons(GroundTile[,] groundTiles, float[,] urban, HeightColor[] urbanColors)
    {
        BuildingTile[,] buildings = new BuildingTile[groundTiles.GetLength(0), groundTiles.GetLength(1)];

        return(buildings);
    }
예제 #21
0
 public void AssertTileHasValues(BuildingTile tile, int value)
 {
     AssertTileHasValues(tile, value, value);
 }
예제 #22
0
 public void AssertTileHasValues(BuildingTile tile, int minValue, int maxValue)
 {
     Assert.AreEqual(minValue, tile.MinValue);
     Assert.AreEqual(maxValue, tile.MaxValue);
 }