I'm trying to create a game with a fixed size map (2D Tile array). I suppose I can inherit other tiles from this base Tile, e.g.: a BankTile. Placing and removing tiles is all too easy, but forming rooms keeps me puzzled.
- Rooms can only be formed by adjacent tiles (4-way: above, below, left and right)
This way, 2 tiles can form a 'room', e.g. a Bank with a maximum amount of resources it can hold (sum of both its tiles).
I am wondering on how I should be implementing this, if there are any existing (and optimal) solutions to this.
Some things I considered:
Tiles must keep a reference to the Room they are in AND rooms must keep a vector of all tiles they hold. So adding tiles and removing tiles becomes pretty efficient. Only obstacle this poses is the splitting of rooms: if 1 tile connects 2 rooms and this tile is removed, it should split the room and creating a new room for the split-off part.
Rooms will be 2D vectors with a begin-position (the room will be a surrounding square of the actual room polygon)
Rooms are 4-way linked lists of tiles
?
What needs to be done with rooms:
- tiles need to be added and removed
- allowing rooms to merge and split
- calculating size of a room
- finding a room quickly on a map
This image clarifies what I need:
Should I pick data structure 1? Rooms are 2D arrays with null-pointers for not-room-tiles. Or should I pick data structure 2? Rooms are 4-way linked lists of tiles. Or should I think of something else, e.g. vector of tiles = room? Given the operations I need to be able to perform on them, which is best?