Crossfire Server, Trunk  1.75.0
shop.cpp File Reference
#include "global.h"
#include <assert.h>
#include <cmath>
#include <stdlib.h>
#include <string.h>
#include "shop.h"
#include "sproto.h"
+ Include dependency graph for shop.cpp:

Go to the source code of this file.

Data Structures

struct  unpaid_count
 

Macros

#define DISAPPROVAL_RATIO   0.2
 Price a shopkeeper will give to someone they disapprove of. More...
 
#define LARGEST_COIN_GIVEN   2
 Never give amber or jade, but accept them. More...
 
#define MAX_BUY_REDUCTION   0.1f
 Maximum price reduction when buying an item with bargaining skill. More...
 
#define MAX_SELL_EXTRA   0.1f
 Maximum price increase when selling an item with bargaining skill. More...
 
#define NEUTRAL_RATIO   0.8
 Price a shopkeeper will give someone they neither like nor dislike. More...
 
#define NUM_COINS   5
 Number of coin types. More...
 
#define SPECIALISATION_EFFECT   0.5
 This is a measure of how effective store specialisation is. More...
 

Functions

static void add_value (object *coin_objs[], int64_t value)
 This function adds a given amount to a list of coins. More...
 
uint64_t add_with_overflow (uint64_t a, uint64_t b)
 
int can_pay (object *pl)
 Checks all unpaid items in op's inventory, adds up all the money they have, and checks that they can actually afford what they want to buy. More...
 
static uint64_t compute_price_variation_with_bargaining (object *pl, uint64_t price, float max_variation)
 Compute a percent of the price which will be used as extra or reduction. More...
 
char * cost_approx_str (const object *tmp, object *who)
 Return a textual cost approximation in a newly-allocated string. More...
 
char * cost_str (uint64_t cost)
 
char * cost_string_from_value (uint64_t cost, int largest_coin)
 Converts a price to number of coins. More...
 
static void count_coins (object *item, uint32_t *coincount)
 Count the number of coins for each type, for all items below item and in inventory. More...
 
static void count_unpaid (object *pl, object *item, int *unpaid_count, uint64_t *unpaid_price)
 Sum the amount to pay for all unpaid items and find available money. More...
 
static void count_unpaid_callback (object *item, void *data)
 
static archetypefind_next_coin (uint64_t c, int *cointype)
 Find the coin type that is worth more than 'c'. More...
 
static void insert_objects (object *pl, object *container, object *objects[], int objects_len)
 Insert a list of objects into a player object. More...
 
int pay_for_amount (uint64_t to_pay, object *pl)
 Takes the amount of money from the the player inventory and from it's various pouches using the pay_from_container() function. More...
 
int pay_for_item (object *op, object *pl, uint64_t reduction)
 Player attemps to buy an item, if she has enough money then remove coins as needed from active containers. More...
 
static uint64_t pay_from_container (object *pl, object *pouch, uint64_t to_pay)
 This pays for the item, and takes the proper amount of money off the specified container (pouch or player), without recursing opened containers. More...
 
uint64_t price_approx (const object *tmp, object *who)
 Adjust the value of the given item based on the player's skills. More...
 
uint64_t query_money (const object *op)
 Determine the amount of money the given object contains, including what is inside containers. More...
 
static StringBufferreal_money_value (const object *coin, StringBuffer *buf)
 Returns a string representing the money's value, in plain coins. More...
 
static int64_t remove_value (object *coin_objs[], int64_t remain)
 This function removes a given amount from a list of coins. More...
 
void sell_item (object *op, object *pl)
 Player is selling an item. More...
 
double shop_approval (const mapstruct *map, const object *player)
 Return the approval ratio for a shop for a given player. More...
 
static float shop_cha_modifier (int charisma)
 Calculate the buy price multiplier based on a player's charisma. More...
 
int shop_describe (const object *op)
 A player is examining a shop, so describe it. More...
 
