gamemap Class Reference

Encapsulates the map of the game. More...

#include <map.hpp>

Inheritance diagram for gamemap:

Inheritance graph
[legend]
Collaboration diagram for gamemap:

Collaboration graph
[legend]

List of all members.

Public Types

enum  tborder { NO_BORDER = 0, SINGLE_TILE_BORDER }
enum  tusage { IS_MAP, IS_MASK }
enum  tmerge_mode { BASE, OVERLAY, BOTH }
enum  { MAX_PLAYERS = 9 }
 Maximum number of players supported. More...

Public Member Functions

const t_translation::t_listunderlying_mvt_terrain (t_translation::t_terrain terrain) const
const t_translation::t_listunderlying_def_terrain (t_translation::t_terrain terrain) const
const t_translation::t_listunderlying_union_terrain (t_translation::t_terrain terrain) const
const t_translation::t_listunderlying_mvt_terrain (const location &loc) const
const t_translation::t_listunderlying_def_terrain (const location &loc) const
const t_translation::t_listunderlying_union_terrain (const location &loc) const
bool is_village (t_translation::t_terrain terrain) const
int gives_healing (t_translation::t_terrain terrain) const
bool is_castle (t_translation::t_terrain terrain) const
bool is_keep (t_translation::t_terrain terrain) const
bool is_village (const location &loc) const
int gives_healing (const location &loc) const
bool is_castle (const location &loc) const
bool is_keep (const location &loc) const
 gamemap (const config &terrain_cfg, const std::string &data)
 Loads a map, with the given terrain configuration.
void read (const std::string &data)
 Reads a map.
std::string write () const
void overlay (const gamemap &m, const config &rules, const int x=0, const int y=0)
 Overlays another map onto this one at the given position.
int w () const
 Effective dimensions of the map.
int h () const
int total_width () const
 Real dimension of the map, including borders.
int total_height () const
const t_translation::t_terrain operator[] (const gamemap::location &loc) const
t_translation::t_terrain get_terrain (const location &loc) const
 Looks up terrain at a particular location.
void write_terrain (const gamemap::location &loc, config &cfg) const
 Writes the terrain at loc to cfg.
const locationstarting_position (int side) const
 Manipulate starting positions of the different sides.
int is_starting_position (const location &loc) const
int num_valid_starting_positions () const
void set_starting_position (int side, const location &loc)
bool on_board (const location &loc, const bool include_border=false) const
 Tell if a location is on the map.
bool empty () const
 Tell if the map is of 0 size.
const std::vector< location > & villages () const
 Return a list of the locations of villages on the map.
const terrain_typeget_terrain_info (const t_translation::t_terrain terrain) const
 Get the corresponding terrain_type information object for a given type of terrain.
const terrain_typeget_terrain_info (const location &loc) const
 Shortcut to get_terrain_info(get_terrain(loc)).
const t_translation::t_listget_terrain_list () const
 Gets the list of terrains.
void set_terrain (const location &loc, const t_translation::t_terrain terrain, const tmerge_mode mode=BOTH, bool replace_if_failed=false)
 Clobbers over the terrain at location 'loc', with the given terrain.
const std::map
< t_translation::t_terrain,
size_t > & 
get_weighted_terrain_frequencies () const
 Returns a list of the frequencies of different terrain types on the map, with terrain nearer the center getting weighted higher.
void remove_from_border_cache (const location &loc)
 Remove the cached border terrain at loc.
tusage get_usage () const
 Returns the usage of the map.
t_translation::t_terrain merge_terrains (const t_translation::t_terrain old_t, const t_translation::t_terrain new_t, const tmerge_mode mode, bool replace_if_failed=false)
 Tries to merge old and new terrain using the merge_settings config Relevant parameters are "layer" and "replace_conflicting" "layer" specifies the layer that should be replaced (base or overlay, default is both).

Static Public Member Functions

static int get_drawing_order (const gamemap::location &loc)
 Drawing order, copied from ordered_draw in display.hpp.

Static Public Attributes

static const std::string default_map_header = "usage=map\nborder_size=1\n\n"
 The default map header, needed for maps created with terrain_translation::write_game_map().
