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);
336 wipe_generate_cave_flags();
343 static void preserve_pet(void)
349 /* Paranoia - prevent loss of rided monster */
350 for (num = 0; (num < MAX_PARTY_MON) && party_mon[num].r_idx; num++) /* Count forward */ ;
351 if (num < MAX_PARTY_MON) COPY(&party_mon[num++], &m_list[p_ptr->riding], monster_type);
353 /* Delete from this floor */
354 delete_monster_idx(p_ptr->riding);
358 * If player is in wild mode, no pets are preserved
359 * except a monster whom player riding
361 if (!p_ptr->wild_mode)
363 for (i = m_max - 1; (i >= 1 && num < MAX_PARTY_MON); i--)
365 monster_type *m_ptr = &m_list[i];
367 if (!m_ptr->r_idx) continue;
368 if (!is_pet(m_ptr)) continue;
369 if (i == p_ptr->riding) continue;
371 if (reinit_wilderness || p_ptr->inside_arena || p_ptr->inside_battle)
373 /* Don't lose sight of pets when getting a Quest */
377 int dis = distance(py, px, m_ptr->fy, m_ptr->fx);
380 * Pets with nickname will follow even from 3 blocks away
381 * when you or the pet can see the other.
383 if (m_ptr->nickname &&
384 (player_has_los_bold(m_ptr->fy, m_ptr->fx) ||
385 los(m_ptr->fy, m_ptr->fx, py, px)))
387 if (dis > 3) continue;
391 if (dis > 1) continue;
393 if (m_ptr->confused || m_ptr->stunned || m_ptr->csleep) continue;
396 for (; (num < MAX_PARTY_MON) && party_mon[num].r_idx; num++) /* Count forward */ ;
397 if (num < MAX_PARTY_MON) COPY(&party_mon[num++], &m_list[i], monster_type);
399 /* Delete from this floor */
400 delete_monster_idx(i);
404 if (record_named_pet)
406 for (i = m_max - 1; i >=1; i--)
408 monster_type *m_ptr = &m_list[i];
411 if (!m_ptr->r_idx) continue;
412 if (!is_pet(m_ptr)) continue;
413 if (!m_ptr->nickname) continue;
414 if (p_ptr->riding == i) continue;
416 monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
417 do_cmd_write_nikki(NIKKI_NAMED_PET, 4, m_name);
424 * Place preserved pet monsters on new floor
426 static void place_pet(void)
429 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
431 for (i = 0; i < max_num; i++)
435 if (!(party_mon[i].r_idx)) continue;
440 p_ptr->riding = m_idx;
451 /* Don't place in arena except rided one */
452 if (p_ptr->inside_arena || p_ptr->inside_battle) continue;
454 for (d = 1; d < 6; d++)
456 for (j = 1000; j > 0; j--)
458 scatter(&cy, &cx, py, px, d, 0);
459 if ((cave_floor_bold(cy, cx) || (cave[cy][cx].feat == FEAT_TREES)) && !cave[cy][cx].m_idx && !player_bold(cy, cx)) break;
463 m_idx = (d == 6) ? 0 : m_pop();
468 monster_type *m_ptr = &m_list[m_idx];
471 cave[cy][cx].m_idx = m_idx;
473 m_ptr->r_idx = party_mon[i].r_idx;
475 /* Copy all member of the structure */
476 *m_ptr = party_mon[i];
477 r_ptr = real_r_ptr(m_ptr);
485 m_ptr->hold_o_idx = 0;
488 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
490 /* Monster is still being nice */
491 m_ptr->mflag |= (MFLAG_NICE);
493 /* Must repair monsters */
494 repair_monsters = TRUE;
497 /* Update the monster */
498 update_mon(m_idx, TRUE);
501 /* Pre-calculated in precalc_cur_num_of_pet() */
502 /* r_ptr->cur_num++; */
504 /* Hack -- Count the number of "reproducers" */
505 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
507 /* Hack -- Notice new multi-hued monsters */
509 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
510 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
511 shimmer_monsters = TRUE;
516 monster_type *m_ptr = &party_mon[i];
517 monster_race *r_ptr = real_r_ptr(m_ptr);
520 monster_desc(m_name, m_ptr, 0);
522 msg_format("%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£", m_name);
524 msg_format("You have lost sight of %s.", m_name);
526 if (record_named_pet && m_ptr->nickname)
528 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
529 do_cmd_write_nikki(NIKKI_NAMED_PET, 5, m_name);
532 /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
533 if (r_ptr->cur_num) r_ptr->cur_num--;
536 /* For accuracy of precalc_cur_num_of_pet() */
537 WIPE(&party_mon[i], monster_type);
543 * Hack -- Update location of unique monsters and artifacts
545 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly
546 * while new floor creation since dungeons may be re-created by
549 static void update_unique_artifact(s16b cur_floor_id)
553 /* Maintain unique monsters */
554 for (i = 1; i < m_max; i++)
557 monster_type *m_ptr = &m_list[i];
559 /* Skip dead monsters */
560 if (!m_ptr->r_idx) continue;
562 /* Extract real monster race */
563 r_ptr = real_r_ptr(m_ptr);
565 /* Memorize location of the unique monster */
566 if ((r_ptr->flags1 & RF1_UNIQUE) ||
567 (r_ptr->flags7 & RF7_NAZGUL))
569 r_ptr->floor_id = cur_floor_id;
573 /* Maintain artifatcs */
574 for (i = 1; i < o_max; i++)
576 object_type *o_ptr = &o_list[i];
578 /* Skip dead objects */
579 if (!o_ptr->k_idx) continue;
581 /* Memorize location of the artifact */
582 if (artifact_p(o_ptr))
584 a_info[o_ptr->name1].floor_id = cur_floor_id;
591 * When a monster is at a place where player will return,
592 * Get out of the my way!
594 static void get_out_monster(void)
600 int m_idx = cave[oy][ox].m_idx;
602 /* Nothing to do if no monster */
605 /* Look until done */
610 /* Pick a (possibly illegal) location */
611 int ny = rand_spread(oy, dis);
612 int nx = rand_spread(ox, dis);
616 /* Stop after 1000 tries */
617 if (tries > 10000) return;
620 * Increase distance after doing enough tries
621 * compared to area of possible space
623 if (tries > 20 * dis * dis) dis++;
625 /* Ignore illegal locations */
626 if (!in_bounds(ny, nx)) continue;
628 /* Require "empty" floor space */
629 if (!cave_empty_bold(ny, nx)) continue;
631 /* Hack -- no teleport onto glyph of warding */
632 if (is_glyph_grid(&cave[ny][nx])) continue;
633 if (is_explosive_rune_grid(&cave[ny][nx])) continue;
635 /* ...nor onto the Pattern */
636 if ((cave[ny][nx].feat >= FEAT_PATTERN_START) &&
637 (cave[ny][nx].feat <= FEAT_PATTERN_XTRA2)) continue;
639 /*** It's a good place ***/
641 m_ptr = &m_list[m_idx];
643 /* Update the new location */
644 cave[ny][nx].m_idx = m_idx;
646 /* Update the old location */
647 cave[oy][ox].m_idx = 0;
649 /* Move the monster */
653 /* No need to do update_mon() */
662 * Maintain quest monsters, mark next floor_id at stairs, save current
663 * floor, and prepare to enter next floor.
665 void leave_floor(void)
667 cave_type *c_ptr = NULL;
668 saved_floor_type *sf_ptr;
672 /* Preserve pets and prepare to take these to next floor */
675 /* Remove all mirrors without explosion */
676 remove_all_mirrors(FALSE);
678 if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
680 /* New floor is not yet prepared */
684 /* From somewhere of the surface to somewhere of the surface */
687 /* No need to save current floor */
691 /* Search the quest monster index */
692 for (i = 0; i < max_quests; i++)
694 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
695 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
696 (quest[i].type == QUEST_TYPE_RANDOM)) &&
697 (quest[i].level == dun_level) &&
698 (dungeon_type == quest[i].dungeon) &&
699 !(quest[i].flags & QUEST_FLAG_PRESET))
701 quest_r_idx = quest[i].r_idx;
705 /* Maintain quest monsters */
706 for (i = 1; i < m_max; i++)
709 monster_type *m_ptr = &m_list[i];
711 /* Skip dead monsters */
712 if (!m_ptr->r_idx) continue;
714 /* Only maintain quest monsters */
715 if (quest_r_idx != m_ptr->r_idx) continue;
717 /* Extract real monster race */
718 r_ptr = real_r_ptr(m_ptr);
720 /* Ignore unique monsters */
721 if ((r_ptr->flags1 & RF1_UNIQUE) ||
722 (r_ptr->flags7 & RF7_NAZGUL)) continue;
724 /* Delete non-unique quest monsters */
725 delete_monster_idx(i);
728 /* Check if there is a same item */
729 for (i = 0; i < INVEN_PACK; i++)
731 object_type *o_ptr = &inventory[i];
733 /* Skip dead objects */
734 if (!o_ptr->k_idx) continue;
736 /* Delete old memorized location of the artifact */
737 if (artifact_p(o_ptr))
739 a_info[o_ptr->name1].floor_id = 0;
743 /* Extract current floor info or NULL */
744 sf_ptr = get_sf_ptr(p_ptr->floor_id);
746 /* Choose random stairs */
747 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
749 int x, y, sx = 0, sy = 0;
755 /* Search usable stairs */
756 for (y = 0; y < cur_hgt; y++)
758 for (x = 0; x < cur_wid; x++)
760 cave_type *c_ptr = &cave[y][x];
763 if (change_floor_mode & CFM_UP)
765 /* Found fixed stairs */
766 if (c_ptr->special &&
767 c_ptr->special == sf_ptr->upper_floor_id)
773 if (c_ptr->feat == FEAT_LESS ||
774 c_ptr->feat == FEAT_LESS_LESS)
777 else if (change_floor_mode & CFM_DOWN)
779 /* Found fixed stairs */
780 if (c_ptr->special &&
781 c_ptr->special == sf_ptr->lower_floor_id)
787 if (c_ptr->feat == FEAT_MORE ||
788 c_ptr->feat == FEAT_MORE_MORE)
809 /* No stairs found! -- No return */
810 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
812 /* Mega Hack -- It's not the stairs you enter. Disable it. */
813 cave[py][px].special = 0;
817 /* Choose random one */
820 /* Point stair location */
826 /* Extract new dungeon level */
827 if (!(change_floor_mode & CFM_CLEAR_ALL))
831 /* Extract stair position */
832 c_ptr = &cave[py][px];
834 /* Get back to old saved floor? */
835 if (dun_level && c_ptr->special && get_sf_ptr(c_ptr->special))
837 /* Saved floor is exist. Use it. */
838 new_floor_id = c_ptr->special;
841 /* Extract level movement number */
842 if (change_floor_mode & CFM_DOWN) move_num = 1;
843 else if (change_floor_mode & CFM_UP) move_num = -1;
845 /* Mark shaft up/down */
846 if (c_ptr->feat == FEAT_LESS_LESS ||
847 c_ptr->feat == FEAT_MORE_MORE)
849 prepare_change_floor_mode(CFM_SHAFT);
850 move_num += SGN(move_num);
853 /* Get out from or Enter the dungeon */
854 if (change_floor_mode & CFM_DOWN)
857 move_num = d_info[c_ptr->special].mindepth;
859 else if (change_floor_mode & CFM_UP)
861 if (dun_level + move_num < d_info[dungeon_type].mindepth)
862 move_num = -dun_level;
865 dun_level += move_num;
868 /* Leaving the dungeon to town */
869 if (!dun_level && dungeon_type)
871 p_ptr->leaving_dungeon = TRUE;
872 if (!vanilla_town && !lite_town)
874 p_ptr->wilderness_y = d_info[dungeon_type].dy;
875 p_ptr->wilderness_x = d_info[dungeon_type].dx;
877 p_ptr->recall_dungeon = dungeon_type;
880 /* Reach to the surface -- Clear all saved floors */
881 prepare_change_floor_mode(CFM_CLEAR_ALL);
884 if (change_floor_mode & CFM_CLEAR_ALL)
888 /* Kill all saved floors */
889 for (i = 0; i < MAX_SAVED_FLOORS; i++)
890 kill_saved_floor(&saved_floors[i]);
892 /* Reset visit_mark count */
893 latest_visit_mark = 1;
895 else if (change_floor_mode & CFM_NO_RETURN)
897 /* Kill current floor */
898 kill_saved_floor(sf_ptr);
901 /* No current floor -- Left/Enter dungeon etc... */
902 if (!p_ptr->floor_id)
904 /* No longer need to save current floor */
909 /* Mark next floor_id on the previous floor */
913 new_floor_id = get_new_floor_id();
915 /* Connect from here */
918 c_ptr->special = new_floor_id;
921 /* Record new dungeon level */
922 get_sf_ptr(new_floor_id)->dun_level = dun_level;
925 /* Fix connection -- level teleportation or trap door */
926 if (change_floor_mode & CFM_RAND_CONNECT)
928 if (change_floor_mode & CFM_UP)
929 sf_ptr->upper_floor_id = new_floor_id;
930 else if (change_floor_mode & CFM_DOWN)
931 sf_ptr->lower_floor_id = new_floor_id;
934 /* If you can return, you need to save previous floor */
935 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)))
937 /* Get out of the my way! */
940 /* Record the last visit turn of current floor */
941 sf_ptr->last_visit = turn;
943 /* Forget the lite */
946 /* Forget the view */
949 /* Forget the view */
952 /* Save current floor */
953 if (!save_floor(sf_ptr, 0))
955 /* Save failed -- No return */
956 prepare_change_floor_mode(CFM_NO_RETURN);
958 /* Kill current floor */
959 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
966 * Enter new floor. If the floor is an old saved floor, it will be
967 * restored from the temporal file. If the floor is new one, new cave
970 void change_floor(void)
972 saved_floor_type *sf_ptr;
975 /* The dungeon is not ready */
976 character_dungeon = FALSE;
978 /* No longer in the trap detecteded region */
979 p_ptr->dtrap = FALSE;
981 /* Mega-Hack -- no panel yet */
987 /* Mega-Hack -- not ambushed on the wildness? */
996 /* Paranoia -- Now on the surface */
1000 /* In the dungeon */
1003 /* No floor_id yet */
1007 new_floor_id = get_new_floor_id();
1010 /* Pointer for infomations of new floor */
1011 sf_ptr = get_sf_ptr(new_floor_id);
1013 /* Try to restore old floor */
1014 if (sf_ptr->last_visit)
1016 /* Old saved floor is exist */
1017 if (load_floor(sf_ptr, 0))
1021 /* Forbid return stairs */
1022 if (change_floor_mode & CFM_NO_RETURN)
1024 cave_type *c_ptr = &cave[py][px];
1026 /* Reset to floor */
1027 place_floor_grid(c_ptr);
1034 * Set lower/upper_floor_id of new floor when the new
1035 * floor is right-above/right-under the current floor.
1037 * Stair creation/Teleport level/Trap door will take
1038 * you the same floor when you used it later again.
1040 if (p_ptr->floor_id)
1042 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1044 if (change_floor_mode & CFM_UP)
1046 /* New floor is right-above */
1047 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1048 sf_ptr->lower_floor_id = p_ptr->floor_id;
1050 else if (change_floor_mode & CFM_DOWN)
1052 /* New floor is right-under */
1053 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1054 sf_ptr->upper_floor_id = p_ptr->floor_id;
1058 /* Break connection to killed floor */
1061 if (change_floor_mode & CFM_UP)
1062 sf_ptr->lower_floor_id = 0;
1063 else if (change_floor_mode & CFM_DOWN)
1064 sf_ptr->upper_floor_id = 0;
1067 /* Maintain monsters and artifacts */
1071 s32b tmp_last_visit = sf_ptr->last_visit;
1073 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
1076 while (tmp_last_visit > turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
1077 absence_ticks = (turn - tmp_last_visit) / TURNS_PER_TICK;
1079 /* Maintain monsters */
1080 for (i = 1; i < m_max; i++)
1082 monster_race *r_ptr;
1083 monster_type *m_ptr = &m_list[i];
1085 /* Skip dead monsters */
1086 if (!m_ptr->r_idx) continue;
1091 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1096 /* Remove invulnerability */
1097 m_ptr->invulner = 0;
1099 /* Remove fast status */
1102 /* Remove slow status */
1108 /* Remove confusion */
1109 m_ptr->confused = 0;
1112 /* Extract real monster race */
1113 r_ptr = real_r_ptr(m_ptr);
1115 /* Ignore non-unique */
1116 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1117 !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1119 /* Appear at a different floor? */
1120 if (r_ptr->floor_id != new_floor_id)
1122 /* Disapper from here */
1123 delete_monster_idx(i);
1127 /* Maintain artifatcs */
1128 for (i = 1; i < o_max; i++)
1130 object_type *o_ptr = &o_list[i];
1132 /* Skip dead objects */
1133 if (!o_ptr->k_idx) continue;
1135 /* Ignore non-artifact */
1136 if (!artifact_p(o_ptr)) continue;
1138 /* Appear at a different floor? */
1139 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1141 /* Disappear from here */
1142 delete_object_idx(i);
1146 /* Cancel preserve */
1147 a_info[o_ptr->name1].cur_num = 1;
1151 (void)place_quest_monsters();
1153 /* Place some random monsters */
1154 alloc_times = absence_ticks / alloc_chance;
1156 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1159 for (i = 0; i < alloc_times; i++)
1161 /* Make a (group of) new monster */
1162 (void)alloc_monster(0, 0);
1166 /* New floor_id or failed to restore */
1167 else /* if (!loaded) */
1169 if (sf_ptr->last_visit)
1171 /* Temporal file is broken? */
1173 msg_print("³¬ÃʤϹԤ»ß¤Þ¤ê¤À¤Ã¤¿¡£");
1175 msg_print("The staircases come to a dead end...");
1178 /* Create simple dead end */
1181 /* Break connection */
1182 if (change_floor_mode & CFM_UP)
1184 sf_ptr->upper_floor_id = 0;
1186 else if (change_floor_mode & CFM_DOWN)
1188 sf_ptr->lower_floor_id = 0;
1193 /* Newly create cave */
1197 /* Record last visit turn */
1198 sf_ptr->last_visit = turn;
1200 /* Set correct dun_level value */
1201 sf_ptr->dun_level = dun_level;
1203 /* Creat connected stairs */
1204 if (!(change_floor_mode & (CFM_NO_RETURN | CFM_CLEAR_ALL)) && dun_level)
1208 /* Extract stair position */
1209 cave_type *c_ptr = &cave[py][px];
1211 /*** Create connected stairs ***/
1213 /* No stairs down from Quest */
1214 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1216 if (change_floor_mode & CFM_SHAFT)
1217 c_ptr->feat = FEAT_MORE_MORE;
1219 c_ptr->feat = FEAT_MORE;
1222 /* No stairs up when ironman_downward */
1223 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1225 if (change_floor_mode & CFM_SHAFT)
1226 c_ptr->feat = FEAT_LESS_LESS;
1228 c_ptr->feat = FEAT_LESS;
1238 /* Paranoia -- Clear mimic */
1241 /* Connect to previous floor */
1242 c_ptr->special = p_ptr->floor_id;
1247 /* Arrive at random grid */
1248 if (change_floor_mode & (CFM_RAND_PLACE))
1250 (void)new_player_spot();
1253 /* You see stairs blocked */
1254 else if (change_floor_mode & CFM_NO_RETURN)
1259 msg_print("ÆÍÁ³³¬Ãʤ¬ºÉ¤¬¤ì¤Æ¤·¤Þ¤Ã¤¿¡£");
1261 msg_print("Suddenly the stairs is blocked!");
1267 msg_print("¥´¥È¥´¥È¤È²¿¤«²»¤¬¤·¤¿¡£");
1269 msg_print("You hear some noises.");
1277 * The "turn" is not always different number because
1278 * the level teleport doesn't take any turn. Use
1279 * visit mark instead of last visit turn to find the
1280 * oldest saved floor.
1282 sf_ptr->visit_mark = latest_visit_mark++;
1285 /* Place preserved pet monsters */
1288 /* Hack -- maintain unique and artifacts */
1289 update_unique_artifact(new_floor_id);
1291 /* Now the player is in new floor */
1292 p_ptr->floor_id = new_floor_id;
1294 /* The dungeon is ready */
1295 character_dungeon = TRUE;
1297 /* Hack -- Munchkin characters always get whole map */
1298 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1299 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1301 /* Remember when this level was "created" */
1304 /* Clear all flags */
1305 change_floor_mode = 0L;
1311 * Create stairs at or move previously created stairs into the player
1314 void stair_creation(void)
1316 saved_floor_type *sf_ptr;
1317 saved_floor_type *dest_sf_ptr;
1321 s16b dest_floor_id = 0;
1324 /* Forbid up staircases on Ironman mode */
1325 if (ironman_downward) up = FALSE;
1327 /* Forbid down staircases on quest level */
1328 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1330 /* No effect out of standard dungeon floor */
1331 if (!dun_level || (!up && !down) ||
1332 (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1333 p_ptr->inside_arena || p_ptr->inside_battle)
1335 /* arena or quest */
1337 msg_print("¸ú²Ì¤¬¤¢¤ê¤Þ¤»¤ó¡ª");
1339 msg_print("There is no effect!");
1344 /* Artifacts resists */
1345 if (!cave_valid_bold(py, px))
1348 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1350 msg_print("The object resists the spell.");
1356 /* Destroy all objects in the grid */
1357 delete_object(py, px);
1359 /* Extract current floor data */
1360 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1362 /* Choose randomly */
1365 if (randint0(100) < 50) up = FALSE;
1369 /* Destination is already fixed */
1372 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1376 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1380 /* Search old stairs leading to the destination */
1385 for (y = 0; y < cur_hgt; y++)
1387 for (x = 0; x < cur_wid; x++)
1389 cave_type *c_ptr = &cave[y][x];
1391 if (!c_ptr->special) continue;
1392 if (c_ptr->special != dest_floor_id) continue;
1394 /* Remove old stairs */
1396 cave_set_feat(y, x, floor_type[randint0(100)]);
1401 /* No old destination -- Get new one now */
1404 dest_floor_id = get_new_floor_id();
1408 sf_ptr->upper_floor_id = dest_floor_id;
1410 sf_ptr->lower_floor_id = dest_floor_id;
1413 /* Extract destination floor data */
1414 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1417 /* Create a staircase */
1420 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level <= dun_level - 2)
1421 cave_set_feat(py, px, FEAT_LESS_LESS);
1423 cave_set_feat(py, px, FEAT_LESS);
1427 if (dest_sf_ptr->last_visit && dest_sf_ptr->dun_level >= dun_level + 2)
1428 cave_set_feat(py, px, FEAT_MORE_MORE);
1430 cave_set_feat(py, px, FEAT_MORE);
1434 /* Connect this stairs to the destination */
1435 cave[py][px].special = dest_floor_id;