OSDN Git Service

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