Skip to content

Commit

Permalink
optimized surface finding
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeb187 committed Nov 7, 2019
1 parent 7c2d92b commit 4ca9fbf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion const.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--
-- switch for debugging
--
settlements.debug = false
settlements.debug = true
--
-- switch for lvm
settlements.lvm = false
Expand Down
6 changes: 3 additions & 3 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ minetest.register_on_generated(function(minp, maxp)
then
return
end
if settlements.debug == true then
minetest.chat_send_all("Last opportunity ".. os.difftime(os.time(), settlements.last_settlement))
end
-- if settlements.debug == true then
-- minetest.chat_send_all("Last opportunity ".. os.difftime(os.time(), settlements.last_settlement))
-- end
--
-- don't build settlement underground
--
Expand Down
22 changes: 16 additions & 6 deletions utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function settlements.find_surface(pos)
--
-- possible surfaces where buildings can be built
--
local surface_mat = {
local surface_mat = settlements.Set {
"default:dirt_with_grass",
"default:dry_dirt_with_grass",
"default:dirt_with_snow",
Expand Down Expand Up @@ -166,8 +166,9 @@ function settlements.find_surface(pos)
-- Check Surface_node and Node above
--
local surface_node_plus_1 = minetest.get_node_or_nil({ x=p6.x, y=p6.y+1, z=p6.z})
for i, mats in ipairs(surface_mat) do
if surface_node.name == mats then
-- for i, mats in ipairs(surface_mat) do
--minetest.chat_send_all(surface_mat[surface_node.name])
if surface_mat[surface_node.name] then
if surface_node_plus_1 and surface_node and
(string.find(surface_node_plus_1.name,"air") or
string.find(surface_node_plus_1.name,"snow") or
Expand All @@ -177,7 +178,7 @@ function settlements.find_surface(pos)
string.find(surface_node_plus_1.name,"tree") or
string.find(surface_node_plus_1.name,"grass"))
then
return p6, mats
return p6, surface_node.name
else
if settlements.debug == true then
minetest.chat_send_all("find_surface2: wrong surface+1")
Expand All @@ -188,11 +189,11 @@ function settlements.find_surface(pos)
if string.find(surface_node.name,"air") then
local a=1
else
minetest.chat_send_all("find_surface3: wrong surface"..surface_node.name)
minetest.chat_send_all("find_surface3: wrong surface "..surface_node.name)
end
end
end
end
-- end
p6.y = p6.y + itter
if p6.y < 0 then
if settlements.debug == true then
Expand Down Expand Up @@ -475,3 +476,12 @@ function settlements.setlvm(vm, data)
vm:set_data(data)
vm:write_to_map(true)
end
-------------------------------------------------------------------------------
-- Set array to list
-- https://stackoverflow.com/questions/656199/search-for-an-item-in-a-lua-list
-------------------------------------------------------------------------------
function settlements.Set (list)
local set = {}
for _, l in ipairs(list) do set[l] = true end
return set
end

0 comments on commit 4ca9fbf

Please sign in to comment.