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 */
313 cur_hgt = SCREEN_HGT;
314 cur_wid = SCREEN_WID;
316 /* Filled with permanent walls */
317 for (y = 0; y < MAX_HGT; y++)
319 for (x = 0; x < MAX_WID; x++)
321 /* Create "solid" perma-wall */
322 cave[y][x].feat = FEAT_PERM_SOLID;
326 /* Place at center of the floor */
330 /* Give one square */
331 place_floor_bold(py, px);
338 static void preserve_pet(void)
342 for(num = 0; num < 21; num++)
344 party_mon[num].r_idx = 0;
349 COPY(&party_mon[0], &m_list[p_ptr->riding], monster_type);
351 /* Delete from this floor */
352 delete_monster_idx(p_ptr->riding);
355 for(i = m_max - 1, num = 1; (i >= 1 && num < 21); i--)
357 monster_type *m_ptr = &m_list[i];
359 if (!m_ptr->r_idx) continue;
360 if (!is_pet(m_ptr)) continue;
361 if (i == p_ptr->riding) continue;
363 if (reinit_wilderness)
365 /* Don't lose sight of pets when getting a Quest */
369 int dis = distance(py, px, m_ptr->fy, m_ptr->fx);
372 * Pets with nickname will follow even from 3 blocks away
373 * when you or the pet can see the other.
375 if (m_ptr->nickname &&
376 (player_has_los_bold(m_ptr->fy, m_ptr->fx) ||
377 los(m_ptr->fy, m_ptr->fx, py, px)))
379 if (dis > 3) continue;
383 if (dis > 1) continue;
385 if (m_ptr->confused || m_ptr->stunned || m_ptr->csleep) continue;
388 COPY(&party_mon[num], &m_list[i], monster_type);
391 /* Delete from this floor */
392 delete_monster_idx(i);
395 if (record_named_pet)
397 for (i = m_max - 1; i >=1; i--)
399 monster_type *m_ptr = &m_list[i];
402 if (!m_ptr->r_idx) continue;
403 if (!is_pet(m_ptr)) continue;
404 if (!m_ptr->nickname) continue;
405 if (p_ptr->riding == i) continue;
407 monster_desc(m_name, m_ptr, 0x88);
408 do_cmd_write_nikki(NIKKI_NAMED_PET, 4, m_name);
415 * Place preserved pet monsters on new floor
417 static void place_pet(void)
421 if (p_ptr->wild_mode)
426 for (i = 0; i < max_num; i++)
430 if (!(party_mon[i].r_idx)) continue;
436 p_ptr->riding = m_idx;
447 for(d = 1; d < 6; d++)
449 for(j = 1000; j > 0; j--)
451 scatter(&cy, &cx, py, px, d, 0);
452 if ((cave_floor_bold(cy, cx) || (cave[cy][cx].feat == FEAT_TREES)) && !cave[cy][cx].m_idx && !((cy == py) && (cx == px))) break;
456 if (d == 6 || p_ptr->inside_arena || p_ptr->inside_battle)
464 monster_type *m_ptr = &m_list[m_idx];
467 cave[cy][cx].m_idx = m_idx;
469 m_ptr->r_idx = party_mon[i].r_idx;
470 r_ptr = real_r_ptr(m_ptr);
472 /* Copy all member of the structure */
473 *m_ptr = party_mon[i];
481 m_ptr->hold_o_idx = 0;
484 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
486 /* Monster is still being nice */
487 m_ptr->mflag |= (MFLAG_NICE);
489 /* Must repair monsters */
490 repair_monsters = TRUE;
493 /* Update the monster */
494 update_mon(m_idx, TRUE);
499 /* Hack -- Count the number of "reproducers" */
500 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
502 /* Hack -- Notice new multi-hued monsters */
503 if (r_ptr->flags1 & RF1_ATTR_MULTI) shimmer_monsters = TRUE;
509 monster_desc(m_name, &party_mon[i], 0);
511 msg_format("%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£", m_name);
513 msg_format("You have lost sight of %s.", m_name);
515 if (record_named_pet && party_mon[i].nickname)
517 monster_desc(m_name, &party_mon[i], 0x08);
518 do_cmd_write_nikki(NIKKI_NAMED_PET, 5, m_name);
526 * Hack -- Update location of unique monsters and artifacts
528 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly
529 * while new floor creation since dungeons may be re-created by
532 static void update_unique_artifact(s16b cur_floor_id)
536 /* Maintain unique monsters */
537 for (i = 1; i < m_max; i++)
540 monster_type *m_ptr = &m_list[i];
542 /* Skip dead monsters */
543 if (!m_ptr->r_idx) continue;
545 /* Extract real monster race */
546 r_ptr = real_r_ptr(m_ptr);
548 /* Memorize location of the unique monster */
549 if ((r_ptr->flags1 & RF1_UNIQUE) ||
550 (r_ptr->flags7 & RF7_UNIQUE_7))
552 r_ptr->floor_id = cur_floor_id;
556 /* Maintain artifatcs */
557 for (i = 1; i < o_max; i++)
559 object_type *o_ptr = &o_list[i];
561 /* Skip dead objects */
562 if (!o_ptr->k_idx) continue;
564 /* Memorize location of the artifact */
565 if (artifact_p(o_ptr))
567 a_info[o_ptr->name1].floor_id = cur_floor_id;
574 * When a monster is at a place where player will return,
575 * Get out of the my way!
577 static void get_out_monster(void)
583 int m_idx = cave[oy][ox].m_idx;
585 /* Nothing to do if no monster */
588 /* Look until done */
593 /* Pick a (possibly illegal) location */
594 int ny = rand_spread(oy, dis);
595 int nx = rand_spread(ox, dis);
599 /* Stop after 1000 tries */
600 if (tries > 10000) return;
603 * Increase distance after doing enough tries
604 * compared to area of possible space
606 if (tries > 20 * dis * dis) dis++;
608 /* Ignore illegal locations */
609 if (!in_bounds(ny, nx)) continue;
611 /* Require "empty" floor space */
612 if (!cave_empty_bold(ny, nx)) continue;
614 /* Hack -- no teleport onto glyph of warding */
615 if (is_glyph_grid(&cave[ny][nx])) continue;
616 if (is_explosive_rune_grid(&cave[ny][nx])) continue;
618 /* ...nor onto the Pattern */
619 if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
620 (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2)) continue;
622 /*** It's a good place ***/
624 m_ptr = &m_list[m_idx];
626 /* Update the new location */
627 cave[ny][nx].m_idx = m_idx;
629 /* Update the old location */
630 cave[oy][ox].m_idx = 0;
632 /* Move the monster */
636 /* No need to do update_mon() */
645 * Maintain quest monsters, mark next floor_id at stairs, save current
646 * floor, and prepare to enter next floor.
648 void leave_floor(void)
650 cave_type *c_ptr = NULL;
651 saved_floor_type *sf_ptr;
654 int oy = py, ox = px;
656 /* Preserve pets and prepare to take these to next floor */
659 /* New floor is not yet prepared */
663 /* From somewhere of the surface to somewhere of the surface */
666 /* No need to save current floor */
670 /* Search the quest monster index */
671 for (i = 0; i < max_quests; i++)
673 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
674 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
675 (quest[i].type == QUEST_TYPE_RANDOM)) &&
676 (quest[i].level == dun_level) &&
677 (dungeon_type == quest[i].dungeon) &&
678 !(quest[i].flags & QUEST_FLAG_PRESET))
680 quest_r_idx = quest[i].r_idx;
684 /* Maintain quest monsters */
685 for (i = 1; i < m_max; i++)
688 monster_type *m_ptr = &m_list[i];
690 /* Skip dead monsters */
691 if (!m_ptr->r_idx) continue;
693 /* Only maintain quest monsters */
694 if (quest_r_idx != m_ptr->r_idx) continue;
696 /* Extract real monster race */
697 r_ptr = real_r_ptr(m_ptr);
699 /* Ignore unique monsters */
700 if ((r_ptr->flags1 & RF1_UNIQUE) ||
701 (r_ptr->flags7 & RF7_UNIQUE_7)) continue;
703 /* Delete non-unique quest monsters */
704 delete_monster_idx(i);
707 /* Check if there is a same item */
708 for (i = 0; i < INVEN_PACK; i++)
710 object_type *o_ptr = &inventory[i];
712 /* Skip dead objects */
713 if (!o_ptr->k_idx) continue;
715 /* Delete old memorized location of the artifact */
716 if (artifact_p(o_ptr))
718 a_info[o_ptr->name1].floor_id = 0;
722 /* Extract current floor info or NULL */
723 sf_ptr = get_sf_ptr(p_ptr->floor_id);
725 /* Choose random stairs */
726 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
728 int x, y, sx = 0, sy = 0;
734 /* Search usable stairs */
735 for (y = 0; y < cur_hgt; y++)
737 for (x = 0; x < cur_wid; x++)
739 cave_type *c_ptr = &cave[y][x];
742 if (change_floor_mode & CFM_UP)
744 /* Found fixed stairs */
745 if (c_ptr->special &&
746 c_ptr->special == sf_ptr->upper_floor_id)
752 if (c_ptr->feat == FEAT_LESS ||
753 c_ptr->feat == FEAT_LESS_LESS)
756 else if (change_floor_mode & CFM_DOWN)
758 /* Found fixed stairs */
759 if (c_ptr->special &&
760 c_ptr->special == sf_ptr->lower_floor_id)
766 if (c_ptr->feat == FEAT_MORE ||
767 c_ptr->feat == FEAT_MORE_MORE)
788 /* No stairs found! -- No return */
789 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
791 /* Mega Hack -- It's not the stairs you enter. Disable it. */
792 cave[py][px].special = 0;
796 /* Choose random one */
799 /* Point stair location */
805 /* Extract new dungeon level */
806 if (!(change_floor_mode & CFM_CLEAR_ALL))
810 /* Extract stair position */
811 c_ptr = &cave[py][px];
813 /* Get back to old saved floor? */
814 if (dun_level && c_ptr->special && get_sf_ptr(c_ptr->special))
816 /* Saved floor is exist. Use it. */
817 new_floor_id = c_ptr->special;
820 /* Extract level movement number */
821 if (change_floor_mode & CFM_DOWN) move_num = 1;
822 else if (change_floor_mode & CFM_UP) move_num = -1;
824 /* Mark shaft up/down */
825 if (c_ptr->feat == FEAT_LESS_LESS ||
826 c_ptr->feat == FEAT_MORE_MORE)
828 prepare_change_floor_mode(CFM_SHAFT);
829 move_num += SGN(move_num);
832 /* Get out from or Enter the dungeon */
833 if (change_floor_mode & CFM_DOWN)
836 move_num = d_info[c_ptr->special].mindepth;
838 else if (change_floor_mode & CFM_UP)
840 if (dun_level + move_num < d_info[dungeon_type].mindepth)
841 move_num = -dun_level;
844 dun_level += move_num;
847 /* Leaving the dungeon to town */
848 if (!dun_level && dungeon_type)
850 p_ptr->leaving_dungeon = TRUE;
851 if (!vanilla_town && !lite_town)
853 p_ptr->wilderness_y = d_info[dungeon_type].dy;
854 p_ptr->wilderness_x = d_info[dungeon_type].dx;
856 p_ptr->recall_dungeon = dungeon_type;
859 /* Reach to the surface -- Clear all saved floors */
860 prepare_change_floor_mode(CFM_CLEAR_ALL);
863 if (change_floor_mode & CFM_CLEAR_ALL)
867 /* Kill all saved floors */
868 for (i = 0; i < MAX_SAVED_FLOORS; i++)
869 kill_saved_floor(&saved_floors[i]);
871 /* Reset visit_mark count */
872 latest_visit_mark = 1;
874 else if (change_floor_mode & CFM_NO_RETURN)
876 /* Kill current floor */
877 kill_saved_floor(sf_ptr);
880 /* No current floor -- Left/Enter dungeon etc... */
881 if (!p_ptr->floor_id)
883 /* No longer need to save current floor */
888 /* Mark next floor_id on the previous floor */
892 new_floor_id = get_new_floor_id();
894 /* Connect from here */
897 c_ptr->special = new_floor_id;
900 /* Record new dungeon level */
901 get_sf_ptr(new_floor_id)->dun_level = dun_level;
904 /* Fix connection -- level teleportation or trap door */
905 if (change_floor_mode & CFM_RAND_CONNECT)
907 if (change_floor_mode & CFM_UP)
908 sf_ptr->upper_floor_id = new_floor_id;
909 else if (change_floor_mode & CFM_DOWN)
910 sf_ptr->lower_floor_id = new_floor_id;
913 /* If you can return, you need to save previous floor */
914 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)))
919 /* Get out of the my way! */
922 /* Record the last visit turn of current floor */
923 sf_ptr->last_visit = turn;
925 /* Hack -- Before visual update */
929 /* Forget the lite */
932 /* Forget the view */
935 /* Forget the view */
938 /* Hack -- After visual update */
942 /* Save current floor */
943 if (!save_floor(sf_ptr, 0))
945 /* Save failed -- No return */
946 prepare_change_floor_mode(CFM_NO_RETURN);
948 /* Kill current floor */
949 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
956 * Enter new floor. If the floor is an old saved floor, it will be
957 * restored from the temporal file. If the floor is new one, new cave
960 void change_floor(void)
962 saved_floor_type *sf_ptr;
965 /* The dungeon is not ready */
966 character_dungeon = FALSE;
968 /* No longer in the trap detecteded region */
969 p_ptr->dtrap = FALSE;
971 /* Mega-Hack -- no panel yet */
977 /* Mega-Hack -- not ambushed on the wildness? */
986 /* Paranoia -- Now on the surface */
993 /* No floor_id yet */
997 new_floor_id = get_new_floor_id();
1000 /* Pointer for infomations of new floor */
1001 sf_ptr = get_sf_ptr(new_floor_id);
1003 /* Try to restore old floor */
1004 if (sf_ptr->last_visit)
1006 /* Old saved floor is exist */
1007 if (load_floor(sf_ptr, 0))
1011 /* Forbid return stairs */
1012 if (change_floor_mode & CFM_NO_RETURN)
1014 cave_type *c_ptr = &cave[py][px];
1016 /* Reset to floor */
1017 place_floor_grid(c_ptr);
1024 * Set lower/upper_floor_id of new floor when the new
1025 * floor is right-above/right-under the current floor.
1027 * Stair creation/Teleport level/Trap door will take
1028 * you the same floor when you used it later again.
1030 if (p_ptr->floor_id)
1032 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1034 if (change_floor_mode & CFM_UP)
1036 /* New floor is right-above */
1037 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1038 sf_ptr->lower_floor_id = p_ptr->floor_id;
1040 else if (change_floor_mode & CFM_DOWN)
1042 /* New floor is right-under */
1043 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1044 sf_ptr->upper_floor_id = p_ptr->floor_id;
1048 /* Maintain monsters and artifacts */
1052 s32b absence_ticks = (turn - sf_ptr->last_visit) / TURNS_PER_TICK;
1053 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
1056 /* Maintain monsters */
1057 for (i = 1; i < m_max; i++)
1059 monster_race *r_ptr;
1060 monster_type *m_ptr = &m_list[i];
1062 /* Skip dead monsters */
1063 if (!m_ptr->r_idx) continue;
1068 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1073 /* Remove invulnerability */
1074 m_ptr->invulner = 0;
1076 /* Remove fast status */
1079 /* Remove slow status */
1085 /* Remove confusion */
1086 m_ptr->confused = 0;
1089 /* Extract real monster race */
1090 r_ptr = real_r_ptr(m_ptr);
1092 /* Ignore non-unique */
1093 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1094 !(r_ptr->flags7 & RF7_UNIQUE_7)) continue;
1096 /* Appear at a different floor? */
1097 if (r_ptr->floor_id != new_floor_id)
1099 /* Disapper from here */
1100 delete_monster_idx(i);
1104 /* Maintain artifatcs */
1105 for (i = 1; i < o_max; i++)
1107 object_type *o_ptr = &o_list[i];
1109 /* Skip dead objects */
1110 if (!o_ptr->k_idx) continue;
1112 /* Ignore non-artifact */
1113 if (!artifact_p(o_ptr)) continue;
1115 /* Appear at a different floor? */
1116 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1118 /* Disappear from here */
1119 delete_object_idx(i);
1123 /* Cancel preserve */
1124 a_info[o_ptr->name1].cur_num = 1;
1128 place_quest_monsters();
1130 /* Place some random monsters */
1131 alloc_times = absence_ticks / alloc_chance;
1133 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1136 for (i = 0; i < alloc_times; i++)
1138 /* Make a (group of) new monster */
1139 (void)alloc_monster(0, 0);
1143 /* New floor_id or failed to restore */
1144 else /* if (!loaded) */
1146 if (sf_ptr->last_visit)
1148 /* Temporal file is broken? */
1150 msg_print("³¬ÃʤϹԤ»ß¤Þ¤ê¤À¤Ã¤¿¡£");
1152 msg_print("The staircases come to a dead end...");
1155 /* Create simple dead end */
1158 /* Break connection */
1159 if (change_floor_mode & CFM_UP)
1161 sf_ptr->upper_floor_id = 0;
1163 else if (change_floor_mode & CFM_DOWN)
1165 sf_ptr->lower_floor_id = 0;
1170 /* Newly create cave */
1174 /* Record last visit turn */
1175 sf_ptr->last_visit = turn;
1177 /* Set correct dun_level value */
1178 sf_ptr->dun_level = dun_level;
1180 /* Creat connected stairs */
1181 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)) && dun_level)
1185 /* Extract stair position */
1186 cave_type *c_ptr = &cave[py][px];
1188 /*** Create connected stairs ***/
1190 /* No stairs down from Quest */
1191 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1193 if (change_floor_mode & CFM_SHAFT)
1194 c_ptr->feat = FEAT_MORE_MORE;
1196 c_ptr->feat = FEAT_MORE;
1199 /* No stairs up when ironman_downward */
1200 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1202 if (change_floor_mode & CFM_SHAFT)
1203 c_ptr->feat = FEAT_LESS_LESS;
1205 c_ptr->feat = FEAT_LESS;
1215 /* Paranoia -- Clear mimic */
1218 /* Connect to previous floor */
1219 c_ptr->special = p_ptr->floor_id;
1224 /* Arrive at random grid */
1225 if (change_floor_mode & (CFM_RAND_PLACE))
1227 (void)new_player_spot();
1230 /* You see stairs blocked */
1231 else if (change_floor_mode & CFM_NO_RETURN)
1236 msg_print("ÆÍÁ³³¬Ãʤ¬ºÉ¤¬¤ì¤Æ¤·¤Þ¤Ã¤¿¡£");
1238 msg_print("Suddenly the stairs is blocked!");
1244 msg_print("¥´¥È¥´¥È¤È²¿¤«²»¤¬¤·¤¿¡£");
1246 msg_print("You hear some noises.");
1254 * The "turn" is not always different number because
1255 * the level teleport doesn't take any turn. Use
1256 * visit mark instead of last visit turn to find the
1257 * oldest saved floor.
1259 sf_ptr->visit_mark = latest_visit_mark++;
1262 /* Place preserved pet monsters */
1265 /* Hack -- maintain unique and artifacts */
1266 update_unique_artifact(new_floor_id);
1268 /* Now the player is in new floor */
1269 p_ptr->floor_id = new_floor_id;
1271 /* The dungeon is ready */
1272 character_dungeon = TRUE;
1274 /* Hack -- Munchkin characters always get whole map */
1275 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1276 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1278 /* Remember when this level was "created" */
1281 /* Clear all flags */
1282 change_floor_mode = 0L;
1288 * Create stairs at or move previously created stairs into the player
1291 void stair_creation(void)
1293 saved_floor_type *sf_ptr;
1294 saved_floor_type *dest_sf_ptr;
1298 s16b dest_floor_id = 0;
1301 /* Forbid up staircases on Ironman mode */
1302 if (ironman_downward) up = FALSE;
1304 /* Forbid down staircases on quest level */
1305 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1307 /* No effect out of standard dungeon floor */
1308 if (!dun_level || (!up && !down) ||
1309 (p_ptr->inside_quest && (p_ptr->inside_quest < MIN_RANDOM_QUEST)) ||
1310 p_ptr->inside_arena || p_ptr->inside_battle)
1312 /* arena or quest */
1314 msg_print("¸ú²Ì¤¬¤¢¤ê¤Þ¤»¤ó¡ª");
1316 msg_print("There is no effect!");
1321 /* Artifacts resists */
1322 if (!cave_valid_bold(py, px))
1325 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1327 msg_print("The object resists the spell.");
1333 /* Destroy all objects in the grid */
1334 delete_object(py, px);
1336 /* Extract current floor data */
1337 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1339 /* Choose randomly */
1342 if (randint0(100) < 50) up = FALSE;
1346 /* Destination is already fixed */
1349 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1353 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1357 /* Search old stairs leading to the destination */
1362 for (y = 0; y < cur_hgt; y++)
1364 for (x = 0; x < cur_wid; x++)
1366 cave_type *c_ptr = &cave[y][x];
1368 if (!c_ptr->special) continue;
1369 if (c_ptr->special != dest_floor_id) continue;
1371 /* Remove old stairs */
1373 cave_set_feat(y, x, floor_type[randint0(100)]);
1378 /* No old destination -- Get new one now */
1381 dest_floor_id = get_new_floor_id();
1385 sf_ptr->upper_floor_id = dest_floor_id;
1387 sf_ptr->lower_floor_id = dest_floor_id;
1390 /* Extract destination floor data */
1391 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1394 /* Create a staircase */
1397 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level <= dun_level - 2)
1398 cave_set_feat(py, px, FEAT_LESS_LESS);
1400 cave_set_feat(py, px, FEAT_LESS);
1404 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level >= dun_level + 2)
1405 cave_set_feat(py, px, FEAT_MORE_MORE);
1407 cave_set_feat(py, px, FEAT_MORE);
1411 /* Connect this stairs to the destination */
1412 cave[py][px].special = dest_floor_id;