OSDN Git Service

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