34 #define ERR_NG LOG_STREAM(err, log_engine)
35 #define LOG_NG LOG_STREAM(info, log_engine)
55 ERR_NG <<
"Next unit id is below 0 after undoing";
63 steps_.emplace_back(std::move(action));
80 for(
auto it =
steps_.begin(); it !=
steps_.end(); ++it) {
86 auto next = std::next(it);
87 while(next !=
steps_.end()) {
89 if(!second || second->route.front() != first->route.back()) {
92 first->
route.insert(first->route.end(), second->route.begin() + 1, second->route.end());
103 add(factory->second(step));
105 throw config::error(
"Invalid undo action type: '" + step[
"type"].str() +
"'");
111 for(
auto& p_step :
steps_) {
133 , filter_loc1(ctx.loc1.filter_loc())
134 , filter_loc2(ctx.loc2.filter_loc())
140 uid1 = u1->underlying_id();
144 uid2 = u2->underlying_id();
153 , filter_loc1(ctx.loc1.filter_loc())
154 , filter_loc2(ctx.loc2.filter_loc())
160 uid1 = u1->underlying_id();
164 uid2 = u2->underlying_id();
171 , loc1(first[
"x"], first[
"y"],
wml_loc())
172 , loc2(second[
"x"], second[
"y"],
wml_loc())
173 , filter_loc1(first[
"filter_x"], first[
"filter_y"],
wml_loc())
174 , filter_loc2(second[
"filter_x"], second[
"filter_y"],
wml_loc())
175 , uid1(first[
"underlying_id"].to_size_t())
176 , uid2(second[
"underlying_id"].to_size_t())
184 cfg.child_or_empty(
"filter_second"),
185 cfg.child_or_empty(
"data"),
186 cfg.child_or_empty(
"command"))
193 unit_ptr get_unit(std::size_t uid,
const std::string&
id)
197 if(!iter.valid() || iter->id() !=
id) {
207 std::string
tag =
"undo";
220 std::unique_ptr<scoped_xy_unit> u1, u2;
232 if(
e.lua_idx.has_value()) {
250 if(evt.lua_idx.has_value()) {
258 entry.
add_child(
"command", evt.commands);
260 first[
"filter_x"] = evt.filter_loc1.wml_x();
261 first[
"filter_y"] = evt.filter_loc1.wml_y();
262 first[
"underlying_id"] = evt.uid1;
263 first[
"id"] = evt.id1;
264 first[
"x"] = evt.loc1.wml_x();
265 first[
"y"] = evt.loc1.wml_y();
267 second[
"filter_x"] = evt.filter_loc2.wml_x();
268 second[
"filter_y"] = evt.filter_loc2.wml_y();
269 second[
"underlying_id"] = evt.uid2;
270 second[
"id"] = evt.id2;
271 second[
"x"] = evt.loc2.wml_x();
272 second[
"y"] = evt.loc2.wml_y();
std::unique_ptr< undo_action > t_step_ptr
void read(const config &cfg)
Creates the list of undo steps based on a config.
std::map< std::string, t_factory > t_factory_map
void combine_moves()
Merges consecutive undo::move_action steps that form one continuous path into a single step.
void add(t_step_ptr &&action)
static t_factory_map & get_factories()
undo_event(int fcn_idx, const config &args, const game_events::queued_event &ctx)
virtual bool undo(int side)
Undoes this action.
virtual void write(config &cfg) const
Writes this into the provided config.
Variant for storing WML attributes.
static config_attribute_value create(const T val)
A config object defines a single node in a WML file, with access to child nodes.
config & add_child(std::string_view key)
child_itors child_range(std::string_view key)
n_unit::id_manager & unit_id_manager()
virtual const unit_map & units() const override
bool run_wml_event(int ref, const vconfig &args, const game_events::queued_event &ev, bool *out=nullptr)
Run a WML stored in the Lua registry.
bool run_wml_action(const std::string &, const vconfig &, const game_events::queued_event &)
Runs a command from an event handler.
std::size_t get_save_id() const
Used for saving id to savegame.
void set_save_id(std::size_t)
unit_iterator find(std::size_t id)
A variable-expanding proxy for the config class.
void swap(config &lhs, config &rhs) noexcept
Implement non-member swap function for std::swap (calls config::swap).
Standard logging facilities (interface).
static auto red_undo_event
std::string tag(std::string_view tag, Args &&... data)
Wraps the given data in the specified tag.
game_lua_kernel * lua_kernel
void commit_music_changes()
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
std::shared_ptr< const unit > unit_const_ptr
std::shared_ptr< unit > unit_ptr
route_t route
The hexes occupied by the affected unit during this action.
virtual void write(config &cfg) const
Writes this into the provided config.
unit_const_ptr get_unit() const
Encapsulates the map of the game.
pointer get_shared_ptr() const
This is exactly the same as operator-> but it's slightly more readable, and can replace &*iter syntax...
static lg::log_domain log_engine("engine")