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
18 static s16b new_floor_id; /*!<次のフロアのID / floor_id of the destination */
19 static u32b change_floor_mode; /*!<フロア移行処理に関するフラグ / Mode flags for changing floor */
20 static u32b latest_visit_mark; /*!<フロアを渡った回数?(確認中) / Max number of visit_mark */
24 * @brief 保存フロア配列を初期化する / Initialize saved_floors array.
25 * @param force テンポラリファイルが残っていた場合も警告なしで強制的に削除する。
26 * @details Make sure that old temporal files are not remaining as gurbages.
29 void init_saved_floors(bool force)
31 char floor_savefile[1024];
34 BIT_FLAGS mode = 0644;
38 /* Get "games" permissions */
43 for (i = 0; i < MAX_SAVED_FLOORS; i++)
45 saved_floor_type *sf_ptr = &saved_floors[i];
48 sprintf(floor_savefile, "%s.F%02d", savefile, i);
50 /* Grab permissions */
53 /* Try to create the file */
54 fd = fd_make(floor_savefile, mode);
56 /* Drop permissions */
64 msg_print(_("エラー:古いテンポラリ・ファイルが残っています。", "Error: There are old temporal files."));
65 msg_print(_("変愚蛮怒を二重に起動していないか確認してください。", "Make sure you are not running two game processes simultaneously."));
66 msg_print(_("過去に変愚蛮怒がクラッシュした場合は一時ファイルを", "If the temporal files are garbages of old crashed process, "));
67 msg_print(_("強制的に削除して実行を続けられます。", "you can delete it safely."));
68 if (!get_check(_("強制的に削除してもよろしいですか?", "Do you delete old temporal files? ")))
69 quit(_("実行中止", "Aborted."));
79 /* Grab permissions */
82 /* Simply kill the temporal file */
83 (void)fd_kill(floor_savefile);
85 /* Drop permissions */
91 /* No floor_id used yet (No.0 is reserved to indicate non existance) */
94 /* vist_mark is from 1 */
95 latest_visit_mark = 1;
97 /* A sign to mark temporal files */
98 saved_floor_file_sign = (u32b)time(NULL);
100 /* No next floor yet */
103 /* No change floor mode yet */
104 change_floor_mode = 0;
108 /* Drop "games" permissions */
115 * @brief 保存フロア用テンポラリファイルを削除する / Kill temporal files
116 * @details Should be called just before the game quit.
119 void clear_saved_floor_files(void)
121 char floor_savefile[1024];
126 /* Get "games" permissions */
131 for (i = 0; i < MAX_SAVED_FLOORS; i++)
133 saved_floor_type *sf_ptr = &saved_floors[i];
135 /* No temporal file */
136 if (!sf_ptr->floor_id) continue;
137 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
140 sprintf(floor_savefile, "%s.F%02d", savefile, i);
142 /* Grab permissions */
145 /* Simply kill the temporal file */
146 (void)fd_kill(floor_savefile);
148 /* Drop permissions */
154 /* Drop "games" permissions */
161 * @brief 保存フロアIDから参照ポインタを得る / Get a pointer for an item of the saved_floors array.
162 * @param floor_id 保存フロアID
163 * @return IDに対応する保存フロアのポインタ、ない場合はNULLを返す。
165 saved_floor_type *get_sf_ptr(FLOOR_IDX floor_id)
169 /* floor_id No.0 indicates no floor */
170 if (!floor_id) return NULL;
172 for (i = 0; i < MAX_SAVED_FLOORS; i++)
174 saved_floor_type *sf_ptr = &saved_floors[i];
176 if (sf_ptr->floor_id == floor_id) return sf_ptr;
185 * @brief 参照ポインタ先の保存フロアを抹消する / kill a saved floor and get an empty space
186 * @param sf_ptr 保存フロアの参照ポインタ
189 static void kill_saved_floor(saved_floor_type *sf_ptr)
191 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 * @brief 新規に利用可能な保存フロアを返す / Initialize new saved floor and get its floor id.
228 * @return 利用可能な保存フロアID
230 * If number of saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
232 s16b get_new_floor_id(void)
234 saved_floor_type *sf_ptr = NULL;
237 /* Look for empty space */
238 for (i = 0; i < MAX_SAVED_FLOORS; i++)
240 sf_ptr = &saved_floors[i];
242 if (!sf_ptr->floor_id) break;
246 if (i == MAX_SAVED_FLOORS)
249 u32b oldest_visit = 0xffffffffL;
251 /* Search for oldest */
252 for (i = 0; i < MAX_SAVED_FLOORS; i++)
254 sf_ptr = &saved_floors[i];
256 /* Don't kill current floor */
257 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
259 /* Don't kill newer */
260 if (sf_ptr->visit_mark > oldest_visit) continue;
263 oldest_visit = sf_ptr->visit_mark;
266 /* Kill oldest saved floor */
267 sf_ptr = &saved_floors[oldest];
268 kill_saved_floor(sf_ptr);
274 /* Prepare new floor data */
275 sf_ptr->savefile_id = i;
276 sf_ptr->floor_id = max_floor_id;
277 sf_ptr->last_visit = 0;
278 sf_ptr->upper_floor_id = 0;
279 sf_ptr->lower_floor_id = 0;
280 sf_ptr->visit_mark = latest_visit_mark++;
282 /* sf_ptr->dun_level may be changed later */
283 sf_ptr->dun_level = dun_level;
286 /* Increment number of floor_id */
287 if (max_floor_id < MAX_SHORT) max_floor_id++;
289 /* 32767 floor_ids are all used up! Re-use ancient IDs */
290 else max_floor_id = 1;
292 return sf_ptr->floor_id;
297 * @brief フロア切り替え時の処理フラグを追加する / Prepare mode flags of changing floor
298 * @param mode 追加したい所持フラグ
301 void prepare_change_floor_mode(BIT_FLAGS mode)
303 change_floor_mode |= mode;
307 * @brief 階段移動先のフロアが生成できない時に簡単な行き止まりマップを作成する / Builds the dead end
310 static void build_dead_end(void)
314 /* Clear and empty the cave */
317 /* Fill the arrays of floors and walls in the good proportions */
318 set_floor_and_wall(0);
321 cur_hgt = SCREEN_HGT;
322 cur_wid = SCREEN_WID;
324 /* Filled with permanent walls */
325 for (y = 0; y < MAX_HGT; y++)
327 for (x = 0; x < MAX_WID; x++)
329 /* Create "solid" perma-wall */
330 place_solid_perm_bold(y, x);
334 /* Place at center of the floor */
335 p_ptr->y = cur_hgt / 2;
336 p_ptr->x = cur_wid / 2;
338 /* Give one square */
339 place_floor_bold(p_ptr->y, p_ptr->x);
341 wipe_generate_cave_flags();
346 #define MAX_PARTY_MON 21 /*!< フロア移動時に先のフロアに連れて行けるペットの最大数 Maximum number of preservable pets */
347 static monster_type party_mon[MAX_PARTY_MON]; /*!< フロア移動に保存するペットモンスターの配列 */
350 * @brief フロア移動時のペット保存処理 / Preserve_pets
353 static void preserve_pet(void)
358 for (num = 0; num < MAX_PARTY_MON; num++)
360 party_mon[num].r_idx = 0;
365 monster_type *m_ptr = &m_list[p_ptr->riding];
367 /* Pet of other pet don't follow. */
368 if (m_ptr->parent_m_idx)
371 p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
372 p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
376 /* Preserve the mount */
377 (void)COPY(&party_mon[0], m_ptr, monster_type);
379 /* Delete from this floor */
380 delete_monster_idx(p_ptr->riding);
385 * If player is in wild mode, no pets are preserved
386 * except a monster whom player riding
388 if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->inside_battle)
390 for (i = m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
392 monster_type *m_ptr = &m_list[i];
394 if (!m_ptr->r_idx) continue;
395 if (!is_pet(m_ptr)) continue;
396 if (i == p_ptr->riding) continue;
398 if (reinit_wilderness)
400 /* Don't lose sight of pets when getting a Quest */
404 POSITION dis = distance(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx);
406 /* Confused (etc.) monsters don't follow. */
407 if (MON_CONFUSED(m_ptr) || MON_STUNNED(m_ptr) || MON_CSLEEP(m_ptr)) continue;
409 /* Pet of other pet don't follow. */
410 if (m_ptr->parent_m_idx) continue;
413 * Pets with nickname will follow even from 3 blocks away
414 * when you or the pet can see the other.
416 if (m_ptr->nickname &&
417 ((player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) ||
418 (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))))
420 if (dis > 3) continue;
424 if (dis > 1) continue;
428 (void)COPY(&party_mon[num], &m_list[i], monster_type);
432 /* Delete from this floor */
433 delete_monster_idx(i);
437 if (record_named_pet)
439 for (i = m_max - 1; i >=1; i--)
441 monster_type *m_ptr = &m_list[i];
444 if (!m_ptr->r_idx) continue;
445 if (!is_pet(m_ptr)) continue;
446 if (!m_ptr->nickname) continue;
447 if (p_ptr->riding == i) continue;
449 monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
450 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_MOVED, m_name);
455 /* Pet of other pet may disappear. */
456 for (i = m_max - 1; i >=1; i--)
458 monster_type *m_ptr = &m_list[i];
460 /* Are there its parent? */
461 if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
463 /* Its parent have gone, it also goes away. */
469 /* Acquire the monster name */
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 < 6; 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);
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();
874 /* Search the quest monster index */
875 for (i = 0; i < max_q_idx; i++)
877 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
878 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
879 (quest[i].type == QUEST_TYPE_RANDOM)) &&
880 (quest[i].level == dun_level) &&
881 (dungeon_type == quest[i].dungeon) &&
882 !(quest[i].flags & QUEST_FLAG_PRESET))
884 quest_r_idx = quest[i].r_idx;
888 /* Maintain quest monsters */
889 for (i = 1; i < m_max; i++)
892 monster_type *m_ptr = &m_list[i];
894 /* Skip dead monsters */
895 if (!m_ptr->r_idx) continue;
897 /* Only maintain quest monsters */
898 if (quest_r_idx != m_ptr->r_idx) continue;
900 /* Extract real monster race */
901 r_ptr = real_r_ptr(m_ptr);
903 /* Ignore unique monsters */
904 if ((r_ptr->flags1 & RF1_UNIQUE) ||
905 (r_ptr->flags7 & RF7_NAZGUL)) continue;
907 /* Delete non-unique quest monsters */
908 delete_monster_idx(i);
911 /* Check if there is a same item */
912 for (i = 0; i < INVEN_PACK; i++)
914 object_type *o_ptr = &inventory[i];
916 /* Skip dead objects */
917 if (!o_ptr->k_idx) continue;
919 /* Delete old memorized location of the artifact */
920 if (object_is_fixed_artifact(o_ptr))
922 a_info[o_ptr->name1].floor_id = 0;
926 /* Extract current floor info or NULL */
927 sf_ptr = get_sf_ptr(p_ptr->floor_id);
929 /* Choose random stairs */
930 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
932 locate_connected_stairs(sf_ptr);
935 /* Extract new dungeon level */
936 if (change_floor_mode & CFM_SAVE_FLOORS)
938 /* Extract stair position */
939 c_ptr = &cave[p_ptr->y][p_ptr->x];
940 f_ptr = &f_info[c_ptr->feat];
942 /* Get back to old saved floor? */
943 if (c_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(c_ptr->special))
945 /* Saved floor is exist. Use it. */
946 new_floor_id = c_ptr->special;
949 /* Mark shaft up/down */
950 if (have_flag(f_ptr->flags, FF_STAIRS) && have_flag(f_ptr->flags, FF_SHAFT))
952 prepare_change_floor_mode(CFM_SHAFT);
956 /* Climb up/down some sort of stairs */
957 if (change_floor_mode & (CFM_DOWN | CFM_UP))
961 /* Extract level movement number */
962 if (change_floor_mode & CFM_DOWN) move_num = 1;
963 else if (change_floor_mode & CFM_UP) move_num = -1;
965 /* Shafts are deeper than normal stairs */
966 if (change_floor_mode & CFM_SHAFT)
967 move_num += SGN(move_num);
969 /* Get out from or Enter the dungeon */
970 if (change_floor_mode & CFM_DOWN)
973 move_num = d_info[dungeon_type].mindepth;
975 else if (change_floor_mode & CFM_UP)
977 if (dun_level + move_num < d_info[dungeon_type].mindepth)
978 move_num = -dun_level;
981 dun_level += move_num;
984 /* Leaving the dungeon to town */
985 if (!dun_level && dungeon_type)
987 p_ptr->leaving_dungeon = TRUE;
988 if (!vanilla_town && !lite_town)
990 p_ptr->wilderness_y = d_info[dungeon_type].dy;
991 p_ptr->wilderness_x = d_info[dungeon_type].dx;
993 p_ptr->recall_dungeon = dungeon_type;
996 /* Reach to the surface -- Clear all saved floors */
997 change_floor_mode &= ~CFM_SAVE_FLOORS;
1000 /* Kill some old saved floors */
1001 if (!(change_floor_mode & CFM_SAVE_FLOORS))
1003 /* Kill all saved floors */
1004 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1005 kill_saved_floor(&saved_floors[i]);
1007 /* Reset visit_mark count */
1008 latest_visit_mark = 1;
1010 else if (change_floor_mode & CFM_NO_RETURN)
1012 /* Kill current floor */
1013 kill_saved_floor(sf_ptr);
1016 /* No current floor -- Left/Enter dungeon etc... */
1017 if (!p_ptr->floor_id)
1019 /* No longer need to save current floor */
1024 /* Mark next floor_id on the previous floor */
1028 new_floor_id = get_new_floor_id();
1030 /* Connect from here */
1031 if (c_ptr && !feat_uses_special(c_ptr->feat))
1033 c_ptr->special = new_floor_id;
1037 /* Fix connection -- level teleportation or trap door */
1038 if (change_floor_mode & CFM_RAND_CONNECT)
1040 if (change_floor_mode & CFM_UP)
1041 sf_ptr->upper_floor_id = new_floor_id;
1042 else if (change_floor_mode & CFM_DOWN)
1043 sf_ptr->lower_floor_id = new_floor_id;
1046 /* If you can return, you need to save previous floor */
1047 if ((change_floor_mode & CFM_SAVE_FLOORS) &&
1048 !(change_floor_mode & CFM_NO_RETURN))
1050 /* Get out of the my way! */
1053 /* Record the last visit turn of current floor */
1054 sf_ptr->last_visit = turn;
1056 /* Forget the lite */
1059 /* Forget the view */
1062 /* Forget the view */
1065 /* Save current floor */
1066 if (!save_floor(sf_ptr, 0))
1068 /* Save failed -- No return */
1069 prepare_change_floor_mode(CFM_NO_RETURN);
1071 /* Kill current floor */
1072 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
1079 * @brief フロアの切り替え処理 / Enter new floor.
1082 * If the floor is an old saved floor, it will be\n
1083 * restored from the temporal file. If the floor is new one, new cave\n
1084 * will be generated.\n
1086 void change_floor(void)
1088 saved_floor_type *sf_ptr;
1089 bool loaded = FALSE;
1091 /* The dungeon is not ready */
1092 character_dungeon = FALSE;
1094 /* No longer in the trap detecteded region */
1095 p_ptr->dtrap = FALSE;
1097 /* Mega-Hack -- no panel yet */
1103 /* Mega-Hack -- not ambushed on the wildness? */
1104 ambush_flag = FALSE;
1106 /* No saved floors (On the surface etc.) */
1107 if (!(change_floor_mode & CFM_SAVE_FLOORS) &&
1108 !(change_floor_mode & CFM_FIRST_FLOOR))
1113 /* Paranoia -- No new saved floor */
1117 /* In the dungeon */
1120 /* No floor_id yet */
1124 new_floor_id = get_new_floor_id();
1127 /* Pointer for infomations of new floor */
1128 sf_ptr = get_sf_ptr(new_floor_id);
1130 /* Try to restore old floor */
1131 if (sf_ptr->last_visit)
1133 /* Old saved floor is exist */
1134 if (load_floor(sf_ptr, 0))
1138 /* Forbid return stairs */
1139 if (change_floor_mode & CFM_NO_RETURN)
1141 cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
1143 if (!feat_uses_special(c_ptr->feat))
1145 if (change_floor_mode & (CFM_DOWN | CFM_UP))
1147 /* Reset to floor */
1148 c_ptr->feat = floor_type[randint0(100)];
1158 * Set lower/upper_floor_id of new floor when the new
1159 * floor is right-above/right-under the current floor.
1161 * Stair creation/Teleport level/Trap door will take
1162 * you the same floor when you used it later again.
1164 if (p_ptr->floor_id)
1166 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1168 if (change_floor_mode & CFM_UP)
1170 /* New floor is right-above */
1171 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1172 sf_ptr->lower_floor_id = p_ptr->floor_id;
1174 else if (change_floor_mode & CFM_DOWN)
1176 /* New floor is right-under */
1177 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1178 sf_ptr->upper_floor_id = p_ptr->floor_id;
1182 /* Break connection to killed floor */
1185 if (change_floor_mode & CFM_UP)
1186 sf_ptr->lower_floor_id = 0;
1187 else if (change_floor_mode & CFM_DOWN)
1188 sf_ptr->upper_floor_id = 0;
1191 /* Maintain monsters and artifacts */
1195 s32b tmp_last_visit = sf_ptr->last_visit;
1197 int alloc_chance = d_info[dungeon_type].max_m_alloc_chance;
1200 while (tmp_last_visit > turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
1201 absence_ticks = (turn - tmp_last_visit) / TURNS_PER_TICK;
1203 /* Maintain monsters */
1204 for (i = 1; i < m_max; i++)
1206 monster_race *r_ptr;
1207 monster_type *m_ptr = &m_list[i];
1209 /* Skip dead monsters */
1210 if (!m_ptr->r_idx) continue;
1215 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1217 /* Remove timed status (except MTIMED_CSLEEP) */
1218 (void)set_monster_fast(i, 0);
1219 (void)set_monster_slow(i, 0);
1220 (void)set_monster_stunned(i, 0);
1221 (void)set_monster_confused(i, 0);
1222 (void)set_monster_monfear(i, 0);
1223 (void)set_monster_invulner(i, 0, FALSE);
1226 /* Extract real monster race */
1227 r_ptr = real_r_ptr(m_ptr);
1229 /* Ignore non-unique */
1230 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1231 !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1233 /* Appear at a different floor? */
1234 if (r_ptr->floor_id != new_floor_id)
1236 /* Disapper from here */
1237 delete_monster_idx(i);
1241 /* Maintain artifatcs */
1242 for (i = 1; i < o_max; i++)
1244 object_type *o_ptr = &o_list[i];
1246 /* Skip dead objects */
1247 if (!o_ptr->k_idx) continue;
1249 /* Ignore non-artifact */
1250 if (!object_is_fixed_artifact(o_ptr)) continue;
1252 /* Appear at a different floor? */
1253 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1255 /* Disappear from here */
1256 delete_object_idx(i);
1260 /* Cancel preserve */
1261 a_info[o_ptr->name1].cur_num = 1;
1265 (void)place_quest_monsters();
1267 /* Place some random monsters */
1268 alloc_times = absence_ticks / alloc_chance;
1270 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1273 for (i = 0; i < alloc_times; i++)
1275 /* Make a (group of) new monster */
1276 (void)alloc_monster(0, 0);
1281 /* New floor_id or failed to restore */
1282 else /* if (!loaded) */
1284 if (sf_ptr->last_visit)
1286 /* Temporal file is broken? */
1287 msg_print(_("階段は行き止まりだった。", "The staircases come to a dead end..."));
1289 /* Create simple dead end */
1292 /* Break connection */
1293 if (change_floor_mode & CFM_UP)
1295 sf_ptr->upper_floor_id = 0;
1297 else if (change_floor_mode & CFM_DOWN)
1299 sf_ptr->lower_floor_id = 0;
1304 /* Newly create cave */
1308 /* Record last visit turn */
1309 sf_ptr->last_visit = turn;
1311 /* Set correct dun_level value */
1312 sf_ptr->dun_level = dun_level;
1314 /* Create connected stairs */
1315 if (!(change_floor_mode & CFM_NO_RETURN))
1317 /* Extract stair position */
1318 cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
1320 /*** Create connected stairs ***/
1322 /* No stairs down from Quest */
1323 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1325 c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair;
1328 /* No stairs up when ironman_downward */
1329 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1331 c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair;
1334 /* Paranoia -- Clear mimic */
1337 /* Connect to previous floor */
1338 c_ptr->special = p_ptr->floor_id;
1342 /* Arrive at random grid */
1343 if (change_floor_mode & (CFM_RAND_PLACE))
1345 (void)new_player_spot();
1348 /* You see stairs blocked */
1349 else if ((change_floor_mode & CFM_NO_RETURN) &&
1350 (change_floor_mode & (CFM_DOWN | CFM_UP)))
1354 msg_print(_("突然階段が塞がれてしまった。", "Suddenly the stairs is blocked!"));
1358 msg_print(_("ゴトゴトと何か音がした。", "You hear some noises."));
1365 * The "turn" is not always different number because
1366 * the level teleport doesn't take any turn. Use
1367 * visit mark instead of last visit turn to find the
1368 * oldest saved floor.
1370 sf_ptr->visit_mark = latest_visit_mark++;
1373 /* Place preserved pet monsters */
1376 /* Reset travel target place */
1377 forget_travel_flow();
1379 /* Hack -- maintain unique and artifacts */
1380 update_unique_artifact(new_floor_id);
1382 /* Now the player is in new floor */
1383 p_ptr->floor_id = new_floor_id;
1385 /* The dungeon is ready */
1386 character_dungeon = TRUE;
1388 /* Hack -- Munchkin characters always get whole map */
1389 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1390 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1392 /* Remember when this level was "created" */
1395 /* No dungeon feeling yet */
1396 p_ptr->feeling_turn = old_turn;
1399 /* Clear all flags */
1400 change_floor_mode = 0L;
1402 select_floor_music();
1406 * @brief プレイヤーの手による能動的な階段生成処理 /
1407 * Create stairs at or move previously created stairs into the player location.
1410 void stair_creation(void)
1412 saved_floor_type *sf_ptr;
1413 saved_floor_type *dest_sf_ptr;
1417 s16b dest_floor_id = 0;
1420 /* Forbid up staircases on Ironman mode */
1421 if (ironman_downward) up = FALSE;
1423 /* Forbid down staircases on quest level */
1424 if (quest_number(dun_level) || (dun_level >= d_info[dungeon_type].maxdepth)) down = FALSE;
1426 /* No effect out of standard dungeon floor */
1427 if (!dun_level || (!up && !down) ||
1428 (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1429 p_ptr->inside_arena || p_ptr->inside_battle)
1431 /* arena or quest */
1432 msg_print(_("効果がありません!", "There is no effect!"));
1436 /* Artifacts resists */
1437 if (!cave_valid_bold(p_ptr->y, p_ptr->x))
1439 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
1443 /* Destroy all objects in the grid */
1444 delete_object(p_ptr->y, p_ptr->x);
1446 /* Extract current floor data */
1447 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1452 /* No floor id? -- Create now! */
1453 p_ptr->floor_id = get_new_floor_id();
1454 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1457 /* Choose randomly */
1460 if (randint0(100) < 50) up = FALSE;
1464 /* Destination is already fixed */
1467 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1471 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1475 /* Search old stairs leading to the destination */
1480 for (y = 0; y < cur_hgt; y++)
1482 for (x = 0; x < cur_wid; x++)
1484 cave_type *c_ptr = &cave[y][x];
1486 if (!c_ptr->special) continue;
1487 if (feat_uses_special(c_ptr->feat)) continue;
1488 if (c_ptr->special != dest_floor_id) continue;
1490 /* Remove old stairs */
1492 cave_set_feat(y, x, floor_type[randint0(100)]);
1497 /* No old destination -- Get new one now */
1500 dest_floor_id = get_new_floor_id();
1504 sf_ptr->upper_floor_id = dest_floor_id;
1506 sf_ptr->lower_floor_id = dest_floor_id;
1509 /* Extract destination floor data */
1510 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1513 /* Create a staircase */
1516 cave_set_feat(p_ptr->y, p_ptr->x,
1517 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level <= dun_level - 2)) ?
1518 feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair);
1522 cave_set_feat(p_ptr->y, p_ptr->x,
1523 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level >= dun_level + 2)) ?
1524 feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair);
1528 /* Connect this stairs to the destination */
1529 cave[p_ptr->y][p_ptr->x].special = dest_floor_id;