OSDN Git Service

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