The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Attributes | Friends | List of all members
game_board Class Reference

Game board class. More...

#include <game_board.hpp>

Inheritance diagram for game_board:
Inheritance graph

Public Member Functions

n_unit::id_managerunit_id_manager ()
 
 game_board (const tdata_cache &tdata, const config &level)
 
virtual ~game_board ()
 
virtual const std::vector< team > & teams () const
 
virtual const gamemapmap () const
 
virtual const unit_mapunits () const
 
unit_mapunits ()
 
virtual const std::vector
< std::string > & 
hidden_label_categories () const
 
 game_board (const game_board &other)
 
game_boardoperator= (game_board other)
 
void write_config (config &cfg) const
 
void new_turn (int pnum)
 
void end_turn (int pnum)
 
void set_all_units_user_end_turn ()
 
void heal_all_survivors ()
 
void check_victory (bool &, bool &, bool &, bool &, std::set< unsigned > &, bool)
 
void side_drop_to (int side_num, team::CONTROLLER ctrl, team::PROXY_CONTROLLER proxy=team::PROXY_CONTROLLER::PROXY_HUMAN)
 
void side_change_controller (int side_num, bool is_local, const std::string &pname="")
 
bool try_add_unit_to_recall_list (const map_location &loc, const unit_ptr u)
 
boost::optional< std::stringreplace_map (const gamemap &r)
 
void overlay_map (const gamemap &o, const config &cfg, map_location loc, bool border)
 
bool change_terrain (const map_location &loc, const std::string &t, const std::string &mode, bool replace_if_failed)
 
unit_map::iterator find_visible_unit (const map_location &loc, const team &current_team, bool see_all=false)
 
unit_map::iterator find_visible_unit (const map_location &loc, size_t team, bool see_all=false)
 
bool has_visible_unit (const map_location &loc, const team &team, bool see_all=false) const
 
bool has_visible_unit (const map_location &loc, size_t team, bool see_all=false) const
 
unitget_visible_unit (const map_location &loc, const team &current_team, bool see_all=false)
 
unit_map::iterator find_unit (const map_location &loc)
 
bool team_is_defeated (const team &t) const
 Calculates whether a team is defeated. More...
 
- Public Member Functions inherited from display_context
std::vector< std::string > & hidden_label_categories_ref ()
 
bool would_be_discovered (const map_location &loc, int side_num, bool see_all=true)
 Given a location and a side number, indicates whether an invisible unit of that side at that location would be revealed (perhaps ambushed), based on what team side_num can see. More...
 
const unitget_visible_unit (const map_location &loc, const team &current_team, bool see_all=false) const
 
bool unit_can_move (const unit &u) const
 Will return true iff the unit u has any possible moves it can do (including attacking etc). More...
 
int village_owner (const map_location &loc) const
 Given the location of a village, will return the 0-based index of the team that currently owns it, and -1 if it is unowned. More...
 
int side_units (int side_num) const
 Returns the number of units of the side side_num. More...
 
int side_units_cost (int side_num) const
 Returns the total cost of units of side side_num. More...
 
int side_upkeep (int side_num) const
 
team_data calculate_team_data (const class team &tm, int side) const
 
bool is_observer () const
 Check if we are an observer in this game. More...
 
virtual ~display_context ()
 

Private Attributes

std::vector< teamteams_
 
std::vector< std::stringlabels_
 
boost::scoped_ptr< gamemapmap_
 
n_unit::id_manager unit_id_manager_
 
unit_map units_
 

Friends

class play_controller
 
class events::mouse_handler
 
class events::menu_handler
 
class game_state
 
class game_lua_kernel
 
struct temporary_unit_placer
 Temporary unit move structs: More...
 
struct temporary_unit_mover
 
struct temporary_unit_remover
 
void swap (game_board &one, game_board &other)
 

Detailed Description

Game board class.

The purpose of this class is to encapsulate some of the core game logic, including the unit map, the list of teams, and the game map.

This should eventually become part of the game state object IMO, which should be a child of play_controller.

I also intend to move the pathfinding module to be housed within this class – this way, we can implement a sound pathfinding data structure to speed up path computations for AI, without having to make "update event" code at all points in the engine which modify the relevant data.

Definition at line 55 of file game_board.hpp.

Constructor & Destructor Documentation

game_board::game_board ( const tdata_cache tdata,
const config level 
)

Definition at line 36 of file game_board.cpp.

game_board::~game_board ( )
virtual

Definition at line 50 of file game_board.cpp.

game_board::game_board ( const game_board other)

Definition at line 44 of file game_board.cpp.

Member Function Documentation

bool game_board::change_terrain ( const map_location loc,
const std::string t,
const std::string mode,
bool  replace_if_failed 
)
void game_board::check_victory ( bool &  continue_level,
bool &  found_player,
bool &  found_network_player,
bool &  cleared_villages,
std::set< unsigned > &  not_defeated,
bool  remove_from_carryover_on_defeat 
)

Definition at line 101 of file game_board.cpp.

References DBG_EE, team::defeat_condition(), i, teams(), teams_, and units().

Referenced by play_controller::check_victory().

void game_board::end_turn ( int  pnum)

Definition at line 77 of file game_board.cpp.

References i, and units_.

Referenced by play_controller::finish_side_turn().

unit_map::iterator game_board::find_unit ( const map_location loc)
inline

Definition at line 149 of file game_board.hpp.

References unit_map::find().

Referenced by unit_display::unit_attack().

unit_map::iterator game_board::find_visible_unit ( const map_location loc,
const team current_team,
bool  see_all = false 
)
unit_map::iterator game_board::find_visible_unit ( const map_location loc,
size_t  team,
bool  see_all = false 
)
inline

Definition at line 141 of file game_board.hpp.

References find_visible_unit().

Referenced by find_visible_unit().

unit * game_board::get_visible_unit ( const map_location loc,
const team current_team,
bool  see_all = false 
)
bool game_board::has_visible_unit ( const map_location loc,
const team team,
bool  see_all = false 
) const
bool game_board::has_visible_unit ( const map_location loc,
size_t  team,
bool  see_all = false 
) const
inline

Definition at line 143 of file game_board.hpp.

References has_visible_unit().

Referenced by has_visible_unit().

void game_board::heal_all_survivors ( )

Definition at line 91 of file game_board.cpp.

References unit_map::begin(), unit_map::end(), teams_, and units_.

Referenced by playsingle_controller::play_scenario().

virtual const std::vector<std::string>& game_board::hidden_label_categories ( ) const
inlinevirtual

Implements display_context.

Definition at line 101 of file game_board.hpp.

References labels_.

virtual const gamemap& game_board::map ( ) const
inlinevirtual

Implements display_context.

Definition at line 98 of file game_board.hpp.

References map_.

Referenced by ai::ai_default_rca::move_to_targets_phase::access_points(), actions::actor_sighted(), calculate_healing(), game_state::can_recruit_from(), game_state::can_recruit_on(), ai::ai_default_rca::move_to_targets_phase::choose_move(), actions::shroud_clearer::clear_loc(), ai::default_recruitment::recruitment::compare_cost_maps_and_update_important_hexes(), events::mouse_handler::current_unit_attacks_from(), ai::ai_default_rca::aspect_attacks_base::do_attack_analysis(), preferences::encounter_all_content(), ai::ai_default_rca::goto_phase::evaluate(), ai::ai_default_rca::move_leader_to_goals_phase::evaluate(), ai::ai_default_rca::move_leader_to_keep_phase::evaluate(), ai::ai_default_rca::retreat_phase::evaluate(), ai::ai_default_rca::move_to_targets_phase::execute(), ai::default_recruitment::recruitment::execute(), unit_creator::find_location(), pathfind::find_routes(), ai::default_ai_context_impl::find_targets(), pathfind::find_vacant_tile(), ai::ai_default_rca::get_villages_phase::find_villages(), pathfind::full_cost_map::full_cost_map(), ai::default_recruitment::recruitment::get_estimated_village_gain(), play_controller::get_map_const(), pathfind::full_cost_map::get_pair_at(), actions::get_recalls(), actions::get_recruits(), events::mouse_handler::get_route(), actions::get_sides_not_seeing(), game_state::init(), team_builder::init(), game_lua_kernel::intf_find_path(), game_lua_kernel::intf_get_map_size(), game_lua_kernel::intf_get_starting_location(), game_lua_kernel::intf_get_terrain(), game_lua_kernel::intf_get_terrain_info(), events::menu_handler::map(), game_lua_kernel::map(), pathfind::mark_route(), events::mouse_handler::mouse_motion(), ai::ai_default_rca::move_to_targets_phase::move_group(), team_builder::new_team(), wb::path_cost(), game_state::place_sides_in_preferred_locations(), team_builder::place_units(), unit_creator::post_create(), ai::readonly_context_impl::power_projection(), ai::ai_default_rca::move_to_targets_phase::rate_group(), ai::ai_default_rca::aspect_attacks_base::rate_terrain(), ai::default_ai_context_impl::rate_terrain(), events::mouse_handler::show_attack_options(), ai::move_result::test_route(), ai::default_recruitment::recruitment::update_average_local_cost(), ai::default_recruitment::recruitment::update_important_hexes(), and game_events::WML_HANDLER_FUNCTION().

