Reformat unit_topic_generator
This commit is contained in:
parent
c2e216be5a
commit
c55d7cb50a
1 changed files with 482 additions and 463 deletions
|
@ -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> ";
|
||||
#endif
|
||||
|
||||
if (&female_type != &male_type)
|
||||
if (&female_type != &male_type) {
|
||||
#ifdef LOW_MEM
|
||||
ss << "<img>src='" << female_type.image() << "~XBRZ(2)' box='no'</img> ";
|
||||
#else
|
||||
ss << "<img>src='" << female_type.image() << "~RC(" << female_type.flag_rgb() << ">red)~XBRZ(2)' box='no'</img> ";
|
||||
#endif
|
||||
}
|
||||
|
||||
const std::string &male_portrait = male_type.small_profile().empty() ?
|
||||
male_type.big_profile() : male_type.small_profile();
|
||||
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
|
||||
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();
|
||||
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);
|
||||
if (!type || type->hide_help()) continue;
|
||||
if (!type || type->hide_help()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (first) {
|
||||
if (reverse)
|
||||
if (reverse) {
|
||||
ss << _("Advances from: ");
|
||||
else
|
||||
} else {
|
||||
ss << _("Advances to: ");
|
||||
}
|
||||
first = false;
|
||||
} else
|
||||
} else {
|
||||
ss << ", ";
|
||||
}
|
||||
|
||||
std::string lang_unit = type->type_name();
|
||||
std::string ref_id;
|
||||
|
@ -309,7 +313,9 @@ std::string unit_topic_generator::operator()() const {
|
|||
}
|
||||
ss << make_link(lang_unit, ref_id);
|
||||
}
|
||||
if (!first) ss << "\n";
|
||||
if (!first) {
|
||||
ss << "\n";
|
||||
}
|
||||
|
||||
reverse = !reverse; //switch direction
|
||||
} while(reverse != first_reverse_value); // don't restart
|
||||
|
@ -343,8 +349,9 @@ std::string unit_topic_generator::operator()() const {
|
|||
if (first) {
|
||||
ss << _("Variations: ");
|
||||
first = false;
|
||||
} else
|
||||
} else {
|
||||
ss << ", ";
|
||||
}
|
||||
|
||||
std::string ref_id;
|
||||
|
||||
|
@ -360,11 +367,10 @@ std::string unit_topic_generator::operator()() const {
|
|||
}
|
||||
ss << "\n"; //added even if empty, to avoid shifting
|
||||
|
||||
// Print the race of the unit, cross-reference it to the
|
||||
// respective topic.
|
||||
// Print the race of the unit, cross-reference it to the respective topic.
|
||||
const std::string race_id = type_.race_id();
|
||||
std::string race_name = type_.race()->plural_name();
|
||||
if ( race_name.empty() ) {
|
||||
if (race_name.empty()) {
|
||||
race_name = _ ("race^Miscellaneous");
|
||||
}
|
||||
ss << _("Race: ");
|
||||
|
@ -397,7 +403,9 @@ std::string unit_topic_generator::operator()() const {
|
|||
std::stringstream random_count;
|
||||
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();
|
||||
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();
|
||||
std::string lang_ability = translation::gettext(ability_it->c_str());
|
||||
ss << make_link(lang_ability, ref_id);
|
||||
if (ability_it + 1 != ability_end)
|
||||
if (ability_it + 1 != ability_end) {
|
||||
ss << ", ";
|
||||
}
|
||||
}
|
||||
ss << "\n\n";
|
||||
}
|
||||
|
||||
// Print the extra AMLA upgrade abilities, cross-reference them
|
||||
// to their respective topics.
|
||||
// Print the extra AMLA upgrade abilities, cross-reference them to their respective topics.
|
||||
if (!type_.adv_abilities().empty()) {
|
||||
ss << _("Ability Upgrades: ");
|
||||
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();
|
||||
std::string lang_ability = translation::gettext(ability_it->c_str());
|
||||
ss << make_link(lang_ability, ref_id);
|
||||
if (ability_it + 1 != ability_end)
|
||||
if (ability_it + 1 != ability_end) {
|
||||
ss << ", ";
|
||||
}
|
||||
}
|
||||
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.
|
||||
ss << _("HP: ") << type_.hitpoints() << jump(30)
|
||||
<< _("Moves: ") << type_.movement() << jump(30);
|
||||
if (type_.vision() != type_.movement())
|
||||
if (type_.vision() != type_.movement()) {
|
||||
ss << _("Vision: ") << type_.vision() << jump(30);
|
||||
if (type_.jamming() > 0)
|
||||
}
|
||||
if (type_.jamming() > 0) {
|
||||
ss << _("Jamming: ") << type_.jamming() << jump(30);
|
||||
}
|
||||
ss << _("Cost: ") << type_.cost() << jump(30)
|
||||
<< _("Alignment: ")
|
||||
<< make_link(type_.alignment_description(type_.alignment(), type_.genders().front()), "time_of_day")
|
||||
<< jump(30);
|
||||
if (type_.can_advance())
|
||||
if (type_.can_advance()) {
|
||||
ss << _("Required XP: ") << type_.experience_needed();
|
||||
}
|
||||
|
||||
// Print the detailed description about the unit.
|
||||
ss << "\n\n" << detailed_description;
|
||||
|
@ -493,35 +505,35 @@ std::string unit_topic_generator::operator()() const {
|
|||
std::vector<item> row;
|
||||
std::stringstream attack_ss;
|
||||
attack_ss << "<img>src='" << (*attack_it).icon() << "'</img>";
|
||||
row.push_back(std::make_pair(attack_ss.str(),
|
||||
image_width(attack_it->icon())));
|
||||
row.push_back(std::make_pair(attack_ss.str(),image_width(attack_it->icon())));
|
||||
push_tab_pair(row, lang_weapon);
|
||||
push_tab_pair(row, lang_type);
|
||||
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());
|
||||
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 << string_table["range_" + (*attack_it).range()];
|
||||
push_tab_pair(row, attack_ss.str());
|
||||
attack_ss.str(clear_stringstream);
|
||||
// Show this attack's special, if it has any. Cross
|
||||
// reference it to the section describing the
|
||||
// special.
|
||||
// reference it to the section describing the special.
|
||||
std::vector<std::pair<t_string, t_string> > specials = attack_it->special_tooltips();
|
||||
if(!specials.empty())
|
||||
{
|
||||
if (!specials.empty()) {
|
||||
std::string lang_special = "";
|
||||
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) {
|
||||
const std::string ref_id = std::string("weaponspecial_")
|
||||
+ specials[i].first.base_str();
|
||||
lang_special = (specials[i].first);
|
||||
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
|
||||
}
|
||||
}
|
||||
row.push_back(std::make_pair(attack_ss.str(),
|
||||
font::line_width(lang_special, normal_font_size)));
|
||||
}
|
||||
|
@ -555,7 +567,7 @@ std::string unit_topic_generator::operator()() const {
|
|||
push_header(first_res_row, _("Resistance"));
|
||||
resistance_table.push_back(first_res_row);
|
||||
utils::string_map dam_tab = movement_type.damage_table();
|
||||
for(utils::string_map::const_iterator dam_it = dam_tab.begin(), dam_end = dam_tab.end();
|
||||
for (utils::string_map::const_iterator dam_it = dam_tab.begin(), dam_end = dam_tab.end();
|
||||
dam_it != dam_end; ++dam_it) {
|
||||
std::vector<item> row;
|
||||
int resistance = 100 - atoi((*dam_it).second.c_str());
|
||||
|
@ -563,8 +575,9 @@ std::string unit_topic_generator::operator()() const {
|
|||
snprintf(resi,sizeof(resi),"% 4d%%",resistance); // range: -100% .. +70%
|
||||
std::string resist = resi;
|
||||
const size_t pos = resist.find('-');
|
||||
if (pos != std::string::npos)
|
||||
if (pos != std::string::npos) {
|
||||
resist.replace(pos, 1, utils::unicode_minus);
|
||||
}
|
||||
std::string color = unit_helper::resistance_color(resistance);
|
||||
std::string lang_weapon = string_table["type_" + dam_it->first];
|
||||
push_tab_pair(row, lang_weapon);
|
||||
|
@ -590,26 +603,29 @@ std::string unit_topic_generator::operator()() const {
|
|||
push_header(first_row, _("Movement Cost"));
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
const bool has_vision = type_.movement_type().has_vision_data();
|
||||
if ( has_vision )
|
||||
if (has_vision) {
|
||||
push_header(first_row, _("Vision Cost"));
|
||||
}
|
||||
const bool has_jamming = type_.movement_type().has_jamming_data();
|
||||
if ( has_jamming )
|
||||
if (has_jamming) {
|
||||
push_header(first_row, _("Jamming Cost"));
|
||||
}
|
||||
|
||||
table.push_back(first_row);
|
||||
std::set<t_translation::t_terrain>::const_iterator terrain_it =
|
||||
preferences::encountered_terrains().begin();
|
||||
|
||||
|
||||
for (; terrain_it != preferences::encountered_terrains().end();
|
||||
++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;
|
||||
}
|
||||
const terrain_type& info = tdata->get_terrain_info(terrain);
|
||||
|
||||
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) ));
|
||||
|
||||
//defense - range: +10 % .. +70 %
|
||||
const int defense =
|
||||
100 - movement_type.defense_modifier(terrain);
|
||||
const int defense = 100 - movement_type.defense_modifier(terrain);
|
||||
std::string color;
|
||||
if (defense <= 10)
|
||||
if (defense <= 10) {
|
||||
color = "red";
|
||||
else if (defense <= 30)
|
||||
} else if (defense <= 30) {
|
||||
color = "yellow";
|
||||
else if (defense <= 50)
|
||||
} else if (defense <= 50) {
|
||||
color = "white";
|
||||
else
|
||||
} else {
|
||||
color = "green";
|
||||
}
|
||||
|
||||
std::stringstream str;
|
||||
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
|
||||
str.str(clear_stringstream);
|
||||
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";
|
||||
else if (moves > 1)
|
||||
} else if (moves > 1) {
|
||||
color = "yellow";
|
||||
else
|
||||
} else {
|
||||
color = "white";
|
||||
}
|
||||
str << "<format>color=" << color << " text='";
|
||||
// A 5 MP margin; if the movement costs go above
|
||||
// the unit's max moves + 5, we replace it with dashes.
|
||||
|
@ -676,7 +693,7 @@ std::string unit_topic_generator::operator()() const {
|
|||
font::line_width(str.str(), normal_font_size)));
|
||||
|
||||
//defense cap
|
||||
if ( has_terrain_defense_caps ) {
|
||||
if (has_terrain_defense_caps) {
|
||||
str.str(clear_stringstream);
|
||||
const bool has_cap = movement_type.get_defense().capped(terrain);
|
||||
if (has_cap) {
|
||||
|
@ -696,17 +713,18 @@ std::string unit_topic_generator::operator()() const {
|
|||
}
|
||||
|
||||
//vision
|
||||
if ( has_vision ) {
|
||||
if (has_vision) {
|
||||
str.str(clear_stringstream);
|
||||
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";
|
||||
else if ( views > moves )
|
||||
} else if (views > moves) {
|
||||
color = "yellow";
|
||||
else if ( views == moves )
|
||||
} else if (views == moves) {
|
||||
color = "white";
|
||||
else
|
||||
} else {
|
||||
color = "green";
|
||||
}
|
||||
str << "<format>color=" << color << " text='";
|
||||
// A 5 MP margin; if the vision costs go above
|
||||
// the unit's vision + 5, we replace it with dashes.
|
||||
|
@ -724,17 +742,18 @@ std::string unit_topic_generator::operator()() const {
|
|||
}
|
||||
|
||||
//jamming
|
||||
if ( has_jamming ) {
|
||||
if (has_jamming) {
|
||||
str.str(clear_stringstream);
|
||||
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";
|
||||
else if ( jams > views )
|
||||
} else if (jams > views) {
|
||||
color = "yellow";
|
||||
else if ( jams == views )
|
||||
} else if (jams == views) {
|
||||
color = "white";
|
||||
else
|
||||
} else {
|
||||
color = "green";
|
||||
}
|
||||
str << "<format>color=" << color << " text='";
|
||||
// A 5 MP margin; if the jamming costs go above
|
||||
// the unit's jamming + 5, we replace it with dashes.
|
||||
|
|
Loading…
Add table
Reference in a new issue