diff --git a/docs/changelog.txt b/docs/changelog.txt index 6b641885a..7a7b29391 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -87,9 +87,11 @@ Template for new versions: - unavailable tools are no longer listed in the tag indices in the online docs ## API +- added ``Items::getCapacity``, returns the capacity of an item as a container (reverse-engineered), needed for `combine` ## Lua - added ``GRAY`` color aliases for ``GREY`` colors +- added ``dfhack.items.getCapacity`` to expose the new module API - ``utils.search_text``: text search routine (generalized from internal ``widgets.FilteredList`` logic) ## Removed diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 5faec6d88..870c28697 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -2139,6 +2139,7 @@ static const LuaWrapper::FunctionReg dfhack_items_module[] = { WRAPM(Items, markForTrade), WRAPM(Items, isRouteVehicle), WRAPM(Items, isSquadEquipment), + WRAPM(Items, getCapacity), WRAPN(moveToGround, items_moveToGround), WRAPN(moveToContainer, items_moveToContainer), WRAPN(moveToInventory, items_moveToInventory), diff --git a/library/include/modules/Items.h b/library/include/modules/Items.h index 9daac1feb..05d0049cf 100644 --- a/library/include/modules/Items.h +++ b/library/include/modules/Items.h @@ -212,6 +212,8 @@ DFHACK_EXPORT bool isRequestedTradeGood(df::item *item, df::caravan_state *carav DFHACK_EXPORT bool isRouteVehicle(df::item *item); /// Checks whether the item is assigned to a squad DFHACK_EXPORT bool isSquadEquipment(df::item *item); +/// Returns the item's capacity as a storage container +DFHACK_EXPORT int32_t getCapacity(df::item* item); } } diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 983921576..944334480 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -2283,3 +2283,45 @@ bool Items::isSquadEquipment(df::item *item) auto &vec = plotinfo->equipment.items_assigned[item->getType()]; return binsearch_index(vec, item->id) >= 0; } + +// reverse engineered, code reference: 0x140953150 in 50.11-win64-steam +// our name for this function: itemst::getCapacity +// bay12 name for this function: not known + +int32_t Items::getCapacity(df::item* item) +{ + CHECK_NULL_POINTER(item); + + switch (item->getType()) { + case df::enums::item_type::FLASK: + case df::enums::item_type::GOBLET: + return 180; + case df::enums::item_type::CAGE: + case df::enums::item_type::BARREL: + case df::enums::item_type::COFFIN: + case df::enums::item_type::BOX: + case df::enums::item_type::BAG: + case df::enums::item_type::BIN: + case df::enums::item_type::ARMORSTAND: + case df::enums::item_type::WEAPONRACK: + case df::enums::item_type::CABINET: + return 6000; + case df::enums::item_type::BUCKET: + return 600; + case df::enums::item_type::ANIMALTRAP: + case df::enums::item_type::BACKPACK: + return 3000; + case df::enums::item_type::QUIVER: + return 1200; + case df::enums::item_type::TOOL: + { + auto tool = virtual_cast(item); + if (tool) + return tool->subtype->container_capacity; + } + // fall through + default: + ; // fall through to default exit + } + return 0; +}