OSDN Git Service

Merge pull request #2241 from sikabane-works/release/3.0.0Alpha53
[hengbandforosx/hengbandosx.git] / src / store / cmd-store.cpp
1 #include "cmd-io/macro-util.h"
2 #include "core/player-redraw-types.h"
3 #include "core/player-update-types.h"
4 #include "core/stuff-handler.h"
5 #include "core/window-redrawer.h"
6 #include "dungeon/dungeon.h"
7 #include "flavor/flavor-describer.h"
8 #include "floor/cave.h"
9 #include "floor/floor-events.h"
10 #include "floor/floor-town.h"
11 #include "floor/wild.h"
12 #include "game-option/birth-options.h"
13 #include "game-option/input-options.h"
14 #include "grid/feature.h"
15 #include "inventory/inventory-object.h"
16 #include "inventory/inventory-slot-types.h"
17 #include "io/input-key-requester.h"
18 #include "main/music-definitions-table.h"
19 #include "main/sound-of-music.h"
20 #include "object/object-info.h"
21 #include "player-status/player-energy.h"
22 #include "store/cmd-store.h"
23 #include "store/home.h"
24 #include "store/store-key-processor.h"
25 #include "store/store-owners.h"
26 #include "store/store-util.h"
27 #include "store/store.h"
28 #include "system/floor-type-definition.h"
29 #include "system/grid-type-definition.h"
30 #include "system/object-type-definition.h"
31 #include "system/player-type-definition.h"
32 #include "term/screen-processor.h"
33 #include "util/bit-flags-calculator.h"
34 #include "view/display-messages.h"
35 #include "view/display-store.h"
36 #include "world/world.h"
37
38 #define MIN_STOCK 12
39
40 /*!
41  * @brief 店舗処理全体のメインルーチン /
42  * Enter a store, and interact with it. *
43  * @param player_ptr プレイヤーへの参照ポインタ
44  * @note
45  * <pre>
46  * Note that we use the standard "request_command()" function
47  * to get a command, allowing us to use "command_arg" and all
48  * command macros and other nifty stuff, but we use the special
49  * "shopping" argument, to force certain commands to be converted
50  * into other commands, normally, we convert "p" (pray) and "m"
51  * (cast magic) into "g" (get), and "s" (search) into "d" (drop).
52  * </pre>
53  */
54 void do_cmd_store(PlayerType *player_ptr)
55 {
56     if (player_ptr->wild_mode)
57         return;
58     TERM_LEN w, h;
59     term_get_size(&w, &h);
60
61     xtra_stock = std::min(14 + 26, ((h > 24) ? (h - 24) : 0));
62     store_bottom = MIN_STOCK + xtra_stock;
63
64     grid_type *g_ptr;
65     g_ptr = &player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x];
66
67     if (!g_ptr->cave_has_flag(FloorFeatureType::STORE)) {
68         msg_print(_("ここには店がありません。", "You see no store here."));
69         return;
70     }
71
72     // TODO:
73     //   施設の種類により、一時的に現在地 (player_ptr->town_num) を違う値に偽装して処理している。
74     //   我が家および博物館は全ての町で内容を共有するため、現在地を辺境の地 (1) にしている。
75     //   ダンジョン内の店の場合、現在地を NO_TOWN にしている。
76     //   inner_town_num は、施設内で C コマンドなどを使ったときにそのままでは現在地の偽装がバレる
77     //   ため、それを糊塗するためのグローバル変数。
78     //   この辺はリファクタしたい。
79     StoreSaleType which = i2enum<StoreSaleType>(f_info[g_ptr->feat].subtype);
80     old_town_num = player_ptr->town_num;
81     if ((which == StoreSaleType::HOME) || (which == StoreSaleType::MUSEUM))
82         player_ptr->town_num = 1;
83     if (is_in_dungeon(player_ptr))
84         player_ptr->town_num = NO_TOWN;
85     inner_town_num = player_ptr->town_num;
86
87     if ((town_info[player_ptr->town_num].store[enum2i(which)].store_open >= w_ptr->game_turn) || ironman_shops) {
88         msg_print(_("ドアに鍵がかかっている。", "The doors are locked."));
89         player_ptr->town_num = old_town_num;
90         return;
91     }
92
93     int maintain_num = (w_ptr->game_turn - town_info[player_ptr->town_num].store[enum2i(which)].last_visit) / (TURNS_PER_TICK * STORE_TICKS);
94     if (maintain_num > 10)
95         maintain_num = 10;
96     if (maintain_num) {
97         store_maintenance(player_ptr, player_ptr->town_num, which, maintain_num);
98
99         town_info[player_ptr->town_num].store[enum2i(which)].last_visit = w_ptr->game_turn;
100     }
101
102     forget_lite(player_ptr->current_floor_ptr);
103     forget_view(player_ptr->current_floor_ptr);
104     w_ptr->character_icky_depth = 1;
105     command_arg = 0;
106     command_rep = 0;
107     command_new = 0;
108     get_com_no_macros = true;
109     cur_store_num = which;
110     cur_store_feat = g_ptr->feat;
111     st_ptr = &town_info[player_ptr->town_num].store[enum2i(cur_store_num)];
112     ot_ptr = &owners[enum2i(cur_store_num)][st_ptr->owner];
113     store_top = 0;
114     play_music(TERM_XTRA_MUSIC_BASIC, MUSIC_BASIC_BUILD);
115     display_store(player_ptr);
116     leave_store = false;
117
118     while (!leave_store) {
119         prt("", 1, 0);
120         clear_from(20 + xtra_stock);
121         prt(_(" ESC) 建物から出る", " ESC) Exit from Building."), 21 + xtra_stock, 0);
122         if (st_ptr->stock_num > store_bottom) {
123             prt(_(" -)前ページ", " -) Previous page"), 22 + xtra_stock, 0);
124             prt(_(" スペース) 次ページ", " SPACE) Next page"), 23 + xtra_stock, 0);
125         }
126
127         if (cur_store_num == StoreSaleType::HOME) {
128             prt(_("g) アイテムを取る", "g) Get an item."), 21 + xtra_stock, 27);
129             prt(_("d) アイテムを置く", "d) Drop an item."), 22 + xtra_stock, 27);
130             prt(_("x) 家のアイテムを調べる", "x) eXamine an item in the home."), 23 + xtra_stock, 27);
131         } else if (cur_store_num == StoreSaleType::MUSEUM) {
132             prt(_("d) アイテムを置く", "d) Drop an item."), 21 + xtra_stock, 27);
133             prt(_("r) アイテムの展示をやめる", "r) order to Remove an item."), 22 + xtra_stock, 27);
134             prt(_("x) 博物館のアイテムを調べる", "x) eXamine an item in the museum."), 23 + xtra_stock, 27);
135         } else {
136             prt(_("p) 商品を買う", "p) Purchase an item."), 21 + xtra_stock, 30);
137             prt(_("s) アイテムを売る", "s) Sell an item."), 22 + xtra_stock, 30);
138             prt(_("x) 商品を調べる", "x) eXamine an item in the shop"), 23 + xtra_stock, 30);
139         }
140
141         prt(_("i/e) 持ち物/装備の一覧", "i/e) Inventry/Equipment list"), 21 + xtra_stock, 56);
142         if (rogue_like_commands)
143             prt(_("w/T) 装備する/はずす", "w/T) Wear/Take off equipment"), 22 + xtra_stock, 56);
144         else
145             prt(_("w/t) 装備する/はずす", "w/t) Wear/Take off equipment"), 22 + xtra_stock, 56);
146
147         prt(_("コマンド:", "You may: "), 20 + xtra_stock, 0);
148         request_command(player_ptr, true);
149         store_process_command(player_ptr);
150
151         bool need_redraw_store_inv = any_bits(player_ptr->update, PU_BONUS);
152         w_ptr->character_icky_depth = 1;
153         handle_stuff(player_ptr);
154         if (player_ptr->inventory_list[INVEN_PACK].k_idx) {
155             INVENTORY_IDX item = INVEN_PACK;
156             auto *o_ptr = &player_ptr->inventory_list[item];
157             if (cur_store_num != StoreSaleType::HOME) {
158                 if (cur_store_num == StoreSaleType::MUSEUM)
159                     msg_print(_("ザックからアイテムがあふれそうなので、あわてて博物館から出た...", "Your pack is so full that you flee the Museum..."));
160                 else
161                     msg_print(_("ザックからアイテムがあふれそうなので、あわてて店から出た...", "Your pack is so full that you flee the store..."));
162
163                 leave_store = true;
164             } else if (!store_check_num(o_ptr)) {
165                 msg_print(_("ザックからアイテムがあふれそうなので、あわてて家から出た...", "Your pack is so full that you flee your home..."));
166                 leave_store = true;
167             } else {
168                 int item_pos;
169                 ObjectType forge;
170                 ObjectType *q_ptr;
171                 GAME_TEXT o_name[MAX_NLEN];
172                 msg_print(_("ザックからアイテムがあふれてしまった!", "Your pack overflows!"));
173                 q_ptr = &forge;
174                 q_ptr->copy_from(o_ptr);
175                 describe_flavor(player_ptr, o_name, q_ptr, 0);
176                 msg_format(_("%sが落ちた。(%c)", "You drop %s (%c)."), o_name, index_to_label(item));
177                 vary_item(player_ptr, item, -255);
178                 handle_stuff(player_ptr);
179
180                 item_pos = home_carry(player_ptr, q_ptr);
181                 if (item_pos >= 0) {
182                     store_top = (item_pos / store_bottom) * store_bottom;
183                     display_store_inventory(player_ptr);
184                 }
185             }
186         }
187
188         if (need_redraw_store_inv)
189             display_store_inventory(player_ptr);
190
191         if (st_ptr->store_open >= w_ptr->game_turn)
192             leave_store = true;
193     }
194
195     // 現在地の偽装を解除。
196     player_ptr->town_num = old_town_num;
197
198     select_floor_music(player_ptr);
199     PlayerEnergy(player_ptr).set_player_turn_energy(100);
200     w_ptr->character_icky_depth = 0;
201     command_new = 0;
202     command_see = false;
203     get_com_no_macros = false;
204
205     msg_erase();
206     term_clear();
207
208     player_ptr->update |= PU_VIEW | PU_LITE | PU_MON_LITE;
209     player_ptr->update |= PU_MONSTERS;
210     player_ptr->redraw |= PR_BASIC | PR_EXTRA | PR_EQUIPPY;
211     player_ptr->redraw |= PR_MAP;
212     player_ptr->window_flags |= PW_OVERHEAD | PW_DUNGEON;
213 }