From 19e24840747c719c6e179459ae75b1c6ef44d9a0 Mon Sep 17 00:00:00 2001 From: newfrenchy83 Date: Tue, 17 Oct 2023 20:17:04 +0200 Subject: [PATCH] simplify code and remove unusable function --- src/units/abilities.cpp | 50 ++++++++++++++++----------------------- src/units/attack_type.hpp | 5 ---- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/src/units/abilities.cpp b/src/units/abilities.cpp index e70d4b414f67a..afec3a45e0d85 100644 --- a/src/units/abilities.cpp +++ b/src/units/abilities.cpp @@ -1178,27 +1178,27 @@ int attack_type::modified_damage() const return damage_value; } -static void alignment_list(unit_ability_list& align_list) -{ //check if have abilities or specials alignment and remove alignment bad specified - const std::set checking_alignment = {"neutral", "lawful", "chaotic", "liminal"}; - utils::erase_if(align_list, [&](const unit_ability& i) { - return (checking_alignment.count((*i.ability_cfg)["alignment"].str()) == 0); - }); -} - -void attack_type::choose_alignment(unit_ability_list& align_list, unit_alignments::type& alignment) const +std::pair attack_type::specials_alignment() const { - std::map values; + unit_ability_list align_list = get_specials_and_abilities("attack_alignment"); + if(align_list.empty()){ + return {(*self_).alignment(), 1}; + } + const std::set checking_alignment = {"neutral", "lawful", "chaotic", "liminal"}; std::map lists; for(const auto& i : align_list) { - const auto& alignment = (*i.ability_cfg)["alignment"].str(); - values[alignment] += 1; - lists[alignment].emplace_back(i); - } - int count_liminal = values["liminal"]; - int count_chaotic = values["chaotic"]; - int count_lawful = values["lawful"]; - int count_neutral = values["neutral"]; + if(checking_alignment.count((*i.ability_cfg)["alignment"].str()) != 0){ + const auto& alignment = (*i.ability_cfg)["alignment"].str(); + lists[alignment].emplace_back(i); + } + } + if(lists.empty()){ + return {(*self_).alignment(), 1}; + } + int count_liminal = lists["liminal"].size(); + int count_chaotic = lists["chaotic"].size(); + int count_lawful = lists["lawful"].size(); + int count_neutral = lists["neutral"].size(); std::string str_alignment; if(count_liminal > 0 && count_liminal >= count_chaotic && count_liminal >= count_lawful && count_liminal >= count_neutral){ str_alignment = "liminal"; @@ -1213,23 +1213,13 @@ void attack_type::choose_alignment(unit_ability_list& align_list, unit_alignment str_alignment = "chaotic"; } + unit_alignments::type alignment = (*self_).alignment(); auto new_align = unit_alignments::get_enum(str_alignment); if(new_align) { alignment = *new_align; } - align_list = lists[str_alignment]; -} -std::pair attack_type::specials_alignment() const -{ - unit_ability_list align_list = get_specials_and_abilities("attack_alignment"); - alignment_list(align_list); - if(align_list.empty()){ - return {(*self_).alignment(), 1}; - } - unit_alignments::type alignment; - choose_alignment(align_list, alignment); - return {alignment, (std::max(0, composite_value(align_list, 100))/100)}; + return {alignment, (std::max(0, composite_value(lists[str_alignment], 100))/100)}; } diff --git a/src/units/attack_type.hpp b/src/units/attack_type.hpp index ef8ca98330a5f..e257443f1c989 100644 --- a/src/units/attack_type.hpp +++ b/src/units/attack_type.hpp @@ -143,11 +143,6 @@ class attack_type : public std::enable_shared_from_this // Configured as a bit field, in case that is useful. enum AFFECTS { AFFECT_SELF=1, AFFECT_OTHER=2, AFFECT_EITHER=3 }; - /** Returns the ToD and percentage in specials_alignment(). If no such specials are active, it returns the unit's alignment. - * @param align_list list who contains [attack_alignment] with alignment choose for composite_value function. - * @param alignment alignment choose, if not [attack_alignment] value is unit alignment. - */ - void choose_alignment(unit_ability_list& align_list, unit_alignments::type& alignment) const; /** * Filter a list of abilities or weapon specials, removing any entries that don't own * the overwrite_specials attributes.