Fix visibility some more

This commit is contained in:
Juhani Krekelä 2019-06-29 00:23:42 +03:00
parent eb3a654c67
commit 9dc1348da1
1 changed files with 51 additions and 48 deletions

View File

@ -252,84 +252,87 @@ function stepVisibilityMapGeneration(queue)
local new_queue = {}
for i, item in ipairs(queue) do
if cavern[item.x][item.y] == tiletypes.empty then
-- Did not yet hit a wall
if item.direction == directions.up then
visibility_map[item.x][item.y] = true
if item.direction == directions.up then
visibility_map[item.x][item.y] = true
if cavern[item.x][item.y] == tiletypes.empty then
table.insert(new_queue, {x = item.x, y = item.y - 1, direction = directions.up})
elseif item.direction == directions.left then
visibility_map[item.x][item.y] = true
end
elseif item.direction == directions.left then
visibility_map[item.x][item.y] = true
if cavern[item.x][item.y] == tiletypes.empty then
table.insert(new_queue, {x = item.x - 1, y = item.y, direction = directions.left})
elseif item.direction == directions.down then
visibility_map[item.x][item.y] = true
end
elseif item.direction == directions.down then
visibility_map[item.x][item.y] = true
if cavern[item.x][item.y] == tiletypes.empty then
table.insert(new_queue, {x = item.x, y = item.y + 1, direction = directions.down})
elseif item.direction == directions.right then
visibility_map[item.x][item.y] = true
end
elseif item.direction == directions.right then
visibility_map[item.x][item.y] = true
if cavern[item.x][item.y] == tiletypes.empty then
table.insert(new_queue, {x = item.x + 1, y = item.y, direction = directions.right})
elseif item.direction == directions.upleft then
-- Check that we could have gotten here also by moving only 4-ways
--
-- The possible cases are:
-- (o represents old position, x is new, and # is a wall)
--
-- x x# x x#
-- o o #o #o
--
-- In the first three, the movement is possible, but in the last one
-- it is not. We can therefore check whether the movement is valid
-- by testing if either the cell to our right or below us (the
-- directions opposite to the ones in an up.left movement) is empty
if cavern[item.x + 1][item.y] == tiletypes.empty or cavern[item.x][item.y + 1] == tiletypes.empty then
end
elseif item.direction == directions.upleft then
-- Check that we could have gotten here also by moving only 4-ways
--
-- The possible cases are:
-- (o represents old position, x is new, and # is a wall)
--
-- x x# x x#
-- o o #o #o
--
-- In the first three, the movement is possible, but in the last one
-- it is not. We can therefore check whether the movement is valid
-- by testing if either the cell to our right or below us (the
-- directions opposite to the ones in an up.left movement) is empty
if cavern[item.x + 1][item.y] == tiletypes.empty or cavern[item.x][item.y + 1] == tiletypes.empty then
visibility_map[item.x][item.y] = true
if cavern[item.x][item.y] == tiletypes.empty then
-- ⌜^
-- ⌜ <x
visibility_map[item.x][item.y] = true
table.insert(new_queue, {x = item.x - 1, y = item.y - 1, direction = directions.upleft})
table.insert(new_queue, {x = item.x, y = item.y - 1, direction = directions.up})
table.insert(new_queue, {x = item.x - 1, y = item.y, direction = directions.left})
end
elseif item.direction == directions.downleft then
-- See under item.direction == directions.upleft
if cavern[item.x + 1][item.y] == tiletypes.empty or cavern[item.x][item.y - 1] == tiletypes.empty then
end
elseif item.direction == directions.downleft then
-- See under item.direction == directions.upleft
if cavern[item.x + 1][item.y] == tiletypes.empty or cavern[item.x][item.y - 1] == tiletypes.empty then
visibility_map[item.x][item.y] = true
if cavern[item.x][item.y] == tiletypes.empty then
-- ⌞ <x
-- ⌞v
visibility_map[item.x][item.y] = true
table.insert(new_queue, {x = item.x - 1, y = item.y, direction = directions.left})
table.insert(new_queue, {x = item.x - 1, y = item.y + 1, direction = directions.downleft})
table.insert(new_queue, {x = item.x, y = item.y + 1, direction = directions.down})
end
elseif item.direction == directions.downright then
-- See under item.direction == directions.upleft
if cavern[item.x - 1][item.y] == tiletypes.empty or cavern[item.x][item.y - 1] == tiletypes.empty then
end
elseif item.direction == directions.downright then
-- See under item.direction == directions.upleft
if cavern[item.x - 1][item.y] == tiletypes.empty or cavern[item.x][item.y - 1] == tiletypes.empty then
visibility_map[item.x][item.y] = true
if cavern[item.x][item.y] == tiletypes.empty then
-- ⌟ x>
-- v⌟
visibility_map[item.x][item.y] = true
table.insert(new_queue, {x = item.x + 1, y = item.y, direction = directions.right})
table.insert(new_queue, {x = item.x, y = item.y + 1, direction = directions.down})
table.insert(new_queue, {x = item.x + 1, y = item.y + 1, direction = directions.downright})
end
elseif item.direction == directions.upright then
-- See under item.direction == directions.upleft
if cavern[item.x - 1][item.y] == tiletypes.empty or cavern[item.x][item.y + 1] == tiletypes.empty then
end
elseif item.direction == directions.upright then
-- See under item.direction == directions.upleft
if cavern[item.x - 1][item.y] == tiletypes.empty or cavern[item.x][item.y + 1] == tiletypes.empty then
visibility_map[item.x][item.y] = true
if cavern[item.x][item.y] == tiletypes.empty then
-- ^⌝
-- ⌝ x>
visibility_map[item.x][item.y] = true
table.insert(new_queue, {x = item.x, y = item.y - 1, direction = directions.up})
table.insert(new_queue, {x = item.x + 1, y = item.y - 1, direction = directions.upright})
table.insert(new_queue, {x = item.x + 1, y = item.y, direction = directions.right})
end
else
error("Visibility floodfill item travelling in an impossible direction")
end
else
-- Hit a wall
if item.direction == directions.up or
item.direction == directions.left or
item.direction == directions.down or
item.direction == directions.right then
-- Only draw it as visible if we reached it with a non-diagonal move
-- because diagonals might have been non-valid moves
visibility_map[item.x][item.y] = true
end
error("Visibility floodfill item travelling in an impossible direction")
end
end