Merge pull request #3949 from myk002/myk_burrow_name_match

[burrow] implement burrow name matching with ignoring plus
develop
Myk 2023-11-02 14:05:44 -07:00 committed by GitHub
commit e22988350c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 30 deletions

@ -1949,9 +1949,11 @@ Maps module
Burrows module Burrows module
-------------- --------------
* ``dfhack.burrows.findByName(name)`` * ``dfhack.burrows.findByName(name[, ignore_final_plus])``
Returns the burrow pointer or *nil*. Returns the burrow pointer or *nil*. if ``ignore_final_plus`` is ``true``,
then ``+`` characters at the end of the names are ignored, both for the
specified ``name`` and the names of the burrows that it matches against.
* ``dfhack.burrows.clearUnits(burrow)`` * ``dfhack.burrows.clearUnits(burrow)``

@ -45,7 +45,7 @@ namespace DFHack
{ {
namespace Burrows namespace Burrows
{ {
DFHACK_EXPORT df::burrow *findByName(std::string name); DFHACK_EXPORT df::burrow *findByName(std::string name, bool ignore_final_plus = false);
// Units // Units
DFHACK_EXPORT void clearUnits(df::burrow *burrow); DFHACK_EXPORT void clearUnits(df::burrow *burrow);

@ -51,13 +51,21 @@ using namespace df::enums;
using df::global::world; using df::global::world;
using df::global::plotinfo; using df::global::plotinfo;
df::burrow *Burrows::findByName(std::string name) df::burrow *Burrows::findByName(std::string name, bool ignore_final_plus)
{ {
auto &vec = df::burrow::get_vector(); auto &vec = df::burrow::get_vector();
for (size_t i = 0; i < vec.size(); i++) if (ignore_final_plus && name.ends_with('+'))
if (vec[i]->name == name) name = name.substr(0, name.length() - 1);
for (size_t i = 0; i < vec.size(); i++) {
std::string bname = vec[i]->name;
if (ignore_final_plus && bname.ends_with('+'))
bname = bname.substr(0, bname.length() - 1);
if (bname == name)
return vec[i]; return vec[i];
}
return NULL; return NULL;
} }
@ -75,18 +83,6 @@ void Burrows::clearUnits(df::burrow *burrow)
} }
burrow->units.clear(); burrow->units.clear();
/* TODO: understand how this changes for v50
// Sync plotinfo if active
if (plotinfo && plotinfo->main.mode == ui_sidebar_mode::Burrows &&
plotinfo->burrows.in_add_units_mode && plotinfo->burrows.sel_id == burrow->id)
{
auto &sel = plotinfo->burrows.sel_units;
for (size_t i = 0; i < sel.size(); i++)
sel[i] = false;
}
*/
} }
bool Burrows::isAssignedUnit(df::burrow *burrow, df::unit *unit) bool Burrows::isAssignedUnit(df::burrow *burrow, df::unit *unit)
@ -114,17 +110,6 @@ void Burrows::setAssignedUnit(df::burrow *burrow, df::unit *unit, bool enable)
erase_from_vector(unit->burrows, burrow->id); erase_from_vector(unit->burrows, burrow->id);
erase_from_vector(burrow->units, unit->id); erase_from_vector(burrow->units, unit->id);
} }
/* TODO: understand how this changes for v50
// Sync plotinfo if active
if (plotinfo && plotinfo->main.mode == ui_sidebar_mode::Burrows &&
plotinfo->burrows.in_add_units_mode && plotinfo->burrows.sel_id == burrow->id)
{
int idx = linear_index(plotinfo->burrows.list_units, unit);
if (idx >= 0)
plotinfo->burrows.sel_units[idx] = enable;
}
*/
} }
void Burrows::listBlocks(std::vector<df::map_block*> *pvec, df::burrow *burrow) void Burrows::listBlocks(std::vector<df::map_block*> *pvec, df::burrow *burrow)

@ -279,7 +279,7 @@ static df::burrow* get_burrow(lua_State *L, int idx) {
if (lua_isuserdata(L, idx)) if (lua_isuserdata(L, idx))
burrow = Lua::GetDFObject<df::burrow>(L, idx); burrow = Lua::GetDFObject<df::burrow>(L, idx);
else if (lua_isstring(L, idx)) else if (lua_isstring(L, idx))
burrow = Burrows::findByName(luaL_checkstring(L, idx)); burrow = Burrows::findByName(luaL_checkstring(L, idx), true);
else if (lua_isinteger(L, idx)) else if (lua_isinteger(L, idx))
burrow = df::burrow::find(luaL_checkinteger(L, idx)); burrow = df::burrow::find(luaL_checkinteger(L, idx));
return burrow; return burrow;