OSDN Git Service

Merge pull request #2013 from sikabane-works/release/3.0.0Alpha51
[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/race-flags1.h"
10 #include "monster-race/monster-race.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)
44         + ((r_ptr->flags1 & RF1_DROP_1D2) ? 2 : 0) + ((r_ptr->flags1 & RF1_DROP_90) ? 1 : 0) + ((r_ptr->flags1 & RF1_DROP_60) ? 1 : 0));
45
46     if (!(r_ptr->flags1 & RF1_ONLY_GOLD)) {
47         if (r_ptr->r_drop_item != tmp_byte)
48             n++;
49         r_ptr->r_drop_item = tmp_byte;
50     }
51     if (!(r_ptr->flags1 & RF1_ONLY_ITEM)) {
52         if (r_ptr->r_drop_gold != tmp_byte)
53             n++;
54         r_ptr->r_drop_gold = tmp_byte;
55     }
56
57     if (r_ptr->r_cast_spell != MAX_UCHAR)
58         n++;
59     r_ptr->r_cast_spell = MAX_UCHAR;
60
61     for (int i = 0; i < 32; i++) {
62         if (!(r_ptr->r_flags1 & (1UL << i)) && (r_ptr->flags1 & (1UL << i)))
63             n++;
64         if (!(r_ptr->r_flags2 & (1UL << i)) && (r_ptr->flags2 & (1UL << i)))
65             n++;
66         if (!(r_ptr->r_flags3 & (1UL << i)) && (r_ptr->flags3 & (1UL << i)))
67             n++;
68         if (!(r_ptr->r_flagsr & (1UL << i)) && (r_ptr->flagsr & (1UL << i)))
69             n++;
70     }
71
72     auto ability_flags = r_ptr->ability_flags;
73     n += ability_flags.reset(r_ptr->r_ability_flags).count();
74
75     r_ptr->r_flags1 = r_ptr->flags1;
76     r_ptr->r_flags2 = r_ptr->flags2;
77     r_ptr->r_flags3 = r_ptr->flags3;
78     r_ptr->r_flagsr = r_ptr->flagsr;
79     r_ptr->r_ability_flags = r_ptr->ability_flags;
80
81     if (!r_ptr->r_can_evolve)
82         n++;
83     r_ptr->r_can_evolve = true;
84
85     if (player_ptr->monster_race_idx == r_idx) {
86         player_ptr->window_flags |= (PW_MONSTER);
87     }
88
89     return n;
90 }
91
92 /*!
93  * @brief モンスターの撃破に伴うドロップ情報の記憶処理 / Take note that the given monster just dropped some treasure
94  * @param player_ptr プレイヤーへの参照ポインタ
95  * @param m_idx モンスター情報のID
96  * @param num_item 手に入れたアイテム数
97  * @param num_gold 手に入れた財宝の単位数
98  */
99 void lore_treasure(PlayerType *player_ptr, MONSTER_IDX m_idx, ITEM_NUMBER num_item, ITEM_NUMBER num_gold)
100 {
101     monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[m_idx];
102     monster_race *r_ptr = &r_info[m_ptr->r_idx];
103
104     if (!is_original_ap(m_ptr))
105         return;
106
107     if (num_item > r_ptr->r_drop_item)
108         r_ptr->r_drop_item = num_item;
109     if (num_gold > r_ptr->r_drop_gold)
110         r_ptr->r_drop_gold = num_gold;
111
112     if (r_ptr->flags1 & (RF1_DROP_GOOD))
113         r_ptr->r_flags1 |= (RF1_DROP_GOOD);
114     if (r_ptr->flags1 & (RF1_DROP_GREAT))
115         r_ptr->r_flags1 |= (RF1_DROP_GREAT);
116     if (player_ptr->monster_race_idx == m_ptr->r_idx)
117         player_ptr->window_flags |= (PW_MONSTER);
118 }