static const tborder default_border = gamemap::SINGLE_TILE_BORDER
 The default border style for a map.

Protected Member Functions

void clear_border_cache ()
 Clears the border cache, needed for the editor.

Protected Attributes

t_translation::t_map tiles_
location startingPositions_ [MAX_PLAYERS+1]
 The size of the starting positions array is MAX_PLAYERS + 1, because the positions themselves are numbered from 1.

Private Member Functions

int num_starting_positions () const
const t_translation::t_list operator[] (int index) const
 Allows lookup of terrain at a particular location.
bool try_merge_terrains (const t_translation::t_terrain terrain)
 Tries to find out if "terrain" can be created by combining two existing terrains Will add the resulting terrain to the terrain list if successfull.

Private Attributes

t_translation::t_list terrainList_
std::map
< t_translation::t_terrain,
terrain_type
tcodeToTerrain_
std::vector< locationvillages_
std::map< location,
t_translation::t_terrain
borderCache_
std::map
< t_translation::t_terrain,
size_t > 
terrainFrequencyCache_
int w_
 Sizes of the map area.
int h_
int total_width_
 Sizes of the map including the borders.
int total_height_
int border_size_
 The size of the border around the map.
tusage usage_
 The kind of map is being loaded.

Classes

struct  incorrect_format_exception
 Throws exception if the map file is not in the correct format. More...
struct  location
 Represents a location on the map. More...


Detailed Description

Encapsulates the map of the game.

Although the game is hexagonal, the map is stored as a grid. Each type of terrain is represented by a multiletter terrain code.

Todo:
Update for new map-format.

Definition at line 43 of file map.hpp.


Member Enumeration Documentation

Enumerator:
NO_BORDER 
SINGLE_TILE_BORDER 

Definition at line 141 of file map.hpp.

Enumerator:
IS_MAP 
IS_MASK 

Definition at line 146 of file map.hpp.

Enumerator:
BASE 
OVERLAY 
BOTH 

Definition at line 151 of file map.hpp.

anonymous enum

Maximum number of players supported.

Warning: when you increase this, you need to add more definitions to the team_colors.cfg file.

Enumerator:
MAX_PLAYERS 

Definition at line 239 of file map.hpp.


Constructor & Destructor Documentation

gamemap::gamemap ( const config cfg,
const std::string &  data 
)

Loads a map, with the given terrain configuration.

gamemap constructor

Data should be a series of lines, with each character representing one hex on the map. Starting locations are represented by numbers, and will be of type keep.

Parameters:
cfg the game config
data the mapdata to load

Definition at line 288 of file map.cpp.

References create_terrain_maps(), DBG_G, config::get_children(), read(), tcodeToTerrain_, and terrainList_.


Member Function Documentation

const t_translation::t_list & gamemap::underlying_mvt_terrain ( t_translation::t_terrain  terrain  )  const

const t_translation::t_list & gamemap::underlying_def_terrain ( t_translation::t_terrain  terrain  )  const

const t_translation::t_list & gamemap::underlying_union_terrain ( t_translation::t_terrain  terrain  )  const

static int gamemap::get_drawing_order ( const gamemap::location loc  )  [inline, static]

Drawing order, copied from ordered_draw in display.hpp.

This returns the order in which the units should be drawn so they overlap propererly.

Definition at line 113 of file map.hpp.

References gamemap::location::x, and gamemap::location::y.

Referenced by game_display::draw(), editor_display::draw(), game_display::draw_movement_info(), display::draw_text_in_hex(), unit_frame::redraw(), and unit::redraw_unit().

const t_translation::t_list& gamemap::underlying_mvt_terrain ( const location loc  )  const [inline]

Definition at line 116 of file map.hpp.

References get_terrain(), and underlying_mvt_terrain().

const t_translation::t_list& gamemap::underlying_def_terrain ( const location loc  )  const [inline]

Definition at line 118 of file map.hpp.

References get_terrain(), and underlying_def_terrain().

const t_translation::t_list& gamemap::underlying_union_terrain ( const location loc  )  const [inline]

