OSDN Git Service

[Refactor] #2807 Renamed monster-race-definition.h to monster-race-info.h
[hengbandforosx/hengbandosx.git] / src / mspell / mspell-special.cpp
1 /*!
2  * @brief 特殊な行動を取るモンスターの具体的な行動定義 (MonsterRaceDefinitionsのSPECIALフラグ)
3  * @date 2020/05/16
4  * @author Hourier
5  */
6
7 #include "mspell/mspell-special.h"
8 #include "core/disturbance.h"
9 #include "core/player-update-types.h"
10 #include "effect/attribute-types.h"
11 #include "effect/effect-characteristics.h"
12 #include "effect/effect-processor.h"
13 #include "floor/cave.h"
14 #include "main/sound-definitions-table.h"
15 #include "main/sound-of-music.h"
16 #include "melee/melee-postprocess.h"
17 #include "monster-floor/monster-death.h"
18 #include "monster-floor/monster-remover.h"
19 #include "monster-floor/monster-summon.h"
20 #include "monster-race/monster-race.h"
21 #include "monster-race/race-flags7.h"
22 #include "monster-race/race-indice-types.h"
23 #include "monster/monster-describer.h"
24 #include "monster/monster-description-types.h"
25 #include "monster/monster-info.h"
26 #include "monster/monster-util.h"
27 #include "mspell/mspell-checker.h"
28 #include "mspell/mspell-result.h"
29 #include "mspell/mspell-util.h"
30 #include "player/player-damage.h"
31 #include "spell-kind/spells-teleport.h"
32 #include "spell-realm/spells-crusade.h"
33 #include "system/floor-type-definition.h"
34 #include "system/grid-type-definition.h"
35 #include "system/monster-race-info.h"
36 #include "system/monster-type-definition.h"
37 #include "system/player-type-definition.h"
38 #include "timed-effect/player-blindness.h"
39 #include "timed-effect/timed-effects.h"
40 #include "view/display-messages.h"
41
42 /*!
43  * @brief バーノール・ルパートのRF6_SPECIALの処理。分裂・合体。 /
44  * @param player_ptr プレイヤーへの参照ポインタ
45  * @param m_idx 呪文を唱えるモンスターID
46  */
47 static MonsterSpellResult spell_RF6_SPECIAL_BANORLUPART(PlayerType *player_ptr, MONSTER_IDX m_idx)
48 {
49     auto *floor_ptr = player_ptr->current_floor_ptr;
50     auto *m_ptr = &floor_ptr->m_list[m_idx];
51     int dummy_hp, dummy_maxhp;
52     POSITION dummy_y = m_ptr->fy;
53     POSITION dummy_x = m_ptr->fx;
54     BIT_FLAGS mode = 0L;
55
56     if (see_monster(player_ptr, m_idx) && monster_near_player(floor_ptr, m_idx, 0)) {
57         disturb(player_ptr, true, true);
58     }
59
60     switch (m_ptr->r_idx) {
61     case MonsterRaceId::BANORLUPART:
62         dummy_hp = (m_ptr->hp + 1) / 2;
63         dummy_maxhp = m_ptr->maxhp / 2;
64
65         if (floor_ptr->inside_arena || player_ptr->phase_out || !summon_possible(player_ptr, m_ptr->fy, m_ptr->fx)) {
66             return MonsterSpellResult::make_invalid();
67         }
68
69         delete_monster_idx(player_ptr, floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].m_idx);
70         summon_named_creature(player_ptr, 0, dummy_y, dummy_x, MonsterRaceId::BANOR, mode);
71         floor_ptr->m_list[hack_m_idx_ii].hp = dummy_hp;
72         floor_ptr->m_list[hack_m_idx_ii].maxhp = dummy_maxhp;
73         summon_named_creature(player_ptr, 0, dummy_y, dummy_x, MonsterRaceId::LUPART, mode);
74         floor_ptr->m_list[hack_m_idx_ii].hp = dummy_hp;
75         floor_ptr->m_list[hack_m_idx_ii].maxhp = dummy_maxhp;
76
77         msg_print(_("『バーノール・ルパート』が分裂した!", "Banor=Rupart splits into two persons!"));
78         break;
79
80     case MonsterRaceId::BANOR:
81     case MonsterRaceId::LUPART:
82         dummy_hp = 0;
83         dummy_maxhp = 0;
84
85         if (!monraces_info[MonsterRaceId::BANOR].cur_num || !monraces_info[MonsterRaceId::LUPART].cur_num) {
86             return MonsterSpellResult::make_invalid();
87         }
88
89         for (MONSTER_IDX k = 1; k < floor_ptr->m_max; k++) {
90             if (floor_ptr->m_list[k].r_idx == MonsterRaceId::BANOR || floor_ptr->m_list[k].r_idx == MonsterRaceId::LUPART) {
91                 dummy_hp += floor_ptr->m_list[k].hp;
92                 dummy_maxhp += floor_ptr->m_list[k].maxhp;
93                 if (floor_ptr->m_list[k].r_idx != m_ptr->r_idx) {
94                     dummy_y = floor_ptr->m_list[k].fy;
95                     dummy_x = floor_ptr->m_list[k].fx;
96                 }
97                 delete_monster_idx(player_ptr, k);
98             }
99         }
100         summon_named_creature(player_ptr, 0, dummy_y, dummy_x, MonsterRaceId::BANORLUPART, mode);
101         floor_ptr->m_list[hack_m_idx_ii].hp = dummy_hp;
102         floor_ptr->m_list[hack_m_idx_ii].maxhp = dummy_maxhp;
103
104         msg_print(_("『バーノール』と『ルパート』が合体した!", "Banor and Rupart combine into one!"));
105         break;
106
107     default:
108         break;
109     }
110
111     return MonsterSpellResult::make_valid();
112 }
113
114 /*!
115  * @brief ロレントのRF6_SPECIALの処理。手榴弾の召喚。 /
116  * @param player_ptr プレイヤーへの参照ポインタ
117  * @param y 対象の地点のy座標
118  * @param x 対象の地点のx座標
119  * @param m_idx 呪文を唱えるモンスターID
120  * @param t_idx 呪文を受けるモンスターID。プレイヤーの場合はdummyで0とする。
121  * @param target_type プレイヤーを対象とする場合MONSTER_TO_PLAYER、モンスターを対象とする場合MONSTER_TO_MONSTER
122  */
123 static MonsterSpellResult spell_RF6_SPECIAL_ROLENTO(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, MONSTER_IDX t_idx, int target_type)
124 {
125     int count = 0, k;
126     int num = 1 + randint1(3);
127     BIT_FLAGS mode = 0L;
128     auto *floor_ptr = player_ptr->current_floor_ptr;
129     bool see_either = see_monster(player_ptr, m_idx) || see_monster(player_ptr, t_idx);
130     bool mon_to_mon = target_type == MONSTER_TO_MONSTER;
131     bool mon_to_player = target_type == MONSTER_TO_PLAYER;
132     bool known = monster_near_player(floor_ptr, m_idx, t_idx);
133
134     mspell_cast_msg_blind msg(_("%^sが何か大量に投げた。", "%^s spreads something."),
135         _("%^sは手榴弾をばらまいた。", "%^s throws some hand grenades."), _("%^sは手榴弾をばらまいた。", "%^s throws some hand grenades."));
136
137     monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
138     if (mon_to_player || (mon_to_mon && known && see_either)) {
139         disturb(player_ptr, true, true);
140     }
141
142     for (k = 0; k < num; k++) {
143         count += summon_named_creature(player_ptr, m_idx, y, x, MonsterRaceId::GRENADE, mode);
144     }
145     if (player_ptr->effects()->blindness()->is_blind() && count) {
146         msg_print(_("多くのものが間近にばらまかれる音がする。", "You hear many things scattered nearby."));
147     }
148
149     return MonsterSpellResult::make_valid();
150 }
151
152 /*!
153  * @brief BシンボルのRF6_SPECIALの処理。投げ落とす攻撃。 /
154  * @param player_ptr プレイヤーへの参照ポインタ
155  * @param y 対象の地点のy座標
156  * @param x 対象の地点のx座標
157  * @param m_idx 呪文を唱えるモンスターID
158  * @param t_idx 呪文を受けるモンスターID。プレイヤーの場合はdummyで0とする。
159  * @param target_type プレイヤーを対象とする場合MONSTER_TO_PLAYER、モンスターを対象とする場合MONSTER_TO_MONSTER
160  */
161 static MonsterSpellResult spell_RF6_SPECIAL_B(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, MONSTER_IDX t_idx, int target_type)
162 {
163     mspell_cast_msg_simple msg;
164     auto *floor_ptr = player_ptr->current_floor_ptr;
165     auto *m_ptr = &floor_ptr->m_list[m_idx];
166     MonsterEntity *t_ptr = &floor_ptr->m_list[t_idx];
167     MonsterRaceInfo *tr_ptr = &monraces_info[t_ptr->r_idx];
168     bool monster_to_player = (target_type == MONSTER_TO_PLAYER);
169     bool monster_to_monster = (target_type == MONSTER_TO_MONSTER);
170     bool direct = player_bold(player_ptr, y, x);
171     GAME_TEXT m_name[MAX_NLEN];
172     monster_name(player_ptr, m_idx, m_name);
173
174     disturb(player_ptr, true, true);
175     if (one_in_(3) || !direct) {
176         msg.to_player = _("%^sは突然視界から消えた!", "You lose sight of %s!");
177         msg.to_mons = _("%^sは突然急上昇して視界から消えた!", "You lose sight of %s!");
178
179         simple_monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
180
181         teleport_away(player_ptr, m_idx, 10, TELEPORT_NONMAGICAL);
182         player_ptr->update |= (PU_MONSTERS);
183         return MonsterSpellResult::make_valid();
184     }
185
186     if (direct) {
187         sound(SOUND_FALL);
188     }
189
190     msg.to_player = _("%^sがあなたを掴んで空中から投げ落とした。", "%^s snatches you, soars into the sky, and drops you.");
191     msg.to_mons = _("%^sが%sを掴んで空中から投げ落とした。", "%^s snatches %s, soars into the sky, and releases its grip.");
192
193     simple_monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
194
195     bool fear, dead; /* dummy */
196     int dam = damroll(4, 8);
197
198     if (monster_to_player || t_idx == player_ptr->riding) {
199         teleport_player_to(player_ptr, m_ptr->fy, m_ptr->fx, i2enum<teleport_flags>(TELEPORT_NONMAGICAL | TELEPORT_PASSIVE));
200     } else {
201         teleport_monster_to(player_ptr, t_idx, m_ptr->fy, m_ptr->fx, 100, i2enum<teleport_flags>(TELEPORT_NONMAGICAL | TELEPORT_PASSIVE));
202     }
203
204     if ((monster_to_player && player_ptr->levitation) || (monster_to_monster && tr_ptr->feature_flags.has(MonsterFeatureType::CAN_FLY))) {
205         msg.to_player = _("あなたは静かに着地した。", "You float gently down to the ground.");
206         msg.to_mons = _("%^sは静かに着地した。", "%^s floats gently down to the ground.");
207     } else {
208         msg.to_player = _("あなたは地面に叩きつけられた。", "You crashed into the ground.");
209         msg.to_mons = _("%^sは地面に叩きつけられた。", "%^s crashed into the ground.");
210     }
211
212     simple_monspell_message(player_ptr, m_idx, t_idx, msg, target_type);
213     dam += damroll(6, 8);
214
215     if (monster_to_player || (monster_to_monster && player_ptr->riding == t_idx)) {
216         int get_damage = take_hit(player_ptr, DAMAGE_NOESCAPE, dam, m_name);
217         if (player_ptr->tim_eyeeye && get_damage > 0 && !player_ptr->is_dead) {
218             GAME_TEXT m_name_self[MAX_MONSTER_NAME];
219             monster_desc(player_ptr, m_name_self, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE | MD_OBJECTIVE);
220             msg_format(_("攻撃が%s自身を傷つけた!", "The attack of %s has wounded %s!"), m_name, m_name_self);
221             project(player_ptr, 0, 0, m_ptr->fy, m_ptr->fx, get_damage, AttributeType::MISSILE, PROJECT_KILL);
222             set_tim_eyeeye(player_ptr, player_ptr->tim_eyeeye - 5, true);
223         }
224     }
225
226     if (monster_to_player && player_ptr->riding) {
227         const auto &m_ref = floor_ptr->m_list[player_ptr->riding];
228         mon_take_hit_mon(player_ptr, player_ptr->riding, dam, &dead, &fear, extract_note_dies(m_ref.get_real_r_idx()), m_idx);
229     }
230
231     if (monster_to_monster) {
232         mon_take_hit_mon(player_ptr, t_idx, dam, &dead, &fear, extract_note_dies(t_ptr->get_real_r_idx()), m_idx);
233     }
234
235     return MonsterSpellResult::make_valid();
236 }
237
238 /*!
239  * @brief RF6_SPECIALの処理。モンスターの種類によって実処理に振り分ける。 /
240  * @param player_ptr プレイヤーへの参照ポインタ
241  * @param y 対象の地点のy座標
242  * @param x 対象の地点のx座標
243  * @param m_idx 呪文を唱えるモンスターID
244  * @param t_idx 呪文を受けるモンスターID。プレイヤーの場合はdummyで0とする。
245  * @param target_type プレイヤーを対象とする場合MONSTER_TO_PLAYER、モンスターを対象とする場合MONSTER_TO_MONSTER
246  *
247  * ラーニング不可。
248  */
249 MonsterSpellResult spell_RF6_SPECIAL(PlayerType *player_ptr, POSITION y, POSITION x, MONSTER_IDX m_idx, MONSTER_IDX t_idx, int target_type)
250 {
251     auto *floor_ptr = player_ptr->current_floor_ptr;
252     auto *m_ptr = &floor_ptr->m_list[m_idx];
253     auto *r_ptr = &monraces_info[m_ptr->r_idx];
254
255     switch (m_ptr->r_idx) {
256     case MonsterRaceId::OHMU:
257         return MonsterSpellResult::make_invalid();
258
259     case MonsterRaceId::BANORLUPART:
260     case MonsterRaceId::BANOR:
261     case MonsterRaceId::LUPART:
262         return spell_RF6_SPECIAL_BANORLUPART(player_ptr, m_idx);
263
264     case MonsterRaceId::ROLENTO:
265         return spell_RF6_SPECIAL_ROLENTO(player_ptr, y, x, m_idx, t_idx, target_type);
266         break;
267
268     default:
269         if (r_ptr->d_char == 'B') {
270             return spell_RF6_SPECIAL_B(player_ptr, y, x, m_idx, t_idx, target_type);
271             break;
272         } else {
273             return MonsterSpellResult::make_invalid();
274         }
275     }
276 }