mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-29 19:38:19 +00:00
Rename functions managing special weapons to improve readability for engine devellopper
When I was looking at the special weapons extension to [abilities] tags, I didn't understand the concept of lists at first, until someone added the .append function to add a list to a list. other, but I kept the names I used for the functions. Now that this work is completed, I would like the function calls to find their original names (get_specials and get_special_bool) among other things to clarify the reading for a developer.
This commit is contained in:
parent
847b70ab4c
commit
abc328e39f
@ -143,24 +143,24 @@ 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->bool_ability("slow");
|
||||
drains = !opp.get_state("undrainable") && weapon->bool_ability("drains");
|
||||
petrifies = weapon->bool_ability("petrifies");
|
||||
poisons = !opp.get_state("unpoisonable") && weapon->bool_ability("poison") && !opp.get_state(unit::STATE_POISONED);
|
||||
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);
|
||||
backstab_pos = is_attacker && backstab_check(u_loc, opp_loc, units, resources::gameboard->teams());
|
||||
rounds = weapon->get_special_ability("berserk").highest("value", 1).first;
|
||||
rounds = weapon->get_specials("berserk").highest("value", 1).first;
|
||||
|
||||
firststrike = weapon->bool_ability("firststrike");
|
||||
firststrike = weapon->get_special_bool("firststrike");
|
||||
|
||||
{
|
||||
const int distance = distance_between(u_loc, opp_loc);
|
||||
const bool out_of_range = distance > weapon->max_range() || distance < weapon->min_range();
|
||||
disable = weapon->get_special_bool("disable") || out_of_range;
|
||||
disable = weapon->get_special_bool_old("disable") || out_of_range;
|
||||
}
|
||||
|
||||
// Handle plague.
|
||||
unit_ability_list plague_specials = weapon->get_specials("plague");
|
||||
unit_ability_list alt_plague_specials = weapon->get_special_ability("plague");
|
||||
unit_ability_list plague_specials = weapon->get_specials_old("plague");
|
||||
unit_ability_list alt_plague_specials = weapon->get_specials("plague");
|
||||
if(!alt_plague_specials.empty() && plague_specials.empty()){
|
||||
plague_specials = alt_plague_specials;
|
||||
}
|
||||
@ -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_special_ability("chance_to_hit");
|
||||
unit_ability_list cth_specials = weapon->get_specials("chance_to_hit");
|
||||
unit_abilities::effect cth_effects(cth_specials, cth, backstab_pos, weapon);
|
||||
cth = cth_effects.get_composite_value();
|
||||
|
||||
@ -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_special_ability("drains");
|
||||
unit_ability_list drain_specials = weapon->get_specials("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_special_ability("heal_on_hit");
|
||||
unit_ability_list heal_on_hit_specials = weapon->get_specials("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();
|
||||
|
||||
@ -305,15 +305,15 @@ battle_context_unit_stats::battle_context_unit_stats(const unit_type* u_type,
|
||||
opp_ctx.emplace(opp_weapon->specials_context(*opp_type, map_location::null_location(), !attacking));
|
||||
}
|
||||
|
||||
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");
|
||||
rounds = weapon->get_specials("berserk").highest("value", 1).first;
|
||||
firststrike = weapon->get_special_bool("firststrike");
|
||||
disable = weapon->get_special_bool("disable");
|
||||
slows = weapon->get_special_bool_old("slow");
|
||||
drains = !opp_type->musthave_status("undrainable") && weapon->get_special_bool_old("drains");
|
||||
petrifies = weapon->get_special_bool_old("petrifies");
|
||||
poisons = !opp_type->musthave_status("unpoisonable") && weapon->get_special_bool_old("poison");
|
||||
rounds = weapon->get_specials_old("berserk").highest("value", 1).first;
|
||||
firststrike = weapon->get_special_bool_old("firststrike");
|
||||
disable = weapon->get_special_bool_old("disable");
|
||||
|
||||
unit_ability_list plague_specials = weapon->get_specials("plague");
|
||||
unit_ability_list plague_specials = weapon->get_specials_old("plague");
|
||||
plagues = !opp_type->musthave_status("unplagueable") && !plague_specials.empty() &&
|
||||
opp_type->undead_variation() != "null";
|
||||
|
||||
@ -327,7 +327,7 @@ battle_context_unit_stats::battle_context_unit_stats(const unit_type* u_type,
|
||||
signed int cth = 100 - opp_terrain_defense + weapon->accuracy() - (opp_weapon ? opp_weapon->parry() : 0);
|
||||
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_old("chance_to_hit");
|
||||
unit_abilities::effect cth_effects(cth_specials, cth, backstab_pos, weapon);
|
||||
cth = cth_effects.get_composite_value();
|
||||
|
||||
@ -343,7 +343,7 @@ battle_context_unit_stats::battle_context_unit_stats(const unit_type* u_type,
|
||||
slow_damage = round_damage(base_damage, damage_multiplier, 20000);
|
||||
|
||||
if(drains) {
|
||||
unit_ability_list drain_specials = weapon->get_specials("drains");
|
||||
unit_ability_list drain_specials = weapon->get_specials_old("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);
|
||||
@ -351,7 +351,7 @@ battle_context_unit_stats::battle_context_unit_stats(const unit_type* u_type,
|
||||
}
|
||||
|
||||
// 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_old("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();
|
||||
|
||||
|
@ -168,11 +168,11 @@ void aspect_attacks_base::do_attack_analysis(const map_location& loc,
|
||||
bool backstab = false, slow = false;
|
||||
for(const attack_type& a : unit_itor->attacks()) {
|
||||
// For speed, just assume these specials will be active if they are present.
|
||||
if(a.get_special_bool("backstab", true)) {
|
||||
if(a.get_special_bool_old("backstab", true)) {
|
||||
backstab = true;
|
||||
}
|
||||
|
||||
if(a.get_special_bool("slow", true)) {
|
||||
if(a.get_special_bool_old("slow", true)) {
|
||||
slow = true;
|
||||
}
|
||||
}
|
||||
|
@ -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_special_ability("damage");
|
||||
unit_ability_list dmg_specials = weapon->get_specials("damage");
|
||||
unit_abilities::effect dmg_effect(dmg_specials, weapon->damage(), attacker.stats_.backstab_pos);
|
||||
|
||||
// Get the SET damage modifier, if any.
|
||||
|
@ -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(const std::string& special, bool simple_check, bool special_id, bool special_tags) const
|
||||
bool attack_type::get_special_bool_old(const std::string& special, bool simple_check, bool special_id, bool special_tags) const
|
||||
{
|
||||
{
|
||||
std::vector<special_match> special_tag_matches;
|
||||
@ -765,9 +765,9 @@ bool attack_type::get_special_bool(const std::string& special, bool simple_check
|
||||
* Returns the currently active specials as an ability list, given the current
|
||||
* context (see set_specials_context).
|
||||
*/
|
||||
unit_ability_list attack_type::get_specials(const std::string& special) const
|
||||
unit_ability_list attack_type::get_specials_old(const std::string& special) const
|
||||
{
|
||||
//log_scope("get_specials");
|
||||
//log_scope("get_specials_old");
|
||||
const map_location loc = self_ ? self_->get_location() : self_loc_;
|
||||
unit_ability_list res(loc);
|
||||
|
||||
@ -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_special_ability("attacks"),
|
||||
unit_abilities::effect attacks_effect(get_specials("attacks"),
|
||||
num_attacks(), is_backstab, shared_from_this());
|
||||
int attacks_value = attacks_effect.get_composite_value();
|
||||
|
||||
@ -974,7 +974,7 @@ void attack_type::modified_attacks(bool is_backstab, unsigned & min_attacks,
|
||||
}
|
||||
|
||||
// Apply [swarm].
|
||||
unit_ability_list swarm_specials = get_special_ability("swarm");
|
||||
unit_ability_list swarm_specials = get_specials("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);
|
||||
@ -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_special_ability("damage"), damage(), is_backstab, shared_from_this());
|
||||
unit_abilities::effect dmg_effect(get_specials("damage"), damage(), is_backstab, shared_from_this());
|
||||
int damage_value = dmg_effect.get_composite_value();
|
||||
return damage_value;
|
||||
}
|
||||
@ -1107,7 +1107,7 @@ namespace { // Helpers for attack_type::special_active()
|
||||
//beneficiary unit does not have a corresponding weapon
|
||||
//(defense against ranged weapons abilities for a unit that only has melee attacks)
|
||||
|
||||
unit_ability_list attack_type::list_ability(const std::string& ability) const
|
||||
unit_ability_list attack_type::get_weapon_ability(const std::string& ability) const
|
||||
{
|
||||
const map_location loc = self_ ? self_->get_location() : self_loc_;
|
||||
unit_ability_list abil_list(loc);
|
||||
@ -1158,16 +1158,16 @@ unit_ability_list attack_type::list_ability(const std::string& ability) const
|
||||
return abil_list;
|
||||
}
|
||||
|
||||
unit_ability_list attack_type::get_special_ability(const std::string& ability) const
|
||||
unit_ability_list attack_type::get_specials(const std::string& ability) const
|
||||
{
|
||||
unit_ability_list abil_list = list_ability(ability);
|
||||
unit_ability_list abil_list = get_weapon_ability(ability);
|
||||
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(ability));
|
||||
abil_list.append(get_specials_old(ability));
|
||||
return abil_list;
|
||||
}
|
||||
|
||||
@ -1261,7 +1261,7 @@ bool attack_type::check_adj_abilities_impl(const_attack_ptr self_attack, const_a
|
||||
* active in the current context (see set_specials_context), including
|
||||
* specials obtained from the opponent's attack.
|
||||
*/
|
||||
bool attack_type::get_special_ability_bool(const std::string& special, bool special_id, bool special_tags) const
|
||||
bool attack_type::get_weapon_ability_bool(const std::string& special, bool special_id, bool special_tags) const
|
||||
{
|
||||
assert(display::get_singleton());
|
||||
const unit_map& units = display::get_singleton()->get_units();
|
||||
@ -1359,9 +1359,9 @@ bool attack_type::get_special_ability_bool(const std::string& special, bool spec
|
||||
return false;
|
||||
}
|
||||
|
||||
bool attack_type::bool_ability(const std::string& special, bool special_id, bool special_tags) const
|
||||
bool attack_type::get_special_bool(const std::string& special, bool special_id, bool special_tags) const
|
||||
{
|
||||
return (get_special_bool(special, false, special_id, special_tags) || get_special_ability_bool(special, special_id, special_tags));
|
||||
return (get_special_bool_old(special, false, special_id, special_tags) || get_weapon_ability_bool(special, special_id, special_tags));
|
||||
}
|
||||
//end of emulate weapon special functions.
|
||||
|
||||
@ -1456,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->bool_ability("firststrike")) {
|
||||
other_attack->get_special_bool("firststrike")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ static bool matches_simple_filter(const attack_type & attack, const config & fil
|
||||
deprecated_message("special=", DEP_LEVEL::PREEMPTIVE, {1, 17, 0}, "Please use special_id or special_type instead");
|
||||
bool found = false;
|
||||
for(auto& special : filter_special) {
|
||||
if(attack.get_special_bool(special, true)) {
|
||||
if(attack.get_special_bool_old(special, true)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@ -154,7 +154,7 @@ static bool matches_simple_filter(const attack_type & attack, const config & fil
|
||||
if(!filter_special_id.empty()) {
|
||||
bool found = false;
|
||||
for(auto& special : filter_special_id) {
|
||||
if(attack.get_special_bool(special, true, true, false)) {
|
||||
if(attack.get_special_bool_old(special, true, true, false)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@ -168,7 +168,7 @@ static bool matches_simple_filter(const attack_type & attack, const config & fil
|
||||
deprecated_message("special_active=", DEP_LEVEL::PREEMPTIVE, {1, 17, 0}, "Please use special_id_active or special_type_active instead");
|
||||
bool found = false;
|
||||
for(auto& special : filter_special_active) {
|
||||
if(attack.get_special_bool(special, false)) {
|
||||
if(attack.get_special_bool_old(special, false)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@ -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.bool_ability(special, true, false)) {
|
||||
if(attack.get_special_bool(special, true, false)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@ -192,7 +192,7 @@ static bool matches_simple_filter(const attack_type & attack, const config & fil
|
||||
if(!filter_special_type.empty()) {
|
||||
bool found = false;
|
||||
for(auto& special : filter_special_type) {
|
||||
if(attack.get_special_bool(special, true, false)) {
|
||||
if(attack.get_special_bool_old(special, true, false)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
@ -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.bool_ability(special, false)) {
|
||||
if(attack.get_special_bool(special, false)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -78,8 +78,8 @@ public:
|
||||
* @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;
|
||||
unit_ability_list get_specials(const std::string& special) const;
|
||||
bool get_special_bool_old(const std::string& special, bool simple_check=false, bool special_id=true, bool special_tags=true) const;
|
||||
unit_ability_list get_specials_old(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;
|
||||
|
||||
@ -89,23 +89,23 @@ public:
|
||||
/** 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. */
|
||||
unit_ability_list list_ability(const std::string& ability) const;
|
||||
/** Returns list who contains list_ability and get_specials list for each ability type */
|
||||
unit_ability_list get_special_ability(const std::string& ability) const;
|
||||
unit_ability_list get_weapon_ability(const std::string& ability) const;
|
||||
/** Returns list who contains get_weapon_ability and get_specials_old list for each ability type */
|
||||
unit_ability_list get_specials(const std::string& ability) const;
|
||||
/** used for abilities used like weapon
|
||||
* @return True if the ability @a special is active.
|
||||
* @param special The special being checked.
|
||||
* @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_ability_bool(const std::string& special, bool special_id=true, bool special_tags=true) const;
|
||||
bool get_weapon_ability_bool(const std::string& special, bool special_id=true, bool special_tags=true) const;
|
||||
/** 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 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 bool_ability(const std::string& special, bool special_id=true, bool special_tags=true) const;
|
||||
bool get_special_bool(const std::string& special, bool special_id=true, bool special_tags=true) const;
|
||||
|
||||
// In unit_types.cpp:
|
||||
|
||||
|
@ -695,7 +695,7 @@ void unit_attack(display * disp, game_board & board,
|
||||
|
||||
unit_ability_list abilities = att->get_location();
|
||||
for(auto& special : attacker.checking_tags()) {
|
||||
abilities.append(weapon->list_ability(special));
|
||||
abilities.append(weapon->get_weapon_ability(special));
|
||||
}
|
||||
|
||||
for(const unit_ability& ability : abilities) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user