OSDN Git Service

[Refactor] #37353 Renamed object-hook.c/h to item-tester-hooker.c/h
[hengband/hengband.git] / src / cmd-item / cmd-smith.c
1 /*!
2  * @brief プレイヤーの鍛冶コマンド実装
3  * @date 2019/03/11
4  * @author deskull
5  */
6
7 #include "cmd-item/cmd-smith.h"
8 #include "autopick/autopick.h"
9 #include "cmd/cmd-basic.h"
10 #include "core/asking-player.h"
11 #include "game-option/text-display-options.h"
12 #include "inventory/player-inventory.h"
13 #include "io/command-repeater.h"
14 #include "io/input-key-acceptor.h"
15 #include "io/input-key-requester.h"
16 #include "main/sound-of-music.h"
17 #include "mind/mind-weaponsmith.h"
18 #include "object-enchant/object-ego.h"
19 #include "object-enchant/special-object-flags.h"
20 #include "object-enchant/tr-types.h"
21 #include "object-enchant/trc-types.h"
22 #include "object-hook/hook-armor.h"
23 #include "object-hook/hook-enchant.h"
24 #include "object-hook/hook-weapon.h"
25 #include "object/item-use-flags.h"
26 #include "object/object-flags.h" // todo 相互参照している.
27 #include "object/object-flavor.h"
28 #include "object/object-generator.h"
29 #include "object/item-tester-hooker.h"
30 #include "perception/object-perception.h"
31 #include "player/player-status.h"
32 #include "term/screen-processor.h"
33 #include "term/term-color-types.h"
34 #include "util/bit-flags-calculator.h"
35 #include "util/buffer-shaper.h"
36 #include "util/int-char-converter.h"
37 #include "view/display-messages.h"
38
39 /*!
40  * エッセンス情報の構造体 / A structure for smithing
41  */
42 typedef struct {
43         int add;       /* TR flag number or special essence id */
44         concptr add_name; /* Name of this ability */
45         ESSENCE_IDX type;      /* Menu number */
46         int essence;   /* Index for carrying essences */
47         int value;     /* Needed value to add this ability */
48 } essence_type;
49
50
51 /*!
52  * エッセンス情報テーブル Smithing type data for Weapon smith
53  */
54 #ifdef JP
55 static essence_type essence_info[] =
56 {
57         {TR_STR, "腕力", 4, TR_STR, 20},
58         {TR_INT, "知能", 4, TR_INT, 20},
59         {TR_WIS, "賢さ", 4, TR_WIS, 20},
60         {TR_DEX, "器用さ", 4, TR_DEX, 20},
61         {TR_CON, "耐久力", 4, TR_CON, 20},
62         {TR_CHR, "魅力", 4, TR_CHR, 20},
63         {TR_MAGIC_MASTERY, "魔力支配", 4, TR_MAGIC_MASTERY, 20},
64         {TR_STEALTH, "隠密", 4, TR_STEALTH, 40},
65         {TR_SEARCH, "探索", 4, TR_SEARCH, 15},
66         {TR_INFRA, "赤外線視力", 4, TR_INFRA, 15},
67         {TR_TUNNEL, "採掘", 4, TR_TUNNEL, 15},
68         {TR_SPEED, "スピード", 4, TR_SPEED, 12},
69         {TR_BLOWS, "追加攻撃", 1, TR_BLOWS, 20},
70         {TR_CHAOTIC, "カオス攻撃", 1, TR_CHAOTIC, 15},
71         {TR_VAMPIRIC, "吸血攻撃", 1, TR_VAMPIRIC, 60},
72         {TR_IMPACT, "地震発動", 7, TR_IMPACT, 15},
73         {TR_BRAND_POIS, "毒殺", 1, TR_BRAND_POIS, 20},
74         {TR_BRAND_ACID, "溶解", 1, TR_BRAND_ACID, 20},
75         {TR_BRAND_ELEC, "電撃", 1, TR_BRAND_ELEC, 20},
76         {TR_BRAND_FIRE, "焼棄", 1, TR_BRAND_FIRE, 20},
77         {TR_BRAND_COLD, "凍結", 1, TR_BRAND_COLD, 20},
78         {TR_SUST_STR, "腕力維持", 3, TR_SUST_STR, 15},
79         {TR_SUST_INT, "知能維持", 3, TR_SUST_STR, 15},
80         {TR_SUST_WIS, "賢さ維持", 3, TR_SUST_STR, 15},
81         {TR_SUST_DEX, "器用さ維持", 3, TR_SUST_STR, 15},
82         {TR_SUST_CON, "耐久力維持", 3, TR_SUST_STR, 15},
83         {TR_SUST_CHR, "魅力維持", 3, TR_SUST_STR, 15},
84         {TR_IM_ACID, "酸免疫", 2, TR_IM_ACID, 20},
85         {TR_IM_ELEC, "電撃免疫", 2, TR_IM_ACID, 20},
86         {TR_IM_FIRE, "火炎免疫", 2, TR_IM_ACID, 20},
87         {TR_IM_COLD, "冷気免疫", 2, TR_IM_ACID, 20},
88         {TR_REFLECT, "反射", 2, TR_REFLECT, 20},
89         {TR_FREE_ACT, "麻痺知らず", 3, TR_FREE_ACT, 20},
90         {TR_HOLD_EXP, "経験値維持", 3, TR_HOLD_EXP, 20},
91         {TR_RES_ACID, "耐酸", 2, TR_RES_ACID, 15},
92         {TR_RES_ELEC, "耐電撃", 2, TR_RES_ELEC, 15},
93         {TR_RES_FIRE, "耐火炎", 2, TR_RES_FIRE, 15},
94         {TR_RES_COLD, "耐冷気", 2, TR_RES_COLD, 15},
95         {TR_RES_POIS, "耐毒", 2, TR_RES_POIS, 25},
96         {TR_RES_FEAR, "耐恐怖", 2, TR_RES_FEAR, 20},
97         {TR_RES_LITE, "耐閃光", 2, TR_RES_LITE, 20},
98         {TR_RES_DARK, "耐暗黒", 2, TR_RES_DARK, 20},
99         {TR_RES_BLIND, "耐盲目", 2, TR_RES_BLIND, 20},
100         {TR_RES_CONF, "耐混乱", 2, TR_RES_CONF, 20},
101         {TR_RES_SOUND, "耐轟音", 2, TR_RES_SOUND, 20},
102         {TR_RES_SHARDS, "耐破片", 2, TR_RES_SHARDS, 20},
103         {TR_RES_NETHER, "耐地獄", 2, TR_RES_NETHER, 20},
104         {TR_RES_NEXUS, "耐因果混乱", 2, TR_RES_NEXUS, 20},
105         {TR_RES_CHAOS, "耐カオス", 2, TR_RES_CHAOS, 20},
106         {TR_RES_DISEN, "耐劣化", 2, TR_RES_DISEN, 20},
107         {TR_SH_FIRE, "", 0, -2, 0},
108         {TR_SH_ELEC, "", 0, -2, 0},
109         {TR_SH_COLD, "", 0, -2, 0},
110         {TR_NO_MAGIC, "反魔法", 3, TR_NO_MAGIC, 15},
111         {TR_WARNING, "警告", 3, TR_WARNING, 20},
112         {TR_LEVITATION, "浮遊", 3, TR_LEVITATION, 20},
113         {TR_LITE_1, "永久光源", 3, TR_LITE_1, 15},
114         {TR_LITE_2, "", 0, -2, 0},
115         {TR_LITE_3, "", 0, -2, 0},
116         {TR_SEE_INVIS, "可視透明", 3, TR_SEE_INVIS, 20},
117         {TR_TELEPATHY, "テレパシー", 6, TR_TELEPATHY, 15},
118         {TR_SLOW_DIGEST, "遅消化", 3, TR_SLOW_DIGEST, 15},
119         {TR_REGEN, "急速回復", 3, TR_REGEN, 20},
120         {TR_TELEPORT, "テレポート", 3, TR_TELEPORT, 25},
121
122         {TR_SLAY_EVIL, "邪悪倍打", 5, TR_SLAY_EVIL, 100},
123         {TR_KILL_EVIL, "邪悪倍倍打", 0, TR_SLAY_EVIL, 60},
124         {TR_SLAY_ANIMAL, "動物倍打", 5, TR_SLAY_ANIMAL, 20},
125         {TR_KILL_ANIMAL, "動物倍倍打", 5, TR_SLAY_ANIMAL, 60},
126         {TR_SLAY_UNDEAD, "不死倍打", 5, TR_SLAY_UNDEAD, 20},
127         {TR_KILL_UNDEAD, "不死倍倍打", 5, TR_SLAY_UNDEAD, 60},
128         {TR_SLAY_DEMON, "悪魔倍打", 5, TR_SLAY_DEMON, 20},
129         {TR_KILL_DEMON, "悪魔倍倍打", 5, TR_SLAY_DEMON, 60},
130         {TR_SLAY_ORC, "オーク倍打", 5, TR_SLAY_ORC, 15},
131         {TR_KILL_ORC, "オーク倍倍打", 5, TR_SLAY_ORC, 60},
132         {TR_SLAY_TROLL, "トロル倍打", 5, TR_SLAY_TROLL, 15},
133         {TR_KILL_TROLL, "トロル倍倍打", 5, TR_SLAY_TROLL, 60},
134         {TR_SLAY_GIANT, "巨人倍打", 5, TR_SLAY_GIANT, 20},
135         {TR_KILL_GIANT, "巨人倍倍打", 5, TR_SLAY_GIANT, 60},
136         {TR_SLAY_DRAGON, "竜倍打", 5, TR_SLAY_DRAGON, 20},
137         {TR_KILL_DRAGON, "竜倍倍打", 5, TR_SLAY_DRAGON, 60},
138         {TR_SLAY_HUMAN, "人間倍打", 5, TR_SLAY_HUMAN, 20},
139         {TR_KILL_HUMAN, "人間倍倍打", 5, TR_SLAY_HUMAN, 60},
140
141         {TR_ESP_ANIMAL, "動物ESP", 6, TR_SLAY_ANIMAL, 40},
142         {TR_ESP_UNDEAD, "不死ESP", 6, TR_SLAY_UNDEAD, 40},
143         {TR_ESP_DEMON, "悪魔ESP", 6, TR_SLAY_DEMON, 40},
144         {TR_ESP_ORC, "オークESP", 6, TR_SLAY_ORC, 40},
145         {TR_ESP_TROLL, "トロルESP", 6, TR_SLAY_TROLL, 40},
146         {TR_ESP_GIANT, "巨人ESP", 6, TR_SLAY_GIANT, 40},
147         {TR_ESP_DRAGON, "竜ESP", 6, TR_SLAY_DRAGON, 40},
148         {TR_ESP_HUMAN, "人間ESP", 6, TR_SLAY_HUMAN, 40},
149
150         {ESSENCE_ATTACK, "攻撃", 10, TR_ES_ATTACK, 30},
151         {ESSENCE_AC, "防御", 10, TR_ES_AC, 15},
152         {ESSENCE_TMP_RES_ACID, "酸耐性発動", 7, TR_RES_ACID, 50},
153         {ESSENCE_TMP_RES_ELEC, "電撃耐性発動", 7, TR_RES_ELEC, 50},
154         {ESSENCE_TMP_RES_FIRE, "火炎耐性発動", 7, TR_RES_FIRE, 50},
155         {ESSENCE_TMP_RES_COLD, "冷気耐性発動", 7, TR_RES_COLD, 50},
156         {ESSENCE_SH_FIRE, "火炎オーラ", 7, -1, 50},
157         {ESSENCE_SH_ELEC, "電撃オーラ", 7, -1, 50},
158         {ESSENCE_SH_COLD, "冷気オーラ", 7, -1, 50},
159         {ESSENCE_RESISTANCE, "全耐性", 2, -1, 150},
160         {ESSENCE_SUSTAIN, "装備保持", 10, -1, 10},
161         {ESSENCE_SLAY_GLOVE, "殺戮の小手", 1, TR_ES_ATTACK, 200},
162
163         {-1, NULL, 0, -1, 0}
164 };
165 #else
166 static essence_type essence_info[] =
167 {
168         {TR_STR, "strength", 4, TR_STR, 20},
169         {TR_INT, "intelligence", 4, TR_INT, 20},
170         {TR_WIS, "wisdom", 4, TR_WIS, 20},
171         {TR_DEX, "dexterity", 4, TR_DEX, 20},
172         {TR_CON, "constitution", 4, TR_CON, 20},
173         {TR_CHR, "charisma", 4, TR_CHR, 20},
174         {TR_MAGIC_MASTERY, "magic mastery", 4, TR_MAGIC_MASTERY, 20},
175         {TR_STEALTH, "stealth", 4, TR_STEALTH, 40},
176         {TR_SEARCH, "serching", 4, TR_SEARCH, 15},
177         {TR_INFRA, "infravision", 4, TR_INFRA, 15},
178         {TR_TUNNEL, "digging", 4, TR_TUNNEL, 15},
179         {TR_SPEED, "speed", 4, TR_SPEED, 12},
180         {TR_BLOWS, "extra attack", 1, TR_BLOWS, 20},
181         {TR_CHAOTIC, "chaos brand", 1, TR_CHAOTIC, 15},
182         {TR_VAMPIRIC, "vampiric brand", 1, TR_VAMPIRIC, 60},
183         {TR_IMPACT, "quake activation", 7, TR_IMPACT, 15},
184         {TR_BRAND_POIS, "poison brand", 1, TR_BRAND_POIS, 20},
185         {TR_BRAND_ACID, "acid brand", 1, TR_BRAND_ACID, 20},
186         {TR_BRAND_ELEC, "electric brand", 1, TR_BRAND_ELEC, 20},
187         {TR_BRAND_FIRE, "fire brand", 1, TR_BRAND_FIRE, 20},
188         {TR_BRAND_COLD, "cold brand", 1, TR_BRAND_COLD, 20},
189         {TR_SUST_STR, "sustain strength", 3, TR_SUST_STR, 15},
190         {TR_SUST_INT, "sustain intelligence", 3, TR_SUST_STR, 15},
191         {TR_SUST_WIS, "sustain wisdom", 3, TR_SUST_STR, 15},
192         {TR_SUST_DEX, "sustain dexterity", 3, TR_SUST_STR, 15},
193         {TR_SUST_CON, "sustain constitution", 3, TR_SUST_STR, 15},
194         {TR_SUST_CHR, "sustain charisma", 3, TR_SUST_STR, 15},
195         {TR_IM_ACID, "acid immunity", 2, TR_IM_ACID, 20},
196         {TR_IM_ELEC, "electric immunity", 2, TR_IM_ACID, 20},
197         {TR_IM_FIRE, "fire immunity", 2, TR_IM_ACID, 20},
198         {TR_IM_COLD, "cold immunity", 2, TR_IM_ACID, 20},
199         {TR_REFLECT, "reflection", 2, TR_REFLECT, 20},
200         {TR_FREE_ACT, "free action", 3, TR_FREE_ACT, 20},
201         {TR_HOLD_EXP, "hold experience", 3, TR_HOLD_EXP, 20},
202         {TR_RES_ACID, "resistance to acid", 2, TR_RES_ACID, 15},
203         {TR_RES_ELEC, "resistance to electric", 2, TR_RES_ELEC, 15},
204         {TR_RES_FIRE, "resistance to fire", 2, TR_RES_FIRE, 15},
205         {TR_RES_COLD, "resistance to cold", 2, TR_RES_COLD, 15},
206         {TR_RES_POIS, "resistance to poison", 2, TR_RES_POIS, 25},
207         {TR_RES_FEAR, "resistance to fear", 2, TR_RES_FEAR, 20},
208         {TR_RES_LITE, "resistance to light", 2, TR_RES_LITE, 20},
209         {TR_RES_DARK, "resistance to dark", 2, TR_RES_DARK, 20},
210         {TR_RES_BLIND, "resistance to blind", 2, TR_RES_BLIND, 20},
211         {TR_RES_CONF, "resistance to confusion", 2, TR_RES_CONF, 20},
212         {TR_RES_SOUND, "resistance to sound", 2, TR_RES_SOUND, 20},
213         {TR_RES_SHARDS, "resistance to shard", 2, TR_RES_SHARDS, 20},
214         {TR_RES_NETHER, "resistance to nether", 2, TR_RES_NETHER, 20},
215         {TR_RES_NEXUS, "resistance to nexus", 2, TR_RES_NEXUS, 20},
216         {TR_RES_CHAOS, "resistance to chaos", 2, TR_RES_CHAOS, 20},
217         {TR_RES_DISEN, "resistance to disenchantment", 2, TR_RES_DISEN, 20},
218         {TR_SH_FIRE, "", 0, -2, 0},
219         {TR_SH_ELEC, "", 0, -2, 0},
220         {TR_SH_COLD, "", 0, -2, 0},
221         {TR_NO_MAGIC, "anti magic", 3, TR_NO_MAGIC, 15},
222         {TR_WARNING, "warning", 3, TR_WARNING, 20},
223         {TR_LEVITATION, "levitation", 3, TR_LEVITATION, 20},
224         {TR_LITE_1, "permanent light", 3, TR_LITE_1, 15},
225         {TR_LITE_2, "", 0, -2, 0},
226         {TR_LITE_3, "", 0, -2, 0},
227         {TR_SEE_INVIS, "see invisible", 3, TR_SEE_INVIS, 20},
228         {TR_TELEPATHY, "telepathy", 6, TR_TELEPATHY, 15},
229         {TR_SLOW_DIGEST, "slow digestion", 3, TR_SLOW_DIGEST, 15},
230         {TR_REGEN, "regeneration", 3, TR_REGEN, 20},
231         {TR_TELEPORT, "teleport", 3, TR_TELEPORT, 25},
232
233         {TR_SLAY_EVIL, "slay evil", 5, TR_SLAY_EVIL, 100},
234         {TR_SLAY_ANIMAL, "slay animal", 5, TR_SLAY_ANIMAL, 20},
235         {TR_KILL_ANIMAL, "kill animal", 5, TR_SLAY_ANIMAL, 60},
236         {TR_KILL_EVIL, "kill evil", 0, TR_SLAY_EVIL, 60},
237         {TR_SLAY_UNDEAD, "slay undead", 5, TR_SLAY_UNDEAD, 20},
238         {TR_KILL_UNDEAD, "kill undead", 5, TR_SLAY_UNDEAD, 60},
239         {TR_SLAY_DEMON, "slay demon", 5, TR_SLAY_DEMON, 20},
240         {TR_KILL_DEMON, "kill demon", 5, TR_SLAY_DEMON, 60},
241         {TR_SLAY_ORC, "slay orc", 5, TR_SLAY_ORC, 15},
242         {TR_KILL_ORC, "kill orc", 5, TR_SLAY_ORC, 60},
243         {TR_SLAY_TROLL, "slay troll", 5, TR_SLAY_TROLL, 15},
244         {TR_KILL_TROLL, "kill troll", 5, TR_SLAY_TROLL, 60},
245         {TR_SLAY_GIANT, "slay giant", 5, TR_SLAY_GIANT, 20},
246         {TR_KILL_GIANT, "kill giant", 5, TR_SLAY_GIANT, 60},
247         {TR_SLAY_DRAGON, "slay dragon", 5, TR_SLAY_DRAGON, 20},
248         {TR_KILL_DRAGON, "kill dragon", 5, TR_SLAY_DRAGON, 60},
249         {TR_SLAY_HUMAN, "slay human", 5, TR_SLAY_HUMAN, 20},
250         {TR_KILL_HUMAN, "kill human", 5, TR_SLAY_HUMAN, 60},
251
252         {TR_ESP_ANIMAL, "sense animal", 6, TR_SLAY_ANIMAL, 40},
253         {TR_ESP_UNDEAD, "sense undead", 6, TR_SLAY_UNDEAD, 40},
254         {TR_ESP_DEMON, "sense demon", 6, TR_SLAY_DEMON, 40},
255         {TR_ESP_ORC, "sense orc", 6, TR_SLAY_ORC, 40},
256         {TR_ESP_TROLL, "sense troll", 6, TR_SLAY_TROLL, 40},
257         {TR_ESP_GIANT, "sense giant", 6, TR_SLAY_GIANT, 40},
258         {TR_ESP_DRAGON, "sense dragon", 6, TR_SLAY_DRAGON, 40},
259         {TR_ESP_HUMAN, "sense human", 6, TR_SLAY_HUMAN, 40},
260
261         {ESSENCE_ATTACK, "weapon enchant", 10, TR_ES_ATTACK, 30},
262         {ESSENCE_AC, "armor enchant", 10, TR_ES_AC, 15},
263         {ESSENCE_TMP_RES_ACID, "resist acid activation", 7, TR_RES_ACID, 50},
264         {ESSENCE_TMP_RES_ELEC, "resist electricity activation", 7, TR_RES_ELEC, 50},
265         {ESSENCE_TMP_RES_FIRE, "resist fire activation", 7, TR_RES_FIRE, 50},
266         {ESSENCE_TMP_RES_COLD, "resist cold activation", 7, TR_RES_COLD, 50},
267         {ESSENCE_SH_FIRE, "fiery sheath", 7, -1, 50},
268         {ESSENCE_SH_ELEC, "electric sheath", 7, -1, 50},
269         {ESSENCE_SH_COLD, "sheath of coldness", 7, -1, 50},
270         {ESSENCE_RESISTANCE, "resistance", 2, -1, 150},
271         {ESSENCE_SUSTAIN, "elements proof", 10, -1, 10},
272         {ESSENCE_SLAY_GLOVE, "gauntlets of slaying", 1, TR_ES_ATTACK, 200},
273
274         {-1, NULL, 0, -1, 0}
275 };
276 #endif
277
278
279 /*!
280  * エッセンス名テーブル / Essense names for Weapon smith
281  */
282 #ifdef JP
283 concptr essence_name[] =
284 {
285         "腕力",
286         "知能",
287         "賢さ",
288         "器用さ",
289         "耐久力",
290         "魅力",
291         "魔力支配",
292         "",
293         "隠密",
294         "探索",
295         "赤外線視力",
296         "採掘",
297         "スピード",
298         "追加攻撃",
299         "カオス攻撃",
300         "吸血攻撃",
301         "動物倍打",
302         "邪悪倍打",
303         "不死倍打",
304         "悪魔倍打",
305         "オーク倍打",
306         "トロル倍打",
307         "巨人倍打",
308         "竜倍打",
309         "",
310         "",
311         "地震",
312         "毒殺",
313         "溶解",
314         "電撃",
315         "焼棄",
316         "凍結",
317         "能力維持",
318         "",
319         "",
320         "",
321         "",
322         "",
323         "",
324         "",
325         "免疫",
326         "",
327         "",
328         "",
329         "",
330         "反射",
331         "麻痺知らず",
332         "経験値維持",
333         "耐酸",
334         "耐電撃",
335         "耐火炎",
336         "耐冷気",
337         "耐毒",
338         "耐恐怖",
339         "耐閃光",
340         "耐暗黒",
341         "耐盲目",
342         "耐混乱",
343         "耐轟音",
344         "耐破片",
345         "耐地獄",
346         "耐因果混乱",
347         "耐カオス",
348         "耐劣化",
349         "",
350         "",
351         "人間倍打",
352         "",
353         "",
354         "反魔法",
355         "",
356         "",
357         "警告",
358         "",
359         "",
360         "",
361         "浮遊",
362         "永久光源",
363         "可視透明",
364         "テレパシー",
365         "遅消化",
366         "急速回復",
367         "",
368         "",
369         "",
370         "",
371         "",
372         "",
373         "",
374         "",
375         "テレポート",
376         "",
377         "",
378         "攻撃",
379         "防御",
380
381         NULL
382 };
383
384 #else
385
386 concptr essence_name[] =
387 {
388         "strength",
389         "intelligen.",
390         "wisdom",
391         "dexterity",
392         "constitut.",
393         "charisma",
394         "magic mast.",
395         "",
396         "stealth",
397         "serching",
398         "infravision",
399         "digging",
400         "speed",
401         "extra atk",
402         "chaos brand",
403         "vampiric",
404         "slay animal",
405         "slay evil",
406         "slay undead",
407         "slay demon",
408         "slay orc",
409         "slay troll",
410         "slay giant",
411         "slay dragon",
412         "",
413         "",
414         "quake",
415         "pois. brand",
416         "acid brand",
417         "elec. brand",
418         "fire brand",
419         "cold brand",
420         "sustain",
421         "",
422         "",
423         "",
424         "",
425         "",
426         "",
427         "",
428         "immunity",
429         "",
430         "",
431         "",
432         "",
433         "reflection",
434         "free action",
435         "hold exp",
436         "res. acid",
437         "res. elec.",
438         "res. fire",
439         "res. cold",
440         "res. poison",
441         "res. fear",
442         "res. light",
443         "res. dark",
444         "res. blind",
445         "res.confuse",
446         "res. sound",
447         "res. shard",
448         "res. nether",
449         "res. nexus",
450         "res. chaos",
451         "res. disen.",
452         "",
453         "",
454         "slay human",
455         "",
456         "",
457         "anti magic",
458         "",
459         "",
460         "warning",
461         "",
462         "",
463         "",
464         "levitation",
465         "perm. light",
466         "see invis.",
467         "telepathy",
468         "slow dige.",
469         "regen.",
470         "",
471         "",
472         "",
473         "",
474         "",
475         "",
476         "",
477         "",
478         "teleport",
479         "",
480         "",
481         "weapon enc.",
482         "armor enc.",
483
484         NULL
485 };
486 #endif
487
488 static concptr const kaji_tips[5] =
489 {
490 #ifdef JP
491         "現在持っているエッセンスの一覧を表示する。",
492         "アイテムからエッセンスを取り出す。エッセンスを取られたアイテムは全く魔法がかかっていない初期状態に戻る。",
493         "既にエッセンスが付加されたアイテムからエッセンスのみ消し去る。エッセンスは手に入らない。",
494         "アイテムにエッセンスを付加する。既にエッセンスが付加されたアイテムやアーティファクトには付加できない。",
495         "武器や防具を強化したり、攻撃で傷つかないようにしたりする。エッセンスが付加されたアイテムやアーティファクトに対しても使用できる。",
496 #else
497         "Display essences you have.",
498         "Extract essences from an item. The item become non magical.",
499         "Remove added essences from an equipment which was improved before. The removed essence will be ruined.",
500         "Add essences to an item. The improved items or artifacts cannot be reimprove.",
501         "Enchant an equipment or make an equiment element-proofed. The improved items and artifacts can be enchanted too.",
502 #endif
503 };
504
505
506 /*!
507  * @brief 所持しているエッセンス一覧を表示する
508  * @return なし
509  */
510 static void display_essence(player_type *creature_ptr)
511 {
512         int i, num = 0;
513
514         screen_save();
515         for (i = 1; i < 22; i++)
516         {
517                 prt("", i, 0);
518         }
519         prt(_("エッセンス   個数     エッセンス   個数     エッセンス   個数",
520                 "Essence      Num      Essence      Num      Essence      Num "), 1, 8);
521         for (i = 0; essence_name[i]; i++)
522         {
523                 if (!essence_name[i][0]) continue;
524                 prt(format("%-11s %5d", essence_name[i], creature_ptr->magic_num1[i]), 2 + num % 21, 8 + num / 21 * 22);
525                 num++;
526         }
527         prt(_("現在所持しているエッセンス", "List of all essences you have."), 0, 0);
528         (void)inkey();
529         screen_load();
530         return;
531 }
532
533 /*!
534  * @brief エッセンスの抽出処理
535  * @param creature_ptr プレーヤーへの参照ポインタ
536  * @return なし
537  */
538 static void drain_essence(player_type *creature_ptr)
539 {
540         int drain_value[sizeof(creature_ptr->magic_num1) / sizeof(s32b)];
541         size_t i;
542         OBJECT_IDX item;
543         int dec = 4;
544         bool observe = FALSE;
545         int old_ds, old_dd, old_to_h, old_to_d, old_ac, old_to_a, old_pval, old_name2;
546         TIME_EFFECT old_timeout;
547         BIT_FLAGS old_flgs[TR_FLAG_SIZE], new_flgs[TR_FLAG_SIZE];
548         object_type *o_ptr;
549         concptr q, s;
550         POSITION iy, ix;
551         byte marked;
552         ITEM_NUMBER number;
553         OBJECT_IDX next_o_idx;
554         WEIGHT weight;
555
556         for (i = 0; i < sizeof(drain_value) / sizeof(int); i++)
557                 drain_value[i] = 0;
558
559         item_tester_hook = object_is_weapon_armour_ammo;
560
561         q = _("どのアイテムから抽出しますか?", "Extract from which item? ");
562         s = _("抽出できるアイテムがありません。", "You have nothing you can extract from.");
563
564         o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
565         if (!o_ptr) return;
566
567         if (object_is_known(o_ptr) && !object_is_nameless(creature_ptr, o_ptr))
568         {
569                 GAME_TEXT o_name[MAX_NLEN];
570                 object_desc(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
571                 if (!get_check(format(_("本当に%sから抽出してよろしいですか?", "Really extract from %s? "), o_name))) return;
572         }
573
574         take_turn(creature_ptr, 100);
575
576         object_flags(creature_ptr, o_ptr, old_flgs);
577         if (have_flag(old_flgs, TR_KILL_DRAGON)) add_flag(old_flgs, TR_SLAY_DRAGON);
578         if (have_flag(old_flgs, TR_KILL_ANIMAL)) add_flag(old_flgs, TR_SLAY_ANIMAL);
579         if (have_flag(old_flgs, TR_KILL_EVIL)) add_flag(old_flgs, TR_SLAY_EVIL);
580         if (have_flag(old_flgs, TR_KILL_UNDEAD)) add_flag(old_flgs, TR_SLAY_UNDEAD);
581         if (have_flag(old_flgs, TR_KILL_DEMON)) add_flag(old_flgs, TR_SLAY_DEMON);
582         if (have_flag(old_flgs, TR_KILL_ORC)) add_flag(old_flgs, TR_SLAY_ORC);
583         if (have_flag(old_flgs, TR_KILL_TROLL)) add_flag(old_flgs, TR_SLAY_TROLL);
584         if (have_flag(old_flgs, TR_KILL_GIANT)) add_flag(old_flgs, TR_SLAY_GIANT);
585         if (have_flag(old_flgs, TR_KILL_HUMAN)) add_flag(old_flgs, TR_SLAY_HUMAN);
586
587         old_to_a = o_ptr->to_a;
588         old_ac = o_ptr->ac;
589         old_to_h = o_ptr->to_h;
590         old_to_d = o_ptr->to_d;
591         old_ds = o_ptr->ds;
592         old_dd = o_ptr->dd;
593         old_pval = o_ptr->pval;
594         old_name2 = o_ptr->name2;
595         old_timeout = o_ptr->timeout;
596         if (o_ptr->curse_flags & (TRC_CURSED | TRC_HEAVY_CURSE | TRC_PERMA_CURSE)) dec--;
597         if (have_flag(old_flgs, TR_ADD_L_CURSE)) dec--;
598         if (have_flag(old_flgs, TR_ADD_H_CURSE)) dec--;
599         if (have_flag(old_flgs, TR_AGGRAVATE)) dec--;
600         if (have_flag(old_flgs, TR_NO_TELE)) dec--;
601         if (have_flag(old_flgs, TR_DRAIN_EXP)) dec--;
602         if (have_flag(old_flgs, TR_DRAIN_HP)) dec--;
603         if (have_flag(old_flgs, TR_DRAIN_MANA)) dec--;
604         if (have_flag(old_flgs, TR_CALL_ANIMAL)) dec--;
605         if (have_flag(old_flgs, TR_CALL_DEMON)) dec--;
606         if (have_flag(old_flgs, TR_CALL_DRAGON)) dec--;
607         if (have_flag(old_flgs, TR_CALL_UNDEAD)) dec--;
608         if (have_flag(old_flgs, TR_COWARDICE)) dec--;
609         if (have_flag(old_flgs, TR_LOW_MELEE)) dec--;
610         if (have_flag(old_flgs, TR_LOW_AC)) dec--;
611         if (have_flag(old_flgs, TR_LOW_MAGIC)) dec--;
612         if (have_flag(old_flgs, TR_FAST_DIGEST)) dec--;
613         if (have_flag(old_flgs, TR_SLOW_REGEN)) dec--;
614         if (have_flag(old_flgs, TR_TY_CURSE)) dec--;
615
616         iy = o_ptr->iy;
617         ix = o_ptr->ix;
618         next_o_idx = o_ptr->next_o_idx;
619         marked = o_ptr->marked;
620         weight = o_ptr->weight;
621         number = o_ptr->number;
622
623         object_prep(creature_ptr, o_ptr, o_ptr->k_idx);
624
625         o_ptr->iy = iy;
626         o_ptr->ix = ix;
627         o_ptr->next_o_idx = next_o_idx;
628         o_ptr->marked = marked;
629         o_ptr->number = number;
630         if (o_ptr->tval == TV_DRAG_ARMOR) o_ptr->timeout = old_timeout;
631         if (item >= 0) creature_ptr->total_weight += (o_ptr->weight*o_ptr->number - weight * number);
632         o_ptr->ident |= (IDENT_FULL_KNOWN);
633         object_aware(creature_ptr, o_ptr);
634         object_known(o_ptr);
635
636         object_flags(creature_ptr, o_ptr, new_flgs);
637
638         for (i = 0; essence_info[i].add_name; i++)
639         {
640                 essence_type *es_ptr = &essence_info[i];
641                 PARAMETER_VALUE pval = 0;
642
643                 if (es_ptr->add < TR_FLAG_MAX && is_pval_flag(es_ptr->add) && old_pval)
644                         pval = (have_flag(new_flgs, es_ptr->add)) ? old_pval - o_ptr->pval : old_pval;
645
646                 if (es_ptr->add < TR_FLAG_MAX &&
647                         (!have_flag(new_flgs, es_ptr->add) || pval) &&
648                         have_flag(old_flgs, es_ptr->add))
649                 {
650                         if (pval)
651                         {
652                                 drain_value[es_ptr->essence] += 10 * pval;
653                         }
654                         else if (es_ptr->essence != -2)
655                         {
656                                 drain_value[es_ptr->essence] += 10;
657                         }
658                         else if (es_ptr->add == TR_SH_FIRE)
659                         {
660                                 drain_value[TR_BRAND_FIRE] += 10;
661                                 drain_value[TR_RES_FIRE] += 10;
662                         }
663                         else if (es_ptr->add == TR_SH_ELEC)
664                         {
665                                 drain_value[TR_BRAND_ELEC] += 10;
666                                 drain_value[TR_RES_ELEC] += 10;
667                         }
668                         else if (es_ptr->add == TR_SH_COLD)
669                         {
670                                 drain_value[TR_BRAND_COLD] += 10;
671                                 drain_value[TR_RES_COLD] += 10;
672                         }
673                         else if (es_ptr->add == TR_LITE_2)
674                         {
675                                 drain_value[TR_LITE_1] += 20;
676                         }
677                         else if (es_ptr->add == TR_LITE_3)
678                         {
679                                 drain_value[TR_LITE_1] += 30;
680                         }
681                 }
682         }
683
684         if ((have_flag(old_flgs, TR_FORCE_WEAPON)) && !(have_flag(new_flgs, TR_FORCE_WEAPON)))
685         {
686                 drain_value[TR_INT] += 5;
687                 drain_value[TR_WIS] += 5;
688         }
689         if ((have_flag(old_flgs, TR_VORPAL)) && !(have_flag(new_flgs, TR_VORPAL)))
690         {
691                 drain_value[TR_BRAND_POIS] += 5;
692                 drain_value[TR_BRAND_ACID] += 5;
693                 drain_value[TR_BRAND_ELEC] += 5;
694                 drain_value[TR_BRAND_FIRE] += 5;
695                 drain_value[TR_BRAND_COLD] += 5;
696         }
697         if ((have_flag(old_flgs, TR_DEC_MANA)) && !(have_flag(new_flgs, TR_DEC_MANA)))
698         {
699                 drain_value[TR_INT] += 10;
700         }
701         if ((have_flag(old_flgs, TR_XTRA_MIGHT)) && !(have_flag(new_flgs, TR_XTRA_MIGHT)))
702         {
703                 drain_value[TR_STR] += 10;
704         }
705         if ((have_flag(old_flgs, TR_XTRA_SHOTS)) && !(have_flag(new_flgs, TR_XTRA_SHOTS)))
706         {
707                 drain_value[TR_DEX] += 10;
708         }
709         if (old_name2 == EGO_2WEAPON)
710         {
711                 drain_value[TR_DEX] += 20;
712         }
713         if (object_is_weapon_ammo(o_ptr))
714         {
715                 if (old_ds > o_ptr->ds) drain_value[TR_ES_ATTACK] += (old_ds - o_ptr->ds) * 10;
716
717                 if (old_dd > o_ptr->dd) drain_value[TR_ES_ATTACK] += (old_dd - o_ptr->dd) * 10;
718         }
719         if (old_to_h > o_ptr->to_h) drain_value[TR_ES_ATTACK] += (old_to_h - o_ptr->to_h) * 10;
720         if (old_to_d > o_ptr->to_d) drain_value[TR_ES_ATTACK] += (old_to_d - o_ptr->to_d) * 10;
721         if (old_ac > o_ptr->ac) drain_value[TR_ES_AC] += (old_ac - o_ptr->ac) * 10;
722         if (old_to_a > o_ptr->to_a) drain_value[TR_ES_AC] += (old_to_a - o_ptr->to_a) * 10;
723
724         for (i = 0; i < sizeof(drain_value) / sizeof(int); i++)
725         {
726                 drain_value[i] *= number;
727                 drain_value[i] = drain_value[i] * dec / 4;
728                 drain_value[i] = MAX(drain_value[i], 0);
729                 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_BOLT)) drain_value[i] /= 10;
730                 if (drain_value[i])
731                 {
732                         observe = TRUE;
733                 }
734         }
735         if (!observe)
736         {
737                 msg_print(_("エッセンスは抽出できませんでした。", "You were not able to extract any essence."));
738         }
739         else
740         {
741                 msg_print(_("抽出したエッセンス:", "Extracted essences:"));
742
743                 for (i = 0; essence_name[i]; i++)
744                 {
745                         if (!essence_name[i][0]) continue;
746                         if (!drain_value[i]) continue;
747
748                         creature_ptr->magic_num1[i] += drain_value[i];
749                         creature_ptr->magic_num1[i] = MIN(20000, creature_ptr->magic_num1[i]);
750                         msg_print(NULL);
751                         msg_format("%s...%d%s", essence_name[i], drain_value[i], _("。", ". "));
752                 }
753         }
754
755         /* Apply autodestroy/inscription to the drained item */
756         autopick_alter_item(creature_ptr, item, TRUE);
757         creature_ptr->update |= (PU_COMBINE | PU_REORDER);
758         creature_ptr->window |= (PW_INVEN);
759 }
760
761 /*!
762  * @brief 付加するエッセンスの大別を選択する
763  * @return 選んだエッセンスの大別ID
764  */
765 static COMMAND_CODE choose_essence(void)
766 {
767         COMMAND_CODE mode = 0;
768         char choice;
769         COMMAND_CODE menu_line = (use_menu ? 1 : 0);
770
771 #ifdef JP
772         concptr menu_name[] = {
773                 "武器属性",
774                 "耐性",
775                 "能力",
776                 "数値",
777                 "スレイ",
778                 "ESP",
779                 "その他"
780         };
781 #else
782         concptr menu_name[] = {
783                 "Brand weapon",
784                 "Resistance",
785                 "Ability",
786                 "Magic number",
787                 "Slay",
788                 "ESP",
789                 "Others"
790         };
791 #endif
792         const COMMAND_CODE mode_max = 7;
793
794         if (repeat_pull(&mode) && 1 <= mode && mode <= mode_max)
795                 return mode;
796         mode = 0;
797         if (use_menu)
798         {
799                 screen_save();
800
801                 while (!mode)
802                 {
803                         int i;
804                         for (i = 0; i < mode_max; i++)
805 #ifdef JP
806                                 prt(format(" %s %s", (menu_line == 1 + i) ? "》" : "  ", menu_name[i]), 2 + i, 14);
807                         prt("どの種類のエッセンス付加を行いますか?", 0, 0);
808 #else
809                                 prt(format(" %s %s", (menu_line == 1 + i) ? "> " : "  ", menu_name[i]), 2 + i, 14);
810                         prt("Choose from menu.", 0, 0);
811 #endif
812
813                         choice = inkey();
814                         switch (choice)
815                         {
816                         case ESCAPE:
817                         case 'z':
818                         case 'Z':
819                                 screen_load();
820                                 return 0;
821                         case '2':
822                         case 'j':
823                         case 'J':
824                                 menu_line++;
825                                 break;
826                         case '8':
827                         case 'k':
828                         case 'K':
829                                 menu_line += mode_max - 1;
830                                 break;
831                         case '\r':
832                         case '\n':
833                         case 'x':
834                         case 'X':
835                                 mode = menu_line;
836                                 break;
837                         }
838                         if (menu_line > mode_max) menu_line -= mode_max;
839                 }
840                 screen_load();
841         }
842         else
843         {
844                 screen_save();
845                 while (!mode)
846                 {
847                         int i;
848
849                         for (i = 0; i < mode_max; i++)
850                                 prt(format("  %c) %s", 'a' + i, menu_name[i]), 2 + i, 14);
851
852                         if (!get_com(_("何を付加しますか:", "Command :"), &choice, TRUE))
853                         {
854                                 screen_load();
855                                 return 0;
856                         }
857
858                         if (isupper(choice)) choice = (char)tolower(choice);
859
860                         if ('a' <= choice && choice <= 'a' + (char)mode_max - 1)
861                                 mode = (int)choice - 'a' + 1;
862                 }
863                 screen_load();
864         }
865
866         repeat_push(mode);
867         return mode;
868 }
869
870 /*!
871  * @brief エッセンスを実際に付加する
872  * @param mode エッセンスの大別ID
873  * @return なし
874  */
875 static void add_essence(player_type *creature_ptr, ESSENCE_IDX mode)
876 {
877         OBJECT_IDX item;
878         int max_num = 0;
879         COMMAND_CODE i;
880         bool flag, redraw;
881         char choice;
882         concptr            q, s;
883         object_type *o_ptr;
884         int ask = TRUE;
885         char out_val[160];
886         int num[22];
887         GAME_TEXT o_name[MAX_NLEN];
888         int use_essence;
889         essence_type *es_ptr;
890         bool able[22] = { 0 };
891         tval_type tval = 0;
892         int menu_line = (use_menu ? 1 : 0);
893
894         for (i = 0; essence_info[i].add_name; i++)
895         {
896                 es_ptr = &essence_info[i];
897
898                 if (es_ptr->type != mode) continue;
899                 num[max_num++] = i;
900         }
901
902         if (!repeat_pull(&i) || i < 0 || i >= max_num)
903         {
904                 flag = FALSE;
905                 redraw = FALSE;
906
907                 (void)strnfmt(out_val, 78, _("('*'で一覧, ESCで中断) どの能力を付加しますか?", "(*=List, ESC=exit) Add which ability? "));
908                 if (use_menu) screen_save();
909
910                 choice = (always_show_list || use_menu) ? ESCAPE : 1;
911                 while (!flag)
912                 {
913                         if (choice == ESCAPE) choice = ' ';
914                         else if (!get_com(out_val, &choice, FALSE))break;
915
916                         if (use_menu && choice != ' ')
917                         {
918                                 switch (choice)
919                                 {
920                                 case '0':
921                                 {
922                                         screen_load();
923                                         return;
924                                 }
925
926                                 case '8':
927                                 case 'k':
928                                 case 'K':
929                                 {
930                                         menu_line += (max_num - 1);
931                                         break;
932                                 }
933
934                                 case '2':
935                                 case 'j':
936                                 case 'J':
937                                 {
938                                         menu_line++;
939                                         break;
940                                 }
941
942                                 case '4':
943                                 case 'h':
944                                 case 'H':
945                                 {
946                                         menu_line = 1;
947                                         break;
948                                 }
949                                 case '6':
950                                 case 'l':
951                                 case 'L':
952                                 {
953                                         menu_line = max_num;
954                                         break;
955                                 }
956
957                                 case 'x':
958                                 case 'X':
959                                 case '\r':
960                                 case '\n':
961                                 {
962                                         i = menu_line - 1;
963                                         ask = FALSE;
964                                         break;
965                                 }
966                                 }
967                                 if (menu_line > max_num) menu_line -= max_num;
968                         }
969                         /* Request redraw */
970                         if ((choice == ' ') || (choice == '*') || (choice == '?') || (use_menu && ask))
971                         {
972                                 /* Show the list */
973                                 if (!redraw || use_menu)
974                                 {
975                                         byte y, x = 10;
976                                         int ctr;
977                                         char dummy[80], dummy2[80];
978                                         byte col;
979
980                                         strcpy(dummy, "");
981                                         redraw = TRUE;
982                                         if (!use_menu) screen_save();
983
984                                         for (y = 1; y < 24; y++)
985                                                 prt("", y, x);
986
987                                         /* Print header(s) */
988 #ifdef JP
989                                         prt(format("   %-43s %6s/%s", "能力(必要エッセンス)", "必要数", "所持数"), 1, x);
990
991 #else
992                                         prt(format("   %-43s %6s/%s", "Ability (needed essence)", "Needs", "Possess"), 1, x);
993 #endif
994                                         /* Print list */
995                                         for (ctr = 0; ctr < max_num; ctr++)
996                                         {
997                                                 es_ptr = &essence_info[num[ctr]];
998
999                                                 if (use_menu)
1000                                                 {
1001                                                         if (ctr == (menu_line - 1))
1002                                                                 strcpy(dummy, _("》 ", ">  "));
1003                                                         else strcpy(dummy, "   ");
1004
1005                                                 }
1006                                                 /* letter/number for power selection */
1007                                                 else
1008                                                 {
1009                                                         sprintf(dummy, "%c) ", I2A(ctr));
1010                                                 }
1011
1012                                                 strcat(dummy, es_ptr->add_name);
1013
1014                                                 col = TERM_WHITE;
1015                                                 able[ctr] = TRUE;
1016
1017                                                 if (es_ptr->essence != -1)
1018                                                 {
1019                                                         strcat(dummy, format("(%s)", essence_name[es_ptr->essence]));
1020                                                         if (creature_ptr->magic_num1[es_ptr->essence] < es_ptr->value) able[ctr] = FALSE;
1021                                                 }
1022                                                 else
1023                                                 {
1024                                                         switch (es_ptr->add)
1025                                                         {
1026                                                         case ESSENCE_SH_FIRE:
1027                                                                 strcat(dummy, _("(焼棄+耐火炎)", "(brand fire + res.fire)"));
1028                                                                 if (creature_ptr->magic_num1[TR_BRAND_FIRE] < es_ptr->value) able[ctr] = FALSE;
1029                                                                 if (creature_ptr->magic_num1[TR_RES_FIRE] < es_ptr->value) able[ctr] = FALSE;
1030                                                                 break;
1031                                                         case ESSENCE_SH_ELEC:
1032                                                                 strcat(dummy, _("(電撃+耐電撃)", "(brand elec. + res. elec.)"));
1033                                                                 if (creature_ptr->magic_num1[TR_BRAND_ELEC] < es_ptr->value) able[ctr] = FALSE;
1034                                                                 if (creature_ptr->magic_num1[TR_RES_ELEC] < es_ptr->value) able[ctr] = FALSE;
1035                                                                 break;
1036                                                         case ESSENCE_SH_COLD:
1037                                                                 strcat(dummy, _("(凍結+耐冷気)", "(brand cold + res. cold)"));
1038                                                                 if (creature_ptr->magic_num1[TR_BRAND_COLD] < es_ptr->value) able[ctr] = FALSE;
1039                                                                 if (creature_ptr->magic_num1[TR_RES_COLD] < es_ptr->value) able[ctr] = FALSE;
1040                                                                 break;
1041                                                         case ESSENCE_RESISTANCE:
1042                                                                 strcat(dummy, _("(耐火炎+耐冷気+耐電撃+耐酸)", "(r.fire+r.cold+r.elec+r.acid)"));
1043                                                                 if (creature_ptr->magic_num1[TR_RES_FIRE] < es_ptr->value) able[ctr] = FALSE;
1044                                                                 if (creature_ptr->magic_num1[TR_RES_COLD] < es_ptr->value) able[ctr] = FALSE;
1045                                                                 if (creature_ptr->magic_num1[TR_RES_ELEC] < es_ptr->value) able[ctr] = FALSE;
1046                                                                 if (creature_ptr->magic_num1[TR_RES_ACID] < es_ptr->value) able[ctr] = FALSE;
1047                                                                 break;
1048                                                         case ESSENCE_SUSTAIN:
1049                                                                 strcat(dummy, _("(耐火炎+耐冷気+耐電撃+耐酸)", "(r.fire+r.cold+r.elec+r.acid)"));
1050                                                                 if (creature_ptr->magic_num1[TR_RES_FIRE] < es_ptr->value) able[ctr] = FALSE;
1051                                                                 if (creature_ptr->magic_num1[TR_RES_COLD] < es_ptr->value) able[ctr] = FALSE;
1052                                                                 if (creature_ptr->magic_num1[TR_RES_ELEC] < es_ptr->value) able[ctr] = FALSE;
1053                                                                 if (creature_ptr->magic_num1[TR_RES_ACID] < es_ptr->value) able[ctr] = FALSE;
1054                                                                 break;
1055                                                         }
1056                                                 }
1057
1058                                                 if (!able[ctr]) col = TERM_RED;
1059
1060                                                 if (es_ptr->essence != -1)
1061                                                 {
1062                                                         sprintf(dummy2, "%-49s %3d/%d", dummy, es_ptr->value, (int)creature_ptr->magic_num1[es_ptr->essence]);
1063                                                 }
1064                                                 else
1065                                                 {
1066                                                         sprintf(dummy2, "%-49s %3d/(\?\?)", dummy, es_ptr->value);
1067                                                 }
1068
1069                                                 c_prt(col, dummy2, ctr + 2, x);
1070                                         }
1071                                 }
1072
1073                                 /* Hide the list */
1074                                 else
1075                                 {
1076                                         /* Hide list */
1077                                         redraw = FALSE;
1078                                         screen_load();
1079                                 }
1080
1081                                 /* Redo asking */
1082                                 continue;
1083                         }
1084
1085                         if (!use_menu)
1086                         {
1087                                 /* Note verify */
1088                                 ask = (isupper(choice));
1089
1090                                 /* Lowercase */
1091                                 if (ask) choice = (char)tolower(choice);
1092
1093                                 /* Extract request */
1094                                 i = (islower(choice) ? A2I(choice) : -1);
1095                         }
1096
1097                         /* Totally Illegal */
1098                         if ((i < 0) || (i >= max_num) || !able[i])
1099                         {
1100                                 bell();
1101                                 continue;
1102                         }
1103
1104                         /* Verify it */
1105                         if (ask)
1106                         {
1107                                 char tmp_val[160];
1108
1109                                 /* Prompt */
1110                                 (void)strnfmt(tmp_val, 78, _("%sを付加しますか? ", "Add the abilitiy of %s? "), essence_info[num[i]].add_name);
1111
1112                                 /* Belay that order */
1113                                 if (!get_check(tmp_val)) continue;
1114                         }
1115
1116                         /* Stop the loop */
1117                         flag = TRUE;
1118                 }
1119                 if (redraw) screen_load();
1120
1121                 if (!flag) return;
1122
1123                 repeat_push(i);
1124         }
1125         es_ptr = &essence_info[num[i]];
1126
1127         if (es_ptr->add == ESSENCE_SLAY_GLOVE)
1128                 tval = TV_GLOVES;
1129         else if (mode == 1 || mode == 5)
1130                 item_tester_hook = item_tester_hook_melee_ammo;
1131         else if (es_ptr->add == ESSENCE_ATTACK)
1132                 item_tester_hook = object_allow_enchant_weapon;
1133         else if (es_ptr->add == ESSENCE_AC)
1134                 item_tester_hook = object_is_armour;
1135         else
1136                 item_tester_hook = object_is_weapon_armour_ammo;
1137
1138         q = _("どのアイテムを改良しますか?", "Improve which item? ");
1139         s = _("改良できるアイテムがありません。", "You have nothing to improve.");
1140
1141         o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), tval);
1142         if (!o_ptr) return;
1143
1144         if ((mode != 10) && (object_is_artifact(o_ptr) || object_is_smith(creature_ptr, o_ptr)))
1145         {
1146                 msg_print(_("そのアイテムはこれ以上改良できない。", "This item can not be improved any further."));
1147                 return;
1148         }
1149
1150         object_desc(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1151
1152         use_essence = es_ptr->value;
1153         if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_BOLT)) use_essence = (use_essence + 9) / 10;
1154         if (o_ptr->number > 1)
1155         {
1156                 use_essence *= o_ptr->number;
1157                 msg_format(_("%d個あるのでエッセンスは%d必要です。", "For %d items, it will take %d essences."), o_ptr->number, use_essence);
1158         }
1159
1160         if (es_ptr->essence != -1)
1161         {
1162                 if (creature_ptr->magic_num1[es_ptr->essence] < use_essence)
1163                 {
1164                         msg_print(_("エッセンスが足りない。", "You don't have enough essences."));
1165                         return;
1166                 }
1167                 if (is_pval_flag(es_ptr->add))
1168                 {
1169                         if (o_ptr->pval < 0)
1170                         {
1171                                 msg_print(_("このアイテムの能力修正を強化することはできない。", "You cannot increase magic number of this item."));
1172                                 return;
1173                         }
1174                         else if (es_ptr->add == TR_BLOWS)
1175                         {
1176                                 if (o_ptr->pval > 1)
1177                                 {
1178                                         if (!get_check(_("修正値は1になります。よろしいですか?", "The magic number of this weapon will become 1. Are you sure? "))) return;
1179                                 }
1180
1181                                 o_ptr->pval = 1;
1182                                 msg_format(_("エッセンスを%d個使用します。", "It will take %d essences."), use_essence);
1183                         }
1184                         else if (o_ptr->pval > 0)
1185                         {
1186                                 use_essence *= o_ptr->pval;
1187                                 msg_format(_("エッセンスを%d個使用します。", "It will take %d essences."), use_essence);
1188                         }
1189                         else
1190                         {
1191                                 char tmp[80];
1192                                 char tmp_val[160];
1193                                 PARAMETER_VALUE pval;
1194                                 PARAMETER_VALUE limit = MIN(5, creature_ptr->magic_num1[es_ptr->essence] / es_ptr->value);
1195
1196                                 sprintf(tmp, _("いくつ付加しますか? (1-%d): ", "Enchant how many? (1-%d): "), limit);
1197                                 strcpy(tmp_val, "1");
1198
1199                                 if (!get_string(tmp, tmp_val, 1)) return;
1200                                 pval = (PARAMETER_VALUE)atoi(tmp_val);
1201                                 if (pval > limit) pval = limit;
1202                                 else if (pval < 1) pval = 1;
1203                                 o_ptr->pval += pval;
1204                                 use_essence *= pval;
1205                                 msg_format(_("エッセンスを%d個使用します。", "It will take %d essences."), use_essence);
1206                         }
1207
1208                         if (creature_ptr->magic_num1[es_ptr->essence] < use_essence)
1209                         {
1210                                 msg_print(_("エッセンスが足りない。", "You don't have enough essences."));
1211                                 return;
1212                         }
1213                 }
1214                 else if (es_ptr->add == ESSENCE_SLAY_GLOVE)
1215                 {
1216                         char tmp_val[160];
1217                         int val;
1218                         HIT_PROB get_to_h;
1219                         HIT_POINT get_to_d;
1220
1221                         strcpy(tmp_val, "1");
1222                         if (!get_string(format(_("いくつ付加しますか? (1-%d):", "Enchant how many? (1-%d):"), creature_ptr->lev / 7 + 3), tmp_val, 2)) return;
1223                         val = atoi(tmp_val);
1224                         if (val > creature_ptr->lev / 7 + 3) val = creature_ptr->lev / 7 + 3;
1225                         else if (val < 1) val = 1;
1226                         use_essence *= val;
1227                         msg_format(_("エッセンスを%d個使用します。", "It will take %d essences."), use_essence);
1228                         if (creature_ptr->magic_num1[es_ptr->essence] < use_essence)
1229                         {
1230                                 msg_print(_("エッセンスが足りない。", "You don't have enough essences."));
1231                                 return;
1232                         }
1233                         get_to_h = ((val + 1) / 2 + randint0(val / 2 + 1));
1234                         get_to_d = ((val + 1) / 2 + randint0(val / 2 + 1));
1235                         o_ptr->xtra4 = (get_to_h << 8) + get_to_d;
1236                         o_ptr->to_h += get_to_h;
1237                         o_ptr->to_d += get_to_d;
1238                 }
1239                 creature_ptr->magic_num1[es_ptr->essence] -= use_essence;
1240                 if (es_ptr->add == ESSENCE_ATTACK)
1241                 {
1242                         if ((o_ptr->to_h >= creature_ptr->lev / 5 + 5) && (o_ptr->to_d >= creature_ptr->lev / 5 + 5))
1243                         {
1244                                 msg_print(_("改良に失敗した。", "You failed to enchant."));
1245                                 take_turn(creature_ptr, 100);
1246                                 return;
1247                         }
1248                         else
1249                         {
1250                                 if (o_ptr->to_h < creature_ptr->lev / 5 + 5) o_ptr->to_h++;
1251                                 if (o_ptr->to_d < creature_ptr->lev / 5 + 5) o_ptr->to_d++;
1252                         }
1253                 }
1254                 else if (es_ptr->add == ESSENCE_AC)
1255                 {
1256                         if (o_ptr->to_a >= creature_ptr->lev / 5 + 5)
1257                         {
1258                                 msg_print(_("改良に失敗した。", "You failed to enchant."));
1259                                 take_turn(creature_ptr, 100);
1260                                 return;
1261                         }
1262                         else
1263                         {
1264                                 if (o_ptr->to_a < creature_ptr->lev / 5 + 5) o_ptr->to_a++;
1265                         }
1266                 }
1267                 else
1268                 {
1269                         o_ptr->xtra3 = es_ptr->add + 1;
1270                 }
1271         }
1272         else
1273         {
1274                 bool success = TRUE;
1275
1276                 switch (es_ptr->add)
1277                 {
1278                 case ESSENCE_SH_FIRE:
1279                         if ((creature_ptr->magic_num1[TR_BRAND_FIRE] < use_essence) || (creature_ptr->magic_num1[TR_RES_FIRE] < use_essence))
1280                         {
1281                                 success = FALSE;
1282                                 break;
1283                         }
1284                         creature_ptr->magic_num1[TR_BRAND_FIRE] -= use_essence;
1285                         creature_ptr->magic_num1[TR_RES_FIRE] -= use_essence;
1286                         break;
1287                 case ESSENCE_SH_ELEC:
1288                         if ((creature_ptr->magic_num1[TR_BRAND_ELEC] < use_essence) || (creature_ptr->magic_num1[TR_RES_ELEC] < use_essence))
1289                         {
1290                                 success = FALSE;
1291                                 break;
1292                         }
1293                         creature_ptr->magic_num1[TR_BRAND_ELEC] -= use_essence;
1294                         creature_ptr->magic_num1[TR_RES_ELEC] -= use_essence;
1295                         break;
1296                 case ESSENCE_SH_COLD:
1297                         if ((creature_ptr->magic_num1[TR_BRAND_COLD] < use_essence) || (creature_ptr->magic_num1[TR_RES_COLD] < use_essence))
1298                         {
1299                                 success = FALSE;
1300                                 break;
1301                         }
1302                         creature_ptr->magic_num1[TR_BRAND_COLD] -= use_essence;
1303                         creature_ptr->magic_num1[TR_RES_COLD] -= use_essence;
1304                         break;
1305                 case ESSENCE_RESISTANCE:
1306                 case ESSENCE_SUSTAIN:
1307                         if ((creature_ptr->magic_num1[TR_RES_ACID] < use_essence) || (creature_ptr->magic_num1[TR_RES_ELEC] < use_essence) || (creature_ptr->magic_num1[TR_RES_FIRE] < use_essence) || (creature_ptr->magic_num1[TR_RES_COLD] < use_essence))
1308                         {
1309                                 success = FALSE;
1310                                 break;
1311                         }
1312                         creature_ptr->magic_num1[TR_RES_ACID] -= use_essence;
1313                         creature_ptr->magic_num1[TR_RES_ELEC] -= use_essence;
1314                         creature_ptr->magic_num1[TR_RES_FIRE] -= use_essence;
1315                         creature_ptr->magic_num1[TR_RES_COLD] -= use_essence;
1316                         break;
1317                 }
1318                 if (!success)
1319                 {
1320                         msg_print(_("エッセンスが足りない。", "You don't have enough essences."));
1321                         return;
1322                 }
1323                 if (es_ptr->add == ESSENCE_SUSTAIN)
1324                 {
1325                         add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
1326                         add_flag(o_ptr->art_flags, TR_IGNORE_ELEC);
1327                         add_flag(o_ptr->art_flags, TR_IGNORE_FIRE);
1328                         add_flag(o_ptr->art_flags, TR_IGNORE_COLD);
1329                 }
1330                 else
1331                 {
1332                         o_ptr->xtra3 = es_ptr->add + 1;
1333                 }
1334         }
1335
1336         take_turn(creature_ptr, 100);
1337         _(msg_format("%sに%sの能力を付加しました。", o_name, es_ptr->add_name),
1338           msg_format("You have added ability of %s to %s.", es_ptr->add_name, o_name));
1339         creature_ptr->update |= (PU_COMBINE | PU_REORDER);
1340         creature_ptr->window |= (PW_INVEN);
1341 }
1342
1343 /*!
1344  * @brief エッセンスを消去する
1345  * @return なし
1346  */
1347 static void erase_essence(player_type *creature_ptr)
1348 {
1349         OBJECT_IDX item;
1350         concptr q, s;
1351         object_type *o_ptr;
1352         GAME_TEXT o_name[MAX_NLEN];
1353         BIT_FLAGS flgs[TR_FLAG_SIZE];
1354
1355         item_tester_hook = object_is_smith;
1356
1357         q = _("どのアイテムのエッセンスを消去しますか?", "Remove from which item? ");
1358         s = _("エッセンスを付加したアイテムがありません。", "You have nothing to remove essence.");
1359
1360         o_ptr = choose_object(creature_ptr, &item, q, s, (USE_INVEN | USE_FLOOR), 0);
1361         if (!o_ptr) return;
1362
1363         object_desc(creature_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1364         if (!get_check(format(_("よろしいですか? [%s]", "Are you sure? [%s]"), o_name))) return;
1365
1366         take_turn(creature_ptr, 100);
1367
1368         if (o_ptr->xtra3 == 1 + ESSENCE_SLAY_GLOVE)
1369         {
1370                 o_ptr->to_h -= (o_ptr->xtra4 >> 8);
1371                 o_ptr->to_d -= (o_ptr->xtra4 & 0x000f);
1372                 o_ptr->xtra4 = 0;
1373                 if (o_ptr->to_h < 0) o_ptr->to_h = 0;
1374                 if (o_ptr->to_d < 0) o_ptr->to_d = 0;
1375         }
1376         o_ptr->xtra3 = 0;
1377         object_flags(creature_ptr, o_ptr, flgs);
1378         if (!(have_pval_flags(flgs))) o_ptr->pval = 0;
1379         msg_print(_("エッセンスを取り去った。", "You removed all essence you have added."));
1380         creature_ptr->update |= (PU_COMBINE | PU_REORDER);
1381         creature_ptr->window |= (PW_INVEN);
1382 }
1383
1384 /*!
1385  * @brief 鍛冶コマンドのメインルーチン
1386  * @param only_browse TRUEならばエッセンス一覧の表示のみを行う
1387  * @return なし
1388  */
1389 void do_cmd_kaji(player_type *creature_ptr, bool only_browse)
1390 {
1391         COMMAND_CODE mode = 0;
1392         char choice;
1393
1394         COMMAND_CODE menu_line = (use_menu ? 1 : 0);
1395
1396         if (!only_browse)
1397         {
1398                 if (cmd_limit_confused(creature_ptr)) return;
1399                 if (cmd_limit_blind(creature_ptr)) return;
1400                 if (cmd_limit_image(creature_ptr)) return;
1401         }
1402
1403         if (!(repeat_pull(&mode) && 1 <= mode && mode <= 5))
1404         {
1405                 if (only_browse) screen_save();
1406                 do {
1407                         if (!only_browse) screen_save();
1408                         if (use_menu)
1409                         {
1410                                 while (!mode)
1411                                 {
1412 #ifdef JP
1413                                         prt(format(" %s エッセンス一覧", (menu_line == 1) ? "》" : "  "), 2, 14);
1414                                         prt(format(" %s エッセンス抽出", (menu_line == 2) ? "》" : "  "), 3, 14);
1415                                         prt(format(" %s エッセンス消去", (menu_line == 3) ? "》" : "  "), 4, 14);
1416                                         prt(format(" %s エッセンス付加", (menu_line == 4) ? "》" : "  "), 5, 14);
1417                                         prt(format(" %s 武器/防具強化", (menu_line == 5) ? "》" : "  "), 6, 14);
1418                                         prt(format("どの種類の技術を%sますか?", only_browse ? "調べ" : "使い"), 0, 0);
1419 #else
1420                                         prt(format(" %s List essences", (menu_line == 1) ? "> " : "  "), 2, 14);
1421                                         prt(format(" %s Extract essence", (menu_line == 2) ? "> " : "  "), 3, 14);
1422                                         prt(format(" %s Remove essence", (menu_line == 3) ? "> " : "  "), 4, 14);
1423                                         prt(format(" %s Add essence", (menu_line == 4) ? "> " : "  "), 5, 14);
1424                                         prt(format(" %s Enchant weapon/armor", (menu_line == 5) ? "> " : "  "), 6, 14);
1425                                         prt(format("Choose command from menu."), 0, 0);
1426 #endif
1427                                         choice = inkey();
1428                                         switch (choice)
1429                                         {
1430                                         case ESCAPE:
1431                                         case 'z':
1432                                         case 'Z':
1433                                                 screen_load();
1434                                                 return;
1435                                         case '2':
1436                                         case 'j':
1437                                         case 'J':
1438                                                 menu_line++;
1439                                                 break;
1440                                         case '8':
1441                                         case 'k':
1442                                         case 'K':
1443                                                 menu_line += 4;
1444                                                 break;
1445                                         case '\r':
1446                                         case '\n':
1447                                         case 'x':
1448                                         case 'X':
1449                                                 mode = menu_line;
1450                                                 break;
1451                                         }
1452                                         if (menu_line > 5) menu_line -= 5;
1453                                 }
1454                         }
1455
1456                         else
1457                         {
1458                                 while (!mode)
1459                                 {
1460                                         prt(_("  a) エッセンス一覧", "  a) List essences"), 2, 14);
1461                                         prt(_("  b) エッセンス抽出", "  b) Extract essence"), 3, 14);
1462                                         prt(_("  c) エッセンス消去", "  c) Remove essence"), 4, 14);
1463                                         prt(_("  d) エッセンス付加", "  d) Add essence"), 5, 14);
1464                                         prt(_("  e) 武器/防具強化", "  e) Enchant weapon/armor"), 6, 14);
1465 #ifdef JP
1466                                         if (!get_com(format("どの能力を%sますか:", only_browse ? "調べ" : "使い"), &choice, TRUE))
1467 #else
1468                                         if (!get_com("Command :", &choice, TRUE))
1469 #endif
1470                                         {
1471                                                 screen_load();
1472                                                 return;
1473                                         }
1474                                         switch (choice)
1475                                         {
1476                                         case 'A':
1477                                         case 'a':
1478                                                 mode = 1;
1479                                                 break;
1480                                         case 'B':
1481                                         case 'b':
1482                                                 mode = 2;
1483                                                 break;
1484                                         case 'C':
1485                                         case 'c':
1486                                                 mode = 3;
1487                                                 break;
1488                                         case 'D':
1489                                         case 'd':
1490                                                 mode = 4;
1491                                                 break;
1492                                         case 'E':
1493                                         case 'e':
1494                                                 mode = 5;
1495                                                 break;
1496                                         }
1497                                 }
1498                         }
1499
1500                         if (only_browse)
1501                         {
1502                                 char temp[62 * 5];
1503                                 int line, j;
1504
1505                                 /* Clear lines, position cursor  (really should use strlen here) */
1506                                 Term_erase(14, 21, 255);
1507                                 Term_erase(14, 20, 255);
1508                                 Term_erase(14, 19, 255);
1509                                 Term_erase(14, 18, 255);
1510                                 Term_erase(14, 17, 255);
1511                                 Term_erase(14, 16, 255);
1512
1513                                 shape_buffer(kaji_tips[mode - 1], 62, temp, sizeof(temp));
1514                                 for (j = 0, line = 17; temp[j]; j += (1 + strlen(&temp[j])))
1515                                 {
1516                                         prt(&temp[j], line, 15);
1517                                         line++;
1518                                 }
1519                                 mode = 0;
1520                         }
1521                         if (!only_browse) screen_load();
1522                 } while (only_browse);
1523                 repeat_push(mode);
1524         }
1525         switch (mode)
1526         {
1527         case 1: display_essence(creature_ptr); break;
1528         case 2: drain_essence(creature_ptr); break;
1529         case 3: erase_essence(creature_ptr); break;
1530         case 4:
1531                 mode = choose_essence();
1532                 if (mode == 0)
1533                         break;
1534                 add_essence(creature_ptr, mode);
1535                 break;
1536         case 5: add_essence(creature_ptr, 10); break;
1537         }
1538 }