generalize dfhack.items.isRequestedTradeGood

develop
Myk Taylor 2023-07-06 03:21:19 -07:00
parent 7d3c8bd040
commit 6a8522ab5e
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
3 changed files with 17 additions and 4 deletions

@ -1778,9 +1778,10 @@ Items module
for the item and ``false`` to get the price that the caravan will sell the
item for.
* ``dfhack.items.isRequestedTradeGood(item)``
* ``dfhack.items.isRequestedTradeGood(item[, caravan_state])``
Returns whether any active caravan will pay extra for the given item.
Returns whether a caravan will pay extra for the given item. If caravan_state
is not given, checks all active caravans.
* ``dfhack.items.createItem(item_type, item_subtype, mat_type, mat_index, unit)``

@ -204,7 +204,7 @@ DFHACK_EXPORT bool canTradeWithContents(df::item *item);
/// marks the given item for trade at the given 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
DFHACK_EXPORT bool isRequestedTradeGood(df::item *item);
DFHACK_EXPORT bool isRequestedTradeGood(df::item *item, df::caravan_state *caravan = NULL);
/// Checks whether the item is an assigned hauling vehicle
DFHACK_EXPORT bool isRouteVehicle(df::item *item);

@ -1917,7 +1917,19 @@ static int32_t get_trade_agreement_multiplier(df::item *item, const df::caravan_
: get_sell_request_multiplier(item, caravan);
}
bool Items::isRequestedTradeGood(df::item *item) {
static bool is_requested_trade_good(df::item *item, df::caravan_state *caravan) {
auto trade_state = caravan->trade_state;
if (caravan->time_remaining <= 0 ||
(trade_state != df::caravan_state::T_trade_state::Approaching &&
trade_state != df::caravan_state::T_trade_state::AtDepot))
return false;
return get_buy_request_multiplier(item, caravan->buy_prices) > DEFAULT_AGREEMENT_MULTIPLIER;
}
bool Items::isRequestedTradeGood(df::item *item, df::caravan_state *caravan) {
if (caravan)
return is_requested_trade_good(item, caravan);
for (auto caravan : df::global::plotinfo->caravans) {
auto trade_state = caravan->trade_state;
if (caravan->time_remaining <= 0 ||