3 /* Purpose: management of the saved floor */
6 * Copyright (c) 2002 Mogami
8 * This software may be copied and distributed for educational, research, and
9 * not for profit purposes provided that this copyright and statement are
10 * included in all such copies.
17 static s16b new_floor_id; /* floor_id of the destination */
18 static u32b change_floor_mode; /* Mode flags for changing floor */
19 static u32b latest_visit_mark; /* Max number of visit_mark */
23 * Initialize saved_floors array. Make sure that old temporal files
24 * are not remaining as gurbages.
26 void init_saved_floors(void)
28 char floor_savefile[1024];
36 /* Get "games" permissions */
41 for (i = 0; i < MAX_SAVED_FLOORS; i++)
43 saved_floor_type *sf_ptr = &saved_floors[i];
46 sprintf(floor_savefile, "%s.F%02d", savefile, i);
48 /* Try to create the file */
49 fd = fd_make(floor_savefile, mode);
57 msg_print("¥¨¥é¡¼¡§¸Å¤¤¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£");
58 msg_print("ÊѶòÈÚÅܤòÆó½Å¤Ëµ¯Æ°¤·¤Æ¤¤¤Ê¤¤¤«³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£");
59 msg_print("²áµî¤ËÊѶòÈÚÅܤ¬¥¯¥é¥Ã¥·¥å¤·¤¿¾ì¹ç¤Ï°ì»þ¥Õ¥¡¥¤¥ë¤ò");
60 msg_print("¶¯À©Åª¤Ëºï½ü¤·¤Æ¼Â¹Ô¤ò³¤±¤é¤ì¤Þ¤¹¡£");
61 if (!get_check("¶¯À©Åª¤Ëºï½ü¤·¤Æ¤â¤è¤í¤·¤¤¤Ç¤¹¤«¡©")) quit("¼Â¹ÔÃæ»ß");
63 msg_print("Error: There are old temporal files.");
64 msg_print("Make sure you are not running two game processes simultaneously.");
65 msg_print("If the temporal files are garbages of old crashed process, ");
66 msg_print("you can delete it safely.");
67 if (!get_check("Do you delete old temporal files? ")) quit("Aborted.");
78 /* Simply kill the temporal file */
79 (void)fd_kill(floor_savefile);
84 /* No floor_id used yet (No.0 is reserved to indicate non existance) */
87 /* vist_mark is from 1 */
88 latest_visit_mark = 1;
90 /* A sign to mark temporal files */
91 saved_floor_file_sign = time(NULL);
93 /* No next floor yet */
96 /* No change floor mode yet */
97 change_floor_mode = 0;
101 /* Drop "games" permissions */
109 * Kill temporal files
110 * Should be called just before the game quit
111 * and before new game discarding saved game.
113 void clear_saved_floor_files(void)
115 char floor_savefile[1024];
123 /* Get "games" permissions */
128 for (i = 0; i < MAX_SAVED_FLOORS; i++)
130 saved_floor_type *sf_ptr = &saved_floors[i];
132 /* No temporal file */
133 if (!sf_ptr->floor_id) continue;
134 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
137 sprintf(floor_savefile, "%s.F%02d", savefile, i);
139 /* Simply kill the temporal file */
140 (void)fd_kill(floor_savefile);
145 /* Drop "games" permissions */
153 * Get a pointer for an item of the saved_floors array.
155 saved_floor_type *get_sf_ptr(s16b floor_id)
159 /* floor_id No.0 indicates no floor */
160 if (!floor_id) return NULL;
162 for (i = 0; i < MAX_SAVED_FLOORS; i++)
164 saved_floor_type *sf_ptr = &saved_floors[i];
166 if (sf_ptr->floor_id == floor_id) return sf_ptr;
175 * kill a saved floor and get an empty space
177 static void kill_saved_floor(saved_floor_type *sf_ptr)
179 char floor_savefile[1024];
182 if (!sf_ptr->floor_id) return;
184 if (sf_ptr->floor_id == p_ptr->floor_id)
186 /* Kill current floor */
189 /* Current floor doesn't have temporal file */
194 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
196 /* Simply kill the temporal file */
197 (void)fd_kill(floor_savefile);
200 /* No longer exists */
201 sf_ptr->floor_id = 0;
206 * Initialize new saved floor and get its floor id. If number of
207 * saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
209 s16b get_new_floor_id(void)
211 saved_floor_type *sf_ptr;
214 /* Look for empty space */
215 for (i = 0; i < MAX_SAVED_FLOORS; i++)
217 sf_ptr = &saved_floors[i];
219 if (!sf_ptr->floor_id) break;
223 if (i == MAX_SAVED_FLOORS)
226 u32b oldest_visit = 0xffffffffL;
228 /* Search for oldest */
229 for (i = 0; i < MAX_SAVED_FLOORS; i++)
231 sf_ptr = &saved_floors[i];
233 /* Don't kill current floor */
234 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
236 /* Don't kill newer */
237 if (sf_ptr->visit_mark > oldest_visit) continue;
240 oldest_visit = sf_ptr->visit_mark;
243 /* Kill oldest saved floor */
244 sf_ptr = &saved_floors[oldest];
245 kill_saved_floor(sf_ptr);
251 /* Prepare new floor data */
252 sf_ptr->savefile_id = i;
253 sf_ptr->floor_id = max_floor_id;
254 sf_ptr->last_visit = 0;
255 sf_ptr->upper_floor_id = 0;
256 sf_ptr->lower_floor_id = 0;
257 sf_ptr->visit_mark = latest_visit_mark++;
259 /* sf_ptr->dun_level is not yet decided */
262 /* Increment number of floor_id */
263 if (max_floor_id < MAX_SHORT) max_floor_id++;
265 /* 32767 floor_ids are all used up! Re-use ancient IDs */
266 else max_floor_id = 1;
268 return sf_ptr->floor_id;
273 * Prepare mode flags of changing floor
275 void prepare_change_floor_mode(u32b mode)
277 change_floor_mode |= mode;
282 * Builds the dead end
284 static void build_dead_end(void)
288 /* Clear and empty the cave */
292 cur_hgt = SCREEN_HGT;
293 cur_wid = SCREEN_WID;
295 /* Filled with permanent walls */
296 for (y = 0; y < MAX_HGT; y++)
298 for (x = 0; x < MAX_WID; x++)
300 /* Create "solid" perma-wall */
301 cave[y][x].feat = FEAT_PERM_SOLID;
305 /* Place at center of the floor */
309 /* Give one square */
310 place_floor_bold(py, px);
317 static void preserve_pet(void)
321 for(num = 0; num < 21; num++)
323 party_mon[num].r_idx = 0;
328 COPY(&party_mon[0], &m_list[p_ptr->riding], monster_type);
330 /* Delete from this floor */
331 delete_monster_idx(p_ptr->riding);
334 for(i = m_max - 1, num = 1; (i >= 1 && num < 21); i--)
336 monster_type *m_ptr = &m_list[i];
338 if (!m_ptr->r_idx) continue;
339 if (!is_pet(m_ptr)) continue;
340 if (i == p_ptr->riding) continue;
342 if (reinit_wilderness)
344 /* Don't lose sight of pets when getting a Quest */
348 int dis = distance(py, px, m_ptr->fy, m_ptr->fx);
351 * Pets with nickname will follow even from 3 blocks away
352 * when you or the pet can see the other.
354 if (m_ptr->nickname &&
355 (player_has_los_bold(m_ptr->fy, m_ptr->fx) ||
356 los(m_ptr->fy, m_ptr->fx, py, px)))
358 if (dis > 3) continue;
362 if (dis > 1) continue;
364 if (m_ptr->confused || m_ptr->stunned || m_ptr->csleep) continue;
367 COPY(&party_mon[num], &m_list[i], monster_type);
370 /* Delete from this floor */
371 delete_monster_idx(i);
374 if (record_named_pet)
376 for (i = m_max - 1; i >=1; i--)
378 monster_type *m_ptr = &m_list[i];
381 if (!m_ptr->r_idx) continue;
382 if (!is_pet(m_ptr)) continue;
383 if (!m_ptr->nickname) continue;
384 if (p_ptr->riding == i) continue;
386 monster_desc(m_name, m_ptr, 0x88);
387 do_cmd_write_nikki(NIKKI_NAMED_PET, 4, m_name);
394 * Place preserved pet monsters on new floor
396 static void place_pet(void)
400 if (p_ptr->wild_mode)
405 for (i = 0; i < max_num; i++)
409 if (!(party_mon[i].r_idx)) continue;
415 p_ptr->riding = m_idx;
426 for(d = 1; d < 6; d++)
428 for(j = 1000; j > 0; j--)
430 scatter(&cy, &cx, py, px, d, 0);
431 if ((cave_floor_bold(cy, cx) || (cave[cy][cx].feat == FEAT_TREES)) && !cave[cy][cx].m_idx && !((cy == py) && (cx == px))) break;
435 if (d == 6 || p_ptr->inside_arena || p_ptr->inside_battle)
443 monster_type *m_ptr = &m_list[m_idx];
446 cave[cy][cx].m_idx = m_idx;
448 m_ptr->r_idx = party_mon[i].r_idx;
449 r_ptr = real_r_ptr(m_ptr);
451 /* Copy all member of the structure */
452 *m_ptr = party_mon[i];
460 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
462 /* Monster is still being nice */
463 m_ptr->mflag |= (MFLAG_NICE);
465 /* Must repair monsters */
466 repair_monsters = TRUE;
469 /* Update the monster */
470 update_mon(m_idx, TRUE);
475 /* Hack -- Count the number of "reproducers" */
476 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
478 /* Hack -- Notice new multi-hued monsters */
479 if (r_ptr->flags1 & RF1_ATTR_MULTI) shimmer_monsters = TRUE;
485 monster_desc(m_name, &party_mon[i], 0);
487 msg_format("%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£", m_name);
489 msg_format("You have lost sight of %s.", m_name);
491 if (record_named_pet && party_mon[i].nickname)
493 monster_desc(m_name, &party_mon[i], 0x08);
494 do_cmd_write_nikki(NIKKI_NAMED_PET, 5, m_name);
502 * Hack -- Update location of unique monsters and artifacts
504 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly
505 * while new floor creation since dungeons may be re-created by
508 static void update_unique_artifact(s16b cur_floor_id)
512 /* Maintain unique monsters */
513 for (i = 1; i < m_max; i++)
516 monster_type *m_ptr = &m_list[i];
518 /* Skip dead monsters */
519 if (!m_ptr->r_idx) continue;
521 /* Extract real monster race */
522 r_ptr = real_r_ptr(m_ptr);
524 /* Memorize location of the unique monster */
525 if ((r_ptr->flags1 & RF1_UNIQUE) ||
526 (r_ptr->flags7 & RF7_UNIQUE_7))
528 r_ptr->floor_id = cur_floor_id;
532 /* Maintain artifatcs */
533 for (i = 1; i < o_max; i++)
535 object_type *o_ptr = &o_list[i];
537 /* Skip dead objects */
538 if (!o_ptr->k_idx) continue;
540 /* Memorize location of the artifact */
541 if (artifact_p(o_ptr))
543 a_info[o_ptr->name1].floor_id = cur_floor_id;
550 * Maintain quest monsters, mark next floor_id at stairs, save current
551 * floor, and prepare to enter next floor.
553 void leave_floor(void)
555 cave_type *c_ptr = NULL;
556 saved_floor_type *sf_ptr;
560 /* Preserve pets and prepare to take these to next floor */
563 /* New floor is not yet prepared */
567 /* From somewhere of the surface to somewhere of the surface */
570 /* No need to save current floor */
574 /* Search the quest monster index */
575 for (i = 0; i < max_quests; i++)
577 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
578 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
579 (quest[i].type == QUEST_TYPE_RANDOM)) &&
580 (quest[i].level == dun_level) &&
581 (dungeon_type == quest[i].dungeon) &&
582 !(quest[i].flags & QUEST_FLAG_PRESET))
584 quest_r_idx = quest[i].r_idx;
588 /* Maintain quest monsters */
589 for (i = 1; i < m_max; i++)
592 monster_type *m_ptr = &m_list[i];
594 /* Skip dead monsters */
595 if (!m_ptr->r_idx) continue;
597 /* Only maintain quest monsters */
598 if (quest_r_idx != m_ptr->r_idx) continue;
600 /* Extract real monster race */
601 r_ptr = real_r_ptr(m_ptr);
603 /* Ignore unique monsters */
604 if ((r_ptr->flags1 & RF1_UNIQUE) ||
605 (r_ptr->flags7 & RF7_UNIQUE_7)) continue;
607 /* Delete non-unique quest monsters */
608 delete_monster_idx(i);
611 /* Check if there is a same item */
612 for (i = 0; i < INVEN_PACK; i++)
614 object_type *o_ptr = &inventory[i];
616 /* Skip dead objects */
617 if (!o_ptr->k_idx) continue;
619 /* Delete old memorized location of the artifact */
620 if (artifact_p(o_ptr))
622 a_info[o_ptr->name1].floor_id = 0;
626 /* Extract current floor info or NULL */
627 sf_ptr = get_sf_ptr(p_ptr->floor_id);
629 /* Choose random stairs */
630 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
632 int x, y, sx = 0, sy = 0;
638 /* Search usable stairs */
639 for (y = 0; y < cur_hgt; y++)
641 for (x = 0; x < cur_wid; x++)
643 cave_type *c_ptr = &cave[y][x];
646 if (change_floor_mode & CFM_UP)
648 /* Found fixed stairs */
649 if (c_ptr->special &&
650 c_ptr->special == sf_ptr->upper_floor_id)
656 if (c_ptr->feat == FEAT_LESS ||
657 c_ptr->feat == FEAT_LESS_LESS)
660 else if (change_floor_mode & CFM_DOWN)
662 /* Found fixed stairs */
663 if (c_ptr->special &&
664 c_ptr->special == sf_ptr->lower_floor_id)
670 if (c_ptr->feat == FEAT_MORE ||
671 c_ptr->feat == FEAT_MORE_MORE)
692 /* No stairs found! -- No return */
693 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
695 /* Mega Hack -- It's not the stairs you enter. Disable it. */
696 cave[py][px].special = 0;
700 /* Choose random one */
703 /* Point stair location */
709 /* Extract new dungeon level */
710 if (!(change_floor_mode & CFM_CLEAR_ALL))
714 /* Extract stair position */
715 c_ptr = &cave[py][px];
717 /* Get back to old saved floor? */
718 if (dun_level && c_ptr->special && get_sf_ptr(c_ptr->special))
720 /* Saved floor is exist. Use it. */
721 new_floor_id = c_ptr->special;
724 /* Extract level movement number */
725 if (change_floor_mode & CFM_DOWN) move_num = 1;
726 else if (change_floor_mode & CFM_UP) move_num = -1;
728 /* Mark shaft up/down */
729 if (c_ptr->feat == FEAT_LESS_LESS ||
730 c_ptr->feat == FEAT_MORE_MORE)
732 prepare_change_floor_mode(CFM_SHAFT);
733 move_num += SGN(move_num);
736 /* Get out from or Enter the dungeon */
737 if (change_floor_mode & CFM_DOWN)
740 move_num = d_info[c_ptr->special].mindepth;
742 else if (change_floor_mode & CFM_UP)
744 if (dun_level + move_num < d_info[dungeon_type].mindepth)
745 move_num = -dun_level;
748 dun_level += move_num;
751 /* Leaving the dungeon to town */
752 if (!dun_level && dungeon_type)
754 p_ptr->leaving_dungeon = TRUE;
755 if (!vanilla_town && !lite_town)
757 p_ptr->wilderness_y = d_info[dungeon_type].dy;
758 p_ptr->wilderness_x = d_info[dungeon_type].dx;
760 p_ptr->recall_dungeon = dungeon_type;
763 /* Reach to the surface -- Clear all saved floors */
764 prepare_change_floor_mode(CFM_CLEAR_ALL);
767 if (change_floor_mode & CFM_CLEAR_ALL)
771 /* Kill all saved floors */
772 for (i = 0; i < MAX_SAVED_FLOORS; i++)
773 kill_saved_floor(&saved_floors[i]);
775 /* Reset visit_mark count */
776 latest_visit_mark = 1;
778 else if (change_floor_mode & CFM_NO_RETURN)
780 /* Kill current floor */
781 kill_saved_floor(sf_ptr);
784 /* No current floor -- Left/Enter dungeon etc... */
785 if (!p_ptr->floor_id)
787 /* No longer need to save current floor */
792 /* Mark next floor_id on the previous floor */
796 new_floor_id = get_new_floor_id();
798 /* Connect from here */
801 c_ptr->special = new_floor_id;
804 /* Record new dungeon level */
805 get_sf_ptr(new_floor_id)->dun_level = dun_level;
808 /* Fix connection -- level teleportation or trap door */
809 if (change_floor_mode & CFM_RAND_CONNECT)
811 if (change_floor_mode & CFM_UP)
812 sf_ptr->upper_floor_id = new_floor_id;
813 else if (change_floor_mode & CFM_DOWN)
814 sf_ptr->lower_floor_id = new_floor_id;
817 /* If you can return, you need to save previous floor */
818 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)))
820 /* Record the last visit turn of current floor */
821 sf_ptr->last_visit = turn;
823 /* Forget the lite */
826 /* Forget the view */
829 /* Forget the view */
832 /* Save current floor */
833 if (!save_floor(sf_ptr, 0))
835 /* Save failed -- No return */
836 prepare_change_floor_mode(CFM_NO_RETURN);
838 /* Kill current floor */
839 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
846 * Enter new floor. If the floor is an old saved floor, it will be
847 * restored from the temporal file. If the floor is new one, new cave
850 void change_floor(void)
852 saved_floor_type *sf_ptr;
855 /* The dungeon is not ready */
856 character_dungeon = FALSE;
858 /* No longer in the trap detecteded region */
859 p_ptr->dtrap = FALSE;
861 /* Mega-Hack -- no panel yet */
867 /* Mega-Hack -- not ambushed on the wildness? */
876 /* Paranoia -- Now on the surface */
883 /* No floor_id yet */
887 new_floor_id = get_new_floor_id();
890 /* Pointer for infomations of new floor */
891 sf_ptr = get_sf_ptr(new_floor_id);
893 /* Try to restore old floor */
894 if (sf_ptr->last_visit)
896 /* Old saved floor is exist */
897 if (load_floor(sf_ptr, 0))
901 /* Forbid return stairs */
902 if (change_floor_mode & CFM_NO_RETURN)
904 cave_type *c_ptr = &cave[py][px];
907 place_floor_grid(c_ptr);
914 * Set lower/upper_floor_id of new floor when the new
915 * floor is right-above/right-under the current floor.
917 * Stair creation/Teleport level/Trap door will take
918 * you the same floor when you used it later again.
922 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
924 if (change_floor_mode & CFM_UP)
926 /* New floor is right-above */
927 if (cur_sf_ptr->upper_floor_id == new_floor_id)
928 sf_ptr->lower_floor_id = p_ptr->floor_id;
930 else if (change_floor_mode & CFM_DOWN)
932 /* New floor is right-under */
933 if (cur_sf_ptr->lower_floor_id == new_floor_id)
934 sf_ptr->upper_floor_id = p_ptr->floor_id;
938 /* Maintain monsters and artifacts */
942 s32b absence_ticks = (turn - sf_ptr->last_visit) / TURNS_PER_TICK;
943 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
946 /* Maintain monsters */
947 for (i = 1; i < m_max; i++)
950 monster_type *m_ptr = &m_list[i];
952 /* Skip dead monsters */
953 if (!m_ptr->r_idx) continue;
958 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
963 /* Remove invulnerability */
966 /* Remove fast status */
969 /* Remove slow status */
975 /* Remove confusion */
979 /* Extract real monster race */
980 r_ptr = real_r_ptr(m_ptr);
982 /* Ignore non-unique */
983 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
984 !(r_ptr->flags7 & RF7_UNIQUE_7)) continue;
986 /* Appear at a different floor? */
987 if (r_ptr->floor_id != new_floor_id)
989 /* Disapper from here */
990 delete_monster_idx(i);
994 /* Maintain artifatcs */
995 for (i = 1; i < o_max; i++)
997 object_type *o_ptr = &o_list[i];
999 /* Skip dead objects */
1000 if (!o_ptr->k_idx) continue;
1002 /* Ignore non-artifact */
1003 if (!artifact_p(o_ptr)) continue;
1005 /* Appear at a different floor? */
1006 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1008 /* Disappear from here */
1009 delete_object_idx(i);
1013 /* Cancel preserve */
1014 a_info[o_ptr->name1].cur_num = 1;
1018 place_quest_monsters();
1020 /* Place some random monsters */
1021 alloc_times = absence_ticks / alloc_chance;
1023 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1026 for (i = 0; i < alloc_times; i++)
1028 /* Make a (group of) new monster */
1029 (void)alloc_monster(0, 0);
1033 /* New floor_id or failed to restore */
1034 else /* if (!loaded) */
1036 if (sf_ptr->last_visit)
1038 /* Temporal file is broken? */
1040 msg_print("³¬ÃʤϹԤ»ß¤Þ¤ê¤À¤Ã¤¿¡£");
1042 msg_print("The staircases come to a dead end...");
1045 /* Create simple dead end */
1048 /* Break connection */
1049 if (change_floor_mode & CFM_UP)
1051 sf_ptr->upper_floor_id = 0;
1053 else if (change_floor_mode & CFM_DOWN)
1055 sf_ptr->lower_floor_id = 0;
1060 /* Newly create cave */
1064 /* Record last visit turn */
1065 sf_ptr->last_visit = turn;
1067 /* Set correct dun_level value */
1068 sf_ptr->dun_level = dun_level;
1070 /* Creat connected stairs */
1071 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)) && dun_level)
1075 /* Extract stair position */
1076 cave_type *c_ptr = &cave[py][px];
1078 /*** Create connected stairs ***/
1080 /* No stairs down from Quest */
1081 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1083 if (change_floor_mode & CFM_SHAFT)
1084 c_ptr->feat = FEAT_MORE_MORE;
1086 c_ptr->feat = FEAT_MORE;
1089 /* No stairs up when ironman_downward */
1090 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1092 if (change_floor_mode & CFM_SHAFT)
1093 c_ptr->feat = FEAT_LESS_LESS;
1095 c_ptr->feat = FEAT_LESS;
1105 /* Paranoia -- Clear mimic */
1108 /* Connect to previous floor */
1109 c_ptr->special = p_ptr->floor_id;
1114 /* Arrive at random grid */
1115 if (change_floor_mode & (CFM_RAND_PLACE))
1117 (void)new_player_spot();
1120 /* You see stairs blocked */
1121 else if (change_floor_mode & CFM_NO_RETURN)
1126 msg_print("ÆÍÁ³³¬Ãʤ¬ºÉ¤¬¤ì¤Æ¤·¤Þ¤Ã¤¿¡£");
1128 msg_print("Suddenly the stairs is blocked!");
1134 msg_print("¥´¥È¥´¥È¤È²¿¤«²»¤¬¤·¤¿¡£");
1136 msg_print("You hear some noises.");
1144 * The "turn" is not always different number because
1145 * the level teleport doesn't take any turn. Use
1146 * visit mark instead of last visit turn to find the
1147 * oldest saved floor.
1149 sf_ptr->visit_mark = latest_visit_mark++;
1152 /* Place preserved pet monsters */
1155 /* Hack -- maintain unique and artifacts */
1156 update_unique_artifact(new_floor_id);
1158 /* Now the player is in new floor */
1159 p_ptr->floor_id = new_floor_id;
1161 /* The dungeon is ready */
1162 character_dungeon = TRUE;
1164 /* Hack -- Munchkin characters always get whole map */
1165 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1166 wiz_lite(TRUE, (bool)(p_ptr->pclass == CLASS_NINJA));
1168 /* Remember when this level was "created" */
1171 /* Clear all flags */
1172 change_floor_mode = 0L;
1178 * Create stairs at or move previously created stairs into the player
1181 void stair_creation(void)
1183 saved_floor_type *sf_ptr;
1184 saved_floor_type *dest_sf_ptr;
1188 s16b dest_floor_id = 0;
1191 /* Forbid up staircases on Ironman mode */
1192 if (ironman_downward) up = FALSE;
1194 /* Forbid down staircases on quest level */
1195 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1197 /* No effect out of standard dungeon floor */
1198 if (!dun_level || (!up && !down) ||
1199 (p_ptr->inside_quest && (p_ptr->inside_quest < MIN_RANDOM_QUEST)) ||
1200 p_ptr->inside_arena || p_ptr->inside_battle)
1202 /* arena or quest */
1204 msg_print("¸ú²Ì¤¬¤¢¤ê¤Þ¤»¤ó¡ª");
1206 msg_print("There is no effect!");
1211 /* Artifacts resists */
1212 if (!cave_valid_bold(py, px))
1215 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1217 msg_print("The object resists the spell.");
1223 /* Destroy all objects in the grid */
1224 delete_object(py, px);
1226 /* Extract current floor data */
1227 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1229 /* Choose randomly */
1232 if (randint0(100) < 50) up = FALSE;
1236 /* Destination is already fixed */
1239 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1243 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1247 /* Search old stairs leading to the destination */
1252 for (y = 0; y < cur_hgt; y++)
1254 for (x = 0; x < cur_wid; x++)
1256 cave_type *c_ptr = &cave[y][x];
1259 if (!c_ptr->special) continue;
1260 if (c_ptr->special != dest_floor_id) continue;
1262 /* Remove old stairs */
1264 cave_set_feat(y, x, floor_type[randint0(100)]);
1269 /* No old destination -- Get new one now */
1272 dest_floor_id = get_new_floor_id();
1276 sf_ptr->upper_floor_id = dest_floor_id;
1278 sf_ptr->lower_floor_id = dest_floor_id;
1281 /* Extract destination floor data */
1282 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1285 /* Create a staircase */
1288 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level <= dun_level - 2)
1289 cave_set_feat(py, px, FEAT_LESS_LESS);
1291 cave_set_feat(py, px, FEAT_LESS);
1295 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level >= dun_level + 2)
1296 cave_set_feat(py, px, FEAT_MORE_MORE);
1298 cave_set_feat(py, px, FEAT_MORE);
1302 /* Connect this stairs to the destination */
1303 cave[py][px].special = dest_floor_id;