The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
movetype::terrain_info::data Class Reference

Public Member Functions

 data (const parameters &params)
 Constructor. More...
 
 data (const config &cfg, const parameters &params)
 Constructor. More...
 
 data (const data &that)
 
void clear_cache (const terrain_info *cascade) const
 Clears the cached data (presumably our fallback has changed). More...
 
bool config_has_changes (const config &new_values, bool overwrite) const
 Tests if merging new_values would result in changes. More...
 
bool empty () const
 Tests for no data in this object. More...
 
void merge (const config &new_values, bool overwrite, const terrain_info *cascade)
 Merges the given config over the existing costs. More...
 
const parametersparams () const
 Read-only access to our parameters. More...
 
int value (const t_translation::terrain_code &terrain, const terrain_info *fallback) const
 Returns the value associated with the given terrain. More...
 
void write (config &out_cfg, const std::string &child_name) const
 If there is data, writes it to the config. More...
 
void write (config &out_cfg, const std::string &child_name, const terrain_info *fallback) const
 If there is (merged) data, writes it to the config. More...
 

Private Types

typedef std::map
< t_translation::terrain_code,
int > 
cache_t
 

Private Member Functions

int calc_value (const t_translation::terrain_code &terrain, const terrain_info *fallback, unsigned recurse_count) const
 Calculates the value associated with the given terrain. More...
 
int value (const t_translation::terrain_code &terrain, const terrain_info *fallback, unsigned recurse_count) const
 Returns the value associated with the given terrain (possibly cached). More...
 

Private Attributes

config cfg_
 Config describing the terrain values. More...
 
cache_t cache_
 Cache of values based on the config. More...
 
const parametersparams_
 Various parameters used when calculating values. More...
 

Detailed Description

Definition at line 85 of file movetype.cpp.

Member Typedef Documentation

Definition at line 135 of file movetype.cpp.

Constructor & Destructor Documentation

movetype::terrain_info::data::data ( const parameters params)
inlineexplicit

Constructor.

params must be long-lived (typically a static variable).

Definition at line 90 of file movetype.cpp.

movetype::terrain_info::data::data ( const config cfg,
const parameters params 
)
inline

Constructor.

params must be long-lived (typically a static variable).

Definition at line 95 of file movetype.cpp.

movetype::terrain_info::data::data ( const data that)
inline

Definition at line 101 of file movetype.cpp.

Member Function Documentation

int movetype::terrain_info::data::calc_value ( const t_translation::terrain_code terrain,
const terrain_info fallback,
unsigned  recurse_count 
) const
private

Calculates the value associated with the given terrain.

This is separate from value() to separate the calculating of the value from the caching of it.

Parameters
[in]terrainThe terrain whose value is requested.
[in]fallbackConsulted if we are missing data.
[in]recurse_countDetects (probable) infinite recursion.

Definition at line 268 of file movetype.cpp.

References ERR_CF, game_config_manager::get(), i, t_translation::MINUS, t_translation::PLUS, gui2::terrain, game_config_manager::terrain_types(), movetype::terrain_info::value(), t_translation::write_terrain_code(), and WRN_CF.

void movetype::terrain_info::data::clear_cache ( const terrain_info cascade) const

Clears the cached data (presumably our fallback has changed).

Parameters
[in]cascadeCache clearing will be cascaded into this terrain_info.

Definition at line 150 of file movetype.cpp.

References cache_, and movetype::terrain_info::clear_cache().

bool movetype::terrain_info::data::config_has_changes ( const config new_values,
bool  overwrite 
) const

Tests if merging new_values would result in changes.

This allows the shared data to actually work, as otherwise each unit created via WML (including unstored units) would "overwrite" its movement data with a usually identical copy and thus break the sharing.

Definition at line 165 of file movetype.cpp.

References a, and config::attribute_range().

bool movetype::terrain_info::data::empty ( ) const
inline

Tests for no data in this object.

Definition at line 110 of file movetype.cpp.

References cfg_, and config::empty().

void movetype::terrain_info::data::merge ( const config new_values,
bool  overwrite,
const terrain_info cascade 
)

Merges the given config over the existing costs.

Parameters
[in]new_valuesThe new values.
[in]overwriteIf true, the new values overwrite the old. If false, the new values are added to the old.
[in]cascadeCache clearing will be cascaded into this terrain_info.

Definition at line 191 of file movetype.cpp.

References a, config::attribute_range(), movetype::terrain_info::clear_cache(), config_attribute_value::to_int(), and movetype::terrain_info::value().

const parameters& movetype::terrain_info::data::params ( ) const
inline

Read-only access to our parameters.

Definition at line 115 of file movetype.cpp.

References params_.

int movetype::terrain_info::data::value ( const t_translation::terrain_code terrain,
const terrain_info fallback 
) const
inline

Returns the value associated with the given terrain.

Definition at line 117 of file movetype.cpp.

int movetype::terrain_info::data::value ( const t_translation::terrain_code terrain,
const terrain_info fallback,
unsigned  recurse_count 
) const
private

Returns the value associated with the given terrain (possibly cached).

Parameters
[in]terrainThe terrain whose value is requested.
[in]fallbackConsulted if we are missing data.
[in]recurse_countDetects (probable) infinite recursion.

Definition at line 373 of file movetype.cpp.

void movetype::terrain_info::data::write ( config out_cfg,
const std::string &  child_name 
) const

If there is data, writes it to the config.

If there is data, writes it to a config.

Parameters
[out]out_cfgThe config that will receive the data.
[in]child_nameIf not empty, create and write to a child config with this tag. This child will not be created if there is no data to write.

Definition at line 228 of file movetype.cpp.

References config::add_child(), and config::merge_with().

void movetype::terrain_info::data::write ( config out_cfg,
const std::string &  child_name,
const terrain_info fallback 
) const

If there is (merged) data, writes it to the config.

Writes merged data to a config.

Parameters
[out]out_cfgThe config that will receive the data.
[in]child_nameIf not empty, create and write to a child config with this tag. This will be created even if there is no data to write.
[in]fallbackIf not nullptr, its data will be merged with ours for the write.

Definition at line 248 of file movetype.cpp.

References config::add_child(), config::empty(), config::merge_with(), and movetype::terrain_info::write().

Member Data Documentation

cache_t movetype::terrain_info::data::cache_
mutableprivate

Cache of values based on the config.

Definition at line 140 of file movetype.cpp.

Referenced by clear_cache().

config movetype::terrain_info::data::cfg_
private

Config describing the terrain values.

Definition at line 138 of file movetype.cpp.

Referenced by empty().

const parameters& movetype::terrain_info::data::params_
private

Various parameters used when calculating values.

Definition at line 142 of file movetype.cpp.

Referenced by params().


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