OSDN Git Service

[Refactor] #40399 Adjusted inclusion relationship for object1.h
[hengband/hengband.git] / src / object-enchant / object-curse.c
1 #include "system/angband.h"
2 #include "util/util.h"
3 #include "object-enchant/item-feeling.h"
4 #include "object-enchant/object-curse.h"
5 #include "object/object-flavor.h"
6 #include "object/object-hook.h"
7 #include "object/object1.h"
8 #include "object-enchant/tr-types.h"
9 #include "object-enchant/trc-types.h"
10
11 #define MAX_CURSE 18
12 #define TRC_SPECIAL_MASK (TRC_TY_CURSE | TRC_AGGRAVATE)
13 #define TRC_HEAVY_MASK (TRC_TY_CURSE | TRC_AGGRAVATE | TRC_DRAIN_EXP | TRC_ADD_H_CURSE | TRC_CALL_DEMON | TRC_CALL_DRAGON | TRC_CALL_UNDEAD | TRC_TELEPORT)
14
15 /*!
16  * @brief アイテムに付加される可能性のある呪いを指定する。
17  * @param power 呪いの段階
18  * @param o_ptr 呪いをかけられる装備オブジェクトの構造体参照ポインタ
19  * @return 与える呪いのID
20  */
21 BIT_FLAGS get_curse(int power, object_type *o_ptr)
22 {
23         BIT_FLAGS new_curse;
24
25         while (TRUE)
26         {
27                 new_curse = (1 << (randint0(MAX_CURSE)+4));
28                 if (power == 2)
29                 {
30                         if (!(new_curse & TRC_HEAVY_MASK)) continue;
31                 }
32                 else if (power == 1)
33                 {
34                         if (new_curse & TRC_SPECIAL_MASK) continue;
35                 }
36                 else if (power == 0)
37                 {
38                         if (new_curse & TRC_HEAVY_MASK) continue;
39                 }
40
41                 if (new_curse == TRC_LOW_MELEE && !object_is_weapon(o_ptr)) continue;
42                 if (new_curse == TRC_LOW_AC && !object_is_armour(o_ptr)) continue;
43                 break;
44         }
45
46         return new_curse;
47 }
48
49
50 /*!
51  * @brief 装備への呪い付加判定と付加処理
52  * @param owner_ptr プレーヤーへの参照ポインタ
53  * @param chance 呪いの基本確率
54  * @param heavy_chance さらに重い呪いとなる確率
55  * @return なし
56  */
57 void curse_equipment(player_type *owner_ptr, PERCENTAGE chance, PERCENTAGE heavy_chance)
58 {
59         if (randint1(100) > chance) return;
60
61         object_type *o_ptr = &owner_ptr->inventory_list[INVEN_RARM + randint0(12)];
62         if (!o_ptr->k_idx) return;
63         BIT_FLAGS oflgs[TR_FLAG_SIZE];
64         object_flags(o_ptr, oflgs);
65         GAME_TEXT o_name[MAX_NLEN];
66         object_desc(owner_ptr, o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
67
68         /* Extra, biased saving throw for blessed items */
69         if (have_flag(oflgs, TR_BLESSED))
70         {
71 #ifdef JP
72                 msg_format("祝福された%sは呪いを跳ね返した!", o_name);
73 #else
74                 msg_format("Your blessed %s resist%s cursing!", o_name, ((o_ptr->number > 1) ? "" : "s"));
75 #endif
76                 /* Hmmm -- can we wear multiple items? If not, this is unnecessary */
77                 return;
78         }
79
80         bool changed = FALSE;
81         int curse_power = 0;
82         if ((randint1(100) <= heavy_chance) &&
83             (object_is_artifact(o_ptr) || object_is_ego(o_ptr)))
84         {
85                 if (!(o_ptr->curse_flags & TRC_HEAVY_CURSE))
86                         changed = TRUE;
87                 o_ptr->curse_flags |= TRC_HEAVY_CURSE;
88                 o_ptr->curse_flags |= TRC_CURSED;
89                 curse_power++;
90         }
91         else
92         {
93                 if (!object_is_cursed(o_ptr))
94                         changed = TRUE;
95                 o_ptr->curse_flags |= TRC_CURSED;
96         }
97
98         if (heavy_chance >= 50) curse_power++;
99
100         BIT_FLAGS new_curse = get_curse(curse_power, o_ptr);
101         if (!(o_ptr->curse_flags & new_curse))
102         {
103                 changed = TRUE;
104                 o_ptr->curse_flags |= new_curse;
105         }
106
107         if (changed)
108         {
109                 msg_format(_("悪意に満ちた黒いオーラが%sをとりまいた...", "There is a malignant black aura surrounding %s..."), o_name);
110                 o_ptr->feeling = FEEL_NONE;
111         }
112
113         owner_ptr->update |= PU_BONUS;
114 }