Skip to content

Commit e229883

Browse files
authored
Merge pull request #3949 from myk002/myk_burrow_name_match
[burrow] implement burrow name matching with ignoring plus
2 parents ff052ae + 604eb47 commit e229883

File tree

4 files changed

+17
-30
lines changed

4 files changed

+17
-30
lines changed

docs/dev/Lua API.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,9 +1949,11 @@ Maps module
19491949
Burrows module
19501950
--------------
19511951

1952-
* ``dfhack.burrows.findByName(name)``
1952+
* ``dfhack.burrows.findByName(name[, ignore_final_plus])``
19531953

1954-
Returns the burrow pointer or *nil*.
1954+
Returns the burrow pointer or *nil*. if ``ignore_final_plus`` is ``true``,
1955+
then ``+`` characters at the end of the names are ignored, both for the
1956+
specified ``name`` and the names of the burrows that it matches against.
19551957

19561958
* ``dfhack.burrows.clearUnits(burrow)``
19571959

library/include/modules/Burrows.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace DFHack
4545
{
4646
namespace Burrows
4747
{
48-
DFHACK_EXPORT df::burrow *findByName(std::string name);
48+
DFHACK_EXPORT df::burrow *findByName(std::string name, bool ignore_final_plus = false);
4949

5050
// Units
5151
DFHACK_EXPORT void clearUnits(df::burrow *burrow);

library/modules/Burrows.cpp

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,21 @@ using namespace df::enums;
5151
using df::global::world;
5252
using df::global::plotinfo;
5353

54-
df::burrow *Burrows::findByName(std::string name)
54+
df::burrow *Burrows::findByName(std::string name, bool ignore_final_plus)
5555
{
5656
auto &vec = df::burrow::get_vector();
5757

58-
for (size_t i = 0; i < vec.size(); i++)
59-
if (vec[i]->name == name)
58+
if (ignore_final_plus && name.ends_with('+'))
59+
name = name.substr(0, name.length() - 1);
60+
61+
for (size_t i = 0; i < vec.size(); i++) {
62+
std::string bname = vec[i]->name;
63+
if (ignore_final_plus && bname.ends_with('+'))
64+
bname = bname.substr(0, bname.length() - 1);
65+
66+
if (bname == name)
6067
return vec[i];
68+
}
6169

6270
return NULL;
6371
}
@@ -75,18 +83,6 @@ void Burrows::clearUnits(df::burrow *burrow)
7583
}
7684

7785
burrow->units.clear();
78-
79-
/* TODO: understand how this changes for v50
80-
// Sync plotinfo if active
81-
if (plotinfo && plotinfo->main.mode == ui_sidebar_mode::Burrows &&
82-
plotinfo->burrows.in_add_units_mode && plotinfo->burrows.sel_id == burrow->id)
83-
{
84-
auto &sel = plotinfo->burrows.sel_units;
85-
86-
for (size_t i = 0; i < sel.size(); i++)
87-
sel[i] = false;
88-
}
89-
*/
9086
}
9187

9288
bool Burrows::isAssignedUnit(df::burrow *burrow, df::unit *unit)
@@ -114,17 +110,6 @@ void Burrows::setAssignedUnit(df::burrow *burrow, df::unit *unit, bool enable)
114110
erase_from_vector(unit->burrows, burrow->id);
115111
erase_from_vector(burrow->units, unit->id);
116112
}
117-
118-
/* TODO: understand how this changes for v50
119-
// Sync plotinfo if active
120-
if (plotinfo && plotinfo->main.mode == ui_sidebar_mode::Burrows &&
121-
plotinfo->burrows.in_add_units_mode && plotinfo->burrows.sel_id == burrow->id)
122-
{
123-
int idx = linear_index(plotinfo->burrows.list_units, unit);
124-
if (idx >= 0)
125-
plotinfo->burrows.sel_units[idx] = enable;
126-
}
127-
*/
128113
}
129114

130115
void Burrows::listBlocks(std::vector<df::map_block*> *pvec, df::burrow *burrow)

plugins/burrow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static df::burrow* get_burrow(lua_State *L, int idx) {
279279
if (lua_isuserdata(L, idx))
280280
burrow = Lua::GetDFObject<df::burrow>(L, idx);
281281
else if (lua_isstring(L, idx))
282-
burrow = Burrows::findByName(luaL_checkstring(L, idx));
282+
burrow = Burrows::findByName(luaL_checkstring(L, idx), true);
283283
else if (lua_isinteger(L, idx))
284284
burrow = df::burrow::find(luaL_checkinteger(L, idx));
285285
return burrow;

0 commit comments

Comments
 (0)