1 #include "player-info/alignment.h"
2 #include "artifact/fixed-art-types.h"
3 #include "game-option/text-display-options.h"
4 #include "inventory/inventory-slot-types.h"
5 #include "monster/monster-info.h"
6 #include "monster-race/monster-race.h"
7 #include "monster-race/race-flags3.h"
8 #include "monster/monster-status.h"
9 #include "player-info/avatar.h"
10 #include "player/player-race.h"
11 #include "player/player-status.h" // todo has_melee_weapon()が相互依存している。後で消す
12 #include "system/floor-type-definition.h"
13 #include "system/monster-race-definition.h"
14 #include "system/monster-type-definition.h"
15 #include "system/object-type-definition.h"
16 #include "system/player-type-definition.h"
17 #include "util/bit-flags-calculator.h"
19 PlayerAlignment::PlayerAlignment(player_type *creature_ptr)
21 this->creature_ptr = creature_ptr;
25 * @brief クリーチャーの抽象的善悪アライメントの表記を返す。 / Return alignment title
26 * @param with_value 徳の情報と一緒に表示する時だけtrue
27 * @return アライメントの表記を返す。
29 concptr PlayerAlignment::get_alignment_description(bool with_value)
31 auto s = alignment_label();
32 if (with_value || show_actual_value)
33 return format(_("%s(%ld)", "%s (%ld)"), s, static_cast<long>(this->creature_ptr->alignment));
43 void PlayerAlignment::update_alignment()
45 this->reset_alignment();
46 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
47 for (MONSTER_IDX m_idx = floor_ptr->m_max - 1; m_idx >= 1; m_idx--) {
48 auto *m_ptr = &floor_ptr->m_list[m_idx];
49 if (!monster_is_valid(m_ptr))
51 auto *r_ptr = &r_info[m_ptr->r_idx];
56 if (any_bits(r_ptr->flags3, RF3_GOOD)) {
57 this->set_alignment(r_ptr->level, update_alignment_type::ALIGNMENT_ADDITION);
60 if (any_bits(r_ptr->flags3, RF3_EVIL)) {
61 this->set_alignment(r_ptr->level, update_alignment_type::ALIGNMENT_SUBTRACTION);
65 if (creature_ptr->mimic_form) {
66 switch (creature_ptr->mimic_form) {
68 this->set_alignment(200, update_alignment_type::ALIGNMENT_SUBTRACTION);
70 case MIMIC_DEMON_LORD:
71 this->set_alignment(200, update_alignment_type::ALIGNMENT_SUBTRACTION);
75 switch (creature_ptr->prace) {
77 this->set_alignment(200, update_alignment_type::ALIGNMENT_ADDITION);
80 this->set_alignment(200, update_alignment_type::ALIGNMENT_SUBTRACTION);
88 for (int i = 0; i < 2; i++) {
89 if (!has_melee_weapon(creature_ptr, INVEN_MAIN_HAND + i) || (creature_ptr->inventory_list[INVEN_MAIN_HAND + i].name1 != ART_IRON_BALL))
92 this->set_alignment(1000, update_alignment_type::ALIGNMENT_SUBTRACTION);
97 for (int i = 0; i < 8; i++) {
98 switch (creature_ptr->vir_types[i]) {
100 this->set_alignment(creature_ptr->virtues[i] * 2, update_alignment_type::ALIGNMENT_ADDITION);
109 this->set_alignment(creature_ptr->virtues[i], update_alignment_type::ALIGNMENT_SUBTRACTION);
112 this->set_alignment(creature_ptr->virtues[i], update_alignment_type::ALIGNMENT_ADDITION);
117 for (int i = 0; i < j; i++) {
118 if (creature_ptr->alignment > 0) {
119 this->set_alignment(creature_ptr->virtues[neutral[i]] / 2, update_alignment_type::ALIGNMENT_SUBTRACTION);
120 if (creature_ptr->alignment < 0)
121 this->reset_alignment();
122 } else if (creature_ptr->alignment < 0) {
123 this->set_alignment(creature_ptr->virtues[neutral[i]] / 2, update_alignment_type::ALIGNMENT_ADDITION);
124 if (creature_ptr->alignment > 0)
125 this->reset_alignment();
130 void PlayerAlignment::set_alignment(int value, update_alignment_type ua_type)
133 case update_alignment_type::ALIGNMENT_SUBSTITUTION:
134 this->creature_ptr->alignment = value;
136 case update_alignment_type::ALIGNMENT_ADDITION:
137 this->creature_ptr->alignment += value;
139 case update_alignment_type::ALIGNMENT_SUBTRACTION:
140 this->creature_ptr->alignment -= value;
147 void PlayerAlignment::reset_alignment()
149 this->set_alignment(0, update_alignment_type::ALIGNMENT_SUBSTITUTION);
153 * @brief クリーチャーの抽象的善悪アライメントの表記名のみを返す。 / Return only alignment title
154 * @param creature_ptr 算出するクリーチャーの参照ポインタ。
157 concptr PlayerAlignment::alignment_label()
159 if (this->creature_ptr->alignment > 150)
160 return _("大善", "Lawful");
161 else if (this->creature_ptr->alignment > 50)
162 return _("中善", "Good");
163 else if (this->creature_ptr->alignment > 10)
164 return _("小善", "Neutral Good");
165 else if (this->creature_ptr->alignment > -11)
166 return _("中立", "Neutral");
167 else if (this->creature_ptr->alignment > -51)
168 return _("小悪", "Neutral Evil");
169 else if (this->creature_ptr->alignment > -151)
170 return _("中悪", "Evil");
172 return _("大悪", "Chaotic");