float shop_efficiency (const object *player)
 Return the shop's efficiency (E) for a player, a number greater than (but not equal to) zero and less than or equal to one. More...
 
static double shop_greed (const mapstruct *map)
 Gets a shop's greed. More...
 
int shop_pay_unpaid (object *pl, object *op)
 Pay as many unpaid items as possible, recursing on op->inv and op->below. More...
 
static void shop_pay_unpaid_callback (object *op, void *data)
 
uint64_t shop_price_buy (const object *tmp, object *who)
 Adjust the value of an item to be bought based on the player's bargaining skill and charisma. More...
 
uint64_t shop_price_sell (const object *tmp, object *who)
 Adjust the value of an item to be sold based on the player's bargaining skill and charisma. More...
 
static double shop_specialisation_ratio (const object *item, const mapstruct *map)
 Returns the ratio of the price that a shop will offer for an item based on the shop's specialisation. More...
 
static void unpaid_iter (object *item, void(*callback)(object *item, void *data), void *data)
 Search for unpaid items in 'item' and call 'callback' on each item. More...
 
static uint64_t value_limit (uint64_t val, int quantity, const object *who, int isshop)
 Limit the value of items based on the wealth of the shop. More...
 

Variables

static const char *const coins []
 Coins to use for shopping. More...
 

Detailed Description

Those functions deal with shop handling, bargaining, things like that.

Todo:
isn't there redundance with pay_for_item(), get_payment(), pay_for_amount()?

Definition in file shop.cpp.

Macro Definition Documentation

◆ DISAPPROVAL_RATIO

#define DISAPPROVAL_RATIO   0.2

Price a shopkeeper will give to someone they disapprove of.

Definition at line 42 of file shop.cpp.

◆ LARGEST_COIN_GIVEN

#define LARGEST_COIN_GIVEN   2

Never give amber or jade, but accept them.

Definition at line 59 of file shop.cpp.

◆ MAX_BUY_REDUCTION

#define MAX_BUY_REDUCTION   0.1f

Maximum price reduction when buying an item with bargaining skill.

Definition at line 48 of file shop.cpp.

◆ MAX_SELL_EXTRA

#define MAX_SELL_EXTRA   0.1f

Maximum price increase when selling an item with bargaining skill.

Definition at line 50 of file shop.cpp.

◆ NEUTRAL_RATIO

#define NEUTRAL_RATIO   0.8

Price a shopkeeper will give someone they neither like nor dislike.

Definition at line 45 of file shop.cpp.

◆ NUM_COINS

#define NUM_COINS   5

Number of coin types.

Definition at line 57 of file shop.cpp.

◆ SPECIALISATION_EFFECT

#define SPECIALISATION_EFFECT   0.5

This is a measure of how effective store specialisation is.

A general store will offer this proportion of the 'maximum' price, a specialised store will offer a range of prices around it such that the maximum price is always one therefore making this number higher, makes specialisation less effective. setting this value above 1 or to a negative value would have interesting, (though not useful) effects.

Definition at line 39 of file shop.cpp.

Function Documentation

◆ add_value()

static void add_value ( object coin_objs[],
int64_t  value 
)
static

This function adds a given amount to a list of coins.

Parameters
coin_objsthe list coins to add to; the list must be ordered from least to most valuable coin
valuethe value (in silver coins) to add

Definition at line 526 of file shop.cpp.

References LARGEST_COIN_GIVEN, object::nrof, NUM_COINS, and object::value.

Referenced by pay_from_container().

+ Here is the caller graph for this function:

◆ add_with_overflow()

uint64_t add_with_overflow ( uint64_t  a,
uint64_t  b 
)

Definition at line 669 of file shop.cpp.

References a().

Referenced by count_unpaid_callback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ can_pay()

int can_pay ( object pl)

Checks all unpaid items in op's inventory, adds up all the money they have, and checks that they can actually afford what they want to buy.

