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
21 static FLOOR_IDX new_floor_id; /*!<次のフロアのID / floor_id of the destination */
22 static u32b change_floor_mode; /*!<フロア移行処理に関するフラグ / Mode flags for changing floor */
23 static u32b latest_visit_mark; /*!<フロアを渡った回数?(確認中) / Max number of visit_mark */
27 * @brief 保存フロア配列を初期化する / Initialize saved_floors array.
28 * @param force テンポラリファイルが残っていた場合も警告なしで強制的に削除する。
29 * @details Make sure that old temporal files are not remaining as gurbages.
32 void init_saved_floors(bool force)
34 char floor_savefile[1024];
37 BIT_FLAGS mode = 0644;
41 /* Get "games" permissions */
46 for (i = 0; i < MAX_SAVED_FLOORS; i++)
48 saved_floor_type *sf_ptr = &saved_floors[i];
51 sprintf(floor_savefile, "%s.F%02d", savefile, i);
53 /* Grab permissions */
56 /* Try to create the file */
57 fd = fd_make(floor_savefile, mode);
59 /* Drop permissions */
67 msg_print(_("エラー:古いテンポラリ・ファイルが残っています。", "Error: There are old temporal files."));
68 msg_print(_("変愚蛮怒を二重に起動していないか確認してください。", "Make sure you are not running two game processes simultaneously."));
69 msg_print(_("過去に変愚蛮怒がクラッシュした場合は一時ファイルを", "If the temporal files are garbages of old crashed process, "));
70 msg_print(_("強制的に削除して実行を続けられます。", "you can delete it safely."));
71 if (!get_check(_("強制的に削除してもよろしいですか?", "Do you delete old temporal files? ")))
72 quit(_("実行中止", "Aborted."));
82 /* Grab permissions */
85 /* Simply kill the temporal file */
86 (void)fd_kill(floor_savefile);
88 /* Drop permissions */
94 /* No floor_id used yet (No.0 is reserved to indicate non existance) */
97 /* vist_mark is from 1 */
98 latest_visit_mark = 1;
100 /* A sign to mark temporal files */
101 saved_floor_file_sign = (u32b)time(NULL);
103 /* No next floor yet */
106 /* No change floor mode yet */
107 change_floor_mode = 0;
111 /* Drop "games" permissions */
118 * @brief 保存フロア用テンポラリファイルを削除する / Kill temporal files
119 * @details Should be called just before the game quit.
122 void clear_saved_floor_files(void)
124 char floor_savefile[1024];
129 /* Get "games" permissions */
134 for (i = 0; i < MAX_SAVED_FLOORS; i++)
136 saved_floor_type *sf_ptr = &saved_floors[i];
138 /* No temporal file */
139 if (!sf_ptr->floor_id) continue;
140 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
143 sprintf(floor_savefile, "%s.F%02d", savefile, i);
145 /* Grab permissions */
148 /* Simply kill the temporal file */
149 (void)fd_kill(floor_savefile);
151 /* Drop permissions */
157 /* Drop "games" permissions */
164 * @brief 保存フロアIDから参照ポインタを得る / Get a pointer for an item of the saved_floors array.
165 * @param floor_id 保存フロアID
166 * @return IDに対応する保存フロアのポインタ、ない場合はNULLを返す。
168 saved_floor_type *get_sf_ptr(FLOOR_IDX floor_id)
172 /* floor_id No.0 indicates no floor */
173 if (!floor_id) return NULL;
175 for (i = 0; i < MAX_SAVED_FLOORS; i++)
177 saved_floor_type *sf_ptr = &saved_floors[i];
179 if (sf_ptr->floor_id == floor_id) return sf_ptr;
188 * @brief 参照ポインタ先の保存フロアを抹消する / kill a saved floor and get an empty space
189 * @param sf_ptr 保存フロアの参照ポインタ
192 static void kill_saved_floor(saved_floor_type *sf_ptr)
194 char floor_savefile[1024];
200 if (!sf_ptr->floor_id) return;
202 if (sf_ptr->floor_id == p_ptr->floor_id)
204 /* Kill current floor */
207 /* Current floor doesn't have temporal file */
212 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
214 /* Grab permissions */
217 /* Simply kill the temporal file */
218 (void)fd_kill(floor_savefile);
220 /* Drop permissions */
224 /* No longer exists */
225 sf_ptr->floor_id = 0;
230 * @brief 新規に利用可能な保存フロアを返す / Initialize new saved floor and get its floor id.
231 * @return 利用可能な保存フロアID
233 * If number of saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
235 FLOOR_IDX get_new_floor_id(void)
237 saved_floor_type *sf_ptr = NULL;
240 /* Look for empty space */
241 for (i = 0; i < MAX_SAVED_FLOORS; i++)
243 sf_ptr = &saved_floors[i];
245 if (!sf_ptr->floor_id) break;
249 if (i == MAX_SAVED_FLOORS)
252 u32b oldest_visit = 0xffffffffL;
254 /* Search for oldest */
255 for (i = 0; i < MAX_SAVED_FLOORS; i++)
257 sf_ptr = &saved_floors[i];
259 /* Don't kill current floor */
260 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
262 /* Don't kill newer */
263 if (sf_ptr->visit_mark > oldest_visit) continue;
266 oldest_visit = sf_ptr->visit_mark;
269 /* Kill oldest saved floor */
270 sf_ptr = &saved_floors[oldest];
271 kill_saved_floor(sf_ptr);
277 /* Prepare new floor data */
278 sf_ptr->savefile_id = i;
279 sf_ptr->floor_id = max_floor_id;
280 sf_ptr->last_visit = 0;
281 sf_ptr->upper_floor_id = 0;
282 sf_ptr->lower_floor_id = 0;
283 sf_ptr->visit_mark = latest_visit_mark++;
285 /* sf_ptr->dun_level may be changed later */
286 sf_ptr->dun_level = dun_level;
289 /* Increment number of floor_id */
290 if (max_floor_id < MAX_SHORT) max_floor_id++;
292 /* 32767 floor_ids are all used up! Re-use ancient IDs */
293 else max_floor_id = 1;
295 return sf_ptr->floor_id;
300 * @brief フロア切り替え時の処理フラグを追加する / Prepare mode flags of changing floor
301 * @param mode 追加したい所持フラグ
304 void prepare_change_floor_mode(BIT_FLAGS mode)
306 change_floor_mode |= mode;
310 * @brief 階段移動先のフロアが生成できない時に簡単な行き止まりマップを作成する / Builds the dead end
313 static void build_dead_end(void)
317 /* Clear and empty the cave */
320 /* Fill the arrays of floors and walls in the good proportions */
321 set_floor_and_wall(0);
324 cur_hgt = SCREEN_HGT;
325 cur_wid = SCREEN_WID;
327 /* Filled with permanent walls */
328 for (y = 0; y < MAX_HGT; y++)
330 for (x = 0; x < MAX_WID; x++)
332 /* Create "solid" perma-wall */
333 place_solid_perm_bold(y, x);
337 /* Place at center of the floor */
338 p_ptr->y = cur_hgt / 2;
339 p_ptr->x = cur_wid / 2;
341 /* Give one square */
342 place_floor_bold(p_ptr->y, p_ptr->x);
344 wipe_generate_cave_flags();
349 #define MAX_PARTY_MON 21 /*!< フロア移動時に先のフロアに連れて行けるペットの最大数 Maximum number of preservable pets */
350 static monster_type party_mon[MAX_PARTY_MON]; /*!< フロア移動に保存するペットモンスターの配列 */
353 * @brief フロア移動時のペット保存処理 / Preserve_pets
356 static void preserve_pet(void)
361 for (num = 0; num < MAX_PARTY_MON; num++)
363 party_mon[num].r_idx = 0;
368 monster_type *m_ptr = &m_list[p_ptr->riding];
370 /* Pet of other pet don't follow. */
371 if (m_ptr->parent_m_idx)
374 p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
375 p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
379 /* Preserve the mount */
380 (void)COPY(&party_mon[0], m_ptr, monster_type);
382 /* Delete from this floor */
383 delete_monster_idx(p_ptr->riding);
388 * If player is in wild mode, no pets are preserved
389 * except a monster whom player riding
391 if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->inside_battle)
393 for (i = m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
395 monster_type *m_ptr = &m_list[i];
397 if (!m_ptr->r_idx) continue;
398 if (!is_pet(m_ptr)) continue;
399 if (i == p_ptr->riding) continue;
401 if (reinit_wilderness)
403 /* Don't lose sight of pets when getting a Quest */
407 POSITION dis = distance(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx);
409 /* Confused (etc.) monsters don't follow. */
410 if (MON_CONFUSED(m_ptr) || MON_STUNNED(m_ptr) || MON_CSLEEP(m_ptr)) continue;
412 /* Pet of other pet don't follow. */
413 if (m_ptr->parent_m_idx) continue;
416 * Pets with nickname will follow even from 3 blocks away
417 * when you or the pet can see the other.
419 if (m_ptr->nickname &&
420 ((player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) ||
421 (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))))
423 if (dis > 3) continue;
427 if (dis > 1) continue;
431 (void)COPY(&party_mon[num], &m_list[i], monster_type);
435 /* Delete from this floor */
436 delete_monster_idx(i);
440 if (record_named_pet)
442 for (i = m_max - 1; i >=1; i--)
444 monster_type *m_ptr = &m_list[i];
445 GAME_TEXT m_name[MAX_NLEN];
447 if (!m_ptr->r_idx) continue;
448 if (!is_pet(m_ptr)) continue;
449 if (!m_ptr->nickname) continue;
450 if (p_ptr->riding == i) continue;
452 monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
453 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_MOVED, m_name);
458 /* Pet of other pet may disappear. */
459 for (i = m_max - 1; i >=1; i--)
461 monster_type *m_ptr = &m_list[i];
463 /* Are there its parent? */
464 if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
466 /* Its parent have gone, it also goes away. */
470 GAME_TEXT m_name[MAX_NLEN];
471 monster_desc(m_name, m_ptr, 0);
472 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
475 delete_monster_idx(i);
482 * @brief フロア移動時にペットを伴った場合の準備処理 / Pre-calculate the racial counters of preserved pets
485 * To prevent multiple generation of unique monster who is the minion of player
487 void precalc_cur_num_of_pet(void)
491 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
493 for (i = 0; i < max_num; i++)
495 m_ptr = &party_mon[i];
497 /* Skip empty monsters */
498 if (!m_ptr->r_idx) continue;
500 /* Hack -- Increase the racial counter */
501 real_r_ptr(m_ptr)->cur_num++;
506 * @brief 移動先のフロアに伴ったペットを配置する / Place preserved pet monsters on new floor
509 static void place_pet(void)
512 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
514 for (i = 0; i < max_num; i++)
516 POSITION cy = 0, cx = 0;
519 if (!(party_mon[i].r_idx)) continue;
524 p_ptr->riding = m_idx;
536 for (d = 1; d < A_MAX; d++)
538 for (j = 1000; j > 0; j--)
540 scatter(&cy, &cx, p_ptr->y, p_ptr->x, d, 0);
541 if (monster_can_enter(cy, cx, &r_info[party_mon[i].r_idx], 0)) break;
545 m_idx = (d == 6) ? 0 : m_pop();
550 monster_type *m_ptr = &m_list[m_idx];
553 cave[cy][cx].m_idx = m_idx;
555 m_ptr->r_idx = party_mon[i].r_idx;
557 /* Copy all member of the structure */
558 *m_ptr = party_mon[i];
559 r_ptr = real_r_ptr(m_ptr);
564 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
567 m_ptr->hold_o_idx = 0;
570 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
572 /* Monster is still being nice */
573 m_ptr->mflag |= (MFLAG_NICE);
575 /* Must repair monsters */
576 repair_monsters = TRUE;
578 update_monster(m_idx, TRUE);
581 /* Pre-calculated in precalc_cur_num_of_pet() */
582 /* r_ptr->cur_num++; */
584 /* Hack -- Count the number of "reproducers" */
585 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
587 /* Hack -- Notice new multi-hued monsters */
589 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
590 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
591 shimmer_monsters = TRUE;
596 monster_type *m_ptr = &party_mon[i];
597 monster_race *r_ptr = real_r_ptr(m_ptr);
598 GAME_TEXT m_name[MAX_NLEN];
600 monster_desc(m_name, m_ptr, 0);
601 msg_format(_("%sとはぐれてしまった。", "You have lost sight of %s."), m_name);
602 if (record_named_pet && m_ptr->nickname)
604 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
605 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOST_SIGHT, m_name);
608 /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
609 if (r_ptr->cur_num) r_ptr->cur_num--;
613 /* For accuracy of precalc_cur_num_of_pet() */
614 (void)C_WIPE(party_mon, MAX_PARTY_MON, monster_type);
619 * @brief ユニークモンスターやアーティファクトの所在フロアを更新する / Hack -- Update location of unique monsters and artifacts
620 * @param cur_floor_id 現在のフロアID
623 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly\n
624 * while new floor creation since dungeons may be re-created by\n
625 * auto-scum option.\n
627 static void update_unique_artifact(s16b cur_floor_id)
631 /* Maintain unique monsters */
632 for (i = 1; i < m_max; i++)
635 monster_type *m_ptr = &m_list[i];
637 /* Skip dead monsters */
638 if (!m_ptr->r_idx) continue;
640 /* Extract real monster race */
641 r_ptr = real_r_ptr(m_ptr);
643 /* Memorize location of the unique monster */
644 if ((r_ptr->flags1 & RF1_UNIQUE) ||
645 (r_ptr->flags7 & RF7_NAZGUL))
647 r_ptr->floor_id = cur_floor_id;
651 /* Maintain artifatcs */
652 for (i = 1; i < o_max; i++)
654 object_type *o_ptr = &o_list[i];
656 /* Skip dead objects */
657 if (!o_ptr->k_idx) continue;
659 /* Memorize location of the artifact */
660 if (object_is_fixed_artifact(o_ptr))
662 a_info[o_ptr->name1].floor_id = cur_floor_id;
669 * @brief フロア移動時、プレイヤーの移動先モンスターが既にいた場合ランダムな近隣に移動させる / When a monster is at a place where player will return,
672 static void get_out_monster(void)
676 POSITION oy = p_ptr->y;
677 POSITION ox = p_ptr->x;
678 MONSTER_IDX m_idx = cave[oy][ox].m_idx;
680 /* Nothing to do if no monster */
683 /* Look until done */
688 /* Pick a (possibly illegal) location */
689 POSITION ny = rand_spread(oy, dis);
690 POSITION nx = rand_spread(ox, dis);
694 /* Stop after 1000 tries */
695 if (tries > 10000) return;
698 * Increase distance after doing enough tries
699 * compared to area of possible space
701 if (tries > 20 * dis * dis) dis++;
703 /* Ignore illegal locations */
704 if (!in_bounds(ny, nx)) continue;
706 /* Require "empty" floor space */
707 if (!cave_empty_bold(ny, nx)) continue;
709 /* Hack -- no teleport onto glyph of warding */
710 if (is_glyph_grid(&cave[ny][nx])) continue;
711 if (is_explosive_rune_grid(&cave[ny][nx])) continue;
713 /* ...nor onto the Pattern */
714 if (pattern_tile(ny, nx)) continue;
716 /*** It's a good place ***/
718 m_ptr = &m_list[m_idx];
720 /* Update the old location */
721 cave[oy][ox].m_idx = 0;
723 /* Update the new location */
724 cave[ny][nx].m_idx = m_idx;
726 /* Move the monster */
730 /* No need to do update_monster() */
738 * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with c_ptr->special?
740 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
744 * @brief 新フロアに移動元フロアに繋がる階段を配置する / Virtually teleport onto the stairs that is connecting between two floors.
745 * @param sf_ptr 移動元の保存フロア構造体参照ポインタ
748 static void locate_connected_stairs(saved_floor_type *sf_ptr)
750 POSITION x, y, sx = 0, sy = 0;
751 POSITION x_table[20];
752 POSITION y_table[20];
756 /* Search usable stairs */
757 for (y = 0; y < cur_hgt; y++)
759 for (x = 0; x < cur_wid; x++)
761 cave_type *c_ptr = &cave[y][x];
762 feature_type *f_ptr = &f_info[c_ptr->feat];
765 if (change_floor_mode & CFM_UP)
767 if (have_flag(f_ptr->flags, FF_LESS) && have_flag(f_ptr->flags, FF_STAIRS) &&
768 !have_flag(f_ptr->flags, FF_SPECIAL))
772 /* Found fixed stairs? */
773 if (c_ptr->special &&
774 c_ptr->special == sf_ptr->upper_floor_id)
782 else if (change_floor_mode & CFM_DOWN)
784 if (have_flag(f_ptr->flags, FF_MORE) && have_flag(f_ptr->flags, FF_STAIRS) &&
785 !have_flag(f_ptr->flags, FF_SPECIAL))
789 /* Found fixed stairs */
790 if (c_ptr->special &&
791 c_ptr->special == sf_ptr->lower_floor_id)
801 if (have_flag(f_ptr->flags, FF_BLDG))
807 if (ok && (num < 20))
824 /* No stairs found! -- No return */
825 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
827 /* Mega Hack -- It's not the stairs you enter. Disable it. */
828 if (!feat_uses_special(cave[p_ptr->y][p_ptr->x].feat)) cave[p_ptr->y][p_ptr->x].special = 0;
832 /* Choose random one */
835 /* Point stair location */
836 p_ptr->y = y_table[i];
837 p_ptr->x = x_table[i];
842 * @brief 現在のフロアを離れるに伴って行なわれる保存処理
843 * / Maintain quest monsters, mark next floor_id at stairs, save current floor, and prepare to enter next floor.
846 void leave_floor(void)
848 cave_type *c_ptr = NULL;
850 saved_floor_type *sf_ptr;
851 MONRACE_IDX quest_r_idx = 0;
854 /* Preserve pets and prepare to take these to next floor */
857 /* Remove all mirrors without explosion */
858 remove_all_mirrors(FALSE);
860 if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
862 /* New floor is not yet prepared */
865 /* Temporary get a floor_id (for Arena) */
866 if (!p_ptr->floor_id &&
867 (change_floor_mode & CFM_SAVE_FLOORS) &&
868 !(change_floor_mode & CFM_NO_RETURN))
870 /* Get temporal floor_id */
871 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 (p_ptr->dungeon_idx == 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[p_ptr->dungeon_idx].mindepth;
975 else if (change_floor_mode & CFM_UP)
977 if (dun_level + move_num < d_info[p_ptr->dungeon_idx].mindepth)
978 move_num = -dun_level;
981 dun_level += move_num;
984 /* Leaving the dungeon to town */
985 if (!dun_level && p_ptr->dungeon_idx)
987 p_ptr->leaving_dungeon = TRUE;
988 if (!vanilla_town && !lite_town)
990 p_ptr->wilderness_y = d_info[p_ptr->dungeon_idx].dy;
991 p_ptr->wilderness_x = d_info[p_ptr->dungeon_idx].dx;
993 p_ptr->recall_dungeon = p_ptr->dungeon_idx;
994 p_ptr->dungeon_idx = 0;
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;
1060 /* Save current floor */
1061 if (!save_floor(sf_ptr, 0))
1063 /* Save failed -- No return */
1064 prepare_change_floor_mode(CFM_NO_RETURN);
1066 /* Kill current floor */
1067 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
1074 * @brief フロアの切り替え処理 / Enter new floor.
1077 * If the floor is an old saved floor, it will be\n
1078 * restored from the temporal file. If the floor is new one, new cave\n
1079 * will be generated.\n
1081 void change_floor(void)
1083 saved_floor_type *sf_ptr;
1084 bool loaded = FALSE;
1086 /* The dungeon is not ready */
1087 character_dungeon = FALSE;
1089 /* No longer in the trap detecteded region */
1090 p_ptr->dtrap = FALSE;
1092 /* Mega-Hack -- no panel yet */
1098 /* Mega-Hack -- not ambushed on the wildness? */
1099 ambush_flag = FALSE;
1101 /* No saved floors (On the surface etc.) */
1102 if (!(change_floor_mode & CFM_SAVE_FLOORS) &&
1103 !(change_floor_mode & CFM_FIRST_FLOOR))
1108 /* Paranoia -- No new saved floor */
1112 /* In the dungeon */
1115 /* No floor_id yet */
1119 new_floor_id = get_new_floor_id();
1122 /* Pointer for infomations of new floor */
1123 sf_ptr = get_sf_ptr(new_floor_id);
1125 /* Try to restore old floor */
1126 if (sf_ptr->last_visit)
1128 /* Old saved floor is exist */
1129 if (load_floor(sf_ptr, 0))
1133 /* Forbid return stairs */
1134 if (change_floor_mode & CFM_NO_RETURN)
1136 cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
1138 if (!feat_uses_special(c_ptr->feat))
1140 if (change_floor_mode & (CFM_DOWN | CFM_UP))
1142 /* Reset to floor */
1143 c_ptr->feat = feat_ground_type[randint0(100)];
1153 * Set lower/upper_floor_id of new floor when the new
1154 * floor is right-above/right-under the current floor.
1156 * Stair creation/Teleport level/Trap door will take
1157 * you the same floor when you used it later again.
1159 if (p_ptr->floor_id)
1161 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1163 if (change_floor_mode & CFM_UP)
1165 /* New floor is right-above */
1166 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1167 sf_ptr->lower_floor_id = p_ptr->floor_id;
1169 else if (change_floor_mode & CFM_DOWN)
1171 /* New floor is right-under */
1172 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1173 sf_ptr->upper_floor_id = p_ptr->floor_id;
1177 /* Break connection to killed floor */
1180 if (change_floor_mode & CFM_UP)
1181 sf_ptr->lower_floor_id = 0;
1182 else if (change_floor_mode & CFM_DOWN)
1183 sf_ptr->upper_floor_id = 0;
1186 /* Maintain monsters and artifacts */
1190 GAME_TURN tmp_last_visit = sf_ptr->last_visit;
1191 GAME_TURN absence_ticks;
1192 int alloc_chance = d_info[p_ptr->dungeon_idx].max_m_alloc_chance;
1193 GAME_TURN alloc_times;
1195 while (tmp_last_visit > turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
1196 absence_ticks = (turn - tmp_last_visit) / TURNS_PER_TICK;
1198 /* Maintain monsters */
1199 for (i = 1; i < m_max; i++)
1201 monster_race *r_ptr;
1202 monster_type *m_ptr = &m_list[i];
1204 /* Skip dead monsters */
1205 if (!m_ptr->r_idx) continue;
1210 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1212 /* Remove timed status (except MTIMED_CSLEEP) */
1213 (void)set_monster_fast(i, 0);
1214 (void)set_monster_slow(i, 0);
1215 (void)set_monster_stunned(i, 0);
1216 (void)set_monster_confused(i, 0);
1217 (void)set_monster_monfear(i, 0);
1218 (void)set_monster_invulner(i, 0, FALSE);
1221 /* Extract real monster race */
1222 r_ptr = real_r_ptr(m_ptr);
1224 /* Ignore non-unique */
1225 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1226 !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1228 /* Appear at a different floor? */
1229 if (r_ptr->floor_id != new_floor_id)
1231 /* Disapper from here */
1232 delete_monster_idx(i);
1236 /* Maintain artifatcs */
1237 for (i = 1; i < o_max; i++)
1239 object_type *o_ptr = &o_list[i];
1241 /* Skip dead objects */
1242 if (!o_ptr->k_idx) continue;
1244 /* Ignore non-artifact */
1245 if (!object_is_fixed_artifact(o_ptr)) continue;
1247 /* Appear at a different floor? */
1248 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1250 /* Disappear from here */
1251 delete_object_idx(i);
1255 /* Cancel preserve */
1256 a_info[o_ptr->name1].cur_num = 1;
1260 (void)place_quest_monsters();
1262 /* Place some random monsters */
1263 alloc_times = absence_ticks / alloc_chance;
1265 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1268 for (i = 0; i < alloc_times; i++)
1270 /* Make a (group of) new monster */
1271 (void)alloc_monster(0, 0);
1276 /* New floor_id or failed to restore */
1277 else /* if (!loaded) */
1279 if (sf_ptr->last_visit)
1281 /* Temporal file is broken? */
1282 msg_print(_("階段は行き止まりだった。", "The staircases come to a dead end..."));
1284 /* Create simple dead end */
1287 /* Break connection */
1288 if (change_floor_mode & CFM_UP)
1290 sf_ptr->upper_floor_id = 0;
1292 else if (change_floor_mode & CFM_DOWN)
1294 sf_ptr->lower_floor_id = 0;
1299 /* Newly create cave */
1303 /* Record last visit turn */
1304 sf_ptr->last_visit = turn;
1306 /* Set correct dun_level value */
1307 sf_ptr->dun_level = dun_level;
1309 /* Create connected stairs */
1310 if (!(change_floor_mode & CFM_NO_RETURN))
1312 /* Extract stair position */
1313 cave_type *c_ptr = &cave[p_ptr->y][p_ptr->x];
1315 /*** Create connected stairs ***/
1317 /* No stairs down from Quest */
1318 if ((change_floor_mode & CFM_UP) && !quest_number(dun_level))
1320 c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair;
1323 /* No stairs up when ironman_downward */
1324 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1326 c_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair;
1329 /* Paranoia -- Clear mimic */
1332 /* Connect to previous floor */
1333 c_ptr->special = p_ptr->floor_id;
1337 /* Arrive at random grid */
1338 if (change_floor_mode & (CFM_RAND_PLACE))
1340 (void)new_player_spot();
1343 /* You see stairs blocked */
1344 else if ((change_floor_mode & CFM_NO_RETURN) && (change_floor_mode & (CFM_DOWN | CFM_UP)))
1348 msg_print(_("突然階段が塞がれてしまった。", "Suddenly the stairs is blocked!"));
1352 msg_print(_("ゴトゴトと何か音がした。", "You hear some noises."));
1359 * The "turn" is not always different number because
1360 * the level teleport doesn't take any turn. Use
1361 * visit mark instead of last visit turn to find the
1362 * oldest saved floor.
1364 sf_ptr->visit_mark = latest_visit_mark++;
1367 /* Place preserved pet monsters */
1370 /* Reset travel target place */
1371 forget_travel_flow();
1373 /* Hack -- maintain unique and artifacts */
1374 update_unique_artifact(new_floor_id);
1376 /* Now the player is in new floor */
1377 p_ptr->floor_id = new_floor_id;
1379 /* The dungeon is ready */
1380 character_dungeon = TRUE;
1382 /* Hack -- Munchkin characters always get whole map */
1383 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1384 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1386 /* Remember when this level was "created" */
1389 /* No dungeon feeling yet */
1390 p_ptr->feeling_turn = old_turn;
1393 /* Clear all flags */
1394 change_floor_mode = 0L;
1396 select_floor_music();
1400 * @brief プレイヤーの手による能動的な階段生成処理 /
1401 * Create stairs at or move previously created stairs into the player location.
1404 void stair_creation(void)
1406 saved_floor_type *sf_ptr;
1407 saved_floor_type *dest_sf_ptr;
1411 FLOOR_IDX dest_floor_id = 0;
1414 /* Forbid up staircases on Ironman mode */
1415 if (ironman_downward) up = FALSE;
1417 /* Forbid down staircases on quest level */
1418 if (quest_number(dun_level) || (dun_level >= d_info[p_ptr->dungeon_idx].maxdepth)) down = FALSE;
1420 /* No effect out of standard dungeon floor */
1421 if (!dun_level || (!up && !down) ||
1422 (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1423 p_ptr->inside_arena || p_ptr->inside_battle)
1425 /* arena or quest */
1426 msg_print(_("効果がありません!", "There is no effect!"));
1430 /* Artifacts resists */
1431 if (!cave_valid_bold(p_ptr->y, p_ptr->x))
1433 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
1437 /* Destroy all objects in the grid */
1438 delete_object(p_ptr->y, p_ptr->x);
1440 /* Extract current floor data */
1441 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1446 /* No floor id? -- Create now! */
1447 p_ptr->floor_id = get_new_floor_id();
1448 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1451 /* Choose randomly */
1454 if (randint0(100) < 50) up = FALSE;
1458 /* Destination is already fixed */
1461 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1465 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1469 /* Search old stairs leading to the destination */
1474 for (y = 0; y < cur_hgt; y++)
1476 for (x = 0; x < cur_wid; x++)
1478 cave_type *c_ptr = &cave[y][x];
1480 if (!c_ptr->special) continue;
1481 if (feat_uses_special(c_ptr->feat)) continue;
1482 if (c_ptr->special != dest_floor_id) continue;
1484 /* Remove old stairs */
1486 cave_set_feat(y, x, feat_ground_type[randint0(100)]);
1491 /* No old destination -- Get new one now */
1494 dest_floor_id = get_new_floor_id();
1498 sf_ptr->upper_floor_id = dest_floor_id;
1500 sf_ptr->lower_floor_id = dest_floor_id;
1503 /* Extract destination floor data */
1504 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1507 /* Create a staircase */
1510 cave_set_feat(p_ptr->y, p_ptr->x,
1511 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level <= dun_level - 2)) ?
1512 feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair);
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_down_stair, FF_SHAFT) : feat_down_stair);
1522 /* Connect this stairs to the destination */
1523 cave[p_ptr->y][p_ptr->x].special = dest_floor_id;