Jank thoughts on using the dijk map to walk from door to door for tunnels.

This commit is contained in:
Zed A. Shaw 2024-09-28 18:15:00 -04:00
parent b100950877
commit a82944f55a
3 changed files with 49 additions and 33 deletions

33
map.cpp
View file

@ -42,7 +42,7 @@ inline void add_neighbors(PairList &neighbors, Matrix &closed, size_t j, size_t
}
Map::Map(size_t width, size_t height) : m_limit(1000) {
m_walls = Matrix(height, MatrixRow(width, 1));
m_walls = Matrix(height, MatrixRow(width, 0));
m_input_map = Matrix(height, MatrixRow(width, 1));
}
@ -94,7 +94,6 @@ void Map::make_paths() {
}
void Map::make_room(size_t origin_x, size_t origin_y, size_t w, size_t h) {
println("MAKE ROOM x={}, y={}, w={}, h={}", origin_x, origin_y, w, h);
dbc::pre("x out of bounds", origin_x < width());
dbc::pre("y out of bounds", origin_y < height());
dbc::pre("w out of bounds", w <= width());
@ -104,7 +103,7 @@ void Map::make_room(size_t origin_x, size_t origin_y, size_t w, size_t h) {
dbc::check(y < m_walls.size(), "y is out of bounds");
for(size_t x = origin_x; x < origin_x + w; ++x) {
dbc::check(x < m_walls[y].size(), "x is out of bounds");
m_walls[y][x] = 0;
m_walls[y][x] = 1;
}
}
}
@ -121,7 +120,6 @@ inline int make_split(Room &cur, bool horiz) {
}
void Map::partition_map(Room &cur, int depth) {
if(cur.width >= 5 && cur.width <= 10 &&
cur.height >= 5 && cur.height <= 10) {
m_rooms.push_back(cur);
@ -158,9 +156,12 @@ void Map::partition_map(Room &cur, int depth) {
}
}
void Map::draw_map(Room &cur) {
for(auto cur : m_rooms) {
make_room(cur.x+1, cur.y+1, cur.width-2, cur.height-2);
void Map::place_rooms(Room &cur) {
for(auto &cur : m_rooms) {
make_room(cur.x+1, cur.y+1, cur.width-2, cur.height-2);
cur.door_x = cur.x+1;
cur.door_y = cur.y;
m_input_map[cur.door_y][cur.door_x] = 0;
}
}
@ -172,8 +173,22 @@ void Map::generate() {
.height = height()
};
partition_map(root, 6);
draw_map(root); // left
partition_map(root, 10);
place_rooms(root);
make_paths();
Room &room0 = m_rooms[0];
Room &room1 = m_rooms[1];
int cur = m_paths[room0.door_y][room0.door_x];
int next = m_paths[room0.door_y][room0.door_x+1];
int i = 1;
while(next >= cur) {
cur = next;
next = m_paths[room0.door_y][room0.door_x+i];
++i;
println("door_y: {}, door_x: {}, CUR: {}, NEXT: {}", room0.door_y, room0.door_x, cur, next);
}
}