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)
347 /* Paranoia - prevent loss of rided monster */
348 for (num = 0; (num < MAX_PARTY_MON) && party_mon[num].r_idx; num++) /* Count forward */ ;
349 if (num < MAX_PARTY_MON) COPY(&party_mon[num++], &m_list[p_ptr->riding], monster_type);
351 /* Delete from this floor */
352 delete_monster_idx(p_ptr->riding);
356 * If player is in wild mode, no pets are preserved
357 * except a monster whom player riding
359 if (!p_ptr->wild_mode)
361 for (i = m_max - 1; (i >= 1 && num < MAX_PARTY_MON); i--)
363 monster_type *m_ptr = &m_list[i];
365 if (!m_ptr->r_idx) continue;
366 if (!is_pet(m_ptr)) continue;
367 if (i == p_ptr->riding) continue;
369 if (reinit_wilderness || p_ptr->inside_arena || p_ptr->inside_battle)
371 /* Don't lose sight of pets when getting a Quest */
375 int dis = distance(py, px, m_ptr->fy, m_ptr->fx);
378 * Pets with nickname will follow even from 3 blocks away
379 * when you or the pet can see the other.
381 if (m_ptr->nickname &&
382 (player_has_los_bold(m_ptr->fy, m_ptr->fx) ||
383 los(m_ptr->fy, m_ptr->fx, py, px)))
385 if (dis > 3) continue;
389 if (dis > 1) continue;
391 if (m_ptr->confused || m_ptr->stunned || m_ptr->csleep) continue;
394 for (; (num < MAX_PARTY_MON) && party_mon[num].r_idx; num++) /* Count forward */ ;
395 if (num < MAX_PARTY_MON) COPY(&party_mon[num++], &m_list[i], monster_type);
397 /* Delete from this floor */
398 delete_monster_idx(i);
402 if (record_named_pet)
404 for (i = m_max - 1; i >=1; i--)
406 monster_type *m_ptr = &m_list[i];
409 if (!m_ptr->r_idx) continue;
410 if (!is_pet(m_ptr)) continue;
411 if (!m_ptr->nickname) continue;
412 if (p_ptr->riding == i) continue;
414 monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
415 do_cmd_write_nikki(NIKKI_NAMED_PET, 4, m_name);
422 * Place preserved pet monsters on new floor
424 static void place_pet(void)
427 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
429 for (i = 0; i < max_num; i++)
433 if (!(party_mon[i].r_idx)) continue;
438 p_ptr->riding = m_idx;
449 /* Don't place in arena except rided one */
450 if (p_ptr->inside_arena || p_ptr->inside_battle) continue;
452 for (d = 1; d < 6; d++)
454 for (j = 1000; j > 0; j--)
456 scatter(&cy, &cx, py, px, d, 0);
457 if ((cave_floor_bold(cy, cx) || (cave[cy][cx].feat == FEAT_TREES)) && !cave[cy][cx].m_idx && !player_bold(cy, cx)) break;
461 m_idx = (d == 6) ? 0 : m_pop();
466 monster_type *m_ptr = &m_list[m_idx];
469 cave[cy][cx].m_idx = m_idx;
471 m_ptr->r_idx = party_mon[i].r_idx;
473 /* Copy all member of the structure */
474 *m_ptr = party_mon[i];
475 r_ptr = real_r_ptr(m_ptr);
483 m_ptr->hold_o_idx = 0;
486 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
488 /* Monster is still being nice */
489 m_ptr->mflag |= (MFLAG_NICE);
491 /* Must repair monsters */
492 repair_monsters = TRUE;
495 /* Update the monster */
496 update_mon(m_idx, TRUE);
499 /* Pre-calculated in precalc_cur_num_of_pet() */
500 /* r_ptr->cur_num++; */
502 /* Hack -- Count the number of "reproducers" */
503 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
505 /* Hack -- Notice new multi-hued monsters */
507 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
508 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
509 shimmer_monsters = TRUE;
514 monster_type *m_ptr = &party_mon[i];
515 monster_race *r_ptr = real_r_ptr(m_ptr);
518 monster_desc(m_name, m_ptr, 0);
520 msg_format("%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£", m_name);
522 msg_format("You have lost sight of %s.", m_name);
524 if (record_named_pet && m_ptr->nickname)
526 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
527 do_cmd_write_nikki(NIKKI_NAMED_PET, 5, m_name);
530 /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
531 if (r_ptr->cur_num) r_ptr->cur_num--;
534 /* For accuracy of precalc_cur_num_of_pet() */
535 WIPE(&party_mon[i], monster_type);
541 * Hack -- Update location of unique monsters and artifacts
543 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly
544 * while new floor creation since dungeons may be re-created by
547 static void update_unique_artifact(s16b cur_floor_id)
551 /* Maintain unique monsters */
552 for (i = 1; i < m_max; i++)
555 monster_type *m_ptr = &m_list[i];
557 /* Skip dead monsters */
558 if (!m_ptr->r_idx) continue;
560 /* Extract real monster race */
561 r_ptr = real_r_ptr(m_ptr);
563 /* Memorize location of the unique monster */
564 if ((r_ptr->flags1 & RF1_UNIQUE) ||
565 (r_ptr->flags7 & RF7_UNIQUE_7))
567 r_ptr->floor_id = cur_floor_id;
571 /* Maintain artifatcs */
572 for (i = 1; i < o_max; i++)
574 object_type *o_ptr = &o_list[i];
576 /* Skip dead objects */
577 if (!o_ptr->k_idx) continue;
579 /* Memorize location of the artifact */
580 if (artifact_p(o_ptr))
582 a_info[o_ptr->name1].floor_id = cur_floor_id;
589 * When a monster is at a place where player will return,
590 * Get out of the my way!
592 static void get_out_monster(void)
598 int m_idx = cave[oy][ox].m_idx;
600 /* Nothing to do if no monster */
603 /* Look until done */
608 /* Pick a (possibly illegal) location */
609 int ny = rand_spread(oy, dis);
610 int nx = rand_spread(ox, dis);
614 /* Stop after 1000 tries */
615 if (tries > 10000) return;
618 * Increase distance after doing enough tries
619 * compared to area of possible space
621 if (tries > 20 * dis * dis) dis++;
623 /* Ignore illegal locations */
624 if (!in_bounds(ny, nx)) continue;
626 /* Require "empty" floor space */
627 if (!cave_empty_bold(ny, nx)) continue;
629 /* Hack -- no teleport onto glyph of warding */
630 if (is_glyph_grid(&cave[ny][nx])) continue;
631 if (is_explosive_rune_grid(&cave[ny][nx])) continue;
633 /* ...nor onto the Pattern */
634 if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
635 (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2)) continue;
637 /*** It's a good place ***/
639 m_ptr = &m_list[m_idx];
641 /* Update the new location */
642 cave[ny][nx].m_idx = m_idx;
644 /* Update the old location */
645 cave[oy][ox].m_idx = 0;
647 /* Move the monster */
651 /* No need to do update_mon() */
660 * Maintain quest monsters, mark next floor_id at stairs, save current
661 * floor, and prepare to enter next floor.
663 void leave_floor(void)
665 cave_type *c_ptr = NULL;
666 saved_floor_type *sf_ptr;
670 /* Preserve pets and prepare to take these to next floor */
673 /* New floor is not yet prepared */
677 /* From somewhere of the surface to somewhere of the surface */
680 /* No need to save current floor */
684 /* Search the quest monster index */
685 for (i = 0; i < max_quests; i++)
687 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
688 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
689 (quest[i].type == QUEST_TYPE_RANDOM)) &&
690 (quest[i].level == dun_level) &&
691 (dungeon_type == quest[i].dungeon) &&
692 !(quest[i].flags & QUEST_FLAG_PRESET))
694 quest_r_idx = quest[i].r_idx;
698 /* Maintain quest monsters */
699 for (i = 1; i < m_max; i++)
702 monster_type *m_ptr = &m_list[i];
704 /* Skip dead monsters */
705 if (!m_ptr->r_idx) continue;
707 /* Only maintain quest monsters */
708 if (quest_r_idx != m_ptr->r_idx) continue;
710 /* Extract real monster race */
711 r_ptr = real_r_ptr(m_ptr);
713 /* Ignore unique monsters */
714 if ((r_ptr->flags1 & RF1_UNIQUE) ||
715 (r_ptr->flags7 & RF7_UNIQUE_7)) continue;
717 /* Delete non-unique quest monsters */
718 delete_monster_idx(i);
721 /* Check if there is a same item */
722 for (i = 0; i < INVEN_PACK; i++)
724 object_type *o_ptr = &inventory[i];
726 /* Skip dead objects */
727 if (!o_ptr->k_idx) continue;
729 /* Delete old memorized location of the artifact */
730 if (artifact_p(o_ptr))
732 a_info[o_ptr->name1].floor_id = 0;
736 /* Extract current floor info or NULL */
737 sf_ptr = get_sf_ptr(p_ptr->floor_id);
739 /* Choose random stairs */
740 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
742 int x, y, sx = 0, sy = 0;
748 /* Search usable stairs */
749 for (y = 0; y < cur_hgt; y++)
751 for (x = 0; x < cur_wid; x++)
753 cave_type *c_ptr = &cave[y][x];
756 if (change_floor_mode & CFM_UP)
758 /* Found fixed stairs */
759 if (c_ptr->special &&
760 c_ptr->special == sf_ptr->upper_floor_id)
766 if (c_ptr->feat == FEAT_LESS ||
767 c_ptr->feat == FEAT_LESS_LESS)
770 else if (change_floor_mode & CFM_DOWN)
772 /* Found fixed stairs */
773 if (c_ptr->special &&
774 c_ptr->special == sf_ptr->lower_floor_id)
780 if (c_ptr->feat == FEAT_MORE ||
781 c_ptr->feat == FEAT_MORE_MORE)
802 /* No stairs found! -- No return */
803 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
805 /* Mega Hack -- It's not the stairs you enter. Disable it. */
806 cave[py][px].special = 0;
810 /* Choose random one */
813 /* Point stair location */
819 /* Extract new dungeon level */
820 if (!(change_floor_mode & CFM_CLEAR_ALL))
824 /* Extract stair position */
825 c_ptr = &cave[py][px];
827 /* Get back to old saved floor? */
828 if (dun_level && c_ptr->special && get_sf_ptr(c_ptr->special))
830 /* Saved floor is exist. Use it. */
831 new_floor_id = c_ptr->special;
834 /* Extract level movement number */
835 if (change_floor_mode & CFM_DOWN) move_num = 1;
836 else if (change_floor_mode & CFM_UP) move_num = -1;
838 /* Mark shaft up/down */
839 if (c_ptr->feat == FEAT_LESS_LESS ||
840 c_ptr->feat == FEAT_MORE_MORE)
842 prepare_change_floor_mode(CFM_SHAFT);
843 move_num += SGN(move_num);
846 /* Get out from or Enter the dungeon */
847 if (change_floor_mode & CFM_DOWN)
850 move_num = d_info[c_ptr->special].mindepth;
852 else if (change_floor_mode & CFM_UP)
854 if (dun_level + move_num < d_info[dungeon_type].mindepth)
855 move_num = -dun_level;
858 dun_level += move_num;
861 /* Leaving the dungeon to town */
862 if (!dun_level && dungeon_type)
864 p_ptr->leaving_dungeon = TRUE;
865 if (!vanilla_town && !lite_town)
867 p_ptr->wilderness_y = d_info[dungeon_type].dy;
868 p_ptr->wilderness_x = d_info[dungeon_type].dx;
870 p_ptr->recall_dungeon = dungeon_type;
873 /* Reach to the surface -- Clear all saved floors */
874 prepare_change_floor_mode(CFM_CLEAR_ALL);
877 if (change_floor_mode & CFM_CLEAR_ALL)
881 /* Kill all saved floors */
882 for (i = 0; i < MAX_SAVED_FLOORS; i++)
883 kill_saved_floor(&saved_floors[i]);
885 /* Reset visit_mark count */
886 latest_visit_mark = 1;
888 else if (change_floor_mode & CFM_NO_RETURN)
890 /* Kill current floor */
891 kill_saved_floor(sf_ptr);
894 /* No current floor -- Left/Enter dungeon etc... */
895 if (!p_ptr->floor_id)
897 /* No longer need to save current floor */
902 /* Mark next floor_id on the previous floor */
906 new_floor_id = get_new_floor_id();
908 /* Connect from here */
911 c_ptr->special = new_floor_id;
914 /* Record new dungeon level */
915 get_sf_ptr(new_floor_id)->dun_level = dun_level;
918 /* Fix connection -- level teleportation or trap door */
919 if (change_floor_mode & CFM_RAND_CONNECT)
921 if (change_floor_mode & CFM_UP)
922 sf_ptr->upper_floor_id = new_floor_id;
923 else if (change_floor_mode & CFM_DOWN)
924 sf_ptr->lower_floor_id = new_floor_id;
927 /* If you can return, you need to save previous floor */
928 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)))
930 /* Get out of the my way! */
933 /* Record the last visit turn of current floor */
934 sf_ptr->last_visit = turn;
936 /* Forget the lite */
939 /* Forget the view */
942 /* Forget the view */
945 /* Save current floor */
946 if (!save_floor(sf_ptr, 0))
948 /* Save failed -- No return */
949 prepare_change_floor_mode(CFM_NO_RETURN);
951 /* Kill current floor */
952 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
959 * Enter new floor. If the floor is an old saved floor, it will be
960 * restored from the temporal file. If the floor is new one, new cave
963 void change_floor(void)
965 saved_floor_type *sf_ptr;
968 /* The dungeon is not ready */
969 character_dungeon = FALSE;
971 /* No longer in the trap detecteded region */
972 p_ptr->dtrap = FALSE;
974 /* Mega-Hack -- no panel yet */
980 /* Mega-Hack -- not ambushed on the wildness? */
989 /* Paranoia -- Now on the surface */
996 /* No floor_id yet */
1000 new_floor_id = get_new_floor_id();
1003 /* Pointer for infomations of new floor */
1004 sf_ptr = get_sf_ptr(new_floor_id);
1006 /* Try to restore old floor */
1007 if (sf_ptr->last_visit)
1009 /* Old saved floor is exist */
1010 if (load_floor(sf_ptr, 0))
1014 /* Forbid return stairs */
1015 if (change_floor_mode & CFM_NO_RETURN)
1017 cave_type *c_ptr = &cave[py][px];
1019 /* Reset to floor */
1020 place_floor_grid(c_ptr);
1027 * Set lower/upper_floor_id of new floor when the new
1028 * floor is right-above/right-under the current floor.
1030 * Stair creation/Teleport level/Trap door will take
1031 * you the same floor when you used it later again.
1033 if (p_ptr->floor_id)
1035 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1037 if (change_floor_mode & CFM_UP)
1039 /* New floor is right-above */
1040 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1041 sf_ptr->lower_floor_id = p_ptr->floor_id;
1043 else if (change_floor_mode & CFM_DOWN)
1045 /* New floor is right-under */
1046 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1047 sf_ptr->upper_floor_id = p_ptr->floor_id;
1051 /* Maintain monsters and artifacts */
1055 s32b absence_ticks = (turn - sf_ptr->last_visit) / TURNS_PER_TICK;
1056 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
1059 /* Maintain monsters */
1060 for (i = 1; i < m_max; i++)
1062 monster_race *r_ptr;
1063 monster_type *m_ptr = &m_list[i];
1065 /* Skip dead monsters */
1066 if (!m_ptr->r_idx) continue;
1071 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1076 /* Remove invulnerability */
1077 m_ptr->invulner = 0;
1079 /* Remove fast status */
1082 /* Remove slow status */
1088 /* Remove confusion */
1089 m_ptr->confused = 0;
1092 /* Extract real monster race */
1093 r_ptr = real_r_ptr(m_ptr);
1095 /* Ignore non-unique */
1096 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1097 !(r_ptr->flags7 & RF7_UNIQUE_7)) continue;
1099 /* Appear at a different floor? */
1100 if (r_ptr->floor_id != new_floor_id)
1102 /* Disapper from here */
1103 delete_monster_idx(i);
1107 /* Maintain artifatcs */
1108 for (i = 1; i < o_max; i++)
1110 object_type *o_ptr = &o_list[i];
1112 /* Skip dead objects */
1113 if (!o_ptr->k_idx) continue;
1115 /* Ignore non-artifact */
1116 if (!artifact_p(o_ptr)) continue;
1118 /* Appear at a different floor? */
1119 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1121 /* Disappear from here */
1122 delete_object_idx(i);
1126 /* Cancel preserve */
1127 a_info[o_ptr->name1].cur_num = 1;
1131 place_quest_monsters();
1133 /* Place some random monsters */
1134 alloc_times = absence_ticks / alloc_chance;
1136 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1139 for (i = 0; i < alloc_times; i++)
1141 /* Make a (group of) new monster */
1142 (void)alloc_monster(0, 0);
1146 /* New floor_id or failed to restore */
1147 else /* if (!loaded) */
1149 if (sf_ptr->last_visit)
1151 /* Temporal file is broken? */
1153 msg_print("³¬ÃʤϹԤ»ß¤Þ¤ê¤À¤Ã¤¿¡£");
1155 msg_print("The staircases come to a dead end...");
1158 /* Create simple dead end */
1161 /* Break connection */
1162 if (change_floor_mode & CFM_UP)
1164 sf_ptr->upper_floor_id = 0;
1166 else if (change_floor_mode & CFM_DOWN)
1168 sf_ptr->lower_floor_id = 0;
1173 /* Newly create cave */
1177 /* Record last visit turn */
1178 sf_ptr->last_visit = turn;
1180 /* Set correct dun_level value */
1181 sf_ptr->dun_level = dun_level;
1183 /* Creat connected stairs */
1184 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)) && dun_level)
1188 /* Extract stair position */
1189 cave_type *c_ptr = &cave[py][px];
1191 /*** Create connected stairs ***/
1193 /* No stairs down from Quest */
1194 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1196 if (change_floor_mode & CFM_SHAFT)
1197 c_ptr->feat = FEAT_MORE_MORE;
1199 c_ptr->feat = FEAT_MORE;
1202 /* No stairs up when ironman_downward */
1203 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1205 if (change_floor_mode & CFM_SHAFT)
1206 c_ptr->feat = FEAT_LESS_LESS;
1208 c_ptr->feat = FEAT_LESS;
1218 /* Paranoia -- Clear mimic */
1221 /* Connect to previous floor */
1222 c_ptr->special = p_ptr->floor_id;
1227 /* Arrive at random grid */
1228 if (change_floor_mode & (CFM_RAND_PLACE))
1230 (void)new_player_spot();
1233 /* You see stairs blocked */
1234 else if (change_floor_mode & CFM_NO_RETURN)
1239 msg_print("ÆÍÁ³³¬Ãʤ¬ºÉ¤¬¤ì¤Æ¤·¤Þ¤Ã¤¿¡£");
1241 msg_print("Suddenly the stairs is blocked!");
1247 msg_print("¥´¥È¥´¥È¤È²¿¤«²»¤¬¤·¤¿¡£");
1249 msg_print("You hear some noises.");
1257 * The "turn" is not always different number because
1258 * the level teleport doesn't take any turn. Use
1259 * visit mark instead of last visit turn to find the
1260 * oldest saved floor.
1262 sf_ptr->visit_mark = latest_visit_mark++;
1265 /* Place preserved pet monsters */
1268 /* Hack -- maintain unique and artifacts */
1269 update_unique_artifact(new_floor_id);
1271 /* Now the player is in new floor */
1272 p_ptr->floor_id = new_floor_id;
1274 /* The dungeon is ready */
1275 character_dungeon = TRUE;
1277 /* Hack -- Munchkin characters always get whole map */
1278 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1279 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1281 /* Remember when this level was "created" */
1284 /* Clear all flags */
1285 change_floor_mode = 0L;
1291 * Create stairs at or move previously created stairs into the player
1294 void stair_creation(void)
1296 saved_floor_type *sf_ptr;
1297 saved_floor_type *dest_sf_ptr;
1301 s16b dest_floor_id = 0;
1304 /* Forbid up staircases on Ironman mode */
1305 if (ironman_downward) up = FALSE;
1307 /* Forbid down staircases on quest level */
1308 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1310 /* No effect out of standard dungeon floor */
1311 if (!dun_level || (!up && !down) ||
1312 (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1313 p_ptr->inside_arena || p_ptr->inside_battle)
1315 /* arena or quest */
1317 msg_print("¸ú²Ì¤¬¤¢¤ê¤Þ¤»¤ó¡ª");
1319 msg_print("There is no effect!");
1324 /* Artifacts resists */
1325 if (!cave_valid_bold(py, px))
1328 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1330 msg_print("The object resists the spell.");
1336 /* Destroy all objects in the grid */
1337 delete_object(py, px);
1339 /* Extract current floor data */
1340 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1342 /* Choose randomly */
1345 if (randint0(100) < 50) up = FALSE;
1349 /* Destination is already fixed */
1352 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1356 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1360 /* Search old stairs leading to the destination */
1365 for (y = 0; y < cur_hgt; y++)
1367 for (x = 0; x < cur_wid; x++)
1369 cave_type *c_ptr = &cave[y][x];
1371 if (!c_ptr->special) continue;
1372 if (c_ptr->special != dest_floor_id) continue;
1374 /* Remove old stairs */
1376 cave_set_feat(y, x, floor_type[randint0(100)]);
1381 /* No old destination -- Get new one now */
1384 dest_floor_id = get_new_floor_id();
1388 sf_ptr->upper_floor_id = dest_floor_id;
1390 sf_ptr->lower_floor_id = dest_floor_id;
1393 /* Extract destination floor data */
1394 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1397 /* Create a staircase */
1400 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level <= dun_level - 2)
1401 cave_set_feat(py, px, FEAT_LESS_LESS);
1403 cave_set_feat(py, px, FEAT_LESS);
1407 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level >= dun_level + 2)
1408 cave_set_feat(py, px, FEAT_MORE_MORE);
1410 cave_set_feat(py, px, FEAT_MORE);
1414 /* Connect this stairs to the destination */
1415 cave[py][px].special = dest_floor_id;