From 6f45e347affe753d5c1015b32ed3cfc8cf0c92aa Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Fri, 22 Sep 2023 12:14:41 +0100 Subject: [PATCH 01/10] digtype now doesn't designate hidden tiles for digging, instead only designating visible tiles in 'auto' mode (also changed MapCache* to unique_ptr) --- plugins/dig.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/plugins/dig.cpp b/plugins/dig.cpp index 879d0dd52..307a1f221 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; } @@ -1462,14 +1459,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) { + out.printerr("Cursor is pointing at a hidden tile. Point the cursor at a visible tile"); + 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); @@ -1486,6 +1490,8 @@ command_result digtype (color_ostream &out, vector & parameters) } } + baseOcc.bits.dig_auto = true; + for( uint32_t z = 0; z < zMax; z++ ) { for( uint32_t x = 1; x < tileXMax-1; x++ ) @@ -1506,18 +1512,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) 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; } From b7fcf035bcd22932a0e16f4efcea323bbd52f9ad Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Fri, 22 Sep 2023 12:18:38 +0100 Subject: [PATCH 02/10] Stopped setting auto-dig on non-default dig designations as auto-dig doesn't work for anything except for the standard 'mine' designation --- plugins/dig.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/dig.cpp b/plugins/dig.cpp index 307a1f221..7b0edf7dd 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -1489,8 +1489,10 @@ command_result digtype (color_ostream &out, vector & parameters) baseDes.bits.dig = tile_dig_designation::Default; } } - - baseOcc.bits.dig_auto = true; + // 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) baseOcc.bits.dig_auto = true; + else baseOcc.bits.dig_auto = false; for( uint32_t z = 0; z < zMax; z++ ) { From 2083bab2e956b1fe0b21342658619e9b0dc4b433 Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Fri, 22 Sep 2023 12:41:41 +0100 Subject: [PATCH 03/10] added a +z option to digtype --- docs/plugins/dig.rst | 7 ++++--- plugins/dig.cpp | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/plugins/dig.rst b/docs/plugins/dig.rst index 77b3137ae..d6b6451a6 100644 --- a/docs/plugins/dig.rst +++ b/docs/plugins/dig.rst @@ -143,9 +143,10 @@ 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. +You can also pass a ``-z`` and/or a ``+z``` option, which restricts designations to the +current z-level and down/up. This is useful when you don't want to designate tiles on the +same z-levels as your carefully dug fort above/below. To dig only at the current z-level, +pass in both. digexp ------ diff --git a/plugins/dig.cpp b/plugins/dig.cpp index 7b0edf7dd..7a92a0851 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -1424,6 +1424,8 @@ command_result digtype (color_ostream &out, vector & parameters) uint32_t xMax,yMax,zMax; Maps::getSize(xMax,yMax,zMax); + uint32_t zMin = 0; + int32_t targetDigType = -1; for (string parameter : parameters) { if ( parameter == "clear" ) @@ -1442,6 +1444,8 @@ command_result digtype (color_ostream &out, vector & parameters) targetDigType = tile_dig_designation::UpStair; else if ( parameter == "-z" ) zMax = *window_z + 1; + else if ( parameter == "+z") + zMin = *window_z; else { out.printerr("Invalid parameter: '%s'.\n", parameter.c_str()); @@ -1494,7 +1498,7 @@ command_result digtype (color_ostream &out, vector & parameters) if (baseDes.bits.dig == tile_dig_designation::Default) 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++ ) { From 6fe0fb5bf92ec68abb5cc54867cb17324f273f70 Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Fri, 22 Sep 2023 12:45:33 +0100 Subject: [PATCH 04/10] removed trailing whitespace --- plugins/dig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/dig.cpp b/plugins/dig.cpp index 7a92a0851..1379bc3db 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -1496,7 +1496,7 @@ command_result digtype (color_ostream &out, vector & parameters) // 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) baseOcc.bits.dig_auto = true; - else baseOcc.bits.dig_auto = false; + else baseOcc.bits.dig_auto = false; for( uint32_t z = zMin; z < zMax; z++ ) { From b22ca57f50d6c3446af6e3cea5375305a3ea9065 Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Sun, 24 Sep 2023 12:15:46 +0100 Subject: [PATCH 05/10] added previous 'hidden' and 'no-auto' functionality as options, and adjusted how z-level options are specified --- docs/plugins/dig.rst | 25 +++++++++++++++++-------- plugins/dig.cpp | 21 +++++++++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/docs/plugins/dig.rst b/docs/plugins/dig.rst index d6b6451a6..9cb3cc505 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,10 +145,17 @@ Designation options: ``clear`` Clear any designations. -You can also pass a ``-z`` and/or a ``+z``` option, which restricts designations to the -current z-level and down/up. This is useful when you don't want to designate tiles on the -same z-levels as your carefully dug fort above/below. To dig only at the current z-level, -pass in both. +Other options: +``--zdown`` or ``-d`` + Only designates tiles on the cursor's z-level and below +``--zup`` or ``-u`` + Only designates tiles on the cursor's z-level and above +``--cur-zlevel`` or ``-z`` + Only designates tiles on the same z-level as the cursor +``--hidden`` or ``-h`` + Allows designation of hidden tiles, and using a hidden tile as the "palette" +``--no-auto`` or ``-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 1379bc3db..836f48e9d 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -1425,6 +1425,9 @@ command_result digtype (color_ostream &out, vector & parameters) Maps::getSize(xMax,yMax,zMax); uint32_t zMin = 0; + + bool hidden = false; + bool automine = true; int32_t targetDigType = -1; for (string parameter : parameters) { @@ -1442,10 +1445,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 == "+z") + 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()); @@ -1466,8 +1475,8 @@ command_result digtype (color_ostream &out, vector & parameters) std::unique_ptr mCache = std::make_unique(); df::tile_designation baseDes = mCache->designationAt(xy); - if (baseDes.bits.hidden) { - out.printerr("Cursor is pointing at a hidden tile. Point the cursor at a visible tile"); + 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; } @@ -1495,7 +1504,7 @@ command_result digtype (color_ostream &out, vector & parameters) } // 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) baseOcc.bits.dig_auto = true; + if (baseDes.bits.dig == tile_dig_designation::Default && automine) baseOcc.bits.dig_auto = true; else baseOcc.bits.dig_auto = false; for( uint32_t z = zMin; z < zMax; z++ ) @@ -1523,7 +1532,7 @@ command_result digtype (color_ostream &out, vector & parameters) df::tile_designation designation = mCache->designationAt(current); - if (designation.bits.hidden) continue; + if (designation.bits.hidden && !hidden) continue; df::tile_occupancy occupancy = mCache->occupancyAt(current); designation.bits.dig = baseDes.bits.dig; From ff03fc1f2d085e981b52a89c1f552649584e3c2b Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Sun, 24 Sep 2023 12:17:50 +0100 Subject: [PATCH 06/10] trailing whitespace removed --- plugins/dig.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/dig.cpp b/plugins/dig.cpp index 836f48e9d..7be7b815f 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -1421,11 +1421,10 @@ 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); - uint32_t zMin = 0; - bool hidden = false; bool automine = true; From dff9edb26bc3affa85a0835ff6c117a2e65264e5 Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Sun, 24 Sep 2023 12:20:55 +0100 Subject: [PATCH 07/10] dig doc unexpected indentation fixed --- docs/plugins/dig.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/plugins/dig.rst b/docs/plugins/dig.rst index 9cb3cc505..91951434e 100644 --- a/docs/plugins/dig.rst +++ b/docs/plugins/dig.rst @@ -147,15 +147,15 @@ Designation options: Other options: ``--zdown`` or ``-d`` - Only designates tiles on the cursor's z-level and below + Only designates tiles on the cursor's z-level and below. ``--zup`` or ``-u`` - Only designates tiles on the cursor's z-level and above + Only designates tiles on the cursor's z-level and above. ``--cur-zlevel`` or ``-z`` - Only designates tiles on the same z-level as the cursor + Only designates tiles on the same z-level as the cursor. ``--hidden`` or ``-h`` - Allows designation of hidden tiles, and using a hidden tile as the "palette" + Allows designation of hidden tiles, and using a hidden tile as the "palette". ``--no-auto`` or ``-a`` - No automatic mining mode designation - useful if you want to avoid dwarves digging where you don't want them + No automatic mining mode designation - useful if you want to avoid dwarves digging where you don't want them. digexp ------ From 15ede64d9b0f3d614c5176596452d9c693e7d21d Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Sun, 24 Sep 2023 12:23:25 +0100 Subject: [PATCH 08/10] dig doc unexpected indentation actually fixed --- docs/plugins/dig.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/plugins/dig.rst b/docs/plugins/dig.rst index 91951434e..dd69a5f04 100644 --- a/docs/plugins/dig.rst +++ b/docs/plugins/dig.rst @@ -146,15 +146,15 @@ Designation options: Clear any designations. Other options: -``--zdown`` or ``-d`` +``--zdown``, ``-d`` Only designates tiles on the cursor's z-level and below. -``--zup`` or ``-u`` +``--zup``, ``-u`` Only designates tiles on the cursor's z-level and above. -``--cur-zlevel`` or ``-z`` +``--cur-zlevel``, ``-z`` Only designates tiles on the same z-level as the cursor. -``--hidden`` or ``-h`` +``--hidden``, ``-h`` Allows designation of hidden tiles, and using a hidden tile as the "palette". -``--no-auto`` or ``-a`` +``--no-auto``, ``-a`` No automatic mining mode designation - useful if you want to avoid dwarves digging where you don't want them. digexp From 26dd4e1f787ff80cad1345bc8d1430d18bed1b03 Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Sun, 24 Sep 2023 12:30:32 +0100 Subject: [PATCH 09/10] dig doc unexpected indentation actually fixed fr this time --- docs/plugins/dig.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/plugins/dig.rst b/docs/plugins/dig.rst index dd69a5f04..b098d5ac1 100644 --- a/docs/plugins/dig.rst +++ b/docs/plugins/dig.rst @@ -146,6 +146,7 @@ Designation options: Clear any designations. Other options: + ``--zdown``, ``-d`` Only designates tiles on the cursor's z-level and below. ``--zup``, ``-u`` From 7d9dad4688df1639f3ecfc8e6c23d9d77bf06e4c Mon Sep 17 00:00:00 2001 From: Najeeb Al-Shabibi Date: Sun, 24 Sep 2023 20:51:30 +0100 Subject: [PATCH 10/10] dig - doc rewording and added change to changelog --- docs/changelog.txt | 1 + docs/plugins/dig.rst | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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 b098d5ac1..8d5c99536 100644 --- a/docs/plugins/dig.rst +++ b/docs/plugins/dig.rst @@ -154,7 +154,7 @@ Other options: ``--cur-zlevel``, ``-z`` Only designates tiles on the same z-level as the cursor. ``--hidden``, ``-h`` - Allows designation of hidden tiles, and using a hidden tile as the "palette". + 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.