OSDN Git Service

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