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 "grid/grid.h"
20 #include "inventory/inventory-object.h"
21 #include "inventory/inventory-slot-types.h"
22 #include "main/sound-definitions-table.h"
23 #include "main/sound-of-music.h"
24 #include "object/item-tester-hooker.h"
25 #include "object/item-use-flags.h"
26 #include "object/object-info.h"
27 #include "object/object-mark-types.h"
28 #include "player/player-move.h"
29 #include "spell-kind/spells-perception.h"
30 #include "system/floor-type-definition.h"
31 #include "system/object-type-definition.h"
32 #include "system/player-type-definition.h"
33 #include "target/target-checker.h"
34 #include "view/display-messages.h"
35 #include "world/world.h"
37 #include "artifact/fixed-art-types.h"
38 #include "flavor/flavor-util.h"
42 * @brief 規定の処理にできるアイテムがプレイヤーの利用可能範囲内にあるかどうかを返す /
43 * Determine whether get_item() can get some item or not
44 * @return アイテムを拾えるならばTRUEを返す。
45 * @details assuming mode = (USE_EQUIP | USE_INVEN | USE_FLOOR).
47 bool can_get_item(player_type *owner_ptr, tval_type tval)
49 for (int j = 0; j < INVEN_TOTAL; j++)
50 if (item_tester_okay(owner_ptr, &owner_ptr->inventory_list[j], tval))
53 OBJECT_IDX floor_list[23];
54 ITEM_NUMBER floor_num = scan_floor_items(owner_ptr, floor_list, owner_ptr->y, owner_ptr->x, SCAN_FLOOR_ITEM_TESTER | SCAN_FLOOR_ONLY_MARKED, tval);
55 return floor_num != 0;
59 * @brief 床上のアイテムを拾う選択用サブルーチン
60 * @return プレイヤーによりアイテムが選択されたならTRUEを返す。
62 static bool py_pickup_floor_aux(player_type *owner_ptr)
64 OBJECT_IDX this_o_idx;
66 item_tester_hook = check_store_item_to_inventory;
67 concptr q = _("どれを拾いますか?", "Get which item? ");
68 concptr s = _("もうザックには床にあるどのアイテムも入らない。", "You no longer have any room for the objects on the floor.");
69 if (choose_object(owner_ptr, &item, q, s, (USE_FLOOR), TV_NONE))
70 this_o_idx = 0 - item;
74 describe_pickup_item(owner_ptr, this_o_idx);
79 * @brief 床上のアイテムを拾うメイン処理
80 * @param pickup FALSEなら金銭の自動拾いのみを行う/ FALSE then only gold will be picked up
82 * This is called by py_pickup() when easy_floor is TRUE.
84 void py_pickup_floor(player_type *owner_ptr, bool pickup)
86 GAME_TEXT o_name[MAX_NLEN];
89 OBJECT_IDX floor_o_idx = 0;
91 auto &o_idx_list = owner_ptr->current_floor_ptr->grid_array[owner_ptr->y][owner_ptr->x].o_idx_list;
92 for (auto it = o_idx_list.begin(); it != o_idx_list.end();) {
93 const OBJECT_IDX this_o_idx = *it++;
94 o_ptr = &owner_ptr->current_floor_ptr->o_list[this_o_idx];
95 describe_flavor(owner_ptr, o_name, o_ptr, 0);
96 disturb(owner_ptr, false, false);
97 if (o_ptr->tval == TV_GOLD) {
98 msg_format(_(" $%ld の価値がある%sを見つけた。", "You have found %ld gold pieces worth of %s."), (long)o_ptr->pval, o_name);
100 owner_ptr->au += o_ptr->pval;
101 owner_ptr->redraw |= (PR_GOLD);
102 owner_ptr->window_flags |= (PW_PLAYER);
103 delete_object_idx(owner_ptr, this_o_idx);
105 } else if (o_ptr->marked & OM_NOMSG) {
106 o_ptr->marked &= ~(OM_NOMSG);
110 if (check_store_item_to_inventory(owner_ptr, o_ptr))
114 floor_o_idx = this_o_idx;
121 if (floor_num == 1) {
122 o_ptr = &owner_ptr->current_floor_ptr->o_list[floor_o_idx];
123 describe_flavor(owner_ptr, o_name, o_ptr, 0);
124 msg_format(_("%sがある。", "You see %s."), o_name);
126 msg_format(_("%d 個のアイテムの山がある。", "You see a pile of %d items."), floor_num);
132 if (floor_num == 1) {
133 o_ptr = &owner_ptr->current_floor_ptr->o_list[floor_o_idx];
134 describe_flavor(owner_ptr, o_name, o_ptr, 0);
135 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
137 msg_print(_("ザックには床にあるどのアイテムも入らない。", "You have no room for any of the objects on the floor."));
142 if (floor_num != 1) {
144 if (!py_pickup_floor_aux(owner_ptr))
150 if (carry_query_flag) {
151 char out_val[MAX_NLEN + 20];
152 o_ptr = &owner_ptr->current_floor_ptr->o_list[floor_o_idx];
153 describe_flavor(owner_ptr, o_name, o_ptr, 0);
154 (void)sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name);
155 if (!get_check(out_val))
159 o_ptr = &owner_ptr->current_floor_ptr->o_list[floor_o_idx];
160 describe_pickup_item(owner_ptr, floor_o_idx);
164 * @brief プレイヤーがオブジェクトを拾った際のメッセージ表示処理 /
165 * Helper routine for py_pickup() and py_pickup_floor().
166 * @param creature_ptr プレーヤーへの参照ポインタ
167 * @param o_idx 取得したオブジェクトの参照ID
169 * アイテムを拾った際に「2つのケーキを持っている」
170 * "You have two cakes." とアイテムを拾った後の合計のみの表示がオリジナルだが、
171 * 違和感があるという指摘をうけたので、「~を拾った、~を持っている」という表示にかえてある。
173 * Add the given dungeon object to the character's inventory.\n
174 * Delete the object afterwards.\n
176 void describe_pickup_item(player_type *owner_ptr, OBJECT_IDX o_idx)
179 GAME_TEXT o_name[MAX_NLEN];
180 GAME_TEXT old_name[MAX_NLEN];
184 GAME_TEXT o_name[MAX_NLEN];
188 o_ptr = &owner_ptr->current_floor_ptr->o_list[o_idx];
191 describe_flavor(owner_ptr, old_name, o_ptr, OD_NAME_ONLY);
192 object_desc_count_japanese(kazu_str, o_ptr);
193 hirottakazu = o_ptr->number;
196 INVENTORY_IDX slot = store_item_to_inventory(owner_ptr, o_ptr);
197 o_ptr = &owner_ptr->inventory_list[slot];
198 delete_object_idx(owner_ptr, o_idx);
199 if (owner_ptr->pseikaku == PERSONALITY_MUNCHKIN) {
200 bool old_known = identify_item(owner_ptr, o_ptr);
201 autopick_alter_item(owner_ptr, slot, (bool)(destroy_identify && !old_known));
202 if (o_ptr->marked & OM_AUTODESTROY)
206 describe_flavor(owner_ptr, o_name, o_ptr, 0);
209 if ((o_ptr->name1 == ART_CRIMSON) && (owner_ptr->pseikaku == PERSONALITY_COMBAT)) {
210 msg_format("こうして、%sは『クリムゾン』を手に入れた。", owner_ptr->name);
211 msg_print("しかし今、『混沌のサーペント』の放ったモンスターが、");
212 msg_format("%sに襲いかかる...", owner_ptr->name);
215 msg_format("%s(%c)を持っている。", o_name, index_to_label(slot));
217 if (o_ptr->number > hirottakazu) {
218 msg_format("%s拾って、%s(%c)を持っている。", kazu_str, o_name, index_to_label(slot));
220 msg_format("%s(%c)を拾った。", o_name, index_to_label(slot));
225 strcpy(record_o_name, old_name);
227 msg_format("You have %s (%c).", o_name, index_to_label(slot));
228 strcpy(record_o_name, o_name);
230 record_turn = current_world_ptr->game_turn;
231 check_find_art_quest_completion(owner_ptr, o_ptr);
235 * @brief プレイヤーがオブジェクト上に乗った際の表示処理 / Player "wants" to pick up an object or gold.
236 * @param creature_ptr プレーヤーへの参照ポインタ
237 * @param pickup 自動拾い処理を行うならばTRUEとする
239 void carry(player_type *creature_ptr, bool pickup)
241 verify_panel(creature_ptr);
242 creature_ptr->update |= PU_MONSTERS;
243 creature_ptr->redraw |= PR_MAP;
244 creature_ptr->window_flags |= PW_OVERHEAD;
245 handle_stuff(creature_ptr);
246 grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
247 autopick_pickup_items(creature_ptr, g_ptr);
249 py_pickup_floor(creature_ptr, pickup);
253 for (auto it = g_ptr->o_idx_list.begin(); it != g_ptr->o_idx_list.end();) {
254 const OBJECT_IDX this_o_idx = *it++;
256 o_ptr = &creature_ptr->current_floor_ptr->o_list[this_o_idx];
257 GAME_TEXT o_name[MAX_NLEN];
258 describe_flavor(creature_ptr, o_name, o_ptr, 0);
259 disturb(creature_ptr, false, false);
260 if (o_ptr->tval == TV_GOLD) {
261 int value = (long)o_ptr->pval;
262 delete_object_idx(creature_ptr, this_o_idx);
263 msg_format(_(" $%ld の価値がある%sを見つけた。", "You collect %ld gold pieces worth of %s."), (long)value, o_name);
265 creature_ptr->au += value;
266 creature_ptr->redraw |= (PR_GOLD);
267 creature_ptr->window_flags |= (PW_PLAYER);
271 if (o_ptr->marked & OM_NOMSG) {
272 o_ptr->marked &= ~OM_NOMSG;
277 msg_format(_("%sがある。", "You see %s."), o_name);
281 if (!check_store_item_to_inventory(creature_ptr, o_ptr)) {
282 msg_format(_("ザックには%sを入れる隙間がない。", "You have no room for %s."), o_name);
286 int is_pickup_successful = true;
287 if (carry_query_flag) {
288 char out_val[MAX_NLEN + 20];
289 sprintf(out_val, _("%sを拾いますか? ", "Pick up %s? "), o_name);
290 is_pickup_successful = get_check(out_val);
293 if (is_pickup_successful) {
294 describe_pickup_item(creature_ptr, this_o_idx);