Contains the database of all known terrain types, both those defined explicitly by WML [terrain_type]s and those made by combining pairs of (base, overlay). More...
#include <type_data.hpp>
Public Types | |
| enum | merge_mode { BASE , OVERLAY , BOTH } |
Public Member Functions | |
| void | lazy_initialization () const |
| On the first call to this function, parse all of the [terrain_type]s that are defined in WML. More... | |
| const t_translation::ter_list & | list () const |
| const std::map< t_translation::terrain_code, terrain_type > & | map () const |
| const terrain_type & | get_terrain_info (const t_translation::terrain_code &terrain) const |
| Get the corresponding terrain_type information object for a given type of terrain. More... | |
| const t_translation::ter_list & | underlying_mvt_terrain (const t_translation::terrain_code &terrain) const |
| The underlying movement type of the terrain. More... | |
| const t_translation::ter_list & | underlying_def_terrain (const t_translation::terrain_code &terrain) const |
| The underlying defense type of the terrain. More... | |
| const t_translation::ter_list & | underlying_union_terrain (const t_translation::terrain_code &terrain) const |
| Unordered set of all terrains used in either underlying_mvt_terrain or underlying_def_terrain. More... | |
| t_string | get_terrain_string (const t_translation::terrain_code &terrain) const |
| Get a formatted terrain name – terrain (underlying terrains) More... | |
| t_string | get_terrain_editor_string (const t_translation::terrain_code &terrain) const |
| t_string | get_underlying_terrain_string (const t_translation::terrain_code &terrain) const |
| bool | is_village (const t_translation::terrain_code &terrain) const |
| int | gives_healing (const t_translation::terrain_code &terrain) const |
| bool | is_castle (const t_translation::terrain_code &terrain) const |
| bool | is_keep (const t_translation::terrain_code &terrain) const |
| t_translation::terrain_code | merge_terrains (const t_translation::terrain_code &old_t, const t_translation::terrain_code &new_t, const merge_mode mode, bool replace_if_failed=false) const |
| Tries to find a new terrain which is the combination of old and new terrain using the merge_settings. More... | |
| bool | is_known (const t_translation::terrain_code &terrain) const |
| Returns true if get_terrain_info(terrain) would succeed, or false if get_terrain_info(terrain) would return a default-constructed instance. More... | |
Static Public Member Functions | |
| static std::shared_ptr< terrain_type_data > | reset (const game_config_view &game_config) |
| Regenerates the terrain database from the given game config. More... | |
| static std::shared_ptr< terrain_type_data > | get () |
Private Types | |
| using | tcodeToTerrain_t = std::map< t_translation::terrain_code, terrain_type > |
Private Member Functions | |
| terrain_type_data (const game_config_view &game_config) | |
| tcodeToTerrain_t::const_iterator | find_or_create (t_translation::terrain_code) const |
Private Attributes | |
| t_translation::ter_list | terrainList_ |
| tcodeToTerrain_t | tcodeToTerrain_ |
| bool | initialized_ |
| const game_config_view & | game_config_ |
Static Private Attributes | |
| static std::shared_ptr< terrain_type_data > | singleton_ |
Contains the database of all known terrain types, both those defined explicitly by WML [terrain_type]s and those made by combining pairs of (base, overlay).
A [terrain_type] isn't limited to (only a base) or (only an overlay). For example, the various impassible mountains Mm^Xm, Ms^Xm, etc are defined by [terrain_type]s for those specific (base, overlay) pairs.
Implementation note: the ones defined by WML [terrain_type]'s are loaded during the first call to lazy_initialization(). Any terrains made by combining pairs of (base, overlay) are lazy-created during a later call to find_or_create().
The is_known() method will trigger creation of the terrain if needed.
Definition at line 41 of file type_data.hpp.
|
private |
Definition at line 44 of file type_data.hpp.
| Enumerator | |
|---|---|
| BASE | |
| OVERLAY | |
| BOTH | |
Definition at line 132 of file type_data.hpp.
|
private |
Definition at line 39 of file type_data.cpp.
Referenced by reset().
|
private |
Definition at line 217 of file type_data.cpp.
References DBG_G, i, lazy_initialization(), t_translation::NO_LAYER, terrain_type::number(), tcodeToTerrain_, and terrainList_.
Referenced by get_terrain_info(), is_known(), underlying_def_terrain(), underlying_mvt_terrain(), and underlying_union_terrain().
|
static |
Definition at line 34 of file type_data.cpp.
References singleton_.
Referenced by movetype::terrain_info::data::calc_value(), help::generate_terrain_sections(), gui2::get_mp_tooltip(), and help::terrain_topic_generator::operator()().
| t_string terrain_type_data::get_terrain_editor_string | ( | const t_translation::terrain_code & | terrain | ) | const |
Definition at line 179 of file type_data.cpp.
References terrain_type::description(), terrain_type::editor_name(), get_terrain_info(), and get_underlying_terrain_string().
| const terrain_type & terrain_type_data::get_terrain_info | ( | const t_translation::terrain_code & | terrain | ) | const |
Get the corresponding terrain_type information object for a given type of terrain.
If the given terrain is not known, and can not be constructed from the known terrains, returns a default-constructed instance.
Definition at line 113 of file type_data.cpp.
References game_config::default_terrain, find_or_create(), i, and tcodeToTerrain_.
Referenced by get_terrain_editor_string(), get_terrain_string(), get_underlying_terrain_string(), gives_healing(), is_castle(), is_keep(), is_village(), and merge_terrains().
| t_string terrain_type_data::get_terrain_string | ( | const t_translation::terrain_code & | terrain | ) | const |
Get a formatted terrain name – terrain (underlying terrains)
Definition at line 169 of file type_data.cpp.
References terrain_type::description(), get_terrain_info(), and get_underlying_terrain_string().
| t_string terrain_type_data::get_underlying_terrain_string | ( | const t_translation::terrain_code & | terrain | ) | const |
Definition at line 196 of file type_data.cpp.
References get_terrain_info(), i, terrain_type::name(), and underlying_union_terrain().
Referenced by get_terrain_editor_string(), and get_terrain_string().
|
inline |
Definition at line 125 of file type_data.hpp.
References get_terrain_info(), and terrain_type::gives_healing().
|
inline |
Definition at line 127 of file type_data.hpp.
References get_terrain_info(), and terrain_type::is_castle().
|
inline |
Definition at line 129 of file type_data.hpp.
References get_terrain_info(), and terrain_type::is_keep().
| bool terrain_type_data::is_known | ( | const t_translation::terrain_code & | terrain | ) | const |
Returns true if get_terrain_info(terrain) would succeed, or false if get_terrain_info(terrain) would return a default-constructed instance.
This has no connection to prefs::get().encountered_terrains().
Implementation note: if necessary, will trigger the lazy-creation and add the resulting terrain to the terrain list.
Definition at line 244 of file type_data.cpp.
References find_or_create(), t, and tcodeToTerrain_.
Referenced by merge_terrains().
|
inline |
Definition at line 123 of file type_data.hpp.
References get_terrain_info(), and terrain_type::is_village().
| void terrain_type_data::lazy_initialization | ( | ) | const |
On the first call to this function, parse all of the [terrain_type]s that are defined in WML.
This is separated from the constructor so that game_config_manager can create an instance while on the title screen, without the delay of loading the data (and it's likely that a different config will be loaded before entering the game).
Definition at line 47 of file type_data.cpp.
References game_config_view::child_range(), curr, DBG_G, terrain_type::editor_group(), ERR_G, game_config_, terrain_type::id(), initialized_, utils::join(), LOG_G, terrain_type::name(), terrain_type::number(), utils::split(), t, tcodeToTerrain_, and terrainList_.
Referenced by find_or_create(), list(), and map().
| const t_translation::ter_list & terrain_type_data::list | ( | ) | const |
Definition at line 100 of file type_data.cpp.
References lazy_initialization(), and terrainList_.
| const std::map< t_translation::terrain_code, terrain_type > & terrain_type_data::map | ( | ) | const |
Definition at line 107 of file type_data.cpp.
References lazy_initialization(), and tcodeToTerrain_.
| t_translation::terrain_code terrain_type_data::merge_terrains | ( | const t_translation::terrain_code & | old_t, |
| const t_translation::terrain_code & | new_t, | ||
| const merge_mode | mode, | ||
| bool | replace_if_failed = false |
||
| ) | const |
Tries to find a new terrain which is the combination of old and new terrain using the merge_settings.
Here "merge" means to find the best-fitting terrain code, it does not change any already-created instance of terrain_data. Think of using the editor's paint-with-one-layer functionality for the purpose of this.
Relevant parameters are "layer" and "replace_conflicting" "layer" specifies the layer that should be replaced (base or overlay, default is both). If "replace_conflicting" is true the new terrain will replace the old one if merging failed (using the default base if new terrain is an overlay terrain) Will return the resulting terrain or NONE_TERRAIN if merging failed
Definition at line 252 of file type_data.cpp.
References t_translation::terrain_code::base, BASE, BOTH, get_terrain_info(), is_known(), t_translation::NO_LAYER, t_translation::NONE_TERRAIN, t_translation::terrain_code::overlay, OVERLAY, t, and terrain_type::terrain_with_default_base().
|
static |
Regenerates the terrain database from the given game config.
Definition at line 28 of file type_data.cpp.
References singleton_, and terrain_type_data().
Referenced by game_config_manager::load_game_config().
| const t_translation::ter_list & terrain_type_data::underlying_def_terrain | ( | const t_translation::terrain_code & | terrain | ) | const |
The underlying defense type of the terrain.
See the notes for underlying_mvt_terrain.
Definition at line 141 of file type_data.cpp.
References find_or_create(), i, and tcodeToTerrain_.
| const t_translation::ter_list & terrain_type_data::underlying_mvt_terrain | ( | const t_translation::terrain_code & | terrain | ) | const |
The underlying movement type of the terrain.
The underlying terrain is the name of the terrain for game-logic purposes. I.e. if the terrain is simply an alias, the underlying terrain name is the name of the terrain(s) that it's aliased to.
Whether "underlying" means "only the types used in [movetype]" is determined by the terrain.cfg file, rather than the .cpp code - in 1.14, the terrain.cfg file uses only the [movetype] terrains in its alias lists.
This may start with a t_translation::PLUS or t_translation::MINUS to indicate whether the movement should be calculated as a best-of or worst-of combination. These may also occur later in the list, however if both PLUS and MINUS appear in the list then the values calculated are implementation defined behavior.
Definition at line 125 of file type_data.cpp.
References find_or_create(), i, and tcodeToTerrain_.
| const t_translation::ter_list & terrain_type_data::underlying_union_terrain | ( | const t_translation::terrain_code & | terrain | ) | const |
Unordered set of all terrains used in either underlying_mvt_terrain or underlying_def_terrain.
This does not include any PLUSes or MINUSes.
May also include the aliasof and vision_alias terrains, however vision_alias is deprecated and aliasof should probably match the movement and defense terrains.
Definition at line 154 of file type_data.cpp.
References find_or_create(), i, and tcodeToTerrain_.
Referenced by get_underlying_terrain_string().
|
private |
Definition at line 47 of file type_data.hpp.
Referenced by lazy_initialization().
|
mutableprivate |
Definition at line 46 of file type_data.hpp.
Referenced by lazy_initialization().
|
inlinestaticprivate |
Definition at line 167 of file type_data.hpp.
|
mutableprivate |
Definition at line 45 of file type_data.hpp.
Referenced by find_or_create(), get_terrain_info(), is_known(), lazy_initialization(), map(), underlying_def_terrain(), underlying_mvt_terrain(), and underlying_union_terrain().
|
mutableprivate |
Definition at line 43 of file type_data.hpp.
Referenced by find_or_create(), lazy_initialization(), and list().