57 #include <boost/intrusive_ptr.hpp>
58 #include <boost/ptr_container/detail/static_move_ptr.hpp>
59 #include <boost/ptr_container/detail/void_ptr_iterator.hpp>
60 #include <boost/ptr_container/ptr_sequence_adapter.hpp>
61 #include <boost/shared_ptr.hpp>
67 #define ERR_NG LOG_STREAM(err, log_engine)
68 #define LOG_NG LOG_STREAM(info, log_engine)
87 if ( str ==
"move" ) {
89 cfg[
"starting_moves"],
93 else if ( str ==
"recruit" ) {
100 ERR_NG <<
"Invalid recruit found in [undo] or [redo]; unit type '"
101 << child[
"type"] <<
"' was not found.\n";
107 else if ( str ==
"recall" )
110 else if ( str ==
"dismiss" )
113 else if ( str ==
"auto_shroud" )
116 else if ( str ==
"update_shroud" )
121 ERR_NG <<
"Unrecognized undo action type: " << str <<
"." << std::endl;
133 undos_(), redos_(), side_(1), committed_actions_(false)
180 const std::vector<map_location>::const_iterator & begin,
181 const std::vector<map_location>::const_iterator &
end,
182 int start_moves,
int timebonus,
int village_owner,
192 const map_location& from,
int orig_village_owner,
bool time_bonus)
201 const map_location& from,
int orig_village_owner,
bool time_bonus)
254 if (cleared_something) {
272 ERR_NG <<
"Undo stack not empty in new_side_turn()." << std::endl;
277 else if ( !
redos_.empty() ) {
278 ERR_NG <<
"Redo stack not empty in new_side_turn()." << std::endl;
308 ERR_NG <<
"Error when parsing undo list from config: bad lexical cast." << std::endl;
309 ERR_NG <<
"config was: " << child.debug() << std::endl;
310 ERR_NG <<
"Skipping this undo action..." << std::endl;
312 ERR_NG <<
"Error when parsing undo list from config: " << e.
what() << std::endl;
313 ERR_NG <<
"config was: " << child.debug() << std::endl;
314 ERR_NG <<
"Skipping this undo action..." << std::endl;
322 if (
undo_action* undoable_action = dynamic_cast<undo_action*>(action)) {
323 redos_.push_back(undoable_action);
326 ERR_NG <<
"Error: redo contained action that is not undoable" << std::endl;
327 ERR_NG <<
"config was: " << child.debug() << std::endl;
328 ERR_NG <<
"Skipping this redo action..." << std::endl;
331 ERR_NG <<
"Error when parsing redo list from config: bad lexical cast." << std::endl;
332 ERR_NG <<
"config was: " << child.debug() << std::endl;
333 ERR_NG <<
"Skipping this redo action..." << std::endl;
335 ERR_NG <<
"Error when parsing redo list from config: " << e.
what() << std::endl;
336 ERR_NG <<
"config was: " << child.debug() << std::endl;
337 ERR_NG <<
"Skipping this redo action..." << std::endl;
351 for ( action_list::const_iterator it =
undos_.begin(); it !=
undos_.end(); ++it )
354 for ( redos_list::const_iterator it =
redos_.begin(); it !=
redos_.end(); ++it )
373 action_list::auto_type action =
undos_.pop_back();
374 if (
undo_action* undoable_action = dynamic_cast<undo_action*>(action.ptr()))
377 if ( !undoable_action->undo(
side_) ) {
380 if(last_unit_id - undoable_action->unit_id_diff < 0) {
381 ERR_NG <<
"Next unit id is below 0 after undoing" << std::endl;
388 redos_.push_back(static_cast<undo_action*>(action.release()));
404 undos_.push_back(action.release());
424 redos_list::auto_type action =
redos_.pop_back();
426 if ( !action->redo(
side_) ) {
430 ERR_NG <<
"Too many units were generated during redoing." << std::endl;
435 undos_.push_back(action.release());
457 team &tm = (*resources::teams)[
side_ - 1];
463 bool cleared_shroud =
false;
464 const size_t list_size =
undos_.size();
468 for(
size_t i = 0;
i != list_size; ++
i ) {
470 LOG_NG <<
"Turning an undo...\n";
474 std::vector<map_location>::const_iterator step;
475 for (step = action->route.begin(); step != action->route.end(); ++step) {
478 if ( clearer.
clear_unit(*step, tm, action->view_info,
true) ) {
479 cleared_shroud =
true;
486 if (!cleared_shroud) {
void clear()
Clears the stack of undoable (and redoable) actions.
base class for classes that clear srhoud (move/recruit/recall)
child_itors child_range(const std::string &key)
bool committed_actions_
Tracks if actions have been cleared from the stack since the turn began.
static DIRECTION parse_direction(const std::string &str)
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
bool clear_unit(const map_location &view_loc, team &view_team, size_t viewer_id, int sight_range, bool slowed, const movetype::terrain_costs &costs, const map_location &real_loc, const std::set< map_location > *known_units=nullptr, size_t *enemy_count=nullptr, size_t *friend_count=nullptr, move_unit_spectator *spectator=nullptr, bool instant=true)
Clears shroud (and fog) around the provided location for view_team based on sight_range, costs, and slowed.
Various functions implementing vision (through fog of war and shroud).
const char * what() const
size_t get_save_id() const
Used for saving id to savegame.
void invalidate_unit()
Function to invalidate that unit status displayed on the sidebar.
void undo()
Undoes the top action on the undo stack.
void add(undo_action_base *action)
Adds an action to the undo stack.
int side_
Tracks the current side.
unit_type_data unit_types
void new_side_turn(int side)
Performs some initializations and error checks when starting a new side-turn.
bool apply_shroud_changes() const
Applies the pending fog/shroud changes from the undo stack.
virtual void draw()
Draws invalidated items.
const config & child_or_empty(const std::string &key) const
Returns the first child with the given key, or an empty config if there is none.
void redraw_minimap()
Schedule the minimap to be redrawn.
Records information to be able to undo an action.
void read(const config &cfg)
Read the undo_list from the provided config.
This class stores all the data for a single 'side' (in game nomenclature).
bool fog_or_shroud() const
bool auto_shroud_updates() const
void redo(const config &dst)
static lg::log_domain log_engine("engine")
config & add_child(const std::string &key)
void commit_vision()
Updates fog/shroud based on the undo stack, then updates stack as needed.
Templates and utility-routines for strings and numbers.
Encapsulates the map of the game.
Various functions related to moving units.
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.
Various functions related to the creation of units (recruits, recalls, and placed units)...
void add_dismissal(const unit_const_ptr u)
Adds a dismissal to the undo stack.
static undo_action_base * create_action(const config &cfg)
Creates an undo_action based on a config.
entry for player actions that do not need any special code to be performed when undoing such as right...
void redo()
Redoes the top action on the redo stack.
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.
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.
DIRECTION
Valid directions which can be moved in our hexagonal world.
bool clear_shroud(int side, bool reset_fog, bool fire_events)
Function that will clear shroud (and fog) based on current unit positions.
bool fire_events()
Fires the sighted events that were earlier recorded by fog/shroud clearing.
void add_update_shroud()
Adds a shroud update to the undo stack.
n_unit::id_manager & unit_id_manager()
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Various functions that implement the undoing (and redoing) of in-game commands.
void undo_cut(config &dst)
Standard logging facilities (interface).
void add_dummy()
Adds an auto-shroud toggle to the undo stack.
Class to encapsulate fog/shroud clearing and the resultant sighted events.
const unit_type * find(const std::string &key, unit_type::BUILD_STATUS status=unit_type::FULL) const
Finds a unit_type by its id() and makes sure it is built to the specified level.
boost::shared_ptr< wb::manager > whiteboard
void add_auto_shroud(bool turned_on)
Adds an auto-shroud toggle to the undo stack.
void invalidate_after_clear()
The invalidations that should occur after invoking clear_unit().
A config object defines a single node in a WML file, with access to child nodes.
Thrown when a lexical_cast fails.
GLsizei const GLcharARB ** string
Display units performing various actions: moving, attacking, and dying.
undo_list(const config &cfg)
Constructor.
actions that are undoable (this does not include update_shroud and auto_shroud)
void write(config &cfg) const
Write the undo_list into the provided config.