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;
|
||||
}
|
||||
|
||||
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) {
|
||||
Point center = $map.place_entity(room);
|
||||
|
@ -271,22 +260,25 @@ void WorldBuilder::place_rooms() {
|
|||
}
|
||||
}
|
||||
|
||||
inline bool random_path(Map &map, PointList &holes, Point src) {
|
||||
bool found = false;
|
||||
Matrix &paths = map.paths();
|
||||
Point out{src.x, src.y};
|
||||
inline bool random_path(Map &map, PointList &holes, Point src, Point target) {
|
||||
bool keep_going = false;
|
||||
bool target_found = false;
|
||||
int count = 0;
|
||||
map.set_target(target);
|
||||
map.make_paths();
|
||||
Matrix &paths = map.paths();
|
||||
|
||||
Point out{src.x, src.y};
|
||||
do {
|
||||
found = map.neighbors(out, true);
|
||||
keep_going = map.neighbors(out, true);
|
||||
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) {
|
||||
return true;
|
||||
}
|
||||
} while(found && ++count < WORLDBUILD_MAX_PATH);
|
||||
map.INVARIANT();
|
||||
map.clear_target(target);
|
||||
|
||||
return found;
|
||||
return target_found;
|
||||
}
|
||||
|
||||
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) {
|
||||
Matrix &paths = $map.paths();
|
||||
|
||||
dbc::check(paths[src.y][src.x] != WALL_PATH_LIMIT,
|
||||
"source room has path as a wall");
|
||||
dbc::check(paths[target.y][target.x] != WALL_PATH_LIMIT,
|
||||
"target room has path as a wall");
|
||||
|
||||
if(!random_path($map, holes, src)) {
|
||||
straight_path(holes, src, target);
|
||||
void WorldBuilder::tunnel_doors(PointList &holes, Room &src, Room &target) {
|
||||
int path_type = Random::uniform<int>(0, 3);
|
||||
switch(path_type) {
|
||||
case 0:
|
||||
// for now do 25% as simple straight paths
|
||||
straight_path(holes, src.exit, target.entry);
|
||||
break;
|
||||
default:
|
||||
// then do the rest as random with fallback
|
||||
if(!random_path($map, holes, src.exit, target.entry)) {
|
||||
straight_path(holes, src.exit, target.entry);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue