OSDN Git Service

[Chore] UTF-8エンコーディングのファイルからBOMを削除
[hengbandforosx/hengbandosx.git] / src / player / player-skill.cpp
index d2d3005..4fc7dc8 100644 (file)
@@ -1,15 +1,17 @@
-#include "player/player-skill.h"
-#include "core/player-update-types.h"
+#include "player/player-skill.h"
 #include "monster-race/monster-race.h"
 #include "player-base/player-class.h"
+#include "player-base/player-race.h"
 #include "player-info/class-info.h"
 #include "player/player-realm.h"
+#include "realm/realm-names-table.h"
 #include "sv-definition/sv-weapon-types.h"
 #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/item-entity.h"
+#include "system/monster-entity.h"
+#include "system/monster-race-info.h"
 #include "system/player-type-definition.h"
+#include "system/redrawing-flags-updater.h"
 #include "util/bit-flags-calculator.h"
 
 /* Proficiency of weapons and misc. skills (except riding) */
@@ -36,7 +38,7 @@ constexpr SUB_EXP SPELL_EXP_MASTER = 1600;
 /*
  * The skill table
  */
-std::vector<skill_table> s_info;
+std::vector<skill_table> class_skills_info;
 
 namespace {
 
@@ -60,7 +62,7 @@ void gain_attack_skill_exp(PlayerType *player_ptr, short &exp, const GainAmountL
     }
 
     exp += static_cast<short>(gain_amount);
-    set_bits(player_ptr->update, PU_BONUS);
+    RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::BONUS);
 }
 
 void gain_spell_skill_exp_aux(PlayerType *player_ptr, short &exp, const GainAmountList &gain_amount_list, int spell_level)
@@ -90,7 +92,7 @@ void gain_spell_skill_exp_aux(PlayerType *player_ptr, short &exp, const GainAmou
     }
 
     exp += static_cast<short>(gain_amount);
-    set_bits(player_ptr->update, PU_BONUS);
+    RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::BONUS);
 }
 
 }
@@ -142,16 +144,17 @@ SUB_EXP PlayerSkill::spell_exp_at(PlayerSkillRank rank)
  */
 PlayerSkillRank PlayerSkill::weapon_skill_rank(int weapon_exp)
 {
-    if (weapon_exp < WEAPON_EXP_BEGINNER)
+    if (weapon_exp < WEAPON_EXP_BEGINNER) {
         return PlayerSkillRank::UNSKILLED;
-    else if (weapon_exp < WEAPON_EXP_SKILLED)
+    } else if (weapon_exp < WEAPON_EXP_SKILLED) {
         return PlayerSkillRank::BEGINNER;
-    else if (weapon_exp < WEAPON_EXP_EXPERT)
+    } else if (weapon_exp < WEAPON_EXP_EXPERT) {
         return PlayerSkillRank::SKILLED;
-    else if (weapon_exp < WEAPON_EXP_MASTER)
+    } else if (weapon_exp < WEAPON_EXP_MASTER) {
         return PlayerSkillRank::EXPERT;
-    else
+    } else {
         return PlayerSkillRank::MASTER;
+    }
 }
 
 bool PlayerSkill::valid_weapon_exp(int weapon_exp)
@@ -166,16 +169,17 @@ bool PlayerSkill::valid_weapon_exp(int weapon_exp)
  */
 PlayerSkillRank PlayerSkill::riding_skill_rank(int riding_exp)
 {
-    if (riding_exp < RIDING_EXP_BEGINNER)
+    if (riding_exp < RIDING_EXP_BEGINNER) {
         return PlayerSkillRank::UNSKILLED;
-    else if (riding_exp < RIDING_EXP_SKILLED)
+    } else if (riding_exp < RIDING_EXP_SKILLED) {
         return PlayerSkillRank::BEGINNER;
-    else if (riding_exp < RIDING_EXP_EXPERT)
+    } else if (riding_exp < RIDING_EXP_EXPERT) {
         return PlayerSkillRank::SKILLED;
-    else if (riding_exp < RIDING_EXP_MASTER)
+    } else if (riding_exp < RIDING_EXP_MASTER) {
         return PlayerSkillRank::EXPERT;
-    else
+    } else {
         return PlayerSkillRank::MASTER;
+    }
 }
 
 /*!
@@ -185,16 +189,17 @@ PlayerSkillRank PlayerSkill::riding_skill_rank(int riding_exp)
  */
 PlayerSkillRank PlayerSkill::spell_skill_rank(int spell_exp)
 {
-    if (spell_exp < SPELL_EXP_BEGINNER)
+    if (spell_exp < SPELL_EXP_BEGINNER) {
         return PlayerSkillRank::UNSKILLED;
-    else if (spell_exp < SPELL_EXP_SKILLED)
+    } else if (spell_exp < SPELL_EXP_SKILLED) {
         return PlayerSkillRank::BEGINNER;
-    else if (spell_exp < SPELL_EXP_EXPERT)
+    } else if (spell_exp < SPELL_EXP_EXPERT) {
         return PlayerSkillRank::SKILLED;
-    else if (spell_exp < SPELL_EXP_MASTER)
+    } else if (spell_exp < SPELL_EXP_MASTER) {
         return PlayerSkillRank::EXPERT;
-    else
+    } else {
         return PlayerSkillRank::MASTER;
+    }
 }
 
 concptr PlayerSkill::skill_name(PlayerSkillKindType skill)
@@ -233,37 +238,37 @@ concptr PlayerSkill::skill_rank_str(PlayerSkillRank rank)
     return _("[不明]", "[Unknown]");
 }
 
-void PlayerSkill::gain_melee_weapon_exp(const ObjectType *o_ptr)
+void PlayerSkill::gain_melee_weapon_exp(const ItemEntity *o_ptr)
 {
-    const GainAmountList gain_amount_list{ 80, 10, 1, (one_in_(2) ? 1 : 0) };
-    constexpr GainAmountList others_gain_amount_list{ 8, 1, 0, 0 };
-
-    for (auto sval = 0U; sval < this->player_ptr->weapon_exp[o_ptr->tval].size(); ++sval) {
-        auto &now_exp = this->player_ptr->weapon_exp[o_ptr->tval][sval];
-        if (now_exp < this->player_ptr->weapon_exp_max[o_ptr->tval][sval]) {
+    const GainAmountList gain_amount_list{ { 80, 10, 1, (one_in_(2) ? 1 : 0) } };
+    constexpr GainAmountList others_gain_amount_list{ { 8, 1, 0, 0 } };
+    const auto tval = o_ptr->bi_key.tval();
+    for (auto sval = 0U; sval < this->player_ptr->weapon_exp[tval].size(); ++sval) {
+        auto &now_exp = this->player_ptr->weapon_exp[tval][sval];
+        if (now_exp < this->player_ptr->weapon_exp_max[tval][sval]) {
             gain_attack_skill_exp(this->player_ptr, now_exp,
-                (static_cast<int>(sval) == o_ptr->sval) ? gain_amount_list : others_gain_amount_list);
+                (static_cast<int>(sval) == o_ptr->bi_key.sval()) ? gain_amount_list : others_gain_amount_list);
         }
     }
 }
 
-void PlayerSkill::gain_range_weapon_exp(const ObjectType *o_ptr)
+void PlayerSkill::gain_range_weapon_exp(const ItemEntity *o_ptr)
 {
-    constexpr GainAmountList gain_amount_list{ 80, 25, 10, 2 };
-    constexpr GainAmountList others_gain_amount_list{ 8, 2, 0, 0 };
-
-    for (auto sval = 0U; sval < this->player_ptr->weapon_exp[o_ptr->tval].size(); ++sval) {
-        auto &now_exp = this->player_ptr->weapon_exp[o_ptr->tval][sval];
-        if (now_exp < this->player_ptr->weapon_exp_max[o_ptr->tval][sval]) {
+    constexpr GainAmountList gain_amount_list{ { 80, 25, 10, 2 } };
+    constexpr GainAmountList others_gain_amount_list{ { 8, 2, 0, 0 } };
+    const auto tval = o_ptr->bi_key.tval();
+    for (auto sval = 0U; sval < this->player_ptr->weapon_exp[tval].size(); ++sval) {
+        auto &now_exp = this->player_ptr->weapon_exp[tval][sval];
+        if (now_exp < this->player_ptr->weapon_exp_max[tval][sval]) {
             gain_attack_skill_exp(this->player_ptr, now_exp,
-                (static_cast<int>(sval) == o_ptr->sval) ? gain_amount_list : others_gain_amount_list);
+                (static_cast<int>(sval) == o_ptr->bi_key.sval()) ? gain_amount_list : others_gain_amount_list);
         }
     }
 }
 
 void PlayerSkill::gain_martial_arts_skill_exp()
 {
-    if (this->player_ptr->skill_exp[PlayerSkillKindType::MARTIAL_ARTS] < s_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::MARTIAL_ARTS]) {
+    if (this->player_ptr->skill_exp[PlayerSkillKindType::MARTIAL_ARTS] < class_skills_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::MARTIAL_ARTS]) {
         const GainAmountList gain_amount_list{ 40, 5, 1, (one_in_(3) ? 1 : 0) };
         gain_attack_skill_exp(this->player_ptr, this->player_ptr->skill_exp[PlayerSkillKindType::MARTIAL_ARTS], gain_amount_list);
     }
@@ -271,87 +276,97 @@ void PlayerSkill::gain_martial_arts_skill_exp()
 
 void PlayerSkill::gain_two_weapon_skill_exp()
 {
-    if (this->player_ptr->skill_exp[PlayerSkillKindType::TWO_WEAPON] < s_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::TWO_WEAPON]) {
+    if (this->player_ptr->skill_exp[PlayerSkillKindType::TWO_WEAPON] < class_skills_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::TWO_WEAPON]) {
         const GainAmountList gain_amount_list{ 80, 4, 1, (one_in_(3) ? 1 : 0) };
         gain_attack_skill_exp(this->player_ptr, this->player_ptr->skill_exp[PlayerSkillKindType::TWO_WEAPON], gain_amount_list);
     }
 }
 
-void PlayerSkill::gain_riding_skill_exp_on_melee_attack(const monster_race *r_ptr)
+void PlayerSkill::gain_riding_skill_exp_on_melee_attack(const MonsterRaceInfo *r_ptr)
 {
     auto now_exp = this->player_ptr->skill_exp[PlayerSkillKindType::RIDING];
-    auto max_exp = s_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::RIDING];
-    if (now_exp >= max_exp)
+    auto max_exp = class_skills_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::RIDING];
+    if (now_exp >= max_exp) {
         return;
+    }
 
-    auto riding_level = r_info[this->player_ptr->current_floor_ptr->m_list[this->player_ptr->riding].r_idx].level;
+    auto riding_level = monraces_info[this->player_ptr->current_floor_ptr->m_list[this->player_ptr->riding].r_idx].level;
     int inc = 0;
 
-    if ((now_exp / 200 - 5) < r_ptr->level)
+    if ((now_exp / 200 - 5) < r_ptr->level) {
         inc += 1;
+    }
 
     if ((now_exp / 100) < riding_level) {
-        if ((now_exp / 100 + 15) < riding_level)
+        if ((now_exp / 100 + 15) < riding_level) {
             inc += 1 + (riding_level - (now_exp / 100 + 15));
-        else
+        } else {
             inc += 1;
+        }
     }
 
     this->player_ptr->skill_exp[PlayerSkillKindType::RIDING] = std::min<SUB_EXP>(max_exp, now_exp + inc);
-    set_bits(this->player_ptr->update, PU_BONUS);
+    RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::BONUS);
 }
 
 void PlayerSkill::gain_riding_skill_exp_on_range_attack()
 {
     auto now_exp = this->player_ptr->skill_exp[PlayerSkillKindType::RIDING];
-    auto max_exp = s_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::RIDING];
-    if (now_exp >= max_exp)
+    auto max_exp = class_skills_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::RIDING];
+    if (now_exp >= max_exp) {
         return;
+    }
 
-    if (((this->player_ptr->skill_exp[PlayerSkillKindType::RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 < r_info[this->player_ptr->current_floor_ptr->m_list[this->player_ptr->riding].r_idx].level) && one_in_(2)) {
+    const auto *floor_ptr = this->player_ptr->current_floor_ptr;
+    const auto &monster = floor_ptr->m_list[this->player_ptr->riding];
+    const auto &monrace = monraces_info[monster.r_idx];
+    if (((this->player_ptr->skill_exp[PlayerSkillKindType::RIDING] - (RIDING_EXP_BEGINNER * 2)) / 200 < monrace.level) && one_in_(2)) {
         this->player_ptr->skill_exp[PlayerSkillKindType::RIDING] += 1;
-        set_bits(this->player_ptr->update, PU_BONUS);
+        RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::BONUS);
     }
 }
 
-void PlayerSkill::gain_riding_skill_exp_on_fall_off_check(HIT_POINT dam)
+void PlayerSkill::gain_riding_skill_exp_on_fall_off_check(int dam)
 {
     auto now_exp = this->player_ptr->skill_exp[PlayerSkillKindType::RIDING];
-    auto max_exp = s_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::RIDING];
-    if (now_exp >= max_exp || max_exp <= 1000)
+    auto max_exp = class_skills_info[enum2i(this->player_ptr->pclass)].s_max[PlayerSkillKindType::RIDING];
+    if (now_exp >= max_exp || max_exp <= 1000) {
         return;
+    }
 
-    auto riding_level = r_info[this->player_ptr->current_floor_ptr->m_list[this->player_ptr->riding].r_idx].level;
+    auto riding_level = monraces_info[this->player_ptr->current_floor_ptr->m_list[this->player_ptr->riding].r_idx].level;
 
-    if ((dam / 2 + riding_level) <= (now_exp / 30 + 10))
+    if ((dam / 2 + riding_level) <= (now_exp / 30 + 10)) {
         return;
+    }
 
     int inc = 0;
-    if ((now_exp / 100 + 15) < riding_level)
+    if ((now_exp / 100 + 15) < riding_level) {
         inc += 1 + (riding_level - (now_exp / 100 + 15));
-    else
+    } else {
         inc += 1;
+    }
 
     this->player_ptr->skill_exp[PlayerSkillKindType::RIDING] = std::min<SUB_EXP>(max_exp, now_exp + inc);
-    set_bits(this->player_ptr->update, PU_BONUS);
+    RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::BONUS);
 }
 
 void PlayerSkill::gain_spell_skill_exp(int realm, int spell_idx)
 {
-    if ((realm < 1) || ((static_cast<int>(std::size(mp_ptr->info)) < realm) && (realm != REALM_MUSIC) && (realm != REALM_HEX))) {
-        return;
-    }
+    auto is_valid_realm = is_magic(realm) ||
+                          (realm == REALM_MUSIC) || (realm == REALM_HEX);
+    is_valid_realm &= (realm == this->player_ptr->realm1) || (realm == this->player_ptr->realm2);
+    const auto is_valid_spell_idx = (0 <= spell_idx) && (spell_idx < 32);
 
-    if (((spell_idx < 0) || (32 <= spell_idx)) ||
-        ((realm != this->player_ptr->realm1) && (realm != this->player_ptr->realm2))) {
+    if (!is_valid_realm || !is_valid_spell_idx) {
         return;
     }
 
-    constexpr GainAmountList gain_amount_list_first{ 60, 8, 2, 1 };
-    constexpr GainAmountList gain_amount_list_second{ 60, 8, 2, 0 };
+    constexpr GainAmountList gain_amount_list_first{ { 60, 8, 2, 1 } };
+    constexpr GainAmountList gain_amount_list_second{ { 60, 8, 2, 0 } };
 
     const auto is_first_realm = (realm == this->player_ptr->realm1);
-    const auto *s_ptr = &mp_ptr->info[realm - 1][spell_idx];
+    const auto *s_ptr = is_magic(realm) ? &mp_ptr->info[realm - 1][spell_idx] : &technic_info[realm - MIN_TECHNIC][spell_idx];
 
     gain_spell_skill_exp_aux(this->player_ptr, this->player_ptr->spell_exp[spell_idx + (is_first_realm ? 0 : 32)],
         (is_first_realm ? gain_amount_list_first : gain_amount_list_second), s_ptr->slevel);
@@ -393,8 +408,7 @@ PlayerSkillRank PlayerSkill::gain_spell_skill_exp_over_learning(int spell_idx)
         exp = SPELL_EXP_BEGINNER + exp / 3;
     }
 
-    set_bits(this->player_ptr->update, PU_BONUS);
-
+    RedrawingFlagsUpdater::get_instance().set_flag(StatusRecalculatingFlag::BONUS);
     return PlayerSkill::spell_skill_rank(exp);
 }
 
@@ -408,16 +422,17 @@ PlayerSkillRank PlayerSkill::gain_spell_skill_exp_over_learning(int spell_idx)
 EXP PlayerSkill::exp_of_spell(int realm, int spell_idx) const
 {
     PlayerClass pc(this->player_ptr);
-    if (pc.equals(PlayerClassType::SORCERER))
+    if (pc.equals(PlayerClassType::SORCERER)) {
         return SPELL_EXP_MASTER;
-    else if (pc.equals(PlayerClassType::RED_MAGE))
+    } else if (pc.equals(PlayerClassType::RED_MAGE)) {
         return SPELL_EXP_SKILLED;
-    else if (realm == this->player_ptr->realm1)
+    } else if (realm == this->player_ptr->realm1) {
         return this->player_ptr->spell_exp[spell_idx];
-    else if (realm == this->player_ptr->realm2)
+    } else if (realm == this->player_ptr->realm2) {
         return this->player_ptr->spell_exp[spell_idx + 32];
-    else
+    } else {
         return 0;
+    }
 }
 
 /*!
@@ -428,7 +443,7 @@ EXP PlayerSkill::exp_of_spell(int realm, int spell_idx) const
  */
 void PlayerSkill::apply_special_weapon_skill_max_values()
 {
-    this->player_ptr->weapon_exp_max = s_info[enum2i(this->player_ptr->pclass)].w_max;
+    this->player_ptr->weapon_exp_max = class_skills_info[enum2i(this->player_ptr->pclass)].w_max;
     if (PlayerClass(this->player_ptr).equals(PlayerClassType::SORCERER)) {
         return;
     }
@@ -438,7 +453,7 @@ void PlayerSkill::apply_special_weapon_skill_max_values()
         w_exp_max[ItemKindType::HAFTED][SV_WHIP] = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER);
     }
 
-    if (this->player_ptr->prace == PlayerRaceType::MERFOLK) {
+    if (PlayerRace(player_ptr).equals(PlayerRaceType::MERFOLK)) {
         w_exp_max[ItemKindType::POLEARM][SV_TRIDENT] = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER);
         w_exp_max[ItemKindType::POLEARM][SV_TRIFURCATE_SPEAR] = PlayerSkill::weapon_exp_at(PlayerSkillRank::MASTER);
     }