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"
23 static FLOOR_IDX new_floor_id; /*!<次のフロアのID / floor_id of the destination */
24 static u32b change_floor_mode; /*!<フロア移行処理に関するフラグ / Mode flags for changing floor */
25 static u32b latest_visit_mark; /*!<フロアを渡った回数?(確認中) / Max number of visit_mark */
29 * @brief 保存フロア配列を初期化する / Initialize saved_floors array.
30 * @param force テンポラリファイルが残っていた場合も警告なしで強制的に削除する。
31 * @details Make sure that old temporal files are not remaining as gurbages.
34 void init_saved_floors(bool force)
36 char floor_savefile[1024];
39 BIT_FLAGS mode = 0644;
43 /* Get "games" permissions */
48 for (i = 0; i < MAX_SAVED_FLOORS; i++)
50 saved_floor_type *sf_ptr = &saved_floors[i];
53 sprintf(floor_savefile, "%s.F%02d", savefile, i);
55 /* Grab permissions */
58 /* Try to create the file */
59 fd = fd_make(floor_savefile, mode);
61 /* Drop permissions */
69 msg_print(_("エラー:古いテンポラリ・ファイルが残っています。", "Error: There are old temporal files."));
70 msg_print(_("変愚蛮怒を二重に起動していないか確認してください。", "Make sure you are not running two game processes simultaneously."));
71 msg_print(_("過去に変愚蛮怒がクラッシュした場合は一時ファイルを", "If the temporal files are garbages of old crashed process, "));
72 msg_print(_("強制的に削除して実行を続けられます。", "you can delete it safely."));
73 if (!get_check(_("強制的に削除してもよろしいですか?", "Do you delete old temporal files? ")))
74 quit(_("実行中止", "Aborted."));
84 /* Grab permissions */
87 /* Simply kill the temporal file */
88 (void)fd_kill(floor_savefile);
90 /* Drop permissions */
96 /* No floor_id used yet (No.0 is reserved to indicate non existance) */
99 /* vist_mark is from 1 */
100 latest_visit_mark = 1;
102 /* A sign to mark temporal files */
103 saved_floor_file_sign = (u32b)time(NULL);
105 /* No next floor yet */
108 /* No change floor mode yet */
109 change_floor_mode = 0;
113 /* Drop "games" permissions */
120 * @brief 保存フロア用テンポラリファイルを削除する / Kill temporal files
121 * @details Should be called just before the game quit.
124 void clear_saved_floor_files(void)
126 char floor_savefile[1024];
131 /* Get "games" permissions */
136 for (i = 0; i < MAX_SAVED_FLOORS; i++)
138 saved_floor_type *sf_ptr = &saved_floors[i];
140 /* No temporal file */
141 if (!sf_ptr->floor_id) continue;
142 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
145 sprintf(floor_savefile, "%s.F%02d", savefile, i);
147 /* Grab permissions */
150 /* Simply kill the temporal file */
151 (void)fd_kill(floor_savefile);
153 /* Drop permissions */
159 /* Drop "games" permissions */
166 * @brief 保存フロアIDから参照ポインタを得る / Get a pointer for an item of the saved_floors array.
167 * @param floor_id 保存フロアID
168 * @return IDに対応する保存フロアのポインタ、ない場合はNULLを返す。
170 saved_floor_type *get_sf_ptr(FLOOR_IDX floor_id)
174 /* floor_id No.0 indicates no floor */
175 if (!floor_id) return NULL;
177 for (i = 0; i < MAX_SAVED_FLOORS; i++)
179 saved_floor_type *sf_ptr = &saved_floors[i];
181 if (sf_ptr->floor_id == floor_id) return sf_ptr;
190 * @brief 参照ポインタ先の保存フロアを抹消する / kill a saved floor and get an empty space
191 * @param sf_ptr 保存フロアの参照ポインタ
194 static void kill_saved_floor(saved_floor_type *sf_ptr)
196 char floor_savefile[1024];
202 if (!sf_ptr->floor_id) return;
204 if (sf_ptr->floor_id == p_ptr->floor_id)
206 /* Kill current floor */
209 /* Current floor doesn't have temporal file */
214 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
216 /* Grab permissions */
219 /* Simply kill the temporal file */
220 (void)fd_kill(floor_savefile);
222 /* Drop permissions */
226 /* No longer exists */
227 sf_ptr->floor_id = 0;
232 * @brief 新規に利用可能な保存フロアを返す / Initialize new saved floor and get its floor id.
233 * @return 利用可能な保存フロアID
235 * If number of saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
237 FLOOR_IDX get_new_floor_id(void)
239 saved_floor_type *sf_ptr = NULL;
242 /* Look for empty space */
243 for (i = 0; i < MAX_SAVED_FLOORS; i++)
245 sf_ptr = &saved_floors[i];
247 if (!sf_ptr->floor_id) break;
251 if (i == MAX_SAVED_FLOORS)
254 u32b oldest_visit = 0xffffffffL;
256 /* Search for oldest */
257 for (i = 0; i < MAX_SAVED_FLOORS; i++)
259 sf_ptr = &saved_floors[i];
261 /* Don't kill current floor */
262 if (sf_ptr->floor_id == p_ptr->floor_id) continue;
264 /* Don't kill newer */
265 if (sf_ptr->visit_mark > oldest_visit) continue;
268 oldest_visit = sf_ptr->visit_mark;
271 /* Kill oldest saved floor */
272 sf_ptr = &saved_floors[oldest];
273 kill_saved_floor(sf_ptr);
279 /* Prepare new floor data */
280 sf_ptr->savefile_id = i;
281 sf_ptr->floor_id = max_floor_id;
282 sf_ptr->last_visit = 0;
283 sf_ptr->upper_floor_id = 0;
284 sf_ptr->lower_floor_id = 0;
285 sf_ptr->visit_mark = latest_visit_mark++;
287 /* sf_ptr->dun_level may be changed later */
288 sf_ptr->dun_level = current_floor_ptr->dun_level;
291 /* Increment number of floor_id */
292 if (max_floor_id < MAX_SHORT) max_floor_id++;
294 /* 32767 floor_ids are all used up! Re-use ancient IDs */
295 else max_floor_id = 1;
297 return sf_ptr->floor_id;
302 * @brief フロア切り替え時の処理フラグを追加する / Prepare mode flags of changing floor
303 * @param mode 追加したい所持フラグ
306 void prepare_change_floor_mode(BIT_FLAGS mode)
308 change_floor_mode |= mode;
312 * @brief 階段移動先のフロアが生成できない時に簡単な行き止まりマップを作成する / Builds the dead end
315 static void build_dead_end(void)
319 /* Clear and empty the current_floor_ptr->grid_array */
322 /* Fill the arrays of floors and walls in the good proportions */
323 set_floor_and_wall(0);
326 cur_hgt = SCREEN_HGT;
327 cur_wid = SCREEN_WID;
329 /* Filled with permanent walls */
330 for (y = 0; y < MAX_HGT; y++)
332 for (x = 0; x < MAX_WID; x++)
334 /* Create "solid" perma-wall */
335 place_solid_perm_bold(y, x);
339 /* Place at center of the floor */
340 p_ptr->y = cur_hgt / 2;
341 p_ptr->x = cur_wid / 2;
343 /* Give one square */
344 place_floor_bold(p_ptr->y, p_ptr->x);
346 wipe_generate_random_floor_flags();
351 #define MAX_PARTY_MON 21 /*!< フロア移動時に先のフロアに連れて行けるペットの最大数 Maximum number of preservable pets */
352 static monster_type party_mon[MAX_PARTY_MON]; /*!< フロア移動に保存するペットモンスターの配列 */
355 * @brief フロア移動時のペット保存処理 / Preserve_pets
358 static void preserve_pet(void)
363 for (num = 0; num < MAX_PARTY_MON; num++)
365 party_mon[num].r_idx = 0;
370 monster_type *m_ptr = &m_list[p_ptr->riding];
372 /* Pet of other pet don't follow. */
373 if (m_ptr->parent_m_idx)
376 p_ptr->pet_extra_flags &= ~(PF_RYOUTE);
377 p_ptr->riding_ryoute = p_ptr->old_riding_ryoute = FALSE;
381 /* Preserve the mount */
382 (void)COPY(&party_mon[0], m_ptr, monster_type);
384 /* Delete from this floor */
385 delete_monster_idx(p_ptr->riding);
390 * If player is in wild mode, no pets are preserved
391 * except a monster whom player riding
393 if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->inside_battle)
395 for (i = m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
397 monster_type *m_ptr = &m_list[i];
399 if (!m_ptr->r_idx) continue;
400 if (!is_pet(m_ptr)) continue;
401 if (i == p_ptr->riding) continue;
403 if (reinit_wilderness)
405 /* Don't lose sight of pets when getting a Quest */
409 POSITION dis = distance(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx);
411 /* Confused (etc.) monsters don't follow. */
412 if (MON_CONFUSED(m_ptr) || MON_STUNNED(m_ptr) || MON_CSLEEP(m_ptr)) continue;
414 /* Pet of other pet don't follow. */
415 if (m_ptr->parent_m_idx) continue;
418 * Pets with nickname will follow even from 3 blocks away
419 * when you or the pet can see the other.
421 if (m_ptr->nickname &&
422 ((player_has_los_bold(m_ptr->fy, m_ptr->fx) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) ||
423 (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))))
425 if (dis > 3) continue;
429 if (dis > 1) continue;
433 (void)COPY(&party_mon[num], &m_list[i], monster_type);
437 /* Delete from this floor */
438 delete_monster_idx(i);
442 if (record_named_pet)
444 for (i = m_max - 1; i >=1; i--)
446 monster_type *m_ptr = &m_list[i];
447 GAME_TEXT m_name[MAX_NLEN];
449 if (!m_ptr->r_idx) continue;
450 if (!is_pet(m_ptr)) continue;
451 if (!m_ptr->nickname) continue;
452 if (p_ptr->riding == i) continue;
454 monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
455 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_MOVED, m_name);
460 /* Pet of other pet may disappear. */
461 for (i = m_max - 1; i >=1; i--)
463 monster_type *m_ptr = &m_list[i];
465 /* Are there its parent? */
466 if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
468 /* Its parent have gone, it also goes away. */
472 GAME_TEXT m_name[MAX_NLEN];
473 monster_desc(m_name, m_ptr, 0);
474 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
477 delete_monster_idx(i);
484 * @brief フロア移動時にペットを伴った場合の準備処理 / Pre-calculate the racial counters of preserved pets
487 * To prevent multiple generation of unique monster who is the minion of player
489 void precalc_cur_num_of_pet(void)
493 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
495 for (i = 0; i < max_num; i++)
497 m_ptr = &party_mon[i];
499 /* Skip empty monsters */
500 if (!m_ptr->r_idx) continue;
502 /* Hack -- Increase the racial counter */
503 real_r_ptr(m_ptr)->cur_num++;
508 * @brief 移動先のフロアに伴ったペットを配置する / Place preserved pet monsters on new floor
511 static void place_pet(void)
514 int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
516 for (i = 0; i < max_num; i++)
518 POSITION cy = 0, cx = 0;
521 if (!(party_mon[i].r_idx)) continue;
526 p_ptr->riding = m_idx;
538 for (d = 1; d < A_MAX; d++)
540 for (j = 1000; j > 0; j--)
542 scatter(&cy, &cx, p_ptr->y, p_ptr->x, d, 0);
543 if (monster_can_enter(cy, cx, &r_info[party_mon[i].r_idx], 0)) break;
547 m_idx = (d == 6) ? 0 : m_pop();
552 monster_type *m_ptr = &m_list[m_idx];
555 current_floor_ptr->grid_array[cy][cx].m_idx = m_idx;
557 m_ptr->r_idx = party_mon[i].r_idx;
559 /* Copy all member of the structure */
560 *m_ptr = party_mon[i];
561 r_ptr = real_r_ptr(m_ptr);
566 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
569 m_ptr->hold_o_idx = 0;
572 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
574 /* Monster is still being nice */
575 m_ptr->mflag |= (MFLAG_NICE);
577 /* Must repair monsters */
578 repair_monsters = TRUE;
580 update_monster(m_idx, TRUE);
583 /* Pre-calculated in precalc_cur_num_of_pet() */
584 /* r_ptr->cur_num++; */
586 /* Hack -- Count the number of "reproducers" */
587 if (r_ptr->flags2 & RF2_MULTIPLY) num_repro++;
589 /* Hack -- Notice new multi-hued monsters */
591 monster_race *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
592 if (ap_r_ptr->flags1 & (RF1_ATTR_MULTI | RF1_SHAPECHANGER))
593 shimmer_monsters = TRUE;
598 monster_type *m_ptr = &party_mon[i];
599 monster_race *r_ptr = real_r_ptr(m_ptr);
600 GAME_TEXT m_name[MAX_NLEN];
602 monster_desc(m_name, m_ptr, 0);
603 msg_format(_("%sとはぐれてしまった。", "You have lost sight of %s."), m_name);
604 if (record_named_pet && m_ptr->nickname)
606 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
607 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOST_SIGHT, m_name);
610 /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
611 if (r_ptr->cur_num) r_ptr->cur_num--;
615 /* For accuracy of precalc_cur_num_of_pet() */
616 (void)C_WIPE(party_mon, MAX_PARTY_MON, monster_type);
621 * @brief ユニークモンスターやアーティファクトの所在フロアを更新する / Hack -- Update location of unique monsters and artifacts
622 * @param cur_floor_id 現在のフロアID
625 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly\n
626 * while new floor creation since dungeons may be re-created by\n
627 * auto-scum option.\n
629 static void update_unique_artifact(s16b cur_floor_id)
633 /* Maintain unique monsters */
634 for (i = 1; i < m_max; i++)
637 monster_type *m_ptr = &m_list[i];
639 /* Skip dead monsters */
640 if (!m_ptr->r_idx) continue;
642 /* Extract real monster race */
643 r_ptr = real_r_ptr(m_ptr);
645 /* Memorize location of the unique monster */
646 if ((r_ptr->flags1 & RF1_UNIQUE) ||
647 (r_ptr->flags7 & RF7_NAZGUL))
649 r_ptr->floor_id = cur_floor_id;
653 /* Maintain artifatcs */
654 for (i = 1; i < o_max; i++)
656 object_type *o_ptr = &o_list[i];
658 /* Skip dead objects */
659 if (!o_ptr->k_idx) continue;
661 /* Memorize location of the artifact */
662 if (object_is_fixed_artifact(o_ptr))
664 a_info[o_ptr->name1].floor_id = cur_floor_id;
671 * @brief フロア移動時、プレイヤーの移動先モンスターが既にいた場合ランダムな近隣に移動させる / When a monster is at a place where player will return,
674 static void get_out_monster(void)
678 POSITION oy = p_ptr->y;
679 POSITION ox = p_ptr->x;
680 MONSTER_IDX m_idx = current_floor_ptr->grid_array[oy][ox].m_idx;
682 /* Nothing to do if no monster */
685 /* Look until done */
690 /* Pick a (possibly illegal) location */
691 POSITION ny = rand_spread(oy, dis);
692 POSITION nx = rand_spread(ox, dis);
696 /* Stop after 1000 tries */
697 if (tries > 10000) return;
700 * Increase distance after doing enough tries
701 * compared to area of possible space
703 if (tries > 20 * dis * dis) dis++;
705 /* Ignore illegal locations */
706 if (!in_bounds(ny, nx)) continue;
708 /* Require "empty" floor space */
709 if (!cave_empty_bold(ny, nx)) continue;
711 /* Hack -- no teleport onto glyph of warding */
712 if (is_glyph_grid(¤t_floor_ptr->grid_array[ny][nx])) continue;
713 if (is_explosive_rune_grid(¤t_floor_ptr->grid_array[ny][nx])) continue;
715 /* ...nor onto the Pattern */
716 if (pattern_tile(ny, nx)) continue;
718 /*** It's a good place ***/
720 m_ptr = &m_list[m_idx];
722 /* Update the old location */
723 current_floor_ptr->grid_array[oy][ox].m_idx = 0;
725 /* Update the new location */
726 current_floor_ptr->grid_array[ny][nx].m_idx = m_idx;
728 /* Move the monster */
732 /* No need to do update_monster() */
740 * マス構造体のspecial要素を利用する地形かどうかを判定するマクロ / Is this feature has special meaning (except floor_id) with g_ptr->special?
742 #define feat_uses_special(F) (have_flag(f_info[(F)].flags, FF_SPECIAL))
746 * @brief 新フロアに移動元フロアに繋がる階段を配置する / Virtually teleport onto the stairs that is connecting between two floors.
747 * @param sf_ptr 移動元の保存フロア構造体参照ポインタ
750 static void locate_connected_stairs(saved_floor_type *sf_ptr)
752 POSITION x, y, sx = 0, sy = 0;
753 POSITION x_table[20];
754 POSITION y_table[20];
758 /* Search usable stairs */
759 for (y = 0; y < cur_hgt; y++)
761 for (x = 0; x < cur_wid; x++)
763 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
764 feature_type *f_ptr = &f_info[g_ptr->feat];
767 if (change_floor_mode & CFM_UP)
769 if (have_flag(f_ptr->flags, FF_LESS) && have_flag(f_ptr->flags, FF_STAIRS) &&
770 !have_flag(f_ptr->flags, FF_SPECIAL))
774 /* Found fixed stairs? */
775 if (g_ptr->special &&
776 g_ptr->special == sf_ptr->upper_floor_id)
784 else if (change_floor_mode & CFM_DOWN)
786 if (have_flag(f_ptr->flags, FF_MORE) && have_flag(f_ptr->flags, FF_STAIRS) &&
787 !have_flag(f_ptr->flags, FF_SPECIAL))
791 /* Found fixed stairs */
792 if (g_ptr->special &&
793 g_ptr->special == sf_ptr->lower_floor_id)
803 if (have_flag(f_ptr->flags, FF_BLDG))
809 if (ok && (num < 20))
826 /* No stairs found! -- No return */
827 prepare_change_floor_mode(CFM_RAND_PLACE | CFM_NO_RETURN);
829 /* Mega Hack -- It's not the stairs you enter. Disable it. */
830 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;
834 /* Choose random one */
837 /* Point stair location */
838 p_ptr->y = y_table[i];
839 p_ptr->x = x_table[i];
844 * @brief 現在のフロアを離れるに伴って行なわれる保存処理
845 * / Maintain quest monsters, mark next floor_id at stairs, save current floor, and prepare to enter next floor.
848 void leave_floor(void)
850 grid_type *g_ptr = NULL;
852 saved_floor_type *sf_ptr;
853 MONRACE_IDX quest_r_idx = 0;
856 /* Preserve pets and prepare to take these to next floor */
859 /* Remove all mirrors without explosion */
860 remove_all_mirrors(FALSE);
862 if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
864 /* New floor is not yet prepared */
867 /* Temporary get a floor_id (for Arena) */
868 if (!p_ptr->floor_id &&
869 (change_floor_mode & CFM_SAVE_FLOORS) &&
870 !(change_floor_mode & CFM_NO_RETURN))
872 /* Get temporal floor_id */
873 p_ptr->floor_id = get_new_floor_id();
876 /* Search the quest monster index */
877 for (i = 0; i < max_q_idx; i++)
879 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
880 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
881 (quest[i].type == QUEST_TYPE_RANDOM)) &&
882 (quest[i].level == current_floor_ptr->dun_level) &&
883 (p_ptr->dungeon_idx == quest[i].dungeon) &&
884 !(quest[i].flags & QUEST_FLAG_PRESET))
886 quest_r_idx = quest[i].r_idx;
890 /* Maintain quest monsters */
891 for (i = 1; i < m_max; i++)
894 monster_type *m_ptr = &m_list[i];
896 /* Skip dead monsters */
897 if (!m_ptr->r_idx) continue;
899 /* Only maintain quest monsters */
900 if (quest_r_idx != m_ptr->r_idx) continue;
902 /* Extract real monster race */
903 r_ptr = real_r_ptr(m_ptr);
905 /* Ignore unique monsters */
906 if ((r_ptr->flags1 & RF1_UNIQUE) ||
907 (r_ptr->flags7 & RF7_NAZGUL)) continue;
909 /* Delete non-unique quest monsters */
910 delete_monster_idx(i);
913 /* Check if there is a same item */
914 for (i = 0; i < INVEN_PACK; i++)
916 object_type *o_ptr = &inventory[i];
918 /* Skip dead objects */
919 if (!o_ptr->k_idx) continue;
921 /* Delete old memorized location of the artifact */
922 if (object_is_fixed_artifact(o_ptr))
924 a_info[o_ptr->name1].floor_id = 0;
928 /* Extract current floor info or NULL */
929 sf_ptr = get_sf_ptr(p_ptr->floor_id);
931 /* Choose random stairs */
932 if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
934 locate_connected_stairs(sf_ptr);
937 /* Extract new dungeon level */
938 if (change_floor_mode & CFM_SAVE_FLOORS)
940 /* Extract stair position */
941 g_ptr = ¤t_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
942 f_ptr = &f_info[g_ptr->feat];
944 /* Get back to old saved floor? */
945 if (g_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(g_ptr->special))
947 /* Saved floor is exist. Use it. */
948 new_floor_id = g_ptr->special;
951 /* Mark shaft up/down */
952 if (have_flag(f_ptr->flags, FF_STAIRS) && have_flag(f_ptr->flags, FF_SHAFT))
954 prepare_change_floor_mode(CFM_SHAFT);
958 /* Climb up/down some sort of stairs */
959 if (change_floor_mode & (CFM_DOWN | CFM_UP))
963 /* Extract level movement number */
964 if (change_floor_mode & CFM_DOWN) move_num = 1;
965 else if (change_floor_mode & CFM_UP) move_num = -1;
967 /* Shafts are deeper than normal stairs */
968 if (change_floor_mode & CFM_SHAFT)
969 move_num += SGN(move_num);
971 /* Get out from or Enter the dungeon */
972 if (change_floor_mode & CFM_DOWN)
974 if (!current_floor_ptr->dun_level)
975 move_num = d_info[p_ptr->dungeon_idx].mindepth;
977 else if (change_floor_mode & CFM_UP)
979 if (current_floor_ptr->dun_level + move_num < d_info[p_ptr->dungeon_idx].mindepth)
980 move_num = -current_floor_ptr->dun_level;
983 current_floor_ptr->dun_level += move_num;
986 /* Leaving the dungeon to town */
987 if (!current_floor_ptr->dun_level && p_ptr->dungeon_idx)
989 p_ptr->leaving_dungeon = TRUE;
990 if (!vanilla_town && !lite_town)
992 p_ptr->wilderness_y = d_info[p_ptr->dungeon_idx].dy;
993 p_ptr->wilderness_x = d_info[p_ptr->dungeon_idx].dx;
995 p_ptr->recall_dungeon = p_ptr->dungeon_idx;
996 p_ptr->dungeon_idx = 0;
998 /* Reach to the surface -- Clear all saved floors */
999 change_floor_mode &= ~CFM_SAVE_FLOORS;
1002 /* Kill some old saved floors */
1003 if (!(change_floor_mode & CFM_SAVE_FLOORS))
1005 /* Kill all saved floors */
1006 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1007 kill_saved_floor(&saved_floors[i]);
1009 /* Reset visit_mark count */
1010 latest_visit_mark = 1;
1012 else if (change_floor_mode & CFM_NO_RETURN)
1014 /* Kill current floor */
1015 kill_saved_floor(sf_ptr);
1018 /* No current floor -- Left/Enter dungeon etc... */
1019 if (!p_ptr->floor_id)
1021 /* No longer need to save current floor */
1026 /* Mark next floor_id on the previous floor */
1030 new_floor_id = get_new_floor_id();
1032 /* Connect from here */
1033 if (g_ptr && !feat_uses_special(g_ptr->feat))
1035 g_ptr->special = new_floor_id;
1039 /* Fix connection -- level teleportation or trap door */
1040 if (change_floor_mode & CFM_RAND_CONNECT)
1042 if (change_floor_mode & CFM_UP)
1043 sf_ptr->upper_floor_id = new_floor_id;
1044 else if (change_floor_mode & CFM_DOWN)
1045 sf_ptr->lower_floor_id = new_floor_id;
1048 /* If you can return, you need to save previous floor */
1049 if ((change_floor_mode & CFM_SAVE_FLOORS) &&
1050 !(change_floor_mode & CFM_NO_RETURN))
1052 /* Get out of the my way! */
1055 /* Record the last visit turn of current floor */
1056 sf_ptr->last_visit = turn;
1062 /* Save current floor */
1063 if (!save_floor(sf_ptr, 0))
1065 /* Save failed -- No return */
1066 prepare_change_floor_mode(CFM_NO_RETURN);
1068 /* Kill current floor */
1069 kill_saved_floor(get_sf_ptr(p_ptr->floor_id));
1076 * @brief フロアの切り替え処理 / Enter new floor.
1079 * If the floor is an old saved floor, it will be\n
1080 * restored from the temporal file. If the floor is new one, new current_floor_ptr->grid_array\n
1081 * will be generated.\n
1083 void change_floor(void)
1085 saved_floor_type *sf_ptr;
1086 bool loaded = FALSE;
1088 /* The dungeon is not ready */
1089 character_dungeon = FALSE;
1091 /* No longer in the trap detecteded region */
1092 p_ptr->dtrap = FALSE;
1094 /* Mega-Hack -- no panel yet */
1100 /* Mega-Hack -- not ambushed on the wildness? */
1101 ambush_flag = FALSE;
1103 /* No saved floors (On the surface etc.) */
1104 if (!(change_floor_mode & CFM_SAVE_FLOORS) &&
1105 !(change_floor_mode & CFM_FIRST_FLOOR))
1107 /* Create current_floor_ptr->grid_array */
1108 generate_random_floor();
1110 /* Paranoia -- No new saved floor */
1114 /* In the dungeon */
1117 /* No floor_id yet */
1121 new_floor_id = get_new_floor_id();
1124 /* Pointer for infomations of new floor */
1125 sf_ptr = get_sf_ptr(new_floor_id);
1127 /* Try to restore old floor */
1128 if (sf_ptr->last_visit)
1130 /* Old saved floor is exist */
1131 if (load_floor(sf_ptr, 0))
1135 /* Forbid return stairs */
1136 if (change_floor_mode & CFM_NO_RETURN)
1138 grid_type *g_ptr = ¤t_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
1140 if (!feat_uses_special(g_ptr->feat))
1142 if (change_floor_mode & (CFM_DOWN | CFM_UP))
1144 /* Reset to floor */
1145 g_ptr->feat = feat_ground_type[randint0(100)];
1155 * Set lower/upper_floor_id of new floor when the new
1156 * floor is right-above/right-under the current floor.
1158 * Stair creation/Teleport level/Trap door will take
1159 * you the same floor when you used it later again.
1161 if (p_ptr->floor_id)
1163 saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
1165 if (change_floor_mode & CFM_UP)
1167 /* New floor is right-above */
1168 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1169 sf_ptr->lower_floor_id = p_ptr->floor_id;
1171 else if (change_floor_mode & CFM_DOWN)
1173 /* New floor is right-under */
1174 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1175 sf_ptr->upper_floor_id = p_ptr->floor_id;
1179 /* Break connection to killed floor */
1182 if (change_floor_mode & CFM_UP)
1183 sf_ptr->lower_floor_id = 0;
1184 else if (change_floor_mode & CFM_DOWN)
1185 sf_ptr->upper_floor_id = 0;
1188 /* Maintain monsters and artifacts */
1192 GAME_TURN tmp_last_visit = sf_ptr->last_visit;
1193 GAME_TURN absence_ticks;
1194 int alloc_chance = d_info[p_ptr->dungeon_idx].max_m_alloc_chance;
1195 GAME_TURN alloc_times;
1197 while (tmp_last_visit > turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
1198 absence_ticks = (turn - tmp_last_visit) / TURNS_PER_TICK;
1200 /* Maintain monsters */
1201 for (i = 1; i < m_max; i++)
1203 monster_race *r_ptr;
1204 monster_type *m_ptr = &m_list[i];
1206 /* Skip dead monsters */
1207 if (!m_ptr->r_idx) continue;
1212 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1214 /* Remove timed status (except MTIMED_CSLEEP) */
1215 (void)set_monster_fast(i, 0);
1216 (void)set_monster_slow(i, 0);
1217 (void)set_monster_stunned(i, 0);
1218 (void)set_monster_confused(i, 0);
1219 (void)set_monster_monfear(i, 0);
1220 (void)set_monster_invulner(i, 0, FALSE);
1223 /* Extract real monster race */
1224 r_ptr = real_r_ptr(m_ptr);
1226 /* Ignore non-unique */
1227 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1228 !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1230 /* Appear at a different floor? */
1231 if (r_ptr->floor_id != new_floor_id)
1233 /* Disapper from here */
1234 delete_monster_idx(i);
1238 /* Maintain artifatcs */
1239 for (i = 1; i < o_max; i++)
1241 object_type *o_ptr = &o_list[i];
1243 /* Skip dead objects */
1244 if (!o_ptr->k_idx) continue;
1246 /* Ignore non-artifact */
1247 if (!object_is_fixed_artifact(o_ptr)) continue;
1249 /* Appear at a different floor? */
1250 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1252 /* Disappear from here */
1253 delete_object_idx(i);
1257 /* Cancel preserve */
1258 a_info[o_ptr->name1].cur_num = 1;
1262 (void)place_quest_monsters();
1264 /* Place some random monsters */
1265 alloc_times = absence_ticks / alloc_chance;
1267 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1270 for (i = 0; i < alloc_times; i++)
1272 /* Make a (group of) new monster */
1273 (void)alloc_monster(0, 0);
1278 /* New floor_id or failed to restore */
1279 else /* if (!loaded) */
1281 if (sf_ptr->last_visit)
1283 /* Temporal file is broken? */
1284 msg_print(_("階段は行き止まりだった。", "The staircases come to a dead end..."));
1286 /* Create simple dead end */
1289 /* Break connection */
1290 if (change_floor_mode & CFM_UP)
1292 sf_ptr->upper_floor_id = 0;
1294 else if (change_floor_mode & CFM_DOWN)
1296 sf_ptr->lower_floor_id = 0;
1301 /* Newly create current_floor_ptr->grid_array */
1302 generate_random_floor();
1305 /* Record last visit turn */
1306 sf_ptr->last_visit = turn;
1308 /* Set correct current_floor_ptr->dun_level value */
1309 sf_ptr->dun_level = current_floor_ptr->dun_level;
1311 /* Create connected stairs */
1312 if (!(change_floor_mode & CFM_NO_RETURN))
1314 /* Extract stair position */
1315 grid_type *g_ptr = ¤t_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
1317 /*** Create connected stairs ***/
1319 /* No stairs down from Quest */
1320 if ((change_floor_mode & CFM_UP) && !quest_number(current_floor_ptr->dun_level))
1322 g_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair;
1325 /* No stairs up when ironman_downward */
1326 else if ((change_floor_mode & CFM_DOWN) && !ironman_downward)
1328 g_ptr->feat = (change_floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair;
1331 /* Paranoia -- Clear mimic */
1334 /* Connect to previous floor */
1335 g_ptr->special = p_ptr->floor_id;
1339 /* Arrive at random grid */
1340 if (change_floor_mode & (CFM_RAND_PLACE))
1342 (void)new_player_spot();
1345 /* You see stairs blocked */
1346 else if ((change_floor_mode & CFM_NO_RETURN) && (change_floor_mode & (CFM_DOWN | CFM_UP)))
1350 msg_print(_("突然階段が塞がれてしまった。", "Suddenly the stairs is blocked!"));
1354 msg_print(_("ゴトゴトと何か音がした。", "You hear some noises."));
1361 * The "turn" is not always different number because
1362 * the level teleport doesn't take any turn. Use
1363 * visit mark instead of last visit turn to find the
1364 * oldest saved floor.
1366 sf_ptr->visit_mark = latest_visit_mark++;
1369 /* Place preserved pet monsters */
1372 /* Reset travel target place */
1373 forget_travel_flow();
1375 /* Hack -- maintain unique and artifacts */
1376 update_unique_artifact(new_floor_id);
1378 /* Now the player is in new floor */
1379 p_ptr->floor_id = new_floor_id;
1381 /* The dungeon is ready */
1382 character_dungeon = TRUE;
1384 /* Hack -- Munchkin characters always get whole map */
1385 if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
1386 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1388 /* Remember when this level was "created" */
1391 /* No dungeon feeling yet */
1392 p_ptr->feeling_turn = old_turn;
1395 /* Clear all flags */
1396 change_floor_mode = 0L;
1398 select_floor_music();
1402 * @brief プレイヤーの手による能動的な階段生成処理 /
1403 * Create stairs at or move previously created stairs into the player location.
1406 void stair_creation(void)
1408 saved_floor_type *sf_ptr;
1409 saved_floor_type *dest_sf_ptr;
1413 FLOOR_IDX dest_floor_id = 0;
1416 /* Forbid up staircases on Ironman mode */
1417 if (ironman_downward) up = FALSE;
1419 /* Forbid down staircases on quest level */
1420 if (quest_number(current_floor_ptr->dun_level) || (current_floor_ptr->dun_level >= d_info[p_ptr->dungeon_idx].maxdepth)) down = FALSE;
1422 /* No effect out of standard dungeon floor */
1423 if (!current_floor_ptr->dun_level || (!up && !down) ||
1424 (p_ptr->inside_quest && is_fixed_quest_idx(p_ptr->inside_quest)) ||
1425 p_ptr->inside_arena || p_ptr->inside_battle)
1427 /* arena or quest */
1428 msg_print(_("効果がありません!", "There is no effect!"));
1432 /* Artifacts resists */
1433 if (!cave_valid_bold(p_ptr->y, p_ptr->x))
1435 msg_print(_("床上のアイテムが呪文を跳ね返した。", "The object resists the spell."));
1439 /* Destroy all objects in the grid */
1440 delete_object(p_ptr->y, p_ptr->x);
1442 /* Extract current floor data */
1443 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1448 /* No floor id? -- Create now! */
1449 p_ptr->floor_id = get_new_floor_id();
1450 sf_ptr = get_sf_ptr(p_ptr->floor_id);
1453 /* Choose randomly */
1456 if (randint0(100) < 50) up = FALSE;
1460 /* Destination is already fixed */
1463 if (sf_ptr->upper_floor_id) dest_floor_id = sf_ptr->upper_floor_id;
1467 if (sf_ptr->lower_floor_id) dest_floor_id = sf_ptr->lower_floor_id;
1471 /* Search old stairs leading to the destination */
1476 for (y = 0; y < cur_hgt; y++)
1478 for (x = 0; x < cur_wid; x++)
1480 grid_type *g_ptr = ¤t_floor_ptr->grid_array[y][x];
1482 if (!g_ptr->special) continue;
1483 if (feat_uses_special(g_ptr->feat)) continue;
1484 if (g_ptr->special != dest_floor_id) continue;
1486 /* Remove old stairs */
1488 cave_set_feat(y, x, feat_ground_type[randint0(100)]);
1493 /* No old destination -- Get new one now */
1496 dest_floor_id = get_new_floor_id();
1500 sf_ptr->upper_floor_id = dest_floor_id;
1502 sf_ptr->lower_floor_id = dest_floor_id;
1505 /* Extract destination floor data */
1506 dest_sf_ptr = get_sf_ptr(dest_floor_id);
1509 /* Create a staircase */
1512 cave_set_feat(p_ptr->y, p_ptr->x,
1513 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level <= current_floor_ptr->dun_level - 2)) ?
1514 feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair);
1518 cave_set_feat(p_ptr->y, p_ptr->x,
1519 (dest_sf_ptr->last_visit && (dest_sf_ptr->dun_level >= current_floor_ptr->dun_level + 2)) ?
1520 feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair);
1524 /* Connect this stairs to the destination */
1525 current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].special = dest_floor_id;