fix adjacent smooth walls when smoothing

develop
myk002 2021-06-06 06:46:59 -07:00
parent c1dcaa4378
commit 61a18b14be
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
1 changed files with 46 additions and 14 deletions

@ -363,18 +363,49 @@ static bool dig_tile(color_ostream &out, MapExtras::MapCache &map,
return true; return true;
} }
static bool is_smooth_wall(MapExtras::MapCache &map, const DFCoord &pos) {
df::tiletype tt = map.tiletypeAt(pos);
return tileSpecial(tt) == df::tiletype_special::SMOOTH
&& tileShape(tt) == df::tiletype_shape::WALL;
}
// adds adjacent smooth walls to the given tdir
static TileDirection get_adjacent_smooth_walls(MapExtras::MapCache &map,
const DFCoord &pos,
TileDirection tdir) {
if (is_smooth_wall(map, DFCoord(pos.x, pos.y-1, pos.z)))
tdir.north = 1;
if (is_smooth_wall(map, DFCoord(pos.x, pos.y+1, pos.z)))
tdir.south = 1;
if (is_smooth_wall(map, DFCoord(pos.x-1, pos.y, pos.z)))
tdir.west = 1;
if (is_smooth_wall(map, DFCoord(pos.x+1, pos.y, pos.z)))
tdir.east = 1;
return tdir;
}
// ensure we have at least two directions enabled so we can find a matching
// tiletype
static TileDirection ensure_valid_tdir(TileDirection tdir) {
if (tdir.sum() < 2) {
if (tdir.north) tdir.south = 1;
else if (tdir.south) tdir.north = 1;
else if (tdir.east) tdir.west = 1;
else if (tdir.west) tdir.east = 1;
}
return tdir;
}
// connects adjacent smooth walls to our new smooth wall // connects adjacent smooth walls to our new smooth wall
static bool adjust_smooth_wall_dir(MapExtras::MapCache &map, static bool adjust_smooth_wall_dir(MapExtras::MapCache &map,
const DFCoord &pos, const DFCoord &pos,
TileDirection adjacent_tdir) { TileDirection tdir) {
df::tiletype tt = map.tiletypeAt(pos); if (!is_smooth_wall(map, pos))
if (tileSpecial(tt) != df::tiletype_special::SMOOTH
|| tileShape(tt) != df::tiletype_shape::WALL)
return false; return false;
TileDirection tdir = tileDirection(tt); tdir = ensure_valid_tdir(get_adjacent_smooth_walls(map, pos, tdir));
tdir.whole |= adjacent_tdir.whole;
df::tiletype tt = map.tiletypeAt(pos);
tt = findTileType(tileShape(tt), tileMaterial(tt), tileVariant(tt), tt = findTileType(tileShape(tt), tileMaterial(tt), tileVariant(tt),
tileSpecial(tt), tdir); tileSpecial(tt), tdir);
if (tt == df::tiletype::Void) if (tt == df::tiletype::Void)
@ -393,17 +424,18 @@ static bool smooth_tile(color_ostream &out, MapExtras::MapCache &map,
TileDirection tdir; TileDirection tdir;
if (tileShape(tt) == df::tiletype_shape::WALL) { if (tileShape(tt) == df::tiletype_shape::WALL) {
if (adjust_smooth_wall_dir(map, DFCoord(pos.x, pos.y-1, pos.z), if (adjust_smooth_wall_dir(map, DFCoord(pos.x, pos.y-1, pos.z),
TileDirection(1, 1, 0, 0))) TileDirection(0, 1, 0, 0)))
tdir.north = tdir.south = 1; tdir.north = 1;
if (adjust_smooth_wall_dir(map, DFCoord(pos.x, pos.y+1, pos.z), if (adjust_smooth_wall_dir(map, DFCoord(pos.x, pos.y+1, pos.z),
TileDirection(1, 1, 0, 0))) TileDirection(1, 0, 0, 0)))
tdir.north = tdir.south = 1; tdir.south = 1;
if (adjust_smooth_wall_dir(map, DFCoord(pos.x-1, pos.y, pos.z), if (adjust_smooth_wall_dir(map, DFCoord(pos.x-1, pos.y, pos.z),
TileDirection(0, 0, 1, 1))) TileDirection(0, 0, 0, 1)))
tdir.east = tdir.west = 1; tdir.west = 1;
if (adjust_smooth_wall_dir(map, DFCoord(pos.x+1, pos.y, pos.z), if (adjust_smooth_wall_dir(map, DFCoord(pos.x+1, pos.y, pos.z),
TileDirection(0, 0, 1, 1))) TileDirection(0, 0, 1, 0)))
tdir.east = tdir.west = 1; tdir.east = 1;
tdir = ensure_valid_tdir(tdir);
} }
tt = findTileType(tileShape(tt), tileMaterial(tt), tileVariant(tt), tt = findTileType(tileShape(tt), tileMaterial(tt), tileVariant(tt),