OSDN Git Service

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