OSDN Git Service

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