mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-06 11:57:01 +00:00
remove duplicate information in attack_type
previously we stored this information in a config object and in member variables, now the config object is removed.
This commit is contained in:
parent
5c27af2978
commit
4c39a23843
@ -519,34 +519,29 @@ namespace {
|
|||||||
*/
|
*/
|
||||||
bool attack_type::get_special_bool(const std::string& special, bool simple_check) const
|
bool attack_type::get_special_bool(const std::string& special, bool simple_check) const
|
||||||
{
|
{
|
||||||
//log_scope("get_special_bool");
|
|
||||||
if (const config &specials = cfg_.child("specials"))
|
|
||||||
{
|
{
|
||||||
std::vector<const config*> list;
|
std::vector<const config*> list;
|
||||||
if ( get_special_children(list, specials, special, simple_check) )
|
if ( get_special_children(list, specials_, special, simple_check) ) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
// If we make it to here, then either list.empty() or !simple_check.
|
// If we make it to here, then either list.empty() or !simple_check.
|
||||||
// So if the list is not empty, then this is not a simple check and
|
// So if the list is not empty, then this is not a simple check and
|
||||||
// we need to check each special in the list to see if any are active.
|
// we need to check each special in the list to see if any are active.
|
||||||
for (std::vector<const config*>::iterator i = list.begin(),
|
for (std::vector<const config*>::iterator i = list.begin(), i_end = list.end(); i != i_end; ++i) {
|
||||||
i_end = list.end(); i != i_end; ++i) {
|
if ( special_active(**i, AFFECT_SELF) ) {
|
||||||
if ( special_active(**i, AFFECT_SELF) )
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Skip checking the opponent's attack?
|
// Skip checking the opponent's attack?
|
||||||
if ( simple_check || !other_attack_ )
|
if ( simple_check || !other_attack_ ) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (const config &specials = other_attack_->cfg_.child("specials"))
|
|
||||||
{
|
|
||||||
std::vector<const config*> list;
|
std::vector<const config*> list;
|
||||||
get_special_children(list, specials, special);
|
get_special_children(list, other_attack_->specials_, special);
|
||||||
for (std::vector<const config*>::iterator i = list.begin(),
|
for (std::vector<const config*>::iterator i = list.begin(), i_end = list.end(); i != i_end; ++i) {
|
||||||
i_end = list.end(); i != i_end; ++i) {
|
if ( other_attack_->special_active(**i, AFFECT_OTHER) ) {
|
||||||
if ( other_attack_->special_active(**i, AFFECT_OTHER) )
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -561,21 +556,15 @@ unit_ability_list attack_type::get_specials(const std::string& special) const
|
|||||||
{
|
{
|
||||||
//log_scope("get_specials");
|
//log_scope("get_specials");
|
||||||
unit_ability_list res;
|
unit_ability_list res;
|
||||||
if (const config &specials = cfg_.child("specials"))
|
BOOST_FOREACH(const config &i, specials_.child_range(special)) {
|
||||||
{
|
|
||||||
BOOST_FOREACH(const config &i, specials.child_range(special)) {
|
|
||||||
if ( special_active(i, AFFECT_SELF) )
|
if ( special_active(i, AFFECT_SELF) )
|
||||||
res.push_back(unit_ability(&i, self_loc_));
|
res.push_back(unit_ability(&i, self_loc_));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (!other_attack_) return res;
|
if (!other_attack_) return res;
|
||||||
if (const config &specials = other_attack_->cfg_.child("specials"))
|
BOOST_FOREACH(const config &i, other_attack_->specials_.child_range(special)) {
|
||||||
{
|
|
||||||
BOOST_FOREACH(const config &i, specials.child_range(special)) {
|
|
||||||
if ( other_attack_->special_active(i, AFFECT_OTHER) )
|
if ( other_attack_->special_active(i, AFFECT_OTHER) )
|
||||||
res.push_back(unit_ability(&i, other_loc_));
|
res.push_back(unit_ability(&i, other_loc_));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,10 +585,7 @@ std::vector<std::pair<t_string, t_string> > attack_type::special_tooltips(
|
|||||||
if ( active_list )
|
if ( active_list )
|
||||||
active_list->clear();
|
active_list->clear();
|
||||||
|
|
||||||
const config &specials = cfg_.child("specials");
|
BOOST_FOREACH(const config::any_child &sp, specials_.all_children_range())
|
||||||
if (!specials) return res;
|
|
||||||
|
|
||||||
BOOST_FOREACH(const config::any_child &sp, specials.all_children_range())
|
|
||||||
{
|
{
|
||||||
if ( !active_list || special_active(sp.cfg, AFFECT_EITHER) ) {
|
if ( !active_list || special_active(sp.cfg, AFFECT_EITHER) ) {
|
||||||
const t_string &name = sp.cfg["name"];
|
const t_string &name = sp.cfg["name"];
|
||||||
@ -632,10 +618,7 @@ std::string attack_type::weapon_specials(bool only_active, bool is_backstab) con
|
|||||||
{
|
{
|
||||||
//log_scope("weapon_specials");
|
//log_scope("weapon_specials");
|
||||||
std::string res;
|
std::string res;
|
||||||
const config &specials = cfg_.child("specials");
|
BOOST_FOREACH(const config::any_child &sp, specials_.all_children_range())
|
||||||
if (!specials) return res;
|
|
||||||
|
|
||||||
BOOST_FOREACH(const config::any_child &sp, specials.all_children_range())
|
|
||||||
{
|
{
|
||||||
if ( only_active && !special_active(sp.cfg, AFFECT_EITHER, is_backstab) )
|
if ( only_active && !special_active(sp.cfg, AFFECT_EITHER, is_backstab) )
|
||||||
continue;
|
continue;
|
||||||
|
@ -36,16 +36,11 @@ static lg::log_domain log_unit("unit");
|
|||||||
#define DBG_UT LOG_STREAM(debug, log_unit)
|
#define DBG_UT LOG_STREAM(debug, log_unit)
|
||||||
#define ERR_UT LOG_STREAM(err, log_unit)
|
#define ERR_UT LOG_STREAM(err, log_unit)
|
||||||
|
|
||||||
|
|
||||||
/* ** attack_type ** */
|
|
||||||
|
|
||||||
|
|
||||||
attack_type::attack_type(const config& cfg) :
|
attack_type::attack_type(const config& cfg) :
|
||||||
self_loc_(),
|
self_loc_(),
|
||||||
other_loc_(),
|
other_loc_(),
|
||||||
is_attacker_(false),
|
is_attacker_(false),
|
||||||
other_attack_(NULL),
|
other_attack_(NULL),
|
||||||
cfg_(cfg),
|
|
||||||
description_(cfg["description"].t_str()),
|
description_(cfg["description"].t_str()),
|
||||||
id_(cfg["name"]),
|
id_(cfg["name"]),
|
||||||
type_(cfg["type"]),
|
type_(cfg["type"]),
|
||||||
@ -59,8 +54,8 @@ attack_type::attack_type(const config& cfg) :
|
|||||||
defense_weight_(cfg["defense_weight"].to_double(1.0)),
|
defense_weight_(cfg["defense_weight"].to_double(1.0)),
|
||||||
accuracy_(cfg["accuracy"]),
|
accuracy_(cfg["accuracy"]),
|
||||||
movement_used_(cfg["movement_used"].to_int(100000)),
|
movement_used_(cfg["movement_used"].to_int(100000)),
|
||||||
parry_(cfg["parry"])
|
parry_(cfg["parry"]),
|
||||||
|
specials_(cfg.child_or_empty("specials"))
|
||||||
{
|
{
|
||||||
if (description_.empty())
|
if (description_.empty())
|
||||||
description_ = translation::egettext(id_.c_str());
|
description_ = translation::egettext(id_.c_str());
|
||||||
@ -190,49 +185,40 @@ bool attack_type::apply_modification(const config& cfg,std::string* description)
|
|||||||
|
|
||||||
if(set_name.empty() == false) {
|
if(set_name.empty() == false) {
|
||||||
id_ = set_name;
|
id_ = set_name;
|
||||||
cfg_["name"] = id_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(set_desc.empty() == false) {
|
if(set_desc.empty() == false) {
|
||||||
description_ = set_desc;
|
description_ = set_desc;
|
||||||
cfg_["description"] = description_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(set_type.empty() == false) {
|
if(set_type.empty() == false) {
|
||||||
type_ = set_type;
|
type_ = set_type;
|
||||||
cfg_["type"] = type_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(set_icon.empty() == false) {
|
if(set_icon.empty() == false) {
|
||||||
icon_ = set_icon;
|
icon_ = set_icon;
|
||||||
cfg_["icon"] = icon_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(del_specials.empty() == false) {
|
if(del_specials.empty() == false) {
|
||||||
const std::vector<std::string>& dsl = utils::split(del_specials);
|
const std::vector<std::string>& dsl = utils::split(del_specials);
|
||||||
if (config &specials = cfg_.child("specials"))
|
|
||||||
{
|
|
||||||
config new_specials;
|
config new_specials;
|
||||||
BOOST_FOREACH(const config::any_child &vp, specials.all_children_range()) {
|
BOOST_FOREACH(const config::any_child &vp, specials_.all_children_range()) {
|
||||||
std::vector<std::string>::const_iterator found_id =
|
std::vector<std::string>::const_iterator found_id =
|
||||||
std::find(dsl.begin(), dsl.end(), vp.cfg["id"].str());
|
std::find(dsl.begin(), dsl.end(), vp.cfg["id"].str());
|
||||||
if (found_id == dsl.end()) {
|
if (found_id == dsl.end()) {
|
||||||
new_specials.add_child(vp.key, vp.cfg);
|
new_specials.add_child(vp.key, vp.cfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cfg_.clear_children("specials");
|
specials_ = new_specials;
|
||||||
cfg_.add_child("specials",new_specials);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (set_specials) {
|
if (set_specials) {
|
||||||
const std::string &mode = set_specials["mode"];
|
const std::string &mode = set_specials["mode"];
|
||||||
if (mode != "append") {
|
if (mode != "append") {
|
||||||
cfg_.clear_children("specials");
|
specials_.clear();
|
||||||
}
|
}
|
||||||
config &new_specials = cfg_.child_or_add("specials");
|
|
||||||
BOOST_FOREACH(const config::any_child &value, set_specials.all_children_range()) {
|
BOOST_FOREACH(const config::any_child &value, set_specials.all_children_range()) {
|
||||||
new_specials.add_child(value.key, value.cfg);
|
specials_.add_child(value.key, value.cfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +227,6 @@ bool attack_type::apply_modification(const config& cfg,std::string* description)
|
|||||||
if (damage_ < 0) {
|
if (damage_ < 0) {
|
||||||
damage_ = 0;
|
damage_ = 0;
|
||||||
}
|
}
|
||||||
cfg_["damage"] = damage_;
|
|
||||||
|
|
||||||
if(description != NULL) {
|
if(description != NULL) {
|
||||||
add_and(desc);
|
add_and(desc);
|
||||||
@ -253,7 +238,6 @@ bool attack_type::apply_modification(const config& cfg,std::string* description)
|
|||||||
|
|
||||||
if(increase_attacks.empty() == false) {
|
if(increase_attacks.empty() == false) {
|
||||||
num_attacks_ = utils::apply_modifier(num_attacks_, increase_attacks, 1);
|
num_attacks_ = utils::apply_modifier(num_attacks_, increase_attacks, 1);
|
||||||
cfg_["number"] = num_attacks_;
|
|
||||||
|
|
||||||
if(description != NULL) {
|
if(description != NULL) {
|
||||||
add_and(desc);
|
add_and(desc);
|
||||||
@ -265,7 +249,6 @@ bool attack_type::apply_modification(const config& cfg,std::string* description)
|
|||||||
|
|
||||||
if(increase_accuracy.empty() == false) {
|
if(increase_accuracy.empty() == false) {
|
||||||
accuracy_ = utils::apply_modifier(accuracy_, increase_accuracy, 1);
|
accuracy_ = utils::apply_modifier(accuracy_, increase_accuracy, 1);
|
||||||
cfg_["accuracy"] = accuracy_;
|
|
||||||
|
|
||||||
if(description != NULL) {
|
if(description != NULL) {
|
||||||
add_and(desc);
|
add_and(desc);
|
||||||
@ -278,7 +261,6 @@ bool attack_type::apply_modification(const config& cfg,std::string* description)
|
|||||||
|
|
||||||
if(increase_parry.empty() == false) {
|
if(increase_parry.empty() == false) {
|
||||||
parry_ = utils::apply_modifier(parry_, increase_parry, 1);
|
parry_ = utils::apply_modifier(parry_, increase_parry, 1);
|
||||||
cfg_["parry"] = parry_;
|
|
||||||
|
|
||||||
if(description != NULL) {
|
if(description != NULL) {
|
||||||
add_and(desc);
|
add_and(desc);
|
||||||
@ -290,12 +272,10 @@ bool attack_type::apply_modification(const config& cfg,std::string* description)
|
|||||||
|
|
||||||
if(set_attack_weight.empty() == false) {
|
if(set_attack_weight.empty() == false) {
|
||||||
attack_weight_ = lexical_cast_default<double>(set_attack_weight,1.0);
|
attack_weight_ = lexical_cast_default<double>(set_attack_weight,1.0);
|
||||||
cfg_["attack_weight"] = attack_weight_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(set_defense_weight.empty() == false) {
|
if(set_defense_weight.empty() == false) {
|
||||||
defense_weight_ = lexical_cast_default<double>(set_defense_weight,1.0);
|
defense_weight_ = lexical_cast_default<double>(set_defense_weight,1.0);
|
||||||
cfg_["defense_weight"] = defense_weight_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(description != NULL) {
|
if(description != NULL) {
|
||||||
@ -350,5 +330,19 @@ bool attack_type::describe_modification(const config& cfg,std::string* descripti
|
|||||||
|
|
||||||
void attack_type::write(config& cfg) const
|
void attack_type::write(config& cfg) const
|
||||||
{
|
{
|
||||||
cfg = cfg_;
|
cfg["description"] = description_;
|
||||||
|
cfg["name"] = id_;
|
||||||
|
cfg["type"] = type_;
|
||||||
|
cfg["icon"] = icon_;
|
||||||
|
cfg["range"] = range_;
|
||||||
|
cfg["min_range"] = min_range_;
|
||||||
|
cfg["max_range"] = max_range_;
|
||||||
|
cfg["damage"] = damage_;
|
||||||
|
cfg["number"] = num_attacks_;
|
||||||
|
cfg["attack_weight"] = attack_weight_;
|
||||||
|
cfg["defense_weight"] = defense_weight_;
|
||||||
|
cfg["accuracy"] = accuracy_;
|
||||||
|
cfg["movement_used"] = movement_used_;
|
||||||
|
cfg["parry"] = parry_;
|
||||||
|
cfg.add_child("specials", specials_);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "map_location.hpp"
|
#include "map_location.hpp"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
#include "tstring.hpp"
|
#include "tstring.hpp"
|
||||||
|
#include "config.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -89,7 +90,6 @@ private:
|
|||||||
mutable bool is_attacker_;
|
mutable bool is_attacker_;
|
||||||
mutable const attack_type* other_attack_;
|
mutable const attack_type* other_attack_;
|
||||||
|
|
||||||
config cfg_;
|
|
||||||
t_string description_;
|
t_string description_;
|
||||||
std::string id_;
|
std::string id_;
|
||||||
std::string type_;
|
std::string type_;
|
||||||
@ -104,5 +104,6 @@ private:
|
|||||||
int accuracy_;
|
int accuracy_;
|
||||||
int movement_used_;
|
int movement_used_;
|
||||||
int parry_;
|
int parry_;
|
||||||
|
config specials_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user