OSDN Git Service

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