OSDN Git Service

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