Deprecate helper.distance_between and implement helper.adjacent_tiles in
terms of wesnoth.map.get_adjacent_tiles
This commit is contained in:
parent
9b635994e1
commit
a98a9a74db
1 changed files with 9 additions and 14 deletions
|
@ -329,16 +329,10 @@ function helper.get_user_choice(attr, options)
|
|||
return result
|
||||
end
|
||||
|
||||
local function is_even(v) return v % 2 == 0 end
|
||||
|
||||
--! Returns the distance between two tiles given by their WML coordinates.
|
||||
function helper.distance_between(x1, y1, x2, y2)
|
||||
local hdist = math.abs(x1 - x2)
|
||||
local vdist = math.abs(y1 - y2)
|
||||
if (y1 < y2 and not is_even(x1) and is_even(x2)) or
|
||||
(y2 < y1 and not is_even(x2) and is_even(x1))
|
||||
then vdist = vdist + 1 end
|
||||
return math.max(hdist, vdist + math.floor(hdist / 2))
|
||||
function helper.distance_between(...)
|
||||
wesnoth.log("warn", "helper.distance_between is deprecated; use wesnoth.map.distance_between instead")
|
||||
return wesnoth.map.distance_between(...)
|
||||
end
|
||||
|
||||
local adjacent_offset = {
|
||||
|
@ -347,6 +341,8 @@ local adjacent_offset = {
|
|||
}
|
||||
|
||||
--! Returns an iterator over adjacent locations that can be used in a for-in loop.
|
||||
-- Not deprecated because, unlike wesnoth.map.get_adjacent_tiles,
|
||||
-- this verifies that the locations are on the map.
|
||||
function helper.adjacent_tiles(x, y, with_borders)
|
||||
local x1,y1,x2,y2,b = 1,1,wesnoth.get_map_size()
|
||||
if with_borders then
|
||||
|
@ -355,13 +351,12 @@ function helper.adjacent_tiles(x, y, with_borders)
|
|||
x2 = x2 + b
|
||||
y2 = y2 + b
|
||||
end
|
||||
local offset = adjacent_offset[is_even(x)]
|
||||
local i = 1
|
||||
local adj = {wesnoth.map.get_adjacent_tiles(x, y)}
|
||||
local i = 0
|
||||
return function()
|
||||
while i <= 6 do
|
||||
local o = offset[i]
|
||||
while i < #adj do
|
||||
i = i + 1
|
||||
local u, v = o[1] + x, o[2] + y
|
||||
local u, v = adj[i][1], adj[i][2]
|
||||
if u >= x1 and u <= x2 and v >= y1 and v <= y2 then
|
||||
return u, v
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue