OSDN Git Service

[Refactor] #37353 コメント整理 / Refactor comments.
[hengband/hengband.git] / src / monster-process.c
index 57b6a1e..aff5af8 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "angband.h"
 #include "cmd-pet.h"
+#include "monsterrace-hook.h"
 
 
 /*!
@@ -84,8 +85,7 @@ static bool get_enemy_dir(MONSTER_IDX m_idx, int *mm)
                                        }
                                }
                                /* Hack -- no fighting away from player */
-                               else if ((m_ptr->cdis < t_ptr->cdis) &&
-                                                       (t_ptr->cdis > p_ptr->pet_follow_distance))
+                               else if ((m_ptr->cdis < t_ptr->cdis) && (t_ptr->cdis > p_ptr->pet_follow_distance))
                                {
                                        continue;
                                }
@@ -212,10 +212,9 @@ void mon_take_hit_mon(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, cptr note, I
                if (p_ptr->riding == m_idx) p_ptr->redraw |= (PR_UHEALTH);
        }
 
-       /* Wake it up */
        (void)set_monster_csleep(m_idx, 0);
 
-       if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 1);
+       if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(TRUE, TRUE);
 
        if (MON_INVULNER(m_ptr) && randint0(PENETRATE_INVULNERABILITY))
        {
@@ -223,7 +222,6 @@ void mon_take_hit_mon(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, cptr note, I
                {
                        msg_format(_("%^sはダメージを受けない。", "%^s is unharmed."), m_name);
                }
-
                return;
        }
 
@@ -245,7 +243,7 @@ void mon_take_hit_mon(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, cptr note, I
        }
 
        /* Hurt it */
-       m_ptr->hp -= (s16b)dam;
+       m_ptr->hp -= dam;
 
        /* It is dead now... or is it? */
        if (m_ptr->hp < 0)
@@ -259,7 +257,7 @@ void mon_take_hit_mon(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, cptr note, I
                else
                {
                        /* Make a sound */
-                       if (!monster_living(r_ptr))
+                       if (!monster_living(m_ptr->r_idx))
                        {
                                sound(SOUND_N_KILL);
                        }
@@ -282,7 +280,7 @@ void mon_take_hit_mon(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, cptr note, I
                                        msg_format(_("%^s%s", "%^s%s"), m_name, note);
                                }
                                /* Death by normal attack -- nonliving monster */
-                               else if (!monster_living(r_ptr))
+                               else if (!monster_living(m_ptr->r_idx))
                                {
                                        msg_format(_("%^sは破壊された。", "%^s is destroyed."), m_name);
                                }
@@ -294,11 +292,7 @@ void mon_take_hit_mon(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, cptr note, I
                        }
 
                        monster_gain_exp(who, m_ptr->r_idx);
-
-                       /* Generate treasure */
                        monster_death(m_idx, FALSE);
-
-                       /* Delete the monster */
                        delete_monster_idx(m_idx);
 
                        /* Not afraid */
@@ -338,7 +332,7 @@ void mon_take_hit_mon(MONSTER_IDX m_idx, HIT_POINT dam, bool *fear, cptr note, I
                        /* Hack -- note fear */
                        (*fear) = TRUE;
 
-                       /* XXX XXX XXX Hack -- Add some timed fear */
+                       /* Hack -- Add some timed fear */
                        (void)set_monster_monfear(m_idx, (randint1(10) +
                                (((dam >= m_ptr->hp) && (percentage > 7)) ?
                                20 : ((11 - percentage) * 5))));
@@ -396,7 +390,8 @@ static bool mon_will_run(MONSTER_IDX m_idx)
 
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
-       u16b p_lev, m_lev;
+       PLAYER_LEVEL p_lev;
+       DEPTH m_lev;
        HIT_POINT p_chp, p_mhp;
        HIT_POINT m_chp, m_mhp;
        u32b p_val, m_val;
@@ -496,7 +491,6 @@ static bool get_moves_aux2(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
        {
                int cost;
 
-               /* Get the location */
                y = y1 + ddy_ddd[i];
                x = x1 + ddx_ddd[i];
 
@@ -630,7 +624,6 @@ static bool get_moves_aux(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp, bool no
        /* Check nearby grids, diagonals first */
        for (i = 7; i >= 0; i--)
        {
-               /* Get the location */
                y = y1 + ddy_ddd[i];
                x = x1 + ddx_ddd[i];
 
@@ -709,7 +702,6 @@ static bool get_fear_moves_aux(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
        {
                POSITION dis, s;
 
-               /* Get the location */
                y = fy + ddy_ddd[i];
                x = fx + ddx_ddd[i];
 
@@ -764,53 +756,30 @@ static bool get_fear_moves_aux(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
  * It is probably better to replace these arrays with code to compute
  * the relevant arrays, even if the storage is pre-allocated in hard
  * coded sizes.  At the very least, code should be included which is
- * able to generate and dump these arrays (ala "los()").  XXX XXX XXX
+ * able to generate and dump these arrays (ala "los()").  
  *
- * Also, the storage needs could be halved by using bytes.  XXX XXX XXX
+ * Also, the storage needs could be halved by using bytes.  
  *
  * These arrays could be combined into two big arrays, using sub-arrays
  * to hold the offsets and lengths of each portion of the sub-arrays, and
- * this could perhaps also be used somehow in the "look" code.  XXX XXX XXX
+ * this could perhaps also be used somehow in the "look" code.  
  */
 
 
-static sint d_off_y_0[] =
-{ 0 };
-
-static sint d_off_x_0[] =
-{ 0 };
-
-
-static sint d_off_y_1[] =
-{ -1, -1, -1, 0, 0, 1, 1, 1, 0 };
-
-static sint d_off_x_1[] =
-{ -1, 0, 1, -1, 1, -1, 0, 1, 0 };
-
-
-static sint d_off_y_2[] =
-{ -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
-
-static sint d_off_x_2[] =
-{ -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
-
+static sint d_off_y_0[] = { 0 };
+static sint d_off_x_0[] = { 0 };
 
-static sint d_off_y_3[] =
-{ -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2,
-  3, 3, 3, 0 };
+static sint d_off_y_1[] = { -1, -1, -1, 0, 0, 1, 1, 1, 0 };
+static sint d_off_x_1[] = { -1, 0, 1, -1, 1, -1, 0, 1, 0 };
 
-static sint d_off_x_3[] =
-{ -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2,
-  -1, 0, 1, 0 };
+static sint d_off_y_2[] = { -1, -1, -2, -2, -2, 0, 0, 1, 1, 2, 2, 2, 0 };
+static sint d_off_x_2[] = { -2, 2, -1, 0, 1, -2, 2, -2, 2, -1, 0, 1, 0 };
 
+static sint d_off_y_3[] = { -1, -1, -2, -2, -3, -3, -3, 0, 0, 1, 1, 2, 2, 3, 3, 3, 0 };
+static sint d_off_x_3[] = { -3, 3, -2, 2, -1, 0, 1, -3, 3, -3, 3, -2, 2, -1, 0, 1, 0 };
 
-static sint d_off_y_4[] =
-{ -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0,
-  0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
-
-static sint d_off_x_4[] =
-{ -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4,
-  -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
+static sint d_off_y_4[] = { -1, -1, -2, -2, -3, -3, -3, -3, -4, -4, -4, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 0 };
+static sint d_off_x_4[] = { -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, -4, 4, -4, 4, -3, 3, -2, -3, 2, 3, -1, 0, 1, 0 };
 
 
 static sint d_off_y_5[] =
@@ -1071,7 +1040,7 @@ static bool find_hiding(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
  * @param mm 移動方向を返す方向IDの参照ポインタ
  * @return 有効方向があった場合TRUEを返す
  */
-static bool get_moves(MONSTER_IDX m_idx, int *mm)
+static bool get_moves(MONSTER_IDX m_idx, DIRECTION *mm)
 {
        monster_type *m_ptr = &m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
@@ -1496,7 +1465,7 @@ static bool monst_attack_monst(MONSTER_IDX m_idx, MONSTER_IDX t_idx)
                mon_fight = TRUE;
        }
 
-       if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(1, 1);
+       if (p_ptr->riding && (m_idx == p_ptr->riding)) disturb(TRUE, TRUE);
 
        /* Scan through all four blows */
        for (ap_cnt = 0; ap_cnt < 4; ap_cnt++)
@@ -1531,7 +1500,6 @@ static bool monst_attack_monst(MONSTER_IDX m_idx, MONSTER_IDX t_idx)
                /* Monster hits */
                if (!effect || check_hit2(power, rlev, ac, MON_STUNNED(m_ptr)))
                {
-                       /* Wake it up */
                        (void)set_monster_csleep(t_idx, 0);
 
                        if (t_ptr->ml)
@@ -1650,7 +1618,7 @@ static bool monst_attack_monst(MONSTER_IDX m_idx, MONSTER_IDX t_idx)
 
                        case RBM_EXPLODE:
                                {
-                                       if (see_either) disturb(1, 1);
+                                       if (see_either) disturb(TRUE, TRUE);
                                        act = _("爆発した。", "explodes.");
                                        explode = TRUE;
                                        touched = FALSE;
@@ -1875,7 +1843,7 @@ static bool monst_attack_monst(MONSTER_IDX m_idx, MONSTER_IDX t_idx)
                                        break;
 
                                case BLOW_EFFECT_TYPE_HEAL:
-                                       if ((monster_living(tr_ptr)) && (damage > 2))
+                                       if ((monster_living(m_idx)) && (damage > 2))
                                        {
                                                bool did_heal = FALSE;
 
@@ -1985,14 +1953,13 @@ static bool monst_attack_monst(MONSTER_IDX m_idx, MONSTER_IDX t_idx)
                        case RBM_ENGULF:
                        case RBM_CHARGE:
                                {
-                                       /* Wake it up */
                                        (void)set_monster_csleep(t_idx, 0);
 
                                        /* Visible monsters */
                                        if (see_m)
                                        {
 #ifdef JP
-                                               msg_format("%sは%^sの攻撃をかわした。", t_name,m_name);
+                                               msg_format("%sは%^sの攻撃をかわした。", t_name, m_name);
 #else
                                                msg_format("%^s misses %s.", m_name, t_name);
 #endif
@@ -2091,7 +2058,7 @@ static bool check_hp_for_feat_destruction(feature_type *f_ptr, monster_type *m_p
  * fixate on opening a door even if they cannot open it.  Actually,\n
  * the same thing happens to normal monsters when they hit a door\n
  *\n
- * XXX XXX XXX In addition, monsters which *cannot* open or bash\n
+ * In addition, monsters which *cannot* open or bash\n
  * down a door will still stand there trying to open it...\n
  *\n
  * XXX Technically, need to check for monster in the way\n
@@ -2105,10 +2072,10 @@ void process_monster(MONSTER_IDX m_idx)
        monster_race    *r_ptr = &r_info[m_ptr->r_idx];
        monster_race    *ap_r_ptr = &r_info[m_ptr->ap_r_idx];
 
-       int             i, d;
-       POSITION        oy, ox, ny, nx;
+       int i, d;
+       POSITION oy, ox, ny, nx;
 
-       int             mm[8];
+       DIRECTION mm[8];
 
        cave_type       *c_ptr;
        feature_type    *f_ptr;
@@ -2176,8 +2143,6 @@ void process_monster(MONSTER_IDX m_idx)
                if (see_m)
                {
                        char m_name[80];
-
-                       /* Acquire the monster name */
                        monster_desc(m_name, m_ptr, 0);
                        msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
                }
@@ -2190,7 +2155,7 @@ void process_monster(MONSTER_IDX m_idx)
                        do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_LOSE_PARENT, m_name);
                }
 
-               /* Delete the monster */
+
                delete_monster_idx(m_idx);
 
                return;
@@ -2207,26 +2172,21 @@ void process_monster(MONSTER_IDX m_idx)
                {
                        bool sad = FALSE;
 
-                       if (is_pet(m_ptr) && !(m_ptr->ml))
-                               sad = TRUE;
+                       if (is_pet(m_ptr) && !(m_ptr->ml)) sad = TRUE;
 
                        if (see_m)
                        {
                                char m_name[80];
-
-                               /* Acquire the monster name */
                                monster_desc(m_name, m_ptr, 0);
 
-                               /* Oops */
                                msg_format(_("%sは消え去った!", "%^s disappears!"), m_name);
                        }
 
                        /* Generate treasure, etc */
                        monster_death(m_idx, FALSE);
 
-                       /* Delete the monster */
-                       delete_monster_idx(m_idx);
 
+                       delete_monster_idx(m_idx);
                        if (sad)
                        {
                                msg_print(_("少しの間悲しい気分になった。", "You feel sad for a moment."));
@@ -2255,7 +2215,7 @@ void process_monster(MONSTER_IDX m_idx)
                                msg_format(_("%sは傷の痛さの余りあなたの束縛から逃れようとしている。",
                                                         "%^s seems to be in so much pain, and trying to escape from your restriction."), m_name);
                                riding_pinch++;
-                               disturb(1, 1);
+                               disturb(TRUE, TRUE);
                        }
                        else
                        {
@@ -2314,8 +2274,6 @@ void process_monster(MONSTER_IDX m_idx)
                if (m_ptr->ml)
                {
                        char m_name[80];
-
-                       /* Acquire the monster name */
                        monster_desc(m_name, m_ptr, 0);
 
                        /* Dump a message */
@@ -2421,9 +2379,9 @@ void process_monster(MONSTER_IDX m_idx)
                        {
                                if (r_ptr->freq_spell && (randint1(100) <= r_ptr->freq_spell))
                                {
-                                       int  k, count = 0;
-                                       int  rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
-                                       u32b p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
+                                       int k, count = 0;
+                                       DEPTH rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
+                                       BIT_FLAGS p_mode = is_pet(m_ptr) ? PM_FORCE_PET : 0L;
 
                                        for (k = 0; k < 6; k++)
                                        {
@@ -2493,11 +2451,10 @@ void process_monster(MONSTER_IDX m_idx)
                /* Give priority to counter attack? */
                if (m_ptr->target_y)
                {
-                       int t_m_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
+                       MONSTER_IDX t_m_idx = cave[m_ptr->target_y][m_ptr->target_x].m_idx;
 
                        /* The monster must be an enemy, and projectable */
-                       if (t_m_idx &&
-                           are_enemies(m_ptr, &m_list[t_m_idx]) &&
+                       if (t_m_idx && are_enemies(m_ptr, &m_list[t_m_idx]) &&
                            projectable(m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
                        {
                                counterattack = TRUE;
@@ -2745,7 +2702,7 @@ void process_monster(MONSTER_IDX m_idx)
                                /* Locked doors (not jammed) */
                                else
                                {
-                                       /* Try to unlock it XXX XXX XXX */
+                                       /* Try to unlock it */
                                        if (randint0(m_ptr->hp / 10) > f_ptr->power)
                                        {
                                                /* Unlock the door */
@@ -2763,7 +2720,7 @@ void process_monster(MONSTER_IDX m_idx)
                        if (may_bash && (r_ptr->flags2 & RF2_BASH_DOOR) && have_flag(f_ptr->flags, FF_BASH) &&
                                (!is_pet(m_ptr) || (p_ptr->pet_extra_flags & PF_OPEN_DOORS)))
                        {
-                               /* Attempt to Bash XXX XXX XXX */
+                               /* Attempt to Bash */
                                if (check_hp_for_feat_destruction(f_ptr, m_ptr) && (randint0(m_ptr->hp / 10) > f_ptr->power))
                                {
                                        if (have_flag(f_ptr->flags, FF_GLASS))
@@ -2772,7 +2729,7 @@ void process_monster(MONSTER_IDX m_idx)
                                                msg_print(_("ドアを叩き開ける音がした!", "You hear a door burst open!"));
 
                                        /* Disturb (sometimes) */
-                                       if (disturb_minor) disturb(0, 0);
+                                       if (disturb_minor) disturb(FALSE, FALSE);
 
                                        /* The door was bashed open */
                                        did_bash_door = TRUE;
@@ -2842,7 +2799,6 @@ void process_monster(MONSTER_IDX m_idx)
                                /* Allow movement */
                                do_move = TRUE;
 
-                               /* Notice */
                                note_spot(ny, nx);
                        }
                }
@@ -2984,7 +2940,7 @@ void process_monster(MONSTER_IDX m_idx)
                                /* Wake up the moved monster */
                                (void)set_monster_csleep(c_ptr->m_idx, 0);
 
-                               /* XXX XXX XXX Message */
+                               /* Message */
                        }
                }
 
@@ -3080,7 +3036,7 @@ void process_monster(MONSTER_IDX m_idx)
                                        y_ptr->fx = ox;
 
                                        /* Update the old monster */
-                                       update_mon(c_ptr->m_idx, TRUE);
+                                       update_monster(c_ptr->m_idx, TRUE);
                                }
 
                                /* Hack -- Update the new location */
@@ -3089,9 +3045,7 @@ void process_monster(MONSTER_IDX m_idx)
                                /* Move the monster */
                                m_ptr->fy = ny;
                                m_ptr->fx = nx;
-
-                               /* Update the monster */
-                               update_mon(m_idx, TRUE);
+                               update_monster(m_idx, TRUE);
 
                                /* Redraw the old grid */
                                lite_spot(oy, ox);
@@ -3113,9 +3067,8 @@ void process_monster(MONSTER_IDX m_idx)
                             (disturb_near && (m_ptr->mflag & MFLAG_VIEW) && projectable(p_ptr->y, p_ptr->x, m_ptr->fy, m_ptr->fx)) ||
                             (disturb_high && ap_r_ptr->r_tkills && ap_r_ptr->level >= p_ptr->lev)))
                        {
-                               /* Disturb */
                                if (is_hostile(m_ptr))
-                                       disturb(0, 1);
+                                       disturb(FALSE, TRUE);
                        }
 
                        /* Take or Kill objects on the floor */
@@ -3130,8 +3083,6 @@ void process_monster(MONSTER_IDX m_idx)
                                {
                                        BIT_FLAGS flgs[TR_FLAG_SIZE], flg2 = 0L, flg3 = 0L, flgr = 0L;
                                        char m_name[80], o_name[MAX_NLEN];
-
-                                       /* Acquire object */
                                        object_type *o_ptr = &o_list[this_o_idx];
 
                                        /* Acquire next object */
@@ -3156,8 +3107,6 @@ void process_monster(MONSTER_IDX m_idx)
 
                                        /* Acquire the object name */
                                        object_desc(o_name, o_ptr, 0);
-
-                                       /* Acquire the monster name */
                                        monster_desc(m_name, m_ptr, MD_INDEF_HIDDEN);
 
                                        /* React to objects that hurt the monster */
@@ -3249,7 +3198,6 @@ void process_monster(MONSTER_IDX m_idx)
                                                        msg_format(_("%^sが%sを破壊した。", "%^s destroys %s."), m_name, o_name);
                                                }
 
-                                               /* Delete the object */
                                                delete_object_idx(this_o_idx);
                                        }
                                }
@@ -3331,8 +3279,6 @@ void process_monster(MONSTER_IDX m_idx)
                if (see_m)
                {
                        char m_name[80];
-
-                       /* Acquire the monster name */
                        monster_desc(m_name, m_ptr, 0);
 
                        /* Dump a message */
@@ -3341,7 +3287,7 @@ void process_monster(MONSTER_IDX m_idx)
 
                if (m_ptr->ml) chg_virtue(V_COMPASSION, -1);
 
-               /* XXX XXX XXX Actually do something now (?) */
+               /* Actually do something now (?) */
        }
 }
 
@@ -3389,24 +3335,24 @@ void process_monsters(void)
        monster_type    *m_ptr;
        monster_race    *r_ptr;
 
-       int             old_monster_race_idx;
+       MONRACE_IDX old_monster_race_idx;
 
-       u32b    old_r_flags1 = 0L;
-       u32b    old_r_flags2 = 0L;
-       u32b    old_r_flags3 = 0L;
-       u32b    old_r_flags4 = 0L;
-       u32b    old_r_flags5 = 0L;
-       u32b    old_r_flags6 = 0L;
-       u32b    old_r_flagsr = 0L;
+       BIT_FLAGS old_r_flags1 = 0L;
+       BIT_FLAGS old_r_flags2 = 0L;
+       BIT_FLAGS old_r_flags3 = 0L;
+       BIT_FLAGS old_r_flags4 = 0L;
+       BIT_FLAGS old_r_flags5 = 0L;
+       BIT_FLAGS old_r_flags6 = 0L;
+       BIT_FLAGS old_r_flagsr = 0L;
 
-       byte    old_r_blows0 = 0;
-       byte    old_r_blows1 = 0;
-       byte    old_r_blows2 = 0;
-       byte    old_r_blows3 = 0;
+       byte old_r_blows0 = 0;
+       byte old_r_blows1 = 0;
+       byte old_r_blows2 = 0;
+       byte old_r_blows3 = 0;
 
-       byte    old_r_cast_spell = 0;
+       byte old_r_cast_spell = 0;
 
-       int speed;
+       SPEED speed;
 
        /* Clear monster fighting indicator */
        mon_fight = FALSE;