Working on the dungeon generator code. However, I only ever get one room. Seems to be while comparing a newly created room to all the rooms in the list of rooms to make sure they don't intersect, it's comparing the only room to itself. I have no idea how to fix this. Full function below.
void MakeMap(TCODList<rect*> rooms, character &player)
{
for (int i = 0;i<MAP_WIDTH;i++){
for (int j = 0;j<MAP_HEIGHT;j++)
map[i][j]=tile(true,true);
}
int num_rooms = 0;
int w,h,x,y,new_x,new_y,prev_x,prev_y,hold;
bool failed = false;
for(int i = 0;i<MAX_ROOMS;i++){
w = default->getInt(ROOM_MIN_SIZE,ROOM_MAX_SIZE);
h = default->getInt(ROOM_MIN_SIZE,ROOM_MAX_SIZE);
x = default->getInt(0,MAP_WIDTH-w-1);
y = default->getInt(0,MAP_HEIGHT-h-1);
rect new_room(x,y,w,h);
if (num_rooms!=0){
for(rect **it = rooms.begin(); it != rooms.end(); it++){
if(new_room.Intersect(**it)){
failed = true;
break;
}
}
}
if(failed == false){
CreateRoom(new_room);
new_x=new_room.centre_x;
new_y=new_room.centre_y;
if(num_rooms==0){
player.x=new_x;
player.y=new_y;
}
else{
rect hold = *rooms.peek();
prev_x = hold.centre_x;
prev_y = hold.centre_y;
if(default->getInt(0,1)==1){
CreateHTunnel(prev_x,new_x,prev_y);
CreateVTunnel(prev_y,new_y,new_x);
}
else{
CreateVTunnel(prev_y,new_y,new_x);
CreateHTunnel(prev_x,new_x,prev_y);
}
}
rooms.push(&new_room);
num_rooms++;
}
}
}