OSDN Git Service

[Refactor] #37353 monster_is_valid() 関数を定義し単純な !r_idx の条件から置換。 / Define monster_is_va...
[hengbandforosx/hengbandosx.git] / src / dungeon.c
index 32ef7e9..8dc901a 100644 (file)
@@ -42,6 +42,7 @@
 #include "realm-hex.h"
 #include "object-hook.h"
 #include "wild.h"
+#include "monster-status.h"
 
 
 static bool load = TRUE; /*!<ロード処理中の分岐フラグ*/
@@ -606,8 +607,6 @@ static void pattern_teleport(void)
         * and create a first saved floor
         */
        prepare_change_floor_mode(CFM_FIRST_FLOOR);
-
-       /* Leaving */
        p_ptr->leaving = TRUE;
 }
 
@@ -873,7 +872,7 @@ static void regen_monsters(void)
 
 
                /* Skip dead monsters */
-               if (!m_ptr->r_idx) continue;
+               if (!monster_is_valid(m_ptr)) continue;
 
                /* Allow regeneration (if needed) */
                if (m_ptr->hp < m_ptr->maxhp)
@@ -2422,7 +2421,7 @@ static void process_world_aux_mutation(void)
                        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
                        /* Paranoia -- Skip dead monsters */
-                       if (!m_ptr->r_idx) continue;
+                       if (!monster_is_valid(m_ptr)) continue;
 
                        if (r_ptr->level >= p_ptr->lev)
                        {
@@ -2958,8 +2957,6 @@ static void process_world_aux_movement(void)
                                 * and create a first saved floor
                                 */
                                prepare_change_floor_mode(CFM_FIRST_FLOOR);
-
-                               /* Leaving */
                                p_ptr->leaving = TRUE;
 
                                if (p_ptr->dungeon_idx == DUNGEON_ANGBAND)
@@ -3017,8 +3014,6 @@ static void process_world_aux_movement(void)
                                 * and create a first saved floor
                                 */
                                prepare_change_floor_mode(CFM_FIRST_FLOOR);
-
-                               /* Leaving */
                                p_ptr->leaving = TRUE;
                        }
                        else
@@ -3089,7 +3084,7 @@ static byte get_dungeon_feeling(void)
                int delta = 0;
 
                /* Skip dead monsters */
-               if (!m_ptr->r_idx) continue;
+               if (!monster_is_valid(m_ptr)) continue;
 
                /* Ignore pet */
                if (is_pet(m_ptr)) continue;
@@ -3381,8 +3376,6 @@ static void process_world(void)
 
                                /* Stop playing */
                                p_ptr->playing = FALSE;
-
-                               /* Leaving */
                                p_ptr->leaving = TRUE;
                        }
                }
@@ -3443,7 +3436,6 @@ static void process_world(void)
                                /* Check every feature */
                                for (i = 1; i < max_f_idx; i++)
                                {
-                                       /* Access the index */
                                        feature_type *f_ptr = &f_info[i];
 
                                        /* Skip empty index */
@@ -3515,7 +3507,6 @@ static void process_world(void)
                /* Every 15 minutes after 11:00 pm */
                if ((hour == 23) && !(min % 15))
                {
-                       /* Disturbing */
                        disturb(FALSE, TRUE);
 
                        switch (min / 15)
@@ -4554,7 +4545,6 @@ static void pack_overflow(void)
                /* Access the slot to be dropped */
                o_ptr = &inventory[INVEN_PACK];
 
-               /* Disturbing */
                disturb(FALSE, TRUE);
 
                /* Warning */
@@ -4614,7 +4604,7 @@ static void process_upkeep_with_speed(void)
  */
 static void process_player(void)
 {
-       IDX i;
+       MONSTER_IDX m_idx;
 
        /*** Apply energy ***/
 
@@ -4635,14 +4625,14 @@ static void process_player(void)
 
        if (p_ptr->inside_battle)
        {
-               for(i = 1; i < m_max; i++)
+               for(m_idx = 1; m_idx < m_max; m_idx++)
                {
-                       monster_type *m_ptr = &current_floor_ptr->m_list[i];
+                       monster_type *m_ptr = &current_floor_ptr->m_list[m_idx];
 
-                       if (!m_ptr->r_idx) continue;
+                       if (!monster_is_valid(m_ptr)) continue;
 
                        m_ptr->mflag2 |= (MFLAG2_MARK | MFLAG2_SHOW);
-                       update_monster(i, FALSE);
+                       update_monster(m_idx, FALSE);
                }
                prt_time();
        }
@@ -4795,7 +4785,6 @@ static void process_player(void)
                        }
                }
 
-               /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
                handle_stuff();
        }
        
@@ -4967,11 +4956,9 @@ static void process_player(void)
                        process_command();
                }
 
