Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Template for new versions:
- `burrow`: fix ``tiles clear`` and other tile operations silently failing because burrow block z-coordinates were stored incorrectly in the ``Burrows`` module
- `export-world-map`: fix crash exporting site data for a site whose owner has an undefined race
- `gui/quickfort`: show smoothing designations immediately after applying a blueprint
- `liquids`: allow painting liquids and obsidian into unallocated sky blocks
- `liquids`: update light/outside flags of covered tiles when painting obsidian or river sources
- `overlay`: overlay hotkeys no longer steal typed characters while the game is capturing text input, e.g. when renaming a building
- `sort`: fix the Places/Workshops and task searches missing workshops by their current display names (e.g. "Stoneworker's Workshop", "Screw Press")
- `stocks`: overlay now resets scroll position when collapsing categories so the item list is no longer left blank and unscrollable
Expand All @@ -115,6 +117,7 @@ Template for new versions:
- Added ``Maps::describeSurroundings`` to get surroundings classification from savagery and evilness
- Added ``Maps::getCurrentWeather`` to determine the current weather on the map.
- Added ``Maps::forEachTile`` with ``Maps::TileFilter``/``Maps::TileActions`` to scan a cuboid of tiles, matching tiles by tiletype, tiletype attributes, and designation/occupancy bits, and counting, rewriting tiletypes, editing designation/occupancy bits, spawning constructions, or invoking a callback on matching tiles
- Added ``MapExtras::MapCache::propagateVerticalFlags`` to update the light/outside/subterranean flags of tiles below a tile that changed between an open and a solid shape
- Added ``MiscUtils::print_range`` to print ranges with prefix, separator, and suffix
- Added ``Units::breathes`` and ``Units::getBreathingState``
- Deprecated ``World::ReadCurrentWeather`` in favor of ``Maps::getCurrentWeather``
Expand Down
5 changes: 5 additions & 0 deletions library/include/modules/MapCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ class DFHACK_EXPORT MapCache
return b ? b->Allocate() : false;
}

/// Propagate the light, outside, and subterranean flags of the tile at
/// pos to the tiles below it. Call after the tile at pos changed
/// between an open and a solid shape.
void propagateVerticalFlags(DFCoord pos);

/// delete the block from memory
void discardBlock(Block *block);

Expand Down
44 changes: 44 additions & 0 deletions library/modules/MapCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,50 @@ void MapExtras::MapCache::discardBlock(Block *block)
delete block;
}

void MapExtras::MapCache::propagateVerticalFlags(DFCoord pos)
{
df::tiletype_shape shape = tileShape(tiletypeAt(pos));
bool open = shape == tiletype_shape::EMPTY || shape == tiletype_shape::RAMP_TOP;

df::tile_designation td = designationAt(pos);
if (open)
{
if (!ensureBlockAt(DFCoord(pos.x, pos.y, pos.z+1))) {
// only the sky above
td.bits.light = true;
td.bits.outside = true;
td.bits.subterranean = false;
}
}
else
{
// a solid tile covers the column below; subterranean is a property
// of each tile and is preserved
td.bits.light = false;
td.bits.outside = false;
}

for (int32_t z = pos.z - 1;
z >= 0 && ensureBlockAt(DFCoord(pos.x, pos.y, z));
--z)
{
DFCoord pos_below(pos.x, pos.y, z);
df::tile_designation td_below = designationAt(pos_below);
bool sub = open ? td.bits.subterranean : td_below.bits.subterranean;
if (td_below.bits.light == td.bits.light
&& td_below.bits.outside == td.bits.outside
&& td_below.bits.subterranean == sub)
break;
td_below.bits.light = td.bits.light;
td_below.bits.outside = td.bits.outside;
td_below.bits.subterranean = sub;
setDesignationAt(pos_below, td_below);
shape = tileShape(tiletypeAt(pos_below));
if (shape != tiletype_shape::EMPTY && shape != tiletype_shape::RAMP_TOP)
break;
}
}

