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 Types | Private Member Functions | Private Attributes | List of all members
actions::undo_list Class Reference

Class to store the actions that a player can undo and redo. More...

#include <undo.hpp>

Public Member Functions

 undo_list (const undo_list &)=delete
 
undo_listoperator= (const undo_list &)=delete
 
 undo_list (const config &cfg)
 Constructor. More...
 
 ~undo_list ()
 Destructor. More...
 
void add_auto_shroud (bool turned_on)
 Adds an auto-shroud toggle to the undo stack. More...
 
void add_dummy ()
 Adds an auto-shroud toggle to the undo stack. More...
 
void add_dismissal (const unit_const_ptr u)
 Adds a dismissal to the undo stack. More...
 
void add_move (const unit_const_ptr u, const std::vector< map_location >::const_iterator &begin, const std::vector< map_location >::const_iterator &end, int start_moves, int timebonus=0, int village_owner=-1, const map_location::DIRECTION dir=map_location::NDIRECTIONS)
 Adds a move to the undo stack. More...
 
void add_recall (const unit_const_ptr u, const map_location &loc, const map_location &from, int orig_village_owner, bool time_bonus)
 Adds a recall to the undo stack. More...
 
void add_recruit (const unit_const_ptr u, const map_location &loc, const map_location &from, int orig_village_owner, bool time_bonus)
 Adds a recruit to the undo stack. More...
 
void add_update_shroud ()
 Adds a shroud update to the undo stack. More...
 
void clear ()
 Clears the stack of undoable (and redoable) actions. More...
 
void commit_vision ()
 Updates fog/shroud based on the undo stack, then updates stack as needed. More...
 
void new_side_turn (int side)
 Performs some initializations and error checks when starting a new side-turn. More...
 
bool player_acted () const
 Returns true if the player has performed any actions this turn. More...
 
void read (const config &cfg)
 Read the undo_list from the provided config. More...
 
void write (config &cfg) const
 Write the undo_list into the provided config. More...
 
bool can_undo () const
 True if there are actions that can be undone. More...
 
bool can_redo () const
 True if there are actions that can be redone. More...
 
void undo ()
 Undoes the top action on the undo stack. More...
 
void redo ()
 Redoes the top action on the redo stack. More...
 

Static Public Member Functions

static undo_action_basecreate_action (const config &cfg)
 Creates an undo_action based on a config. More...
 

Private Types

typedef boost::ptr_vector
< undo_action_base
action_list
 
typedef boost::ptr_vector< configredos_list
 

Private Member Functions

void add (undo_action_base *action)
 Adds an action to the undo stack. More...
 
bool apply_shroud_changes () const
 Applies the pending fog/shroud changes from the undo stack. More...
 

Private Attributes

action_list undos_
 
redos_list redos_
 
int side_
 Tracks the current side. More...
 
bool committed_actions_
 Tracks if actions have been cleared from the stack since the turn began. More...
 

Detailed Description

Class to store the actions that a player can undo and redo.

Definition at line 35 of file undo.hpp.

Member Typedef Documentation

typedef boost::ptr_vector<undo_action_base> actions::undo_list::action_list
private

Definition at line 37 of file undo.hpp.

typedef boost::ptr_vector<config> actions::undo_list::redos_list
private

Definition at line 38 of file undo.hpp.

Constructor & Destructor Documentation

actions::undo_list::undo_list ( const undo_list )
delete
actions::undo_list::undo_list ( const config cfg)
explicit

Constructor.

The config is allowed to be invalid.

Definition at line 124 of file undo.cpp.

References read().

actions::undo_list::~undo_list ( )

Destructor.

Definition at line 134 of file undo.cpp.

Member Function Documentation

void actions::undo_list::add ( undo_action_base action)
inlineprivate

Adds an action to the undo stack.

Definition at line 102 of file undo.hpp.

References redos_, and undos_.

Referenced by add_auto_shroud(), add_dismissal(), add_dummy(), add_move(), add_recall(), add_recruit(), and add_update_shroud().

void actions::undo_list::add_auto_shroud ( bool  turned_on)

Adds an auto-shroud toggle to the undo stack.

Todo:
: Consecutive shroud actions can be collapsed into one.

Definition at line 144 of file undo.cpp.

References add().

Referenced by SYNCED_COMMAND_HANDLER_FUNCTION().

void actions::undo_list::add_dismissal ( const unit_const_ptr  u)

Adds a dismissal to the undo stack.

Definition at line 163 of file undo.cpp.

References add().

Referenced by SYNCED_COMMAND_HANDLER_FUNCTION().

void actions::undo_list::add_dummy ( )

Adds an auto-shroud toggle to the undo stack.

Todo:
: Consecutive shroud actions can be collapsed into one.

Definition at line 152 of file undo.cpp.

References add().

Referenced by SYNCED_COMMAND_HANDLER_FUNCTION().

void actions::undo_list::add_move ( const unit_const_ptr  u,
const std::vector< map_location >::const_iterator &  begin,
const std::vector< map_location >::const_iterator &  end,
int  start_moves,
int  timebonus = 0,
int  village_owner = -1,
const map_location::DIRECTION  dir = map_location::NDIRECTIONS 
)

Adds a move to the undo stack.

Definition at line 171 of file undo.cpp.

References add().

void actions::undo_list::add_recall ( const unit_const_ptr  u,
const map_location loc,
const map_location from,
int  orig_village_owner,
bool  time_bonus 
)

Adds a recall to the undo stack.

