Reformat unit_topic_generator

This commit is contained in:
Celtic Minstrel 2016-03-21 11:26:25 -04:00
parent c2e216be5a
commit c55d7cb50a

View file

@ -249,17 +249,18 @@ std::string unit_topic_generator::operator()() const {
ss << "<img>src='" << male_type.image() << "~RC(" << male_type.flag_rgb() << ">red)~XBRZ(2)' box='no'</img> "; ss << "<img>src='" << male_type.image() << "~RC(" << male_type.flag_rgb() << ">red)~XBRZ(2)' box='no'</img> ";
#endif #endif
if (&female_type != &male_type) if (&female_type != &male_type) {
#ifdef LOW_MEM #ifdef LOW_MEM
ss << "<img>src='" << female_type.image() << "~XBRZ(2)' box='no'</img> "; ss << "<img>src='" << female_type.image() << "~XBRZ(2)' box='no'</img> ";
#else #else
ss << "<img>src='" << female_type.image() << "~RC(" << female_type.flag_rgb() << ">red)~XBRZ(2)' box='no'</img> "; ss << "<img>src='" << female_type.image() << "~RC(" << female_type.flag_rgb() << ">red)~XBRZ(2)' box='no'</img> ";
#endif #endif
}
const std::string &male_portrait = male_type.small_profile().empty() ? const std::string &male_portrait = male_type.small_profile().empty() ?
male_type.big_profile() : male_type.small_profile(); male_type.big_profile() : male_type.small_profile();
const std::string &female_portrait = female_type.small_profile().empty() ? const std::string &female_portrait = female_type.small_profile().empty() ?
female_type.big_profile() : female_type.small_profile(); ; female_type.big_profile() : female_type.small_profile();
// TODO: figure out why the second checks don't match but the last does // TODO: figure out why the second checks don't match but the last does
if (!male_portrait.empty() && male_portrait != male_type.image() && male_portrait != "unit_image") { if (!male_portrait.empty() && male_portrait != male_type.image() && male_portrait != "unit_image") {
@ -284,19 +285,22 @@ std::string unit_topic_generator::operator()() const {
reverse ? type_.advances_from() : type_.advances_to(); reverse ? type_.advances_from() : type_.advances_to();
bool first = true; bool first = true;
BOOST_FOREACH(const std::string &adv, adv_units) BOOST_FOREACH(const std::string &adv, adv_units) {
{
const unit_type *type = unit_types.find(adv, unit_type::HELP_INDEXED); const unit_type *type = unit_types.find(adv, unit_type::HELP_INDEXED);
if (!type || type->hide_help()) continue; if (!type || type->hide_help()) {
continue;
}
if (first) { if (first) {
if (reverse) if (reverse) {
ss << _("Advances from: "); ss << _("Advances from: ");
else } else {
ss << _("Advances to: "); ss << _("Advances to: ");
}
first = false; first = false;
} else } else {
ss << ", "; ss << ", ";
}
std::string lang_unit = type->type_name(); std::string lang_unit = type->type_name();
std::string ref_id; std::string ref_id;
@ -309,7 +313,9 @@ std::string unit_topic_generator::operator()() const {
} }
ss << make_link(lang_unit, ref_id); ss << make_link(lang_unit, ref_id);
} }
if (!first) ss << "\n"; if (!first) {
ss << "\n";
}
reverse = !reverse; //switch direction reverse = !reverse; //switch direction
} while(reverse != first_reverse_value); // don't restart } while(reverse != first_reverse_value); // don't restart
@ -343,8 +349,9 @@ std::string unit_topic_generator::operator()() const {
if (first) { if (first) {
ss << _("Variations: "); ss << _("Variations: ");
first = false; first = false;
} else } else {
ss << ", "; ss << ", ";
}
std::string ref_id; std::string ref_id;
@ -360,8 +367,7 @@ std::string unit_topic_generator::operator()() const {
} }
ss << "\n"; //added even if empty, to avoid shifting ss << "\n"; //added even if empty, to avoid shifting
// Print the race of the unit, cross-reference it to the // Print the race of the unit, cross-reference it to the respective topic.
// respective topic.
const std::string race_id = type_.race_id(); const std::string race_id = type_.race_id();
std::string race_name = type_.race()->plural_name(); std::string race_name = type_.race()->plural_name();
if (race_name.empty()) { if (race_name.empty()) {
@ -397,7 +403,9 @@ std::string unit_topic_generator::operator()() const {
std::stringstream random_count; std::stringstream random_count;
random_count << " (" << (type_.num_traits() - must_have_traits.size()) << ") : "; random_count << " (" << (type_.num_traits() - must_have_traits.size()) << ") : ";
int second_line_whitespace = font::line_width(traits_label+must_have_count.str(), normal_font_size) - font::line_width(random_count.str(), normal_font_size); // This ensures that the second line is justified so that the ':' characters are aligned. int second_line_whitespace = font::line_width(traits_label+must_have_count.str(), normal_font_size)
- font::line_width(random_count.str(), normal_font_size);
// This ensures that the second line is justified so that the ':' characters are aligned.
ss << must_have_count.str(); ss << must_have_count.str();
print_trait_list(ss, must_have_traits); print_trait_list(ss, must_have_traits);
@ -427,14 +435,14 @@ std::string unit_topic_generator::operator()() const {
const std::string ref_id = "ability_" + ability_it->base_str(); const std::string ref_id = "ability_" + ability_it->base_str();
std::string lang_ability = translation::gettext(ability_it->c_str()); std::string lang_ability = translation::gettext(ability_it->c_str());
ss << make_link(lang_ability, ref_id); ss << make_link(lang_ability, ref_id);
if (ability_it + 1 != ability_end) if (ability_it + 1 != ability_end) {
ss << ", "; ss << ", ";
} }
}
ss << "\n\n"; ss << "\n\n";
} }
// Print the extra AMLA upgrade abilities, cross-reference them // Print the extra AMLA upgrade abilities, cross-reference them to their respective topics.
// to their respective topics.
if (!type_.adv_abilities().empty()) { if (!type_.adv_abilities().empty()) {
ss << _("Ability Upgrades: "); ss << _("Ability Upgrades: ");
for(std::vector<t_string>::const_iterator ability_it = type_.adv_abilities().begin(), for(std::vector<t_string>::const_iterator ability_it = type_.adv_abilities().begin(),
@ -443,9 +451,10 @@ std::string unit_topic_generator::operator()() const {
const std::string ref_id = "ability_" + ability_it->base_str(); const std::string ref_id = "ability_" + ability_it->base_str();
std::string lang_ability = translation::gettext(ability_it->c_str()); std::string lang_ability = translation::gettext(ability_it->c_str());
ss << make_link(lang_ability, ref_id); ss << make_link(lang_ability, ref_id);
if (ability_it + 1 != ability_end) if (ability_it + 1 != ability_end) {
ss << ", "; ss << ", ";
} }
}
ss << "\n\n"; ss << "\n\n";
} }
@ -453,16 +462,19 @@ std::string unit_topic_generator::operator()() const {
// TODO: Make this info update according to musthave traits, similar to movetype below. // TODO: Make this info update according to musthave traits, similar to movetype below.
ss << _("HP: ") << type_.hitpoints() << jump(30) ss << _("HP: ") << type_.hitpoints() << jump(30)
<< _("Moves: ") << type_.movement() << jump(30); << _("Moves: ") << type_.movement() << jump(30);
if (type_.vision() != type_.movement()) if (type_.vision() != type_.movement()) {
ss << _("Vision: ") << type_.vision() << jump(30); ss << _("Vision: ") << type_.vision() << jump(30);
if (type_.jamming() > 0) }
if (type_.jamming() > 0) {
ss << _("Jamming: ") << type_.jamming() << jump(30); ss << _("Jamming: ") << type_.jamming() << jump(30);
}
ss << _("Cost: ") << type_.cost() << jump(30) ss << _("Cost: ") << type_.cost() << jump(30)
<< _("Alignment: ") << _("Alignment: ")
<< make_link(type_.alignment_description(type_.alignment(), type_.genders().front()), "time_of_day") << make_link(type_.alignment_description(type_.alignment(), type_.genders().front()), "time_of_day")
<< jump(30); << jump(30);
if (type_.can_advance()) if (type_.can_advance()) {
ss << _("Required XP: ") << type_.experience_needed(); ss << _("Required XP: ") << type_.experience_needed();
}
// Print the detailed description about the unit. // Print the detailed description about the unit.
ss << "\n\n" << detailed_description; ss << "\n\n" << detailed_description;
@ -493,25 +505,24 @@ std::string unit_topic_generator::operator()() const {
std::vector<item> row; std::vector<item> row;
std::stringstream attack_ss; std::stringstream attack_ss;
attack_ss << "<img>src='" << (*attack_it).icon() << "'</img>"; attack_ss << "<img>src='" << (*attack_it).icon() << "'</img>";
row.push_back(std::make_pair(attack_ss.str(), row.push_back(std::make_pair(attack_ss.str(),image_width(attack_it->icon())));
image_width(attack_it->icon())));
push_tab_pair(row, lang_weapon); push_tab_pair(row, lang_weapon);
push_tab_pair(row, lang_type); push_tab_pair(row, lang_type);
attack_ss.str(clear_stringstream); attack_ss.str(clear_stringstream);
attack_ss << attack_it->damage() << utils::unicode_en_dash << attack_it->num_attacks() << " " << attack_it->accuracy_parry_description(); attack_ss << attack_it->damage() << utils::unicode_en_dash << attack_it->num_attacks()
<< " " << attack_it->accuracy_parry_description();
push_tab_pair(row, attack_ss.str()); push_tab_pair(row, attack_ss.str());
attack_ss.str(clear_stringstream); attack_ss.str(clear_stringstream);
if ((*attack_it).min_range() > 1 || (*attack_it).max_range() > 1) if ((*attack_it).min_range() > 1 || (*attack_it).max_range() > 1) {
attack_ss << (*attack_it).min_range() << "-" << (*attack_it).max_range() << ' '; attack_ss << (*attack_it).min_range() << "-" << (*attack_it).max_range() << ' ';
}
attack_ss << string_table["range_" + (*attack_it).range()]; attack_ss << string_table["range_" + (*attack_it).range()];
push_tab_pair(row, attack_ss.str()); push_tab_pair(row, attack_ss.str());
attack_ss.str(clear_stringstream); attack_ss.str(clear_stringstream);
// Show this attack's special, if it has any. Cross // Show this attack's special, if it has any. Cross
// reference it to the section describing the // reference it to the section describing the special.
// special.
std::vector<std::pair<t_string, t_string> > specials = attack_it->special_tooltips(); std::vector<std::pair<t_string, t_string> > specials = attack_it->special_tooltips();
if(!specials.empty()) if (!specials.empty()) {
{
std::string lang_special = ""; std::string lang_special = "";
const size_t specials_size = specials.size(); const size_t specials_size = specials.size();
for (size_t i = 0; i != specials_size; ++i) { for (size_t i = 0; i != specials_size; ++i) {
@ -519,9 +530,10 @@ std::string unit_topic_generator::operator()() const {
+ specials[i].first.base_str(); + specials[i].first.base_str();
lang_special = (specials[i].first); lang_special = (specials[i].first);
attack_ss << make_link(lang_special, ref_id); attack_ss << make_link(lang_special, ref_id);
if ( i+1 != specials_size ) if (i+1 != specials_size) {
attack_ss << ", "; //comma placed before next special attack_ss << ", "; //comma placed before next special
} }
}
row.push_back(std::make_pair(attack_ss.str(), row.push_back(std::make_pair(attack_ss.str(),
font::line_width(lang_special, normal_font_size))); font::line_width(lang_special, normal_font_size)));
} }
@ -563,8 +575,9 @@ std::string unit_topic_generator::operator()() const {
snprintf(resi,sizeof(resi),"% 4d%%",resistance); // range: -100% .. +70% snprintf(resi,sizeof(resi),"% 4d%%",resistance); // range: -100% .. +70%
std::string resist = resi; std::string resist = resi;
const size_t pos = resist.find('-'); const size_t pos = resist.find('-');
if (pos != std::string::npos) if (pos != std::string::npos) {
resist.replace(pos, 1, utils::unicode_minus); resist.replace(pos, 1, utils::unicode_minus);
}
std::string color = unit_helper::resistance_color(resistance); std::string color = unit_helper::resistance_color(resistance);
std::string lang_weapon = string_table["type_" + dam_it->first]; std::string lang_weapon = string_table["type_" + dam_it->first];
push_tab_pair(row, lang_weapon); push_tab_pair(row, lang_weapon);
@ -590,26 +603,29 @@ std::string unit_topic_generator::operator()() const {
push_header(first_row, _("Movement Cost")); push_header(first_row, _("Movement Cost"));
const bool has_terrain_defense_caps = movement_type.has_terrain_defense_caps(preferences::encountered_terrains()); const bool has_terrain_defense_caps = movement_type.has_terrain_defense_caps(preferences::encountered_terrains());
if ( has_terrain_defense_caps ) if (has_terrain_defense_caps) {
push_header(first_row, _("Defense Cap")); push_header(first_row, _("Defense Cap"));
}
const bool has_vision = type_.movement_type().has_vision_data(); const bool has_vision = type_.movement_type().has_vision_data();
if ( has_vision ) if (has_vision) {
push_header(first_row, _("Vision Cost")); push_header(first_row, _("Vision Cost"));
}
const bool has_jamming = type_.movement_type().has_jamming_data(); const bool has_jamming = type_.movement_type().has_jamming_data();
if ( has_jamming ) if (has_jamming) {
push_header(first_row, _("Jamming Cost")); push_header(first_row, _("Jamming Cost"));
}
table.push_back(first_row); table.push_back(first_row);
std::set<t_translation::t_terrain>::const_iterator terrain_it = std::set<t_translation::t_terrain>::const_iterator terrain_it =
preferences::encountered_terrains().begin(); preferences::encountered_terrains().begin();
for (; terrain_it != preferences::encountered_terrains().end(); for (; terrain_it != preferences::encountered_terrains().end();
++terrain_it) { ++terrain_it) {
const t_translation::t_terrain terrain = *terrain_it; const t_translation::t_terrain terrain = *terrain_it;
if (terrain == t_translation::FOGGED || terrain == t_translation::VOID_TERRAIN || terrain == t_translation::OFF_MAP_USER) if (terrain == t_translation::FOGGED || terrain == t_translation::VOID_TERRAIN || terrain == t_translation::OFF_MAP_USER) {
continue; continue;
}
const terrain_type& info = tdata->get_terrain_info(terrain); const terrain_type& info = tdata->get_terrain_info(terrain);
if (info.union_type().size() == 1 && info.union_type()[0] == info.number() && info.is_nonnull()) { if (info.union_type().size() == 1 && info.union_type()[0] == info.number() && info.is_nonnull()) {
@ -631,17 +647,17 @@ std::string unit_topic_generator::operator()() const {
font::line_width(name, normal_font_size) + (high_res ? 32 : 16) )); font::line_width(name, normal_font_size) + (high_res ? 32 : 16) ));
//defense - range: +10 % .. +70 % //defense - range: +10 % .. +70 %
const int defense = const int defense = 100 - movement_type.defense_modifier(terrain);
100 - movement_type.defense_modifier(terrain);
std::string color; std::string color;
if (defense <= 10) if (defense <= 10) {
color = "red"; color = "red";
else if (defense <= 30) } else if (defense <= 30) {
color = "yellow"; color = "yellow";
else if (defense <= 50) } else if (defense <= 50) {
color = "white"; color = "white";
else } else {
color = "green"; color = "green";
}
std::stringstream str; std::stringstream str;
str << "<format>color=" << color << " text='"<< defense << "%'</format>"; str << "<format>color=" << color << " text='"<< defense << "%'</format>";
@ -654,12 +670,13 @@ std::string unit_topic_generator::operator()() const {
//movement - range: 1 .. 5, movetype::UNREACHABLE=impassable //movement - range: 1 .. 5, movetype::UNREACHABLE=impassable
str.str(clear_stringstream); str.str(clear_stringstream);
const bool cannot_move = moves > type_.movement(); const bool cannot_move = moves > type_.movement();
if (cannot_move) // cannot move in this terrain if (cannot_move) { // cannot move in this terrain
color = "red"; color = "red";
else if (moves > 1) } else if (moves > 1) {
color = "yellow"; color = "yellow";
else } else {
color = "white"; color = "white";
}
str << "<format>color=" << color << " text='"; str << "<format>color=" << color << " text='";
// A 5 MP margin; if the movement costs go above // A 5 MP margin; if the movement costs go above
// the unit's max moves + 5, we replace it with dashes. // the unit's max moves + 5, we replace it with dashes.
@ -699,14 +716,15 @@ std::string unit_topic_generator::operator()() const {
if (has_vision) { if (has_vision) {
str.str(clear_stringstream); str.str(clear_stringstream);
const bool cannot_view = views > type_.vision(); const bool cannot_view = views > type_.vision();
if (cannot_view) // cannot view in this terrain if (cannot_view) { // cannot view in this terrain
color = "red"; color = "red";
else if ( views > moves ) } else if (views > moves) {
color = "yellow"; color = "yellow";
else if ( views == moves ) } else if (views == moves) {
color = "white"; color = "white";
else } else {
color = "green"; color = "green";
}
str << "<format>color=" << color << " text='"; str << "<format>color=" << color << " text='";
// A 5 MP margin; if the vision costs go above // A 5 MP margin; if the vision costs go above
// the unit's vision + 5, we replace it with dashes. // the unit's vision + 5, we replace it with dashes.
@ -727,14 +745,15 @@ std::string unit_topic_generator::operator()() const {
if (has_jamming) { if (has_jamming) {
str.str(clear_stringstream); str.str(clear_stringstream);
const bool cannot_jam = jams > type_.jamming(); const bool cannot_jam = jams > type_.jamming();
if ( cannot_jam ) // cannot jamm in this terrain if (cannot_jam) { // cannot jamm in this terrain
color = "red"; color = "red";
else if ( jams > views ) } else if (jams > views) {
color = "yellow"; color = "yellow";
else if ( jams == views ) } else if (jams == views) {
color = "white"; color = "white";
else } else {
color = "green"; color = "green";
}
str << "<format>color=" << color << " text='"; str << "<format>color=" << color << " text='";
// A 5 MP margin; if the jamming costs go above // A 5 MP margin; if the jamming costs go above
// the unit's jamming + 5, we replace it with dashes. // the unit's jamming + 5, we replace it with dashes.