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 |
| 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) |
| 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::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 parameters & | params_ |
| Various parameters used when calculating values. More... | |
Definition at line 89 of file movetype.cpp.
|
private |
Definition at line 142 of file movetype.cpp.
|
inlineexplicit |
Constructor.
params must be long-lived (typically a static variable).
Definition at line 96 of file movetype.cpp.
|
inline |
Constructor.
params must be long-lived (typically a static variable).
Definition at line 103 of file movetype.cpp.
|
inline |
Definition at line 109 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 273 of file movetype.cpp.
References ERR_CF, terrain_type_data::get(), i, terrain_type::is_indivisible(), t_translation::MINUS, t_translation::PLUS, movetype::terrain_info::value(), t_translation::write_terrain_code(), and WRN_CF.
| void movetype::terrain_info::data::clear_cache | ( | ) | const |
Clears the cached data (presumably our fallback has changed).
Definition at line 156 of file movetype.cpp.
References 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 168 of file movetype.cpp.
References _(), config::attribute_range(), and movetype::terrain_info::value().
|
inline |
Tests for no data in this object.
Definition at line 118 of file movetype.cpp.
References cfg_, and config::empty().
| void movetype::terrain_info::data::merge | ( | const config & | new_values, |
| bool | overwrite | ||
| ) |
Merges the given config over the existing costs.
After calling this function, the caller must call clear_cache on any terrain_info that uses this one as a fallback.
| [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. |
Definition at line 197 of file movetype.cpp.
References config::attribute_range(), config_attribute_value::to_int(), and movetype::terrain_info::value().
|
inline |
Read-only access to our parameters.
Definition at line 122 of file movetype.cpp.
References params_.
|
inline |
Returns the value associated with the given terrain.
Definition at line 124 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 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.
| [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 233 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 253 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 147 of file movetype.cpp.
Referenced by clear_cache().
|
private |
Config describing the terrain values.
Definition at line 145 of file movetype.cpp.
Referenced by empty().
|
private |
Various parameters used when calculating values.
Definition at line 149 of file movetype.cpp.
Referenced by params().