trade a bin if any contents can be traded

the new trade screens will make it easy to filter out unwanted items
later
develop
Myk Taylor 2023-07-16 11:55:45 -07:00
parent 5c7aea0775
commit 39612f0d5a
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
5 changed files with 32 additions and 3 deletions

@ -1797,7 +1797,12 @@ Items module
* ``dfhack.items.canTradeWithContents(item)`` * ``dfhack.items.canTradeWithContents(item)``
Checks whether the item and all items it contains, if any, can be traded. Returns false if the item or any contained items cannot be traded.
* ``canTradeAnyWithContents(item)``
Returns true if the item is empty and can be traded or if the item contains
any item that can be traded.
* ``dfhack.items.markForTrade(item, depot)`` * ``dfhack.items.markForTrade(item, depot)``

@ -2025,6 +2025,7 @@ static const LuaWrapper::FunctionReg dfhack_items_module[] = {
WRAPM(Items, checkMandates), WRAPM(Items, checkMandates),
WRAPM(Items, canTrade), WRAPM(Items, canTrade),
WRAPM(Items, canTradeWithContents), WRAPM(Items, canTradeWithContents),
WRAPM(Items, canTradeAnyWithContents),
WRAPM(Items, markForTrade), WRAPM(Items, markForTrade),
WRAPM(Items, isRouteVehicle), WRAPM(Items, isRouteVehicle),
WRAPM(Items, isSquadEquipment), WRAPM(Items, isSquadEquipment),

@ -199,8 +199,10 @@ DFHACK_EXPORT int32_t createItem(df::item_type type, int16_t item_subtype, int16
DFHACK_EXPORT bool checkMandates(df::item *item); DFHACK_EXPORT bool checkMandates(df::item *item);
/// Checks whether the item can be traded /// Checks whether the item can be traded
DFHACK_EXPORT bool canTrade(df::item *item); DFHACK_EXPORT bool canTrade(df::item *item);
/// Checks whether the item and all items it contains, if any, can be traded /// Returns false if the item or any contained items cannot be traded
DFHACK_EXPORT bool canTradeWithContents(df::item *item); DFHACK_EXPORT bool canTradeWithContents(df::item *item);
/// Returns true if the item is empty and can be traded or if the item contains any item that can be traded
DFHACK_EXPORT bool canTradeAnyWithContents(df::item *item);
/// marks the given item for trade at the given depot /// marks the given item for trade at the given depot
DFHACK_EXPORT bool markForTrade(df::item *item, df::building_tradedepotst *depot); DFHACK_EXPORT bool markForTrade(df::item *item, df::building_tradedepotst *depot);
/// Returns true if an active caravan will pay extra for the given item /// Returns true if an active caravan will pay extra for the given item

@ -2172,6 +2172,27 @@ bool Items::canTradeWithContents(df::item *item)
return true; return true;
} }
bool Items::canTradeAnyWithContents(df::item *item)
{
CHECK_NULL_POINTER(item);
if (item->flags.bits.in_inventory)
return false;
vector<df::item*> contained_items;
getContainedItems(item, &contained_items);
if (contained_items.empty())
return canTrade(item);
for (df::item *cit : contained_items) {
if (canTrade(cit))
return true;
}
return false;
}
bool Items::markForTrade(df::item *item, df::building_tradedepotst *depot) { bool Items::markForTrade(df::item *item, df::building_tradedepotst *depot) {
CHECK_NULL_POINTER(item); CHECK_NULL_POINTER(item);
CHECK_NULL_POINTER(depot); CHECK_NULL_POINTER(depot);

@ -317,7 +317,7 @@ public:
} }
bool can_designate(color_ostream& out, df::item* item) override { bool can_designate(color_ostream& out, df::item* item) override {
return Items::canTradeWithContents(item); return Items::canTradeAnyWithContents(item);
} }
bool designate(color_ostream& out, df::item* item) override { bool designate(color_ostream& out, df::item* item) override {