OSDN Git Service

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