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);
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()) {
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()) {
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) {
221 if (
auto child_cfg = help_cfg->
find_child(
"section",
"id", *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) {
266 if (
auto topic_cfg = help_cfg->
find_child(
"topic",
"id", *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) {
315 std::vector<topic> res;
322 }
else if (
generator ==
"weapon_specials") {
324 }
else if (
generator ==
"time_of_days") {
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;
349 DBG_HP <<
"Generating eras...";
353 if (parts.size() > 1 && parts[0] ==
"units") {
356 WRN_HP <<
"Found a section generator that I didn't recognize: " <<
generator;
363 std::string empty_string =
"";
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);
469 if (!
type.hide_help()) {
471 std::string type_name =
type.type_name();
473 const std::string section_prefix =
type.show_variations_in_help() ?
".." :
"";
477 std::string link =
make_link(type_name, ref_id);
478 special_units[specials[
i].first].insert(link);
483 for(
config adv :
type.modification_advancements()) {
485 if(effect[
"apply_to"] ==
"new_attack" && effect.has_child(
"specials")) {
486 for(
config::any_child spec : effect.mandatory_child(
"specials").all_children_range()) {
487 if(!spec.cfg[
"name"].empty()) {
488 special_description.emplace(spec.cfg[
"name"].t_str(), spec.cfg[
"description"].t_str());
489 if(!
type.hide_help()) {
491 std::string type_name =
type.type_name();
493 const std::string section_prefix =
type.show_variations_in_help() ?
".." :
"";
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.mandatory_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());
506 if(!
type.hide_help()) {
508 std::string type_name =
type.type_name();
510 const std::string section_prefix =
type.show_variations_in_help() ?
".." :
"";
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);
560 if(!
type.hide_help()) {
565 ability_units[topic_ref].insert(link);
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]) {
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) {
641 topics.push_back( era_topic );
648 std::vector<topic> topics;
649 for (
const config &
f :
era.child_range(
"multiplayer_side")) {
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) {
674 alignments.insert(
make_link(
type.alignment_description(
type.alignment(),
type.genders().front()),
"time_of_day"));
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"];
714 topics.emplace_back(name, ref_id, text.str());
717 std::sort(topics.begin(), topics.end(),
title_less());
726 std::map<t_string, const config> trait_list;
730 trait_list.emplace(trait[
"id"], trait);
734 std::set<std::string> races;
745 races.insert(
type.race_id());
755 for (
const config& trait :
type.possible_traits()) {
756 trait_list.emplace(trait[
"id"], trait);
766 for(
const auto& race_id : races) {
768 for(
const config & trait : r->additional_traits()) {
769 trait_list.emplace(trait[
"id"], trait);
774 std::vector<topic> topics;
775 for(
auto&
a : trait_list) {
776 std::string
id =
"traits_" +
a.first;
777 const config& trait =
a.second;
779 std::string name = trait[
"male_name"].str();
780 if (name.empty()) name = trait[
"female_name"].str();
781 if (name.empty()) name = trait[
"name"].str();
782 if (name.empty())
continue;
784 std::stringstream text;
785 if (!trait[
"help_text"].empty()) {
786 text << trait[
"help_text"];
787 }
else if (!trait[
"description"].empty()) {
788 text << trait[
"description"];
790 text <<
_(
"No description available.");
794 topics.emplace_back(name,
id, text.str());
798 std::sort(topics.begin(), topics.end(),
title_less());
809 PLAIN_LOG <<
"Unknown unit type : " << type_id;
813 }
else if (!
type->hide_help()) {
814 std::string name =
type->type_name();
817 const std::string section_prefix =
type->show_variations_in_help() ?
".." :
"";
831 std::vector<std::string> links_list;
832 for (
const std::string &type_id : type_id_list) {
834 if (!unit_link.empty())
835 links_list.push_back(unit_link);
839 std::sort(links_list.begin(), links_list.end());
846 std::set<std::string, string_less> races;
847 std::set<std::string, string_less> visible_races;
854 races.insert(
type.race_id());
855 if(!
type.hide_help())
856 visible_races.insert(
type.race_id());
861 std::set<std::string, string_less> last_sweep = visible_races;
862 while(!last_sweep.empty()) {
863 std::set<std::string, string_less> current_sweep;
864 for(
const auto& race_id : last_sweep) {
866 const auto& help_taxonomy = r->help_taxonomy();
867 if(!help_taxonomy.empty() && !visible_races.count(help_taxonomy) &&
unit_types.
find_race(help_taxonomy)) {
868 current_sweep.insert(help_taxonomy);
869 races.insert(help_taxonomy);
870 visible_races.insert(help_taxonomy);
874 last_sweep = std::move(current_sweep);
877 struct taxonomy_queue_type
879 std::string parent_id;
882 std::vector<taxonomy_queue_type> taxonomy_queue;
886 for(
const auto& race_id : races) {
890 bool hidden = (visible_races.count(race_id) == 0);
895 std::string help_taxonomy;
897 title = r->plural_name();
898 help_taxonomy = r->help_taxonomy();
900 title =
_(
"race^Miscellaneous");
903 section_cfg[
"title"] = title;
905 section_cfg[
"sections_generator"] =
"units:" + race_id;
906 section_cfg[
"generator"] =
"units:" + race_id;
910 if(help_taxonomy.empty()) {
913 bool parent_hidden = (visible_races.count(help_taxonomy) == 0);
915 taxonomy_queue.push_back({std::move(parent_id), std::move(race_section)});
920 bool process_queue_again =
true;
921 while(process_queue_again && !taxonomy_queue.empty()) {
922 process_queue_again =
false;
923 std::vector<taxonomy_queue_type> to_process = std::move(taxonomy_queue);
925 for(
auto& x : to_process) {
928 parent->add_section(std::move(x.content));
929 process_queue_again =
true;
931 taxonomy_queue.push_back(std::move(x));
937 for(
auto& x : taxonomy_queue) {
945 if (
era[
"hide_help"].to_bool()) {
949 DBG_HP <<
"Adding help section: " <<
era[
"id"].str();
954 section_cfg[
"title"] =
era[
"name"];
956 section_cfg[
"generator"] =
"era:" +
era[
"id"].str();
970 WRN_HP <<
"When building terrain help sections, couldn't acquire terrain types data, aborting.";
974 std::map<std::string, section> base_map;
982 bool hidden =
info.hide_help();
989 terrain_topic.
title =
info.editor_name();
991 terrain_topic.
text = std::make_shared<terrain_topic_generator>(
info);
996 const terrain_type& base_info = tdata->get_terrain_info(base);
1001 section& base_section = base_map[base_info.
id()];
1006 if (base_info.
id() ==
info.id())
1008 base_section.
topics.push_back(terrain_topic);
1012 for (
const auto& base : base_map) {
1019 for (
const unit_type_data::unit_type_map::value_type &
i :
unit_types.
types()) {
1022 if (
type.race_id() != race)
1025 if (!
type.show_variations_in_help())
1029 for (
const std::string &variation_id :
type.variations()) {
1031 const unit_type &var_type =
type.get_variation(variation_id);
1035 topic var_topic(topic_name, var_ref,
"");
1036 var_topic.
text = std::make_shared<unit_topic_generator>(var_type, variation_id);
1037 base_unit.
topics.push_back(var_topic);
1040 const std::string type_name =
type.type_name();
1043 base_unit.
id = ref_id;
1044 base_unit.
title = type_name;
1052 std::vector<topic> topics;
1053 std::set<std::string, string_less> race_units;
1054 std::set<std::string, string_less> race_topics;
1055 std::set<std::string> alignments;
1057 for (
const unit_type_data::unit_type_map::value_type &
i :
unit_types.
types())
1061 if (
type.race_id() != race)
1069 const std::string type_name =
type.type_name() + (
type.id() ==
type.type_name().str() ?
"" : debug_suffix);
1070 const std::string real_prefix =
type.show_variations_in_help() ?
".." :
"";
1072 topic unit_topic(type_name, ref_id,
"");
1073 unit_topic.
text = std::make_shared<unit_topic_generator>(
type);
1074 topics.push_back(unit_topic);
1076 if (!
type.hide_help()) {
1079 std::string link =
make_link(type_name, ref_id);
1080 race_units.insert(link);
1082 alignments.insert(
make_link(
type.alignment_description(
type.alignment(),
type.genders().front()),
"time_of_day"));
1087 std::string race_id =
"..race_"+race;
1088 std::string race_name;
1089 std::string race_description;
1090 std::string race_help_taxonomy;
1092 race_name = r->plural_name();
1093 race_description = r->description();
1094 race_help_taxonomy = r->help_taxonomy();
1096 for (
const config &additional_topic : r->additional_topics())
1098 std::string
id = additional_topic[
"id"];
1099 std::string title = additional_topic[
"title"];
1100 std::string text = additional_topic[
"text"];
1102 topics.emplace_back(title,
id,text);
1103 std::string link =
make_link(title,
id);
1104 race_topics.insert(link);
1107 race_name =
_ (
"race^Miscellaneous");
1112 std::map<std::string, t_string> subgroups;
1114 if (r.second.help_taxonomy() == race) {
1115 if (!r.second.plural_name().empty())
1116 subgroups[r.first] = r.second.plural_name();
1118 subgroups[r.first] = r.first;
1122 std::stringstream text;
1124 if (!race_description.empty()) {
1125 text << race_description <<
"\n\n";
1128 if (!alignments.empty()) {
1130 text << (alignments.size() > 1 ?
_(
"Alignments: ") :
_(
"Alignment: ")) << *(it++);
1131 while(it != alignments.end()) {
1132 text <<
", " << *(it++);
1137 if (!race_help_taxonomy.empty()) {
1139 symbols[
"topic_id"] =
"..race_"+race_help_taxonomy;
1141 symbols[
"help_taxonomy"] = r->plural_name();
1145 symbols[
"help_taxonomy"] = race_help_taxonomy;
1149 text <<
VGETTEXT(
"This is a group of units, all of whom are <ref>dst='$topic_id' text='$help_taxonomy'</ref>.", symbols) <<
"\n\n";
1152 if (!subgroups.empty()) {
1153 if (!race_help_taxonomy.empty()) {
1154 text <<
_(
"<header>text='Subgroups of units within this group'</header>") <<
"\n";
1156 text <<
_(
"<header>text='Groups of units within this race'</header>") <<
"\n";
1158 for (
const auto &sg : subgroups) {
1164 if (!race_help_taxonomy.empty()) {
1165 text <<
_(
"<header>text='Units of this group'</header>") <<
"\n";
1167 text <<
_(
"<header>text='Units of this race'</header>") <<
"\n";
1169 for (
const auto &u : race_units) {
1173 topics.emplace_back(race_name, race_id, text.str());
1176 std::sort(topics.begin(), topics.end(),
title_less());
1194 if (
type.id() ==
"Fog Clearer") {
1203 auto section_cfg = help_cfg->
find_child(
"section",
"id", section_name);
1205 return std::string();
1208 std::ostringstream res;
1213 typedef std::pair<std::string,std::string> link;
1214 std::vector<link> topics_links;
1218 for (
t = topics.begin();
t != topics.end(); ++
t) {
1219 if (
auto topic_cfg = help_cfg->
find_child(
"topic",
"id", *
t)) {
1220 std::string
id = topic_cfg[
"id"];
1222 topics_links.emplace_back(topic_cfg[
"title"],
id);
1226 if (section_cfg[
"sort_topics"] ==
"yes") {
1227 std::sort(topics_links.begin(),topics_links.end());
1231 for (l = topics_links.begin(); l != topics_links.end(); ++l) {
1232 std::string link =
make_link(l->first, l->second);
1241 std::stringstream res;
1250 for (
auto &
t : topics) {
1271 return sec.
id ==
id;
1292 topic_list::const_iterator tit =
1294 if (tit != sec.
topics.end()) {
1313 for (
const auto &subsection : sec.
sections) {
1329 std::vector<std::string> res;
1330 bool last_char_escape =
false;
1331 const char escape_char =
'\\';
1332 std::stringstream ss;
1335 for (pos = 0; pos < text.size(); ++pos) {
1336 const char c = text[pos];
1337 if (
c == escape_char && !last_char_escape) {
1338 last_char_escape =
true;
1341 if (state ==
OTHER) {
1343 if (last_char_escape) {
1347 res.push_back(ss.str());
1349 state = ELEMENT_NAME;
1356 else if (state == ELEMENT_NAME) {
1358 std::string
msg =
"Erroneous / in element name.";
1361 else if (
c ==
'>') {
1363 std::stringstream
s;
1364 const std::string element_name = ss.str();
1366 s <<
"</" << element_name <<
">";
1367 const std::string end_element_name =
s.str();
1368 std::size_t end_pos = text.find(end_element_name, pos);
1369 if (end_pos == std::string::npos) {
1370 std::stringstream
msg;
1371 msg <<
"Unterminated element: " << element_name;
1375 const std::string contents = text.substr(pos + 1, end_pos - pos - 1);
1376 const std::string element =
convert_to_wml(element_name, contents);
1377 res.push_back(element);
1378 pos = end_pos + end_element_name.size() - 1;
1385 last_char_escape =
false;
1388 if (state == ELEMENT_NAME) {
1389 std::stringstream
msg;
1390 msg <<
"Element '" << ss.str() <<
"' continues through end of string.";
1393 if (!ss.str().empty()) {
1395 res.push_back(ss.str());
1400 std::string
convert_to_wml(
const std::string &element_name,
const std::string &contents)
1402 std::stringstream ss;
1403 bool in_quotes =
false;
1404 bool last_char_escape =
false;
1405 const char escape_char =
'\\';
1406 std::vector<std::string> attributes;
1411 for (std::size_t pos = 0; pos < contents.size(); ++pos) {
1412 const char c = contents[pos];
1413 if (
c == escape_char && !last_char_escape) {
1414 last_char_escape =
true;
1417 if (
c ==
'\'' && !last_char_escape) {
1419 in_quotes = !in_quotes;
1421 else if ((
c ==
' ' ||
c ==
'\n') && !last_char_escape && !in_quotes) {
1423 attributes.push_back(ss.str());
1429 last_char_escape =
false;
1433 std::stringstream
msg;
1434 msg <<
"Unterminated single quote after: '" << ss.str() <<
"'";
1437 if (!ss.str().empty()) {
1438 attributes.push_back(ss.str());
1442 ss <<
"[" << element_name <<
"]\n";
1443 for (std::vector<std::string>::const_iterator it = attributes.begin();
1444 it != attributes.end(); ++it) {
1447 ss <<
"[/" << element_name <<
"]\n";
1453 if (cmp_str ==
"green") {
1456 if (cmp_str ==
"red") {
1459 if (cmp_str ==
"black") {
1462 if (cmp_str ==
"yellow") {
1465 if (cmp_str ==
"white") {
1469 if (*cmp_str.c_str() ==
'#' && cmp_str.size() == 7) {
1476 const unsigned width)
1478 std::vector<std::string> res;
1481 res.push_back(first_line);
1482 if(
s.size() > first_line.size()) {
1483 res.push_back(
s.substr(first_line.size()));
1496 if (text.length() > 0 && text[0] ==
' ') {
1497 return text.substr(1);
1504 std::size_t first_word_start =
s.find_first_not_of(
' ');
1505 if (first_word_start == std::string::npos) {
1508 std::size_t first_word_end =
s.find_first_of(
" \n", first_word_start);
1509 if( first_word_end == first_word_start ) {
1511 first_word_end = first_word_start+1;
1515 std::string re =
s.substr(0, first_word_end);
1521 char32_t firstchar = *ch;
1523 re = unicode_cast<std::string>(firstchar);
1543 std::stringstream ss;
1546 const std::string
id =
section[
"id"];
1552 if (!ss.str().empty()) {
1559 hidden_toplevel[
"sections"] = ss.str();
1563 const std::string
id =
topic[
"id"];
1566 if (!ss.str().empty()) {
1573 hidden_toplevel[
"topics"] = ss.str();
1574 config hidden_cfg = *help_config;
1577 hidden_cfg.
add_child(
"toplevel", std::move(hidden_toplevel));
1581 std::stringstream
msg;
1582 msg <<
"Parse error when parsing help text: '" <<
e.message <<
"'";
1590 return (hidden ?
"." :
"");
1594 return (
id.empty() ||
id[0] !=
'.');
1603 if (
id ==
"toplevel") {
1609 if (
id.
compare(0, 8,
"ability_") == 0) {
1612 if (
id.
compare(0, 14,
"weaponspecial_") == 0) {
1615 if (
id ==
"hidden") {
1627 if (surf !=
nullptr) {
1633 void push_tab_pair(std::vector<help::item> &v,
const std::string &
s,
const std::optional<std::string> &
image,
unsigned padding)
1639 padding = (width ? padding : 0);
1641 item.first =
"<img>src='" + *
image +
"'</img>" + (padding ?
jump(padding) :
"") +
s;
1642 item.second += width + padding;
1644 v.emplace_back(
item);
1649 table_spec::const_iterator row_it;
1650 std::vector<std::pair<std::string, unsigned>>::const_iterator col_it;
1651 unsigned int num_cols = 0;
1652 for (row_it = tab.begin(); row_it != tab.end(); ++row_it) {
1653 if (row_it->size() > num_cols) {
1654 num_cols = row_it->size();
1657 std::vector<unsigned int> col_widths(num_cols, 0);
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 if (col_widths[col] < col_it->second + spacing) {
1663 col_widths[col] = col_it->second + spacing;
1668 std::vector<unsigned int> col_starts(num_cols);
1670 for (
unsigned int i = 0;
i < num_cols; ++
i) {
1671 unsigned int this_col_start = 0;
1672 for (
unsigned int j = 0; j <
i; ++j) {
1673 this_col_start += col_widths[j];
1675 col_starts[
i] = this_col_start;
1677 std::stringstream ss;
1678 for (row_it = tab.begin(); row_it != tab.end(); ++row_it) {
1679 unsigned int col = 0;
1680 for (col_it = row_it->begin(); col_it != row_it->end(); ++col_it) {
1681 ss <<
jump_to(col_starts[col]) << col_it->first;
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.
Various functions that implement attacks and attack calculations.
Variant for storing WML attributes.
bool empty() const
Tests for an attribute that either was never set or was set to "".
A config object defines a single node in a WML file, with access to child nodes.
optional_config_impl< 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.
void clear_children(T... keys)
child_itors child_range(config_key_type key)
std::string debug() const
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Euivalent to mandatory_child, but returns an empty optional if the nth child was not found.
config & add_child(config_key_type key)
virtual const gamemap & map() const =0
const display_context & get_disp_context() const
static display * get_singleton()
Returns the display object if a display object exists.
static game_config_manager * get()
const std::shared_ptr< terrain_type_data > & terrain_types() const
A class grating read only view to a vector of config objects, viewed as one config with all children ...
const config & child_or_empty(config_key_type key) const
optional_const_config find_child(config_key_type key, const std::string &name, const std::string &value) const
config_array_view child_range(config_key_type key) const
const std::shared_ptr< terrain_type_data > & tdata() const
To be used as a function object to locate sections and topics with a specified ID.
To be used as a function object when sorting section lists on the title.
To be used as a function object when sorting topic lists on the title.
The text displayed in a topic.
const std::vector< std::string > & parsed_text() const
std::shared_ptr< topic_generator > generator_
topic_text & operator=(topic_text &&t)=default
std::vector< std::string > parsed_text_
Generic locator abstracting the location of an image.
bool hide_help() const
For instances created from a [terrain_type] tag, the value in the tag (with default false).
bool is_nonnull() const
True if this object represents some sentinel values.
const std::string & id() const
const t_string & editor_name() const
int get_max_liminal_bonus() const
const std::vector< time_of_day > & times(const map_location &loc=map_location::null_location()) const
static iterator_base end(const string_type &str)
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.
const race_map & races() const
const unit_race * find_race(const std::string &) const
const unit_type_map & types() const
config_array_view traits() const
A single unit type that the player may recruit.
const std::string & id() const
The id for this unit_type.
const t_string & variation_name() const
const t_string & type_name() const
The name of the unit in the current language setting.
Thrown by operations encountering invalid UTF-8 data.
static std::string _(const char *str)
std::string id
Text to match against addon_info.tags()
static lg::log_domain log_display("display")
static lg::log_domain log_help("help")
Standard logging facilities (interface).
const color_t YELLOW_COLOR
const color_t BLACK_COLOR
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.
const color_t BIGMAP_COLOR
const std::string unicode_bullet
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 color_t NORMAL_COLOR
std::string get_first_word(const std::string &s)
Return the first word in s, not removing any spaces in the start of it.
std::vector< topic > generate_unit_topics(const bool sort_generated, const std::string &race)
std::string hidden_symbol(bool hidden)
void generate_unit_sections(const config *, section &sec, int, const bool, const std::string &race)
@ HIDDEN_BUT_SHOW_MACROS
Although the unit itself is hidden, traits reachable via this unit are not hidden.
@ NO_DESCRIPTION
Ignore this unit for documentation purposes.
std::string make_link(const std::string &text, const std::string &dst)
void generate_races_sections(const config *help_cfg, section &sec, int level)
std::string escape(const std::string &s)
Prepend all chars with meaning inside attributes with a backslash.
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,...
std::vector< topic > generate_time_of_day_topics(const bool)
int last_num_encountered_units
void generate_terrain_sections(section &sec, int)
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
const std::string unit_prefix
unsigned image_width(const std::string &filename)
const std::string variation_prefix
void parse_config_internal(const config *help_cfg, const config *section_cfg, section &sec, int level)
Recursive function used by parse_config.
bool is_visible_id(const std::string &id)
const std::string closed_section_img
std::vector< topic > generate_faction_topics(const config &era, const bool sort_generated)
void generate_sections(const config *help_cfg, const std::string &generator, section &sec, int level)
Dispatch generators to their appropriate functions.
const std::string topic_img
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.
const std::string race_prefix
const std::string ability_prefix
std::vector< std::vector< help::item > > table_spec
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)
std::vector< topic > generate_topics(const bool sort_generated, const std::string &generator)
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.
void push_tab_pair(std::vector< help::item > &v, const std::string &s, const std::optional< std::string > &image, unsigned padding)
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].
std::pair< std::string, unsigned > item
static std::string time_of_day_bonus_colored(const int time_of_day_bonus)
const int normal_font_size
void generate_contents()
Generate the help contents from the configurations given to the manager.
std::string generate_table(const table_spec &tab, const unsigned int spacing)
const std::string terrain_prefix
std::vector< topic > generate_weapon_special_topics(const bool sort_generated)
std::vector< topic > generate_ability_topics(const bool sort_generated)
std::string remove_first_space(const std::string &text)
std::string jump_to(const unsigned pos)
const std::string unknown_unit_topic
const int max_section_level
const unsigned max_history
std::vector< std::string > empty_string_vector
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,...
std::shared_ptr< terrain_type_data > load_terrain_types_data()
Load the appropriate terrain types data to use.
std::string generate_topic_text(const std::string &generator, const config *help_cfg, const section &sec, const std::vector< topic > &generated_topics)
bool is_valid_id(const std::string &id)
Return true if the id is valid for user defined topics and sections.
boost::tribool last_debug_state
std::string generate_contents_links(const std::string §ion_name, config const *help_cfg)
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.
help::section default_toplevel
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.
color_t string_to_color(const std::string &cmp_str)
Return the color the string represents.
std::string jump(const unsigned amount)
section parse_config(const config *cfg)
Parse a help config, return the top level section.
std::vector< topic > generate_era_topics(const bool sort_generated, const std::string &era_id)
const game_config_view * game_cfg
int last_num_encountered_terrains
help::section hidden_sections
std::vector< topic > generate_trait_topics(const bool sort_generated)
std::vector< std::string > parse_text(const std::string &text)
Parse a text string.
const std::string default_show_topic
void generate_era_sections(const config *help_cfg, section &sec, int level)
static bool is_cjk_char(const char32_t ch)
const std::string era_prefix
const std::string faction_prefix
bool is_scope_active(scope s)
Functions to load and save images from/to disk.
surface get_surface(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image surface suitable for software manipulation.
bool show_all_units_in_help()
std::set< std::string > & encountered_units()
std::set< t_translation::terrain_code > & encountered_terrains()
rng * generator
This generator is automatically synced during synced context.
::tod_manager * tod_manager
std::vector< terrain_code > ter_list
int compare(const std::string &s1, const std::string &s2)
Case-sensitive lexicographical comparison.
@ STRIP_SPACES
REMOVE_EMPTY: remove empty elements.
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...
std::string escape(const std::string &str, const char *special_chars)
Prepends a configurable set of characters with a backslash.
std::map< std::string, t_string > string_map
std::vector< std::string > split(const config_attribute_value &val)
std::string::const_iterator iterator
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
Transitional API for porting SDL_ttf-based code to Pango.
The basic class for representing 8-bit RGB or RGBA colour values.
static color_t from_hex_string(const std::string &c)
Creates a new color_t object from a string variable in hex format.
Thrown when the help system fails to parse something.
A section contains topics and sections along with title and ID.
bool operator<(const section &) const
Comparison on the ID.
void add_section(const section &s)
Allocate memory for and add the section.
bool operator==(const section &) const
Two sections are equal if their IDs are equal.
A topic contains a title, an id and some text.
bool operator==(const topic &) const
Two topics are equal if their IDs are equal.
bool operator<(const topic &) const
Comparison on the ID.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Object which defines a time of day with associated bonuses, image, sounds etc.
static map_location::DIRECTION s
unit_type_data unit_types