OSDN Git Service

Merge pull request #3569 from sikabane-works/release/3.0.0.88-alpha
[hengbandforosx/hengbandosx.git] / src / mspell / improper-mspell-remover.cpp
1 #include "mspell/improper-mspell-remover.h"
2 #include "game-option/birth-options.h"
3 #include "monster-race/monster-race.h"
4 #include "monster-race/race-flags2.h"
5 #include "monster/smart-learn-types.h"
6 #include "mspell/element-resistance-checker.h"
7 #include "mspell/high-resistance-checker.h"
8 #include "mspell/smart-mspell-util.h"
9 #include "system/floor-type-definition.h"
10 #include "system/monster-entity.h"
11 #include "system/monster-race-info.h"
12 #include "system/player-type-definition.h"
13
14 static void add_cheat_remove_flags(PlayerType *player_ptr, msr_type *msr_ptr)
15 {
16     if (!smart_cheat) {
17         return;
18     }
19
20     add_cheat_remove_flags_element(player_ptr, msr_ptr);
21     add_cheat_remove_flags_others(player_ptr, msr_ptr);
22 }
23
24 /*!
25  * @brief モンスターの魔法一覧から戦術的に適さない魔法を除外する /
26  * Remove the "bad" spells from a spell list
27  * @param m_idx モンスターの構造体参照ポインタ
28  * @param f4p モンスター魔法のフラグリスト1
29  * @param f5p モンスター魔法のフラグリスト2
30  * @param f6p モンスター魔法のフラグリスト3
31  */
32 void remove_bad_spells(MONSTER_IDX m_idx, PlayerType *player_ptr, EnumClassFlagGroup<MonsterAbilityType> &ability_flags)
33 {
34     msr_type tmp_msr(player_ptr, m_idx, ability_flags);
35     auto *msr_ptr = &tmp_msr;
36     if (msr_ptr->r_ptr->behavior_flags.has(MonsterBehaviorType::STUPID)) {
37         return;
38     }
39
40     if (!smart_cheat && !smart_learn) {
41         return;
42     }
43
44     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
45     if (smart_learn) {
46         /* 時々学習情報を忘れる */
47         if (randint0(100) < 1) {
48             m_ptr->smart.clear();
49         }
50
51         msr_ptr->smart_flags = m_ptr->smart;
52     }
53
54     add_cheat_remove_flags(player_ptr, msr_ptr);
55     if (msr_ptr->smart_flags.none()) {
56         return;
57     }
58
59     check_element_resistance(msr_ptr);
60     check_high_resistances(player_ptr, msr_ptr);
61     ability_flags = msr_ptr->ability_flags;
62 }