OSDN Git Service

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