1 #include "inventory/player-inventory.h"
2 #include "autopick/autopick.h"
3 #include "core/asking-player.h"
4 #include "core/disturbance.h"
5 #include "core/player-redraw-types.h"
6 #include "core/player-update-types.h"
7 #include "core/stuff-handler.h"
8 #include "core/window-redrawer.h"
9 #include "dungeon/quest.h"
10 #include "flavor/flavor-describer.h"
11 #include "flavor/object-flavor-types.h"
12 #include "floor/floor-object.h"
13 #include "floor/object-scanner.h"
14 #include "game-option/auto-destruction-options.h"
15 #include "game-option/birth-options.h"
16 #include "game-option/input-options.h"
17 #include "game-option/play-record-options.h"
18 #include "game-option/text-display-options.h"
19 #include "inventory/inventory-object.h"
20 #include "inventory/inventory-slot-types.h"
21 #include "main/sound-definitions-table.h"
22 #include "main/sound-of-music.h"
23 #include "object/item-tester-hooker.h"
24 #include "object/item-use-flags.h"
25 #include "object/object-info.h"
26 #include "object/object-mark-types.h"
27 #include "player/player-move.h"
28 #include "spell-kind/spells-perception.h"
29 #include "system/floor-type-definition.h"
30 #include "system/grid-type-definition.h"
31 #include "system/item-entity.h"
32 #include "system/player-type-definition.h"
33 #include "target/target-checker.h"
34 #include "term/z-form.h"
35 #include "view/display-messages.h"
36 #include "world/world.h"
38 #include "artifact/fixed-art-types.h"
39 #include "flavor/flavor-util.h"
43 * @brief 規定の処理にできるアイテムがプレイヤーの利用可能範囲内にあるかどうかを返す /
44 * Determine whether get_item() can get some item or not
45 * @return アイテムを拾えるならばTRUEを返す。
46 * @details assuming mode = (USE_EQUIP | USE_INVEN | USE_FLOOR).
48 bool can_get_item(PlayerType *player_ptr, const ItemTester &item_tester)
50 for (int j = 0; j < INVEN_TOTAL; j++) {
51 if (item_tester.okay(&player_ptr->inventory_list[j])) {
56 OBJECT_IDX floor_list[23];
57 ITEM_NUMBER floor_num = scan_floor_items(player_ptr, floor_list, player_ptr->y, player_ptr->x, SCAN_FLOOR_ITEM_TESTER | SCAN_FLOOR_ONLY_MARKED, item_tester);
58 return floor_num != 0;
62 * @brief 床上のアイテムを拾う選択用サブルーチン
63 * @return プレイヤーによりアイテムが選択されたならTRUEを返す。
65 static bool py_pickup_floor_aux(PlayerType *player_ptr)
67 OBJECT_IDX this_o_idx;
69 concptr q = _("どれを拾いますか?", "Get which item? ");
70 concptr s = _("もうザックには床にあるどのアイテムも入らない。", "You no longer have any room for the objects on the floor.");
71 if (choose_object(player_ptr, &item, q, s, (USE_FLOOR), FuncItemTester(check_store_item_to_inventory, player_ptr))) {
72 this_o_idx = 0 - item;
77 describe_pickup_item(player_ptr, this_o_idx);
82 * @brief 床上のアイテムを拾うメイン処理
83 * @param pickup FALSEなら金銭の自動拾いのみを行う/ FALSE then only gold will be picked up
85 * This is called by py_pickup() when easy_floor is TRUE.
87 void py_pickup_floor(PlayerType *player_ptr, bool pickup)
89 GAME_TEXT o_name[MAX_NLEN];
92 OBJECT_IDX floor_o_idx = 0;
94 auto &o_idx_list = player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x].o_idx_list;
95 for (auto it = o_idx_list.begin(); it != o_idx_list.end();) {
96 const OBJECT_IDX this_o_idx = *it++;
97 o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx];
98 describe_flavor(player_ptr, o_name, o_ptr, 0);
99 disturb(player_ptr, false, false);
100 if (o_ptr->bi_key.tval() == ItemKindType::GOLD) {
101 msg_format(_(" $%ld の価値がある%sを見つけた。", "You have found %ld gold pieces worth of %s."), (long)o_ptr->pval, o_name);
103 player_ptr->au += o_ptr->pval;
104 player_ptr->redraw |= (PR_GOLD);
105 player_ptr->window_flags |= (PW_PLAYER);
106 delete_object_idx(player_ptr, this_o_idx);
108 } else if (o_ptr->marked.has(OmType::SUPRESS_MESSAGE)) {
109 o_ptr->marked.reset(OmType::SUPRESS_MESSAGE);
113 if (check_store_item_to_inventory(player_ptr, o_ptr)) {
118 floor_o_idx = this_o_idx;
126 if (floor_num == 1) {
127 o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx];
128 describe_flavor(player_ptr, o_name, o_ptr, 0);
129 msg_format(_("%sがある。", "You see %s."), o_name);
131 msg_format(_("%d 個のアイテムの山がある。", "You see a pile of %d items."), floor_num);
138 if (floor_num == 1) {
139 o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx];
140 describe_flavor(player_ptr, o_name, o_ptr, 0);
141 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
143 msg_print(_("ザックには床にあるどのアイテムも入らない。", "You have no room for any of the objects on the floor."));
149 if (floor_num != 1) {
150 while (can_pickup--) {
151 if (!py_pickup_floor_aux(player_ptr)) {
159 if (carry_query_flag) {
160 char out_val[MAX_NLEN + 20];
161 o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx];
162 describe_flavor(player_ptr, o_name, o_ptr, 0);
163 strnfmt(out_val, sizeof(out_val), _("%sを拾いますか? ", "Pick up %s? "), o_name);
164 if (!get_check(out_val)) {
169 o_ptr = &player_ptr->current_floor_ptr->o_list[floor_o_idx];
170 describe_pickup_item(player_ptr, floor_o_idx);
174 * @brief プレイヤーがオブジェクトを拾った際のメッセージ表示処理 /
175 * Helper routine for py_pickup() and py_pickup_floor().
176 * @param player_ptr プレイヤーへの参照ポインタ
177 * @param o_idx 取得したオブジェクトの参照ID
179 * アイテムを拾った際に「2つのケーキを持っている」
180 * "You have two cakes." とアイテムを拾った後の合計のみの表示がオリジナルだが、
181 * 違和感があるという指摘をうけたので、「~を拾った、~を持っている」という表示にかえてある。
183 * Add the given dungeon object to the character's inventory.\n
184 * Delete the object afterwards.\n
186 void describe_pickup_item(PlayerType *player_ptr, OBJECT_IDX o_idx)
189 GAME_TEXT o_name[MAX_NLEN];
190 GAME_TEXT old_name[MAX_NLEN];
192 GAME_TEXT o_name[MAX_NLEN];
196 o_ptr = &player_ptr->current_floor_ptr->o_list[o_idx];
199 describe_flavor(player_ptr, old_name, o_ptr, OD_NAME_ONLY);
200 const auto picked_count_str = describe_count_with_counter_suffix(*o_ptr);
201 const auto picked_count = o_ptr->number;
204 INVENTORY_IDX slot = store_item_to_inventory(player_ptr, o_ptr);
205 o_ptr = &player_ptr->inventory_list[slot];
206 delete_object_idx(player_ptr, o_idx);
207 if (player_ptr->ppersonality == PERSONALITY_MUNCHKIN) {
208 bool old_known = identify_item(player_ptr, o_ptr);
209 autopick_alter_item(player_ptr, slot, (bool)(destroy_identify && !old_known));
210 if (o_ptr->marked.has(OmType::AUTODESTROY)) {
215 describe_flavor(player_ptr, o_name, o_ptr, 0);
218 if (o_ptr->is_specific_artifact(FixedArtifactId::CRIMSON) && (player_ptr->ppersonality == PERSONALITY_COMBAT)) {
219 msg_format("こうして、%sは『クリムゾン』を手に入れた。", player_ptr->name);
220 msg_print("しかし今、『混沌のサーペント』の放ったモンスターが、");
221 msg_format("%sに襲いかかる...", player_ptr->name);
224 msg_format("%s(%c)を持っている。", o_name, index_to_label(slot));
226 if (o_ptr->number > picked_count) {
227 msg_format("%s拾って、%s(%c)を持っている。", picked_count_str.data(), o_name, index_to_label(slot));
229 msg_format("%s(%c)を拾った。", o_name, index_to_label(slot));
234 strcpy(record_o_name, old_name);
236 msg_format("You have %s (%c).", o_name, index_to_label(slot));
237 strcpy(record_o_name, o_name);
239 record_turn = w_ptr->game_turn;
240 check_find_art_quest_completion(player_ptr, o_ptr);
244 * @brief プレイヤーがオブジェクト上に乗った際の表示処理 / Player "wants" to pick up an object or gold.
245 * @param player_ptr プレイヤーへの参照ポインタ
246 * @param pickup 自動拾い処理を行うならばTRUEとする
248 void carry(PlayerType *player_ptr, bool pickup)
250 verify_panel(player_ptr);
251 player_ptr->update |= PU_MONSTERS;
252 player_ptr->redraw |= PR_MAP;
253 player_ptr->window_flags |= PW_OVERHEAD;
254 handle_stuff(player_ptr);
255 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[player_ptr->y][player_ptr->x];
256 autopick_pickup_items(player_ptr, g_ptr);
258 py_pickup_floor(player_ptr, pickup);
262 for (auto it = g_ptr->o_idx_list.begin(); it != g_ptr->o_idx_list.end();) {
263 const OBJECT_IDX this_o_idx = *it++;
265 o_ptr = &player_ptr->current_floor_ptr->o_list[this_o_idx];
266 GAME_TEXT o_name[MAX_NLEN];
267 describe_flavor(player_ptr, o_name, o_ptr, 0);
268 disturb(player_ptr, false, false);
269 if (o_ptr->bi_key.tval() == ItemKindType::GOLD) {
270 int value = (long)o_ptr->pval;
271 delete_object_idx(player_ptr, this_o_idx);
272 msg_format(_(" $%ld の価値がある%sを見つけた。", "You collect %ld gold pieces worth of %s."), (long)value, o_name);
274 player_ptr->au += value;
275 player_ptr->redraw |= (PR_GOLD);
276 player_ptr->window_flags |= (PW_PLAYER);
280 if (o_ptr->marked.has(OmType::SUPRESS_MESSAGE)) {
281 o_ptr->marked.reset(OmType::SUPRESS_MESSAGE);
286 msg_format(_("%sがある。", "You see %s."), o_name);
290 if (!check_store_item_to_inventory(player_ptr, o_ptr)) {
291 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
295 int is_pickup_successful = true;
296 if (carry_query_flag) {
297 char out_val[MAX_NLEN + 20];
298 strnfmt(out_val, sizeof(out_val), _("%sを拾いますか? ", "Pick up %s? "), o_name);
299 is_pickup_successful = get_check(out_val);
302 if (is_pickup_successful) {
303 describe_pickup_item(player_ptr, this_o_idx);