OSDN Git Service

[Refactor] #37353 monster_is_valid() 関数を定義し単純な !r_idx の条件から置換。 / Define monster_is_va...
[hengbandforosx/hengbandosx.git] / src / floor-save.c
index cf886a6..c2a466a 100644 (file)
@@ -18,6 +18,7 @@
 #include "quest.h"
 #include "wild.h"
 #include "spells-floor.h"
+#include "monster-status.h"
 
 
 static FLOOR_IDX new_floor_id;  /*!<次のフロアのID / floor_id of the destination */
@@ -367,7 +368,7 @@ static void preserve_pet(void)
 
        if (p_ptr->riding)
        {
-               monster_type *m_ptr = &m_list[p_ptr->riding];
+               monster_type *m_ptr = &current_floor_ptr->m_list[p_ptr->riding];
 
                /* Pet of other pet don't follow. */
                if (m_ptr->parent_m_idx)
@@ -394,9 +395,9 @@ static void preserve_pet(void)
        {
                for (i = m_max - 1, num = 1; (i >= 1 && num < MAX_PARTY_MON); i--)
                {
-                       monster_type *m_ptr = &m_list[i];
+                       monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
-                       if (!m_ptr->r_idx) continue;
+                       if (!monster_is_valid(m_ptr)) continue;
                        if (!is_pet(m_ptr)) continue;
                        if (i == p_ptr->riding) continue;
 
@@ -430,7 +431,7 @@ static void preserve_pet(void)
                                }
                        }
 
-                       (void)COPY(&party_mon[num], &m_list[i], monster_type);
+                       (void)COPY(&party_mon[num], &current_floor_ptr->m_list[i], monster_type);
 
                        num++;
 
@@ -443,10 +444,10 @@ static void preserve_pet(void)
        {
                for (i = m_max - 1; i >=1; i--)
                {
-                       monster_type *m_ptr = &m_list[i];
+                       monster_type *m_ptr = &current_floor_ptr->m_list[i];
                        GAME_TEXT m_name[MAX_NLEN];
 
-                       if (!m_ptr->r_idx) continue;
+                       if (!monster_is_valid(m_ptr)) continue;
                        if (!is_pet(m_ptr)) continue;
                        if (!m_ptr->nickname) continue;
                        if (p_ptr->riding == i) continue;
@@ -460,10 +461,10 @@ static void preserve_pet(void)
        /* Pet of other pet may disappear. */
        for (i = m_max - 1; i >=1; i--)
        {
-               monster_type *m_ptr = &m_list[i];
+               monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
                /* Are there its parent? */
-               if (m_ptr->parent_m_idx && !m_list[m_ptr->parent_m_idx].r_idx)
+               if (m_ptr->parent_m_idx && !current_floor_ptr->m_list[m_ptr->parent_m_idx].r_idx)
                {
                        /* Its parent have gone, it also goes away. */
 
@@ -497,7 +498,7 @@ void precalc_cur_num_of_pet(void)
                m_ptr = &party_mon[i];
 
                /* Skip empty monsters */
-               if (!m_ptr->r_idx) continue;
+               if (!monster_is_valid(m_ptr)) continue;
 
                /* Hack -- Increase the racial counter */
                real_r_ptr(m_ptr)->cur_num++;
@@ -549,7 +550,7 @@ static void place_pet(void)
 
                if (m_idx)
                {
-                       monster_type *m_ptr = &m_list[m_idx];
+                       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
                        monster_race *r_ptr;
 
                        current_floor_ptr->grid_array[cy][cx].m_idx = m_idx;
@@ -634,10 +635,9 @@ static void update_unique_artifact(s16b cur_floor_id)
        for (i = 1; i < m_max; i++)
        {
                monster_race *r_ptr;
-               monster_type *m_ptr = &m_list[i];
+               monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
-               /* Skip dead monsters */
-               if (!m_ptr->r_idx) continue;
+               if (!monster_is_valid(m_ptr)) continue;
 
                /* Extract real monster race */
                r_ptr = real_r_ptr(m_ptr);
@@ -717,7 +717,7 @@ static void get_out_monster(void)
 
                /*** It's a good place ***/
 
-               m_ptr = &m_list[m_idx];
+               m_ptr = &current_floor_ptr->m_list[m_idx];
 
                /* Update the old location */
                current_floor_ptr->grid_array[oy][ox].m_idx = 0;
@@ -891,10 +891,9 @@ void leave_floor(void)
        for (i = 1; i < m_max; i++)
        {
                monster_race *r_ptr;
-               monster_type *m_ptr = &m_list[i];
+               monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
-               /* Skip dead monsters */
-               if (!m_ptr->r_idx) continue;
+               if (!monster_is_valid(m_ptr)) continue;
 
                /* Only maintain quest monsters */
                if (quest_r_idx != m_ptr->r_idx) continue;
@@ -1052,8 +1051,8 @@ void leave_floor(void)
                /* Get out of the my way! */
                get_out_monster();
 
-               /* Record the last visit turn of current floor */
-               sf_ptr->last_visit = turn;
+               /* Record the last visit current_world_ptr->game_turn of current floor */
+               sf_ptr->last_visit = current_world_ptr->game_turn;
 
                forget_lite();
                forget_view();
@@ -1098,7 +1097,7 @@ void change_floor(void)
        panel_col_max = 0;
 
        /* Mega-Hack -- not ambushed on the wildness? */
-       ambush_flag = FALSE;
+       p_ptr->ambush_flag = FALSE;
 
        /* No saved floors (On the surface etc.) */
        if (!(change_floor_mode & CFM_SAVE_FLOORS) &&
@@ -1194,17 +1193,16 @@ void change_floor(void)
                        int alloc_chance = d_info[p_ptr->dungeon_idx].max_m_alloc_chance;
                        GAME_TURN alloc_times;
 
-                       while (tmp_last_visit > turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
-                       absence_ticks = (turn - tmp_last_visit) / TURNS_PER_TICK;
+                       while (tmp_last_visit > current_world_ptr->game_turn) tmp_last_visit -= TURNS_PER_TICK * TOWN_DAWN;
+                       absence_ticks = (current_world_ptr->game_turn - tmp_last_visit) / TURNS_PER_TICK;
 
                        /* Maintain monsters */
                        for (i = 1; i < m_max; i++)
                        {
                                monster_race *r_ptr;
-                               monster_type *m_ptr = &m_list[i];
+                               monster_type *m_ptr = &current_floor_ptr->m_list[i];
 
-                               /* Skip dead monsters */
-                               if (!m_ptr->r_idx) continue;
+                               if (!monster_is_valid(m_ptr)) continue;
 
                                if (!is_pet(m_ptr))
                                {
@@ -1302,8 +1300,8 @@ void change_floor(void)
                                generate_random_floor();
                        }
 
-                       /* Record last visit turn */
-                       sf_ptr->last_visit = turn;
+                       /* Record last visit current_world_ptr->game_turn */
+                       sf_ptr->last_visit = current_world_ptr->game_turn;
 
                        /* Set correct current_floor_ptr->dun_level value */
                        sf_ptr->dun_level = current_floor_ptr->dun_level;
@@ -1358,9 +1356,9 @@ void change_floor(void)
                /*
                 * Update visit mark
                 *
-                * The "turn" is not always different number because
-                * the level teleport doesn't take any turn.  Use
-                * visit mark instead of last visit turn to find the
+                * The "current_world_ptr->game_turn" is not always different number because
+                * the level teleport doesn't take any current_world_ptr->game_turn.  Use
+                * visit mark instead of last visit current_world_ptr->game_turn to find the
                 * oldest saved floor.
                 */
                sf_ptr->visit_mark = latest_visit_mark++;
@@ -1386,10 +1384,10 @@ void change_floor(void)
                wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
 
        /* Remember when this level was "created" */
-       old_turn = turn;
+       current_floor_ptr->generated_turn = current_world_ptr->game_turn;
 
        /* No dungeon feeling yet */
-       p_ptr->feeling_turn = old_turn;
+       p_ptr->feeling_turn = current_floor_ptr->generated_turn;
        p_ptr->feeling = 0;
 
        /* Clear all flags */