The Battle for Wesnoth  1.15.1+dev
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes | Static Private Attributes | Friends | List of all members
movetype Class Reference

The basic "size" of the unit - flying, small land, large land, etc. More...

#include <movetype.hpp>

Classes

class  resistances
 Stores a set of resistances. More...
 
class  terrain_costs
 A const-only interface for how many (movement, vision, or "jamming") points a unit needs for each hex. More...
 
class  terrain_defense
 Stores a set of defense levels. More...
 
class  terrain_info
 Stores a set of data based on terrain, in some cases with raw pointers to other instances of terrain_info (the fallback_). More...
 

Public Member Functions

 movetype ()
 Default constructor. More...
 
 movetype (const config &cfg)
 Constructor from a config. More...
 
 movetype (const movetype &that)
 Copy constructor. More...
 
 movetype (movetype &&that)
 Move constructor. More...
 
movetypeoperator= (const movetype &that)
 
movetypeoperator= (movetype &&that)
 
 ~movetype ()=default
 
terrain_defenseget_defense ()
 
resistancesget_resistances ()
 
const terrain_costsget_movement () const
 
const terrain_costsget_vision () const
 
const terrain_costsget_jamming () const
 
const terrain_defenseget_defense () const
 
const resistancesget_resistances () const
 
bool is_flying () const
 Returns whether or not *this is flagged as a flying movement type. More...
 
void set_flying (bool flies=true)
 Sets whether or not *this is flagged as a flying movement type. More...
 
int movement_cost (const t_translation::terrain_code &terrain, bool slowed=false) const
 Returns the cost to move through the indicated terrain. More...
 
int vision_cost (const t_translation::terrain_code &terrain, bool slowed=false) const
 Returns the cost to see through the indicated terrain. More...
 
int jamming_cost (const t_translation::terrain_code &terrain, bool slowed=false) const
 Returns the cost to "jam" through the indicated terrain. More...
 
int defense_modifier (const t_translation::terrain_code &terrain) const
 Returns the defensive value of the indicated terrain. More...
 
int resistance_against (const attack_type &attack) const
 Returns the resistance against the indicated attack. More...
 
int resistance_against (const std::string &damage_type) const
 Returns the resistance against the indicated damage type. More...
 
utils::string_map damage_table () const
 Returns a map from attack types to resistances. More...
 
bool has_terrain_defense_caps (const std::set< t_translation::terrain_code > &ts) const
 Returns whether or not there are any terrain caps with respect to a set of terrains. More...
 
bool has_vision_data () const
 Returns whether or not there are any vision-specific costs. More...
 
bool has_jamming_data () const
 Returns whether or not there are any jamming-specific costs. More...
 
void merge (const config &new_cfg, bool overwrite=true)
 Merges the given config over the existing data, the config should have zero or more children named "movement_costs", "defense", etc. More...
 
void merge (const config &new_cfg, const std::string &applies_to, bool overwrite=true)
 Merges the given config over the existing data. More...
 
void write (config &cfg) const
 Writes the movement type data to the provided config. More...
 

Static Public Member Functions

static std::unique_ptr< terrain_costsread_terrain_costs (const config &cfg)
 Reverse of terrain_costs::write. Never returns nullptr. More...
 

Static Public Attributes

static const int UNREACHABLE = 99
 Magic value that signifies a hex is unreachable. More...
 
static const std::set< std::string > effects
 The set of applicable effects for movement types. More...
 

Private Attributes

terrain_info movement_
 
terrain_info vision_
 
terrain_info jamming_
 
terrain_defense defense_
 
resistances resist_
 
bool flying_
 

Static Private Attributes

static const terrain_info::parameters mvj_params_ {1, movetype::UNREACHABLE}
 Limits for movement, vision and jamming. More...
 

Friends

void swap (movetype &a, movetype &b)
 Swap function for the movetype class, including its terrain_info members. More...
 
void swap (movetype::terrain_info &a, movetype::terrain_info &b)
 

Detailed Description

The basic "size" of the unit - flying, small land, large land, etc.

This encompasses terrain costs, defenses, and resistances.

This class is used for both [movetype] and [unit] configs, which use the same data in their configs for [movement_costs], [defense], etc. However, the data for whether the unit flies is historically held in [movetype]'s "flies" vs [unit]'s "flying".

Existing behavior of 1.14:

Todo:
make this more logical. Ideas:
  • for 1.15, support both "flying" and "flies" in [movetype]
  • for 1.17 or later, drop the "flies"

Definition at line 41 of file movetype.hpp.

Constructor & Destructor Documentation

◆ movetype() [1/4]

movetype::movetype ( )

Default constructor.

Definition at line 787 of file movetype.cpp.

◆ movetype() [2/4]

movetype::movetype ( const config cfg)
explicit

Constructor from a config.

Definition at line 801 of file movetype.cpp.

References flying_.

◆ movetype() [3/4]

movetype::movetype ( const movetype that)

Copy constructor.

Definition at line 817 of file movetype.cpp.

◆ movetype() [4/4]

movetype::movetype ( movetype &&  that)

Move constructor.

Definition at line 830 of file movetype.cpp.

◆ ~movetype()

movetype::~movetype ( )
default

Member Function Documentation

◆ damage_table()

utils::string_map movetype::damage_table ( ) const
inline

Returns a map from attack types to resistances.

Definition at line 277 of file movetype.hpp.

Referenced by help::unit_topic_generator::operator()().

◆ defense_modifier()

int movetype::defense_modifier ( const t_translation::terrain_code terrain) const
inline

◆ get_defense() [1/2]

terrain_defense& movetype::get_defense ( )
inline

Definition at line 242 of file movetype.hpp.

Referenced by help::unit_topic_generator::operator()().

◆ get_defense() [2/2]

const terrain_defense& movetype::get_defense ( ) const
inline

Definition at line 248 of file movetype.hpp.

◆ get_jamming()

const terrain_costs& movetype::get_jamming ( ) const
inline

Definition at line 247 of file movetype.hpp.

Referenced by pathfind::jamming_path::jamming_path().

◆ get_movement()

const terrain_costs& movetype::get_movement ( ) const
inline

◆ get_resistances() [1/2]

resistances& movetype::get_resistances ( )
inline

Definition at line 243 of file movetype.hpp.

Referenced by gui2::unit_preview_pane::set_displayed_type().

◆ get_resistances() [2/2]

const resistances& movetype::get_resistances ( ) const
inline

Definition at line 249 of file movetype.hpp.

◆ get_vision()

const terrain_costs& movetype::get_vision ( ) const
inline

◆ has_jamming_data()

bool movetype::has_jamming_data ( ) const
inline

Returns whether or not there are any jamming-specific costs.

Definition at line 285 of file movetype.hpp.

◆ has_terrain_defense_caps()

bool movetype::has_terrain_defense_caps ( const std::set< t_translation::terrain_code > &  ts) const

Returns whether or not there are any terrain caps with respect to a set of terrains.

Checks if we have a defense cap (nontrivial min value) for any of the given terrain types.

Definition at line 843 of file movetype.cpp.

References movetype::terrain_defense::capped(), defense_, and t.

Referenced by help::unit_topic_generator::operator()().

◆ has_vision_data()

bool movetype::has_vision_data ( ) const
inline

Returns whether or not there are any vision-specific costs.

Definition at line 283 of file movetype.hpp.

◆ is_flying()

bool movetype::is_flying ( ) const
inline

Returns whether or not *this is flagged as a flying movement type.

Definition at line 252 of file movetype.hpp.

◆ jamming_cost()

int movetype::jamming_cost ( const t_translation::terrain_code terrain,
bool  slowed = false 
) const
inline

Returns the cost to "jam" through the indicated terrain.

Definition at line 263 of file movetype.hpp.

References game_config::sounds::status::slowed.

Referenced by help::unit_topic_generator::operator()().

◆ merge() [1/2]

void movetype::merge ( const config new_cfg,
bool  overwrite = true 
)

Merges the given config over the existing data, the config should have zero or more children named "movement_costs", "defense", etc.

Merges the given config over the existing data.

If overwrite is false, the new values will be added to the old.

Definition at line 855 of file movetype.cpp.

References config::child_range(), effects, and flying_.

Referenced by unit::apply_builtin_effect(), unit_type::build_help_index(), unit::init(), and help::unit_topic_generator::operator()().

◆ merge() [2/2]

void movetype::merge ( const config new_cfg,
const std::string &  applies_to,
bool  overwrite = true 
)

Merges the given config over the existing data.

applies_to which type of movement to change ("movement_costs", etc) new_cfg data which could be one of the children of the config for the two-argument form of this function.

Definition at line 871 of file movetype.cpp.

References defense_, effects, jamming_, movetype::terrain_info::merge(), movetype::terrain_defense::merge(), movetype::resistances::merge(), movement_, resist_, and vision_.

◆ movement_cost()

int movetype::movement_cost ( const t_translation::terrain_code terrain,
bool  slowed = false 
) const
inline

