OSDN Git Service

[Refactor] #38997 select_floor_music() に player_type * 引数を追加. / Add player_type ...
[hengband/hengband.git] / src / floor-save.c
index 4e65769..a439fed 100644 (file)
@@ -44,7 +44,6 @@
 
 
 static FLOOR_IDX new_floor_id;  /*!<次のフロアのID / floor_id of the destination */
-BIT_FLAGS change_floor_mode;  /*!<フロア移行処理に関するフラグ / Mode flags for changing floor */
 static u32b latest_visit_mark;  /*!<フロアを渡った回数?(確認中) / Max number of visit_mark */
 
 /*
@@ -139,7 +138,7 @@ void init_saved_floors(bool force)
        new_floor_id = 0;
 
        /* No change floor mode yet */
-       change_floor_mode = 0;
+       p_ptr->change_floor_mode = 0;
 
 #ifdef SET_UID
 # ifdef SECURE
@@ -336,26 +335,25 @@ FLOOR_IDX get_new_floor_id(void)
  */
 void prepare_change_floor_mode(BIT_FLAGS mode)
 {
-       change_floor_mode |= mode;
+       p_ptr->change_floor_mode |= mode;
 }
 
 /*!
  * @brief 階段移動先のフロアが生成できない時に簡単な行き止まりマップを作成する / Builds the dead end
  * @return なし
  */
-static void build_dead_end(void)
+static void build_dead_end(floor_type *floor_ptr)
 {
        POSITION x, y;
 
-       /* Clear and empty the current_floor_ptr->grid_array */
-       clear_cave();
+       clear_cave(floor_ptr);
 
        /* Fill the arrays of floors and walls in the good proportions */
        set_floor_and_wall(0);
 
        /* Smallest area */
-       current_floor_ptr->height = SCREEN_HGT;
-       current_floor_ptr->width = SCREEN_WID;
+       floor_ptr->height = SCREEN_HGT;
+       floor_ptr->width = SCREEN_WID;
 
        /* Filled with permanent walls */
        for (y = 0; y < MAX_HGT; y++)
@@ -368,13 +366,13 @@ static void build_dead_end(void)
        }
 
        /* Place at center of the floor */
-       p_ptr->y = current_floor_ptr->height / 2;
-       p_ptr->x = current_floor_ptr->width / 2;
+       p_ptr->y = floor_ptr->height / 2;
+       p_ptr->x = floor_ptr->width / 2;
 
        /* Give one square */
        place_floor_bold(p_ptr->y, p_ptr->x);
 
-       wipe_generate_random_floor_flags();
+       wipe_generate_random_floor_flags(floor_ptr);
 }
 
 
@@ -421,7 +419,7 @@ static void preserve_pet(void)
         * If player is in wild mode, no pets are preserved
         * except a monster whom player riding
         */
-       if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->inside_battle)
+       if (!p_ptr->wild_mode && !p_ptr->inside_arena && !p_ptr->phase_out)
        {
                for (i = current_floor_ptr->m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
                {
@@ -483,7 +481,7 @@ static void preserve_pet(void)
                        if (p_ptr->riding == i) continue;
 
                        monster_desc(m_name, m_ptr, MD_ASSUME_VISIBLE | MD_INDEF_VISIBLE);
-                       do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_MOVED, m_name);
+                       exe_write_diary(p_ptr, NIKKI_NAMED_PET, RECORD_NAMED_PET_MOVED, m_name);
                }
        }
 
@@ -539,10 +537,10 @@ void precalc_cur_num_of_pet(void)
  * @brief 移動先のフロアに伴ったペットを配置する / Place preserved pet monsters on new floor
  * @return なし
  */
