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

This class is the frontend of the whiteboard framework for the rest of the Wesnoth code. More...

#include <manager.hpp>

Public Member Functions

 manager (const manager &)=delete
 
manageroperator= (const manager &)=delete
 
 manager ()
 
 ~manager ()
 
void print_help_once ()
 
bool can_modify_game_state () const
 Determine whether the game is initialized and the current side has control of the game i.e. More...
 
bool can_activate () const
 Determine whether the whiteboard can be activated safely. More...
 
bool is_active () const
 Determine whether the whiteboard is activated. More...
 
void set_active (bool active)
 Activates/Deactivates the whiteboard. More...
 
void set_invert_behavior (bool invert)
 Called by the key that temporarily toggles the activated state when held. More...
 
whiteboard_lock get_activation_state_lock ()
 Prevents the whiteboard from changing its activation state, as long as the returned reference is held. More...
 
bool is_executing_actions () const
 Is the whiteboard in the process of executing an action? More...
 
bool can_enable_execution_hotkeys () const
 Used to ask the whiteboard if its action execution hotkeys should be available to the user. More...
 
bool can_enable_modifier_hotkeys () const
 Used to ask the whiteboard if hotkeys affecting the action queue should be available to the user. More...
 
bool can_enable_reorder_hotkeys () const
 Used to ask the whiteboard if its action reordering hotkeys should be available to the user. More...
 
bool allow_leader_to_move (unit const &leader) const
 Used to ask permission to the wb to move a leader, to avoid invalidating planned recruits. More...
 
bool allow_end_turn ()
 @ return true if the whiteboard is ready to end turn. More...
 
void on_init_side ()
 The on_* methods below inform the whiteboard of specific events. More...
 
void on_finish_side_turn (int side)
 
void on_mouseover_change (const map_location &hex)
 
void on_deselect_hex ()
 
void on_gamestate_change ()
 
void on_viewer_change (size_t team_index)
 
void on_change_controller (int side, const team &t)
 
void on_kill_unit ()
 
void pre_delete_action (action_ptr action)
 Handles various cleanup right before removing an action from the queue. More...
 
void post_delete_action (action_ptr action)
 Handles various cleanup right after removing an action from the queue. More...
 
void send_network_data ()
 Called by replay_network_sender to add whiteboard data to the outgoing network packets. More...
 
void process_network_data (config const &)
 Called by turn_info::process_network_data() when network data needs to be processed. More...
 
void queue_net_cmd (size_t team_index, side_actions::net_cmd const &)
 Adds a side_actions::net_cmd to net_buffer_[team_index], whereupon it will (later) be sent to all allies. More...
 
void validate_viewer_actions ()
 Validates all actions of the current viewing side. More...
 
bool has_planned_unit_map () const
 Whether the planned unit map is currently applied. More...
 
void pre_draw ()
 Called from the display before drawing. More...
 
void post_draw ()
 Called from the display after drawing. More...
 
void draw_hex (const map_location &hex)
 Called from the display when drawing hexes, to allow the whiteboard to add visual elements. More...
 
void create_temp_move ()
 Creates a temporary visual arrow, that follows the cursor, for move creation purposes. More...
 
bool has_temp_move () const
 Informs whether an arrow is being displayed for move creation purposes. More...
 
void erase_temp_move ()
 Erase the temporary arrow. More...
 
void save_temp_move ()
 Creates a move action for the current side, and erases the temp move. More...
 
unit_map::iterator get_temp_move_unit () const
 
void save_temp_attack (const map_location &attacker_loc, const map_location &defender_loc, int weapon_choice)
 Creates an attack or attack-move action for the current side. More...
 
bool save_recruit (const std::string &name, int side_num, const map_location &recruit_hex)
 Creates a recruit action for the current side. More...
 
bool save_recall (const unit &unit, int side_num, const map_location &recall_hex)
 Creates a recall action for the current side. More...
 
void save_suppose_dead (unit &curr_unit, map_location const &loc)
 Creates a suppose-dead action for the current side. More...
 
void contextual_execute ()
 Executes first action in the queue for current side. More...
 
bool execute_all_actions ()
 Executes all actions for the current turn in sequence. More...
 
void contextual_delete ()
 Deletes last action in the queue for current side. More...
 
void contextual_bump_up_action ()
 Moves the action determined by the UI toward the beginning of the queue. More...
 
void contextual_bump_down_action ()
 Moves the action determined by the UI toward the beginning of the queue. More...
 
std::weak_ptr< highlighterget_highlighter ()
 Get the highlight visitor instance in use by the manager. More...
 
bool has_actions () const
 Checks whether the whiteboard has any planned action on any team. More...
 
bool unit_has_actions (unit const *unit) const
 Checks whether the specified unit has at least one planned action. More...
 
int get_spent_gold_for (int side)
 Used to track gold spending per-side when building the planned unit map Is referenced by the top bar gold display. More...
 
bool should_clear_undo () const
 Determines whether or not the undo_stack should be cleared. More...
 
void options_dlg ()
 Displays the whiteboard options dialog. More...
 

Static Public Member Functions

static bool current_side_has_actions ()
 Whether the current side has actions in the first turn of its planned actions queue. More...
 

Private Member Functions

void set_planned_unit_map ()
 Transforms the unit map so that it now reflects the future state of things, i.e. More...
 
void set_real_unit_map ()
 Restore the regular unit map. More...
 
void validate_actions_if_needed ()
 
void update_plan_hiding (size_t viewing_team)
 Called by all of the save_***() methods after they have added their action to the queue. More...
 
void update_plan_hiding ()
 

Private Attributes

bool active_
 Tracks whether the whiteboard is active. More...
 
bool inverted_behavior_
 
bool self_activate_once_
 
bool wait_for_side_init_
 
bool planned_unit_map_active_
 
bool executing_actions_
 Track whenever we're modifying actions, to avoid dual execution etc. More...
 
bool executing_all_actions_
 Track whether we're in the process of executing all actions. More...
 
bool preparing_to_end_turn_
 true if we're in the process of executing all action and should end turn once finished. More...
 
bool gamestate_mutated_
 Track whether the gamestate changed and we need to validate actions. More...
 
whiteboard_lock activation_state_lock_
 Reference counted "lock" to allow preventing whiteboard activation state changes. More...
 
whiteboard_lock unit_map_lock_
 Reference counted "lock" to prevent the building of the unit map at certain times. More...
 
std::unique_ptr< mapbuildermapbuilder_
 
std::shared_ptr< highlighterhighlighter_
 
std::unique_ptr
< pathfind::marked_route
route_
 
std::vector< arrow_ptrmove_arrows_
 
std::vector< fake_unit_ptrfake_units_
 
size_t temp_move_unit_underlying_id_
 
const std::unique_ptr< CKeykey_poller_
 
std::vector< map_locationhidden_unit_hexes_
 
std::vector< confignet_buffer_
 net_buffer_[i] = whiteboard network data to be sent "from" teams[i]. More...
 
boost::dynamic_bitset team_plans_hidden_
 team_plans_hidden_[i] = whether or not to hide actions from teams[i]. More...
 
std::set< size_t > units_owning_moves_
 used to keep track of units owning planned moves for visual ghosting/unghosting More...
 

Friends

struct future_map
 
struct future_map_if_active
 
struct real_map
 

Detailed Description

This class is the frontend of the whiteboard framework for the rest of the Wesnoth code.

Definition at line 42 of file manager.hpp.

Constructor & Destructor Documentation

wb::manager::manager ( const manager )
delete
wb::manager::manager ( )

Definition at line 58 of file manager.cpp.

References preferences::hide_whiteboard(), LOG_WB, and team_plans_hidden_.

wb::manager::~manager ( )

Definition at line 91 of file manager.cpp.

References LOG_WB.

Member Function Documentation

bool wb::manager::allow_end_turn ( )

@ return true if the whiteboard is ready to end turn.

Triggers the execution of remaining planned actions.