Definition at line 120 of file map.hpp.

References get_terrain(), and underlying_union_terrain().

bool gamemap::is_village ( t_translation::t_terrain  terrain  )  const [inline]

int gamemap::gives_healing ( t_translation::t_terrain  terrain  )  const [inline]

bool gamemap::is_castle ( t_translation::t_terrain  terrain  )  const [inline]

bool gamemap::is_keep ( t_translation::t_terrain  terrain  )  const [inline]

bool gamemap::is_village ( const location loc  )  const [inline]

Definition at line 132 of file map.hpp.

References get_terrain(), is_village(), and on_board().

int gamemap::gives_healing ( const location loc  )  const [inline]

Definition at line 134 of file map.hpp.

References get_terrain(), gives_healing(), and on_board().

bool gamemap::is_castle ( const location loc  )  const [inline]

Definition at line 136 of file map.hpp.

References get_terrain(), is_castle(), and on_board().

bool gamemap::is_keep ( const location loc  )  const [inline]

Definition at line 138 of file map.hpp.

References get_terrain(), is_keep(), and on_board().

void gamemap::read ( const std::string &  data  ) 

std::string gamemap::write (  )  const

void gamemap::overlay ( const gamemap m,
const config rules,
const int  x = 0,
const int  y = 0 
)

int gamemap::w (  )  const [inline]

int gamemap::h (  )  const [inline]

int gamemap::total_width (  )  const [inline]

Real dimension of the map, including borders.

Definition at line 175 of file map.hpp.

References total_width_.

Referenced by image::getMinimap().

int gamemap::total_height (  )  const [inline]

Definition at line 176 of file map.hpp.

References total_height_.

Referenced by image::getMinimap().

const t_translation::t_terrain gamemap::operator[] ( const gamemap::location loc  )  const [inline]

Definition at line 178 of file map.hpp.

References border_size_, tiles_, gamemap::location::x, and gamemap::location::y.

t_translation::t_terrain gamemap::get_terrain ( const location loc  )  const

Looks up terrain at a particular location.

Hexes off the map may be looked up, and their 'emulated' terrain will also be returned. This allows proper drawing of the edges of the map.

Definition at line 547 of file map.cpp.

References border_size_, borderCache_, get_adjacent_tiles(), is_keep(), is_village(), t_translation::NONE_TERRAIN, on_board(), tiles_, gamemap::location::x, and gamemap::location::y.

Referenced by ai::best_defensive_position(), terrain_builder::build_terrains(), ai::choose_move(), map_editor::copy_buffer(), sample_ai::do_attacks(), game_display::draw(), editor_display::draw(), game_display::draw_movement_info(), map_editor::draw_terrain(), preferences::encounter_map_terrain(), map_editor::flood_fill(), game_display::footsteps_images(), reports::generate_report(), map_editor::get_component(), game_display::get_flag(), get_terrain_info(), gives_healing(), unit::internal_matches_filter(), is_castle(), is_keep(), is_village(), map_editor::left_click(), unit_animation::matches(), ai::move_group(), unit::overlaps(), map_editor::paste_buffer(), map_editor::perform_fill_hexes(), ai::rate_group(), ai::rate_terrain(), terrain_builder::rebuild_terrain(), unit::redraw_unit(), ai::retreat_units(), map_editor::right_click(), terrain_builder::rule_matches(), set_terrain(), ai::should_retreat(), timeofday_at(), underlying_def_terrain(), underlying_mvt_terrain(), underlying_union_terrain(), events::menu_handler::unit_list(), battle_context::unit_stats::unit_stats(), and write_terrain().

void gamemap::write_terrain ( const gamemap::location loc,
config cfg 
) const

Writes the terrain at loc to cfg.

Definition at line 93 of file map.cpp.

References get_terrain(), and t_translation::write_terrain_code().

const gamemap::location & gamemap::starting_position ( int  side  )  const

int gamemap::is_starting_position ( const location loc  )  const

int gamemap::num_valid_starting_positions (  )  const

void gamemap::set_starting_position ( int  side,
const location loc 
)

bool gamemap::on_board ( const location loc,
const bool  include_border = false 
) const

