diff options
| author | Alexander Gavrilov | 2012-08-24 18:26:18 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-08-24 18:26:18 +0400 |
| commit | 8359e80b233675ee347ff1ac8ec7d37430d52a7a (patch) | |
| tree | c9d6876ef0fb50ffd3e27d793ac505d63f401ed9 /library | |
| parent | d52c54cc762e4f525b4d1f3c339e9cf5a1230ee7 (diff) | |
| download | dfhack-8359e80b233675ee347ff1ac8ec7d37430d52a7a.tar.gz dfhack-8359e80b233675ee347ff1ac8ec7d37430d52a7a.tar.bz2 dfhack-8359e80b233675ee347ff1ac8ec7d37430d52a7a.tar.xz | |
Expose a few API functions to lua, and implement a room browser overlay.
Diffstat (limited to 'library')
| -rw-r--r-- | library/LuaApi.cpp | 3 | ||||
| -rw-r--r-- | library/include/modules/Buildings.h | 5 | ||||
| -rw-r--r-- | library/modules/Buildings.cpp | 39 |
3 files changed, 47 insertions, 0 deletions
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 35cf1435..00d4c517 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -815,6 +815,8 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = { WRAPM(Units, getAge), WRAPM(Units, getProfessionName), WRAPM(Units, getCasteProfessionName), + WRAPM(Units, getProfessionColor), + WRAPM(Units, getCasteProfessionColor), { NULL, NULL } }; @@ -985,6 +987,7 @@ static bool buildings_containsTile(df::building *bld, int x, int y, bool room) { } static const LuaWrapper::FunctionReg dfhack_buildings_module[] = { + WRAPM(Buildings, setOwner), WRAPM(Buildings, allocInstance), WRAPM(Buildings, checkFreeTiles), WRAPM(Buildings, countExtentTiles), diff --git a/library/include/modules/Buildings.h b/library/include/modules/Buildings.h index 6e0a2205..639df686 100644 --- a/library/include/modules/Buildings.h +++ b/library/include/modules/Buildings.h @@ -93,6 +93,11 @@ DFHACK_EXPORT bool Read (const uint32_t index, t_building & building); DFHACK_EXPORT bool ReadCustomWorkshopTypes(std::map <uint32_t, std::string> & btypes); /** + * Sets the owner unit for the building. + */ +DFHACK_EXPORT bool setOwner(df::building *building, df::unit *owner); + +/** * Find the building located at the specified tile. * Does not work on civzones. */ diff --git a/library/modules/Buildings.cpp b/library/modules/Buildings.cpp index 8ec60e55..d1aed897 100644 --- a/library/modules/Buildings.cpp +++ b/library/modules/Buildings.cpp @@ -49,6 +49,7 @@ using namespace DFHack; #include "df/ui_look_list.h" #include "df/d_init.h" #include "df/item.h" +#include "df/unit.h" #include "df/job.h" #include "df/job_item.h" #include "df/general_ref_building_holderst.h" @@ -177,6 +178,44 @@ bool Buildings::ReadCustomWorkshopTypes(map <uint32_t, string> & btypes) return true; } +bool Buildings::setOwner(df::building *bld, df::unit *unit) +{ + CHECK_NULL_POINTER(bld); + + if (!bld->is_room) + return false; + if (bld->owner == unit) + return true; + + if (bld->owner) + { + auto &blist = bld->owner->owned_buildings; + vector_erase_at(blist, linear_index(blist, bld)); + + if (auto spouse = df::unit::find(bld->owner->relations.spouse_id)) + { + auto &blist = spouse->owned_buildings; + vector_erase_at(blist, linear_index(blist, bld)); + } + } + + bld->owner = unit; + + if (unit) + { + unit->owned_buildings.push_back(bld); + + if (auto spouse = df::unit::find(unit->relations.spouse_id)) + { + auto &blist = spouse->owned_buildings; + if (bld->canUseSpouseRoom() && linear_index(blist, bld) < 0) + blist.push_back(bld); + } + } + + return true; +} + df::building *Buildings::findAtTile(df::coord pos) { auto occ = Maps::getTileOccupancy(pos); |