Definition at line 954 of file manager.cpp.

References execute_all_actions(), and preparing_to_end_turn_.

bool wb::manager::allow_leader_to_move ( unit const &  leader) const

Used to ask permission to the wb to move a leader, to avoid invalidating planned recruits.

Definition at line 261 of file manager.cpp.

References resources::filter_con, wb::find_backup_leader(), has_actions(), has_planned_unit_map(), wb::viewer_actions(), and WRN_WB.

bool wb::manager::can_activate ( ) const

Determine whether the whiteboard can be activated safely.

Definition at line 161 of file manager.cpp.

References activation_state_lock_, and can_modify_game_state().

Referenced by set_active(), and set_invert_behavior().

bool wb::manager::can_enable_execution_hotkeys ( ) const

Used to ask the whiteboard if its action execution hotkeys should be available to the user.

Definition at line 245 of file manager.cpp.

References can_enable_modifier_hotkeys(), resources::controller, play_controller::current_side(), wb::viewer_actions(), and wb::viewer_side().

Referenced by contextual_execute(), and execute_all_actions().

bool wb::manager::can_enable_modifier_hotkeys ( ) const

Used to ask the whiteboard if hotkeys affecting the action queue should be available to the user.

Definition at line 251 of file manager.cpp.

References can_modify_game_state(), and wb::viewer_actions().

Referenced by can_enable_execution_hotkeys(), can_enable_reorder_hotkeys(), and contextual_delete().

bool wb::manager::can_enable_reorder_hotkeys ( ) const

Used to ask the whiteboard if its action reordering hotkeys should be available to the user.

Definition at line 256 of file manager.cpp.

References can_enable_modifier_hotkeys(), and highlighter_.

Referenced by contextual_bump_down_action(), and contextual_bump_up_action().

bool wb::manager::can_modify_game_state ( ) const

Determine whether the game is initialized and the current side has control of the game i.e.

the whiteboard can take over

Definition at line 145 of file manager.cpp.

References resources::controller, executing_actions_, resources::gameboard, and wait_for_side_init_.

Referenced by can_activate(), can_enable_modifier_hotkeys(), create_temp_move(), pre_draw(), and set_planned_unit_map().

void wb::manager::contextual_bump_down_action ( )

Moves the action determined by the UI toward the beginning of the queue.

Definition at line 1046 of file manager.cpp.

References can_enable_reorder_hotkeys(), highlighter_, validate_viewer_actions(), and wb::viewer_actions().

void wb::manager::contextual_bump_up_action ( )

Moves the action determined by the UI toward the beginning of the queue.

Definition at line 1034 of file manager.cpp.

References can_enable_reorder_hotkeys(), highlighter_, validate_viewer_actions(), and wb::viewer_actions().

void wb::manager::contextual_delete ( )

Deletes last action in the queue for current side.

Todo:
Shouldn't we probably deselect the unit at this point?

Definition at line 1008 of file manager.cpp.

References can_enable_modifier_hotkeys(), resources::controller, erase_temp_move(), wb::future_visible_unit(), highlighter_, validate_viewer_actions(), wb::viewer_actions(), and wb::viewer_side().

void wb::manager::contextual_execute ( )
void wb::manager::create_temp_move ( )
bool wb::manager::current_side_has_actions ( )
static

Whether the current side has actions in the first turn of its planned actions queue.

Definition at line 420 of file manager.cpp.

References wb::current_side_actions().

void wb::manager::draw_hex ( const map_location hex)

Called from the display when drawing hexes, to allow the whiteboard to add visual elements.

Some visual elements such as arrows and fake units are not handled through this function, but separately registered with the display.

IMPORTANT: none of the code in this method can call anything which would cause a hex to be invalidated (i.e. by calling in turn any variant of display::invalidate()). Doing so messes up the iterator currently going over the list of invalidated hexes to draw.

Definition at line 549 of file manager.cpp.

References wb::action::draw_hex(), wb::draw_numbers(), wb::for_each_action(), resources::gameboard, wb::side_actions::get_numbers(), has_actions(), wb::side_actions::hidden(), t, and wait_for_side_init_.

