Connecting rooms with halls

I used BSP algorithm to split my map into subsections. Each subsections has 1 room inside.

I cant figure out how to connect all these rooms. Currently i have randomly selected rooms and then hallway made between them, but this creates a problem where there can be 3 or more halls side by side and halls that connect 2 rooms goes through other rooms.

I removed some of the repetition by checking current connections between rooms, but this doesent solve all the problems.(only 1 level deep, if i go deeper i get stack overflow)

http://tinypic.com/r/jhq7tg/8 current output. Some boxes are hard to see because colors are also randomly generated.
Last edited on
Instead of generating halls between two random rooms try to select one room and determine candidates: closest fooms in each cardinal directiron.

Or reject passage in it intersects another room
I found another solution for the problem. But i think i have gotten something wrong.

I wrote a code that just goes over the hallway vector and removes any vector where 2 are next to each other, shorter one will be removed. But now i get unreachable rooms.

I think i have gotten something wrong or some idea wrong.

X1 and Y1 is hte starting point and X2 and Y2 is the ending point of a hall.
If i need a 90degree hall i just crate 2 halls one horisontal, 1 vertical.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
for (std::vector<Hall*>::iterator it = halls.begin(); it != halls.end();){
		for (std::vector<Hall*>::iterator it2 = halls.begin(); it2 != halls.end();){
			bool erase = false;
			if (it != it2){
				if ((*it)->getHeight() != 1 && (*it2)->getHeight() != 1){
					if ((*it)->getX1() + 1 == (*it2)->getX1() || (*it)->getX1() - 1 == (*it2)->getX1()){
						it2 = halls.erase(it2);
						erase = true;
					}
				}
				if ((*it)->getWidth() != 1 || (*it2)->getWidth() != 1){
					if ((*it)->getY1() + 1 == (*it2)->getY1() || (*it)->getY1() - 1 == (*it2)->getY1()){
						it2 = halls.erase(it2);
						erase = true;
					}
					
				}
			}
			if(!erase){
				++it2;
			}
		}
		++it;
	}
Anyone have any ideas?
Topic archived. No new replies allowed.