add "Defense Capped" col. to terrain table in help page for units

If a unit has a "negative" modifier on one of its terrain defenses,
for the basic terrain defense types that have been discovered and
will be displayed on the current help page, a column will be
generated "Defense Capped" which indicates which terrain types
have the negative modifier. In each row the column contains either
'-' or 'yes'.
This commit is contained in:
Chris Beck 2014-07-16 01:08:56 -04:00
parent 2a7d020c1f
commit 47f9accb9e
3 changed files with 41 additions and 0 deletions

View file

@ -1731,6 +1731,10 @@ public:
push_header(first_row, _("Defense"));
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 )
push_header(first_row, _("Defense Capped"));
const bool has_vision = type_.movement_type().has_vision_data();
if ( has_vision )
push_header(first_row, _("Vision Cost"));
@ -1813,6 +1817,29 @@ public:
row.push_back(std::make_pair(markup,
font::line_width(str.str(), normal_font_size)));
//defense cap
if ( has_terrain_defense_caps ) {
str.str(clear_stringstream);
const bool has_cap = movement_type.get_defense().capped(terrain);
str << "<format>color=" << (has_cap? "yellow" : "white")
<< " text='";
if (has_cap) {
str << "yes";
} else {
str << utils::unicode_figure_dash;
}
str << "'</format>";
markup = str.str();
str.str(clear_stringstream);
if (has_cap) {
str << "yes";
} else {
str << utils::unicode_figure_dash;
}
row.push_back(std::make_pair(markup,
font::line_width(str.str(), normal_font_size)));
}
//vision
if ( has_vision ) {
str.str(clear_stringstream);

View file

@ -730,6 +730,15 @@ movetype::movetype(const movetype & that) :
{
}
/**
* Checks if we have a defense cap (nontrivial min value) for any of the given terrain types.
*/
bool movetype::has_terrain_defense_caps(const std::set<t_translation::t_terrain> & ts) const {
BOOST_FOREACH(const t_translation::t_terrain & t, ts)
if (defense_.capped(t))
return true;
return false;
}
/**
* Merges the given config over the existing data.

View file

@ -130,6 +130,9 @@ public:
/// Returns the defense associated with the given terrain.
int defense(const t_translation::t_terrain & terrain) const
{ return std::max(min_.value(terrain), max_.value(terrain)); }
/// Returns whether there is a defense cap associated to this terrain.
bool capped(const t_translation::t_terrain & terrain) const
{ return min_.value(terrain) != 0; }
/// Merges the given config over the existing costs.
/// (Not overwriting implies adding.)
void merge(const config & new_data, bool overwrite)
@ -216,6 +219,8 @@ public:
utils::string_map damage_table() const
{ return resist_.damage_table(); }
/// Returns whether or not there are any terrain caps with respect to a set of terrains.
bool has_terrain_defense_caps(const std::set<t_translation::t_terrain> & ts) const;
/// Returns whether or not there are any vision-specific costs.
bool has_vision_data() const { return !vision_.empty(); }
/// Returns whether or not there are any jamming-specific costs.