-static void place_pet(void)
+static void place_pet(player_type *master_ptr)
 {
        int i;
-       int max_num = p_ptr->wild_mode ? 1 : MAX_PARTY_MON;
+       int max_num = master_ptr->wild_mode ? 1 : MAX_PARTY_MON;
 
        for (i = 0; i < max_num; i++)
        {
@@ -554,11 +552,11 @@ static void place_pet(void)
                if (i == 0)
                {
                        m_idx = m_pop();
-                       p_ptr->riding = m_idx;
+                       master_ptr->riding = m_idx;
                        if (m_idx)
                        {
-                               cy = p_ptr->y;
-                               cx = p_ptr->x;
+                               cy = master_ptr->y;
+                               cx = master_ptr->x;
                        }
                }
                else
@@ -570,7 +568,7 @@ static void place_pet(void)
                        {
                                for (j = 1000; j > 0; j--)
                                {
-                                       scatter(&cy, &cx, p_ptr->y, p_ptr->x, d, 0);
+                                       scatter(&cy, &cx, master_ptr->y, master_ptr->x, d, 0);
                                        if (monster_can_enter(cy, cx, &r_info[party_mon[i].r_idx], 0)) break;
                                }
                                if (j) break;
@@ -627,7 +625,7 @@ static void place_pet(void)
                        if (record_named_pet && m_ptr->nickname)
                        {
                                monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
-                               do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOST_SIGHT, m_name);
+                               exe_write_diary(master_ptr, NIKKI_NAMED_PET, RECORD_NAMED_PET_LOST_SIGHT, m_name);
                        }
 
                        /* Pre-calculated in precalc_cur_num_of_pet(), but need to decrease */
@@ -762,7 +760,7 @@ static void get_out_monster(void)
  * @param sf_ptr 移動元の保存フロア構造体参照ポインタ
  * @return なし
  */
-static void locate_connected_stairs(saved_floor_type *sf_ptr, BIT_FLAGS prev_floor_mode)
+static void locate_connected_stairs(saved_floor_type *sf_ptr, BIT_FLAGS floor_mode)
 {
        POSITION x, y, sx = 0, sy = 0;
        POSITION x_table[20];
@@ -779,7 +777,7 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr, BIT_FLAGS prev_flo
                        feature_type *f_ptr = &f_info[g_ptr->feat];
                        bool ok = FALSE;
 
-                       if (prev_floor_mode & CFM_UP)
+                       if (floor_mode & CFM_UP)
                        {
                                if (have_flag(f_ptr->flags, FF_LESS) && have_flag(f_ptr->flags, FF_STAIRS) &&
                                    !have_flag(f_ptr->flags, FF_SPECIAL))
@@ -796,7 +794,7 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr, BIT_FLAGS prev_flo
                                }
                        }
 
-                       else if (prev_floor_mode & CFM_DOWN)
+                       else if (floor_mode & CFM_DOWN)
                        {
                                if (have_flag(f_ptr->flags, FF_MORE) && have_flag(f_ptr->flags, FF_STAIRS) &&
                                    !have_flag(f_ptr->flags, FF_SPECIAL))
@@ -860,7 +858,7 @@ static void locate_connected_stairs(saved_floor_type *sf_ptr, BIT_FLAGS prev_flo
  * / Maintain quest monsters, mark next floor_id at stairs, save current floor, and prepare to enter next floor.
  * @return なし
  */
-void leave_floor(void)
+void leave_floor(BIT_FLAGS floor_mode)
 {
        grid_type *g_ptr = NULL;
        feature_type *f_ptr;
@@ -874,15 +872,15 @@ void leave_floor(void)
        /* Remove all mirrors without explosion */
        remove_all_mirrors(FALSE);
 
-       if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(FALSE);
+       if (p_ptr->special_defense & NINJA_S_STEALTH) set_superstealth(p_ptr, FALSE);
 
        /* New floor is not yet prepared */
        new_floor_id = 0;
 
        /* Temporary get a floor_id (for Arena) */
        if (!p_ptr->floor_id &&
-           (change_floor_mode & CFM_SAVE_FLOORS) &&
-           !(change_floor_mode & CFM_NO_RETURN))
+           (floor_mode & CFM_SAVE_FLOORS) &&
+           !(floor_mode & CFM_NO_RETURN))
        {
            /* Get temporal floor_id */
            p_ptr->floor_id = get_new_floor_id();
@@ -942,13 +940,13 @@ void leave_floor(void)
        sf_ptr = get_sf_ptr(p_ptr->floor_id);
 
        /* Choose random stairs */
-       if ((change_floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
+       if ((floor_mode & CFM_RAND_CONNECT) && p_ptr->floor_id)
        {
-               locate_connected_stairs(sf_ptr, change_floor_mode);
+               locate_connected_stairs(sf_ptr, floor_mode);
        }
 
        /* Extract new dungeon level */
-       if (change_floor_mode & CFM_SAVE_FLOORS)
+       if (floor_mode & CFM_SAVE_FLOORS)
        {
                /* Extract stair position */
                g_ptr = &current_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
@@ -969,25 +967,25 @@ void leave_floor(void)
        }
 
        /* Climb up/down some sort of stairs */
-       if (change_floor_mode & (CFM_DOWN | CFM_UP))
+       if (floor_mode & (CFM_DOWN | CFM_UP))
        {
                int move_num = 0;
 
                /* Extract level movement number */
-               if (change_floor_mode & CFM_DOWN) move_num = 1;
-               else if (change_floor_mode & CFM_UP) move_num = -1;
+               if (floor_mode & CFM_DOWN) move_num = 1;
+               else if (floor_mode & CFM_UP) move_num = -1;
 
                /* Shafts are deeper than normal stairs */
-               if (change_floor_mode & CFM_SHAFT)
+               if (floor_mode & CFM_SHAFT)
                        move_num += SGN(move_num);
 
                /* Get out from or Enter the dungeon */
-               if (change_floor_mode & CFM_DOWN)
+               if (floor_mode & CFM_DOWN)
                {
                        if (!current_floor_ptr->dun_level)
                                move_num = d_info[p_ptr->dungeon_idx].mindepth;
                }
-               else if (change_floor_mode & CFM_UP)
+               else if (floor_mode & CFM_UP)
                {
                        if (current_floor_ptr->dun_level + move_num < d_info[p_ptr->dungeon_idx].mindepth)
                                move_num = -current_floor_ptr->dun_level;
@@ -1009,11 +1007,11 @@ void leave_floor(void)
                p_ptr->dungeon_idx = 0;
 
                /* Reach to the surface -- Clear all saved floors */
-               change_floor_mode &= ~CFM_SAVE_FLOORS;
+               floor_mode &= ~CFM_SAVE_FLOORS;
        }
 
        /* Kill some old saved floors */
-       if (!(change_floor_mode & CFM_SAVE_FLOORS))
+       if (!(floor_mode & CFM_SAVE_FLOORS))
        {
                /* Kill all saved floors */
                for (i = 0; i < MAX_SAVED_FLOORS; i++)
@@ -1022,7 +1020,7 @@ void leave_floor(void)
                /* Reset visit_mark count */
                latest_visit_mark = 1;
        }
-       else if (change_floor_mode & CFM_NO_RETURN)
+       else if (floor_mode & CFM_NO_RETURN)
        {
                /* Kill current floor */
                kill_saved_floor(sf_ptr);
@@ -1050,17 +1048,17 @@ void leave_floor(void)
        }
 
        /* Fix connection -- level teleportation or trap door */
-       if (change_floor_mode & CFM_RAND_CONNECT)
+       if (floor_mode & CFM_RAND_CONNECT)
        {
-               if (change_floor_mode & CFM_UP)
+               if (floor_mode & CFM_UP)
                        sf_ptr->upper_floor_id = new_floor_id;
-               else if (change_floor_mode & CFM_DOWN)
+               else if (floor_mode & CFM_DOWN)
                        sf_ptr->lower_floor_id = new_floor_id;
        }
 
        /* If you can return, you need to save previous floor */
-       if ((change_floor_mode & CFM_SAVE_FLOORS) &&
-           !(change_floor_mode & CFM_NO_RETURN))
+       if ((floor_mode & CFM_SAVE_FLOORS) &&
+           !(floor_mode & CFM_NO_RETURN))
        {
                /* Get out of the my way! */
                get_out_monster();
@@ -1070,7 +1068,7 @@ void leave_floor(void)
 
                forget_lite();
                forget_view();
-               clear_mon_lite();
+               clear_mon_lite(current_floor_ptr);
 
                /* Save current floor */
                if (!save_floor(sf_ptr, 0))
@@ -1093,7 +1091,7 @@ void leave_floor(void)
  * restored from the temporal file.  If the floor is new one, new current_floor_ptr->grid_array\n
  * will be generated.\n
  */
-void change_floor(BIT_FLAGS next_floor_mode)
+void change_floor(BIT_FLAGS floor_mode)
 {
        saved_floor_type *sf_ptr;
        bool loaded = FALSE;
@@ -1114,11 +1112,11 @@ void change_floor(BIT_FLAGS next_floor_mode)
        p_ptr->ambush_flag = FALSE;
 
        /* No saved floors (On the surface etc.) */
-       if (!(next_floor_mode & CFM_SAVE_FLOORS) &&
-           !(next_floor_mode & CFM_FIRST_FLOOR))
+       if (!(floor_mode & CFM_SAVE_FLOORS) &&
+           !(floor_mode & CFM_FIRST_FLOOR))
        {
                /* Create current_floor_ptr->grid_array */
-               generate_random_floor();
+               generate_random_floor(current_floor_ptr);
 
                /* Paranoia -- No new saved floor */
                new_floor_id = 0;
@@ -1146,13 +1144,13 @@ void change_floor(BIT_FLAGS next_floor_mode)
                                loaded = TRUE;
 
                                /* Forbid return stairs */
-                               if (next_floor_mode & CFM_NO_RETURN)
+                               if (floor_mode & CFM_NO_RETURN)
                                {
                                        grid_type *g_ptr = &current_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
 
                                        if (!feat_uses_special(g_ptr->feat))
                                        {
-                                               if (next_floor_mode & (CFM_DOWN | CFM_UP))
+                                               if (floor_mode & (CFM_DOWN | CFM_UP))
                                                {
                                                        /* Reset to floor */
                                                        g_ptr->feat = feat_ground_type[randint0(100)];
@@ -1175,13 +1173,13 @@ void change_floor(BIT_FLAGS next_floor_mode)
                {
                        saved_floor_type *cur_sf_ptr = get_sf_ptr(p_ptr->floor_id);
 
-                       if (next_floor_mode & CFM_UP)
+                       if (floor_mode & CFM_UP)
                        {
                                /* New floor is right-above */
                                if (cur_sf_ptr->upper_floor_id == new_floor_id)
                                        sf_ptr->lower_floor_id = p_ptr->floor_id;
                        }
-                       else if (next_floor_mode & CFM_DOWN)
+                       else if (floor_mode & CFM_DOWN)
                        {
                                /* New floor is right-under */
                                if (cur_sf_ptr->lower_floor_id == new_floor_id)
@@ -1192,9 +1190,9 @@ void change_floor(BIT_FLAGS next_floor_mode)
                /* Break connection to killed floor */
                else
                {
-                       if (next_floor_mode & CFM_UP)
+                       if (floor_mode & CFM_UP)
                                sf_ptr->lower_floor_id = 0;
-                       else if (next_floor_mode & CFM_DOWN)
+                       else if (floor_mode & CFM_DOWN)
                                sf_ptr->upper_floor_id = 0;
                }
 
@@ -1295,14 +1293,14 @@ void change_floor(BIT_FLAGS next_floor_mode)
                                msg_print(_("階段は行き止まりだった。", "The staircases come to a dead end..."));
 
                                /* Create simple dead end */
-                               build_dead_end();
+                               build_dead_end(current_floor_ptr);
 
                                /* Break connection */
-                               if (next_floor_mode & CFM_UP)
+                               if (floor_mode & CFM_UP)
                                {
                                        sf_ptr->upper_floor_id = 0;
                                }
-                               else if (next_floor_mode & CFM_DOWN)
+                               else if (floor_mode & CFM_DOWN)
                                {
                                        sf_ptr->lower_floor_id = 0;
                                }
@@ -1310,7 +1308,7 @@ void change_floor(BIT_FLAGS next_floor_mode)
                        else
                        {
                                /* Newly create current_floor_ptr->grid_array */
-                               generate_random_floor();
+                               generate_random_floor(current_floor_ptr);
                        }
 
                        /* Record last visit current_world_ptr->game_turn */
@@ -1320,7 +1318,7 @@ void change_floor(BIT_FLAGS next_floor_mode)
                        sf_ptr->dun_level = current_floor_ptr->dun_level;
 
                        /* Create connected stairs */
-                       if (!(next_floor_mode & CFM_NO_RETURN))
+                       if (!(floor_mode & CFM_NO_RETURN))
                        {
                                /* Extract stair position */
                                grid_type *g_ptr = &current_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
@@ -1328,15 +1326,15 @@ void change_floor(BIT_FLAGS next_floor_mode)
                                /*** Create connected stairs ***/
 
                                /* No stairs down from Quest */
-                               if ((next_floor_mode & CFM_UP) && !quest_number(current_floor_ptr->dun_level))
+                               if ((floor_mode & CFM_UP) && !quest_number(current_floor_ptr->dun_level))
                                {
-                                       g_ptr->feat = (next_floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair;
+                                       g_ptr->feat = (floor_mode & CFM_SHAFT) ? feat_state(feat_down_stair, FF_SHAFT) : feat_down_stair;
                                }
 
                                /* No stairs up when ironman_downward */
-                               else if ((next_floor_mode & CFM_DOWN) && !ironman_downward)
+                               else if ((floor_mode & CFM_DOWN) && !ironman_downward)
                                {
-                                       g_ptr->feat = (next_floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair;
+                                       g_ptr->feat = (floor_mode & CFM_SHAFT) ? feat_state(feat_up_stair, FF_SHAFT) : feat_up_stair;
                                }
 
                                /* Paranoia -- Clear mimic */
@@ -1348,13 +1346,13 @@ void change_floor(BIT_FLAGS next_floor_mode)
                }
 
                /* Arrive at random grid */
-               if (next_floor_mode & (CFM_RAND_PLACE))
+               if (floor_mode & (CFM_RAND_PLACE))
                {
                        (void)new_player_spot();
                }
 
                /* You see stairs blocked */
-               else if ((next_floor_mode & CFM_NO_RETURN) && (next_floor_mode & (CFM_DOWN | CFM_UP)))
+               else if ((floor_mode & CFM_NO_RETURN) && (floor_mode & (CFM_DOWN | CFM_UP)))
                {
                        if (!p_ptr->blind)
                        {
@@ -1378,7 +1376,7 @@ void change_floor(BIT_FLAGS next_floor_mode)
        }
 
        /* Place preserved pet monsters */
-       place_pet();
+       place_pet(p_ptr);
 
        /* Reset travel target place */
        forget_travel_flow();
@@ -1394,7 +1392,7 @@ void change_floor(BIT_FLAGS next_floor_mode)
 
        /* Hack -- Munchkin characters always get whole map */
        if (p_ptr->pseikaku == SEIKAKU_MUNCHKIN)
-               wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
+               wiz_lite(p_ptr, (bool)(p_ptr->pclass == CLASS_NINJA));
 
        /* Remember when this level was "created" */
        current_floor_ptr->generated_turn = current_world_ptr->game_turn;
@@ -1404,7 +1402,8 @@ void change_floor(BIT_FLAGS next_floor_mode)
        p_ptr->feeling = 0;
 
        /* Clear all flags */
-       next_floor_mode = 0L;
+       floor_mode = 0L;
 
-       select_floor_music();
+       select_floor_music(p_ptr);
+       p_ptr->change_floor_mode = 0;
 }