OSDN Git Service

a35fa75e35f8dbc81a14cfc5427e8927d9e674bb
[hengbandforosx/hengbandosx.git] / src / mind / mind-archer.cpp
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 "core/player-update-types.h"
6 #include "flavor/flavor-describer.h"
7 #include "floor/cave.h"
8 #include "floor/floor-object.h"
9 #include "floor/geometry.h"
10 #include "grid/feature.h"
11 #include "grid/grid.h"
12 #include "inventory/inventory-object.h"
13 #include "io/command-repeater.h"
14 #include "object-enchant/apply-magic.h"
15 #include "object-enchant/item-apply-magic.h"
16 #include "object-enchant/object-boost.h"
17 #include "object-hook/hook-bow.h"
18 #include "object/item-tester-hooker.h"
19 #include "object/item-use-flags.h"
20 #include "object/object-kind-hook.h"
21 #include "perception/object-perception.h"
22 #include "system/floor-type-definition.h"
23 #include "system/grid-type-definition.h"
24 #include "system/object-type-definition.h"
25 #include "system/player-type-definition.h"
26 #include "target/target-getter.h"
27 #include "util/bit-flags-calculator.h"
28 #include "view/display-messages.h"
29
30 enum ammo_creation_type {
31     AMMO_NONE = 0,
32     AMMO_SHOT = 1,
33     AMMO_ARROW = 2,
34     AMMO_BOLT = 3,
35 };
36
37 static bool select_ammo_creation_type(ammo_creation_type &type, PLAYER_LEVEL plev)
38 {
39     COMMAND_CODE code;
40     if (repeat_pull(&code)) {
41         type = static_cast<ammo_creation_type>(code);
42         switch (type) {
43         case AMMO_SHOT:
44         case AMMO_ARROW:
45         case AMMO_BOLT:
46             return true;
47         case AMMO_NONE:
48         default:
49             break;
50         }
51     }
52
53     concptr com;
54     if (plev >= 20)
55         com = _("[S]弾, [A]矢, [B]クロスボウの矢 :", "Create [S]hots, Create [A]rrow or Create [B]olt ?");
56     else if (plev >= 10)
57         com = _("[S]弾, [A]矢:", "Create [S]hots or Create [A]rrow ?");
58     else
59         com = _("[S]弾:", "Create [S]hots ?");
60
61     while (type == AMMO_NONE) {
62         char ch;
63
64         if (!get_com(com, &ch, true)) {
65             return false;
66         }
67
68         if (ch == 'S' || ch == 's') {
69             type = AMMO_SHOT;
70             break;
71         }
72
73         if ((ch == 'A' || ch == 'a') && (plev >= 10)) {
74             type = AMMO_ARROW;
75             break;
76         }
77
78         if ((ch == 'B' || ch == 'b') && (plev >= 20)) {
79             type = AMMO_BOLT;
80             break;
81         }
82     }
83
84     repeat_push(static_cast<COMMAND_CODE>(type));
85     return true;
86 }
87
88 /*!
89  * @brief「弾/矢の製造」処理 / do_cmd_cast calls this function if the player's class is 'archer'.
90  * Hook to determine if an object is contertible in an arrow/bolt
91  * @return 製造を実際に行ったらTRUE、キャンセルしたらFALSEを返す
92  */
93 bool create_ammo(player_type *creature_ptr)
94 {
95     if (cmd_limit_confused(creature_ptr) || cmd_limit_blind(creature_ptr))
96         return false;
97
98     ammo_creation_type ext = AMMO_NONE;
99
100     if (!select_ammo_creation_type(ext, creature_ptr->lev))
101         return false;
102
103     switch (ext) {
104     case AMMO_SHOT: {
105         DIRECTION dir;
106         if (!get_rep_dir(creature_ptr, &dir, false))
107             return false;
108
109         POSITION y = creature_ptr->y + ddy[dir];
110         POSITION x = creature_ptr->x + ddx[dir];
111         grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
112         if (!has_flag(f_info[g_ptr->get_feat_mimic()].flags, FF_CAN_DIG)) {
113             msg_print(_("そこには岩石がない。", "You need a pile of rubble."));
114             return false;
115         }
116
117         if (!cave_has_flag_grid(g_ptr, FF_CAN_DIG) || !cave_has_flag_grid(g_ptr, FF_HURT_ROCK)) {
118             msg_print(_("硬すぎて崩せなかった。", "You failed to make ammo."));
119             return true;
120         }
121
122         object_type forge;
123         object_type *q_ptr = &forge;
124         q_ptr->prep(creature_ptr, lookup_kind(TV_SHOT, (OBJECT_SUBTYPE_VALUE)m_bonus(1, creature_ptr->lev) + 1));
125         q_ptr->number = (byte)rand_range(15, 30);
126         object_aware(creature_ptr, q_ptr);
127         object_known(q_ptr);
128         apply_magic_to_object(creature_ptr, q_ptr, creature_ptr->lev, AM_NO_FIXED_ART);
129         q_ptr->discount = 99;
130         s16b slot = store_item_to_inventory(creature_ptr, q_ptr);
131         GAME_TEXT o_name[MAX_NLEN];
132         describe_flavor(creature_ptr, o_name, q_ptr, 0);
133         msg_format(_("%sを作った。", "You make some ammo."), o_name);
134         if (slot >= 0)
135             autopick_alter_item(creature_ptr, slot, false);
136
137         cave_alter_feat(creature_ptr, y, x, FF_HURT_ROCK);
138         creature_ptr->update |= PU_FLOW;
139         return true;
140     }
141     case AMMO_ARROW: {
142         item_tester_hook = item_tester_hook_convertible;
143         concptr q = _("どのアイテムから作りますか? ", "Convert which item? ");
144         concptr s = _("材料を持っていない。", "You have no item to convert.");
145         OBJECT_IDX item;
146         object_type *q_ptr = choose_object(creature_ptr, &item, q, s, USE_INVEN | USE_FLOOR, TV_NONE);
147         if (!q_ptr)
148             return false;
149
150         object_type forge;
151         q_ptr = &forge;
152         q_ptr->prep(creature_ptr, lookup_kind(TV_ARROW, (OBJECT_SUBTYPE_VALUE)m_bonus(1, creature_ptr->lev) + 1));
153         q_ptr->number = (byte)rand_range(5, 10);
154         object_aware(creature_ptr, q_ptr);
155         object_known(q_ptr);
156         apply_magic_to_object(creature_ptr, q_ptr, creature_ptr->lev, AM_NO_FIXED_ART);
157         q_ptr->discount = 99;
158         GAME_TEXT o_name[MAX_NLEN];
159         describe_flavor(creature_ptr, o_name, q_ptr, 0);
160         msg_format(_("%sを作った。", "You make some ammo."), o_name);
161         vary_item(creature_ptr, item, -1);
162         s16b slot = store_item_to_inventory(creature_ptr, q_ptr);
163         if (slot >= 0)
164             autopick_alter_item(creature_ptr, slot, false);
165
166         return true;
167     }
168     case AMMO_BOLT: {
169         item_tester_hook = item_tester_hook_convertible;
170         concptr q = _("どのアイテムから作りますか? ", "Convert which item? ");
171         concptr s = _("材料を持っていない。", "You have no item to convert.");
172         OBJECT_IDX item;
173         object_type *q_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), TV_NONE);
174         if (!q_ptr)
175             return false;
176
177         object_type forge;
178         q_ptr = &forge;
179         q_ptr->prep(creature_ptr, lookup_kind(TV_BOLT, (OBJECT_SUBTYPE_VALUE)m_bonus(1, creature_ptr->lev) + 1));
180         q_ptr->number = (byte)rand_range(4, 8);
181         object_aware(creature_ptr, q_ptr);
182         object_known(q_ptr);
183         apply_magic_to_object(creature_ptr, q_ptr, creature_ptr->lev, AM_NO_FIXED_ART);
184         q_ptr->discount = 99;
185         GAME_TEXT o_name[MAX_NLEN];
186         describe_flavor(creature_ptr, o_name, q_ptr, 0);
187         msg_format(_("%sを作った。", "You make some ammo."), o_name);
188         vary_item(creature_ptr, item, -1);
189         s16b slot = store_item_to_inventory(creature_ptr, q_ptr);
190         if (slot >= 0)
191             autopick_alter_item(creature_ptr, slot, false);
192
193         return true;
194     }
195     default:
196         return true;
197     }
198 }