The Battle for Wesnoth  1.19.5+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 std::string &damage_type) const
 Returns the vulnerability to the indicated damage type (higher means takes more damage). More...
 
utils::string_map_res damage_table () const
 Returns a map from damage 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; this 3-argument version affects only the subelement identified by the applies_to argument. More...
 
const std::vector< t_string > & special_notes () const
 Contents of any [special_note] tags. More...
 
void write (config &cfg, bool include_notes) 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. 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_
 
std::vector< t_stringspecial_notes_
 

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:

Definition at line 43 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 802 of file movetype.cpp.

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

◆ movetype() [3/4]

movetype::movetype ( const movetype that)

Copy constructor.

Definition at line 822 of file movetype.cpp.

◆ movetype() [4/4]

movetype::movetype ( movetype &&  that)

Move constructor.

Definition at line 836 of file movetype.cpp.

◆ ~movetype()

movetype::~movetype ( )
default

Member Function Documentation

◆ damage_table()

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

Returns a map from damage types to resistances.

Definition at line 295 of file movetype.hpp.

References movetype::resistances::damage_table(), and resist_.

Referenced by unit::get_base_resistances(), and 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 263 of file movetype.hpp.

References defense_.

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

◆ get_defense() [2/2]

const terrain_defense& movetype::get_defense ( ) const
inline

Definition at line 269 of file movetype.hpp.

References defense_.

◆ get_jamming()

const terrain_costs& movetype::get_jamming ( ) const
inline

Definition at line 268 of file movetype.hpp.

References jamming_.

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 264 of file movetype.hpp.

References resist_.

◆ get_resistances() [2/2]

const resistances& movetype::get_resistances ( ) const
inline

Definition at line 270 of file movetype.hpp.

References resist_.

◆ get_vision()

const terrain_costs& movetype::get_vision ( ) const
inline

Definition at line 267 of file movetype.hpp.

References vision_.

Referenced by actions::shroud_clearer::clear_unit(), and pathfind::vision_path::vision_path().

◆ has_jamming_data()

bool movetype::has_jamming_data ( ) const
inline

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

Definition at line 303 of file movetype.hpp.

References movetype::terrain_info::empty(), and jamming_.

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

◆ 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 850 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 301 of file movetype.hpp.

References movetype::terrain_info::empty(), and vision_.

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

◆ is_flying()

bool movetype::is_flying ( ) const
inline

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

Definition at line 273 of file movetype.hpp.

References flying_.

Referenced by unit::is_flying().

◆ 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 284 of file movetype.hpp.

References movetype::terrain_costs::cost(), jamming_, and game_config::sounds::status::slowed.

Referenced by wfl::gamestate::DEFINE_WFL_FUNCTION(), unit::jamming_cost(), and 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.

Only those children will be affected (in the case of movement and vision the cascaded values in vision and jamming will also be affected).

If overwrite is true, the new values will replace the old ones. If it's false, the new values are relative improvements or maluses which will be applied on top of the old values.

If the old values included defense caps and overwrite is false, the calculations are done with absolute values and then changed back to the old sign. This means that merge() doesn't create or remove defense caps when overwrite is false.

If new_cfg["flying"] is provided, it overrides the old value, regardless of the value of overwrite.

This neither adds nor removes special notes. One purpose of this function is to have [unit_type][movement_costs] partially overwrite data from [unit_type]movetype=, and it would be unhelpful if an unrelated [unit_type][special_note] cleared the movetype's special notes.

Definition at line 858 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; this 3-argument version affects only the subelement identified by the applies_to argument.

Parameters
applies_towhich type of movement to change ("movement_costs", etc)
new_cfgdata which could be one of the children of the config for the two-argument form of this function.
overwriteif false, the new values will be added to the old.

Definition at line 874 of file movetype.cpp.

References defense_, ERR_CF, jamming_, movetype::terrain_defense::merge(), movetype::resistances::merge(), movetype::terrain_info::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 522 of file movetype.cpp.

References swap.

◆ operator=() [2/2]

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

Definition at line 529 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.

Never returns nullptr.

Parameters
[in]cfgAn initial data set

Definition at line 427 of file movetype.cpp.

References mvj_params_.

◆ resistance_against()

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

Returns the vulnerability to the indicated damage type (higher means takes more damage).

Definition at line 292 of file movetype.hpp.

References resist_, and movetype::resistances::resistance_against().

Referenced by unit_type::resistance_against(), and unit::resistance_value().

◆ 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 275 of file movetype.hpp.

References flying_.

◆ special_notes()

const std::vector<t_string>& movetype::special_notes ( ) const
inline

Contents of any [special_note] tags.

Definition at line 343 of file movetype.hpp.

References special_notes_.

Referenced by combine_special_notes().

◆ 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 281 of file movetype.hpp.

References movetype::terrain_costs::cost(), game_config::sounds::status::slowed, and vision_.

Referenced by wfl::gamestate::DEFINE_WFL_FUNCTION(), help::unit_topic_generator::operator()(), and unit::vision_cost().

◆ write()

void movetype::write ( config cfg,
bool  include_notes 
) const

Writes the movement type data to the provided config.

There is no default value for the include_notes argument. Given the implied contract that a class with a constructor(const config&) and a write(config&) supports round-tripping the data, the default would need to be true. However, this method has only two callers, and neither of them want to include the notes:

Movetype patching is unaffected by the notes, as they will be ignored by movetype::merge().

[store_unit] is broken by the notes, because they end up in unit::special_notes_ instead of movetype::special_notes_ after the subsequent [unstore_unit].

Parameters
cfgoutput
include_notesif false, omits any special notes

Definition at line 902 of file movetype.cpp.

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

Referenced by movetype::terrain_info::make_standalone(), and 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 511 of file movetype.cpp.

Referenced by operator=().

◆ 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 367 of file movetype.hpp.

Referenced by defense_modifier(), get_defense(), has_terrain_defense_caps(), merge(), 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 340 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 370 of file movetype.hpp.

Referenced by is_flying(), merge(), movetype(), set_flying(), and write().

◆ jamming_

terrain_info movetype::jamming_
private

Definition at line 366 of file movetype.hpp.

Referenced by get_jamming(), has_jamming_data(), jamming_cost(), merge(), and write().

◆ movement_

terrain_info movetype::movement_
private

Definition at line 364 of file movetype.hpp.

Referenced by get_movement(), merge(), movement_cost(), 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 240 of file movetype.hpp.

Referenced by read_terrain_costs().

◆ resist_

resistances movetype::resist_
private

Definition at line 368 of file movetype.hpp.

Referenced by damage_table(), get_resistances(), merge(), resistance_against(), and write().

◆ special_notes_

std::vector<t_string> movetype::special_notes_
private

Definition at line 371 of file movetype.hpp.

Referenced by movetype(), special_notes(), 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 174 of file movetype.hpp.

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

◆ vision_

terrain_info movetype::vision_
private

Definition at line 365 of file movetype.hpp.

Referenced by get_vision(), has_vision_data(), merge(), vision_cost(), and write().


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