OSDN Git Service

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