add dfhack.items.isRequestedTradeGood

develop
Myk Taylor 2023-07-04 03:58:45 -07:00
parent c45dcdd7b0
commit b938891e11
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
5 changed files with 22 additions and 1 deletions

@ -50,8 +50,9 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- Price calculations fixed for many item types
## Lua
- ``dfhack.items.markForTrade``: new API for marking items for trade
- ``dfhack.units.getUnitByNobleRole``, ``dfhack.units.getUnitsByNobleRole``: unit lookup API by role
- ``dfhack.items.markForTrade``: mark items for trade
- ``dfhack.items.isRequestedTradeGood``: discover whether an item is named in a trade agreement with an active caravan
- ``dfhack.items.getValue``: gained optional ``caravan`` and ``caravan_buying`` parameters for prices that take trader races and agreements into account
## Removed

@ -1778,6 +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)``
Returns whether any active caravan will pay extra for the given item.
* ``dfhack.items.createItem(item_type, item_subtype, mat_type, mat_index, unit)``
Creates an item, similar to the `createitem` plugin.

@ -2020,6 +2020,7 @@ static const LuaWrapper::FunctionReg dfhack_items_module[] = {
WRAPM(Items, getSubtypeDef),
WRAPM(Items, getItemBaseValue),
WRAPM(Items, getValue),
WRAPM(Items, isRequestedTradeGood),
WRAPM(Items, createItem),
WRAPM(Items, checkMandates),
WRAPM(Items, canTrade),

@ -203,6 +203,8 @@ DFHACK_EXPORT bool canTrade(df::item *item);
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);
/// Checks whether the item is an assigned hauling vehicle
DFHACK_EXPORT bool isRouteVehicle(df::item *item);

@ -1917,6 +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) {
for (auto caravan : df::global::plotinfo->caravans) {
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))
continue;
if (get_buy_request_multiplier(item, caravan->buy_prices) > DEFAULT_AGREEMENT_MULTIPLIER)
return true;
}
return false;
}
int Items::getValue(df::item *item, df::caravan_state *caravan, bool caravan_buying)
{
CHECK_NULL_POINTER(item);