Public Member Functions | |
data (const parameters ¶ms) | |
Constructor. More... | |
data (const config &cfg, const parameters ¶ms) | |
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 parameters & | params () const |
Read-only access to our parameters. More... | |
int | value (const t_translation::t_terrain &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::t_terrain, int > | cache_t |
Private Member Functions | |
int | calc_value (const t_translation::t_terrain &terrain, const terrain_info *fallback, unsigned recurse_count) const |
Calculates the value associated with the given terrain. More... | |
int | value (const t_translation::t_terrain &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 parameters & | params_ |
Various parameters used when calculating values. More... | |
Definition at line 89 of file movetype.cpp.
|
private |
Definition at line 139 of file movetype.cpp.
|
inlineexplicit |
Constructor.
params must be long-lived (typically a static variable).
Definition at line 94 of file movetype.cpp.
|
inline |
Constructor.
params must be long-lived (typically a static variable).
Definition at line 99 of file movetype.cpp.
|
inline |
Definition at line 105 of file movetype.cpp.
|
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.
[in] | terrain | The terrain whose value is requested. |
[in] | fallback | Consulted if we are missing data. |
[in] | recurse_count | Detects (probable) infinite recursion. |
Definition at line 272 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).
[in] | cascade | Cache clearing will be cascaded into this terrain_info. |
Definition at line 154 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 169 of file movetype.cpp.
References config::attribute_range().
|
inline |
Tests for no data in this object.
Definition at line 114 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.
[in] | new_values | The new values. |
[in] | overwrite | If true, the new values overwrite the old. If false, the new values are added to the old. |
[in] | cascade | Cache clearing will be cascaded into this terrain_info. |
Definition at line 195 of file movetype.cpp.
References config::attribute_range(), movetype::terrain_info::clear_cache(), config::attribute_value::to_int(), and movetype::terrain_info::value().
|
inline |
Read-only access to our parameters.
Definition at line 119 of file movetype.cpp.
References params_.
|
inline |
Returns the value associated with the given terrain.
Definition at line 121 of file movetype.cpp.
|
private |
Returns the value associated with the given terrain (possibly cached).
[in] | terrain | The terrain whose value is requested. |
[in] | fallback | Consulted if we are missing data. |
[in] | recurse_count | Detects (probable) infinite recursion. |
Definition at line 377 of file movetype.cpp.
References cache_.
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.
[out] | out_cfg | The config that will receive the data. |
[in] | child_name | If 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 232 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.
[out] | out_cfg | The config that will receive the data. |
[in] | child_name | If 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] | fallback | If not nullptr, its data will be merged with ours for the write. |
Definition at line 252 of file movetype.cpp.
References config::add_child(), config::empty(), config::merge_with(), and movetype::terrain_info::write().
|
mutableprivate |
Cache of values based on the config.
Definition at line 144 of file movetype.cpp.
Referenced by clear_cache().
|
private |
Config describing the terrain values.
Definition at line 142 of file movetype.cpp.
Referenced by empty().
|
private |
Various parameters used when calculating values.
Definition at line 146 of file movetype.cpp.
Referenced by params().