The Battle for Wesnoth  1.19.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:

Public Member Functions

n_unit::id_managerunit_id_manager ()
 
 game_board (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
 
gamemapmap ()
 
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, side_controller::type ctrl, side_proxy_controller::type proxy=side_proxy_controller::type::human)
 
void side_change_controller (int side_num, bool is_local, const std::string &pname, const std::string &controller_type)
 
bool try_add_unit_to_recall_list (const map_location &loc, const unit_ptr u)
 
std::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)
 
bool change_terrain (const map_location &loc, const t_translation::terrain_code &t, terrain_type_data::merge_mode &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...
 
const teamget_team (int side) const
 This getter takes a 1-based side number, not a 0-based team number. More...
 
- Public Member Functions inherited from display_context
const teamget_team (int side) const
 This getter takes a 1-based side number, not a 0-based team number. More...
 
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
 
unit_const_ptr get_visible_unit_shared_ptr (const map_location &loc, const team &current_team, bool see_all=false) const
 
can_move_result unit_can_move (const unit &u) const
 Work out what u can do - this does not check which player's turn is currently active, the result is calculated assuming that the unit's owner is currently active. More...
 
orb_status unit_orb_status (const unit &u) const
 Returns an enumurated summary of whether this unit can move and/or attack. More...
 
int village_owner (const map_location &loc) const
 Given the location of a village, will return the 1-based number of the team that currently owns it, and 0 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

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

Constructor & Destructor Documentation

◆ game_board() [1/2]

game_board::game_board ( const config level)

Definition at line 38 of file game_board.cpp.

◆ ~game_board()

game_board::~game_board ( )
virtual

Definition at line 55 of file game_board.cpp.

◆ game_board() [2/2]

game_board::game_board ( const game_board other)

Definition at line 46 of file game_board.cpp.

Member Function Documentation

◆ change_terrain() [1/2]

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

◆ change_terrain() [2/2]

bool game_board::change_terrain ( const map_location loc,
const t_translation::terrain_code t,
terrain_type_data::merge_mode 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 114 of file game_board.cpp.

References DBG_EE, get_team(), i, and units().

Referenced by play_controller::check_victory().

◆ end_turn()

void game_board::end_turn ( int  pnum)

Definition at line 79 of file game_board.cpp.

References i, and units_.

Referenced by play_controller::finish_side_turn_events().

◆ find_unit()

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

Definition at line 171 of file game_board.hpp.

References unit_map::find(), and units_.

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

References find_visible_unit(), and teams_.

Referenced by find_visible_unit().

◆ get_team() [1/2]

team& game_board::get_team ( int  i)
inline

Definition at line 91 of file game_board.hpp.

References i, and teams_.

Referenced by pathfind::full_cost_map::add_unit(), unit::apply_builtin_effect(), actions::undo_list::apply_shroud_changes(), game_state::can_recruit_from(), game_state::can_recruit_on(), actions::shroud_clearer::clear_dest(), actions::clear_shroud(), actions::shroud_clearer::clear_unit(), ai::default_ai_context_impl::count_free_hexes_in_castle(), wb::current_side_actions(), play_controller::current_team(), ai::readonly_context_impl::current_team(), ai::readwrite_context_impl::current_team_w(), do_replay_handle(), ai::ai_default_rca::leader_shares_keep_phase::execute(), wb::find_actions_of(), 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(), game_state::init(), game_lua_kernel::intf_erase_unit(), game_lua_kernel::intf_extract_unit(), game_lua_kernel::intf_find_cost_map(), game_lua_kernel::intf_find_reach(), game_lua_kernel::intf_match_unit(), game_lua_kernel::intf_put_recall_unit(), game_lua_kernel::intf_set_side_id(), game_lua_kernel::intf_set_village_owner(), game_lua_kernel::intf_toggle_fog(), ai::ai_default_rca::aspect_attacks::is_allowed_enemy(), playsingle_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(), unit_display::unit_mover::replace_temporary(), playsingle_controller::show_turn_dialog(), ai::simulated_recall(), ai::simulated_recruit(), SYNCED_COMMAND_HANDLER_FUNCTION(), actions::undo::dismiss_action::undo(), actions::undo::recall_action::undo(), actions::undo::recruit_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(), pathfind::vision_path::vision_path(), and game_events::WML_HANDLER_FUNCTION().

◆ get_team() [2/2]

const team & display_context::get_team

This getter takes a 1-based side number, not a 0-based team number.

Definition at line 44 of file display_context.cpp.

Referenced by change_terrain(), check_victory(), heal_all_survivors(), replace_map(), side_change_controller(), side_drop_to(), and try_add_unit_to_recall_list().

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

References has_visible_unit(), and teams_.

Referenced by has_visible_unit().

◆ heal_all_survivors()

void game_board::heal_all_survivors ( )

Definition at line 95 of file game_board.cpp.

References get_team(), team::persistent(), t, teams_, and units_.

Referenced by playsingle_controller::do_end_level().

◆ hidden_label_categories() [1/2]

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

Implements display_context.

Definition at line 116 of file game_board.hpp.

References labels_.

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

References labels_.

◆ map() [1/2]

gamemap& game_board::map ( )
inline

Definition at line 101 of file game_board.hpp.

References map_.

◆ map() [2/2]

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

Implements display_context.

Definition at line 96 of file game_board.hpp.

References map_.

Referenced by ai::ai_default_rca::move_to_targets_phase::access_points(), game_state::add_side_wml(), battle_context_unit_stats::battle_context_unit_stats(), game_state::can_recruit_from(), game_state::can_recruit_on(), carryover_show_gold(), 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(), 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::get_villages_phase::execute(), 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(), pathfind::full_cost_map::get_pair_at(), actions::get_recalls(), actions::get_recruits(), events::mouse_handler::get_route(), game_lua_kernel::impl_get_terrain_info(), impl_side_get(), team_builder::init(), game_state::init(), game_lua_kernel::intf_find_path(), game_lua_kernel::map(), pathfind::mark_route(), 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_impl(), 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 70 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()

std::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 88 of file game_board.cpp.

References i, and units_.

Referenced by playsingle_controller::linger().

◆ side_change_controller()

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

◆ side_drop_to()

void game_board::side_drop_to ( int  side_num,
side_controller::type  ctrl,
side_proxy_controller::type  proxy = side_proxy_controller::type::human 
)

◆ team_is_defeated()

bool game_board::team_is_defeated ( const team t) const

Calculates whether a team is defeated.

Definition at line 267 of file game_board.cpp.

References unit_map::find_leader(), t, units_, and unit_map::iterator_base< iter_types >::valid().

Referenced by actions::get_village().

◆ teams() [1/2]

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

Definition at line 84 of file game_board.hpp.

References teams_.

◆ teams() [2/2]

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

Implements display_context.

Definition at line 79 of file game_board.hpp.

References teams_.

Referenced by scoped_recall_unit::activate(), actions::actor_sighted(), game_state::add_side_wml(), map_labels::all_categories(), wb::recall::apply_temp_modifier(), wb::recruit::apply_temp_modifier(), team::calculate_is_enemy(), ai::readonly_context_impl::calculate_moves(), carryover_show_gold(), wb::recruit::check_validity(), 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(), wb::recruit::execute(), gui2::dialogs::game_stats::execute(), 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(), play_controller::get_teams(), 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(), game_state::init(), wb::move::init(), game_lua_kernel::intf_find_cost_map(), 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(), playmp_controller::process_network_change_controller_impl(), playmp_controller::process_network_side_drop_impl(), wb::recall::remove_temp_modifier(), wb::manager::send_network_data(), game_lua_kernel::teams(), user_choice_manager::user_choice_manager(), wb::viewer_actions(), and game_events::WML_HANDLER_FUNCTION().

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

References recall_list_manager::add(), get_team(), and team::recall_list().

Referenced by replace_map().

◆ unit_id_manager()

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

◆ units() [1/2]

unit_map& game_board::units ( )
inline

Definition at line 111 of file game_board.hpp.

References units_.

◆ units() [2/2]

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

Implements display_context.

Definition at line 106 of file game_board.hpp.

References units_.

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(), 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::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(), 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::combat_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::ai_default_rca::get_healing_phase::evaluate(), ai::ai_default_rca::retreat_phase::evaluate(), ai::ai_default_rca::leader_shares_keep_phase::evaluate(), ai::default_recruitment::recruitment::evaluate(), ai::ai_default_rca::get_villages_phase::execute(), ai::ai_default_rca::leader_shares_keep_phase::execute(), ai::ai_default_rca::move_to_targets_phase::execute(), ai::default_recruitment::recruitment::execute(), wb::attack::execute(), wb::move::execute(), wb::recruit::execute(), ai::readwrite_context_impl::execute_attack_action(), wfl::set_unit_var_callable::execute_self(), ai::attack_analysis::execute_self(), wb::find_backup_leader(), unit_creator::find_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(), ai::move_result::get_unit(), ai::stopunit_result::get_unit(), game_events::entity_location::get_unit(), wb::move::get_unit(), wb::suppose_dead::get_unit(), wb::highlighter::get_unit_map(), ai::default_recruitment::recruitment::get_unit_ratio(), play_controller::get_units(), ai::formula_ai::get_value(), wfl::attack_map_callable::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(), 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(), actions::move_unit_and_record(), wb::manager::on_mouseover_change(), game_events::filter_unit::operator()(), game_events::filter_attack::operator()(), actions::place_recruit(), 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::move::remove_temp_modifier(), wb::suppose_dead::remove_temp_modifier(), ai::formula_ai::shortest_path_calculator(), events::mouse_handler::show_attack_dialog(), 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::move_action::undo(), actions::undo::recall_action::undo(), actions::undo::recruit_action::undo(), unit_display::unit_attack(), game_lua_kernel::units(), 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().

◆ write_config()

void game_board::write_config ( config cfg) const

Friends And Related Function Documentation

◆ swap

void swap ( game_board one,
game_board other 
)
friend

Definition at line 62 of file game_board.cpp.

◆ temporary_unit_mover

friend struct temporary_unit_mover
friend

Definition at line 69 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 68 of file game_board.hpp.

◆ temporary_unit_remover

friend struct temporary_unit_remover
friend

Definition at line 70 of file game_board.hpp.

Member Data Documentation

◆ labels_

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

Definition at line 48 of file game_board.hpp.

Referenced by hidden_label_categories().

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

Referenced by unit_id_manager(), and write_config().

◆ units_

unit_map game_board::units_
private

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