Prints appropriate messages to the player.

Parameters
plplayer trying to bug.
Return values
1player could buy the items.
0some items can't be bought.

Definition at line 784 of file shop.cpp.

References buf, archetype::clone, coins, cost_str(), count_coins(), count_unpaid(), draw_ext_info, find_archetype(), object::inv, llevError, LOG(), make_list_like(), MAX_BUF, MSG_TYPE_SHOP, MSG_TYPE_SHOP_PAYMENT, object::name_pl, NDI_UNIQUE, NUM_COINS, unpaid_count::pl, PLAYER, query_money(), and object::type.

Referenced by cfapi_player_can_pay(), and shop_mat_type_move_on().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compute_price_variation_with_bargaining()

static uint64_t compute_price_variation_with_bargaining ( object pl,
uint64_t  price,
float  max_variation 
)
static

Compute a percent of the price which will be used as extra or reduction.

This will be 0 if the player doesn't have the bargaining skill.

Parameters
plplayer to compute for.
pricebase price.
max_variationmaximum variation, 1 means 100%.
Returns
price variation, always 0 or positive.

Definition at line 764 of file shop.cpp.

References find_skill_by_number(), Settings::max_level, unpaid_count::pl, unpaid_count::price, rndm(), settings, SK_BARGAINING, and skill.

Referenced by sell_item(), and shop_pay_unpaid_callback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cost_approx_str()

char* cost_approx_str ( const object obj,
object who 
)

Return a textual cost approximation in a newly-allocated string.

Parameters
objitem to query the price of, must not be NULL.
whoplayer asking for the price, must not be NULL.
Returns
converted value the caller is responsible to free.

Definition at line 312 of file shop.cpp.

References buf, archetype::clone, cost_str(), find_next_coin(), find_skill_by_number(), get_typedata(), typedata::identifyskill, typedata::identifyskill2, LARGEST_COIN_GIVEN, MONEY, object::name, object::name_pl, price_approx(), real_money_value(), SK_BARGAINING, stringbuffer_append_printf(), stringbuffer_append_string(), stringbuffer_delete(), stringbuffer_finish(), stringbuffer_new(), object::type, and object::value.

Referenced by examine().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cost_str()

char* cost_str ( uint64_t  cost)

Definition at line 308 of file shop.cpp.

References cost_string_from_value(), and LARGEST_COIN_GIVEN.

Referenced by can_pay(), cost_approx_str(), examine(), pick_up_object(), sell_item(), shop_describe(), and shop_pay_unpaid_callback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cost_string_from_value()

char* cost_string_from_value ( uint64_t  cost,
int  largest_coin 
)

Converts a price to number of coins.

While cost is 64 bit, the number of any coin is still really limited to 32 bit (size of nrof field). If it turns out players have so much money that they have more than 2 billion platinum coins, there are certainly issues - the easiest fix at that time is to add a higher denomination (mithril piece with 10,000 silver or something)

Parameters
costvalue to transform to currency.
largest_coinmaximum coin to give the price into, should be between 0 and NUM_COINS - 1.
Returns
converted value the caller is responsible to free.

Definition at line 220 of file shop.cpp.

References buf, archetype::clone, done, find_next_coin(), object::name, NUM_COINS, stringbuffer_append_printf(), stringbuffer_append_string(), stringbuffer_finish(), stringbuffer_new(), UINT32_MAX, and object::value.

Referenced by cfapi_cost_string_from_value(), and cost_str().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ count_coins()

static void count_coins ( object item,
uint32_t *  coincount 
)
static

Count the number of coins for each type, for all items below item and in inventory.

Parameters
itemitem to get the money from.
coincountarray of NUM_COINS size, will contain how many coins of the type the player has.

Definition at line 738 of file shop.cpp.

