Merge pull request #2331 from wolfboyft/constructions-find-at-tile-patch

Implement/change/expose to Lua constructions findAtTile & insert
develop
Myk 2022-10-13 17:40:21 -07:00 committed by GitHub
commit 4f10cd4a9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 4 deletions

@ -1906,6 +1906,14 @@ Constructions module
coordinates, designates it for removal, or instantly cancels the planned one.
Returns *true, was_only_planned* if removed; or *false* if none found.
* ``dfhack.constructions.findAtTile(pos)``, or ``findAtTile(x,y,z)``
Returns the construction at the given position, or ``nil`` if there isn't one.
* ``dfhack.constructions.insert(construction)``
Properly inserts the given construction into the game. Returns false and fails to
insert if there was already a construction at the position.
Kitchen module
--------------

@ -49,13 +49,17 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- UX: List widgets now have mouse-interactive scrollbars
- UX: You can now hold down the mouse button on a scrollbar to make it scroll multiple times.
- UX: You can now drag the scrollbar to scroll to a specific spot
- Constructions module: ``findAtTile`` now uses a binary search intead of a linear search.
## Documentation
## API
- Constructions module: added ``insert()`` to insert constructions into the game's sorted list.
## Lua
- ``widgets.Scrollbar``: new scrollbar widget that can be paired with an associated scrollable widget. Integrated with ``widgets.Label`` and ``widgets.List``.
- ``dfhack.constructions.findAtTile()``: exposed preexisting function to Lua.
- ``dfhack.constructions.insert()``: exposed new function to Lua.
# 0.47.05-r7

@ -2264,6 +2264,7 @@ static const luaL_Reg dfhack_buildings_funcs[] = {
static const LuaWrapper::FunctionReg dfhack_constructions_module[] = {
WRAPM(Constructions, designateNew),
WRAPM(Constructions, insert),
{ NULL, NULL }
};
@ -2276,8 +2277,16 @@ static int constructions_designateRemove(lua_State *L)
return 2;
}
static int constructions_findAtTile(lua_State *L)
{
auto pos = CheckCoordXYZ(L, 1, true);
Lua::PushDFObject(L, Constructions::findAtTile(pos));
return 1;
}
static const luaL_Reg dfhack_constructions_funcs[] = {
{ "designateRemove", constructions_designateRemove },
{ "findAtTile", constructions_findAtTile },
{ NULL, NULL }
};

@ -45,6 +45,8 @@ namespace Constructions
DFHACK_EXPORT df::construction * findAtTile(df::coord pos);
DFHACK_EXPORT bool insert(df::construction * constr);
DFHACK_EXPORT bool designateNew(df::coord pos, df::construction_type type,
df::item_type item = df::item_type::NONE, int mat_index = -1);

@ -54,12 +54,19 @@ using df::global::world;
df::construction * Constructions::findAtTile(df::coord pos)
{
for (auto it = world->constructions.begin(); it != world->constructions.end(); ++it) {
if ((*it)->pos == pos)
return *it;
}
int index = binsearch_index(world->constructions, pos);
if (index == -1) {
return NULL;
}
return world->constructions[index];
}
bool Constructions::insert(df::construction * constr)
{
bool toInsert;
insert_into_vector(world->constructions, &df::construction::pos, constr, &toInsert);
return toInsert;
}
bool Constructions::designateNew(df::coord pos, df::construction_type type,
df::item_type item, int mat_index)