OSDN Git Service

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