Skip to content

Commit 579c063

Browse files
authored
Merge pull request #5702 from ab9rf/autochop-report-fix
fix autochop report bug
2 parents 652b792 + 821123c commit 579c063

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,11 @@ 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+
24922497
* ``dfhack.burrows.findByName(name[, ignore_final_plus])``
24932498

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

library/include/modules/Burrows.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ namespace DFHack
4545
{
4646
namespace Burrows
4747
{
48+
DFHACK_EXPORT std::string getName(df::burrow* burrow);
49+
4850
DFHACK_EXPORT df::burrow *findByName(std::string name, bool ignore_final_plus = false);
4951

5052
// Units

library/modules/Burrows.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ using namespace df::enums;
5252
using df::global::world;
5353
using df::global::plotinfo;
5454

55+
std::string Burrows::getName(df::burrow* burrow)
56+
{
57+
CHECK_NULL_POINTER(burrow);
58+
return burrow->name.empty() ? fmt::format("Burrow {}", burrow->id + 1) : burrow->name;
59+
}
60+
61+
5562
df::burrow *Burrows::findByName(std::string name, bool ignore_final_plus)
5663
{
5764
auto &vec = df::burrow::get_vector();

plugins/autochop.cpp

Lines changed: 2 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

@@ -689,7 +688,7 @@ static void autochop_printStatus(color_ostream &out) {
689688
protect_edible = c.get_bool(BURROW_CONFIG_PROTECT_EDIBLE);
690689
protect_cookable = c.get_bool(BURROW_CONFIG_PROTECT_COOKABLE);
691690
}
692-
out.print(fmt, burrow->name, name_width, burrow->id,
691+
out.print(fmt, Burrows::getName(burrow), name_width, burrow->id,
693692
chop ? "[x]" : "[ ]", clearcut ? "[x]" : "[ ]",
694693
tree_counts[burrow->id],
695694
designated_tree_counts[burrow->id],

0 commit comments

Comments
 (0)