References object::arch, coins, FOR_OB_AND_BELOW_FINISH, FOR_OB_AND_BELOW_PREPARE, object::inv, archetype::name, object::nrof, and NUM_COINS.

Referenced by can_pay().

+ Here is the caller graph for this function:

◆ count_unpaid()

static void count_unpaid ( object pl,
object item,
int *  unpaid_count,
uint64_t *  unpaid_price 
)
static

Sum the amount to pay for all unpaid items and find available money.

Parameters
plplayer we're checking for, used for buying price with bargaining.
itemitem to check for.
[out]unpaid_counthow many unpaid items are left.
[out]unpaid_pricetotal price unpaid.

Definition at line 724 of file shop.cpp.

References unpaid_count::count, count_unpaid_callback(), unpaid_count::pl, unpaid_count::price, and unpaid_iter().

Referenced by can_pay().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ count_unpaid_callback()

static void count_unpaid_callback ( object item,
void *  data 
)
static

Definition at line 706 of file shop.cpp.

References add_with_overflow(), unpaid_count::count, unpaid_count::pl, unpaid_count::price, and shop_price_buy().

Referenced by count_unpaid().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_next_coin()

static archetype* find_next_coin ( uint64_t  c,
int *  cointype 
)
static

Find the coin type that is worth more than 'c'.

Starts at the cointype placement.

Parameters
cvalue we're searching.
cointypefirst coin type to search.
Returns
coin archetype, NULL if none found.

Definition at line 188 of file shop.cpp.

References c, archetype::clone, coins, find_archetype(), and object::value.

Referenced by cost_approx_str(), and cost_string_from_value().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insert_objects()

static void insert_objects ( object pl,
object container,
object objects[],
int  objects_len 
)
static

Insert a list of objects into a player object.

Parameters
plthe player to add to
containerthe container (inside the player object) to add to
objectsthe list of objects to add; the objects will be either inserted into the player object or freed
objects_lenthe length of objects

Definition at line 550 of file shop.cpp.

References esrv_update_item(), object_free_drop_inventory(), object_insert_in_ob(), objects, and UPD_WEIGHT.

Referenced by pay_from_container().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pay_for_amount()

int pay_for_amount ( uint64_t  to_pay,
object pl 
)

Takes the amount of money from the the player inventory and from it's various pouches using the pay_from_container() function.

Parameters
to_payamount to pay.
plplayer paying.
Returns
0 if not enough money, in which case nothing is removed, 1 if money was removed.
Todo:
check if pl is a player, as query_money() expects that. Check if fix_object() call is required.

Definition at line 404 of file shop.cpp.

References CONTAINER, fix_object(), FLAG_APPLIED, FMT64U, FOR_INV_FINISH, FOR_INV_PREPARE, llevError, LOG(), pay_from_container(), QUERY_FLAG, and query_money().

Referenced by cfapi_object_pay_amount().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pay_for_item()

int pay_for_item ( object op,
object pl,
uint64_t  reduction 
)

Player attemps to buy an item, if she has enough money then remove coins as needed from active containers.

Also handles bargaining experience.

Parameters
opobject to buy.
plplayer buying.
reductionpositive or null price reduction, must be below the price of the item.
Returns
1 if object was bought, 0 else.
Todo:
check if pl is a player, as query_money() expects a player.

Definition at line 444 of file shop.cpp.

References CONTAINER, FALSE, fix_object(), FLAG_APPLIED, FLAG_WAS_WIZ, FMT64U, FOR_INV_FINISH, FOR_INV_PREPARE, llevError, LOG(), pay_from_container(), QUERY_FLAG, query_money(), Settings::real_wiz, SET_FLAG, settings, and shop_price_buy().

Referenced by cfapi_object_pay_item(), and shop_pay_unpaid_callback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pay_from_container()

static uint64_t pay_from_container ( object pl,
object pouch,
uint64_t  to_pay 
)
static

