Add a terrible maze generation algorithm to test if a maze style map looks/feels better. The walls are disabled so you can walk around.

This commit is contained in:
Zed A. Shaw 2025-05-18 01:00:47 -04:00
parent 6cbfcf993e
commit 7a0b2f988d
9 changed files with 207 additions and 52 deletions

View file

@ -5,6 +5,7 @@
#include "components.hpp"
#include "inventory.hpp"
#include "rituals.hpp"
#include "maze.hpp"
using namespace fmt;
using namespace components;
@ -103,20 +104,22 @@ void WorldBuilder::stylize_room(int room, string tile_name, float size) {
Point pos_out;
bool placed = $map.place_entity(room, pos_out);
dbc::check(placed, "failed to place style in room");
(void)tile_name;
(void)size;
tile_name = tile_name == "FLOOR_TILE" ? "WALL_PLAIN" : tile_name;
//tile_name = tile_name == "FLOOR_TILE" ? "WALL_PLAIN" : tile_name;
for(matrix::circle it{$map.$walls, pos_out, size}; it.next();) {
for(int x = it.left; x < it.right; x++) {
if($map.iswall(x, it.y)) {
// a wall tile
$map.$tiles.set_tile(x, it.y, tile_name);
} else {
// a floor tile
$map.$tiles.set_tile(x, it.y, "FLOOR_TILE");
}
}
}
//for(matrix::circle it{$map.$walls, pos_out, size}; it.next();) {
// for(int x = it.left; x < it.right; x++) {
// if($map.iswall(x, it.y)) {
// // a wall tile
// $map.$tiles.set_tile(x, it.y, tile_name);
// } else {
// // a floor tile
// $map.$tiles.set_tile(x, it.y, "FLOOR_TILE");
// }
// }
//}
}
void WorldBuilder::generate_rooms() {
@ -134,33 +137,10 @@ void WorldBuilder::generate_rooms() {
}
void WorldBuilder::generate_map() {
generate_rooms();
matrix::dump("BEFORE MAZE:", $map.$walls);
maze::recursive_div($map.$walls, $map.$rooms);
matrix::dump("AFTER MAZE:", $map.$walls);
PointList holes;
for(size_t i = 0; i < $map.$rooms.size() - 1; i++) {
tunnel_doors(holes, $map.$rooms[i], $map.$rooms[i+1]);
}
// one last connection from first room to last
tunnel_doors(holes, $map.$rooms.back(), $map.$rooms.front());
// place all the holes
for(auto hole : holes) {
if(!matrix::inbounds($map.$walls, hole.x, hole.y)) {
matrix::dump("MAP BEFORE CRASH", $map.$walls, hole.x, hole.y);
auto err = fmt::format("invalid hold target {},{} map is only {},{}",
hole.x, hole.y, matrix::width($map.$walls),
matrix::height($map.$walls));
dbc::sentinel(err);
}
$map.$walls[hole.y][hole.x] = INV_SPACE;
}
$map.invert_space();
$map.expand();
$map.load_tiles();