Refactored the maze functions to be a builder that can do different things to the maze. Also when I hit p in the game it'll save the map to a file. This was extremely hard for no reason.

This commit is contained in:
Zed A. Shaw 2025-05-21 13:56:53 -04:00
parent 20f03731e5
commit 5f1a453fb4
8 changed files with 270 additions and 254 deletions

View file

@ -11,17 +11,20 @@ using namespace fmt;
using namespace components;
void WorldBuilder::generate_map() {
maze::init($map.$walls);
maze::hunt_and_kill($map.$walls, $map.$rooms, $map.$dead_ends);
maze::randomize_rooms($map.$rooms, $map.$dead_ends);
maze::hunt_and_kill($map.$walls, $map.$rooms, $map.$dead_ends);
maze::Builder maze($map);
size_t x_diff = $map.width() / 4;
size_t y_diff = $map.height() / 4;
maze.divide({x_diff, y_diff}, {$map.width() - x_diff, $map.height() - y_diff});
maze.hunt_and_kill();
dbc::check($map.$dead_ends.size() > 0, "world builder/maze builder made a map with no dead ends.");
$map.expand();
$map.load_tiles();
}
DinkyECS::Entity WorldBuilder::configure_entity_in_map(DinkyECS::World &world, json &entity_data, Point pos_out) {
dbc::log(">>>>>>>>>>> ENTER");
auto item = world.entity();
world.set<Position>(item, {pos_out.x+1, pos_out.y+1});
@ -33,17 +36,14 @@ DinkyECS::Entity WorldBuilder::configure_entity_in_map(DinkyECS::World &world, j
components::configure_entity($components, world, item, entity_data["components"]);
}
dbc::log("<<<<<<<<<<<<< EXIT");
return item;
}
DinkyECS::Entity WorldBuilder::configure_entity_in_room(DinkyECS::World &world, json &entity_data, int in_room) {
Point pos_out;
dbc::log("is it configure_entity_in_map's fault?");
bool placed = $map.place_entity(in_room, pos_out);
dbc::check(placed, "failed to randomly place item in room");
auto entity = configure_entity_in_map(world, entity_data, pos_out);
dbc::log("<<<<<<<<<<<<<<<<<<<<<<<<<<< leaving configure_entity_in_room");
return entity;
}
@ -118,7 +118,6 @@ void WorldBuilder::place_entities(DinkyECS::World &world) {
if(world.has_the<Player>()) {
auto& player = world.get_the<Player>();
Point pos_out;
dbc::log("or is it in place_entities placing the player?");
bool placed = $map.place_entity(0, pos_out);
dbc::check(placed, "failed to randomly place item in room");
world.set<Position>(player.entity, {pos_out.x+1, pos_out.y+1});