OSDN Git Service

[Refactor] #2205 Separated enchant_figurine() from OtherItemsEnchanter::apply_magic()
[hengbandforosx/hengbandosx.git] / src / object-enchant / others / apply-magic-others.cpp
1 /*!
2  * @brief 防具系のアイテムを強化して(恐らく床に)生成する処理
3  * @date 2020/06/02
4  * @author Hourier
5  * @todo ちょっと長い。要分割
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 OtherItemsEnchanter::OtherItemsEnchanter(PlayerType *player_ptr, ObjectType *o_ptr)
33     : player_ptr(player_ptr)
34     , o_ptr(o_ptr)
35 {
36 }
37
38 /*!
39  * @brief その他雑多のオブジェクトに生成ランクごとの強化を与えるサブルーチン
40  * Apply magic to an item known to be "boring"
41  * @param player_ptr プレイヤーへの参照ポインタ
42  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
43  * @param power 生成ランク
44  * @details power > 2はデバッグ専用.
45  */
46 void OtherItemsEnchanter::apply_magic()
47 {
48     auto *floor_ptr = this->player_ptr->current_floor_ptr;
49     switch (this->o_ptr->tval) {
50     case ItemKindType::FLASK:
51         this->o_ptr->fuel = this->o_ptr->pval;
52         this->o_ptr->pval = 0;
53         break;
54     case ItemKindType::WAND:
55     case ItemKindType::STAFF:
56         this->enchant_wand_staff();
57         break;
58     case ItemKindType::ROD:
59         this->o_ptr->pval = k_info[this->o_ptr->k_idx].pval;
60         break;
61     case ItemKindType::CAPTURE:
62         this->o_ptr->pval = 0;
63         object_aware(this->player_ptr, this->o_ptr);
64         object_known(this->o_ptr);
65         break;
66     case ItemKindType::FIGURINE:
67         this->enchant_figurine();
68         break;
69     case ItemKindType::CORPSE: {
70         PARAMETER_VALUE i = 1;
71         int check;
72         uint32_t match = 0;
73         monster_race *r_ptr;
74         if (this->o_ptr->sval == SV_SKELETON) {
75             match = RF9_DROP_SKELETON;
76         } else if (this->o_ptr->sval == SV_CORPSE) {
77             match = RF9_DROP_CORPSE;
78         }
79
80         get_mon_num_prep(this->player_ptr, item_monster_okay, nullptr);
81         while (true) {
82             i = get_mon_num(this->player_ptr, 0, floor_ptr->dun_level, 0);
83             r_ptr = &r_info[i];
84             check = (floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - floor_ptr->dun_level) : 0;
85             if (!r_ptr->rarity)
86                 continue;
87             if (!(r_ptr->flags9 & match))
88                 continue;
89             if (randint0(check))
90                 continue;
91
92             break;
93         }
94
95         this->o_ptr->pval = i;
96         object_aware(this->player_ptr, this->o_ptr);
97         object_known(this->o_ptr);
98         break;
99     }
100     case ItemKindType::STATUE: {
101         PARAMETER_VALUE i = 1;
102         monster_race *r_ptr;
103         while (true) {
104             i = randint1(r_info.size() - 1);
105             r_ptr = &r_info[i];
106             if (!r_ptr->rarity)
107                 continue;
108
109             break;
110         }
111
112         this->o_ptr->pval = i;
113         if (cheat_peek) {
114             msg_format(_("%sの像", "Statue of %s"), r_ptr->name.c_str());
115         }
116
117         object_aware(this->player_ptr, this->o_ptr);
118         object_known(this->o_ptr);
119         break;
120     }
121     case ItemKindType::CHEST: {
122         DEPTH obj_level = k_info[this->o_ptr->k_idx].level;
123         if (obj_level <= 0)
124             break;
125
126         this->o_ptr->pval = randint1(obj_level);
127         if (this->o_ptr->sval == SV_CHEST_KANDUME)
128             this->o_ptr->pval = 6;
129
130         this->o_ptr->chest_level = floor_ptr->dun_level + 5;
131         if (this->o_ptr->pval > 55)
132             this->o_ptr->pval = 55 + (byte)randint0(5);
133
134         break;
135     }
136     default:
137         break;
138     }
139 }
140
141 /*
142  * @brief 杖を強化する
143  * The wand or staff gets a number of initial charges equal
144  * to between 1/2 (+1) and the full object kind's pval.
145  */
146 void OtherItemsEnchanter::enchant_wand_staff()
147 {
148     auto *k_ptr = &k_info[this->o_ptr->k_idx];
149     this->o_ptr->pval = k_ptr->pval / 2 + randint1((k_ptr->pval + 1) / 2);
150 }
151
152 void OtherItemsEnchanter::enchant_figurine()
153 {
154     auto *floor_ptr = this->player_ptr->current_floor_ptr;
155     short r_idx;
156     while (true)
157     {
158         r_idx = randint1(r_info.size() - 1);
159         if (!item_monster_okay(this->player_ptr, r_idx) || (r_idx == MON_TSUCHINOKO)) {
160             continue;
161         }
162
163         auto *r_ptr = &r_info[r_idx];
164         auto check = (floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - floor_ptr->dun_level) : 0;
165         if ((r_ptr->rarity == 0) || (r_ptr->rarity > 100) || (randint0(check) > 0)) {
166             continue;
167         }
168
169         break;
170     }
171
172     this->o_ptr->pval = r_idx;
173     if (one_in_(6)) {
174         this->o_ptr->curse_flags.set(CurseTraitType::CURSED);
175     }
176 }