From 821123c558cca83d71b347cac147e96b319f95f7 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Thu, 8 Jan 2026 20:10:15 -0600 Subject: [PATCH] fix autochop report bug fix format string specification in `autochop` fixes #5701 --- docs/changelog.txt | 3 +++ docs/dev/Lua API.rst | 5 +++++ library/include/modules/Burrows.h | 2 ++ library/modules/Burrows.cpp | 7 +++++++ plugins/autochop.cpp | 5 ++--- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index da2aa1ef4e..63ed45501e 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -59,14 +59,17 @@ Template for new versions: ## New Features ## Fixes +- `autochop`: the report will no longer throw a C++ exception when burrows are defined. ## Misc Improvements ## Documentation ## API +- Added ``Burrows::getName``: obtains the name of a burrow, or the same placeholder name that DF would show if the burrow is unnamed. ## Lua +- Added ``Burrows::getName`` as ``dfhack.burrows.getName``. ## Removed diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 3ba6389088..52fb7c778f 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -2489,6 +2489,11 @@ Maps module Burrows module -------------- +* ``dfhack.burrows.getName(burrow)`` + + Returns the name of the burrow. + If the burrow has no set name, returns the same placeholder name that DF would show in the UI. + * ``dfhack.burrows.findByName(name[, ignore_final_plus])`` Returns the burrow pointer or *nil*. if ``ignore_final_plus`` is ``true``, diff --git a/library/include/modules/Burrows.h b/library/include/modules/Burrows.h index b2e3e56b4e..dbd2e51dd6 100644 --- a/library/include/modules/Burrows.h +++ b/library/include/modules/Burrows.h @@ -45,6 +45,8 @@ namespace DFHack { namespace Burrows { + DFHACK_EXPORT std::string getName(df::burrow* burrow); + DFHACK_EXPORT df::burrow *findByName(std::string name, bool ignore_final_plus = false); // Units diff --git a/library/modules/Burrows.cpp b/library/modules/Burrows.cpp index 6c8802469c..17ab0389d4 100644 --- a/library/modules/Burrows.cpp +++ b/library/modules/Burrows.cpp @@ -52,6 +52,13 @@ using namespace df::enums; using df::global::world; using df::global::plotinfo; +std::string Burrows::getName(df::burrow* burrow) +{ + CHECK_NULL_POINTER(burrow); + return burrow->name.empty() ? fmt::format("Burrow {}", burrow->id + 1) : burrow->name; +} + + df::burrow *Burrows::findByName(std::string name, bool ignore_final_plus) { auto &vec = df::burrow::get_vector(); diff --git a/plugins/autochop.cpp b/plugins/autochop.cpp index 6b98d0347a..811a3d1cb0 100644 --- a/plugins/autochop.cpp +++ b/plugins/autochop.cpp @@ -669,9 +669,8 @@ static void autochop_printStatus(color_ostream &out) { for (auto &burrow : plotinfo->burrows.list) { name_width = std::max(name_width, (int)burrow->name.size()); } - name_width = -name_width; // left justify - constexpr auto fmt = "{:{}} {:4} {:4} {:8} {:5} {:6} {:7}\n"; + constexpr auto fmt = "{:<{}} {:4} {:4} {:8} {:5} {:6} {:7}\n"; out.print(fmt, "burrow name", name_width, " id ", "chop", "clearcut", "trees", "marked", "protect"); out.print(fmt, "-----------", name_width, "----", "----", "--------", "-----", "------", "-------"); @@ -689,7 +688,7 @@ static void autochop_printStatus(color_ostream &out) { protect_edible = c.get_bool(BURROW_CONFIG_PROTECT_EDIBLE); protect_cookable = c.get_bool(BURROW_CONFIG_PROTECT_COOKABLE); } - out.print(fmt, burrow->name, name_width, burrow->id, + out.print(fmt, Burrows::getName(burrow), name_width, burrow->id, chop ? "[x]" : "[ ]", clearcut ? "[x]" : "[ ]", tree_counts[burrow->id], designated_tree_counts[burrow->id],