38 , filter_loc1(ctx.loc1.filter_loc())
39 , filter_loc2(ctx.loc2.filter_loc())
45 uid1 = u1->underlying_id();
49 uid2 = u2->underlying_id();
58 , filter_loc1(ctx.loc1.filter_loc())
59 , filter_loc2(ctx.loc2.filter_loc())
65 uid1 = u1->underlying_id();
69 uid2 = u2->underlying_id();
76 , loc1(first[
"x"], first[
"y"],
wml_loc())
77 , loc2(second[
"x"], second[
"y"],
wml_loc())
78 , filter_loc1(first[
"filter_x"], first[
"filter_y"],
wml_loc())
79 , filter_loc2(second[
"filter_x"], second[
"filter_y"],
wml_loc())
80 , uid1(first[
"underlying_id"].to_size_t())
81 , uid2(second[
"underlying_id"].to_size_t())
93 if(
p.lua_.has_value()) {
105 , unit_id_diff(cfg[
"unit_id_diff"].to_int())
111 unit_ptr get_unit(std::size_t uid,
const std::string&
id) {
114 if(!iter.valid() || iter->id() !=
id) {
119 void execute_event(
const undo_event&
e, std::string
tag) {
128 x1 =
e.filter_loc1.wml_x(); y1 =
e.filter_loc1.wml_y();
129 x2 =
e.filter_loc2.wml_x(); y2 =
e.filter_loc2.wml_y();
131 std::unique_ptr<scoped_xy_unit> u1, u2;
143 if(
e.lua_idx.has_value()) {
150 x1 = oldx1; y1 = oldy1;
151 x2 = oldx2; y2 = oldy2;
159 execute_event(
e,
"undo");
174 vec.emplace_back(
c.child_or_empty(
"filter"),
c.child_or_empty(
"filter_second"),
c.child_or_empty(
"data"),
c.child_or_empty(
"command"));
180 for(
const auto& evt : vec)
182 if(evt.lua_idx.has_value()) {
190 entry.
add_child(
"command", evt.commands);
192 first[
"filter_x"] = evt.filter_loc1.wml_x();
193 first[
"filter_y"] = evt.filter_loc1.wml_y();
194 first[
"underlying_id"] = evt.uid1;
195 first[
"id"] = evt.id1;
196 first[
"x"] = evt.loc1.wml_x();
197 first[
"y"] = evt.loc1.wml_y();
199 second[
"filter_x"] = evt.filter_loc2.wml_x();
200 second[
"filter_y"] = evt.filter_loc2.wml_y();
201 second[
"underlying_id"] = evt.uid2;
202 second[
"id"] = evt.id2;
203 second[
"x"] = evt.loc2.wml_x();
204 second[
"y"] = evt.loc2.wml_y();
Variant for storing WML attributes.
int to_int(int def=0) const
A config object defines a single node in a WML file, with access to child nodes.
child_itors child_range(config_key_type key)
config & add_child(config_key_type key)
virtual const unit_map & units() const override
config::attribute_value & get_variable(const std::string &varname)
throws invalid_variablename_exception if varname is no valid variable name.
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.
static event_list & get_undo_commands()
unit_iterator find(std::size_t id)
A variable-expanding proxy for the config class.
std::string tag(const std::string &tag_name, Args &&... contents)
Returns the contents enclosed inside <tag_name> and </tag_name>
game_lua_kernel * lua_kernel
void commit_music_changes()
std::shared_ptr< const unit > unit_const_ptr
std::shared_ptr< unit > unit_ptr
Records information to be able to undo an action.
virtual void write(config &cfg) const
Writes this into the provided config.
event_vector umc_commands_undo
virtual void write(config &cfg) const
Writes this into the provided config.
std::vector< undo_event > event_vector
actions wml (specified by wml) that should be executed when undoing this command.
undo_action()
Default constructor.
void execute_undo_umc_wml()
static void read_event_vector(event_vector &vec, const config &cfg, const std::string &tag)
virtual bool undo(int side)=0
Undoes this action.
static void write_event_vector(const event_vector &vec, config &cfg, const std::string &tag)
int unit_id_diff
the difference in the unit ids TODO: does it really make sense to allow undoing if the unit id counte...
undo_event(int fcn_idx, const config &args, const game_events::queued_event &ctx)
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...