void wb::manager::erase_temp_move ( )
bool wb::manager::execute_all_actions ( )

Executes all actions for the current turn in sequence.

Returns
true if the there are no more actions left for this turn when the method returns

Definition at line 960 of file manager.cpp.

References can_enable_execution_hotkeys(), erase_temp_move(), ERR_WB, executing_actions_, executing_all_actions_, has_planned_unit_map(), set_planned_unit_map(), set_real_unit_map(), validate_viewer_actions(), wb::viewer_actions(), and resources::whiteboard.

Referenced by allow_end_turn().

whiteboard_lock wb::manager::get_activation_state_lock ( )
inline

Prevents the whiteboard from changing its activation state, as long as the returned reference is held.

Definition at line 70 of file manager.hpp.

References activation_state_lock_.

std::weak_ptr<highlighter> wb::manager::get_highlighter ( )
inline

Get the highlight visitor instance in use by the manager.

Definition at line 172 of file manager.hpp.

References highlighter_.

int wb::manager::get_spent_gold_for ( int  side)

Used to track gold spending per-side when building the planned unit map Is referenced by the top bar gold display.

Definition at line 1071 of file manager.cpp.

References resources::gameboard, team::get_side_actions(), game_board::get_team(), and wait_for_side_init_.

unit_map::iterator wb::manager::get_temp_move_unit ( ) const
Returns
an iterator to the unit that owns the temp move, resources::gameboard->units().end() if there's none.

Definition at line 802 of file manager.cpp.

References unit_map::find(), resources::gameboard, temp_move_unit_underlying_id_, and game_board::units().

bool wb::manager::has_actions ( ) const

Checks whether the whiteboard has any planned action on any team.

Definition at line 1058 of file manager.cpp.

References resources::gameboard, and wb::has_actions().

Referenced by allow_leader_to_move(), draw_hex(), and pre_draw().

bool wb::manager::has_planned_unit_map ( ) const
inline

Whether the planned unit map is currently applied.

Definition at line 115 of file manager.hpp.

References planned_unit_map_active_.

Referenced by allow_leader_to_move(), execute_all_actions(), and validate_viewer_actions().

bool wb::manager::has_temp_move ( ) const
inline

Informs whether an arrow is being displayed for move creation purposes.

Definition at line 136 of file manager.hpp.

References fake_units_, move_arrows_, and route_.

Referenced by on_mouseover_change(), and save_temp_move().

bool wb::manager::is_active ( ) const
inline

Determine whether the whiteboard is activated.

Definition at line 64 of file manager.hpp.

References active_.

bool wb::manager::is_executing_actions ( ) const
inline

Is the whiteboard in the process of executing an action?

Definition at line 73 of file manager.hpp.

References executing_actions_.

void wb::manager::on_change_controller ( int  side,
const team t 
)
void wb::manager::on_deselect_hex ( )
inline

Definition at line 91 of file manager.hpp.

References erase_temp_move().

void wb::manager::on_finish_side_turn ( int  side)
void wb::manager::on_gamestate_change ( )
void wb::manager::on_init_side ( )

The on_* methods below inform the whiteboard of specific events.

Definition at line 294 of file manager.cpp.

References preferences::enable_whiteboard_mode_on_start(), executing_actions_, executing_all_actions_, LOG_WB, self_activate_once_, set_active(), update_plan_hiding(), and wait_for_side_init_.

void wb::manager::on_kill_unit ( )

Definition at line 413 of file manager.cpp.

References highlighter_.

void wb::manager::on_mouseover_change ( const map_location hex)
void wb::manager::on_viewer_change ( size_t  team_index)

Definition at line 378 of file manager.cpp.

References update_plan_hiding(), and wait_for_side_init_.

manager& wb::manager::operator= ( const manager )
delete
void wb::manager::options_dlg ( )
void wb::manager::post_delete_action ( action_ptr  action)

Handles various cleanup right after removing an action from the queue.

