OSDN Git Service

[Style] Apply clang-format to all *.cpp files
[hengbandforosx/hengbandosx.git] / src / object-enchant / others / apply-magic-others.cpp
1 /*!
2  * @brief 武器でも防具でもアクセサリでもない、その他のアイテム群を生成・強化する処理
3  * @date 2022/02/23
4  * @author Hourier
5  * @details 他との兼ね合いでEnchanterとなっているが、油つぼ・人形・死体・像は生成のみで強化はしない
6  */
7
8 #include "object-enchant/others/apply-magic-others.h"
9 #include "artifact/random-art-generator.h"
10 #include "game-option/cheat-options.h"
11 #include "inventory/inventory-slot-types.h"
12 #include "monster-race/monster-race-hook.h"
13 #include "monster-race/monster-race.h"
14 #include "monster-race/race-flags9.h"
15 #include "monster-race/race-indice-types.h"
16 #include "monster/monster-list.h"
17 #include "monster/monster-util.h"
18 #include "object-enchant/object-ego.h"
19 #include "object-enchant/tr-types.h"
20 #include "object-enchant/trc-types.h"
21 #include "object/object-kind.h"
22 #include "perception/object-perception.h"
23 #include "sv-definition/sv-lite-types.h"
24 #include "sv-definition/sv-other-types.h"
25 #include "system/floor-type-definition.h"
26 #include "system/monster-race-definition.h"
27 #include "system/object-type-definition.h"
28 #include "system/player-type-definition.h"
29 #include "util/bit-flags-calculator.h"
30 #include "view/display-messages.h"
31
32 /*!
33  * @brief コンストラクタ
34  * @param player_ptr プレイヤーへの参照ポインタ
35  * @param o_ptr 強化を与えたい/生成したいオブジェクトの構造体参照ポインタ
36  * @param power 生成ランク
37  * @details power > 2はデバッグ専用.
38  */
39 OtherItemsEnchanter::OtherItemsEnchanter(PlayerType *player_ptr, ObjectType *o_ptr)
40     : player_ptr(player_ptr)
41     , o_ptr(o_ptr)
42 {
43 }
44
45 /*!
46  * @brief その他雑多のオブジェクトに生成ランクごとの強化を与える
47  * @details power > 2はデバッグ専用.
48  */
49 void OtherItemsEnchanter::apply_magic()
50 {
51     switch (this->o_ptr->tval) {
52     case ItemKindType::FLASK:
53         this->o_ptr->fuel = this->o_ptr->pval;
54         this->o_ptr->pval = 0;
55         break;
56     case ItemKindType::WAND:
57     case ItemKindType::STAFF:
58         this->enchant_wand_staff();
59         break;
60     case ItemKindType::ROD:
61         this->o_ptr->pval = k_info[this->o_ptr->k_idx].pval;
62         break;
63     case ItemKindType::CAPTURE:
64         this->o_ptr->pval = 0;
65         object_aware(this->player_ptr, this->o_ptr);
66         object_known(this->o_ptr);
67         break;
68     case ItemKindType::FIGURINE:
69         this->generate_figurine();
70         break;
71     case ItemKindType::CORPSE:
72         this->generate_corpse();
73         break;
74     case ItemKindType::STATUE:
75         this->generate_statue();
76         break;
77     case ItemKindType::CHEST:
78         this->generate_chest();
79         break;
80     default:
81         break;
82     }
83 }
84
85 /*
86  * @brief 杖を強化する
87  * The wand or staff gets a number of initial charges equal
88  * to between 1/2 (+1) and the full object kind's pval.
89  */
90 void OtherItemsEnchanter::enchant_wand_staff()
91 {
92     auto *k_ptr = &k_info[this->o_ptr->k_idx];
93     this->o_ptr->pval = k_ptr->pval / 2 + randint1((k_ptr->pval + 1) / 2);
94 }
95
96 /*
97  * @brief ランダムに選択したモンスター種族IDからその人形を作る
98  * @details
99  * ツチノコの人形は作らない
100  * レアリティが1~100のものだけ生成対象になる
101  * レベルの高い人形ほど生成されにくい
102  * たまに呪われる
103  */
104 void OtherItemsEnchanter::generate_figurine()
105 {
106     auto *floor_ptr = this->player_ptr->current_floor_ptr;
107     short r_idx;
108     while (true) {
109         r_idx = randint1(r_info.size() - 1);
110         if (!item_monster_okay(this->player_ptr, r_idx) || (r_idx == MON_TSUCHINOKO)) {
111             continue;
112         }
113
114         auto *r_ptr = &r_info[r_idx];
115         auto check = (floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - floor_ptr->dun_level) : 0;
116         if ((r_ptr->rarity == 0) || (r_ptr->rarity > 100) || (randint0(check) > 0)) {
117             continue;
118         }
119
120         break;
121     }
122
123     this->o_ptr->pval = r_idx;
124     if (one_in_(6)) {
125         this->o_ptr->curse_flags.set(CurseTraitType::CURSED);
126     }
127 }
128
129 /*
130  * @brief ランダムに選択したモンスター種族IDからその死体/骨を作る
131  * @details
132  * そもそも死体も骨も落とさないモンスターは対象外
133  * ユニークやあやしい影等、そこらに落ちている死体としてふさわしくないものは弾く
134  * レアリティが1~100のものだけ生成対象になる (はず)
135  * レベルの高い死体/骨ほど生成されにくい
136  */
137 void OtherItemsEnchanter::generate_corpse()
138 {
139     uint32_t match = 0;
140     if (this->o_ptr->sval == SV_SKELETON) {
141         match = RF9_DROP_SKELETON;
142     } else if (this->o_ptr->sval == SV_CORPSE) {
143         match = RF9_DROP_CORPSE;
144     }
145
146     get_mon_num_prep(this->player_ptr, item_monster_okay, nullptr);
147     auto *floor_ptr = this->player_ptr->current_floor_ptr;
148     short r_idx;
149     while (true) {
150         r_idx = get_mon_num(this->player_ptr, 0, floor_ptr->dun_level, 0);
151         auto &r_ref = r_info[r_idx];
152         auto check = (floor_ptr->dun_level < r_ref.level) ? (r_ref.level - floor_ptr->dun_level) : 0;
153         if ((r_ref.rarity == 0) || none_bits(r_ref.flags9, match) || (randint0(check) > 0)) {
154             continue;
155         }
156
157         break;
158     }
159
160     this->o_ptr->pval = r_idx;
161     object_aware(this->player_ptr, this->o_ptr);
162     object_known(this->o_ptr);
163 }
164
165 /*
166  * @brief ランダムに選択したモンスター種族IDからその像を作る
167  * @details レアリティが1以上のものだけ生成対象になる
168  */
169 void OtherItemsEnchanter::generate_statue()
170 {
171     short r_idx;
172     auto &r_ref = r_info[0];
173     while (true) {
174         r_idx = randint1(r_info.size() - 1);
175         r_ref = r_info[r_idx];
176         if (r_ref.rarity == 0) {
177             continue;
178         }
179
180         break;
181     }
182
183     this->o_ptr->pval = r_idx;
184     if (cheat_peek) {
185         msg_format(_("%sの像", "Statue of %s"), r_ref.name.c_str());
186     }
187
188     object_aware(this->player_ptr, this->o_ptr);
189     object_known(this->o_ptr);
190 }
191
192 /*
193  * @brief 箱を生成する
194  * @details 箱にはレベルがあり、箱の召喚トラップが発動すると箱レベルと同等のモンスターが召喚される
195  */
196 void OtherItemsEnchanter::generate_chest()
197 {
198     auto obj_level = k_info[this->o_ptr->k_idx].level;
199     if (obj_level <= 0) {
200         return;
201     }
202
203     this->o_ptr->pval = randint1(obj_level);
204     if (this->o_ptr->sval == SV_CHEST_KANDUME) {
205         this->o_ptr->pval = 6;
206     }
207
208     this->o_ptr->chest_level = this->player_ptr->current_floor_ptr->dun_level + 5;
209     if (this->o_ptr->pval > 55) {
210         this->o_ptr->pval = 55 + randint0(5);
211     }
212 }