57 #define WRN_DP LOG_STREAM(warn, log_display) 60 #define WRN_HP LOG_STREAM(warn, log_help) 61 #define DBG_HP LOG_STREAM(debug, log_help) 107 if (ch < 0x2e80)
return false;
111 (ch >= 0x4e00 && ch < 0x9fcf) ||
112 (ch >= 0x3400 && ch < 0x4dbf) ||
113 (ch >= 0x20000 && ch < 0x2a6df) ||
114 (ch >= 0xf900 && ch < 0xfaff) ||
115 (ch >= 0x3190 && ch < 0x319f) ||
118 (ch >= 0x2e80 && ch < 0x2eff) ||
119 (ch >= 0x2f00 && ch < 0x2fdf) ||
120 (ch >= 0x31c0 && ch < 0x31ef) ||
123 (ch >= 0x3104 && ch < 0x312e) ||
124 (ch >= 0x31a0 && ch < 0x31bb) ||
127 (ch >= 0xa490 && ch < 0xa4c7) ||
128 (ch >= 0xa000 && ch < 0xa48d) ||
131 (ch >= 0x3040 && ch <= 0x309f) ||
132 (ch >= 0x30a0 && ch <= 0x30ff) ||
133 (ch >= 0x1b000 && ch <= 0x1b001) ||
136 (ch >= 0x31f0 && ch <= 0x31ff) ||
139 (ch >= 0xac00 && ch < 0xd7af) ||
140 (ch >= 0x1100 && ch <= 0x11ff) ||
141 (ch >= 0xa960 && ch <= 0xa97c) ||
142 (ch >= 0xd7b0 && ch <= 0xd7fb) ||
145 (ch >= 0x3000 && ch < 0x303f) ||
148 (ch >= 0xff00 && ch < 0xffef);
153 if (
const config &toplevel = cfg.
child(
"toplevel"))
155 const std::vector<std::string> toplevel_refs
157 if (std::find(toplevel_refs.begin(), toplevel_refs.end(), section_id)
158 != toplevel_refs.end()) {
165 const std::vector<std::string> sections_refd
167 if (std::find(sections_refd.begin(), sections_refd.end(), section_id)
168 != sections_refd.end()) {
177 if (
const config &toplevel = cfg.
child(
"toplevel"))
179 const std::vector<std::string> toplevel_refs
181 if (std::find(toplevel_refs.begin(), toplevel_refs.end(), topic_id)
182 != toplevel_refs.end()) {
189 const std::vector<std::string> topics_refd
191 if (std::find(topics_refd.begin(), topics_refd.end(), topic_id)
192 != topics_refd.end()) {
202 if (level > max_section_level) {
203 PLAIN_LOG <<
"Maximum section depth has been reached. Maybe circular dependency?";
205 else if (section_cfg !=
nullptr) {
207 std::string
id = level == 0 ?
"toplevel" : (*section_cfg)[
"id"].str();
210 std::stringstream ss;
211 ss <<
"Invalid ID, used for internal purpose: '" <<
id <<
"'";
215 std::string title = level == 0 ?
"" : (*section_cfg)[
"title"].str();
218 std::vector<std::string>::const_iterator it;
220 for (it = sections.begin(); it != sections.end(); ++it) {
228 std::stringstream ss;
229 ss <<
"Help-section '" << *it <<
"' referenced from '" 230 <<
id <<
"' but could not be found.";
236 if ((*section_cfg)[
"sort_sections"] ==
"yes") {
240 bool sort_topics =
false;
241 bool sort_generated =
true;
243 if ((*section_cfg)[
"sort_topics"] ==
"yes") {
245 sort_generated =
false;
246 }
else if ((*section_cfg)[
"sort_topics"] ==
"no") {
248 sort_generated =
false;
249 }
else if ((*section_cfg)[
"sort_topics"] ==
"generated") {
251 sort_generated =
true;
252 }
else if (!(*section_cfg)[
"sort_topics"].empty()) {
253 std::stringstream ss;
254 ss <<
"Invalid sort option: '" << (*section_cfg)[
"sort_topics"] <<
"'";
258 std::vector<topic> generated_topics =
262 std::vector<topic> topics;
265 for (it = topics_id.begin(); it != topics_id.end(); ++it) {
268 std::string text = topic_cfg[
"text"];
270 topic child_topic(topic_cfg[
"title"], topic_cfg[
"id"], text);
272 std::stringstream ss;
273 ss <<
"Invalid ID, used for internal purpose: '" <<
id <<
"'";
276 topics.push_back(child_topic);
279 std::stringstream ss;
280 ss <<
"Help-topic '" << *it <<
"' referenced from '" <<
id 281 <<
"' but could not be found." << std::endl;
287 std::sort(topics.begin(),topics.end(),
title_less());
288 std::sort(generated_topics.begin(),
290 std::merge(generated_topics.begin(),
291 generated_topics.end(),topics.begin(),topics.end()
296 topics.begin(), topics.end());
298 generated_topics.begin(), generated_topics.end());
306 if (cfg !=
nullptr) {
307 const config& toplevel_cfg = cfg->
child(
"toplevel");
315 std::vector<topic> res;
316 if (generator.empty()) {
320 if (generator ==
"abilities") {
322 }
else if (generator ==
"weapon_specials") {
324 }
else if (generator ==
"time_of_days") {
326 }
else if (generator ==
"traits") {
330 if (parts.size() > 1 && parts[0] ==
"units") {
332 }
else if (parts[0] ==
"era" && parts.size()>1) {
335 WRN_HP <<
"Found a topic generator that I didn't recognize: " <<
generator;
344 if (generator ==
"races") {
346 }
else if (generator ==
"terrains") {
348 }
else if (generator ==
"eras") {
349 DBG_HP <<
"Generating eras...";
353 if (parts.size() > 1 && parts[0] ==
"units") {
355 }
else if (generator.size() > 0) {
356 WRN_HP <<
"Found a section generator that I didn't recognize: " <<
generator;
363 std::string empty_string =
"";
364 if (generator.empty()) {
367 std::vector<std::string> parts =
utils::split(generator,
':');
368 if (parts.size() > 1 && parts[0] ==
"contents") {
369 if (parts[1] ==
"generated") {
397 return std::string(
"<format>color='") + (time_of_day_bonus > 0 ?
"green" : (time_of_day_bonus < 0 ?
"red" :
"white")) +
"' text='" + std::to_string(time_of_day_bonus) +
"'</format>";
402 std::vector<topic> topics;
403 std::stringstream toplevel;
406 toplevel <<
_(
"Only available during a scenario.");
407 topics.emplace_back(
_(
"Time of Day Schedule"),
"..schedule", toplevel.str());
414 const std::string
id =
"time_of_day_" + time.id;
415 const std::string
image =
"<img>src='" + time.image +
"'</img>";
416 const std::string image_lawful =
"<img>src='icons/alignments/alignment_lawful_30.png'</img>";
417 const std::string image_neutral =
"<img>src='icons/alignments/alignment_neutral_30.png'</img>";
418 const std::string image_chaotic =
"<img>src='icons/alignments/alignment_chaotic_30.png'</img>";
419 const std::string image_liminal =
"<img>src='icons/alignments/alignment_liminal_30.png'</img>";
420 std::stringstream text;
433 text << image <<
'\n' << time.description.str() <<
'\n' <<
438 '\n' <<
make_link(
_(
"Schedule"),
"..schedule");
440 topics.emplace_back(time.name.str(),
id, text.str());
443 topics.emplace_back(
_(
"Time of Day Schedule"),
"..schedule", toplevel.str());
449 std::vector<topic> topics;
451 std::map<t_string, std::string> special_description;
452 std::map<t_string, std::set<std::string, string_less>> special_units;
454 for (
const unit_type_data::unit_type_map::value_type &type_mapping :
unit_types.
types())
464 std::vector<std::pair<t_string, t_string>> specials = atk.special_tooltips();
465 for ( std::size_t
i = 0;
i != specials.size(); ++
i )
467 special_description.emplace(specials[
i].first, specials[
i].second);
471 std::string type_name = type.
type_name();
474 std::string ref_id = section_prefix + unit_prefix + type.
id();
477 std::string link =
make_link(type_name, ref_id);
478 special_units[specials[
i].first].insert(link);
485 if(effect[
"apply_to"] ==
"new_attack" && effect.has_child(
"specials")) {
487 if(!spec.cfg[
"name"].empty()) {
488 special_description.emplace(spec.cfg[
"name"].t_str(), spec.cfg[
"description"].t_str());
491 std::string type_name = type.
type_name();
494 std::string ref_id = section_prefix + unit_prefix + type.
id();
497 std::string link =
make_link(type_name, ref_id);
498 special_units[spec.cfg[
"name"]].insert(link);
502 }
else if(effect[
"apply_to"] ==
"attack" && effect.has_child(
"set_specials")) {
503 for(
config::any_child spec : effect.child(
"set_specials").all_children_range()) {
504 if(!spec.cfg[
"name"].empty()) {
505 special_description.emplace(spec.cfg[
"name"].t_str(), spec.cfg[
"description"].t_str());
508 std::string type_name = type.
type_name();
511 std::string ref_id = section_prefix + unit_prefix + type.
id();
514 std::string link =
make_link(type_name, ref_id);
515 special_units[spec.cfg[
"name"]].insert(link);
525 s != special_description.end(); ++
s) {
527 std::string
id =
"weaponspecial_" +
s->first.base_str();
528 std::stringstream text;
530 text <<
"\n\n" <<
_(
"<header>text='Units with this special attack'</header>") <<
"\n";
531 std::set<std::string, string_less> &units = special_units[
s->first];
536 topics.emplace_back(
s->first,
id, text.str());
540 std::sort(topics.begin(), topics.end(),
title_less());
546 std::vector<topic> topics;
548 std::map<std::string, const unit_type::ability_metadata*> ability_topic_data;
549 std::map<std::string, std::set<std::string, string_less>> ability_units;
556 const std::string topic_ref = ability.id + ability.name.base_str();
558 ability_topic_data.emplace(topic_ref, &ability);
565 ability_units[topic_ref].insert(link);
573 const unit_type& type = type_mapping.second;
580 parse(type, ability);
584 parse(type, ability);
588 for(
const auto&
a : ability_topic_data) {
589 if (
a.second->name.empty()) {
592 std::ostringstream text;
593 text <<
a.second->description;
594 text <<
"\n\n" <<
_(
"<header>text='Units with this ability'</header>") <<
"\n";
596 for(
const auto& u : ability_units[
a.first]) {
600 topics.emplace_back(
a.second->name, ability_prefix +
a.first, text.str());
604 std::sort(topics.begin(), topics.end(),
title_less());
612 std::vector<topic> topics;
615 if(era && !era[
"hide_help"].to_bool()) {
618 std::vector<std::string> faction_links;
619 for (
const topic &
t : topics) {
623 std::stringstream text;
624 text <<
"<header>text='" <<
_(
"Era:") <<
" " << era[
"name"] <<
"'</header>" <<
"\n";
627 if (!description.
empty()) {
628 text << description.
t_str() <<
"\n";
632 text <<
"<header>text='" <<
_(
"Factions") <<
"'</header>" <<
"\n";
634 std::sort(faction_links.begin(), faction_links.end());
635 for (
const std::string &link : faction_links) {
639 topic era_topic(era[
"name"],
".." + era_prefix + era[
"id"].str(), text.str());
641 topics.push_back( era_topic );
648 std::vector<topic> topics;
650 const std::string&
id =
f[
"id"];
654 std::stringstream text;
657 if (!description.
empty()) {
658 text << description.
t_str() <<
"\n";
662 const std::vector<std::string> recruit_ids =
utils::split(
f[
"recruit"]);
663 std::set<std::string> races;
664 std::set<std::string> alignments;
666 for (
const std::string & u_id : recruit_ids) {
672 races.insert(
make_link(r->plural_name(), std::string(
"..") + race_prefix + r->id()));
678 if (!races.empty()) {
680 text <<
_(
"Races: ") << *(it++);
681 while(it != races.end()) {
682 text <<
", " << *(it++);
687 if (!alignments.empty()) {
689 text <<
_(
"Alignments: ") << *(it++);
690 while(it != alignments.end()) {
691 text <<
", " << *(it++);
696 text <<
"<header>text='" <<
_(
"Leaders") <<
"'</header>" <<
"\n";
697 const std::vector<std::string> leaders =
699 for (
const std::string &link : leaders) {
705 text <<
"<header>text='" <<
_(
"Recruits") <<
"'</header>" <<
"\n";
706 const std::vector<std::string> recruit_links =
708 for (
const std::string &link : recruit_links) {
712 const std::string name =
f[
"name"];
713 const std::string ref_id = faction_prefix + era[
"id"] +
"_" +
id;
714 topics.emplace_back(name, ref_id, text.str());
717 std::sort(topics.begin(), topics.end(),
title_less());
723 std::vector<topic> topics;
724 std::map<t_string, const config> trait_list;
727 const std::string trait_id = trait[
"id"];
728 trait_list.emplace(trait_id, trait);
732 for (
const unit_type_data::unit_type_map::value_type &
i :
unit_types.
types())
738 for (
const config & trait : traits) {
739 const std::string trait_id = trait[
"id"];
740 trait_list.emplace(trait_id, trait);
744 for (
const config & trait : r->additional_traits()) {
745 const std::string trait_id = trait[
"id"];
746 trait_list.emplace(trait_id, trait);
753 std::string
id =
"traits_" +
a->first;
754 const config trait =
a->second;
756 std::string name = trait[
"male_name"].str();
757 if (name.empty()) name = trait[
"female_name"].str();
758 if (name.empty()) name = trait[
"name"].str();
759 if (name.empty())
continue;
761 std::stringstream text;
762 if (!trait[
"help_text"].empty()) {
763 text << trait[
"help_text"];
764 }
else if (!trait[
"description"].empty()) {
765 text << trait[
"description"];
767 text <<
_(
"No description available.");
770 if (trait[
"availability"] ==
"musthave") {
771 text <<
_(
"Availability: ") <<
_(
"Must-have") <<
"\n";
772 }
else if (trait[
"availability"] ==
"none") {
773 text <<
_(
"Availability: ") <<
_(
"Unavailable") <<
"\n";
775 topics.emplace_back(name,
id, text.str());
779 std::sort(topics.begin(), topics.end(),
title_less());
790 PLAIN_LOG <<
"Unknown unit type : " << type_id;
799 ref_id = section_prefix + unit_prefix + type->
id();
812 std::vector<std::string> links_list;
813 for (
const std::string &type_id : type_id_list) {
815 if (!unit_link.empty())
816 links_list.push_back(unit_link);
820 std::sort(links_list.begin(), links_list.end());
827 std::set<std::string, string_less> races;
828 std::set<std::string, string_less> visible_races;
831 for(
const unit_type_data::unit_type_map::value_type&
i :
unit_types.
types()) {
837 visible_races.insert(type.
race_id());
842 std::set<std::string, string_less> last_sweep = visible_races;
843 while(!last_sweep.empty()) {
844 std::set<std::string, string_less> current_sweep;
845 for(
const auto& race_id : last_sweep) {
847 const auto& help_taxonomy = r->help_taxonomy();
848 if(!help_taxonomy.empty() && !visible_races.count(help_taxonomy) &&
unit_types.
find_race(help_taxonomy)) {
849 current_sweep.insert(help_taxonomy);
850 races.insert(help_taxonomy);
851 visible_races.insert(help_taxonomy);
855 last_sweep = std::move(current_sweep);
858 struct taxonomy_queue_type
860 std::string parent_id;
863 std::vector<taxonomy_queue_type> taxonomy_queue;
867 for(
const auto& race_id : races) {
871 bool hidden = (visible_races.count(race_id) == 0);
873 section_cfg[
"id"] =
hidden_symbol(hidden) + race_prefix + race_id;
876 std::string help_taxonomy;
878 title = r->plural_name();
879 help_taxonomy = r->help_taxonomy();
881 title =
_(
"race^Miscellaneous");
884 section_cfg[
"title"] = title;
886 section_cfg[
"sections_generator"] =
"units:" + race_id;
887 section_cfg[
"generator"] =
"units:" + race_id;
891 if(help_taxonomy.empty()) {
894 bool parent_hidden = (visible_races.count(help_taxonomy) == 0);
895 auto parent_id =
hidden_symbol(parent_hidden) + race_prefix + help_taxonomy;
896 taxonomy_queue.push_back({std::move(parent_id), std::move(race_section)});
901 bool process_queue_again =
true;
902 while(process_queue_again && !taxonomy_queue.empty()) {
903 process_queue_again =
false;
904 std::vector<taxonomy_queue_type> to_process = std::move(taxonomy_queue);
906 for(
auto& x : to_process) {
909 parent->add_section(std::move(x.content));
910 process_queue_again =
true;
912 taxonomy_queue.push_back(std::move(x));
918 for(
auto& x : taxonomy_queue) {
926 if (
era[
"hide_help"].to_bool()) {
930 DBG_HP <<
"Adding help section: " <<
era[
"id"].str();
934 section_cfg[
"id"] = era_prefix +
era[
"id"].str();
935 section_cfg[
"title"] =
era[
"name"];
937 section_cfg[
"generator"] =
"era:" +
era[
"id"].str();
951 WRN_HP <<
"When building terrain help sections, couldn't acquire terrain types data, aborting.";
955 std::map<std::string, section> base_map;
972 terrain_topic.
text = std::make_shared<terrain_topic_generator>(
info);
977 const terrain_type& base_info = tdata->get_terrain_info(base);
982 section& base_section = base_map[base_info.
id()];
984 base_section.
id = terrain_prefix + base_info.
id();
987 if (base_info.
id() == info.
id())
988 terrain_topic.
id =
".." + terrain_prefix + info.
id();
989 base_section.
topics.push_back(terrain_topic);
993 for (
const auto& base : base_map) {
1000 for (
const unit_type_data::unit_type_map::value_type &
i :
unit_types.
types()) {
1010 for (
const std::string &variation_id : type.
variations()) {
1014 const std::string var_ref =
hidden_symbol(var_type.
hide_help()) + variation_prefix + var_type.
id() +
"_" + variation_id;
1016 topic var_topic(topic_name, var_ref,
"");
1017 var_topic.
text = std::make_shared<unit_topic_generator>(var_type, variation_id);
1018 base_unit.
topics.push_back(var_topic);
1021 const std::string type_name = type.
type_name();
1024 base_unit.
id = ref_id;
1025 base_unit.
title = type_name;
1033 std::vector<topic> topics;
1034 std::set<std::string, string_less> race_units;
1035 std::set<std::string, string_less> race_topics;
1036 std::set<std::string> alignments;
1038 for (
const unit_type_data::unit_type_map::value_type &
i :
unit_types.
types())
1053 topic unit_topic(type_name, ref_id,
"");
1054 unit_topic.
text = std::make_shared<unit_topic_generator>(
type);
1055 topics.push_back(unit_topic);
1060 std::string link =
make_link(type_name, ref_id);
1061 race_units.insert(link);
1068 std::string race_id =
"..race_"+race;
1069 std::string race_name;
1070 std::string race_description;
1071 std::string race_help_taxonomy;
1073 race_name = r->plural_name();
1074 race_description = r->description();
1075 race_help_taxonomy = r->help_taxonomy();
1077 for (
const config &additional_topic : r->additional_topics())
1079 std::string
id = additional_topic[
"id"];
1080 std::string title = additional_topic[
"title"];
1081 std::string text = additional_topic[
"text"];
1083 topics.emplace_back(title,
id,text);
1084 std::string link =
make_link(title,
id);
1085 race_topics.insert(link);
1088 race_name =
_ (
"race^Miscellaneous");
1093 std::map<std::string, t_string> subgroups;
1095 if (r.second.help_taxonomy() == race) {
1096 if (!r.second.plural_name().empty())
1097 subgroups[r.first] = r.second.plural_name();
1099 subgroups[r.first] = r.first;
1103 std::stringstream text;
1105 if (!race_description.empty()) {
1106 text << race_description <<
"\n\n";
1109 if (!alignments.empty()) {
1111 text << (alignments.size() > 1 ?
_(
"Alignments: ") :
_(
"Alignment: ")) << *(it++);
1112 while(it != alignments.end()) {
1113 text <<
", " << *(it++);
1118 if (!race_help_taxonomy.empty()) {
1120 symbols[
"topic_id"] =
"..race_"+race_help_taxonomy;
1122 symbols[
"help_taxonomy"] = r->plural_name();
1126 symbols[
"help_taxonomy"] = race_help_taxonomy;
1130 text <<
VGETTEXT(
"This is a group of units, all of whom are <ref>dst='$topic_id' text='$help_taxonomy'</ref>.", symbols) <<
"\n\n";
1133 if (!subgroups.empty()) {
1134 if (!race_help_taxonomy.empty()) {
1135 text <<
_(
"<header>text='Subgroups of units within this group'</header>") <<
"\n";
1137 text <<
_(
"<header>text='Groups of units within this race'</header>") <<
"\n";
1139 for (
const auto &sg : subgroups) {
1145 if (!race_help_taxonomy.empty()) {
1146 text <<
_(
"<header>text='Units of this group'</header>") <<
"\n";
1148 text <<
_(
"<header>text='Units of this race'</header>") <<
"\n";
1150 for (
const auto &u : race_units) {
1154 topics.emplace_back(race_name, race_id, text.str());
1157 std::sort(topics.begin(), topics.end(),
title_less());
1170 if (encountered_units.find(type.
id()) != encountered_units.end()) {
1175 if (type.
id() ==
"Fog Clearer") {
1184 const config& section_cfg = help_cfg->
find_child(
"section",
"id", section_name);
1186 return std::string();
1189 std::ostringstream res;
1194 typedef std::pair<std::string,std::string> link;
1195 std::vector<link> topics_links;
1199 for (t = topics.begin(); t != topics.end(); ++
t) {
1201 std::string
id = topic_cfg[
"id"];
1203 topics_links.emplace_back(topic_cfg[
"title"],
id);
1207 if (section_cfg[
"sort_topics"] ==
"yes") {
1208 std::sort(topics_links.begin(),topics_links.end());
1212 for (l = topics_links.begin(); l != topics_links.end(); ++l) {
1213 std::string link =
make_link(l->first, l->second);
1222 std::stringstream res;
1231 for (
auto &
t : topics) {
1252 return sec.
id ==
id;
1262 sections.emplace_back(s);
1273 topic_list::const_iterator tit =
1275 if (tit != sec.
topics.end()) {
1294 for (
const auto &subsection : sec.
sections) {
1310 std::vector<std::string> res;
1311 bool last_char_escape =
false;
1312 const char escape_char =
'\\';
1313 std::stringstream ss;
1316 for (pos = 0; pos < text.size(); ++pos) {
1317 const char c = text[pos];
1318 if (c == escape_char && !last_char_escape) {
1319 last_char_escape =
true;
1322 if (state ==
OTHER) {
1324 if (last_char_escape) {
1328 res.push_back(ss.str());
1330 state = ELEMENT_NAME;
1337 else if (state == ELEMENT_NAME) {
1339 std::string
msg =
"Erroneous / in element name.";
1342 else if (c ==
'>') {
1344 std::stringstream
s;
1345 const std::string element_name = ss.str();
1347 s <<
"</" << element_name <<
">";
1348 const std::string end_element_name = s.str();
1349 std::size_t end_pos = text.find(end_element_name, pos);
1350 if (end_pos == std::string::npos) {
1351 std::stringstream
msg;
1352 msg <<
"Unterminated element: " << element_name;
1356 const std::string contents = text.substr(pos + 1, end_pos - pos - 1);
1357 const std::string element =
convert_to_wml(element_name, contents);
1358 res.push_back(element);
1359 pos = end_pos + end_element_name.size() - 1;
1366 last_char_escape =
false;
1369 if (state == ELEMENT_NAME) {
1370 std::stringstream
msg;
1371 msg <<
"Element '" << ss.str() <<
"' continues through end of string.";
1374 if (!ss.str().empty()) {
1376 res.push_back(ss.str());
1381 std::string
convert_to_wml(
const std::string &element_name,
const std::string &contents)
1383 std::stringstream ss;
1384 bool in_quotes =
false;
1385 bool last_char_escape =
false;
1386 const char escape_char =
'\\';
1387 std::vector<std::string> attributes;
1392 for (std::size_t pos = 0; pos < contents.size(); ++pos) {
1393 const char c = contents[pos];
1394 if (c == escape_char && !last_char_escape) {
1395 last_char_escape =
true;
1398 if (c ==
'\'' && !last_char_escape) {
1400 in_quotes = !in_quotes;
1402 else if ((c ==
' ' || c ==
'\n') && !last_char_escape && !in_quotes) {
1404 attributes.push_back(ss.str());
1410 last_char_escape =
false;
1414 std::stringstream
msg;
1415 msg <<
"Unterminated single quote after: '" << ss.str() <<
"'";
1418 if (!ss.str().empty()) {
1419 attributes.push_back(ss.str());
1423 ss <<
"[" << element_name <<
"]\n";
1424 for (std::vector<std::string>::const_iterator it = attributes.begin();
1425 it != attributes.end(); ++it) {
1428 ss <<
"[/" << element_name <<
"]\n";
1434 if (cmp_str ==
"green") {
1437 if (cmp_str ==
"red") {
1440 if (cmp_str ==
"black") {
1443 if (cmp_str ==
"yellow") {
1446 if (cmp_str ==
"white") {
1450 if (*cmp_str.c_str() ==
'#' && cmp_str.size() == 7) {
1457 const unsigned width)
1459 std::vector<std::string> res;
1462 res.push_back(first_line);
1463 if(s.size() > first_line.size()) {
1464 res.push_back(s.substr(first_line.size()));
1477 if (text.length() > 0 && text[0] ==
' ') {
1478 return text.substr(1);
1485 std::size_t first_word_start = s.find_first_not_of(
' ');
1486 if (first_word_start == std::string::npos) {
1489 std::size_t first_word_end = s.find_first_of(
" \n", first_word_start);
1490 if( first_word_end == first_word_start ) {
1492 first_word_end = first_word_start+1;
1496 std::string re = s.substr(0, first_word_end);
1502 char32_t firstchar = *ch;
1511 default_toplevel.
clear();
1512 hidden_sections.
clear();
1513 if (game_cfg !=
nullptr) {
1524 std::stringstream ss;
1527 const std::string
id =
section[
"id"];
1533 if (!ss.str().empty()) {
1540 hidden_toplevel[
"sections"] = ss.str();
1544 const std::string
id =
topic[
"id"];
1545 if (
find_topic(default_toplevel,
id) ==
nullptr) {
1547 if (!ss.str().empty()) {
1554 hidden_toplevel[
"topics"] = ss.str();
1555 config hidden_cfg = *help_config;
1558 hidden_cfg.
add_child(
"toplevel", std::move(hidden_toplevel));
1562 std::stringstream
msg;
1563 msg <<
"Parse error when parsing help text: '" << e.
message <<
"'";
1571 return (hidden ?
"." :
"");
1575 return (
id.empty() ||
id[0] !=
'.');
1584 if (
id ==
"toplevel") {
1590 if (
id.
compare(0, 8,
"ability_") == 0) {
1593 if (
id.
compare(0, 14,
"weaponspecial_") == 0) {
1596 if (
id ==
"hidden") {
1608 if (surf !=
nullptr) {
1614 void push_tab_pair(std::vector<help::item> &v,
const std::string &
s,
const std::optional<std::string> &
image,
unsigned padding)
1620 padding = (width ? padding : 0);
1622 item.first =
"<img>src='" + *image +
"'</img>" + (padding ?
jump(padding) :
"") + s;
1623 item.second += width + padding;
1625 v.emplace_back(item);
1630 table_spec::const_iterator row_it;
1631 std::vector<std::pair<std::string, unsigned>>::const_iterator col_it;
1632 unsigned int num_cols = 0;
1633 for (row_it = tab.begin(); row_it != tab.end(); ++row_it) {
1634 if (row_it->size() > num_cols) {
1635 num_cols = row_it->size();
1638 std::vector<unsigned int> col_widths(num_cols, 0);
1640 for (row_it = tab.begin(); row_it != tab.end(); ++row_it) {
1641 unsigned int col = 0;
1642 for (col_it = row_it->begin(); col_it != row_it->end(); ++col_it) {
1643 if (col_widths[col] < col_it->second + spacing) {
1644 col_widths[col] = col_it->second + spacing;
1649 std::vector<unsigned int> col_starts(num_cols);
1651 for (
unsigned int i = 0;
i < num_cols; ++
i) {
1652 unsigned int this_col_start = 0;
1653 for (
unsigned int j = 0; j <
i; ++j) {
1654 this_col_start += col_widths[j];
1656 col_starts[
i] = this_col_start;
1658 std::stringstream ss;
1659 for (row_it = tab.begin(); row_it != tab.end(); ++row_it) {
1660 unsigned int col = 0;
1661 for (col_it = row_it->begin(); col_it != row_it->end(); ++col_it) {
1662 ss <<
jump_to(col_starts[col]) << col_it->first;
std::string jump_to(const unsigned pos)
surface get_image(const image::locator &i_locator, TYPE type)
[DEPRECATED] Caches and returns an image.
bool empty() const
Tests for an attribute that either was never set or was set to "".
const std::string ability_prefix
section parse_config(const config *cfg)
Parse a help config, return the top level section.
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
::tod_manager * tod_manager
Ignore this unit for documentation purposes.
std::string make_unit_link(const std::string &type_id)
return a hyperlink with the unit's name and pointing to the unit page return empty string if this uni...
const std::string open_section_img
int get_max_liminal_bonus() const
static display * get_singleton()
Returns the display object if a display object exists.
std::vector< topic > generate_trait_topics(const bool sort_generated)
const std::string unit_prefix
void push_tab_pair(std::vector< help::item > &v, const std::string &s, const std::optional< std::string > &image, unsigned padding)
std::vector< topic > generate_unit_topics(const bool sort_generated, const std::string &race)
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
std::map< std::string, t_string > string_map
const std::string era_prefix
const std::string topic_img
void clear_children(T... keys)
config_array_view traits() const
const std::string closed_section_img
std::string remove_first_space(const std::string &text)
bool is_scope_active(scope s)
A section contains topics and sections along with title and ID.
Various functions that implement attacks and attack calculations.
config & find_child(config_key_type key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
const std::string unknown_unit_topic
Variant for storing WML attributes.
const std::string race_prefix
std::string generate_topic_text(const std::string &generator, const config *help_cfg, const section &sec, const std::vector< topic > &generated_topics)
config_array_view child_range(config_key_type key) const
int compare(const std::string &s1, const std::string &s2)
Case-sensitive lexicographical comparison.
boost::tribool last_debug_state
ucs4_convert_impl::enableif< TD, typename TS::value_type >::type unicode_cast(const TS &source)
int generic_combat_modifier(int lawful_bonus, unit_alignments::type alignment, bool is_fearless, int max_liminal_bonus)
Returns the amount that a unit's damage should be multiplied by due to a given lawful_bonus.
child_itors child_range(config_key_type key)
Thrown when the help system fails to parse something.
bool operator<(const section &) const
Comparison on the ID.
std::vector< std::string > empty_string_vector
Although the unit itself is hidden, traits reachable via this unit are not hidden.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
unit_type_data unit_types
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
const race_map & races() const
const int normal_font_size
unsigned image_width(const std::string &filename)
static std::string _(const char *str)
const std::string terrain_prefix
int last_num_encountered_terrains
color_t string_to_color(const std::string &cmp_str)
Return the color the string represents.
const unit_type_map & types() const
bool is_visible_id(const std::string &id)
virtual const gamemap & map() const =0
bool hide_help() const
For instances created from a [terrain_type] tag, the value in the tag (with default false)...
std::vector< topic > generate_weapon_special_topics(const bool sort_generated)
std::vector< std::string > make_unit_links_list(const std::vector< std::string > &type_id_list, bool ordered)
return a list of hyperlinks to unit's pages (ordered or not)
A single unit type that the player may recruit.
bool is_nonnull() const
True if this object represents some sentinel values.
void generate_sections(const config *help_cfg, const std::string &generator, section &sec, int level)
Dispatch generators to their appropriate functions.
help::section hidden_sections
const std::shared_ptr< terrain_type_data > & terrain_types() const
const section * find_section(const section &sec, const std::string &id)
Search for the section with the specified identifier in the section and its subsections.
Object which defines a time of day with associated bonuses, image, sounds etc.
To be used as a function object to locate sections and topics with a specified ID.
static game_config_manager * get()
const t_string & editor_name() const
const color_t BIGMAP_COLOR
The text displayed in a topic.
std::string generate_table(const table_spec &tab, const unsigned int spacing)
const std::vector< unit_race::GENDER > & genders() const
The returned vector will not be empty, provided this has been built to the HELP_INDEXED status...
std::vector< std::vector< help::item > > table_spec
std::string hidden_symbol(bool hidden)
unit_alignments::type alignment() const
std::shared_ptr< terrain_type_data > load_terrain_types_data()
Load the appropriate terrain types data to use.
const t_string & type_name() const
The name of the unit in the current language setting.
static color_t from_hex_string(const std::string &c)
Creates a new color_t object from a string variable in hex format.
std::vector< topic > generate_era_topics(const bool sort_generated, const std::string &era_id)
std::vector< topic > generate_faction_topics(const config &era, const bool sort_generated)
The basic class for representing 8-bit RGB or RGBA colour values.
REMOVE_EMPTY: remove empty elements.
std::set< t_translation::terrain_code > & encountered_terrains()
const std::vector< ability_metadata > & abilities_metadata() const
std::string race_id() const
Returns the ID of this type's race without the need to build the type.
std::string pango_word_wrap(const std::string &unwrapped_text, int font_size, int max_width, int max_height, int max_lines, bool)
Uses Pango to word wrap text.
const std::string & id() const
The id for this unit_type.
static std::string time_of_day_bonus_colored(const int time_of_day_bonus)
map_display and display: classes which take care of displaying the map and game-data on the screen...
std::vector< std::string > parsed_text_
const std::shared_ptr< terrain_type_data > & tdata() const
static lg::log_domain log_help("help")
static bool is_cjk_char(const char32_t ch)
const color_t YELLOW_COLOR
bool show_all_units_in_help()
const config & child_or_empty(config_key_type key) const
const color_t NORMAL_COLOR
std::shared_ptr< topic_generator > generator_
Generic locator abstracting the location of an image.
void parse_config_internal(const config *help_cfg, const config *section_cfg, section &sec, int level)
Recursive function used by parse_config.
std::string escape(const std::string &str, const char *special_chars)
Prepends a configurable set of characters with a backslash.
boost::iterator_range< const_child_iterator > const_child_itors
bool section_is_referenced(const std::string §ion_id, const config &cfg)
Return true if the section with id section_id is referenced from another section in the config...
bool topic_is_referenced(const std::string &topic_id, const config &cfg)
Return true if the topic with id topic_id is referenced from another section in the config...
void generate_unit_sections(const config *, section &sec, int, const bool, const std::string &race)
To be used as a function object when sorting section lists on the title.
std::string id
Text to match against addon_info.tags()
config::const_child_itors modification_advancements() const
Returns two iterators pointing to a range of AMLA configs.
const unit_race * find_race(const std::string &) const
const color_t BLACK_COLOR
const std::string variation_prefix
std::vector< std::string > variations() const
Thrown by operations encountering invalid UTF-8 data.
void generate_terrain_sections(section &sec, int)
int last_num_encountered_units
std::string make_link(const std::string &text, const std::string &dst)
std::string convert_to_wml(const std::string &element_name, const std::string &contents)
Convert the contents to wml attributes, surrounded within [element_name]...[/element_name].
static map_location::DIRECTION s
bool show_variations_in_help() const
Whether the unit type has at least one help-visible variation.
const std::vector< time_of_day > & times(const map_location &loc=map_location::null_location()) const
std::vector< std::string > quoted_split(const std::string &val, char c, int flags, char quote)
This function is identical to split(), except it does not split when it otherwise would if the previo...
const display_context & get_disp_context() const
const game_config_view * game_cfg
std::set< std::string > & encountered_units()
bool operator<(const topic &) const
Comparison on the ID.
void generate_races_sections(const config *help_cfg, section &sec, int level)
const std::string unicode_bullet
static iterator_base end(const string_type &str)
const std::vector< ability_metadata > & adv_abilities_metadata() const
Some extra abilities that may be gained through AMLA advancements.
rng * generator
This generator is automatically synced during synced context.
std::string escape(const std::string &s)
Prepend all chars with meaning inside attributes with a backslash.
std::vector< std::string > parse_text(const std::string &text)
Parse a text string.
config & add_child(config_key_type key)
const config & find_child(config_key_type key, const std::string &name, const std::string &value) const
const unsigned max_history
static std::string alignment_description(unit_alignments::type align, unit_race::GENDER gender=unit_race::MALE)
Implementation detail of unit_type::alignment_description.
std::vector< topic > generate_time_of_day_topics(const bool)
config::const_child_itors possible_traits() const
static lg::log_domain log_display("display")
std::string generate_contents_links(const std::string §ion_name, config const *help_cfg)
const std::string faction_prefix
std::string jump(const unsigned amount)
const std::string default_show_topic
const unit_type & get_variation(const std::string &id) const
void generate_contents()
Generate the help contents from the configurations given to the manager.
std::vector< std::string > split(const config_attribute_value &val)
std::vector< topic > generate_topics(const bool sort_generated, const std::string &generator)
bool operator==(const topic &) const
Two topics are equal if their IDs are equal.
const topic * find_topic(const section &sec, const std::string &id)
Search for the topic with the specified identifier in the section and its subsections.
const t_string & variation_name() const
const std::vector< std::string > & parsed_text() const
Functions to load and save images from/to disk.
Standard logging facilities (interface).
const std::string & id() const
std::vector< terrain_code > ter_list
A topic contains a title, an id and some text.
const_attack_itors attacks() const
bool is_valid_id(const std::string &id)
Return true if the id is valid for user defined topics and sections.
A config object defines a single node in a WML file, with access to child nodes.
const std::string & str() const
std::string get_first_word(const std::string &s)
Return the first word in s, not removing any spaces in the start of it.
void add_section(const section &s)
Allocate memory for and add the section.
UNIT_DESCRIPTION_TYPE description_type(const unit_type &type)
Return the type of description that should be shown for a unit of the given kind. ...
std::vector< topic > generate_ability_topics(const bool sort_generated)
void generate_era_sections(const config *help_cfg, section &sec, int level)
Transitional API for porting SDL_ttf-based code to Pango.
std::string::const_iterator iterator
const int max_section_level
topic_text & operator=(topic_text &&t)=default
To be used as a function object when sorting topic lists on the title.
std::vector< std::string > split_in_width(const std::string &s, const int font_size, const unsigned width)
Make a best effort to word wrap s.
std::string debug() const
std::pair< std::string, unsigned > item
bool operator==(const section &) const
Two sections are equal if their IDs are equal.
help::section default_toplevel
int pango_line_width(const std::string &line, int font_size, font::pango_text::FONT_STYLE font_style=font::pango_text::STYLE_NORMAL)
Determine the width of a line of text given a certain font size.