The Battle for Wesnoth  1.15.0+dev
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 ter_data_cache &tdata, const config &level)
 
virtual ~game_board ()
 
virtual const std::vector< team > & teams () const override
 
std::vector< team > & teams ()
 
teamget_team (int i)
 
virtual const gamemapmap () const override
 
virtual const unit_mapunits () const override
 
unit_mapunits ()
 
virtual const std::vector< std::string > & hidden_label_categories () const override
 
virtual std::vector< std::string > & hidden_label_categories () override
 
 game_board (const game_board &other)
 
game_boardoperator= (const game_board &other)=delete
 
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::string > replace_map (const gamemap &r)
 
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, std::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, std::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
const teamget_team (int side) const
 
template<typename T = void>
bool has_team (int side) const
 
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
 
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::string > labels_
 
std::unique_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 50 of file game_board.hpp.

Constructor & Destructor Documentation

◆ game_board() [1/2]

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

Definition at line 36 of file game_board.cpp.

◆ ~game_board()

game_board::~game_board ( )
virtual

Definition at line 51 of file game_board.cpp.

◆ game_board() [2/2]

game_board::game_board ( const game_board other)

Definition at line 44 of file game_board.cpp.

Member Function Documentation

◆ change_terrain()

bool game_board::change_terrain ( const map_location loc,
const std::string &  t,
const std::string &  mode,
bool  replace_if_failed 
)

◆ check_victory()

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 96 of file game_board.cpp.

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

Referenced by play_controller::check_victory().

◆ end_turn()

void game_board::end_turn ( int  pnum)

Definition at line 72 of file game_board.cpp.

References i, and units_.

Referenced by play_controller::finish_side_turn().

◆ find_unit()

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

Definition at line 179 of file game_board.hpp.

References unit_map::find(), and swap().

Referenced by unit_display::unit_attack().

◆ find_visible_unit() [1/2]

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

◆ find_visible_unit() [2/2]

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

Definition at line 171 of file game_board.hpp.

References find_visible_unit().

Referenced by find_visible_unit().

◆ get_team()

team& game_board::get_team ( int  i)
inline

Definition at line 104 of file game_board.hpp.

Referenced by pathfind::full_cost_map::add_unit(), actions::undo_list::apply_shroud_changes(), game_state::can_recruit_from(), game_state::can_recruit_on(), check_victory(), battle_context::choose_defender_weapon(), actions::shroud_clearer::clear_dest(), actions::clear_shroud(), actions::shroud_clearer::clear_unit(), wb::current_side_actions(), play_controller::current_team(), ai::readonly_context_impl::current_team(), ai::readwrite_context_impl::current_team_w(), events::menu_handler::do_recruit(), do_replay_handle(), ai::ai_default_rca::leader_shares_keep_phase::execute(), wb::find_actions_of(), actions::find_recruit_location(), pathfind::find_vacant_castle(), lua_unit::get(), ai::default_recruitment::recruitment::get_cost_map_of_side(), ai::default_recruitment::recruitment::get_estimated_income(), ai::action_result::get_my_team(), actions::get_recalls(), actions::get_recruits(), lua_unit::get_shared(), wb::manager::get_spent_gold_for(), mp_sync::get_user_choice(), ai::ai_default_rca::aspect_attacks::is_allowed_enemy(), play_controller::is_team_visible(), ai_testing::log_turn(), pathfind::mark_route(), wb::path_cost(), pathfind::paths::paths(), actions::place_recruit(), gui2::dialogs::mp_change_control::pre_show(), wb::manager::process_network_data(), lua_unit::put_map(), actions::recalculate_fog(), events::menu_handler::recall(), events::menu_handler::repeat_recruit(), unit_display::unit_mover::replace_temporary(), events::menu_handler::show_enemy_moves(), playsingle_controller::show_turn_dialog(), side_change_controller(), side_drop_to(), ai::simulated_recall(), ai::simulated_recruit(), SYNCED_COMMAND_HANDLER_FUNCTION(), events::menu_handler::toggle_shroud_updates(), try_add_unit_to_recall_list(), actions::undo::recall_action::undo(), actions::undo::recruit_action::undo(), actions::undo::dismiss_action::undo(), ai::default_recruitment::recruitment::update_average_local_cost(), user_choice_manager::user_choice_manager(), verify_and_clear_global_variable(), verify_and_set_global_variable(), and game_events::WML_HANDLER_FUNCTION().

