OSDN Git Service

[Refactor] format 関数の戻り値を std::string にする
[hengbandforosx/hengbandosx.git] / src / spell-kind / spells-genocide.cpp
1 #include "spell-kind/spells-genocide.h"
2 #include "avatar/avatar.h"
3 #include "core/asking-player.h"
4 #include "core/player-redraw-types.h"
5 #include "core/stuff-handler.h"
6 #include "core/window-redrawer.h"
7 #include "dungeon/quest.h"
8 #include "floor/geometry.h"
9 #include "game-option/map-screen-options.h"
10 #include "game-option/play-record-options.h"
11 #include "game-option/special-options.h"
12 #include "grid/grid.h"
13 #include "io/cursor.h"
14 #include "io/write-diary.h"
15 #include "monster-floor/monster-remover.h"
16 #include "monster-race/monster-race.h"
17 #include "monster-race/race-flags1.h"
18 #include "monster-race/race-flags3.h"
19 #include "monster-race/race-flags7.h"
20 #include "monster/monster-describer.h"
21 #include "monster/monster-description-types.h"
22 #include "monster/monster-flag-types.h"
23 #include "monster/monster-info.h"
24 #include "monster/monster-status-setter.h"
25 #include "monster/monster-status.h"
26 #include "player/player-damage.h"
27 #include "system/floor-type-definition.h"
28 #include "system/monster-entity.h"
29 #include "system/monster-race-info.h"
30 #include "system/player-type-definition.h"
31 #include "util/bit-flags-calculator.h"
32 #include "view/display-messages.h"
33
34 /*!
35  * @brief モンスターへの単体抹殺処理サブルーチン / Delete a non-unique/non-quest monster
36  * @param m_idx 抹殺するモンスターID
37  * @param power 抹殺の威力
38  * @param player_cast プレイヤーの魔法によるものならば TRUE
39  * @param dam_side プレイヤーへの負担ダメージ量(1d(dam_side))
40  * @param spell_name 抹殺効果を起こした魔法の名前
41  * @return 効力があった場合TRUEを返す
42  */
43 bool genocide_aux(PlayerType *player_ptr, MONSTER_IDX m_idx, int power, bool player_cast, int dam_side, concptr spell_name)
44 {
45     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
46     auto *r_ptr = &monraces_info[m_ptr->r_idx];
47     if (m_ptr->is_pet() && !player_cast) {
48         return false;
49     }
50
51     bool resist = false;
52     if (r_ptr->kind_flags.has(MonsterKindType::UNIQUE) || any_bits(r_ptr->flags1, RF1_QUESTOR)) {
53         resist = true;
54     } else if (r_ptr->flags7 & RF7_UNIQUE2) {
55         resist = true;
56     } else if (m_idx == player_ptr->riding) {
57         resist = true;
58     } else if ((inside_quest(player_ptr->current_floor_ptr->quest_number) && !inside_quest(random_quest_number(player_ptr, player_ptr->current_floor_ptr->dun_level))) || player_ptr->current_floor_ptr->inside_arena || player_ptr->phase_out) {
59         resist = true;
60     } else if (player_cast && (r_ptr->level > randint0(power))) {
61         resist = true;
62     } else if (player_cast && m_ptr->mflag2.has(MonsterConstantFlagType::NOGENO)) {
63         resist = true;
64     } else {
65         if (record_named_pet && m_ptr->is_pet() && m_ptr->nickname) {
66             GAME_TEXT m_name[MAX_NLEN];
67             monster_desc(player_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
68             exe_write_diary(player_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_GENOCIDE, m_name);
69         }
70
71         delete_monster_idx(player_ptr, m_idx);
72     }
73
74     if (resist && player_cast) {
75         bool see_m = is_seen(player_ptr, m_ptr);
76         GAME_TEXT m_name[MAX_NLEN];
77         monster_desc(player_ptr, m_name, m_ptr, 0);
78         if (see_m) {
79             msg_format(_("%^sには効果がなかった。", "%^s is unaffected."), m_name);
80         }
81
82         if (m_ptr->is_asleep()) {
83             (void)set_monster_csleep(player_ptr, m_idx, 0);
84             if (m_ptr->ml) {
85                 msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name);
86             }
87         }
88
89         if (m_ptr->is_friendly() && !m_ptr->is_pet()) {
90             if (see_m) {
91                 msg_format(_("%sは怒った!", "%^s gets angry!"), m_name);
92             }
93
94             set_hostile(player_ptr, m_ptr);
95         }
96
97         if (one_in_(13)) {
98             m_ptr->mflag2.set(MonsterConstantFlagType::NOGENO);
99         }
100     }
101
102     if (player_cast) {
103         take_hit(player_ptr, DAMAGE_GENO, randint1(dam_side), format(_("%^sの呪文を唱えた疲労", "the strain of casting %^s"), spell_name).data());
104     }
105
106     move_cursor_relative(player_ptr->y, player_ptr->x);
107     player_ptr->redraw |= (PR_HP);
108     player_ptr->window_flags |= (PW_PLAYER);
109     handle_stuff(player_ptr);
110     term_fresh();
111
112     term_xtra(TERM_XTRA_DELAY, delay_factor);
113
114     return !resist;
115 }
116
117 /*!
118  * @brief モンスターへのシンボル抹殺処理ルーチン / Delete all non-unique/non-quest monsters of a given "type" from the level
119  * @param power 抹殺の威力
120  * @param player_cast プレイヤーの魔法によるものならば TRUE
121  * @return 効力があった場合TRUEを返す
122  */
123 bool symbol_genocide(PlayerType *player_ptr, int power, bool player_cast)
124 {
125     auto *floor_ptr = player_ptr->current_floor_ptr;
126     bool is_special_floor = inside_quest(floor_ptr->quest_number) && !inside_quest(random_quest_number(player_ptr, floor_ptr->dun_level));
127     is_special_floor |= player_ptr->current_floor_ptr->inside_arena;
128     is_special_floor |= player_ptr->phase_out;
129     if (is_special_floor) {
130         msg_print(_("何も起きないようだ……", "Nothing seems to happen..."));
131         return false;
132     }
133
134     char typ;
135     while (!get_com(_("どの種類(文字)のモンスターを抹殺しますか: ", "Choose a monster race (by symbol) to genocide: "), &typ, false)) {
136         ;
137     }
138     bool result = false;
139     for (MONSTER_IDX i = 1; i < player_ptr->current_floor_ptr->m_max; i++) {
140         auto *m_ptr = &player_ptr->current_floor_ptr->m_list[i];
141         auto *r_ptr = &monraces_info[m_ptr->r_idx];
142         if (!m_ptr->is_valid()) {
143             continue;
144         }
145         if (r_ptr->d_char != typ) {
146             continue;
147         }
148
149         result |= genocide_aux(player_ptr, i, power, player_cast, 4, _("抹殺", "Genocide"));
150     }
151
152     if (result) {
153         chg_virtue(player_ptr, V_VITALITY, -2);
154         chg_virtue(player_ptr, V_CHANCE, -1);
155     }
156
157     return result;
158 }
159
160 /*!
161  * @brief モンスターへの周辺抹殺処理ルーチン / Delete all nearby (non-unique) monsters
162  * @param power 抹殺の威力
163  * @param player_cast プレイヤーの魔法によるものならば TRUE
164  * @return 効力があった場合TRUEを返す
165  */
166 bool mass_genocide(PlayerType *player_ptr, int power, bool player_cast)
167 {
168     auto *floor_ptr = player_ptr->current_floor_ptr;
169     bool is_special_floor = inside_quest(floor_ptr->quest_number) && !inside_quest(random_quest_number(player_ptr, floor_ptr->dun_level));
170     is_special_floor |= player_ptr->current_floor_ptr->inside_arena;
171     is_special_floor |= player_ptr->phase_out;
172     if (is_special_floor) {
173         return false;
174     }
175
176     bool result = false;
177     for (MONSTER_IDX i = 1; i < player_ptr->current_floor_ptr->m_max; i++) {
178         auto *m_ptr = &player_ptr->current_floor_ptr->m_list[i];
179         if (!m_ptr->is_valid()) {
180             continue;
181         }
182         if (m_ptr->cdis > MAX_PLAYER_SIGHT) {
183             continue;
184         }
185
186         result |= genocide_aux(player_ptr, i, power, player_cast, 3, _("周辺抹殺", "Mass Genocide"));
187     }
188
189     if (result) {
190         chg_virtue(player_ptr, V_VITALITY, -2);
191         chg_virtue(player_ptr, V_CHANCE, -1);
192     }
193
194     return result;
195 }
196
197 /*!
198  * @brief アンデッド・モンスターへの周辺抹殺処理ルーチン / Delete all nearby (non-unique) undead
199  * @param power 抹殺の威力
200  * @param player_cast プレイヤーの魔法によるものならば TRUE
201  * @return 効力があった場合TRUEを返す
202  */
203 bool mass_genocide_undead(PlayerType *player_ptr, int power, bool player_cast)
204 {
205     auto *floor_ptr = player_ptr->current_floor_ptr;
206     bool is_special_floor = inside_quest(floor_ptr->quest_number) && !inside_quest(random_quest_number(player_ptr, floor_ptr->dun_level));
207     is_special_floor |= player_ptr->current_floor_ptr->inside_arena;
208     is_special_floor |= player_ptr->phase_out;
209     if (is_special_floor) {
210         return false;
211     }
212
213     bool result = false;
214     for (MONSTER_IDX i = 1; i < player_ptr->current_floor_ptr->m_max; i++) {
215         auto *m_ptr = &player_ptr->current_floor_ptr->m_list[i];
216         auto *r_ptr = &monraces_info[m_ptr->r_idx];
217         if (!m_ptr->is_valid()) {
218             continue;
219         }
220         if (r_ptr->kind_flags.has_not(MonsterKindType::UNDEAD)) {
221             continue;
222         }
223         if (m_ptr->cdis > MAX_PLAYER_SIGHT) {
224             continue;
225         }
226
227         result |= genocide_aux(player_ptr, i, power, player_cast, 3, _("アンデッド消滅", "Annihilate Undead"));
228     }
229
230     if (result) {
231         chg_virtue(player_ptr, V_UNLIFE, -2);
232         chg_virtue(player_ptr, V_CHANCE, -1);
233     }
234
235     return result;
236 }