Simplify help's logic for terrain_types that should be hidden in help

Even when a terrain has hide_help=yes, its help should still be shown if the
player right-clicks on a hex of that type and selects "Terrain description".

This commit changes lines that have inconsistent logic, and the main reason for
doing it was to work out whether that inconsistency was something that needed
to be kept when refactoring the terrain code.

The inconsistency was a bug, help would fail to open the topic.  However, the
bug is so obscure that I only found it when considering the edge case that the
commit is removing, and there's no terrain in core that would trigger it.  The
edge case requires a terrain to be:

* defined by a [terrain_type] tag, so is_combined()==false
* hide_help=yes
* hidden=no (or is the default value)

To replicate the bug, try changing the definition of Gg to have hide_help=yes.
This commit is contained in:
Steve Cotton 2020-01-12 17:56:03 +01:00 committed by Steve Cotton
parent 4c1d526061
commit c2ce47f6a3
4 changed files with 35 additions and 3 deletions

View file

@ -61,7 +61,7 @@ void show_unit_description(const unit &u)
void show_terrain_description(const terrain_type &t)
{
help::show_terrain_help(t.id(), t.hide_in_editor() || t.is_combined());
help::show_terrain_help(t.id(), t.hide_help());
}
void show_unit_description(const unit_type &t)

View file

@ -851,7 +851,7 @@ void generate_terrain_sections(const config* /*help_cfg*/, section& sec, int /*l
const terrain_type& info = tdata->get_terrain_info(t);
bool hidden = info.is_combined() || info.hide_help();
bool hidden = info.hide_help();
if (preferences::encountered_terrains().find(t)
== preferences::encountered_terrains().end() && !info.is_overlay())

View file

@ -238,7 +238,7 @@ terrain_type::terrain_type(const terrain_type& base, const terrain_type& overlay
overlay_(false),
combined_(true),
editor_default_base_(),
hide_help_(base.hide_help_ || overlay.hide_help_),
hide_help_(true),
hide_in_editor_(base.hide_in_editor_ || overlay.hide_in_editor_),
hide_if_impassable_(base.hide_if_impassable_ || overlay.hide_if_impassable_)
{

View file

@ -22,8 +22,22 @@ class terrain_type
{
public:
/**
* Creates an instance for which is_nonnull() returns false. Used for the
* sentinel value when terrain_type_data::get_terrain_info() is called for
* an unknown terrain code.
*/
explicit terrain_type();
/**
* Constructor for terrains defined by a WML [terrain_type] tag.
*/
explicit terrain_type(const config& cfg);
/**
* Used when a terrain code which hasn't been defined with a [terrain_type]
* tag is used in a map, to build the terrain from already-defined terrains.
*/
explicit terrain_type(const terrain_type& base, const terrain_type& overlay);
const std::string& icon_image() const { return icon_image_; }
@ -36,6 +50,13 @@ public:
const t_string& help_topic_text() const { return help_topic_text_; }
const std::string& id() const { return id_; }
/**
* For instances created from a [terrain_type] tag, the value in the tag
* (with default false).
*
* Always true for instances generated by the terrain_type(base, overlay)
* constructor.
*/
bool hide_help() const { return hide_help_; }
bool hide_in_editor() const { return hide_in_editor_; }
bool hide_if_impassable() const { return hide_if_impassable_; }
@ -132,6 +153,17 @@ public:
void set_editor_group(const std::string& str) { editor_group_ = str; }
bool is_overlay() const { return overlay_; }
/**
* True for instances created by the terrain_code(base, overlay) constructor.
*
* False for instances created by the terrain_type(config) constructor,
* implying that they were created directly from a WML [terrain_type] tag.
*
* Note that this returns false for terrains such as Dd^Dc (crater) and
* Mm^Xm (regular impassible mountains), because there are [terrain_type]
* tags for those specific combinations of base^overlay.
*/
bool is_combined() const { return combined_; }
t_translation::terrain_code default_base() const { return editor_default_base_; }