#include "player-info/alignment.h"
+#include "artifact/fixed-art-types.h"
#include "game-option/text-display-options.h"
+#include "inventory/inventory-slot-types.h"
+#include "monster/monster-info.h"
+#include "monster-race/monster-race.h"
+#include "monster-race/race-flags3.h"
+#include "monster/monster-status.h"
+#include "player-info/avatar.h"
+#include "player/player-race.h"
+#include "player/player-status.h" // todo has_melee_weapon()が相互依存している。後で消す
+#include "system/floor-type-definition.h"
+#include "system/monster-race-definition.h"
+#include "system/monster-type-definition.h"
+#include "system/object-type-definition.h"
#include "system/player-type-definition.h"
+#include "util/bit-flags-calculator.h"
PlayerAlignment::PlayerAlignment(player_type *creature_ptr)
{
}
/*!
+ * @brief クリーチャーの抽象的善悪アライメントの表記を返す。 / Return alignment title
+ * @param with_value 徳の情報と一緒に表示する時だけtrue
+ * @return アライメントの表記を返す。
+ */
+concptr PlayerAlignment::get_alignment_description(bool with_value)
+{
+ auto s = alignment_label();
+ if (with_value || show_actual_value)
+ return format(_("%s(%ld)", "%s (%ld)"), s, static_cast<long>(this->creature_ptr->alignment));
+
+ return s;
+}
+
+/*
+ * @brief アライメント情報の更新
+ * @param なし
+ * @return なし
+ */
+void PlayerAlignment::update_alignment()
+{
+ this->reset_alignment();
+ floor_type *floor_ptr = creature_ptr->current_floor_ptr;
+ for (MONSTER_IDX m_idx = floor_ptr->m_max - 1; m_idx >= 1; m_idx--) {
+ auto *m_ptr = &floor_ptr->m_list[m_idx];
+ if (!monster_is_valid(m_ptr))
+ continue;
+ auto *r_ptr = &r_info[m_ptr->r_idx];
+
+ if (!is_pet(m_ptr))
+ continue;
+
+ if (any_bits(r_ptr->flags3, RF3_GOOD)) {
+ this->set_alignment(r_ptr->level, update_alignment_type::ALIGNMENT_ADDITION);
+ }
+
+ if (any_bits(r_ptr->flags3, RF3_EVIL)) {
+ this->set_alignment(r_ptr->level, update_alignment_type::ALIGNMENT_SUBTRACTION);
+ }
+ }
+
+ if (creature_ptr->mimic_form) {
+ switch (creature_ptr->mimic_form) {
+ case MIMIC_DEMON:
+ this->set_alignment(200, update_alignment_type::ALIGNMENT_SUBTRACTION);
+ break;
+ case MIMIC_DEMON_LORD:
+ this->set_alignment(200, update_alignment_type::ALIGNMENT_SUBTRACTION);
+ break;
+ }
+ } else {
+ switch (creature_ptr->prace) {
+ case RACE_ARCHON:
+ this->set_alignment(200, update_alignment_type::ALIGNMENT_ADDITION);
+ break;
+ case RACE_BALROG:
+ this->set_alignment(200, update_alignment_type::ALIGNMENT_SUBTRACTION);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ for (int i = 0; i < 2; i++) {
+ if (!has_melee_weapon(creature_ptr, INVEN_MAIN_HAND + i) || (creature_ptr->inventory_list[INVEN_MAIN_HAND + i].name1 != ART_IRON_BALL))
+ continue;
+
+ this->set_alignment(1000, update_alignment_type::ALIGNMENT_SUBTRACTION);
+ }
+
+ int j = 0;
+ int neutral[2];
+ for (int i = 0; i < 8; i++) {
+ switch (creature_ptr->vir_types[i]) {
+ case V_JUSTICE:
+ this->set_alignment(creature_ptr->virtues[i] * 2, update_alignment_type::ALIGNMENT_ADDITION);
+ break;
+ case V_CHANCE:
+ break;
+ case V_NATURE:
+ case V_HARMONY:
+ neutral[j++] = i;
+ break;
+ case V_UNLIFE:
+ this->set_alignment(creature_ptr->virtues[i], update_alignment_type::ALIGNMENT_SUBTRACTION);
+ break;
+ default:
+ this->set_alignment(creature_ptr->virtues[i], update_alignment_type::ALIGNMENT_ADDITION);
+ break;
+ }
+ }
+
+ for (int i = 0; i < j; i++) {
+ if (creature_ptr->alignment > 0) {
+ this->set_alignment(creature_ptr->virtues[neutral[i]] / 2, update_alignment_type::ALIGNMENT_SUBTRACTION);
+ if (creature_ptr->alignment < 0)
+ this->reset_alignment();
+ } else if (creature_ptr->alignment < 0) {
+ this->set_alignment(creature_ptr->virtues[neutral[i]] / 2, update_alignment_type::ALIGNMENT_ADDITION);
+ if (creature_ptr->alignment > 0)
+ this->reset_alignment();
+ }
+ }
+}
+
+void PlayerAlignment::set_alignment(int value, update_alignment_type ua_type)
+{
+ switch (ua_type) {
+ case update_alignment_type::ALIGNMENT_SUBSTITUTION:
+ this->creature_ptr->alignment = value;
+ return;
+ case update_alignment_type::ALIGNMENT_ADDITION:
+ this->creature_ptr->alignment += value;
+ return;
+ case update_alignment_type::ALIGNMENT_SUBTRACTION:
+ this->creature_ptr->alignment -= value;
+ return;
+ default:
+ return;
+ }
+}
+
+void PlayerAlignment::reset_alignment()
+{
+ this->set_alignment(0, update_alignment_type::ALIGNMENT_SUBSTITUTION);
+}
+
+/*!
* @brief クリーチャーの抽象的善悪アライメントの表記名のみを返す。 / Return only alignment title
* @param creature_ptr 算出するクリーチャーの参照ポインタ。
* @return アライメントの表記名
else
return _("大悪", "Chaotic");
}
-
-/*!
- * @brief クリーチャーの抽象的善悪アライメントの表記を返す。 / Return alignment title
- * @param creature_ptr 算出するクリーチャーの参照ポインタ。
- * @return アライメントの表記を返す。
- */
-concptr PlayerAlignment::get_alignment_description(bool with_value)
-{
- auto s = alignment_label();
- if (with_value || show_actual_value)
- return format(_("%s(%ld)", "%s (%ld)"), s, static_cast<long>(this->creature_ptr->alignment));
-
- return s;
-}
#include "floor/floor-save.h"
#include "floor/floor-util.h"
#include "game-option/birth-options.h"
-#include "game-option/text-display-options.h"
#include "grid/feature.h"
#include "grid/grid.h"
#include "inventory/inventory-object.h"
-#include "inventory/inventory-slot-types.h"
#include "io/input-key-acceptor.h"
#include "io/write-diary.h"
#include "main/sound-definitions-table.h"
#include "monster-race/monster-race.h"
#include "monster-race/race-flags1.h"
#include "monster-race/race-flags2.h"
-#include "monster-race/race-flags3.h"
#include "monster-race/race-flags7.h"
-#include "monster/monster-info.h"
-#include "monster/monster-status.h"
#include "monster/monster-update.h"
#include "monster/smart-learn-types.h"
#include "mutation/mutation-calculator.h"
#include "object/object-mark-types.h"
#include "perception/object-perception.h"
#include "pet/pet-util.h"
+#include "player-info/alignment.h"
#include "player-info/avatar.h"
#include "player-status/player-basic-statistics.h"
#include "player-status/player-hand-types.h"
check_no_flowed(creature_ptr);
}
-static void update_alignment(player_type *creature_ptr)
-{
- creature_ptr->alignment = 0;
- floor_type *floor_ptr = creature_ptr->current_floor_ptr;
- for (MONSTER_IDX m_idx = floor_ptr->m_max - 1; m_idx >= 1; m_idx--) {
- monster_type *m_ptr;
- monster_race *r_ptr;
- m_ptr = &floor_ptr->m_list[m_idx];
- if (!monster_is_valid(m_ptr))
- continue;
- r_ptr = &r_info[m_ptr->r_idx];
-
- if (!is_pet(m_ptr))
- continue;
-
- if (any_bits(r_ptr->flags3, RF3_GOOD))
- creature_ptr->alignment += r_ptr->level;
- if (any_bits(r_ptr->flags3, RF3_EVIL))
- creature_ptr->alignment -= r_ptr->level;
- }
-
- if (creature_ptr->mimic_form) {
- switch (creature_ptr->mimic_form) {
- case MIMIC_DEMON:
- creature_ptr->alignment -= 200;
- break;
- case MIMIC_DEMON_LORD:
- creature_ptr->alignment -= 200;
- break;
- }
- } else {
- switch (creature_ptr->prace) {
- case RACE_ARCHON:
- creature_ptr->alignment += 200;
- break;
- case RACE_BALROG:
- creature_ptr->alignment -= 200;
- break;
-
- default:
- break;
- }
- }
-
- for (int i = 0; i < 2; i++) {
- if (!has_melee_weapon(creature_ptr, INVEN_MAIN_HAND + i))
- continue;
- if (creature_ptr->inventory_list[INVEN_MAIN_HAND + i].name1 != ART_IRON_BALL)
- continue;
- creature_ptr->alignment -= 1000;
- }
-
- int j = 0;
- int neutral[2];
- for (int i = 0; i < 8; i++) {
- switch (creature_ptr->vir_types[i]) {
- case V_JUSTICE:
- creature_ptr->alignment += creature_ptr->virtues[i] * 2;
- break;
- case V_CHANCE:
- break;
- case V_NATURE:
- case V_HARMONY:
- neutral[j++] = i;
- break;
- case V_UNLIFE:
- creature_ptr->alignment -= creature_ptr->virtues[i];
- break;
- default:
- creature_ptr->alignment += creature_ptr->virtues[i];
- break;
- }
- }
-
- for (int i = 0; i < j; i++) {
- if (creature_ptr->alignment > 0) {
- creature_ptr->alignment -= creature_ptr->virtues[neutral[i]] / 2;
- if (creature_ptr->alignment < 0)
- creature_ptr->alignment = 0;
- } else if (creature_ptr->alignment < 0) {
- creature_ptr->alignment += creature_ptr->virtues[neutral[i]] / 2;
- if (creature_ptr->alignment > 0)
- creature_ptr->alignment = 0;
- }
- }
-}
-
/*!
* @brief プレイヤーの最大HPを更新する /
* Update the players maximal hit points
if (any_bits(creature_ptr->update, (PU_BONUS))) {
reset_bits(creature_ptr->update, PU_BONUS);
- update_alignment(creature_ptr);
+ std::unique_ptr<PlayerAlignment> alignment(new PlayerAlignment(creature_ptr));
+ alignment->update_alignment();
update_bonuses(creature_ptr);
}