Fixed a problem in the world builder after a refactor then made it do less random paths.
This commit is contained in:
parent
128fc4f540
commit
80ef052e15
2 changed files with 25 additions and 34 deletions
|
@ -95,17 +95,6 @@ void WorldBuilder::update_door(Point &at, int wall_or_space) {
|
||||||
$map.$walls[at.y][at.x] = wall_or_space;
|
$map.$walls[at.y][at.x] = wall_or_space;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldBuilder::tunnel_doors(PointList &holes, Room &src, Room &target) {
|
|
||||||
$map.set_target(target.entry);
|
|
||||||
$map.make_paths();
|
|
||||||
|
|
||||||
bool found = dig_tunnel(holes, src.exit, target.entry);
|
|
||||||
dbc::check(found, "room should always be found");
|
|
||||||
|
|
||||||
$map.INVARIANT();
|
|
||||||
$map.clear_target(target.entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void WorldBuilder::stylize_room(int room, string tile_name, float size) {
|
void WorldBuilder::stylize_room(int room, string tile_name, float size) {
|
||||||
Point center = $map.place_entity(room);
|
Point center = $map.place_entity(room);
|
||||||
|
@ -271,22 +260,25 @@ void WorldBuilder::place_rooms() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool random_path(Map &map, PointList &holes, Point src) {
|
inline bool random_path(Map &map, PointList &holes, Point src, Point target) {
|
||||||
bool found = false;
|
bool keep_going = false;
|
||||||
Matrix &paths = map.paths();
|
bool target_found = false;
|
||||||
Point out{src.x, src.y};
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
map.set_target(target);
|
||||||
|
map.make_paths();
|
||||||
|
Matrix &paths = map.paths();
|
||||||
|
|
||||||
|
Point out{src.x, src.y};
|
||||||
do {
|
do {
|
||||||
found = map.neighbors(out, true);
|
keep_going = map.neighbors(out, true);
|
||||||
holes.push_back(out);
|
holes.push_back(out);
|
||||||
|
target_found = paths[out.y][out.x] == 0;
|
||||||
|
} while(!target_found && keep_going && ++count < WORLDBUILD_MAX_PATH);
|
||||||
|
|
||||||
if(paths[out.y][out.x] == 0) {
|
map.INVARIANT();
|
||||||
return true;
|
map.clear_target(target);
|
||||||
}
|
|
||||||
} while(found && ++count < WORLDBUILD_MAX_PATH);
|
|
||||||
|
|
||||||
return found;
|
return target_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void straight_path(PointList &holes, Point src, Point target) {
|
inline void straight_path(PointList &holes, Point src, Point target) {
|
||||||
|
@ -296,17 +288,17 @@ inline void straight_path(PointList &holes, Point src, Point target) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WorldBuilder::dig_tunnel(PointList &holes, Point &src, Point &target) {
|
void WorldBuilder::tunnel_doors(PointList &holes, Room &src, Room &target) {
|
||||||
Matrix &paths = $map.paths();
|
int path_type = Random::uniform<int>(0, 3);
|
||||||
|
switch(path_type) {
|
||||||
dbc::check(paths[src.y][src.x] != WALL_PATH_LIMIT,
|
case 0:
|
||||||
"source room has path as a wall");
|
// for now do 25% as simple straight paths
|
||||||
dbc::check(paths[target.y][target.x] != WALL_PATH_LIMIT,
|
straight_path(holes, src.exit, target.entry);
|
||||||
"target room has path as a wall");
|
break;
|
||||||
|
default:
|
||||||
if(!random_path($map, holes, src)) {
|
// then do the rest as random with fallback
|
||||||
straight_path(holes, src, target);
|
if(!random_path($map, holes, src.exit, target.entry)) {
|
||||||
|
straight_path(holes, src.exit, target.entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ class WorldBuilder {
|
||||||
void add_door(Room &room);
|
void add_door(Room &room);
|
||||||
void set_door(Room &room, int value);
|
void set_door(Room &room, int value);
|
||||||
void place_rooms();
|
void place_rooms();
|
||||||
bool dig_tunnel(PointList &holes, Point &src, Point &target);
|
|
||||||
void tunnel_doors(PointList &holes, Room &src, Room &target);
|
void tunnel_doors(PointList &holes, Room &src, Room &target);
|
||||||
void update_door(Point &at, int wall_or_space);
|
void update_door(Point &at, int wall_or_space);
|
||||||
void stylize_room(int room, string tile_name, float size);
|
void stylize_room(int room, string tile_name, float size);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue