59 #define ERR_NG LOG_STREAM(err, log_engine) 60 #define LOG_NG LOG_STREAM(info, log_engine) 73 const std::string str = cfg[
"type"];
79 if ( str ==
"move" ) {
81 cfg[
"starting_moves"],
85 else if ( str ==
"recruit" ) {
92 ERR_NG <<
"Invalid recruit found in [undo] or [redo]; unit type '" 93 << child[
"type"] <<
"' was not found.\n";
99 else if ( str ==
"recall" )
102 else if ( str ==
"dismiss" )
105 else if ( str ==
"auto_shroud" )
108 else if ( str ==
"update_shroud" )
110 else if ( str ==
"dummy" )
115 ERR_NG <<
"Unrecognized undo action type: " << str <<
"." << std::endl;
174 const std::vector<map_location>::const_iterator & begin,
175 const std::vector<map_location>::const_iterator & end,
176 int start_moves,
int timebonus,
int village_owner,
186 const map_location& from,
int orig_village_owner,
bool time_bonus)
195 const map_location& from,
int orig_village_owner,
bool time_bonus)
248 if (cleared_something) {
266 ERR_NG <<
"Undo stack not empty in new_side_turn()." << std::endl;
271 else if ( !
redos_.empty() ) {
272 ERR_NG <<
"Redo stack not empty in new_side_turn()." << std::endl;
299 undos_.emplace_back(action);
302 ERR_NG <<
"Error when parsing undo list from config: bad lexical cast." << std::endl;
303 ERR_NG <<
"config was: " << child.debug() << std::endl;
304 ERR_NG <<
"Skipping this undo action..." << std::endl;
306 ERR_NG <<
"Error when parsing undo list from config: " << e.
what() << std::endl;
307 ERR_NG <<
"config was: " << child.debug() << std::endl;
308 ERR_NG <<
"Skipping this undo action..." << std::endl;
317 ERR_NG <<
"Error when parsing redo list from config: bad lexical cast." << std::endl;
318 ERR_NG <<
"config was: " << child.debug() << std::endl;
319 ERR_NG <<
"Skipping this redo action..." << std::endl;
321 ERR_NG <<
"Error when parsing redo list from config: " << e.
what() << std::endl;
322 ERR_NG <<
"config was: " << child.debug() << std::endl;
323 ERR_NG <<
"Skipping this redo action..." << std::endl;
340 for (
const auto& cfg_ptr :
redos_)
359 auto action = std::move(
undos_.back());
361 if (
undo_action* undoable_action = dynamic_cast<undo_action*>(action.get()))
364 if ( !undoable_action->undo(
side_) ) {
367 if(last_unit_id - undoable_action->unit_id_diff < 0) {
368 ERR_NG <<
"Next unit id is below 0 after undoing" << std::endl;
390 undos_.emplace_back(std::move(action));
415 auto action = std::move(
redos_.back());
418 const config& command_wml = action->
child(
"command");
456 bool cleared_shroud =
false;
457 const std::size_t list_size =
undos_.size();
461 for( std::size_t
i = 0;
i != list_size; ++
i ) {
463 LOG_NG <<
"Turning an undo...\n";
467 std::vector<map_location>::const_iterator step;
468 for (step = action->route.begin(); step != action->route.end(); ++step) {
471 if ( clearer.
clear_unit(*step, tm, action->view_info,
true) ) {
472 cleared_shroud =
true;
479 if (!cleared_shroud) {
void clear()
Clears the stack of undoable (and redoable) actions.
base class for classes that clear srhoud (move/recruit/recall)
bool committed_actions_
Tracks if actions have been cleared from the stack since the turn began.
static DIRECTION parse_direction(const std::string &str)
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
const_all_children_itors all_children_range() const
In-order iteration over all children.
std::size_t get_save_id() const
Used for saving id to savegame.
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.
void invalidate_game_status()
Function to invalidate the game status displayed on the sidebar.
bool apply_shroud_changes() const
Applies the pending fog/shroud changes from the undo stack.
Various functions implementing vision (through fog of war and shroud).
static bool run(const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
Sets the context to 'synced', initialises random context, and calls the given function.
std::vector< std::unique_ptr< config > > redos_list
child_itors child_range(config_key_type key)
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.
std::unique_ptr< undo_action_base > action_ptr_t
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.
void redraw_minimap()
Schedule the minimap to be redrawn.
A single unit type that the player may recruit.
Records information to be able to undo an action.
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, costs, and slowed.
void read(const config &cfg)
Read the undo_list from the provided config.
std::shared_ptr< const unit > unit_const_ptr
undo_list(const undo_list &)=delete
This class stores all the data for a single 'side' (in game nomenclature).
game_events::pump_result_t fire_events()
Fires the sighted events that were earlier recorded by fog/shroud clearing.
void redo(const config &dst, bool set_to_end=false)
bool fog_or_shroud() const
static lg::log_domain log_engine("engine")
std::shared_ptr< action > action_ptr
const char * what() const noexcept
void commit_vision()
Updates fog/shroud based on the undo stack, then updates stack as needed.
void set_save_id(std::size_t)
Encapsulates the map of the game.
bool auto_shroud_updates() const
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.
std::shared_ptr< wb::manager > whiteboard
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.
config & add_child(config_key_type key)
bool clear_shroud(int side, bool reset_fog, bool fire_events)
Function that will clear shroud (and fog) based on current unit positions.
void add_update_shroud()
Adds a shroud update to the undo stack.
n_unit::id_manager & unit_id_manager()
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.
void add_auto_shroud(bool turned_on)
Adds an auto-shroud toggle to the undo stack.
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
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.
void write(config &cfg) const
Write the undo_list into the provided config.
actions that are undoable (this does not include update_shroud and auto_shroud)
static game_display * get_singleton()