void game_board::new_turn ( int  pnum)

Definition at line 69 of file game_board.cpp.

References i, and units_.

Referenced by play_controller::do_init_side().

game_board & game_board::operator= ( game_board  other)

Definition at line 63 of file game_board.cpp.

References swap.

void game_board::overlay_map ( const gamemap o,
const config cfg,
map_location  loc,
bool  border 
)

Definition at line 294 of file game_board.cpp.

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

Referenced by game_events::WML_HANDLER_FUNCTION().

boost::optional< std::string > game_board::replace_map ( const gamemap r)
void game_board::set_all_units_user_end_turn ( )

Definition at line 85 of file game_board.cpp.

References i, and units_.

Referenced by playmp_controller::linger(), and playsingle_controller::linger().

void game_board::side_change_controller ( int  side_num,
bool  is_local,
const std::string pname = "" 
)
void game_board::side_drop_to ( int  side_num,
team::CONTROLLER  ctrl,
team::PROXY_CONTROLLER  proxy = team::PROXY_CONTROLLER::PROXY_HUMAN 
)
bool game_board::team_is_defeated ( const team t) const

Calculates whether a team is defeated.

Definition at line 230 of file game_board.cpp.

References team::defeat_condition(), unit_map::find_leader(), team::side(), units_, and schema_validation::valid.

Referenced by actions::get_village().

virtual const std::vector<team>& game_board::teams ( ) const
inlinevirtual
bool game_board::try_add_unit_to_recall_list ( const map_location loc,
const unit_ptr  u 
)

Definition at line 251 of file game_board.cpp.

References teams_.

Referenced by replace_map().

n_unit::id_manager& game_board::unit_id_manager ( )
inline
virtual const unit_map& game_board::units ( ) const
inlinevirtual
unit_map& game_board::units ( )
inline

Definition at line 100 of file game_board.hpp.

References units_.

void game_board::write_config ( config cfg) const

Friends And Related Function Documentation

friend class events::menu_handler
friend

Definition at line 68 of file game_board.hpp.

friend class events::mouse_handler
friend

Definition at line 67 of file game_board.hpp.

friend class game_lua_kernel
friend

Definition at line 70 of file game_board.hpp.

friend class game_state
friend

Definition at line 69 of file game_board.hpp.

friend class play_controller
friend

Definition at line 66 of file game_board.hpp.

void swap ( game_board one,
game_board other 
)
friend

Definition at line 56 of file game_board.cpp.

Referenced by operator=().

friend struct temporary_unit_mover
friend

Definition at line 87 of file game_board.hpp.

friend struct temporary_unit_placer
friend

Temporary unit move structs:

Probably don't remove these friends, this is actually fairly useful. These structs are used by:

  • AI
  • Whiteboard
  • I think certain wml actions For AI, the ai wants to move two units next to eachother so it can ask for attack calculations. This should not trigger pathfinding modifications, so the version that directly changes the unit map is probably preferable, although it should be refactored. For whiteboard and wml actions, we generally do want pathfinding to be updated, so use the game_board constructors which I have added to these structs instead.

Definition at line 86 of file game_board.hpp.

friend struct temporary_unit_remover
friend

Definition at line 88 of file game_board.hpp.

Member Data Documentation

std::vector<std::string> game_board::labels_
private

Definition at line 59 of file game_board.hpp.

Referenced by hidden_label_categories().

boost::scoped_ptr<gamemap> game_board::map_
private
std::vector<team> game_board::teams_
private
n_unit::id_manager game_board::unit_id_manager_
private

Definition at line 62 of file game_board.hpp.

Referenced by swap(), unit_id_manager(), and write_config().

unit_map game_board::units_
private

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