Skip to content

Commit

Permalink
determining own heightmap too heavy, using official heightmap now
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeb187 committed Jul 19, 2018
1 parent b63e574 commit f52c3f3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion buildings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function settlements.place_settlement_circle(minp, maxp)
then
minetest.chat_send_all("really ".. number_built)
end
minetest.after(2, settlements.paths)
minetest.after(2, settlements.paths)
-- settlements.paths()
end
end
Expand Down
4 changes: 3 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ minetest.register_on_generated(function(minp, maxp)
--
-- don't build settlements on (too) uneven terrain
--
local height_difference = settlements.determine_heightmap(minp, maxp)
local height_difference = settlements.evaluate_heightmap(minp, maxp)
if height_difference > max_height_difference
then
return
Expand Down Expand Up @@ -116,6 +116,8 @@ minetest.register_craftitem("settlements:tool", {
-- build ssettlement
--
on_place = function(itemstack, placer, pointed_thing)
-- enable debug routines
settlements.debug = true
local center_surface = pointed_thing.under
if center_surface then
local minp = {
Expand Down
4 changes: 2 additions & 2 deletions paths.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function settlements.paths()
local starting_point
local end_point
local distance
-- for k,v in pairs(settlement_info) do
--for k,v in pairs(settlement_info) do
starting_point = settlement_info[1]["pos"]
for o,p in pairs(settlement_info) do

Expand Down Expand Up @@ -84,5 +84,5 @@ function settlements.paths()
end
end
end
-- end
--end
end
48 changes: 47 additions & 1 deletion utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function settlements.find_surface(pos)
-- if s and s.name == mats and not string.find(minetest.get_node_or_nil({ x=p6.x, y=p6.y+1, z=p6.z}).name,"water") then
local node_check = minetest.get_node_or_nil({ x=p6.x, y=p6.y+1, z=p6.z})
if node_check and s and s.name == mats and
(string.find(node_check.name,"air") or
(string.find(node_check.name,"air") or
string.find(node_check.name,"snow") or
string.find(node_check.name,"fern") or
string.find(node_check.name,"flower") or
Expand Down Expand Up @@ -235,4 +235,50 @@ function settlements.determine_heightmap(minp, maxp)
end
-- return the difference between highest and lowest pos in chunk
return max_y - min_y
end
--
-- evaluate heightmap
--
function settlements.evaluate_heightmap(minp, maxp)
-- max height and min height, initialize with impossible values for easier first time setting
local max_y = -50000
local min_y = 50000
-- only evaluate the center square of heightmap 40 x 40
local square_start = 1621
local square_end = 1661
local heightmap = minetest.get_mapgen_object("heightmap")
for j = 1 , 40, 1 do
for i = square_start, square_end, 1 do
-- skip buggy heightmaps, return high value
if heightmap[i] == -31000 or
heightmap[i] == 31000
then
return max_height_difference + 1
end
if heightmap[i] < min_y
then
min_y = heightmap[i]
end
if heightmap[i] > max_y
then
max_y = heightmap[i]
end
end
-- set next line
square_start = square_start + 80
square_end = square_end + 80
end
-- return the difference between highest and lowest pos in chunk
local height_diff = max_y - min_y
-- filter buggy heightmaps
if height_diff <= 1
then
return max_height_difference + 1
end
-- debug info
if settlements.debug == true
then
minetest.chat_send_all("heightdiff ".. height_diff)
end
return height_diff
end

0 comments on commit f52c3f3

Please sign in to comment.