50 #define ERR_NG LOG_STREAM(err, log_engine)
51 #define LOG_NG LOG_STREAM(info, log_engine)
62 undos_(), redos_(), side_(1), committed_actions_(false)
81 add(std::make_unique<undo::auto_shroud_action>(turned_on));
90 add(std::make_unique<undo::dismiss_action>(u));
97 const std::vector<map_location>::const_iterator & begin,
98 const std::vector<map_location>::const_iterator & end,
102 add(std::make_unique<undo::move_action>(u, begin, end, start_moves, dir));
111 add(std::make_unique<undo::recall_action>(u,
loc, from));
120 add(std::make_unique<undo::recruit_action>(u,
loc, from));
158 if (cleared_something) {
165 return cleared_something;
177 ERR_NG <<
"Undo stack not empty in new_side_turn().";
182 else if ( !
redos_.empty() ) {
183 ERR_NG <<
"Redo stack not empty in new_side_turn().";
201 side_ = current_side;
212 undos_.push_back(std::make_unique<undo_action_container>());
213 undos_.back()->read(child);
217 ERR_NG <<
"Error when parsing undo list from config: bad lexical cast.";
219 ERR_NG <<
"discardind undo stack...";
222 ERR_NG <<
"Error when parsing undo list from config: " <<
e.what();
224 ERR_NG <<
"discardind undo stack...";
246 for (
const auto& cfg_ptr :
redos_)
253 current_ = std::make_unique<undo_action_container>();
289 auto action = std::move(
undos_.back());
290 if(!action->undo(
side_)) {
303 gui.invalidate_unit();
304 gui.invalidate_game_status();
305 gui.redraw_minimap();
319 auto action = std::move(
redos_.back());
322 auto [commandname,
data] = action->mandatory_child(
"command").all_children_view().front();
329 ERR_NG <<
"Out of sync when redoing: " <<
msg;
331 _(
"The redo stack is out of sync. This is most commonly caused by a corrupt save file or by faulty WML code in the scenario or era. Details:") +
msg);
345 gui.invalidate_unit();
346 gui.invalidate_game_status();
347 gui.redraw_minimap();
368 bool cleared_shroud =
false;
369 const std::size_t list_size =
undos_.size();
373 for( std::size_t
i = 0;
i != list_size; ++
i ) {
375 for(
auto& step_ptr :
undos_[
i]->steps()) {
377 LOG_NG <<
"Turning an undo...";
381 std::vector<map_location>::const_iterator step;
382 for(step = action->route.begin(); step != action->route.end(); ++step) {
385 if(clearer.
clear_unit(*step, tm, action->view_info,
true)) {
386 cleared_shroud =
true;
394 if (!cleared_shroud) {
Class to encapsulate fog/shroud clearing and the resultant sighted events.
void invalidate_after_clear()
The invalidations that should occur after invoking clear_unit().
game_events::pump_result_t fire_events()
Fires the sighted events that were earlier recorded by fog/shroud clearing.
bool clear_unit(const map_location &view_loc, team &view_team, std::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, std::size_t *enemy_count=nullptr, std::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,...
void new_side_turn(int side)
Performs some initializations and error checks when starting a new side-turn.
bool can_undo() const
True if there are actions that can be undone.
void add_dismissal(const unit_const_ptr &u)
Adds a dismissal to the undo stack.
void add_recall(const unit_const_ptr &u, const map_location &loc, const map_location &from)
Adds a recall to the undo stack.
bool committed_actions_
Tracks if actions have been cleared from the stack since the turn began.
void add(std::unique_ptr< undo_action > &&action)
Adds an undo step to the current action.
void write(config &cfg) const
Write the undo_list into the provided config.
bool commit_vision()
Updates fog/shroud based on the undo stack, then updates stack as needed.
void read(const config &cfg, int current_side)
Read the undo_list from the provided config.
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, const map_location::direction dir=map_location::direction::indeterminate)
Adds a move to the undo stack.
void redo()
Redoes the top action on the redo stack.
void cleanup_action()
called after a user action, removes empty actions
bool apply_shroud_changes() const
Applies the pending fog/shroud changes from the undo stack.
std::vector< std::unique_ptr< config > > redos_list
void clear()
Clears the stack of undoable (and redoable) actions.
int side_
Tracks the current side.
void init_action()
called before a user action, starts collecting undo steps for the new action.
void add_auto_shroud(bool turned_on)
Adds an auto-shroud toggle to the undo stack.
void add_recruit(const unit_const_ptr &u, const map_location &loc, const map_location &from)
Adds a recruit to the undo stack.
void finish_action(bool can_undo)
called after a user action, pushes the collected undo steps on the undo stack.
void undo()
Undoes the top action on the undo stack.
A config object defines a single node in a WML file, with access to child nodes.
bool has_attribute(config_key_type key) const
child_itors child_range(config_key_type key)
std::string debug() const
config & add_child(config_key_type key)
void invalidate_unit()
Function to invalidate that unit status displayed on the sidebar.
static game_display * get_singleton()
void undo_cut(config &dst)
void redo(const config &dst, bool set_to_end=false)
static bool run(const std::string &commandname, const config &data, action_spectator &spectator=get_default_spectator())
Sets the context to 'synced', initialises random context, and calls the given function.
static int get_unit_id_diff()
This class stores all the data for a single 'side' (in game nomenclature).
bool fog_or_shroud() const
bool auto_shroud_updates() const
static std::string _(const char *str)
Standard logging facilities (interface).
bool clear_shroud(int side, bool reset_fog, bool fire_events)
Function that will clear shroud (and fog) based on current unit positions.
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup)
Shows a transient message to the user.
std::shared_ptr< wb::manager > whiteboard
std::shared_ptr< action > action_ptr
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
std::shared_ptr< const unit > unit_const_ptr
base class for classes that clear srhoud (move/recruit/recall)
Thrown when a lexical_cast fails.
Encapsulates the map of the game.
direction
Valid directions which can be moved in our hexagonal world.
static lg::log_domain log_engine("engine")
Various functions that implement the undoing (and redoing) of in-game commands.
Various functions implementing vision (through fog of war and shroud).