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
13 #include "floor/floor-save.h"
14 #include "cmd-building/cmd-building.h"
15 #include "cmd-io/cmd-dump.h"
16 #include "cmd/cmd-basic.h"
17 #include "core/player-processor.h"
18 #include "dungeon/dungeon.h"
19 #include "dungeon/quest.h"
20 #include "floor/floor-events.h"
21 #include "floor/floor-generate.h"
22 #include "floor/floor-object.h"
23 #include "floor/floor.h"
24 #include "floor/geometry.h"
25 #include "floor/wild.h"
26 #include "grid/feature.h"
27 #include "grid/grid.h"
28 #include "io/files-util.h"
31 #include "io/uid-checker.h"
32 #include "io/write-diary.h"
33 #include "mind/mind-mirror-master.h"
34 #include "monster-race/race-flags1.h"
35 #include "monster-race/race-flags2.h"
36 #include "monster-race/race-flags7.h"
37 #include "monster/monster-describer.h"
38 #include "monster/monster-description-types.h"
39 #include "monster/monster-flag-types.h"
40 #include "monster/monster-status.h"
41 #include "monster/monster-update.h"
42 #include "monster/monster-info.h"
43 #include "monster/monster2.h"
44 #include "monster/smart-learn-types.h"
45 #include "object-enchant/artifact.h"
46 #include "object/object-hook.h"
47 #include "pet/pet-util.h"
48 #include "player/player-class.h"
49 #include "player/player-effects.h"
50 #include "player/player-personalities-table.h"
51 #include "spell-kind/spells-floor.h"
52 #include "system/system-variables.h"
53 #include "util/util.h"
54 #include "view/display-main-window.h"
55 #include "world/world.h"
57 static FLOOR_IDX new_floor_id; /*!<次のフロアのID / floor_id of the destination */
58 static u32b latest_visit_mark; /*!<フロアを渡った回数?(確認中) / Max number of visit_mark */
59 #define MAX_PARTY_MON 21 /*!< フロア移動時に先のフロアに連れて行けるペットの最大数 Maximum number of preservable pets */
60 static monster_type party_mon[MAX_PARTY_MON]; /*!< フロア移動に保存するペットモンスターの配列 */
63 * Number of floor_id used from birth
65 FLOOR_IDX max_floor_id;
68 * Sign for current process used in temporary files.
69 * Actually it is the start time of current process.
71 u32b saved_floor_file_sign;
74 * @brief 保存フロア配列を初期化する / Initialize saved_floors array.
75 * @param creature_ptr プレーヤーへの参照ポインタ
76 * @param force テンポラリファイルが残っていた場合も警告なしで強制的に削除するフラグ
77 * @details Make sure that old temporary files are not remaining as gurbages.
80 void init_saved_floors(player_type *creature_ptr, bool force)
82 char floor_savefile[1024];
85 BIT_FLAGS mode = 0644;
86 for (i = 0; i < MAX_SAVED_FLOORS; i++)
88 saved_floor_type *sf_ptr = &saved_floors[i];
91 sprintf(floor_savefile, "%s.F%02d", savefile, i);
93 /* Grab permissions */
96 /* Try to create the file */
97 fd = fd_make(floor_savefile, mode);
99 /* Drop permissions */
107 msg_print(_("エラー:古いテンポラリ・ファイルが残っています。", "Error: There are old temporary files."));
108 msg_print(_("変愚蛮怒を二重に起動していないか確認してください。", "Make sure you are not running two game processes simultaneously."));
109 msg_print(_("過去に変愚蛮怒がクラッシュした場合は一時ファイルを", "If the temporary files are garbage from an old crashed process, "));
110 msg_print(_("強制的に削除して実行を続けられます。", "you can delete them safely."));
111 if (!get_check(_("強制的に削除してもよろしいですか?", "Do you delete the old temporary files? ")))
112 quit(_("実行中止", "Aborted."));
122 /* Grab permissions */
125 /* Simply kill the temporary file */
126 (void)fd_kill(floor_savefile);
128 /* Drop permissions */
131 sf_ptr->floor_id = 0;
134 /* No floor_id used yet (No.0 is reserved to indicate non existance) */
137 /* vist_mark is from 1 */
138 latest_visit_mark = 1;
140 /* A sign to mark temporary files */
141 saved_floor_file_sign = (u32b)time(NULL);
143 /* No next floor yet */
146 /* No change floor mode yet */
147 creature_ptr->change_floor_mode = 0;
151 * @brief 保存フロア用テンポラリファイルを削除する / Kill temporary files
152 * @details Should be called just before the game quit.
153 * @param creature_ptr プレーヤーへの参照ポインタ
156 void clear_saved_floor_files(player_type *creature_ptr)
158 char floor_savefile[1024];
160 for (i = 0; i < MAX_SAVED_FLOORS; i++)
162 saved_floor_type *sf_ptr = &saved_floors[i];
164 /* No temporary file */
165 if (!sf_ptr->floor_id) continue;
166 if (sf_ptr->floor_id == creature_ptr->floor_id) continue;
169 sprintf(floor_savefile, "%s.F%02d", savefile, i);
171 /* Grab permissions */
174 /* Simply kill the temporary file */
175 (void)fd_kill(floor_savefile);
177 /* Drop permissions */
183 * @brief 保存フロアIDから参照ポインタを得る / Get a pointer for an item of the saved_floors array.
184 * @param floor_id 保存フロアID
185 * @return IDに対応する保存フロアのポインタ、ない場合はNULLを返す。
187 saved_floor_type *get_sf_ptr(FLOOR_IDX floor_id)
191 /* floor_id No.0 indicates no floor */
192 if (!floor_id) return NULL;
194 for (i = 0; i < MAX_SAVED_FLOORS; i++)
196 saved_floor_type *sf_ptr = &saved_floors[i];
198 if (sf_ptr->floor_id == floor_id) return sf_ptr;
207 * @brief 参照ポインタ先の保存フロアを抹消する / kill a saved floor and get an empty space
208 * @param creature_ptr プレーヤーへの参照ポインタ
209 * @param sf_ptr 保存フロアの参照ポインタ
212 static void kill_saved_floor(player_type *creature_ptr, saved_floor_type *sf_ptr)
214 char floor_savefile[1024];
218 if (!sf_ptr->floor_id) return;
220 if (sf_ptr->floor_id == creature_ptr->floor_id)
222 /* Kill current floor */
223 creature_ptr->floor_id = 0;
225 /* Current floor doesn't have temporary file */
230 sprintf(floor_savefile, "%s.F%02d", savefile, (int)sf_ptr->savefile_id);
232 /* Grab permissions */
235 /* Simply kill the temporary file */
236 (void)fd_kill(floor_savefile);
238 /* Drop permissions */
242 /* No longer exists */
243 sf_ptr->floor_id = 0;
248 * @brief 新規に利用可能な保存フロアを返す / Initialize new saved floor and get its floor id.
249 * @param creature_ptr プレーヤーへの参照ポインタ
250 * @return 利用可能な保存フロアID
252 * If number of saved floors are already MAX_SAVED_FLOORS, kill the oldest one.
254 FLOOR_IDX get_new_floor_id(player_type *creature_ptr)
256 saved_floor_type *sf_ptr = NULL;
259 /* Look for empty space */
260 for (i = 0; i < MAX_SAVED_FLOORS; i++)
262 sf_ptr = &saved_floors[i];
264 if (!sf_ptr->floor_id) break;
268 if (i == MAX_SAVED_FLOORS)
271 u32b oldest_visit = 0xffffffffL;
273 /* Search for oldest */
274 for (i = 0; i < MAX_SAVED_FLOORS; i++)
276 sf_ptr = &saved_floors[i];
278 /* Don't kill current floor */
279 if (sf_ptr->floor_id == creature_ptr->floor_id) continue;
281 /* Don't kill newer */
282 if (sf_ptr->visit_mark > oldest_visit) continue;
285 oldest_visit = sf_ptr->visit_mark;
288 /* Kill oldest saved floor */
289 sf_ptr = &saved_floors[oldest];
290 kill_saved_floor(creature_ptr, sf_ptr);
296 /* Prepare new floor data */
297 sf_ptr->savefile_id = i;
298 sf_ptr->floor_id = max_floor_id;
299 sf_ptr->last_visit = 0;
300 sf_ptr->upper_floor_id = 0;
301 sf_ptr->lower_floor_id = 0;
302 sf_ptr->visit_mark = latest_visit_mark++;
304 /* sf_ptr->dun_level may be changed later */
305 sf_ptr->dun_level = creature_ptr->current_floor_ptr->dun_level;
308 /* Increment number of floor_id */
309 if (max_floor_id < MAX_SHORT) max_floor_id++;
311 /* 32767 floor_ids are all used up! Re-use ancient IDs */
312 else max_floor_id = 1;
314 return sf_ptr->floor_id;
319 * @brief フロア切り替え時の処理フラグを追加する / Prepare mode flags of changing floor
320 * @param creature_ptr プレーヤーへの参照ポインタ
321 * @param mode 追加したい所持フラグ
324 void prepare_change_floor_mode(player_type *creature_ptr, BIT_FLAGS mode)
326 creature_ptr->change_floor_mode |= mode;
330 * @brief 階段移動先のフロアが生成できない時に簡単な行き止まりマップを作成する / Builds the dead end
333 static void build_dead_end(player_type *creature_ptr)
337 clear_cave(creature_ptr);
339 /* Mega-Hack -- no player yet */
340 creature_ptr->x = creature_ptr->y = 0;
342 /* Fill the arrays of floors and walls in the good proportions */
343 set_floor_and_wall(0);
346 creature_ptr->current_floor_ptr->height = SCREEN_HGT;
347 creature_ptr->current_floor_ptr->width = SCREEN_WID;
349 /* Filled with permanent walls */
350 for (y = 0; y < MAX_HGT; y++)
352 for (x = 0; x < MAX_WID; x++)
354 /* Create "solid" perma-wall */
355 place_bold(creature_ptr, y, x, GB_SOLID_PERM);
359 /* Place at center of the floor */
360 creature_ptr->y = creature_ptr->current_floor_ptr->height / 2;
361 creature_ptr->x = creature_ptr->current_floor_ptr->width / 2;
363 /* Give one square */
364 place_bold(creature_ptr, creature_ptr->y, creature_ptr->x, GB_FLOOR);
366 wipe_generate_random_floor_flags(creature_ptr->current_floor_ptr);
371 * @brief フロア移動時のペット保存処理 / Preserve_pets
372 * @param master_ptr プレーヤーへの参照ポインタ
375 static void preserve_pet(player_type *master_ptr)
380 for (num = 0; num < MAX_PARTY_MON; num++)
382 party_mon[num].r_idx = 0;
385 if (master_ptr->riding)
387 monster_type *m_ptr = &master_ptr->current_floor_ptr->m_list[master_ptr->riding];
389 /* Pet of other pet don't follow. */
390 if (m_ptr->parent_m_idx)
392 master_ptr->riding = 0;
393 master_ptr->pet_extra_flags &= ~(PF_TWO_HANDS);
394 master_ptr->riding_ryoute = master_ptr->old_riding_ryoute = FALSE;
398 /* Preserve the mount */
399 (void)COPY(&party_mon[0], m_ptr, monster_type);
401 /* Delete from this floor */
402 delete_monster_idx(master_ptr, master_ptr->riding);
407 * If player is in wild mode, no pets are preserved
408 * except a monster whom player riding
410 if (!master_ptr->wild_mode && !master_ptr->current_floor_ptr->inside_arena && !master_ptr->phase_out)
412 for (i = master_ptr->current_floor_ptr->m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
414 monster_type *m_ptr = &master_ptr->current_floor_ptr->m_list[i];
416 if (!monster_is_valid(m_ptr)) continue;
417 if (!is_pet(m_ptr)) continue;
418 if (i == master_ptr->riding) continue;
420 if (reinit_wilderness)
422 /* Don't lose sight of pets when getting a Quest */
426 POSITION dis = distance(master_ptr->y, master_ptr->x, m_ptr->fy, m_ptr->fx);
428 /* Confused (etc.) monsters don't follow. */
429 if (monster_confused_remaining(m_ptr) || monster_stunned_remaining(m_ptr) || monster_csleep_remaining(m_ptr)) continue;
431 /* Pet of other pet don't follow. */
432 if (m_ptr->parent_m_idx) continue;
435 * Pets with nickname will follow even from 3 blocks away
436 * when you or the pet can see the other.
438 if (m_ptr->nickname &&
439 ((player_has_los_bold(master_ptr, m_ptr->fy, m_ptr->fx) && projectable(master_ptr, master_ptr->y, master_ptr->x, m_ptr->fy, m_ptr->fx)) ||
440 (los(master_ptr, m_ptr->fy, m_ptr->fx, master_ptr->y, master_ptr->x) && projectable(master_ptr, m_ptr->fy, m_ptr->fx, master_ptr->y, master_ptr->x))))
442 if (dis > 3) continue;
446 if (dis > 1) continue;
450 (void)COPY(&party_mon[num], &master_ptr->current_floor_ptr->m_list[i], monster_type);
454 /* Delete from this floor */
455 delete_monster_idx(master_ptr, i);
459 if (record_named_pet)
461 for (i = master_ptr->current_floor_ptr->m_max - 1; i >=1; i--)
463 monster_type *m_ptr = &master_ptr->current_floor_ptr->m_list[i];
464 GAME_TEXT m_name[MAX_NLEN];
466 if (!monster_is_valid(m_ptr)) continue;
467 if (!is_pet(m_ptr)) continue;
468 if (!m_ptr->nickname) continue;
469 if (master_ptr->riding == i) continue;
471 monster_desc(master_ptr, m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
472 exe_write_diary(master_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_MOVED, m_name);
477 /* Pet of other pet may disappear. */
478 for (i = master_ptr->current_floor_ptr->m_max - 1; i >=1; i--)
480 monster_type *m_ptr = &master_ptr->current_floor_ptr->m_list[i];
482 /* Are there its parent? */
483 if (m_ptr->parent_m_idx && !master_ptr->current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx)
485 /* Its parent have gone, it also goes away. */
489 GAME_TEXT m_name[MAX_NLEN];
490 monster_desc(master_ptr, m_name, m_ptr, 0);
491 msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
494 delete_monster_idx(master_ptr, i);
501 * @brief フロア移動時にペットを伴った場合の準備処理 / Pre-calculate the racial counters of preserved pets
502 * @param master_ptr プレーヤーへの参照ポインタ
505 * To prevent multiple generation of unique monster who is the minion of player
507 void precalc_cur_num_of_pet(player_type *player_ptr)
511 int max_num = player_ptr->wild_mode ? 1 : MAX_PARTY_MON;
513 for (i = 0; i < max_num; i++)
515 m_ptr = &party_mon[i];
517 /* Skip empty monsters */
518 if (!monster_is_valid(m_ptr)) continue;
520 /* Hack -- Increase the racial counter */
521 real_r_ptr(m_ptr)->cur_num++;
526 * @brief 移動先のフロアに伴ったペットを配置する / Place preserved pet monsters on new floor
527 * @param master_ptr プレーヤーへの参照ポインタ
530 static void place_pet(player_type *master_ptr)
533 int max_num = master_ptr->wild_mode ? 1 : MAX_PARTY_MON;
535 for (i = 0; i < max_num; i++)
537 POSITION cy = 0, cx = 0;
540 if (!(party_mon[i].r_idx)) continue;
544 m_idx = m_pop(master_ptr);
545 master_ptr->riding = m_idx;
557 for (d = 1; d < A_MAX; d++)
559 for (j = 1000; j > 0; j--)
561 scatter(master_ptr, &cy, &cx, master_ptr->y, master_ptr->x, d, 0);
562 if (monster_can_enter(master_ptr, cy, cx, &r_info[party_mon[i].r_idx], 0)) break;
566 m_idx = (d == 6) ? 0 : m_pop(master_ptr);
571 monster_type *m_ptr = &master_ptr->current_floor_ptr->m_list[m_idx];
574 master_ptr->current_floor_ptr->grid_array[cy][cx].m_idx = m_idx;
576 m_ptr->r_idx = party_mon[i].r_idx;
578 /* Copy all member of the structure */
579 *m_ptr = party_mon[i];
580 r_ptr = real_r_ptr(m_ptr);
584 m_ptr->current_floor_ptr = master_ptr->current_floor_ptr;
586 m_ptr->mtimed[MTIMED_CSLEEP] = 0;
587 m_ptr->hold_o_idx = 0;
590 if ((r_ptr->flags1 & RF1_FORCE_SLEEP) && !ironman_nightmare)
592 /* Monster is still being nice */
593 m_ptr->mflag |= (MFLAG_NICE);
595 /* Must repair monsters */
596 repair_monsters = TRUE;
598 update_monster(master_ptr, m_idx, TRUE);
599 lite_spot(master_ptr, cy, cx);
601 /* Pre-calculated in precalc_cur_num_of_pet() */
602 /* r_ptr->cur_num++; */
604 /* Hack -- Count the number of "reproducers" */
605 if (r_ptr->flags2 & RF2_MULTIPLY) master_ptr->current_floor_ptr->num_repro++;
610 monster_type *m_ptr = &party_mon[i];
611 monster_race *r_ptr = real_r_ptr(m_ptr);
612 GAME_TEXT m_name[MAX_NLEN];
614 monster_desc(master_ptr, m_name, m_ptr, 0);
615 msg_format(_("%sとはぐれてしまった。", "You have lost sight of %s."), m_name);
616 if (record_named_pet && m_ptr->nickname)
618 monster_desc(master_ptr, m_name, m_ptr, MD_INDEF_VISIBLE);
619 exe_write_diary(master_ptr, DIARY_NAMED_PET, RECORD_NAMED_PET_LOST_SIGHT, m_name);
622 /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
623 if (r_ptr->cur_num) r_ptr->cur_num--;
627 /* For accuracy of precalc_cur_num_of_pet() */
628 (void)C_WIPE(party_mon, MAX_PARTY_MON, monster_type);
633 * @brief ユニークモンスターやアーティファクトの所在フロアを更新する / Hack -- Update location of unique monsters and artifacts
634 * @param cur_floor_id 現在のフロアID
637 * The r_ptr->floor_id and a_ptr->floor_id are not updated correctly\n
638 * while new floor creation since dungeons may be re-created by\n
639 * auto-scum option.\n
641 static void update_unique_artifact(floor_type *floor_ptr, s16b cur_floor_id)
645 /* Maintain unique monsters */
646 for (i = 1; i < floor_ptr->m_max; i++)
649 monster_type *m_ptr = &floor_ptr->m_list[i];
651 if (!monster_is_valid(m_ptr)) continue;
653 /* Extract real monster race */
654 r_ptr = real_r_ptr(m_ptr);
656 /* Memorize location of the unique monster */
657 if ((r_ptr->flags1 & RF1_UNIQUE) ||
658 (r_ptr->flags7 & RF7_NAZGUL))
660 r_ptr->floor_id = cur_floor_id;
664 /* Maintain artifatcs */
665 for (i = 1; i < floor_ptr->o_max; i++)
667 object_type *o_ptr = &floor_ptr->o_list[i];
669 if (!OBJECT_IS_VALID(o_ptr)) continue;
671 /* Memorize location of the artifact */
672 if (object_is_fixed_artifact(o_ptr))
674 a_info[o_ptr->name1].floor_id = cur_floor_id;
681 * @brief フロア移動時、プレイヤーの移動先モンスターが既にいた場合ランダムな近隣に移動させる / When a monster is at a place where player will return,
684 static void get_out_monster(player_type *protected_ptr)
688 POSITION oy = protected_ptr->y;
689 POSITION ox = protected_ptr->x;
690 floor_type *floor_ptr = protected_ptr->current_floor_ptr;
691 MONSTER_IDX m_idx = floor_ptr->grid_array[oy][ox].m_idx;
693 /* Nothing to do if no monster */
696 /* Look until done */
701 /* Pick a (possibly illegal) location */
702 POSITION ny = rand_spread(oy, dis);
703 POSITION nx = rand_spread(ox, dis);
707 /* Stop after 1000 tries */
708 if (tries > 10000) return;
711 * Increase distance after doing enough tries
712 * compared to area of possible space
714 if (tries > 20 * dis * dis) dis++;
716 /* Ignore illegal locations */
717 if (!in_bounds(floor_ptr, ny, nx)) continue;
719 /* Require "empty" floor space */
720 if (!is_cave_empty_bold(protected_ptr, ny, nx)) continue;
722 /* Hack -- no teleport onto glyph of warding */
723 if (is_glyph_grid(&floor_ptr->grid_array[ny][nx])) continue;
724 if (is_explosive_rune_grid(&floor_ptr->grid_array[ny][nx])) continue;
726 /* ...nor onto the Pattern */
727 if (pattern_tile(floor_ptr, ny, nx)) continue;
729 /*** It's a good place ***/
731 m_ptr = &floor_ptr->m_list[m_idx];
733 /* Update the old location */
734 floor_ptr->grid_array[oy][ox].m_idx = 0;
736 /* Update the new location */
737 floor_ptr->grid_array[ny][nx].m_idx = m_idx;
739 /* Move the monster */
743 /* No need to do update_monster() */
751 * @brief 新フロアに移動元フロアに繋がる階段を配置する / Virtually teleport onto the stairs that is connecting between two floors.
752 * @param sf_ptr 移動元の保存フロア構造体参照ポインタ
755 static void locate_connected_stairs(player_type *creature_ptr, floor_type *floor_ptr, saved_floor_type *sf_ptr, BIT_FLAGS floor_mode)
757 POSITION x, y, sx = 0, sy = 0;
758 POSITION x_table[20];
759 POSITION y_table[20];
763 /* Search usable stairs */
764 for (y = 0; y < floor_ptr->height; y++)
766 for (x = 0; x < floor_ptr->width; x++)
768 grid_type *g_ptr = &floor_ptr->grid_array[y][x];
769 feature_type *f_ptr = &f_info[g_ptr->feat];
772 if (floor_mode & CFM_UP)
774 if (have_flag(f_ptr->flags, FF_LESS) && have_flag(f_ptr->flags, FF_STAIRS) &&
775 !have_flag(f_ptr->flags, FF_SPECIAL))
779 /* Found fixed stairs? */
780 if (g_ptr->special &&
781 g_ptr->special == sf_ptr->upper_floor_id)
789 else if (floor_mode & CFM_DOWN)
791 if (have_flag(f_ptr->flags, FF_MORE) && have_flag(f_ptr->flags, FF_STAIRS) &&
792 !have_flag(f_ptr->flags, FF_SPECIAL))
796 /* Found fixed stairs */
797 if (g_ptr->special &&
798 g_ptr->special == sf_ptr->lower_floor_id)
808 if (have_flag(f_ptr->flags, FF_BLDG))
814 if (ok && (num < 20))
826 creature_ptr->y = sy;
827 creature_ptr->x = sx;
831 /* No stairs found! -- No return */
832 prepare_change_floor_mode(creature_ptr, CFM_RAND_PLACE | CFM_NO_RETURN);
834 /* Mega Hack -- It's not the stairs you enter. Disable it. */
835 if (!feat_uses_special(floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].feat)) floor_ptr->grid_array[creature_ptr->y][creature_ptr->x].special = 0;
839 /* Choose random one */
842 /* Point stair location */
843 creature_ptr->y = y_table[i];
844 creature_ptr->x = x_table[i];
849 * @brief 現在のフロアを離れるに伴って行なわれる保存処理
850 * / Maintain quest monsters, mark next floor_id at stairs, save current floor, and prepare to enter next floor.
851 * @param creature_ptr プレーヤーへの参照ポインタ
854 void leave_floor(player_type *creature_ptr)
856 grid_type *g_ptr = NULL;
858 saved_floor_type *sf_ptr;
859 MONRACE_IDX quest_r_idx = 0;
861 FLOOR_IDX tmp_floor_idx = 0;
863 /* Preserve pets and prepare to take these to next floor */
864 preserve_pet(creature_ptr);
866 /* Remove all mirrors without explosion */
867 remove_all_mirrors(creature_ptr, FALSE);
869 if (creature_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(creature_ptr, FALSE);
871 /* New floor is not yet prepared */
874 /* Temporarily get a floor_id (for Arena) */
875 if (!creature_ptr->floor_id &&
876 (creature_ptr->change_floor_mode & CFM_SAVE_FLOORS) &&
877 !(creature_ptr->change_floor_mode & CFM_NO_RETURN))
879 /* Get temporary floor_id */
880 tmp_floor_idx = get_new_floor_id(creature_ptr);
883 /* Search the quest monster index */
884 for (i = 0; i < max_q_idx; i++)
886 if ((quest[i].status == QUEST_STATUS_TAKEN) &&
887 ((quest[i].type == QUEST_TYPE_KILL_LEVEL) ||
888 (quest[i].type == QUEST_TYPE_RANDOM)) &&
889 (quest[i].level == creature_ptr->current_floor_ptr->dun_level) &&
890 (creature_ptr->dungeon_idx == quest[i].dungeon) &&
891 !(quest[i].flags & QUEST_FLAG_PRESET))
893 quest_r_idx = quest[i].r_idx;
897 /* Maintain quest monsters */
898 for (i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
901 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
903 if (!monster_is_valid(m_ptr)) continue;
905 /* Only maintain quest monsters */
906 if (quest_r_idx != m_ptr->r_idx) continue;
908 /* Extract real monster race */
909 r_ptr = real_r_ptr(m_ptr);
911 /* Ignore unique monsters */
912 if ((r_ptr->flags1 & RF1_UNIQUE) ||
913 (r_ptr->flags7 & RF7_NAZGUL)) continue;
915 /* Delete non-unique quest monsters */
916 delete_monster_idx(creature_ptr, i);
919 /* Check if there is a same item */
920 for (i = 0; i < INVEN_PACK; i++)
922 object_type *o_ptr = &creature_ptr->inventory_list[i];
924 if (!OBJECT_IS_VALID(o_ptr)) continue;
926 /* Delete old memorized location of the artifact */
927 if (object_is_fixed_artifact(o_ptr))
929 a_info[o_ptr->name1].floor_id = 0;
933 /* Extract current floor info or NULL */
934 sf_ptr = get_sf_ptr(creature_ptr->floor_id);
936 /* Choose random stairs */
937 if ((creature_ptr->change_floor_mode & CFM_RAND_CONNECT) && tmp_floor_idx)
939 locate_connected_stairs(creature_ptr, creature_ptr->current_floor_ptr, sf_ptr, creature_ptr->change_floor_mode);
942 /* Extract new dungeon level */
943 if (creature_ptr->change_floor_mode & CFM_SAVE_FLOORS)
945 /* Extract stair position */
946 g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
947 f_ptr = &f_info[g_ptr->feat];
949 /* Get back to old saved floor? */
950 if (g_ptr->special && !have_flag(f_ptr->flags, FF_SPECIAL) && get_sf_ptr(g_ptr->special))
952 /* Saved floor is exist. Use it. */
953 new_floor_id = g_ptr->special;
956 /* Mark shaft up/down */
957 if (have_flag(f_ptr->flags, FF_STAIRS) && have_flag(f_ptr->flags, FF_SHAFT))
959 prepare_change_floor_mode(creature_ptr, CFM_SHAFT);
963 /* Climb up/down some sort of stairs */
964 if (creature_ptr->change_floor_mode & (CFM_DOWN | CFM_UP))
968 /* Extract level movement number */
969 if (creature_ptr->change_floor_mode & CFM_DOWN) move_num = 1;
970 else if (creature_ptr->change_floor_mode & CFM_UP) move_num = -1;
972 /* Shafts are deeper than normal stairs */
973 if (creature_ptr->change_floor_mode & CFM_SHAFT)
974 move_num += SGN(move_num);
976 /* Get out from or Enter the dungeon */
977 if (creature_ptr->change_floor_mode & CFM_DOWN)
979 if (!creature_ptr->current_floor_ptr->dun_level)
980 move_num = d_info[creature_ptr->dungeon_idx].mindepth;
982 else if (creature_ptr->change_floor_mode & CFM_UP)
984 if (creature_ptr->current_floor_ptr->dun_level + move_num < d_info[creature_ptr->dungeon_idx].mindepth)
985 move_num = -creature_ptr->current_floor_ptr->dun_level;
988 creature_ptr->current_floor_ptr->dun_level += move_num;
991 /* Leaving the dungeon to town */
992 if (!creature_ptr->current_floor_ptr->dun_level && creature_ptr->dungeon_idx)
994 creature_ptr->leaving_dungeon = TRUE;
995 if (!vanilla_town && !lite_town)
997 creature_ptr->wilderness_y = d_info[creature_ptr->dungeon_idx].dy;
998 creature_ptr->wilderness_x = d_info[creature_ptr->dungeon_idx].dx;
1000 creature_ptr->recall_dungeon = creature_ptr->dungeon_idx;
1001 creature_ptr->dungeon_idx = 0;
1003 /* Reach to the surface -- Clear all saved floors */
1004 creature_ptr->change_floor_mode &= ~CFM_SAVE_FLOORS; // TODO
1007 /* Kill some old saved floors */
1008 if (!(creature_ptr->change_floor_mode & CFM_SAVE_FLOORS))
1010 /* Kill all saved floors */
1011 for (i = 0; i < MAX_SAVED_FLOORS; i++)
1012 kill_saved_floor(creature_ptr, &saved_floors[i]);
1014 /* Reset visit_mark count */
1015 latest_visit_mark = 1;
1017 else if (creature_ptr->change_floor_mode & CFM_NO_RETURN)
1019 /* Kill current floor */
1020 kill_saved_floor(creature_ptr, sf_ptr);
1023 /* No current floor -- Left/Enter dungeon etc... */
1024 if (!creature_ptr->floor_id)
1026 /* No longer need to save current floor */
1030 /* Mark next floor_id on the previous floor */
1034 new_floor_id = get_new_floor_id(creature_ptr);
1036 /* Connect from here */
1037 if (g_ptr && !feat_uses_special(g_ptr->feat))
1039 g_ptr->special = new_floor_id;
1043 /* Fix connection -- level teleportation or trap door */
1044 if (creature_ptr->change_floor_mode & CFM_RAND_CONNECT)
1046 if (creature_ptr->change_floor_mode & CFM_UP)
1047 sf_ptr->upper_floor_id = new_floor_id;
1048 else if (creature_ptr->change_floor_mode & CFM_DOWN)
1049 sf_ptr->lower_floor_id = new_floor_id;
1052 /* If you can return, you need to save previous floor */
1053 if ((creature_ptr->change_floor_mode & CFM_SAVE_FLOORS) &&
1054 !(creature_ptr->change_floor_mode & CFM_NO_RETURN))
1056 /* Get out of the my way! */
1057 get_out_monster(creature_ptr);
1059 /* Record the last visit turn of current floor */
1060 sf_ptr->last_visit = current_world_ptr->game_turn;
1062 forget_lite(creature_ptr->current_floor_ptr);
1063 forget_view(creature_ptr->current_floor_ptr);
1064 clear_mon_lite(creature_ptr->current_floor_ptr);
1066 /* Save current floor */
1067 if (!save_floor(creature_ptr, sf_ptr, 0))
1069 /* Save failed -- No return */
1070 prepare_change_floor_mode(creature_ptr, CFM_NO_RETURN);
1072 /* Kill current floor */
1073 kill_saved_floor(creature_ptr, get_sf_ptr(creature_ptr->floor_id));
1080 * @brief フロアの切り替え処理 / Enter new floor.
1081 * @param creature_ptr プレーヤーへの参照ポインタ
1084 * If the floor is an old saved floor, it will be\n
1085 * restored from the temporary file. If the floor is new one, new floor\n
1086 * will be generated.\n
1088 void change_floor(player_type *creature_ptr)
1090 saved_floor_type *sf_ptr;
1091 bool loaded = FALSE;
1093 /* The dungeon is not ready */
1094 current_world_ptr->character_dungeon = FALSE;
1096 /* No longer in the trap detecteded region */
1097 creature_ptr->dtrap = FALSE;
1099 /* Mega-Hack -- no panel yet */
1105 /* Mega-Hack -- not ambushed on the wildness? */
1106 creature_ptr->ambush_flag = FALSE;
1108 /* No saved floors (On the surface etc.) */
1109 if (!(creature_ptr->change_floor_mode & CFM_SAVE_FLOORS) &&
1110 !(creature_ptr->change_floor_mode & CFM_FIRST_FLOOR))
1112 generate_floor(creature_ptr);
1114 /* Paranoia -- No new saved floor */
1118 /* In the dungeon */
1121 /* No floor_id yet */
1125 new_floor_id = get_new_floor_id(creature_ptr);
1128 /* Pointer for infomations of new floor */
1129 sf_ptr = get_sf_ptr(new_floor_id);
1131 /* Try to restore old floor */
1132 if (sf_ptr->last_visit)
1134 /* Old saved floor is exist */
1135 if (load_floor(creature_ptr, sf_ptr, 0))
1139 /* Forbid return stairs */
1140 if (creature_ptr->change_floor_mode & CFM_NO_RETURN)
1142 grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
1144 if (!feat_uses_special(g_ptr->feat))
1146 if (creature_ptr->change_floor_mode & (CFM_DOWN | CFM_UP))
1148 /* Reset to floor */
1149 g_ptr->feat = feat_ground_type[randint0(100)];
1159 * Set lower/upper_floor_id of new floor when the new
1160 * floor is right-above/right-under the current floor.
1162 * Stair creation/Teleport level/Trap door will take
1163 * you the same floor when you used it later again.
1165 if (creature_ptr->floor_id)
1167 saved_floor_type *cur_sf_ptr = get_sf_ptr(creature_ptr->floor_id);
1169 if (creature_ptr->change_floor_mode & CFM_UP)
1171 /* New floor is right-above */
1172 if (cur_sf_ptr->upper_floor_id == new_floor_id)
1173 sf_ptr->lower_floor_id = creature_ptr->floor_id;
1175 else if (creature_ptr->change_floor_mode & CFM_DOWN)
1177 /* New floor is right-under */
1178 if (cur_sf_ptr->lower_floor_id == new_floor_id)
1179 sf_ptr->upper_floor_id = creature_ptr->floor_id;
1183 /* Break connection to killed floor */
1186 if (creature_ptr->change_floor_mode & CFM_UP)
1187 sf_ptr->lower_floor_id = 0;
1188 else if (creature_ptr->change_floor_mode & CFM_DOWN)
1189 sf_ptr->upper_floor_id = 0;
1192 /* Maintain monsters and artifacts */
1196 GAME_TURN tmp_last_visit = sf_ptr->last_visit;
1197 GAME_TURN absence_ticks;
1198 int alloc_chance = d_info[creature_ptr->dungeon_idx].max_m_alloc_chance;
1199 GAME_TURN alloc_times;
1201 while (tmp_last_visit > current_world_ptr->game_turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
1202 absence_ticks = (current_world_ptr->game_turn - tmp_last_visit) / TURNS_PER_TICK;
1204 /* Maintain monsters */
1205 for (i = 1; i < creature_ptr->current_floor_ptr->m_max; i++)
1207 monster_race *r_ptr;
1208 monster_type *m_ptr = &creature_ptr->current_floor_ptr->m_list[i];
1210 if (!monster_is_valid(m_ptr)) continue;
1215 m_ptr->hp = m_ptr->maxhp = m_ptr->max_maxhp;
1217 /* Remove timed status (except MTIMED_CSLEEP) */
1218 (void)set_monster_fast(creature_ptr, i, 0);
1219 (void)set_monster_slow(creature_ptr, i, 0);
1220 (void)set_monster_stunned(creature_ptr, i, 0);
1221 (void)set_monster_confused(creature_ptr, i, 0);
1222 (void)set_monster_monfear(creature_ptr, i, 0);
1223 (void)set_monster_invulner(creature_ptr, i, 0, FALSE);
1226 /* Extract real monster race */
1227 r_ptr = real_r_ptr(m_ptr);
1229 /* Ignore non-unique */
1230 if (!(r_ptr->flags1 & RF1_UNIQUE) &&
1231 !(r_ptr->flags7 & RF7_NAZGUL)) continue;
1233 /* Appear at a different floor? */
1234 if (r_ptr->floor_id != new_floor_id)
1236 /* Disapper from here */
1237 delete_monster_idx(creature_ptr, i);
1241 /* Maintain artifatcs */
1242 for (i = 1; i < creature_ptr->current_floor_ptr->o_max; i++)
1244 object_type *o_ptr = &creature_ptr->current_floor_ptr->o_list[i];
1246 if (!OBJECT_IS_VALID(o_ptr)) continue;
1248 /* Ignore non-artifact */
1249 if (!object_is_fixed_artifact(o_ptr)) continue;
1251 /* Appear at a different floor? */
1252 if (a_info[o_ptr->name1].floor_id != new_floor_id)
1254 /* Disappear from here */
1255 delete_object_idx(creature_ptr, i);
1259 /* Cancel preserve */
1260 a_info[o_ptr->name1].cur_num = 1;
1264 (void)place_quest_monsters(creature_ptr);
1266 /* Place some random monsters */
1267 alloc_times = absence_ticks / alloc_chance;
1269 if (randint0(alloc_chance) < (absence_ticks % alloc_chance))
1272 for (i = 0; i < alloc_times; i++)
1274 /* Make a (group of) new monster */
1275 (void)alloc_monster(creature_ptr, 0, 0);
1280 /* New floor_id or failed to restore */
1281 else /* if (!loaded) */
1283 if (sf_ptr->last_visit)
1285 /* Temporary file is broken? */
1286 msg_print(_("階段は行き止まりだった。", "The staircases come to a dead end..."));
1288 /* Create simple dead end */
1289 build_dead_end(creature_ptr);
1291 /* Break connection */
1292 if (creature_ptr->change_floor_mode & CFM_UP)
1294 sf_ptr->upper_floor_id = 0;
1296 else if (creature_ptr->change_floor_mode & CFM_DOWN)
1298 sf_ptr->lower_floor_id = 0;
1303 generate_floor(creature_ptr);
1306 /* Record last visit turn */
1307 sf_ptr->last_visit = current_world_ptr->game_turn;
1309 /* Set correct dun_level value */
1310 sf_ptr->dun_level = creature_ptr->current_floor_ptr->dun_level;
1312 /* Create connected stairs */
1313 if (!(creature_ptr->change_floor_mode & CFM_NO_RETURN))
1315 /* Extract stair position */
1316 grid_type *g_ptr = &creature_ptr->current_floor_ptr->grid_array[creature_ptr->y][creature_ptr->x];
1318 /*** Create connected stairs ***/
1320 /* No stairs down from Quest */
1321 if ((creature_ptr->change_floor_mode & CFM_UP) && !quest_number(creature_ptr, creature_ptr->current_floor_ptr->dun_level))
1323 g_ptr->feat = (creature_ptr->change_floor_mode & CFM_SHAFT) ? feat_state(creature_ptr, feat_down_stair, FF_SHAFT) : feat_down_stair;
1326 /* No stairs up when ironman_downward */
1327 else if ((creature_ptr->change_floor_mode & CFM_DOWN) && !ironman_downward)
1329 g_ptr->feat = (creature_ptr->change_floor_mode & CFM_SHAFT) ? feat_state(creature_ptr, feat_up_stair, FF_SHAFT) : feat_up_stair;
1332 /* Paranoia -- Clear mimic */
1335 /* Connect to previous floor */
1336 g_ptr->special = creature_ptr->floor_id;
1340 /* Arrive at random grid */
1341 if (creature_ptr->change_floor_mode & (CFM_RAND_PLACE))
1343 (void)new_player_spot(creature_ptr);
1346 /* You see stairs blocked */
1347 else if ((creature_ptr->change_floor_mode & CFM_NO_RETURN) && (creature_ptr->change_floor_mode & (CFM_DOWN | CFM_UP)))
1349 if (!creature_ptr->blind)
1351 msg_print(_("突然階段が塞がれてしまった。", "Suddenly the stairs is blocked!"));
1355 msg_print(_("ゴトゴトと何か音がした。", "You hear some noises."));
1362 * The "turn" is not always different number because
1363 * the level teleport doesn't take any turn. Use
1364 * visit mark instead of last visit turn to find the
1365 * oldest saved floor.
1367 sf_ptr->visit_mark = latest_visit_mark++;
1370 /* Place preserved pet monsters */
1371 place_pet(creature_ptr);
1373 /* Reset travel target place */
1374 forget_travel_flow(creature_ptr->current_floor_ptr);
1376 /* Hack -- maintain unique and artifacts */
1377 update_unique_artifact(creature_ptr->current_floor_ptr, new_floor_id);
1379 /* Now the player is in new floor */
1380 creature_ptr->floor_id = new_floor_id;
1382 /* The dungeon is ready */
1383 current_world_ptr->character_dungeon = TRUE;
1385 /* Hack -- Munchkin characters always get whole map */
1386 if (creature_ptr->pseikaku == PERSONALITY_MUNCHKIN)
1387 wiz_lite(creature_ptr, (bool)(creature_ptr->pclass == CLASS_NINJA));
1389 /* Remember when this level was "created" */
1390 creature_ptr->current_floor_ptr->generated_turn = current_world_ptr->game_turn;
1392 /* No dungeon feeling yet */
1393 creature_ptr->feeling_turn = creature_ptr->current_floor_ptr->generated_turn;
1394 creature_ptr->feeling = 0;
1396 /* Clear all flags */
1397 creature_ptr->change_floor_mode = 0L;
1399 select_floor_music(creature_ptr);
1400 creature_ptr->change_floor_mode = 0;