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 < MAX_PARTY_MON; num++)
347 party_mon[num].r_idx = 0;
352 monster_type *m_ptr = &m_list[p_ptr->riding];
354 /* Pet of other pet don't follow. */
355 if (m_ptr->parent_m_idx)
358 p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
359 p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
363 /* Preserve the mount */
364 COPY(&party_mon[0], m_ptr, monster_type);
366 /* Delete from this floor */
367 delete_monster_idx(p_ptr->riding);
372 * If player is in wild mode, no pets are preserved
373 * except a monster whom player riding
375 if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->inside_battle)
377 for (i = m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
379 monster_type *m_ptr = &m_list[i];
381 if (!m_ptr->r_idx) continue;
382 if (!is_pet(m_ptr)) continue;
383 if (i == p_ptr->riding) continue;
385 if (reinit_wilderness)
387 /* Don't lose sight of pets when getting a Quest */
391 int dis = distance(py, px, m_ptr->fy, m_ptr->fx);
393 /* Confused (etc.) monsters don't follow. */
394 if (m_ptr->confused || m_ptr->stunned || m_ptr->csleep) continue;
396 /* Pet of other pet don't follow. */
397 if (m_ptr->parent_m_idx) continue;
400 * Pets with nickname will follow even from 3 blocks away
401 * when you or the pet can see the other.
403 if (m_ptr->nickname &&
404 (player_has_los_bold(m_ptr->fy, m_ptr->fx) ||
405 los(m_ptr->fy, m_ptr->fx, py, px)))
407 if (dis > 3) continue;
411 if (dis > 1) continue;
415 COPY(&party_mon[num], &m_list[i], monster_type);
419 /* Delete from this floor */
420 delete_monster_idx(i);
424 if (record_named_pet)
426 for (i = m_max - 1; i >=1; i--)
428 monster_type *m_ptr = &m_list[i];
431 if (!m_ptr->r_idx) continue;
432 if (!is_pet(m_ptr)) continue;
433 if (!m_ptr->nickname) continue;
434 if (p_ptr->riding == i) continue;
436 monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
437 do_cmd_write_nikki(NIKKI_NAMED_PET, 4, m_name);
442 /* Pet of other pet may disappear. */
443 for (i = m_max - 1; i >=1; i--)
445 monster_type *m_ptr = &m_list[i];
447 /* Are there its parent? */
448 if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
450 /* Its parent have gone, it also goes away. */
456 /* Acquire the monster name */
457 monster_desc(m_name, m_ptr, 0);
460 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
462 msg_format("%^s disappears!", m_name);
466 /* Delete the monster */
467 delete_monster_idx(i);
474 * Pre-calculate the racial counters of preserved pets
475 * To prevent multiple generation of unique monster who is the minion of player
477 void precalc_cur_num_of_pet(void)
481 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
483 for (i = 0; i < max_num; i++)
485 m_ptr = &party_mon[i];
487 /* Skip empty monsters */
488 if (!m_ptr->r_idx) continue;
490 /* Hack -- Increase the racial counter */
491 real_r_ptr(m_ptr)->cur_num++;
497 * Place preserved pet monsters on new floor
499 static void place_pet(void)
502 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
504 for (i = 0; i < max_num; i++)
508 if (!(party_mon[i].r_idx)) continue;
513 p_ptr->riding = m_idx;
524 for (d = 1; d < 6; d++)
526 for (j = 1000; j > 0; j--)
528 scatter(&cy, &cx, py, px, d, 0);
529 if ((cave_floor_bold(cy, cx) || (cave[cy][cx].feat == FEAT_TREES)) && !cave[cy][cx].m_idx && !player_bold(cy, cx)) break;
533 m_idx = (d == 6) ? 0 : m_pop();
538 monster_type *m_ptr = &m_list[m_idx];
541 cave[cy][cx].m_idx = m_idx;
543 m_ptr->r_idx = party_mon[i].r_idx;
545 /* Copy all member of the structure */
546 *m_ptr = party_mon[i];
547 r_ptr = real_r_ptr(m_ptr);
555 m_ptr->hold_o_idx = 0;
558 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
560 /* Monster is still being nice */
561 m_ptr->mflag |= (MFLAG_NICE);
563 /* Must repair monsters */
564 repair_monsters = TRUE;
567 /* Update the monster */
568 update_mon(m_idx, TRUE);
571 /* Pre-calculated in precalc_cur_num_of_pet() */
572 /* r_ptr->cur_num++; */
574 /* Hack -- Count the number of "reproducers" */
575 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
577 /* Hack -- Notice new multi-hued monsters */
579 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
580 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
581 shimmer_monsters = TRUE;
586 monster_type *m_ptr = &party_mon[i];
587 monster_race *r_ptr = real_r_ptr(m_ptr);
590 monster_desc(m_name, m_ptr, 0);
592 msg_format("%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£", m_name);
594 msg_format("You have lost sight of %s.", m_name);
596 if (record_named_pet && m_ptr->nickname)
598 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
599 do_cmd_write_nikki(NIKKI_NAMED_PET, 5, m_name);
602 /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
603 if (r_ptr->cur_num) r_ptr->cur_num--;
607 /* For accuracy of precalc_cur_num_of_pet() */
608 C_WIPE(party_mon, MAX_PARTY_MON, monster_type);
613 * Hack -- Update location of unique monsters and artifacts
615 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly
616 * while new floor creation since dungeons may be re-created by
619 static void update_unique_artifact(s16b cur_floor_id)
623 /* Maintain unique monsters */
624 for (i = 1; i < m_max; i++)
627 monster_type *m_ptr = &m_list[i];
629 /* Skip dead monsters */
630 if (!m_ptr->r_idx) continue;
632 /* Extract real monster race */
633 r_ptr = real_r_ptr(m_ptr);
635 /* Memorize location of the unique monster */
636 if ((r_ptr->flags1 & RF1_UNIQUE) ||
637 (r_ptr->flags7 & RF7_NAZGUL))
639 r_ptr->floor_id = cur_floor_id;
643 /* Maintain artifatcs */
644 for (i = 1; i < o_max; i++)
646 object_type *o_ptr = &o_list[i];
648 /* Skip dead objects */
649 if (!o_ptr->k_idx) continue;
651 /* Memorize location of the artifact */
652 if (artifact_p(o_ptr))
654 a_info[o_ptr->name1].floor_id = cur_floor_id;
661 * When a monster is at a place where player will return,
662 * Get out of the my way!
664 static void get_out_monster(void)
670 int m_idx = cave[oy][ox].m_idx;
672 /* Nothing to do if no monster */
675 /* Look until done */
680 /* Pick a (possibly illegal) location */
681 int ny = rand_spread(oy, dis);
682 int nx = rand_spread(ox, dis);
686 /* Stop after 1000 tries */
687 if (tries > 10000) return;
690 * Increase distance after doing enough tries
691 * compared to area of possible space
693 if (tries > 20 * dis * dis) dis++;
695 /* Ignore illegal locations */
696 if (!in_bounds(ny, nx)) continue;
698 /* Require "empty" floor space */
699 if (!cave_empty_bold(ny, nx)) continue;
701 /* Hack -- no teleport onto glyph of warding */
702 if (is_glyph_grid(&cave[ny][nx])) continue;
703 if (is_explosive_rune_grid(&cave[ny][nx])) continue;
705 /* ...nor onto the Pattern */
706 if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
707 (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2)) continue;
709 /*** It's a good place ***/
711 m_ptr = &m_list[m_idx];
713 /* Update the new location */
714 cave[ny][nx].m_idx = m_idx;
716 /* Update the old location */
717 cave[oy][ox].m_idx = 0;
719 /* Move the monster */
723 /* No need to do update_mon() */
732 * Maintain quest monsters, mark next floor_id at stairs, save current
733 * floor, and prepare to enter next floor.
735 void leave_floor(void)
737 cave_type *c_ptr = NULL;
738 saved_floor_type *sf_ptr;
742 /* Preserve pets and prepare to take these to next floor */
745 /* Remove all mirrors without explosion */
746 remove_all_mirrors(FALSE);
748 /* New floor is not yet prepared */
752 /* From somewhere of the surface to somewhere of the surface */
755 if (change_floor_mode & CFM_SAVE_SURFACE)
757 /* Save surface floor to preserve pets (for Arena) */
758 if (!p_ptr->floor_id)
760 /* Get temporal floor_id */
761 p_ptr->floor_id = get_new_floor_id();
763 /* Record the dungeon level */
764 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
769 /* No need to save current floor */
774 /* Search the quest monster index */
775 for (i = 0; i < max_quests; i++)
777 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
778 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
779 (quest[i].type == QUEST_TYPE_RANDOM)) &&
780 (quest[i].level == dun_level) &&
781 (dungeon_type == quest[i].dungeon) &&
782 !(quest[i].flags & QUEST_FLAG_PRESET))
784 quest_r_idx = quest[i].r_idx;
788 /* Maintain quest monsters */
789 for (i = 1; i < m_max; i++)
792 monster_type *m_ptr = &m_list[i];
794 /* Skip dead monsters */
795 if (!m_ptr->r_idx) continue;
797 /* Only maintain quest monsters */
798 if (quest_r_idx != m_ptr->r_idx) continue;
800 /* Extract real monster race */
801 r_ptr = real_r_ptr(m_ptr);
803 /* Ignore unique monsters */
804 if ((r_ptr->flags1 & RF1_UNIQUE) ||
805 (r_ptr->flags7 & RF7_NAZGUL)) continue;
807 /* Delete non-unique quest monsters */
808 delete_monster_idx(i);
811 /* Check if there is a same item */
812 for (i = 0; i < INVEN_PACK; i++)
814 object_type *o_ptr = &inventory[i];
816 /* Skip dead objects */
817 if (!o_ptr->k_idx) continue;
819 /* Delete old memorized location of the artifact */
820 if (artifact_p(o_ptr))
822 a_info[o_ptr->name1].floor_id = 0;
826 /* Extract current floor info or NULL */
827 sf_ptr = get_sf_ptr(p_ptr->floor_id);
829 /* Choose random stairs */
830 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
832 int x, y, sx = 0, sy = 0;
838 /* Search usable stairs */
839 for (y = 0; y < cur_hgt; y++)
841 for (x = 0; x < cur_wid; x++)
843 cave_type *c_ptr = &cave[y][x];
846 if (change_floor_mode & CFM_UP)
848 /* Found fixed stairs */
849 if (c_ptr->special &&
850 c_ptr->special == sf_ptr->upper_floor_id)
856 if (c_ptr->feat == FEAT_LESS ||
857 c_ptr->feat == FEAT_LESS_LESS)
860 else if (change_floor_mode & CFM_DOWN)
862 /* Found fixed stairs */
863 if (c_ptr->special &&
864 c_ptr->special == sf_ptr->lower_floor_id)
870 if (c_ptr->feat == FEAT_MORE ||
871 c_ptr->feat == FEAT_MORE_MORE)
892 /* No stairs found! -- No return */
893 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
895 /* Mega Hack -- It's not the stairs you enter. Disable it. */
896 cave[py][px].special = 0;
900 /* Choose random one */
903 /* Point stair location */
909 /* Extract new dungeon level */
910 if (!(change_floor_mode & CFM_CLEAR_ALL))
914 /* Extract stair position */
915 c_ptr = &cave[py][px];
917 /* Get back to old saved floor? */
918 if ((dun_level || (change_floor_mode & CFM_SAVE_SURFACE))
919 && c_ptr->special && get_sf_ptr(c_ptr->special))
921 /* Saved floor is exist. Use it. */
922 new_floor_id = c_ptr->special;
925 /* Extract level movement number */
926 if (change_floor_mode & CFM_DOWN) move_num = 1;
927 else if (change_floor_mode & CFM_UP) move_num = -1;
929 /* Mark shaft up/down */
930 if (c_ptr->feat == FEAT_LESS_LESS ||
931 c_ptr->feat == FEAT_MORE_MORE)
933 prepare_change_floor_mode(CFM_SHAFT);
934 move_num += SGN(move_num);
937 /* Get out from or Enter the dungeon */
938 if (change_floor_mode & CFM_DOWN)
941 move_num = d_info[c_ptr->special].mindepth;
943 else if (change_floor_mode & CFM_UP)
945 if (dun_level + move_num < d_info[dungeon_type].mindepth)
946 move_num = -dun_level;
949 dun_level += move_num;
952 /* Leaving the dungeon to town */
953 if (!dun_level && dungeon_type)
955 p_ptr->leaving_dungeon = TRUE;
956 if (!vanilla_town && !lite_town)
958 p_ptr->wilderness_y = d_info[dungeon_type].dy;
959 p_ptr->wilderness_x = d_info[dungeon_type].dx;
961 p_ptr->recall_dungeon = dungeon_type;
964 /* Reach to the surface -- Clear all saved floors */
965 prepare_change_floor_mode(CFM_CLEAR_ALL);
968 if (change_floor_mode & CFM_CLEAR_ALL)
972 /* Kill all saved floors */
973 for (i = 0; i < MAX_SAVED_FLOORS; i++)
974 kill_saved_floor(&saved_floors[i]);
976 /* Reset visit_mark count */
977 latest_visit_mark = 1;
979 else if (change_floor_mode & CFM_NO_RETURN)
981 /* Kill current floor */
982 kill_saved_floor(sf_ptr);
985 /* No current floor -- Left/Enter dungeon etc... */
986 if (!p_ptr->floor_id)
988 /* No longer need to save current floor */
993 /* Mark next floor_id on the previous floor */
997 new_floor_id = get_new_floor_id();
999 /* Connect from here */
1002 c_ptr->special = new_floor_id;
1005 /* Record new dungeon level */
1006 get_sf_ptr(new_floor_id)->dun_level = dun_level;
1009 /* Fix connection -- level teleportation or trap door */
1010 if (change_floor_mode & CFM_RAND_CONNECT)
1012 if (change_floor_mode & CFM_UP)
1013 sf_ptr->upper_floor_id = new_floor_id;
1014 else if (change_floor_mode & CFM_DOWN)
1015 sf_ptr->lower_floor_id = new_floor_id;
1018 /* If you can return, you need to save previous floor */
1019 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)))
1021 /* Get out of the my way! */
1024 /* Record the last visit turn of current floor */
1025 sf_ptr->last_visit = turn;
1027 /* Forget the lite */
1030 /* Forget the view */
1033 /* Forget the view */
1036 /* Save current floor */
1037 if (!save_floor(sf_ptr, 0))
1039 /* Save failed -- No return */
1040 prepare_change_floor_mode(CFM_NO_RETURN);
1042 /* Kill current floor */
1043 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
1050 * Enter new floor. If the floor is an old saved floor, it will be
1051 * restored from the temporal file. If the floor is new one, new cave
1052 * will be generated.
1054 void change_floor(void)
1056 saved_floor_type *sf_ptr;
1057 bool loaded = FALSE;
1059 /* The dungeon is not ready */
1060 character_dungeon = FALSE;
1062 /* No longer in the trap detecteded region */
1063 p_ptr->dtrap = FALSE;
1065 /* Mega-Hack -- no panel yet */
1071 /* Mega-Hack -- not ambushed on the wildness? */
1072 ambush_flag = FALSE;
1074 /* On the surface */
1075 if (!dungeon_type && !(change_floor_mode & CFM_SAVE_SURFACE))
1080 /* Paranoia -- Now on the surface */
1084 /* In the dungeon */
1087 /* No floor_id yet */
1091 new_floor_id = get_new_floor_id();
1094 /* Pointer for infomations of new floor */
1095 sf_ptr = get_sf_ptr(new_floor_id);
1097 /* Try to restore old floor */
1098 if (sf_ptr->last_visit)
1100 /* Old saved floor is exist */
1101 if (load_floor(sf_ptr, 0))
1105 /* Forbid return stairs */
1106 if (change_floor_mode & CFM_NO_RETURN)
1108 cave_type *c_ptr = &cave[py][px];
1110 if (change_floor_mode & (CFM_DOWN | CFM_UP))
1112 /* Reset to floor */
1113 c_ptr->feat = floor_type[randint0(100)];
1122 * Set lower/upper_floor_id of new floor when the new
1123 * floor is right-above/right-under the current floor.
1125 * Stair creation/Teleport level/Trap door will take
1126 * you the same floor when you used it later again.
1128 if (p_ptr->floor_id)
1130 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1132 if (change_floor_mode & CFM_UP)
1134 /* New floor is right-above */
1135 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1136 sf_ptr->lower_floor_id = p_ptr->floor_id;
1138 else if (change_floor_mode & CFM_DOWN)
1140 /* New floor is right-under */
1141 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1142 sf_ptr->upper_floor_id = p_ptr->floor_id;
1146 /* Maintain monsters and artifacts */
1150 s32b absence_ticks = (turn - sf_ptr->last_visit) / TURNS_PER_TICK;
1151 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
1154 /* Maintain monsters */
1155 for (i = 1; i < m_max; i++)
1157 monster_race *r_ptr;
1158 monster_type *m_ptr = &m_list[i];
1160 /* Skip dead monsters */
1161 if (!m_ptr->r_idx) continue;
1166 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1171 /* Remove invulnerability */
1172 m_ptr->invulner = 0;
1174 /* Remove fast status */
1177 /* Remove slow status */
1183 /* Remove confusion */
1184 m_ptr->confused = 0;
1187 /* Extract real monster race */
1188 r_ptr = real_r_ptr(m_ptr);
1190 /* Ignore non-unique */
1191 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1192 !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1194 /* Appear at a different floor? */
1195 if (r_ptr->floor_id != new_floor_id)
1197 /* Disapper from here */
1198 delete_monster_idx(i);
1202 /* Maintain artifatcs */
1203 for (i = 1; i < o_max; i++)
1205 object_type *o_ptr = &o_list[i];
1207 /* Skip dead objects */
1208 if (!o_ptr->k_idx) continue;
1210 /* Ignore non-artifact */
1211 if (!artifact_p(o_ptr)) continue;
1213 /* Appear at a different floor? */
1214 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1216 /* Disappear from here */
1217 delete_object_idx(i);
1221 /* Cancel preserve */
1222 a_info[o_ptr->name1].cur_num = 1;
1226 place_quest_monsters();
1228 /* Place some random monsters */
1229 alloc_times = absence_ticks / alloc_chance;
1231 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1234 for (i = 0; i < alloc_times; i++)
1236 /* Make a (group of) new monster */
1237 (void)alloc_monster(0, 0);
1241 /* New floor_id or failed to restore */
1242 else /* if (!loaded) */
1244 if (sf_ptr->last_visit)
1246 /* Temporal file is broken? */
1248 msg_print("³¬ÃʤϹԤ»ß¤Þ¤ê¤À¤Ã¤¿¡£");
1250 msg_print("The staircases come to a dead end...");
1253 /* Create simple dead end */
1256 /* Break connection */
1257 if (change_floor_mode & CFM_UP)
1259 sf_ptr->upper_floor_id = 0;
1261 else if (change_floor_mode & CFM_DOWN)
1263 sf_ptr->lower_floor_id = 0;
1268 /* Newly create cave */
1272 /* Record last visit turn */
1273 sf_ptr->last_visit = turn;
1275 /* Set correct dun_level value */
1276 sf_ptr->dun_level = dun_level;
1278 /* Creat connected stairs */
1279 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL))
1280 && (dun_level || (change_floor_mode & CFM_SAVE_SURFACE)))
1284 /* Extract stair position */
1285 cave_type *c_ptr = &cave[py][px];
1287 /*** Create connected stairs ***/
1289 /* No stairs down from Quest */
1290 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1292 if (change_floor_mode & CFM_SHAFT)
1293 c_ptr->feat = FEAT_MORE_MORE;
1295 c_ptr->feat = FEAT_MORE;
1298 /* No stairs up when ironman_downward */
1299 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1301 if (change_floor_mode & CFM_SHAFT)
1302 c_ptr->feat = FEAT_LESS_LESS;
1304 c_ptr->feat = FEAT_LESS;
1307 /* Enter to/leave the Arena */
1308 else if (change_floor_mode & CFM_SAVE_SURFACE)
1321 /* Paranoia -- Clear mimic */
1324 /* Connect to previous floor */
1325 c_ptr->special = p_ptr->floor_id;
1330 /* Arrive at random grid */
1331 if (change_floor_mode & (CFM_RAND_PLACE))
1333 (void)new_player_spot();
1336 /* You see stairs blocked */
1337 else if ((change_floor_mode & CFM_NO_RETURN) &&
1338 (change_floor_mode & (CFM_DOWN | CFM_UP)))
1343 msg_print("ÆÍÁ³³¬Ãʤ¬ºÉ¤¬¤ì¤Æ¤·¤Þ¤Ã¤¿¡£");
1345 msg_print("Suddenly the stairs is blocked!");
1351 msg_print("¥´¥È¥´¥È¤È²¿¤«²»¤¬¤·¤¿¡£");
1353 msg_print("You hear some noises.");
1361 * The "turn" is not always different number because
1362 * the level teleport doesn't take any turn. Use
1363 * visit mark instead of last visit turn to find the
1364 * oldest saved floor.
1366 sf_ptr->visit_mark = latest_visit_mark++;
1369 /* Place preserved pet monsters */
1372 /* Hack -- maintain unique and artifacts */
1373 update_unique_artifact(new_floor_id);
1375 /* Now the player is in new floor */
1376 p_ptr->floor_id = new_floor_id;
1378 /* The dungeon is ready */
1379 character_dungeon = TRUE;
1381 /* Hack -- Munchkin characters always get whole map */
1382 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1383 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1385 /* Remember when this level was "created" */
1388 /* Clear all flags */
1389 change_floor_mode = 0L;
1395 * Create stairs at or move previously created stairs into the player
1398 void stair_creation(void)
1400 saved_floor_type *sf_ptr;
1401 saved_floor_type *dest_sf_ptr;
1405 s16b dest_floor_id = 0;
1408 /* Forbid up staircases on Ironman mode */
1409 if (ironman_downward) up = FALSE;
1411 /* Forbid down staircases on quest level */
1412 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1414 /* No effect out of standard dungeon floor */
1415 if (!dun_level || (!up && !down) ||
1416 (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1417 p_ptr->inside_arena || p_ptr->inside_battle)
1419 /* arena or quest */
1421 msg_print("¸ú²Ì¤¬¤¢¤ê¤Þ¤»¤ó¡ª");
1423 msg_print("There is no effect!");
1428 /* Artifacts resists */
1429 if (!cave_valid_bold(py, px))
1432 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1434 msg_print("The object resists the spell.");
1440 /* Destroy all objects in the grid */
1441 delete_object(py, px);
1443 /* Extract current floor data */
1444 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1446 /* Choose randomly */
1449 if (randint0(100) < 50) up = FALSE;
1453 /* Destination is already fixed */
1456 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1460 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1464 /* Search old stairs leading to the destination */
1469 for (y = 0; y < cur_hgt; y++)
1471 for (x = 0; x < cur_wid; x++)
1473 cave_type *c_ptr = &cave[y][x];
1475 if (!c_ptr->special) continue;
1476 if (c_ptr->special != dest_floor_id) continue;
1478 /* Remove old stairs */
1480 cave_set_feat(y, x, floor_type[randint0(100)]);
1485 /* No old destination -- Get new one now */
1488 dest_floor_id = get_new_floor_id();
1492 sf_ptr->upper_floor_id = dest_floor_id;
1494 sf_ptr->lower_floor_id = dest_floor_id;
1497 /* Extract destination floor data */
1498 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1501 /* Create a staircase */
1504 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level <= dun_level - 2)
1505 cave_set_feat(py, px, FEAT_LESS_LESS);
1507 cave_set_feat(py, px, FEAT_LESS);
1511 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level >= dun_level + 2)
1512 cave_set_feat(py, px, FEAT_MORE_MORE);
1514 cave_set_feat(py, px, FEAT_MORE);
1518 /* Connect this stairs to the destination */
1519 cave[py][px].special = dest_floor_id;