Skip to content

Commit

Permalink
revert last modification and use specials_and_abilities in name of gl…
Browse files Browse the repository at this point in the history
…obal function
  • Loading branch information
newfrenchy83 authored and Pentarctagon committed Mar 26, 2021
1 parent 1bb895c commit 92ad8ab
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 45 deletions.
26 changes: 13 additions & 13 deletions src/actions/attack.cpp
Expand Up @@ -143,14 +143,14 @@ battle_context_unit_stats::battle_context_unit_stats(nonempty_unit_const_ptr up,
opp_ctx.emplace(opp_weapon->specials_context(oppp, up, opp_loc, u_loc, !attacking, weapon));
}

slows = weapon->get_special_bool("slow");
drains = !opp.get_state("undrainable") && weapon->get_special_bool("drains");
petrifies = weapon->get_special_bool("petrifies");
poisons = !opp.get_state("unpoisonable") && weapon->get_special_bool("poison") && !opp.get_state(unit::STATE_POISONED);
slows = weapon->get_special_and_abilities_bool("slow");
drains = !opp.get_state("undrainable") && weapon->get_special_and_abilities_bool("drains");
petrifies = weapon->get_special_and_abilities_bool("petrifies");
poisons = !opp.get_state("unpoisonable") && weapon->get_special_and_abilities_bool("poison") && !opp.get_state(unit::STATE_POISONED);
backstab_pos = is_attacker && backstab_check(u_loc, opp_loc, units, resources::gameboard->teams());
rounds = weapon->get_specials("berserk").highest("value", 1).first;
rounds = weapon->get_specials_and_abilities("berserk").highest("value", 1).first;

firststrike = weapon->get_special_bool("firststrike");
firststrike = weapon->get_special_and_abilities_bool("firststrike");

{
const int distance = distance_between(u_loc, opp_loc);
Expand All @@ -159,8 +159,8 @@ battle_context_unit_stats::battle_context_unit_stats(nonempty_unit_const_ptr up,
}

// Handle plague.
unit_ability_list plague_specials = weapon->get_specials("plague", false);
unit_ability_list alt_plague_specials = weapon->get_specials("plague");
unit_ability_list plague_specials = weapon->get_specials("plague");
unit_ability_list alt_plague_specials = weapon->get_specials_and_abilities("plague");
if(!alt_plague_specials.empty() && plague_specials.empty()){
plague_specials = alt_plague_specials;
}
Expand All @@ -181,7 +181,7 @@ battle_context_unit_stats::battle_context_unit_stats(nonempty_unit_const_ptr up,

cth = std::clamp(cth, 0, 100);

unit_ability_list cth_specials = weapon->get_specials("chance_to_hit");
unit_ability_list cth_specials = weapon->get_specials_and_abilities("chance_to_hit");
unit_abilities::effect cth_effects(cth_specials, cth, backstab_pos, weapon);
cth = cth_effects.get_composite_value();

Expand Down Expand Up @@ -221,14 +221,14 @@ battle_context_unit_stats::battle_context_unit_stats(nonempty_unit_const_ptr up,

// Compute drain amounts only if draining is possible.
if(drains) {
unit_ability_list drain_specials = weapon->get_specials("drains");
unit_ability_list drain_specials = weapon->get_specials_and_abilities("drains");
// Compute the drain percent (with 50% as the base for backward compatibility)
unit_abilities::effect drain_percent_effects(drain_specials, 50, backstab_pos, weapon);
drain_percent = drain_percent_effects.get_composite_value();
}

// Add heal_on_hit (the drain constant)
unit_ability_list heal_on_hit_specials = weapon->get_specials("heal_on_hit");
unit_ability_list heal_on_hit_specials = weapon->get_specials_and_abilities("heal_on_hit");
unit_abilities::effect heal_on_hit_effects(heal_on_hit_specials, 0, backstab_pos, weapon);
drain_constant += heal_on_hit_effects.get_composite_value();

Expand Down Expand Up @@ -308,12 +308,12 @@ battle_context_unit_stats::battle_context_unit_stats(const unit_type* u_type,
slows = weapon->get_special_bool("slow");
drains = !opp_type->musthave_status("undrainable") && weapon->get_special_bool("drains");
petrifies = weapon->get_special_bool("petrifies");
poisons = !opp_type->musthave_status("unpoisonable") && weapon->get_special_bool("poison");
poisons = !opp_type->musthave_status("unpoisonable") && weapon->get_special_and_abilities_bool("poison");
rounds = weapon->get_specials("berserk").highest("value", 1).first;
firststrike = weapon->get_special_bool("firststrike");
disable = weapon->get_special_bool("disable");

unit_ability_list plague_specials = weapon->get_specials("plague", false);
unit_ability_list plague_specials = weapon->get_specials("plague");
plagues = !opp_type->musthave_status("unplagueable") && !plague_specials.empty() &&
opp_type->undead_variation() != "null";

Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/attack_predictions.cpp
Expand Up @@ -133,7 +133,7 @@ void attack_predictions::set_data(window& window, const combatant_data& attacker
}

// Get damage modifiers.
unit_ability_list dmg_specials = weapon->get_specials("damage");
unit_ability_list dmg_specials = weapon->get_specials_and_abilities("damage");
unit_abilities::effect dmg_effect(dmg_specials, weapon->damage(), attacker.stats_.backstab_pos);

// Get the SET damage modifier, if any.
Expand Down
38 changes: 16 additions & 22 deletions src/units/abilities.cpp
Expand Up @@ -693,7 +693,7 @@ namespace {
* active in the current context (see set_specials_context), including
* specials obtained from the opponent's attack.
*/
bool attack_type::get_special_bool_temp(const std::string& special, bool simple_check, bool special_id, bool special_tags) const
bool attack_type::get_special_bool(const std::string& special, bool simple_check, bool special_id, bool special_tags) const
{
{
std::vector<special_match> special_tag_matches;
Expand Down Expand Up @@ -765,9 +765,9 @@ bool attack_type::get_special_bool_temp(const std::string& special, bool simple_
* Returns the currently active specials as an ability list, given the current
* context (see set_specials_context).
*/
unit_ability_list attack_type::get_specials_temp(const std::string& special) const
unit_ability_list attack_type::get_specials(const std::string& special) const
{
//log_scope("get_specials_temp");
//log_scope("get_specials");
const map_location loc = self_ ? self_->get_location() : self_loc_;
unit_ability_list res(loc);

Expand Down Expand Up @@ -964,7 +964,7 @@ void attack_type::modified_attacks(bool is_backstab, unsigned & min_attacks,
unsigned & max_attacks) const
{
// Apply [attacks].
unit_abilities::effect attacks_effect(get_specials("attacks"),
unit_abilities::effect attacks_effect(get_specials_and_abilities("attacks"),
num_attacks(), is_backstab, shared_from_this());
int attacks_value = attacks_effect.get_composite_value();

Expand All @@ -974,7 +974,7 @@ void attack_type::modified_attacks(bool is_backstab, unsigned & min_attacks,
}

// Apply [swarm].
unit_ability_list swarm_specials = get_specials("swarm");
unit_ability_list swarm_specials = get_specials_and_abilities("swarm");
if ( !swarm_specials.empty() ) {
min_attacks = std::max<int>(0, swarm_specials.highest("swarm_attacks_min").first);
max_attacks = std::max<int>(0, swarm_specials.highest("swarm_attacks_max", attacks_value).first);
Expand All @@ -989,7 +989,7 @@ void attack_type::modified_attacks(bool is_backstab, unsigned & min_attacks,
*/
int attack_type::modified_damage(bool is_backstab) const
{
unit_abilities::effect dmg_effect(get_specials("damage"), damage(), is_backstab, shared_from_this());
unit_abilities::effect dmg_effect(get_specials_and_abilities("damage"), damage(), is_backstab, shared_from_this());
int damage_value = dmg_effect.get_composite_value();
return damage_value;
}
Expand Down Expand Up @@ -1158,19 +1158,16 @@ unit_ability_list attack_type::get_weapon_ability(const std::string& ability) co
return abil_list;
}

unit_ability_list attack_type::get_specials(const std::string& special, bool with_ability) const
unit_ability_list attack_type::get_specials_and_abilities(const std::string& special) const
{
unit_ability_list abil_list(self_loc_);
if(with_ability){
abil_list = get_weapon_ability(special);
for(unit_ability_list::iterator i = abil_list.begin(); i != abil_list.end();) {
if((*i->ability_cfg)["overwrite_specials"].to_bool()) {
return abil_list;
}
++i;
unit_ability_list abil_list = get_weapon_ability(special);
for(unit_ability_list::iterator i = abil_list.begin(); i != abil_list.end();) {
if((*i->ability_cfg)["overwrite_specials"].to_bool()) {
return abil_list;
}
++i;
}
abil_list.append(get_specials_temp(special));
abil_list.append(get_specials(special));
return abil_list;
}

Expand Down Expand Up @@ -1362,12 +1359,9 @@ bool attack_type::get_weapon_ability_bool(const std::string& special, bool speci
return false;
}

bool attack_type::get_special_bool(const std::string& special, bool simple_check, bool special_id, bool special_tags) const
bool attack_type::get_special_and_abilities_bool(const std::string& special, bool special_id, bool special_tags) const
{
if(simple_check){
return get_special_bool_temp(special, simple_check, special_id, special_tags);
}
return (get_special_bool_temp(special, simple_check, special_id, special_tags) || get_weapon_ability_bool(special, special_id, special_tags));
return (get_special_bool(special, false, special_id, special_tags) || get_weapon_ability_bool(special, special_id, special_tags));
}
//end of emulate weapon special functions.

Expand Down Expand Up @@ -1462,7 +1456,7 @@ bool attack_type::special_active_impl(const_attack_ptr self_attack, const_attack
return false;
}
if (tag_name == "firststrike" && !is_attacker && other_attack &&
other_attack->get_special_bool("firststrike")) {
other_attack->get_special_and_abilities_bool("firststrike")) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/units/attack_type.cpp
Expand Up @@ -180,7 +180,7 @@ static bool matches_simple_filter(const attack_type & attack, const config & fil
if(!filter_special_id_active.empty()) {
bool found = false;
for(auto& special : filter_special_id_active) {
if(attack.get_special_bool(special, false, true, false)) {
if(attack.get_special_and_abilities_bool(special, true, false)) {
found = true;
break;
}
Expand All @@ -204,7 +204,7 @@ static bool matches_simple_filter(const attack_type & attack, const config & fil
if(!filter_special_type_active.empty()) {
bool found = false;
for(auto& special : filter_special_type_active) {
if(attack.get_special_bool(special, false, false)) {
if(attack.get_special_and_abilities_bool(special, false)) {
found = true;
break;
}
Expand Down
13 changes: 6 additions & 7 deletions src/units/attack_type.hpp
Expand Up @@ -78,8 +78,8 @@ class attack_type : public std::enable_shared_from_this<attack_type>
* @param special_id If true, match @a special against the @c id of special tags.
* @param special_tags If true, match @a special against the tag name of special tags.
*/
bool get_special_bool_temp(const std::string& special, bool simple_check=false, bool special_id=true, bool special_tags=true) const;
unit_ability_list get_specials_temp(const std::string& special) const;
bool get_special_bool(const std::string& special, bool simple_check=false, bool special_id=true, bool special_tags=true) const;
unit_ability_list get_specials(const std::string& special) const;
std::vector<std::pair<t_string, t_string>> special_tooltips(boost::dynamic_bitset<>* active_list = nullptr) const;
std::string weapon_specials(bool only_active=false, bool is_backstab=false) const;

Expand All @@ -88,10 +88,10 @@ class attack_type : public std::enable_shared_from_this<attack_type>
unsigned & max_attacks) const;
/** Returns the damage per attack of this weapon, considering specials. */
int modified_damage(bool is_backstab) const;
/** Returns list for weapon like abilitiesfor each ability type. */
/** Returns list for weapon like abilities for each ability type. */
unit_ability_list get_weapon_ability(const std::string& ability) const;
/** Returns list who contains get_weapon_ability and get_specials_temp list for each ability type */
unit_ability_list get_specials(const std::string& special, bool with_ability = true) const;
/** Returns list who contains get_weapon_ability and get_specials list for each ability type */
unit_ability_list get_specials_and_abilities(const std::string& special) const;
/** used for abilities used like weapon
* @return True if the ability @a special is active.
* @param special The special being checked.
Expand All @@ -102,11 +102,10 @@ class attack_type : public std::enable_shared_from_this<attack_type>
/** used for abilities used like weapon and true specials
* @return True if the ability @a special is active.
* @param special The special being checked.
* @param simple_check If true, check whether the unit has the special, ability don't checked then. Else, check whether the special or ability is currently active.
* @param special_id If true, match @a special against the @c id of special tags.
* @param special_tags If true, match @a special against the tag name of special tags.
*/
bool get_special_bool(const std::string& special, bool simple_check=false, bool special_id=true, bool special_tags=true) const;
bool get_special_and_abilities_bool(const std::string& special, bool special_id=true, bool special_tags=true) const;

// In unit_types.cpp:

Expand Down

0 comments on commit 92ad8ab

Please sign in to comment.