Author: alink
Date: Mon Apr 20 23:46:25 2009
New Revision: 35087
URL: http://svn.gna.org/viewcvs/wesnoth?rev=35087&view=rev
Log:
Little cleaning of [hide_help]:
Reset it between campaigns and allow to use more than one [not] subtag
Modified:
trunk/src/unit_types.cpp
trunk/src/unit_types.hpp
Modified: trunk/src/unit_types.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_types.cpp?rev=35087&r1=35086&r2=35087&view=diff
==============================================================================
--- trunk/src/unit_types.cpp (original)
+++ trunk/src/unit_types.cpp Mon Apr 20 23:46:25 2009
@@ -1111,6 +1111,7 @@
dummy_unit_map_(),
movement_types_(),
races_(),
+ hide_help_all_(false),
unit_cfg_(NULL)
{
dummy_unit_map_.insert(std::pair<const
std::string,unit_type>("dummy_unit", unit_type()));
@@ -1175,22 +1176,9 @@
build_all(unit_type::CREATED);
- if (const config &hide = cfg.child("hide_help")) {
- hide_help_all_ = utils::string_bool(hide["all"], false);
-
- std::vector<std::string> types = utils::split(hide["type"]);
- hide_help_[TYPE].insert(types.begin(), types.end());
-
- std::vector<std::string> races = utils::split(hide["race"]);
- hide_help_[RACE].insert(races.begin(), races.end());
-
- if (const config &hide_not = hide.child("not")) {
- std::vector<std::string> n_types =
utils::split(hide_not["type"]);
- hide_help_[NOT_TYPE].insert(n_types.begin(),
n_types.end());
-
- std::vector<std::string> n_races =
utils::split(hide_not["race"]);
- hide_help_[NOT_RACE].insert(n_races.begin(),
n_races.end());
- }
+ if (const config &hide_help = cfg.child("hide_help")) {
+ hide_help_all_ = utils::string_bool(hide_help["all"], false);
+ read_hide_help(hide_help);
}
}
@@ -1244,6 +1232,17 @@
ERROR_LOG("unit type not found");
}
+void unit_type_data::unit_type_map_wrapper::clear()
+{
+ types_.clear();
+ movement_types_.clear();
+ races_.clear();
+
+ hide_help_all_ = false;
+ hide_help_race_.clear();
+ hide_help_type_.clear();
+}
+
void unit_type_data::unit_type_map_wrapper::build_all(unit_type::BUILD_STATUS
status) const
{
assert(unit_cfg_ != NULL);
@@ -1299,10 +1298,37 @@
return ut->second;
}
+void unit_type_data::unit_type_map_wrapper::read_hide_help(const config& cfg)
+{
+ if (!cfg)
+ return;
+
+ hide_help_race_.push_back(std::set<std::string>());
+ hide_help_type_.push_back(std::set<std::string>());
+
+ std::vector<std::string> races = utils::split(cfg["race"]);
+ hide_help_race_.back().insert(races.begin(), races.end());
+
+ std::vector<std::string> types = utils::split(cfg["type"]);
+ hide_help_type_.back().insert(types.begin(), types.end());
+
+ // we call recursively all the imbricated [not] tags
+ read_hide_help(cfg.child("not"));
+}
+
bool unit_type_data::unit_type_map_wrapper::hide_help(const std::string& type,
const std::string& race) const
{
- return (hide_help_all_ || hide_help_[RACE].count(race) ||
hide_help_[TYPE].count(type))
- && !(hide_help_[NOT_RACE].count(race) ||
hide_help_[NOT_TYPE].count(type));
+ bool res = hide_help_all_;
+ int lvl = hide_help_all_ ? 1 : 0; // first level is covered by 'all=yes'
+
+ // supposed to be equal but let's be cautious
+ int lvl_nb = std::min(hide_help_race_.size(), hide_help_type_.size());
+
+ for (; lvl < lvl_nb; ++lvl) {
+ if (hide_help_race_[lvl].count(race) ||
hide_help_type_[lvl].count(type))
+ res = !res; // each level is a [not]
+ }
+ return res;
}
void unit_type_data::unit_type_map_wrapper::add_advancefrom(const config&
unit_cfg) const
Modified: trunk/src/unit_types.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_types.hpp?rev=35087&r1=35086&r2=35087&view=diff
==============================================================================
--- trunk/src/unit_types.hpp (original)
+++ trunk/src/unit_types.hpp Mon Apr 20 23:46:25 2009
@@ -362,15 +362,14 @@
unit_type_map_wrapper();
unit_type_map_wrapper(const unit_type_map_wrapper &);
+ // parse the [hide_help] tag
+ void read_hide_help(const config& cfg);
+
void set_unit_config(const config& unit_cfg) { unit_cfg_ =
&unit_cfg; }
const config& find_config(const std::string& key) const;
std::pair<unit_type_map::iterator, bool> insert(const
std::pair<std::string,unit_type>& utype) { return types_.insert(utype); }
- void clear() {
- types_.clear();
- movement_types_.clear();
- races_.clear();
- }
+ void clear();
unit_type& build_unit_type(const std::string& key,
unit_type::BUILD_STATUS status) const;
void add_advancefrom(const config& unit_cfg) const;
@@ -381,9 +380,11 @@
movement_type_map movement_types_;
race_map races_;
+ // if [hide_help] contains a 'all=yes' at its root
bool hide_help_all_;
- enum HIDE_KEY {TYPE=0, RACE, NOT_TYPE, NOT_RACE,
NB_HIDE_KEY};
- std::set<std::string> hide_help_[NB_HIDE_KEY];
+ // vectors containing the [hide_help] and its sub-tags
[not]
+ std::vector< std::set<std::string> > hide_help_type_;
+ std::vector< std::set<std::string> > hide_help_race_;
const config* unit_cfg_;
};
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits