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
20 static FLOOR_IDX new_floor_id; /*!<次のフロアのID / floor_id of the destination */
21 static u32b change_floor_mode; /*!<フロア移行処理に関するフラグ / Mode flags for changing floor */
22 static u32b latest_visit_mark; /*!<フロアを渡った回数?(確認中) / Max number of visit_mark */
26 * @brief 保存フロア配列を初期化する / Initialize saved_floors array.
27 * @param force テンポラリファイルが残っていた場合も警告なしで強制的に削除する。
28 * @details Make sure that old temporal files are not remaining as gurbages.
31 void init_saved_floors(bool force)
33 char floor_savefile[1024];
36 BIT_FLAGS mode = 0644;
40 /* Get "games" permissions */
45 for (i = 0; i < MAX_SAVED_FLOORS; i++)
47 saved_floor_type *sf_ptr = &saved_floors[i];
50 sprintf(floor_savefile, "%s.F%02d", savefile, i);
52 /* Grab permissions */
55 /* Try to create the file */
56 fd = fd_make(floor_savefile, mode);
58 /* Drop permissions */
66 msg_print(_("エラー:古いテンポラリ・ファイルが残っています。", "Error: There are old temporal files."));
67 msg_print(_("変愚蛮怒を二重に起動していないか確認してください。", "Make sure you are not running two game processes simultaneously."));
68 msg_print(_("過去に変愚蛮怒がクラッシュした場合は一時ファイルを", "If the temporal files are garbages of old crashed process, "));
69 msg_print(_("強制的に削除して実行を続けられます。", "you can delete it safely."));
70 if (!get_check(_("強制的に削除してもよろしいですか?", "Do you delete old temporal files? ")))
71 quit(_("実行中止", "Aborted."));
81 /* Grab permissions */
84 /* Simply kill the temporal file */
85 (void)fd_kill(floor_savefile);
87 /* Drop permissions */
93 /* No floor_id used yet (No.0 is reserved to indicate non existance) */
96 /* vist_mark is from 1 */
97 latest_visit_mark = 1;
99 /* A sign to mark temporal files */
100 saved_floor_file_sign = (u32b)time(NULL);
102 /* No next floor yet */
105 /* No change floor mode yet */
106 change_floor_mode = 0;
110 /* Drop "games" permissions */
117 * @brief 保存フロア用テンポラリファイルを削除する / Kill temporal files
118 * @details Should be called just before the game quit.
121 void clear_saved_floor_files(void)
123 char floor_savefile[1024];
128 /* Get "games" permissions */
133 for (i = 0; i < MAX_SAVED_FLOORS; i++)
135 saved_floor_type *sf_ptr = &saved_floors[i];
137 /* No temporal file */
138 if (!sf_ptr->floor_id) continue;
139 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
142 sprintf(floor_savefile, "%s.F%02d", savefile, i);
144 /* Grab permissions */
147 /* Simply kill the temporal file */
148 (void)fd_kill(floor_savefile);
150 /* Drop permissions */
156 /* Drop "games" permissions */
163 * @brief 保存フロアIDから参照ポインタを得る / Get a pointer for an item of the saved_floors array.
164 * @param floor_id 保存フロアID
165 * @return IDに対応する保存フロアのポインタ、ない場合はNULLを返す。
167 saved_floor_type *get_sf_ptr(FLOOR_IDX floor_id)
171 /* floor_id No.0 indicates no floor */
172 if (!floor_id) return NULL;
174 for (i = 0; i < MAX_SAVED_FLOORS; i++)
176 saved_floor_type *sf_ptr = &saved_floors[i];
178 if (sf_ptr->floor_id == floor_id) return sf_ptr;
187 * @brief 参照ポインタ先の保存フロアを抹消する / kill a saved floor and get an empty space
188 * @param sf_ptr 保存フロアの参照ポインタ
191 static void kill_saved_floor(saved_floor_type *sf_ptr)
193 char floor_savefile[1024];
199 if (!sf_ptr->floor_id) return;
201 if (sf_ptr->floor_id == p_ptr->floor_id)
203 /* Kill current floor */
206 /* Current floor doesn't have temporal file */
211 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
213 /* Grab permissions */
216 /* Simply kill the temporal file */
217 (void)fd_kill(floor_savefile);
219 /* Drop permissions */
223 /* No longer exists */
224 sf_ptr->floor_id = 0;
229 * @brief 新規に利用可能な保存フロアを返す / Initialize new saved floor and get its floor id.
230 * @return 利用可能な保存フロアID
232 * If number of saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
234 FLOOR_IDX get_new_floor_id(void)
236 saved_floor_type *sf_ptr = NULL;
239 /* Look for empty space */
240 for (i = 0; i < MAX_SAVED_FLOORS; i++)
242 sf_ptr = &saved_floors[i];
244 if (!sf_ptr->floor_id) break;
248 if (i == MAX_SAVED_FLOORS)
251 u32b oldest_visit = 0xffffffffL;
253 /* Search for oldest */
254 for (i = 0; i < MAX_SAVED_FLOORS; i++)
256 sf_ptr = &saved_floors[i];
258 /* Don't kill current floor */
259 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
261 /* Don't kill newer */
262 if (sf_ptr->visit_mark > oldest_visit) continue;
265 oldest_visit = sf_ptr->visit_mark;
268 /* Kill oldest saved floor */
269 sf_ptr = &saved_floors[oldest];
270 kill_saved_floor(sf_ptr);
276 /* Prepare new floor data */
277 sf_ptr->savefile_id = i;
278 sf_ptr->floor_id = max_floor_id;
279 sf_ptr->last_visit = 0;
280 sf_ptr->upper_floor_id = 0;
281 sf_ptr->lower_floor_id = 0;
282 sf_ptr->visit_mark = latest_visit_mark++;
284 /* sf_ptr->dun_level may be changed later */
285 sf_ptr->dun_level = dun_level;
288 /* Increment number of floor_id */
289 if (max_floor_id < MAX_SHORT) max_floor_id++;
291 /* 32767 floor_ids are all used up! Re-use ancient IDs */
292 else max_floor_id = 1;
294 return sf_ptr->floor_id;
299 * @brief フロア切り替え時の処理フラグを追加する / Prepare mode flags of changing floor
300 * @param mode 追加したい所持フラグ
303 void prepare_change_floor_mode(BIT_FLAGS mode)
305 change_floor_mode |= mode;
309 * @brief 階段移動先のフロアが生成できない時に簡単な行き止まりマップを作成する / 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 */
337 p_ptr->y = cur_hgt / 2;
338 p_ptr->x = cur_wid / 2;
340 /* Give one square */
341 place_floor_bold(p_ptr->y, p_ptr->x);
343 wipe_generate_cave_flags();
348 #define MAX_PARTY_MON 21 /*!< フロア移動時に先のフロアに連れて行けるペットの最大数 Maximum number of preservable pets */
349 static monster_type party_mon[MAX_PARTY_MON]; /*!< フロア移動に保存するペットモンスターの配列 */
352 * @brief フロア移動時のペット保存処理 / Preserve_pets
355 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 POSITION dis = distance(p_ptr->y, p_ptr->x, 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(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) ||
420 (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))))
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];
444 GAME_TEXT m_name[MAX_NLEN];
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. */
469 GAME_TEXT m_name[MAX_NLEN];
470 monster_desc(m_name, m_ptr, 0);
471 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
474 delete_monster_idx(i);
481 * @brief フロア移動時にペットを伴った場合の準備処理 / Pre-calculate the racial counters of preserved pets
484 * To prevent multiple generation of unique monster who is the minion of player
486 void precalc_cur_num_of_pet(void)
490 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
492 for (i = 0; i < max_num; i++)
494 m_ptr = &party_mon[i];
496 /* Skip empty monsters */
497 if (!m_ptr->r_idx) continue;
499 /* Hack -- Increase the racial counter */
500 real_r_ptr(m_ptr)->cur_num++;
505 * @brief 移動先のフロアに伴ったペットを配置する / Place preserved pet monsters on new floor
508 static void place_pet(void)
511 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
513 for (i = 0; i < max_num; i++)
515 POSITION cy = 0, cx = 0;
518 if (!(party_mon[i].r_idx)) continue;
523 p_ptr->riding = m_idx;
535 for (d = 1; d < A_MAX; d++)
537 for (j = 1000; j > 0; j--)
539 scatter(&cy, &cx, p_ptr->y, p_ptr->x, d, 0);
540 if (monster_can_enter(cy, cx, &r_info[party_mon[i].r_idx], 0)) break;
544 m_idx = (d == 6) ? 0 : m_pop();
549 monster_type *m_ptr = &m_list[m_idx];
552 cave[cy][cx].m_idx = m_idx;
554 m_ptr->r_idx = party_mon[i].r_idx;
556 /* Copy all member of the structure */
557 *m_ptr = party_mon[i];
558 r_ptr = real_r_ptr(m_ptr);
563 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
566 m_ptr->hold_o_idx = 0;
569 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
571 /* Monster is still being nice */
572 m_ptr->mflag |= (MFLAG_NICE);
574 /* Must repair monsters */
575 repair_monsters = TRUE;
577 update_monster(m_idx, TRUE);
580 /* Pre-calculated in precalc_cur_num_of_pet() */
581 /* r_ptr->cur_num++; */
583 /* Hack -- Count the number of "reproducers" */
584 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
586 /* Hack -- Notice new multi-hued monsters */
588 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
589 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
590 shimmer_monsters = TRUE;
595 monster_type *m_ptr = &party_mon[i];
596 monster_race *r_ptr = real_r_ptr(m_ptr);
597 GAME_TEXT m_name[MAX_NLEN];
599 monster_desc(m_name, m_ptr, 0);
600 msg_format(_("%sとはぐれてしまった。", "You have lost sight of %s."), m_name);
601 if (record_named_pet && m_ptr->nickname)
603 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
604 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOST_SIGHT, m_name);
607 /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
608 if (r_ptr->cur_num) r_ptr->cur_num--;
612 /* For accuracy of precalc_cur_num_of_pet() */
613 (void)C_WIPE(party_mon, MAX_PARTY_MON, monster_type);
618 * @brief ユニークモンスターやアーティファクトの所在フロアを更新する / Hack -- Update location of unique monsters and artifacts
619 * @param cur_floor_id 現在のフロアID
622 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly\n
623 * while new floor creation since dungeons may be re-created by\n
624 * auto-scum option.\n
626 static void update_unique_artifact(s16b cur_floor_id)
630 /* Maintain unique monsters */
631 for (i = 1; i < m_max; i++)
634 monster_type *m_ptr = &m_list[i];
636 /* Skip dead monsters */
637 if (!m_ptr->r_idx) continue;
639 /* Extract real monster race */
640 r_ptr = real_r_ptr(m_ptr);
642 /* Memorize location of the unique monster */
643 if ((r_ptr->flags1 & RF1_UNIQUE) ||
644 (r_ptr->flags7 & RF7_NAZGUL))
646 r_ptr->floor_id = cur_floor_id;
650 /* Maintain artifatcs */
651 for (i = 1; i < o_max; i++)
653 object_type *o_ptr = &o_list[i];
655 /* Skip dead objects */
656 if (!o_ptr->k_idx) continue;
658 /* Memorize location of the artifact */
659 if (object_is_fixed_artifact(o_ptr))
661 a_info[o_ptr->name1].floor_id = cur_floor_id;
668 * @brief フロア移動時、プレイヤーの移動先モンスターが既にいた場合ランダムな近隣に移動させる / When a monster is at a place where player will return,
671 static void get_out_monster(void)
675 POSITION oy = p_ptr->y;
676 POSITION ox = p_ptr->x;
677 MONSTER_IDX m_idx = cave[oy][ox].m_idx;
679 /* Nothing to do if no monster */
682 /* Look until done */
687 /* Pick a (possibly illegal) location */
688 POSITION ny = rand_spread(oy, dis);
689 POSITION nx = rand_spread(ox, dis);
693 /* Stop after 1000 tries */
694 if (tries > 10000) return;
697 * Increase distance after doing enough tries
698 * compared to area of possible space
700 if (tries > 20 * dis * dis) dis++;
702 /* Ignore illegal locations */
703 if (!in_bounds(ny, nx)) continue;
705 /* Require "empty" floor space */
706 if (!cave_empty_bold(ny, nx)) continue;
708 /* Hack -- no teleport onto glyph of warding */
709 if (is_glyph_grid(&cave[ny][nx])) continue;
710 if (is_explosive_rune_grid(&cave[ny][nx])) continue;
712 /* ...nor onto the Pattern */
713 if (pattern_tile(ny, nx)) continue;
715 /*** It's a good place ***/
717 m_ptr = &m_list[m_idx];
719 /* Update the old location */
720 cave[oy][ox].m_idx = 0;
722 /* Update the new location */
723 cave[ny][nx].m_idx = m_idx;
725 /* Move the monster */
729 /* No need to do update_monster() */
737 * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with c_ptr->special?
739 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
743 * @brief 新フロアに移動元フロアに繋がる階段を配置する / Virtually teleport onto the stairs that is connecting between two floors.
744 * @param sf_ptr 移動元の保存フロア構造体参照ポインタ
747 static void locate_connected_stairs(saved_floor_type *sf_ptr)
749 POSITION x, y, sx = 0, sy = 0;
750 POSITION x_table[20];
751 POSITION y_table[20];
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];
761 feature_type *f_ptr = &f_info[c_ptr->feat];
764 if (change_floor_mode & CFM_UP)
766 if (have_flag(f_ptr->flags, FF_LESS) && have_flag(f_ptr->flags, FF_STAIRS) &&
767 !have_flag(f_ptr->flags, FF_SPECIAL))
771 /* Found fixed stairs? */
772 if (c_ptr->special &&
773 c_ptr->special == sf_ptr->upper_floor_id)
781 else if (change_floor_mode & CFM_DOWN)
783 if (have_flag(f_ptr->flags, FF_MORE) && have_flag(f_ptr->flags, FF_STAIRS) &&
784 !have_flag(f_ptr->flags, FF_SPECIAL))
788 /* Found fixed stairs */
789 if (c_ptr->special &&
790 c_ptr->special == sf_ptr->lower_floor_id)
800 if (have_flag(f_ptr->flags, FF_BLDG))
806 if (ok && (num < 20))
823 /* No stairs found! -- No return */
824 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
826 /* Mega Hack -- It's not the stairs you enter. Disable it. */
827 if (!feat_uses_special(cave[p_ptr->y][p_ptr->x].feat)) cave[p_ptr->y][p_ptr->x].special = 0;
831 /* Choose random one */
834 /* Point stair location */
835 p_ptr->y = y_table[i];
836 p_ptr->x = x_table[i];
841 * @brief 現在のフロアを離れるに伴って行なわれる保存処理
842 * / Maintain quest monsters, mark next floor_id at stairs, save current floor, and prepare to enter next floor.
845 void leave_floor(void)
847 cave_type *c_ptr = NULL;
849 saved_floor_type *sf_ptr;
850 MONRACE_IDX quest_r_idx = 0;
853 /* Preserve pets and prepare to take these to next floor */
856 /* Remove all mirrors without explosion */
857 remove_all_mirrors(FALSE);
859 if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
861 /* New floor is not yet prepared */
864 /* Temporary get a floor_id (for Arena) */
865 if (!p_ptr->floor_id &&
866 (change_floor_mode & CFM_SAVE_FLOORS) &&
867 !(change_floor_mode & CFM_NO_RETURN))
869 /* Get temporal floor_id */
870 p_ptr->floor_id = get_new_floor_id();
873 /* Search the quest monster index */
874 for (i = 0; i < max_q_idx; i++)
876 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
877 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
878 (quest[i].type == QUEST_TYPE_RANDOM)) &&
879 (quest[i].level == dun_level) &&
880 (dungeon_type == quest[i].dungeon) &&
881 !(quest[i].flags & QUEST_FLAG_PRESET))
883 quest_r_idx = quest[i].r_idx;
887 /* Maintain quest monsters */
888 for (i = 1; i < m_max; i++)
891 monster_type *m_ptr = &m_list[i];
893 /* Skip dead monsters */
894 if (!m_ptr->r_idx) continue;
896 /* Only maintain quest monsters */
897 if (quest_r_idx != m_ptr->r_idx) continue;
899 /* Extract real monster race */
900 r_ptr = real_r_ptr(m_ptr);
902 /* Ignore unique monsters */
903 if ((r_ptr->flags1 & RF1_UNIQUE) ||
904 (r_ptr->flags7 & RF7_NAZGUL)) continue;
906 /* Delete non-unique quest monsters */
907 delete_monster_idx(i);
910 /* Check if there is a same item */
911 for (i = 0; i < INVEN_PACK; i++)
913 object_type *o_ptr = &inventory[i];
915 /* Skip dead objects */
916 if (!o_ptr->k_idx) continue;
918 /* Delete old memorized location of the artifact */
919 if (object_is_fixed_artifact(o_ptr))
921 a_info[o_ptr->name1].floor_id = 0;
925 /* Extract current floor info or NULL */
926 sf_ptr = get_sf_ptr(p_ptr->floor_id);
928 /* Choose random stairs */
929 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
931 locate_connected_stairs(sf_ptr);
934 /* Extract new dungeon level */
935 if (change_floor_mode & CFM_SAVE_FLOORS)
937 /* Extract stair position */
938 c_ptr = &cave[p_ptr->y][p_ptr->x];
939 f_ptr = &f_info[c_ptr->feat];
941 /* Get back to old saved floor? */
942 if (c_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(c_ptr->special))
944 /* Saved floor is exist. Use it. */
945 new_floor_id = c_ptr->special;
948 /* Mark shaft up/down */
949 if (have_flag(f_ptr->flags, FF_STAIRS) && have_flag(f_ptr->flags, FF_SHAFT))
951 prepare_change_floor_mode(CFM_SHAFT);
955 /* Climb up/down some sort of stairs */
956 if (change_floor_mode & (CFM_DOWN | CFM_UP))
960 /* Extract level movement number */
961 if (change_floor_mode & CFM_DOWN) move_num = 1;
962 else if (change_floor_mode & CFM_UP) move_num = -1;
964 /* Shafts are deeper than normal stairs */
965 if (change_floor_mode & CFM_SHAFT)
966 move_num += SGN(move_num);
968 /* Get out from or Enter the dungeon */
969 if (change_floor_mode & CFM_DOWN)
972 move_num = d_info[dungeon_type].mindepth;
974 else if (change_floor_mode & CFM_UP)
976 if (dun_level + move_num < d_info[dungeon_type].mindepth)
977 move_num = -dun_level;
980 dun_level += move_num;
983 /* Leaving the dungeon to town */
984 if (!dun_level && dungeon_type)
986 p_ptr->leaving_dungeon = TRUE;
987 if (!vanilla_town && !lite_town)
989 p_ptr->wilderness_y = d_info[dungeon_type].dy;
990 p_ptr->wilderness_x = d_info[dungeon_type].dx;
992 p_ptr->recall_dungeon = dungeon_type;
995 /* Reach to the surface -- Clear all saved floors */
996 change_floor_mode &= ~CFM_SAVE_FLOORS;
999 /* Kill some old saved floors */
1000 if (!(change_floor_mode & CFM_SAVE_FLOORS))
1002 /* Kill all saved floors */
1003 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1004 kill_saved_floor(&saved_floors[i]);
1006 /* Reset visit_mark count */
1007 latest_visit_mark = 1;
1009 else if (change_floor_mode & CFM_NO_RETURN)
1011 /* Kill current floor */
1012 kill_saved_floor(sf_ptr);
1015 /* No current floor -- Left/Enter dungeon etc... */
1016 if (!p_ptr->floor_id)
1018 /* No longer need to save current floor */
1023 /* Mark next floor_id on the previous floor */
1027 new_floor_id = get_new_floor_id();
1029 /* Connect from here */
1030 if (c_ptr && !feat_uses_special(c_ptr->feat))
1032 c_ptr->special = new_floor_id;
1036 /* Fix connection -- level teleportation or trap door */
1037 if (change_floor_mode & CFM_RAND_CONNECT)
1039 if (change_floor_mode & CFM_UP)
1040 sf_ptr->upper_floor_id = new_floor_id;
1041 else if (change_floor_mode & CFM_DOWN)
1042 sf_ptr->lower_floor_id = new_floor_id;
1045 /* If you can return, you need to save previous floor */
1046 if ((change_floor_mode & CFM_SAVE_FLOORS) &&
1047 !(change_floor_mode & CFM_NO_RETURN))
1049 /* Get out of the my way! */
1052 /* Record the last visit turn of current floor */
1053 sf_ptr->last_visit = turn;
1059 /* Save current floor */
1060 if (!save_floor(sf_ptr, 0))
1062 /* Save failed -- No return */
1063 prepare_change_floor_mode(CFM_NO_RETURN);
1065 /* Kill current floor */
1066 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
1073 * @brief フロアの切り替え処理 / Enter new floor.
1076 * If the floor is an old saved floor, it will be\n
1077 * restored from the temporal file. If the floor is new one, new cave\n
1078 * will be generated.\n
1080 void change_floor(void)
1082 saved_floor_type *sf_ptr;
1083 bool loaded = FALSE;
1085 /* The dungeon is not ready */
1086 character_dungeon = FALSE;
1088 /* No longer in the trap detecteded region */
1089 p_ptr->dtrap = FALSE;
1091 /* Mega-Hack -- no panel yet */
1097 /* Mega-Hack -- not ambushed on the wildness? */
1098 ambush_flag = FALSE;
1100 /* No saved floors (On the surface etc.) */
1101 if (!(change_floor_mode & CFM_SAVE_FLOORS) &&
1102 !(change_floor_mode & CFM_FIRST_FLOOR))
1107 /* Paranoia -- No new saved floor */
1111 /* In the dungeon */
1114 /* No floor_id yet */
1118 new_floor_id = get_new_floor_id();
1121 /* Pointer for infomations of new floor */
1122 sf_ptr = get_sf_ptr(new_floor_id);
1124 /* Try to restore old floor */
1125 if (sf_ptr->last_visit)
1127 /* Old saved floor is exist */
1128 if (load_floor(sf_ptr, 0))
1132 /* Forbid return stairs */
1133 if (change_floor_mode & CFM_NO_RETURN)
1135 cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
1137 if (!feat_uses_special(c_ptr->feat))
1139 if (change_floor_mode & (CFM_DOWN | CFM_UP))
1141 /* Reset to floor */
1142 c_ptr->feat = floor_type[randint0(100)];
1152 * Set lower/upper_floor_id of new floor when the new
1153 * floor is right-above/right-under the current floor.
1155 * Stair creation/Teleport level/Trap door will take
1156 * you the same floor when you used it later again.
1158 if (p_ptr->floor_id)
1160 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1162 if (change_floor_mode & CFM_UP)
1164 /* New floor is right-above */
1165 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1166 sf_ptr->lower_floor_id = p_ptr->floor_id;
1168 else if (change_floor_mode & CFM_DOWN)
1170 /* New floor is right-under */
1171 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1172 sf_ptr->upper_floor_id = p_ptr->floor_id;
1176 /* Break connection to killed floor */
1179 if (change_floor_mode & CFM_UP)
1180 sf_ptr->lower_floor_id = 0;
1181 else if (change_floor_mode & CFM_DOWN)
1182 sf_ptr->upper_floor_id = 0;
1185 /* Maintain monsters and artifacts */
1189 GAME_TURN tmp_last_visit = sf_ptr->last_visit;
1190 GAME_TURN absence_ticks;
1191 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
1192 GAME_TURN alloc_times;
1194 while (tmp_last_visit > turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
1195 absence_ticks = (turn - tmp_last_visit) / TURNS_PER_TICK;
1197 /* Maintain monsters */
1198 for (i = 1; i < m_max; i++)
1200 monster_race *r_ptr;
1201 monster_type *m_ptr = &m_list[i];
1203 /* Skip dead monsters */
1204 if (!m_ptr->r_idx) continue;
1209 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1211 /* Remove timed status (except MTIMED_CSLEEP) */
1212 (void)set_monster_fast(i, 0);
1213 (void)set_monster_slow(i, 0);
1214 (void)set_monster_stunned(i, 0);
1215 (void)set_monster_confused(i, 0);
1216 (void)set_monster_monfear(i, 0);
1217 (void)set_monster_invulner(i, 0, FALSE);
1220 /* Extract real monster race */
1221 r_ptr = real_r_ptr(m_ptr);
1223 /* Ignore non-unique */
1224 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1225 !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1227 /* Appear at a different floor? */
1228 if (r_ptr->floor_id != new_floor_id)
1230 /* Disapper from here */
1231 delete_monster_idx(i);
1235 /* Maintain artifatcs */
1236 for (i = 1; i < o_max; i++)
1238 object_type *o_ptr = &o_list[i];
1240 /* Skip dead objects */
1241 if (!o_ptr->k_idx) continue;
1243 /* Ignore non-artifact */
1244 if (!object_is_fixed_artifact(o_ptr)) continue;
1246 /* Appear at a different floor? */
1247 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1249 /* Disappear from here */
1250 delete_object_idx(i);
1254 /* Cancel preserve */
1255 a_info[o_ptr->name1].cur_num = 1;
1259 (void)place_quest_monsters();
1261 /* Place some random monsters */
1262 alloc_times = absence_ticks / alloc_chance;
1264 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1267 for (i = 0; i < alloc_times; i++)
1269 /* Make a (group of) new monster */
1270 (void)alloc_monster(0, 0);
1275 /* New floor_id or failed to restore */
1276 else /* if (!loaded) */
1278 if (sf_ptr->last_visit)
1280 /* Temporal file is broken? */
1281 msg_print(_("階段は行き止まりだった。", "The staircases come to a dead end..."));
1283 /* Create simple dead end */
1286 /* Break connection */
1287 if (change_floor_mode & CFM_UP)
1289 sf_ptr->upper_floor_id = 0;
1291 else if (change_floor_mode & CFM_DOWN)
1293 sf_ptr->lower_floor_id = 0;
1298 /* Newly create cave */
1302 /* Record last visit turn */
1303 sf_ptr->last_visit = turn;
1305 /* Set correct dun_level value */
1306 sf_ptr->dun_level = dun_level;
1308 /* Create connected stairs */
1309 if (!(change_floor_mode & CFM_NO_RETURN))
1311 /* Extract stair position */
1312 cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
1314 /*** Create connected stairs ***/
1316 /* No stairs down from Quest */
1317 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1319 c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair;
1322 /* No stairs up when ironman_downward */
1323 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1325 c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair;
1328 /* Paranoia -- Clear mimic */
1331 /* Connect to previous floor */
1332 c_ptr->special = p_ptr->floor_id;
1336 /* Arrive at random grid */
1337 if (change_floor_mode & (CFM_RAND_PLACE))
1339 (void)new_player_spot();
1342 /* You see stairs blocked */
1343 else if ((change_floor_mode & CFM_NO_RETURN) && (change_floor_mode & (CFM_DOWN | CFM_UP)))
1347 msg_print(_("突然階段が塞がれてしまった。", "Suddenly the stairs is blocked!"));
1351 msg_print(_("ゴトゴトと何か音がした。", "You hear some noises."));
1358 * The "turn" is not always different number because
1359 * the level teleport doesn't take any turn. Use
1360 * visit mark instead of last visit turn to find the
1361 * oldest saved floor.
1363 sf_ptr->visit_mark = latest_visit_mark++;
1366 /* Place preserved pet monsters */
1369 /* Reset travel target place */
1370 forget_travel_flow();
1372 /* Hack -- maintain unique and artifacts */
1373 update_unique_artifact(new_floor_id);
1375 /* Now the player is in new floor */
1376 p_ptr->floor_id = new_floor_id;
1378 /* The dungeon is ready */
1379 character_dungeon = TRUE;
1381 /* Hack -- Munchkin characters always get whole map */
1382 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1383 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1385 /* Remember when this level was "created" */
1388 /* No dungeon feeling yet */
1389 p_ptr->feeling_turn = old_turn;
1392 /* Clear all flags */
1393 change_floor_mode = 0L;
1395 select_floor_music();
1399 * @brief プレイヤーの手による能動的な階段生成処理 /
1400 * Create stairs at or move previously created stairs into the player location.
1403 void stair_creation(void)
1405 saved_floor_type *sf_ptr;
1406 saved_floor_type *dest_sf_ptr;
1410 FLOOR_IDX dest_floor_id = 0;
1413 /* Forbid up staircases on Ironman mode */
1414 if (ironman_downward) up = FALSE;
1416 /* Forbid down staircases on quest level */
1417 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1419 /* No effect out of standard dungeon floor */
1420 if (!dun_level || (!up && !down) ||
1421 (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1422 p_ptr->inside_arena || p_ptr->inside_battle)
1424 /* arena or quest */
1425 msg_print(_("効果がありません!", "There is no effect!"));
1429 /* Artifacts resists */
1430 if (!cave_valid_bold(p_ptr->y, p_ptr->x))
1432 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
1436 /* Destroy all objects in the grid */
1437 delete_object(p_ptr->y, p_ptr->x);
1439 /* Extract current floor data */
1440 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1445 /* No floor id? -- Create now! */
1446 p_ptr->floor_id = get_new_floor_id();
1447 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1450 /* Choose randomly */
1453 if (randint0(100) < 50) up = FALSE;
1457 /* Destination is already fixed */
1460 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1464 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1468 /* Search old stairs leading to the destination */
1473 for (y = 0; y < cur_hgt; y++)
1475 for (x = 0; x < cur_wid; x++)
1477 cave_type *c_ptr = &cave[y][x];
1479 if (!c_ptr->special) continue;
1480 if (feat_uses_special(c_ptr->feat)) continue;
1481 if (c_ptr->special != dest_floor_id) continue;
1483 /* Remove old stairs */
1485 cave_set_feat(y, x, floor_type[randint0(100)]);
1490 /* No old destination -- Get new one now */
1493 dest_floor_id = get_new_floor_id();
1497 sf_ptr->upper_floor_id = dest_floor_id;
1499 sf_ptr->lower_floor_id = dest_floor_id;
1502 /* Extract destination floor data */
1503 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1506 /* Create a staircase */
1509 cave_set_feat(p_ptr->y, p_ptr->x,
1510 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level <= dun_level - 2)) ?
1511 feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair);
1515 cave_set_feat(p_ptr->y, p_ptr->x,
1516 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level >= dun_level + 2)) ?
1517 feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair);
1521 /* Connect this stairs to the destination */
1522 cave[p_ptr->y][p_ptr->x].special = dest_floor_id;