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 * Is this feature has special meaning (except floor_id) with c_ptr->special?
734 static bool feat_uses_special(byte feat)
738 case FEAT_QUEST_ENTER:
739 case FEAT_QUEST_EXIT:
740 case FEAT_QUEST_DOWN:
752 * Maintain quest monsters, mark next floor_id at stairs, save current
753 * floor, and prepare to enter next floor.
755 void leave_floor(void)
757 cave_type *c_ptr = NULL;
758 saved_floor_type *sf_ptr;
762 /* Preserve pets and prepare to take these to next floor */
765 /* Remove all mirrors without explosion */
766 remove_all_mirrors(FALSE);
768 /* New floor is not yet prepared */
772 if (!p_ptr->floor_id)
774 if (change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL))
776 /* No need to save current floor */
781 /* Get temporal floor_id */
782 p_ptr->floor_id = get_new_floor_id();
784 /* Record the dungeon level */
785 get_sf_ptr(p_ptr->floor_id)->dun_level = dun_level;
790 /* Search the quest monster index */
791 for (i = 0; i < max_quests; i++)
793 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
794 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
795 (quest[i].type == QUEST_TYPE_RANDOM)) &&
796 (quest[i].level == dun_level) &&
797 (dungeon_type == quest[i].dungeon) &&
798 !(quest[i].flags & QUEST_FLAG_PRESET))
800 quest_r_idx = quest[i].r_idx;
804 /* Maintain quest monsters */
805 for (i = 1; i < m_max; i++)
808 monster_type *m_ptr = &m_list[i];
810 /* Skip dead monsters */
811 if (!m_ptr->r_idx) continue;
813 /* Only maintain quest monsters */
814 if (quest_r_idx != m_ptr->r_idx) continue;
816 /* Extract real monster race */
817 r_ptr = real_r_ptr(m_ptr);
819 /* Ignore unique monsters */
820 if ((r_ptr->flags1 & RF1_UNIQUE) ||
821 (r_ptr->flags7 & RF7_NAZGUL)) continue;
823 /* Delete non-unique quest monsters */
824 delete_monster_idx(i);
827 /* Check if there is a same item */
828 for (i = 0; i < INVEN_PACK; i++)
830 object_type *o_ptr = &inventory[i];
832 /* Skip dead objects */
833 if (!o_ptr->k_idx) continue;
835 /* Delete old memorized location of the artifact */
836 if (artifact_p(o_ptr))
838 a_info[o_ptr->name1].floor_id = 0;
842 /* Extract current floor info or NULL */
843 sf_ptr = get_sf_ptr(p_ptr->floor_id);
845 /* Choose random stairs */
846 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
848 int x, y, sx = 0, sy = 0;
854 /* Search usable stairs */
855 for (y = 0; y < cur_hgt; y++)
857 for (x = 0; x < cur_wid; x++)
859 cave_type *c_ptr = &cave[y][x];
862 if (change_floor_mode & CFM_UP)
864 /* Found fixed stairs */
865 if (c_ptr->special &&
866 c_ptr->special == sf_ptr->upper_floor_id)
872 if (c_ptr->feat == FEAT_LESS ||
873 c_ptr->feat == FEAT_LESS_LESS)
876 else if (change_floor_mode & CFM_DOWN)
878 /* Found fixed stairs */
879 if (c_ptr->special &&
880 c_ptr->special == sf_ptr->lower_floor_id)
886 if (c_ptr->feat == FEAT_MORE ||
887 c_ptr->feat == FEAT_MORE_MORE)
908 /* No stairs found! -- No return */
909 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
911 /* Mega Hack -- It's not the stairs you enter. Disable it. */
912 if (!feat_uses_special(cave[py][px].feat)) cave[py][px].special = 0;
916 /* Choose random one */
919 /* Point stair location */
925 /* Extract new dungeon level */
926 if (!(change_floor_mode & CFM_CLEAR_ALL))
930 /* Extract stair position */
931 c_ptr = &cave[py][px];
933 /* Get back to old saved floor? */
934 if (c_ptr->special && !feat_uses_special(c_ptr->feat) && get_sf_ptr(c_ptr->special))
936 /* Saved floor is exist. Use it. */
937 new_floor_id = c_ptr->special;
940 /* Extract level movement number */
941 if (change_floor_mode & CFM_DOWN) move_num = 1;
942 else if (change_floor_mode & CFM_UP) move_num = -1;
944 /* Mark shaft up/down */
945 if (c_ptr->feat == FEAT_LESS_LESS ||
946 c_ptr->feat == FEAT_MORE_MORE)
948 prepare_change_floor_mode(CFM_SHAFT);
949 move_num += SGN(move_num);
952 /* Get out from or Enter the dungeon */
953 if (change_floor_mode & CFM_DOWN)
955 /* Hack -- Prevent "wild to wild stair" */
957 move_num = d_info[(c_ptr->feat == FEAT_ENTRANCE) ? c_ptr->special : DUNGEON_ANGBAND].mindepth;
959 else if (change_floor_mode & CFM_UP)
961 if (dun_level + move_num < d_info[dungeon_type].mindepth)
962 move_num = -dun_level;
965 dun_level += move_num;
968 /* Leaving the dungeon to town */
969 if (!dun_level && dungeon_type)
971 p_ptr->leaving_dungeon = TRUE;
972 if (!vanilla_town && !lite_town)
974 p_ptr->wilderness_y = d_info[dungeon_type].dy;
975 p_ptr->wilderness_x = d_info[dungeon_type].dx;
977 p_ptr->recall_dungeon = dungeon_type;
980 /* Reach to the surface -- Clear all saved floors */
981 prepare_change_floor_mode(CFM_CLEAR_ALL);
984 if (change_floor_mode & CFM_CLEAR_ALL)
988 /* Kill all saved floors */
989 for (i = 0; i < MAX_SAVED_FLOORS; i++)
990 kill_saved_floor(&saved_floors[i]);
992 /* Reset visit_mark count */
993 latest_visit_mark = 1;
995 else if (change_floor_mode & CFM_NO_RETURN)
997 /* Kill current floor */
998 kill_saved_floor(sf_ptr);
1001 /* No current floor -- Left/Enter dungeon etc... */
1002 if (!p_ptr->floor_id)
1004 /* No longer need to save current floor */
1009 /* Mark next floor_id on the previous floor */
1013 new_floor_id = get_new_floor_id();
1015 /* Connect from here */
1016 if (c_ptr && !feat_uses_special(c_ptr->feat))
1018 c_ptr->special = new_floor_id;
1021 /* Record new dungeon level */
1022 get_sf_ptr(new_floor_id)->dun_level = dun_level;
1025 /* Fix connection -- level teleportation or trap door */
1026 if (change_floor_mode & CFM_RAND_CONNECT)
1028 if (change_floor_mode & CFM_UP)
1029 sf_ptr->upper_floor_id = new_floor_id;
1030 else if (change_floor_mode & CFM_DOWN)
1031 sf_ptr->lower_floor_id = new_floor_id;
1034 /* If you can return, you need to save previous floor */
1035 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)))
1037 /* Get out of the my way! */
1040 /* Record the last visit turn of current floor */
1041 sf_ptr->last_visit = turn;
1043 /* Forget the lite */
1046 /* Forget the view */
1049 /* Forget the view */
1052 /* Save current floor */
1053 if (!save_floor(sf_ptr, 0))
1055 /* Save failed -- No return */
1056 prepare_change_floor_mode(CFM_NO_RETURN);
1058 /* Kill current floor */
1059 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
1066 * Enter new floor. If the floor is an old saved floor, it will be
1067 * restored from the temporal file. If the floor is new one, new cave
1068 * will be generated.
1070 void change_floor(void)
1072 saved_floor_type *sf_ptr;
1073 bool loaded = FALSE;
1075 /* The dungeon is not ready */
1076 character_dungeon = FALSE;
1078 /* No longer in the trap detecteded region */
1079 p_ptr->dtrap = FALSE;
1081 /* Mega-Hack -- no panel yet */
1087 /* Mega-Hack -- not ambushed on the wildness? */
1088 ambush_flag = FALSE;
1090 /* No saved floors (On the surface etc.) */
1091 if (change_floor_mode & CFM_CLEAR_ALL)
1096 /* Paranoia -- No new saved floor */
1100 /* In the dungeon */
1103 /* No floor_id yet */
1107 new_floor_id = get_new_floor_id();
1110 /* Pointer for infomations of new floor */
1111 sf_ptr = get_sf_ptr(new_floor_id);
1113 /* Try to restore old floor */
1114 if (sf_ptr->last_visit)
1116 /* Old saved floor is exist */
1117 if (load_floor(sf_ptr, 0))
1121 /* Forbid return stairs */
1122 if (change_floor_mode & CFM_NO_RETURN)
1124 cave_type *c_ptr = &cave[py][px];
1126 if (!feat_uses_special(c_ptr->feat))
1128 if (change_floor_mode & (CFM_DOWN | CFM_UP))
1130 /* Reset to floor */
1131 c_ptr->feat = floor_type[randint0(100)];
1141 * Set lower/upper_floor_id of new floor when the new
1142 * floor is right-above/right-under the current floor.
1144 * Stair creation/Teleport level/Trap door will take
1145 * you the same floor when you used it later again.
1147 if (p_ptr->floor_id)
1149 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1151 if (change_floor_mode & CFM_UP)
1153 /* New floor is right-above */
1154 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1155 sf_ptr->lower_floor_id = p_ptr->floor_id;
1157 else if (change_floor_mode & CFM_DOWN)
1159 /* New floor is right-under */
1160 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1161 sf_ptr->upper_floor_id = p_ptr->floor_id;
1165 /* Maintain monsters and artifacts */
1169 s32b absence_ticks = (turn - sf_ptr->last_visit) / TURNS_PER_TICK;
1170 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
1173 /* Maintain monsters */
1174 for (i = 1; i < m_max; i++)
1176 monster_race *r_ptr;
1177 monster_type *m_ptr = &m_list[i];
1179 /* Skip dead monsters */
1180 if (!m_ptr->r_idx) continue;
1185 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1190 /* Remove invulnerability */
1191 m_ptr->invulner = 0;
1193 /* Remove fast status */
1196 /* Remove slow status */
1202 /* Remove confusion */
1203 m_ptr->confused = 0;
1206 /* Extract real monster race */
1207 r_ptr = real_r_ptr(m_ptr);
1209 /* Ignore non-unique */
1210 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1211 !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1213 /* Appear at a different floor? */
1214 if (r_ptr->floor_id != new_floor_id)
1216 /* Disapper from here */
1217 delete_monster_idx(i);
1221 /* Maintain artifatcs */
1222 for (i = 1; i < o_max; i++)
1224 object_type *o_ptr = &o_list[i];
1226 /* Skip dead objects */
1227 if (!o_ptr->k_idx) continue;
1229 /* Ignore non-artifact */
1230 if (!artifact_p(o_ptr)) continue;
1232 /* Appear at a different floor? */
1233 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1235 /* Disappear from here */
1236 delete_object_idx(i);
1240 /* Cancel preserve */
1241 a_info[o_ptr->name1].cur_num = 1;
1245 place_quest_monsters();
1247 /* Place some random monsters */
1248 alloc_times = absence_ticks / alloc_chance;
1250 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1253 for (i = 0; i < alloc_times; i++)
1255 /* Make a (group of) new monster */
1256 (void)alloc_monster(0, 0);
1260 /* New floor_id or failed to restore */
1261 else /* if (!loaded) */
1263 if (sf_ptr->last_visit)
1265 /* Temporal file is broken? */
1267 msg_print("³¬ÃʤϹԤ»ß¤Þ¤ê¤À¤Ã¤¿¡£");
1269 msg_print("The staircases come to a dead end...");
1272 /* Create simple dead end */
1275 /* Break connection */
1276 if (change_floor_mode & CFM_UP)
1278 sf_ptr->upper_floor_id = 0;
1280 else if (change_floor_mode & CFM_DOWN)
1282 sf_ptr->lower_floor_id = 0;
1287 /* Newly create cave */
1291 /* Record last visit turn */
1292 sf_ptr->last_visit = turn;
1294 /* Set correct dun_level value */
1295 sf_ptr->dun_level = dun_level;
1297 /* Create connected stairs */
1298 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)))
1300 /* Extract stair position */
1301 cave_type *c_ptr = &cave[py][px];
1303 /*** Create connected stairs ***/
1305 /* No stairs down from Quest */
1306 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1308 if (change_floor_mode & CFM_SHAFT)
1309 c_ptr->feat = FEAT_MORE_MORE;
1311 c_ptr->feat = FEAT_MORE;
1314 /* No stairs up when ironman_downward */
1315 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1317 if (change_floor_mode & CFM_SHAFT)
1318 c_ptr->feat = FEAT_LESS_LESS;
1320 c_ptr->feat = FEAT_LESS;
1323 if (!feat_uses_special(c_ptr->feat))
1325 /* Paranoia -- Clear mimic */
1328 /* Connect to previous floor */
1329 c_ptr->special = p_ptr->floor_id;
1334 /* Arrive at random grid */
1335 if (change_floor_mode & (CFM_RAND_PLACE))
1337 (void)new_player_spot();
1340 /* You see stairs blocked */
1341 else if ((change_floor_mode & CFM_NO_RETURN) &&
1342 (change_floor_mode & (CFM_DOWN | CFM_UP)))
1347 msg_print("ÆÍÁ³³¬Ãʤ¬ºÉ¤¬¤ì¤Æ¤·¤Þ¤Ã¤¿¡£");
1349 msg_print("Suddenly the stairs is blocked!");
1355 msg_print("¥´¥È¥´¥È¤È²¿¤«²»¤¬¤·¤¿¡£");
1357 msg_print("You hear some noises.");
1365 * The "turn" is not always different number because
1366 * the level teleport doesn't take any turn. Use
1367 * visit mark instead of last visit turn to find the
1368 * oldest saved floor.
1370 sf_ptr->visit_mark = latest_visit_mark++;
1373 /* Place preserved pet monsters */
1376 /* Hack -- maintain unique and artifacts */
1377 update_unique_artifact(new_floor_id);
1379 /* Now the player is in new floor */
1380 p_ptr->floor_id = new_floor_id;
1382 /* The dungeon is ready */
1383 character_dungeon = TRUE;
1385 /* Hack -- Munchkin characters always get whole map */
1386 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1387 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1389 /* Remember when this level was "created" */
1392 /* Clear all flags */
1393 change_floor_mode = 0L;
1399 * Create stairs at or move previously created stairs into the player
1402 void stair_creation(void)
1404 saved_floor_type *sf_ptr;
1405 saved_floor_type *dest_sf_ptr;
1409 s16b dest_floor_id = 0;
1412 /* Forbid up staircases on Ironman mode */
1413 if (ironman_downward) up = FALSE;
1415 /* Forbid down staircases on quest level */
1416 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1418 /* No effect out of standard dungeon floor */
1419 if (!dun_level || (!up && !down) ||
1420 (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1421 p_ptr->inside_arena || p_ptr->inside_battle)
1423 /* arena or quest */
1425 msg_print("¸ú²Ì¤¬¤¢¤ê¤Þ¤»¤ó¡ª");
1427 msg_print("There is no effect!");
1432 /* Artifacts resists */
1433 if (!cave_valid_bold(py, px))
1436 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1438 msg_print("The object resists the spell.");
1444 /* Destroy all objects in the grid */
1445 delete_object(py, px);
1447 /* Extract current floor data */
1448 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1450 /* Choose randomly */
1453 if (randint0(100) < 50) up = FALSE;
1457 /* Destination is already fixed */
1460 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1464 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1468 /* Search old stairs leading to the destination */
1473 for (y = 0; y < cur_hgt; y++)
1475 for (x = 0; x < cur_wid; x++)
1477 cave_type *c_ptr = &cave[y][x];
1479 if (!c_ptr->special) continue;
1480 if (feat_uses_special(c_ptr->feat)) continue;
1481 if (c_ptr->special != dest_floor_id) continue;
1483 /* Remove old stairs */
1485 cave_set_feat(y, x, floor_type[randint0(100)]);
1490 /* No old destination -- Get new one now */
1493 dest_floor_id = get_new_floor_id();
1497 sf_ptr->upper_floor_id = dest_floor_id;
1499 sf_ptr->lower_floor_id = dest_floor_id;
1502 /* Extract destination floor data */
1503 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1506 /* Create a staircase */
1509 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level <= dun_level - 2)
1510 cave_set_feat(py, px, FEAT_LESS_LESS);
1512 cave_set_feat(py, px, FEAT_LESS);
1516 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level >= dun_level + 2)
1517 cave_set_feat(py, px, FEAT_MORE_MORE);
1519 cave_set_feat(py, px, FEAT_MORE);
1523 /* Connect this stairs to the destination */
1524 cave[py][px].special = dest_floor_id;