3 * @brief Êݸ¤µ¤ì¤¿³¬¤Î´ÉÍý / management of the saved floor
6 * Copyright (c) 2002 Mogami \n
7 * This software may be copied and distributed for educational, research, and \n
8 * not for profit purposes provided that this copyright and statement are \n
9 * included in all such copies. \n
10 * 2014 Deskull rearranged comment for Doxygen. \n
17 static s16b new_floor_id; /*!<¼¡¤Î¥Õ¥í¥¢¤Î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 * @brief Êݸ¥Õ¥í¥¢ÇÛÎó¤ò½é´ü²½¤¹¤ë / Initialize saved_floors array.
24 * @param force ¥Æ¥ó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤¬»Ä¤Ã¤Æ¤¤¤¿¾ì¹ç¤â·Ù¹ð¤Ê¤·¤Ç¶¯À©Åª¤Ëºï½ü¤¹¤ë¡£
25 * @details Make sure that old temporal files are not remaining as gurbages.
28 void init_saved_floors(bool force)
30 char floor_savefile[1024];
37 /* Get "games" permissions */
42 for (i = 0; i < MAX_SAVED_FLOORS; i++)
44 saved_floor_type *sf_ptr = &saved_floors[i];
47 sprintf(floor_savefile, "%s.F%02d", savefile, i);
49 /* Grab permissions */
52 /* Try to create the file */
53 fd = fd_make(floor_savefile, mode);
55 /* Drop permissions */
64 msg_print("¥¨¥é¡¼¡§¸Å¤¤¥Æ¥ó¥Ý¥é¥ê¡¦¥Õ¥¡¥¤¥ë¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£");
65 msg_print("ÊѶòÈÚÅܤòÆó½Å¤Ëµ¯Æ°¤·¤Æ¤¤¤Ê¤¤¤«³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£");
66 msg_print("²áµî¤ËÊѶòÈÚÅܤ¬¥¯¥é¥Ã¥·¥å¤·¤¿¾ì¹ç¤Ï°ì»þ¥Õ¥¡¥¤¥ë¤ò");
67 msg_print("¶¯À©Åª¤Ëºï½ü¤·¤Æ¼Â¹Ô¤ò³¤±¤é¤ì¤Þ¤¹¡£");
68 if (!get_check("¶¯À©Åª¤Ëºï½ü¤·¤Æ¤â¤è¤í¤·¤¤¤Ç¤¹¤«¡©")) quit("¼Â¹ÔÃæ»ß");
70 msg_print("Error: There are old temporal files.");
71 msg_print("Make sure you are not running two game processes simultaneously.");
72 msg_print("If the temporal files are garbages of old crashed process, ");
73 msg_print("you can delete it safely.");
74 if (!get_check("Do you delete old temporal files? ")) quit("Aborted.");
85 /* Grab permissions */
88 /* Simply kill the temporal file */
89 (void)fd_kill(floor_savefile);
91 /* Drop permissions */
97 /* No floor_id used yet (No.0 is reserved to indicate non existance) */
100 /* vist_mark is from 1 */
101 latest_visit_mark = 1;
103 /* A sign to mark temporal files */
104 saved_floor_file_sign = time(NULL);
106 /* No next floor yet */
109 /* No change floor mode yet */
110 change_floor_mode = 0;
114 /* Drop "games" permissions */
121 * @brief Êݸ¥Õ¥í¥¢Íѥƥó¥Ý¥é¥ê¥Õ¥¡¥¤¥ë¤òºï½ü¤¹¤ë / Kill temporal files
122 * @details Should be called just before the game quit.
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 */
167 * @brief Êݸ¥Õ¥í¥¢ID¤«¤é»²¾È¥Ý¥¤¥ó¥¿¤òÆÀ¤ë / Get a pointer for an item of the saved_floors array.
168 * @param floor_id Êݸ¥Õ¥í¥¢ID
169 * @return ID¤ËÂбþ¤¹¤ëÊݸ¥Õ¥í¥¢¤Î¥Ý¥¤¥ó¥¿¡¢¤Ê¤¤¾ì¹ç¤ÏNULL¤òÊÖ¤¹¡£
171 saved_floor_type *get_sf_ptr(s16b floor_id)
175 /* floor_id No.0 indicates no floor */
176 if (!floor_id) return NULL;
178 for (i = 0; i < MAX_SAVED_FLOORS; i++)
180 saved_floor_type *sf_ptr = &saved_floors[i];
182 if (sf_ptr->floor_id == floor_id) return sf_ptr;
191 * @brief »²¾È¥Ý¥¤¥ó¥¿Àè¤ÎÊݸ¥Õ¥í¥¢¤òËõ¾Ã¤¹¤ë / kill a saved floor and get an empty space
192 * @param sf_ptr Êݸ¥Õ¥í¥¢¤Î»²¾È¥Ý¥¤¥ó¥¿
195 static void kill_saved_floor(saved_floor_type *sf_ptr)
197 char floor_savefile[1024];
203 if (!sf_ptr->floor_id) return;
205 if (sf_ptr->floor_id == p_ptr->floor_id)
207 /* Kill current floor */
210 /* Current floor doesn't have temporal file */
215 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
217 /* Grab permissions */
220 /* Simply kill the temporal file */
221 (void)fd_kill(floor_savefile);
223 /* Drop permissions */
227 /* No longer exists */
228 sf_ptr->floor_id = 0;
233 * Initialize new saved floor and get its floor id. If number of
234 * saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
236 s16b get_new_floor_id(void)
238 saved_floor_type *sf_ptr;
241 /* Look for empty space */
242 for (i = 0; i < MAX_SAVED_FLOORS; i++)
244 sf_ptr = &saved_floors[i];
246 if (!sf_ptr->floor_id) break;
250 if (i == MAX_SAVED_FLOORS)
253 u32b oldest_visit = 0xffffffffL;
255 /* Search for oldest */
256 for (i = 0; i < MAX_SAVED_FLOORS; i++)
258 sf_ptr = &saved_floors[i];
260 /* Don't kill current floor */
261 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
263 /* Don't kill newer */
264 if (sf_ptr->visit_mark > oldest_visit) continue;
267 oldest_visit = sf_ptr->visit_mark;
270 /* Kill oldest saved floor */
271 sf_ptr = &saved_floors[oldest];
272 kill_saved_floor(sf_ptr);
278 /* Prepare new floor data */
279 sf_ptr->savefile_id = i;
280 sf_ptr->floor_id = max_floor_id;
281 sf_ptr->last_visit = 0;
282 sf_ptr->upper_floor_id = 0;
283 sf_ptr->lower_floor_id = 0;
284 sf_ptr->visit_mark = latest_visit_mark++;
286 /* sf_ptr->dun_level may be changed later */
287 sf_ptr->dun_level = dun_level;
290 /* Increment number of floor_id */
291 if (max_floor_id < MAX_SHORT) max_floor_id++;
293 /* 32767 floor_ids are all used up! Re-use ancient IDs */
294 else max_floor_id = 1;
296 return sf_ptr->floor_id;
301 * Prepare mode flags of changing floor
303 void prepare_change_floor_mode(u32b mode)
305 change_floor_mode |= mode;
310 * Builds the dead end
312 static void build_dead_end(void)
316 /* Clear and empty the cave */
319 /* Fill the arrays of floors and walls in the good proportions */
320 set_floor_and_wall(0);
323 cur_hgt = SCREEN_HGT;
324 cur_wid = SCREEN_WID;
326 /* Filled with permanent walls */
327 for (y = 0; y < MAX_HGT; y++)
329 for (x = 0; x < MAX_WID; x++)
331 /* Create "solid" perma-wall */
332 place_solid_perm_bold(y, x);
336 /* Place at center of the floor */
340 /* Give one square */
341 place_floor_bold(py, px);
343 wipe_generate_cave_flags();
347 /* Maximum number of preservable pets */
348 #define MAX_PARTY_MON 21
350 static monster_type party_mon[MAX_PARTY_MON];
356 static void preserve_pet(void)
360 for (num = 0; num < MAX_PARTY_MON; num++)
362 party_mon[num].r_idx = 0;
367 monster_type *m_ptr = &m_list[p_ptr->riding];
369 /* Pet of other pet don't follow. */
370 if (m_ptr->parent_m_idx)
373 p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
374 p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
378 /* Preserve the mount */
379 (void)COPY(&party_mon[0], m_ptr, monster_type);
381 /* Delete from this floor */
382 delete_monster_idx(p_ptr->riding);
387 * If player is in wild mode, no pets are preserved
388 * except a monster whom player riding
390 if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->inside_battle)
392 for (i = m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
394 monster_type *m_ptr = &m_list[i];
396 if (!m_ptr->r_idx) continue;
397 if (!is_pet(m_ptr)) continue;
398 if (i == p_ptr->riding) continue;
400 if (reinit_wilderness)
402 /* Don't lose sight of pets when getting a Quest */
406 int dis = distance(py, px, m_ptr->fy, m_ptr->fx);
408 /* Confused (etc.) monsters don't follow. */
409 if (MON_CONFUSED(m_ptr) || MON_STUNNED(m_ptr) || MON_CSLEEP(m_ptr)) continue;
411 /* Pet of other pet don't follow. */
412 if (m_ptr->parent_m_idx) continue;
415 * Pets with nickname will follow even from 3 blocks away
416 * when you or the pet can see the other.
418 if (m_ptr->nickname &&
419 ((player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(py, px, m_ptr->fy, m_ptr->fx)) ||
420 (los(m_ptr->fy, m_ptr->fx, py, px) && projectable(m_ptr->fy, m_ptr->fx, py, px))))
422 if (dis > 3) continue;
426 if (dis > 1) continue;
430 (void)COPY(&party_mon[num], &m_list[i], monster_type);
434 /* Delete from this floor */
435 delete_monster_idx(i);
439 if (record_named_pet)
441 for (i = m_max - 1; i >=1; i--)
443 monster_type *m_ptr = &m_list[i];
446 if (!m_ptr->r_idx) continue;
447 if (!is_pet(m_ptr)) continue;
448 if (!m_ptr->nickname) continue;
449 if (p_ptr->riding == i) continue;
451 monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
452 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_MOVED, m_name);
457 /* Pet of other pet may disappear. */
458 for (i = m_max - 1; i >=1; i--)
460 monster_type *m_ptr = &m_list[i];
462 /* Are there its parent? */
463 if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
465 /* Its parent have gone, it also goes away. */
471 /* Acquire the monster name */
472 monster_desc(m_name, m_ptr, 0);
475 msg_format("%s¤Ï¾Ã¤¨µî¤Ã¤¿¡ª", m_name);
477 msg_format("%^s disappears!", m_name);
481 /* Delete the monster */
482 delete_monster_idx(i);
489 * Pre-calculate the racial counters of preserved pets
490 * To prevent multiple generation of unique monster who is the minion of player
492 void precalc_cur_num_of_pet(void)
496 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
498 for (i = 0; i < max_num; i++)
500 m_ptr = &party_mon[i];
502 /* Skip empty monsters */
503 if (!m_ptr->r_idx) continue;
505 /* Hack -- Increase the racial counter */
506 real_r_ptr(m_ptr)->cur_num++;
512 * Place preserved pet monsters on new floor
514 static void place_pet(void)
517 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
519 for (i = 0; i < max_num; i++)
523 if (!(party_mon[i].r_idx)) continue;
528 p_ptr->riding = m_idx;
539 for (d = 1; d < 6; d++)
541 for (j = 1000; j > 0; j--)
543 scatter(&cy, &cx, py, px, d, 0);
544 if (monster_can_enter(cy, cx, &r_info[party_mon[i].r_idx], 0)) break;
548 m_idx = (d == 6) ? 0 : m_pop();
553 monster_type *m_ptr = &m_list[m_idx];
556 cave[cy][cx].m_idx = m_idx;
558 m_ptr->r_idx = party_mon[i].r_idx;
560 /* Copy all member of the structure */
561 *m_ptr = party_mon[i];
562 r_ptr = real_r_ptr(m_ptr);
567 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
570 m_ptr->hold_o_idx = 0;
573 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
575 /* Monster is still being nice */
576 m_ptr->mflag |= (MFLAG_NICE);
578 /* Must repair monsters */
579 repair_monsters = TRUE;
582 /* Update the monster */
583 update_mon(m_idx, TRUE);
586 /* Pre-calculated in precalc_cur_num_of_pet() */
587 /* r_ptr->cur_num++; */
589 /* Hack -- Count the number of "reproducers" */
590 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
592 /* Hack -- Notice new multi-hued monsters */
594 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
595 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
596 shimmer_monsters = TRUE;
601 monster_type *m_ptr = &party_mon[i];
602 monster_race *r_ptr = real_r_ptr(m_ptr);
605 monster_desc(m_name, m_ptr, 0);
607 msg_format("%s¤È¤Ï¤°¤ì¤Æ¤·¤Þ¤Ã¤¿¡£", m_name);
609 msg_format("You have lost sight of %s.", m_name);
611 if (record_named_pet && m_ptr->nickname)
613 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
614 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOST_SIGHT, m_name);
617 /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
618 if (r_ptr->cur_num) r_ptr->cur_num--;
622 /* For accuracy of precalc_cur_num_of_pet() */
623 (void)C_WIPE(party_mon, MAX_PARTY_MON, monster_type);
628 * Hack -- Update location of unique monsters and artifacts
630 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly
631 * while new floor creation since dungeons may be re-created by
634 static void update_unique_artifact(s16b cur_floor_id)
638 /* Maintain unique monsters */
639 for (i = 1; i < m_max; i++)
642 monster_type *m_ptr = &m_list[i];
644 /* Skip dead monsters */
645 if (!m_ptr->r_idx) continue;
647 /* Extract real monster race */
648 r_ptr = real_r_ptr(m_ptr);
650 /* Memorize location of the unique monster */
651 if ((r_ptr->flags1 & RF1_UNIQUE) ||
652 (r_ptr->flags7 & RF7_NAZGUL))
654 r_ptr->floor_id = cur_floor_id;
658 /* Maintain artifatcs */
659 for (i = 1; i < o_max; i++)
661 object_type *o_ptr = &o_list[i];
663 /* Skip dead objects */
664 if (!o_ptr->k_idx) continue;
666 /* Memorize location of the artifact */
667 if (object_is_fixed_artifact(o_ptr))
669 a_info[o_ptr->name1].floor_id = cur_floor_id;
676 * When a monster is at a place where player will return,
677 * Get out of the my way!
679 static void get_out_monster(void)
685 int m_idx = cave[oy][ox].m_idx;
687 /* Nothing to do if no monster */
690 /* Look until done */
695 /* Pick a (possibly illegal) location */
696 int ny = rand_spread(oy, dis);
697 int nx = rand_spread(ox, dis);
701 /* Stop after 1000 tries */
702 if (tries > 10000) return;
705 * Increase distance after doing enough tries
706 * compared to area of possible space
708 if (tries > 20 * dis * dis) dis++;
710 /* Ignore illegal locations */
711 if (!in_bounds(ny, nx)) continue;
713 /* Require "empty" floor space */
714 if (!cave_empty_bold(ny, nx)) continue;
716 /* Hack -- no teleport onto glyph of warding */
717 if (is_glyph_grid(&cave[ny][nx])) continue;
718 if (is_explosive_rune_grid(&cave[ny][nx])) continue;
720 /* ...nor onto the Pattern */
721 if (pattern_tile(ny, nx)) continue;
723 /*** It's a good place ***/
725 m_ptr = &m_list[m_idx];
727 /* Update the old location */
728 cave[oy][ox].m_idx = 0;
730 /* Update the new location */
731 cave[ny][nx].m_idx = m_idx;
733 /* Move the monster */
737 /* No need to do update_mon() */
746 * Is this feature has special meaning (except floor_id) with c_ptr->special?
748 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
752 * Virtually teleport onto the stairs that is connecting between two
755 * Teleport level spell and trap doors will always lead the player to
756 * the one of the floors connected by the one of the stairs in the
759 static void locate_connected_stairs(saved_floor_type *sf_ptr)
761 int x, y, sx = 0, sy = 0;
767 /* Search usable stairs */
768 for (y = 0; y < cur_hgt; y++)
770 for (x = 0; x < cur_wid; x++)
772 cave_type *c_ptr = &cave[y][x];
773 feature_type *f_ptr = &f_info[c_ptr->feat];
776 if (change_floor_mode & CFM_UP)
778 if (have_flag(f_ptr->flags, FF_LESS) && have_flag(f_ptr->flags, FF_STAIRS) &&
779 !have_flag(f_ptr->flags, FF_SPECIAL))
783 /* Found fixed stairs? */
784 if (c_ptr->special &&
785 c_ptr->special == sf_ptr->upper_floor_id)
793 else if (change_floor_mode & CFM_DOWN)
795 if (have_flag(f_ptr->flags, FF_MORE) && have_flag(f_ptr->flags, FF_STAIRS) &&
796 !have_flag(f_ptr->flags, FF_SPECIAL))
800 /* Found fixed stairs */
801 if (c_ptr->special &&
802 c_ptr->special == sf_ptr->lower_floor_id)
812 if (have_flag(f_ptr->flags, FF_BLDG))
818 if (ok && (num < 20))
835 /* No stairs found! -- No return */
836 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
838 /* Mega Hack -- It's not the stairs you enter. Disable it. */
839 if (!feat_uses_special(cave[py][px].feat)) cave[py][px].special = 0;
843 /* Choose random one */
846 /* Point stair location */
853 * Maintain quest monsters, mark next floor_id at stairs, save current
854 * floor, and prepare to enter next floor.
856 void leave_floor(void)
858 cave_type *c_ptr = NULL;
860 saved_floor_type *sf_ptr;
864 /* Preserve pets and prepare to take these to next floor */
867 /* Remove all mirrors without explosion */
868 remove_all_mirrors(FALSE);
870 if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
872 /* New floor is not yet prepared */
875 /* Temporary get a floor_id (for Arena) */
876 if (!p_ptr->floor_id &&
877 (change_floor_mode & CFM_SAVE_FLOORS) &&
878 !(change_floor_mode & CFM_NO_RETURN))
880 /* Get temporal floor_id */
881 p_ptr->floor_id = get_new_floor_id();
885 /* Search the quest monster index */
886 for (i = 0; i < max_quests; i++)
888 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
889 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
890 (quest[i].type == QUEST_TYPE_RANDOM)) &&
891 (quest[i].level == dun_level) &&
892 (dungeon_type == quest[i].dungeon) &&
893 !(quest[i].flags & QUEST_FLAG_PRESET))
895 quest_r_idx = quest[i].r_idx;
899 /* Maintain quest monsters */
900 for (i = 1; i < m_max; i++)
903 monster_type *m_ptr = &m_list[i];
905 /* Skip dead monsters */
906 if (!m_ptr->r_idx) continue;
908 /* Only maintain quest monsters */
909 if (quest_r_idx != m_ptr->r_idx) continue;
911 /* Extract real monster race */
912 r_ptr = real_r_ptr(m_ptr);
914 /* Ignore unique monsters */
915 if ((r_ptr->flags1 & RF1_UNIQUE) ||
916 (r_ptr->flags7 & RF7_NAZGUL)) continue;
918 /* Delete non-unique quest monsters */
919 delete_monster_idx(i);
922 /* Check if there is a same item */
923 for (i = 0; i < INVEN_PACK; i++)
925 object_type *o_ptr = &inventory[i];
927 /* Skip dead objects */
928 if (!o_ptr->k_idx) continue;
930 /* Delete old memorized location of the artifact */
931 if (object_is_fixed_artifact(o_ptr))
933 a_info[o_ptr->name1].floor_id = 0;
937 /* Extract current floor info or NULL */
938 sf_ptr = get_sf_ptr(p_ptr->floor_id);
940 /* Choose random stairs */
941 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
943 locate_connected_stairs(sf_ptr);
946 /* Extract new dungeon level */
947 if (change_floor_mode & CFM_SAVE_FLOORS)
949 /* Extract stair position */
950 c_ptr = &cave[py][px];
951 f_ptr = &f_info[c_ptr->feat];
953 /* Get back to old saved floor? */
954 if (c_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(c_ptr->special))
956 /* Saved floor is exist. Use it. */
957 new_floor_id = c_ptr->special;
960 /* Mark shaft up/down */
961 if (have_flag(f_ptr->flags, FF_STAIRS) && have_flag(f_ptr->flags, FF_SHAFT))
963 prepare_change_floor_mode(CFM_SHAFT);
967 /* Climb up/down some sort of stairs */
968 if (change_floor_mode & (CFM_DOWN | CFM_UP))
972 /* Extract level movement number */
973 if (change_floor_mode & CFM_DOWN) move_num = 1;
974 else if (change_floor_mode & CFM_UP) move_num = -1;
976 /* Shafts are deeper than normal stairs */
977 if (change_floor_mode & CFM_SHAFT)
978 move_num += SGN(move_num);
980 /* Get out from or Enter the dungeon */
981 if (change_floor_mode & CFM_DOWN)
984 move_num = d_info[dungeon_type].mindepth;
986 else if (change_floor_mode & CFM_UP)
988 if (dun_level + move_num < d_info[dungeon_type].mindepth)
989 move_num = -dun_level;
992 dun_level += move_num;
995 /* Leaving the dungeon to town */
996 if (!dun_level && dungeon_type)
998 p_ptr->leaving_dungeon = TRUE;
999 if (!vanilla_town && !lite_town)
1001 p_ptr->wilderness_y = d_info[dungeon_type].dy;
1002 p_ptr->wilderness_x = d_info[dungeon_type].dx;
1004 p_ptr->recall_dungeon = dungeon_type;
1007 /* Reach to the surface -- Clear all saved floors */
1008 change_floor_mode &= ~CFM_SAVE_FLOORS;
1011 /* Kill some old saved floors */
1012 if (!(change_floor_mode & CFM_SAVE_FLOORS))
1016 /* Kill all saved floors */
1017 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1018 kill_saved_floor(&saved_floors[i]);
1020 /* Reset visit_mark count */
1021 latest_visit_mark = 1;
1023 else if (change_floor_mode & CFM_NO_RETURN)
1025 /* Kill current floor */
1026 kill_saved_floor(sf_ptr);
1029 /* No current floor -- Left/Enter dungeon etc... */
1030 if (!p_ptr->floor_id)
1032 /* No longer need to save current floor */
1037 /* Mark next floor_id on the previous floor */
1041 new_floor_id = get_new_floor_id();
1043 /* Connect from here */
1044 if (c_ptr && !feat_uses_special(c_ptr->feat))
1046 c_ptr->special = new_floor_id;
1050 /* Fix connection -- level teleportation or trap door */
1051 if (change_floor_mode & CFM_RAND_CONNECT)
1053 if (change_floor_mode & CFM_UP)
1054 sf_ptr->upper_floor_id = new_floor_id;
1055 else if (change_floor_mode & CFM_DOWN)
1056 sf_ptr->lower_floor_id = new_floor_id;
1059 /* If you can return, you need to save previous floor */
1060 if ((change_floor_mode & CFM_SAVE_FLOORS) &&
1061 !(change_floor_mode & CFM_NO_RETURN))
1063 /* Get out of the my way! */
1066 /* Record the last visit turn of current floor */
1067 sf_ptr->last_visit = turn;
1069 /* Forget the lite */
1072 /* Forget the view */
1075 /* Forget the view */
1078 /* Save current floor */
1079 if (!save_floor(sf_ptr, 0))
1081 /* Save failed -- No return */
1082 prepare_change_floor_mode(CFM_NO_RETURN);
1084 /* Kill current floor */
1085 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
1092 * Enter new floor. If the floor is an old saved floor, it will be
1093 * restored from the temporal file. If the floor is new one, new cave
1094 * will be generated.
1096 void change_floor(void)
1098 saved_floor_type *sf_ptr;
1099 bool loaded = FALSE;
1101 /* The dungeon is not ready */
1102 character_dungeon = FALSE;
1104 /* No longer in the trap detecteded region */
1105 p_ptr->dtrap = FALSE;
1107 /* Mega-Hack -- no panel yet */
1113 /* Mega-Hack -- not ambushed on the wildness? */
1114 ambush_flag = FALSE;
1116 /* No saved floors (On the surface etc.) */
1117 if (!(change_floor_mode & CFM_SAVE_FLOORS) &&
1118 !(change_floor_mode & CFM_FIRST_FLOOR))
1123 /* Paranoia -- No new saved floor */
1127 /* In the dungeon */
1130 /* No floor_id yet */
1134 new_floor_id = get_new_floor_id();
1137 /* Pointer for infomations of new floor */
1138 sf_ptr = get_sf_ptr(new_floor_id);
1140 /* Try to restore old floor */
1141 if (sf_ptr->last_visit)
1143 /* Old saved floor is exist */
1144 if (load_floor(sf_ptr, 0))
1148 /* Forbid return stairs */
1149 if (change_floor_mode & CFM_NO_RETURN)
1151 cave_type *c_ptr = &cave[py][px];
1153 if (!feat_uses_special(c_ptr->feat))
1155 if (change_floor_mode & (CFM_DOWN | CFM_UP))
1157 /* Reset to floor */
1158 c_ptr->feat = floor_type[randint0(100)];
1168 * Set lower/upper_floor_id of new floor when the new
1169 * floor is right-above/right-under the current floor.
1171 * Stair creation/Teleport level/Trap door will take
1172 * you the same floor when you used it later again.
1174 if (p_ptr->floor_id)
1176 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1178 if (change_floor_mode & CFM_UP)
1180 /* New floor is right-above */
1181 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1182 sf_ptr->lower_floor_id = p_ptr->floor_id;
1184 else if (change_floor_mode & CFM_DOWN)
1186 /* New floor is right-under */
1187 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1188 sf_ptr->upper_floor_id = p_ptr->floor_id;
1192 /* Break connection to killed floor */
1195 if (change_floor_mode & CFM_UP)
1196 sf_ptr->lower_floor_id = 0;
1197 else if (change_floor_mode & CFM_DOWN)
1198 sf_ptr->upper_floor_id = 0;
1201 /* Maintain monsters and artifacts */
1205 s32b tmp_last_visit = sf_ptr->last_visit;
1207 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
1210 while (tmp_last_visit > turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
1211 absence_ticks = (turn - tmp_last_visit) / TURNS_PER_TICK;
1213 /* Maintain monsters */
1214 for (i = 1; i < m_max; i++)
1216 monster_race *r_ptr;
1217 monster_type *m_ptr = &m_list[i];
1219 /* Skip dead monsters */
1220 if (!m_ptr->r_idx) continue;
1225 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1227 /* Remove timed status (except MTIMED_CSLEEP) */
1228 (void)set_monster_fast(i, 0);
1229 (void)set_monster_slow(i, 0);
1230 (void)set_monster_stunned(i, 0);
1231 (void)set_monster_confused(i, 0);
1232 (void)set_monster_monfear(i, 0);
1233 (void)set_monster_invulner(i, 0, FALSE);
1236 /* Extract real monster race */
1237 r_ptr = real_r_ptr(m_ptr);
1239 /* Ignore non-unique */
1240 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1241 !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1243 /* Appear at a different floor? */
1244 if (r_ptr->floor_id != new_floor_id)
1246 /* Disapper from here */
1247 delete_monster_idx(i);
1251 /* Maintain artifatcs */
1252 for (i = 1; i < o_max; i++)
1254 object_type *o_ptr = &o_list[i];
1256 /* Skip dead objects */
1257 if (!o_ptr->k_idx) continue;
1259 /* Ignore non-artifact */
1260 if (!object_is_fixed_artifact(o_ptr)) continue;
1262 /* Appear at a different floor? */
1263 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1265 /* Disappear from here */
1266 delete_object_idx(i);
1270 /* Cancel preserve */
1271 a_info[o_ptr->name1].cur_num = 1;
1275 (void)place_quest_monsters();
1277 /* Place some random monsters */
1278 alloc_times = absence_ticks / alloc_chance;
1280 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1283 for (i = 0; i < alloc_times; i++)
1285 /* Make a (group of) new monster */
1286 (void)alloc_monster(0, 0);
1290 /* New floor_id or failed to restore */
1291 else /* if (!loaded) */
1293 if (sf_ptr->last_visit)
1295 /* Temporal file is broken? */
1297 msg_print("³¬ÃʤϹԤ»ß¤Þ¤ê¤À¤Ã¤¿¡£");
1299 msg_print("The staircases come to a dead end...");
1302 /* Create simple dead end */
1305 /* Break connection */
1306 if (change_floor_mode & CFM_UP)
1308 sf_ptr->upper_floor_id = 0;
1310 else if (change_floor_mode & CFM_DOWN)
1312 sf_ptr->lower_floor_id = 0;
1317 /* Newly create cave */
1321 /* Record last visit turn */
1322 sf_ptr->last_visit = turn;
1324 /* Set correct dun_level value */
1325 sf_ptr->dun_level = dun_level;
1327 /* Create connected stairs */
1328 if (!(change_floor_mode & CFM_NO_RETURN))
1330 /* Extract stair position */
1331 cave_type *c_ptr = &cave[py][px];
1333 /*** Create connected stairs ***/
1335 /* No stairs down from Quest */
1336 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1338 c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair;
1341 /* No stairs up when ironman_downward */
1342 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1344 c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair;
1347 /* Paranoia -- Clear mimic */
1350 /* Connect to previous floor */
1351 c_ptr->special = p_ptr->floor_id;
1355 /* Arrive at random grid */
1356 if (change_floor_mode & (CFM_RAND_PLACE))
1358 (void)new_player_spot();
1361 /* You see stairs blocked */
1362 else if ((change_floor_mode & CFM_NO_RETURN) &&
1363 (change_floor_mode & (CFM_DOWN | CFM_UP)))
1368 msg_print("ÆÍÁ³³¬Ãʤ¬ºÉ¤¬¤ì¤Æ¤·¤Þ¤Ã¤¿¡£");
1370 msg_print("Suddenly the stairs is blocked!");
1376 msg_print("¥´¥È¥´¥È¤È²¿¤«²»¤¬¤·¤¿¡£");
1378 msg_print("You hear some noises.");
1386 * The "turn" is not always different number because
1387 * the level teleport doesn't take any turn. Use
1388 * visit mark instead of last visit turn to find the
1389 * oldest saved floor.
1391 sf_ptr->visit_mark = latest_visit_mark++;
1394 /* Place preserved pet monsters */
1397 /* Reset travel target place */
1398 forget_travel_flow();
1400 /* Hack -- maintain unique and artifacts */
1401 update_unique_artifact(new_floor_id);
1403 /* Now the player is in new floor */
1404 p_ptr->floor_id = new_floor_id;
1406 /* The dungeon is ready */
1407 character_dungeon = TRUE;
1409 /* Hack -- Munchkin characters always get whole map */
1410 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1411 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1413 /* Remember when this level was "created" */
1416 /* No dungeon feeling yet */
1417 p_ptr->feeling_turn = old_turn;
1420 /* Clear all flags */
1421 change_floor_mode = 0L;
1427 * Create stairs at or move previously created stairs into the player
1430 void stair_creation(void)
1432 saved_floor_type *sf_ptr;
1433 saved_floor_type *dest_sf_ptr;
1437 s16b dest_floor_id = 0;
1440 /* Forbid up staircases on Ironman mode */
1441 if (ironman_downward) up = FALSE;
1443 /* Forbid down staircases on quest level */
1444 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1446 /* No effect out of standard dungeon floor */
1447 if (!dun_level || (!up && !down) ||
1448 (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1449 p_ptr->inside_arena || p_ptr->inside_battle)
1451 /* arena or quest */
1453 msg_print("¸ú²Ì¤¬¤¢¤ê¤Þ¤»¤ó¡ª");
1455 msg_print("There is no effect!");
1460 /* Artifacts resists */
1461 if (!cave_valid_bold(py, px))
1464 msg_print("¾²¾å¤Î¥¢¥¤¥Æ¥à¤¬¼öʸ¤òÄ·¤ÍÊÖ¤·¤¿¡£");
1466 msg_print("The object resists the spell.");
1472 /* Destroy all objects in the grid */
1473 delete_object(py, px);
1475 /* Extract current floor data */
1476 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1481 /* No floor id? -- Create now! */
1482 p_ptr->floor_id = get_new_floor_id();
1483 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1486 /* Choose randomly */
1489 if (randint0(100) < 50) up = FALSE;
1493 /* Destination is already fixed */
1496 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1500 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1504 /* Search old stairs leading to the destination */
1509 for (y = 0; y < cur_hgt; y++)
1511 for (x = 0; x < cur_wid; x++)
1513 cave_type *c_ptr = &cave[y][x];
1515 if (!c_ptr->special) continue;
1516 if (feat_uses_special(c_ptr->feat)) continue;
1517 if (c_ptr->special != dest_floor_id) continue;
1519 /* Remove old stairs */
1521 cave_set_feat(y, x, floor_type[randint0(100)]);
1526 /* No old destination -- Get new one now */
1529 dest_floor_id = get_new_floor_id();
1533 sf_ptr->upper_floor_id = dest_floor_id;
1535 sf_ptr->lower_floor_id = dest_floor_id;
1538 /* Extract destination floor data */
1539 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1542 /* Create a staircase */
1545 cave_set_feat(py, px,
1546 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level <= dun_level - 2)) ?
1547 feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair);
1551 cave_set_feat(py, px,
1552 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level >= dun_level + 2)) ?
1553 feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair);
1557 /* Connect this stairs to the destination */
1558 cave[py][px].special = dest_floor_id;