Skip to content

Commit 03b678e

Browse files
committed
fix autochop report bug
fix format string specification in `autochop` fixes #5701
1 parent 652b792 commit 03b678e

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

docs/changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,17 @@ Template for new versions:
5959
## New Features
6060

6161
## Fixes
62+
- `autochop`: the report will no longer throw a C++ exception when burrows are defined.
6263

6364
## Misc Improvements
6465

6566
## Documentation
6667

6768
## API
69+
- Added ``Burrows::getName``: obtains the name of a burrow, or the same placeholder name that DF would show if the burrow is unnamed.
6870

6971
## Lua
72+
- Added ``Burrows::getName`` as ``dfhack.burrows.getName``.
7073

7174
## Removed
7275

docs/dev/Lua API.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,12 @@ Maps module
24892489
Burrows module
24902490
--------------
24912491

2492+
* ``dfhack.burrows.getName(burrow)``
2493+
2494+
Returns the name of the burrow.
2495+
If the burrow has no set name, returns the same placeholder name that DF would show in the UI.
2496+
2497+
Returns a table of all burrow pointers.
24922498
* ``dfhack.burrows.findByName(name[, ignore_final_plus])``
24932499

24942500
Returns the burrow pointer or *nil*. if ``ignore_final_plus`` is ``true``,

plugins/autochop.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,8 @@ static void autochop_printStatus(color_ostream &out) {
669669
for (auto &burrow : plotinfo->burrows.list) {
670670
name_width = std::max(name_width, (int)burrow->name.size());
671671
}
672-
name_width = -name_width; // left justify
673672

674-
constexpr auto fmt = "{:{}} {:4} {:4} {:8} {:5} {:6} {:7}\n";
673+
constexpr auto fmt = "{:<{}} {:4} {:4} {:8} {:5} {:6} {:7}\n";
675674
out.print(fmt, "burrow name", name_width, " id ", "chop", "clearcut", "trees", "marked", "protect");
676675
out.print(fmt, "-----------", name_width, "----", "----", "--------", "-----", "------", "-------");
677676

@@ -681,6 +680,7 @@ static void autochop_printStatus(color_ostream &out) {
681680
bool protect_brewable = false;
682681
bool protect_edible = false;
683682
bool protect_cookable = false;
683+
std::string name = burrow->name.empty() ? fmt::format("Burrow {}", burrow->id+1) : burrow->name;
684684
if (watched_burrows_indices.count(burrow->id)) {
685685
auto &c = watched_burrows[watched_burrows_indices[burrow->id]];
686686
chop = c.get_bool(BURROW_CONFIG_CHOP);
@@ -689,7 +689,7 @@ static void autochop_printStatus(color_ostream &out) {
689689
protect_edible = c.get_bool(BURROW_CONFIG_PROTECT_EDIBLE);
690690
protect_cookable = c.get_bool(BURROW_CONFIG_PROTECT_COOKABLE);
691691
}
692-
out.print(fmt, burrow->name, name_width, burrow->id,
692+
out.print(fmt, name, name_width, burrow->id,
693693
chop ? "[x]" : "[ ]", clearcut ? "[x]" : "[ ]",
694694
tree_counts[burrow->id],
695695
designated_tree_counts[burrow->id],

0 commit comments

Comments
 (0)