Now have more fancy rooms with different floors to play with.
This commit is contained in:
parent
f46b5f15ef
commit
9c03e850b5
7 changed files with 96 additions and 41 deletions
|
@ -106,6 +106,19 @@ void WorldBuilder::tunnel_doors(PointList &holes, Room &src, Room &target) {
|
|||
$map.clear_target(target.entry);
|
||||
}
|
||||
|
||||
|
||||
void WorldBuilder::stylize_room(int room, string tile_name, float size) {
|
||||
Point center = $map.place_entity(room);
|
||||
|
||||
for(matrix::circle it{$map.$walls, center, size}; it.next();) {
|
||||
for(int x = it.left; x < it.right; x++) {
|
||||
if(!$map.iswall(x, it.y)) {
|
||||
$map.$tiles.set_tile(x, it.y, tile_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WorldBuilder::generate() {
|
||||
PointList holes;
|
||||
Room root{
|
||||
|
@ -140,15 +153,10 @@ void WorldBuilder::generate() {
|
|||
}
|
||||
|
||||
$map.load_tiles();
|
||||
|
||||
Point center = $map.place_entity(1);
|
||||
for(matrix::circle it{$map.$walls, center, 3}; it.next();) {
|
||||
for(int x = it.left; x < it.right; x++) {
|
||||
if(!$map.iswall(x, it.y)) {
|
||||
$map.$tiles.set_tile(x, it.y, "WATER_TILE");
|
||||
}
|
||||
}
|
||||
}
|
||||
stylize_room(3, "WATER_TILE", 2.5);
|
||||
stylize_room(2, "SAND_TILE", 4.5);
|
||||
stylize_room(4, "MOSAIC_TILE_2", 7.0);
|
||||
stylize_room(1, "GRASS_TILE", 3.4);
|
||||
}
|
||||
|
||||
void WorldBuilder::make_room(size_t origin_x, size_t origin_y, size_t w, size_t h) {
|
||||
|
@ -176,6 +184,31 @@ void WorldBuilder::place_rooms() {
|
|||
}
|
||||
}
|
||||
|
||||
inline bool random_path(Map &map, PointList &holes, Point src, Point target) {
|
||||
bool found = false;
|
||||
Matrix &paths = map.paths();
|
||||
Point out{src.x, src.y};
|
||||
int count = 0;
|
||||
|
||||
do {
|
||||
found = map.neighbors(out, true);
|
||||
holes.push_back(out);
|
||||
|
||||
if(paths[out.y][out.x] == 0) {
|
||||
return true;
|
||||
}
|
||||
} while(found && ++count < WORLDBUILD_MAX_PATH);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
inline void straight_path(PointList &holes, Point src, Point target) {
|
||||
for(matrix::line dig{src, target}; dig.next();) {
|
||||
holes.push_back({size_t(dig.x), size_t(dig.y)});
|
||||
holes.push_back({size_t(dig.x+1), size_t(dig.y)});
|
||||
}
|
||||
}
|
||||
|
||||
bool WorldBuilder::dig_tunnel(PointList &holes, Point &src, Point &target) {
|
||||
Matrix &paths = $map.paths();
|
||||
|
||||
|
@ -184,18 +217,9 @@ bool WorldBuilder::dig_tunnel(PointList &holes, Point &src, Point &target) {
|
|||
dbc::check(paths[target.y][target.x] != WALL_PATH_LIMIT,
|
||||
"target room has path as a wall");
|
||||
|
||||
bool found = false;
|
||||
Point out{src.x, src.y};
|
||||
int count = 0;
|
||||
if(!random_path($map, holes, src, target)) {
|
||||
straight_path(holes, src, target);
|
||||
}
|
||||
|
||||
do {
|
||||
found = $map.neighbors(out, true);
|
||||
holes.push_back(out);
|
||||
|
||||
if(paths[out.y][out.x] == 0) {
|
||||
return true;
|
||||
}
|
||||
} while(found && ++count < WORLDBUILD_MAX_PATH);
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue