OSDN Git Service

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