diff --git a/plugins/dig-now.cpp b/plugins/dig-now.cpp index 1da6780b5..0b4f3d2b5 100644 --- a/plugins/dig-now.cpp +++ b/plugins/dig-now.cpp @@ -287,27 +287,14 @@ static bool carve_tile(color_ostream &out, MapExtras::MapCache &map, return false; } -command_result dig_dug(color_ostream &out, std::vector &) { - CoreSuspender suspend; - - if (!Maps::IsValid()) { - out.printerr("Map is not available!\n"); - return CR_FAILURE; - } - - // scan the whole map for now. we can add in boundaries later. - uint32_t endx, endy, endz; - Maps::getTileSize(endx, endy, endz); - +static void do_dig(color_ostream &out, std::vector &dug_coords, + const DFCoord &start, const DFCoord &end) { // use the proxy layer for the layer material-setting ease-of-use functions. MapExtras::MapCache map; - // tracks which positions to unhide - std::vector dug_coords; - - for (uint32_t z = 0; z <= endz; ++z) { - for (uint32_t y = 0; y <= endy; ++y) { - for (uint32_t x = 0; x <= endx; ++x) { + for (uint32_t z = start.z; z <= end.z; ++z) { + for (uint32_t y = start.y; y <= end.y; ++y) { + for (uint32_t x = start.x; x <= end.x; ++x) { // this will return NULL if the map block hasn't been allocated // yet, but that means there aren't any designations anyway. if (!Maps::getTileBlock(x, y, z)) @@ -348,16 +335,36 @@ command_result dig_dug(color_ostream &out, std::vector &) { } map.WriteAll(); +} + +command_result dig_now(color_ostream &out, std::vector &) { + CoreSuspender suspend; + + if (!Maps::IsValid()) { + out.printerr("Map is not available!\n"); + return CR_FAILURE; + } + + // tracks which positions to unhide + std::vector dug_coords; + + // scan the whole map for now. we can add in configurable boundaries later + DFCoord start(0, 0, 0); + uint32_t endx, endy, endz; + Maps::getTileSize(endx, endy, endz); + DFCoord end(endx, endy, endz); + + do_dig(out, dug_coords, start, end); - // unhide newly dug tiles. we can't do this in the loop above since our - // MapCache wouldn't detect the changes made by reveal.unhideFlood() without - // invalidating and reinitializing on every call. + // unhide newly dug tiles. we can't do this in do_dig() since our MapCache + // wouldn't detect the changes made by reveal.unhideFlood() without + // invalidating and reinitializing on every call for (DFCoord pos : dug_coords) { if (Maps::getTileDesignation(pos)->bits.hidden) flood_unhide(out, pos); } - // Force the game to recompute its walkability cache + // force the game to recompute its walkability cache world->reindex_pathfinding = true; return CR_OK; @@ -366,7 +373,7 @@ command_result dig_dug(color_ostream &out, std::vector &) { DFhackCExport command_result plugin_init(color_ostream &, std::vector &commands) { commands.push_back(PluginCommand( - "dig-now", "Simulate completion of dig designations", dig_dug, false)); + "dig-now", "Instantly complete dig designations", dig_now, false)); return CR_OK; }