OSDN Git Service

[Refactor] #40653 Separated mind-magic-eater.c/h from spells-object.c/h
[hengband/hengband.git] / src / spell / spells-object.c
1 /*!
2  * @brief アイテムに影響のある魔法の処理
3  * @date 2019/01/22
4  * @author deskull
5  */
6
7 #include "spell/spells-object.h"
8 #include "action/action-limited.h"
9 #include "autopick/autopick.h"
10 #include "core/asking-player.h"
11 #include "core/player-redraw-types.h"
12 #include "core/player-update-types.h"
13 #include "core/window-redrawer.h"
14 #include "flavor/flavor-describer.h"
15 #include "flavor/object-flavor-types.h"
16 #include "floor/cave.h"
17 #include "floor/floor-object.h"
18 #include "game-option/disturbance-options.h"
19 #include "grid/feature.h"
20 #include "grid/grid.h"
21 #include "inventory/inventory-object.h"
22 #include "inventory/inventory-slot-types.h"
23 #include "inventory/player-inventory.h"
24 #include "monster-race/monster-race.h"
25 #include "monster-race/race-flags1.h"
26 #include "object-enchant/apply-magic.h"
27 #include "object-enchant/item-apply-magic.h"
28 #include "object-enchant/item-feeling.h"
29 #include "object-enchant/object-boost.h"
30 #include "object-enchant/object-ego.h"
31 #include "object-enchant/special-object-flags.h"
32 #include "object-enchant/tr-types.h"
33 #include "object-enchant/trc-types.h"
34 #include "object-enchant/trg-types.h"
35 #include "object-hook/hook-armor.h"
36 #include "object-hook/hook-bow.h"
37 #include "object-hook/hook-checker.h"
38 #include "object-hook/hook-enchant.h"
39 #include "object-hook/hook-magic.h"
40 #include "object-hook/hook-weapon.h"
41 #include "object/item-tester-hooker.h"
42 #include "object/item-use-flags.h"
43 #include "object/object-flags.h"
44 #include "object/object-generator.h"
45 #include "object/object-kind-hook.h"
46 #include "object/object-kind.h"
47 #include "perception/object-perception.h"
48 #include "player-info/avatar.h"
49 #include "player/player-class.h"
50 #include "player/player-damage.h"
51 #include "player/player-status.h"
52 #include "racial/racial-android.h"
53 #include "spell-kind/spells-perception.h"
54 #include "status/bad-status-setter.h"
55 #include "sv-definition/sv-food-types.h"
56 #include "sv-definition/sv-lite-types.h"
57 #include "sv-definition/sv-other-types.h"
58 #include "sv-definition/sv-protector-types.h"
59 #include "sv-definition/sv-scroll-types.h"
60 #include "sv-definition/sv-staff-types.h"
61 #include "sv-definition/sv-weapon-types.h"
62 #include "system/artifact-type-definition.h"
63 #include "system/floor-type-definition.h"
64 #include "system/object-type-definition.h"
65 #include "target/target-getter.h"
66 #include "term/screen-processor.h"
67 #include "util/bit-flags-calculator.h"
68 #include "view/display-messages.h"
69
70 typedef struct {
71     tval_type tval;
72     OBJECT_SUBTYPE_VALUE sval;
73     PERCENTAGE prob;
74     byte flag;
75 } amuse_type;
76
77 /*!
78  * @brief 装備強化処理の失敗率定数(千分率) /
79  * Used by the "enchant" function (chance of failure)
80  * (modified for Zangband, we need better stuff there...) -- TY
81  * @return なし
82  */
83 static int enchant_table[16] = { 0, 10, 50, 100, 200, 300, 400, 500, 650, 800, 950, 987, 993, 995, 998, 1000 };
84
85 /*
86  * Scatter some "amusing" objects near the player
87  */
88
89 #define AMS_NOTHING 0x00 /* No restriction */
90 #define AMS_NO_UNIQUE 0x01 /* Don't make the amusing object of uniques */
91 #define AMS_FIXED_ART 0x02 /* Make a fixed artifact based on the amusing object */
92 #define AMS_MULTIPLE 0x04 /* Drop 1-3 objects for one type */
93 #define AMS_PILE 0x08 /* Drop 1-99 pile objects for one type */
94
95 static amuse_type amuse_info[]
96     = { { TV_BOTTLE, SV_ANY, 5, AMS_NOTHING }, { TV_JUNK, SV_ANY, 3, AMS_MULTIPLE }, { TV_SPIKE, SV_ANY, 10, AMS_PILE }, { TV_STATUE, SV_ANY, 15, AMS_NOTHING },
97           { TV_CORPSE, SV_ANY, 15, AMS_NO_UNIQUE }, { TV_SKELETON, SV_ANY, 10, AMS_NO_UNIQUE }, { TV_FIGURINE, SV_ANY, 10, AMS_NO_UNIQUE },
98           { TV_PARCHMENT, SV_ANY, 1, AMS_NOTHING }, { TV_POLEARM, SV_TSURIZAO, 3, AMS_NOTHING }, // Fishing Pole of Taikobo
99           { TV_SWORD, SV_BROKEN_DAGGER, 3, AMS_FIXED_ART }, // Broken Dagger of Magician
100           { TV_SWORD, SV_BROKEN_DAGGER, 10, AMS_NOTHING }, { TV_SWORD, SV_BROKEN_SWORD, 5, AMS_NOTHING }, { TV_SCROLL, SV_SCROLL_AMUSEMENT, 10, AMS_NOTHING },
101
102           { 0, 0, 0, 0 } };
103
104 /*!
105  * @brief 誰得ドロップを行う。
106  * @param creature_ptr プレーヤーへの参照ポインタ
107  * @param y1 配置したいフロアのY座標
108  * @param x1 配置したいフロアのX座標
109  * @param num 誰得の処理回数
110  * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
111  * @return なし
112  */
113 void amusement(player_type *creature_ptr, POSITION y1, POSITION x1, int num, bool known)
114 {
115     int t = 0;
116     for (int n = 0; amuse_info[n].tval != 0; n++) {
117         t += amuse_info[n].prob;
118     }
119
120     /* Acquirement */
121     object_type *i_ptr;
122     object_type object_type_body;
123     while (num) {
124         int i;
125         KIND_OBJECT_IDX k_idx;
126         ARTIFACT_IDX a_idx = 0;
127         int r = randint0(t);
128         bool insta_art, fixed_art;
129
130         for (i = 0;; i++) {
131             r -= amuse_info[i].prob;
132             if (r <= 0)
133                 break;
134         }
135         i_ptr = &object_type_body;
136         object_wipe(i_ptr);
137         k_idx = lookup_kind(amuse_info[i].tval, amuse_info[i].sval);
138
139         /* Paranoia - reroll if nothing */
140         if (!k_idx)
141             continue;
142
143         /* Search an artifact index if need */
144         insta_art = (k_info[k_idx].gen_flags & TRG_INSTA_ART);
145         fixed_art = (amuse_info[i].flag & AMS_FIXED_ART);
146
147         if (insta_art || fixed_art) {
148             for (a_idx = 1; a_idx < max_a_idx; a_idx++) {
149                 if (insta_art && !(a_info[a_idx].gen_flags & TRG_INSTA_ART))
150                     continue;
151                 if (a_info[a_idx].tval != k_info[k_idx].tval)
152                     continue;
153                 if (a_info[a_idx].sval != k_info[k_idx].sval)
154                     continue;
155                 if (a_info[a_idx].cur_num > 0)
156                     continue;
157                 break;
158             }
159
160             if (a_idx >= max_a_idx)
161                 continue;
162         }
163
164         /* Make an object (if possible) */
165         object_prep(creature_ptr, i_ptr, k_idx);
166         if (a_idx)
167             i_ptr->name1 = a_idx;
168         apply_magic(creature_ptr, i_ptr, 1, AM_NO_FIXED_ART);
169
170         if (amuse_info[i].flag & AMS_NO_UNIQUE) {
171             if (r_info[i_ptr->pval].flags1 & RF1_UNIQUE)
172                 continue;
173         }
174
175         if (amuse_info[i].flag & AMS_MULTIPLE)
176             i_ptr->number = randint1(3);
177         if (amuse_info[i].flag & AMS_PILE)
178             i_ptr->number = randint1(99);
179
180         if (known) {
181             object_aware(creature_ptr, i_ptr);
182             object_known(i_ptr);
183         }
184
185         /* Paranoia - reroll if nothing */
186         if (!(i_ptr->k_idx))
187             continue;
188
189         (void)drop_near(creature_ptr, i_ptr, -1, y1, x1);
190
191         num--;
192     }
193 }
194
195 /*!
196  * @brief 獲得ドロップを行う。
197  * Scatter some "great" objects near the player
198  * @param caster_ptr プレーヤーへの参照ポインタ
199  * @param y1 配置したいフロアのY座標
200  * @param x1 配置したいフロアのX座標
201  * @param num 獲得の処理回数
202  * @param great TRUEならば必ず高級品以上を落とす
203  * @param special TRUEならば必ず特別品を落とす
204  * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
205  * @return なし
206  */
207 void acquirement(player_type *caster_ptr, POSITION y1, POSITION x1, int num, bool great, bool special, bool known)
208 {
209     object_type *i_ptr;
210     object_type object_type_body;
211     BIT_FLAGS mode = AM_GOOD | (great || special ? AM_GREAT : 0L) | (special ? AM_SPECIAL : 0L);
212
213     /* Acquirement */
214     while (num--) {
215         i_ptr = &object_type_body;
216         object_wipe(i_ptr);
217
218         /* Make a good (or great) object (if possible) */
219         if (!make_object(caster_ptr, i_ptr, mode))
220             continue;
221
222         if (known) {
223             object_aware(caster_ptr, i_ptr);
224             object_known(i_ptr);
225         }
226
227         (void)drop_near(caster_ptr, i_ptr, -1, y1, x1);
228     }
229 }
230
231 void acquire_chaos_weapon(player_type *creature_ptr)
232 {
233     object_type forge;
234     object_type *q_ptr = &forge;
235     tval_type dummy = TV_SWORD;
236     OBJECT_SUBTYPE_VALUE dummy2;
237     switch (randint1(creature_ptr->lev)) {
238     case 0:
239     case 1:
240         dummy2 = SV_DAGGER;
241         break;
242     case 2:
243     case 3:
244         dummy2 = SV_MAIN_GAUCHE;
245         break;
246     case 4:
247         dummy2 = SV_TANTO;
248         break;
249     case 5:
250     case 6:
251         dummy2 = SV_RAPIER;
252         break;
253     case 7:
254     case 8:
255         dummy2 = SV_SMALL_SWORD;
256         break;
257     case 9:
258     case 10:
259         dummy2 = SV_BASILLARD;
260         break;
261     case 11:
262     case 12:
263     case 13:
264         dummy2 = SV_SHORT_SWORD;
265         break;
266     case 14:
267     case 15:
268         dummy2 = SV_SABRE;
269         break;
270     case 16:
271     case 17:
272         dummy2 = SV_CUTLASS;
273         break;
274     case 18:
275         dummy2 = SV_WAKIZASHI;
276         break;
277     case 19:
278         dummy2 = SV_KHOPESH;
279         break;
280     case 20:
281         dummy2 = SV_TULWAR;
282         break;
283     case 21:
284         dummy2 = SV_BROAD_SWORD;
285         break;
286     case 22:
287     case 23:
288         dummy2 = SV_LONG_SWORD;
289         break;
290     case 24:
291     case 25:
292         dummy2 = SV_SCIMITAR;
293         break;
294     case 26:
295         dummy2 = SV_NINJATO;
296         break;
297     case 27:
298         dummy2 = SV_KATANA;
299         break;
300     case 28:
301     case 29:
302         dummy2 = SV_BASTARD_SWORD;
303         break;
304     case 30:
305         dummy2 = SV_GREAT_SCIMITAR;
306         break;
307     case 31:
308         dummy2 = SV_CLAYMORE;
309         break;
310     case 32:
311         dummy2 = SV_ESPADON;
312         break;
313     case 33:
314         dummy2 = SV_TWO_HANDED_SWORD;
315         break;
316     case 34:
317         dummy2 = SV_FLAMBERGE;
318         break;
319     case 35:
320         dummy2 = SV_NO_DACHI;
321         break;
322     case 36:
323         dummy2 = SV_EXECUTIONERS_SWORD;
324         break;
325     case 37:
326         dummy2 = SV_ZWEIHANDER;
327         break;
328     case 38:
329         dummy2 = SV_HAYABUSA;
330         break;
331     default:
332         dummy2 = SV_BLADE_OF_CHAOS;
333     }
334
335     object_prep(creature_ptr, q_ptr, lookup_kind(dummy, dummy2));
336     q_ptr->to_h = 3 + randint1(creature_ptr->current_floor_ptr->dun_level) % 10;
337     q_ptr->to_d = 3 + randint1(creature_ptr->current_floor_ptr->dun_level) % 10;
338     one_resistance(q_ptr);
339     q_ptr->name2 = EGO_CHAOTIC;
340     (void)drop_near(creature_ptr, q_ptr, -1, creature_ptr->y, creature_ptr->x);
341 }
342
343 /*!
344  * todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
345  * @brief 防具呪縛処理 /
346  * Curse the players armor
347  * @return 何も持っていない場合を除き、常にTRUEを返す
348  */
349 bool curse_armor(player_type *owner_ptr)
350 {
351     /* Curse the body armor */
352     object_type *o_ptr;
353     o_ptr = &owner_ptr->inventory_list[INVEN_BODY];
354
355     if (!o_ptr->k_idx)
356         return FALSE;
357
358     GAME_TEXT o_name[MAX_NLEN];
359     describe_flavor(owner_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
360
361     /* Attempt a saving throw for artifacts */
362     if (object_is_artifact(o_ptr) && (randint0(100) < 50)) {
363         /* Cool */
364 #ifdef JP
365         msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "防具", o_name);
366 #else
367         msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your armor", o_name);
368 #endif
369         return TRUE;
370     }
371
372     /* not artifact or failed save... */
373     msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
374     chg_virtue(owner_ptr, V_ENCHANT, -5);
375
376     /* Blast the armor */
377     o_ptr->name1 = 0;
378     o_ptr->name2 = EGO_BLASTED;
379     o_ptr->to_a = 0 - randint1(5) - randint1(5);
380     o_ptr->to_h = 0;
381     o_ptr->to_d = 0;
382     o_ptr->ac = 0;
383     o_ptr->dd = 0;
384     o_ptr->ds = 0;
385
386     for (int i = 0; i < TR_FLAG_SIZE; i++)
387         o_ptr->art_flags[i] = 0;
388
389     /* Curse it */
390     o_ptr->curse_flags = TRC_CURSED;
391
392     /* Break it */
393     o_ptr->ident |= (IDENT_BROKEN);
394     owner_ptr->update |= (PU_BONUS | PU_MANA);
395     owner_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
396     return TRUE;
397 }
398
399 /*!
400  * todo 元のreturnは間違っているが、修正後の↓文がどれくらい正しいかは要チェック
401  * @brief 武器呪縛処理 /
402  * Curse the players weapon
403  * @param owner_ptr 所持者の参照ポインタ
404  * @param force 無条件に呪縛を行うならばTRUE
405  * @param o_ptr 呪縛する武器のアイテム情報参照ポインタ
406  * @return 何も持っていない場合を除き、常にTRUEを返す
407  */
408 bool curse_weapon_object(player_type *owner_ptr, bool force, object_type *o_ptr)
409 {
410     if (!o_ptr->k_idx)
411         return FALSE;
412
413     GAME_TEXT o_name[MAX_NLEN];
414     describe_flavor(owner_ptr, o_name, o_ptr, OD_OMIT_PREFIX);
415
416     /* Attempt a saving throw */
417     if (object_is_artifact(o_ptr) && (randint0(100) < 50) && !force) {
418 #ifdef JP
419         msg_format("%sが%sを包み込もうとしたが、%sはそれを跳ね返した!", "恐怖の暗黒オーラ", "武器", o_name);
420 #else
421         msg_format("A %s tries to %s, but your %s resists the effects!", "terrible black aura", "surround your weapon", o_name);
422 #endif
423         return TRUE;
424     }
425
426     /* not artifact or failed save... */
427     if (!force)
428         msg_format(_("恐怖の暗黒オーラがあなたの%sを包み込んだ!", "A terrible black aura blasts your %s!"), o_name);
429     chg_virtue(owner_ptr, V_ENCHANT, -5);
430
431     /* Shatter the weapon */
432     o_ptr->name1 = 0;
433     o_ptr->name2 = EGO_SHATTERED;
434     o_ptr->to_h = 0 - randint1(5) - randint1(5);
435     o_ptr->to_d = 0 - randint1(5) - randint1(5);
436     o_ptr->to_a = 0;
437     o_ptr->ac = 0;
438     o_ptr->dd = 0;
439     o_ptr->ds = 0;
440
441     for (int i = 0; i < TR_FLAG_SIZE; i++)
442         o_ptr->art_flags[i] = 0;
443
444     /* Curse it */
445     o_ptr->curse_flags = TRC_CURSED;
446
447     /* Break it */
448     o_ptr->ident |= (IDENT_BROKEN);
449     owner_ptr->update |= (PU_BONUS | PU_MANA);
450     owner_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
451     return TRUE;
452 }
453
454 /*!
455  * @brief 防具の錆止め防止処理
456  * @param caster_ptr 錆止め実行者の参照ポインタ
457  * @return ターン消費を要する処理を行ったならばTRUEを返す
458  */
459 bool rustproof(player_type *caster_ptr)
460 {
461     /* Select a piece of armour */
462     item_tester_hook = object_is_armour;
463
464     concptr q = _("どの防具に錆止めをしますか?", "Rustproof which piece of armour? ");
465     concptr s = _("錆止めできるものがありません。", "You have nothing to rustproof.");
466
467     OBJECT_IDX item;
468     object_type *o_ptr;
469     o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
470     if (!o_ptr)
471         return FALSE;
472
473     GAME_TEXT o_name[MAX_NLEN];
474     describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
475
476     add_flag(o_ptr->art_flags, TR_IGNORE_ACID);
477
478     if ((o_ptr->to_a < 0) && !object_is_cursed(o_ptr)) {
479 #ifdef JP
480         msg_format("%sは新品同様になった!", o_name);
481 #else
482         msg_format("%s %s look%s as good as new!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
483 #endif
484
485         o_ptr->to_a = 0;
486     }
487
488 #ifdef JP
489     msg_format("%sは腐食しなくなった。", o_name);
490 #else
491     msg_format("%s %s %s now protected against corrosion.", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "are" : "is"));
492 #endif
493
494     calc_android_exp(caster_ptr);
495     return TRUE;
496 }
497
498 /*!
499  * @brief ボルトのエゴ化処理(火炎エゴのみ) /
500  * Enchant some bolts
501  * @param caster_ptr プレーヤーへの参照ポインタ
502  * @return なし
503  */
504 void brand_bolts(player_type *caster_ptr)
505 {
506     /* Use the first acceptable bolts */
507     for (int i = 0; i < INVEN_PACK; i++) {
508         object_type *o_ptr = &caster_ptr->inventory_list[i];
509
510         /* Skip non-bolts */
511         if (o_ptr->tval != TV_BOLT)
512             continue;
513
514         /* Skip artifacts and ego-items */
515         if (object_is_artifact(o_ptr) || object_is_ego(o_ptr))
516             continue;
517
518         /* Skip cursed/broken items */
519         if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
520             continue;
521
522         /* Randomize */
523         if (randint0(100) < 75)
524             continue;
525
526         msg_print(_("クロスボウの矢が炎のオーラに包まれた!", "Your bolts are covered in a fiery aura!"));
527
528         /* Ego-item */
529         o_ptr->name2 = EGO_FLAME;
530         enchant(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
531         return;
532     }
533
534     if (flush_failure)
535         flush();
536     msg_print(_("炎で強化するのに失敗した。", "The fiery enchantment failed."));
537 }
538
539 bool perilous_secrets(player_type *user_ptr)
540 {
541     if (!ident_spell(user_ptr, FALSE, 0))
542         return FALSE;
543
544     if (mp_ptr->spell_book) {
545         /* Sufficient mana */
546         if (20 <= user_ptr->csp) {
547             /* Use some mana */
548             user_ptr->csp -= 20;
549         }
550
551         /* Over-exert the player */
552         else {
553             int oops = 20 - user_ptr->csp;
554
555             /* No mana left */
556             user_ptr->csp = 0;
557             user_ptr->csp_frac = 0;
558
559             msg_print(_("石を制御できない!", "You are too weak to control the stone!"));
560             /* Hack -- Bypass free action */
561             (void)set_paralyzed(user_ptr, user_ptr->paralyzed + randint1(5 * oops + 1));
562
563             /* Confusing. */
564             (void)set_confused(user_ptr, user_ptr->confused + randint1(5 * oops + 1));
565         }
566
567         user_ptr->redraw |= (PR_MANA);
568     }
569
570     take_hit(user_ptr, DAMAGE_LOSELIFE, damroll(1, 12), _("危険な秘密", "perilous secrets"), -1);
571     /* Confusing. */
572     if (one_in_(5))
573         (void)set_confused(user_ptr, user_ptr->confused + randint1(10));
574
575     /* Exercise a little care... */
576     if (one_in_(20))
577         take_hit(user_ptr, DAMAGE_LOSELIFE, damroll(4, 10), _("危険な秘密", "perilous secrets"), -1);
578     return TRUE;
579 }
580
581 /*!
582  * @brief 寿命つき光源の燃素追加処理 /
583  * Charge a lite (torch or latern)
584  * @return なし
585  */
586 void phlogiston(player_type *caster_ptr)
587 {
588     GAME_TURN max_flog = 0;
589     object_type *o_ptr = &caster_ptr->inventory_list[INVEN_LITE];
590
591     /* It's a lamp */
592     if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_LANTERN)) {
593         max_flog = FUEL_LAMP;
594     }
595
596     /* It's a torch */
597     else if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH)) {
598         max_flog = FUEL_TORCH;
599     }
600
601     /* No torch to refill */
602     else {
603         msg_print(_("燃素を消費するアイテムを装備していません。", "You are not wielding anything which uses phlogiston."));
604         return;
605     }
606
607     if (o_ptr->xtra4 >= max_flog) {
608         msg_print(_("このアイテムにはこれ以上燃素を補充できません。", "No more phlogiston can be put in this item."));
609         return;
610     }
611
612     /* Refuel */
613     o_ptr->xtra4 += (XTRA16)(max_flog / 2);
614     msg_print(_("照明用アイテムに燃素を補充した。", "You add phlogiston to your light item."));
615
616     if (o_ptr->xtra4 >= max_flog) {
617         o_ptr->xtra4 = (XTRA16)max_flog;
618         msg_print(_("照明用アイテムは満タンになった。", "Your light item is full."));
619     }
620
621     caster_ptr->update |= (PU_TORCH);
622 }
623
624 /*!
625  * @brief 武器の祝福処理 /
626  * Bless a weapon
627  * @return ターン消費を要する処理を行ったならばTRUEを返す
628  */
629 bool bless_weapon(player_type *caster_ptr)
630 {
631     /* Bless only weapons */
632     item_tester_hook = object_is_weapon;
633
634     concptr q = _("どのアイテムを祝福しますか?", "Bless which weapon? ");
635     concptr s = _("祝福できる武器がありません。", "You have weapon to bless.");
636
637     OBJECT_IDX item;
638     object_type *o_ptr;
639     o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
640     if (!o_ptr)
641         return FALSE;
642
643     GAME_TEXT o_name[MAX_NLEN];
644     describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
645     BIT_FLAGS flgs[TR_FLAG_SIZE];
646     object_flags(caster_ptr, o_ptr, flgs);
647
648     if (object_is_cursed(o_ptr)) {
649         if (((o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint1(100) < 33)) || have_flag(flgs, TR_ADD_L_CURSE) || have_flag(flgs, TR_ADD_H_CURSE)
650             || (o_ptr->curse_flags & TRC_PERMA_CURSE)) {
651 #ifdef JP
652             msg_format("%sを覆う黒いオーラは祝福を跳ね返した!", o_name);
653 #else
654             msg_format("The black aura on %s %s disrupts the blessing!", ((item >= 0) ? "your" : "the"), o_name);
655 #endif
656
657             return TRUE;
658         }
659
660 #ifdef JP
661         msg_format("%s から邪悪なオーラが消えた。", o_name);
662 #else
663         msg_format("A malignant aura leaves %s %s.", ((item >= 0) ? "your" : "the"), o_name);
664 #endif
665
666         o_ptr->curse_flags = 0L;
667
668         o_ptr->ident |= (IDENT_SENSE);
669         o_ptr->feeling = FEEL_NONE;
670
671         /* Recalculate the bonuses */
672         caster_ptr->update |= (PU_BONUS);
673         caster_ptr->window |= (PW_EQUIP);
674     }
675
676     /*
677      * Next, we try to bless it. Artifacts have a 1/3 chance of
678      * being blessed, otherwise, the operation simply disenchants
679      * them, godly power negating the magic. Ok, the explanation
680      * is silly, but otherwise priests would always bless every
681      * artifact weapon they find. Ego weapons and normal weapons
682      * can be blessed automatically.
683      */
684     if (have_flag(flgs, TR_BLESSED)) {
685 #ifdef JP
686         msg_format("%s は既に祝福されている。", o_name);
687 #else
688         msg_format("%s %s %s blessed already.", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "were" : "was"));
689 #endif
690
691         return TRUE;
692     }
693
694     if (!(object_is_artifact(o_ptr) || object_is_ego(o_ptr)) || one_in_(3)) {
695 #ifdef JP
696         msg_format("%sは輝いた!", o_name);
697 #else
698         msg_format("%s %s shine%s!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
699 #endif
700
701         add_flag(o_ptr->art_flags, TR_BLESSED);
702         o_ptr->discount = 99;
703     } else {
704         bool dis_happened = FALSE;
705         msg_print(_("その武器は祝福を嫌っている!", "The weapon resists your blessing!"));
706
707         /* Disenchant tohit */
708         if (o_ptr->to_h > 0) {
709             o_ptr->to_h--;
710             dis_happened = TRUE;
711         }
712
713         if ((o_ptr->to_h > 5) && (randint0(100) < 33))
714             o_ptr->to_h--;
715
716         /* Disenchant todam */
717         if (o_ptr->to_d > 0) {
718             o_ptr->to_d--;
719             dis_happened = TRUE;
720         }
721
722         if ((o_ptr->to_d > 5) && (randint0(100) < 33))
723             o_ptr->to_d--;
724
725         /* Disenchant toac */
726         if (o_ptr->to_a > 0) {
727             o_ptr->to_a--;
728             dis_happened = TRUE;
729         }
730
731         if ((o_ptr->to_a > 5) && (randint0(100) < 33))
732             o_ptr->to_a--;
733
734         if (dis_happened) {
735             msg_print(_("周囲が凡庸な雰囲気で満ちた...", "There is a static feeling in the air..."));
736
737 #ifdef JP
738             msg_format("%s は劣化した!", o_name);
739 #else
740             msg_format("%s %s %s disenchanted!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "were" : "was"));
741 #endif
742         }
743     }
744
745     caster_ptr->update |= (PU_BONUS);
746     caster_ptr->window |= (PW_EQUIP | PW_PLAYER);
747     calc_android_exp(caster_ptr);
748
749     return TRUE;
750 }
751
752 /*!
753  * @brief 盾磨き処理 /
754  * pulish shield
755  * @return ターン消費を要する処理を行ったならばTRUEを返す
756  */
757 bool pulish_shield(player_type *caster_ptr)
758 {
759     concptr q = _("どの盾を磨きますか?", "Pulish which weapon? ");
760     concptr s = _("磨く盾がありません。", "You have weapon to pulish.");
761
762     OBJECT_IDX item;
763     object_type *o_ptr;
764     o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), TV_SHIELD);
765     if (!o_ptr)
766         return FALSE;
767
768     GAME_TEXT o_name[MAX_NLEN];
769     describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
770     BIT_FLAGS flgs[TR_FLAG_SIZE];
771     object_flags(caster_ptr, o_ptr, flgs);
772
773     bool is_pulish_successful = o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr);
774     is_pulish_successful &= !object_is_cursed(o_ptr);
775     is_pulish_successful &= (o_ptr->sval != SV_MIRROR_SHIELD);
776     if (is_pulish_successful) {
777 #ifdef JP
778         msg_format("%sは輝いた!", o_name);
779 #else
780         msg_format("%s %s shine%s!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
781 #endif
782         o_ptr->name2 = EGO_REFLECTION;
783         enchant(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOAC);
784
785         o_ptr->discount = 99;
786         chg_virtue(caster_ptr, V_ENCHANT, 2);
787
788         return TRUE;
789     }
790
791     if (flush_failure)
792         flush();
793
794     msg_print(_("失敗した。", "Failed."));
795     chg_virtue(caster_ptr, V_ENCHANT, -2);
796     calc_android_exp(caster_ptr);
797     return FALSE;
798 }
799
800 /*!
801  * @brief 呪いの打ち破り処理 /
802  * Break the curse of an item
803  * @param o_ptr 呪い装備情報の参照ポインタ
804  * @return なし
805  */
806 static void break_curse(object_type *o_ptr)
807 {
808     BIT_FLAGS is_curse_broken
809         = object_is_cursed(o_ptr) && !(o_ptr->curse_flags & TRC_PERMA_CURSE) && !(o_ptr->curse_flags & TRC_HEAVY_CURSE) && (randint0(100) < 25);
810     if (!is_curse_broken) {
811         return;
812     }
813
814     msg_print(_("かけられていた呪いが打ち破られた!", "The curse is broken!"));
815
816     o_ptr->curse_flags = 0L;
817     o_ptr->ident |= (IDENT_SENSE);
818     o_ptr->feeling = FEEL_NONE;
819 }
820
821 /*!
822  * @brief 装備修正強化処理 /
823  * Enchants a plus onto an item. -RAK-
824  * @param caster_ptr プレーヤーへの参照ポインタ
825  * @param o_ptr 強化するアイテムの参照ポインタ
826  * @param n 強化基本量
827  * @param eflag 強化オプション(命中/ダメージ/AC)
828  * @return 強化に成功した場合TRUEを返す
829  * @details
830  * <pre>
831  * Revamped!  Now takes item pointer, number of times to try enchanting,
832  * and a flag of what to try enchanting.  Artifacts resist enchantment
833  * some of the time, and successful enchantment to at least +0 might
834  * break a curse on the item. -CFT-
835  *
836  * Note that an item can technically be enchanted all the way to +15 if
837  * you wait a very, very, long time.  Going from +9 to +10 only works
838  * about 5% of the time, and from +10 to +11 only about 1% of the time.
839  *
840  * Note that this function can now be used on "piles" of items, and
841  * the larger the pile, the lower the chance of success.
842  * </pre>
843  */
844 bool enchant(player_type *caster_ptr, object_type *o_ptr, int n, int eflag)
845 {
846     /* Large piles resist enchantment */
847     int prob = o_ptr->number * 100;
848
849     /* Missiles are easy to enchant */
850     if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT)) {
851         prob = prob / 20;
852     }
853
854     /* Try "n" times */
855     int chance;
856     bool res = FALSE;
857     bool a = object_is_artifact(o_ptr);
858     bool force = (eflag & ENCH_FORCE);
859     for (int i = 0; i < n; i++) {
860         /* Hack -- Roll for pile resistance */
861         if (!force && randint0(prob) >= 100)
862             continue;
863
864         /* Enchant to hit */
865         if (eflag & ENCH_TOHIT) {
866             if (o_ptr->to_h < 0)
867                 chance = 0;
868             else if (o_ptr->to_h > 15)
869                 chance = 1000;
870             else
871                 chance = enchant_table[o_ptr->to_h];
872
873             if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
874                 o_ptr->to_h++;
875                 res = TRUE;
876
877                 /* only when you get it above -1 -CFT */
878                 if (o_ptr->to_h >= 0)
879                     break_curse(o_ptr);
880             }
881         }
882
883         /* Enchant to damage */
884         if (eflag & ENCH_TODAM) {
885             if (o_ptr->to_d < 0)
886                 chance = 0;
887             else if (o_ptr->to_d > 15)
888                 chance = 1000;
889             else
890                 chance = enchant_table[o_ptr->to_d];
891
892             if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
893                 o_ptr->to_d++;
894                 res = TRUE;
895
896                 /* only when you get it above -1 -CFT */
897                 if (o_ptr->to_d >= 0)
898                     break_curse(o_ptr);
899             }
900         }
901
902         /* Enchant to armor class */
903         if (!(eflag & ENCH_TOAC)) {
904             continue;
905         }
906
907         if (o_ptr->to_a < 0)
908             chance = 0;
909         else if (o_ptr->to_a > 15)
910             chance = 1000;
911         else
912             chance = enchant_table[o_ptr->to_a];
913
914         if (force || ((randint1(1000) > chance) && (!a || (randint0(100) < 50)))) {
915             o_ptr->to_a++;
916             res = TRUE;
917
918             /* only when you get it above -1 -CFT */
919             if (o_ptr->to_a >= 0)
920                 break_curse(o_ptr);
921         }
922     }
923
924     /* Failure */
925     if (!res)
926         return FALSE;
927     caster_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
928     caster_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
929
930     calc_android_exp(caster_ptr);
931
932     /* Success */
933     return TRUE;
934 }
935
936 /*!
937  * @brief 装備修正強化処理のメインルーチン /
938  * Enchant an item (in the inventory or on the floor)
939  * @param caster_ptr プレーヤーへの参照ポインタ
940  * @param num_hit 命中修正量
941  * @param num_dam ダメージ修正量
942  * @param num_ac AC修正量
943  * @return 強化に成功した場合TRUEを返す
944  * @details
945  * Note that "num_ac" requires armour, else weapon
946  * Returns TRUE if attempted, FALSE if cancelled
947  */
948 bool enchant_spell(player_type *caster_ptr, HIT_PROB num_hit, HIT_POINT num_dam, ARMOUR_CLASS num_ac)
949 {
950     /* Assume enchant weapon */
951     item_tester_hook = object_allow_enchant_weapon;
952
953     /* Enchant armor if requested */
954     if (num_ac)
955         item_tester_hook = object_is_armour;
956
957     concptr q = _("どのアイテムを強化しますか? ", "Enchant which item? ");
958     concptr s = _("強化できるアイテムがない。", "You have nothing to enchant.");
959
960     OBJECT_IDX item;
961     object_type *o_ptr;
962     o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT), 0);
963     if (!o_ptr)
964         return FALSE;
965
966     GAME_TEXT o_name[MAX_NLEN];
967     describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
968 #ifdef JP
969     msg_format("%s は明るく輝いた!", o_name);
970 #else
971     msg_format("%s %s glow%s brightly!", ((item >= 0) ? "Your" : "The"), o_name, ((o_ptr->number > 1) ? "" : "s"));
972 #endif
973
974     /* Enchant */
975     bool is_enchant_successful = FALSE;
976     if (enchant(caster_ptr, o_ptr, num_hit, ENCH_TOHIT))
977         is_enchant_successful = TRUE;
978     if (enchant(caster_ptr, o_ptr, num_dam, ENCH_TODAM))
979         is_enchant_successful = TRUE;
980     if (enchant(caster_ptr, o_ptr, num_ac, ENCH_TOAC))
981         is_enchant_successful = TRUE;
982
983     if (!is_enchant_successful) {
984         if (flush_failure)
985             flush();
986         msg_print(_("強化に失敗した。", "The enchantment failed."));
987         if (one_in_(3))
988             chg_virtue(caster_ptr, V_ENCHANT, -1);
989     } else
990         chg_virtue(caster_ptr, V_ENCHANT, 1);
991
992     calc_android_exp(caster_ptr);
993
994     /* Something happened */
995     return TRUE;
996 }
997
998 /*!
999  * @brief 武器へのエゴ付加処理 /
1000  * Brand the current weapon
1001  * @param caster_ptr プレーヤーへの参照ポインタ
1002  * @param brand_type エゴ化ID(e_info.txtとは連動していない)
1003  * @return なし
1004  */
1005 void brand_weapon(player_type *caster_ptr, int brand_type)
1006 {
1007     /* Assume enchant weapon */
1008     item_tester_hook = object_allow_enchant_melee_weapon;
1009
1010     concptr q = _("どの武器を強化しますか? ", "Enchant which weapon? ");
1011     concptr s = _("強化できる武器がない。", "You have nothing to enchant.");
1012
1013     OBJECT_IDX item;
1014     object_type *o_ptr;
1015     o_ptr = choose_object(caster_ptr, &item, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT), 0);
1016     if (!o_ptr)
1017         return;
1018
1019     bool is_special_item = o_ptr->k_idx && !object_is_artifact(o_ptr) && !object_is_ego(o_ptr) && !object_is_cursed(o_ptr)
1020         && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) && !((o_ptr->tval == TV_POLEARM) && (o_ptr->sval == SV_DEATH_SCYTHE))
1021         && !((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_DIAMOND_EDGE));
1022     if (!is_special_item) {
1023         if (flush_failure)
1024             flush();
1025
1026         msg_print(_("属性付加に失敗した。", "The branding failed."));
1027         chg_virtue(caster_ptr, V_ENCHANT, -2);
1028         calc_android_exp(caster_ptr);
1029         return;
1030     }
1031
1032     /* Let's get the name before it is changed... */
1033     GAME_TEXT o_name[MAX_NLEN];
1034     describe_flavor(caster_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
1035
1036     concptr act = NULL;
1037     switch (brand_type) {
1038     case 17:
1039         if (o_ptr->tval == TV_SWORD) {
1040             act = _("は鋭さを増した!", "becomes very sharp!");
1041
1042             o_ptr->name2 = EGO_SHARPNESS;
1043             o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, caster_ptr->current_floor_ptr->dun_level) + 1;
1044
1045             if ((o_ptr->sval == SV_HAYABUSA) && (o_ptr->pval > 2))
1046                 o_ptr->pval = 2;
1047         } else {
1048             act = _("は破壊力を増した!", "seems very powerful.");
1049             o_ptr->name2 = EGO_EARTHQUAKES;
1050             o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, caster_ptr->current_floor_ptr->dun_level);
1051         }
1052
1053         break;
1054     case 16:
1055         act = _("は人間の血を求めている!", "seems to be looking for humans!");
1056         o_ptr->name2 = EGO_KILL_HUMAN;
1057         break;
1058     case 15:
1059         act = _("は電撃に覆われた!", "covered with lightning!");
1060         o_ptr->name2 = EGO_BRAND_ELEC;
1061         break;
1062     case 14:
1063         act = _("は酸に覆われた!", "coated with acid!");
1064         o_ptr->name2 = EGO_BRAND_ACID;
1065         break;
1066     case 13:
1067         act = _("は邪悪なる怪物を求めている!", "seems to be looking for evil monsters!");
1068         o_ptr->name2 = EGO_KILL_EVIL;
1069         break;
1070     case 12:
1071         act = _("は異世界の住人の肉体を求めている!", "seems to be looking for demons!");
1072         o_ptr->name2 = EGO_KILL_DEMON;
1073         break;
1074     case 11:
1075         act = _("は屍を求めている!", "seems to be looking for undead!");
1076         o_ptr->name2 = EGO_KILL_UNDEAD;
1077         break;
1078     case 10:
1079         act = _("は動物の血を求めている!", "seems to be looking for animals!");
1080         o_ptr->name2 = EGO_KILL_ANIMAL;
1081         break;
1082     case 9:
1083         act = _("はドラゴンの血を求めている!", "seems to be looking for dragons!");
1084         o_ptr->name2 = EGO_KILL_DRAGON;
1085         break;
1086     case 8:
1087         act = _("はトロルの血を求めている!", "seems to be looking for troll!s");
1088         o_ptr->name2 = EGO_KILL_TROLL;
1089         break;
1090     case 7:
1091         act = _("はオークの血を求めている!", "seems to be looking for orcs!");
1092         o_ptr->name2 = EGO_KILL_ORC;
1093         break;
1094     case 6:
1095         act = _("は巨人の血を求めている!", "seems to be looking for giants!");
1096         o_ptr->name2 = EGO_KILL_GIANT;
1097         break;
1098     case 5:
1099         act = _("は非常に不安定になったようだ。", "seems very unstable now.");
1100         o_ptr->name2 = EGO_TRUMP;
1101         o_ptr->pval = randint1(2);
1102         break;
1103     case 4:
1104         act = _("は血を求めている!", "thirsts for blood!");
1105         o_ptr->name2 = EGO_VAMPIRIC;
1106         break;
1107     case 3:
1108         act = _("は毒に覆われた。", "is coated with poison.");
1109         o_ptr->name2 = EGO_BRAND_POIS;
1110         break;
1111     case 2:
1112         act = _("は純ログルスに飲み込まれた。", "is engulfed in raw Logrus!");
1113         o_ptr->name2 = EGO_CHAOTIC;
1114         break;
1115     case 1:
1116         act = _("は炎のシールドに覆われた!", "is covered in a fiery shield!");
1117         o_ptr->name2 = EGO_BRAND_FIRE;
1118         break;
1119     default:
1120         act = _("は深く冷たいブルーに輝いた!", "glows deep, icy blue!");
1121         o_ptr->name2 = EGO_BRAND_COLD;
1122         break;
1123     }
1124
1125     msg_format(_("あなたの%s%s", "Your %s %s"), o_name, act);
1126     enchant(caster_ptr, o_ptr, randint0(3) + 4, ENCH_TOHIT | ENCH_TODAM);
1127
1128     o_ptr->discount = 99;
1129     chg_virtue(caster_ptr, V_ENCHANT, 2);
1130     calc_android_exp(caster_ptr);
1131 }
1132
1133 bool create_ration(player_type *creature_ptr)
1134 {
1135     object_type *q_ptr;
1136     object_type forge;
1137     q_ptr = &forge;
1138     object_prep(creature_ptr, q_ptr, lookup_kind(TV_FOOD, SV_FOOD_RATION));
1139     (void)drop_near(creature_ptr, q_ptr, -1, creature_ptr->y, creature_ptr->x);
1140     msg_print(_("食事を料理して作った。", "You cook some food."));
1141     return TRUE;
1142 }