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];
33 BIT_FLAGS mode = 0644;
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 = (u32b)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 * @brief 新規に利用可能な保存フロアを返す / Initialize new saved floor and get its floor id.
234 * @return 利用可能な保存フロアID
236 * If number of saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
238 s16b get_new_floor_id(void)
240 saved_floor_type *sf_ptr = NULL;
243 /* Look for empty space */
244 for (i = 0; i < MAX_SAVED_FLOORS; i++)
246 sf_ptr = &saved_floors[i];
248 if (!sf_ptr->floor_id) break;
252 if (i == MAX_SAVED_FLOORS)
255 u32b oldest_visit = 0xffffffffL;
257 /* Search for oldest */
258 for (i = 0; i < MAX_SAVED_FLOORS; i++)
260 sf_ptr = &saved_floors[i];
262 /* Don't kill current floor */
263 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
265 /* Don't kill newer */
266 if (sf_ptr->visit_mark > oldest_visit) continue;
269 oldest_visit = sf_ptr->visit_mark;
272 /* Kill oldest saved floor */
273 sf_ptr = &saved_floors[oldest];
274 kill_saved_floor(sf_ptr);
280 /* Prepare new floor data */
281 sf_ptr->savefile_id = i;
282 sf_ptr->floor_id = max_floor_id;
283 sf_ptr->last_visit = 0;
284 sf_ptr->upper_floor_id = 0;
285 sf_ptr->lower_floor_id = 0;
286 sf_ptr->visit_mark = latest_visit_mark++;
288 /* sf_ptr->dun_level may be changed later */
289 sf_ptr->dun_level = dun_level;
292 /* Increment number of floor_id */
293 if (max_floor_id < MAX_SHORT) max_floor_id++;
295 /* 32767 floor_ids are all used up! Re-use ancient IDs */
296 else max_floor_id = 1;
298 return sf_ptr->floor_id;
303 * @brief フロア切り替え時の処理フラグを追加する / Prepare mode flags of changing floor
304 * @param mode 追加したい所持フラグ
307 void prepare_change_floor_mode(BIT_FLAGS mode)
309 change_floor_mode |= mode;
313 * @brief 階段移動先のフロアが生成できない時に簡単な行き止まりマップを作成する / Builds the dead end
316 static void build_dead_end(void)
320 /* Clear and empty the cave */
323 /* Fill the arrays of floors and walls in the good proportions */
324 set_floor_and_wall(0);
327 cur_hgt = SCREEN_HGT;
328 cur_wid = SCREEN_WID;
330 /* Filled with permanent walls */
331 for (y = 0; y < MAX_HGT; y++)
333 for (x = 0; x < MAX_WID; x++)
335 /* Create "solid" perma-wall */
336 place_solid_perm_bold(y, x);
340 /* Place at center of the floor */
341 p_ptr->y = cur_hgt / 2;
342 p_ptr->x = cur_wid / 2;
344 /* Give one square */
345 place_floor_bold(p_ptr->y, p_ptr->x);
347 wipe_generate_cave_flags();
352 #define MAX_PARTY_MON 21 /*!< フロア移動時に先のフロアに連れて行けるペットの最大数 Maximum number of preservable pets */
353 static monster_type party_mon[MAX_PARTY_MON]; /*!< フロア移動に保存するペットモンスターの配列 */
356 * @brief フロア移動時のペット保存処理 / Preserve_pets
359 static void preserve_pet(void)
364 for (num = 0; num < MAX_PARTY_MON; num++)
366 party_mon[num].r_idx = 0;
371 monster_type *m_ptr = &m_list[p_ptr->riding];
373 /* Pet of other pet don't follow. */
374 if (m_ptr->parent_m_idx)
377 p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
378 p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
382 /* Preserve the mount */
383 (void)COPY(&party_mon[0], m_ptr, monster_type);
385 /* Delete from this floor */
386 delete_monster_idx(p_ptr->riding);
391 * If player is in wild mode, no pets are preserved
392 * except a monster whom player riding
394 if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->inside_battle)
396 for (i = m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
398 monster_type *m_ptr = &m_list[i];
400 if (!m_ptr->r_idx) continue;
401 if (!is_pet(m_ptr)) continue;
402 if (i == p_ptr->riding) continue;
404 if (reinit_wilderness)
406 /* Don't lose sight of pets when getting a Quest */
410 int dis = distance(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx);
412 /* Confused (etc.) monsters don't follow. */
413 if (MON_CONFUSED(m_ptr) || MON_STUNNED(m_ptr) || MON_CSLEEP(m_ptr)) continue;
415 /* Pet of other pet don't follow. */
416 if (m_ptr->parent_m_idx) continue;
419 * Pets with nickname will follow even from 3 blocks away
420 * when you or the pet can see the other.
422 if (m_ptr->nickname &&
423 ((player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) ||
424 (los(m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x) && projectable(m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x))))
426 if (dis > 3) continue;
430 if (dis > 1) continue;
434 (void)COPY(&party_mon[num], &m_list[i], monster_type);
438 /* Delete from this floor */
439 delete_monster_idx(i);
443 if (record_named_pet)
445 for (i = m_max - 1; i >=1; i--)
447 monster_type *m_ptr = &m_list[i];
450 if (!m_ptr->r_idx) continue;
451 if (!is_pet(m_ptr)) continue;
452 if (!m_ptr->nickname) continue;
453 if (p_ptr->riding == i) continue;
455 monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
456 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_MOVED, m_name);
461 /* Pet of other pet may disappear. */
462 for (i = m_max - 1; i >=1; i--)
464 monster_type *m_ptr = &m_list[i];
466 /* Are there its parent? */
467 if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
469 /* Its parent have gone, it also goes away. */
475 /* Acquire the monster name */
476 monster_desc(m_name, m_ptr, 0);
477 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
480 /* Delete the monster */
481 delete_monster_idx(i);
488 * @brief フロア移動時にペットを伴った場合の準備処理 / Pre-calculate the racial counters of preserved pets
491 * To prevent multiple generation of unique monster who is the minion of player
493 void precalc_cur_num_of_pet(void)
497 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
499 for (i = 0; i < max_num; i++)
501 m_ptr = &party_mon[i];
503 /* Skip empty monsters */
504 if (!m_ptr->r_idx) continue;
506 /* Hack -- Increase the racial counter */
507 real_r_ptr(m_ptr)->cur_num++;
512 * @brief 移動先のフロアに伴ったペットを配置する / Place preserved pet monsters on new floor
515 static void place_pet(void)
518 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
520 for (i = 0; i < max_num; i++)
522 POSITION cy = 0, cx = 0;
525 if (!(party_mon[i].r_idx)) continue;
530 p_ptr->riding = m_idx;
542 for (d = 1; d < 6; d++)
544 for (j = 1000; j > 0; j--)
546 scatter(&cy, &cx, p_ptr->y, p_ptr->x, d, 0);
547 if (monster_can_enter(cy, cx, &r_info[party_mon[i].r_idx], 0)) break;
551 m_idx = (d == 6) ? 0 : m_pop();
556 monster_type *m_ptr = &m_list[m_idx];
559 cave[cy][cx].m_idx = m_idx;
561 m_ptr->r_idx = party_mon[i].r_idx;
563 /* Copy all member of the structure */
564 *m_ptr = party_mon[i];
565 r_ptr = real_r_ptr(m_ptr);
570 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
573 m_ptr->hold_o_idx = 0;
576 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
578 /* Monster is still being nice */
579 m_ptr->mflag |= (MFLAG_NICE);
581 /* Must repair monsters */
582 repair_monsters = TRUE;
585 /* Update the monster */
586 update_mon(m_idx, TRUE);
589 /* Pre-calculated in precalc_cur_num_of_pet() */
590 /* r_ptr->cur_num++; */
592 /* Hack -- Count the number of "reproducers" */
593 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
595 /* Hack -- Notice new multi-hued monsters */
597 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
598 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
599 shimmer_monsters = TRUE;
604 monster_type *m_ptr = &party_mon[i];
605 monster_race *r_ptr = real_r_ptr(m_ptr);
608 monster_desc(m_name, m_ptr, 0);
609 msg_format(_("%sとはぐれてしまった。", "You have lost sight of %s."), m_name);
610 if (record_named_pet && m_ptr->nickname)
612 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
613 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOST_SIGHT, m_name);
616 /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
617 if (r_ptr->cur_num) r_ptr->cur_num--;
621 /* For accuracy of precalc_cur_num_of_pet() */
622 (void)C_WIPE(party_mon, MAX_PARTY_MON, monster_type);
627 * @brief ユニークモンスターやアーティファクトの所在フロアを更新する / Hack -- Update location of unique monsters and artifacts
628 * @param cur_floor_id 現在のフロアID
631 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly\n
632 * while new floor creation since dungeons may be re-created by\n
633 * auto-scum option.\n
635 static void update_unique_artifact(s16b cur_floor_id)
639 /* Maintain unique monsters */
640 for (i = 1; i < m_max; i++)
643 monster_type *m_ptr = &m_list[i];
645 /* Skip dead monsters */
646 if (!m_ptr->r_idx) continue;
648 /* Extract real monster race */
649 r_ptr = real_r_ptr(m_ptr);
651 /* Memorize location of the unique monster */
652 if ((r_ptr->flags1 & RF1_UNIQUE) ||
653 (r_ptr->flags7 & RF7_NAZGUL))
655 r_ptr->floor_id = cur_floor_id;
659 /* Maintain artifatcs */
660 for (i = 1; i < o_max; i++)
662 object_type *o_ptr = &o_list[i];
664 /* Skip dead objects */
665 if (!o_ptr->k_idx) continue;
667 /* Memorize location of the artifact */
668 if (object_is_fixed_artifact(o_ptr))
670 a_info[o_ptr->name1].floor_id = cur_floor_id;
677 * @brief フロア移動時、プレイヤーの移動先モンスターが既にいた場合ランダムな近隣に移動させる / When a monster is at a place where player will return,
680 static void get_out_monster(void)
686 MONSTER_IDX m_idx = cave[oy][ox].m_idx;
688 /* Nothing to do if no monster */
691 /* Look until done */
696 /* Pick a (possibly illegal) location */
697 int ny = rand_spread(oy, dis);
698 int nx = rand_spread(ox, dis);
702 /* Stop after 1000 tries */
703 if (tries > 10000) return;
706 * Increase distance after doing enough tries
707 * compared to area of possible space
709 if (tries > 20 * dis * dis) dis++;
711 /* Ignore illegal locations */
712 if (!in_bounds(ny, nx)) continue;
714 /* Require "empty" floor space */
715 if (!cave_empty_bold(ny, nx)) continue;
717 /* Hack -- no teleport onto glyph of warding */
718 if (is_glyph_grid(&cave[ny][nx])) continue;
719 if (is_explosive_rune_grid(&cave[ny][nx])) continue;
721 /* ...nor onto the Pattern */
722 if (pattern_tile(ny, nx)) continue;
724 /*** It's a good place ***/
726 m_ptr = &m_list[m_idx];
728 /* Update the old location */
729 cave[oy][ox].m_idx = 0;
731 /* Update the new location */
732 cave[ny][nx].m_idx = m_idx;
734 /* Move the monster */
738 /* No need to do update_mon() */
746 * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / 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 * @brief 新フロアに移動元フロアに繋がる階段を配置する / Virtually teleport onto the stairs that is connecting between two floors.
753 * @param sf_ptr 移動元の保存フロア構造体参照ポインタ
756 static void locate_connected_stairs(saved_floor_type *sf_ptr)
758 int x, y, sx = 0, sy = 0;
764 /* Search usable stairs */
765 for (y = 0; y < cur_hgt; y++)
767 for (x = 0; x < cur_wid; x++)
769 cave_type *c_ptr = &cave[y][x];
770 feature_type *f_ptr = &f_info[c_ptr->feat];
773 if (change_floor_mode & CFM_UP)
775 if (have_flag(f_ptr->flags, FF_LESS) && have_flag(f_ptr->flags, FF_STAIRS) &&
776 !have_flag(f_ptr->flags, FF_SPECIAL))
780 /* Found fixed stairs? */
781 if (c_ptr->special &&
782 c_ptr->special == sf_ptr->upper_floor_id)
790 else if (change_floor_mode & CFM_DOWN)
792 if (have_flag(f_ptr->flags, FF_MORE) && have_flag(f_ptr->flags, FF_STAIRS) &&
793 !have_flag(f_ptr->flags, FF_SPECIAL))
797 /* Found fixed stairs */
798 if (c_ptr->special &&
799 c_ptr->special == sf_ptr->lower_floor_id)
809 if (have_flag(f_ptr->flags, FF_BLDG))
815 if (ok && (num < 20))
832 /* No stairs found! -- No return */
833 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
835 /* Mega Hack -- It's not the stairs you enter. Disable it. */
836 if (!feat_uses_special(cave[p_ptr->y][p_ptr->x].feat)) cave[p_ptr->y][p_ptr->x].special = 0;
840 /* Choose random one */
843 /* Point stair location */
844 p_ptr->y = y_table[i];
845 p_ptr->x = x_table[i];
850 * @brief 現在のフロアを離れるに伴って行なわれる保存処理
851 * / Maintain quest monsters, mark next floor_id at stairs, save current floor, and prepare to enter next floor.
854 void leave_floor(void)
856 cave_type *c_ptr = NULL;
858 saved_floor_type *sf_ptr;
862 /* Preserve pets and prepare to take these to next floor */
865 /* Remove all mirrors without explosion */
866 remove_all_mirrors(FALSE);
868 if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
870 /* New floor is not yet prepared */
873 /* Temporary get a floor_id (for Arena) */
874 if (!p_ptr->floor_id &&
875 (change_floor_mode & CFM_SAVE_FLOORS) &&
876 !(change_floor_mode & CFM_NO_RETURN))
878 /* Get temporal floor_id */
879 p_ptr->floor_id = get_new_floor_id();
883 /* Search the quest monster index */
884 for (i = 0; i < max_q_idx; i++)
886 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
887 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
888 (quest[i].type == QUEST_TYPE_RANDOM)) &&
889 (quest[i].level == dun_level) &&
890 (dungeon_type == quest[i].dungeon) &&
891 !(quest[i].flags & QUEST_FLAG_PRESET))
893 quest_r_idx = quest[i].r_idx;
897 /* Maintain quest monsters */
898 for (i = 1; i < m_max; i++)
901 monster_type *m_ptr = &m_list[i];
903 /* Skip dead monsters */
904 if (!m_ptr->r_idx) continue;
906 /* Only maintain quest monsters */
907 if (quest_r_idx != m_ptr->r_idx) continue;
909 /* Extract real monster race */
910 r_ptr = real_r_ptr(m_ptr);
912 /* Ignore unique monsters */
913 if ((r_ptr->flags1 & RF1_UNIQUE) ||
914 (r_ptr->flags7 & RF7_NAZGUL)) continue;
916 /* Delete non-unique quest monsters */
917 delete_monster_idx(i);
920 /* Check if there is a same item */
921 for (i = 0; i < INVEN_PACK; i++)
923 object_type *o_ptr = &inventory[i];
925 /* Skip dead objects */
926 if (!o_ptr->k_idx) continue;
928 /* Delete old memorized location of the artifact */
929 if (object_is_fixed_artifact(o_ptr))
931 a_info[o_ptr->name1].floor_id = 0;
935 /* Extract current floor info or NULL */
936 sf_ptr = get_sf_ptr(p_ptr->floor_id);
938 /* Choose random stairs */
939 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
941 locate_connected_stairs(sf_ptr);
944 /* Extract new dungeon level */
945 if (change_floor_mode & CFM_SAVE_FLOORS)
947 /* Extract stair position */
948 c_ptr = &cave[p_ptr->y][p_ptr->x];
949 f_ptr = &f_info[c_ptr->feat];
951 /* Get back to old saved floor? */
952 if (c_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(c_ptr->special))
954 /* Saved floor is exist. Use it. */
955 new_floor_id = c_ptr->special;
958 /* Mark shaft up/down */
959 if (have_flag(f_ptr->flags, FF_STAIRS) && have_flag(f_ptr->flags, FF_SHAFT))
961 prepare_change_floor_mode(CFM_SHAFT);
965 /* Climb up/down some sort of stairs */
966 if (change_floor_mode & (CFM_DOWN | CFM_UP))
970 /* Extract level movement number */
971 if (change_floor_mode & CFM_DOWN) move_num = 1;
972 else if (change_floor_mode & CFM_UP) move_num = -1;
974 /* Shafts are deeper than normal stairs */
975 if (change_floor_mode & CFM_SHAFT)
976 move_num += SGN(move_num);
978 /* Get out from or Enter the dungeon */
979 if (change_floor_mode & CFM_DOWN)
982 move_num = d_info[dungeon_type].mindepth;
984 else if (change_floor_mode & CFM_UP)
986 if (dun_level + move_num < d_info[dungeon_type].mindepth)
987 move_num = -dun_level;
990 dun_level += move_num;
993 /* Leaving the dungeon to town */
994 if (!dun_level && dungeon_type)
996 p_ptr->leaving_dungeon = TRUE;
997 if (!vanilla_town && !lite_town)
999 p_ptr->wilderness_y = d_info[dungeon_type].dy;
1000 p_ptr->wilderness_x = d_info[dungeon_type].dx;
1002 p_ptr->recall_dungeon = dungeon_type;
1005 /* Reach to the surface -- Clear all saved floors */
1006 change_floor_mode &= ~CFM_SAVE_FLOORS;
1009 /* Kill some old saved floors */
1010 if (!(change_floor_mode & CFM_SAVE_FLOORS))
1012 /* Kill all saved floors */
1013 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1014 kill_saved_floor(&saved_floors[i]);
1016 /* Reset visit_mark count */
1017 latest_visit_mark = 1;
1019 else if (change_floor_mode & CFM_NO_RETURN)
1021 /* Kill current floor */
1022 kill_saved_floor(sf_ptr);
1025 /* No current floor -- Left/Enter dungeon etc... */
1026 if (!p_ptr->floor_id)
1028 /* No longer need to save current floor */
1033 /* Mark next floor_id on the previous floor */
1037 new_floor_id = get_new_floor_id();
1039 /* Connect from here */
1040 if (c_ptr && !feat_uses_special(c_ptr->feat))
1042 c_ptr->special = new_floor_id;
1046 /* Fix connection -- level teleportation or trap door */
1047 if (change_floor_mode & CFM_RAND_CONNECT)
1049 if (change_floor_mode & CFM_UP)
1050 sf_ptr->upper_floor_id = new_floor_id;
1051 else if (change_floor_mode & CFM_DOWN)
1052 sf_ptr->lower_floor_id = new_floor_id;
1055 /* If you can return, you need to save previous floor */
1056 if ((change_floor_mode & CFM_SAVE_FLOORS) &&
1057 !(change_floor_mode & CFM_NO_RETURN))
1059 /* Get out of the my way! */
1062 /* Record the last visit turn of current floor */
1063 sf_ptr->last_visit = turn;
1065 /* Forget the lite */
1068 /* Forget the view */
1071 /* Forget the view */
1074 /* Save current floor */
1075 if (!save_floor(sf_ptr, 0))
1077 /* Save failed -- No return */
1078 prepare_change_floor_mode(CFM_NO_RETURN);
1080 /* Kill current floor */
1081 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
1088 * @brief フロアの切り替え処理 / Enter new floor.
1091 * If the floor is an old saved floor, it will be\n
1092 * restored from the temporal file. If the floor is new one, new cave\n
1093 * will be generated.\n
1095 void change_floor(void)
1097 saved_floor_type *sf_ptr;
1098 bool loaded = FALSE;
1100 /* The dungeon is not ready */
1101 character_dungeon = FALSE;
1103 /* No longer in the trap detecteded region */
1104 p_ptr->dtrap = FALSE;
1106 /* Mega-Hack -- no panel yet */
1112 /* Mega-Hack -- not ambushed on the wildness? */
1113 ambush_flag = FALSE;
1115 /* No saved floors (On the surface etc.) */
1116 if (!(change_floor_mode & CFM_SAVE_FLOORS) &&
1117 !(change_floor_mode & CFM_FIRST_FLOOR))
1122 /* Paranoia -- No new saved floor */
1126 /* In the dungeon */
1129 /* No floor_id yet */
1133 new_floor_id = get_new_floor_id();
1136 /* Pointer for infomations of new floor */
1137 sf_ptr = get_sf_ptr(new_floor_id);
1139 /* Try to restore old floor */
1140 if (sf_ptr->last_visit)
1142 /* Old saved floor is exist */
1143 if (load_floor(sf_ptr, 0))
1147 /* Forbid return stairs */
1148 if (change_floor_mode & CFM_NO_RETURN)
1150 cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
1152 if (!feat_uses_special(c_ptr->feat))
1154 if (change_floor_mode & (CFM_DOWN | CFM_UP))
1156 /* Reset to floor */
1157 c_ptr->feat = floor_type[randint0(100)];
1167 * Set lower/upper_floor_id of new floor when the new
1168 * floor is right-above/right-under the current floor.
1170 * Stair creation/Teleport level/Trap door will take
1171 * you the same floor when you used it later again.
1173 if (p_ptr->floor_id)
1175 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1177 if (change_floor_mode & CFM_UP)
1179 /* New floor is right-above */
1180 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1181 sf_ptr->lower_floor_id = p_ptr->floor_id;
1183 else if (change_floor_mode & CFM_DOWN)
1185 /* New floor is right-under */
1186 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1187 sf_ptr->upper_floor_id = p_ptr->floor_id;
1191 /* Break connection to killed floor */
1194 if (change_floor_mode & CFM_UP)
1195 sf_ptr->lower_floor_id = 0;
1196 else if (change_floor_mode & CFM_DOWN)
1197 sf_ptr->upper_floor_id = 0;
1200 /* Maintain monsters and artifacts */
1204 s32b tmp_last_visit = sf_ptr->last_visit;
1206 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
1209 while (tmp_last_visit > turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
1210 absence_ticks = (turn - tmp_last_visit) / TURNS_PER_TICK;
1212 /* Maintain monsters */
1213 for (i = 1; i < m_max; i++)
1215 monster_race *r_ptr;
1216 monster_type *m_ptr = &m_list[i];
1218 /* Skip dead monsters */
1219 if (!m_ptr->r_idx) continue;
1224 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1226 /* Remove timed status (except MTIMED_CSLEEP) */
1227 (void)set_monster_fast(i, 0);
1228 (void)set_monster_slow(i, 0);
1229 (void)set_monster_stunned(i, 0);
1230 (void)set_monster_confused(i, 0);
1231 (void)set_monster_monfear(i, 0);
1232 (void)set_monster_invulner(i, 0, FALSE);
1235 /* Extract real monster race */
1236 r_ptr = real_r_ptr(m_ptr);
1238 /* Ignore non-unique */
1239 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1240 !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1242 /* Appear at a different floor? */
1243 if (r_ptr->floor_id != new_floor_id)
1245 /* Disapper from here */
1246 delete_monster_idx(i);
1250 /* Maintain artifatcs */
1251 for (i = 1; i < o_max; i++)
1253 object_type *o_ptr = &o_list[i];
1255 /* Skip dead objects */
1256 if (!o_ptr->k_idx) continue;
1258 /* Ignore non-artifact */
1259 if (!object_is_fixed_artifact(o_ptr)) continue;
1261 /* Appear at a different floor? */
1262 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1264 /* Disappear from here */
1265 delete_object_idx(i);
1269 /* Cancel preserve */
1270 a_info[o_ptr->name1].cur_num = 1;
1274 (void)place_quest_monsters();
1276 /* Place some random monsters */
1277 alloc_times = absence_ticks / alloc_chance;
1279 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1282 for (i = 0; i < alloc_times; i++)
1284 /* Make a (group of) new monster */
1285 (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? */
1296 msg_print(_("階段は行き止まりだった。", "The staircases come to a dead end..."));
1298 /* Create simple dead end */
1301 /* Break connection */
1302 if (change_floor_mode & CFM_UP)
1304 sf_ptr->upper_floor_id = 0;
1306 else if (change_floor_mode & CFM_DOWN)
1308 sf_ptr->lower_floor_id = 0;
1313 /* Newly create cave */
1317 /* Record last visit turn */
1318 sf_ptr->last_visit = turn;
1320 /* Set correct dun_level value */
1321 sf_ptr->dun_level = dun_level;
1323 /* Create connected stairs */
1324 if (!(change_floor_mode & CFM_NO_RETURN))
1326 /* Extract stair position */
1327 cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
1329 /*** Create connected stairs ***/
1331 /* No stairs down from Quest */
1332 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1334 c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair;
1337 /* No stairs up when ironman_downward */
1338 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1340 c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair;
1343 /* Paranoia -- Clear mimic */
1346 /* Connect to previous floor */
1347 c_ptr->special = p_ptr->floor_id;
1351 /* Arrive at random grid */
1352 if (change_floor_mode & (CFM_RAND_PLACE))
1354 (void)new_player_spot();
1357 /* You see stairs blocked */
1358 else if ((change_floor_mode & CFM_NO_RETURN) &&
1359 (change_floor_mode & (CFM_DOWN | CFM_UP)))
1363 msg_print(_("突然階段が塞がれてしまった。", "Suddenly the stairs is blocked!"));
1367 msg_print(_("ゴトゴトと何か音がした。", "You hear some noises."));
1374 * The "turn" is not always different number because
1375 * the level teleport doesn't take any turn. Use
1376 * visit mark instead of last visit turn to find the
1377 * oldest saved floor.
1379 sf_ptr->visit_mark = latest_visit_mark++;
1382 /* Place preserved pet monsters */
1385 /* Reset travel target place */
1386 forget_travel_flow();
1388 /* Hack -- maintain unique and artifacts */
1389 update_unique_artifact(new_floor_id);
1391 /* Now the player is in new floor */
1392 p_ptr->floor_id = new_floor_id;
1394 /* The dungeon is ready */
1395 character_dungeon = TRUE;
1397 /* Hack -- Munchkin characters always get whole map */
1398 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1399 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1401 /* Remember when this level was "created" */
1404 /* No dungeon feeling yet */
1405 p_ptr->feeling_turn = old_turn;
1408 /* Clear all flags */
1409 change_floor_mode = 0L;
1411 select_floor_music();
1415 * @brief プレイヤーの手による能動的な階段生成処理 /
1416 * Create stairs at or move previously created stairs into the player location.
1419 void stair_creation(void)
1421 saved_floor_type *sf_ptr;
1422 saved_floor_type *dest_sf_ptr;
1426 s16b dest_floor_id = 0;
1429 /* Forbid up staircases on Ironman mode */
1430 if (ironman_downward) up = FALSE;
1432 /* Forbid down staircases on quest level */
1433 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1435 /* No effect out of standard dungeon floor */
1436 if (!dun_level || (!up && !down) ||
1437 (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1438 p_ptr->inside_arena || p_ptr->inside_battle)
1440 /* arena or quest */
1441 msg_print(_("効果がありません!", "There is no effect!"));
1445 /* Artifacts resists */
1446 if (!cave_valid_bold(p_ptr->y, p_ptr->x))
1448 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
1452 /* Destroy all objects in the grid */
1453 delete_object(p_ptr->y, p_ptr->x);
1455 /* Extract current floor data */
1456 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1461 /* No floor id? -- Create now! */
1462 p_ptr->floor_id = get_new_floor_id();
1463 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1466 /* Choose randomly */
1469 if (randint0(100) < 50) up = FALSE;
1473 /* Destination is already fixed */
1476 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1480 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1484 /* Search old stairs leading to the destination */
1489 for (y = 0; y < cur_hgt; y++)
1491 for (x = 0; x < cur_wid; x++)
1493 cave_type *c_ptr = &cave[y][x];
1495 if (!c_ptr->special) continue;
1496 if (feat_uses_special(c_ptr->feat)) continue;
1497 if (c_ptr->special != dest_floor_id) continue;
1499 /* Remove old stairs */
1501 cave_set_feat(y, x, floor_type[randint0(100)]);
1506 /* No old destination -- Get new one now */
1509 dest_floor_id = get_new_floor_id();
1513 sf_ptr->upper_floor_id = dest_floor_id;
1515 sf_ptr->lower_floor_id = dest_floor_id;
1518 /* Extract destination floor data */
1519 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1522 /* Create a staircase */
1525 cave_set_feat(p_ptr->y, p_ptr->x,
1526 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level <= dun_level - 2)) ?
1527 feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair);
1531 cave_set_feat(p_ptr->y, p_ptr->x,
1532 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level >= dun_level + 2)) ?
1533 feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair);
1537 /* Connect this stairs to the destination */
1538 cave[p_ptr->y][p_ptr->x].special = dest_floor_id;