unit_map Class Reference

#include <unit_map.hpp>

List of all members.

Public Types

typedef std::map< std::string,
std::pair< bool, std::pair
< gamemap::location, unit > * > > 
umap
 Keyed with unit's underlying_id.
typedef std::map
< gamemap::location,
std::string > 
lmap
 Maps locations to the underlying_id() of the unit at that location.
typedef unit_iterator iterator
typedef const_unit_iterator const_iterator

Public Member Functions

 unit_map ()
 unit_map (const unit_map &that)
unit_mapoperator= (const unit_map &that)
 unit_map (const gamemap::location &loc, const unit &u)
 A unit map with a copy of a single unit in it.
 ~unit_map ()
unit_iterator find (const gamemap::location &loc)
 Return object can be implicitly converted to any of the other iterators or accessors.
unit_iterator find (const std::string &id)
const_unit_iterator find (const gamemap::location &loc) const
 Return object can be implicity converted to any of the other const iterators or accessors.
const_unit_iterator find (const std::string &id) const
size_t count (const gamemap::location &loc) const
unit_iterator begin ()
 Return object can be implicitly converted to any of the other iterators or accessors.
const_unit_iterator begin () const
 Return object can be implicity converted to any of the other const iterators or accessors.
unit_iterator end ()
 Return object can be implicitly converted to any of the other iterators or accessors.
const_unit_iterator end () const
 Return object can be implicity converted to any of the other const iterators or accessors.
