diff --git a/docs/changelog.txt b/docs/changelog.txt index 044cb1ca4..74522451d 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -58,6 +58,7 @@ Template for new versions: ## Fixes ## Misc Improvements +- `dig`: `digtype` command now has options to choose between designating only visible tiles or hidden tiles, as well as "auto" dig mode. Z-level options adjusted to allow choosing z-levels above, below, or the same as the cursor. ## Documentation diff --git a/docs/plugins/dig.rst b/docs/plugins/dig.rst index 77b3137ae..8d5c99536 100644 --- a/docs/plugins/dig.rst +++ b/docs/plugins/dig.rst @@ -50,7 +50,7 @@ Usage Designate circles. The diameter is the number of tiles across the center of the circle that you want to dig. See the `digcircle`_ section below for options. -``digtype [] [-p] [-z]`` +``digtype [] [-p] [--zup|-u] [--zdown|-zu] [--cur-zlevel|-z] [--hidden|-h] [--no-auto|-a]`` Designate all vein tiles of the same type as the selected tile. See the `digtype`_ section below for options. ``digexp [] [] [-p]`` @@ -119,9 +119,11 @@ the last selected parameters. digtype ------- -For every tile on the map of the same vein type as the selected tile, this -command designates it to have the same designation as the selected tile. If the -selected tile has no designation, they will be dig designated. +For every tile on the map of the same vein type as the selected tile, this command +designates it to have the same designation as the selected tile. If the selected +tile has no designation, they will be dig designated. By default, only designates +visible tiles, and in the case of dig designation, applies automatic mining to them +(designates uncovered neighbouring tiles of the same type to be dug). If an argument is given, the designation of the selected tile is ignored, and all appropriate tiles are set to the specified designation. @@ -143,9 +145,18 @@ Designation options: ``clear`` Clear any designations. -You can also pass a ``-z`` option, which restricts designations to the current -z-level and down. This is useful when you don't want to designate tiles on the -same z-levels as your carefully dug fort above. +Other options: + +``--zdown``, ``-d`` + Only designates tiles on the cursor's z-level and below. +``--zup``, ``-u`` + Only designates tiles on the cursor's z-level and above. +``--cur-zlevel``, ``-z`` + Only designates tiles on the same z-level as the cursor. +``--hidden``, ``-h`` + Allows designation of hidden tiles, and picking a hidden tile as the target type. +``--no-auto``, ``-a`` + No automatic mining mode designation - useful if you want to avoid dwarves digging where you don't want them. digexp ------ diff --git a/plugins/dig.cpp b/plugins/dig.cpp index 879d0dd52..7be7b815f 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "Core.h" #include "Console.h" @@ -1072,14 +1073,13 @@ command_result digv (color_ostream &out, vector & parameters) con.printerr("I won't dig the borders. That would be cheating!\n"); return CR_FAILURE; } - MapExtras::MapCache * MCache = new MapExtras::MapCache; + std::unique_ptr MCache = std::make_unique(); df::tile_designation des = MCache->designationAt(xy); df::tiletype tt = MCache->tiletypeAt(xy); int16_t veinmat = MCache->veinMaterialAt(xy); if( veinmat == -1 ) { con.printerr("This tile is not a vein.\n"); - delete MCache; return CR_FAILURE; } con.print("%d/%d/%d tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, des.whole); @@ -1192,7 +1192,6 @@ command_result digv (color_ostream &out, vector & parameters) } } MCache->WriteAll(); - delete MCache; return CR_OK; } @@ -1259,7 +1258,7 @@ command_result digl (color_ostream &out, vector & parameters) con.printerr("I won't dig the borders. That would be cheating!\n"); return CR_FAILURE; } - MapExtras::MapCache * MCache = new MapExtras::MapCache; + std::unique_ptr MCache = std::make_unique(); df::tile_designation des = MCache->designationAt(xy); df::tiletype tt = MCache->tiletypeAt(xy); int16_t veinmat = MCache->veinMaterialAt(xy); @@ -1267,7 +1266,6 @@ command_result digl (color_ostream &out, vector & parameters) if( veinmat != -1 ) { con.printerr("This is a vein. Use digv instead!\n"); - delete MCache; return CR_FAILURE; } con.print("%d/%d/%d tiletype: %d, basemat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, basemat, des.whole); @@ -1408,7 +1406,6 @@ command_result digl (color_ostream &out, vector & parameters) } } MCache->WriteAll(); - delete MCache; return CR_OK; } @@ -1424,9 +1421,13 @@ command_result digtype (color_ostream &out, vector & parameters) return CR_FAILURE; } + uint32_t zMin = 0; uint32_t xMax,yMax,zMax; Maps::getSize(xMax,yMax,zMax); + bool hidden = false; + bool automine = true; + int32_t targetDigType = -1; for (string parameter : parameters) { if ( parameter == "clear" ) @@ -1443,8 +1444,16 @@ command_result digtype (color_ostream &out, vector & parameters) targetDigType = tile_dig_designation::DownStair; else if ( parameter == "up" ) targetDigType = tile_dig_designation::UpStair; - else if ( parameter == "-z" ) + else if ( parameter == "-z" || parameter == "--cur-zlevel" ) + {zMax = *window_z + 1; zMin = *window_z;} + else if ( parameter == "--zdown" || parameter == "-d") zMax = *window_z + 1; + else if ( parameter == "--zup" || parameter == "-u") + zMin = *window_z; + else if ( parameter == "--hidden" || parameter == "-h") + hidden = true; + else if ( parameter == "--no-auto" || parameter == "-a" ) + automine = false; else { out.printerr("Invalid parameter: '%s'.\n", parameter.c_str()); @@ -1462,14 +1471,21 @@ command_result digtype (color_ostream &out, vector & parameters) return CR_FAILURE; } DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); - MapExtras::MapCache * mCache = new MapExtras::MapCache; + std::unique_ptr mCache = std::make_unique(); df::tile_designation baseDes = mCache->designationAt(xy); + + if (baseDes.bits.hidden && !hidden) { + out.printerr("Cursor is pointing at a hidden tile. Point the cursor at a visible tile when using the --hidden option.\n"); + return CR_FAILURE; + } + + df::tile_occupancy baseOcc = mCache->occupancyAt(xy); + df::tiletype tt = mCache->tiletypeAt(xy); int16_t veinmat = mCache->veinMaterialAt(xy); if( veinmat == -1 ) { out.printerr("This tile is not a vein.\n"); - delete mCache; return CR_FAILURE; } out.print("(%d,%d,%d) tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, baseDes.whole); @@ -1485,8 +1501,12 @@ command_result digtype (color_ostream &out, vector & parameters) baseDes.bits.dig = tile_dig_designation::Default; } } + // Auto dig only works on default dig designation. Setting dig_auto for any other designation + // prevents dwarves from digging that tile at all. + if (baseDes.bits.dig == tile_dig_designation::Default && automine) baseOcc.bits.dig_auto = true; + else baseOcc.bits.dig_auto = false; - for( uint32_t z = 0; z < zMax; z++ ) + for( uint32_t z = zMin; z < zMax; z++ ) { for( uint32_t x = 1; x < tileXMax-1; x++ ) { @@ -1506,18 +1526,22 @@ command_result digtype (color_ostream &out, vector & parameters) if ( !mCache->testCoord(current) ) { out.printerr("testCoord failed at (%d,%d,%d)\n", x, y, z); - delete mCache; return CR_FAILURE; } df::tile_designation designation = mCache->designationAt(current); + + if (designation.bits.hidden && !hidden) continue; + + df::tile_occupancy occupancy = mCache->occupancyAt(current); designation.bits.dig = baseDes.bits.dig; - mCache->setDesignationAt(current, designation,priority); + occupancy.bits.dig_auto = baseOcc.bits.dig_auto; + mCache->setDesignationAt(current, designation, priority); + mCache->setOccupancyAt(current, occupancy); } } } mCache->WriteAll(); - delete mCache; return CR_OK; }