Implement/change/expose constructions findAtTile & insert (not building)

develop
Tachytaenius 2022-10-12 21:10:22 +01:00
parent 8f024216b8
commit 1cf9688349
3 changed files with 27 additions and 4 deletions

@ -1906,6 +1906,13 @@ 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.
Kitchen module
--------------

@ -2276,8 +2276,17 @@ 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 },
WRAPM(Constructions, insert),
{ NULL, NULL }
};

@ -54,11 +54,18 @@ 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,