Tell if a location is on the map.

Should be called before indexing using [].

Definition at line 646 of file map.cpp.

References border_size_, h_, tiles_, gamemap::location::valid(), w_, gamemap::location::x, and gamemap::location::y.

Referenced by ai::analyze_potential_recruit_movements(), playsingle_controller::before_human_turn(), playsingle_controller::can_execute_command(), can_recruit_on(), ai::choose_move(), clear_shroud_loc(), emergency_path_calculator::cost(), shortest_path_calculator::cost(), move_cost_calculator::cost(), events::mouse_handler::current_unit_attacks_from(), ai::do_attack_analysis(), events::console_handler::do_create(), ai::do_move(), game_display::draw(), editor_display::draw(), map_editor::draw_on_mouseover_hexes(), find_routes(), ai::find_targets(), find_vacant(), find_vacant_tile(), find_visible_unit(), reports::generate_report(), map_editor::get_component(), get_player_info(), get_terrain(), map_editor::get_tiles(), get_tiles_radius(), image::getMinimap(), gives_healing(), map_editor::handle_mouse_button_event(), unit::internal_matches_filter(), is_castle(), is_keep(), is_village(), events::menu_handler::label_terrain(), map_editor::left_button_down(), terrain_filter::match(), terrain_filter::match_internal(), events::mouse_handler::mouse_motion(), ai::move_group(), ai::move_leader_after_recruit(), ai::move_to_targets(), map_editor::paste_buffer(), map_editor::perform_fill_hexes(), placing_score(), ai::power_projection(), recruit_unit(), route_turns_to_complete(), display::scroll_to_tile(), display::scroll_to_tiles(), map_editor::set_starting_position(), set_terrain(), unit_can_move(), and write().

bool gamemap::empty (  )  const [inline]

Tell if the map is of 0 size.

Definition at line 203 of file map.hpp.

References h_, and w_.

Referenced by game_display::draw(), editor_display::draw(), display::draw_init(), get_player_info(), and display::screenshot().

const std::vector<location>& gamemap::villages (  )  const [inline]

Return a list of the locations of villages on the map.

Definition at line 209 of file map.hpp.

References villages_.

Referenced by ai::do_recruitment(), editor_display::draw(), ai::find_targets(), reports::generate_report(), ai_interface::get_value(), and playsingle_controller::play_scenario().

const terrain_type & gamemap::get_terrain_info ( const t_translation::t_terrain  terrain  )  const

const terrain_type& gamemap::get_terrain_info ( const location loc  )  const [inline]

Shortcut to get_terrain_info(get_terrain(loc)).

Definition at line 216 of file map.hpp.

References get_terrain(), and get_terrain_info().

const t_translation::t_list& gamemap::get_terrain_list (  )  const [inline]

Gets the list of terrains.

Definition at line 220 of file map.hpp.

References terrainList_.

Referenced by map_editor::terrain_palette::terrain_palette().

void gamemap::set_terrain ( const location loc,
const t_translation::t_terrain  terrain,
const tmerge_mode  mode = BOTH,
bool  replace_if_failed = false 
)

const std::map< t_translation::t_terrain, size_t > & gamemap::get_weighted_terrain_frequencies (  )  const

Returns a list of the frequencies of different terrain types on the map, with terrain nearer the center getting weighted higher.

Definition at line 803 of file map.cpp.

References distance_between(), h(), terrainFrequencyCache_, and w().

Referenced by ai::average_resistance_against().

void gamemap::remove_from_border_cache ( const location loc  )  [inline]

Remove the cached border terrain at loc.

Needed by the editor to make tiles at the border update correctly when drawing other tiles.

Definition at line 233 of file map.hpp.

References borderCache_.

Referenced by set_terrain().

tusage gamemap::get_usage (  )  const [inline]

Returns the usage of the map.

Definition at line 242 of file map.hpp.

References usage_.

t_translation::t_terrain gamemap::merge_terrains ( const t_translation::t_terrain  old_t,
const t_translation::t_terrain  new_t,
const tmerge_mode  mode,
bool  replace_if_failed = false 
)

