The Battle for Wesnoth  1.19.13+dev
Macros | Functions | Variables
location.cpp File Reference

Routines related to game-maps, terrain, locations, directions. More...

#include <cassert>
#include "map/location.hpp"
#include "config.hpp"
#include "formula/string_utils.hpp"
#include "gettext.hpp"
#include "log.hpp"
#include "serialization/string_utils.hpp"
#include "utils/math.hpp"
Include dependency graph for location.cpp:

Go to the source code of this file.

Macros

#define ERR_CF   LOG_STREAM(err, log_config)
 
#define sgn(x)   ((x) < 0 ? -1 : 1)
 

Functions

std::ostream & operator<< (std::ostream &s, const map_location &l)
 Dumps a position on a stream, for debug purposes. More...
 
std::ostream & operator<< (std::ostream &s, const std::vector< map_location > &v)
 Dumps a vector of positions on a stream, for debug purposes. More...
 
std::ostream & operator<< (std::ostream &s, map_location::direction dir)
 Print a direction to stream. More...
 
std::size_t hash_value (const map_location &a)
 
static bool is_vertically_higher_than (const map_location &m1, const map_location &m2)
 
void write_location_range (const std::set< map_location > &locs, config &cfg)
 Write a set of locations into a config using ranges, adding keys x=x1,..,xn and y=y1a-y1b,..,yna-ynb. More...
 
static map_location read_locations_helper (const std::string &xi, const std::string &yi)
 
void read_locations (const config &cfg, std::vector< map_location > &locs)
 Parse x,y keys of a config into a vector of locations. More...
 
void write_locations (const std::vector< map_location > &locs, config &cfg)
 Write a vector of locations into a config adding keys x=x1,x2,..,xn and y=y1,y2,..,yn. More...
 
void get_adjacent_tiles (const map_location &a, map_location *res)
 Function which, given a location, will place all adjacent locations in res. More...
 
std::array< map_location, 6 > get_adjacent_tiles (const map_location &center)
 Returns an array of the six hexes adjacent to center. More...
 
bool tiles_adjacent (const map_location &a, const map_location &b)
 Function which tells if two locations are adjacent. More...
 
