OSDN Git Service

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