way better map/maze debug output.
This commit is contained in:
parent
3394de064c
commit
f304538325
8 changed files with 72 additions and 24 deletions
|
|
@ -18,14 +18,22 @@ namespace matrix {
|
|||
} else {
|
||||
print("{:x}<", cell);
|
||||
}
|
||||
} else if(cell == WALL_PATH_LIMIT) {
|
||||
print("# ");
|
||||
} else if(cell == 0) {
|
||||
print(". ");
|
||||
} else if(cell > 15 && cell < 32) {
|
||||
print("{:x}+", cell - 16);
|
||||
} else if(cell > 31) {
|
||||
} else if(cell == DEAD_END_VALUE) {
|
||||
print("* ");
|
||||
} else if(cell == DOOR_VALUE) {
|
||||
print("¦ ");
|
||||
} else if(cell == 1) {
|
||||
print("▒▒");
|
||||
} else if(cell == ROOM_SPACE_VALUE) {
|
||||
print("\%\%");
|
||||
} else if(cell == WALL_PATH_LIMIT) {
|
||||
print("■■");
|
||||
} else if(cell == 0) {
|
||||
print(" ");
|
||||
} else if(cell > 15 && cell < 32) {
|
||||
print("{:X} ", cell - 16);
|
||||
} else if(cell > 31) {
|
||||
print("..");
|
||||
} else {
|
||||
print("{:x} ", cell);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "algos/rand.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "algos/maze.hpp"
|
||||
#include <ranges>
|
||||
#include <algorithm>
|
||||
|
||||
using std::string;
|
||||
using matrix::Matrix;
|
||||
|
|
@ -111,11 +111,30 @@ namespace maze {
|
|||
return true;
|
||||
}
|
||||
|
||||
inline size_t room_sweetspot(size_t width, size_t room_size) {
|
||||
if(width < 20) {
|
||||
return 4;
|
||||
} else if(width < 30) {
|
||||
return (width / room_size / 2);
|
||||
} if(width < 50) {
|
||||
return width / room_size;
|
||||
} else {
|
||||
return width / 2;
|
||||
}
|
||||
}
|
||||
|
||||
void Builder::randomize_rooms(size_t room_size) {
|
||||
std::shuffle($dead_ends.begin(), $dead_ends.end(), Random::GENERATOR);
|
||||
|
||||
size_t max_rooms = room_sweetspot($width, room_size);
|
||||
|
||||
// use those dead ends to randomly place rooms
|
||||
for(auto at : $dead_ends) {
|
||||
// skip 50% of them
|
||||
if(Random::uniform(0,1) == 0) continue;
|
||||
// if(Random::uniform(0,1) == 0) continue;
|
||||
|
||||
// quit after we've hit the room max threshold
|
||||
if($rooms.size() > max_rooms) break;
|
||||
|
||||
// get the room corners randomized
|
||||
std::array<Point, 4> starts{{
|
||||
|
|
@ -125,7 +144,6 @@ namespace maze {
|
|||
{at.x, at.y - room_size + 1} // bottom left
|
||||
}};
|
||||
|
||||
|
||||
size_t offset = Random::uniform(0, 3);
|
||||
|
||||
// BUG: this still accidentally merges rooms
|
||||
|
|
@ -221,7 +239,7 @@ namespace maze {
|
|||
}
|
||||
}
|
||||
|
||||
void Builder::dump(const std::string& msg) {
|
||||
void Builder::dump(const std::string& msg, bool path_too) {
|
||||
auto wall_copy = $walls;
|
||||
|
||||
// mark the rooms too
|
||||
|
|
@ -230,7 +248,7 @@ namespace maze {
|
|||
it.next();)
|
||||
{
|
||||
if(wall_copy[it.y][it.x] == 0 && wall_copy[it.y][it.x] != 3) {
|
||||
wall_copy[it.y][it.x] = WALL_PATH_LIMIT;
|
||||
wall_copy[it.y][it.x] = ROOM_SPACE_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -238,11 +256,19 @@ namespace maze {
|
|||
// mark dead ends
|
||||
for(auto at : $dead_ends) {
|
||||
// don't mark dead ends if there's something else there
|
||||
wall_copy[at.y][at.x] = 32;
|
||||
wall_copy[at.y][at.x] = DEAD_END_VALUE;
|
||||
}
|
||||
|
||||
for(auto [at, _] : $doors) {
|
||||
wall_copy[at.y][at.x] = 0xd;
|
||||
wall_copy[at.y][at.x] = DOOR_VALUE;
|
||||
}
|
||||
|
||||
if(path_too) {
|
||||
for(matrix::each_cell it{wall_copy}; it.next();) {
|
||||
if(wall_copy[it.y][it.x] == SPACE_VALUE) {
|
||||
wall_copy[it.y][it.x] = $paths.$paths[it.y][it.x];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matrix::dump(msg, wall_copy);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "algos/matrix.hpp"
|
||||
#include "game/map.hpp"
|
||||
#include "algos/pathing.hpp"
|
||||
#include <functional>
|
||||
|
||||
namespace maze {
|
||||
|
|
@ -36,7 +37,7 @@ namespace maze {
|
|||
void inner_box(size_t outer_size, size_t inner_size);
|
||||
void divide(Point start, Point end);
|
||||
void remove_dead_ends();
|
||||
void dump(const std::string& msg);
|
||||
void dump(const std::string& msg, bool path_too=false);
|
||||
void open_box(size_t outer_size);
|
||||
void add_dead_end(Point at);
|
||||
bool room_should_exist(Room& room, bool allow_dupes=false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue