Skip to content

Commit

Permalink
simplify code and remove unusable function
Browse files Browse the repository at this point in the history
  • Loading branch information
newfrenchy83 committed Oct 17, 2023
1 parent b85adb4 commit 19e2484
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
50 changes: 20 additions & 30 deletions src/units/abilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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<unit_alignments::type, int> attack_type::specials_alignment() const
{
std::map<std::string, int> values;
unit_ability_list align_list = get_specials_and_abilities("attack_alignment");
if(align_list.empty()){
return {(*self_).alignment(), 1};
}
const std::set<std::string> checking_alignment = {"neutral", "lawful", "chaotic", "liminal"};
std::map<std::string, unit_ability_list> 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";
Expand All @@ -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<unit_alignments::type, int> 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)};
}


Expand Down
5 changes: 0 additions & 5 deletions src/units/attack_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,6 @@ class attack_type : public std::enable_shared_from_this<attack_type>

// 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.
Expand Down

0 comments on commit 19e2484

Please sign in to comment.