OSDN Git Service

[Refactor] struct player_type を class PlayerType に置換。
[hengbandforosx/hengbandosx.git] / src / view / display-store.cpp
1 #include "view/display-store.h"
2 #include "flavor/flavor-describer.h"
3 #include "game-option/birth-options.h"
4 #include "game-option/special-options.h"
5 #include "game-option/text-display-options.h"
6 #include "grid/feature.h"
7 #include "locale/japanese.h"
8 #include "object-enchant/special-object-flags.h"
9 #include "object/object-info.h"
10 #include "object/object-kind.h"
11 #include "player/race-info-table.h"
12 #include "store/pricing.h"
13 #include "store/store-owners.h"
14 #include "store/store-util.h"
15 #include "store/store.h" //!< @todo 相互依存している、こっちは残す?.
16 #include "system/object-type-definition.h"
17 #include "system/player-type-definition.h"
18 #include "term/gameterm.h"
19 #include "term/screen-processor.h"
20 #include "util/enum-converter.h"
21 #include "util/int-char-converter.h"
22
23 /*!
24  * @brief プレイヤーの所持金を表示する /
25  * Displays players gold                                        -RAK-
26  * @param player_ptr プレイヤーへの参照ポインタ
27  * @details
28  */
29 void store_prt_gold(PlayerType *player_ptr)
30 {
31     prt(_("手持ちのお金: ", "Gold Remaining: "), 19 + xtra_stock, 53);
32     char out_val[64];
33     sprintf(out_val, "%9ld", (long)player_ptr->au);
34     prt(out_val, 19 + xtra_stock, 68);
35 }
36
37 /*!
38  * @brief 店の商品リストを再表示する /
39  * Re-displays a single store entry
40  * @param player_ptr プレイヤーへの参照ポインタ
41  * @param pos 表示行
42  */
43 void display_entry(PlayerType *player_ptr, int pos)
44 {
45     object_type *o_ptr;
46     o_ptr = &st_ptr->stock[pos];
47     int i = (pos % store_bottom);
48
49     /* Label it, clear the line --(-- */
50     char out_val[160];
51     (void)sprintf(out_val, "%c) ", ((i > 25) ? toupper(I2A(i - 26)) : I2A(i)));
52     prt(out_val, i + 6, 0);
53
54     int cur_col = 3;
55     if (show_item_graph) {
56         TERM_COLOR a = object_attr(o_ptr);
57         SYMBOL_CODE c = object_char(o_ptr);
58
59         term_queue_bigchar(cur_col, i + 6, a, c, 0, 0);
60         if (use_bigtile)
61             cur_col++;
62
63         cur_col += 2;
64     }
65
66     /* Describe an item in the home */
67     int maxwid = 75;
68     if ((cur_store_num == StoreSaleType::HOME) || (cur_store_num == StoreSaleType::MUSEUM)) {
69         maxwid = 75;
70         if (show_weights)
71             maxwid -= 10;
72
73         GAME_TEXT o_name[MAX_NLEN];
74         describe_flavor(player_ptr, o_name, o_ptr, 0);
75         o_name[maxwid] = '\0';
76         c_put_str(tval_to_attr[enum2i(o_ptr->tval)], o_name, i + 6, cur_col);
77         if (show_weights) {
78             WEIGHT wgt = o_ptr->weight;
79             sprintf(out_val, _("%3d.%1d kg", "%3d.%d lb"), _(lb_to_kg_integer(wgt), wgt / 10), _(lb_to_kg_fraction(wgt), wgt % 10));
80             put_str(out_val, i + 6, _(67, 68));
81         }
82
83         return;
84     }
85
86     maxwid = 65;
87     if (show_weights)
88         maxwid -= 7;
89
90     GAME_TEXT o_name[MAX_NLEN];
91     describe_flavor(player_ptr, o_name, o_ptr, 0);
92     o_name[maxwid] = '\0';
93     c_put_str(tval_to_attr[enum2i(o_ptr->tval)], o_name, i + 6, cur_col);
94
95     if (show_weights) {
96         int wgt = o_ptr->weight;
97         sprintf(out_val, "%3d.%1d", _(lb_to_kg_integer(wgt), wgt / 10), _(lb_to_kg_fraction(wgt), wgt % 10));
98         put_str(out_val, i + 6, _(60, 61));
99     }
100
101     const auto price = price_item(player_ptr, o_ptr, ot_ptr->inflate, false);
102
103     (void)sprintf(out_val, "%9ld  ", (long)price);
104     put_str(out_val, i + 6, 68);
105 }
106
107 /*!
108  * @brief 店の商品リストを表示する /
109  * Displays a store's inventory -RAK-
110  * @param player_ptr プレイヤーへの参照ポインタ
111  * @details
112  * All prices are listed as "per individual object".  -BEN-
113  */
114 void display_store_inventory(PlayerType *player_ptr)
115 {
116     int k;
117     for (k = 0; k < store_bottom; k++) {
118         if (store_top + k >= st_ptr->stock_num)
119             break;
120
121         display_entry(player_ptr, store_top + k);
122     }
123
124     for (int i = k; i < store_bottom + 1; i++)
125         prt("", i + 6, 0);
126
127     put_str(_("          ", "        "), 5, _(20, 22));
128     if (st_ptr->stock_num > store_bottom) {
129         prt(_("-続く-", "-more-"), k + 6, 3);
130         put_str(format(_("(%dページ)  ", "(Page %d)  "), store_top / store_bottom + 1), 5, _(20, 22));
131     }
132
133     if (cur_store_num == StoreSaleType::HOME || cur_store_num == StoreSaleType::MUSEUM) {
134         k = st_ptr->stock_size;
135         if (cur_store_num == StoreSaleType::HOME && !powerup_home)
136             k /= 10;
137
138         put_str(format(_("アイテム数:  %4d/%4d", "Objects:  %4d/%4d"), st_ptr->stock_num, k), 19 + xtra_stock, _(27, 30));
139     }
140 }
141
142 /*!
143  * @brief 店舗情報全体を表示するメインルーチン /
144  * Displays store (after clearing screen)               -RAK-
145  * @param player_ptr プレイヤーへの参照ポインタ
146  * @details
147  */
148 void display_store(PlayerType *player_ptr)
149 {
150     term_clear();
151     if (cur_store_num == StoreSaleType::HOME) {
152         put_str(_("我が家", "Your Home"), 3, 31);
153         put_str(_("アイテムの一覧", "Item Description"), 5, 4);
154         if (show_weights) {
155             put_str(_("  重さ", "Weight"), 5, 70);
156         }
157
158         store_prt_gold(player_ptr);
159         display_store_inventory(player_ptr);
160         return;
161     }
162
163     if (cur_store_num == StoreSaleType::MUSEUM) {
164         put_str(_("博物館", "Museum"), 3, 31);
165         put_str(_("アイテムの一覧", "Item Description"), 5, 4);
166         if (show_weights) {
167             put_str(_("  重さ", "Weight"), 5, 70);
168         }
169
170         store_prt_gold(player_ptr);
171         display_store_inventory(player_ptr);
172         return;
173     }
174
175     concptr store_name = f_info[cur_store_feat].name.c_str();
176     concptr owner_name = (ot_ptr->owner_name);
177     concptr race_name = race_info[enum2i(ot_ptr->owner_race)].title;
178     char buf[80];
179     sprintf(buf, "%s (%s)", owner_name, race_name);
180     put_str(buf, 3, 10);
181
182     sprintf(buf, "%s (%ld)", store_name, (long)(ot_ptr->max_cost));
183     prt(buf, 3, 50);
184
185     put_str(_("商品の一覧", "Item Description"), 5, 5);
186     if (show_weights)
187         put_str(_("  重さ", "Weight"), 5, 60);
188
189     put_str(_(" 価格", "Price"), 5, 72);
190     store_prt_gold(player_ptr);
191     display_store_inventory(player_ptr);
192 }