Definition at line 326 of file manager.cpp.

References resources::gameboard, wb::move::get_fake_unit(), and game_board::teams().

void wb::manager::post_draw ( )
void wb::manager::pre_delete_action ( action_ptr  action)

Handles various cleanup right before removing an action from the queue.

Definition at line 322 of file manager.cpp.

void wb::manager::pre_draw ( )
void wb::manager::print_help_once ( )
void wb::manager::process_network_data ( config const &  cfg)
void wb::manager::queue_net_cmd ( size_t  team_index,
side_actions::net_cmd const &  cmd 
)

Adds a side_actions::net_cmd to net_buffer_[team_index], whereupon it will (later) be sent to all allies.

Definition at line 644 of file manager.cpp.

References net_buffer_.

Referenced by on_change_controller().

bool wb::manager::save_recall ( const unit unit,
int  side_num,
const map_location recall_hex 
)

Creates a recall action for the current side.

Returns
true if manager has saved a planned recall

Definition at line 885 of file manager.cpp.

References active_, resources::controller, executing_actions_, LOG_WB, wb::side_actions::num_turns(), print_help_once(), wb::side_actions::queue_recall(), resources::screen, and wb::viewer_actions().

bool wb::manager::save_recruit ( const std::string &  name,
int  side_num,
const map_location recruit_hex 
)

Creates a recruit action for the current side.

Returns
true if manager has saved a planned recruit

Definition at line 857 of file manager.cpp.

References active_, resources::controller, executing_actions_, wb::find_recruiter(), wb::side_actions::get_turn_num_of(), LOG_WB, print_help_once(), wb::side_actions::queue_recruit(), resources::screen, and wb::viewer_actions().

void wb::manager::save_suppose_dead ( unit curr_unit,
map_location const &  loc 
)
void wb::manager::save_temp_attack ( const map_location attacker_loc,
const map_location defender_loc,
int  weapon_choice 
)
void wb::manager::save_temp_move ( )
void wb::manager::send_network_data ( )
void wb::manager::set_active ( bool  active)
void wb::manager::set_invert_behavior ( bool  invert)

Called by the key that temporarily toggles the activated state when held.

Definition at line 195 of file manager.cpp.

References activation_state_lock_, active_, can_activate(), DBG_WB, inverted_behavior_, and set_active().

void wb::manager::set_planned_unit_map ( )
private

Transforms the unit map so that it now reflects the future state of things, i.e.

when all planned actions will have been executed

Definition at line 1141 of file manager.cpp.

References can_modify_game_state(), resources::gameboard, log_scope2, LOG_WB, mapbuilder_, planned_unit_map_active_, unit_map_lock_, resources::units, and WRN_WB.

Referenced by execute_all_actions().

void wb::manager::set_real_unit_map ( )
private

Restore the regular unit map.

Definition at line 1164 of file manager.cpp.

References executing_actions_, log_scope2, LOG_WB, mapbuilder_, planned_unit_map_active_, and wait_for_side_init_.

Referenced by execute_all_actions().

bool wb::manager::should_clear_undo ( ) const
inline

Determines whether or not the undo_stack should be cleared.

Todo:
Only when there are networked allies and we have set a preferences option

Definition at line 185 of file manager.hpp.

Referenced by set_active().

bool wb::manager::unit_has_actions ( unit const *  unit) const

Checks whether the specified unit has at least one planned action.

Definition at line 1064 of file manager.cpp.

References resources::gameboard, and wb::viewer_actions().

void wb::manager::update_plan_hiding ( size_t  viewing_team)
private

Called by all of the save_***() methods after they have added their action to the queue.

Definition at line 354 of file manager.cpp.

References schema_validation::at(), resources::gameboard, wb::hide_all_plans(), t, team_plans_hidden_, and validate_viewer_actions().

void wb::manager::update_plan_hiding ( )
private

Definition at line 375 of file manager.cpp.

References wb::viewer_team().

Referenced by on_change_controller(), on_init_side(), on_viewer_change(), and options_dlg().

void wb::manager::validate_actions_if_needed ( )
private

