1 #include "mind/mind-archer.h"
2 #include "action/action-limited.h"
3 #include "autopick/autopick.h"
4 #include "core/asking-player.h"
5 #include "flavor/flavor-describer.h"
6 #include "floor/cave.h"
7 #include "floor/floor-object.h"
8 #include "floor/geometry.h"
10 #include "inventory/inventory-object.h"
11 #include "io/command-repeater.h"
12 #include "object-enchant/item-apply-magic.h"
13 #include "object-enchant/item-magic-applier.h"
14 #include "object-enchant/object-boost.h"
15 #include "object/item-tester-hooker.h"
16 #include "object/item-use-flags.h"
17 #include "object/object-kind-hook.h"
18 #include "perception/object-perception.h"
19 #include "system/angband.h"
20 #include "system/baseitem-info.h"
21 #include "system/floor-type-definition.h"
22 #include "system/grid-type-definition.h"
23 #include "system/item-entity.h"
24 #include "system/player-type-definition.h"
25 #include "system/redrawing-flags-updater.h"
26 #include "system/terrain-type-definition.h"
27 #include "target/target-getter.h"
28 #include "util/bit-flags-calculator.h"
29 #include "view/display-messages.h"
32 enum ammo_creation_type {
39 static bool select_ammo_creation_type(ammo_creation_type &type, PLAYER_LEVEL plev)
42 if (repeat_pull(&code)) {
43 type = i2enum<ammo_creation_type>(code);
57 prompt = _("[S]弾, [A]矢, [B]クロスボウの矢 :", "Create [S]hots, Create [A]rrow or Create [B]olt ?");
58 } else if (plev >= 10) {
59 prompt = _("[S]弾, [A]矢:", "Create [S]hots or Create [A]rrow ?");
61 prompt = _("[S]弾:", "Create [S]hots ?");
64 while (type == AMMO_NONE) {
65 const auto command = input_command(prompt, true);
66 if (!command.has_value()) {
70 const auto ch = command.value();
71 if (ch == 'S' || ch == 's') {
76 if ((ch == 'A' || ch == 'a') && (plev >= 10)) {
81 if ((ch == 'B' || ch == 'b') && (plev >= 20)) {
87 repeat_push(static_cast<COMMAND_CODE>(type));
92 * @brief「弾/矢の製造」処理 / do_cmd_cast calls this function if the player's class is 'archer'.
93 * Hook to determine if an object is contertible in an arrow/bolt
94 * @return 製造を実際に行ったらTRUE、キャンセルしたらFALSEを返す
96 bool create_ammo(PlayerType *player_ptr)
98 if (cmd_limit_confused(player_ptr) || cmd_limit_blind(player_ptr)) {
102 ammo_creation_type ext = AMMO_NONE;
104 if (!select_ammo_creation_type(ext, player_ptr->lev)) {
111 if (!get_rep_dir(player_ptr, &dir)) {
115 POSITION y = player_ptr->y + ddy[dir];
116 POSITION x = player_ptr->x + ddx[dir];
117 auto *g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
118 if (terrains_info[g_ptr->get_feat_mimic()].flags.has_not(TerrainCharacteristics::CAN_DIG)) {
119 msg_print(_("そこには岩石がない。", "You need a pile of rubble."));
123 if (!g_ptr->cave_has_flag(TerrainCharacteristics::CAN_DIG) || !g_ptr->cave_has_flag(TerrainCharacteristics::HURT_ROCK)) {
124 msg_print(_("硬すぎて崩せなかった。", "You failed to make ammo."));
129 auto *q_ptr = &forge;
130 q_ptr->prep(lookup_baseitem_id({ ItemKindType::SHOT, m_bonus(1, player_ptr->lev) + 1 }));
131 q_ptr->number = (byte)rand_range(15, 30);
132 object_aware(player_ptr, q_ptr);
134 ItemMagicApplier(player_ptr, q_ptr, player_ptr->lev, AM_NO_FIXED_ART).execute();
135 q_ptr->discount = 99;
136 int16_t slot = store_item_to_inventory(player_ptr, q_ptr);
137 const auto item_name = describe_flavor(player_ptr, q_ptr, 0);
138 msg_print(_(format("%sを作った。", item_name.data()), "You make some ammo."));
140 autopick_alter_item(player_ptr, slot, false);
143 cave_alter_feat(player_ptr, y, x, TerrainCharacteristics::HURT_ROCK);
144 RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::FLOW);
148 concptr q = _("どのアイテムから作りますか? ", "Convert which item? ");
149 concptr s = _("材料を持っていない。", "You have no item to convert.");
151 auto *q_ptr = choose_object(player_ptr, &item, q, s, USE_INVEN | USE_FLOOR, FuncItemTester(&ItemEntity::is_convertible));
158 q_ptr->prep(lookup_baseitem_id({ ItemKindType::ARROW, static_cast<short>(m_bonus(1, player_ptr->lev) + 1) }));
159 q_ptr->number = (byte)rand_range(5, 10);
160 object_aware(player_ptr, q_ptr);
162 ItemMagicApplier(player_ptr, q_ptr, player_ptr->lev, AM_NO_FIXED_ART).execute();
163 q_ptr->discount = 99;
164 const auto item_name = describe_flavor(player_ptr, q_ptr, 0);
165 msg_print(_(format("%sを作った。", item_name.data()), "You make some ammo."));
166 vary_item(player_ptr, item, -1);
167 int16_t slot = store_item_to_inventory(player_ptr, q_ptr);
169 autopick_alter_item(player_ptr, slot, false);
175 concptr q = _("どのアイテムから作りますか? ", "Convert which item? ");
176 concptr s = _("材料を持っていない。", "You have no item to convert.");
178 auto *q_ptr = choose_object(player_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), FuncItemTester(&ItemEntity::is_convertible));
185 q_ptr->prep(lookup_baseitem_id({ ItemKindType::BOLT, static_cast<short>(m_bonus(1, player_ptr->lev) + 1) }));
186 q_ptr->number = (byte)rand_range(4, 8);
187 object_aware(player_ptr, q_ptr);
189 ItemMagicApplier(player_ptr, q_ptr, player_ptr->lev, AM_NO_FIXED_ART).execute();
190 q_ptr->discount = 99;
191 const auto item_name = describe_flavor(player_ptr, q_ptr, 0);
192 msg_print(_(format("%sを作った。", item_name.data()), "You make some ammo."));
193 vary_item(player_ptr, item, -1);
194 int16_t slot = store_item_to_inventory(player_ptr, q_ptr);
196 autopick_alter_item(player_ptr, slot, false);