This pays for the item, and takes the proper amount of money off the specified container (pouch or player), without recursing opened containers.

Parameters
plplayer paying.
pouchcontainer (pouch or player) to remove the coins from.
to_payrequired amount.
Returns
amount still not paid after using "pouch".

Definition at line 578 of file shop.cpp.

References add_value(), archetype::clone, coins, CONTAINER, find_archetype(), FOR_INV_FINISH, FOR_INV_PREPARE, if(), insert_objects(), llevError, LOG(), MONEY, object::name, object::nrof, NUM_COINS, object_copy(), object_free_drop_inventory(), object_new(), object_remove(), PLAYER, remove_value(), object::type, and object::value.

Referenced by pay_for_amount(), and pay_for_item().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ price_approx()

uint64_t price_approx ( const object obj,
object who 
)

Adjust the value of the given item based on the player's skills.

This function should only be used when calculating "you reckon" prices.

Parameters
objitem in question. Must not be NULL.
whoplayer trying to judge the value of the item. Must not be NULL.
Returns
approximate value of obj.

Definition at line 71 of file shop.cpp.

References object::count, find_skill_by_number(), get_typedata(), typedata::identifyskill, typedata::identifyskill2, object::level, llevError, LOG(), object::name, price_base(), and object::type.

Referenced by cost_approx_str().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ query_money()

uint64_t query_money ( const object op)

Determine the amount of money the given object contains, including what is inside containers.

Parameters
opPlayer or container object
Returns
Total amount of money inside

Definition at line 373 of file shop.cpp.

References CONTAINER, FLAG_APPLIED, FOR_INV_FINISH, FOR_INV_PREPARE, llevError, LOG(), MONEY, PLAYER, QUERY_FLAG, and object::type.

Referenced by can_pay(), cfapi_object_query_money(), pay_for_amount(), pay_for_item(), and shop_pay_unpaid_callback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ real_money_value()

static StringBuffer* real_money_value ( const object coin,
StringBuffer buf 
)
static

Returns a string representing the money's value, in plain coins.

Parameters
coincoin. Must be of type MONEY.
bufbuffer to append to. Must not be NULL.
Returns
buf with the value.

Definition at line 300 of file shop.cpp.

References buf, MONEY, object::name, object::name_pl, object::nrof, stringbuffer_append_printf(), and object::type.

Referenced by cost_approx_str().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ remove_value()

static int64_t remove_value ( object coin_objs[],
int64_t  remain 
)
static

This function removes a given amount from a list of coins.

Parameters
coin_objsthe list coins to remove from; the list must be ordered from least to most valuable coin.
remainthe value (in silver coins) to remove
Returns
the value remaining

Definition at line 485 of file shop.cpp.

References object::nrof, NUM_COINS, and object::value.

Referenced by pay_from_container().

+ Here is the caller graph for this function:

◆ sell_item()

void sell_item ( object op,
object pl 
)

Player is selling an item.

Give money, print appropriate messages.

Will fill applied money containers before dumping remaining coins in character's inventory.

Parameters
opobject to sell.
plplayer. Shouldn't be NULL or non player.

Definition at line 915 of file shop.cpp.

References change_exp(), archetype::clone, coins, compute_price_variation_with_bargaining(), CONTAINER, cost_str(), unpaid_count::count, CUSTOM_NAME_FIELD, draw_ext_info_format(), esrv_update_item(), EVENT_GSOLD, EVENT_SELLING, events_execute_global_event(), events_execute_object_event(), find_archetype(), FLAG_APPLIED, FLAG_UNPAID, FOR_INV_FINISH, FOR_INV_PREPARE, identify(), LARGEST_COIN_GIVEN, llevDebug, llevError, LOG(), MAX_BUF, MAX_SELL_EXTRA, MSG_TYPE_SHOP, MSG_TYPE_SHOP_SELL, NDI_UNIQUE, object::nrof, object_copy(), object_insert_in_ob(), object_new(), object_set_value(), unpaid_count::pl, PLAYER, unpaid_count::price, QUERY_FLAG, query_name(), SCRIPT_FIX_ALL, SET_FLAG, shop_price_sell(), SK_EXP_NONE, object::type, UPD_WEIGHT, object::value, and object::weight.

