From b42e6a2289236371a69ac5a70e401096cbe335c8 Mon Sep 17 00:00:00 2001 From: Hourier Date: Mon, 13 Jan 2020 17:09:51 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#38997=20monster-status.c=20?= =?utf8?q?=E3=81=AE=E6=95=B4=E5=BD=A2=20/=20Reshaped=20monster-status.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/monster-status.c | 343 +++++++++++++++++++++++++++------------------------ 1 file changed, 183 insertions(+), 160 deletions(-) diff --git a/src/monster-status.c b/src/monster-status.c index 2d6853c6e..9f26c4c38 100644 --- a/src/monster-status.c +++ b/src/monster-status.c @@ -40,6 +40,7 @@ bool monster_is_powerful(floor_type *floor_ptr, MONSTER_IDX m_idx) return powerful; } + /*! * @brief モンスターIDからモンスターのレベルを取得する(ただし最低1を保証する) / * @param m_idx モンスターID @@ -53,6 +54,7 @@ DEPTH monster_level_idx(floor_type *floor_ptr, MONSTER_IDX m_idx) return rlev; } + /*! * @brief モンスターに与えたダメージの修正処理 / * Modify the physical damage done to the monster. @@ -90,10 +92,11 @@ HIT_POINT mon_damage_mod(player_type *target_ptr, monster_type *m_ptr, HIT_POINT } else if (!one_in_(PENETRATE_INVULNERABILITY)) { - return (0); + return 0; } } - return (dam); + + return dam; } @@ -115,14 +118,18 @@ static void get_exp_from_mon(player_type *target_ptr, HIT_POINT dam, monster_typ { monster_race *r_ptr = &r_info[m_ptr->r_idx]; + if (!monster_is_valid(m_ptr)) return; + if (is_pet(m_ptr) || target_ptr->phase_out) return; + + /*! + * todo 変数宣言と代入を同時に実行するとコンパイル警告が出る + * ここの整形は実施せず保留 + */ s32b new_exp; u32b new_exp_frac; s32b div_h; u32b div_l; - if (!monster_is_valid(m_ptr)) return; - if (is_pet(m_ptr) || target_ptr->phase_out) return; - /* * - Ratio of monster's level to player's level effects * - Varying speed effects @@ -173,14 +180,11 @@ static void get_exp_from_mon(player_type *target_ptr, HIT_POINT dam, monster_typ } } - /* Finally multiply base experience point of the monster */ s64b_mul(&new_exp, &new_exp_frac, 0, r_ptr->mexp); - gain_exp_64(target_ptr, new_exp, new_exp_frac); } - /*! * @brief モンスターの時限ステータスを取得する * @param floor_ptr 現在フロアへの参照ポインタ @@ -191,9 +195,7 @@ static void get_exp_from_mon(player_type *target_ptr, HIT_POINT dam, monster_typ int get_mproc_idx(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_type) { s16b *cur_mproc_list = floor_ptr->mproc_list[mproc_type]; - int i; - - for (i = floor_ptr->mproc_max[mproc_type] - 1; i >= 0; i--) + for (int i = floor_ptr->mproc_max[mproc_type] - 1; i >= 0; i--) { if (cur_mproc_list[i] == m_idx) return i; } @@ -201,6 +203,7 @@ int get_mproc_idx(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_type) return -1; } + /*! * @brief モンスターの時限ステータスリストを追加する * @param floor_ptr 現在フロアへの参照ポインタ @@ -210,7 +213,10 @@ int get_mproc_idx(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_type) */ static void mproc_add(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_type) { - if (floor_ptr->mproc_max[mproc_type] < current_world_ptr->max_m_idx) floor_ptr->mproc_list[mproc_type][floor_ptr->mproc_max[mproc_type]++] = (s16b)m_idx; + if (floor_ptr->mproc_max[mproc_type] < current_world_ptr->max_m_idx) + { + floor_ptr->mproc_list[mproc_type][floor_ptr->mproc_max[mproc_type]++] = (s16b)m_idx; + } } @@ -224,7 +230,10 @@ static void mproc_add(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_type) static void mproc_remove(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_type) { int mproc_idx = get_mproc_idx(floor_ptr, m_idx, mproc_type); - if (mproc_idx >= 0) floor_ptr->mproc_list[mproc_type][mproc_idx] = floor_ptr->mproc_list[mproc_type][--floor_ptr->mproc_max[mproc_type]]; + if (mproc_idx >= 0) + { + floor_ptr->mproc_list[mproc_type][mproc_idx] = floor_ptr->mproc_list[mproc_type][--floor_ptr->mproc_max[mproc_type]]; + } } @@ -235,22 +244,22 @@ static void mproc_remove(floor_type *floor_ptr, MONSTER_IDX m_idx, int mproc_typ */ void mproc_init(floor_type *floor_ptr) { - monster_type *m_ptr; - MONSTER_IDX i; - int cmi; - /* Reset "target_ptr->current_floor_ptr->mproc_max[]" */ - for (cmi = 0; cmi < MAX_MTIMED; cmi++) floor_ptr->mproc_max[cmi] = 0; + for (int i = 0; i < MAX_MTIMED; i++) + { + floor_ptr->mproc_max[i] = 0; + } /* Process the monsters (backwards) */ - for (i = floor_ptr->m_max - 1; i >= 1; i--) + for (MONSTER_IDX i = floor_ptr->m_max - 1; i >= 1; i--) { + monster_type *m_ptr; m_ptr = &floor_ptr->m_list[i]; /* Ignore "dead" monsters */ if (!monster_is_valid(m_ptr)) continue; - for (cmi = 0; cmi < MAX_MTIMED; cmi++) + for (int cmi = 0; cmi < MAX_MTIMED; cmi++) { if (m_ptr->mtimed[cmi]) mproc_add(floor_ptr, i, cmi); } @@ -612,56 +621,53 @@ static void process_monsters_mtimed_aux(player_type *target_ptr, MONSTER_IDX m_i } } - if (test) - { - u32b notice = randint0(1024); + if (!test) break; - /* Nightmare monsters are more alert */ - if (ironman_nightmare) notice /= 2; + u32b notice = randint0(1024); - /* Hack -- See if monster "notices" player */ - if ((notice * notice * notice) <= csleep_noise) - { - /* Hack -- amount of "waking" */ - /* Wake up faster near the player */ - int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1; + /* Nightmare monsters are more alert */ + if (ironman_nightmare) notice /= 2; - /* Hack -- amount of "waking" is affected by speed of player */ - d = (d * SPEED_TO_ENERGY(target_ptr->pspeed)) / 10; - if (d < 0) d = 1; + /* Hack -- See if monster "notices" player */ + if ((notice * notice * notice) > csleep_noise) break; - /* Monster wakes up "a little bit" */ + /* Hack -- amount of "waking" */ + /* Wake up faster near the player */ + int d = (m_ptr->cdis < AAF_LIMIT / 2) ? (AAF_LIMIT / m_ptr->cdis) : 1; - /* Still asleep */ - if (!set_monster_csleep(target_ptr, m_idx, MON_CSLEEP(m_ptr) - d)) - { - /* Notice the "not waking up" */ - if (is_original_ap_and_seen(m_ptr)) - { - /* Hack -- Count the ignores */ - if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++; - } - } + /* Hack -- amount of "waking" is affected by speed of player */ + d = (d * SPEED_TO_ENERGY(target_ptr->pspeed)) / 10; + if (d < 0) d = 1; - /* Just woke up */ - else - { - /* Notice the "waking up" */ - if (m_ptr->ml) - { - GAME_TEXT m_name[MAX_NLEN]; - monster_desc(m_name, m_ptr, 0); - msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name); - } - - if (is_original_ap_and_seen(m_ptr)) - { - /* Hack -- Count the wakings */ - if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++; - } - } + /* Monster wakes up "a little bit" */ + + /* Still asleep */ + if (!set_monster_csleep(target_ptr, m_idx, MON_CSLEEP(m_ptr) - d)) + { + /* Notice the "not waking up" */ + if (is_original_ap_and_seen(m_ptr)) + { + /* Hack -- Count the ignores */ + if (r_ptr->r_ignore < MAX_UCHAR) r_ptr->r_ignore++; } + + break; + } + + /* Notice the "waking up" */ + if (m_ptr->ml) + { + GAME_TEXT m_name[MAX_NLEN]; + monster_desc(m_name, m_ptr, 0); + msg_format(_("%^sが目を覚ました。", "%^s wakes up."), m_name); } + + if (is_original_ap_and_seen(m_ptr)) + { + /* Hack -- Count the wakings */ + if (r_ptr->r_wake < MAX_UCHAR) r_ptr->r_wake++; + } + break; } @@ -676,6 +682,7 @@ static void process_monsters_mtimed_aux(player_type *target_ptr, MONSTER_IDX m_i msg_format(_("%^sはもう加速されていない。", "%^s is no longer fast."), m_name); } } + break; case MTIMED_SLOW: @@ -689,6 +696,7 @@ static void process_monsters_mtimed_aux(player_type *target_ptr, MONSTER_IDX m_i msg_format(_("%^sはもう減速されていない。", "%^s is no longer slow."), m_name); } } + break; case MTIMED_STUNNED: @@ -706,61 +714,70 @@ static void process_monsters_mtimed_aux(player_type *target_ptr, MONSTER_IDX m_i msg_format(_("%^sは朦朧状態から立ち直った。", "%^s is no longer stunned."), m_name); } } + break; } case MTIMED_CONFUSED: + { /* Reduce the confusion */ - if (set_monster_confused(target_ptr, m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1))) + if (!set_monster_confused(target_ptr, m_idx, MON_CONFUSED(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1))) + break; + /* Message if visible */ + if (is_seen(m_ptr)) { - /* Message if visible */ - if (is_seen(m_ptr)) - { - GAME_TEXT m_name[MAX_NLEN]; - monster_desc(m_name, m_ptr, 0); - msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name); - } + GAME_TEXT m_name[MAX_NLEN]; + monster_desc(m_name, m_ptr, 0); + msg_format(_("%^sは混乱から立ち直った。", "%^s is no longer confused."), m_name); } + break; + } case MTIMED_MONFEAR: + { /* Reduce the fear */ - if (set_monster_monfear(target_ptr, m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1))) + if (!set_monster_monfear(target_ptr, m_idx, MON_MONFEAR(m_ptr) - randint1(r_info[m_ptr->r_idx].level / 20 + 1))) + break; + + /* Visual note */ + if (is_seen(m_ptr)) { - /* Visual note */ - if (is_seen(m_ptr)) - { - GAME_TEXT m_name[MAX_NLEN]; + GAME_TEXT m_name[MAX_NLEN]; #ifndef JP - char m_poss[80]; + char m_poss[80]; - /* Acquire the monster possessive */ - monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE); + /* Acquire the monster possessive */ + monster_desc(m_poss, m_ptr, MD_PRON_VISIBLE | MD_POSSESSIVE); #endif - monster_desc(m_name, m_ptr, 0); + monster_desc(m_name, m_ptr, 0); #ifdef JP - msg_format("%^sは勇気を取り戻した。", m_name); + msg_format("%^sは勇気を取り戻した。", m_name); #else - msg_format("%^s recovers %s courage.", m_name, m_poss); + msg_format("%^s recovers %s courage.", m_name, m_poss); #endif - } } + break; + } case MTIMED_INVULNER: + { /* Reduce by one, note if expires */ - if (set_monster_invulner(target_ptr, m_idx, MON_INVULNER(m_ptr) - 1, TRUE)) + if (!set_monster_invulner(target_ptr, m_idx, MON_INVULNER(m_ptr) - 1, TRUE)) + break; + + if (is_seen(m_ptr)) { - if (is_seen(m_ptr)) - { - GAME_TEXT m_name[MAX_NLEN]; - monster_desc(m_name, m_ptr, 0); - msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name); - } + GAME_TEXT m_name[MAX_NLEN]; + monster_desc(m_name, m_ptr, 0); + msg_format(_("%^sはもう無敵でない。", "%^s is no longer invulnerable."), m_name); } + break; } } +} /*! @@ -774,7 +791,6 @@ static void process_monsters_mtimed_aux(player_type *target_ptr, MONSTER_IDX m_i */ void process_monsters_mtimed(player_type *target_ptr, int mtimed_idx) { - int i; floor_type *floor_ptr = target_ptr->current_floor_ptr; s16b *cur_mproc_list = floor_ptr->mproc_list[mtimed_idx]; @@ -782,7 +798,7 @@ void process_monsters_mtimed(player_type *target_ptr, int mtimed_idx) if (mtimed_idx == MTIMED_CSLEEP) csleep_noise = (1L << (30 - target_ptr->skill_stl)); /* Process the monsters (backwards) */ - for (i = floor_ptr->mproc_max[mtimed_idx] - 1; i >= 0; i--) + for (int i = floor_ptr->mproc_max[mtimed_idx] - 1; i >= 0; i--) { process_monsters_mtimed_aux(target_ptr, cur_mproc_list[i], mtimed_idx); } @@ -805,16 +821,19 @@ void dispel_monster_status(player_type *target_ptr, MONSTER_IDX m_idx) { if (m_ptr->ml) msg_format(_("%sはもう無敵ではない。", "%^s is no longer invulnerable."), m_name); } + if (set_monster_fast(target_ptr, m_idx, 0)) { if (m_ptr->ml) msg_format(_("%sはもう加速されていない。", "%^s is no longer fast."), m_name); } + if (set_monster_slow(target_ptr, m_idx, 0)) { if (m_ptr->ml) msg_format(_("%sはもう減速されていない。", "%^s is no longer slow."), m_name); } } + /*! * @brief モンスターの時間停止処理 * @param target_ptr プレーヤーへの参照ポインタ @@ -885,7 +904,6 @@ void monster_gain_exp(player_type *target_ptr, MONSTER_IDX m_idx, MONRACE_IDX s_ monster_type *m_ptr; monster_race *r_ptr; monster_race *s_ptr; - int new_exp; if (m_idx <= 0 || s_idx <= 0) return; floor_type *floor_ptr = target_ptr->current_floor_ptr; @@ -900,94 +918,100 @@ void monster_gain_exp(player_type *target_ptr, MONSTER_IDX m_idx, MONRACE_IDX s_ if (!r_ptr->next_exp) return; - new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2); + int new_exp = s_ptr->mexp * s_ptr->level / (r_ptr->level + 2); if (m_idx == target_ptr->riding) new_exp = (new_exp + 1) / 2; if (!floor_ptr->dun_level) new_exp /= 5; m_ptr->exp += new_exp; if (m_ptr->mflag2 & MFLAG2_CHAMELEON) return; - if (m_ptr->exp >= r_ptr->next_exp) + if (m_ptr->exp < r_ptr->next_exp) { - GAME_TEXT m_name[MAX_NLEN]; - int old_hp = m_ptr->hp; - int old_maxhp = m_ptr->max_maxhp; - int old_r_idx = m_ptr->r_idx; - byte old_sub_align = m_ptr->sub_align; + if (m_idx == target_ptr->riding) target_ptr->update |= PU_BONUS; + return; + } - /* Hack -- Reduce the racial counter of previous monster */ - real_r_ptr(m_ptr)->cur_num--; + GAME_TEXT m_name[MAX_NLEN]; + int old_hp = m_ptr->hp; + int old_maxhp = m_ptr->max_maxhp; + int old_r_idx = m_ptr->r_idx; + byte old_sub_align = m_ptr->sub_align; - monster_desc(m_name, m_ptr, 0); - m_ptr->r_idx = r_ptr->next_r_idx; + /* Hack -- Reduce the racial counter of previous monster */ + real_r_ptr(m_ptr)->cur_num--; - /* Count the monsters on the level */ - real_r_ptr(m_ptr)->cur_num++; + monster_desc(m_name, m_ptr, 0); + m_ptr->r_idx = r_ptr->next_r_idx; - m_ptr->ap_r_idx = m_ptr->r_idx; - r_ptr = &r_info[m_ptr->r_idx]; + /* Count the monsters on the level */ + real_r_ptr(m_ptr)->cur_num++; - if (r_ptr->flags1 & RF1_FORCE_MAXHP) - { - m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside); - } - else - { - m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside); - } - if (ironman_nightmare) - { - HIT_POINT hp = m_ptr->max_maxhp * 2L; - m_ptr->max_maxhp = MIN(30000, hp); - } - m_ptr->maxhp = m_ptr->max_maxhp; - m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp; + m_ptr->ap_r_idx = m_ptr->r_idx; + r_ptr = &r_info[m_ptr->r_idx]; + + if (r_ptr->flags1 & RF1_FORCE_MAXHP) + { + m_ptr->max_maxhp = maxroll(r_ptr->hdice, r_ptr->hside); + } + else + { + m_ptr->max_maxhp = damroll(r_ptr->hdice, r_ptr->hside); + } + if (ironman_nightmare) + { + HIT_POINT hp = m_ptr->max_maxhp * 2L; + m_ptr->max_maxhp = MIN(30000, hp); + } - /* dealt damage is 0 at initial*/ - m_ptr->dealt_damage = 0; + m_ptr->maxhp = m_ptr->max_maxhp; + m_ptr->hp = old_hp * m_ptr->maxhp / old_maxhp; - /* Extract the monster base speed */ - m_ptr->mspeed = get_mspeed(r_ptr); + /* dealt damage is 0 at initial*/ + m_ptr->dealt_damage = 0; - /* Sub-alignment of a monster */ - if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))) - m_ptr->sub_align = old_sub_align; - else - { - m_ptr->sub_align = SUB_ALIGN_NEUTRAL; - if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL; - if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD; - } + /* Extract the monster base speed */ + m_ptr->mspeed = get_mspeed(r_ptr); - m_ptr->exp = 0; + /* Sub-alignment of a monster */ + if (!is_pet(m_ptr) && !(r_ptr->flags3 & (RF3_EVIL | RF3_GOOD))) + m_ptr->sub_align = old_sub_align; + else + { + m_ptr->sub_align = SUB_ALIGN_NEUTRAL; + if (r_ptr->flags3 & RF3_EVIL) m_ptr->sub_align |= SUB_ALIGN_EVIL; + if (r_ptr->flags3 & RF3_GOOD) m_ptr->sub_align |= SUB_ALIGN_GOOD; + } - if (is_pet(m_ptr) || m_ptr->ml) + m_ptr->exp = 0; + + if (is_pet(m_ptr) || m_ptr->ml) + { + if (!ignore_unview || player_can_see_bold(target_ptr, m_ptr->fy, m_ptr->fx)) { - if (!ignore_unview || player_can_see_bold(target_ptr, m_ptr->fy, m_ptr->fx)) + if (target_ptr->image) { - if (target_ptr->image) - { - monster_race *hallu_race; + monster_race *hallu_race; - do - { - hallu_race = &r_info[randint1(max_r_idx - 1)]; - } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE)); - msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name); - } - else + do { - msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name); - } + hallu_race = &r_info[randint1(max_r_idx - 1)]; + } while (!hallu_race->name || (hallu_race->flags1 & RF1_UNIQUE)); + msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + hallu_race->name); + } + else + { + msg_format(_("%sは%sに進化した。", "%^s evolved into %s."), m_name, r_name + r_ptr->name); } + } - if (!target_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA; + if (!target_ptr->image) r_info[old_r_idx].r_xtra1 |= MR1_SINKA; - /* Now you feel very close to this pet. */ - m_ptr->parent_m_idx = 0; - } - update_monster(target_ptr, m_idx, FALSE); - lite_spot(m_ptr->fy, m_ptr->fx); + /* Now you feel very close to this pet. */ + m_ptr->parent_m_idx = 0; } + + update_monster(target_ptr, m_idx, FALSE); + lite_spot(m_ptr->fy, m_ptr->fx); + if (m_idx == target_ptr->riding) target_ptr->update |= PU_BONUS; } @@ -1314,7 +1338,7 @@ bool mon_take_hit(player_type *target_ptr, MONSTER_IDX m_idx, HIT_POINT dam, boo for (i = 0; i < 4; i++) { if (r_ptr->blow[i].method == RBM_EXPLODE) explode = TRUE; - } + } /* Special note at death */ if (explode) @@ -1330,7 +1354,7 @@ bool mon_take_hit(player_type *target_ptr, MONSTER_IDX m_idx, HIT_POINT dam, boo msg_format("You have destroyed %s.", m_name); #endif } - } + } /* Death by Physical attack -- living monster */ else @@ -1385,8 +1409,7 @@ bool mon_take_hit(player_type *target_ptr, MONSTER_IDX m_idx, HIT_POINT dam, boo /* Monster is dead */ return TRUE; - } - +} #ifdef ALLOW_FEAR -- 2.11.0