The Battle for Wesnoth  1.19.5+dev
Public Member Functions | Public Attributes | Private Attributes | List of all members
pathfind::full_cost_map Struct Reference

Structure which uses find_routes() to build a cost map This maps each hex to a the movements a unit will need to reach this hex. More...

#include <pathfind.hpp>

Public Member Functions

 full_cost_map (const unit &u, bool force_ignore_zoc, bool allow_teleport, const team &viewing_team, bool see_all=true, bool ignore_units=true)
 Constructs a cost-map. More...
 
 full_cost_map (bool force_ignore_zoc, bool allow_teleport, const team &viewing_team, bool see_all=true, bool ignore_units=true)
 Same as other constructor but without unit. More...
 
void add_unit (const unit &u, bool use_max_moves=true)
 Adds a units cost map to cost_map (increments the elements in cost_map) More...
 
void add_unit (const map_location &origin, const unit_type *const unit_type, int side)
 Adds a units cost map to cost_map (increments the elements in cost_map) This function can be used to generate a cost_map with a non existing unit. More...
 
int get_cost_at (map_location loc) const
 Accessor for the costs. More...
 
std::pair< int, int > get_pair_at (map_location loc) const
 Accessor for the cost/reach-amount pairs. More...
 
double get_average_cost_at (map_location loc) const
 Accessor for the costs. More...
 
virtual ~full_cost_map ()
 

Public Attributes

std::vector< std::pair< int, int > > cost_map
 

Private Attributes

const bool force_ignore_zoc_
 
const bool allow_teleport_
 
const teamviewing_team_
 
const bool see_all_
 
const bool ignore_units_
 

Detailed Description

Structure which uses find_routes() to build a cost map This maps each hex to a the movements a unit will need to reach this hex.

Can be used commutative by calling add_unit() multiple times.

Definition at line 267 of file pathfind.hpp.

Constructor & Destructor Documentation

◆ full_cost_map() [1/2]

pathfind::full_cost_map::full_cost_map ( const unit u,
bool  force_ignore_zoc,
bool  allow_teleport,
const team viewing_team,
bool  see_all = true,
bool  ignore_units = true 
)

Constructs a cost-map.

For a unit each hex is mapped to the cost the unit will need to reach this hex. Considers movement-loss caused by turn changes. Can also used with multiple units to accumulate their costs efficiently. Will also count how many units could reach a hex for easy normalization.

Parameters
uthe unit
force_ignore_zocSet to true to completely ignore zones of control.
allow_teleportSet to true to consider teleportation abilities.
viewing_teamUsually the current team, except for "show enemy moves", etc.
see_allSet to true to remove unit visibility from consideration.
ignore_unitsSet to true if units should never obstruct paths (implies ignoring ZoC as well).

Definition at line 889 of file pathfind.cpp.

References add_unit(), cost_map, resources::gameboard, gamemap_base::h(), game_board::map(), and gamemap_base::w().

◆ full_cost_map() [2/2]

pathfind::full_cost_map::full_cost_map ( bool  force_ignore_zoc,
bool  allow_teleport,
const team viewing_team,
bool  see_all = true,
bool  ignore_units = true 
)

Same as other constructor but without unit.

Use this when working with add_unit().

Definition at line 904 of file pathfind.cpp.

References cost_map, resources::gameboard, gamemap_base::h(), game_board::map(), and gamemap_base::w().

◆ ~full_cost_map()

virtual pathfind::full_cost_map::~full_cost_map ( )
inlinevirtual

Definition at line 285 of file pathfind.hpp.

Member Function Documentation

◆ add_unit() [1/2]

void pathfind::full_cost_map::add_unit ( const map_location origin,
const unit_type *const  ut,
int  side 
)

Adds a units cost map to cost_map (increments the elements in cost_map) This function can be used to generate a cost_map with a non existing unit.

Parameters
originthe location on the map from where the calculations shall start
utthe unit type we are interested in
sidethe side of the unit. Important for zocs.

Definition at line 953 of file pathfind.cpp.

References add_unit(), and unit::create().

◆ add_unit() [2/2]

void pathfind::full_cost_map::add_unit ( const unit u,
bool  use_max_moves = true 
)

Adds a units cost map to cost_map (increments the elements in cost_map)

Parameters
ua real existing unit on the map
use_max_moveswhether to use the unit's max movement or the unit's remaining movement

Definition at line 919 of file pathfind.cpp.

References allow_teleport_, cost_map, dummy, pathfind::find_routes(), force_ignore_zoc_, resources::gameboard, unit::get_location(), movetype::get_movement(), unit::get_state(), game_board::get_team(), ignore_units_, unit::movement_left(), unit::movement_type(), see_all_, unit::STATE_SLOWED, unit::total_movement(), and viewing_team_.

Referenced by add_unit(), full_cost_map(), ai::default_recruitment::recruitment::get_cost_map_of_side(), and game_lua_kernel::intf_find_cost_map().

◆ get_average_cost_at()

double pathfind::full_cost_map::get_average_cost_at ( map_location  loc) const

Accessor for the costs.

Returns
The average cost of all added units for this hex or -1 if no unit can reach the hex.

Definition at line 999 of file pathfind.cpp.

References get_pair_at(), and p.

Referenced by ai::default_recruitment::recruitment::compare_cost_maps_and_update_important_hexes().

◆ get_cost_at()

int pathfind::full_cost_map::get_cost_at ( map_location  loc) const

Accessor for the costs.

Returns
the value of the cost_map at (x, y) or -1 if value is not set or (x, y) is invalid.

Definition at line 988 of file pathfind.cpp.

References get_pair_at().

Referenced by ai::default_recruitment::recruitment::update_important_hexes().

◆ get_pair_at()

std::pair< int, int > pathfind::full_cost_map::get_pair_at ( map_location  loc) const

Accessor for the cost/reach-amount pairs.

Read comment in pathfind.hpp to cost_map.

Returns
the entry of the cost_map at (x, y) or (-1, 0) if value is not set or (x, y) is invalid.

Definition at line 970 of file pathfind.cpp.

References cost_map, resources::gameboard, gamemap_base::h(), game_board::map(), gamemap_base::on_board(), gamemap_base::w(), map_location::x, and map_location::y.

Referenced by get_average_cost_at(), get_cost_at(), and game_lua_kernel::intf_find_cost_map().

Member Data Documentation

◆ allow_teleport_

const bool pathfind::full_cost_map::allow_teleport_
private

Definition at line 300 of file pathfind.hpp.

Referenced by add_unit().

◆ cost_map

std::vector<std::pair<int, int> > pathfind::full_cost_map::cost_map

Definition at line 296 of file pathfind.hpp.

Referenced by add_unit(), full_cost_map(), and get_pair_at().

◆ force_ignore_zoc_

const bool pathfind::full_cost_map::force_ignore_zoc_
private

Definition at line 299 of file pathfind.hpp.

Referenced by add_unit().

◆ ignore_units_

const bool pathfind::full_cost_map::ignore_units_
private

Definition at line 303 of file pathfind.hpp.

Referenced by add_unit().

◆ see_all_

const bool pathfind::full_cost_map::see_all_
private

Definition at line 302 of file pathfind.hpp.

Referenced by add_unit().

◆ viewing_team_

const team& pathfind::full_cost_map::viewing_team_
private

Definition at line 301 of file pathfind.hpp.

Referenced by add_unit().


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