Game board class. More...
#include <game_board.hpp>
Public Member Functions | |
n_unit::id_manager & | unit_id_manager () |
game_board (const config &level) | |
virtual | ~game_board () |
virtual const std::vector< team > & | teams () const override |
std::vector< team > & | teams () |
team & | get_team (int i) |
virtual const gamemap & | map () const override |
gamemap & | map () |
virtual const unit_map & | units () const override |
unit_map & | units () |
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_board & | operator= (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) |
utils::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 ¤t_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 |
unit * | get_visible_unit (const map_location &loc, const team ¤t_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 team & | get_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 team & | get_team (int side) const |
This getter takes a 1-based side number, not a 0-based team number. More... | |
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 unit * | get_visible_unit (const map_location &loc, const team ¤t_team, bool see_all=false) const |
unit_const_ptr | get_visible_unit_shared_ptr (const map_location &loc, const team ¤t_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< team > | teams_ |
std::vector< std::string > | labels_ |
std::unique_ptr< gamemap > | map_ |
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) |
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 46 of file game_board.hpp.
game_board::game_board | ( | const config & | level | ) |
Definition at line 38 of file game_board.cpp.
|
virtual |
Definition at line 55 of file game_board.cpp.
game_board::game_board | ( | const game_board & | other | ) |
Definition at line 46 of file game_board.cpp.
bool game_board::change_terrain | ( | const map_location & | loc, |
const std::string & | t, | ||
const std::string & | mode, | ||
bool | replace_if_failed | ||
) |
Definition at line 327 of file game_board.cpp.
References terrain_type_data::BASE, terrain_type_data::BOTH, loc, t_translation::NONE_TERRAIN, terrain_type_data::OVERLAY, and t_translation::read_terrain_code().
Referenced by impl_merge_terrain(), and SYNCED_COMMAND_HANDLER_FUNCTION().
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 | ||
) |
Definition at line 347 of file game_board.cpp.
References prefs::encountered_terrains(), prefs::get(), get_team(), loc, team::lose_village(), map_, t_translation::NONE_TERRAIN, and display_context::village_owner().
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, team::defeat_cond(), string_enums::enum_base< Definition >::get_string(), get_team(), i, and units().
Referenced by play_controller::check_victory().
void game_board::end_turn | ( | int | pnum | ) |
Definition at line 79 of file game_board.cpp.
Referenced by play_controller::finish_side_turn_events().
|
inline |
Definition at line 172 of file game_board.hpp.
References unit_map::find(), loc, and units_.
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 |
||
) |
Definition at line 185 of file game_board.cpp.
References unit_map::end(), unit_map::find(), loc, map_, units_, and unit_map::iterator_base< iter_types >::valid().
Referenced by actions::shroud_clearer::clear_loc(), events::menu_handler::current_unit(), events::mouse_handler::find_unit(), events::mouse_handler::find_unit_nonowning(), get_visible_unit(), game_lua_kernel::intf_get_displayed_unit(), SYNCED_COMMAND_HANDLER_FUNCTION(), and pathfind::teleport_map::teleport_map().
|
inline |
Definition at line 164 of file game_board.hpp.
References find_visible_unit(), loc, and teams_.
Referenced by find_visible_unit().
|
inline |
Definition at line 92 of file game_board.hpp.
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(), 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().
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().
unit * game_board::get_visible_unit | ( | const map_location & | loc, |
const team & | current_team, | ||
bool | see_all = false |
||
) |
Definition at line 213 of file game_board.cpp.
References unit_map::end(), find_visible_unit(), loc, and units_.
Referenced by wb::move::check_validity(), pathfind::shortest_path_calculator::cost(), pathfind::enemy_zoc(), pathfind::find_routes(), and wb::future_visible_unit().
bool game_board::has_visible_unit | ( | const map_location & | loc, |
const team & | team, | ||
bool | see_all = false |
||
) | const |
Definition at line 199 of file game_board.cpp.
References unit_map::find(), loc, map_, units_, and unit_map::iterator_base< iter_types >::valid().
Referenced by game_state::can_recruit_on().
|
inline |
Definition at line 166 of file game_board.hpp.
References has_visible_unit(), loc, and teams_.
Referenced by has_visible_unit().
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().
|
inlineoverridevirtual |
Implements display_context.
Definition at line 117 of file game_board.hpp.
References labels_.
Referenced by game_state::init().
|
inlineoverridevirtual |
|
inline |
Definition at line 102 of file game_board.hpp.
References map_.
|
inlineoverridevirtual |
Implements display_context.
Definition at line 97 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(), 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(), prefs::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(), game_lua_kernel::impl_get_terrain_list(), 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(), SIDE_GETTER(), 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().
void game_board::new_turn | ( | int | pnum | ) |
Definition at line 70 of file game_board.cpp.
Referenced by play_controller::do_init_side().
|
delete |
utils::optional< std::string > game_board::replace_map | ( | const gamemap & | r | ) |
Definition at line 292 of file game_board.cpp.
References unit_map::begin(), unit_map::end(), unit_map::erase(), get_team(), gamemap::is_village(), team::lose_village(), map_, gamemap_base::on_board(), try_add_unit_to_recall_list(), units_, and display_context::village_owner().
Referenced by game_events::WML_HANDLER_FUNCTION().
void game_board::set_all_units_user_end_turn | ( | ) |
Definition at line 88 of file game_board.cpp.
Referenced by playsingle_controller::linger().
void game_board::side_change_controller | ( | int | side_num, |
bool | is_local, | ||
const std::string & | pname, | ||
const std::string & | controller_type | ||
) |
Definition at line 239 of file game_board.cpp.
References unit_map::find_leader(), get_team(), team::is_ai(), team::is_human(), team::make_ai(), team::make_human(), team::set_current_player(), team::set_local(), units_, and unit_map::iterator_base< iter_types >::valid().
Referenced by playmp_controller::process_network_change_controller_impl().
void game_board::side_drop_to | ( | int | side_num, |
side_controller::type | ctrl, | ||
side_proxy_controller::type | proxy = side_proxy_controller::type::human |
||
) |
Definition at line 223 of file game_board.cpp.
References team::change_controller(), team::change_proxy(), unit_map::find_leader(), string_enums::enum_base< Definition >::get_string(), get_team(), team::set_current_player(), team::set_local(), units_, and unit_map::iterator_base< iter_types >::valid().
Referenced by playmp_controller::process_network_side_drop_impl().
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().
|
inline |
Definition at line 85 of file game_board.hpp.
References teams_.
|
inlineoverridevirtual |
Implements display_context.
Definition at line 80 of file game_board.hpp.
References teams_.
Referenced by scoped_recall_unit::activate(), actions::actor_sighted(), game_state::add_side_wml(), wb::recall::apply_temp_modifier(), wb::recruit::apply_temp_modifier(), team::calculate_is_enemy(), wb::recruit::check_validity(), wfl::gamestate::DEFINE_WFL_FUNCTION(), ai::ai_default_rca::aspect_attacks_base::do_attack_analysis(), wb::recall::draw_hex(), prefs::encounter_all_content(), wb::recall::execute(), wb::recruit::execute(), gui2::dialogs::game_stats::execute(), pathfind::find_routes(), events::mouse_handler::get_route(), team::get_side_color_id(), 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(), actions::move_unit_and_record(), wb::manager::on_change_controller(), playsingle_controller::play_scenario_main_loop(), wb::manager::post_delete_action(), 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(), and game_events::WML_HANDLER_FUNCTION().
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().
|
inline |
Definition at line 74 of file game_board.hpp.
References unit_id_manager_.
Referenced by set_scontext_synced::do_final_checkup(), synced_context::get_unit_id_diff(), unit::mark_clone(), and actions::undo_action_container::undo().
|
inline |
Definition at line 112 of file game_board.hpp.
References units_.
|
inlineoverridevirtual |
Implements display_context.
Definition at line 107 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(), prefs::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_event::undo(), 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().
void game_board::write_config | ( | config & | cfg | ) | const |
Definition at line 381 of file game_board.cpp.
References config::add_child(), n_unit::id_manager::get_save_id(), i, map_, t, teams_, unit_id_manager_, and units_.
Referenced by game_state::write().
|
friend |
Definition at line 62 of file game_board.cpp.
|
friend |
Definition at line 70 of file game_board.hpp.
|
friend |
Temporary unit move structs:
Probably don't remove these friends, this is actually fairly useful. These structs are used by:
Definition at line 69 of file game_board.hpp.
|
friend |
Definition at line 71 of file game_board.hpp.
|
private |
Definition at line 49 of file game_board.hpp.
Referenced by hidden_label_categories().
|
private |
Definition at line 51 of file game_board.hpp.
Referenced by change_terrain(), find_visible_unit(), has_visible_unit(), map(), replace_map(), and write_config().
|
private |
Definition at line 48 of file game_board.hpp.
Referenced by find_visible_unit(), get_team(), has_visible_unit(), heal_all_survivors(), teams(), and write_config().
|
private |
Definition at line 52 of file game_board.hpp.
Referenced by unit_id_manager(), and write_config().
|
private |
Definition at line 53 of file game_board.hpp.
Referenced by end_turn(), find_unit(), find_visible_unit(), get_visible_unit(), has_visible_unit(), heal_all_survivors(), new_turn(), replace_map(), set_all_units_user_end_turn(), side_change_controller(), side_drop_to(), team_is_defeated(), units(), and write_config().