OSDN Git Service

[Refactor] #40572 Separated quest-monster-placer.c/h
[hengband/hengband.git] / src / floor / floor-save.c
1 /*!
2  * @brief 保存された階の管理 / management of the saved floor
3  * @date 2014/01/04
4  * @author
5  * Copyright (c) 2002  Mogami \n
6  * This software may be copied and distributed for educational, research, and \n
7  * not for profit purposes provided that this copyright and statement are \n
8  * included in all such copies. \n
9  * 2014 Deskull rearranged comment for Doxygen. \n
10  */
11
12 #include "floor/floor-save.h"
13 #include "action/travel-execution.h"
14 #include "cmd-building/cmd-building.h"
15 #include "cmd-io/cmd-dump.h"
16 #include "core/asking-player.h"
17 #include "dungeon/quest-monster-placer.h"
18 #include "dungeon/dungeon.h"
19 #include "dungeon/quest.h"
20 #include "floor/cave.h"
21 #include "floor/floor-events.h"
22 #include "floor/floor-generator.h"
23 #include "floor/floor-object.h"
24 #include "floor/floor.h"
25 #include "floor/geometry.h"
26 #include "floor/wild.h"
27 #include "game-option/birth-options.h"
28 #include "game-option/play-record-options.h"
29 #include "grid/feature.h"
30 #include "grid/grid.h"
31 #include "inventory/inventory-slot-types.h"
32 #include "io/files-util.h"
33 #include "io/uid-checker.h"
34 #include "io/write-diary.h"
35 #include "load/floor-loader.h"
36 #include "main/sound-of-music.h"
37 #include "mind/mind-mirror-master.h"
38 #include "mind/mind-ninja.h"
39 #include "monster-floor/monster-generator.h"
40 #include "monster-floor/monster-remover.h"
41 #include "monster-floor/monster-summon.h"
42 #include "monster-race/monster-race.h"
43 #include "monster-race/race-flags1.h"
44 #include "monster-race/race-flags2.h"
45 #include "monster-race/race-flags7.h"
46 #include "monster/monster-describer.h"
47 #include "monster/monster-description-types.h"
48 #include "monster/monster-flag-types.h"
49 #include "monster/monster-info.h"
50 #include "monster/monster-list.h"
51 #include "monster/monster-status.h"
52 #include "monster/monster-update.h"
53 #include "monster/smart-learn-types.h"
54 #include "object-hook/hook-checker.h"
55 #include "object-hook/hook-enchant.h"
56 #include "pet/pet-util.h"
57 #include "player/player-class.h"
58 #include "player/player-personalities-types.h"
59 #include "player/special-defense-types.h"
60 #include "save/floor-writer.h"
61 #include "spell-kind/spells-floor.h"
62 #include "system/artifact-type-definition.h"
63 #include "system/floor-type-definition.h"
64 #include "system/system-variables.h"
65 #include "util/angband-files.h"
66 #include "util/bit-flags-calculator.h"
67 #include "view/display-messages.h"
68 #include "window/main-window-util.h"
69 #include "world/world.h"
70
71 bool repair_monsters;
72
73 static FLOOR_IDX new_floor_id; /*!<次のフロアのID / floor_id of the destination */
74 static u32b latest_visit_mark; /*!<フロアを渡った回数?(確認中) / Max number of visit_mark */
75 #define MAX_PARTY_MON 21 /*!< フロア移動時に先のフロアに連れて行けるペットの最大数 Maximum number of preservable pets */
76 static monster_type party_mon[MAX_PARTY_MON]; /*!< フロア移動に保存するペットモンスターの配列 */
77
78 /*
79  * Number of floor_id used from birth
80  */
81 FLOOR_IDX max_floor_id;
82
83 /*
84  * Sign for current process used in temporary files.
85  * Actually it is the start time of current process.
86  */
87 u32b saved_floor_file_sign;
88
89 saved_floor_type saved_floors[MAX_SAVED_FLOORS];
90
91 /*!
92  * @brief 保存フロア配列を初期化する / Initialize saved_floors array.
93  * @param creature_ptr プレーヤーへの参照ポインタ
94  * @param force テンポラリファイルが残っていた場合も警告なしで強制的に削除するフラグ
95  * @details Make sure that old temporary files are not remaining as gurbages.
96  * @return なし
97  */
98 void init_saved_floors(player_type *creature_ptr, bool force)
99 {
100     char floor_savefile[1024];
101     int i;
102     int fd = -1;
103     BIT_FLAGS mode = 0644;
104     for (i = 0; i < MAX_SAVED_FLOORS; i++) {
105         saved_floor_type *sf_ptr = &saved_floors[i];
106
107         /* File name */
108         sprintf(floor_savefile, "%s.F%02d", savefile, i);
109
110         /* Grab permissions */
111         safe_setuid_grab(creature_ptr);
112
113         /* Try to create the file */
114         fd = fd_make(floor_savefile, mode);
115
116         /* Drop permissions */
117         safe_setuid_drop();
118
119         /* Failed! */
120         if (fd < 0) {
121             if (!force) {
122                 msg_print(_("エラー:古いテンポラリ・ファイルが残っています。", "Error: There are old temporary files."));
123                 msg_print(_("変愚蛮怒を二重に起動していないか確認してください。", "Make sure you are not running two game processes simultaneously."));
124                 msg_print(_("過去に変愚蛮怒がクラッシュした場合は一時ファイルを", "If the temporary files are garbage from an old crashed process, "));
125                 msg_print(_("強制的に削除して実行を続けられます。", "you can delete them safely."));
126                 if (!get_check(_("強制的に削除してもよろしいですか?", "Do you delete the old temporary files? ")))
127                     quit(_("実行中止", "Aborted."));
128                 force = TRUE;
129             }
130         } else {
131             /* Close the "fd" */
132             (void)fd_close(fd);
133         }
134
135         /* Grab permissions */
136         safe_setuid_grab(creature_ptr);
137
138         /* Simply kill the temporary file */
139         (void)fd_kill(floor_savefile);
140
141         /* Drop permissions */
142         safe_setuid_drop();
143
144         sf_ptr->floor_id = 0;
145     }
146
147     /* No floor_id used yet (No.0 is reserved to indicate non existance) */
148     max_floor_id = 1;
149
150     /* vist_mark is from 1 */
151     latest_visit_mark = 1;
152
153     /* A sign to mark temporary files */
154     saved_floor_file_sign = (u32b)time(NULL);
155
156     /* No next floor yet */
157     new_floor_id = 0;
158
159     /* No change floor mode yet */
160     creature_ptr->change_floor_mode = 0;
161 }
162
163 /*!
164  * @brief 保存フロア用テンポラリファイルを削除する / Kill temporary files
165  * @details Should be called just before the game quit.
166  * @param creature_ptr プレーヤーへの参照ポインタ
167  * @return なし
168  */
169 void clear_saved_floor_files(player_type *creature_ptr)
170 {
171     char floor_savefile[1024];
172     int i;
173     for (i = 0; i < MAX_SAVED_FLOORS; i++) {
174         saved_floor_type *sf_ptr = &saved_floors[i];
175
176         /* No temporary file */
177         if (!sf_ptr->floor_id)
178             continue;
179         if (sf_ptr->floor_id == creature_ptr->floor_id)
180             continue;
181
182         /* File name */
183         sprintf(floor_savefile, "%s.F%02d", savefile, i);
184
185         /* Grab permissions */
186         safe_setuid_grab(creature_ptr);
187
188         /* Simply kill the temporary file */
189         (void)fd_kill(floor_savefile);
190
191         /* Drop permissions */
192         safe_setuid_drop();
193     }
194 }
195
196 /*!
197  * @brief 保存フロアIDから参照ポインタを得る / Get a pointer for an item of the saved_floors array.
198  * @param floor_id 保存フロアID
199  * @return IDに対応する保存フロアのポインタ、ない場合はNULLを返す。
200  */
201 saved_floor_type *get_sf_ptr(FLOOR_IDX floor_id)
202 {
203     int i;
204
205     /* floor_id No.0 indicates no floor */
206     if (!floor_id)
207         return NULL;
208
209     for (i = 0; i < MAX_SAVED_FLOORS; i++) {
210         saved_floor_type *sf_ptr = &saved_floors[i];
211
212         if (sf_ptr->floor_id == floor_id)
213             return sf_ptr;
214     }
215
216     /* None found */
217     return NULL;
218 }
219
220 /*!
221  * @brief 参照ポインタ先の保存フロアを抹消する / kill a saved floor and get an empty space
222  * @param creature_ptr プレーヤーへの参照ポインタ
223  * @param sf_ptr 保存フロアの参照ポインタ
224  * @return なし
225  */
226 static void kill_saved_floor(player_type *creature_ptr, saved_floor_type *sf_ptr)
227 {
228     char floor_savefile[1024];
229     if (!sf_ptr)
230         return;
231
232     /* Already empty */
233     if (!sf_ptr->floor_id)
234         return;
235
236     if (sf_ptr->floor_id == creature_ptr->floor_id) {
237         /* Kill current floor */
238         creature_ptr->floor_id = 0;
239
240         /* Current floor doesn't have temporary file */
241     } else {
242         /* File name */
243         sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
244
245         /* Grab permissions */
246         safe_setuid_grab(creature_ptr);
247
248         /* Simply kill the temporary file */
249         (void)fd_kill(floor_savefile);
250
251         /* Drop permissions */
252         safe_setuid_drop();
253     }
254
255     /* No longer exists */
256     sf_ptr->floor_id = 0;
257 }
258
259 /*!
260  * @brief 新規に利用可能な保存フロアを返す / Initialize new saved floor and get its floor id.
261  * @param creature_ptr プレーヤーへの参照ポインタ
262  * @return 利用可能な保存フロアID
263  * @details
264  * If number of saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
265  */
266 FLOOR_IDX get_new_floor_id(player_type *creature_ptr)
267 {
268     saved_floor_type *sf_ptr = NULL;
269     FLOOR_IDX i;
270
271     /* Look for empty space */
272     for (i = 0; i < MAX_SAVED_FLOORS; i++) {
273         sf_ptr = &saved_floors[i];
274
275         if (!sf_ptr->floor_id)
276             break;
277     }
278
279     /* None found */
280     if (i == MAX_SAVED_FLOORS) {
281         s16b oldest = 0;
282         u32b oldest_visit = 0xffffffffL;
283
284         /* Search for oldest */
285         for (i = 0; i < MAX_SAVED_FLOORS; i++) {
286             sf_ptr = &saved_floors[i];
287
288             /* Don't kill current floor */
289             if (sf_ptr->floor_id == creature_ptr->floor_id)
290                 continue;
291
292             /* Don't kill newer */
293             if (sf_ptr->visit_mark > oldest_visit)
294                 continue;
295
296             oldest = i;
297             oldest_visit = sf_ptr->visit_mark;
298         }
299
300         /* Kill oldest saved floor */
301         sf_ptr = &saved_floors[oldest];
302         kill_saved_floor(creature_ptr, sf_ptr);
303
304         /* Use it */
305         i = oldest;
306     }
307
308     /* Prepare new floor data */
309     sf_ptr->savefile_id = i;
310     sf_ptr->floor_id = max_floor_id;
311     sf_ptr->last_visit = 0;
312     sf_ptr->upper_floor_id = 0;
313     sf_ptr->lower_floor_id = 0;
314     sf_ptr->visit_mark = latest_visit_mark++;
315
316     /* sf_ptr->dun_level may be changed later */
317     sf_ptr->dun_level = creature_ptr->current_floor_ptr->dun_level;
318
319     /* Increment number of floor_id */
320     if (max_floor_id < MAX_SHORT)
321         max_floor_id++;
322
323     /* 32767 floor_ids are all used up!  Re-use ancient IDs */
324     else
325         max_floor_id = 1;
326
327     return sf_ptr->floor_id;
328 }
329
330 /*!
331  * @brief フロア切り替え時の処理フラグを追加する / Prepare mode flags of changing floor
332  * @param creature_ptr プレーヤーへの参照ポインタ
333  * @param mode 追加したい所持フラグ
334  * @return なし
335  */
336 void prepare_change_floor_mode(player_type *creature_ptr, BIT_FLAGS mode) { creature_ptr->change_floor_mode |= mode; }
337
338 /*!
339  * @brief 階段移動先のフロアが生成できない時に簡単な行き止まりマップを作成する / Builds the dead end
340  * @return なし
341  */
342 static void build_dead_end(player_type *creature_ptr)
343 {
344     POSITION x, y;
345
346     clear_cave(creature_ptr);
347
348     /* Mega-Hack -- no player yet */
349     creature_ptr->x = creature_ptr->y = 0;
350
351     /* Fill the arrays of floors and walls in the good proportions */
352     set_floor_and_wall(0);
353
354     /* Smallest area */
355     creature_ptr->current_floor_ptr->height = SCREEN_HGT;
356     creature_ptr->current_floor_ptr->width = SCREEN_WID;
357
358     /* Filled with permanent walls */
359     for (y = 0; y < MAX_HGT; y++) {
360         for (x = 0; x < MAX_WID; x++) {
361             /* Create "solid" perma-wall */
362             place_bold(creature_ptr, y, x, GB_SOLID_PERM);
363         }
364     }
365
366     /* Place at center of the floor */
367     creature_ptr->y = creature_ptr->current_floor_ptr->height / 2;
368     creature_ptr->x = creature_ptr->current_floor_ptr->width / 2;
369
370     /* Give one square */
371     place_bold(creature_ptr, creature_ptr->y, creature_ptr->x, GB_FLOOR);
372
373     wipe_generate_random_floor_flags(creature_ptr->current_floor_ptr);
374 }
375
376 /*!
377  * @brief フロア移動時のペット保存処理 / Preserve_pets
378  * @param master_ptr プレーヤーへの参照ポインタ
379  * @return なし
380  */
381 static void preserve_pet(player_type *master_ptr)
382 {
383     int num;
384     MONSTER_IDX i;
385
386     for (num = 0; num < MAX_PARTY_MON; num++) {
387         party_mon[num].r_idx = 0;
388     }
389
390     if (master_ptr->riding) {
391         monster_type *m_ptr = &master_ptr->current_floor_ptr->m_list[master_ptr->riding];
392
393         /* Pet of other pet don't follow. */
394         if (m_ptr->parent_m_idx) {
395             master_ptr->riding = 0;
396             master_ptr->pet_extra_flags &= ~(PF_TWO_HANDS);
397             master_ptr->riding_ryoute = master_ptr->old_riding_ryoute = FALSE;
398         } else {
399             /* Preserve the mount */
400             (void)COPY(&party_mon[0], m_ptr, monster_type);
401
402             /* Delete from this floor */
403             delete_monster_idx(master_ptr, master_ptr->riding);
404         }
405     }
406
407     /*
408      * If player is in wild mode, no pets are preserved
409      * except a monster whom player riding
410      */
411     if (!master_ptr->wild_mode && !master_ptr->current_floor_ptr->inside_arena && !master_ptr->phase_out) {
412         for (i = master_ptr->current_floor_ptr->m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--) {
413             monster_type *m_ptr = &master_ptr->current_floor_ptr->m_list[i];
414
415             if (!monster_is_valid(m_ptr))
416                 continue;
417             if (!is_pet(m_ptr))
418                 continue;
419             if (i == master_ptr->riding)
420                 continue;
421
422             if (reinit_wilderness) {
423                 /* Don't lose sight of pets when getting a Quest */
424             } else {
425                 POSITION dis = distance(master_ptr->y, master_ptr->x, m_ptr->fy, m_ptr->fx);
426
427                 /* Confused (etc.) monsters don't follow. */
428                 if (monster_confused_remaining(m_ptr) || monster_stunned_remaining(m_ptr) || monster_csleep_remaining(m_ptr))
429                     continue;
430
431                 /* Pet of other pet don't follow. */
432                 if (m_ptr->parent_m_idx)
433                     continue;
434
435                 /*
436                  * Pets with nickname will follow even from 3 blocks away
437                  * when you or the pet can see the other.
438                  */
439                 if (m_ptr->nickname
440                     && ((player_has_los_bold(master_ptr, m_ptr->fy, m_ptr->fx) && projectable(master_ptr, master_ptr->y, master_ptr->x, m_ptr->fy, m_ptr->fx))
441                         || (los(master_ptr, m_ptr->fy, m_ptr->fx, master_ptr->y, master_ptr->x)
442                             && projectable(master_ptr, m_ptr->fy, m_ptr->fx, master_ptr->y, master_ptr->x)))) {
443                     if (dis > 3)
444                         continue;
445                 } else {
446                     if (dis > 1)
447                         continue;
448                 }
449             }
450
451             (void)COPY(&party_mon[num], &master_ptr->current_floor_ptr->m_list[i], monster_type);
452
453             num++;
454
455             /* Delete from this floor */
456             delete_monster_idx(master_ptr, i);
457         }
458     }
459
460     if (record_named_pet) {
461         for (i = master_ptr->current_floor_ptr->m_max - 1; i >= 1; i--) {
462             monster_type *m_ptr = &master_ptr->current_floor_ptr->m_list[i];
463             GAME_TEXT m_name[MAX_NLEN];
464
465             if (!monster_is_valid(m_ptr))
466                 continue;
467             if (!is_pet(m_ptr))
468                 continue;
469             if (!m_ptr->nickname)
470                 continue;
471             if (master_ptr->riding == i)
472                 continue;
473
474             monster_desc(master_ptr, m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
475             exe_write_diary(master_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_MOVED, m_name);
476         }
477     }
478
479     /* Pet of other pet may disappear. */
480     for (i = master_ptr->current_floor_ptr->m_max - 1; i >= 1; i--) {
481         monster_type *m_ptr = &master_ptr->current_floor_ptr->m_list[i];
482
483         /* Are there its parent? */
484         if (m_ptr->parent_m_idx && !master_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx) {
485             /* Its parent have gone, it also goes away. */
486
487             if (is_seen(master_ptr, m_ptr)) {
488                 GAME_TEXT m_name[MAX_NLEN];
489                 monster_desc(master_ptr, m_name, m_ptr, 0);
490                 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
491             }
492
493             delete_monster_idx(master_ptr, i);
494         }
495     }
496 }
497
498 /*!
499  * @brief フロア移動時にペットを伴った場合の準備処理 / Pre-calculate the racial counters of preserved pets
500  * @param master_ptr プレーヤーへの参照ポインタ
501  * @return なし
502  * @details
503  * To prevent multiple generation of unique monster who is the minion of player
504  */
505 void precalc_cur_num_of_pet(player_type *player_ptr)
506 {
507     monster_type *m_ptr;
508     int i;
509     int max_num = player_ptr->wild_mode ? 1 : MAX_PARTY_MON;
510
511     for (i = 0; i < max_num; i++) {
512         m_ptr = &party_mon[i];
513
514         /* Skip empty monsters */
515         if (!monster_is_valid(m_ptr))
516             continue;
517
518         /* Hack -- Increase the racial counter */
519         real_r_ptr(m_ptr)->cur_num++;
520     }
521 }
522
523 /*!
524  * @brief 移動先のフロアに伴ったペットを配置する / Place preserved pet monsters on new floor
525  * @param master_ptr プレーヤーへの参照ポインタ
526  * @return なし
527  */
528 static void place_pet(player_type *master_ptr)
529 {
530     int i;
531     int max_num = master_ptr->wild_mode ? 1 : MAX_PARTY_MON;
532     floor_type *floor_ptr = master_ptr->current_floor_ptr;
533     for (i = 0; i < max_num; i++) {
534         POSITION cy = 0, cx = 0;
535         MONSTER_IDX m_idx;
536
537         if (!(party_mon[i].r_idx))
538             continue;
539
540         if (i == 0) {
541             m_idx = m_pop(floor_ptr);
542             master_ptr->riding = m_idx;
543             if (m_idx) {
544                 cy = master_ptr->y;
545                 cx = master_ptr->x;
546             }
547         } else {
548             int j;
549             POSITION d;
550
551             for (d = 1; d < A_MAX; d++) {
552                 for (j = 1000; j > 0; j--) {
553                     scatter(master_ptr, &cy, &cx, master_ptr->y, master_ptr->x, d, 0);
554                     if (monster_can_enter(master_ptr, cy, cx, &r_info[party_mon[i].r_idx], 0))
555                         break;
556                 }
557                 if (j)
558                     break;
559             }
560             m_idx = (d == 6) ? 0 : m_pop(floor_ptr);
561         }
562
563         if (m_idx) {
564             monster_type *m_ptr = &master_ptr->current_floor_ptr->m_list[m_idx];
565             monster_race *r_ptr;
566
567             master_ptr->current_floor_ptr->grid_array[cy][cx].m_idx = m_idx;
568
569             m_ptr->r_idx = party_mon[i].r_idx;
570
571             /* Copy all member of the structure */
572             *m_ptr = party_mon[i];
573             r_ptr = real_r_ptr(m_ptr);
574
575             m_ptr->fy = cy;
576             m_ptr->fx = cx;
577             m_ptr->current_floor_ptr = master_ptr->current_floor_ptr;
578             m_ptr->ml = TRUE;
579             m_ptr->mtimed[MTIMED_CSLEEP] = 0;
580             m_ptr->hold_o_idx = 0;
581             m_ptr->target_y = 0;
582
583             if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare) {
584                 /* Monster is still being nice */
585                 m_ptr->mflag |= (MFLAG_NICE);
586
587                 /* Must repair monsters */
588                 repair_monsters = TRUE;
589             }
590             update_monster(master_ptr, m_idx, TRUE);
591             lite_spot(master_ptr, cy, cx);
592
593             /* Pre-calculated in precalc_cur_num_of_pet() */
594             /* r_ptr->cur_num++; */
595
596             /* Hack -- Count the number of "reproducers" */
597             if (r_ptr->flags2 & RF2_MULTIPLY)
598                 master_ptr->current_floor_ptr->num_repro++;
599
600         } else {
601             monster_type *m_ptr = &party_mon[i];
602             monster_race *r_ptr = real_r_ptr(m_ptr);
603             GAME_TEXT m_name[MAX_NLEN];
604
605             monster_desc(master_ptr, m_name, m_ptr, 0);
606             msg_format(_("%sとはぐれてしまった。", "You have lost sight of %s."), m_name);
607             if (record_named_pet && m_ptr->nickname) {
608                 monster_desc(master_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
609                 exe_write_diary(master_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOST_SIGHT, m_name);
610             }
611
612             /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
613             if (r_ptr->cur_num)
614                 r_ptr->cur_num--;
615         }
616     }
617
618     /* For accuracy of precalc_cur_num_of_pet() */
619     (void)C_WIPE(party_mon, MAX_PARTY_MON, monster_type);
620 }
621
622 /*!
623  * @brief ユニークモンスターやアーティファクトの所在フロアを更新する / Hack -- Update location of unique monsters and artifacts
624  * @param cur_floor_id 現在のフロアID
625  * @return なし
626  * @details
627  * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly\n
628  * while new floor creation since dungeons may be re-created by\n
629  * auto-scum option.\n
630  */
631 static void update_unique_artifact(floor_type *floor_ptr, s16b cur_floor_id)
632 {
633     int i;
634
635     /* Maintain unique monsters */
636     for (i = 1; i < floor_ptr->m_max; i++) {
637         monster_race *r_ptr;
638         monster_type *m_ptr = &floor_ptr->m_list[i];
639
640         if (!monster_is_valid(m_ptr))
641             continue;
642
643         /* Extract real monster race */
644         r_ptr = real_r_ptr(m_ptr);
645
646         /* Memorize location of the unique monster */
647         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) {
648             r_ptr->floor_id = cur_floor_id;
649         }
650     }
651
652     /* Maintain artifatcs */
653     for (i = 1; i < floor_ptr->o_max; i++) {
654         object_type *o_ptr = &floor_ptr->o_list[i];
655
656         if (!object_is_valid(o_ptr))
657             continue;
658
659         /* Memorize location of the artifact */
660         if (object_is_fixed_artifact(o_ptr)) {
661             a_info[o_ptr->name1].floor_id = cur_floor_id;
662         }
663     }
664 }
665
666 /*!
667  * @brief フロア移動時、プレイヤーの移動先モンスターが既にいた場合ランダムな近隣に移動させる / When a monster is at a place where player will return,
668  * @return なし
669  */
670 static void get_out_monster(player_type *protected_ptr)
671 {
672     int tries = 0;
673     POSITION dis = 1;
674     POSITION oy = protected_ptr->y;
675     POSITION ox = protected_ptr->x;
676     floor_type *floor_ptr = protected_ptr->current_floor_ptr;
677     MONSTER_IDX m_idx = floor_ptr->grid_array[oy][ox].m_idx;
678
679     /* Nothing to do if no monster */
680     if (!m_idx)
681         return;
682
683     /* Look until done */
684     while (TRUE) {
685         monster_type *m_ptr;
686
687         /* Pick a (possibly illegal) location */
688         POSITION ny = rand_spread(oy, dis);
689         POSITION nx = rand_spread(ox, dis);
690
691         tries++;
692
693         /* Stop after 1000 tries */
694         if (tries > 10000)
695             return;
696
697         /*
698          * Increase distance after doing enough tries
699          * compared to area of possible space
700          */
701         if (tries > 20 * dis * dis)
702             dis++;
703
704         /* Ignore illegal locations */
705         if (!in_bounds(floor_ptr, ny, nx))
706             continue;
707
708         /* Require "empty" floor space */
709         if (!is_cave_empty_bold(protected_ptr, ny, nx))
710             continue;
711
712         /* Hack -- no teleport onto glyph of warding */
713         if (is_glyph_grid(&floor_ptr->grid_array[ny][nx]))
714             continue;
715         if (is_explosive_rune_grid(&floor_ptr->grid_array[ny][nx]))
716             continue;
717
718         /* ...nor onto the Pattern */
719         if (pattern_tile(floor_ptr, ny, nx))
720             continue;
721
722         /*** It's a good place ***/
723
724         m_ptr = &floor_ptr->m_list[m_idx];
725
726         /* Update the old location */
727         floor_ptr->grid_array[oy][ox].m_idx = 0;
728
729         /* Update the new location */
730         floor_ptr->grid_array[ny][nx].m_idx = m_idx;
731
732         /* Move the monster */
733         m_ptr->fy = ny;
734         m_ptr->fx = nx;
735
736         /* No need to do update_monster() */
737
738         /* Success */
739         return;
740     }
741 }
742
743 /*!
744  * @brief 新フロアに移動元フロアに繋がる階段を配置する / Virtually teleport onto the stairs that is connecting between two floors.
745  * @param sf_ptr 移動元の保存フロア構造体参照ポインタ
746  * @return なし
747  */
748 static void locate_connected_stairs(player_type *creature_ptr, floor_type *floor_ptr, saved_floor_type *sf_ptr, BIT_FLAGS floor_mode)
749 {
750     POSITION x, y, sx = 0, sy = 0;
751     POSITION x_table[20];
752     POSITION y_table[20];
753     int num = 0;
754     int i;
755
756     /* Search usable stairs */
757     for (y = 0; y < floor_ptr->height; y++) {
758         for (x = 0; x < floor_ptr->width; x++) {
759             grid_type *g_ptr = &floor_ptr->grid_array[y][x];
760             feature_type *f_ptr = &f_info[g_ptr->feat];
761             bool ok = FALSE;
762
763             if (floor_mode & CFM_UP) {
764                 if (have_flag(f_ptr->flags, FF_LESS) && have_flag(f_ptr->flags, FF_STAIRS) && !have_flag(f_ptr->flags, FF_SPECIAL)) {
765                     ok = TRUE;
766
767                     /* Found fixed stairs? */
768                     if (g_ptr->special && g_ptr->special == sf_ptr->upper_floor_id) {
769                         sx = x;
770                         sy = y;
771                     }
772                 }
773             }
774
775             else if (floor_mode & CFM_DOWN) {
776                 if (have_flag(f_ptr->flags, FF_MORE) && have_flag(f_ptr->flags, FF_STAIRS) && !have_flag(f_ptr->flags, FF_SPECIAL)) {
777                     ok = TRUE;
778
779                     /* Found fixed stairs */
780                     if (g_ptr->special && g_ptr->special == sf_ptr->lower_floor_id) {
781                         sx = x;
782                         sy = y;
783                     }
784                 }
785             }
786
787             else {
788                 if (have_flag(f_ptr->flags, FF_BLDG)) {
789                     ok = TRUE;
790                 }
791             }
792
793             if (ok && (num < 20)) {
794                 x_table[num] = x;
795                 y_table[num] = y;
796                 num++;
797             }
798         }
799     }
800
801     if (sx) {
802         /* Already fixed */
803         creature_ptr->y = sy;
804         creature_ptr->x = sx;
805     } else if (!num) {
806         /* No stairs found! -- No return */
807         prepare_change_floor_mode(creature_ptr, CFM_RAND_PLACE | CFM_NO_RETURN);
808
809         /* Mega Hack -- It's not the stairs you enter.  Disable it.  */
810         if (!feat_uses_special(floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].feat))
811             floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].special = 0;
812     } else {
813         /* Choose random one */
814         i = randint0(num);
815
816         /* Point stair location */
817         creature_ptr->y = y_table[i];
818         creature_ptr->x = x_table[i];
819     }
820 }
821
822 /*!
823  * @brief 現在のフロアを離れるに伴って行なわれる保存処理
824  * / Maintain quest monsters, mark next floor_id at stairs, save current floor, and prepare to enter next floor.
825  * @param creature_ptr プレーヤーへの参照ポインタ
826  * @return なし
827  */
828 void leave_floor(player_type *creature_ptr)
829 {
830     grid_type *g_ptr = NULL;
831     feature_type *f_ptr;
832     saved_floor_type *sf_ptr;
833     MONRACE_IDX quest_r_idx = 0;
834     DUNGEON_IDX i;
835     FLOOR_IDX tmp_floor_idx = 0;
836
837     /* Preserve pets and prepare to take these to next floor */
838     preserve_pet(creature_ptr);
839
840     /* Remove all mirrors without explosion */
841     remove_all_mirrors(creature_ptr, FALSE);
842
843     if (creature_ptr->special_defense & NINJA_S_STEALTH)
844         set_superstealth(creature_ptr, FALSE);
845
846     /* New floor is not yet prepared */
847     new_floor_id = 0;
848
849     /* Temporarily get a floor_id (for Arena) */
850     if (!creature_ptr->floor_id && (creature_ptr->change_floor_mode & CFM_SAVE_FLOORS) && !(creature_ptr->change_floor_mode & CFM_NO_RETURN)) {
851         /* Get temporary floor_id */
852         tmp_floor_idx = get_new_floor_id(creature_ptr);
853     }
854
855     /* Search the quest monster index */
856     for (i = 0; i < max_q_idx; i++) {
857         if ((quest[i].status == QUEST_STATUS_TAKEN) && ((quest[i].type == QUEST_TYPE_KILL_LEVEL) || (quest[i].type == QUEST_TYPE_RANDOM))
858             && (quest[i].level == creature_ptr->current_floor_ptr->dun_level) && (creature_ptr->dungeon_idx == quest[i].dungeon)
859             && !(quest[i].flags & QUEST_FLAG_PRESET)) {
860             quest_r_idx = quest[i].r_idx;
861         }
862     }
863
864     /* Maintain quest monsters */
865     for (i = 1; i < creature_ptr->current_floor_ptr->m_max; i++) {
866         monster_race *r_ptr;
867         monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
868
869         if (!monster_is_valid(m_ptr))
870             continue;
871
872         /* Only maintain quest monsters */
873         if (quest_r_idx != m_ptr->r_idx)
874             continue;
875
876         /* Extract real monster race */
877         r_ptr = real_r_ptr(m_ptr);
878
879         /* Ignore unique monsters */
880         if ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL))
881             continue;
882
883         /* Delete non-unique quest monsters */
884         delete_monster_idx(creature_ptr, i);
885     }
886
887     /* Check if there is a same item */
888     for (i = 0; i < INVEN_PACK; i++) {
889         object_type *o_ptr = &creature_ptr->inventory_list[i];
890
891         if (!object_is_valid(o_ptr))
892             continue;
893
894         /* Delete old memorized location of the artifact */
895         if (object_is_fixed_artifact(o_ptr)) {
896             a_info[o_ptr->name1].floor_id = 0;
897         }
898     }
899
900     /* Extract current floor info or NULL */
901     sf_ptr = get_sf_ptr(creature_ptr->floor_id);
902
903     /* Choose random stairs */
904     if ((creature_ptr->change_floor_mode & CFM_RAND_CONNECT) && tmp_floor_idx) {
905         locate_connected_stairs(creature_ptr, creature_ptr->current_floor_ptr, sf_ptr, creature_ptr->change_floor_mode);
906     }
907
908     /* Extract new dungeon level */
909     if (creature_ptr->change_floor_mode & CFM_SAVE_FLOORS) {
910         /* Extract stair position */
911         g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
912         f_ptr = &f_info[g_ptr->feat];
913
914         /* Get back to old saved floor? */
915         if (g_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(g_ptr->special)) {
916             /* Saved floor is exist.  Use it. */
917             new_floor_id = g_ptr->special;
918         }
919
920         /* Mark shaft up/down */
921         if (have_flag(f_ptr->flags, FF_STAIRS) && have_flag(f_ptr->flags, FF_SHAFT)) {
922             prepare_change_floor_mode(creature_ptr, CFM_SHAFT);
923         }
924     }
925
926     /* Climb up/down some sort of stairs */
927     if (creature_ptr->change_floor_mode & (CFM_DOWN | CFM_UP)) {
928         int move_num = 0;
929
930         /* Extract level movement number */
931         if (creature_ptr->change_floor_mode & CFM_DOWN)
932             move_num = 1;
933         else if (creature_ptr->change_floor_mode & CFM_UP)
934             move_num = -1;
935
936         /* Shafts are deeper than normal stairs */
937         if (creature_ptr->change_floor_mode & CFM_SHAFT)
938             move_num += SGN(move_num);
939
940         /* Get out from or Enter the dungeon */
941         if (creature_ptr->change_floor_mode & CFM_DOWN) {
942             if (!creature_ptr->current_floor_ptr->dun_level)
943                 move_num = d_info[creature_ptr->dungeon_idx].mindepth;
944         } else if (creature_ptr->change_floor_mode & CFM_UP) {
945             if (creature_ptr->current_floor_ptr->dun_level + move_num < d_info[creature_ptr->dungeon_idx].mindepth)
946                 move_num = -creature_ptr->current_floor_ptr->dun_level;
947         }
948
949         creature_ptr->current_floor_ptr->dun_level += move_num;
950     }
951
952     /* Leaving the dungeon to town */
953     if (!creature_ptr->current_floor_ptr->dun_level && creature_ptr->dungeon_idx) {
954         creature_ptr->leaving_dungeon = TRUE;
955         if (!vanilla_town && !lite_town) {
956             creature_ptr->wilderness_y = d_info[creature_ptr->dungeon_idx].dy;
957             creature_ptr->wilderness_x = d_info[creature_ptr->dungeon_idx].dx;
958         }
959         creature_ptr->recall_dungeon = creature_ptr->dungeon_idx;
960         creature_ptr->dungeon_idx = 0;
961
962         /* Reach to the surface -- Clear all saved floors */
963         creature_ptr->change_floor_mode &= ~CFM_SAVE_FLOORS; // TODO
964     }
965
966     /* Kill some old saved floors */
967     if (!(creature_ptr->change_floor_mode & CFM_SAVE_FLOORS)) {
968         /* Kill all saved floors */
969         for (i = 0; i < MAX_SAVED_FLOORS; i++)
970             kill_saved_floor(creature_ptr, &saved_floors[i]);
971
972         /* Reset visit_mark count */
973         latest_visit_mark = 1;
974     } else if (creature_ptr->change_floor_mode & CFM_NO_RETURN) {
975         /* Kill current floor */
976         kill_saved_floor(creature_ptr, sf_ptr);
977     }
978
979     /* No current floor -- Left/Enter dungeon etc... */
980     if (!creature_ptr->floor_id) {
981         /* No longer need to save current floor */
982         return;
983     }
984
985     /* Mark next floor_id on the previous floor */
986     if (!new_floor_id) {
987         /* Get new id */
988         new_floor_id = get_new_floor_id(creature_ptr);
989
990         /* Connect from here */
991         if (g_ptr && !feat_uses_special(g_ptr->feat)) {
992             g_ptr->special = new_floor_id;
993         }
994     }
995
996     /* Fix connection -- level teleportation or trap door */
997     if (creature_ptr->change_floor_mode & CFM_RAND_CONNECT) {
998         if (creature_ptr->change_floor_mode & CFM_UP)
999             sf_ptr->upper_floor_id = new_floor_id;
1000         else if (creature_ptr->change_floor_mode & CFM_DOWN)
1001             sf_ptr->lower_floor_id = new_floor_id;
1002     }
1003
1004     /* If you can return, you need to save previous floor */
1005     if ((creature_ptr->change_floor_mode & CFM_SAVE_FLOORS) && !(creature_ptr->change_floor_mode & CFM_NO_RETURN)) {
1006         /* Get out of the my way! */
1007         get_out_monster(creature_ptr);
1008
1009         /* Record the last visit turn of current floor */
1010         sf_ptr->last_visit = current_world_ptr->game_turn;
1011
1012         forget_lite(creature_ptr->current_floor_ptr);
1013         forget_view(creature_ptr->current_floor_ptr);
1014         clear_mon_lite(creature_ptr->current_floor_ptr);
1015
1016         /* Save current floor */
1017         if (!save_floor(creature_ptr, sf_ptr, 0)) {
1018             /* Save failed -- No return */
1019             prepare_change_floor_mode(creature_ptr, CFM_NO_RETURN);
1020
1021             /* Kill current floor */
1022             kill_saved_floor(creature_ptr, get_sf_ptr(creature_ptr->floor_id));
1023         }
1024     }
1025 }
1026
1027 /*!
1028  * @brief フロアの切り替え処理 / Enter new floor.
1029  * @param creature_ptr プレーヤーへの参照ポインタ
1030  * @return なし
1031  * @details
1032  * If the floor is an old saved floor, it will be\n
1033  * restored from the temporary file.  If the floor is new one, new floor\n
1034  * will be generated.\n
1035  */
1036 void change_floor(player_type *creature_ptr)
1037 {
1038     saved_floor_type *sf_ptr;
1039     bool loaded = FALSE;
1040
1041     /* The dungeon is not ready */
1042     current_world_ptr->character_dungeon = FALSE;
1043
1044     /* No longer in the trap detecteded region */
1045     creature_ptr->dtrap = FALSE;
1046
1047     /* Mega-Hack -- no panel yet */
1048     panel_row_min = 0;
1049     panel_row_max = 0;
1050     panel_col_min = 0;
1051     panel_col_max = 0;
1052
1053     /* Mega-Hack -- not ambushed on the wildness? */
1054     creature_ptr->ambush_flag = FALSE;
1055
1056     /* No saved floors (On the surface etc.) */
1057     if (!(creature_ptr->change_floor_mode & CFM_SAVE_FLOORS) && !(creature_ptr->change_floor_mode & CFM_FIRST_FLOOR)) {
1058         generate_floor(creature_ptr);
1059
1060         /* Paranoia -- No new saved floor */
1061         new_floor_id = 0;
1062     }
1063
1064     /* In the dungeon */
1065     else {
1066         /* No floor_id yet */
1067         if (!new_floor_id) {
1068             /* Get new id */
1069             new_floor_id = get_new_floor_id(creature_ptr);
1070         }
1071
1072         /* Pointer for infomations of new floor */
1073         sf_ptr = get_sf_ptr(new_floor_id);
1074
1075         /* Try to restore old floor */
1076         if (sf_ptr->last_visit) {
1077             /* Old saved floor is exist */
1078             if (load_floor(creature_ptr, sf_ptr, 0)) {
1079                 loaded = TRUE;
1080
1081                 /* Forbid return stairs */
1082                 if (creature_ptr->change_floor_mode & CFM_NO_RETURN) {
1083                     grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
1084
1085                     if (!feat_uses_special(g_ptr->feat)) {
1086                         if (creature_ptr->change_floor_mode & (CFM_DOWN | CFM_UP)) {
1087                             /* Reset to floor */
1088                             g_ptr->feat = feat_ground_type[randint0(100)];
1089                         }
1090
1091                         g_ptr->special = 0;
1092                     }
1093                 }
1094             }
1095         }
1096
1097         /*
1098          * Set lower/upper_floor_id of new floor when the new
1099          * floor is right-above/right-under the current floor.
1100          *
1101          * Stair creation/Teleport level/Trap door will take
1102          * you the same floor when you used it later again.
1103          */
1104         if (creature_ptr->floor_id) {
1105             saved_floor_type *cur_sf_ptr = get_sf_ptr(creature_ptr->floor_id);
1106
1107             if (creature_ptr->change_floor_mode & CFM_UP) {
1108                 /* New floor is right-above */
1109                 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1110                     sf_ptr->lower_floor_id = creature_ptr->floor_id;
1111             } else if (creature_ptr->change_floor_mode & CFM_DOWN) {
1112                 /* New floor is right-under */
1113                 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1114                     sf_ptr->upper_floor_id = creature_ptr->floor_id;
1115             }
1116         }
1117
1118         /* Break connection to killed floor */
1119         else {
1120             if (creature_ptr->change_floor_mode & CFM_UP)
1121                 sf_ptr->lower_floor_id = 0;
1122             else if (creature_ptr->change_floor_mode & CFM_DOWN)
1123                 sf_ptr->upper_floor_id = 0;
1124         }
1125
1126         /* Maintain monsters and artifacts */
1127         if (loaded) {
1128             MONSTER_IDX i;
1129             GAME_TURN tmp_last_visit = sf_ptr->last_visit;
1130             GAME_TURN absence_ticks;
1131             int alloc_chance = d_info[creature_ptr->dungeon_idx].max_m_alloc_chance;
1132             GAME_TURN alloc_times;
1133
1134             while (tmp_last_visit > current_world_ptr->game_turn)
1135                 tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
1136             absence_ticks = (current_world_ptr->game_turn - tmp_last_visit) / TURNS_PER_TICK;
1137
1138             /* Maintain monsters */
1139             for (i = 1; i < creature_ptr->current_floor_ptr->m_max; i++) {
1140                 monster_race *r_ptr;
1141                 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1142
1143                 if (!monster_is_valid(m_ptr))
1144                     continue;
1145
1146                 if (!is_pet(m_ptr)) {
1147                     /* Restore HP */
1148                     m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1149
1150                     /* Remove timed status (except MTIMED_CSLEEP) */
1151                     (void)set_monster_fast(creature_ptr, i, 0);
1152                     (void)set_monster_slow(creature_ptr, i, 0);
1153                     (void)set_monster_stunned(creature_ptr, i, 0);
1154                     (void)set_monster_confused(creature_ptr, i, 0);
1155                     (void)set_monster_monfear(creature_ptr, i, 0);
1156                     (void)set_monster_invulner(creature_ptr, i, 0, FALSE);
1157                 }
1158
1159                 /* Extract real monster race */
1160                 r_ptr = real_r_ptr(m_ptr);
1161
1162                 /* Ignore non-unique */
1163                 if (!(r_ptr->flags1 & RF1_UNIQUE) && !(r_ptr->flags7 & RF7_NAZGUL))
1164                     continue;
1165
1166                 /* Appear at a different floor? */
1167                 if (r_ptr->floor_id != new_floor_id) {
1168                     /* Disapper from here */
1169                     delete_monster_idx(creature_ptr, i);
1170                 }
1171             }
1172
1173             /* Maintain artifatcs */
1174             for (i = 1; i < creature_ptr->current_floor_ptr->o_max; i++) {
1175                 object_type *o_ptr = &creature_ptr->current_floor_ptr->o_list[i];
1176
1177                 if (!object_is_valid(o_ptr))
1178                     continue;
1179
1180                 /* Ignore non-artifact */
1181                 if (!object_is_fixed_artifact(o_ptr))
1182                     continue;
1183
1184                 /* Appear at a different floor? */
1185                 if (a_info[o_ptr->name1].floor_id != new_floor_id) {
1186                     /* Disappear from here */
1187                     delete_object_idx(creature_ptr, i);
1188                 } else {
1189                     /* Cancel preserve */
1190                     a_info[o_ptr->name1].cur_num = 1;
1191                 }
1192             }
1193
1194             (void)place_quest_monsters(creature_ptr);
1195
1196             /* Place some random monsters */
1197             alloc_times = absence_ticks / alloc_chance;
1198
1199             if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1200                 alloc_times++;
1201
1202             for (i = 0; i < alloc_times; i++) {
1203                 /* Make a (group of) new monster */
1204                 (void)alloc_monster(creature_ptr, 0, 0, summon_specific);
1205             }
1206
1207         }
1208
1209         /* New floor_id or failed to restore */
1210         else /* if (!loaded) */
1211         {
1212             if (sf_ptr->last_visit) {
1213                 /* Temporary file is broken? */
1214                 msg_print(_("階段は行き止まりだった。", "The staircases come to a dead end..."));
1215
1216                 /* Create simple dead end */
1217                 build_dead_end(creature_ptr);
1218
1219                 /* Break connection */
1220                 if (creature_ptr->change_floor_mode & CFM_UP) {
1221                     sf_ptr->upper_floor_id = 0;
1222                 } else if (creature_ptr->change_floor_mode & CFM_DOWN) {
1223                     sf_ptr->lower_floor_id = 0;
1224                 }
1225             } else {
1226                 generate_floor(creature_ptr);
1227             }
1228
1229             /* Record last visit turn */
1230             sf_ptr->last_visit = current_world_ptr->game_turn;
1231
1232             /* Set correct dun_level value */
1233             sf_ptr->dun_level = creature_ptr->current_floor_ptr->dun_level;
1234
1235             /* Create connected stairs */
1236             if (!(creature_ptr->change_floor_mode & CFM_NO_RETURN)) {
1237                 /* Extract stair position */
1238                 grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
1239
1240                 /*** Create connected stairs ***/
1241
1242                 /* No stairs down from Quest */
1243                 if ((creature_ptr->change_floor_mode & CFM_UP) && !quest_number(creature_ptr, creature_ptr->current_floor_ptr->dun_level)) {
1244                     g_ptr->feat = (creature_ptr->change_floor_mode & CFM_SHAFT) ? feat_state(creature_ptr, feat_down_stair, FF_SHAFT) : feat_down_stair;
1245                 }
1246
1247                 /* No stairs up when ironman_downward */
1248                 else if ((creature_ptr->change_floor_mode & CFM_DOWN) && !ironman_downward) {
1249                     g_ptr->feat = (creature_ptr->change_floor_mode & CFM_SHAFT) ? feat_state(creature_ptr, feat_up_stair, FF_SHAFT) : feat_up_stair;
1250                 }
1251
1252                 /* Paranoia -- Clear mimic */
1253                 g_ptr->mimic = 0;
1254
1255                 /* Connect to previous floor */
1256                 g_ptr->special = creature_ptr->floor_id;
1257             }
1258         }
1259
1260         /* Arrive at random grid */
1261         if (creature_ptr->change_floor_mode & (CFM_RAND_PLACE)) {
1262             (void)new_player_spot(creature_ptr);
1263         }
1264
1265         /* You see stairs blocked */
1266         else if ((creature_ptr->change_floor_mode & CFM_NO_RETURN) && (creature_ptr->change_floor_mode & (CFM_DOWN | CFM_UP))) {
1267             if (!creature_ptr->blind) {
1268                 msg_print(_("突然階段が塞がれてしまった。", "Suddenly the stairs is blocked!"));
1269             } else {
1270                 msg_print(_("ゴトゴトと何か音がした。", "You hear some noises."));
1271             }
1272         }
1273
1274         /*
1275          * Update visit mark
1276          *
1277          * The "turn" is not always different number because
1278          * the level teleport doesn't take any turn.  Use
1279          * visit mark instead of last visit turn to find the
1280          * oldest saved floor.
1281          */
1282         sf_ptr->visit_mark = latest_visit_mark++;
1283     }
1284
1285     /* Place preserved pet monsters */
1286     place_pet(creature_ptr);
1287
1288     /* Reset travel target place */
1289     forget_travel_flow(creature_ptr->current_floor_ptr);
1290
1291     /* Hack -- maintain unique and artifacts */
1292     update_unique_artifact(creature_ptr->current_floor_ptr, new_floor_id);
1293
1294     /* Now the player is in new floor */
1295     creature_ptr->floor_id = new_floor_id;
1296
1297     /* The dungeon is ready */
1298     current_world_ptr->character_dungeon = TRUE;
1299
1300     /* Hack -- Munchkin characters always get whole map */
1301     if (creature_ptr->pseikaku == PERSONALITY_MUNCHKIN)
1302         wiz_lite(creature_ptr, (bool)(creature_ptr->pclass == CLASS_NINJA));
1303
1304     /* Remember when this level was "created" */
1305     creature_ptr->current_floor_ptr->generated_turn = current_world_ptr->game_turn;
1306
1307     /* No dungeon feeling yet */
1308     creature_ptr->feeling_turn = creature_ptr->current_floor_ptr->generated_turn;
1309     creature_ptr->feeling = 0;
1310
1311     /* Clear all flags */
1312     creature_ptr->change_floor_mode = 0L;
1313
1314     select_floor_music(creature_ptr);
1315     creature_ptr->change_floor_mode = 0;
1316 }