Merge pull request #3899 from ab9rf/item-capacity

implement simulated `Items::getCapacity`
develop
Myk 2023-10-16 10:23:52 -07:00 committed by GitHub
commit 5f70ea8432
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 0 deletions

@ -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

@ -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),

@ -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);
}
}

@ -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<df::item_toolst>(item);
if (tool)
return tool->subtype->container_capacity;
}
// fall through
default:
; // fall through to default exit
}
return 0;
}