The Battle for Wesnoth  1.19.4+dev
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
terrain_type_data Class Reference

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

 terrain_type_data (const game_config_view &game_config)
 
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_listlist () const
 
const std::map< t_translation::terrain_code, terrain_type > & map () const
 
const terrain_typeget_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_listunderlying_mvt_terrain (const t_translation::terrain_code &terrain) const
 The underlying movement type of the terrain. More...
 
const t_translation::ter_listunderlying_def_terrain (const t_translation::terrain_code &terrain) const
 The underlying defense type of the terrain. More...
 
const t_translation::ter_listunderlying_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...
 

Private Types

using tcodeToTerrain_t = std::map< t_translation::terrain_code, terrain_type >
 

Private Member Functions

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_viewgame_config_
 

Detailed Description

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 40 of file type_data.hpp.

Member Typedef Documentation

◆ tcodeToTerrain_t

Definition at line 43 of file type_data.hpp.

Member Enumeration Documentation

◆ merge_mode

Enumerator
BASE 
OVERLAY 
BOTH 

Definition at line 119 of file type_data.hpp.

Constructor & Destructor Documentation

◆ terrain_type_data()

terrain_type_data::terrain_type_data ( const game_config_view game_config)

Definition at line 28 of file type_data.cpp.

Member Function Documentation

◆ find_or_create()

terrain_type_data::tcodeToTerrain_t::const_iterator terrain_type_data::find_or_create ( t_translation::terrain_code  terrain) const
private

◆ get_terrain_editor_string()

t_string terrain_type_data::get_terrain_editor_string ( const t_translation::terrain_code terrain) const

◆ get_terrain_info()

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 102 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().

◆ get_terrain_string()

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 158 of file type_data.cpp.

References terrain_type::description(), get_terrain_info(), and get_underlying_terrain_string().

◆ get_underlying_terrain_string()

t_string terrain_type_data::get_underlying_terrain_string ( const t_translation::terrain_code terrain) const

◆ gives_healing()

int terrain_type_data::gives_healing ( const t_translation::terrain_code terrain) const
inline

Definition at line 112 of file type_data.hpp.

References get_terrain_info(), and terrain_type::gives_healing().

◆ is_castle()

bool terrain_type_data::is_castle ( const t_translation::terrain_code terrain) const
inline

Definition at line 114 of file type_data.hpp.

References get_terrain_info(), and terrain_type::is_castle().

◆ is_keep()

bool terrain_type_data::is_keep ( const t_translation::terrain_code terrain) const
inline

Definition at line 116 of file type_data.hpp.

References get_terrain_info(), and terrain_type::is_keep().

◆ is_known()

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 233 of file type_data.cpp.

References find_or_create(), t, and tcodeToTerrain_.

Referenced by merge_terrains().

◆ is_village()

bool terrain_type_data::is_village ( const t_translation::terrain_code terrain) const
inline

Definition at line 110 of file type_data.hpp.

References get_terrain_info(), and terrain_type::is_village().

◆ lazy_initialization()

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 36 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().

◆ list()

const t_translation::ter_list & terrain_type_data::list ( ) const

Definition at line 89 of file type_data.cpp.

References lazy_initialization(), and terrainList_.

◆ map()

const std::map< t_translation::terrain_code, terrain_type > & terrain_type_data::map ( ) const

Definition at line 96 of file type_data.cpp.

References lazy_initialization(), and tcodeToTerrain_.

◆ merge_terrains()

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 241 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().

◆ underlying_def_terrain()

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 130 of file type_data.cpp.

References find_or_create(), i, and tcodeToTerrain_.

◆ underlying_mvt_terrain()

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 114 of file type_data.cpp.

References find_or_create(), i, and tcodeToTerrain_.

◆ underlying_union_terrain()

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 143 of file type_data.cpp.

References find_or_create(), i, and tcodeToTerrain_.

Referenced by get_underlying_terrain_string().

Member Data Documentation

◆ game_config_

const game_config_view& terrain_type_data::game_config_
private

Definition at line 46 of file type_data.hpp.

Referenced by lazy_initialization().

◆ initialized_

bool terrain_type_data::initialized_
mutableprivate

Definition at line 45 of file type_data.hpp.

Referenced by lazy_initialization().

◆ tcodeToTerrain_

tcodeToTerrain_t terrain_type_data::tcodeToTerrain_
mutableprivate

◆ terrainList_

t_translation::ter_list terrain_type_data::terrainList_
mutableprivate

Definition at line 42 of file type_data.hpp.

Referenced by find_or_create(), lazy_initialization(), and list().


The documentation for this class was generated from the following files: