OSDN Git Service

Merge pull request #1054 from shimitei/feature/#1022_extend_autopick_max_line
[hengbandforosx/hengbandosx.git] / src / player-status / player-basic-statistics.cpp
1 #include "player-status/player-basic-statistics.h"
2 #include "core/player-redraw-types.h"
3 #include "core/player-update-types.h"
4 #include "core/window-redrawer.h"
5 #include "mutation/mutation-flag-types.h"
6 #include "object/object-flags.h"
7 #include "player/mimic-info-table.h"
8 #include "player/player-class.h"
9 #include "player/player-personality.h"
10 #include "player/player-status.h"
11 #include "player/race-info-table.h"
12 #include "player/special-defense-types.h"
13 #include "realm/realm-hex-numbers.h"
14 #include "spell-realm/spells-hex.h"
15 #include "system/player-type-definition.h"
16 #include "util/bit-flags-calculator.h"
17
18 /*!
19  * @brief 基礎ステータス補正値
20  * @return ステータス補正値
21  * @details
22  * * 各要素によるステータス修正値の合計
23  */
24 s16b PlayerBasicStatistics::modification_value()
25 {
26     return PlayerStatusBase::get_value();
27 }
28
29 /*!
30  * @brief 基礎ステータスの実値
31  * @return status_typeに対応するステータスの実値を返す
32  */
33 s16b PlayerBasicStatistics::get_value()
34 {
35     this->set_locals();
36     return this->owner_ptr->stat_index[(int)this->ability_type];
37 }
38
39 /*!
40  * @brief 基礎ステータス補正計算 - 種族
41  * @param 計算するステータスの種類
42  * @return ステータス補正値
43  * @details
44  * * 種族によるステータス修正値。
45  */
46 s16b PlayerBasicStatistics::race_value()
47 {
48     const player_race *tmp_rp_ptr;
49     if (this->owner_ptr->mimic_form)
50         tmp_rp_ptr = &mimic_info[this->owner_ptr->mimic_form];
51     else
52         tmp_rp_ptr = &race_info[this->owner_ptr->prace];
53
54     return tmp_rp_ptr->r_adj[this->ability_type];
55 }
56
57 /*!
58  * @brief ステータス補正計算 - 職業
59  * @param 計算するステータスの種類
60  * @return ステータス補正値
61  * @details
62  * * 職業によるステータス修正値
63  */
64 s16b PlayerBasicStatistics::class_value()
65 {
66     const player_class *c_ptr = &class_info[this->owner_ptr->pclass];
67     return c_ptr->c_adj[this->ability_type];
68 }
69
70 /*!
71  * @brief ステータス補正計算 - 性格
72  * @param 計算するステータスの種類
73  * @return ステータス補正値
74  * @details
75  * * 性格によるステータス修正値
76  */
77 s16b PlayerBasicStatistics::personality_value()
78 {
79     const player_personality *a_ptr = &personality_info[this->owner_ptr->pseikaku];
80     return a_ptr->a_adj[this->ability_type];
81 }
82
83 /*!
84  * @brief ステータス更新処理
85  * @details
86  * * owner_ptrのステータスを更新する
87  */
88 void PlayerBasicStatistics::update_value()
89 {
90     this->set_locals();
91     this->update_top_status();
92     this->update_use_status();
93     this->update_index_status();
94 }
95
96 /*!
97  * @brief ステータス最大値更新処理
98  * @details
99  * * owner_ptrのステータス最大値を更新する
100  * * 更新対象はset_locals()で設定したstatus_typeで決定される
101  */
102 void PlayerBasicStatistics::update_top_status()
103 {
104     int status = (int)this->ability_type;
105     int top = modify_stat_value(this->owner_ptr->stat_max[status], this->owner_ptr->stat_add[status]);
106
107     if (this->owner_ptr->stat_top[status] != top) {
108         this->owner_ptr->stat_top[status] = (s16b)top;
109         set_bits(this->owner_ptr->redraw, PR_STATS);
110         set_bits(this->owner_ptr->window_flags, PW_PLAYER);
111     }
112 }
113
114 /*!
115  * @brief ステータス現在値更新の例外処理
116  * @param 通常処理されたステータスの値
117  * @returns 例外処理されたステータスの値
118  * @details
119  * * owner_ptrのステータス現在値を更新する際の例外処理
120  * * 派生クラスでoverrideして使用する。
121  */
122 s16b PlayerBasicStatistics::set_exception_use_status(s16b value)
123 {
124     return value;
125 }
126
127 /*!
128  * @brief ステータス現在値更新処理
129  * @details
130  * * owner_ptrのステータス現在値を更新する
131  * * 更新対象はset_locals()で設定したstatus_typeで決定される
132  */
133 void PlayerBasicStatistics::update_use_status()
134 {
135     int status = (int)this->ability_type;
136     s16b use = modify_stat_value(this->owner_ptr->stat_cur[status], this->owner_ptr->stat_add[status]);
137
138     use = this->set_exception_use_status(use);
139
140     if (this->owner_ptr->stat_use[status] != use) {
141         this->owner_ptr->stat_use[status] = (s16b)use;
142         set_bits(this->owner_ptr->redraw, PR_STATS);
143         set_bits(this->owner_ptr->window_flags, PW_PLAYER);
144     }
145 }
146
147 /*!
148  * @brief ステータス内部値更新処理
149  * @details
150  * * owner_ptrのステータス内部値を更新する
151  * * ステータス内部値は実際の数値処理に使われる0-37の整数値
152  * * 更新対象はset_locals()で設定したstatus_typeで決定される
153  */
154 void PlayerBasicStatistics::update_index_status()
155 {
156     int status = (int)this->ability_type;
157     int index;
158     if (this->owner_ptr->stat_use[status] <= 18)
159         index = (this->owner_ptr->stat_use[status] - 3);
160     else if (this->owner_ptr->stat_use[status] <= 18 + 219)
161         index = (15 + (this->owner_ptr->stat_use[status] - 18) / 10);
162     else
163         index = (37);
164
165     if (this->owner_ptr->stat_index[status] == index)
166         return;
167
168     this->owner_ptr->stat_index[status] = (s16b)index;
169     if (status == A_CON) {
170         set_bits(this->owner_ptr->update, PU_HP);
171     } else if (status == A_INT) {
172         if (mp_ptr->spell_stat == A_INT) {
173             set_bits(this->owner_ptr->update, (PU_MANA | PU_SPELLS));
174         }
175     } else if (status == A_WIS) {
176         if (mp_ptr->spell_stat == A_WIS) {
177             set_bits(this->owner_ptr->update, (PU_MANA | PU_SPELLS));
178         }
179     } else if (status == A_CHR) {
180         if (mp_ptr->spell_stat == A_CHR) {
181             set_bits(this->owner_ptr->update, (PU_MANA | PU_SPELLS));
182         }
183     }
184
185     set_bits(this->owner_ptr->window_flags, PW_PLAYER);
186 }