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 /* Grab permissions */
51 /* Try to create the file */
52 fd = fd_make(floor_savefile, mode);
54 /* Drop permissions */
63 msg_print("¥¨¥é¡¼¡§¸Å¤¤¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£");
64 msg_print("ÊѶòÈÚÅܤòÆó½Å¤Ëµ¯Æ°¤·¤Æ¤¤¤Ê¤¤¤«³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£");
65 msg_print("²áµî¤ËÊѶòÈÚÅܤ¬¥¯¥é¥Ã¥·¥å¤·¤¿¾ì¹ç¤Ï°ì»þ¥Õ¥¡¥¤¥ë¤ò");
66 msg_print("¶¯À©Åª¤Ëºï½ü¤·¤Æ¼Â¹Ô¤ò³¤±¤é¤ì¤Þ¤¹¡£");
67 if (!get_check("¶¯À©Åª¤Ëºï½ü¤·¤Æ¤â¤è¤í¤·¤¤¤Ç¤¹¤«¡©")) quit("¼Â¹ÔÃæ»ß");
69 msg_print("Error: There are old temporal files.");
70 msg_print("Make sure you are not running two game processes simultaneously.");
71 msg_print("If the temporal files are garbages of old crashed process, ");
72 msg_print("you can delete it safely.");
73 if (!get_check("Do you delete old temporal files? ")) quit("Aborted.");
84 /* Grab permissions */
87 /* Simply kill the temporal file */
88 (void)fd_kill(floor_savefile);
90 /* Drop permissions */
96 /* No floor_id used yet (No.0 is reserved to indicate non existance) */
99 /* vist_mark is from 1 */
100 latest_visit_mark = 1;
102 /* A sign to mark temporal files */
103 saved_floor_file_sign = time(NULL);
105 /* No next floor yet */
108 /* No change floor mode yet */
109 change_floor_mode = 0;
113 /* Drop "games" permissions */
121 * Kill temporal files
122 * Should be called just before the game quit
123 * and before new game discarding saved game.
125 void clear_saved_floor_files(void)
127 char floor_savefile[1024];
132 /* Get "games" permissions */
137 for (i = 0; i < MAX_SAVED_FLOORS; i++)
139 saved_floor_type *sf_ptr = &saved_floors[i];
141 /* No temporal file */
142 if (!sf_ptr->floor_id) continue;
143 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
146 sprintf(floor_savefile, "%s.F%02d", savefile, i);
148 /* Grab permissions */
151 /* Simply kill the temporal file */
152 (void)fd_kill(floor_savefile);
154 /* Drop permissions */
160 /* Drop "games" permissions */
168 * Get a pointer for an item of the saved_floors array.
170 saved_floor_type *get_sf_ptr(s16b floor_id)
174 /* floor_id No.0 indicates no floor */
175 if (!floor_id) return NULL;
177 for (i = 0; i < MAX_SAVED_FLOORS; i++)
179 saved_floor_type *sf_ptr = &saved_floors[i];
181 if (sf_ptr->floor_id == floor_id) return sf_ptr;
190 * kill a saved floor and get an empty space
192 static void kill_saved_floor(saved_floor_type *sf_ptr)
194 char floor_savefile[1024];
197 if (!sf_ptr->floor_id) return;
199 if (sf_ptr->floor_id == p_ptr->floor_id)
201 /* Kill current floor */
204 /* Current floor doesn't have temporal file */
209 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
211 /* Grab permissions */
214 /* Simply kill the temporal file */
215 (void)fd_kill(floor_savefile);
217 /* Drop permissions */
221 /* No longer exists */
222 sf_ptr->floor_id = 0;
227 * Initialize new saved floor and get its floor id. If number of
228 * saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
230 s16b get_new_floor_id(void)
232 saved_floor_type *sf_ptr;
235 /* Look for empty space */
236 for (i = 0; i < MAX_SAVED_FLOORS; i++)
238 sf_ptr = &saved_floors[i];
240 if (!sf_ptr->floor_id) break;
244 if (i == MAX_SAVED_FLOORS)
247 u32b oldest_visit = 0xffffffffL;
249 /* Search for oldest */
250 for (i = 0; i < MAX_SAVED_FLOORS; i++)
252 sf_ptr = &saved_floors[i];
254 /* Don't kill current floor */
255 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
257 /* Don't kill newer */
258 if (sf_ptr->visit_mark > oldest_visit) continue;
261 oldest_visit = sf_ptr->visit_mark;
264 /* Kill oldest saved floor */
265 sf_ptr = &saved_floors[oldest];
266 kill_saved_floor(sf_ptr);
272 /* Prepare new floor data */
273 sf_ptr->savefile_id = i;
274 sf_ptr->floor_id = max_floor_id;
275 sf_ptr->last_visit = 0;
276 sf_ptr->upper_floor_id = 0;
277 sf_ptr->lower_floor_id = 0;
278 sf_ptr->visit_mark = latest_visit_mark++;
280 /* sf_ptr->dun_level is not yet decided */
283 /* Increment number of floor_id */
284 if (max_floor_id < MAX_SHORT) max_floor_id++;
286 /* 32767 floor_ids are all used up! Re-use ancient IDs */
287 else max_floor_id = 1;
289 return sf_ptr->floor_id;
294 * Prepare mode flags of changing floor
296 void prepare_change_floor_mode(u32b mode)
298 change_floor_mode |= mode;
303 * Builds the dead end
305 static void build_dead_end(void)
309 /* Clear and empty the cave */
312 /* Fill the arrays of floors and walls in the good proportions */
313 set_floor_and_wall(0);
316 cur_hgt = SCREEN_HGT;
317 cur_wid = SCREEN_WID;
319 /* Filled with permanent walls */
320 for (y = 0; y < MAX_HGT; y++)
322 for (x = 0; x < MAX_WID; x++)
324 /* Create "solid" perma-wall */
325 cave[y][x].feat = FEAT_PERM_SOLID;
329 /* Place at center of the floor */
333 /* Give one square */
334 place_floor_bold(py, px);
341 static void preserve_pet(void)
345 for(num = 0; num < 21; num++)
347 party_mon[num].r_idx = 0;
352 COPY(&party_mon[0], &m_list[p_ptr->riding], monster_type);
354 /* Delete from this floor */
355 delete_monster_idx(p_ptr->riding);
358 for(i = m_max - 1, num = 1; (i >= 1 && num < 21); i--)
360 monster_type *m_ptr = &m_list[i];
362 if (!m_ptr->r_idx) continue;
363 if (!is_pet(m_ptr)) continue;
364 if (i == p_ptr->riding) continue;
366 if (reinit_wilderness)
368 /* Don't lose sight of pets when getting a Quest */
372 int dis = distance(py, px, m_ptr->fy, m_ptr->fx);
375 * Pets with nickname will follow even from 3 blocks away
376 * when you or the pet can see the other.
378 if (m_ptr->nickname &&
379 (player_has_los_bold(m_ptr->fy, m_ptr->fx) ||
380 los(m_ptr->fy, m_ptr->fx, py, px)))
382 if (dis > 3) continue;
386 if (dis > 1) continue;
388 if (m_ptr->confused || m_ptr->stunned || m_ptr->csleep) continue;
391 COPY(&party_mon[num], &m_list[i], monster_type);
394 /* Delete from this floor */
395 delete_monster_idx(i);
398 if (record_named_pet)
400 for (i = m_max - 1; i >=1; i--)
402 monster_type *m_ptr = &m_list[i];
405 if (!m_ptr->r_idx) continue;
406 if (!is_pet(m_ptr)) continue;
407 if (!m_ptr->nickname) continue;
408 if (p_ptr->riding == i) continue;
410 monster_desc(m_name, m_ptr, 0x88);
411 do_cmd_write_nikki(NIKKI_NAMED_PET, 4, m_name);
418 * Place preserved pet monsters on new floor
420 static void place_pet(void)
424 if (p_ptr->wild_mode)
429 for (i = 0; i < max_num; i++)
433 if (!(party_mon[i].r_idx)) continue;
439 p_ptr->riding = m_idx;
450 for(d = 1; d < 6; d++)
452 for(j = 1000; j > 0; j--)
454 scatter(&cy, &cx, py, px, d, 0);
455 if ((cave_floor_bold(cy, cx) || (cave[cy][cx].feat == FEAT_TREES)) && !cave[cy][cx].m_idx && !((cy == py) && (cx == px))) break;
459 if (d == 6 || p_ptr->inside_arena || p_ptr->inside_battle)
467 monster_type *m_ptr = &m_list[m_idx];
470 cave[cy][cx].m_idx = m_idx;
472 m_ptr->r_idx = party_mon[i].r_idx;
473 r_ptr = real_r_ptr(m_ptr);
475 /* Copy all member of the structure */
476 *m_ptr = party_mon[i];
484 m_ptr->hold_o_idx = 0;
487 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
489 /* Monster is still being nice */
490 m_ptr->mflag |= (MFLAG_NICE);
492 /* Must repair monsters */
493 repair_monsters = TRUE;
496 /* Update the monster */
497 update_mon(m_idx, TRUE);
502 /* Hack -- Count the number of "reproducers" */
503 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
505 /* Hack -- Notice new multi-hued monsters */
506 if (r_ptr->flags1 & RF1_ATTR_MULTI) shimmer_monsters = TRUE;
512 monster_desc(m_name, &party_mon[i], 0);
514 msg_format("%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£", m_name);
516 msg_format("You have lost sight of %s.", m_name);
518 if (record_named_pet && party_mon[i].nickname)
520 monster_desc(m_name, &party_mon[i], 0x08);
521 do_cmd_write_nikki(NIKKI_NAMED_PET, 5, m_name);
529 * Hack -- Update location of unique monsters and artifacts
531 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly
532 * while new floor creation since dungeons may be re-created by
535 static void update_unique_artifact(s16b cur_floor_id)
539 /* Maintain unique monsters */
540 for (i = 1; i < m_max; i++)
543 monster_type *m_ptr = &m_list[i];
545 /* Skip dead monsters */
546 if (!m_ptr->r_idx) continue;
548 /* Extract real monster race */
549 r_ptr = real_r_ptr(m_ptr);
551 /* Memorize location of the unique monster */
552 if ((r_ptr->flags1 & RF1_UNIQUE) ||
553 (r_ptr->flags7 & RF7_UNIQUE_7))
555 r_ptr->floor_id = cur_floor_id;
559 /* Maintain artifatcs */
560 for (i = 1; i < o_max; i++)
562 object_type *o_ptr = &o_list[i];
564 /* Skip dead objects */
565 if (!o_ptr->k_idx) continue;
567 /* Memorize location of the artifact */
568 if (artifact_p(o_ptr))
570 a_info[o_ptr->name1].floor_id = cur_floor_id;
577 * When a monster is at a place where player will return,
578 * Get out of the my way!
580 static void get_out_monster(void)
586 int m_idx = cave[oy][ox].m_idx;
588 /* Nothing to do if no monster */
591 /* Look until done */
596 /* Pick a (possibly illegal) location */
597 int ny = rand_spread(oy, dis);
598 int nx = rand_spread(ox, dis);
602 /* Stop after 1000 tries */
603 if (tries > 10000) return;
606 * Increase distance after doing enough tries
607 * compared to area of possible space
609 if (tries > 20 * dis * dis) dis++;
611 /* Ignore illegal locations */
612 if (!in_bounds(ny, nx)) continue;
614 /* Require "empty" floor space */
615 if (!cave_empty_bold(ny, nx)) continue;
617 /* Hack -- no teleport onto glyph of warding */
618 if (is_glyph_grid(&cave[ny][nx])) continue;
619 if (is_explosive_rune_grid(&cave[ny][nx])) continue;
621 /* ...nor onto the Pattern */
622 if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
623 (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2)) continue;
625 /*** It's a good place ***/
627 m_ptr = &m_list[m_idx];
629 /* Update the new location */
630 cave[ny][nx].m_idx = m_idx;
632 /* Update the old location */
633 cave[oy][ox].m_idx = 0;
635 /* Move the monster */
639 /* No need to do update_mon() */
648 * Maintain quest monsters, mark next floor_id at stairs, save current
649 * floor, and prepare to enter next floor.
651 void leave_floor(void)
653 cave_type *c_ptr = NULL;
654 saved_floor_type *sf_ptr;
658 /* Preserve pets and prepare to take these to next floor */
661 /* New floor is not yet prepared */
665 /* From somewhere of the surface to somewhere of the surface */
668 /* No need to save current floor */
672 /* Search the quest monster index */
673 for (i = 0; i < max_quests; i++)
675 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
676 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
677 (quest[i].type == QUEST_TYPE_RANDOM)) &&
678 (quest[i].level == dun_level) &&
679 (dungeon_type == quest[i].dungeon) &&
680 !(quest[i].flags & QUEST_FLAG_PRESET))
682 quest_r_idx = quest[i].r_idx;
686 /* Maintain quest monsters */
687 for (i = 1; i < m_max; i++)
690 monster_type *m_ptr = &m_list[i];
692 /* Skip dead monsters */
693 if (!m_ptr->r_idx) continue;
695 /* Only maintain quest monsters */
696 if (quest_r_idx != m_ptr->r_idx) continue;
698 /* Extract real monster race */
699 r_ptr = real_r_ptr(m_ptr);
701 /* Ignore unique monsters */
702 if ((r_ptr->flags1 & RF1_UNIQUE) ||
703 (r_ptr->flags7 & RF7_UNIQUE_7)) continue;
705 /* Delete non-unique quest monsters */
706 delete_monster_idx(i);
709 /* Check if there is a same item */
710 for (i = 0; i < INVEN_PACK; i++)
712 object_type *o_ptr = &inventory[i];
714 /* Skip dead objects */
715 if (!o_ptr->k_idx) continue;
717 /* Delete old memorized location of the artifact */
718 if (artifact_p(o_ptr))
720 a_info[o_ptr->name1].floor_id = 0;
724 /* Extract current floor info or NULL */
725 sf_ptr = get_sf_ptr(p_ptr->floor_id);
727 /* Choose random stairs */
728 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
730 int x, y, sx = 0, sy = 0;
736 /* Search usable stairs */
737 for (y = 0; y < cur_hgt; y++)
739 for (x = 0; x < cur_wid; x++)
741 cave_type *c_ptr = &cave[y][x];
744 if (change_floor_mode & CFM_UP)
746 /* Found fixed stairs */
747 if (c_ptr->special &&
748 c_ptr->special == sf_ptr->upper_floor_id)
754 if (c_ptr->feat == FEAT_LESS ||
755 c_ptr->feat == FEAT_LESS_LESS)
758 else if (change_floor_mode & CFM_DOWN)
760 /* Found fixed stairs */
761 if (c_ptr->special &&
762 c_ptr->special == sf_ptr->lower_floor_id)
768 if (c_ptr->feat == FEAT_MORE ||
769 c_ptr->feat == FEAT_MORE_MORE)
790 /* No stairs found! -- No return */
791 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
793 /* Mega Hack -- It's not the stairs you enter. Disable it. */
794 cave[py][px].special = 0;
798 /* Choose random one */
801 /* Point stair location */
807 /* Extract new dungeon level */
808 if (!(change_floor_mode & CFM_CLEAR_ALL))
812 /* Extract stair position */
813 c_ptr = &cave[py][px];
815 /* Get back to old saved floor? */
816 if (dun_level && c_ptr->special && get_sf_ptr(c_ptr->special))
818 /* Saved floor is exist. Use it. */
819 new_floor_id = c_ptr->special;
822 /* Extract level movement number */
823 if (change_floor_mode & CFM_DOWN) move_num = 1;
824 else if (change_floor_mode & CFM_UP) move_num = -1;
826 /* Mark shaft up/down */
827 if (c_ptr->feat == FEAT_LESS_LESS ||
828 c_ptr->feat == FEAT_MORE_MORE)
830 prepare_change_floor_mode(CFM_SHAFT);
831 move_num += SGN(move_num);
834 /* Get out from or Enter the dungeon */
835 if (change_floor_mode & CFM_DOWN)
838 move_num = d_info[c_ptr->special].mindepth;
840 else if (change_floor_mode & CFM_UP)
842 if (dun_level + move_num < d_info[dungeon_type].mindepth)
843 move_num = -dun_level;
846 dun_level += move_num;
849 /* Leaving the dungeon to town */
850 if (!dun_level && dungeon_type)
852 p_ptr->leaving_dungeon = TRUE;
853 if (!vanilla_town && !lite_town)
855 p_ptr->wilderness_y = d_info[dungeon_type].dy;
856 p_ptr->wilderness_x = d_info[dungeon_type].dx;
858 p_ptr->recall_dungeon = dungeon_type;
861 /* Reach to the surface -- Clear all saved floors */
862 prepare_change_floor_mode(CFM_CLEAR_ALL);
865 if (change_floor_mode & CFM_CLEAR_ALL)
869 /* Kill all saved floors */
870 for (i = 0; i < MAX_SAVED_FLOORS; i++)
871 kill_saved_floor(&saved_floors[i]);
873 /* Reset visit_mark count */
874 latest_visit_mark = 1;
876 else if (change_floor_mode & CFM_NO_RETURN)
878 /* Kill current floor */
879 kill_saved_floor(sf_ptr);
882 /* No current floor -- Left/Enter dungeon etc... */
883 if (!p_ptr->floor_id)
885 /* No longer need to save current floor */
890 /* Mark next floor_id on the previous floor */
894 new_floor_id = get_new_floor_id();
896 /* Connect from here */
899 c_ptr->special = new_floor_id;
902 /* Record new dungeon level */
903 get_sf_ptr(new_floor_id)->dun_level = dun_level;
906 /* Fix connection -- level teleportation or trap door */
907 if (change_floor_mode & CFM_RAND_CONNECT)
909 if (change_floor_mode & CFM_UP)
910 sf_ptr->upper_floor_id = new_floor_id;
911 else if (change_floor_mode & CFM_DOWN)
912 sf_ptr->lower_floor_id = new_floor_id;
915 /* If you can return, you need to save previous floor */
916 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)))
918 /* Get out of the my way! */
921 /* Record the last visit turn of current floor */
922 sf_ptr->last_visit = turn;
924 /* Forget the lite */
927 /* Forget the view */
930 /* Forget the view */
933 /* Save current floor */
934 if (!save_floor(sf_ptr, 0))
936 /* Save failed -- No return */
937 prepare_change_floor_mode(CFM_NO_RETURN);
939 /* Kill current floor */
940 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
947 * Enter new floor. If the floor is an old saved floor, it will be
948 * restored from the temporal file. If the floor is new one, new cave
951 void change_floor(void)
953 saved_floor_type *sf_ptr;
956 /* The dungeon is not ready */
957 character_dungeon = FALSE;
959 /* No longer in the trap detecteded region */
960 p_ptr->dtrap = FALSE;
962 /* Mega-Hack -- no panel yet */
968 /* Mega-Hack -- not ambushed on the wildness? */
977 /* Paranoia -- Now on the surface */
984 /* No floor_id yet */
988 new_floor_id = get_new_floor_id();
991 /* Pointer for infomations of new floor */
992 sf_ptr = get_sf_ptr(new_floor_id);
994 /* Try to restore old floor */
995 if (sf_ptr->last_visit)
997 /* Old saved floor is exist */
998 if (load_floor(sf_ptr, 0))
1002 /* Forbid return stairs */
1003 if (change_floor_mode & CFM_NO_RETURN)
1005 cave_type *c_ptr = &cave[py][px];
1007 /* Reset to floor */
1008 place_floor_grid(c_ptr);
1015 * Set lower/upper_floor_id of new floor when the new
1016 * floor is right-above/right-under the current floor.
1018 * Stair creation/Teleport level/Trap door will take
1019 * you the same floor when you used it later again.
1021 if (p_ptr->floor_id)
1023 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1025 if (change_floor_mode & CFM_UP)
1027 /* New floor is right-above */
1028 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1029 sf_ptr->lower_floor_id = p_ptr->floor_id;
1031 else if (change_floor_mode & CFM_DOWN)
1033 /* New floor is right-under */
1034 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1035 sf_ptr->upper_floor_id = p_ptr->floor_id;
1039 /* Maintain monsters and artifacts */
1043 s32b absence_ticks = (turn - sf_ptr->last_visit) / TURNS_PER_TICK;
1044 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
1047 /* Maintain monsters */
1048 for (i = 1; i < m_max; i++)
1050 monster_race *r_ptr;
1051 monster_type *m_ptr = &m_list[i];
1053 /* Skip dead monsters */
1054 if (!m_ptr->r_idx) continue;
1059 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1064 /* Remove invulnerability */
1065 m_ptr->invulner = 0;
1067 /* Remove fast status */
1070 /* Remove slow status */
1076 /* Remove confusion */
1077 m_ptr->confused = 0;
1080 /* Extract real monster race */
1081 r_ptr = real_r_ptr(m_ptr);
1083 /* Ignore non-unique */
1084 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1085 !(r_ptr->flags7 & RF7_UNIQUE_7)) continue;
1087 /* Appear at a different floor? */
1088 if (r_ptr->floor_id != new_floor_id)
1090 /* Disapper from here */
1091 delete_monster_idx(i);
1095 /* Maintain artifatcs */
1096 for (i = 1; i < o_max; i++)
1098 object_type *o_ptr = &o_list[i];
1100 /* Skip dead objects */
1101 if (!o_ptr->k_idx) continue;
1103 /* Ignore non-artifact */
1104 if (!artifact_p(o_ptr)) continue;
1106 /* Appear at a different floor? */
1107 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1109 /* Disappear from here */
1110 delete_object_idx(i);
1114 /* Cancel preserve */
1115 a_info[o_ptr->name1].cur_num = 1;
1119 place_quest_monsters();
1121 /* Place some random monsters */
1122 alloc_times = absence_ticks / alloc_chance;
1124 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1127 for (i = 0; i < alloc_times; i++)
1129 /* Make a (group of) new monster */
1130 (void)alloc_monster(0, 0);
1134 /* New floor_id or failed to restore */
1135 else /* if (!loaded) */
1137 if (sf_ptr->last_visit)
1139 /* Temporal file is broken? */
1141 msg_print("³¬ÃʤϹԤ»ß¤Þ¤ê¤À¤Ã¤¿¡£");
1143 msg_print("The staircases come to a dead end...");
1146 /* Create simple dead end */
1149 /* Break connection */
1150 if (change_floor_mode & CFM_UP)
1152 sf_ptr->upper_floor_id = 0;
1154 else if (change_floor_mode & CFM_DOWN)
1156 sf_ptr->lower_floor_id = 0;
1161 /* Newly create cave */
1165 /* Record last visit turn */
1166 sf_ptr->last_visit = turn;
1168 /* Set correct dun_level value */
1169 sf_ptr->dun_level = dun_level;
1171 /* Creat connected stairs */
1172 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)) && dun_level)
1176 /* Extract stair position */
1177 cave_type *c_ptr = &cave[py][px];
1179 /*** Create connected stairs ***/
1181 /* No stairs down from Quest */
1182 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1184 if (change_floor_mode & CFM_SHAFT)
1185 c_ptr->feat = FEAT_MORE_MORE;
1187 c_ptr->feat = FEAT_MORE;
1190 /* No stairs up when ironman_downward */
1191 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1193 if (change_floor_mode & CFM_SHAFT)
1194 c_ptr->feat = FEAT_LESS_LESS;
1196 c_ptr->feat = FEAT_LESS;
1206 /* Paranoia -- Clear mimic */
1209 /* Connect to previous floor */
1210 c_ptr->special = p_ptr->floor_id;
1215 /* Arrive at random grid */
1216 if (change_floor_mode & (CFM_RAND_PLACE))
1218 (void)new_player_spot();
1221 /* You see stairs blocked */
1222 else if (change_floor_mode & CFM_NO_RETURN)
1227 msg_print("ÆÍÁ³³¬Ãʤ¬ºÉ¤¬¤ì¤Æ¤·¤Þ¤Ã¤¿¡£");
1229 msg_print("Suddenly the stairs is blocked!");
1235 msg_print("¥´¥È¥´¥È¤È²¿¤«²»¤¬¤·¤¿¡£");
1237 msg_print("You hear some noises.");
1245 * The "turn" is not always different number because
1246 * the level teleport doesn't take any turn. Use
1247 * visit mark instead of last visit turn to find the
1248 * oldest saved floor.
1250 sf_ptr->visit_mark = latest_visit_mark++;
1253 /* Place preserved pet monsters */
1256 /* Hack -- maintain unique and artifacts */
1257 update_unique_artifact(new_floor_id);
1259 /* Now the player is in new floor */
1260 p_ptr->floor_id = new_floor_id;
1262 /* The dungeon is ready */
1263 character_dungeon = TRUE;
1265 /* Hack -- Munchkin characters always get whole map */
1266 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1267 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1269 /* Remember when this level was "created" */
1272 /* Clear all flags */
1273 change_floor_mode = 0L;
1279 * Create stairs at or move previously created stairs into the player
1282 void stair_creation(void)
1284 saved_floor_type *sf_ptr;
1285 saved_floor_type *dest_sf_ptr;
1289 s16b dest_floor_id = 0;
1292 /* Forbid up staircases on Ironman mode */
1293 if (ironman_downward) up = FALSE;
1295 /* Forbid down staircases on quest level */
1296 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1298 /* No effect out of standard dungeon floor */
1299 if (!dun_level || (!up && !down) ||
1300 (p_ptr->inside_quest && (p_ptr->inside_quest < MIN_RANDOM_QUEST)) ||
1301 p_ptr->inside_arena || p_ptr->inside_battle)
1303 /* arena or quest */
1305 msg_print("¸ú²Ì¤¬¤¢¤ê¤Þ¤»¤ó¡ª");
1307 msg_print("There is no effect!");
1312 /* Artifacts resists */
1313 if (!cave_valid_bold(py, px))
1316 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1318 msg_print("The object resists the spell.");
1324 /* Destroy all objects in the grid */
1325 delete_object(py, px);
1327 /* Extract current floor data */
1328 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1330 /* Choose randomly */
1333 if (randint0(100) < 50) up = FALSE;
1337 /* Destination is already fixed */
1340 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1344 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1348 /* Search old stairs leading to the destination */
1353 for (y = 0; y < cur_hgt; y++)
1355 for (x = 0; x < cur_wid; x++)
1357 cave_type *c_ptr = &cave[y][x];
1359 if (!c_ptr->special) continue;
1360 if (c_ptr->special != dest_floor_id) continue;
1362 /* Remove old stairs */
1364 cave_set_feat(y, x, floor_type[randint0(100)]);
1369 /* No old destination -- Get new one now */
1372 dest_floor_id = get_new_floor_id();
1376 sf_ptr->upper_floor_id = dest_floor_id;
1378 sf_ptr->lower_floor_id = dest_floor_id;
1381 /* Extract destination floor data */
1382 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1385 /* Create a staircase */
1388 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level <= dun_level - 2)
1389 cave_set_feat(py, px, FEAT_LESS_LESS);
1391 cave_set_feat(py, px, FEAT_LESS);
1395 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level >= dun_level + 2)
1396 cave_set_feat(py, px, FEAT_MORE_MORE);
1398 cave_set_feat(py, px, FEAT_MORE);
1402 /* Connect this stairs to the destination */
1403 cave[py][px].special = dest_floor_id;