OSDN Git Service

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