The Battle for Wesnoth  1.15.13+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...
 
const std::vector< t_string > & special_notes () const
 Contents of any [special_note] tags. 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. 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:

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

Constructor & Destructor Documentation

◆ movetype() [1/4]

movetype::movetype ( )

Default constructor.

Definition at line 799 of file movetype.cpp.

◆ movetype() [2/4]

movetype::movetype ( const config cfg)
explicit

Constructor from a config.

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

◆ movetype() [4/4]

movetype::movetype ( movetype &&  that)

Move constructor.

Definition at line 848 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 301 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 266 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 272 of file movetype.hpp.

◆ get_jamming()

const terrain_costs& movetype::get_jamming ( ) const
inline

Definition at line 271 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 267 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 273 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 309 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 862 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 307 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 276 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 287 of file movetype.hpp.

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

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

Merges the given config over the existing data.

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.

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

Definition at line 874 of file movetype.cpp.

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

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

◆ 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 890 of file movetype.cpp.

References defense_, effects, ERR_CF, 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 524 of file movetype.cpp.

References swap.

◆ operator=() [2/2]

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

Definition at line 531 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 429 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 295 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 298 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 278 of file movetype.hpp.

◆ special_notes()

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

Contents of any [special_note] tags.

Definition at line 346 of file movetype.hpp.

References write().

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

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

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

◆ write()

void movetype::write ( config cfg) const

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 513 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 355 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 343 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 358 of file movetype.hpp.

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

◆ jamming_

terrain_info movetype::jamming_
private

Definition at line 354 of file movetype.hpp.

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

◆ movement_

terrain_info movetype::movement_
private

Definition at line 352 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 243 of file movetype.hpp.

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

◆ resist_

resistances movetype::resist_
private

Definition at line 356 of file movetype.hpp.

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

◆ special_notes_

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

Definition at line 359 of file movetype.hpp.

Referenced by movetype(), 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 175 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(), REPORT_GENERATOR(), and unit_type_data::set_config().

◆ vision_

terrain_info movetype::vision_
private

Definition at line 353 of file movetype.hpp.

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


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