Tries to merge old and new terrain using the merge_settings config Relevant parameters are "layer" and "replace_conflicting" "layer" specifies the layer that should be replaced (base or overlay, default is both).

If "replace_conflicting" is true the new terrain will replace the old one if merging failed (using the default base if new terrain is an overlay terrain) Will return the resulting terrain or NONE_TERRAIN if merging failed

Definition at line 848 of file map.cpp.

References BASE, t_translation::t_terrain::base, BOTH, terrain_type::default_base(), get_terrain_info(), t_translation::NO_LAYER, t_translation::NONE_TERRAIN, t_translation::t_terrain::overlay, OVERLAY, tcodeToTerrain_, terrain_type::terrain_with_default_base(), and try_merge_terrains().

Referenced by set_terrain().

void gamemap::clear_border_cache (  )  [inline, protected]

Clears the border cache, needed for the editor.

Definition at line 267 of file map.hpp.

References borderCache_.

Referenced by editormap::add_tiles_left(), and editormap::add_tiles_top().

int gamemap::num_starting_positions (  )  const [inline, private]

const t_translation::t_list gamemap::operator[] ( int  index  )  const [inline, private]

Allows lookup of terrain at a particular location.

Definition at line 274 of file map.hpp.

References border_size_, and tiles_.

bool gamemap::try_merge_terrains ( const t_translation::t_terrain  terrain  )  [private]

Tries to find out if "terrain" can be created by combining two existing terrains Will add the resulting terrain to the terrain list if successfull.

Definition at line 827 of file map.cpp.

References t_translation::t_terrain::base, t_translation::NO_LAYER, terrain_type::number(), t_translation::t_terrain::overlay, tcodeToTerrain_, and terrainList_.

Referenced by merge_terrains(), and read().


Member Data Documentation

const std::string gamemap::default_map_header = "usage=map\nborder_size=1\n\n" [static]

The default map header, needed for maps created with terrain_translation::write_game_map().

Definition at line 246 of file map.hpp.

Referenced by cave_map_generator::create_scenario(), map_editor::new_map(), and output_map().

const gamemap::tborder gamemap::default_border = gamemap::SINGLE_TILE_BORDER [static]

The default border style for a map.

Definition at line 248 of file map.hpp.

Referenced by cave_map_generator::cave_map_generator(), map_editor::new_map_dialog(), and output_map().

location gamemap::startingPositions_[MAX_PLAYERS+1] [protected]

The size of the starting positions array is MAX_PLAYERS + 1, because the positions themselves are numbered from 1.

Definition at line 262 of file map.hpp.

Referenced by is_starting_position(), num_starting_positions(), overlay(), read(), editormap::resize(), editormap::set_starting_position(), set_starting_position(), starting_position(), and write().

Definition at line 281 of file map.hpp.

Referenced by gamemap(), get_terrain_list(), and try_merge_terrains().

std::vector<location> gamemap::villages_ [private]

Definition at line 283 of file map.hpp.

Referenced by read(), set_terrain(), and villages().

Definition at line 285 of file map.hpp.

Referenced by clear_border_cache(), get_terrain(), and remove_from_border_cache().

Definition at line 286 of file map.hpp.

Referenced by get_weighted_terrain_frequencies().

int gamemap::w_ [private]

Sizes of the map area.

Definition at line 289 of file map.hpp.

Referenced by empty(), on_board(), read(), and w().

int gamemap::h_ [private]

Definition at line 290 of file map.hpp.

Referenced by empty(), h(), on_board(), and read().

int gamemap::total_width_ [private]

Sizes of the map including the borders.

Definition at line 293 of file map.hpp.

Referenced by read(), and total_width().

int gamemap::total_height_ [private]

Definition at line 294 of file map.hpp.

Referenced by read(), and total_height().

int gamemap::border_size_ [private]

The size of the border around the map.

Definition at line 297 of file map.hpp.

Referenced by get_terrain(), on_board(), operator[](), overlay(), read(), set_terrain(), and write().

The kind of map is being loaded.

Definition at line 299 of file map.hpp.

Referenced by get_usage(), read(), and write().


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

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs