From 539caf3dbaf58f7aec0ad7440f9dfe18204b1054 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Sun, 5 Nov 2023 01:18:21 -0800 Subject: [PATCH] handle inactive burrows when assigning/clearing units --- docs/changelog.txt | 1 + library/modules/Burrows.cpp | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 4059aa577..522291a92 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -77,6 +77,7 @@ Template for new versions: - ``Gui::revealInDwarfmodeMap``: gained ``highlight`` parameter to control setting the tile highlight on the zoom target - ``Maps::getWalkableGroup``: get the walkability group of a tile - ``Units::getReadableName``: now returns the *untranslated* name +- ``Burrows::setAssignedUnit``: now properly handles inactive burrows ## Lua - ``dfhack.gui.revealInDwarfmodeMap``: gained ``highlight`` parameter to control setting the tile highlight on the zoom target diff --git a/library/modules/Burrows.cpp b/library/modules/Burrows.cpp index 9e63c0dbc..afd6ac9e3 100644 --- a/library/modules/Burrows.cpp +++ b/library/modules/Burrows.cpp @@ -78,8 +78,10 @@ void Burrows::clearUnits(df::burrow *burrow) { auto unit = df::unit::find(burrow->units[i]); - if (unit) + if (unit) { erase_from_vector(unit->burrows, burrow->id); + erase_from_vector(unit->inactive_burrows, burrow->id); + } } burrow->units.clear(); @@ -90,7 +92,8 @@ bool Burrows::isAssignedUnit(df::burrow *burrow, df::unit *unit) CHECK_NULL_POINTER(unit); CHECK_NULL_POINTER(burrow); - return binsearch_index(unit->burrows, burrow->id) >= 0; + return binsearch_index(unit->burrows, burrow->id) >= 0 || + binsearch_index(unit->inactive_burrows, burrow->id) >= 0; } void Burrows::setAssignedUnit(df::burrow *burrow, df::unit *unit, bool enable) @@ -100,14 +103,15 @@ void Burrows::setAssignedUnit(df::burrow *burrow, df::unit *unit, bool enable) CHECK_NULL_POINTER(unit); CHECK_NULL_POINTER(burrow); - if (enable) - { - insert_into_vector(unit->burrows, burrow->id); + if (enable) { + if (burrow->limit_workshops & 2) // inactive flag + insert_into_vector(unit->inactive_burrows, burrow->id); + else + insert_into_vector(unit->burrows, burrow->id); insert_into_vector(burrow->units, unit->id); - } - else - { + } else { erase_from_vector(unit->burrows, burrow->id); + erase_from_vector(unit->inactive_burrows, burrow->id); erase_from_vector(burrow->units, unit->id); } }