OSDN Git Service

[Refactor] #38997 lite_spot() にplayer_type * 引数を追加 / Added player_type * argument...
[hengband/hengband.git] / src / spells-floor.c
1 #include "angband.h"
2 #include "util.h"
3
4 #include "dungeon.h"
5 #include "floor.h"
6 #include "grid.h"
7 #include "quest.h"
8 #include "artifact.h"
9 #include "objectkind.h"
10 #include "object-flavor.h"
11 #include "object-hook.h"
12
13 #include "cmd-basic.h"
14 #include "cmd-dump.h"
15
16 #include "floor-events.h"
17 #include "floor-save.h"
18 #include "player-damage.h"
19 #include "player-effects.h"
20 #include "player-move.h"
21 #include "feature.h"
22 #include "view-mainwindow.h"
23
24 #include "monster-status.h"
25
26 #include "spells.h"
27 #include "spells-floor.h"
28
29 /*
30  * Light up the dungeon using "clairvoyance"
31  *
32  * This function "illuminates" every grid in the dungeon, memorizes all
33  * "objects", memorizes all grids as with magic mapping, and, under the
34  * standard option settings (view_perma_grids but not view_torch_grids)
35  * memorizes all floor grids too.
36  *
37  * Note that if "view_perma_grids" is not set, we do not memorize floor
38  * grids, since this would defeat the purpose of "view_perma_grids", not
39  * that anyone seems to play without this option.
40  *
41  * Note that if "view_torch_grids" is set, we do not memorize floor grids,
42  * since this would prevent the use of "view_torch_grids" as a method to
43  * keep track of what grids have been observed directly.
44  */
45 void wiz_lite(player_type *caster_ptr, bool ninja)
46 {
47         /* Memorize objects */
48         for (OBJECT_IDX i = 1; i < caster_ptr->current_floor_ptr->o_max; i++)
49         {
50                 object_type *o_ptr = &caster_ptr->current_floor_ptr->o_list[i];
51                 if (!OBJECT_IS_VALID(o_ptr)) continue;
52                 if (OBJECT_IS_HELD_MONSTER(o_ptr)) continue;
53                 o_ptr->marked |= OM_FOUND;
54         }
55
56         /* Scan all normal grids */
57         for (POSITION y = 1; y < caster_ptr->current_floor_ptr->height - 1; y++)
58         {
59                 /* Scan all normal grids */
60                 for (POSITION x = 1; x < caster_ptr->current_floor_ptr->width - 1; x++)
61                 {
62                         grid_type *g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][x];
63
64                         /* Memorize terrain of the grid */
65                         g_ptr->info |= (CAVE_KNOWN);
66
67                         /* Feature code (applying "mimic" field) */
68                         FEAT_IDX feat = get_feat_mimic(g_ptr);
69                         feature_type *f_ptr;
70                         f_ptr = &f_info[feat];
71
72                         /* Process all non-walls */
73                         if (have_flag(f_ptr->flags, FF_WALL)) continue;
74
75                         /* Scan all neighbors */
76                         for (OBJECT_IDX i = 0; i < 9; i++)
77                         {
78                                 POSITION yy = y + ddy_ddd[i];
79                                 POSITION xx = x + ddx_ddd[i];
80                                 g_ptr = &caster_ptr->current_floor_ptr->grid_array[yy][xx];
81
82                                 /* Feature code (applying "mimic" field) */
83                                 f_ptr = &f_info[get_feat_mimic(g_ptr)];
84
85                                 /* Perma-lite the grid */
86                                 if (!(d_info[caster_ptr->dungeon_idx].flags1 & DF1_DARKNESS) && !ninja)
87                                 {
88                                         g_ptr->info |= (CAVE_GLOW);
89                                 }
90
91                                 /* Memorize normal features */
92                                 if (have_flag(f_ptr->flags, FF_REMEMBER))
93                                 {
94                                         /* Memorize the grid */
95                                         g_ptr->info |= (CAVE_MARK);
96                                 }
97
98                                 /* Perma-lit grids (newly and previously) */
99                                 else if (g_ptr->info & CAVE_GLOW)
100                                 {
101                                         /* Normally, memorize floors (see above) */
102                                         if (view_perma_grids && !view_torch_grids)
103                                         {
104                                                 /* Memorize the grid */
105                                                 g_ptr->info |= (CAVE_MARK);
106                                         }
107                                 }
108                         }
109                 }
110         }
111
112         caster_ptr->update |= (PU_MONSTERS);
113         caster_ptr->redraw |= (PR_MAP);
114         caster_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
115
116         if (caster_ptr->special_defense & NINJA_S_STEALTH)
117         {
118                 if (caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].info & CAVE_GLOW) set_superstealth(caster_ptr, FALSE);
119         }
120 }
121
122
123 /*
124  * Forget the dungeon map (ala "Thinking of Maud...").
125  */
126 void wiz_dark(player_type *caster_ptr)
127 {
128         /* Forget every grid */
129         for (POSITION y = 1; y < caster_ptr->current_floor_ptr->height - 1; y++)
130         {
131                 for (POSITION x = 1; x < caster_ptr->current_floor_ptr->width - 1; x++)
132                 {
133                         grid_type *g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][x];
134
135                         /* Process the grid */
136                         g_ptr->info &= ~(CAVE_MARK | CAVE_IN_DETECT | CAVE_KNOWN);
137                         g_ptr->info |= (CAVE_UNSAFE);
138                 }
139         }
140
141         /* Forget every grid on horizontal edge */
142         for (POSITION x = 0; x < caster_ptr->current_floor_ptr->width; x++)
143         {
144                 caster_ptr->current_floor_ptr->grid_array[0][x].info &= ~(CAVE_MARK);
145                 caster_ptr->current_floor_ptr->grid_array[caster_ptr->current_floor_ptr->height - 1][x].info &= ~(CAVE_MARK);
146         }
147
148         /* Forget every grid on vertical edge */
149         for (POSITION y = 1; y < (caster_ptr->current_floor_ptr->height - 1); y++)
150         {
151                 caster_ptr->current_floor_ptr->grid_array[y][0].info &= ~(CAVE_MARK);
152                 caster_ptr->current_floor_ptr->grid_array[y][caster_ptr->current_floor_ptr->width - 1].info &= ~(CAVE_MARK);
153         }
154
155         /* Forget all objects */
156         for (OBJECT_IDX i = 1; i < caster_ptr->current_floor_ptr->o_max; i++)
157         {
158                 object_type *o_ptr = &caster_ptr->current_floor_ptr->o_list[i];
159
160                 if (!OBJECT_IS_VALID(o_ptr)) continue;
161                 if (OBJECT_IS_HELD_MONSTER(o_ptr)) continue;
162
163                 /* Forget the object */
164                 o_ptr->marked &= OM_TOUCHED;
165         }
166
167         /* Forget travel route when we have forgotten map */
168         forget_travel_flow(caster_ptr->current_floor_ptr);
169
170         caster_ptr->update |= (PU_UN_VIEW | PU_UN_LITE);
171         caster_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE);
172         caster_ptr->update |= (PU_MONSTERS);
173         caster_ptr->redraw |= (PR_MAP);
174         caster_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
175 }
176
177
178 /*!
179  * @brief 守りのルーン設置処理 /
180  * Leave a "glyph of warding" which prevents monster movement
181  * @return 実際に設置が行われた場合TRUEを返す
182  */
183 bool warding_glyph(player_type *caster_ptr)
184 {
185         if (!cave_clean_bold(caster_ptr->current_floor_ptr, caster_ptr->y, caster_ptr->x))
186         {
187                 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
188                 return FALSE;
189         }
190
191         /* Create a glyph */
192         caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].info |= CAVE_OBJECT;
193         caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].mimic = feat_glyph;
194
195         note_spot(caster_ptr, caster_ptr->y, caster_ptr->x);
196         lite_spot(caster_ptr, caster_ptr->y, caster_ptr->x);
197
198         return TRUE;
199 }
200
201
202 /*!
203  * @brief 爆発のルーン設置処理 /
204  * Leave an "explosive rune" which prevents monster movement
205  * @param caster_ptr プレーヤーへの参照ポインタ
206  * @param y 設置場所
207  * @param x 設置場所
208  * @return 実際に設置が行われた場合TRUEを返す
209  */
210 bool explosive_rune(player_type *caster_ptr, POSITION y, POSITION x)
211 {
212         floor_type *floor_ptr = caster_ptr->current_floor_ptr;
213         if (!cave_clean_bold(floor_ptr, y, x))
214         {
215                 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
216                 return FALSE;
217         }
218
219         /* Create a glyph */
220         floor_ptr->grid_array[y][x].info |= CAVE_OBJECT;
221         floor_ptr->grid_array[y][x].mimic = feat_explosive_rune;
222
223         note_spot(caster_ptr, y, x);
224         lite_spot(caster_ptr, y, x);
225
226         return TRUE;
227 }
228
229
230 /*!
231  * @brief 鏡設置処理
232  * @return 実際に設置が行われた場合TRUEを返す
233  */
234 bool place_mirror(player_type *caster_ptr)
235 {
236         if (!cave_clean_bold(caster_ptr->current_floor_ptr, caster_ptr->y, caster_ptr->x))
237         {
238                 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
239                 return FALSE;
240         }
241
242         /* Create a mirror */
243         caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].info |= CAVE_OBJECT;
244         caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].mimic = feat_mirror;
245
246         /* Turn on the light */
247         caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].info |= CAVE_GLOW;
248
249         note_spot(caster_ptr, caster_ptr->y, caster_ptr->x);
250         lite_spot(caster_ptr, caster_ptr->y, caster_ptr->x);
251         update_local_illumination(caster_ptr, caster_ptr->y, caster_ptr->x);
252
253         return TRUE;
254 }
255
256
257 /*!
258  * @brief プレイヤーの手による能動的な階段生成処理 /
259  * Create stairs at or move previously created stairs into the player location.
260  * @return なし
261  */
262 void stair_creation(player_type *caster_ptr)
263 {
264         /* Forbid up staircases on Ironman mode */
265         bool up = TRUE;
266         if (ironman_downward) up = FALSE;
267
268         /* Forbid down staircases on quest level */
269         bool down = TRUE;
270         floor_type *floor_ptr = caster_ptr->current_floor_ptr;
271         if (quest_number(caster_ptr, floor_ptr->dun_level) || (floor_ptr->dun_level >= d_info[caster_ptr->dungeon_idx].maxdepth)) down = FALSE;
272
273         /* No effect out of standard dungeon floor */
274         if (!floor_ptr->dun_level || (!up && !down) ||
275                 (floor_ptr->inside_quest && is_fixed_quest_idx(floor_ptr->inside_quest)) ||
276                 floor_ptr->inside_arena || caster_ptr->phase_out)
277         {
278                 /* arena or quest */
279                 msg_print(_("効果がありません!", "There is no effect!"));
280                 return;
281         }
282
283         /* Artifacts resists */
284         if (!cave_valid_bold(floor_ptr, caster_ptr->y, caster_ptr->x))
285         {
286                 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
287                 return;
288         }
289
290         /* Destroy all objects in the grid */
291         delete_object(caster_ptr, caster_ptr->y, caster_ptr->x);
292
293         /* Extract current floor data */
294         saved_floor_type *sf_ptr;
295         sf_ptr = get_sf_ptr(caster_ptr->floor_id);
296         if (!sf_ptr)
297         {
298                 /* No floor id? -- Create now! */
299                 caster_ptr->floor_id = get_new_floor_id(caster_ptr);
300                 sf_ptr = get_sf_ptr(caster_ptr->floor_id);
301         }
302
303         /* Choose randomly */
304         if (up && down)
305         {
306                 if (randint0(100) < 50) up = FALSE;
307                 else down = FALSE;
308         }
309
310         /* Destination is already fixed */
311         FLOOR_IDX dest_floor_id = 0;
312         if (up)
313         {
314                 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
315         }
316         else
317         {
318                 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
319         }
320         
321         /* Search old stairs leading to the destination */
322         if (dest_floor_id)
323         {
324                 POSITION x, y;
325
326                 for (y = 0; y < floor_ptr->height; y++)
327                 {
328                         for (x = 0; x < floor_ptr->width; x++)
329                         {
330                                 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
331
332                                 if (!g_ptr->special) continue;
333                                 if (feat_uses_special(g_ptr->feat)) continue;
334                                 if (g_ptr->special != dest_floor_id) continue;
335
336                                 /* Remove old stairs */
337                                 g_ptr->special = 0;
338                                 cave_set_feat(caster_ptr, y, x, feat_ground_type[randint0(100)]);
339                         }
340                 }
341         }
342
343         /* No old destination -- Get new one now */
344         else
345         {
346                 dest_floor_id = get_new_floor_id(caster_ptr);
347
348                 /* Fix it */
349                 if (up)
350                         sf_ptr->upper_floor_id = dest_floor_id;
351                 else
352                         sf_ptr->lower_floor_id = dest_floor_id;
353         }
354
355         /* Extract destination floor data */
356         saved_floor_type *dest_sf_ptr;
357         dest_sf_ptr = get_sf_ptr(dest_floor_id);
358         
359         /* Create a staircase */
360         if (up)
361         {
362                 cave_set_feat(caster_ptr, caster_ptr->y, caster_ptr->x,
363                         (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level <= floor_ptr->dun_level - 2)) ?
364                         feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair);
365         }
366         else
367         {
368                 cave_set_feat(caster_ptr, caster_ptr->y, caster_ptr->x,
369                         (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level >= floor_ptr->dun_level + 2)) ?
370                         feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair);
371         }
372
373         /* Connect this stairs to the destination */
374         floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].special = dest_floor_id;
375 }
376
377 /*
378  * Hack -- map the current panel (plus some) ala "magic mapping"
379  */
380 void map_area(player_type *caster_ptr, POSITION range)
381 {
382         if (d_info[caster_ptr->dungeon_idx].flags1 & DF1_DARKNESS) range /= 3;
383
384         /* Scan that area */
385         for (POSITION y = 1; y < caster_ptr->current_floor_ptr->height - 1; y++)
386         {
387                 for (POSITION x = 1; x < caster_ptr->current_floor_ptr->width - 1; x++)
388                 {
389                         if (distance(caster_ptr->y, caster_ptr->x, y, x) > range) continue;
390
391                         grid_type *g_ptr;
392                         g_ptr = &caster_ptr->current_floor_ptr->grid_array[y][x];
393
394                         /* Memorize terrain of the grid */
395                         g_ptr->info |= (CAVE_KNOWN);
396
397                         /* Feature code (applying "mimic" field) */
398                         FEAT_IDX feat = get_feat_mimic(g_ptr);
399                         feature_type *f_ptr;
400                         f_ptr = &f_info[feat];
401
402                         /* All non-walls are "checked" */
403                         if (have_flag(f_ptr->flags, FF_WALL)) continue;
404
405                         /* Memorize normal features */
406                         if (have_flag(f_ptr->flags, FF_REMEMBER))
407                         {
408                                 /* Memorize the object */
409                                 g_ptr->info |= (CAVE_MARK);
410                         }
411
412                         /* Memorize known walls */
413                         for (int i = 0; i < 8; i++)
414                         {
415                                 g_ptr = &caster_ptr->current_floor_ptr->grid_array[y + ddy_ddd[i]][x + ddx_ddd[i]];
416
417                                 /* Feature code (applying "mimic" field) */
418                                 feat = get_feat_mimic(g_ptr);
419                                 f_ptr = &f_info[feat];
420
421                                 /* Memorize walls (etc) */
422                                 if (have_flag(f_ptr->flags, FF_REMEMBER))
423                                 {
424                                         /* Memorize the walls */
425                                         g_ptr->info |= (CAVE_MARK);
426                                 }
427                         }
428                 }
429         }
430
431         caster_ptr->redraw |= (PR_MAP);
432         caster_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
433 }
434
435
436
437 /*!
438  * @brief *破壊*処理を行う / The spell of destruction
439  * @param y1 破壊の中心Y座標
440  * @param x1 破壊の中心X座標
441  * @param r 破壊の半径
442  * @param in_generate ダンジョンフロア生成中の処理ならばTRUE
443  * @return 効力があった場合TRUEを返す
444  * @details
445  * <pre>
446  * This spell "deletes" monsters (instead of "killing" them).
447  *
448  * Later we may use one function for both "destruction" and
449  * "earthquake" by using the "full" to select "destruction".
450  * </pre>
451  */
452 bool destroy_area(player_type *caster_ptr, POSITION y1, POSITION x1, POSITION r, bool in_generate)
453 {
454         /* Prevent destruction of quest levels and town */
455         floor_type *floor_ptr = caster_ptr->current_floor_ptr;
456         if ((floor_ptr->inside_quest && is_fixed_quest_idx(floor_ptr->inside_quest)) || !floor_ptr->dun_level)
457         {
458                 return FALSE;
459         }
460
461         /* Lose monster light */
462         if (!in_generate) clear_mon_lite(floor_ptr);
463
464         /* Big area of affect */
465         bool flag = FALSE;
466         for (POSITION y = (y1 - r); y <= (y1 + r); y++)
467         {
468                 for (POSITION x = (x1 - r); x <= (x1 + r); x++)
469                 {
470                         if (!in_bounds(floor_ptr, y, x)) continue;
471
472                         /* Extract the distance */
473                         int k = distance(y1, x1, y, x);
474
475                         /* Stay in the circle of death */
476                         if (k > r) continue;
477                         grid_type *g_ptr;
478                         g_ptr = &floor_ptr->grid_array[y][x];
479
480                         /* Lose room and vault */
481                         g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY);
482
483                         /* Lose light and knowledge */
484                         g_ptr->info &= ~(CAVE_MARK | CAVE_GLOW | CAVE_KNOWN);
485
486                         if (!in_generate) /* Normal */
487                         {
488                                 /* Lose unsafety */
489                                 g_ptr->info &= ~(CAVE_UNSAFE);
490
491                                 /* Hack -- Notice player affect */
492                                 if (player_bold(caster_ptr, y, x))
493                                 {
494                                         /* Hurt the player later */
495                                         flag = TRUE;
496
497                                         /* Do not hurt this grid */
498                                         continue;
499                                 }
500                         }
501
502                         /* Hack -- Skip the epicenter */
503                         if ((y == y1) && (x == x1)) continue;
504
505                         if (g_ptr->m_idx)
506                         {
507                                 monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
508                                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
509
510                                 if (in_generate) /* In generation */
511                                 {
512                                         /* Delete the monster (if any) */
513                                         delete_monster(caster_ptr, y, x);
514                                 }
515                                 else if (r_ptr->flags1 & RF1_QUESTOR)
516                                 {
517                                         /* Heal the monster */
518                                         m_ptr->hp = m_ptr->maxhp;
519
520                                         /* Try to teleport away quest monsters */
521                                         if (!teleport_away(caster_ptr, g_ptr->m_idx, (r * 2) + 1, TELEPORT_DEC_VALOUR)) continue;
522                                 }
523                                 else
524                                 {
525                                         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
526                                         {
527                                                 GAME_TEXT m_name[MAX_NLEN];
528
529                                                 monster_desc(caster_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
530                                                 exe_write_diary(caster_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_DESTROY, m_name);
531                                         }
532
533                                         /* Delete the monster (if any) */
534                                         delete_monster(caster_ptr, y, x);
535                                 }
536                         }
537
538                         /* During generation, destroyed artifacts are "preserved" */
539                         if (preserve_mode || in_generate)
540                         {
541                                 OBJECT_IDX this_o_idx, next_o_idx = 0;
542
543                                 /* Scan all objects in the grid */
544                                 for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
545                                 {
546                                         object_type *o_ptr;
547                                         o_ptr = &floor_ptr->o_list[this_o_idx];
548                                         next_o_idx = o_ptr->next_o_idx;
549
550                                         /* Hack -- Preserve unknown artifacts */
551                                         if (object_is_fixed_artifact(o_ptr) && (!object_is_known(o_ptr) || in_generate))
552                                         {
553                                                 /* Mega-Hack -- Preserve the artifact */
554                                                 a_info[o_ptr->name1].cur_num = 0;
555
556                                                 if (in_generate && cheat_peek)
557                                                 {
558                                                         GAME_TEXT o_name[MAX_NLEN];
559                                                         object_desc(o_name, o_ptr, (OD_NAME_ONLY | OD_STORE));
560                                                         msg_format(_("伝説のアイテム (%s) は生成中に*破壊*された。", "Artifact (%s) was *destroyed* during generation."), o_name);
561                                                 }
562                                         }
563                                         else if (in_generate && cheat_peek && o_ptr->art_name)
564                                         {
565                                                 msg_print(_("ランダム・アーティファクトの1つは生成中に*破壊*された。",
566                                                         "One of the random artifacts was *destroyed* during generation."));
567                                         }
568                                 }
569                         }
570
571                         delete_object(caster_ptr, y, x);
572
573                         /* Destroy "non-permanent" grids */
574                         if (cave_perma_grid(g_ptr)) continue;
575
576                         /* Wall (or floor) type */
577                         int t = randint0(200);
578
579                         if (!in_generate) /* Normal */
580                         {
581                                 if (t < 20)
582                                 {
583                                         /* Create granite wall */
584                                         cave_set_feat(caster_ptr, y, x, feat_granite);
585                                 }
586                                 else if (t < 70)
587                                 {
588                                         /* Create quartz vein */
589                                         cave_set_feat(caster_ptr, y, x, feat_quartz_vein);
590                                 }
591                                 else if (t < 100)
592                                 {
593                                         /* Create magma vein */
594                                         cave_set_feat(caster_ptr, y, x, feat_magma_vein);
595                                 }
596                                 else
597                                 {
598                                         /* Create floor */
599                                         cave_set_feat(caster_ptr, y, x, feat_ground_type[randint0(100)]);
600                                 }
601
602                                 continue;
603                         }
604                         
605                         if (t < 20)
606                         {
607                                 /* Create granite wall */
608                                 place_grid(caster_ptr, g_ptr, extra);
609                         }
610                         else if (t < 70)
611                         {
612                                 /* Create quartz vein */
613                                 g_ptr->feat = feat_quartz_vein;
614                         }
615                         else if (t < 100)
616                         {
617                                 /* Create magma vein */
618                                 g_ptr->feat = feat_magma_vein;
619                         }
620                         else
621                         {
622                                 /* Create floor */
623                                 place_grid(caster_ptr, g_ptr, floor);
624                         }
625
626                         /* Clear garbage of hidden trap or door */
627                         g_ptr->mimic = 0;
628                 }
629         }
630
631         if (in_generate) return TRUE;
632
633         /* Process "re-glowing" */
634         for (POSITION y = (y1 - r); y <= (y1 + r); y++)
635         {
636                 for (POSITION x = (x1 - r); x <= (x1 + r); x++)
637                 {
638                         if (!in_bounds(floor_ptr, y, x)) continue;
639
640                         /* Extract the distance */
641                         int k = distance(y1, x1, y, x);
642
643                         /* Stay in the circle of death */
644                         if (k > r) continue;
645                         grid_type *g_ptr;
646                         g_ptr = &floor_ptr->grid_array[y][x];
647
648                         if (is_mirror_grid(g_ptr))
649                         {
650                                 g_ptr->info |= CAVE_GLOW;
651                                 continue;
652                         }
653                         
654                         if ((d_info[floor_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) continue;
655
656                         DIRECTION i;
657                         POSITION yy, xx;
658                         grid_type *cc_ptr;
659
660                         for (i = 0; i < 9; i++)
661                         {
662                                 yy = y + ddy_ddd[i];
663                                 xx = x + ddx_ddd[i];
664                                 if (!in_bounds2(floor_ptr, yy, xx)) continue;
665                                 cc_ptr = &floor_ptr->grid_array[yy][xx];
666                                 if (have_flag(f_info[get_feat_mimic(cc_ptr)].flags, FF_GLOW))
667                                 {
668                                         g_ptr->info |= CAVE_GLOW;
669                                         break;
670                                 }
671                         }
672                 }
673         }
674
675         /* Hack -- Affect player */
676         if (flag)
677         {
678                 msg_print(_("燃えるような閃光が発生した!", "There is a searing blast of light!"));
679
680                 /* Blind the player */
681                 if (!caster_ptr->resist_blind && !caster_ptr->resist_lite)
682                 {
683                         /* Become blind */
684                         (void)set_blind(caster_ptr, caster_ptr->blind + 10 + randint1(10));
685                 }
686         }
687
688         forget_flow(floor_ptr);
689
690         /* Mega-Hack -- Forget the view and lite */
691         caster_ptr->update |= (PU_UN_VIEW | PU_UN_LITE | PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS);
692         caster_ptr->redraw |= (PR_MAP);
693         caster_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
694
695         if (caster_ptr->special_defense & NINJA_S_STEALTH)
696         {
697                 if (floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].info & CAVE_GLOW) set_superstealth(caster_ptr, FALSE);
698         }
699
700         return TRUE;
701 }
702
703
704 /*!
705  * @brief 地震処理(サブルーチン) /
706  * Induce an "earthquake" of the given radius at the given location.
707  * @param caster_ptrプレーヤーへの参照ポインタ
708  * @param cy 中心Y座標
709  * @param cx 中心X座標
710  * @param r 効果半径
711  * @param m_idx 地震を起こしたモンスターID(0ならばプレイヤー)
712  * @return 効力があった場合TRUEを返す
713  * @details
714  * <pre>
715  *
716  * This will turn some walls into floors and some floors into walls.
717  *
718  * The player will take damage and "jump" into a safe grid if possible,
719  * otherwise, he will "tunnel" through the rubble instantaneously.
720  *
721  * Monsters will take damage, and "jump" into a safe grid if possible,
722  * otherwise they will be "buried" in the rubble, disappearing from
723  * the level in the same way that they do when genocided.
724  *
725  * Note that thus the player and monsters (except eaters of walls and
726  * passers through walls) will never occupy the same grid as a wall.
727  * Note that as of now (2.7.8) no monster may occupy a "wall" grid, even
728  * for a single turn, unless that monster can pass_walls or kill_walls.
729  * This has allowed massive simplification of the "monster" code.
730  * </pre>
731  */
732 bool earthquake(player_type *caster_ptr, POSITION cy, POSITION cx, POSITION r, MONSTER_IDX m_idx)
733 {
734         /* Prevent destruction of quest levels and town */
735         floor_type *floor_ptr = caster_ptr->current_floor_ptr;
736         if ((floor_ptr->inside_quest && is_fixed_quest_idx(floor_ptr->inside_quest)) || !floor_ptr->dun_level)
737         {
738                 return FALSE;
739         }
740
741         /* Paranoia -- Enforce maximum range */
742         if (r > 12) r = 12;
743
744         /* Clear the "maximal blast" area */
745         POSITION y, x;
746         bool map[32][32];
747         for (y = 0; y < 32; y++)
748         {
749                 for (x = 0; x < 32; x++)
750                 {
751                         map[y][x] = FALSE;
752                 }
753         }
754
755         /* Check around the epicenter */
756         POSITION yy, xx, dy, dx;
757         int damage = 0;
758         bool hurt = FALSE;
759         for (dy = -r; dy <= r; dy++)
760         {
761                 for (dx = -r; dx <= r; dx++)
762                 {
763                         yy = cy + dy;
764                         xx = cx + dx;
765
766                         if (!in_bounds(floor_ptr, yy, xx)) continue;
767
768                         /* Skip distant grids */
769                         if (distance(cy, cx, yy, xx) > r) continue;
770                         grid_type *g_ptr;
771                         g_ptr = &floor_ptr->grid_array[yy][xx];
772
773                         /* Lose room and vault / Lose light and knowledge */
774                         g_ptr->info &= ~(CAVE_ROOM | CAVE_ICKY | CAVE_UNSAFE);
775                         g_ptr->info &= ~(CAVE_GLOW | CAVE_MARK | CAVE_KNOWN);
776
777                         /* Skip the epicenter */
778                         if (!dx && !dy) continue;
779
780                         /* Skip most grids */
781                         if (randint0(100) < 85) continue;
782
783                         /* Damage this grid */
784                         map[16 + yy - cy][16 + xx - cx] = TRUE;
785
786                         /* Hack -- Take note of player damage */
787                         if (player_bold(caster_ptr, yy, xx)) hurt = TRUE;
788                 }
789         }
790
791         /* First, affect the player (if necessary) */
792         int sn = 0;
793         POSITION sy = 0, sx = 0;
794         if (hurt && !caster_ptr->pass_wall && !caster_ptr->kill_wall)
795         {
796                 /* Check around the player */
797                 for (DIRECTION i = 0; i < 8; i++)
798                 {
799                         y = caster_ptr->y + ddy_ddd[i];
800                         x = caster_ptr->x + ddx_ddd[i];
801
802                         /* Skip non-empty grids */
803                         if (!cave_empty_bold(floor_ptr, y, x)) continue;
804
805                         /* Important -- Skip "quake" grids */
806                         if (map[16 + y - cy][16 + x - cx]) continue;
807
808                         if (floor_ptr->grid_array[y][x].m_idx) continue;
809
810                         /* Count "safe" grids */
811                         sn++;
812
813                         /* Randomize choice */
814                         if (randint0(sn) > 0) continue;
815
816                         /* Save the safe location */
817                         sy = y; sx = x;
818                 }
819
820                 /* Random message */
821                 switch (randint1(3))
822                 {
823                 case 1:
824                 {
825                         msg_print(_("ダンジョンの壁が崩れた!", "The dungeon's ceiling collapses!"));
826                         break;
827                 }
828                 case 2:
829                 {
830                         msg_print(_("ダンジョンの床が不自然にねじ曲がった!", "The dungeon's floor twists in an unnatural way!"));
831                         break;
832                 }
833                 default:
834                 {
835                         msg_print(_("ダンジョンが揺れた!崩れた岩が頭に降ってきた!", "The dungeon quakes!  You are pummeled with debris!"));
836                         break;
837                 }
838                 }
839
840                 /* Hurt the player a lot */
841                 if (!sn)
842                 {
843                         /* Message and damage */
844                         msg_print(_("あなたはひどい怪我を負った!", "You are severely crushed!"));
845                         damage = 200;
846                 }
847
848                 /* Destroy the grid, and push the player to safety */
849                 else
850                 {
851                         /* Calculate results */
852                         switch (randint1(3))
853                         {
854                         case 1:
855                         {
856                                 msg_print(_("降り注ぐ岩をうまく避けた!", "You nimbly dodge the blast!"));
857                                 damage = 0;
858                                 break;
859                         }
860                         case 2:
861                         {
862                                 msg_print(_("岩石があなたに直撃した!", "You are bashed by rubble!"));
863                                 damage = damroll(10, 4);
864                                 (void)set_stun(caster_ptr, caster_ptr->stun + randint1(50));
865                                 break;
866                         }
867                         case 3:
868                         {
869                                 msg_print(_("あなたは床と壁との間に挟まれてしまった!", "You are crushed between the floor and ceiling!"));
870                                 damage = damroll(10, 4);
871                                 (void)set_stun(caster_ptr, caster_ptr->stun + randint1(50));
872                                 break;
873                         }
874                         }
875
876                         /* Move the player to the safe location */
877                         (void)move_player_effect(caster_ptr, sy, sx, MPE_DONT_PICKUP);
878                 }
879
880                 /* Important -- no wall on player */
881                 map[16 + caster_ptr->y - cy][16 + caster_ptr->x - cx] = FALSE;
882
883                 if (damage)
884                 {
885                         concptr killer;
886
887                         if (m_idx)
888                         {
889                                 GAME_TEXT m_name[MAX_NLEN];
890                                 monster_type *m_ptr = &floor_ptr->m_list[m_idx];
891                                 monster_desc(caster_ptr, m_name, m_ptr, MD_WRONGDOER_NAME);
892                                 killer = format(_("%sの起こした地震", "an earthquake caused by %s"), m_name);
893                         }
894                         else
895                         {
896                                 killer = _("地震", "an earthquake");
897                         }
898
899                         take_hit(caster_ptr, DAMAGE_ATTACK, damage, killer, -1);
900                 }
901         }
902
903         /* Examine the quaked region */
904         for (dy = -r; dy <= r; dy++)
905         {
906                 for (dx = -r; dx <= r; dx++)
907                 {
908                         yy = cy + dy;
909                         xx = cx + dx;
910
911                         /* Skip unaffected grids */
912                         if (!map[16 + yy - cy][16 + xx - cx]) continue;
913
914                         grid_type *g_ptr;
915                         g_ptr = &floor_ptr->grid_array[yy][xx];
916
917                         if (g_ptr->m_idx == caster_ptr->riding) continue;
918
919                         /* Process monsters */
920                         if (!g_ptr->m_idx) continue;
921
922                         monster_type *m_ptr = &floor_ptr->m_list[g_ptr->m_idx];
923                         monster_race *r_ptr = &r_info[m_ptr->r_idx];
924
925                         /* Quest monsters */
926                         if (r_ptr->flags1 & RF1_QUESTOR)
927                         {
928                                 /* No wall on quest monsters */
929                                 map[16 + yy - cy][16 + xx - cx] = FALSE;
930
931                                 continue;
932                         }
933
934                         /* Most monsters cannot co-exist with rock */
935                         if ((r_ptr->flags2 & RF2_KILL_WALL) || (r_ptr->flags2 & RF2_PASS_WALL)) continue;
936
937                         GAME_TEXT m_name[MAX_NLEN];
938
939                         /* Assume not safe */
940                         sn = 0;
941
942                         /* Monster can move to escape the wall */
943                         if (!(r_ptr->flags1 & RF1_NEVER_MOVE))
944                         {
945                                 /* Look for safety */
946                                 for (DIRECTION i = 0; i < 8; i++)
947                                 {
948                                         y = yy + ddy_ddd[i];
949                                         x = xx + ddx_ddd[i];
950
951                                         /* Skip non-empty grids */
952                                         if (!cave_empty_bold(floor_ptr, y, x)) continue;
953
954                                         /* Hack -- no safety on glyph of warding */
955                                         if (is_glyph_grid(&floor_ptr->grid_array[y][x])) continue;
956                                         if (is_explosive_rune_grid(&floor_ptr->grid_array[y][x])) continue;
957
958                                         /* ... nor on the Pattern */
959                                         if (pattern_tile(y, x)) continue;
960
961                                         /* Important -- Skip "quake" grids */
962                                         if (map[16 + y - cy][16 + x - cx]) continue;
963
964                                         if (floor_ptr->grid_array[y][x].m_idx) continue;
965                                         if (player_bold(caster_ptr, y, x)) continue;
966
967                                         /* Count "safe" grids */
968                                         sn++;
969
970                                         /* Randomize choice */
971                                         if (randint0(sn) > 0) continue;
972
973                                         /* Save the safe grid */
974                                         sy = y; sx = x;
975                                 }
976                         }
977
978                         monster_desc(caster_ptr, m_name, m_ptr, 0);
979
980                         /* Scream in pain */
981                         if (!ignore_unview || is_seen(m_ptr)) msg_format(_("%^sは苦痛で泣きわめいた!", "%^s wails out in pain!"), m_name);
982
983                         /* Take damage from the quake */
984                         damage = (sn ? damroll(4, 8) : (m_ptr->hp + 1));
985
986                         /* Monster is certainly awake */
987                         (void)set_monster_csleep(caster_ptr, g_ptr->m_idx, 0);
988
989                         /* Apply damage directly */
990                         m_ptr->hp -= damage;
991
992                         /* Delete (not kill) "dead" monsters */
993                         if (m_ptr->hp < 0)
994                         {
995                                 if (!ignore_unview || is_seen(m_ptr))
996                                         msg_format(_("%^sは岩石に埋もれてしまった!", "%^s is embedded in the rock!"), m_name);
997
998                                 if (g_ptr->m_idx)
999                                 {
1000                                         if (record_named_pet && is_pet(&floor_ptr->m_list[g_ptr->m_idx]) && floor_ptr->m_list[g_ptr->m_idx].nickname)
1001                                         {
1002                                                 char m2_name[MAX_NLEN];
1003
1004                                                 monster_desc(caster_ptr, m2_name, m_ptr, MD_INDEF_VISIBLE);
1005                                                 exe_write_diary(caster_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_EARTHQUAKE, m2_name);
1006                                         }
1007                                 }
1008
1009                                 delete_monster(caster_ptr, yy, xx);
1010
1011                                 sn = 0;
1012                         }
1013
1014                         /* Hack -- Escape from the rock */
1015                         if (sn == 0) continue;
1016
1017                         IDX m_idx_aux = floor_ptr->grid_array[yy][xx].m_idx;
1018
1019                         /* Update the old location */
1020                         floor_ptr->grid_array[yy][xx].m_idx = 0;
1021
1022                         /* Update the new location */
1023                         floor_ptr->grid_array[sy][sx].m_idx = m_idx_aux;
1024
1025                         /* Move the monster */
1026                         m_ptr->fy = sy;
1027                         m_ptr->fx = sx;
1028
1029                         update_monster(caster_ptr, m_idx, TRUE);
1030                         lite_spot(caster_ptr, yy, xx);
1031                         lite_spot(caster_ptr, sy, sx);
1032                 }
1033         }
1034
1035         /* Lose monster light */
1036         clear_mon_lite(floor_ptr);
1037
1038         /* Examine the quaked region */
1039         for (dy = -r; dy <= r; dy++)
1040         {
1041                 for (dx = -r; dx <= r; dx++)
1042                 {
1043                         yy = cy + dy;
1044                         xx = cx + dx;
1045
1046                         /* Skip unaffected grids */
1047                         if (!map[16 + yy - cy][16 + xx - cx]) continue;
1048
1049                         grid_type *g_ptr;
1050                         g_ptr = &floor_ptr->grid_array[yy][xx];
1051
1052                         /* Destroy location (if valid) */
1053                         if (!cave_valid_bold(floor_ptr, yy, xx)) continue;
1054
1055                         delete_object(caster_ptr, yy, xx);
1056
1057                         /* Wall (or floor) type */
1058                         int t = cave_have_flag_bold(floor_ptr, yy, xx, FF_PROJECT) ? randint0(100) : 200;
1059
1060                         /* Create granite wall */
1061                         if (t < 20)
1062                         {
1063                                 cave_set_feat(caster_ptr, yy, xx, feat_granite);
1064                                 continue;
1065                         }
1066
1067                         /* Create quartz vein */
1068                         if (t < 70)
1069                         {
1070                                 cave_set_feat(caster_ptr, yy, xx, feat_quartz_vein);
1071                                 continue;
1072                         }
1073
1074                         /* Create magma vein */
1075                         if (t < 100)
1076                         {
1077                                 cave_set_feat(caster_ptr, yy, xx, feat_magma_vein);
1078                                 continue;
1079                         }
1080
1081                         /* Create floor */
1082                         cave_set_feat(caster_ptr, yy, xx, feat_ground_type[randint0(100)]);
1083                 }
1084         }
1085
1086         /* Process "re-glowing" */
1087         for (dy = -r; dy <= r; dy++)
1088         {
1089                 for (dx = -r; dx <= r; dx++)
1090                 {
1091                         yy = cy + dy;
1092                         xx = cx + dx;
1093
1094                         if (!in_bounds(floor_ptr, yy, xx)) continue;
1095
1096                         /* Skip distant grids */
1097                         if (distance(cy, cx, yy, xx) > r) continue;
1098                         grid_type *g_ptr;
1099                         g_ptr = &floor_ptr->grid_array[yy][xx];
1100
1101                         if (is_mirror_grid(g_ptr))
1102                         {
1103                                 g_ptr->info |= CAVE_GLOW;
1104                                 continue;
1105                         }
1106                         
1107                         if ((d_info[caster_ptr->dungeon_idx].flags1 & DF1_DARKNESS)) continue;
1108                         
1109                         DIRECTION ii;
1110                         POSITION yyy, xxx;
1111                         grid_type *cc_ptr;
1112
1113                         for (ii = 0; ii < 9; ii++)
1114                         {
1115                                 yyy = yy + ddy_ddd[ii];
1116                                 xxx = xx + ddx_ddd[ii];
1117                                 if (!in_bounds2(floor_ptr, yyy, xxx)) continue;
1118                                 cc_ptr = &floor_ptr->grid_array[yyy][xxx];
1119                                 if (have_flag(f_info[get_feat_mimic(cc_ptr)].flags, FF_GLOW))
1120                                 {
1121                                         g_ptr->info |= CAVE_GLOW;
1122                                         break;
1123                                 }
1124                         }
1125                 }
1126         }
1127
1128         /* Mega-Hack -- Forget the view and lite */
1129         caster_ptr->update |= (PU_UN_VIEW | PU_UN_LITE | PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_MONSTERS);
1130         caster_ptr->redraw |= (PR_HEALTH | PR_UHEALTH | PR_MAP);
1131         caster_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1132
1133         if (caster_ptr->special_defense & NINJA_S_STEALTH)
1134         {
1135                 if (floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].info & CAVE_GLOW) set_superstealth(caster_ptr, FALSE);
1136         }
1137
1138         /* Success */
1139         return TRUE;
1140 }