From 351e67b02660fec205a4d59a1f1f907b2b4a46db Mon Sep 17 00:00:00 2001 From: alek13 Date: Thu, 14 Dec 2023 02:04:39 +0300 Subject: [PATCH] MapGen: Dungeons: corrected walls calc/finding. Relates to #1140, #1141 --- mods/lord/Core/builtin/src/mapgen.lua | 37 ++++++++++++++------------- util/mt-ide-helper/minetest_types.lua | 5 ++-- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/mods/lord/Core/builtin/src/mapgen.lua b/mods/lord/Core/builtin/src/mapgen.lua index 8e2e8aec7..cc85859eb 100644 --- a/mods/lord/Core/builtin/src/mapgen.lua +++ b/mods/lord/Core/builtin/src/mapgen.lua @@ -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 @@ -44,7 +44,7 @@ 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 @@ -52,7 +52,7 @@ local function find_room_high_y(rc, wx_minus, wx_plus, wz_minus, wz_plus, data, 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 @@ -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 diff --git a/util/mt-ide-helper/minetest_types.lua b/util/mt-ide-helper/minetest_types.lua index 09b3733f1..218df00de 100644 --- a/util/mt-ide-helper/minetest_types.lua +++ b/util/mt-ide-helper/minetest_types.lua @@ -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"} @@ -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