OSDN Git Service

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