OSDN Git Service

b414afdf98443f451f53d6c87228ff0022d10588
[hengbandforosx/hengbandosx.git] / src / lore / lore-store.cpp
1 /*!
2  * @brief モンスターの思い出を記憶する処理
3  * @date 2020/06/09
4  * @author Hourier
5  */
6
7 #include "lore/lore-store.h"
8 #include "core/window-redrawer.h"
9 #include "monster-race/monster-race.h"
10 #include "monster-race/race-flags1.h"
11 #include "monster/monster-info.h"
12 #include "system/floor-type-definition.h"
13 #include "system/monster-race-definition.h"
14 #include "system/monster-type-definition.h" //!< @todo 違和感、m_ptr は外から与えることとしたい.
15 #include "system/player-type-definition.h"
16
17 /*!
18  * @brief モンスターの調査による思い出補完処理 / Learn about a monster (by "probing" it)
19  * @param player_ptr プレイヤーへの参照ポインタ
20  * @param r_idx 補完されるモンスター種族ID
21  * @return 明らかになった情報の度数
22  * @details
23  * Return the number of new flags learnt.  -Mogami-
24  */
25 int lore_do_probe(PlayerType *player_ptr, MONRACE_IDX r_idx)
26 {
27     int n = 0;
28     monster_race *r_ptr = &r_info[r_idx];
29     if (r_ptr->r_wake != MAX_UCHAR)
30         n++;
31     if (r_ptr->r_ignore != MAX_UCHAR)
32         n++;
33     r_ptr->r_wake = r_ptr->r_ignore = MAX_UCHAR;
34
35     for (int i = 0; i < 4; i++) {
36         if (r_ptr->blow[i].effect != RaceBlowEffectType::NONE || r_ptr->blow[i].method != RaceBlowMethodType::NONE) {
37             if (r_ptr->r_blows[i] != MAX_UCHAR)
38                 n++;
39             r_ptr->r_blows[i] = MAX_UCHAR;
40         }
41     }
42
43     byte tmp_byte = (((r_ptr->flags1 & RF1_DROP_4D2) ? 8 : 0) + ((r_ptr->flags1 & RF1_DROP_3D2) ? 6 : 0) + ((r_ptr->flags1 & RF1_DROP_2D2) ? 4 : 0) + ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) + ((r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) + ((r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
44
45     if (!(r_ptr->flags1 & RF1_ONLY_GOLD)) {
46         if (r_ptr->r_drop_item != tmp_byte)
47             n++;
48         r_ptr->r_drop_item = tmp_byte;
49     }
50     if (!(r_ptr->flags1 & RF1_ONLY_ITEM)) {
51         if (r_ptr->r_drop_gold != tmp_byte)
52             n++;
53         r_ptr->r_drop_gold = tmp_byte;
54     }
55
56     if (r_ptr->r_cast_spell != MAX_UCHAR)
57         n++;
58     r_ptr->r_cast_spell = MAX_UCHAR;
59
60     for (int i = 0; i < 32; i++) {
61         if (!(r_ptr->r_flags1 & (1UL << i)) && (r_ptr->flags1 & (1UL << i)))
62             n++;
63         if (!(r_ptr->r_flags2 & (1UL << i)) && (r_ptr->flags2 & (1UL << i)))
64             n++;
65         if (!(r_ptr->r_flags3 & (1UL << i)) && (r_ptr->flags3 & (1UL << i)))
66             n++;
67         if (!(r_ptr->r_flagsr & (1UL << i)) && (r_ptr->flagsr & (1UL << i)))
68             n++;
69     }
70
71     auto ability_flags = r_ptr->ability_flags;
72     n += ability_flags.reset(r_ptr->r_ability_flags).count();
73
74     auto behavior_flags = r_ptr->behavior_flags;
75     n += behavior_flags.reset(r_ptr->r_behavior_flags).count();
76
77     r_ptr->r_flags1 = r_ptr->flags1;
78     r_ptr->r_flags2 = r_ptr->flags2;
79     r_ptr->r_flags3 = r_ptr->flags3;
80     r_ptr->r_flagsr = r_ptr->flagsr;
81     r_ptr->r_ability_flags = r_ptr->ability_flags;
82     r_ptr->r_behavior_flags = r_ptr->behavior_flags;
83
84     if (!r_ptr->r_can_evolve)
85         n++;
86     r_ptr->r_can_evolve = true;
87
88     if (player_ptr->monster_race_idx == r_idx) {
89         player_ptr->window_flags |= (PW_MONSTER);
90     }
91
92     return n;
93 }
94
95 /*!
96  * @brief モンスターの撃破に伴うドロップ情報の記憶処理 / Take note that the given monster just dropped some treasure
97  * @param player_ptr プレイヤーへの参照ポインタ
98  * @param m_idx モンスター情報のID
99  * @param num_item 手に入れたアイテム数
100  * @param num_gold 手に入れた財宝の単位数
101  */
102 void lore_treasure(PlayerType *player_ptr, MONSTER_IDX m_idx, ITEM_NUMBER num_item, ITEM_NUMBER num_gold)
103 {
104     auto *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
105     monster_race *r_ptr = &r_info[m_ptr->r_idx];
106
107     if (!is_original_ap(m_ptr))
108         return;
109
110     if (num_item > r_ptr->r_drop_item)
111         r_ptr->r_drop_item = num_item;
112     if (num_gold > r_ptr->r_drop_gold)
113         r_ptr->r_drop_gold = num_gold;
114
115     if (r_ptr->flags1 & (RF1_DROP_GOOD))
116         r_ptr->r_flags1 |= (RF1_DROP_GOOD);
117     if (r_ptr->flags1 & (RF1_DROP_GREAT))
118         r_ptr->r_flags1 |= (RF1_DROP_GREAT);
119     if (player_ptr->monster_race_idx == m_ptr->r_idx)
120         player_ptr->window_flags |= (PW_MONSTER);
121 }