Allow moving on-map units by setting unit.x an unit.y fields.
This commit is contained in:
parent
fe23166a31
commit
13cacd1d1e
2 changed files with 37 additions and 0 deletions
|
@ -36,6 +36,7 @@ Version 1.13.10+dev:
|
||||||
* New wesnoth.unit_types[].advances_to getter.
|
* New wesnoth.unit_types[].advances_to getter.
|
||||||
* New wesnoth.unit_types[].advances_from getter.
|
* New wesnoth.unit_types[].advances_from getter.
|
||||||
* unit.id is now a modifiable field for off-map (Lua-only) units.
|
* unit.id is now a modifiable field for off-map (Lua-only) units.
|
||||||
|
* Allow moving on-map units by setting unit.x an unit.y fields.
|
||||||
* Multiplayer:
|
* Multiplayer:
|
||||||
* Dark Forecast: Fixed broken faction and leader selection.
|
* Dark Forecast: Fixed broken faction and leader selection.
|
||||||
* Rename the Khalifate to Dunefolk.
|
* Rename the Khalifate to Dunefolk.
|
||||||
|
|
|
@ -427,11 +427,47 @@ static int impl_unit_set(lua_State *L)
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!lu->on_map()) {
|
if(!lu->on_map()) {
|
||||||
map_location loc = u.get_location();
|
map_location loc = u.get_location();
|
||||||
modify_int_attrib("x", loc.set_wml_x(value); u.set_location(loc));
|
modify_int_attrib("x", loc.set_wml_x(value); u.set_location(loc));
|
||||||
modify_int_attrib("y", loc.set_wml_y(value); u.set_location(loc));
|
modify_int_attrib("y", loc.set_wml_y(value); u.set_location(loc));
|
||||||
modify_string_attrib("id", u.set_id(value));
|
modify_string_attrib("id", u.set_id(value));
|
||||||
|
} else {
|
||||||
|
const bool is_key_x = strcmp(m, "x") == 0;
|
||||||
|
const bool is_key_y = strcmp(m, "y") == 0;
|
||||||
|
|
||||||
|
// Handle moving an on-map unit
|
||||||
|
if(is_key_x || is_key_y) {
|
||||||
|
game_board* gb = resources::gameboard;
|
||||||
|
|
||||||
|
if(!gb) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
map_location src = u.get_location();
|
||||||
|
map_location dst = src;
|
||||||
|
|
||||||
|
if(is_key_x) {
|
||||||
|
dst.set_wml_x(static_cast<int>(luaL_checknumber(L, 3)));
|
||||||
|
} else {
|
||||||
|
dst.set_wml_y(static_cast<int>(luaL_checknumber(L, 3)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: could probably be relegated to a helper function.
|
||||||
|
if(src != dst) {
|
||||||
|
unit_map::iterator u = gb->units().end();
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
std::tie(u, success) = gb->units().move(src, dst);
|
||||||
|
|
||||||
|
if(success) {
|
||||||
|
u->anim_comp().set_standing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string err_msg = "unknown modifiable property of unit: ";
|
std::string err_msg = "unknown modifiable property of unit: ";
|
||||||
|
|
Loading…
Add table
Reference in a new issue