OSDN Git Service

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