From 666edd6d60d99f49ce2556af0c58e53d8795c6c0 Mon Sep 17 00:00:00 2001 From: myk002 Date: Wed, 19 Oct 2022 16:47:54 -0700 Subject: [PATCH] don't overwrite dig priority by accident many callers of setDesignationAt simply didn't bother with the priority parameter. change the default value of the priority param so that by default we will keep the previous value instead of overwriting it --- docs/changelog.txt | 1 + library/include/modules/MapCache.h | 12 +++++++++--- library/modules/MapCache.cpp | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 8b5603a6f..b2bf9f4c0 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -36,6 +36,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## New Plugins ## Fixes +- `tiletypes`: no longer resets dig priority to the default when updating other properties of a tile ## Misc Improvements - `blueprint`: new ``--smooth`` option for recording all smoothed floors and walls instead of just the ones that require smoothing for later carving diff --git a/library/include/modules/MapCache.h b/library/include/modules/MapCache.h index 70ba0a858..522746fb0 100644 --- a/library/include/modules/MapCache.h +++ b/library/include/modules/MapCache.h @@ -267,7 +267,7 @@ public: { return index_tile(designation,p); } - bool setDesignationAt(df::coord2d p, df::tile_designation des, int32_t priority = 4000) + bool setDesignationAt(df::coord2d p, df::tile_designation des, int32_t priority = 0) { if(!valid) return false; dirty_designations = true; @@ -276,6 +276,12 @@ public: index_tile(designation,p) = des; if((des.bits.dig || des.bits.smooth) && block) { block->flags.bits.designated = true; + // if priority is not specified, keep the existing priority if it + // is set. otherwise default to 4000. + if (priority <= 0) + priority = priorityAt(p); + if (priority <= 0) + priority = 4000; setPriorityAt(p, priority); } return true; @@ -554,8 +560,8 @@ class DFHACK_EXPORT MapCache Block * b= BlockAtTile(tilecoord); return b ? b->DesignationAt(tilecoord) : df::tile_designation(); } - // priority is optional, only set if >= 0 - bool setDesignationAt (DFCoord tilecoord, df::tile_designation des, int32_t priority = 4000) + // if priority is 0, it is kept unchanged if previously set, otherwise 4000 + bool setDesignationAt (DFCoord tilecoord, df::tile_designation des, int32_t priority = 0) { if (Block *b = BlockAtTile(tilecoord)) { diff --git a/library/modules/MapCache.cpp b/library/modules/MapCache.cpp index ce3039ecf..b88a078b1 100644 --- a/library/modules/MapCache.cpp +++ b/library/modules/MapCache.cpp @@ -303,7 +303,7 @@ int32_t MapExtras::Block::priorityAt(df::coord2d pos) bool MapExtras::Block::setPriorityAt(df::coord2d pos, int32_t priority) { - if (!block || priority < 0) + if (!block || priority <= 0) return false; auto event = getPriorityEvent(block, true);