Referenced by drop_object().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shop_approval()

double shop_approval ( const mapstruct map,
const object player 
)

Return the approval ratio for a shop for a given player.

This is based on both the race of the shopkeeper and the player.

Parameters
mapMap with a shop
playerPlayer in question
Returns
Approval ratio between 0 and 1

Definition at line 1081 of file shop.cpp.

References NEUTRAL_RATIO, and mapstruct::shoprace.

Referenced by shop_describe(), shop_efficiency(), and shop_mat_type_move_on().

+ Here is the caller graph for this function:

◆ shop_cha_modifier()

static float shop_cha_modifier ( int  charisma)
static

Calculate the buy price multiplier based on a player's charisma.

Parameters
charismaplayer's charisma.
Returns
multiplier between 0 and 1

Definition at line 111 of file shop.cpp.

Referenced by shop_efficiency().

+ Here is the caller graph for this function:

◆ shop_describe()

int shop_describe ( const object op)

A player is examining a shop, so describe it.

Give the player a description of the shop on their current map.

Parameters
opwho is examining the shop.
Returns
0 if op is not a player, 1 else.

Definition at line 1144 of file shop.cpp.

References cost_str(), draw_ext_info, draw_ext_info_format(), shopitems::index, make_list_like(), object::map, MAX_BUF, MSG_TYPE_SHOP, MSG_TYPE_SHOP_LISTING, MSG_TYPE_SHOP_MISC, shopitems::name, shopitems::name_pl, NDI_UNIQUE, PLAYER, shop_approval(), mapstruct::shopgreed, mapstruct::shopitems, mapstruct::shopmax, mapstruct::shopmin, mapstruct::shoprace, shopitems::strength, and object::type.

Referenced by do_skill().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shop_efficiency()

float shop_efficiency ( const object player)

Return the shop's efficiency (E) for a player, a number greater than (but not equal to) zero and less than or equal to one.

When E is one, there is no buy/sell spread and the shop makes no money. When E is low, transaction costs to the player are high. Shops should pay players price*E for items and sell it to players for price/E.

Definition at line 122 of file shop.cpp.

References shop_approval(), shop_cha_modifier(), and shop_greed().

Referenced by shop_price_buy(), and shop_price_sell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shop_greed()

static double shop_greed ( const mapstruct map)
static

Gets a shop's greed.

For historical reasons, this is a number between 0 and 2. Use this to compute a base efficiency for a shop: 0 ~= 1.0 (shop makes no profit) 1 ~= 0.9 (a reasonably efficient market) 2 ~= 0.5 (2x more expensive items, pays 0.5x for items)

Caveat: most shops have greed unset (0), so make that 1

Parameters
mapmap to get greed.
Returns
greed of the shop on map, or 1 if it isn't specified.

Definition at line 1073 of file shop.cpp.

References mapstruct::shopgreed.

Referenced by shop_efficiency().

+ Here is the caller graph for this function:

◆ shop_pay_unpaid()

int shop_pay_unpaid ( object pl,
object op 
)

Pay as many unpaid items as possible, recursing on op->inv and op->below.

Pay for each unpaid item carried by a player, including those inside containers.

Parameters
plplayer who is buying items.
opfirst potentially unpaid item.
Returns
0 if some items were unpaid, 1 if all unpaid items (if any) were paid.

Definition at line 896 of file shop.cpp.

References unpaid_count::pl, shop_pay_unpaid_callback(), and unpaid_iter().

Referenced by shop_mat_type_move_on().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shop_pay_unpaid_callback()

◆ shop_price_buy()