Definition at line 1183 of file manager.cpp.

References gamestate_mutated_, and validate_viewer_actions().

void wb::manager::validate_viewer_actions ( )

Friends And Related Function Documentation

friend struct future_map
friend

Definition at line 44 of file manager.hpp.

Referenced by validate_viewer_actions().

friend struct future_map_if_active
friend

Definition at line 45 of file manager.hpp.

friend struct real_map
friend

Definition at line 46 of file manager.hpp.

Referenced by validate_viewer_actions().

Member Data Documentation

whiteboard_lock wb::manager::activation_state_lock_
private

Reference counted "lock" to allow preventing whiteboard activation state changes.

Definition at line 221 of file manager.hpp.

Referenced by can_activate(), get_activation_state_lock(), and set_invert_behavior().

bool wb::manager::active_
private

Tracks whether the whiteboard is active.

Definition at line 203 of file manager.hpp.

Referenced by create_temp_move(), is_active(), save_recall(), save_recruit(), save_suppose_dead(), save_temp_attack(), set_active(), and set_invert_behavior().

bool wb::manager::executing_actions_
private
bool wb::manager::executing_all_actions_
private

Track whether we're in the process of executing all actions.

Definition at line 214 of file manager.hpp.

Referenced by execute_all_actions(), and on_init_side().

std::vector<fake_unit_ptr> wb::manager::fake_units_
private
bool wb::manager::gamestate_mutated_
private

Track whether the gamestate changed and we need to validate actions.

Definition at line 218 of file manager.hpp.

Referenced by on_gamestate_change(), validate_actions_if_needed(), and validate_viewer_actions().

std::vector<map_location> wb::manager::hidden_unit_hexes_
private

Definition at line 237 of file manager.hpp.

std::shared_ptr<highlighter> wb::manager::highlighter_
private
bool wb::manager::inverted_behavior_
private

Definition at line 204 of file manager.hpp.

Referenced by set_invert_behavior().

const std::unique_ptr<CKey> wb::manager::key_poller_
private

Definition at line 235 of file manager.hpp.

std::unique_ptr<mapbuilder> wb::manager::mapbuilder_
private

Definition at line 226 of file manager.hpp.

Referenced by set_planned_unit_map(), and set_real_unit_map().

std::vector<arrow_ptr> wb::manager::move_arrows_
private
std::vector<config> wb::manager::net_buffer_
private

net_buffer_[i] = whiteboard network data to be sent "from" teams[i].

Definition at line 240 of file manager.hpp.

Referenced by queue_net_cmd(), and send_network_data().

bool wb::manager::planned_unit_map_active_
private
bool wb::manager::preparing_to_end_turn_
private

true if we're in the process of executing all action and should end turn once finished.

Definition at line 216 of file manager.hpp.

Referenced by allow_end_turn(), and on_finish_side_turn().

std::unique_ptr<pathfind::marked_route> wb::manager::route_
private
bool wb::manager::self_activate_once_
private

Definition at line 205 of file manager.hpp.

Referenced by on_init_side().

boost::dynamic_bitset wb::manager::team_plans_hidden_
private

team_plans_hidden_[i] = whether or not to hide actions from teams[i].

Definition at line 243 of file manager.hpp.

Referenced by manager(), options_dlg(), and update_plan_hiding().

size_t wb::manager::temp_move_unit_underlying_id_
private

Definition at line 233 of file manager.hpp.

Referenced by create_temp_move(), erase_temp_move(), and get_temp_move_unit().

whiteboard_lock wb::manager::unit_map_lock_
private

Reference counted "lock" to prevent the building of the unit map at certain times.

Definition at line 223 of file manager.hpp.

Referenced by pre_draw(), and set_planned_unit_map().

std::set<size_t> wb::manager::units_owning_moves_
private

used to keep track of units owning planned moves for visual ghosting/unghosting

Definition at line 246 of file manager.hpp.

Referenced by post_draw(), and pre_draw().

bool wb::manager::wait_for_side_init_
private

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