OSDN Git Service

Merge pull request #936 from shimitei/feature/#916_fix_sound_on_off
[hengbandforosx/hengbandosx.git] / src / player-status / player-status-base.cpp
1 #include "player-status/player-status-base.h"
2 #include "inventory/inventory-slot-types.h"
3 #include "object/object-flags.h"
4 #include "player/player-status.h"
5 #include "system/object-type-definition.h"
6 #include "system/player-type-definition.h"
7 #include "util/bit-flags-calculator.h"
8
9 /*!
10  * @brief プレイヤーの各ステータス計算用のクラス
11  * @param owner_ptr プレイヤーの参照ポインタ
12  * @details
13  * * コンストラクタでowner_ptrをセット。メンバ変数を0クリア。
14  */
15 PlayerStatusBase::PlayerStatusBase(player_type *owner_ptr)
16 {
17     this->owner_ptr = owner_ptr;
18     this->set_locals(); /* 初期化。基底クラスの0クリアが呼ばれる。*/
19 }
20
21 /*!
22  * @brief 該当する値を計算して取得する。
23  * @details
24  * * 派生クラスからset_locals()をコールして初期値、上限、下限をセット。
25  * * 各要素毎に計算した値を初期値に単純に加算し、上限と下限で丸める。
26  */
27 s16b PlayerStatusBase::get_value()
28 {
29     this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
30     s16b pow = this->default_value;
31
32     pow += this->action_value();
33     pow += this->battleform_value();
34     pow += this->class_base_value();
35     pow += this->class_value();
36     pow += this->equipments_value();
37     pow += this->inventory_weight_value();
38     pow += this->mutation_value();
39     pow += this->personality_value();
40     pow += this->race_value();
41     pow += this->riding_value();
42     pow += this->time_effect_value();
43     pow = this->set_exception_value(pow);
44
45     if ((pow > this->max_value)) {
46         pow = this->max_value;
47     }
48
49     if (pow < this->min_value)
50         pow = this->min_value;
51
52     return pow;
53 }
54
55 /*!
56  * @brief 修正値が0でないところにビットを立てて返す。
57  * @return 判定結果のBIT_FLAGS
58  */
59 BIT_FLAGS PlayerStatusBase::get_all_flags()
60 {
61     this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
62     BIT_FLAGS result = equipments_flags(this->tr_flag);
63
64     if (this->class_value() != 0)
65         set_bits(result, FLAG_CAUSE_CLASS);
66
67     if (this->race_value() != 0)
68         set_bits(result, FLAG_CAUSE_RACE);
69
70     if (this->battleform_value() != 0)
71         set_bits(result, FLAG_CAUSE_BATTLE_FORM);
72
73     if (this->mutation_value() != 0)
74         set_bits(result, FLAG_CAUSE_MUTATION);
75
76     if (this->time_effect_value() != 0)
77         set_bits(result, FLAG_CAUSE_MAGIC_TIME_EFFECT);
78
79     if (this->personality_value() != 0)
80         set_bits(result, FLAG_CAUSE_PERSONALITY);
81
82     if (this->riding_value() != 0)
83         set_bits(result, FLAG_CAUSE_RIDING);
84
85     if (this->inventory_weight_value() != 0)
86         set_bits(result, FLAG_CAUSE_INVEN_PACK);
87
88     if (this->action_value() != 0)
89         set_bits(result, FLAG_CAUSE_ACTION);
90
91     return result;
92 }
93
94 /*!
95  * @brief 修正値が1以上のところにビットを立てて返す。
96  * @return 判定結果のBIT_FLAGS
97  */
98 BIT_FLAGS PlayerStatusBase::get_good_flags()
99 {
100     this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
101     BIT_FLAGS result = equipments_flags(this->tr_flag);
102
103     if (this->class_value() > 0)
104         set_bits(result, FLAG_CAUSE_CLASS);
105
106     if (this->race_value() > 0)
107         set_bits(result, FLAG_CAUSE_RACE);
108
109     if (this->battleform_value() > 0)
110         set_bits(result, FLAG_CAUSE_BATTLE_FORM);
111
112     if (this->mutation_value() > 0)
113         set_bits(result, FLAG_CAUSE_MUTATION);
114
115     if (this->time_effect_value() > 0)
116         set_bits(result, FLAG_CAUSE_MAGIC_TIME_EFFECT);
117
118     if (this->personality_value() > 0)
119         set_bits(result, FLAG_CAUSE_PERSONALITY);
120
121     if (this->riding_value() > 0)
122         set_bits(result, FLAG_CAUSE_RIDING);
123
124     if (this->inventory_weight_value() > 0)
125         set_bits(result, FLAG_CAUSE_INVEN_PACK);
126
127     if (this->action_value() > 0)
128         set_bits(result, FLAG_CAUSE_ACTION);
129
130     return result;
131 }
132
133 /*!
134  * @brief 修正値が-1以下のところにビットを立てて返す。
135  * @return 判定結果のBIT_FLAGS
136  */
137 BIT_FLAGS PlayerStatusBase::get_bad_flags()
138 {
139     this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
140     BIT_FLAGS result = equipments_bad_flags(this->tr_bad_flag);
141
142     if (this->class_value() < 0)
143         set_bits(result, FLAG_CAUSE_CLASS);
144
145     if (this->race_value() < 0)
146         set_bits(result, FLAG_CAUSE_RACE);
147
148     if (this->battleform_value() < 0)
149         set_bits(result, FLAG_CAUSE_BATTLE_FORM);
150
151     if (this->mutation_value() < 0)
152         set_bits(result, FLAG_CAUSE_MUTATION);
153
154     if (this->time_effect_value() < 0)
155         set_bits(result, FLAG_CAUSE_MAGIC_TIME_EFFECT);
156
157     if (this->personality_value() < 0)
158         set_bits(result, FLAG_CAUSE_PERSONALITY);
159
160     if (this->riding_value() < 0)
161         set_bits(result, FLAG_CAUSE_RIDING);
162
163     if (this->inventory_weight_value() < 0)
164         set_bits(result, FLAG_CAUSE_INVEN_PACK);
165
166     if (this->action_value() < 0)
167         set_bits(result, FLAG_CAUSE_ACTION);
168
169     return result;
170 }
171
172 void PlayerStatusBase::set_locals()
173 {
174     this->default_value = 0;
175     this->min_value = 0;
176     this->max_value = 0;
177     this->tr_flag = TR_FLAG_MAX;
178     this->tr_bad_flag = TR_FLAG_MAX;
179 }
180
181 /*!
182  * @brief 判定するflagを持つ装備品に対応するBIT_FLAGSを返す
183  * @param check_flag 判定するtr_type
184  * @return 判定結果のBIT_FLAGS
185  */
186 BIT_FLAGS PlayerStatusBase::equipments_flags(tr_type check_flag)
187 {
188     object_type *o_ptr;
189     BIT_FLAGS flgs[TR_FLAG_SIZE];
190     BIT_FLAGS result = 0L;
191     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
192         o_ptr = &owner_ptr->inventory_list[i];
193         if (!o_ptr->k_idx)
194             continue;
195
196         object_flags(owner_ptr, o_ptr, flgs);
197
198         if (has_flag(flgs, check_flag))
199             set_bits(result, convert_inventory_slot_type_to_flag_cause(static_cast<inventory_slot_type>(i)));
200     }
201     return result;
202 }
203
204 /*!
205  * @brief 判定するflagを持ち、pvalが負の装備品に対応するBIT_FLAGSを返す
206  * @param check_flag 判定するtr_type
207  * @return 判定結果のBIT_FLAGS
208  */
209 BIT_FLAGS PlayerStatusBase::equipments_bad_flags(tr_type check_flag)
210 {
211     object_type *o_ptr;
212     BIT_FLAGS flgs[TR_FLAG_SIZE];
213     BIT_FLAGS result = 0L;
214     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
215         o_ptr = &owner_ptr->inventory_list[i];
216         if (!o_ptr->k_idx)
217             continue;
218
219         object_flags(owner_ptr, o_ptr, flgs);
220
221         if (has_flag(flgs, check_flag)) {
222             if (o_ptr->pval < 0) {
223                 set_bits(result, convert_inventory_slot_type_to_flag_cause(static_cast<inventory_slot_type>(i)));
224             }
225         }
226     }
227     return result;
228 }
229
230 /*!
231  * @brief this->tr_flagを持つ装備品のpval合計値を返す
232  * @return 該当するfalgを持つ全装備のpvalの合計値
233  */
234 s16b PlayerStatusBase::equipments_value()
235 {
236     this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
237     s16b result = 0;
238     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
239         object_type *o_ptr = &owner_ptr->inventory_list[i];
240         BIT_FLAGS flgs[TR_FLAG_SIZE];
241         object_flags(owner_ptr, o_ptr, flgs);
242
243         if (!o_ptr->k_idx)
244             continue;
245         if (has_flag(flgs, this->tr_flag))
246             result += o_ptr->pval;
247     }
248     return result;
249 }
250
251 s16b PlayerStatusBase::race_value()
252 {
253     return 0;
254 }
255 s16b PlayerStatusBase::class_value()
256 {
257     return 0;
258 }
259 s16b PlayerStatusBase::class_base_value()
260 {
261     return 0;
262
263 s16b PlayerStatusBase::personality_value()
264 {
265     return 0;
266 }
267 s16b PlayerStatusBase::time_effect_value()
268 {
269     return 0;
270 }
271 s16b PlayerStatusBase::battleform_value()
272 {
273     return 0;
274 }
275 s16b PlayerStatusBase::mutation_value()
276 {
277     return 0;
278 }
279 s16b PlayerStatusBase::riding_value()
280 {
281     return 0;
282 }
283 s16b PlayerStatusBase::inventory_weight_value()
284 {
285     return 0;
286 }
287 s16b PlayerStatusBase::action_value()
288 {
289     return 0;
290 }
291
292 /*!
293  * @brief 値を直接変更する例外処理。
294  * @param value 単純加算された修正値の合計
295  * @details
296  * * 派生クラスで必要とされる例外処理でoverrideされる
297  * @return 直接変更された値。このままmin-max処理され最終的なvalueになる。
298  */
299 s16b PlayerStatusBase::set_exception_value(s16b value)
300 {
301     return value;
302 }