OSDN Git Service

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