std::size_t distance_between (const map_location &a, const map_location &b)
 Function which gives the number of hexes between two tiles (i.e. More...
 

Variables

static lg::log_domain log_config ("config")
 

Detailed Description

Routines related to game-maps, terrain, locations, directions.

etc.

Definition in file location.cpp.

Macro Definition Documentation

◆ ERR_CF

#define ERR_CF   LOG_STREAM(err, log_config)

Definition at line 34 of file location.cpp.

◆ sgn

#define sgn (   x)    ((x) < 0 ? -1 : 1)

Function Documentation

◆ distance_between()

std::size_t distance_between ( const map_location a,
const map_location b 
)

Function which gives the number of hexes between two tiles (i.e.

the minimum number of hexes that have to be traversed to get from one hex to the other).

Definition at line 583 of file location.cpp.

References b, map_location::x, and map_location::y.

Referenced by attack_type::abilities_special_tooltips(), ability_active_adjacent_helper(), ai::ai_default_rca::move_to_targets_phase::access_points(), actions::actor_sighted(), ai::protect_goal::add_targets(), ai::attack_analysis::attack_close(), battle_context_unit_stats::battle_context_unit_stats(), soundsource::positional_source::calculate_volume(), characterization_distance_direction(), ai::ai_default_rca::move_to_targets_phase::choose_move(), events::mouse_handler::current_unit_attacks_from(), wfl::builtins::DEFINE_WFL_FUNCTION(), ai::ai_default_rca::goto_phase::evaluate(), ai::ai_default_rca::leader_shares_keep_phase::execute(), unit_filter_impl::unit_filter_compound::fill(), ai::default_ai_context_impl::find_targets(), ai::ai_default_rca::get_villages_phase::find_villages(), unit::get_abilities(), unit::get_ability_bool(), wfl::function_symbol_table::get_builtins(), unit::halo_or_icon_abilities(), attack_type::has_filter_special_or_ability(), attack_type::has_special_or_ability(), attack_type::has_special_or_ability_with_filter(), lua_map_location::intf_distance_between(), ai::readonly_context_impl::nearest_keep(), rank_castle_location(), reality_check_get_direction_helper(), display_context::unit_can_move(), and attack_type::weapon_specials_impl_adj().

◆ get_adjacent_tiles() [1/2]

void get_adjacent_tiles ( const map_location a,
map_location res 
)

Function which, given a location, will place all adjacent locations in res.

res must point to an array of 6 location objects.

Definition at line 512 of file location.cpp.

References map_location::x, and map_location::y.

Referenced by pathfind::a_star_search(), ability_active_adjacent_helper(), ai::attack_analysis::analyze(), ai::ai_default_rca::aspect_attacks_base::analyze_targets(), backstab_check(), cave_map_generator::cave_map_generator_job::build_chamber(), actions::shroud_clearer::clear_dest(), actions::shroud_clearer::clear_loc(), wfl::attack_map_callable::collect_possible_attacks(), ai::default_ai_context_impl::count_free_hexes_in_castle(), events::mouse_handler::current_unit_attacks_from(), default_map_generator_job::default_generate_map(), wfl::builtins::DEFINE_WFL_FUNCTION(), wfl::gamestate::DEFINE_WFL_FUNCTION(), ai::ai_default_rca::aspect_attacks_base::do_attack_analysis(), ai::ai_default_rca::move_to_targets_phase::enemies_along_path(), pathfind::enemy_zoc(), ai::ai_default_rca::retreat_phase::evaluate(), unit_filter_impl::unit_filter_compound::fill(), pathfind::find_routes(), ai::default_ai_context_impl::find_targets(), pathfind::find_vacant_tile(), flood_name(), default_map_generator_job::generate_river_internal(), ai::keeps_cache::get(), events::mouse_handler::get_adj_enemies(), get_adjacent_tiles(), editor::editor_map::get_contiguous_terrain_tiles(), display::get_fog_shroud_images(), tod_manager::get_illuminated_time_of_day(), ai::formula_ai::get_keeps(), game_display::get_reachmap_images(), display::get_terrain_images(), get_tiles_radius(), lua_map_location::intf_get_adjacent_tiles(), terrain_filter::match_internal(), editor::mouse_action_item::move(), editor::mouse_action_unit::move(), ai::ai_default_rca::move_to_targets_phase::move_group(), cave_map_generator::cave_map_generator_job::place_castle(), place_village(), ai::readonly_context_impl::power_projection(), ai::formula_ai::shortest_path_calculator(), display_context::unit_can_move(), unit_display::unit_mover::wait_for_anims(), and display_context::would_be_discovered().

◆ get_adjacent_tiles() [2/2]

std::array<map_location, 6> get_adjacent_tiles ( const map_location center)

Returns an array of the six hexes adjacent to center.

Definition at line 533 of file location.cpp.

References get_adjacent_tiles().

◆ hash_value()

std::size_t hash_value ( const map_location a)

Definition at line 73 of file location.cpp.

◆ is_vertically_higher_than()

static bool is_vertically_higher_than ( const map_location m1,
const map_location m2 
)
static

◆ operator<<() [1/3]

std::ostream& operator<< ( std::ostream &  s,
const map_location l 
)

Dumps a position on a stream, for debug purposes.

Definition at line 36 of file location.cpp.

References s, map_location::wml_x(), and map_location::wml_y().

◆ operator<<() [2/3]

std::ostream& operator<< ( std::ostream &  s,
const std::vector< map_location > &  v 
)

Dumps a vector of positions on a stream, for debug purposes.

Definition at line 41 of file location.cpp.

References i, and s.

◆ operator<<() [3/3]

std::ostream& operator<< ( std::ostream &  s,
map_location::direction  dir 
)

Print a direction to stream.

Print a direction's string representation to stream.

Definition at line 50 of file location.cpp.

References s, and map_location::write_direction().

◆ read_locations()

void read_locations ( const config cfg,
std::vector< map_location > &  locs 
)

Parse x,y keys of a config into a vector of locations.

Throws bad_lexical_cast if it fails to parse.

Definition at line 480 of file location.cpp.

References read_locations_helper(), utils::split(), and utils::views::transform.

Referenced by fix_rename_command(), actions::shroud_clearing_action::shroud_clearing_action(), soundsource::sourcespec::sourcespec(), and SYNCED_COMMAND_HANDLER_FUNCTION().

◆ read_locations_helper()

static map_location read_locations_helper ( const std::string &  xi,
const std::string &  yi 
)
static

Definition at line 475 of file location.cpp.

References utils::stoi().

Referenced by read_locations().

◆ tiles_adjacent()

bool tiles_adjacent ( const map_location a,
const map_location b 
)

◆ write_location_range()

void write_location_range ( const std::set< map_location > &  locs,
config cfg 
)

Write a set of locations into a config using ranges, adding keys x=x1,..,xn and y=y1a-y1b,..,yna-ynb.

Definition at line 436 of file location.cpp.

References i.

Referenced by tod_manager::to_config(), and team::write().

◆ write_locations()

void write_locations ( const std::vector< map_location > &  locs,
config cfg 
)

Write a vector of locations into a config adding keys x=x1,x2,..,xn and y=y1,y2,..,yn.

Definition at line 492 of file location.cpp.

References i.

Referenced by replay_helper::get_movement(), actions::shroud_clearing_action::write(), soundsource::sourcespec::write(), and soundsource::positional_source::write_config().

Variable Documentation

◆ log_config

lg::log_domain log_config("config") ( "config"  )
static