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

Stores a set of data based on terrain. More...

Inheritance diagram for movetype::terrain_info:
Inheritance graph

Classes

class  data
 
struct  parameters
 The parameters used when calculating a terrain-based value. More...
 

Public Member Functions

 terrain_info (const parameters &params, const terrain_info *fallback=nullptr, const terrain_info *cascade=nullptr)
 Constructor. More...
 
 terrain_info (const config &cfg, const parameters &params, 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_infooperator= (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< datadata_
 
boost::shared_ptr< datamerged_data_
 Never nullptr. More...
 
const terrain_info *const fallback_
 Created as needed. More...
 
const terrain_info *const cascade_
 

Detailed Description

Stores a set of data based on terrain.

Definition at line 31 of file movetype.hpp.

Constructor & Destructor Documentation

movetype::terrain_info::terrain_info ( const parameters params,
const terrain_info fallback = nullptr,
const terrain_info cascade = nullptr 
)
explicit

Constructor.

Parameters
[in]paramsThe parameters to use when calculating values. This is stored as a reference, so it must be long-lived (typically a static variable).
[in]fallbackUsed as a backup in case we are asked for data we do not have (think vision costs falling back to movement costs).
[in]cascadeA terrain_info that uses us as a fallback. (Needed to sync cache clearing.)
Note
The fallback/cascade mechanism is a bit fragile and really should only be used by movetype.

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.

Parameters
[in]cfgAn initial data set.
[in]paramsThe parameters to use when calculating values. This is stored as a reference, so it must be long-lived (typically a static variable).
[in]fallbackUsed as a backup in case we are asked for data we do not have (think vision costs falling back to movement costs).
[in]cascadeA terrain_info that uses us as a fallback. (Needed to sync cache clearing.)
Note
The fallback/cascade mechanism is a bit fragile and really should only be used by movetype.

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.

Parameters
[in]thatThe terran_info to copy.
[in]fallbackUsed as a backup in case we are asked for data we do not have (think vision costs falling back to movement costs).
[in]cascadeA terrain_info that uses us as a fallback. (Needed to sync cache clearing.)
Note
The fallback/cascade mechanism is a bit fragile and really should only be used by movetype.

Definition at line 445 of file movetype.cpp.

movetype::terrain_info::~terrain_info ( )

Destructor.

Definition at line 461 of file movetype.cpp.

Member Function Documentation

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().

const boost::shared_ptr< movetype::terrain_info::data > & movetype::terrain_info::get_merged ( ) const
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=().

void movetype::terrain_info::make_unique_cascade ( ) const
private

Ensures our data is not shared, and propagates to our cascade.

Definition at line 599 of file movetype.cpp.

void movetype::terrain_info::make_unique_fallback ( ) const
private

Ensures our data is not shared, and propagates to our fallback.

Definition at line 613 of file movetype.cpp.

References fallback_.

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

Merges the given config over the existing values.

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.

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
void movetype::terrain_info::write ( config cfg,
const std::string child_name = "",
bool  merged = true 
) const

Writes our data to a config.

Parameters
[out]cfgThe config that will receive the data.
[in]child_nameIf not empty, create and write to a child config with this tag.
[in]mergedIf 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().

Member Data Documentation

const terrain_info* const movetype::terrain_info::cascade_
private

Definition at line 78 of file movetype.hpp.

boost::shared_ptr<data> movetype::terrain_info::data_
private

Definition at line 75 of file movetype.hpp.

Referenced by operator=().

const terrain_info* const movetype::terrain_info::fallback_
private

Created as needed.

Definition at line 77 of file movetype.hpp.

boost::shared_ptr<data> movetype::terrain_info::merged_data_
mutableprivate

Never nullptr.

Definition at line 76 of file movetype.hpp.

Referenced by operator=().


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