◆ get_visible_unit()

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

◆ has_visible_unit() [1/2]

bool game_board::has_visible_unit ( const map_location loc,
const team team,
bool  see_all = false 
) const

◆ has_visible_unit() [2/2]

bool game_board::has_visible_unit ( const map_location loc,
std::size_t  team,
bool  see_all = false 
) const
inline

Definition at line 173 of file game_board.hpp.

References get_visible_unit(), and has_visible_unit().

Referenced by has_visible_unit().

◆ heal_all_survivors()

void game_board::heal_all_survivors ( )

Definition at line 86 of file game_board.cpp.

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

Referenced by playsingle_controller::play_scenario().

◆ hidden_label_categories() [1/2]

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

Implements display_context.

Definition at line 124 of file game_board.hpp.

Referenced by game_state::init().

◆ hidden_label_categories() [2/2]

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

Implements display_context.

Definition at line 129 of file game_board.hpp.

References swap(), and t.

◆ map()

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

Implements display_context.

Definition at line 109 of file game_board.hpp.

Referenced by ai::ai_default_rca::move_to_targets_phase::access_points(), battle_context_unit_stats::battle_context_unit_stats(), 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(), wfl::gamestate::DEFINE_WFL_FUNCTION(), 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(), actions::find_recruit_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(), pathfind::full_cost_map::get_pair_at(), actions::get_recalls(), actions::get_recruits(), events::mouse_handler::get_route(), impl_unit_set(), game_state::init(), team_builder::init(), events::menu_handler::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(), attack_type::special_active(), ai::move_result::test_route(), events::mouse_handler::touch_motion(), ai::default_recruitment::recruitment::update_average_local_cost(), ai::default_recruitment::recruitment::update_important_hexes(), and game_events::WML_HANDLER_FUNCTION().

◆ new_turn()

void game_board::new_turn ( int  pnum)

Definition at line 64 of file game_board.cpp.

References i, and units_.

Referenced by play_controller::do_init_side().

◆ operator=()

game_board& game_board::operator= ( const game_board other)
delete

◆ replace_map()

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

◆ set_all_units_user_end_turn()

void game_board::set_all_units_user_end_turn ( )

Definition at line 80 of file game_board.cpp.

References i, and units_.

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

◆ side_change_controller()

void game_board::side_change_controller ( int  side_num,
bool  is_local,
const std::string &  pname = "" 
)

◆ side_drop_to()

void game_board::side_drop_to ( int  side_num,
team::CONTROLLER  ctrl,
team::PROXY_CONTROLLER  proxy = team::PROXY_CONTROLLER::PROXY_HUMAN 
)

◆ team_is_defeated()

bool game_board::team_is_defeated ( const team t) const

Calculates whether a team is defeated.

Definition at line 225 of file game_board.cpp.

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

Referenced by actions::get_village().

◆ teams() [1/2]

virtual const std::vector<team>& game_board::teams ( ) const
inlineoverridevirtual

Implements display_context.

Definition at line 92 of file game_board.hpp.

