DFHack / dfhack

Memory hacking library for Dwarf Fortress and a set of tools that use it
Other
1.87k stars 475 forks source link

insta-dig plugin #1843

Closed myk002 closed 3 years ago

myk002 commented 3 years ago

In support of functional tests for #1842, I'd like to write a tool that can convert a tile with a dig designation into a tile that has the shape/properties that the tile would have after a dwarf dug the designated tile.

It looks like the functionality would fit well in the tiletypes plugin. Indeed, there is already a "DESIGNATION" paint option, which sounds relevant, but it currently doesn't do anything. The option is completely ignored (when painting) in the existing implementation.

An argument against doing this in tiletypes is that it would behave differently from any other paint type. It could affect the tile below the target tile (in the case of channeling) or above it (ramps) instead of being restricted to modifying just the tile itself like every other paint command. Moreover, a true "dig" simulation would allow light, skyview, and outdoors flags to propagate from the tile above when channeling. The hidden flag would also need to be set to false for any newly exposed tiles, and in the case of a cavern breach, that could be many tiles.

Does this behavior necessitate a new plugin? Or could it fit into tiletypes without semantically and architecturally feeling out of place?

warmist commented 3 years ago

Imho the value of such a thing would be above the "tiletypes" plugin and it should be added as a function in map module. This way you could add a script and/or plugin that utilizes map digging. Bonus points if you reproduce the item creation due to digging.

Alternatively we could find the function that does the digging and use it directly.

myk002 commented 3 years ago

It looks like a good amount of the required logic has been implemented already for the deramp plugin. Specifically, findSimilarTileType() in TileTypes.h (impl in TileTypes.cpp)

but, yes, if we could find the function that does the dig for us, that would be better : ) How would I go about that? Set up a designation, find the job, set a read/write watchpoint on the designation in the map block, and, hopefully, the watchpoint will trigger when a dwarf starts digging? Then I'd have to trace that back to the code structure in the binary. I'm not familiar with any of the tools at https://docs.dfhack.org/en/latest/docs/Memory-research.html, so this might be more than I'm willing to pursue at this point.

I'm encouraged by the amount of logic already in TileTypes.cpp, so I might poke at that and see how easy it would be to augment its feature set.

Another alternative might be to fastdwarf the dwarves, make them all miners, and just let it happen "organically". This will be slower than digging programmatically, of course, but I'll have to test to see if it's too slow.

myk002 commented 3 years ago

Bonus points if you reproduce the item creation due to digging.

This is actually done now in #1853! https://github.com/DFHack/dfhack/pull/1853/commits/9ff95e6f4ff66edae970ec9116d5f9a7087ff6ee#diff-2d6a3ff76af0fba5cca4b4c49bd1a415925ea68332464d4431a33b03b53d54d3R457

complete with configurable chances for boulder creation for each vein type : )

i can haz bonus points now? kthxbye!