size_t size () const
void clear ()
std::pair< gamemap::location,
unit > * 
extract (const gamemap::location &loc)
 Extract (like erase, but don't delete).
void add (std::pair< gamemap::location, unit > *p)
 Map owns pointer after this.
void replace (std::pair< gamemap::location, unit > *p)
 Like add, but loc must be occupied (implicitly erased).
void erase (xy_accessor pos)
size_t erase (const gamemap::location &loc)
void swap (unit_map &o)

Private Member Functions

void clean_invalid ()
 Removes invalid entries in map_.
void invalidate (umap::iterator i)
void validate (umap::iterator i)
void delete_all ()
void add_iter () const
void remove_iter () const

Private Attributes

std::map< std::string,
std::pair< bool, std::pair
< gamemap::location, unit > * > > 
map_
 Key: unit's underlying_id.
std::map< gamemap::location,
std::string > 
lmap_
 location -> unit.underlying_id().
size_t num_iters_
size_t num_invalid_

Classes

struct  const_unit_iterator
struct  const_unit_xy_iterator
struct  const_xy_accessor
struct  iterator_counter
 Used so unit_map can keep a count of iterators and clean invalid pointers when no iterators exist. More...
struct  unit_iterator
 For iterating over every unit. More...
struct  unit_xy_iterator
 Similar to unit_iterator, except that becomes invalid if unit is moved while the iterator points at it. More...
struct  xy_accessor
 Used to access the unit at a given position. More...


Detailed Description

Definition at line 38 of file unit_map.hpp.


Member Typedef Documentation

typedef std::map<std::string,std::pair<bool, std::pair<gamemap::location,unit>*> > unit_map::umap

Keyed with unit's underlying_id.

bool flag is whether the following pair pointer is valid. pointer to pair used to imitate a map<location, unit>

Definition at line 86 of file unit_map.hpp.

typedef std::map<gamemap::location, std::string> unit_map::lmap

Maps locations to the underlying_id() of the unit at that location.

Definition at line 89 of file unit_map.hpp.

Definition at line 174 of file unit_map.hpp.

Definition at line 175 of file unit_map.hpp.


Constructor & Destructor Documentation

unit_map::unit_map (  )  [inline]

Definition at line 75 of file unit_map.hpp.

unit_map::unit_map ( const unit_map that  ) 

Definition at line 36 of file unit_map.cpp.

unit_map::unit_map ( const gamemap::location loc,
const unit u 
) [explicit]

A unit map with a copy of a single unit in it.

Definition at line 31 of file unit_map.cpp.

unit_map::~unit_map (  ) 

Definition at line 54 of file unit_map.cpp.

References delete_all().


Member Function Documentation

unit_map & unit_map::operator= ( const unit_map that  ) 

Definition at line 41 of file unit_map.cpp.

References clear(), map_, num_invalid_, and num_iters_.

unit_map::unit_iterator unit_map::find ( const gamemap::location loc  ) 

Return object can be implicitly converted to any of the other iterators or accessors.

Definition at line 341 of file unit_map.cpp.

References lmap_, and map_.

Referenced by unit::ability_active(), ai::access_points(), scoped_xy_unit::activate(), replay::add_unit_checksum(), dialogs::advance_unit(), ai::attack_analysis::analyze(), dialogs::animate_unit_advancement(), apply_shroud_changes(), attack::attack(), ai_interface::attack_enemy(), backstab_check(), battle_context::battle_context(), playsingle_controller::before_human_turn(), ai::best_defensive_position(), calculate_healing(), playsingle_controller::can_execute_command(), events::menu_handler::change_unit_side(), check_checksums(), ai::choose_move(), clear_shroud_unit(), events::menu_handler::continue_move(), ai::desperate_attack(), ai::do_attack_analysis(), sample_ai::do_attacks(), ai::do_combat(), ai::do_move(), do_replay_handle(), events::menu_handler::do_search(), game_display::draw(), game_display::draw_movement_info(), events::menu_handler::end_unit_turn(), formula_ai::execute_variant(), find_vacant(), find_visible_unit(), attack::fire_event(), game_display::footsteps_images(), ai::form_group(), unit::get_abilities(), unit::get_ability_bool(), get_advanced_unit(), ai::get_healing(), get_player_info(), ai::get_villages(), unit::internal_matches_filter(), game_display::invalidate(), terrain_filter::match_internal(), ai::move_group(), ai::move_leader_after_recruit(), ai::move_to_targets(), ai::move_unit(), ai_interface::move_unit(), move_unit(), ai_interface::move_unit_partial(), ai::multistep_move_possible(), paths::paths(), ai::power_projection(), process_event(), ai::rate_group(), recruit_unit(), events::menu_handler::redo(), attack::refresh_bc(), attack_type::special_active(), timeofday_at(), under_leadership(), events::menu_handler::undo(), unit_display::unit_attack(), unit_can_move(), events::menu_handler::unit_hold_position(), unit_display::unit_recruited(), unit_map::const_xy_accessor::valid(), unit_map::xy_accessor::valid(), and verify().

unit_map::unit_iterator unit_map::find ( const std::string &  id  ) 

Definition at line 366 of file unit_map.cpp.

References map_.

unit_map::const_unit_iterator unit_map::find ( const gamemap::location loc  )  const

Return object can be implicity converted to any of the other const iterators or accessors.

Definition at line 354 of file unit_map.cpp.

References lmap_, and map_.

unit_map::const_unit_iterator unit_map::find ( const std::string &  id  )  const

Definition at line 374 of file unit_map.cpp.

References map_.

size_t unit_map::count ( const gamemap::location loc  )  const [inline]

unit_map::unit_iterator unit_map::begin (  ) 

Return object can be implicitly converted to any of the other iterators or accessors.

Definition at line 382 of file unit_map.cpp.

References clean_invalid(), lmap_, map_, num_invalid_, and num_iters_.

Referenced by dfool::dfool_ai::all_units(), ai::analyze_potential_recruit_combat(), ai::analyze_targets(), apply_shroud_changes(), ai::avoided_locations(), playsingle_controller::before_human_turn(), calculate_healing(), check_victory(), ai::choose_move(), clear_shroud(), events::mouse_handler::cycle_units(), ai::do_attack_analysis(), sample_ai::do_attacks(), ai::do_move(), sample_ai::do_moves(), ai::do_recruitment(), game_display::draw_minimap_units(), draw_panel(), preferences::encounter_start_units(), events::menu_handler::end_turn(), play_controller::enemies_visible(), find_leader(), ai::find_targets(), ai::find_threats(), play_controller::finish_side_turn(), help::generate_ability_topics(), reports::generate_report(), preprocessor_data::get_chunk(), dialogs::units_list_preview_pane::get_details(), ai::get_healing(), ai_interface::get_value(), ai::get_villages(), play_controller::init_side(), game_events::internal_conditional_passed(), game_display::invalidate_animations(), unit::invisible(), events::mouse_handler::left_click(), playsingle_controller::linger(), playmp_controller::linger(), unit_animation::matches(), move_unit(), dfool::dfool_ai::moveto(), unit_map::const_unit_iterator::operator--(), playsingle_controller::play_scenario(), replay_controller::play_side(), formula_ai::play_turn(), ai::rate_group(), recalculate_fog(), recruit_unit(), reset_resting(), ai::retreat_units(), events::mouse_handler::show_attack_options(), events::menu_handler::show_enemy_moves(), team_leader(), team_units(), team_upkeep(), dfool::dfool_ai::unit(), events::menu_handler::unit_list(), verify(), dfool::dfool_ai::visible_units(), and events::menu_handler::write_game_snapshot().

const_unit_iterator unit_map::begin (  )  const [inline]

Return object can be implicity converted to any of the other const iterators or accessors.

Definition at line 335 of file unit_map.hpp.

References map_.

unit_iterator unit_map::end (  )  [inline]

Return object can be implicitly converted to any of the other iterators or accessors.

Definition at line 347 of file unit_map.hpp.

References map_.

Referenced by unit::ability_active(), ai::access_points(), scoped_xy_unit::activate(), replay::add_unit_checksum(), dialogs::advance_unit(), dfool::dfool_ai::all_units(), ai::attack_analysis::analyze(), ai::analyze_potential_recruit_combat(), ai::analyze_potential_recruit_movements(), ai::analyze_targets(), dialogs::animate_unit_advancement(), apply_shroud_changes(), attack::attack(), ai_interface::attack_enemy(), ai::avoided_locations(), backstab_check(), playsingle_controller::before_human_turn(), ai::best_defensive_position(), calculate_healing(), playsingle_controller::can_execute_command(), play_controller::can_execute_command(), events::menu_handler::change_unit_side(), check_checksums(), check_victory(), ai::choose_move(), clear_shroud(), clear_shroud_unit(), events::menu_handler::continue_move(), shortest_path_calculator::cost(), events::menu_handler::current_unit(), events::mouse_handler::current_unit_attacks_from(), events::mouse_handler::cycle_units(), ai::desperate_attack(), game_display::display_unit_hex(), ai::do_attack_analysis(), sample_ai::do_attacks(), events::console_handler::do_buff(), ai::do_combat(), ai::do_move(), sample_ai::do_moves(), ai::do_recruitment(), do_replay_handle(), events::menu_handler::do_search(), events::console_handler::do_unbuff(), events::console_handler::do_unit(), game_display::draw(), game_display::draw_minimap_units(), game_display::draw_movement_info(), draw_panel(), game_display::draw_sidebar(), preferences::encounter_start_units(), events::menu_handler::end_turn(), events::menu_handler::end_unit_turn(), play_controller::enemies_visible(), enemy_zoc(), formula_ai::execute_variant(), find_leader(), find_routes(), ai::find_targets(), ai::find_threats(), find_vacant(), find_visible_unit(), play_controller::finish_side_turn(), attack::fire_event(), game_display::footsteps_images(), ai::form_group(), help::generate_ability_topics(), reports::generate_report(), unit::get_abilities(), unit::get_ability_bool(), get_advanced_unit(), dialogs::units_list_preview_pane::get_details(), ai::get_healing(), get_player_info(), events::mouse_handler::get_route(), events::menu_handler::get_title_suffix(), formula_ai::get_value(), ai_interface::get_value(), get_village(), ai::get_villages(), events::menu_handler::goto_leader(), play_controller::handle_event(), game_display::highlight_hex(), play_controller::in_context_menu(), play_controller::init_side(), game_events::internal_conditional_passed(), unit::internal_matches_filter(), game_display::invalidate(), game_display::invalidate_animations(), unit::invisible(), ai::leader_can_reach_keep(), events::mouse_handler::left_click(), playsingle_controller::linger(), playmp_controller::linger(), terrain_filter::match_internal(), unit_animation::matches(), events::mouse_handler::mouse_motion(), events::mouse_handler::mouse_press(), ai::move_group(), ai::move_leader_after_recruit(), ai::move_leader_to_goals(), ai::move_leader_to_keep(), ai::move_to_targets(), ai::move_unit(), ai_interface::move_unit(), move_unit(), ai_interface::move_unit_partial(), events::menu_handler::move_unit_to_loc(), dfool::dfool_ai::moveto(), ai::multistep_move_possible(), utils::parse_range(), paths::paths(), playsingle_controller::play_scenario(), replay_controller::play_side(), formula_ai::play_turn(), dfool::dfool_ai::play_turn(), ai::power_projection(), process_event(), turn_info::process_network_data(), ai::rate_group(), recalculate_fog(), recruit_unit(), events::menu_handler::redo(), attack::refresh_bc(), events::menu_handler::rename_unit(), reset_resting(), ai::retreat_units(), events::menu_handler::scenario_settings_table(), game_display::scroll_to_leader(), events::mouse_handler::select_hex(), events::mouse_handler::selected_unit(), events::mouse_handler::show_attack_options(), events::menu_handler::show_enemy_moves(), attack_type::special_active(), events::menu_handler::status_table(), team_leader(), team_units(), team_upkeep(), timeofday_at(), under_leadership(), events::menu_handler::undo(), dfool::dfool_ai::unit(), unit_display::unit_attack(), unit_can_move(), events::menu_handler::unit_description(), events::menu_handler::unit_hold_position(), events::mouse_handler::unit_in_cycle(), events::menu_handler::unit_list(), unit_display::unit_recruited(), verify(), dfool::dfool_ai::visible_units(), and events::menu_handler::write_game_snapshot().

const_unit_iterator unit_map::end (  )  const [inline]

Return object can be implicity converted to any of the other const iterators or accessors.

Definition at line 355 of file unit_map.hpp.

References map_.

size_t unit_map::size (  )  const [inline]

Definition at line 359 of file unit_map.hpp.

References lmap_.

Referenced by verify().

void unit_map::clear ( void   ) 

Definition at line 482 of file unit_map.cpp.

References delete_all().

Referenced by operator=().

std::pair< gamemap::location, unit > * unit_map::extract ( const gamemap::location loc  ) 

void unit_map::add ( std::pair< gamemap::location, unit > *  p  ) 

void unit_map::replace ( std::pair< gamemap::location, unit > *  p  ) 

Like add, but loc must be occupied (implicitly erased).

Definition at line 426 of file unit_map.cpp.

References erase().

Referenced by advance_unit(), dialogs::animate_unit_advancement(), and dfool::unit_memory::known_map().

void unit_map::erase ( xy_accessor  pos  ) 

size_t unit_map::erase ( const gamemap::location loc  ) 

Definition at line 458 of file unit_map.cpp.

References invalidate(), lmap_, and map_.

void unit_map::swap ( unit_map o  )  [inline]

Definition at line 380 of file unit_map.hpp.

References lmap_, and map_.

void unit_map::clean_invalid (  )  [private]

Removes invalid entries in map_.

Called automatically when safe and needed.

Definition at line 487 of file unit_map.cpp.

References LOG_NG, map_, and num_invalid_.

Referenced by begin().

void unit_map::invalidate ( umap::iterator  i  )  [inline, private]

Definition at line 390 of file unit_map.hpp.

References map_, and num_invalid_.

Referenced by erase(), and extract().

void unit_map::validate ( umap::iterator  i  )  [inline, private]

Definition at line 392 of file unit_map.hpp.

References map_, and num_invalid_.

Referenced by add().

void unit_map::delete_all (  )  [private]

Definition at line 433 of file unit_map.cpp.

References lmap_, and map_.

Referenced by clear(), and ~unit_map().

void unit_map::add_iter (  )  const [inline, private]

void unit_map::remove_iter (  )  const [inline, private]


Member Data Documentation

std::map<std::string,std::pair<bool, std::pair<gamemap::location,unit>*> > unit_map::map_ [private]

std::map<gamemap::location, std::string> unit_map::lmap_ [private]

location -> unit.underlying_id().

Unit_map is usually used as though it is a map<location, unit> and so we need this map for efficient access/modification.

Definition at line 411 of file unit_map.hpp.

Referenced by add(), begin(), count(), delete_all(), erase(), extract(), find(), size(), and swap().

size_t unit_map::num_iters_ [mutable, private]

Definition at line 413 of file unit_map.hpp.

Referenced by add_iter(), begin(), operator=(), and remove_iter().

size_t unit_map::num_invalid_ [private]

Definition at line 414 of file unit_map.hpp.

Referenced by begin(), clean_invalid(), invalidate(), operator=(), and validate().


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