OSDN Git Service

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