void MapExtras::MapCache::resetTags()
{
for (auto it = blocks.begin(); it != blocks.end(); ++it)
Expand Down
66 changes: 66 additions & 0 deletions plugins/liquids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,64 @@ struct OperationMode {
command_result df_liquids_execute(color_ostream &out);
command_result df_liquids_execute(color_ostream &out, OperationMode &mode, df::coord pos);

// allocate the map block containing pos if it doesn't exist yet; newly
// allocated sky blocks are filled with open space tiles like natural sky
static void ensure_block(MapExtras::MapCache &mcache, const DFCoord &pos)
{
auto block = mcache.BlockAtTile(pos);
if (!block || block->is_valid())
return;
if (!block->Allocate())
return;
for (int x = 0; x < 16; x++)
for (int y = 0; y < 16; y++)
block->setTiletypeAt(df::coord2d(x, y), tiletype::OpenSpace);
}

// ensure the target map blocks exist so that liquids and obsidian can be
// placed in unallocated sky blocks
static void ensure_brush_blocks(MapExtras::MapCache &mcache,
const OperationMode &mode, const DFCoord &cursor)
{
switch (mode.brush)
{
case B_POINT:
case B_BLOCK:
ensure_block(mcache, cursor);
break;
case B_RANGE:
{
// RectangleBrush paints the size-sized box extending
// forward from the cursor; note that z is already in map
// block units so only x and y get scaled down
DFCoord lo = cursor / 16;
DFCoord hi = (cursor + mode.size - DFCoord(1,1,1)) / 16;
for (int32_t z = cursor.z; z < cursor.z + mode.size.z; z++)
for (int32_t x = lo.x; x <= hi.x; x++)
for (int32_t y = lo.y; y <= hi.y; y++)
ensure_block(mcache, DFCoord(x*16, y*16, z));
}
break;
case B_COLUMN:
// ensure blocks upward while the column stays open, mirroring
// ColumnBrush's stopping condition
for (int32_t z = cursor.z; z < (int32_t)mcache.maxZ(); z++)
{
DFCoord pos(cursor.x, cursor.y, z);
ensure_block(mcache, pos);
df::tiletype tt = mcache.tiletypeAt(pos);
if (!DFHack::LowPassable(tt) &&
!(z == cursor.z && DFHack::HighPassable(tt)))
break;
}
break;
case B_FLOOD:
// flood fill only travels through water tiles, which unallocated
// blocks can never contain
break;
}
}

static void print_prompt(std::ostream &str, OperationMode &cur_mode)
{
str <<"[" << paint_mode_name[cur_mode.paint] << ":" << brush_name[cur_mode.brush];
Expand Down Expand Up @@ -446,6 +504,11 @@ command_result df_liquids_execute(color_ostream &out, OperationMode &cur_mode, d
}

MapCache mcache;

// allocate any unallocated target blocks so that liquids and obsidian
// can be placed in the sky
ensure_brush_blocks(mcache, cur_mode, cursor);

coord_vec all_tiles = brush->points(mcache,cursor);

// Force the game to recompute its walkability cache
Expand All @@ -465,6 +528,7 @@ command_result df_liquids_execute(color_ostream &out, OperationMode &cur_mode, d
des.bits.flow_size = 0;
des.bits.flow_forbid = false;
mcache.setDesignationAt(*iter, des);
mcache.propagateVerticalFlags(*iter);
iter ++;
}
break;
Expand All @@ -475,6 +539,7 @@ command_result df_liquids_execute(color_ostream &out, OperationMode &cur_mode, d
while (iter != all_tiles.end())
{
mcache.setTiletypeAt(*iter, findRandomVariant(tiletype::LavaFloor1));
mcache.propagateVerticalFlags(*iter);
iter ++;
}
break;
Expand All @@ -497,6 +562,7 @@ command_result df_liquids_execute(color_ostream &out, OperationMode &cur_mode, d
Block * b = mcache.BlockAt((*iter)/16);
b->enableBlockUpdates(true);

mcache.propagateVerticalFlags(*iter);
iter++;
}
break;
Expand Down
Loading
Loading