OSDN Git Service

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