OSDN Git Service

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