Config: use structured bindings with all_children_range (#9387)
This commit is contained in:
parent
5913cfdf55
commit
95c9f0c720
30 changed files with 331 additions and 350 deletions
|
@ -108,8 +108,8 @@ bool move_action::undo(int)
|
|||
// Move the unit.
|
||||
unit_display::move_unit(rev_route, u.get_shared_ptr(), true, starting_dir);
|
||||
bool halo_adjacent = false;
|
||||
for (const config::any_child sp : u->abilities().all_children_range()){
|
||||
if(!(sp.cfg)["halo_image"].empty() && (sp.cfg).has_child("affect_adjacent")){
|
||||
for(const auto [_, cfg] : u->abilities().all_children_range()){
|
||||
if(!cfg["halo_image"].empty() && cfg.has_child("affect_adjacent")){
|
||||
halo_adjacent = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -353,25 +353,25 @@ bool addons_client::install_addon(config& archive_cfg, const addon_info& info)
|
|||
LOG_ADDONS << "Received an updatepack for the addon '" << info.id << "'";
|
||||
|
||||
// A consistency check
|
||||
for(const config::any_child entry : archive_cfg.all_children_range()) {
|
||||
if(entry.key == "removelist" || entry.key == "addlist") {
|
||||
if(!check_names_legal(entry.cfg)) {
|
||||
for(const auto [key, cfg] : archive_cfg.all_children_range()) {
|
||||
if(key == "removelist" || key == "addlist") {
|
||||
if(!check_names_legal(cfg)) {
|
||||
gui2::show_error_message(VGETTEXT("The add-on <i>$addon_title</i> has an invalid file or directory "
|
||||
"name and cannot be installed.", i18n_symbols));
|
||||
return false;
|
||||
}
|
||||
if(!check_case_insensitive_duplicates(entry.cfg)) {
|
||||
if(!check_case_insensitive_duplicates(cfg)) {
|
||||
gui2::show_error_message(VGETTEXT("The add-on <i>$addon_title</i> has file or directory names "
|
||||
"with case conflicts. This may cause problems.", i18n_symbols));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(const config::any_child entry : archive_cfg.all_children_range()) {
|
||||
if(entry.key == "removelist") {
|
||||
purge_addon(entry.cfg);
|
||||
} else if(entry.key == "addlist") {
|
||||
unarchive_addon(entry.cfg, progress_cb);
|
||||
for(const auto [key, cfg] : archive_cfg.all_children_range()) {
|
||||
if(key == "removelist") {
|
||||
purge_addon(cfg);
|
||||
} else if(key == "addlist") {
|
||||
unarchive_addon(cfg, progress_cb);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -311,24 +311,24 @@ void configuration::expand_simplified_aspects(side_number side, config &cfg) {
|
|||
facet_config["value"] = value;
|
||||
facet_configs.emplace_back(key, facet_config);
|
||||
}
|
||||
for (const config::any_child child : aiparam.all_children_range()) {
|
||||
if (just_copy_tags.count(child.key)) {
|
||||
for(const auto [child_key, child_cfg] : aiparam.all_children_range()) {
|
||||
if (just_copy_tags.count(child_key)) {
|
||||
// These aren't simplified, so just copy over unchanged.
|
||||
parsed_config.add_child(child.key, child.cfg);
|
||||
parsed_config.add_child(child_key, child_cfg);
|
||||
if(
|
||||
(child.key != "modify_ai" && child.cfg["engine"] == "fai") ||
|
||||
(child.key == "modify_ai" && child.cfg.all_children_count() > 0 && child.cfg.all_children_range().front().cfg["engine"] == "fai")
|
||||
(child_key != "modify_ai" && child_cfg["engine"] == "fai") ||
|
||||
(child_key == "modify_ai" && child_cfg.all_children_count() > 0 && child_cfg.all_children_range().front().cfg["engine"] == "fai")
|
||||
) {
|
||||
deprecated_message("FormulaAI", DEP_LEVEL::FOR_REMOVAL, "1.17", "FormulaAI is slated to be removed. Use equivalent Lua AIs instead");
|
||||
}
|
||||
continue;
|
||||
} else if(old_goal_tags.count(child.key)) {
|
||||
} else if(old_goal_tags.count(child_key)) {
|
||||
// A simplified goal, mainly kept around just for backwards compatibility.
|
||||
config goal_config, criteria_config = child.cfg;
|
||||
goal_config["name"] = child.key;
|
||||
config goal_config, criteria_config = child_cfg;
|
||||
goal_config["name"] = child_key;
|
||||
goal_config["turns"] = turns;
|
||||
goal_config["time_of_day"] = time_of_day;
|
||||
if(child.key.substr(0,7) == "protect" && criteria_config.has_attribute("protect_radius")) {
|
||||
if(child_key.substr(0,7) == "protect" && criteria_config.has_attribute("protect_radius")) {
|
||||
goal_config["protect_radius"] = criteria_config["protect_radius"];
|
||||
criteria_config.remove_attribute("protect_radius");
|
||||
}
|
||||
|
@ -343,23 +343,23 @@ void configuration::expand_simplified_aspects(side_number side, config &cfg) {
|
|||
// Now there's two possibilities. If the tag is [attacks] or contains either value= or [value],
|
||||
// then it can be copied verbatim as a [facet] tag.
|
||||
// Otherwise, it needs to be placed as a [value] within a [facet] tag.
|
||||
if (child.key == "attacks" || child.cfg.has_attribute("value") || child.cfg.has_child("value")) {
|
||||
facet_configs.emplace_back(child.key, child.cfg);
|
||||
if (child_key == "attacks" || child_cfg.has_attribute("value") || child_cfg.has_child("value")) {
|
||||
facet_configs.emplace_back(child_key, child_cfg);
|
||||
} else {
|
||||
config facet_config;
|
||||
facet_config["engine"] = engine;
|
||||
facet_config["name"] = "standard_aspect";
|
||||
facet_config["turns"] = turns;
|
||||
facet_config["time_of_day"] = time_of_day;
|
||||
facet_config.add_child("value", child.cfg);
|
||||
if (child.key == "leader_goal" && !child.cfg["id"].empty()) {
|
||||
facet_config.add_child("value", child_cfg);
|
||||
if (child_key == "leader_goal" && !child_cfg["id"].empty()) {
|
||||
// Use id= attribute (if present) as the facet ID
|
||||
const std::string& id = child.cfg["id"];
|
||||
const std::string& id = child_cfg["id"];
|
||||
if(id != "*" && id.find_first_not_of("0123456789") != std::string::npos) {
|
||||
facet_config["id"] = child.cfg["id"];
|
||||
facet_config["id"] = child_cfg["id"];
|
||||
}
|
||||
}
|
||||
facet_configs.emplace_back(child.key, facet_config);
|
||||
facet_configs.emplace_back(child_key, facet_config);
|
||||
}
|
||||
}
|
||||
std::map<std::string, config> aspect_configs;
|
||||
|
@ -386,8 +386,8 @@ void configuration::expand_simplified_aspects(side_number side, config &cfg) {
|
|||
if (algorithm.empty() && !parsed_config.has_child("stage")) {
|
||||
base_config = get_ai_config_for(default_ai_algorithm_);
|
||||
}
|
||||
for (const config::any_child child : parsed_config.all_children_range()) {
|
||||
base_config.add_child(child.key, child.cfg);
|
||||
for(const auto [child_key, child_cfg] : parsed_config.all_children_range()) {
|
||||
base_config.add_child(child_key, child_cfg);
|
||||
}
|
||||
cfg.clear_children("ai");
|
||||
cfg.add_child("ai", std::move(base_config));
|
||||
|
|
|
@ -165,8 +165,8 @@ void config::remove_attribute(config_key_type key)
|
|||
|
||||
void config::append_children(const config& cfg)
|
||||
{
|
||||
for(const any_child value : cfg.all_children_range()) {
|
||||
add_child(value.key, value.cfg);
|
||||
for(const auto [key, cfg] : cfg.all_children_range()) {
|
||||
add_child(key, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,8 +179,8 @@ void config::append_children(config&& cfg)
|
|||
cfg.clear_all_children();
|
||||
return;
|
||||
}
|
||||
for(const any_child value : cfg.all_children_range()) {
|
||||
add_child(value.key, std::move(value.cfg));
|
||||
for(const auto [child_key, child_value] : cfg.all_children_range()) {
|
||||
add_child(child_key, std::move(child_value));
|
||||
}
|
||||
cfg.clear_all_children();
|
||||
}
|
||||
|
@ -1047,24 +1047,24 @@ void config::apply_diff(const config& diff, bool track /* = false */)
|
|||
|
||||
for(const config& i : diff.child_range("change_child")) {
|
||||
const std::size_t index = lexical_cast<std::size_t>(i["index"].str());
|
||||
for(const any_child item : i.all_children_range()) {
|
||||
if(item.key.empty()) {
|
||||
for(const auto [key, cfg] : i.all_children_range()) {
|
||||
if(key.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const child_map::iterator itor = children_.find(item.key);
|
||||
const child_map::iterator itor = children_.find(key);
|
||||
if(itor == children_.end() || index >= itor->second.size()) {
|
||||
throw error("error in diff: could not find element '" + item.key + "'");
|
||||
throw error("error in diff: could not find element '" + key + "'");
|
||||
}
|
||||
|
||||
itor->second[index]->apply_diff(item.cfg, track);
|
||||
itor->second[index]->apply_diff(cfg, track);
|
||||
}
|
||||
}
|
||||
|
||||
for(const config& i : diff.child_range("insert_child")) {
|
||||
const auto index = lexical_cast<std::size_t>(i["index"].str());
|
||||
for(const any_child item : i.all_children_range()) {
|
||||
config& inserted = add_child_at(item.key, item.cfg, index);
|
||||
for(const auto [key, cfg] : i.all_children_range()) {
|
||||
config& inserted = add_child_at(key, cfg, index);
|
||||
if(track) {
|
||||
inserted[diff_track_attribute] = "new";
|
||||
}
|
||||
|
@ -1073,13 +1073,13 @@ void config::apply_diff(const config& diff, bool track /* = false */)
|
|||
|
||||
for(const config& i : diff.child_range("delete_child")) {
|
||||
const auto index = lexical_cast<std::size_t>(i["index"].str());
|
||||
for(const any_child item : i.all_children_range()) {
|
||||
for(const auto [key, cfg] : i.all_children_range()) {
|
||||
if(!track) {
|
||||
remove_child(item.key, index);
|
||||
remove_child(key, index);
|
||||
} else {
|
||||
const child_map::iterator itor = children_.find(item.key);
|
||||
const child_map::iterator itor = children_.find(key);
|
||||
if(itor == children_.end() || index >= itor->second.size()) {
|
||||
throw error("error in diff: could not find element '" + item.key + "'");
|
||||
throw error("error in diff: could not find element '" + key + "'");
|
||||
}
|
||||
|
||||
itor->second[index]->values_[diff_track_attribute] = "deleted";
|
||||
|
@ -1093,24 +1093,24 @@ void config::clear_diff_track(const config& diff)
|
|||
remove_attribute(diff_track_attribute);
|
||||
for(const config& i : diff.child_range("delete_child")) {
|
||||
const auto index = lexical_cast<std::size_t>(i["index"].str());
|
||||
for(const any_child item : i.all_children_range()) {
|
||||
remove_child(item.key, index);
|
||||
for(const auto [key, cfg] : i.all_children_range()) {
|
||||
remove_child(key, index);
|
||||
}
|
||||
}
|
||||
|
||||
for(const config& i : diff.child_range("change_child")) {
|
||||
const std::size_t index = lexical_cast<std::size_t>(i["index"].str());
|
||||
for(const any_child item : i.all_children_range()) {
|
||||
if(item.key.empty()) {
|
||||
for(const auto [key, cfg] : i.all_children_range()) {
|
||||
if(key.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const child_map::iterator itor = children_.find(item.key);
|
||||
const child_map::iterator itor = children_.find(key);
|
||||
if(itor == children_.end() || index >= itor->second.size()) {
|
||||
throw error("error in diff: could not find element '" + item.key + "'");
|
||||
throw error("error in diff: could not find element '" + key + "'");
|
||||
}
|
||||
|
||||
itor->second[index]->clear_diff_track(item.cfg);
|
||||
itor->second[index]->clear_diff_track(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1215,21 +1215,21 @@ bool config::matches(const config& filter) const
|
|||
}
|
||||
}
|
||||
|
||||
for(const any_child i : filter.all_children_range()) {
|
||||
if(i.key == "not") {
|
||||
result = result && !matches(i.cfg);
|
||||
for(const auto [key, cfg] : filter.all_children_range()) {
|
||||
if(key == "not") {
|
||||
result = result && !matches(cfg);
|
||||
continue;
|
||||
} else if(i.key == "and") {
|
||||
result = result && matches(i.cfg);
|
||||
} else if(key == "and") {
|
||||
result = result && matches(cfg);
|
||||
continue;
|
||||
} else if(i.key == "or") {
|
||||
result = result || matches(i.cfg);
|
||||
} else if(key == "or") {
|
||||
result = result || matches(cfg);
|
||||
continue;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for(const config& j : child_range(i.key)) {
|
||||
if(j.matches(i.cfg)) {
|
||||
for(const config& j : child_range(key)) {
|
||||
if(j.matches(cfg)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -1265,19 +1265,19 @@ std::ostream& operator<<(std::ostream& outstream, const config& cfg)
|
|||
outstream << key << " = " << value << '\n';
|
||||
}
|
||||
|
||||
for(const config::any_child child : cfg.all_children_range()) {
|
||||
for(const auto [key, cfg] : cfg.all_children_range()) {
|
||||
for(int j = 0; j < i - 1; ++j) {
|
||||
outstream << '\t';
|
||||
}
|
||||
|
||||
outstream << "[" << child.key << "]\n";
|
||||
outstream << child.cfg;
|
||||
outstream << "[" << key << "]\n";
|
||||
outstream << cfg;
|
||||
|
||||
for(int j = 0; j < i - 1; ++j) {
|
||||
outstream << '\t';
|
||||
}
|
||||
|
||||
outstream << "[/" << child.key << "]\n";
|
||||
outstream << "[/" << key << "]\n";
|
||||
}
|
||||
|
||||
i--;
|
||||
|
@ -1319,8 +1319,8 @@ std::string config::hash() const
|
|||
}
|
||||
}
|
||||
|
||||
for(const any_child ch : all_children_range()) {
|
||||
std::string child_hash = ch.cfg.hash();
|
||||
for(const auto [key, cfg] : all_children_range()) {
|
||||
std::string child_hash = cfg.hash();
|
||||
for(char c : child_hash) {
|
||||
hash_str[i] ^= c;
|
||||
++i;
|
||||
|
|
|
@ -270,9 +270,8 @@ void config_cache::read_defines_file(const std::string& file_path)
|
|||
|
||||
// use static preproc_define::read_pair(config) to make a object
|
||||
// and pass that object config_cache_transaction::insert_to_active method
|
||||
for(const config::any_child value : cfg.all_children_range()) {
|
||||
config_cache_transaction::instance().insert_to_active(
|
||||
preproc_define::read_pair(value.cfg));
|
||||
for(const auto [key, cfg] : cfg.all_children_range()) {
|
||||
config_cache_transaction::instance().insert_to_active(preproc_define::read_pair(cfg));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -419,29 +419,29 @@ config map_context::convert_scenario(const config& old_scenario)
|
|||
// if [unit], set the unit's side
|
||||
// for [time]:
|
||||
// keep under [multiplayer]
|
||||
for(const config::any_child child : old_scenario.all_children_range()) {
|
||||
if(child.key != "side" && child.key != "time") {
|
||||
config& c = event.add_child(child.key);
|
||||
c.append_attributes(child.cfg);
|
||||
c.append_children(child.cfg);
|
||||
} else if(child.key == "side") {
|
||||
for(const auto [child_key, child_cfg]: old_scenario.all_children_range()) {
|
||||
if(child_key != "side" && child_key != "time") {
|
||||
config& c = event.add_child(child_key);
|
||||
c.append_attributes(child_cfg);
|
||||
c.append_children(child_cfg);
|
||||
} else if(child_key == "side") {
|
||||
config& c = multiplayer.add_child("side");
|
||||
c.append_attributes(child.cfg);
|
||||
for(const config::any_child side_child : child.cfg.all_children_range()) {
|
||||
if(side_child.key == "village") {
|
||||
c.append_attributes(child_cfg);
|
||||
for(const auto [side_key, side_cfg] : child_cfg.all_children_range()) {
|
||||
if(side_key == "village") {
|
||||
config& c1 = c.add_child("village");
|
||||
c1.append_attributes(side_child.cfg);
|
||||
c1.append_attributes(side_cfg);
|
||||
} else {
|
||||
config& c1 = event.add_child(side_child.key);
|
||||
c1.append_attributes(side_child.cfg);
|
||||
if(side_child.key == "unit") {
|
||||
c1["side"] = child.cfg["side"];
|
||||
config& c1 = event.add_child(side_key);
|
||||
c1.append_attributes(side_cfg);
|
||||
if(side_key == "unit") {
|
||||
c1["side"] = child_cfg["side"];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(child.key == "time") {
|
||||
} else if(child_key == "time") {
|
||||
config& c = multiplayer.add_child("time");
|
||||
c.append_attributes(child.cfg);
|
||||
c.append_attributes(child_cfg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -118,9 +118,9 @@ variant attack_type_callable::get_value(const std::string& key) const
|
|||
} else if(key == "specials" || key == "special") {
|
||||
std::vector<variant> res;
|
||||
|
||||
for(const auto special : att_->specials().all_children_range()) {
|
||||
if(!special.cfg["id"].empty()) {
|
||||
res.emplace_back(special.cfg["id"].str());
|
||||
for(const auto [_, special_cfg] : att_->specials().all_children_range()) {
|
||||
if(!special_cfg["id"].empty()) {
|
||||
res.emplace_back(special_cfg["id"].str());
|
||||
}
|
||||
}
|
||||
return variant(res);
|
||||
|
@ -549,18 +549,18 @@ variant config_callable::get_value(const std::string& key) const
|
|||
return variant(result);
|
||||
} else if(key == "__all_children") {
|
||||
std::vector<variant> result;
|
||||
for(const auto child : cfg_.all_children_range()) {
|
||||
const variant cfg_child(std::make_shared<config_callable>(child.cfg));
|
||||
const variant kv(std::make_shared<key_value_pair>(variant(child.key), cfg_child));
|
||||
for(const auto [child_key, child_cfg] : cfg_.all_children_range()) {
|
||||
const variant cfg_child(std::make_shared<config_callable>(child_cfg));
|
||||
const variant kv(std::make_shared<key_value_pair>(variant(child_key), cfg_child));
|
||||
result.push_back(kv);
|
||||
}
|
||||
|
||||
return variant(result);
|
||||
} else if(key == "__children") {
|
||||
std::map<std::string, std::vector<variant>> build;
|
||||
for(const auto child : cfg_.all_children_range()) {
|
||||
const variant cfg_child(std::make_shared<config_callable>(child.cfg));
|
||||
build[child.key].push_back(cfg_child);
|
||||
for(const auto [child_key, child_cfg] : cfg_.all_children_range()) {
|
||||
const variant cfg_child(std::make_shared<config_callable>(child_cfg));
|
||||
build[child_key].push_back(cfg_child);
|
||||
}
|
||||
|
||||
std::map<variant,variant> result;
|
||||
|
|
|
@ -569,9 +569,8 @@ void game_config_manager::load_addons_cfg()
|
|||
};
|
||||
|
||||
// Annotate appropriate addon types with addon_id info.
|
||||
for(auto child : umc_cfg.all_children_range()) {
|
||||
if(tags_with_addon_id.count(child.key) > 0) {
|
||||
auto& cfg = child.cfg;
|
||||
for(auto [key, cfg] : umc_cfg.all_children_range()) {
|
||||
if(tags_with_addon_id.count(key) > 0) {
|
||||
cfg["addon_id"] = addon_id;
|
||||
cfg["addon_title"] = addon_title;
|
||||
// Note that this may reformat the string in a canonical form.
|
||||
|
|
|
@ -362,11 +362,11 @@ private:
|
|||
|
||||
void event_handler::read_filters(const config &cfg)
|
||||
{
|
||||
for(auto filter : cfg.all_children_range()) {
|
||||
vconfig vcfg(filter.cfg);
|
||||
if(auto filter_ptr = make_filter(filter.key, vcfg)) {
|
||||
for(const auto [filter_key, filter_cfg] : cfg.all_children_range()) {
|
||||
vconfig vcfg(filter_cfg);
|
||||
if(auto filter_ptr = make_filter(filter_key, vcfg)) {
|
||||
add_filter(std::move(filter_ptr));
|
||||
} else if(filter.key == "insert_tag" && make_filter(vcfg["name"], vconfig::empty_vconfig())) {
|
||||
} else if(filter_key == "insert_tag" && make_filter(vcfg["name"], vconfig::empty_vconfig())) {
|
||||
add_filter(std::make_unique<filter_dynamic>(vcfg["name"], vcfg["variable"]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,9 +83,9 @@ void manager::add_event_handler_from_wml(const config& handler, game_lua_kernel&
|
|||
}
|
||||
args[attr] = val;
|
||||
}
|
||||
for(auto child : handler.all_children_range()) {
|
||||
if(child.key.compare(0, 6, "filter") != 0) {
|
||||
args.add_child(child.key, child.cfg);
|
||||
for(auto [key, cfg] : handler.all_children_range()) {
|
||||
if(key.compare(0, 6, "filter") != 0) {
|
||||
args.add_child(key, cfg);
|
||||
}
|
||||
}
|
||||
new_handler->set_arguments(args);
|
||||
|
|
|
@ -228,9 +228,9 @@ void cave_map_generator::cave_map_generator_job::place_chamber(const chamber& c)
|
|||
if (c.items == nullptr || c.locs.empty()) return;
|
||||
|
||||
std::size_t index = 0;
|
||||
for (const config::any_child it : c.items->all_children_range())
|
||||
for(const auto [child_key, child_cfg] : c.items->all_children_range())
|
||||
{
|
||||
config cfg = it.cfg;
|
||||
config cfg = child_cfg;
|
||||
auto filter = cfg.optional_child("filter");
|
||||
config* object_filter = nullptr;
|
||||
if (auto object = cfg.optional_child("object")) {
|
||||
|
@ -239,10 +239,10 @@ void cave_map_generator::cave_map_generator_job::place_chamber(const chamber& c)
|
|||
}
|
||||
}
|
||||
|
||||
if (!it.cfg["same_location_as_previous"].to_bool()) {
|
||||
if (!child_cfg["same_location_as_previous"].to_bool()) {
|
||||
index = rng_()%c.locs.size();
|
||||
}
|
||||
std::string loc_var = it.cfg["store_location_as"];
|
||||
std::string loc_var = child_cfg["store_location_as"];
|
||||
|
||||
std::set<map_location>::const_iterator loc = c.locs.begin();
|
||||
std::advance(loc,index);
|
||||
|
@ -261,11 +261,11 @@ void cave_map_generator::cave_map_generator_job::place_chamber(const chamber& c)
|
|||
}
|
||||
|
||||
// If this is a side, place a castle for the side
|
||||
if (it.key == "side" && !it.cfg["no_castle"].to_bool()) {
|
||||
place_castle(it.cfg["side"].to_int(-1), *loc);
|
||||
if (child_key == "side" && !child_cfg["no_castle"].to_bool()) {
|
||||
place_castle(child_cfg["side"].to_int(-1), *loc);
|
||||
}
|
||||
|
||||
res_.add_child(it.key, cfg);
|
||||
res_.add_child(child_key, cfg);
|
||||
|
||||
if(!loc_var.empty()) {
|
||||
config &temp = res_.add_child("event");
|
||||
|
|
|
@ -677,11 +677,8 @@ void canvas::parse_cfg(const config& cfg)
|
|||
{
|
||||
log_scope2(log_gui_parse, "Canvas: parsing config.");
|
||||
|
||||
for(const auto shape : cfg.all_children_range())
|
||||
for(const auto [type, data] : cfg.all_children_range())
|
||||
{
|
||||
const std::string& type = shape.key;
|
||||
const config& data = shape.cfg;
|
||||
|
||||
DBG_GUI_P << "Canvas: found shape of the type " << type << ".";
|
||||
|
||||
if(type == "line") {
|
||||
|
@ -699,11 +696,10 @@ void canvas::parse_cfg(const config& cfg)
|
|||
} else if(type == "pre_commit") {
|
||||
|
||||
/* note this should get split if more preprocessing is used. */
|
||||
for(const auto function : data.all_children_range())
|
||||
for(const auto [func_key, func_cfg] : data.all_children_range())
|
||||
{
|
||||
|
||||
if(function.key == "blur") {
|
||||
blur_depth_ = function.cfg["depth"];
|
||||
if(func_key == "blur") {
|
||||
blur_depth_ = func_cfg["depth"];
|
||||
} else {
|
||||
ERR_GUI_P << "Canvas: found a pre commit function"
|
||||
<< " of an invalid type " << type << ".";
|
||||
|
|
|
@ -511,18 +511,17 @@ void variable_mode_controller::show_list(tree_view_node& node)
|
|||
|
||||
std::map<std::string, std::size_t> wml_array_sizes;
|
||||
|
||||
for(const auto ch : vars().all_children_range())
|
||||
for(const auto [key, cfg] : vars().all_children_range())
|
||||
{
|
||||
|
||||
std::ostringstream cur_str;
|
||||
cur_str << "[" << ch.key << "][" << wml_array_sizes[ch.key] << "]";
|
||||
cur_str << "[" << key << "][" << wml_array_sizes[key] << "]";
|
||||
|
||||
this->c.set_node_callback(
|
||||
view().stuff_list_entry(&node, "basic")
|
||||
.widget("name", cur_str.str())
|
||||
.add(),
|
||||
&variable_mode_controller::show_array);
|
||||
wml_array_sizes[ch.key]++;
|
||||
wml_array_sizes[key]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -660,18 +659,17 @@ void unit_mode_controller::show_unit(tree_view_node& node)
|
|||
|
||||
std::map<std::string, std::size_t> wml_array_sizes;
|
||||
|
||||
for(const auto ch : u->variables().all_children_range())
|
||||
for(const auto [key, cfg] : u->variables().all_children_range())
|
||||
{
|
||||
|
||||
std::ostringstream cur_str;
|
||||
cur_str << "[" << ch.key << "][" << wml_array_sizes[ch.key] << "]";
|
||||
cur_str << "[" << key << "][" << wml_array_sizes[key] << "]";
|
||||
|
||||
this->c.set_node_callback(
|
||||
view().stuff_list_entry(&node, "basic")
|
||||
.widget("name", cur_str.str())
|
||||
.add(),
|
||||
&unit_mode_controller::show_array);
|
||||
wml_array_sizes[ch.key]++;
|
||||
wml_array_sizes[key]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -865,11 +863,10 @@ void team_mode_controller::show_vars(tree_view_node& node, int side)
|
|||
|
||||
std::map<std::string, std::size_t> wml_array_sizes;
|
||||
|
||||
for(const auto ch : t.variables().all_children_range())
|
||||
for(const auto [key, cfg] : t.variables().all_children_range())
|
||||
{
|
||||
|
||||
std::ostringstream cur_str;
|
||||
cur_str << "[" << ch.key << "][" << wml_array_sizes[ch.key] << "]";
|
||||
cur_str << "[" << key << "][" << wml_array_sizes[key] << "]";
|
||||
|
||||
this->c.set_node_callback(
|
||||
view().stuff_list_entry(&node, "basic")
|
||||
|
@ -877,7 +874,7 @@ void team_mode_controller::show_vars(tree_view_node& node, int side)
|
|||
.add(),
|
||||
&team_mode_controller::show_array,
|
||||
side);
|
||||
wml_array_sizes[ch.key]++;
|
||||
wml_array_sizes[key]++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,9 +39,9 @@ mp_options_helper::mp_options_helper(window& window, ng::create_engine& create_e
|
|||
, visible_options_()
|
||||
, options_data_()
|
||||
{
|
||||
for(const auto c : prefs::get().options().all_children_range()) {
|
||||
for(const auto& saved_option : c.cfg.child_range("option")) {
|
||||
options_data_[c.cfg["id"]][saved_option["id"].str()] = saved_option["value"];
|
||||
for(const auto [_, cfg] : prefs::get().options().all_children_range()) {
|
||||
for(const auto& saved_option : cfg.child_range("option")) {
|
||||
options_data_[cfg["id"]][saved_option["id"].str()] = saved_option["value"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,21 +224,15 @@ void mp_options_helper::display_custom_options(const std::string& type, int node
|
|||
tree_view_node& option_node = options_tree_.add_node("option_node", data, node_position);
|
||||
type_node_vector.push_back(&option_node);
|
||||
|
||||
for(const config::any_child opt : options.all_children_range()) {
|
||||
for(const auto [option_key, option_cfg] : options.all_children_range()) {
|
||||
data.clear();
|
||||
item.clear();
|
||||
|
||||
const config& option_cfg = opt.cfg;
|
||||
|
||||
const auto add_name = [&](const std::string& id) {
|
||||
item["label"] = option_cfg["name"];
|
||||
data.emplace(id, item);
|
||||
};
|
||||
|
||||
config::attribute_value val;
|
||||
|
||||
if(opt.key == "checkbox") {
|
||||
add_name("option_checkbox");
|
||||
if(option_key == "checkbox") {
|
||||
item["label"] = option_cfg["name"];
|
||||
data.emplace("option_checkbox", item);
|
||||
|
||||
toggle_button* checkbox;
|
||||
std::tie(checkbox, val) = add_node_and_get_widget<toggle_button>(option_node, "option_checkbox", data, option_cfg);
|
||||
|
@ -248,15 +242,16 @@ void mp_options_helper::display_custom_options(const std::string& type, int node
|
|||
connect_signal_notify_modified(*checkbox,
|
||||
std::bind(&mp_options_helper::update_options_data_map<toggle_button>, this, checkbox, visible_options_.back()));
|
||||
|
||||
} else if(opt.key == "spacer") {
|
||||
} else if(option_key == "spacer") {
|
||||
option_node.add_child("options_spacer_node", empty_map);
|
||||
|
||||
} else if(opt.key == "choice") {
|
||||
} else if(option_key == "choice") {
|
||||
if(!option_cfg.has_child("item")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
add_name("menu_button_label");
|
||||
item["label"] = option_cfg["name"];
|
||||
data.emplace("menu_button_label", item);
|
||||
|
||||
std::vector<config> combo_items;
|
||||
std::vector<std::string> combo_values;
|
||||
|
@ -284,8 +279,9 @@ void mp_options_helper::display_custom_options(const std::string& type, int node
|
|||
connect_signal_notify_modified(*menu,
|
||||
std::bind(&mp_options_helper::update_options_data_map_menu_button, this, menu, visible_options_.back(), option_cfg));
|
||||
|
||||
} else if(opt.key == "slider") {
|
||||
add_name("slider_label");
|
||||
} else if(option_key == "slider") {
|
||||
item["label"] = option_cfg["name"];
|
||||
data.emplace("slider_label", item);
|
||||
|
||||
slider* slide;
|
||||
std::tie(slide, val) = add_node_and_get_widget<slider>(option_node, "option_slider", data, option_cfg);
|
||||
|
@ -297,8 +293,9 @@ void mp_options_helper::display_custom_options(const std::string& type, int node
|
|||
connect_signal_notify_modified(*slide,
|
||||
std::bind(&mp_options_helper::update_options_data_map<slider>, this, slide, visible_options_.back()));
|
||||
|
||||
} else if(opt.key == "entry") {
|
||||
add_name("text_entry_label");
|
||||
} else if(option_key == "entry") {
|
||||
item["label"] = option_cfg["name"];
|
||||
data.emplace("text_entry_label", item);
|
||||
|
||||
text_box* textbox;
|
||||
std::tie(textbox, val) = add_node_and_get_widget<text_box>(option_node, "option_text_entry", data, option_cfg);
|
||||
|
|
|
@ -1158,8 +1158,8 @@ static void find_next_scenarios(const config& parent, std::set<std::string>& res
|
|||
result.insert(endlevel["next_scenario"]);
|
||||
}
|
||||
}
|
||||
for(const auto cfg : parent.all_children_range()) {
|
||||
find_next_scenarios(cfg.cfg, result);
|
||||
for(const auto [key, cfg] : parent.all_children_range()) {
|
||||
find_next_scenarios(cfg, result);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -271,14 +271,14 @@ void prefs::load_preferences()
|
|||
}
|
||||
}
|
||||
|
||||
for(const auto child : synced_prefs.all_children_range()) {
|
||||
if(std::find(synced_children_.begin(), synced_children_.end(), child.key) == synced_children_.end()) {
|
||||
unknown_synced_children_.insert(child.key);
|
||||
for(const auto [key, _] : synced_prefs.all_children_range()) {
|
||||
if(std::find(synced_children_.begin(), synced_children_.end(), key) == synced_children_.end()) {
|
||||
unknown_synced_children_.insert(key);
|
||||
}
|
||||
}
|
||||
for(const auto child : unsynced_prefs.all_children_range()) {
|
||||
if(std::find(unsynced_children_.begin(), unsynced_children_.end(), child.key) == unsynced_children_.end()) {
|
||||
unknown_unsynced_children_.insert(child.key);
|
||||
for(const auto [key, _] : unsynced_prefs.all_children_range()) {
|
||||
if(std::find(unsynced_children_.begin(), unsynced_children_.end(), key) == unsynced_children_.end()) {
|
||||
unknown_unsynced_children_.insert(key);
|
||||
}
|
||||
}
|
||||
} catch(const config::error& e) {
|
||||
|
@ -324,9 +324,9 @@ void prefs::load_preferences()
|
|||
message = foobar
|
||||
[/line]
|
||||
*/
|
||||
for(const config::any_child h : history->all_children_range()) {
|
||||
for(const config& l : h.cfg.child_range("line")) {
|
||||
history_map_[h.key].push_back(l["message"]);
|
||||
for(const auto [key, cfg] : history->all_children_range()) {
|
||||
for(const config& l : cfg.child_range("line")) {
|
||||
history_map_[key].push_back(l["message"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -698,8 +698,8 @@ REPLAY_ACTION_TYPE get_replay_action_type(const config& command)
|
|||
if(command.all_children_count() != 1) {
|
||||
return REPLAY_ACTION_TYPE::INVALID;
|
||||
}
|
||||
auto child = command.all_children_range().front();
|
||||
if(child.key == "speak" || child.key == "label" || child.key == "surrender" || child.key == "clear_labels" || child.key == "rename" || child.key == "countdown_update") {
|
||||
auto [key, _] = command.all_children_range().front();
|
||||
if(key == "speak" || key == "label" || key == "surrender" || key == "clear_labels" || key == "rename" || key == "countdown_update") {
|
||||
return REPLAY_ACTION_TYPE::UNSYNCED;
|
||||
}
|
||||
if(command["dependent"].to_bool(false)) {
|
||||
|
@ -750,7 +750,7 @@ REPLAY_RETURN do_replay_handle(bool one_move)
|
|||
}
|
||||
|
||||
|
||||
const config::const_all_children_itors ch_itors = cfg->all_children_range();
|
||||
const auto ch_itors = cfg->all_children_range();
|
||||
//if there is an empty command tag or a start tag
|
||||
if (ch_itors.empty() || cfg->has_child("start"))
|
||||
{
|
||||
|
@ -882,7 +882,7 @@ REPLAY_RETURN do_replay_handle(bool one_move)
|
|||
// but we are called from
|
||||
// the only other option for "dependent" command is checksum which is already checked.
|
||||
assert(cfg->all_children_count() == 1);
|
||||
std::string child_name = cfg->all_children_range().front().key;
|
||||
auto [child_name, _] = cfg->all_children_range().front();
|
||||
DBG_REPLAY << "got an dependent action name = " << child_name;
|
||||
resources::recorder->revert_action();
|
||||
return REPLAY_FOUND_DEPENDENT;
|
||||
|
@ -890,8 +890,7 @@ REPLAY_RETURN do_replay_handle(bool one_move)
|
|||
else
|
||||
{
|
||||
//we checked for empty commands at the beginning.
|
||||
const std::string & commandname = cfg->ordered_begin()->key;
|
||||
config data = cfg->ordered_begin()->cfg;
|
||||
const auto [commandname, data] = cfg->all_children_range().front();
|
||||
|
||||
if(!is_unsynced)
|
||||
{
|
||||
|
|
|
@ -5762,13 +5762,13 @@ void game_lua_kernel::load_game(const config& level)
|
|||
|
||||
lua_newtable(L);
|
||||
int k = 1;
|
||||
for (const config::any_child v : level.all_children_range())
|
||||
for(const auto [child_key, child_cfg] : level.all_children_range())
|
||||
{
|
||||
if (is_handled_file_tag(v.key)) continue;
|
||||
if (is_handled_file_tag(child_key)) continue;
|
||||
lua_createtable(L, 2, 0);
|
||||
lua_pushstring(L, v.key.c_str());
|
||||
lua_pushstring(L, child_key.c_str());
|
||||
lua_rawseti(L, -2, 1);
|
||||
luaW_pushconfig(L, v.cfg);
|
||||
luaW_pushconfig(L, child_cfg);
|
||||
lua_rawseti(L, -2, 2);
|
||||
lua_rawseti(L, -2, k++);
|
||||
}
|
||||
|
|
|
@ -657,13 +657,13 @@ void luaW_filltable(lua_State *L, const config& cfg)
|
|||
return;
|
||||
|
||||
int k = 1;
|
||||
for (const config::any_child ch : cfg.all_children_range())
|
||||
for(const auto [child_key, child_cfg] : cfg.all_children_range())
|
||||
{
|
||||
luaW_push_namedtuple(L, {"tag", "contents"});
|
||||
lua_pushstring(L, ch.key.c_str());
|
||||
lua_pushstring(L, child_key.c_str());
|
||||
lua_rawseti(L, -2, 1);
|
||||
lua_newtable(L);
|
||||
luaW_filltable(L, ch.cfg);
|
||||
luaW_filltable(L, child_cfg);
|
||||
lua_rawseti(L, -2, 2);
|
||||
lua_rawseti(L, -2, k++);
|
||||
}
|
||||
|
|
|
@ -174,8 +174,8 @@ static int intf_wml_merge(lua_State* L)
|
|||
base.append_children(merge);
|
||||
} else {
|
||||
if(mode == "replace") {
|
||||
for(const auto c : merge.all_children_range()) {
|
||||
base.clear_children(c.key);
|
||||
for(const auto [key, _] : merge.all_children_range()) {
|
||||
base.clear_children(key);
|
||||
}
|
||||
} else if(mode != "merge") {
|
||||
return luaL_argerror(L, 3, "invalid merge mode - must be merge, append, or replace");
|
||||
|
|
|
@ -720,15 +720,15 @@ static void write_internal(const config& cfg, std::ostream& out, std::string& te
|
|||
write_key_val(out, key, value, tab, textdomain);
|
||||
}
|
||||
|
||||
for(const config::any_child item : cfg.all_children_range()) {
|
||||
if(!config::valid_tag(item.key)) {
|
||||
ERR_CF << "Config contains invalid tag name '" << item.key << "', skipping...";
|
||||
for(const auto [key, item_cfg] : cfg.all_children_range()) {
|
||||
if(!config::valid_tag(key)) {
|
||||
ERR_CF << "Config contains invalid tag name '" << key << "', skipping...";
|
||||
continue;
|
||||
}
|
||||
|
||||
write_open_child(out, item.key, tab);
|
||||
write_internal(item.cfg, out, textdomain, tab + 1);
|
||||
write_close_child(out, item.key, tab);
|
||||
write_open_child(out, key, tab);
|
||||
write_internal(item_cfg, out, textdomain, tab + 1);
|
||||
write_close_child(out, key, tab);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -808,10 +808,10 @@ void schema_self_validator::validate(const config& cfg, const std::string& name,
|
|||
} else if(name == "tag") {
|
||||
bool first_tag = true, first_key = true;
|
||||
std::vector<std::string> tag_names, key_names;
|
||||
for(auto current : cfg.all_children_range()) {
|
||||
if(current.key == "tag" || current.key == "link") {
|
||||
std::string tag_name = current.cfg["name"];
|
||||
if(current.key == "link") {
|
||||
for(const auto [current_key, current_cfg] : cfg.all_children_range()) {
|
||||
if(current_key == "tag" || current_key == "link") {
|
||||
std::string tag_name = current_cfg["name"];
|
||||
if(current_key == "link") {
|
||||
tag_name.erase(0, tag_name.find_last_of('/') + 1);
|
||||
}
|
||||
if(first_tag) {
|
||||
|
@ -819,15 +819,15 @@ void schema_self_validator::validate(const config& cfg, const std::string& name,
|
|||
first_tag = false;
|
||||
continue;
|
||||
}
|
||||
check_for_duplicates(tag_name, tag_names, current.cfg, DUPLICATE_TAG, file, start_line, current.key);
|
||||
} else if(current.key == "key") {
|
||||
std::string key_name = current.cfg["name"];
|
||||
check_for_duplicates(tag_name, tag_names, current_cfg, DUPLICATE_TAG, file, start_line, current_key);
|
||||
} else if(current_key == "key") {
|
||||
std::string key_name = current_cfg["name"];
|
||||
if(first_key) {
|
||||
key_names.push_back(key_name);
|
||||
first_key = false;
|
||||
continue;
|
||||
}
|
||||
check_for_duplicates(key_name, key_names, current.cfg, DUPLICATE_KEY, file, start_line, current.key);
|
||||
check_for_duplicates(key_name, key_names, current_cfg, DUPLICATE_KEY, file, start_line, current_key);
|
||||
}
|
||||
}
|
||||
} else if(name == "wml_schema") {
|
||||
|
|
|
@ -226,8 +226,8 @@ static config expand_partialresolution(const config& theme)
|
|||
|
||||
// cannot add [status] sub-elements, but who cares
|
||||
for(const auto& add : part.child_range("add")) {
|
||||
for(const auto child : add.all_children_range()) {
|
||||
resolution.add_child(child.key, child.cfg);
|
||||
for(const auto [key, cfg] : add.all_children_range()) {
|
||||
resolution.add_child(key, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,9 +240,9 @@ static config expand_partialresolution(const config& theme)
|
|||
static void do_resolve_rects(const config& cfg, config& resolved_config, config* resol_cfg = nullptr)
|
||||
{
|
||||
// recursively resolve children
|
||||
for(const config::any_child value : cfg.all_children_range()) {
|
||||
config& childcfg = resolved_config.add_child(value.key);
|
||||
do_resolve_rects(value.cfg, childcfg, value.key == "resolution" ? &childcfg : resol_cfg);
|
||||
for(const auto [child_key, child_cfg] : cfg.all_children_range()) {
|
||||
config& dest = resolved_config.add_child(child_key);
|
||||
do_resolve_rects(child_cfg, dest, child_key == "resolution" ? &dest : resol_cfg);
|
||||
}
|
||||
|
||||
// copy all key/values
|
||||
|
@ -689,8 +689,8 @@ void theme::add_object(std::size_t sw, std::size_t sh, const config& cfg)
|
|||
}
|
||||
|
||||
if(const auto status_cfg = cfg.optional_child("status")) {
|
||||
for(const config::any_child i : status_cfg->all_children_range()) {
|
||||
status_[i.key].reset(new status_item(sw, sh, i.cfg));
|
||||
for(const auto [child_key, child_cfg] : status_cfg->all_children_range()) {
|
||||
status_[child_key].reset(new status_item(sw, sh, child_cfg));
|
||||
}
|
||||
if(const auto unit_image_cfg = status_cfg->optional_child("unit_image")) {
|
||||
unit_image_ = object(sw, sh, unit_image_cfg.value());
|
||||
|
|
|
@ -268,8 +268,8 @@ std::vector<std::string> unit::get_ability_list() const
|
|||
{
|
||||
std::vector<std::string> res;
|
||||
|
||||
for (const config::any_child ab : this->abilities_.all_children_range()) {
|
||||
std::string id = ab.cfg["id"];
|
||||
for(const auto [key, cfg] : this->abilities_.all_children_range()) {
|
||||
std::string id = cfg["id"];
|
||||
if (!id.empty())
|
||||
res.push_back(std::move(id));
|
||||
}
|
||||
|
@ -284,17 +284,17 @@ namespace {
|
|||
*
|
||||
* @returns Whether name was resolved and quadruple added.
|
||||
*/
|
||||
bool add_ability_tooltip(const config::any_child &ab, unit_race::GENDER gender, std::vector<std::tuple<std::string, t_string,t_string,t_string>>& res, bool active)
|
||||
bool add_ability_tooltip(const config& ab, unit_race::GENDER gender, std::vector<std::tuple<std::string, t_string,t_string,t_string>>& res, bool active)
|
||||
{
|
||||
if (active) {
|
||||
const t_string& name = gender_value(ab.cfg, gender, "name", "female_name", "name").t_str();
|
||||
const t_string& name = gender_value(ab, gender, "name", "female_name", "name").t_str();
|
||||
|
||||
if (!name.empty()) {
|
||||
res.emplace_back(
|
||||
ab.cfg["id"],
|
||||
ab.cfg["name"].t_str(),
|
||||
ab["id"],
|
||||
ab["name"].t_str(),
|
||||
name,
|
||||
ab.cfg["description"].t_str() );
|
||||
ab["description"].t_str() );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -302,17 +302,17 @@ namespace {
|
|||
{
|
||||
// See if an inactive name was specified.
|
||||
const config::attribute_value& inactive_value =
|
||||
gender_value(ab.cfg, gender, "name_inactive",
|
||||
gender_value(ab, gender, "name_inactive",
|
||||
"female_name_inactive", "name_inactive");
|
||||
const t_string& name = !inactive_value.blank() ? inactive_value.t_str() :
|
||||
gender_value(ab.cfg, gender, "name", "female_name", "name").t_str();
|
||||
gender_value(ab, gender, "name", "female_name", "name").t_str();
|
||||
|
||||
if (!name.empty()) {
|
||||
res.emplace_back(
|
||||
ab.cfg["id"],
|
||||
ab.cfg.get_or("name_inactive", "name").t_str(),
|
||||
ab["id"],
|
||||
ab.get_or("name_inactive", "name").t_str(),
|
||||
name,
|
||||
ab.cfg.get_or("description_inactive", "description").t_str() );
|
||||
ab.get_or("description_inactive", "description").t_str() );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -325,9 +325,9 @@ std::vector<std::tuple<std::string, t_string, t_string, t_string>> unit::ability
|
|||
{
|
||||
std::vector<std::tuple<std::string, t_string,t_string,t_string>> res;
|
||||
|
||||
for (const config::any_child ab : this->abilities_.all_children_range())
|
||||
for(const auto [_, cfg] : this->abilities_.all_children_range())
|
||||
{
|
||||
add_ability_tooltip(ab, gender_, res, true);
|
||||
add_ability_tooltip(cfg, gender_, res, true);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -338,10 +338,10 @@ std::vector<std::tuple<std::string, t_string, t_string, t_string>> unit::ability
|
|||
std::vector<std::tuple<std::string, t_string,t_string,t_string>> res;
|
||||
active_list.clear();
|
||||
|
||||
for (const config::any_child ab : this->abilities_.all_children_range())
|
||||
for(const auto [key, cfg] : this->abilities_.all_children_range())
|
||||
{
|
||||
bool active = ability_active(ab.key, ab.cfg, loc);
|
||||
if (add_ability_tooltip(ab, gender_, res, active))
|
||||
bool active = ability_active(key, cfg, loc);
|
||||
if (add_ability_tooltip(cfg, gender_, res, active))
|
||||
{
|
||||
active_list.push_back(active);
|
||||
}
|
||||
|
@ -594,15 +594,15 @@ static void add_string_to_vector(std::vector<std::string>& image_list, const con
|
|||
const std::vector<std::string> unit::halo_or_icon_abilities(const std::string& image_type) const
|
||||
{
|
||||
std::vector<std::string> image_list;
|
||||
for (const config::any_child sp : abilities_.all_children_range()){
|
||||
bool is_active = ability_active(sp.key, sp.cfg, loc_);
|
||||
for(const auto [key, cfg] : abilities_.all_children_range()){
|
||||
bool is_active = ability_active(key, cfg, loc_);
|
||||
//Add halo/overlay to owner of ability if active and affect_self is true.
|
||||
if( !(sp.cfg)[image_type + "_image"].str().empty() && is_active && ability_affects_self(sp.key, sp.cfg, loc_)){
|
||||
add_string_to_vector(image_list, sp.cfg,image_type + "_image");
|
||||
if( !cfg[image_type + "_image"].str().empty() && is_active && ability_affects_self(key, cfg, loc_)){
|
||||
add_string_to_vector(image_list, cfg,image_type + "_image");
|
||||
}
|
||||
//Add halo/overlay to owner of ability who affect adjacent only if active.
|
||||
if(!(sp.cfg)[image_type + "_image_self"].str().empty() && is_active){
|
||||
add_string_to_vector(image_list, sp.cfg, image_type + "_image_self");
|
||||
if(!cfg[image_type + "_image_self"].str().empty() && is_active){
|
||||
add_string_to_vector(image_list, cfg, image_type + "_image_self");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -617,10 +617,10 @@ const std::vector<std::string> unit::halo_or_icon_abilities(const std::string& i
|
|||
continue;
|
||||
if ( &*it == this )
|
||||
continue;
|
||||
for(const config::any_child j : it->abilities_.all_children_range()) {
|
||||
if(!(j.cfg)[image_type + "_image"].str().empty() && affects_side(j.cfg, side(), it->side()) && it->ability_active(j.key, j.cfg, adjacent[i]) && ability_affects_adjacent(j.key, j.cfg, i, loc_, *it))
|
||||
for(const auto [key, cfg] : it->abilities_.all_children_range()) {
|
||||
if(!cfg[image_type + "_image"].str().empty() && affects_side(cfg, side(), it->side()) && it->ability_active(key, cfg, adjacent[i]) && ability_affects_adjacent(key, cfg, i, loc_, *it))
|
||||
{
|
||||
add_string_to_vector(image_list, j.cfg, image_type + "_image");
|
||||
add_string_to_vector(image_list, cfg, image_type + "_image");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -796,18 +796,18 @@ namespace {
|
|||
std::vector<special_match>& id_result,
|
||||
const config& parent, const std::string& id,
|
||||
bool just_peeking=false) {
|
||||
for (const config::any_child sp : parent.all_children_range())
|
||||
for(const auto [key, cfg] : parent.all_children_range())
|
||||
{
|
||||
if (just_peeking && (sp.key == id || sp.cfg["id"] == id)) {
|
||||
if (just_peeking && (key == id || cfg["id"] == id)) {
|
||||
return true; // peek succeeded; done
|
||||
}
|
||||
|
||||
if(sp.key == id) {
|
||||
special_match special = { sp.key, &sp.cfg };
|
||||
if(key == id) {
|
||||
special_match special = { key, &cfg };
|
||||
tag_result.push_back(special);
|
||||
}
|
||||
if(sp.cfg["id"] == id) {
|
||||
special_match special = { sp.key, &sp.cfg };
|
||||
if(cfg["id"] == id) {
|
||||
special_match special = { key, &cfg };
|
||||
id_result.push_back(special);
|
||||
}
|
||||
}
|
||||
|
@ -817,14 +817,14 @@ namespace {
|
|||
bool get_special_children_id(std::vector<special_match>& id_result,
|
||||
const config& parent, const std::string& id,
|
||||
bool just_peeking=false) {
|
||||
for (const config::any_child sp : parent.all_children_range())
|
||||
for(const auto [key, cfg] : parent.all_children_range())
|
||||
{
|
||||
if (just_peeking && (sp.cfg["id"] == id)) {
|
||||
if (just_peeking && (cfg["id"] == id)) {
|
||||
return true; // peek succeeded; done
|
||||
}
|
||||
|
||||
if(sp.cfg["id"] == id) {
|
||||
special_match special = { sp.key, &sp.cfg };
|
||||
if(cfg["id"] == id) {
|
||||
special_match special = { key, &cfg };
|
||||
id_result.push_back(special);
|
||||
}
|
||||
}
|
||||
|
@ -834,14 +834,14 @@ namespace {
|
|||
bool get_special_children_tags(std::vector<special_match>& tag_result,
|
||||
const config& parent, const std::string& id,
|
||||
bool just_peeking=false) {
|
||||
for (const config::any_child sp : parent.all_children_range())
|
||||
for(const auto [key, cfg] : parent.all_children_range())
|
||||
{
|
||||
if (just_peeking && (sp.key == id)) {
|
||||
if (just_peeking && (key == id)) {
|
||||
return true; // peek succeeded; done
|
||||
}
|
||||
|
||||
if(sp.key == id) {
|
||||
special_match special = { sp.key, &sp.cfg };
|
||||
if(key == id) {
|
||||
special_match special = { key, &cfg };
|
||||
tag_result.push_back(special);
|
||||
}
|
||||
}
|
||||
|
@ -969,19 +969,19 @@ std::vector<std::pair<t_string, t_string>> attack_type::special_tooltips(
|
|||
if ( active_list )
|
||||
active_list->clear();
|
||||
|
||||
for (const config::any_child sp : specials_.all_children_range())
|
||||
for(const auto [key, cfg] : specials_.all_children_range())
|
||||
{
|
||||
if ( !active_list || special_active(sp.cfg, AFFECT_EITHER, sp.key) ) {
|
||||
const t_string &name = sp.cfg["name"];
|
||||
if ( !active_list || special_active(cfg, AFFECT_EITHER, key) ) {
|
||||
const t_string &name = cfg["name"];
|
||||
if (!name.empty()) {
|
||||
res.emplace_back(name, sp.cfg["description"].t_str() );
|
||||
res.emplace_back(name, cfg["description"].t_str() );
|
||||
if ( active_list )
|
||||
active_list->push_back(true);
|
||||
}
|
||||
} else {
|
||||
const t_string& name = sp.cfg.get_or("name_inactive", "name").t_str();
|
||||
const t_string& name = cfg.get_or("name_inactive", "name").t_str();
|
||||
if (!name.empty()) {
|
||||
res.emplace_back(name, sp.cfg.get_or("description_inactive", "description").t_str() );
|
||||
res.emplace_back(name, cfg.get_or("description_inactive", "description").t_str() );
|
||||
active_list->push_back(false);
|
||||
}
|
||||
}
|
||||
|
@ -1019,14 +1019,14 @@ std::string attack_type::weapon_specials() const
|
|||
{
|
||||
//log_scope("weapon_specials");
|
||||
std::string res;
|
||||
for (const config::any_child sp : specials_.all_children_range())
|
||||
for(const auto [key, cfg] : specials_.all_children_range())
|
||||
{
|
||||
const bool active = special_active(sp.cfg, AFFECT_EITHER, sp.key);
|
||||
const bool active = special_active(cfg, AFFECT_EITHER, key);
|
||||
|
||||
const std::string& name =
|
||||
active
|
||||
? sp.cfg["name"].str()
|
||||
: sp.cfg.get_or("name_inactive", "name").str();
|
||||
? cfg["name"].str()
|
||||
: cfg.get_or("name_inactive", "name").str();
|
||||
if (!name.empty()) {
|
||||
if (!res.empty()) res += ", ";
|
||||
if (!active) res += font::span_color(font::inactive_details_color);
|
||||
|
@ -1063,10 +1063,10 @@ std::string attack_type::weapon_specials_value(const std::set<std::string> check
|
|||
//log_scope("weapon_specials_value");
|
||||
std::string temp_string, weapon_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(temp_string, active, sp.cfg["name"].str(), checking_name);
|
||||
for(const auto [key, cfg] : specials_.all_children_range()) {
|
||||
if((checking_tags.count(key) != 0)){
|
||||
const bool active = special_active(cfg, AFFECT_SELF, key);
|
||||
add_name(temp_string, active, cfg["name"].str(), checking_name);
|
||||
}
|
||||
}
|
||||
add_name_list(temp_string, weapon_abilities, checking_name, "");
|
||||
|
@ -1084,10 +1084,10 @@ std::string attack_type::weapon_specials_value(const std::set<std::string> check
|
|||
|
||||
|
||||
if(other_attack_) {
|
||||
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(temp_string, active, sp.cfg["name"].str(), checking_name);
|
||||
for(const auto [key, cfg] : other_attack_->specials_.all_children_range()) {
|
||||
if((checking_tags.count(key) != 0)){
|
||||
const bool active = other_attack_->special_active(cfg, AFFECT_OTHER, key);
|
||||
add_name(temp_string, active, cfg["name"].str(), checking_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1110,10 +1110,10 @@ void attack_type::weapon_specials_impl_self(
|
|||
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(temp_string, active, sp.cfg["name"].str(), checking_name);
|
||||
for(const auto [key, cfg] : self->abilities().all_children_range()){
|
||||
bool tag_checked = (!checking_tags.empty()) ? (checking_tags.count(key) != 0) : true;
|
||||
const bool active = tag_checked && check_self_abilities_impl(self_attack, other_attack, cfg, self, self_loc, whom, key, leader_bool);
|
||||
add_name(temp_string, active, cfg["name"].str(), checking_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1139,12 +1139,12 @@ void attack_type::weapon_specials_impl_adj(
|
|||
continue;
|
||||
if(&*it == self.get())
|
||||
continue;
|
||||
for (const config::any_child sp : it->abilities().all_children_range()){
|
||||
bool tag_checked = (!checking_tags.empty()) ? (checking_tags.count(sp.key) != 0) : true;
|
||||
for(const auto [key, cfg] : it->abilities().all_children_range()) {
|
||||
bool tag_checked = (!checking_tags.empty()) ? (checking_tags.count(key) != 0) : true;
|
||||
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(temp_string, active, sp.cfg["name"].str(), checking_name);
|
||||
bool affect_allies = (!affect_adjacents.empty()) ? cfg[affect_adjacents].to_bool(default_bool) : true;
|
||||
const bool active = tag_checked && check_adj_abilities_impl(self_attack, other_attack, cfg, self, *it, i, self_loc, whom, key, leader_bool) && affect_allies;
|
||||
add_name(temp_string, active, cfg["name"].str(), checking_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1958,19 +1958,19 @@ namespace
|
|||
bool matches = matches_ability_filter(cfg, tag_name, filter);
|
||||
|
||||
// Handle [and], [or], and [not] with in-order precedence
|
||||
for (const config::any_child condition : filter.all_children_range() )
|
||||
for(const auto [key, condition_cfg] : filter.all_children_range() )
|
||||
{
|
||||
// Handle [and]
|
||||
if ( condition.key == "and" )
|
||||
matches = matches && common_matches_filter(cfg, tag_name, condition.cfg);
|
||||
if ( key == "and" )
|
||||
matches = matches && common_matches_filter(cfg, tag_name, condition_cfg);
|
||||
|
||||
// Handle [or]
|
||||
else if ( condition.key == "or" )
|
||||
matches = matches || common_matches_filter(cfg, tag_name, condition.cfg);
|
||||
else if ( key == "or" )
|
||||
matches = matches || common_matches_filter(cfg, tag_name, condition_cfg);
|
||||
|
||||
// Handle [not]
|
||||
else if ( condition.key == "not" )
|
||||
matches = matches && !common_matches_filter(cfg, tag_name, condition.cfg);
|
||||
else if ( key == "not" )
|
||||
matches = matches && !common_matches_filter(cfg, tag_name, condition_cfg);
|
||||
}
|
||||
|
||||
return matches;
|
||||
|
|
|
@ -350,19 +350,19 @@ bool attack_type::matches_filter(const config& filter, const std::string& check_
|
|||
bool matches = matches_simple_filter(*this, filter, check_if_recursion);
|
||||
|
||||
// Handle [and], [or], and [not] with in-order precedence
|
||||
for (const config::any_child condition : filter.all_children_range() )
|
||||
for(const auto [key, condition_cfg] : filter.all_children_range() )
|
||||
{
|
||||
// Handle [and]
|
||||
if ( condition.key == "and" )
|
||||
matches = matches && matches_filter(condition.cfg, check_if_recursion);
|
||||
if ( key == "and" )
|
||||
matches = matches && matches_filter(condition_cfg, check_if_recursion);
|
||||
|
||||
// Handle [or]
|
||||
else if ( condition.key == "or" )
|
||||
matches = matches || matches_filter(condition.cfg, check_if_recursion);
|
||||
else if ( key == "or" )
|
||||
matches = matches || matches_filter(condition_cfg, check_if_recursion);
|
||||
|
||||
// Handle [not]
|
||||
else if ( condition.key == "not" )
|
||||
matches = matches && !matches_filter(condition.cfg, check_if_recursion);
|
||||
else if ( key == "not" )
|
||||
matches = matches && !matches_filter(condition_cfg, check_if_recursion);
|
||||
}
|
||||
|
||||
return matches;
|
||||
|
@ -436,11 +436,11 @@ bool attack_type::apply_modification(const config& cfg)
|
|||
if(del_specials.empty() == false) {
|
||||
const std::vector<std::string>& dsl = utils::split(del_specials);
|
||||
config new_specials;
|
||||
for (const config::any_child vp : specials_.all_children_range()) {
|
||||
for(const auto [key, cfg] : specials_.all_children_range()) {
|
||||
std::vector<std::string>::const_iterator found_id =
|
||||
std::find(dsl.begin(), dsl.end(), vp.cfg["id"].str());
|
||||
std::find(dsl.begin(), dsl.end(), cfg["id"].str());
|
||||
if (found_id == dsl.end()) {
|
||||
new_specials.add_child(vp.key, vp.cfg);
|
||||
new_specials.add_child(key, cfg);
|
||||
}
|
||||
}
|
||||
specials_ = new_specials;
|
||||
|
@ -456,8 +456,8 @@ bool attack_type::apply_modification(const config& cfg)
|
|||
if(mode != "append") {
|
||||
specials_.clear();
|
||||
}
|
||||
for(const config::any_child value : set_specials->all_children_range()) {
|
||||
specials_.add_child(value.key, value.cfg);
|
||||
for(const auto [key, cfg] : set_specials->all_children_range()) {
|
||||
specials_.add_child(key, cfg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -302,10 +302,10 @@ namespace {
|
|||
|
||||
void get_ability_children_id(std::vector<ability_match>& id_result,
|
||||
const config& parent, const std::string& id) {
|
||||
for (const config::any_child sp : parent.all_children_range())
|
||||
for (const auto [key, cfg] : parent.all_children_range())
|
||||
{
|
||||
if(sp.cfg["id"] == id) {
|
||||
ability_match special = { sp.key, &sp.cfg };
|
||||
if(cfg["id"] == id) {
|
||||
ability_match special = { key, &cfg };
|
||||
id_result.push_back(special);
|
||||
}
|
||||
}
|
||||
|
@ -776,8 +776,8 @@ void unit_filter_compound::fill(vconfig cfg)
|
|||
}
|
||||
else if (child.first == "experimental_filter_ability") {
|
||||
create_child(child.second, [](const vconfig& c, const unit_filter_args& args) {
|
||||
for(const config::any_child ab : args.u.abilities().all_children_range()) {
|
||||
if(args.u.ability_matches_filter(ab.cfg, ab.key, c.get_parsed_config())) {
|
||||
for(const auto [key, cfg] : args.u.abilities().all_children_range()) {
|
||||
if(args.u.ability_matches_filter(cfg, key, c.get_parsed_config())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -790,9 +790,9 @@ void unit_filter_compound::fill(vconfig cfg)
|
|||
return false;
|
||||
}
|
||||
const unit_map& units = display::get_singleton()->get_units();
|
||||
for(const config::any_child ab : args.u.abilities().all_children_range()) {
|
||||
if(args.u.ability_matches_filter(ab.cfg, ab.key, c.get_parsed_config())) {
|
||||
if (args.u.get_self_ability_bool(ab.cfg, ab.key, args.loc)) {
|
||||
for(const auto [key, cfg] : args.u.abilities().all_children_range()) {
|
||||
if(args.u.ability_matches_filter(cfg, key, c.get_parsed_config())) {
|
||||
if (args.u.get_self_ability_bool(cfg, key, args.loc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -806,9 +806,9 @@ void unit_filter_compound::fill(vconfig cfg)
|
|||
if (&*it == (args.u.shared_from_this()).get())
|
||||
continue;
|
||||
|
||||
for(const config::any_child ab : it->abilities().all_children_range()) {
|
||||
if(it->ability_matches_filter(ab.cfg, ab.key, c.get_parsed_config())) {
|
||||
if (args.u.get_adj_ability_bool(ab.cfg, ab.key, i, args.loc, *it)) {
|
||||
for(const auto [key, cfg] : it->abilities().all_children_range()) {
|
||||
if(it->ability_matches_filter(cfg, key, c.get_parsed_config())) {
|
||||
if (args.u.get_adj_ability_bool(cfg, key, i, args.loc, *it)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -300,8 +300,8 @@ void unit_type::build_help_index(
|
|||
}
|
||||
|
||||
if(auto abil_cfg = cfg.optional_child("abilities")) {
|
||||
for(const config::any_child ab : abil_cfg->all_children_range()) {
|
||||
abilities_.emplace_back(ab.cfg);
|
||||
for(const auto [key, cfg] : abil_cfg->all_children_range()) {
|
||||
abilities_.emplace_back(cfg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -313,8 +313,8 @@ void unit_type::build_help_index(
|
|||
continue;
|
||||
}
|
||||
|
||||
for(const config::any_child ab : abil_cfg->all_children_range()) {
|
||||
adv_abilities_.emplace_back(ab.cfg);
|
||||
for(const auto [key, cfg] : abil_cfg->all_children_range()) {
|
||||
adv_abilities_.emplace_back(cfg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -510,15 +510,15 @@ std::vector<t_string> combine_special_notes(const std::vector<t_string> direct,
|
|||
for(const auto& note : direct) {
|
||||
append_special_note(notes, note);
|
||||
}
|
||||
for(const config::any_child ability : abilities.all_children_range()) {
|
||||
if(ability.cfg.has_attribute("special_note")) {
|
||||
append_special_note(notes, ability.cfg["special_note"].t_str());
|
||||
for(const auto [key, cfg] : abilities.all_children_range()) {
|
||||
if(cfg.has_attribute("special_note")) {
|
||||
append_special_note(notes, cfg["special_note"].t_str());
|
||||
}
|
||||
}
|
||||
for(const auto& attack : attacks) {
|
||||
for(const config::any_child ability : attack.specials().all_children_range()) {
|
||||
if(ability.cfg.has_attribute("special_note")) {
|
||||
append_special_note(notes, ability.cfg["special_note"].t_str());
|
||||
for(const auto [key, cfg] : attack.specials().all_children_range()) {
|
||||
if(cfg.has_attribute("special_note")) {
|
||||
append_special_note(notes, cfg["special_note"].t_str());
|
||||
}
|
||||
}
|
||||
if(auto attack_type_note = string_table.find("special_note_damage_type_" + attack.type()); attack_type_note != string_table.end()) {
|
||||
|
@ -591,8 +591,8 @@ int unit_type::experience_needed(bool with_acceleration) const
|
|||
bool unit_type::has_ability_by_id(const std::string& ability) const
|
||||
{
|
||||
if(auto abil = get_cfg().optional_child("abilities")) {
|
||||
for(const config::any_child ab : abil->all_children_range()) {
|
||||
if(ab.cfg["id"] == ability) {
|
||||
for(const auto [key, cfg] : abil->all_children_range()) {
|
||||
if(cfg["id"] == ability) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -610,8 +610,8 @@ std::vector<std::string> unit_type::get_ability_list() const
|
|||
return res;
|
||||
}
|
||||
|
||||
for(const config::any_child ab : abilities->all_children_range()) {
|
||||
std::string id = ab.cfg["id"];
|
||||
for(const auto [key, cfg] : abilities->all_children_range()) {
|
||||
std::string id = cfg["id"];
|
||||
|
||||
if(!id.empty()) {
|
||||
res.push_back(std::move(id));
|
||||
|
|
|
@ -462,8 +462,7 @@ void unit::init(const config& cfg, bool use_traits, const vconfig* vcfg)
|
|||
events_.add_child("event", unit_event);
|
||||
}
|
||||
for(const config& abilities : cfg.child_range("abilities")) {
|
||||
for(const config::any_child child : abilities.all_children_range()) {
|
||||
const config& ability = child.cfg;
|
||||
for(const auto [key, ability] : abilities.all_children_range()) {
|
||||
for(const config& ability_event : ability.child_range("event")) {
|
||||
events_.add_child("event", ability_event);
|
||||
}
|
||||
|
@ -471,8 +470,7 @@ void unit::init(const config& cfg, bool use_traits, const vconfig* vcfg)
|
|||
}
|
||||
for(const config& attack : cfg.child_range("attack")) {
|
||||
for(const config& specials : attack.child_range("specials")) {
|
||||
for(const config::any_child child : specials.all_children_range()) {
|
||||
const config& special = child.cfg;
|
||||
for(const auto [key, special] : specials.all_children_range()) {
|
||||
for(const config& special_event : special.child_range("event")) {
|
||||
events_.add_child("event", special_event);
|
||||
}
|
||||
|
@ -1082,8 +1080,7 @@ void unit::advance_to(const unit_type& u_type, bool use_traits)
|
|||
events.add_child("event", unit_event);
|
||||
}
|
||||
for(const config& abilities : cfg.child_range("abilities")) {
|
||||
for(const config::any_child child : abilities.all_children_range()) {
|
||||
const config& ability = child.cfg;
|
||||
for(const auto [key, ability] : abilities.all_children_range()) {
|
||||
for(const config& ability_event : ability.child_range("event")) {
|
||||
events.add_child("event", ability_event);
|
||||
}
|
||||
|
@ -1091,8 +1088,7 @@ void unit::advance_to(const unit_type& u_type, bool use_traits)
|
|||
}
|
||||
for(const config& attack : cfg.child_range("attack")) {
|
||||
for(const config& specials : attack.child_range("specials")) {
|
||||
for(const config::any_child child : specials.all_children_range()) {
|
||||
const config& special = child.cfg;
|
||||
for(const auto [key, special] : specials.all_children_range()) {
|
||||
for(const config& special_event : special.child_range("event")) {
|
||||
events.add_child("event", special_event);
|
||||
}
|
||||
|
@ -1465,8 +1461,8 @@ void unit::set_state(const std::string& state, bool value)
|
|||
|
||||
bool unit::has_ability_by_id(const std::string& ability) const
|
||||
{
|
||||
for(const config::any_child ab : abilities_.all_children_range()) {
|
||||
if(ab.cfg["id"] == ability) {
|
||||
for(const auto [key, cfg] : abilities_.all_children_range()) {
|
||||
if(cfg["id"] == ability) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2069,8 +2065,7 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
|
|||
set_attr_changed(UA_ATTACKS);
|
||||
attacks_.emplace_back(new attack_type(effect));
|
||||
for(const config& specials : effect.child_range("specials")) {
|
||||
for(const config::any_child child : specials.all_children_range()) {
|
||||
const config& special = child.cfg;
|
||||
for(const auto [key, special] : specials.all_children_range()) {
|
||||
for(const config& special_event : special.child_range("event")) {
|
||||
events.add_child("event", special_event);
|
||||
}
|
||||
|
@ -2088,8 +2083,7 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
|
|||
for(attack_ptr a : attacks_) {
|
||||
a->apply_modification(effect);
|
||||
for(const config& specials : effect.child_range("set_specials")) {
|
||||
for(const config::any_child child : specials.all_children_range()) {
|
||||
const config& special = child.cfg;
|
||||
for(const auto [key, special] : specials.all_children_range()) {
|
||||
for(const config& special_event : special.child_range("event")) {
|
||||
events.add_child("event", special_event);
|
||||
}
|
||||
|
@ -2251,10 +2245,10 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
|
|||
if(auto ab_effect = effect.optional_child("abilities")) {
|
||||
set_attr_changed(UA_ABILITIES);
|
||||
config to_append;
|
||||
for(const config::any_child ab : ab_effect->all_children_range()) {
|
||||
if(!has_ability_by_id(ab.cfg["id"])) {
|
||||
to_append.add_child(ab.key, ab.cfg);
|
||||
for(const config& event : ab.cfg.child_range("event")) {
|
||||
for(const auto [key, cfg] : ab_effect->all_children_range()) {
|
||||
if(!has_ability_by_id(cfg["id"])) {
|
||||
to_append.add_child(key, cfg);
|
||||
for(const config& event : cfg.child_range("event")) {
|
||||
events.add_child("event", event);
|
||||
}
|
||||
}
|
||||
|
@ -2263,8 +2257,8 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
|
|||
}
|
||||
} else if(apply_to == "remove_ability") {
|
||||
if(auto ab_effect = effect.optional_child("abilities")) {
|
||||
for(const config::any_child ab : ab_effect->all_children_range()) {
|
||||
remove_ability_by_id(ab.cfg["id"]);
|
||||
for(const auto [key, cfg] : ab_effect->all_children_range()) {
|
||||
remove_ability_by_id(cfg["id"]);
|
||||
}
|
||||
}
|
||||
if(auto fab_effect = effect.optional_child("experimental_filter_ability")) {
|
||||
|
@ -2571,8 +2565,8 @@ void unit::apply_modifications()
|
|||
if(modifications_.has_child("advance")) {
|
||||
deprecated_message("[advance]", DEP_LEVEL::PREEMPTIVE, {1, 15, 0}, "Use [advancement] instead.");
|
||||
}
|
||||
for (const config::any_child mod : modifications_.all_children_range()) {
|
||||
add_modification(mod.key, mod.cfg, true);
|
||||
for(const auto [key, cfg] : modifications_.all_children_range()) {
|
||||
add_modification(key, cfg, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -184,10 +184,10 @@ config vconfig::get_parsed_config() const
|
|||
res[key] = expand(key);
|
||||
}
|
||||
|
||||
for (const config::any_child child : cfg_->all_children_range())
|
||||
for(const auto [key, cfg] : cfg_->all_children_range())
|
||||
{
|
||||
if (child.key == "insert_tag") {
|
||||
vconfig insert_cfg(child.cfg, *variables_);
|
||||
if (key == "insert_tag") {
|
||||
vconfig insert_cfg(cfg, *variables_);
|
||||
std::string name = insert_cfg["name"];
|
||||
std::string vname = insert_cfg["variable"];
|
||||
if(!vconfig_recursion.insert(vname).second) {
|
||||
|
@ -217,23 +217,23 @@ config vconfig::get_parsed_config() const
|
|||
}
|
||||
vconfig_recursion.erase(vname);
|
||||
} else {
|
||||
res.add_child(child.key, vconfig(child.cfg, *variables_).get_parsed_config());
|
||||
res.add_child(key, vconfig(cfg, *variables_).get_parsed_config());
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
vconfig::child_list vconfig::get_children(const std::string& key) const
|
||||
vconfig::child_list vconfig::get_children(const std::string& key_to_get) const
|
||||
{
|
||||
vconfig::child_list res;
|
||||
|
||||
for (const config::any_child child : cfg_->all_children_range())
|
||||
for(const auto [key, cfg] : cfg_->all_children_range())
|
||||
{
|
||||
if (child.key == key) {
|
||||
res.push_back(vconfig(child.cfg, cache_, *variables_));
|
||||
} else if (child.key == "insert_tag") {
|
||||
vconfig insert_cfg(child.cfg, *variables_);
|
||||
if(insert_cfg["name"] == key)
|
||||
if (key == key_to_get) {
|
||||
res.push_back(vconfig(cfg, cache_, *variables_));
|
||||
} else if (key == "insert_tag") {
|
||||
vconfig insert_cfg(cfg, *variables_);
|
||||
if(insert_cfg["name"] == key_to_get)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -253,17 +253,17 @@ vconfig::child_list vconfig::get_children(const std::string& key) const
|
|||
return res;
|
||||
}
|
||||
|
||||
std::size_t vconfig::count_children(const std::string& key) const
|
||||
std::size_t vconfig::count_children(const std::string& key_to_count) const
|
||||
{
|
||||
std::size_t n = 0;
|
||||
|
||||
for (const config::any_child child : cfg_->all_children_range())
|
||||
for(const auto [key, cfg] : cfg_->all_children_range())
|
||||
{
|
||||
if (child.key == key) {
|
||||
if (key == key_to_count) {
|
||||
n++;
|
||||
} else if (child.key == "insert_tag") {
|
||||
vconfig insert_cfg(child.cfg, *variables_);
|
||||
if(insert_cfg["name"] == key)
|
||||
} else if (key == "insert_tag") {
|
||||
vconfig insert_cfg(cfg, *variables_);
|
||||
if(insert_cfg["name"] == key_to_count)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -147,8 +147,8 @@ static void handle_preprocess_command(const commandline_options& cmdline_opts)
|
|||
int read = 0;
|
||||
|
||||
// use static preproc_define::read_pair(config) to make a object
|
||||
for(const config::any_child value : cfg.all_children_range()) {
|
||||
const preproc_map::value_type def = preproc_define::read_pair(value.cfg);
|
||||
for(const auto [_, cfg] : cfg.all_children_range()) {
|
||||
const preproc_map::value_type def = preproc_define::read_pair(cfg);
|
||||
input_macros[def.first] = def.second;
|
||||
++read;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue