|
|
@ -179,7 +179,12 @@ bool Map::neighbors(Point &out, bool greater) { |
|
|
|
|
|
|
|
|
|
|
|
int zero_i = -1; |
|
|
|
int zero_i = -1; |
|
|
|
int cur = m_paths[out.y][out.x]; |
|
|
|
int cur = m_paths[out.y][out.x]; |
|
|
|
dbc::check(cur != 1000, "WRONG! start point is in a wall"); |
|
|
|
|
|
|
|
|
|
|
|
if(cur == 1000) { |
|
|
|
|
|
|
|
// BUG: sometimes the generation clips a door and we
|
|
|
|
|
|
|
|
// start in a wall
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 4; ++i) { |
|
|
|
for(int i = 0; i < 4; ++i) { |
|
|
|
Point dir = dirs[i]; |
|
|
|
Point dir = dirs[i]; |
|
|
@ -210,11 +215,36 @@ void Map::set_door(Room &room, int value) { |
|
|
|
m_walls[room.exit.y][room.exit.x] = value; |
|
|
|
m_walls[room.exit.y][room.exit.x] = value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void rand_side(Room &room, Point &door) { |
|
|
|
|
|
|
|
std::uniform_int_distribution<int> rand_side(0, 3); |
|
|
|
|
|
|
|
std::uniform_int_distribution<int> rand_x(0, room.width - 1); |
|
|
|
|
|
|
|
std::uniform_int_distribution<int> rand_y(0, room.height - 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(rand_side(g_generator)) { |
|
|
|
|
|
|
|
case 0: // north
|
|
|
|
|
|
|
|
door.x = room.x + rand_x(g_generator); |
|
|
|
|
|
|
|
door.y = room.y-1; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 1: // south
|
|
|
|
|
|
|
|
door.x = room.x + rand_x(g_generator); |
|
|
|
|
|
|
|
door.y = room.y + room.height; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 2: // east
|
|
|
|
|
|
|
|
door.x = room.x + room.width; |
|
|
|
|
|
|
|
door.y = room.y + rand_y(g_generator); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 3: // west
|
|
|
|
|
|
|
|
door.x = room.x - 1; |
|
|
|
|
|
|
|
door.y = room.y + rand_y(g_generator); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
dbc::sentinel("impossible side"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Map::add_door(Room &room) { |
|
|
|
void Map::add_door(Room &room) { |
|
|
|
room.entry.x = room.x; |
|
|
|
rand_side(room, room.entry); |
|
|
|
room.entry.y = room.y-1; |
|
|
|
rand_side(room, room.exit); |
|
|
|
room.exit.x = room.x + room.width - 1; |
|
|
|
|
|
|
|
room.exit.y = room.y + room.height; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Map::walk(Point &src, Point &target) { |
|
|
|
bool Map::walk(Point &src, Point &target) { |
|
|
@ -231,10 +261,8 @@ bool Map::walk(Point &src, Point &target) { |
|
|
|
"target room has a wall at entry door"); |
|
|
|
"target room has a wall at entry door"); |
|
|
|
|
|
|
|
|
|
|
|
make_paths(); |
|
|
|
make_paths(); |
|
|
|
|
|
|
|
|
|
|
|
bool found = false; |
|
|
|
bool found = false; |
|
|
|
Point out{src.x, src.y}; |
|
|
|
Point out{src.x, src.y}; |
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
do { |
|
|
|
m_walls[out.y][out.x] = INV_SPACE; |
|
|
|
m_walls[out.y][out.x] = INV_SPACE; |
|
|
|
found = neighbors(out, true); |
|
|
|
found = neighbors(out, true); |
|
|
|