◆ operator=() [1/2]

movetype & movetype::operator= ( const movetype that)

Definition at line 514 of file movetype.cpp.

References swap.

◆ operator=() [2/2]

movetype & movetype::operator= ( movetype &&  that)

Definition at line 521 of file movetype.cpp.

References swap.

◆ read_terrain_costs()

std::unique_ptr< movetype::terrain_costs > movetype::read_terrain_costs ( const config cfg)
static

Reverse of terrain_costs::write. Never returns nullptr.

Reverse of terrain_costs::write.

Never returns nullptr.

Parameters
[in]cfgAn initial data set

Definition at line 420 of file movetype.cpp.

References mvj_params_.

◆ resistance_against() [1/2]

int movetype::resistance_against ( const attack_type attack) const
inline

Returns the resistance against the indicated attack.

Definition at line 271 of file movetype.hpp.

Referenced by unit::resistance_against().

◆ resistance_against() [2/2]

int movetype::resistance_against ( const std::string &  damage_type) const
inline

Returns the resistance against the indicated damage type.

Definition at line 274 of file movetype.hpp.

◆ set_flying()

void movetype::set_flying ( bool  flies = true)
inline

Sets whether or not *this is flagged as a flying movement type.

Definition at line 254 of file movetype.hpp.

◆ vision_cost()

int movetype::vision_cost ( const t_translation::terrain_code terrain,
bool  slowed = false 
) const
inline

Returns the cost to see through the indicated terrain.

Definition at line 260 of file movetype.hpp.

References game_config::sounds::status::slowed.

Referenced by help::unit_topic_generator::operator()().

◆ write()

void movetype::write ( config cfg) const

Writes the movement type data to the provided config.

Definition at line 899 of file movetype.cpp.

References defense_, flying_, jamming_, movement_, resist_, vision_, movetype::terrain_info::write(), movetype::terrain_defense::write(), and movetype::resistances::write().

Referenced by unit::write().

Friends And Related Function Documentation

◆ swap [1/2]

void swap ( movetype a,
movetype b 
)
friend

Swap function for the movetype class, including its terrain_info members.

This relies on the two sets of the terrain_infos having their movement, vision and jamming cascaded in the same way. This assumption is provided by movetype's constructors.

Definition at line 504 of file movetype.cpp.

Referenced by operator=(), and swap().

◆ swap [2/2]

void swap ( movetype::terrain_info a,
movetype::terrain_info b 
)
friend

Member Data Documentation

◆ defense_

terrain_defense movetype::defense_
private

Definition at line 306 of file movetype.hpp.

Referenced by has_terrain_defense_caps(), merge(), swap(), and write().

◆ effects

const std::set< std::string > movetype::effects
static
Initial value:
{"movement_costs",
"vision_costs", "jamming_costs", "defense", "resistance"}

The set of applicable effects for movement types.

The set of strings defining effects which apply to movetypes.

Definition at line 297 of file movetype.hpp.

Referenced by unit::apply_builtin_effect(), merge(), and help::unit_topic_generator::operator()().

◆ flying_

bool movetype::flying_
private

Definition at line 309 of file movetype.hpp.

Referenced by merge(), movetype(), swap(), and write().

◆ jamming_

terrain_info movetype::jamming_
private

Definition at line 305 of file movetype.hpp.

Referenced by merge(), swap(), and write().

◆ movement_

terrain_info movetype::movement_
private

Definition at line 303 of file movetype.hpp.

Referenced by merge(), swap(), and write().

◆ mvj_params_

const movetype::terrain_info::parameters movetype::mvj_params_ {1, movetype::UNREACHABLE}
staticprivate

Limits for movement, vision and jamming.

Definition at line 219 of file movetype.hpp.

Referenced by movetype::terrain_info::parameters::parameters(), and read_terrain_costs().

◆ resist_

resistances movetype::resist_
private

Definition at line 307 of file movetype.hpp.

Referenced by merge(), swap(), and write().

◆ UNREACHABLE

const int movetype::UNREACHABLE = 99
static

Magic value that signifies a hex is unreachable.

The UNREACHABLE macro in the data tree should match this value.

Definition at line 155 of file movetype.hpp.

Referenced by movetype::terrain_costs::cost(), pathfind::shortest_path_calculator::cost(), game_display::draw_movement_info(), pathfind::find_vacant_tile(), movetype::terrain_info::parameters::parameters(), and REPORT_GENERATOR().

◆ vision_

terrain_info movetype::vision_
private

Definition at line 304 of file movetype.hpp.

Referenced by merge(), swap(), and write().


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