From fb5f4f1942d91e75bb172bafff5e5d3c582845f5 Mon Sep 17 00:00:00 2001 From: Hourier Date: Sat, 18 Jan 2020 22:20:48 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#38997=20monster=5Fhas=5Fhostile=5F?= =?utf8?q?align()=E3=81=ABplayer=5Ftype=20*=20=E5=BC=95=E6=95=B0=E3=82=92?= =?utf8?q?=E8=BF=BD=E5=8A=A0=20/=20Added=20player=5Ftype=20*=20argument=20?= =?utf8?q?to=20monster=5Fhas=5Fhostile=5Falign()?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/monster.h | 2 +- src/monster1.c | 7 ++++--- src/monster2.c | 18 +++++++++--------- src/rooms-pitnest.c | 6 +++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/monster.h b/src/monster.h index d0a974b34..0d632029a 100644 --- a/src/monster.h +++ b/src/monster.h @@ -457,7 +457,7 @@ extern bool monster_can_cross_terrain(player_type *player_ptr, FEAT_IDX feat, mo extern bool monster_can_enter(player_type *player_ptr, POSITION y, POSITION x, monster_race *r_ptr, BIT_FLAGS16 mode); extern bool are_enemies(player_type *player_ptr, monster_type *m_ptr1, monster_type *m_ptr2); -extern bool monster_has_hostile_align(monster_type *m_ptr, int pa_good, int pa_evil, monster_race *r_ptr); +extern bool monster_has_hostile_align(player_type *player_ptr, monster_type *m_ptr, int pa_good, int pa_evil, monster_race *r_ptr); extern void dice_to_string(int base_damage, int dice_num, int dice_side, int dice_mult, int dice_div, char* msg); extern concptr look_mon_desc(monster_type *m_ptr, BIT_FLAGS mode); extern int get_monster_crowd_number(player_type *player_ptr, MONSTER_IDX m_idx); diff --git a/src/monster1.c b/src/monster1.c index b8bfac055..482a1025c 100644 --- a/src/monster1.c +++ b/src/monster1.c @@ -2285,6 +2285,7 @@ bool are_enemies(player_type *player_ptr, monster_type *m_ptr, monster_type *n_p /*! * @brief モンスターがプレイヤーに対して敵意を抱くかどうかを返す * Check if this monster race has "hostile" alignment + * @param player_ptr プレーヤーへの参照ポインタ * @param m_ptr モンスター情報構造体の参照ポインタ * @param pa_good プレイヤーの善傾向値 * @param pa_evil プレイヤーの悪傾向値 @@ -2293,7 +2294,7 @@ bool are_enemies(player_type *player_ptr, monster_type *m_ptr, monster_type *n_p * @details * If user is player, m_ptr == NULL. */ -bool monster_has_hostile_align(monster_type *m_ptr, int pa_good, int pa_evil, monster_race *r_ptr) +bool monster_has_hostile_align(player_type *player_ptr, monster_type *m_ptr, int pa_good, int pa_evil, monster_race *r_ptr) { byte sub_align1 = SUB_ALIGN_NEUTRAL; byte sub_align2 = SUB_ALIGN_NEUTRAL; @@ -2304,8 +2305,8 @@ bool monster_has_hostile_align(monster_type *m_ptr, int pa_good, int pa_evil, mo } else /* For player */ { - if (p_ptr->align >= pa_good) sub_align1 |= SUB_ALIGN_GOOD; - if (p_ptr->align <= pa_evil) sub_align1 |= SUB_ALIGN_EVIL; + if (player_ptr->align >= pa_good) sub_align1 |= SUB_ALIGN_GOOD; + if (player_ptr->align <= pa_evil) sub_align1 |= SUB_ALIGN_EVIL; } /* Racial alignment flags */ diff --git a/src/monster2.c b/src/monster2.c index 8b4281fa0..18fcf3285 100644 --- a/src/monster2.c +++ b/src/monster2.c @@ -2193,13 +2193,13 @@ static bool monster_hook_chameleon_lord(MONRACE_IDX r_idx) /* Not born */ if (!(old_r_ptr->flags7 & RF7_CHAMELEON)) { - if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE; + if (monster_has_hostile_align(p_ptr, m_ptr, 0, 0, r_ptr)) return FALSE; } /* Born now */ else if (summon_specific_who > 0) { - if (monster_has_hostile_align(&floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE; + if (monster_has_hostile_align(p_ptr, &floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE; } return TRUE; @@ -2241,7 +2241,7 @@ static bool monster_hook_chameleon(MONRACE_IDX r_idx) /* Born now */ else if (summon_specific_who > 0) { - if (monster_has_hostile_align(&floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE; + if (monster_has_hostile_align(p_ptr, &floor_ptr->m_list[summon_specific_who], 0, 0, r_ptr)) return FALSE; } return (*(get_monster_hook(p_ptr)))(r_idx); @@ -2663,7 +2663,7 @@ static bool place_monster_one(player_type *player_ptr, MONSTER_IDX who, POSITION else if ((r_ptr->flags7 & RF7_FRIENDLY) || (mode & PM_FORCE_FRIENDLY) || is_friendly_idx(player_ptr, who)) { - if (!monster_has_hostile_align(NULL, 0, -1, r_ptr)) set_friendly(m_ptr); + if (!monster_has_hostile_align(player_ptr, NULL, 0, -1, r_ptr)) set_friendly(m_ptr); } /* Assume no sleeping */ @@ -3032,11 +3032,11 @@ static bool place_monster_can_escort(MONRACE_IDX r_idx) if (place_monster_idx == r_idx) return FALSE; /* Skip different alignment */ - if (monster_has_hostile_align(m_ptr, 0, 0, z_ptr)) return FALSE; + if (monster_has_hostile_align(p_ptr, m_ptr, 0, 0, z_ptr)) return FALSE; if (r_ptr->flags7 & RF7_FRIENDLY) { - if (monster_has_hostile_align(NULL, 1, -1, z_ptr)) return FALSE; + if (monster_has_hostile_align(p_ptr, NULL, 1, -1, z_ptr)) return FALSE; } if ((r_ptr->flags7 & RF7_CHAMELEON) && !(z_ptr->flags7 & RF7_CHAMELEON)) @@ -3370,13 +3370,13 @@ static bool summon_specific_okay(MONRACE_IDX r_idx) /* Do not summon enemies */ /* Friendly vs. opposite aligned normal or pet */ - if (monster_has_hostile_align(m_ptr, 0, 0, r_ptr)) return FALSE; + if (monster_has_hostile_align(p_ptr, m_ptr, 0, 0, r_ptr)) return FALSE; } /* Use the player's alignment */ else if (summon_specific_who < 0) { /* Do not summon enemies of the pets */ - if (monster_has_hostile_align(NULL, 10, -10, r_ptr)) + if (monster_has_hostile_align(p_ptr, NULL, 10, -10, r_ptr)) { if (!one_in_(ABS(p_ptr->align) / 2 + 1)) return FALSE; } @@ -3389,7 +3389,7 @@ static bool summon_specific_okay(MONRACE_IDX r_idx) if ((summon_specific_who < 0) && ((r_ptr->flags1 & RF1_UNIQUE) || (r_ptr->flags7 & RF7_NAZGUL)) && - monster_has_hostile_align(NULL, 10, -10, r_ptr)) + monster_has_hostile_align(p_ptr, NULL, 10, -10, r_ptr)) return FALSE; if ((r_ptr->flags7 & RF7_CHAMELEON) && (d_info[p_ptr->dungeon_idx].flags1 & DF1_CHAMELEON)) return TRUE; diff --git a/src/rooms-pitnest.c b/src/rooms-pitnest.c index c12fa0857..252809d07 100644 --- a/src/rooms-pitnest.c +++ b/src/rooms-pitnest.c @@ -323,7 +323,7 @@ bool build_type5(player_type *player_ptr) r_ptr = &r_info[r_idx]; /* Decline incorrect alignment */ - if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue; + if (monster_has_hostile_align(player_ptr, &align, 0, 0, r_ptr)) continue; /* Accept this monster */ break; @@ -533,7 +533,7 @@ bool build_type6(player_type *player_ptr) r_ptr = &r_info[r_idx]; /* Decline incorrect alignment */ - if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue; + if (monster_has_hostile_align(player_ptr, &align, 0, 0, r_ptr)) continue; /* Accept this monster */ break; @@ -842,7 +842,7 @@ bool build_type13(player_type *player_ptr) r_ptr = &r_info[r_idx]; /* Decline incorrect alignment */ - if (monster_has_hostile_align(&align, 0, 0, r_ptr)) continue; + if (monster_has_hostile_align(player_ptr, &align, 0, 0, r_ptr)) continue; /* Accept this monster */ break; -- 2.11.0