OSDN Git Service

[Refactor] #38997 clean_shot() にplayer_type * 引数を追加 / Added player_type * argument...
authorHourier <hourier@users.sourceforge.jp>
Sat, 11 Jan 2020 04:26:51 +0000 (13:26 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sat, 11 Jan 2020 04:26:51 +0000 (13:26 +0900)
src/monster-process.c
src/monster-spell.h
src/mspells1.c
src/mspells2.c

index 26b511b..02ec419 100644 (file)
@@ -789,6 +789,7 @@ static bool find_safety(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
 /*!
  * @brief モンスターが隠れ潜める地点を返す /
  * Choose a good hiding place near a monster for it to run toward.
+ * @param target_ptr プレーヤーへの参照ポインタ
  * @param m_idx モンスターの参照ID
  * @param yp 移動先のマスのY座標を返す参照ポインタ
  * @param xp 移動先のマスのX座標を返す参照ポインタ
@@ -799,9 +800,10 @@ static bool find_safety(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
  *\n
  * Return TRUE if a good location is available.\n
  */
-static bool find_hiding(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
+static bool find_hiding(player_type *target_ptr, MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
 {
-       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
+       floor_type *floor_ptr = target_ptr->current_floor_ptr;
+       monster_type *m_ptr = &floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
 
        POSITION fy = m_ptr->fy;
@@ -828,16 +830,16 @@ static bool find_hiding(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
                        x = fx + dx;
 
                        /* Skip illegal locations */
-                       if (!in_bounds(p_ptr->current_floor_ptr, y, x)) continue;
+                       if (!in_bounds(floor_ptr, y, x)) continue;
 
                        /* Skip occupied locations */
                        if (!monster_can_enter(y, x, r_ptr, 0)) continue;
 
                        /* Check for hidden, available grid */
-                       if (!projectable(p_ptr->current_floor_ptr, p_ptr->y, p_ptr->x, y, x) && clean_shot(fy, fx, y, x, FALSE))
+                       if (!projectable(floor_ptr, target_ptr->y, target_ptr->x, y, x) && clean_shot(target_ptr, fy, fx, y, x, FALSE))
                        {
                                /* Calculate distance from player */
-                               dis = distance(y, x, p_ptr->y, p_ptr->x);
+                               dis = distance(y, x, target_ptr->y, target_ptr->x);
 
                                /* Remember if closer than previous */
                                if (dis < gdis && dis >= 2)
@@ -869,34 +871,36 @@ static bool find_hiding(MONSTER_IDX m_idx, POSITION *yp, POSITION *xp)
 /*!
  * @brief モンスターの移動方向を返す /
  * Choose "logical" directions for monster movement
+ * @param target_ptr プレーヤーへの参照ポインタ
  * @param m_idx モンスターの参照ID
  * @param mm 移動方向を返す方向IDの参照ポインタ
  * @return 有効方向があった場合TRUEを返す
  */
-static bool get_moves(MONSTER_IDX m_idx, DIRECTION *mm)
+static bool get_moves(player_type *target_ptr, MONSTER_IDX m_idx, DIRECTION *mm)
 {
-       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[m_idx];
+       floor_type *floor_ptr = target_ptr->current_floor_ptr;
+       monster_type *m_ptr = &floor_ptr->m_list[m_idx];
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
        POSITION     y = 0, ay, x = 0, ax;
        int          move_val = 0;
-       POSITION     y2 = p_ptr->y;
-       POSITION     x2 = p_ptr->x;
+       POSITION     y2 = target_ptr->y;
+       POSITION     x2 = target_ptr->x;
        bool         done = FALSE;
        bool         will_run = mon_will_run(m_idx);
        grid_type    *g_ptr;
-       bool         no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (p_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2));
-       bool         can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != p_ptr->riding) || p_ptr->pass_wall));
+       bool         no_flow = ((m_ptr->mflag2 & MFLAG2_NOFLOW) && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].cost > 2));
+       bool         can_pass_wall = ((r_ptr->flags2 & RF2_PASS_WALL) && ((m_idx != target_ptr->riding) || target_ptr->pass_wall));
 
        /* Counter attack to an enemy monster */
        if (!will_run && m_ptr->target_y)
        {
-               int t_m_idx = p_ptr->current_floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
+               int t_m_idx = floor_ptr->grid_array[m_ptr->target_y][m_ptr->target_x].m_idx;
 
                /* The monster must be an enemy, and in LOS */
                if (t_m_idx &&
-                   are_enemies(m_ptr, &p_ptr->current_floor_ptr->m_list[t_m_idx]) &&
-                   los(p_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
-                   projectable(p_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
+                   are_enemies(m_ptr, &floor_ptr->m_list[t_m_idx]) &&
+                   los(floor_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x) &&
+                   projectable(floor_ptr, m_ptr->fy, m_ptr->fx, m_ptr->target_y, m_ptr->target_x))
                {
                        /* Extract the "pseudo-direction" */
                        y = m_ptr->fy - m_ptr->target_y;
@@ -907,8 +911,8 @@ static bool get_moves(MONSTER_IDX m_idx, DIRECTION *mm)
 
        if (!done && !will_run && is_hostile(m_ptr) &&
            (r_ptr->flags1 & RF1_FRIENDS) &&
-           ((los(p_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x) && projectable(p_ptr->current_floor_ptr, m_ptr->fy, m_ptr->fx, p_ptr->y, p_ptr->x)) ||
-           (p_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
+           ((los(floor_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x) && projectable(floor_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x)) ||
+           (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < MAX_SIGHT / 2)))
        {
        /*
         * Animal packs try to get the player out of corridors
@@ -922,12 +926,12 @@ static bool get_moves(MONSTER_IDX m_idx, DIRECTION *mm)
                        /* Count room grids next to player */
                        for (i = 0; i < 8; i++)
                        {
-                               int xx = p_ptr->x + ddx_ddd[i];
-                               int yy = p_ptr->y + ddy_ddd[i];
+                               int xx = target_ptr->x + ddx_ddd[i];
+                               int yy = target_ptr->y + ddy_ddd[i];
 
-                               if (!in_bounds2(p_ptr->current_floor_ptr, yy, xx)) continue;
+                               if (!in_bounds2(floor_ptr, yy, xx)) continue;
 
-                               g_ptr = &p_ptr->current_floor_ptr->grid_array[yy][xx];
+                               g_ptr = &floor_ptr->grid_array[yy][xx];
 
                                /* Check grid */
                                if (monster_can_cross_terrain(g_ptr->feat, r_ptr, 0))
@@ -936,20 +940,20 @@ static bool get_moves(MONSTER_IDX m_idx, DIRECTION *mm)
                                        room++;
                                }
                        }
-                       if (p_ptr->current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_ROOM) room -= 2;
+                       if (floor_ptr->grid_array[target_ptr->y][target_ptr->x].info & CAVE_ROOM) room -= 2;
                        if (!r_ptr->flags4 && !r_ptr->a_ability_flags1 && !r_ptr->a_ability_flags2) room -= 2;
 
                        /* Not in a room and strong player */
-                       if (room < (8 * (p_ptr->chp + p_ptr->csp)) /
-                           (p_ptr->mhp + p_ptr->msp))
+                       if (room < (8 * (target_ptr->chp + target_ptr->csp)) /
+                           (target_ptr->mhp + target_ptr->msp))
                        {
                                /* Find hiding place */
-                               if (find_hiding(m_idx, &y, &x)) done = TRUE;
+                               if (find_hiding(target_ptr, m_idx, &y, &x)) done = TRUE;
                        }
                }
 
                /* Monster groups try to surround the player */
-               if (!done && (p_ptr->current_floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
+               if (!done && (floor_ptr->grid_array[m_ptr->fy][m_ptr->fx].dist < 3))
                {
                        int i;
 
@@ -957,20 +961,20 @@ static bool get_moves(MONSTER_IDX m_idx, DIRECTION *mm)
                        for (i = 0; i < 8; i++)
                        {
                                /* Pick squares near player (semi-randomly) */
-                               y2 = p_ptr->y + ddy_ddd[(m_idx + i) & 7];
-                               x2 = p_ptr->x + ddx_ddd[(m_idx + i) & 7];
+                               y2 = target_ptr->y + ddy_ddd[(m_idx + i) & 7];
+                               x2 = target_ptr->x + ddx_ddd[(m_idx + i) & 7];
 
                                /* Already there? */
                                if ((m_ptr->fy == y2) && (m_ptr->fx == x2))
                                {
                                        /* Attack the player */
-                                       y2 = p_ptr->y;
-                                       x2 = p_ptr->x;
+                                       y2 = target_ptr->y;
+                                       x2 = target_ptr->x;
 
                                        break;
                                }
 
-                               if (!in_bounds2(p_ptr->current_floor_ptr, y2, x2)) continue;
+                               if (!in_bounds2(floor_ptr, y2, x2)) continue;
 
                                /* Ignore filled grids */
                                if (!monster_can_enter(y2, x2, r_ptr, 0)) continue;
@@ -1722,7 +1726,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
                                }
 
                                /* Find the player */
-                               (void)get_moves(m_idx, mm);
+                               (void)get_moves(target_ptr, m_idx, mm);
 
                                /* Restore the leash */
                                target_ptr->pet_follow_distance = (s16b)dis;
@@ -1743,7 +1747,7 @@ void process_monster(player_type *target_ptr, MONSTER_IDX m_idx)
        else
        {
                /* Logical moves, may do nothing */
-               if (!get_moves(m_idx, mm)) return;
+               if (!get_moves(target_ptr, m_idx, mm)) return;
        }
 
        /* Assume nothing */
index e20b5d3..a0fdabb 100644 (file)
@@ -306,7 +306,7 @@ extern const monster_power monster_powers[MAX_MONSPELLS];
 extern const concptr monster_powers_short[MAX_MONSPELLS];
 
 /* mspells1.c */
-extern bool clean_shot(POSITION y1, POSITION x1, POSITION y2, POSITION x2, bool is_friend);
+extern bool clean_shot(player_type *target_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, bool is_friend);
 extern bool summon_possible(floor_type *floor_ptr, POSITION y1, POSITION x1);
 extern bool raise_possible(floor_type *floor_ptr, monster_type *m_ptr);
 extern bool dispel_check(player_type *creature_ptr, MONSTER_IDX m_idx);
index efee732..847de16 100644 (file)
@@ -456,7 +456,7 @@ bool raise_possible(floor_type *floor_ptr, monster_type *m_ptr)
 /*!
  * @brief モンスターにとってボルト型魔法が有効な状態かを返す /
  * Determine if a bolt spell will hit the player.
- * @param caster_ptr プレーヤーへの参照ポインタ
+ * @param target_ptr プレーヤーへの参照ポインタ
  * @param y1 ボルト魔法発射地点のY座標
  * @param x1 ボルト魔法発射地点のX座標
  * @param y2 ボルト魔法目標地点のY座標
@@ -473,7 +473,7 @@ bool raise_possible(floor_type *floor_ptr, monster_type *m_ptr)
  * no equally friendly monster is\n
  * between the attacker and target.\n
  */
-bool clean_shot(POSITION y1, POSITION x1, POSITION y2, POSITION x2, bool is_friend)
+bool clean_shot(player_type *target_ptr, POSITION y1, POSITION x1, POSITION y2, POSITION x2, bool is_friend)
 {
        /* Must be the same as projectable() */
 
@@ -484,7 +484,8 @@ bool clean_shot(POSITION y1, POSITION x1, POSITION y2, POSITION x2, bool is_frie
        u16b grid_g[512];
 
        /* Check the projection path */
-       grid_n = project_path(p_ptr->current_floor_ptr, grid_g, MAX_RANGE, y1, x1, y2, x2, 0);
+       floor_type *floor_ptr = target_ptr->current_floor_ptr;
+       grid_n = project_path(floor_ptr, grid_g, MAX_RANGE, y1, x1, y2, x2, 0);
 
        /* No grid is ever projectable from itself */
        if (!grid_n) return FALSE;
@@ -501,16 +502,17 @@ bool clean_shot(POSITION y1, POSITION x1, POSITION y2, POSITION x2, bool is_frie
                y = GRID_Y(grid_g[i]);
                x = GRID_X(grid_g[i]);
 
-               if ((p_ptr->current_floor_ptr->grid_array[y][x].m_idx > 0) && !((y == y2) && (x == x2)))
+               if ((floor_ptr->grid_array[y][x].m_idx > 0) && !((y == y2) && (x == x2)))
                {
-                       monster_type *m_ptr = &p_ptr->current_floor_ptr->m_list[p_ptr->current_floor_ptr->grid_array[y][x].m_idx];
+                       monster_type *m_ptr = &floor_ptr->m_list[floor_ptr->grid_array[y][x].m_idx];
                        if (is_friend == is_pet(m_ptr))
                        {
                                return FALSE;
                        }
                }
+
                /* Pets may not shoot through the character - TNB */
-               if (player_bold(p_ptr, y, x))
+               if (player_bold(target_ptr, y, x))
                {
                        if (is_friend) return FALSE;
                }
@@ -523,7 +525,7 @@ bool clean_shot(POSITION y1, POSITION x1, POSITION y2, POSITION x2, bool is_frie
 /*!
  * @brief モンスターのボルト型魔法処理 /
  * Cast a bolt at the player Stop if we hit a monster Affect monsters and the player
- * @param caster_ptr プレーヤーへの参照ポインタ
+ * @param target_ptr プレーヤーへの参照ポインタ
  * @param m_idx モンスターのID
  * @param y 目標のY座標
  * @param x 目標のX座標
@@ -556,7 +558,7 @@ void bolt(MONSTER_IDX m_idx, POSITION y, POSITION x, EFFECT_ID typ, int dam_hp,
 
 /*!
  * @brief モンスターのビーム型魔法処理 /
- * @param caster_ptr プレーヤーへの参照ポインタ
+ * @param target_ptr プレーヤーへの参照ポインタ
  * @param m_idx モンスターのID
  * @param y 目標のY座標
  * @param x 目標のX座標
@@ -589,7 +591,7 @@ void beam(MONSTER_IDX m_idx, POSITION y, POSITION x, EFFECT_ID typ, int dam_hp,
 /*!
  * @brief モンスターのボール型&ブレス型魔法処理 /
  * Cast a breath (or ball) attack at the player Pass over any monsters that may be in the way Affect grids, objects, monsters, and the player
- * @param caster_ptr プレーヤーへの参照ポインタ
+ * @param target_ptr プレーヤーへの参照ポインタ
  * @param y 目標地点のY座標
  * @param x 目標地点のX座標
  * @param m_idx モンスターのID
@@ -820,7 +822,7 @@ static bool spell_world(byte spell)
 /*!
  * @brief ID値が特別効果のモンスター魔法IDかどうかを返す /
  * Return TRUE if a spell special.
- * @param caster_ptr プレーヤーへの参照ポインタ
+ * @param target_ptr プレーヤーへの参照ポインタ
  * @param spell 判定対象のID
  * @return 特別効果魔法のIDならばTRUEを返す。
  */
@@ -986,7 +988,7 @@ bool dispel_check(player_type *creature_ptr, MONSTER_IDX m_idx)
 /*!
  * @brief モンスターの魔法選択ルーチン
  * Have a monster choose a spell from a list of "useful" spells.
- * @param caster_ptr プレーヤーへの参照ポインタ
+ * @param target_ptr プレーヤーへの参照ポインタ
  * @param m_idx モンスターの構造体配列ID
  * @param spells 候補魔法IDをまとめた配列
  * @param num spellsの長さ
@@ -1254,7 +1256,7 @@ bool spell_is_inate(SPELL_IDX spell)
 
 /*!
  * @brief モンスターがプレイヤーにダメージを与えるための最適な座標を算出する /
- * @param caster_ptr プレーヤーへの参照ポインタ
+ * @param target_ptr プレーヤーへの参照ポインタ
  * @param m_ptr 技能を使用するモンスター構造体の参照ポインタ
  * @param yp 最適な目標地点のY座標を返す参照ポインタ
  * @param xp 最適な目標地点のX座標を返す参照ポインタ
@@ -1309,7 +1311,7 @@ static bool adjacent_grid_check(monster_type *m_ptr, POSITION *yp, POSITION *xp,
  * todo メインルーチンの割に長過ぎる。要分割
  * @brief モンスターの特殊技能メインルーチン /
  * Creatures can cast spells, shoot missiles, and breathe.
- * @param caster_ptr プレーヤーへの参照ポインタ
+ * @param target_ptr プレーヤーへの参照ポインタ
  * @param m_idx モンスター構造体配列のID
  * @return 実際に特殊技能を利用したらTRUEを返す
  * @details
@@ -1613,7 +1615,7 @@ bool make_attack_spell(MONSTER_IDX m_idx, player_type *target_ptr)
                if (((f4 & RF4_BOLT_MASK) ||
                     (f5 & RF5_BOLT_MASK) ||
                     (f6 & RF6_BOLT_MASK)) &&
-                   !clean_shot(m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x, FALSE))
+                   !clean_shot(target_ptr, m_ptr->fy, m_ptr->fx, target_ptr->y, target_ptr->x, FALSE))
                {
                        /* Remove spells that will only hurt friends */
                        f4 &= ~(RF4_BOLT_MASK);
index 29da087..bd3460c 100644 (file)
@@ -588,7 +588,7 @@ bool monst_spell_monst(player_type *target_ptr, MONSTER_IDX m_idx)
                if (((f4 & RF4_BOLT_MASK) ||
                     (f5 & RF5_BOLT_MASK) ||
                     (f6 & RF6_BOLT_MASK)) &&
-                   !clean_shot(m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, pet))
+                   !clean_shot(target_ptr, m_ptr->fy, m_ptr->fx, t_ptr->fy, t_ptr->fx, pet))
                {
                        f4 &= ~(RF4_BOLT_MASK);
                        f5 &= ~(RF5_BOLT_MASK);