OSDN Git Service

[Refactor] #40233 Separated pricing.c/h from store.c/h
[hengband/hengband.git] / src / store / pricing.c
1 #include "store/pricing.h"
2 #include "market/gold-magnification-table.h"
3 #include "object/object-value.h"
4 #include "store/store-util.h"
5 #include "store/store.h"
6
7 /*!
8  * @brief 店舗価格を決定する. 無料にはならない /
9  * Determine the price of an item (qty one) in a store.
10  * @param o_ptr 店舗に並べるオブジェクト構造体の参照ポインタ
11  * @param greed 店主の強欲度
12  * @param flip TRUEならば店主にとっての買取価格、FALSEなら売出価格を計算
13  * @return アイテムの店舗価格
14  * @details
15  * <pre>
16  * This function takes into account the player's charisma, and the
17  * shop-keepers friendliness, and the shop-keeper's base greed, but
18  * never lets a shop-keeper lose money in a transaction.
19  * The "greed" value should exceed 100 when the player is "buying" the
20  * item, and should be less than 100 when the player is "selling" it.
21  * Hack -- the black market always charges twice as much as it should.
22  * Charisma adjustment runs from 80 to 130
23  * Racial adjustment runs from 95 to 130
24  * Since greed/charisma/racial adjustments are centered at 100, we need
25  * to adjust (by 200) to extract a usable multiplier.  Note that the
26  * "greed" value is always something (?).
27  * </pre>
28  */
29 PRICE price_item(player_type *player_ptr, object_type *o_ptr, int greed, bool flip)
30 {
31     PRICE price = object_value(player_ptr, o_ptr);
32     if (price <= 0)
33         return 0L;
34
35     int factor = rgold_adj[ot_ptr->owner_race][player_ptr->prace];
36     factor += adj_chr_gold[player_ptr->stat_ind[A_CHR]];
37     int adjust;
38     if (flip) {
39         adjust = 100 + (300 - (greed + factor));
40         if (adjust > 100)
41             adjust = 100;
42
43         if (cur_store_num == STORE_BLACK)
44             price = price / 2;
45
46         price = (price * adjust + 50L) / 100L;
47     } else {
48         adjust = 100 + ((greed + factor) - 300);
49         if (adjust < 100)
50             adjust = 100;
51
52         if (cur_store_num == STORE_BLACK)
53             price = price * 2;
54
55         price = (s32b)(((u32b)price * (u32b)adjust + 50UL) / 100UL);
56     }
57
58     if (price <= 0L)
59         return 1L;
60
61     return price;
62 }
63
64 /*!
65  * @brief 店舗の割引対象外にするかどうかを判定 /
66  * Eliminate need to bargain if player has haggled well in the past
67  * @param minprice アイテムの最低販売価格
68  * @return 割引を禁止するならTRUEを返す。
69  */
70 bool noneedtobargain(PRICE minprice)
71 {
72     PRICE good = st_ptr->good_buy;
73     PRICE bad = st_ptr->bad_buy;
74     return (minprice < 10L) || (good == MAX_SHORT) || (good > ((3 * bad) + (5 + (minprice / 50))));
75 }