OSDN Git Service

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