OSDN Git Service

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