diff --git a/data/lua/core/map.lua b/data/lua/core/map.lua index 34333516f122..2879956e51a7 100644 --- a/data/lua/core/map.lua +++ b/data/lua/core/map.lua @@ -5,6 +5,23 @@ function wesnoth.map.split_terrain_code(code) return table.unpack(code:split('^', {remove_empty = false})) end +function wesnoth.map.read_location(...) + local x, y = ... + if y == nil then + if type(x.x) == 'number' and type(x.y) == 'number' then + x, y = x.x, x.y + elseif type(x[1]) == 'number' and type(x[2]) == 'number' then + x, y = table.unpack(x) + else + return nil, 0 + end + return {x = x, y = y}, 1 + elseif type(x) == 'number' or type(y) == 'number' then + return {x = x, y = y}, 2 + end + return nil, 0 +end + if wesnoth.kernel_type() ~= "Application Lua Kernel" then -- possible terrain string inputs: -- A A^ A^B ^ ^B diff --git a/data/lua/location_set.lua b/data/lua/location_set.lua index a9b61f180a51..6e90010358fd 100644 --- a/data/lua/location_set.lua +++ b/data/lua/location_set.lua @@ -84,16 +84,20 @@ function methods:clear() self.values = {} end -function methods:get(x, y) - return self.values[index(x, y)] +function methods:get(...) + local loc = wesnoth.map.read_location(...) + return self.values[index(loc.x, loc.y)] end -function methods:insert(x, y, v) - self.values[index(x, y)] = v or true +function methods:insert(...) + local loc, n = wesnoth.map.read_location(...) + local v = select(n + 1, ...) + self.values[index(loc.x, loc.y)] = v or true end function methods:remove(x, y) - self.values[index(x, y)] = nil + local loc = wesnoth.map.read_location(...) + self.values[index(loc.x, loc.y)] = nil end function methods:clone()