Skip to content

Commit

Permalink
Merge pull request #3530 from myk002/myk_item_value
Browse files Browse the repository at this point in the history
fix item prices and algorithm
  • Loading branch information
myk002 authored Jul 6, 2023
2 parents 0b1ca69 + 6a8522a commit dbc3cad
Show file tree
Hide file tree
Showing 5 changed files with 569 additions and 17 deletions.
6 changes: 5 additions & 1 deletion docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:

## API
- ``Units::getUnitByNobleRole``, ``Units::getUnitsByNobleRole``: unit lookup API by role
- ``Items::markForTrade()``, ``Items::isRequestedTradeGood()``, ``Items::getValue``: see Lua notes below

## Internals
- 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

Expand Down
15 changes: 13 additions & 2 deletions docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1768,9 +1768,20 @@ Items module

Calculates the base value for an item of the specified type and material.

* ``dfhack.items.getValue(item)``
* ``dfhack.items.getValue(item[, caravan_state, caravan_buying])``

Calculates the Basic Value of an item, as seen in the View Item screen.
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.

* ``dfhack.items.isRequestedTradeGood(item[, caravan_state])``

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)``

Expand Down
1 change: 1 addition & 0 deletions library/LuaApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 5 additions & 2 deletions library/include/modules/Items.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ distribution.

#include "DataDefs.h"
#include "df/building_tradedepotst.h"
#include "df/caravan_state.h"
#include "df/item.h"
#include "df/item_type.h"
#include "df/general_ref.h"
Expand Down Expand Up @@ -189,8 +190,8 @@ DFHACK_EXPORT df::proj_itemst *makeProjectile(MapExtras::MapCache &mc, df::item
/// Gets value of base-quality item with specified type and material
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, ignoring civ values and trade agreements
DFHACK_EXPORT int getValue(df::item *item);
/// 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 int32_t createItem(df::item_type type, int16_t item_subtype, int16_t mat_type, int32_t mat_index, df::unit* creator);

Expand All @@ -202,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, df::caravan_state *caravan = NULL);

/// Checks whether the item is an assigned hauling vehicle
DFHACK_EXPORT bool isRouteVehicle(df::item *item);
Expand Down
Loading

0 comments on commit dbc3cad

Please sign in to comment.