OSDN Git Service

[Refactor] PlayerStatusBase、PlayerSpeedクラスの導入
[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 "util/bit-flags-calculator.h"
7
8 /*!
9  * @brief プレイヤーの各ステータス計算用のクラス
10  * @param owner_ptr プレイヤーの参照ポインタ
11  * @details
12  * * コンストラクタでowner_ptrをセット。メンバ変数を0クリア。
13  */
14 PlayerStatusBase::PlayerStatusBase(player_type *owner_ptr)
15 {
16     this->owner_ptr = owner_ptr;
17     this->set_locals(); /* 初期化。基底クラスの0クリアが呼ばれる。*/
18 }
19
20 /*!
21  * @brief 該当する値を計算して取得する。
22  * @details
23  * * 派生クラスからset_locals()をコールして初期値、上限、下限をセット。
24  * * 各要素毎に計算した値を初期値に単純に加算し、上限と下限で丸める。
25  */
26 s16b PlayerStatusBase::getValue()
27 {
28     this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
29     s16b pow = this->default_value;
30
31     pow += this->action_value();
32     pow += this->battleform_value();
33     pow += this->class_value();
34     pow += this->equipments_value();
35     pow += this->inventory_weight_value();
36     pow += this->mutation_value();
37     pow += this->personality_value();
38     pow += this->race_value();
39     pow += this->riding_value();
40     pow += this->time_effect_value();
41
42     if ((pow > this->max_value)) {
43         pow = this->max_value;
44     }
45
46     if (pow < this->min_value)
47         pow = this->min_value;
48
49     return pow;
50 }
51
52 /*!
53  * @brief 修正値が0でないところにビットを立てて返す。
54  * @return 判定結果のBIT_FLAGS
55  */
56 BIT_FLAGS PlayerStatusBase::getFlags()
57 {
58     BIT_FLAGS result = equipments_flags();
59
60     if (this->class_value() != 0)
61         set_bits(result, FLAG_CAUSE_CLASS);
62
63     if (this->race_value() != 0)
64         set_bits(result, FLAG_CAUSE_RACE);
65
66     if (this->battleform_value() != 0)
67         set_bits(result, FLAG_CAUSE_BATTLE_FORM);
68
69     if (this->mutation_value() != 0)
70         set_bits(result, FLAG_CAUSE_MUTATION);
71
72     if (this->time_effect_value() != 0)
73         set_bits(result, FLAG_CAUSE_MAGIC_TIME_EFFECT);
74
75     if (this->personality_value() != 0)
76         set_bits(result, FLAG_CAUSE_PERSONALITY);
77
78     if (this->riding_value() != 0)
79         set_bits(result, FLAG_CAUSE_RIDING);
80
81     if (this->inventory_weight_value() != 0)
82         set_bits(result, FLAG_CAUSE_INVEN_PACK);
83
84     if (this->action_value() != 0)
85         set_bits(result, FLAG_CAUSE_ACTION);
86
87     return result;
88 }
89
90 /*!
91  * @brief 修正値が0以下のところにビットを立てて返す。
92  * @return 判定結果のBIT_FLAGS
93  */
94 BIT_FLAGS PlayerStatusBase::getBadFlags()
95 {
96     BIT_FLAGS result = equipments_bad_flags();
97
98     if (this->class_value() < 0)
99         set_bits(result, FLAG_CAUSE_CLASS);
100
101     if (this->race_value() < 0)
102         set_bits(result, FLAG_CAUSE_RACE);
103
104     if (this->battleform_value() < 0)
105         set_bits(result, FLAG_CAUSE_BATTLE_FORM);
106
107     if (this->mutation_value() < 0)
108         set_bits(result, FLAG_CAUSE_MUTATION);
109
110     if (this->time_effect_value() < 0)
111         set_bits(result, FLAG_CAUSE_MAGIC_TIME_EFFECT);
112
113     if (this->personality_value() < 0)
114         set_bits(result, FLAG_CAUSE_PERSONALITY);
115
116     if (this->riding_value() < 0)
117         set_bits(result, FLAG_CAUSE_RIDING);
118
119     if (this->inventory_weight_value() < 0)
120         set_bits(result, FLAG_CAUSE_INVEN_PACK);
121
122     if (this->action_value() < 0)
123         set_bits(result, FLAG_CAUSE_ACTION);
124
125     return result;
126 }
127
128 void PlayerStatusBase::set_locals()
129 {
130     this->default_value = 0;
131     this->min_value = 0;
132     this->max_value = 0;
133     this->tr_flag = TR_FLAG_MAX;
134     this->tr_bad_flag = TR_FLAG_MAX;
135 }
136
137 BIT_FLAGS PlayerStatusBase::equipments_flags()
138 {
139     this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
140     object_type *o_ptr;
141     BIT_FLAGS flgs[TR_FLAG_SIZE];
142     BIT_FLAGS result = 0L;
143     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
144         o_ptr = &owner_ptr->inventory_list[i];
145         if (!o_ptr->k_idx)
146             continue;
147
148         object_flags(owner_ptr, o_ptr, flgs);
149
150         if (has_flag(flgs, tr_flag))
151             set_bits(result, convert_inventory_slot_type_to_flag_cause(static_cast<inventory_slot_type>(i)));
152     }
153     return result;
154 }
155
156 BIT_FLAGS PlayerStatusBase::equipments_bad_flags()
157 {
158     this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
159     object_type *o_ptr;
160     BIT_FLAGS flgs[TR_FLAG_SIZE];
161     BIT_FLAGS result = 0L;
162     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
163         o_ptr = &owner_ptr->inventory_list[i];
164         if (!o_ptr->k_idx)
165             continue;
166
167         object_flags(owner_ptr, o_ptr, flgs);
168
169         if (has_flag(flgs, tr_bad_flag)) {
170             if (o_ptr->pval < 0) {
171                 set_bits(result, convert_inventory_slot_type_to_flag_cause(static_cast<inventory_slot_type>(i)));
172             }
173         }
174     }
175     return result;
176 }
177
178 s16b PlayerStatusBase::equipments_value()
179 {
180     this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
181     s16b result = 0;
182     for (int i = INVEN_MAIN_HAND; i < INVEN_TOTAL; i++) {
183         object_type *o_ptr = &owner_ptr->inventory_list[i];
184         BIT_FLAGS flgs[TR_FLAG_SIZE];
185         object_flags(owner_ptr, o_ptr, flgs);
186
187         if (!o_ptr->k_idx)
188             continue;
189         if (has_flag(flgs, tr_flag))
190             result += o_ptr->pval;
191     }
192     return result;
193 }
194
195 s16b PlayerStatusBase::race_value() { return 0; }
196 s16b PlayerStatusBase::class_value() { return 0; }
197 s16b PlayerStatusBase::personality_value() { return 0; }
198 s16b PlayerStatusBase::time_effect_value() { return 0; }
199 s16b PlayerStatusBase::battleform_value() { return 0; }
200 s16b PlayerStatusBase::mutation_value() { return 0; }
201 s16b PlayerStatusBase::riding_value() { return 0; }
202 s16b PlayerStatusBase::inventory_weight_value() { return 0; }
203 s16b PlayerStatusBase::action_value() { return 0; }