Skip to content

Commit

Permalink
Lua API: Add wesnoth.map.iter_adjacent
Browse files Browse the repository at this point in the history
This replaces helper.adjacent_tiles
  • Loading branch information
CelticMinstrel committed Jul 6, 2021
1 parent bd093f0 commit 78f595b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions data/lua/core/map.lua
Expand Up @@ -65,6 +65,24 @@ if wesnoth.kernel_type() ~= "Application Lua Kernel" then
return code
end
end

function wesnoth.map.iter_adjacent(map, ...)
local where, n = wesnoth.read_location(...)
if n == 0 then error('wesnoth.map.iter_adjacent: missing location') end
local with_borders = select(n + 1, ...)
local adj = {wesnoth.map.get_adjacent_hexes(where)}
local i = 0
return function()
while i < #adj do
i = i + 1
local u, v = adj[i].x, adj[i].y
if map:on_board(u, v, with_borders) then
return u, v
end
end
return nil
end
end
end

if wesnoth.kernel_type() == "Game Lua Kernel" then
Expand Down
1 change: 1 addition & 0 deletions data/lua/helper.lua
Expand Up @@ -114,5 +114,6 @@ helper.round = wesnoth.deprecate_api('helper.round', 'mathx.round', 1, nil, math
helper.shuffle = wesnoth.deprecate_api('helper.shuffle', 'mathx.shuffle', 1, nil, mathx.shuffle)
helper.all_teams = wesnoth.deprecate_api('helper.all_teams', 'wesnoth.sides.iter', 1, nil, helper.all_teams)
helper.get_sides = wesnoth.deprecate_api('helper.get_sides', 'wesnoth.sides.iter', 1, nil, helper.get_sides)
helper.adjacent_tiles = wesnoth.deprecate_api('helper.adjacent_tiles', 'wesnoth.map.iter_adjacent', 1, nil, helper.adjacent_tiles)

return helper

0 comments on commit 78f595b

Please sign in to comment.