Crossfire Server, Trunk
shop.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int can_pay (object *pl)
 
char * cost_approx_str (const object *obj, object *who)
 
char * cost_str (uint64_t cost)
 
char * cost_string_from_value (uint64_t cost, int largest_coin)
 
int pay_for_amount (uint64_t to_pay, object *pl)
 
int pay_for_item (object *op, object *pl, uint64_t reduction)
 
uint64_t price_approx (const object *obj, object *who)
 
uint64_t price_base (const object *obj)
 
uint64_t query_money (const object *op)
 
void sell_item (object *op, object *pl)
 
double shop_approval (const mapstruct *map, const object *player)
 
bool shop_contains (object *ob)
 
int shop_describe (const object *op)
 
int shop_pay_unpaid (object *pl, object *op)
 
uint64_t shop_price_buy (const object *obj, object *who)
 
uint64_t shop_price_sell (const object *obj, object *who)
 

Function Documentation

◆ 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 841 of file shop.cpp.

References archininventory::arch, buf, coins, cost_str(), count_coins(), count_unpaid(), draw_ext_info(), find_archetype(), llevError, LOG(), make_list_like(), MAX_BUF, MSG_TYPE_SHOP, MSG_TYPE_SHOP_PAYMENT, NDI_UNIQUE, NUM_COINS, altar_valkyrie::pl, PLAYER, query_money(), and autojail::value.

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:

◆ 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 369 of file shop.cpp.

References buf, archetype::clone, diamondslots::cointype, 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(), Ice::tmp, object::value, and autojail::who.

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 365 of file shop.cpp.

References diamondslots::cost, 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 277 of file shop.cpp.

References buf, archetype::clone, diamondslots::cointype, diamondslots::cost, 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:

◆ 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 461 of file shop.cpp.

References CONTAINER, fix_object(), FLAG_APPLIED, FMT64U, FOR_INV_FINISH, FOR_INV_PREPARE, llevError, LOG(), pay_from_container(), altar_valkyrie::pl, 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 501 of file shop.cpp.

References CONTAINER, FALSE, fix_object(), FLAG_APPLIED, FLAG_WAS_WIZ, FMT64U, FOR_INV_FINISH, FOR_INV_PREPARE, llevError, LOG(), give::op, pay_from_container(), altar_valkyrie::pl, 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:

◆ 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 133 of file shop.cpp.

References find_skill_by_number(), get_typedata(), typedata::identifyskill, typedata::identifyskill2, object::level, llevError, LOG(), price_base(), Ice::tmp, and autojail::who.

Referenced by cost_approx_str().

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

◆ price_base()

uint64_t price_base ( const object obj)

Determine the base (intrinsic) value of an item. This should not include adjustments such as bargaining, charisma, or shop specialization.

Parameters
objitem in question.
Returns
base price.

Price an item based on its value or archetype value, type, identification/BUC status, and other heuristics.

Shopkeepers always know the BUC status of items. Adjust the base price of items based on their BUC status. Note that religious players can readily uncurse items, so don't make this too drastic.

Definition at line 75 of file shop.cpp.

References FLAG_BLESSED, FLAG_CURSED, FLAG_DAMNED, GEM, is_identified(), castle_read::key, MONEY, NROF(), altar_valkyrie::obj, object_get_value(), QUERY_FLAG, and WAND.

Referenced by alchemy_object(), attempt_do_alchemy(), check_pick(), price_approx(), shop_price_buy(), and shop_price_sell().

+ 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 430 of file shop.cpp.

References CONTAINER, FLAG_APPLIED, FOR_INV_FINISH, FOR_INV_PREPARE, llevError, LOG(), MONEY, give::op, PLAYER, QUERY_FLAG, Ice::tmp, and mail_login::total.

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:

◆ 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 966 of file shop.cpp.

References change_exp(), archetype::clone, coins, compute_price_variation_with_bargaining(), CONTAINER, cost_str(), disinfect::count, CUSTOM_NAME_FIELD, draw_ext_info_format(), esrv_update_item(), EVENT_SELLING, 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_copy(), object_insert_in_ob(), object_new(), object_set_value(), give::op, altar_valkyrie::pl, PLAYER, say::price, QUERY_FLAG, query_name(), SCRIPT_FIX_ALL, SET_FLAG, shop_price_sell(), SK_EXP_NONE, Ice::tmp, 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 1131 of file shop.cpp.

References disinfect::map, and NEUTRAL_RATIO.

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

+ Here is the caller graph for this function:

◆ shop_contains()

bool shop_contains ( object ob)

Check if an object is in a shop.

Definition at line 1296 of file shop.cpp.

References coords_in_shop(), and guildjoin::ob.

Referenced by do_item_conversion(), drop_object(), examine(), kill_player_not_permadeath(), shop_mat_type_move_on(), and transport_type_apply().

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

◆ shop_describe()

int shop_describe ( const object op)

Give the player a description of the shop on their current map. This is used for the bargaining skill.

Parameters
opNon-null player to describe the shop to
Returns
Zero if the object is not a player, 1 otherwise

A player is examining a shop, so describe it.

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

Definition at line 1194 of file shop.cpp.

References cost_str(), draw_ext_info(), draw_ext_info_format(), make_list_like(), disinfect::map, MAX_BUF, MSG_TYPE_SHOP, MSG_TYPE_SHOP_LISTING, MSG_TYPE_SHOP_MISC, NDI_UNIQUE, give::op, PLAYER, shop_approval(), Ice::tmp, and autojail::value.

Referenced by do_skill().

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

◆ shop_pay_unpaid()

int shop_pay_unpaid ( object pl,
object op 
)

Pay for each unpaid item carried by a player, including those inside containers. It is a good idea to call can_pay() before using this function, because items are paid for here in no particular order.

Parameters
plPlayer making purchase
opContainer to examine, usually the same player object
Return values
0Player still has unpaid items
1Player paid for all unpaid items

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

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 947 of file shop.cpp.

References give::op, altar_valkyrie::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_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 190 of file shop.cpp.

References castle_read::key, llevDebug, LOG(), object_get_value(), PLAYER, price_base(), shop_efficiency(), Ice::tmp, and autojail::who.

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 211 of file shop.cpp.

References castle_read::key, llevDebug, LOG(), NROF(), object_get_value(), PLAYER, price_base(), shop_efficiency(), shop_specialisation_ratio(), Ice::tmp, value_limit(), and autojail::who.

Referenced by examine(), sell_item(), and START_TEST().

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