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"
9 * @brief プレイヤーの各ステータス計算用のクラス
10 * @param owner_ptr プレイヤーの参照ポインタ
12 * * コンストラクタでowner_ptrをセット。メンバ変数を0クリア。
14 PlayerStatusBase::PlayerStatusBase(player_type *owner_ptr)
16 this->owner_ptr = owner_ptr;
17 this->set_locals(); /* 初期化。基底クラスの0クリアが呼ばれる。*/
21 * @brief 該当する値を計算して取得する。
23 * * 派生クラスからset_locals()をコールして初期値、上限、下限をセット。
24 * * 各要素毎に計算した値を初期値に単純に加算し、上限と下限で丸める。
26 s16b PlayerStatusBase::getValue()
28 this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
29 s16b pow = this->default_value;
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();
42 if ((pow > this->max_value)) {
43 pow = this->max_value;
46 if (pow < this->min_value)
47 pow = this->min_value;
53 * @brief 修正値が0でないところにビットを立てて返す。
54 * @return 判定結果のBIT_FLAGS
56 BIT_FLAGS PlayerStatusBase::getFlags()
58 BIT_FLAGS result = equipments_flags();
60 if (this->class_value() != 0)
61 set_bits(result, FLAG_CAUSE_CLASS);
63 if (this->race_value() != 0)
64 set_bits(result, FLAG_CAUSE_RACE);
66 if (this->battleform_value() != 0)
67 set_bits(result, FLAG_CAUSE_BATTLE_FORM);
69 if (this->mutation_value() != 0)
70 set_bits(result, FLAG_CAUSE_MUTATION);
72 if (this->time_effect_value() != 0)
73 set_bits(result, FLAG_CAUSE_MAGIC_TIME_EFFECT);
75 if (this->personality_value() != 0)
76 set_bits(result, FLAG_CAUSE_PERSONALITY);
78 if (this->riding_value() != 0)
79 set_bits(result, FLAG_CAUSE_RIDING);
81 if (this->inventory_weight_value() != 0)
82 set_bits(result, FLAG_CAUSE_INVEN_PACK);
84 if (this->action_value() != 0)
85 set_bits(result, FLAG_CAUSE_ACTION);
91 * @brief 修正値が0以下のところにビットを立てて返す。
92 * @return 判定結果のBIT_FLAGS
94 BIT_FLAGS PlayerStatusBase::getBadFlags()
96 BIT_FLAGS result = equipments_bad_flags();
98 if (this->class_value() < 0)
99 set_bits(result, FLAG_CAUSE_CLASS);
101 if (this->race_value() < 0)
102 set_bits(result, FLAG_CAUSE_RACE);
104 if (this->battleform_value() < 0)
105 set_bits(result, FLAG_CAUSE_BATTLE_FORM);
107 if (this->mutation_value() < 0)
108 set_bits(result, FLAG_CAUSE_MUTATION);
110 if (this->time_effect_value() < 0)
111 set_bits(result, FLAG_CAUSE_MAGIC_TIME_EFFECT);
113 if (this->personality_value() < 0)
114 set_bits(result, FLAG_CAUSE_PERSONALITY);
116 if (this->riding_value() < 0)
117 set_bits(result, FLAG_CAUSE_RIDING);
119 if (this->inventory_weight_value() < 0)
120 set_bits(result, FLAG_CAUSE_INVEN_PACK);
122 if (this->action_value() < 0)
123 set_bits(result, FLAG_CAUSE_ACTION);
128 void PlayerStatusBase::set_locals()
130 this->default_value = 0;
133 this->tr_flag = TR_FLAG_MAX;
134 this->tr_bad_flag = TR_FLAG_MAX;
137 BIT_FLAGS PlayerStatusBase::equipments_flags()
139 this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
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];
148 object_flags(owner_ptr, o_ptr, flgs);
150 if (has_flag(flgs, tr_flag))
151 set_bits(result, convert_inventory_slot_type_to_flag_cause(static_cast<inventory_slot_type>(i)));
156 BIT_FLAGS PlayerStatusBase::equipments_bad_flags()
158 this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
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];
167 object_flags(owner_ptr, o_ptr, flgs);
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)));
178 s16b PlayerStatusBase::equipments_value()
180 this->set_locals(); /* 計算前に値のセット。派生クラスの値がセットされる。*/
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);
189 if (has_flag(flgs, tr_flag))
190 result += o_ptr->pval;
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; }