After lots and lots of dirty hacks and ugly workarounds, I got new partitioner working (and then cleaned to a degree). Now it is possible to have levels, where rooms don’t form uniform grid, but form more interesting shapes.
If you recall from previous blog posts, level generation is split into multiple steps. One of the very first ones is dividing the level into square sections that are randomly linked together. Rooms are then placed within those sections and linked together with corridors. Previously sections formed uniform grid that produced somewhat uninteresting results.
The new routine starts by dividing the level in two sections. The split is done randomly in either horizontal or in vertical line. Resulting two sections are then split into two and this is repeated until they are small enough. After that sections are randomly linked together and level generation proceeds as before.
The routine used to link sections together is simple. First a random section is chosen. Then one of the neighbours that has not been connected is selected and connected to. Same is repeated to the neighbour that we just connected to, thus building a chain of linked sections. When new connection is not possible, we check if there are any sections that have been linked and have unconnected neighbours. If one is found, a new path is built from it, otherwise the routine terminates.
Results are pretty good already. At later time, I’ll add more routines for partitioning level, which hopefully will make environment more interesting.