protected virtual void InsertRoom(RoomController cont, Vector2Int position)
    {
        room_origins.Add(position, cont);
        foreach (Vector2Int local_position in cont.room.GetLocalCoordinatesList())
        {
            Room.Section section = cont.room.GetSection(local_position);
            tiles.Add(position + local_position, section);
            available_spaces.Remove(position + local_position);
            adjacent_spaces.Remove(position + local_position);

            UpdateAdjacentSpaces(section, local_position + position);
        }
    }
    protected virtual void ConvertIsland(Vector2Int position)
    {
        Room room = islands[position].room;

        position = islands[position].origin;
        foreach (Vector2Int local_position in room.GetLocalCoordinatesList())
        {
            Room.Section section = room.GetSection(local_position);
            islands.Remove(position + local_position);
            tiles.Add(position + local_position, section);
            adjacent_spaces.Remove(position + local_position);

            UpdateAdjacentSpaces(section, local_position + position);
        }
    }
    protected virtual void InsertIsland(RoomController cont, Vector2Int position)
    {
        room_origins.Add(position, cont);
        bool is_true_island = true;

        foreach (Vector2Int local_position in cont.room.GetLocalCoordinatesList())
        {
            Room.Section section = cont.room.GetSection(local_position);
            islands.Add(position + local_position, new Island(position, cont));
            available_spaces.Remove(position + local_position);
            adjacent_spaces.Remove(position + local_position);

            Vector2Int pos = local_position + position + Vector2Int.down;
            if (section.HasOpenableDoorway(Direction.BOTTOM) && tiles.ContainsKey(pos) && tiles[pos].HasOpenableDoorway(Direction.TOP))
            {
                is_true_island = false;
                break;
            }
            pos = local_position + position + Vector2Int.up;
            if (section.HasOpenableDoorway(Direction.TOP) && tiles.ContainsKey(pos) && tiles[pos].HasOpenableDoorway(Direction.BOTTOM))
            {
                is_true_island = false;
                break;
            }
            pos = local_position + position + Vector2Int.left;
            if (section.HasOpenableDoorway(Direction.LEFT) && tiles.ContainsKey(pos) && tiles[pos].HasOpenableDoorway(Direction.RIGHT))
            {
                is_true_island = false;
                break;
            }
            pos = local_position + position + Vector2Int.right;
            if (section.HasOpenableDoorway(Direction.RIGHT) && tiles.ContainsKey(pos) && tiles[pos].HasOpenableDoorway(Direction.LEFT))
            {
                is_true_island = false;
                break;
            }
        }
        if (!is_true_island)
        {
            ConvertIsland(position);
        }
    }
 protected bool SectionConnects(Room.Section section, Vector2Int position)
 {
     if (section.HasOpenableDoorway(Direction.BOTTOM) && tiles.ContainsKey(position + Vector2Int.down) && tiles[position + Vector2Int.down].HasOpenableDoorway(Direction.TOP))
     {
         return(true);
     }
     if (section.HasOpenableDoorway(Direction.TOP) && tiles.ContainsKey(position + Vector2Int.up) && tiles[position + Vector2Int.up].HasOpenableDoorway(Direction.BOTTOM))
     {
         return(true);
     }
     if (section.HasOpenableDoorway(Direction.LEFT) && tiles.ContainsKey(position + Vector2Int.left) && tiles[position + Vector2Int.left].HasOpenableDoorway(Direction.RIGHT))
     {
         return(true);
     }
     if (section.HasOpenableDoorway(Direction.RIGHT) && tiles.ContainsKey(position + Vector2Int.right) && tiles[position + Vector2Int.right].HasOpenableDoorway(Direction.LEFT))
     {
         return(true);
     }
     return(false);
 }
 void UpdateAdjacentSpaces(Room.Section section, Vector2Int position)
 {
     foreach (Pair <Vector2Int, Direction> pair in position.GetNeighborsWithDirection())
     {
         Vector2Int pos = pair.first;
         if (section.HasOpenableDoorway(pair.second) && !tiles.ContainsKey(pos))
         {
             if (islands.ContainsKey(pos))
             {
                 Island island = islands[pos];
                 if (island.room.HasOpenableDoorway(pos - island.origin, pair.second.Opposite()))
                 {
                     ConvertIsland(islands[pos].origin);
                 }
             }
             else
             {
                 adjacent_spaces.Add(pos);
             }
         }
     }
 }
Beispiel #6
0
 void FindPossibleNeighbors(Vector2Int v)
 {
     Room.Section section = GetSection(v);
     possible_neighbors.Add(section, new List <Room.Section>());
     if (section.HasOpenableDoorway(Direction.BOTTOM) && positions_to_rooms.ContainsKey(v + Vector2Int.down))
     {
         Room.Section neighbor = GetSection(v + Vector2Int.down);
         if (neighbor.HasOpenableDoorway(Direction.TOP))
         {
             possible_neighbors[section].Add(neighbor);
         }
     }
     if (section.HasOpenableDoorway(Direction.TOP) && positions_to_rooms.ContainsKey(v + Vector2Int.up))
     {
         Room.Section neighbor = GetSection(v + Vector2Int.up);
         if (neighbor.HasOpenableDoorway(Direction.BOTTOM))
         {
             possible_neighbors[section].Add(neighbor);
         }
     }
     if (section.HasOpenableDoorway(Direction.LEFT) && positions_to_rooms.ContainsKey(v + Vector2Int.left))
     {
         Room.Section neighbor = GetSection(v + Vector2Int.left);
         if (neighbor.HasOpenableDoorway(Direction.RIGHT))
         {
             possible_neighbors[section].Add(neighbor);
         }
     }
     if (section.HasOpenableDoorway(Direction.RIGHT) && positions_to_rooms.ContainsKey(v + Vector2Int.right))
     {
         Room.Section neighbor = GetSection(v + Vector2Int.right);
         if (neighbor.HasOpenableDoorway(Direction.LEFT))
         {
             possible_neighbors[section].Add(neighbor);
         }
     }
 }