Merge pull request #3644 from myk002/myk_trade

remove caravan_buying param from getValue call
develop
Myk 2023-08-06 23:57:07 -07:00 committed by GitHub
commit 30befab78f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 16 deletions

@ -62,11 +62,13 @@ Template for new versions:
## Documentation ## Documentation
## API ## API
- ``Items::getValue()``: remove ``caravan_buying`` parameter since the identity of the selling party doesn't actually affect the item value
## Internals ## Internals
## Lua ## 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()`` - ``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 ## Removed

@ -1773,15 +1773,12 @@ Items module
Calculates the base value for an item of the specified type and material. 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 Calculates the value of an item. If a ``df.caravan_state`` object is given
(from ``df.global.plotinfo.caravans`` or (from ``df.global.plotinfo.caravans`` or
``df.global.main_interface.trade.mer``), then the value is modified by civ ``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, properties and any trade agreements that might be in effect.
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.
* ``dfhack.items.isRequestedTradeGood(item[, caravan_state])`` * ``dfhack.items.isRequestedTradeGood(item[, caravan_state])``

@ -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); 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 /// 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); DFHACK_EXPORT int32_t createItem(df::item_type type, int16_t item_subtype, int16_t mat_type, int32_t mat_index, df::unit* creator);

@ -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]); 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) { static bool is_requested_trade_good(df::item *item, df::caravan_state *caravan) {
auto trade_state = caravan->trade_state; auto trade_state = caravan->trade_state;
if (caravan->time_remaining <= 0 || if (caravan->time_remaining <= 0 ||
@ -1942,7 +1935,7 @@ bool Items::isRequestedTradeGood(df::item *item, df::caravan_state *caravan) {
return false; 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); CHECK_NULL_POINTER(item);
@ -2011,8 +2004,12 @@ int Items::getValue(df::item *item, df::caravan_state *caravan, bool caravan_buy
value *= 10; value *= 10;
// modify buy/sell prices // modify buy/sell prices
value *= get_trade_agreement_multiplier(item, caravan, caravan_buying); if (caravan) {
value *= get_buy_request_multiplier(item, caravan->buy_prices);
value >>= 7;
value *= get_sell_request_multiplier(item, caravan);
value >>= 7; value >>= 7;
}
// Boost value from stack size // Boost value from stack size
value *= item->getStackSize(); value *= item->getStackSize();