Referenced by scoped_recall_unit::activate(), actions::actor_sighted(), map_labels::all_categories(), unit::apply_builtin_effect(), wb::recall::apply_temp_modifier(), wb::recruit::apply_temp_modifier(), team::calculate_is_enemy(), ai::readonly_context_impl::calculate_moves(), playsingle_controller::check_objectives(), wb::recall::check_validity(), wb::recruit::check_validity(), check_victory(), wfl::gamestate::DEFINE_WFL_FUNCTION(), ai::ai_default_rca::aspect_attacks_base::do_attack_analysis(), wb::recall::draw_hex(), preferences::encounter_all_content(), wb::recall::execute(), gui2::dialogs::game_stats::execute(), wb::recruit::execute(), play_controller::find_last_visible_team(), pathfind::find_routes(), ai::default_ai_context_impl::find_targets(), ai::ai_default_rca::get_villages_phase::find_villages(), events::mouse_handler::get_route(), team::get_side_color_id(), actions::get_sides_not_seeing(), mp_sync::get_user_choice(), mp_sync::get_user_choice_multiple_sides(), ai::formula_ai::get_value(), actions::get_village(), ai::helper_check_village(), gui2::dialogs::mp_change_control::highlight_side_nick(), wb::move::init(), team::knows_about_team(), wb::highlighter::last_action_redraw(), ai_testing::log_game_end(), ai_testing::log_game_start(), pathfind::mark_route(), actions::move_unit_and_record(), wb::manager::on_change_controller(), playsingle_controller::play_scenario_main_loop(), wb::manager::post_delete_action(), wb::mapbuilder::pre_build(), gui2::dialogs::mp_change_control::pre_show(), turn_info::process_network_data(), wb::recall::remove_temp_modifier(), wb::manager::send_network_data(), campaign_controller::show_carryover_message(), play_controller::show_objectives(), play_controller::tab(), user_choice_manager::user_choice_manager(), wb::viewer_actions(), events::mouse_handler::viewing_team(), pathfind::vision_path::vision_path(), and game_events::WML_HANDLER_FUNCTION().

◆ teams() [2/2]

std::vector<team>& game_board::teams ( )
inline

Definition at line 97 of file game_board.hpp.

References display_context::get_team().

◆ try_add_unit_to_recall_list()

bool game_board::try_add_unit_to_recall_list ( const map_location loc,
const unit_ptr  u 
)

Definition at line 246 of file game_board.cpp.

References get_team().

Referenced by replace_map().

◆ unit_id_manager()

n_unit::id_manager& game_board::unit_id_manager ( )
inline

◆ units() [1/2]

virtual const unit_map& game_board::units ( ) const
inlineoverridevirtual

Implements display_context.

Definition at line 114 of file game_board.hpp.

