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 #include "spells-floor.h"
21 #include "monster-status.h"
24 static FLOOR_IDX new_floor_id; /*!<次のフロアのID / floor_id of the destination */
25 static u32b change_floor_mode; /*!<フロア移行処理に関するフラグ / Mode flags for changing floor */
26 static u32b latest_visit_mark; /*!<フロアを渡った回数?(確認中) / Max number of visit_mark */
30 * @brief 保存フロア配列を初期化する / Initialize saved_floors array.
31 * @param force テンポラリファイルが残っていた場合も警告なしで強制的に削除する。
32 * @details Make sure that old temporal files are not remaining as gurbages.
35 void init_saved_floors(bool force)
37 char floor_savefile[1024];
40 BIT_FLAGS mode = 0644;
44 /* Get "games" permissions */
49 for (i = 0; i < MAX_SAVED_FLOORS; i++)
51 saved_floor_type *sf_ptr = &saved_floors[i];
54 sprintf(floor_savefile, "%s.F%02d", savefile, i);
56 /* Grab permissions */
59 /* Try to create the file */
60 fd = fd_make(floor_savefile, mode);
62 /* Drop permissions */
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? ")))
75 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(FLOOR_IDX 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];
201 if (!sf_ptr->floor_id) return;
203 if (sf_ptr->floor_id == p_ptr->floor_id)
205 /* Kill current floor */
208 /* Current floor doesn't have temporal file */
213 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
215 /* Grab permissions */
218 /* Simply kill the temporal file */
219 (void)fd_kill(floor_savefile);
221 /* Drop permissions */
225 /* No longer exists */
226 sf_ptr->floor_id = 0;
231 * @brief 新規に利用可能な保存フロアを返す / Initialize new saved floor and get its floor id.
232 * @return 利用可能な保存フロアID
234 * If number of saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
236 FLOOR_IDX get_new_floor_id(void)
238 saved_floor_type *sf_ptr = NULL;
241 /* Look for empty space */
242 for (i = 0; i < MAX_SAVED_FLOORS; i++)
244 sf_ptr = &saved_floors[i];
246 if (!sf_ptr->floor_id) break;
250 if (i == MAX_SAVED_FLOORS)
253 u32b oldest_visit = 0xffffffffL;
255 /* Search for oldest */
256 for (i = 0; i < MAX_SAVED_FLOORS; i++)
258 sf_ptr = &saved_floors[i];
260 /* Don't kill current floor */
261 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
263 /* Don't kill newer */
264 if (sf_ptr->visit_mark > oldest_visit) continue;
267 oldest_visit = sf_ptr->visit_mark;
270 /* Kill oldest saved floor */
271 sf_ptr = &saved_floors[oldest];
272 kill_saved_floor(sf_ptr);
278 /* Prepare new floor data */
279 sf_ptr->savefile_id = i;
280 sf_ptr->floor_id = max_floor_id;
281 sf_ptr->last_visit = 0;
282 sf_ptr->upper_floor_id = 0;
283 sf_ptr->lower_floor_id = 0;
284 sf_ptr->visit_mark = latest_visit_mark++;
286 /* sf_ptr->dun_level may be changed later */
287 sf_ptr->dun_level = current_floor_ptr->dun_level;
290 /* Increment number of floor_id */
291 if (max_floor_id < MAX_SHORT) max_floor_id++;
293 /* 32767 floor_ids are all used up! Re-use ancient IDs */
294 else max_floor_id = 1;
296 return sf_ptr->floor_id;
301 * @brief フロア切り替え時の処理フラグを追加する / Prepare mode flags of changing floor
302 * @param mode 追加したい所持フラグ
305 void prepare_change_floor_mode(BIT_FLAGS mode)
307 change_floor_mode |= mode;
311 * @brief 階段移動先のフロアが生成できない時に簡単な行き止まりマップを作成する / Builds the dead end
314 static void build_dead_end(void)
318 /* Clear and empty the current_floor_ptr->grid_array */
321 /* Fill the arrays of floors and walls in the good proportions */
322 set_floor_and_wall(0);
325 current_floor_ptr->height = SCREEN_HGT;
326 current_floor_ptr->width = SCREEN_WID;
328 /* Filled with permanent walls */
329 for (y = 0; y < MAX_HGT; y++)
331 for (x = 0; x < MAX_WID; x++)
333 /* Create "solid" perma-wall */
334 place_solid_perm_bold(y, x);
338 /* Place at center of the floor */
339 p_ptr->y = current_floor_ptr->height / 2;
340 p_ptr->x = current_floor_ptr->width / 2;
342 /* Give one square */
343 place_floor_bold(p_ptr->y, p_ptr->x);
345 wipe_generate_random_floor_flags();
350 #define MAX_PARTY_MON 21 /*!< フロア移動時に先のフロアに連れて行けるペットの最大数 Maximum number of preservable pets */
351 static monster_type party_mon[MAX_PARTY_MON]; /*!< フロア移動に保存するペットモンスターの配列 */
354 * @brief フロア移動時のペット保存処理 / Preserve_pets
357 static void preserve_pet(void)
362 for (num = 0; num < MAX_PARTY_MON; num++)
364 party_mon[num].r_idx = 0;
369 monster_type *m_ptr = ¤t_floor_ptr->m_list[p_ptr->riding];
371 /* Pet of other pet don't follow. */
372 if (m_ptr->parent_m_idx)
375 p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
376 p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
380 /* Preserve the mount */
381 (void)COPY(&party_mon[0], m_ptr, monster_type);
383 /* Delete from this floor */
384 delete_monster_idx(p_ptr->riding);
389 * If player is in wild mode, no pets are preserved
390 * except a monster whom player riding
392 if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->inside_battle)
394 for (i = m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
396 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
398 if (!monster_is_valid(m_ptr)) continue;
399 if (!is_pet(m_ptr)) continue;
400 if (i == p_ptr->riding) continue;
402 if (reinit_wilderness)
404 /* Don't lose sight of pets when getting a Quest */
408 POSITION dis = distance(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx);
410 /* Confused (etc.) monsters don't follow. */
411 if (MON_CONFUSED(m_ptr) || MON_STUNNED(m_ptr) || MON_CSLEEP(m_ptr)) continue;
413 /* Pet of other pet don't follow. */
414 if (m_ptr->parent_m_idx) continue;
417 * Pets with nickname will follow even from 3 blocks away
418 * when you or the pet can see the other.
420 if (m_ptr->nickname &&
421 ((player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) ||
422 (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))))
424 if (dis > 3) continue;
428 if (dis > 1) continue;
432 (void)COPY(&party_mon[num], ¤t_floor_ptr->m_list[i], monster_type);
436 /* Delete from this floor */
437 delete_monster_idx(i);
441 if (record_named_pet)
443 for (i = m_max - 1; i >=1; i--)
445 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
446 GAME_TEXT m_name[MAX_NLEN];
448 if (!monster_is_valid(m_ptr)) continue;
449 if (!is_pet(m_ptr)) continue;
450 if (!m_ptr->nickname) continue;
451 if (p_ptr->riding == i) continue;
453 monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
454 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_MOVED, m_name);
459 /* Pet of other pet may disappear. */
460 for (i = m_max - 1; i >=1; i--)
462 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
464 /* Are there its parent? */
465 if (m_ptr->parent_m_idx && !current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx)
467 /* Its parent have gone, it also goes away. */
471 GAME_TEXT m_name[MAX_NLEN];
472 monster_desc(m_name, m_ptr, 0);
473 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
476 delete_monster_idx(i);
483 * @brief フロア移動時にペットを伴った場合の準備処理 / Pre-calculate the racial counters of preserved pets
486 * To prevent multiple generation of unique monster who is the minion of player
488 void precalc_cur_num_of_pet(void)
492 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
494 for (i = 0; i < max_num; i++)
496 m_ptr = &party_mon[i];
498 /* Skip empty monsters */
499 if (!monster_is_valid(m_ptr)) continue;
501 /* Hack -- Increase the racial counter */
502 real_r_ptr(m_ptr)->cur_num++;
507 * @brief 移動先のフロアに伴ったペットを配置する / Place preserved pet monsters on new floor
510 static void place_pet(void)
513 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
515 for (i = 0; i < max_num; i++)
517 POSITION cy = 0, cx = 0;
520 if (!(party_mon[i].r_idx)) continue;
525 p_ptr->riding = m_idx;
537 for (d = 1; d < A_MAX; d++)
539 for (j = 1000; j > 0; j--)
541 scatter(&cy, &cx, p_ptr->y, p_ptr->x, d, 0);
542 if (monster_can_enter(cy, cx, &r_info[party_mon[i].r_idx], 0)) break;
546 m_idx = (d == 6) ? 0 : m_pop();
551 monster_type *m_ptr = ¤t_floor_ptr->m_list[m_idx];
554 current_floor_ptr->grid_array[cy][cx].m_idx = m_idx;
556 m_ptr->r_idx = party_mon[i].r_idx;
558 /* Copy all member of the structure */
559 *m_ptr = party_mon[i];
560 r_ptr = real_r_ptr(m_ptr);
565 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) current_floor_ptr->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 = ¤t_floor_ptr->m_list[i];
636 if (!monster_is_valid(m_ptr)) continue;
638 /* Extract real monster race */
639 r_ptr = real_r_ptr(m_ptr);
641 /* Memorize location of the unique monster */
642 if ((r_ptr->flags1 & RF1_UNIQUE) ||
643 (r_ptr->flags7 & RF7_NAZGUL))
645 r_ptr->floor_id = cur_floor_id;
649 /* Maintain artifatcs */
650 for (i = 1; i < o_max; i++)
652 object_type *o_ptr = ¤t_floor_ptr->o_list[i];
654 /* Skip dead objects */
655 if (!o_ptr->k_idx) continue;
657 /* Memorize location of the artifact */
658 if (object_is_fixed_artifact(o_ptr))
660 a_info[o_ptr->name1].floor_id = cur_floor_id;
667 * @brief フロア移動時、プレイヤーの移動先モンスターが既にいた場合ランダムな近隣に移動させる / When a monster is at a place where player will return,
670 static void get_out_monster(void)
674 POSITION oy = p_ptr->y;
675 POSITION ox = p_ptr->x;
676 MONSTER_IDX m_idx = current_floor_ptr->grid_array[oy][ox].m_idx;
678 /* Nothing to do if no monster */
681 /* Look until done */
686 /* Pick a (possibly illegal) location */
687 POSITION ny = rand_spread(oy, dis);
688 POSITION nx = rand_spread(ox, dis);
692 /* Stop after 1000 tries */
693 if (tries > 10000) return;
696 * Increase distance after doing enough tries
697 * compared to area of possible space
699 if (tries > 20 * dis * dis) dis++;
701 /* Ignore illegal locations */
702 if (!in_bounds(ny, nx)) continue;
704 /* Require "empty" floor space */
705 if (!cave_empty_bold(ny, nx)) continue;
707 /* Hack -- no teleport onto glyph of warding */
708 if (is_glyph_grid(¤t_floor_ptr->grid_array[ny][nx])) continue;
709 if (is_explosive_rune_grid(¤t_floor_ptr->grid_array[ny][nx])) continue;
711 /* ...nor onto the Pattern */
712 if (pattern_tile(ny, nx)) continue;
714 /*** It's a good place ***/
716 m_ptr = ¤t_floor_ptr->m_list[m_idx];
718 /* Update the old location */
719 current_floor_ptr->grid_array[oy][ox].m_idx = 0;
721 /* Update the new location */
722 current_floor_ptr->grid_array[ny][nx].m_idx = m_idx;
724 /* Move the monster */
728 /* No need to do update_monster() */
736 * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with g_ptr->special?
738 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
742 * @brief 新フロアに移動元フロアに繋がる階段を配置する / Virtually teleport onto the stairs that is connecting between two floors.
743 * @param sf_ptr 移動元の保存フロア構造体参照ポインタ
746 static void locate_connected_stairs(saved_floor_type *sf_ptr)
748 POSITION x, y, sx = 0, sy = 0;
749 POSITION x_table[20];
750 POSITION y_table[20];
754 /* Search usable stairs */
755 for (y = 0; y < current_floor_ptr->height; y++)
757 for (x = 0; x < current_floor_ptr->width; x++)
759 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
760 feature_type *f_ptr = &f_info[g_ptr->feat];
763 if (change_floor_mode & CFM_UP)
765 if (have_flag(f_ptr->flags, FF_LESS) && have_flag(f_ptr->flags, FF_STAIRS) &&
766 !have_flag(f_ptr->flags, FF_SPECIAL))
770 /* Found fixed stairs? */
771 if (g_ptr->special &&
772 g_ptr->special == sf_ptr->upper_floor_id)
780 else if (change_floor_mode & CFM_DOWN)
782 if (have_flag(f_ptr->flags, FF_MORE) && have_flag(f_ptr->flags, FF_STAIRS) &&
783 !have_flag(f_ptr->flags, FF_SPECIAL))
787 /* Found fixed stairs */
788 if (g_ptr->special &&
789 g_ptr->special == sf_ptr->lower_floor_id)
799 if (have_flag(f_ptr->flags, FF_BLDG))
805 if (ok && (num < 20))
822 /* No stairs found! -- No return */
823 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
825 /* Mega Hack -- It's not the stairs you enter. Disable it. */
826 if (!feat_uses_special(current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].feat)) current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].special = 0;
830 /* Choose random one */
833 /* Point stair location */
834 p_ptr->y = y_table[i];
835 p_ptr->x = x_table[i];
840 * @brief 現在のフロアを離れるに伴って行なわれる保存処理
841 * / Maintain quest monsters, mark next floor_id at stairs, save current floor, and prepare to enter next floor.
844 void leave_floor(void)
846 grid_type *g_ptr = NULL;
848 saved_floor_type *sf_ptr;
849 MONRACE_IDX quest_r_idx = 0;
852 /* Preserve pets and prepare to take these to next floor */
855 /* Remove all mirrors without explosion */
856 remove_all_mirrors(FALSE);
858 if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
860 /* New floor is not yet prepared */
863 /* Temporary get a floor_id (for Arena) */
864 if (!p_ptr->floor_id &&
865 (change_floor_mode & CFM_SAVE_FLOORS) &&
866 !(change_floor_mode & CFM_NO_RETURN))
868 /* Get temporal floor_id */
869 p_ptr->floor_id = get_new_floor_id();
872 /* Search the quest monster index */
873 for (i = 0; i < max_q_idx; i++)
875 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
876 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
877 (quest[i].type == QUEST_TYPE_RANDOM)) &&
878 (quest[i].level == current_floor_ptr->dun_level) &&
879 (p_ptr->dungeon_idx == quest[i].dungeon) &&
880 !(quest[i].flags & QUEST_FLAG_PRESET))
882 quest_r_idx = quest[i].r_idx;
886 /* Maintain quest monsters */
887 for (i = 1; i < m_max; i++)
890 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
892 if (!monster_is_valid(m_ptr)) continue;
894 /* Only maintain quest monsters */
895 if (quest_r_idx != m_ptr->r_idx) continue;
897 /* Extract real monster race */
898 r_ptr = real_r_ptr(m_ptr);
900 /* Ignore unique monsters */
901 if ((r_ptr->flags1 & RF1_UNIQUE) ||
902 (r_ptr->flags7 & RF7_NAZGUL)) continue;
904 /* Delete non-unique quest monsters */
905 delete_monster_idx(i);
908 /* Check if there is a same item */
909 for (i = 0; i < INVEN_PACK; i++)
911 object_type *o_ptr = &inventory[i];
913 /* Skip dead objects */
914 if (!o_ptr->k_idx) continue;
916 /* Delete old memorized location of the artifact */
917 if (object_is_fixed_artifact(o_ptr))
919 a_info[o_ptr->name1].floor_id = 0;
923 /* Extract current floor info or NULL */
924 sf_ptr = get_sf_ptr(p_ptr->floor_id);
926 /* Choose random stairs */
927 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
929 locate_connected_stairs(sf_ptr);
932 /* Extract new dungeon level */
933 if (change_floor_mode & CFM_SAVE_FLOORS)
935 /* Extract stair position */
936 g_ptr = ¤t_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
937 f_ptr = &f_info[g_ptr->feat];
939 /* Get back to old saved floor? */
940 if (g_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(g_ptr->special))
942 /* Saved floor is exist. Use it. */
943 new_floor_id = g_ptr->special;
946 /* Mark shaft up/down */
947 if (have_flag(f_ptr->flags, FF_STAIRS) && have_flag(f_ptr->flags, FF_SHAFT))
949 prepare_change_floor_mode(CFM_SHAFT);
953 /* Climb up/down some sort of stairs */
954 if (change_floor_mode & (CFM_DOWN | CFM_UP))
958 /* Extract level movement number */
959 if (change_floor_mode & CFM_DOWN) move_num = 1;
960 else if (change_floor_mode & CFM_UP) move_num = -1;
962 /* Shafts are deeper than normal stairs */
963 if (change_floor_mode & CFM_SHAFT)
964 move_num += SGN(move_num);
966 /* Get out from or Enter the dungeon */
967 if (change_floor_mode & CFM_DOWN)
969 if (!current_floor_ptr->dun_level)
970 move_num = d_info[p_ptr->dungeon_idx].mindepth;
972 else if (change_floor_mode & CFM_UP)
974 if (current_floor_ptr->dun_level + move_num < d_info[p_ptr->dungeon_idx].mindepth)
975 move_num = -current_floor_ptr->dun_level;
978 current_floor_ptr->dun_level += move_num;
981 /* Leaving the dungeon to town */
982 if (!current_floor_ptr->dun_level && p_ptr->dungeon_idx)
984 p_ptr->leaving_dungeon = TRUE;
985 if (!vanilla_town && !lite_town)
987 p_ptr->wilderness_y = d_info[p_ptr->dungeon_idx].dy;
988 p_ptr->wilderness_x = d_info[p_ptr->dungeon_idx].dx;
990 p_ptr->recall_dungeon = p_ptr->dungeon_idx;
991 p_ptr->dungeon_idx = 0;
993 /* Reach to the surface -- Clear all saved floors */
994 change_floor_mode &= ~CFM_SAVE_FLOORS;
997 /* Kill some old saved floors */
998 if (!(change_floor_mode & CFM_SAVE_FLOORS))
1000 /* Kill all saved floors */
1001 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1002 kill_saved_floor(&saved_floors[i]);
1004 /* Reset visit_mark count */
1005 latest_visit_mark = 1;
1007 else if (change_floor_mode & CFM_NO_RETURN)
1009 /* Kill current floor */
1010 kill_saved_floor(sf_ptr);
1013 /* No current floor -- Left/Enter dungeon etc... */
1014 if (!p_ptr->floor_id)
1016 /* No longer need to save current floor */
1021 /* Mark next floor_id on the previous floor */
1025 new_floor_id = get_new_floor_id();
1027 /* Connect from here */
1028 if (g_ptr && !feat_uses_special(g_ptr->feat))
1030 g_ptr->special = new_floor_id;
1034 /* Fix connection -- level teleportation or trap door */
1035 if (change_floor_mode & CFM_RAND_CONNECT)
1037 if (change_floor_mode & CFM_UP)
1038 sf_ptr->upper_floor_id = new_floor_id;
1039 else if (change_floor_mode & CFM_DOWN)
1040 sf_ptr->lower_floor_id = new_floor_id;
1043 /* If you can return, you need to save previous floor */
1044 if ((change_floor_mode & CFM_SAVE_FLOORS) &&
1045 !(change_floor_mode & CFM_NO_RETURN))
1047 /* Get out of the my way! */
1050 /* Record the last visit current_world_ptr->game_turn of current floor */
1051 sf_ptr->last_visit = current_world_ptr->game_turn;
1057 /* Save current floor */
1058 if (!save_floor(sf_ptr, 0))
1060 /* Save failed -- No return */
1061 prepare_change_floor_mode(CFM_NO_RETURN);
1063 /* Kill current floor */
1064 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
1071 * @brief フロアの切り替え処理 / Enter new floor.
1074 * If the floor is an old saved floor, it will be\n
1075 * restored from the temporal file. If the floor is new one, new current_floor_ptr->grid_array\n
1076 * will be generated.\n
1078 void change_floor(void)
1080 saved_floor_type *sf_ptr;
1081 bool loaded = FALSE;
1083 /* The dungeon is not ready */
1084 character_dungeon = FALSE;
1086 /* No longer in the trap detecteded region */
1087 p_ptr->dtrap = FALSE;
1089 /* Mega-Hack -- no panel yet */
1095 /* Mega-Hack -- not ambushed on the wildness? */
1096 p_ptr->ambush_flag = FALSE;
1098 /* No saved floors (On the surface etc.) */
1099 if (!(change_floor_mode & CFM_SAVE_FLOORS) &&
1100 !(change_floor_mode & CFM_FIRST_FLOOR))
1102 /* Create current_floor_ptr->grid_array */
1103 generate_random_floor();
1105 /* Paranoia -- No new saved floor */
1109 /* In the dungeon */
1112 /* No floor_id yet */
1116 new_floor_id = get_new_floor_id();
1119 /* Pointer for infomations of new floor */
1120 sf_ptr = get_sf_ptr(new_floor_id);
1122 /* Try to restore old floor */
1123 if (sf_ptr->last_visit)
1125 /* Old saved floor is exist */
1126 if (load_floor(sf_ptr, 0))
1130 /* Forbid return stairs */
1131 if (change_floor_mode & CFM_NO_RETURN)
1133 grid_type *g_ptr = ¤t_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
1135 if (!feat_uses_special(g_ptr->feat))
1137 if (change_floor_mode & (CFM_DOWN | CFM_UP))
1139 /* Reset to floor */
1140 g_ptr->feat = feat_ground_type[randint0(100)];
1150 * Set lower/upper_floor_id of new floor when the new
1151 * floor is right-above/right-under the current floor.
1153 * Stair creation/Teleport level/Trap door will take
1154 * you the same floor when you used it later again.
1156 if (p_ptr->floor_id)
1158 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1160 if (change_floor_mode & CFM_UP)
1162 /* New floor is right-above */
1163 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1164 sf_ptr->lower_floor_id = p_ptr->floor_id;
1166 else if (change_floor_mode & CFM_DOWN)
1168 /* New floor is right-under */
1169 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1170 sf_ptr->upper_floor_id = p_ptr->floor_id;
1174 /* Break connection to killed floor */
1177 if (change_floor_mode & CFM_UP)
1178 sf_ptr->lower_floor_id = 0;
1179 else if (change_floor_mode & CFM_DOWN)
1180 sf_ptr->upper_floor_id = 0;
1183 /* Maintain monsters and artifacts */
1187 GAME_TURN tmp_last_visit = sf_ptr->last_visit;
1188 GAME_TURN absence_ticks;
1189 int alloc_chance = d_info[p_ptr->dungeon_idx].max_m_alloc_chance;
1190 GAME_TURN alloc_times;
1192 while (tmp_last_visit > current_world_ptr->game_turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
1193 absence_ticks = (current_world_ptr->game_turn - tmp_last_visit) / TURNS_PER_TICK;
1195 /* Maintain monsters */
1196 for (i = 1; i < m_max; i++)
1198 monster_race *r_ptr;
1199 monster_type *m_ptr = ¤t_floor_ptr->m_list[i];
1201 if (!monster_is_valid(m_ptr)) continue;
1206 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1208 /* Remove timed status (except MTIMED_CSLEEP) */
1209 (void)set_monster_fast(i, 0);
1210 (void)set_monster_slow(i, 0);
1211 (void)set_monster_stunned(i, 0);
1212 (void)set_monster_confused(i, 0);
1213 (void)set_monster_monfear(i, 0);
1214 (void)set_monster_invulner(i, 0, FALSE);
1217 /* Extract real monster race */
1218 r_ptr = real_r_ptr(m_ptr);
1220 /* Ignore non-unique */
1221 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1222 !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1224 /* Appear at a different floor? */
1225 if (r_ptr->floor_id != new_floor_id)
1227 /* Disapper from here */
1228 delete_monster_idx(i);
1232 /* Maintain artifatcs */
1233 for (i = 1; i < o_max; i++)
1235 object_type *o_ptr = ¤t_floor_ptr->o_list[i];
1237 /* Skip dead objects */
1238 if (!o_ptr->k_idx) continue;
1240 /* Ignore non-artifact */
1241 if (!object_is_fixed_artifact(o_ptr)) continue;
1243 /* Appear at a different floor? */
1244 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1246 /* Disappear from here */
1247 delete_object_idx(i);
1251 /* Cancel preserve */
1252 a_info[o_ptr->name1].cur_num = 1;
1256 (void)place_quest_monsters();
1258 /* Place some random monsters */
1259 alloc_times = absence_ticks / alloc_chance;
1261 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1264 for (i = 0; i < alloc_times; i++)
1266 /* Make a (group of) new monster */
1267 (void)alloc_monster(0, 0);
1272 /* New floor_id or failed to restore */
1273 else /* if (!loaded) */
1275 if (sf_ptr->last_visit)
1277 /* Temporal file is broken? */
1278 msg_print(_("階段は行き止まりだった。", "The staircases come to a dead end..."));
1280 /* Create simple dead end */
1283 /* Break connection */
1284 if (change_floor_mode & CFM_UP)
1286 sf_ptr->upper_floor_id = 0;
1288 else if (change_floor_mode & CFM_DOWN)
1290 sf_ptr->lower_floor_id = 0;
1295 /* Newly create current_floor_ptr->grid_array */
1296 generate_random_floor();
1299 /* Record last visit current_world_ptr->game_turn */
1300 sf_ptr->last_visit = current_world_ptr->game_turn;
1302 /* Set correct current_floor_ptr->dun_level value */
1303 sf_ptr->dun_level = current_floor_ptr->dun_level;
1305 /* Create connected stairs */
1306 if (!(change_floor_mode & CFM_NO_RETURN))
1308 /* Extract stair position */
1309 grid_type *g_ptr = ¤t_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
1311 /*** Create connected stairs ***/
1313 /* No stairs down from Quest */
1314 if ((change_floor_mode & CFM_UP) && !quest_number(current_floor_ptr->dun_level))
1316 g_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair;
1319 /* No stairs up when ironman_downward */
1320 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1322 g_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair;
1325 /* Paranoia -- Clear mimic */
1328 /* Connect to previous floor */
1329 g_ptr->special = p_ptr->floor_id;
1333 /* Arrive at random grid */
1334 if (change_floor_mode & (CFM_RAND_PLACE))
1336 (void)new_player_spot();
1339 /* You see stairs blocked */
1340 else if ((change_floor_mode & CFM_NO_RETURN) && (change_floor_mode & (CFM_DOWN | CFM_UP)))
1344 msg_print(_("突然階段が塞がれてしまった。", "Suddenly the stairs is blocked!"));
1348 msg_print(_("ゴトゴトと何か音がした。", "You hear some noises."));
1355 * The "current_world_ptr->game_turn" is not always different number because
1356 * the level teleport doesn't take any current_world_ptr->game_turn. Use
1357 * visit mark instead of last visit current_world_ptr->game_turn to find the
1358 * oldest saved floor.
1360 sf_ptr->visit_mark = latest_visit_mark++;
1363 /* Place preserved pet monsters */
1366 /* Reset travel target place */
1367 forget_travel_flow();
1369 /* Hack -- maintain unique and artifacts */
1370 update_unique_artifact(new_floor_id);
1372 /* Now the player is in new floor */
1373 p_ptr->floor_id = new_floor_id;
1375 /* The dungeon is ready */
1376 character_dungeon = TRUE;
1378 /* Hack -- Munchkin characters always get whole map */
1379 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1380 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1382 /* Remember when this level was "created" */
1383 current_floor_ptr->generated_turn = current_world_ptr->game_turn;
1385 /* No dungeon feeling yet */
1386 p_ptr->feeling_turn = current_floor_ptr->generated_turn;
1389 /* Clear all flags */
1390 change_floor_mode = 0L;
1392 select_floor_music();
1396 * @brief プレイヤーの手による能動的な階段生成処理 /
1397 * Create stairs at or move previously created stairs into the player location.
1400 void stair_creation(void)
1402 saved_floor_type *sf_ptr;
1403 saved_floor_type *dest_sf_ptr;
1407 FLOOR_IDX dest_floor_id = 0;
1410 /* Forbid up staircases on Ironman mode */
1411 if (ironman_downward) up = FALSE;
1413 /* Forbid down staircases on quest level */
1414 if (quest_number(current_floor_ptr->dun_level) || (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth)) down = FALSE;
1416 /* No effect out of standard dungeon floor */
1417 if (!current_floor_ptr->dun_level || (!up && !down) ||
1418 (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1419 p_ptr->inside_arena || p_ptr->inside_battle)
1421 /* arena or quest */
1422 msg_print(_("効果がありません!", "There is no effect!"));
1426 /* Artifacts resists */
1427 if (!cave_valid_bold(p_ptr->y, p_ptr->x))
1429 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
1433 /* Destroy all objects in the grid */
1434 delete_object(p_ptr->y, p_ptr->x);
1436 /* Extract current floor data */
1437 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1440 /* No floor id? -- Create now! */
1441 p_ptr->floor_id = get_new_floor_id();
1442 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1445 /* Choose randomly */
1448 if (randint0(100) < 50) up = FALSE;
1452 /* Destination is already fixed */
1455 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1459 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1463 /* Search old stairs leading to the destination */
1468 for (y = 0; y < current_floor_ptr->height; y++)
1470 for (x = 0; x < current_floor_ptr->width; x++)
1472 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1474 if (!g_ptr->special) continue;
1475 if (feat_uses_special(g_ptr->feat)) continue;
1476 if (g_ptr->special != dest_floor_id) continue;
1478 /* Remove old stairs */
1480 cave_set_feat(y, x, feat_ground_type[randint0(100)]);
1485 /* No old destination -- Get new one now */
1488 dest_floor_id = get_new_floor_id();
1492 sf_ptr->upper_floor_id = dest_floor_id;
1494 sf_ptr->lower_floor_id = dest_floor_id;
1497 /* Extract destination floor data */
1498 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1501 /* Create a staircase */
1504 cave_set_feat(p_ptr->y, p_ptr->x,
1505 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level <= current_floor_ptr->dun_level - 2)) ?
1506 feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair);
1510 cave_set_feat(p_ptr->y, p_ptr->x,
1511 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level >= current_floor_ptr->dun_level + 2)) ?
1512 feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair);
1516 /* Connect this stairs to the destination */
1517 current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].special = dest_floor_id;