From f9fef49d4159bf1cf26cafb2f9a74b75dece9f3e Mon Sep 17 00:00:00 2001 From: Hourier Date: Thu, 11 Jun 2020 20:22:58 +0900 Subject: [PATCH] [Refactor] #40014 Moved update_smart_learn() from monster2.c/h to monster-update.c/h --- src/monster-attack/monster-attack-switcher.c | 2 +- src/monster/monster-update.c | 136 +++++++++++++++++++++++ src/monster/monster-update.h | 1 + src/monster/monster2.c | 154 +-------------------------- src/monster/monster2.h | 1 - src/mspell/mspell-ball.c | 4 +- src/mspell/mspell-bolt.c | 2 +- src/mspell/mspell-breath.c | 2 +- src/mspell/mspell-floor.c | 2 +- src/mspell/mspell-particularity.c | 2 +- src/mspell/mspell-status.c | 2 +- 11 files changed, 146 insertions(+), 162 deletions(-) diff --git a/src/monster-attack/monster-attack-switcher.c b/src/monster-attack/monster-attack-switcher.c index 0b89f6b5f..dbca9e330 100644 --- a/src/monster-attack/monster-attack-switcher.c +++ b/src/monster-attack/monster-attack-switcher.c @@ -11,7 +11,7 @@ #include "mind/drs-types.h" #include "mind/mind-mirror-master.h" #include "monster/monster-status.h" -#include "monster/monster2.h" +#include "monster/monster-update.h" #include "player/player-damage.h" #include "player/player-effects.h" #include "spell-kind/earthquake.h" diff --git a/src/monster/monster-update.c b/src/monster/monster-update.c index 930b53110..eada1c4c4 100644 --- a/src/monster/monster-update.c +++ b/src/monster/monster-update.c @@ -6,6 +6,7 @@ #include "monster/monster-update.h" #include "dungeon/dungeon.h" +#include "mind/drs-types.h" #include "monster-race/race-flags1.h" #include "monster-race/race-flags2.h" #include "monster-race/race-flags3.h" @@ -14,6 +15,7 @@ #include "monster/monster-flag-types.h" #include "monster/monster-info.h" #include "monster/monster-status.h" +#include "monster/smart-learn-types.h" #include "player/eldritch-horror.h" #include "player/player-move.h" @@ -411,3 +413,137 @@ void update_monsters(player_type *player_ptr, bool full) update_monster(player_ptr, i, full); } } + +/*! + * @brief SMART(適格に攻撃を行う)モンスターの学習状況を更新する / Learn about an "observed" resistance. + * @param m_idx 更新を行う「モンスター情報ID + * @param what 学習対象ID + * @return なし + */ +void update_smart_learn(player_type *player_ptr, MONSTER_IDX m_idx, int what) +{ + monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx]; + monster_race *r_ptr = &r_info[m_ptr->r_idx]; + + if (!smart_learn) + return; + if (r_ptr->flags2 & (RF2_STUPID)) + return; + if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) + return; + + switch (what) { + case DRS_ACID: + if (player_ptr->resist_acid) + m_ptr->smart |= (SM_RES_ACID); + if (is_oppose_acid(player_ptr)) + m_ptr->smart |= (SM_OPP_ACID); + if (player_ptr->immune_acid) + m_ptr->smart |= (SM_IMM_ACID); + break; + + case DRS_ELEC: + if (player_ptr->resist_elec) + m_ptr->smart |= (SM_RES_ELEC); + if (is_oppose_elec(player_ptr)) + m_ptr->smart |= (SM_OPP_ELEC); + if (player_ptr->immune_elec) + m_ptr->smart |= (SM_IMM_ELEC); + break; + + case DRS_FIRE: + if (player_ptr->resist_fire) + m_ptr->smart |= (SM_RES_FIRE); + if (is_oppose_fire(player_ptr)) + m_ptr->smart |= (SM_OPP_FIRE); + if (player_ptr->immune_fire) + m_ptr->smart |= (SM_IMM_FIRE); + break; + + case DRS_COLD: + if (player_ptr->resist_cold) + m_ptr->smart |= (SM_RES_COLD); + if (is_oppose_cold(player_ptr)) + m_ptr->smart |= (SM_OPP_COLD); + if (player_ptr->immune_cold) + m_ptr->smart |= (SM_IMM_COLD); + break; + + case DRS_POIS: + if (player_ptr->resist_pois) + m_ptr->smart |= (SM_RES_POIS); + if (is_oppose_pois(player_ptr)) + m_ptr->smart |= (SM_OPP_POIS); + break; + + case DRS_NETH: + if (player_ptr->resist_neth) + m_ptr->smart |= (SM_RES_NETH); + break; + + case DRS_LITE: + if (player_ptr->resist_lite) + m_ptr->smart |= (SM_RES_LITE); + break; + + case DRS_DARK: + if (player_ptr->resist_dark) + m_ptr->smart |= (SM_RES_DARK); + break; + + case DRS_FEAR: + if (player_ptr->resist_fear) + m_ptr->smart |= (SM_RES_FEAR); + break; + + case DRS_CONF: + if (player_ptr->resist_conf) + m_ptr->smart |= (SM_RES_CONF); + break; + + case DRS_CHAOS: + if (player_ptr->resist_chaos) + m_ptr->smart |= (SM_RES_CHAOS); + break; + + case DRS_DISEN: + if (player_ptr->resist_disen) + m_ptr->smart |= (SM_RES_DISEN); + break; + + case DRS_BLIND: + if (player_ptr->resist_blind) + m_ptr->smart |= (SM_RES_BLIND); + break; + + case DRS_NEXUS: + if (player_ptr->resist_nexus) + m_ptr->smart |= (SM_RES_NEXUS); + break; + + case DRS_SOUND: + if (player_ptr->resist_sound) + m_ptr->smart |= (SM_RES_SOUND); + break; + + case DRS_SHARD: + if (player_ptr->resist_shard) + m_ptr->smart |= (SM_RES_SHARD); + break; + + case DRS_FREE: + if (player_ptr->free_act) + m_ptr->smart |= (SM_IMM_FREE); + break; + + case DRS_MANA: + if (!player_ptr->msp) + m_ptr->smart |= (SM_IMM_MANA); + break; + + case DRS_REFLECT: + if (player_ptr->reflect) + m_ptr->smart |= (SM_IMM_REFLECT); + break; + } +} diff --git a/src/monster/monster-update.h b/src/monster/monster-update.h index 07482e87d..101f5a6e4 100644 --- a/src/monster/monster-update.h +++ b/src/monster/monster-update.h @@ -10,3 +10,4 @@ void update_monster_race_flags(player_type *target_ptr, turn_flags *turn_flags_p void update_player_window(player_type *target_ptr, old_race_flags *old_race_flags_ptr); void update_monster(player_type *subject_ptr, MONSTER_IDX m_idx, bool full); void update_monsters(player_type *player_ptr, bool full); +void update_smart_learn(player_type *player_ptr, MONSTER_IDX m_idx, int what); diff --git a/src/monster/monster2.c b/src/monster/monster2.c index 6e6ecfe5f..77b903da6 100644 --- a/src/monster/monster2.c +++ b/src/monster/monster2.c @@ -10,40 +10,22 @@ */ #include "monster/monster2.h" -#include "core/player-processor.h" #include "core/speed-table.h" #include "dungeon/dungeon.h" -#include "dungeon/quest.h" -#include "effect/effect-characteristics.h" #include "floor/floor-object.h" #include "floor/wild.h" -#include "io/files-util.h" -#include "main/sound-definitions-table.h" -#include "mind/drs-types.h" -#include "monster-race/monster-race-hook.h" #include "monster-race/race-flags1.h" #include "monster-race/race-flags2.h" #include "monster-race/race-flags3.h" #include "monster-race/race-flags7.h" #include "monster-race/race-indice-types.h" -#include "monster/monster-describer.h" // todo 相互参照している. -#include "monster/monster-flag-types.h" +#include "monster/monster-describer.h" #include "monster/monster-generator.h" #include "monster/monster-info.h" #include "monster/monster-update.h" #include "monster/monster-util.h" -#include "monster/place-monster-types.h" -#include "monster/smart-learn-types.h" -#include "mspell/summon-checker.h" -#include "object/object-flavor.h" #include "object/object-generator.h" -#include "object/warning.h" #include "pet/pet-fall-off.h" -#include "player/eldritch-horror.h" -#include "player/player-move.h" -#include "spell/process-effect.h" -#include "spell/spells-summon.h" -#include "spell/spells-type.h" #include "world/world.h" #define HORDE_NOGOOD 0x01 /*!< (未実装フラグ)HORDE生成でGOODなモンスターの生成を禁止する? */ @@ -443,140 +425,6 @@ SPEED get_mspeed(player_type *player_ptr, monster_race *r_ptr) } /*! - * @brief SMART(適格に攻撃を行う)モンスターの学習状況を更新する / Learn about an "observed" resistance. - * @param m_idx 更新を行う「モンスター情報ID - * @param what 学習対象ID - * @return なし - */ -void update_smart_learn(player_type *player_ptr, MONSTER_IDX m_idx, int what) -{ - monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx]; - monster_race *r_ptr = &r_info[m_ptr->r_idx]; - - if (!smart_learn) - return; - if (r_ptr->flags2 & (RF2_STUPID)) - return; - if (!(r_ptr->flags2 & (RF2_SMART)) && (randint0(100) < 50)) - return; - - switch (what) { - case DRS_ACID: - if (player_ptr->resist_acid) - m_ptr->smart |= (SM_RES_ACID); - if (is_oppose_acid(player_ptr)) - m_ptr->smart |= (SM_OPP_ACID); - if (player_ptr->immune_acid) - m_ptr->smart |= (SM_IMM_ACID); - break; - - case DRS_ELEC: - if (player_ptr->resist_elec) - m_ptr->smart |= (SM_RES_ELEC); - if (is_oppose_elec(player_ptr)) - m_ptr->smart |= (SM_OPP_ELEC); - if (player_ptr->immune_elec) - m_ptr->smart |= (SM_IMM_ELEC); - break; - - case DRS_FIRE: - if (player_ptr->resist_fire) - m_ptr->smart |= (SM_RES_FIRE); - if (is_oppose_fire(player_ptr)) - m_ptr->smart |= (SM_OPP_FIRE); - if (player_ptr->immune_fire) - m_ptr->smart |= (SM_IMM_FIRE); - break; - - case DRS_COLD: - if (player_ptr->resist_cold) - m_ptr->smart |= (SM_RES_COLD); - if (is_oppose_cold(player_ptr)) - m_ptr->smart |= (SM_OPP_COLD); - if (player_ptr->immune_cold) - m_ptr->smart |= (SM_IMM_COLD); - break; - - case DRS_POIS: - if (player_ptr->resist_pois) - m_ptr->smart |= (SM_RES_POIS); - if (is_oppose_pois(player_ptr)) - m_ptr->smart |= (SM_OPP_POIS); - break; - - case DRS_NETH: - if (player_ptr->resist_neth) - m_ptr->smart |= (SM_RES_NETH); - break; - - case DRS_LITE: - if (player_ptr->resist_lite) - m_ptr->smart |= (SM_RES_LITE); - break; - - case DRS_DARK: - if (player_ptr->resist_dark) - m_ptr->smart |= (SM_RES_DARK); - break; - - case DRS_FEAR: - if (player_ptr->resist_fear) - m_ptr->smart |= (SM_RES_FEAR); - break; - - case DRS_CONF: - if (player_ptr->resist_conf) - m_ptr->smart |= (SM_RES_CONF); - break; - - case DRS_CHAOS: - if (player_ptr->resist_chaos) - m_ptr->smart |= (SM_RES_CHAOS); - break; - - case DRS_DISEN: - if (player_ptr->resist_disen) - m_ptr->smart |= (SM_RES_DISEN); - break; - - case DRS_BLIND: - if (player_ptr->resist_blind) - m_ptr->smart |= (SM_RES_BLIND); - break; - - case DRS_NEXUS: - if (player_ptr->resist_nexus) - m_ptr->smart |= (SM_RES_NEXUS); - break; - - case DRS_SOUND: - if (player_ptr->resist_sound) - m_ptr->smart |= (SM_RES_SOUND); - break; - - case DRS_SHARD: - if (player_ptr->resist_shard) - m_ptr->smart |= (SM_RES_SHARD); - break; - - case DRS_FREE: - if (player_ptr->free_act) - m_ptr->smart |= (SM_IMM_FREE); - break; - - case DRS_MANA: - if (!player_ptr->msp) - m_ptr->smart |= (SM_IMM_MANA); - break; - - case DRS_REFLECT: - if (player_ptr->reflect) - m_ptr->smart |= (SM_IMM_REFLECT); - break; - } -} - -/*! * @brief モンスターが盗みや拾いで確保していたアイテムを全てドロップさせる / Drop all items carried by a monster * @param player_ptr プレーヤーへの参照ポインタ * @param m_ptr モンスター参照ポインタ diff --git a/src/monster/monster2.h b/src/monster/monster2.h index a238425c1..bc1cbe04c 100644 --- a/src/monster/monster2.h +++ b/src/monster/monster2.h @@ -10,7 +10,6 @@ MONSTER_IDX m_pop(player_type *player_ptr); #define GMN_ARENA 0x00000001 //!< 賭け闘技場向け生成 MONRACE_IDX get_mon_num(player_type *player_ptr, DEPTH level, BIT_FLAGS option); -void update_smart_learn(player_type *player_ptr, MONSTER_IDX m_idx, int what); void choose_new_monster(player_type *player_ptr, MONSTER_IDX m_idx, bool born, MONRACE_IDX r_idx); SPEED get_mspeed(player_type *player_ptr, monster_race *r_ptr); void monster_drop_carried_objects(player_type *player_ptr, monster_type *m_ptr); diff --git a/src/mspell/mspell-ball.c b/src/mspell/mspell-ball.c index 2b82dc2ea..b51786b47 100644 --- a/src/mspell/mspell-ball.c +++ b/src/mspell/mspell-ball.c @@ -2,9 +2,9 @@ #include "floor/floor.h" #include "mind/drs-types.h" #include "monster-race/race-indice-types.h" -#include "monster/monster-status.h" #include "monster/monster-info.h" -#include "monster/monster2.h" +#include "monster/monster-status.h" +#include "monster/monster-update.h" #include "mspell/monster-spell.h" #include "mspell/mspell-damage-calculator.h" #include "mspell/mspell-type.h" diff --git a/src/mspell/mspell-bolt.c b/src/mspell/mspell-bolt.c index 50d5d6736..ec5e696ee 100644 --- a/src/mspell/mspell-bolt.c +++ b/src/mspell/mspell-bolt.c @@ -2,7 +2,7 @@ #include "main/sound-definitions-table.h" #include "mind/drs-types.h" #include "monster/monster-info.h" -#include "monster/monster2.h" +#include "monster/monster-update.h" #include "mspell/monster-spell.h" #include "mspell/mspell-damage-calculator.h" #include "mspell/mspell-type.h" diff --git a/src/mspell/mspell-breath.c b/src/mspell/mspell-breath.c index 56227085e..bf3d8bd65 100644 --- a/src/mspell/mspell-breath.c +++ b/src/mspell/mspell-breath.c @@ -3,7 +3,7 @@ #include "mind/drs-types.h" #include "monster-race/race-indice-types.h" #include "monster/monster-info.h" -#include "monster/monster2.h" +#include "monster/monster-update.h" #include "mspell/monster-spell.h" #include "mspell/mspell-damage-calculator.h" #include "mspell/mspell-util.h" diff --git a/src/mspell/mspell-floor.c b/src/mspell/mspell-floor.c index db6d54bb0..d25f070a6 100644 --- a/src/mspell/mspell-floor.c +++ b/src/mspell/mspell-floor.c @@ -15,7 +15,7 @@ #include "monster-race/race-indice-types.h" #include "monster/monster-info.h" #include "monster/monster-status.h" -#include "monster/monster2.h" +#include "monster/monster-update.h" #include "mspell/monster-spell.h" #include "mspell/mspell-status.h" #include "mspell/mspell-util.h" diff --git a/src/mspell/mspell-particularity.c b/src/mspell/mspell-particularity.c index a5663b4a7..be9670540 100644 --- a/src/mspell/mspell-particularity.c +++ b/src/mspell/mspell-particularity.c @@ -10,7 +10,7 @@ #include "mspell/mspell-particularity.h" #include "mind/drs-types.h" -#include "monster/monster2.h" +#include "monster/monster-update.h" #include "mspell/mspell-type.h" #include "mspell/monster-spell.h" #include "spell/spells-type.h" diff --git a/src/mspell/mspell-status.c b/src/mspell/mspell-status.c index a437266ce..923fa1559 100644 --- a/src/mspell/mspell-status.c +++ b/src/mspell/mspell-status.c @@ -14,7 +14,7 @@ #include "monster/monster-description-types.h" #include "monster/monster-info.h" #include "monster/monster-status.h" -#include "monster/monster2.h" +#include "monster/monster-update.h" #include "mspell/monster-spell.h" #include "mspell/mspell-damage-calculator.h" #include "mspell/mspell-util.h" -- 2.11.0