Referenced by ai::ai_default_rca::move_to_targets_phase::access_points(), ai::protect_goal::add_targets(), unit_creator::add_unit(), replay::add_unit_checksum(), advance_unit(), advance_unit_at(), ai::ai_default_rca::aspect_attacks_base::analyze_targets(), attack_unit_and_advance(), ai::readonly_context_impl::best_defensive_position(), ai::readonly_context_impl::check_attack_action(), actions::check_recall_location(), actions::check_recruit_location(), wb::attack::check_validity(), wb::move::check_validity(), wb::suppose_dead::check_validity(), check_victory(), ai::ai_default_rca::move_to_targets_phase::choose_move(), actions::shroud_clearer::clear_unit(), ai::default_ai_context_impl::count_free_hexes_in_castle(), events::mouse_handler::cycle_units(), wfl::gamestate::DEFINE_WFL_FUNCTION(), ai::ai_default_rca::aspect_attacks_base::do_attack_analysis(), ai::recall_result::do_check_after(), ai::recruit_result::do_check_after(), ai::stopunit_result::do_check_after(), ai::attack_result::do_check_before(), ai::default_recruitment::recruitment::do_combat_analysis(), ai::attack_result::do_execute(), ai::move_result::do_execute(), ai::stopunit_result::do_execute(), ai::stage_unit_formulas::do_play_stage(), do_replay_handle(), 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::get_villages_phase::evaluate(), ai::default_recruitment::recruitment::evaluate(), ai::ai_default_rca::get_healing_phase::evaluate(), ai::ai_default_rca::retreat_phase::evaluate(), ai::ai_default_rca::leader_shares_keep_phase::evaluate(), wb::attack::execute(), wb::recruit::execute(), wb::move::execute(), ai::ai_default_rca::move_to_targets_phase::execute(), ai::ai_default_rca::get_villages_phase::execute(), ai::default_recruitment::recruitment::execute(), ai::ai_default_rca::leader_shares_keep_phase::execute(), ai::readwrite_context_impl::execute_attack_action(), ai::attack_analysis::execute_self(), wfl::set_unit_var_callable::execute_self(), game_events::wml_event_pump::filter_event(), wb::find_backup_leader(), unit_creator::find_location(), actions::find_recruit_location(), ai::default_ai_context_impl::find_targets(), pathfind::find_vacant_tile(), ai::ai_default_rca::get_villages_phase::find_villages(), actions::shroud_clearer::fire_events(), ai::ai_default_rca::move_to_targets_phase::form_group(), lua_unit::get(), ai::default_recruitment::recruitment::get_cost_map_of_side(), actions::get_recalls(), actions::get_recruits(), lua_unit::get_shared(), wb::manager::get_temp_move_unit(), gui2::dialogs::get_title_suffix(), wb::suppose_dead::get_unit(), game_events::entity_location::get_unit(), wb::move::get_unit(), ai::move_result::get_unit(), ai::stopunit_result::get_unit(), wb::highlighter::get_unit_map(), ai::default_recruitment::recruitment::get_unit_ratio(), wfl::attack_map_callable::get_value(), ai::formula_ai::get_value(), ai::ai_default_rca::get_villages_phase::get_villages(), ai::helper_advance_unit(), ai::helper_check_village(), ai::helper_place_unit(), ai::impl_ai_aspect_get(), impl_unit_set(), ai::default_recruitment::recruitment::is_enemy_in_radius(), ai::readonly_context_impl::leader_can_reach_keep(), ai::lua_sticky_candidate_action_wrapper::lua_sticky_candidate_action_wrapper(), luaW_pushfaivariant(), pathfind::mark_route(), wb::move::move(), ai::ai_default_rca::move_to_targets_phase::move_group(), events::mouse_handler::move_unit_along_route(), actions::move_unit_and_record(), wb::manager::on_mouseover_change(), actions::place_recruit(), playsingle_controller::play_side_impl(), wb::manager::post_draw(), ai::readonly_context_impl::power_projection(), wb::manager::pre_draw(), game_events::wml_event_pump::process_event(), lua_unit::put_map(), ai::ai_default_rca::move_to_targets_phase::rate_group(), ai::readonly_context_impl::recalculate_move_maps(), wb::suppose_dead::remove_temp_modifier(), wb::move::remove_temp_modifier(), ai::formula_ai::shortest_path_calculator(), events::mouse_handler::show_attack_options(), game_state::side_can_recruit_on(), ai::simulated_attack(), ai::simulated_move(), ai::simulated_stopunit(), wb::suppose_dead::suppose_dead(), SYNCED_COMMAND_HANDLER_FUNCTION(), pathfind::teleport_map::teleport_map(), actions::undo::recall_action::undo(), actions::undo::recruit_action::undo(), actions::undo::move_action::undo(), actions::undo_action::undo_action(), unit_display::unit_attack(), ai::default_recruitment::recruitment::update_important_hexes(), ai::default_recruitment::recruitment::update_own_units_count(), pathfind::vision_path::vision_path(), and game_events::WML_HANDLER_FUNCTION().

◆ units() [2/2]

unit_map& game_board::units ( )
inline

Definition at line 119 of file game_board.hpp.

◆ write_config()

void game_board::write_config ( config cfg) const

Friends And Related Function Documentation

◆ events::menu_handler

friend class events::menu_handler
friend

Definition at line 63 of file game_board.hpp.

◆ events::mouse_handler

friend class events::mouse_handler
friend

Definition at line 62 of file game_board.hpp.

◆ game_lua_kernel

friend class game_lua_kernel
friend

Definition at line 65 of file game_board.hpp.

◆ game_state

friend class game_state
friend

Definition at line 64 of file game_board.hpp.

◆ play_controller

friend class play_controller
friend

Definition at line 61 of file game_board.hpp.

◆ swap

void swap ( game_board one,
game_board other 
)
friend

Definition at line 57 of file game_board.cpp.

◆ temporary_unit_mover

friend struct temporary_unit_mover
friend

Definition at line 82 of file game_board.hpp.

◆ temporary_unit_placer

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 81 of file game_board.hpp.

◆ temporary_unit_remover

friend struct temporary_unit_remover
friend

Definition at line 83 of file game_board.hpp.

Member Data Documentation

◆ labels_

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

Definition at line 54 of file game_board.hpp.

◆ map_

std::unique_ptr<gamemap> game_board::map_
private

◆ teams_

std::vector<team> game_board::teams_
private

◆ unit_id_manager_

n_unit::id_manager game_board::unit_id_manager_
private

Definition at line 57 of file game_board.hpp.

Referenced by swap(), and write_config().

◆ units_

unit_map game_board::units_
private

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