Stores a set of data based on terrain. More...
Classes | |
class | data |
struct | parameters |
The parameters used when calculating a terrain-based value. More... | |
Public Member Functions | |
terrain_info (const parameters ¶ms, const terrain_info *fallback=nullptr, const terrain_info *cascade=nullptr) | |
Constructor. More... | |
terrain_info (const config &cfg, const parameters ¶ms, const terrain_info *fallback=nullptr, const terrain_info *cascade=nullptr) | |
Constructor. More... | |
terrain_info (const terrain_info &that, const terrain_info *fallback=nullptr, const terrain_info *cascade=nullptr) | |
Copy constructor. More... | |
~terrain_info () | |
Destructor. More... | |
terrain_info & | operator= (const terrain_info &that) |
Assignment operator. More... | |
void | clear_cache () const |
Clears the cache of values. More... | |
bool | empty () const |
Returns whether or not our data is empty. More... | |
void | merge (const config &new_values, bool overwrite) |
Merges the given config over the existing values. More... | |
int | value (const t_translation::t_terrain &terrain) const |
Returns the value associated with the given terrain. More... | |
void | write (config &cfg, const std::string &child_name="", bool merged=true) const |
Writes our data to a config. More... | |
Private Member Functions | |
const boost::shared_ptr< data > & | get_merged () const |
Returns a pointer to data the incorporates our fallback. More... | |
void | make_unique_cascade () const |
Ensures our data is not shared, and propagates to our cascade. More... | |
void | make_unique_fallback () const |
Ensures our data is not shared, and propagates to our fallback. More... | |
Private Attributes | |
boost::shared_ptr< data > | data_ |
boost::shared_ptr< data > | merged_data_ |
Never nullptr. More... | |
const terrain_info *const | fallback_ |
Created as needed. More... | |
const terrain_info *const | cascade_ |
Stores a set of data based on terrain.
Definition at line 31 of file movetype.hpp.
|
explicit |
Constructor.
[in] | params | The parameters to use when calculating values. This is stored as a reference, so it must be long-lived (typically a static variable). |
[in] | fallback | Used as a backup in case we are asked for data we do not have (think vision costs falling back to movement costs). |
[in] | cascade | A terrain_info that uses us as a fallback. (Needed to sync cache clearing.) |
Definition at line 405 of file movetype.cpp.
movetype::terrain_info::terrain_info | ( | const config & | cfg, |
const parameters & | params, | ||
const terrain_info * | fallback = nullptr , |
||
const terrain_info * | cascade = nullptr |
||
) |
Constructor.
[in] | cfg | An initial data set. |
[in] | params | The parameters to use when calculating values. This is stored as a reference, so it must be long-lived (typically a static variable). |
[in] | fallback | Used as a backup in case we are asked for data we do not have (think vision costs falling back to movement costs). |
[in] | cascade | A terrain_info that uses us as a fallback. (Needed to sync cache clearing.) |
Definition at line 426 of file movetype.cpp.
movetype::terrain_info::terrain_info | ( | const terrain_info & | that, |
const terrain_info * | fallback = nullptr , |
||
const terrain_info * | cascade = nullptr |
||
) |
Copy constructor.
[in] | that | The terran_info to copy. |
[in] | fallback | Used as a backup in case we are asked for data we do not have (think vision costs falling back to movement costs). |
[in] | cascade | A terrain_info that uses us as a fallback. (Needed to sync cache clearing.) |
Definition at line 445 of file movetype.cpp.
movetype::terrain_info::~terrain_info | ( | ) |
Destructor.
Definition at line 461 of file movetype.cpp.
void movetype::terrain_info::clear_cache | ( | ) | const |
Clears the cache of values.
Definition at line 489 of file movetype.cpp.
Referenced by movetype::terrain_info::data::clear_cache(), and movetype::terrain_info::data::merge().
bool movetype::terrain_info::empty | ( | ) | const |
Returns whether or not our data is empty.
Definition at line 499 of file movetype.cpp.
Referenced by movetype::has_jamming_data(), and movetype::has_vision_data().
|
private |
Returns a pointer to data the incorporates our fallback.
Definition at line 572 of file movetype.cpp.
References fallback_, and movetype::write().
Referenced by operator=().
|
private |
Ensures our data is not shared, and propagates to our cascade.
Definition at line 599 of file movetype.cpp.
|
private |
Ensures our data is not shared, and propagates to our fallback.
Definition at line 613 of file movetype.cpp.
References fallback_.
Merges the given config over the existing values.
[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 511 of file movetype.cpp.
References fallback_.
Referenced by unit::apply_builtin_effect(), movetype::terrain_defense::merge(), and movetype::merge().
movetype::terrain_info & movetype::terrain_info::operator= | ( | const terrain_info & | that | ) |
Assignment operator.
Definition at line 472 of file movetype.cpp.
References data_, fallback_, get_merged(), and merged_data_.
int movetype::terrain_info::value | ( | const t_translation::t_terrain & | terrain | ) | const |
Returns the value associated with the given terrain.
Definition at line 545 of file movetype.cpp.
References fallback_.
Referenced by movetype::terrain_info::data::calc_value(), movetype::terrain_defense::capped(), movetype::terrain_costs::cost(), movetype::terrain_defense::defense(), and movetype::terrain_info::data::merge().
void movetype::terrain_info::write | ( | config & | cfg, |
const std::string & | child_name = "" , |
||
bool | merged = true |
||
) | const |
Writes our data to a config.
[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. |
[in] | merged | If true, our data will be merged with our fallback's, and it is possible an empty child will be created. If false, data will not be merged, and an empty child will not be created. |
Definition at line 558 of file movetype.cpp.
References fallback_.
Referenced by actions::clearer_info::write(), movetype::terrain_info::data::write(), movetype::terrain_defense::write(), and movetype::write().
|
private |
Definition at line 78 of file movetype.hpp.
|
private |
Definition at line 75 of file movetype.hpp.
Referenced by operator=().
|
private |
Created as needed.
Definition at line 77 of file movetype.hpp.
|
mutableprivate |