Expand 13cacd1d1e
by allowing unit.loc = {x, y}
This commit is contained in:
parent
419568dad5
commit
883b4f1856
2 changed files with 20 additions and 4 deletions
|
@ -36,7 +36,8 @@ Version 1.13.10+dev:
|
|||
* New wesnoth.unit_types[].advances_to getter.
|
||||
* New wesnoth.unit_types[].advances_from getter.
|
||||
* 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.
|
||||
* Allow moving on-map units by setting unit.x an unit.y fields, or with
|
||||
unit.loc = {x, y}
|
||||
* Multiplayer:
|
||||
* Dark Forecast: Fixed broken faction and leader selection.
|
||||
* Rename the Khalifate to Dunefolk. This includes renaming all the faction's
|
||||
|
|
|
@ -440,9 +440,10 @@ static int impl_unit_set(lua_State *L)
|
|||
} else {
|
||||
const bool is_key_x = strcmp(m, "x") == 0;
|
||||
const bool is_key_y = strcmp(m, "y") == 0;
|
||||
const bool is_loc_key = strcmp(m, "loc") == 0;
|
||||
|
||||
// Handle moving an on-map unit
|
||||
if(is_key_x || is_key_y) {
|
||||
if(is_key_x || is_key_y || is_loc_key) {
|
||||
game_board* gb = resources::gameboard;
|
||||
|
||||
if(!gb) {
|
||||
|
@ -453,9 +454,23 @@ static int impl_unit_set(lua_State *L)
|
|||
map_location dst = src;
|
||||
|
||||
if(is_key_x) {
|
||||
dst.set_wml_x(static_cast<int>(luaL_checkinteger(L, 3)));
|
||||
dst.set_wml_x(luaL_checkinteger(L, 3));
|
||||
} else if(is_key_y) {
|
||||
dst.set_wml_y(luaL_checkinteger(L, 3));
|
||||
} else if(lua_istable(L, 3)) { // is_loc_key
|
||||
const auto& v = lua_check<std::vector<int>>(L, 3);
|
||||
|
||||
if(v.size() != 2) {
|
||||
std::string err_msg = "both x, y coordinates not provided when assigning unit.loc";
|
||||
return luaL_argerror(L, 2, err_msg.c_str());
|
||||
}
|
||||
|
||||
dst.set_wml_x(v[0]);
|
||||
dst.set_wml_y(v[1]);
|
||||
} else {
|
||||
dst.set_wml_y(static_cast<int>(luaL_checkinteger(L, 3)));
|
||||
// This should only happen if trying to assign unit.loc with a non-table value.
|
||||
std::string err_msg = "unknown value type for unit.loc, expected table";
|
||||
return luaL_argerror(L, 2, err_msg.c_str());
|
||||
}
|
||||
|
||||
// TODO: could probably be relegated to a helper function.
|
||||
|
|
Loading…
Add table
Reference in a new issue