Skip to content

Commit

Permalink
MapGen: Dungeons: corrected walls calc/finding. Relates to #1140, #1141
Browse files Browse the repository at this point in the history
  • Loading branch information
alek13 committed Dec 13, 2023
1 parent 2defd20 commit 351e67b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
37 changes: 19 additions & 18 deletions mods/lord/Core/builtin/src/mapgen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ local c_air = id("air")


--- @class RoomWall
--- @field start_pos Position
--- @field end_pos Position
--- @field start_pos vector
--- @field end_pos vector

--- @class RoomWalls
--- @field north RoomWall
Expand Down Expand Up @@ -44,15 +44,15 @@ end
--- @param data table
--- @param area VoxelArea
--- @return number|nil
local function find_room_high_y(rc, wx_minus, wx_plus, wz_minus, wz_plus, data, area)
local function find_room_ceiling_y(rc, wx_minus, wx_plus, wz_minus, wz_plus, data, area)
for dy = 1, 16 do
if
data[area:index(wx_plus - 1, rc.y + dy, rc.z )] ~= c_air or
data[area:index(wx_minus + 1, rc.y + dy, rc.z )] ~= c_air or
data[area:index(rc.x, rc.y + dy, wz_plus - 1)] ~= c_air or
data[area:index(rc.x, rc.y + dy, wz_minus + 1)] ~= c_air
then
return rc.y + dy - 1
return rc.y + dy
end
end

Expand All @@ -71,35 +71,36 @@ local function find_room_walls(room_center, data, area)
return {}
end

local high_y = find_room_high_y(rc, wx_minus, wx_plus, wz_minus, wz_plus, data, area)
if high_y == nil then
local ceil_y = find_room_ceiling_y(rc, wx_minus, wx_plus, wz_minus, wz_plus, data, area)
if ceil_y == nil then
return {}
end
local floor_y = rc.y - 1

return {
west = {
start_pos = { x = wx_minus, y = rc.y, z = wz_minus },
end_pos = { x = wx_minus, y = high_y, z = wz_plus },
start_pos = vector.new(wx_minus, floor_y, wz_minus),
end_pos = vector.new(wx_minus, ceil_y, wz_plus),
},
east = {
start_pos = { x = wx_plus, y = rc.y, z = wz_minus },
end_pos = { x = wx_plus, y = high_y, z = wz_plus },
start_pos = vector.new(wx_plus, floor_y, wz_minus),
end_pos = vector.new(wx_plus, ceil_y, wz_plus),
},
south = {
start_pos = { x = wx_minus, y = rc.y, z = wz_minus },
end_pos = { x = wx_plus, y = high_y, z = wz_minus },
start_pos = vector.new(wx_minus, floor_y, wz_minus),
end_pos = vector.new(wx_plus, ceil_y, wz_minus),
},
north = {
start_pos = { x = wx_minus, y = rc.y, z = wz_plus },
end_pos = { x = wx_plus, y = high_y, z = wz_plus },
start_pos = vector.new(wx_minus, floor_y, wz_plus),
end_pos = vector.new(wx_plus, ceil_y, wz_plus),
},
floor = {
start_pos = { x = wx_minus, y = rc.y - 1, z = wz_minus },
end_pos = { x = wx_plus, y = rc.y - 1, z = wz_plus },
start_pos = vector.new(wx_minus, floor_y, wz_minus),
end_pos = vector.new(wx_plus, floor_y, wz_plus),
},
ceiling = {
start_pos = { x = wx_minus, y = high_y + 1, z = wz_minus },
end_pos = { x = wx_plus, y = high_y + 1, z = wz_plus },
start_pos = vector.new(wx_minus, ceil_y, wz_minus),
end_pos = vector.new(wx_plus, ceil_y, wz_plus),
},
}
end
Expand Down
5 changes: 3 additions & 2 deletions util/mt-ide-helper/minetest_types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ PseudoRandom = {}
--- @field x number
--- @field y number
--- @field z number
Position = {x,y,z}

--- @class vector: Position

--- @class pointed_thing
--- @field public type string one of {"nothing"|"node"|"object"}
Expand All @@ -47,7 +48,7 @@ Position = {x,y,z}
--- @field public box_id number The ID of the pointed selection box (counting starts from 1)
--- @field public intersection_normal Position Unit vector, points outwards of the selected selection box. This specifies which face is pointed at. Is a null vector `vector.zero()` when the pointer is inside the selection box.
---
pointed_thing = {}


--
-- `minetest.` / `core.` functions
Expand Down

0 comments on commit 351e67b

Please sign in to comment.