Definition at line 183 of file undo.cpp.

References add().

Referenced by actions::recall_unit().

void actions::undo_list::add_recruit ( const unit_const_ptr  u,
const map_location loc,
const map_location from,
int  orig_village_owner,
bool  time_bonus 
)

Adds a recruit to the undo stack.

Definition at line 192 of file undo.cpp.

References add().

Referenced by actions::recruit_unit().

void actions::undo_list::add_update_shroud ( )

Adds a shroud update to the undo stack.

This is called from within commit_vision(), so there should be no need for this to be publicly visible.

Todo:
: Consecutive shroud actions can be collapsed into one.

Definition at line 203 of file undo.cpp.

References add().

Referenced by SYNCED_COMMAND_HANDLER_FUNCTION().

bool actions::undo_list::apply_shroud_changes ( ) const
private

Applies the pending fog/shroud changes from the undo stack.

Does nothing if the the current side does not use fog or shroud.

Returns
true if shroud or fog was cleared.

Definition at line 440 of file undo.cpp.

References team::auto_shroud_updates(), actions::clear_shroud(), actions::shroud_clearer::clear_unit(), display::draw(), actions::shroud_clearer::fire_events(), team::fog_or_shroud(), resources::gameboard, game_board::get_team(), i, actions::shroud_clearer::invalidate_after_clear(), game_display::invalidate_unit(), synced_context::is_synced(), LOG_NG, resources::screen, side_, and undos_.

Referenced by clear(), and commit_vision().

bool actions::undo_list::can_redo ( ) const
inline

True if there are actions that can be redone.

Definition at line 94 of file undo.hpp.

References redos_.

Referenced by play_controller::can_redo().

bool actions::undo_list::can_undo ( ) const
inline

True if there are actions that can be undone.

Definition at line 92 of file undo.hpp.

References undos_.

Referenced by play_controller::can_undo().

void actions::undo_list::clear ( )

Clears the stack of undoable (and redoable) actions.

(Also handles updating fog/shroud if needed.) Call this if an action alters the game state, but add that action to the stack before calling this (if the action is a kind that can be undone). This may fire events and change the game state.

Definition at line 218 of file undo.cpp.

References apply_shroud_changes(), committed_actions_, redos_, and undos_.

Referenced by synced_context::ask_server_choice(), wb::side_actions::execute(), play_controller::finish_side_turn(), playsingle_controller::play_ai_turn(), playmp_controller::play_human_turn(), actions::recall_unit(), actions::recruit_unit(), wb::manager::set_active(), synced_context::set_is_simultaneously(), and SYNCED_COMMAND_HANDLER_FUNCTION().

void actions::undo_list::commit_vision ( )

Updates fog/shroud based on the undo stack, then updates stack as needed.

Call this when "updating shroud now". This may fire events and change the game state.

Parameters
[in]is_replaySet to true when this is called during a replay.

Definition at line 241 of file undo.cpp.

References apply_shroud_changes(), committed_actions_, and undos_.

Referenced by SYNCED_COMMAND_HANDLER_FUNCTION().

undo_action_base * actions::undo_list::create_action ( const config cfg)
static

Creates an undo_action based on a config.

Throws bad_lexical_cast or config::error if it cannot parse the config properly.

Returns
a pointer that must be deleted, or nullptr if the cfg could not be parsed.

Definition at line 71 of file undo.cpp.

References config::child(), config::child_or_empty(), ERR_NG, unit_type_data::find(), map_location::parse_direction(), and unit_types.

Referenced by read().

void actions::undo_list::new_side_turn ( int  side)

Performs some initializations and error checks when starting a new side-turn.

Parameters
[in]sideThe side whose turn is about to start.

Definition at line 260 of file undo.cpp.

References committed_actions_, ERR_NG, redos_, side_, and undos_.

Referenced by play_controller::do_init_side().

undo_list& actions::undo_list::operator= ( const undo_list )
delete
bool actions::undo_list::player_acted ( ) const
inline

Returns true if the player has performed any actions this turn.

Definition at line 83 of file undo.hpp.

References committed_actions_, and undos_.

Referenced by events::menu_handler::end_turn().

void actions::undo_list::read ( const config cfg)

Read the undo_list from the provided config.

Currently, this is only used when the undo_list is empty, but in theory it could be used to append the config to the current data.

Definition at line 286 of file undo.cpp.

References config::child_range(), committed_actions_, create_action(), e, ERR_NG, redos_, side_, undos_, and game::error::what().

Referenced by undo_list().

void actions::undo_list::redo ( )
void actions::undo_list::undo ( )
void actions::undo_list::write ( config cfg) const

Write the undo_list into the provided config.

Definition at line 330 of file undo.cpp.

References config::add_child(), committed_actions_, redos_, side_, and undos_.

Member Data Documentation

bool actions::undo_list::committed_actions_
private

Tracks if actions have been cleared from the stack since the turn began.

Definition at line 114 of file undo.hpp.

Referenced by clear(), commit_vision(), new_side_turn(), player_acted(), read(), and write().

redos_list actions::undo_list::redos_
private

Definition at line 109 of file undo.hpp.

Referenced by add(), can_redo(), clear(), new_side_turn(), read(), redo(), undo(), and write().

int actions::undo_list::side_
private

Tracks the current side.

Definition at line 112 of file undo.hpp.

Referenced by apply_shroud_changes(), new_side_turn(), read(), undo(), and write().

action_list actions::undo_list::undos_
private

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