OSDN Git Service

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