OSDN Git Service

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