On a tile based strategy game I'm working on the player may select an area in which a room is placed. To do so the player selects the tiles. Either by clicking on each individual tile or dragging from one point to another. An algorithm kicks in and decides how and where the pre-made tiles should be placed. My concern is getting this algorithm working for more complex shapes than a single rectangle.
My first approach was to check whether or not the tiles around each selected tile is selected. Using this "signature" the algorithm chooses what tile matches that description and places it accordingly. With this setup I would need 7 models:
- floor tile
- tile with single wall & floor
- tile with two walls (placed opposite of eachother) & floor
- tile with three walls & floor
- tile with four walls & floor
- corner tile & floor
- "cap" for inverted corners (as shown in blue below)
This seems like a viable option without too much work for the modellers. I have however had some problems recognising the tiles where an cap should be placed. And for situations as shown on the right-hand room would require a near endless combination of caps and walls.
A solution to discard the caps would be to make walls with a 45 degree cut on the end. This way there would be a lot more flexibility in placing the tiles and it would allow for special cases found in T-junctions. I believe the current pattern recognition algorithm would not suffice here. In order for it to work I think each tile had to check what kind of tile is around it, not only whether or not it's selected. I fear that this option would require too much computing power as the surrounding tiles may change recursively.
Any help, tip or solution is greatly appreciated.