OSDN Git Service

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