-
                /* Hack -- Pack Overflow */
                pack_overflow();
 
-
                /*** Clean up ***/
 
                /* Significant */
@@ -5000,16 +4987,15 @@ static void process_player(void)
                                shimmer_monsters = FALSE;
 
                                /* Shimmer multi-hued monsters */
-                               for (i = 1; i < m_max; i++)
+                               for (m_idx = 1; m_idx < m_max; m_idx++)
                                {
                                        monster_type *m_ptr;
                                        monster_race *r_ptr;
 
-                                       /* Access monster */
-                                       m_ptr = &current_floor_ptr->m_list[i];
+                                       m_ptr = &current_floor_ptr->m_list[m_idx];
 
                                        /* Skip dead monsters */
-                                       if (!m_ptr->r_idx) continue;
+                                       if (!monster_is_valid(m_ptr)) continue;
 
                                        /* Skip unseen monsters */
                                        if (!m_ptr->ml) continue;
@@ -5037,15 +5023,13 @@ static void process_player(void)
                                repair_monsters = FALSE;
 
                                /* Rotate detection flags */
-                               for (i = 1; i < m_max; i++)
+                               for (m_idx = 1; m_idx < m_max; m_idx++)
                                {
                                        monster_type *m_ptr;
-
-                                       /* Access monster */
-                                       m_ptr = &current_floor_ptr->m_list[i];
+                                       m_ptr = &current_floor_ptr->m_list[m_idx];
 
                                        /* Skip dead monsters */
-                                       if (!m_ptr->r_idx) continue;
+                                       if (!monster_is_valid(m_ptr)) continue;
 
                                        /* Nice monsters get mean */
                                        if (m_ptr->mflag & MFLAG_NICE)
@@ -5075,10 +5059,10 @@ static void process_player(void)
 
                                                        /* Assume invisible */
                                                        m_ptr->ml = FALSE;
-                                                       update_monster(i, FALSE);
+                                                       update_monster(m_idx, FALSE);
 
-                                                       if (p_ptr->health_who == i) p_ptr->redraw |= (PR_HEALTH);
-                                                       if (p_ptr->riding == i) p_ptr->redraw |= (PR_UHEALTH);
+                                                       if (p_ptr->health_who == m_idx) p_ptr->redraw |= (PR_HEALTH);
+                                                       if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
 
                                                        /* Redraw regardless */
                                                        lite_spot(m_ptr->fy, m_ptr->fx);
@@ -5088,13 +5072,14 @@ static void process_player(void)
                        }
                        if (p_ptr->pclass == CLASS_IMITATOR)
                        {
+                               int j;
                                if (p_ptr->mane_num > (p_ptr->lev > 44 ? 3 : p_ptr->lev > 29 ? 2 : 1))
                                {
                                        p_ptr->mane_num--;
-                                       for (i = 0; i < p_ptr->mane_num; i++)
+                                       for (j = 0; j < p_ptr->mane_num; j++)
                                        {
-                                               p_ptr->mane_spell[i] = p_ptr->mane_spell[i+1];
-                                               p_ptr->mane_dam[i] = p_ptr->mane_dam[i+1];
+                                               p_ptr->mane_spell[j] = p_ptr->mane_spell[j + 1];
+                                               p_ptr->mane_dam[j] = p_ptr->mane_dam[j + 1];
                                        }
                                }
                                new_mane = FALSE;
@@ -5111,7 +5096,6 @@ static void process_player(void)
 
                                p_ptr->redraw |= (PR_MAP);
                                p_ptr->update |= (PU_MONSTERS);
-
                                p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
 
                                msg_print(_("「時は動きだす…」", "You feel time flowing around you once more."));
@@ -5119,7 +5103,6 @@ static void process_player(void)
                                p_ptr->timewalk = FALSE;
                                p_ptr->energy_need = ENERGY_NEED();
 
-                               /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
                                handle_stuff();
                        }
                }
@@ -5237,19 +5220,9 @@ static void dungeon(bool load_game)
        character_xtra = TRUE;
 
        p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_MONSTER | PW_OVERHEAD | PW_DUNGEON);
+       p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_EQUIPPY | PR_MAP);
+       p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS | PU_VIEW | PU_LITE | PU_MON_LITE | PU_TORCH | PU_MONSTERS | PU_DISTANCE | PU_FLOW);
 
-       /* Redraw dungeon */
-       p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_EQUIPPY);
-
-       p_ptr->redraw |= (PR_MAP);
-
-       p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
-
-       /* Update lite/view */
-       p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_TORCH);
-       p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
-
-       /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
        handle_stuff();
 
        /* Leave "xtra" mode */
@@ -5346,7 +5319,6 @@ static void dungeon(bool load_game)
                process_player();
                process_upkeep_with_speed();
 
-               /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
                handle_stuff();
 
                /* Hack -- Hilite the player */