Skip to content

Draft: dig-now plugin: remove dependencies on MapCache module.#5832

Draft
SilasD wants to merge 9 commits into
DFHack:developfrom
SilasD:dig-now
Draft

Draft: dig-now plugin: remove dependencies on MapCache module.#5832
SilasD wants to merge 9 commits into
DFHack:developfrom
SilasD:dig-now

Conversation

@SilasD

@SilasD SilasD commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

I request code review on this draft PR, with a focus on dig-now.cpp lines 60 to 380 or so, which contain new code, and the dig_type() function in lines 624-682, which is a complete reimplementation.

I would like this code to be up to modern C++ standards, and I know that my C++ knowledge and skills are not the best.

The remainder of the file is old code updated with different types, e.g. df::coord instead of DFCoord, and removal of all references to the MapExtras::MapCache &map object.

There are also a couple of minor bugfixes, in particular in the dig_tile() function Channel case.

I don't think that part of the plugin needs full review yet, but I do welcome comments.

LuaLS annotations were added to dig-now.lua. No code changes.

General notes:

This PR is intended to be a naive-but-correct reimplementation of dig-now using the Maps module instead of the MapCache module. Note that it does not have the caching that MapCache provided. This results in a lot of unnecessary info lookups.

This PR is known to have bugs. These bugs already existed in the old version. They will be fixed in the near future.

This code has been verified to be almost bug-for-bug compatible with the old version. It results in the same map state with these exceptions:

  • Blueprint-mode designations for carving fortifications and tracks: the old version improperly carves them even though they are set as blueprints, and it also doesn't clear map_block.flags.designated. This new version replicates the buggy behavior, but it properly clears that flag. I can't be bothered to track down the exact line and state to replicate that tiny bug, when I expect to fix the larger bug soon.
  • Undiggable ramps are no longer improperly removed by the clean_ramp() function. This has been seen on tower-cap cap ramps, but has not been verified for all undiggable ramps.

Intended future directions, roughly in this order:

  • Extend the Lua API calls or create new parallel calls to allow Lua scripts to process a list of tiles instead of processing one tile per invocation.
  • The Lua API calls must be able to request dig/smooth operations instead of depending on map tile designations. This is because one of the expected uses is for adventure-mode mods to alter the map, and adventure mode uses the dig and smooth bits for other purposes. The current code does not support this use case.
  • Fix many, many ways that dig-now doesn't leave the map in the same state as actual mining does. See bug-report issue #TODO.
  • Make the core loop map-block-centric, perhaps using Maps::cuboid::forBlock(). Currently it is a naive
    layer-by-layer, column-by-column, row-by-row scan.
  • Re-add caching of region data, biome and geo-biome data, and material data. This reimplementation does a lot of unnecessary info lookups.

SilasD added 7 commits May 22, 2026 10:33
this is intended to be a naive direct-replacement with
minimal changes to algorithms.

this commit is the easy stuff:

remove MapExtras::MapCache &map parameter from functions
change DFCoord to df::coord
change MapCache::ensureBlockAt to Maps::ensureTileBlock
change MapCache::BlockAtTile to Maps::getTileBlock
change MapCache::tiletypeAt to *Maps::getTileType
change MapCache::getDesignationAt to *Maps::getTileDesignation
change MapCache::setDesignationAt to *Maps::getTileDesignation
change MapCache::occupancyAt to *Maps::getTileOccupancy
flag MapCache::layerMaterialAt for further work
flag MapCache::baseMaterialAt for further work
flag Block::veinTypeAt for further work
flag Block::setStoneAt for further work
flag Block::setSoilAt for further work
flag DesignationJobs for further work

add several now-necessary headers.
this is a naive-but-correct implementation with no caching.
@SilasD SilasD marked this pull request as draft June 19, 2026 19:31
@SilasD SilasD self-assigned this Jun 19, 2026
SilasD added 2 commits June 19, 2026 18:11
turns out I'm not allowed to have unused functions.
so much for forward planning.

also, apparently 0 is signed!  who would have known?

In file included from /home/runner/work/dfhack/dfhack/library/include/Error.h:31,
                 from /home/runner/work/dfhack/dfhack/library/include/BitArray.h:26,
                 from /home/runner/work/dfhack/dfhack/library/include/DataDefs.h:37,
                 from /home/runner/work/dfhack/dfhack/library/include/DataIdentity.h:38,
                 from /home/runner/work/dfhack/dfhack/library/include/DataFuncs.h:30,
                 from /home/runner/work/dfhack/dfhack/plugins/dig-now.cpp:5:
/home/runner/work/dfhack/dfhack/library/include/MiscUtils.h: In instantiation of ‘T clip_range(T, T1, T2) [with T = long unsigned int; T1 = int; T2 = long unsigned int]’:
/home/runner/work/dfhack/dfhack/plugins/dig-now.cpp:108:23:   required from here
/home/runner/work/dfhack/dfhack/library/include/MiscUtils.h:553:11: error: comparison of integer expressions of different signedness: ‘long unsigned int’ and ‘int’ [-Werror=sign-compare]
  553 |     if (a < minv) return minv;
      |         ~~^~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant