Skip to content

Commit

Permalink
pull few changes requested.
Browse files Browse the repository at this point in the history
rename satic add_string to 'add_line' because this function add a line between diffrent string bloc, and clean temp_string and checking _name.

checking_tag is referenced now, and weapon_abilities renamed to tem_string, and self_abilities string to weapon_abilities.

self conditionnal is not removed because checking  in building will be mark that like error and build fail(in unbuntu, i believe)
  • Loading branch information
newfrenchy83 committed Jan 26, 2022
1 parent 80489dd commit 1b2551a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 52 deletions.
93 changes: 46 additions & 47 deletions src/units/abilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,18 +834,18 @@ std::vector<std::pair<t_string, t_string>> attack_type::special_tooltips(
/**
* static used in weapon_specials (bool only_active, bool is_backstab) and
* @return a string and a set_string for the weapon_specials function below.
* @param[in,out] weapon_abilities the string modified and returned
* @param[in,out] temp_string the string modified and returned
* @param[in] active the boolean for determine if @name can be added or not
* @param[in] name string who must be or not added
* @param[in,out] checking_name the reference for checking if @name already added
*/
static void add_name(std::string& weapon_abilities, bool active, const std::string name, std::set<std::string>& checking_name)
static void add_name(std::string& temp_string, bool active, const std::string name, std::set<std::string>& checking_name)
{
if (active) {
if (!name.empty() && checking_name.count(name) == 0) {
checking_name.insert(name);
if (!weapon_abilities.empty()) weapon_abilities += ", ";
weapon_abilities += name;
if (!temp_string.empty()) temp_string += ", ";
temp_string += name;
}
}
}
Expand Down Expand Up @@ -877,62 +877,62 @@ std::string attack_type::weapon_specials(bool only_active, bool is_backstab) con
if (only_active && !active) res += "</span>";
}
}
std::string weapon_abilities;
std::string temp_string;
std::set<std::string> checking_name;
if(self_){
weapon_specials_impl_self(weapon_abilities, self_, shared_from_this(), other_attack_, self_loc_, AFFECT_SELF, checking_name);
weapon_specials_impl_adj(weapon_abilities, self_, shared_from_this(), other_attack_, self_loc_, AFFECT_SELF, checking_name);
weapon_specials_impl_self(temp_string, self_, shared_from_this(), other_attack_, self_loc_, AFFECT_SELF, checking_name);
weapon_specials_impl_adj(temp_string, self_, shared_from_this(), other_attack_, self_loc_, AFFECT_SELF, checking_name);
}
if(other_){
weapon_specials_impl_self(weapon_abilities, other_, other_attack_, shared_from_this(), other_loc_, AFFECT_OTHER, checking_name);
weapon_specials_impl_adj(weapon_abilities, other_, other_attack_, shared_from_this(), other_loc_, AFFECT_OTHER, checking_name);
weapon_specials_impl_self(temp_string, other_, other_attack_, shared_from_this(), other_loc_, AFFECT_OTHER, checking_name);
weapon_specials_impl_adj(temp_string, other_, other_attack_, shared_from_this(), other_loc_, AFFECT_OTHER, checking_name);
}
if(!weapon_abilities.empty() && !res.empty()) {
weapon_abilities = ", \n" + weapon_abilities;
res += weapon_abilities;
} else if (!weapon_abilities.empty()){
res = weapon_abilities;
if(!temp_string.empty() && !res.empty()) {
temp_string = ", \n" + temp_string;
res += temp_string;
} else if (!temp_string.empty()){
res = temp_string;
}
return res;
}

static void add_string(std::string& weapon_abilities, std::string& self_abilities, const std::string temp_abilities, std::set<std::string>& checking_name)
static void add_line(std::string& temp_string, std::string& weapon_abilities, const std::string temp_abilities, std::set<std::string>& checking_name)
{
weapon_abilities = "";
temp_string.clear();
checking_name.clear();
self_abilities += (!self_abilities.empty() && !temp_abilities.empty()) ? "\n" : "";
self_abilities += temp_abilities;
weapon_abilities += (!weapon_abilities.empty() && !temp_abilities.empty()) ? "\n" : "";
weapon_abilities += temp_abilities;
}

std::string attack_type::weapon_specials_value(const std::set<std::string> checking_tags) const
{
//log_scope("weapon_specials_value");
std::string weapon_abilities, self_abilities, self_teacher_allies, self_teacher_enemies, opponent_abilities;
std::string temp_string, weapon_abilities, self_teacher_allies, self_teacher_enemies, opponent_abilities;
std::set<std::string> checking_name;
for (const config::any_child sp : specials_.all_children_range()) {
if((checking_tags.count(sp.key) != 0)){
const bool active = special_active(sp.cfg, AFFECT_SELF, sp.key);
add_name(weapon_abilities, active, sp.cfg["name"].str(), checking_name);
add_name(temp_string, active, sp.cfg["name"].str(), checking_name);
}
}
if(self_){
weapon_specials_impl_self(weapon_abilities, self_, shared_from_this(), other_attack_, self_loc_, AFFECT_SELF, checking_name, checking_tags, true);
if(!weapon_abilities.empty()){
self_abilities += translation::dsgettext("wesnoth", "Self: ");
self_abilities += weapon_abilities;
add_string(weapon_abilities, self_abilities, self_teacher_allies, checking_name);
}
weapon_specials_impl_adj(weapon_abilities, self_, shared_from_this(), other_attack_, self_loc_, AFFECT_SELF, checking_name, checking_tags, "affect_allies", true);
if(!weapon_abilities.empty()){
weapon_specials_impl_self(temp_string, self_, shared_from_this(), other_attack_, self_loc_, AFFECT_SELF, checking_name, checking_tags, true);
if(!temp_string.empty()){
weapon_abilities += translation::dsgettext("wesnoth", "Self: ");
weapon_abilities += temp_string;
add_line(temp_string, weapon_abilities, self_teacher_allies, checking_name);
}
weapon_specials_impl_adj(temp_string, self_, shared_from_this(), other_attack_, self_loc_, AFFECT_SELF, checking_name, checking_tags, "affect_allies", true);
if(!temp_string.empty()){
self_teacher_allies += translation::dsgettext("wesnoth", "Teachers: ");
self_teacher_allies += weapon_abilities;
add_string(weapon_abilities, self_abilities, self_teacher_allies, checking_name);
self_teacher_allies += temp_string;
add_line(temp_string, weapon_abilities, self_teacher_allies, checking_name);
}
weapon_specials_impl_adj(weapon_abilities, self_, shared_from_this(), other_attack_, self_loc_, AFFECT_SELF, checking_name, checking_tags, "affect_enemies", true);
if(!weapon_abilities.empty()){
weapon_specials_impl_adj(temp_string, self_, shared_from_this(), other_attack_, self_loc_, AFFECT_SELF, checking_name, checking_tags, "affect_enemies", true);
if(!temp_string.empty()){
self_teacher_enemies += translation::dsgettext("wesnoth", "Enemies Teachers: ");
self_teacher_enemies += weapon_abilities;
add_string(weapon_abilities, self_abilities, self_teacher_enemies, checking_name);
self_teacher_enemies += temp_string;
add_line(temp_string, weapon_abilities, self_teacher_enemies, checking_name);
}
}

Expand All @@ -941,36 +941,35 @@ std::string attack_type::weapon_specials_value(const std::set<std::string> check
for (const config::any_child sp : other_attack_->specials_.all_children_range()) {
if((checking_tags.count(sp.key) != 0)){
const bool active = other_attack_->special_active(sp.cfg, AFFECT_OTHER, sp.key);
add_name(weapon_abilities, active, sp.cfg["name"].str(), checking_name);
add_name(temp_string, active, sp.cfg["name"].str(), checking_name);
}
}
}
weapon_specials_impl_self(weapon_abilities, other_, other_attack_, shared_from_this(), other_loc_, AFFECT_OTHER, checking_name, checking_tags);
weapon_specials_impl_adj(weapon_abilities, other_, other_attack_, shared_from_this(), other_loc_, AFFECT_OTHER, checking_name, checking_tags);
if(!weapon_abilities.empty()){
weapon_specials_impl_self(temp_string, other_, other_attack_, shared_from_this(), other_loc_, AFFECT_OTHER, checking_name, checking_tags);
weapon_specials_impl_adj(temp_string, other_, other_attack_, shared_from_this(), other_loc_, AFFECT_OTHER, checking_name, checking_tags);
if(!temp_string.empty()){
opponent_abilities += translation::dsgettext("wesnoth", "Opponent: ");
opponent_abilities += weapon_abilities;
add_string(weapon_abilities, self_abilities, opponent_abilities, checking_name);
opponent_abilities += temp_string;
add_line(temp_string, weapon_abilities, opponent_abilities, checking_name);
}
}
weapon_abilities = self_abilities;
return weapon_abilities;
}

void attack_type::weapon_specials_impl_self(std::string& weapon_abilities, unit_const_ptr self, const_attack_ptr self_attack, const_attack_ptr other_attack, const map_location& self_loc, AFFECTS whom,
std::set<std::string>& checking_name, const std::set<std::string> checking_tags, bool leader_bool)
void attack_type::weapon_specials_impl_self(std::string& temp_string, unit_const_ptr self, const_attack_ptr self_attack, const_attack_ptr other_attack, const map_location& self_loc, AFFECTS whom,
std::set<std::string>& checking_name, const std::set<std::string>& checking_tags, bool leader_bool)
{
if(self){
for (const config::any_child sp : self->abilities().all_children_range()){
bool tag_checked = (!checking_tags.empty()) ? (checking_tags.count(sp.key) != 0) : true;
const bool active = tag_checked && check_self_abilities_impl(self_attack, other_attack, sp.cfg, self, self_loc, whom, sp.key, leader_bool);
add_name(weapon_abilities, active, font::span_color(font::BUTTON_COLOR, sp.cfg["name"].str()), checking_name);
add_name(temp_string, active, font::span_color(font::BUTTON_COLOR, sp.cfg["name"].str()), checking_name);
}
}
}

void attack_type::weapon_specials_impl_adj(std::string& weapon_abilities, unit_const_ptr self, const_attack_ptr self_attack, const_attack_ptr other_attack, const map_location& self_loc, AFFECTS whom,
std::set<std::string>& checking_name, const std::set<std::string> checking_tags, const std::string& affect_adjacents, bool leader_bool)
void attack_type::weapon_specials_impl_adj(std::string& temp_string, unit_const_ptr self, const_attack_ptr self_attack, const_attack_ptr other_attack, const map_location& self_loc, AFFECTS whom,
std::set<std::string>& checking_name, const std::set<std::string>& checking_tags, const std::string& affect_adjacents, bool leader_bool)
{
assert(display::get_singleton());
const unit_map& units = display::get_singleton()->get_units();
Expand All @@ -987,7 +986,7 @@ void attack_type::weapon_specials_impl_adj(std::string& weapon_abilities, unit_c
bool default_bool = (affect_adjacents == "affect_allies") ? true : false;
bool affect_allies = (!affect_adjacents.empty()) ? sp.cfg[affect_adjacents].to_bool(default_bool) : true;
const bool active = tag_checked && check_adj_abilities_impl(self_attack, other_attack, sp.cfg, self, *it, i, self_loc, whom, sp.key, leader_bool) && affect_allies;
add_name(weapon_abilities, active, font::span_color(font::BUTTON_COLOR, sp.cfg["name"].str()), checking_name);
add_name(temp_string, active, font::span_color(font::BUTTON_COLOR, sp.cfg["name"].str()), checking_name);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/units/attack_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class attack_type : public std::enable_shared_from_this<attack_type>
bool include_backstab=true, const std::string& filter_self ="filter_self") const;

/** weapon_specials_impl_self and weapon_specials_impl_adj : check if special name can be added.
* @param[in,out] weapon_abilities the string modified and returned
* @param[in,out] temp_string the string modified and returned
* @param[in] self the unit checked.
* @param[in] self_attack the attack used by unit checked in this function.
* @param[in] other_attack the attack used by opponent to unit checked.
Expand All @@ -163,26 +163,26 @@ class attack_type : public std::enable_shared_from_this<attack_type>
* @param[in] leader_bool If true, [leadership] abilities are checked.
*/
static void weapon_specials_impl_self(
std::string& weapon_abilities,
std::string& temp_string,
unit_const_ptr self,
const_attack_ptr self_attack,
const_attack_ptr other_attack,
const map_location& self_loc,
AFFECTS whom,
std::set<std::string>& checking_name,
const std::set<std::string> checking_tags={},
const std::set<std::string>& checking_tags={},
bool leader_bool=false
);

static void weapon_specials_impl_adj(
std::string& weapon_abilities,
std::string& temp_string,
unit_const_ptr self,
const_attack_ptr self_attack,
const_attack_ptr other_attack,
const map_location& self_loc,
AFFECTS whom,
std::set<std::string>& checking_name,
const std::set<std::string> checking_tags={},
const std::set<std::string>& checking_tags={},
const std::string& affect_adjacents="",
bool leader_bool=false
);
Expand Down

0 comments on commit 1b2551a

Please sign in to comment.