The Battle for Wesnoth  1.19.19+dev
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static 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)
 
 ~terrain_type_data ()
 
void reset () const
 Clears the database and queues reinitialization on the next call to lazy_initialization. More...
 
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...
 
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 terrain_type_dataget ()
 

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_
 

Static Private Attributes

static terrain_type_datasingleton_ {nullptr}
 

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

Member Typedef Documentation

◆ tcodeToTerrain_t

Definition at line 44 of file type_data.hpp.

Member Enumeration Documentation

◆ merge_mode

Enumerator
BASE 
OVERLAY 
BOTH 

Definition at line 101 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 34 of file type_data.cpp.

References singleton_.

◆ ~terrain_type_data()

terrain_type_data::~terrain_type_data ( )

Definition at line 44 of file type_data.cpp.

References singleton_.

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_type_data * terrain_type_data::get ( )
static
Returns
A pointer to the current terrain database instance.

Definition at line 28 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()().

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

References game_config::default_terrain, find_or_create(), i, and tcodeToTerrain_.

Referenced by movetype::terrain_info::data::calc_value(), get_terrain_editor_string(), gamemap::get_terrain_info(), get_terrain_string(), get_underlying_terrain_string(), gamemap::gives_healing(), gives_healing(), gamemap::is_castle(), is_castle(), gamemap::is_keep(), is_keep(), gamemap::is_village(), is_village(), merge_terrains(), and help::terrain_topic_generator::operator()().

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

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

Referenced by gamemap::get_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 94 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 96 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 98 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 209 of file type_data.cpp.

References find_or_create(), t, and tcodeToTerrain_.

Referenced by merge_terrains(), and gamemap::read().

◆ is_village()

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

Definition at line 92 of file type_data.hpp.

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

Referenced by gamemap::set_terrain().

◆ 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 57 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 110 of file type_data.cpp.

References lazy_initialization(), and terrainList_.

Referenced by gamemap::get_terrain_list().

◆ map()

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

Definition at line 117 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 217 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().

Referenced by gamemap::set_terrain().

◆ reset()

void terrain_type_data::reset ( ) const

Clears the database and queues reinitialization on the next call to lazy_initialization.

Definition at line 50 of file type_data.cpp.

References initialized_, tcodeToTerrain_, and terrainList_.

Referenced by game_config_manager::load_game_config().

Member Data Documentation

◆ game_config_

const game_config_view& terrain_type_data::game_config_
private

Definition at line 47 of file type_data.hpp.

Referenced by lazy_initialization().

◆ initialized_

bool terrain_type_data::initialized_
mutableprivate

Definition at line 46 of file type_data.hpp.

Referenced by lazy_initialization(), and reset().

◆ singleton_

terrain_type_data* terrain_type_data::singleton_ {nullptr}
inlinestaticprivate

Definition at line 136 of file type_data.hpp.

Referenced by get(), terrain_type_data(), and ~terrain_type_data().

◆ tcodeToTerrain_

tcodeToTerrain_t terrain_type_data::tcodeToTerrain_
mutableprivate

◆ terrainList_

t_translation::ter_list terrain_type_data::terrainList_
mutableprivate

Definition at line 43 of file type_data.hpp.

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


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