Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``,
Expand Down
2 changes: 2 additions & 0 deletions library/include/modules/Burrows.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions library/modules/Burrows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions plugins/autochop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "----", "----", "--------", "-----", "------", "-------");

Expand All @@ -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],
Expand Down