diff --git a/docs/changelog.txt b/docs/changelog.txt index eca35b2e8..8d5e18467 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -62,11 +62,13 @@ Template for new versions: ## Documentation ## API +- ``Items::getValue()``: remove ``caravan_buying`` parameter since the identity of the selling party doesn't actually affect the item value ## Internals ## Lua - ``new()``: improved error handling so that certain errors that were previously uncatchable (creating objects with members with unknown vtables) are now catchable with ``pcall()`` +- ``dfhack.items.getValue()``: remove ``caravan_buying`` param as per C++ API change ## Removed diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index cd35d9465..dbd837e25 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -1773,15 +1773,12 @@ Items module Calculates the base value for an item of the specified type and material. -* ``dfhack.items.getValue(item[, caravan_state, caravan_buying])`` +* ``dfhack.items.getValue(item[, caravan_state])`` Calculates the value of an item. If a ``df.caravan_state`` object is given (from ``df.global.plotinfo.caravans`` or ``df.global.main_interface.trade.mer``), then the value is modified by civ - properties and any trade agreements that might be in effect. In this case, - specify ``caravan_buying`` as ``true`` to get the price the caravan will pay - for the item and ``false`` to get the price that the caravan will sell the - item for. + properties and any trade agreements that might be in effect. * ``dfhack.items.isRequestedTradeGood(item[, caravan_state])`` diff --git a/library/include/modules/Items.h b/library/include/modules/Items.h index beccd669a..9daac1feb 100644 --- a/library/include/modules/Items.h +++ b/library/include/modules/Items.h @@ -191,7 +191,7 @@ DFHACK_EXPORT df::proj_itemst *makeProjectile(MapExtras::MapCache &mc, df::item DFHACK_EXPORT int getItemBaseValue(int16_t item_type, int16_t item_subtype, int16_t mat_type, int32_t mat_subtype); /// Gets the value of a specific item, taking into account civ values and trade agreements if a caravan is given -DFHACK_EXPORT int getValue(df::item *item, df::caravan_state *caravan = NULL, bool caravan_buying = false); +DFHACK_EXPORT int getValue(df::item *item, df::caravan_state *caravan = NULL); DFHACK_EXPORT int32_t createItem(df::item_type type, int16_t item_subtype, int16_t mat_type, int32_t mat_index, df::unit* creator); diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 3694e0203..0b91bdd47 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -1910,13 +1910,6 @@ static int32_t get_sell_request_multiplier(df::item *item, const df::caravan_sta return get_sell_request_multiplier(item, caravan_he->resources, &sell_prices->price[0]); } -static int32_t get_trade_agreement_multiplier(df::item *item, const df::caravan_state *caravan, bool caravan_buying) { - if (!caravan) - return DEFAULT_AGREEMENT_MULTIPLIER; - return caravan_buying ? get_buy_request_multiplier(item, caravan->buy_prices) - : get_sell_request_multiplier(item, caravan); -} - static bool is_requested_trade_good(df::item *item, df::caravan_state *caravan) { auto trade_state = caravan->trade_state; if (caravan->time_remaining <= 0 || @@ -1942,7 +1935,7 @@ bool Items::isRequestedTradeGood(df::item *item, df::caravan_state *caravan) { return false; } -int Items::getValue(df::item *item, df::caravan_state *caravan, bool caravan_buying) +int Items::getValue(df::item *item, df::caravan_state *caravan) { CHECK_NULL_POINTER(item); @@ -2011,8 +2004,12 @@ int Items::getValue(df::item *item, df::caravan_state *caravan, bool caravan_buy value *= 10; // modify buy/sell prices - value *= get_trade_agreement_multiplier(item, caravan, caravan_buying); - value >>= 7; + if (caravan) { + value *= get_buy_request_multiplier(item, caravan->buy_prices); + value >>= 7; + value *= get_sell_request_multiplier(item, caravan); + value >>= 7; + } // Boost value from stack size value *= item->getStackSize();