OSDN Git Service

3fb9e42101fea3f9fd0c16688c5be2fb174e2866
[hengband/hengband.git] / src / spell-kind / earthquake.c
1 #include "spell-kind/earthquake.h"
2 #include "core/player-redraw-types.h"
3 #include "core/player-update-types.h"
4 #include "core/window-redrawer.h"
5 #include "dungeon/dungeon-flag-types.h"
6 #include "dungeon/dungeon.h"
7 #include "dungeon/quest.h"
8 #include "floor/cave.h"
9 #include "floor/floor-object.h"
10 #include "game-option/play-record-options.h"
11 #include "game-option/text-display-options.h"
12 #include "grid/grid.h"
13 #include "grid/stair.h"
14 #include "io/write-diary.h"
15 #include "mind/mind-ninja.h"
16 #include "monster-floor/monster-lite.h"
17 #include "monster-race/monster-race.h"
18 #include "monster-race/race-flags1.h"
19 #include "monster-race/race-flags2.h"
20 #include "monster/monster-describer.h"
21 #include "monster/monster-description-types.h"
22 #include "monster/monster-info.h"
23 #include "monster/monster-status-setter.h"
24 #include "monster/monster-update.h"
25 #include "monster/smart-learn-types.h"
26 #include "status/bad-status-setter.h"
27 #include "player/player-damage.h"
28 #include "player/player-move.h"
29 #include "player/special-defense-types.h"
30 #include "player/player-status-flags.h"
31 #include "system/floor-type-definition.h"
32 #include "util/bit-flags-calculator.h"
33 #include "view/display-messages.h"
34
35 /*!
36  * @brief 地震処理
37  * Induce an "earthquake" of the given radius at the given location.
38  * @param caster_ptrプレーヤーへの参照ポインタ
39  * @param cy 中心Y座標
40  * @param cx 中心X座標
41  * @param r 効果半径
42  * @param m_idx 地震を起こしたモンスターID(0ならばプレイヤー)
43  * @return 効力があった場合TRUEを返す
44  */
45 bool earthquake(player_type *caster_ptr, POSITION cy, POSITION cx, POSITION r, MONSTER_IDX m_idx)
46 {
47     floor_type *floor_ptr = caster_ptr->current_floor_ptr;
48     if ((floor_ptr->inside_quest && is_fixed_quest_idx(floor_ptr->inside_quest)) || !floor_ptr->dun_level) {
49         return FALSE;
50     }
51
52     if (r > 12)
53         r = 12;
54
55     bool map[32][32];
56     for (POSITION y = 0; y < 32; y++) {
57         for (POSITION x = 0; x < 32; x++) {
58             map[y][x] = FALSE;
59         }
60     }
61
62     int damage = 0;
63     bool hurt = FALSE;
64     for (POSITION dy = -r; dy <= r; dy++) {
65         for (POSITION dx = -r; dx <= r; dx++) {
66             POSITION yy = cy + dy;
67             POSITION xx = cx + dx;
68
69             if (!in_bounds(floor_ptr, yy, xx))
70                 continue;
71
72             if (distance(cy, cx, yy, xx) > r)
73                 continue;
74
75             grid_type *g_ptr;
76             g_ptr = &floor_ptr->grid_array[yy][xx];
77             g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY | CAVE_UNSAFE);
78             g_ptr->info &= ~(CAVE_GLOW | CAVE_MARK | CAVE_KNOWN);
79             if (!dx && !dy)
80                 continue;
81
82             if (randint0(100) < 85)
83                 continue;
84
85             map[16 + yy - cy][16 + xx - cx] = TRUE;
86             if (player_bold(caster_ptr, yy, xx))
87                 hurt = TRUE;
88         }
89     }
90
91     int sn = 0;
92     POSITION sy = 0, sx = 0;
93     if (hurt && !has_pass_wall(caster_ptr) && !caster_ptr->kill_wall) {
94         for (DIRECTION i = 0; i < 8; i++) {
95             POSITION y = caster_ptr->y + ddy_ddd[i];
96             POSITION x = caster_ptr->x + ddx_ddd[i];
97             if (!is_cave_empty_bold(caster_ptr, y, x))
98                 continue;
99
100             if (map[16 + y - cy][16 + x - cx])
101                 continue;
102
103             if (floor_ptr->grid_array[y][x].m_idx)
104                 continue;
105
106             sn++;
107             if (randint0(sn) > 0)
108                 continue;
109
110             sy = y;
111             sx = x;
112         }
113
114         switch (randint1(3)) {
115         case 1: {
116             msg_print(_("ダンジョンの壁が崩れた!", "The dungeon's ceiling collapses!"));
117             break;
118         }
119         case 2: {
120             msg_print(_("ダンジョンの床が不自然にねじ曲がった!", "The dungeon's floor twists in an unnatural way!"));
121             break;
122         }
123         default: {
124             msg_print(_("ダンジョンが揺れた!崩れた岩が頭に降ってきた!", "The dungeon quakes!  You are pummeled with debris!"));
125             break;
126         }
127         }
128
129         if (!sn) {
130             msg_print(_("あなたはひどい怪我を負った!", "You are severely crushed!"));
131             damage = 200;
132         }
133         else {
134             switch (randint1(3)) {
135             case 1: {
136                 msg_print(_("降り注ぐ岩をうまく避けた!", "You nimbly dodge the blast!"));
137                 damage = 0;
138                 break;
139             }
140             case 2: {
141                 msg_print(_("岩石があなたに直撃した!", "You are bashed by rubble!"));
142                 damage = damroll(10, 4);
143                 (void)set_stun(caster_ptr, caster_ptr->stun + randint1(50));
144                 break;
145             }
146             case 3: {
147                 msg_print(_("あなたは床と壁との間に挟まれてしまった!", "You are crushed between the floor and ceiling!"));
148                 damage = damroll(10, 4);
149                 (void)set_stun(caster_ptr, caster_ptr->stun + randint1(50));
150                 break;
151             }
152             }
153
154             (void)move_player_effect(caster_ptr, sy, sx, MPE_DONT_PICKUP);
155         }
156
157         map[16 + caster_ptr->y - cy][16 + caster_ptr->x - cx] = FALSE;
158         if (damage) {
159             concptr killer;
160
161             if (m_idx) {
162                 GAME_TEXT m_name[MAX_NLEN];
163                 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
164                 monster_desc(caster_ptr, m_name, m_ptr, MD_WRONGDOER_NAME);
165                 killer = format(_("%sの起こした地震", "an earthquake caused by %s"), m_name);
166             } else {
167                 killer = _("地震", "an earthquake");
168             }
169
170             take_hit(caster_ptr, DAMAGE_ATTACK, damage, killer, -1);
171         }
172     }
173
174     for (POSITION dy = -r; dy <= r; dy++) {
175         for (POSITION dx = -r; dx <= r; dx++) {
176             POSITION yy = cy + dy;
177             POSITION xx = cx + dx;
178             if (!map[16 + yy - cy][16 + xx - cx])
179                 continue;
180
181             grid_type *g_ptr;
182             g_ptr = &floor_ptr->grid_array[yy][xx];
183             if (g_ptr->m_idx == caster_ptr->riding)
184                 continue;
185
186             if (!g_ptr->m_idx)
187                 continue;
188
189             monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
190             monster_race *r_ptr = &r_info[m_ptr->r_idx];
191             if (r_ptr->flags1 & RF1_QUESTOR) {
192                 map[16 + yy - cy][16 + xx - cx] = FALSE;
193                 continue;
194             }
195
196             if ((r_ptr->flags2 & RF2_KILL_WALL) || (r_ptr->flags2 & RF2_PASS_WALL))
197                 continue;
198
199             GAME_TEXT m_name[MAX_NLEN];
200             sn = 0;
201             if (!(r_ptr->flags1 & RF1_NEVER_MOVE)) {
202                 for (DIRECTION i = 0; i < 8; i++) {
203                     POSITION y = yy + ddy_ddd[i];
204                     POSITION x = xx + ddx_ddd[i];
205                     if (!is_cave_empty_bold(caster_ptr, y, x))
206                         continue;
207
208                     if (is_glyph_grid(&floor_ptr->grid_array[y][x]))
209                         continue;
210
211                     if (is_explosive_rune_grid(&floor_ptr->grid_array[y][x]))
212                         continue;
213
214                     if (pattern_tile(floor_ptr, y, x))
215                         continue;
216
217                     if (map[16 + y - cy][16 + x - cx])
218                         continue;
219
220                     if (floor_ptr->grid_array[y][x].m_idx)
221                         continue;
222
223                     if (player_bold(caster_ptr, y, x))
224                         continue;
225
226                     sn++;
227
228                     if (randint0(sn) > 0)
229                         continue;
230
231                     sy = y;
232                     sx = x;
233                 }
234             }
235
236             monster_desc(caster_ptr, m_name, m_ptr, 0);
237             if (!ignore_unview || is_seen(caster_ptr, m_ptr))
238                 msg_format(_("%^sは苦痛で泣きわめいた!", "%^s wails out in pain!"), m_name);
239
240             damage = (sn ? damroll(4, 8) : (m_ptr->hp + 1));
241             (void)set_monster_csleep(caster_ptr, g_ptr->m_idx, 0);
242             m_ptr->hp -= damage;
243             if (m_ptr->hp < 0) {
244                 if (!ignore_unview || is_seen(caster_ptr, m_ptr))
245                     msg_format(_("%^sは岩石に埋もれてしまった!", "%^s is embedded in the rock!"), m_name);
246
247                 if (g_ptr->m_idx) {
248                     if (record_named_pet && is_pet(&floor_ptr->m_list[g_ptr->m_idx]) && floor_ptr->m_list[g_ptr->m_idx].nickname) {
249                         char m2_name[MAX_NLEN];
250
251                         monster_desc(caster_ptr, m2_name, m_ptr, MD_INDEF_VISIBLE);
252                         exe_write_diary(caster_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_EARTHQUAKE, m2_name);
253                     }
254                 }
255
256                 delete_monster(caster_ptr, yy, xx);
257                 sn = 0;
258             }
259
260             if (sn == 0)
261                 continue;
262
263             IDX m_idx_aux = floor_ptr->grid_array[yy][xx].m_idx;
264             floor_ptr->grid_array[yy][xx].m_idx = 0;
265             floor_ptr->grid_array[sy][sx].m_idx = m_idx_aux;
266             m_ptr->fy = sy;
267             m_ptr->fx = sx;
268             update_monster(caster_ptr, m_idx, TRUE);
269             lite_spot(caster_ptr, yy, xx);
270             lite_spot(caster_ptr, sy, sx);
271         }
272     }
273
274     clear_mon_lite(floor_ptr);
275     for (POSITION dy = -r; dy <= r; dy++) {
276         for (POSITION dx = -r; dx <= r; dx++) {
277             POSITION yy = cy + dy;
278             POSITION xx = cx + dx;
279             if (!map[16 + yy - cy][16 + xx - cx])
280                 continue;
281
282             if (!cave_valid_bold(floor_ptr, yy, xx))
283                 continue;
284
285             delete_all_items_from_floor(caster_ptr, yy, xx);
286             int t = cave_has_flag_bold(floor_ptr, yy, xx, FF_PROJECT) ? randint0(100) : 200;
287             if (t < 20) {
288                 cave_set_feat(caster_ptr, yy, xx, feat_granite);
289                 continue;
290             }
291
292             if (t < 70) {
293                 cave_set_feat(caster_ptr, yy, xx, feat_quartz_vein);
294                 continue;
295             }
296
297             if (t < 100) {
298                 cave_set_feat(caster_ptr, yy, xx, feat_magma_vein);
299                 continue;
300             }
301
302             cave_set_feat(caster_ptr, yy, xx, feat_ground_type[randint0(100)]);
303         }
304     }
305
306     for (POSITION dy = -r; dy <= r; dy++) {
307         for (POSITION dx = -r; dx <= r; dx++) {
308             POSITION yy = cy + dy;
309             POSITION xx = cx + dx;
310             if (!in_bounds(floor_ptr, yy, xx))
311                 continue;
312
313             if (distance(cy, cx, yy, xx) > r)
314                 continue;
315
316             grid_type *g_ptr;
317             g_ptr = &floor_ptr->grid_array[yy][xx];
318             if (is_mirror_grid(g_ptr)) {
319                 g_ptr->info |= CAVE_GLOW;
320                 continue;
321             }
322
323             if ((d_info[caster_ptr->dungeon_idx].flags1 & DF1_DARKNESS))
324                 continue;
325
326             grid_type *cc_ptr;
327             for (DIRECTION ii = 0; ii < 9; ii++) {
328                 POSITION yyy = yy + ddy_ddd[ii];
329                 POSITION xxx = xx + ddx_ddd[ii];
330                 if (!in_bounds2(floor_ptr, yyy, xxx))
331                     continue;
332                 cc_ptr = &floor_ptr->grid_array[yyy][xxx];
333                 if (has_flag(f_info[get_feat_mimic(cc_ptr)].flags, FF_GLOW)) {
334                     g_ptr->info |= CAVE_GLOW;
335                     break;
336                 }
337             }
338         }
339     }
340
341     caster_ptr->update |= (PU_UN_VIEW | PU_UN_LITE | PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS);
342     caster_ptr->redraw |= (PR_HEALTH | PR_UHEALTH | PR_MAP);
343     caster_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
344     if (caster_ptr->special_defense & NINJA_S_STEALTH) {
345         if (floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].info & CAVE_GLOW)
346             set_superstealth(caster_ptr, FALSE);
347     }
348
349     return TRUE;
350 }