OSDN Git Service

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