2021-01-27 09:56:53 +01:00
settlements = { }
2021-05-29 16:12:33 +02:00
settlements.modpath = minetest.get_modpath ( minetest.get_current_modname ( ) )
2021-01-27 09:56:53 +01:00
2021-05-02 01:56:55 +02:00
local minetest_get_spawn_level = minetest.get_spawn_level
2021-01-27 09:56:53 +01:00
dofile ( settlements.modpath .. " /const.lua " )
dofile ( settlements.modpath .. " /utils.lua " )
dofile ( settlements.modpath .. " /foundation.lua " )
dofile ( settlements.modpath .. " /buildings.lua " )
dofile ( settlements.modpath .. " /paths.lua " )
2022-02-07 01:25:52 +01:00
2021-01-27 09:56:53 +01:00
--
-- load settlements on server
--
settlements_in_world = settlements.load ( )
settlements.grundstellungen ( )
2021-02-09 13:06:19 +01:00
2021-01-27 09:56:53 +01:00
--
-- register block for npc spawn
--
2021-02-09 13:06:19 +01:00
minetest.register_node ( " mcl_villages:stonebrickcarved " , {
description = ( " Chiseled Stone Village Bricks " ) ,
_doc_items_longdesc = doc.sub . items.temp . build ,
tiles = { " mcl_core_stonebrick_carved.png " } ,
stack_max = 64 ,
drop = " mcl_core:stonebrickcarved " ,
groups = { pickaxey = 1 , stone = 1 , stonebrick = 1 , building_block = 1 , material_stone = 1 } ,
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
is_ground_content = false ,
_mcl_blast_resistance = 6 ,
_mcl_hardness = 1.5 ,
} )
2021-01-27 09:56:53 +01:00
--
-- on map generation, try to build a settlement
--
2021-02-22 00:15:32 +01:00
local function build_a_settlement ( minp , maxp , blockseed )
2021-05-02 01:56:55 +02:00
minetest.log ( " action " , " [mcl_villages] Building village at mapchunk " .. minetest.pos_to_string ( minp ) .. " ... " .. minetest.pos_to_string ( maxp ) .. " , blockseed = " .. tostring ( blockseed ) )
2021-01-27 09:56:53 +01:00
local pr = PseudoRandom ( blockseed )
2021-01-29 19:49:33 +01:00
2021-01-27 09:56:53 +01:00
-- fill settlement_info with buildings and their data
2022-02-06 03:46:21 +01:00
local settlement_info = settlements.create_site_plan ( minp , maxp , pr )
2021-01-27 09:56:53 +01:00
if not settlement_info then return end
-- evaluate settlement_info and prepair terrain
2021-01-29 19:49:33 +01:00
settlements.terraform ( settlement_info , pr )
2021-01-27 09:56:53 +01:00
-- evaluate settlement_info and build paths between buildings
2021-01-29 19:49:33 +01:00
settlements.paths ( settlement_info )
2021-01-27 09:56:53 +01:00
-- evaluate settlement_info and place schematics
2021-01-29 19:49:33 +01:00
settlements.place_schematics ( settlement_info , pr )
2021-01-27 09:56:53 +01:00
end
2021-02-01 22:45:22 +01:00
-- Disable natural generation in singlenode.
local mg_name = minetest.get_mapgen_setting ( " mg_name " )
2022-02-06 03:46:21 +01:00
local scan_last_node = ( mcl_mapgen.CS - 2 ) * mcl_mapgen.BS - 1
local scan_offset = mcl_mapgen.BS
2021-02-01 22:45:22 +01:00
if mg_name ~= " singlenode " then
2021-08-05 02:01:07 +02:00
mcl_mapgen.register_mapgen ( function ( minp , maxp , blockseed )
2021-05-02 01:56:55 +02:00
-- local str1 = (maxp.y >= 0 and blockseed % 77 == 17) and "YES" or "no"
-- minetest.log("action","[mcl_villages] " .. str1 .. ": minp=" .. minetest.pos_to_string(minp) .. ", maxp=" .. minetest.pos_to_string(maxp) .. ", blockseed=" .. tostring(blockseed))
2021-02-01 22:45:22 +01:00
-- don't build settlement underground
2022-02-06 03:46:21 +01:00
local y_max = maxp.y
if y_max < - 30 then return end
2021-02-22 00:15:32 +01:00
-- randomly try to build settlements
2022-02-06 03:46:21 +01:00
-- if blockseed % 77 ~= 17 then return end
2021-05-02 01:56:55 +02:00
2021-02-01 22:45:22 +01:00
-- don't build settlements on (too) uneven terrain
2021-05-02 01:56:55 +02:00
-- lame and quick replacement of `heightmap` by kay27 - we maybe need to restore `heightmap` analysis if there will be a way for the engine to avoid cavegen conflicts:
--------------------------------------------------------------------------
2022-02-06 03:46:21 +01:00
local min , max = 9999999 , - 9999999
local pr = PseudoRandom ( blockseed )
for i = 1 , pr : next ( 5 , 10 ) do
local pos = vector.add ( vector.new ( pr : next ( 0 , scan_last_node ) + scan_offset , 0 , pr : next ( 0 , scan_last_node ) + scan_offset ) , minp )
local surface_point = settlements.find_surface ( pos )
if not surface_point then return end
local y = surface_point.y
min = math.min ( y , min )
max = math.max ( y , max )
2021-05-02 01:56:55 +02:00
end
2022-02-06 03:46:21 +01:00
local height_difference = max - min
2021-05-02 01:56:55 +02:00
--------------------------------------------------------------------------
2022-02-06 03:46:21 +01:00
minetest.chat_send_all ( " height diff= " .. height_difference )
if height_difference > 10 then return end
2021-02-22 00:15:32 +01:00
2021-05-02 01:56:55 +02:00
build_a_settlement ( minp , maxp , blockseed )
2021-08-05 02:01:07 +02:00
end , mcl_mapgen.order . VILLAGES )
2021-02-01 22:45:22 +01:00
end
2021-01-29 19:49:33 +01:00
-- manually place villages
if minetest.is_creative_enabled ( " " ) then
minetest.register_craftitem ( " mcl_villages:tool " , {
description = " mcl_villages build tool " ,
inventory_image = " default_tool_woodshovel.png " ,
-- build ssettlement
on_place = function ( itemstack , placer , pointed_thing )
if not pointed_thing.under then return end
local minp = vector.subtract ( pointed_thing.under , half_map_chunk_size )
local maxp = vector.add ( pointed_thing.under , half_map_chunk_size )
2021-02-22 00:15:32 +01:00
build_a_settlement ( minp , maxp , math.random ( 0 , 32767 ) )
2021-01-29 19:49:33 +01:00
end
} )
2021-03-07 17:07:55 +01:00
mcl_wip.register_experimental_item ( " mcl_villages:tool " )
2021-01-29 19:49:33 +01:00
end