uint64_t shop_price_buy ( const object obj,
object who 
)

Adjust the value of an item to be bought based on the player's bargaining skill and charisma.

This should only be used if the player is in a shop.

Parameters
objitem in question. Must not be NULL.
whoplayer trying to judge the value of the item. Must not be NULL.
Returns
value of obj.

Definition at line 128 of file shop.cpp.

References object::arch, llevDebug, LOG(), archetype::name, NROF(), object_get_value(), object_value_set(), PLAYER, price_base(), shop_efficiency(), and object::type.

Referenced by count_unpaid_callback(), examine(), pay_for_item(), pick_up_object(), and shop_pay_unpaid_callback().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shop_price_sell()

uint64_t shop_price_sell ( const object obj,
object who 
)

Adjust the value of an item to be sold based on the player's bargaining skill and charisma.

This should only be used if the player is in a shop.

Parameters
objitem in question. Must not be NULL.
whoplayer trying to judge the value of the item. Must not be NULL.
Returns
value of obj.

Definition at line 154 of file shop.cpp.

References object::arch, llevDebug, LOG(), object::map, archetype::name, NROF(), object_get_value(), PLAYER, price_base(), shop_efficiency(), shop_specialisation_ratio(), object::type, and value_limit().

Referenced by examine(), and sell_item().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shop_specialisation_ratio()

static double shop_specialisation_ratio ( const object item,
const mapstruct map 
)
static

Returns the ratio of the price that a shop will offer for an item based on the shop's specialisation.

The ratio is between (2*SPECIALISATION_EFFECT-1) and 1 and in any event is never less than 0.1 (calling functions divide by it). This ratio should multiply only the sell price, because incorrectly coded shops that generate items outside of specialty shouldn't give away items for very low prices.

Parameters
itemitem to get ratio of.
mapshop map.
Returns
ratio specialisation for the item.

Definition at line 1022 of file shop.cpp.

References shopitems::index, llevDebug, llevError, LOG(), mapstruct::path, mapstruct::shopitems, SPECIALISATION_EFFECT, shopitems::strength, object::type, and shopitems::typenum.

Referenced by shop_price_sell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unpaid_iter()

static void unpaid_iter ( object item,
void(*)(object *item, void *data callback,
void *  data 
)
static

Search for unpaid items in 'item' and call 'callback' on each item.

Parameters
itemWhere to search for unpaid items
dataData to pass to callback
callbackFunction to run for each unpaid item

Definition at line 695 of file shop.cpp.

References FLAG_UNPAID, FOR_OB_AND_BELOW_FINISH, FOR_OB_AND_BELOW_PREPARE, object::inv, and QUERY_FLAG.

Referenced by count_unpaid(), and shop_pay_unpaid().

+ Here is the caller graph for this function:

◆ value_limit()

static uint64_t value_limit ( uint64_t  val,
int  quantity,
const object who,
int  isshop 
)
static

Limit the value of items based on the wealth of the shop.

If the item is close to the maximum value a shop will offer, we start to reduce it, if the item is below the minimum value the shop is prepared to trade in, then we don't want it and offer nothing. If it isn't a shop, check whether we should do generic value reduction.

Parameters
valcurrent price.
quantitynumber of items.
whoplayer selling.
isshop0 if not a shop, 1 if a shop.
Returns
maximum global value.

Definition at line 1110 of file shop.cpp.

References isqrt(), llevError, LOG(), object::map, MIN, object::name, mapstruct::shopmax, and mapstruct::shopmin.

Referenced by shop_price_sell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ coins

const char* const coins[]
static
Initial value:
= {
"ambercoin",
"jadecoin",
"platinacoin",
"goldcoin",
"silvercoin",
NULL
}

Coins to use for shopping.

Definition at line 62 of file shop.cpp.

Referenced by can_pay(), count_coins(), find_next_coin(), pay_from_container(), and sell_item().