From 54d00a7303608191f7ad0ab99abf94d7b2f420bb Mon Sep 17 00:00:00 2001 From: Sokomine Date: Tue, 19 Aug 2014 03:45:45 +0200 Subject: [PATCH] added plantlist depending on village type --- mapgen.lua | 68 +++++++++++++++++++++++++++++++++++++++----- replacements.lua | 14 ---------- villages.lua | 73 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 132 insertions(+), 23 deletions(-) diff --git a/mapgen.lua b/mapgen.lua index 2aeadad..6c8bd88 100644 --- a/mapgen.lua +++ b/mapgen.lua @@ -199,7 +199,7 @@ mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm, for _, pos in ipairs(village.to_add_data.dirt_roads) do -- the building + a border of 1 around it for x = 0, pos.bsizex-1 do - for z = 0, pos.bsizez-2 do + for z = 0, pos.bsizez-1 do local p = {x=pos.x+x, z=pos.z+z}; if( not( village_area[ p.x ] )) then village_area[ p.x ] = {}; @@ -277,7 +277,7 @@ print('For village_nr '..tostring( village_nr )..', a height of '..tostring( ide if( not( c_feldweg )) then c_feldweg = minetest.get_content_id('default:cobble'); end - local c_air = minetest.get_content_id('air'); + for _, village in ipairs(villages) do village.to_add_data = mg_villages.place_buildings( village, minp, maxp, data, param2_data, a, village_noise); @@ -285,10 +285,18 @@ print('For village_nr '..tostring( village_nr )..', a height of '..tostring( ide mg_villages.place_dirt_roads( village, minp, maxp, data, param2_data, a, village_noise, c_feldweg); end + local c_air = minetest.get_content_id( 'air'); + -- trees which require grow functions to be called + local c_sapling = minetest.get_content_id( 'default:sapling'); + local c_junglesapling = minetest.get_content_id( 'default:junglesapling'); + local c_savannasapling = minetest.get_content_id( 'mg:savannasapling'); + local c_pinesapling = minetest.get_content_id( 'mg:pinesapling'); -- add farmland local c_dirt_with_grass = minetest.get_content_id( 'default:dirt_with_grass' ); local c_desert_sand = minetest.get_content_id( 'default:desert_sand' ); local c_wheat = minetest.get_content_id( 'farming:wheat_8' ); + local c_cotton = minetest.get_content_id( 'farming:cotton_8' ); + local c_shrub = minetest.get_content_id( 'default:dry_shrub'); local c_soil_wet = minetest.get_content_id( 'farming:soil_wet' ); local c_soil_sand = minetest.get_content_id( 'farming:desert_sand_soil_wet' ); -- desert sand soil is only available in minetest_next @@ -302,26 +310,72 @@ print('For village_nr '..tostring( village_nr )..', a height of '..tostring( ide c_feldweg = c_dirt_with_grass; end + + local pr = PseudoRandom(mg_villages.get_bseed(minp)); for x = minp.x, maxp.x do for z = minp.z, maxp.z do -- turn unused land (which is either dirt or desert sand) into a field that grows wheat if( village_area[ x ][ z ][ 2 ]==1 ) then - local h = villages[ village_area[ x ][ z ][ 1 ] ].vh; + local village = villages[ village_area[ x ][ z ][ 1 ] ]; + local h = village.vh; local g = data[a:index( x, h, z )]; - if( g==c_dirt_with_grass ) then + + -- choose a plant/tree with a certain chance + -- Note: There are no checks weather the tree/plant will actually grow there or not; + -- Tree type is derived from wood type used in the village + local plant_id = data[a:index( x, h+1, z)]; + local on_soil = false; + for _,v in ipairs( village.to_add_data.plantlist ) do + -- select the first plant that fits; if the node is not air, keep what is currently inside + if( plant_id==c_air and (( v.p == 1 or pr:next( 1, v.p )==1 ))) then + -- TODO: check if the plant grows on that soil + plant_id = v.id; + -- wheat and cotton require soil + if( plant_id == c_wheat or plant_id == c_cotton ) then + on_soil = true; + end + end + end + + local pos = {x=x, y=h+1, z=z}; + -- a normal tree; sometimes comes with apples + if( plant_id == c_sapling ) then + default.grow_tree( data, a, pos, math.random(1, 4) == 1, math.random(1,100000)) + -- a normal jungletree + elseif( plant_id == c_junglesapling ) then + default.grow_jungletree( data, a, pos, math.random(1,100000)) + -- a savannatree from the mg mod + elseif( plant_id == c_savannasapling and add_savannatree) then + add_savannatree( data, a, pos.x, pos.y, pos.z, minp, maxp, pr) + -- a pine tree from the mg mod + elseif( plant_id == c_pinesapling and add_pinetree ) then + add_pinetree( data, a, pos.x, pos.y, pos.z, minp, maxp, pr) + + -- grow wheat and cotton on normal wet soil + elseif( on_soil and g==c_dirt_with_grass ) then param2_data[a:index( x, h+1, z)] = math.random( 1, 179 ); - data[a:index( x, h+1, z)] = c_wheat; + data[a:index( x, h+1, z)] = plant_id; data[a:index( x, h, z)] = c_soil_wet; data[a:index( x, h-1, z)] = c_water_source; data[a:index( x, h-2, z)] = c_clay; - elseif( g==c_desert_sand and c_soil_sand and c_soil_sand > 0) then + + -- grow wheat and cotton on desert sand soil + elseif( on_soil and g==c_desert_sand and c_soil_sand and c_soil_sand > 0) then param2_data[a:index( x, h+1, z)] = math.random( 1, 179 ); - data[a:index( x, h+1, z)] = c_wheat; + data[a:index( x, h+1, z)] = plant_id; data[a:index( x, h, z)] = c_soil_sand; data[a:index( x, h-1, z)] = c_clay; -- so that desert sand soil does not fall down data[a:index( x, h-2, z)] = c_water_source; data[a:index( x, h-3, z)] = c_clay; + + elseif( on_soil ) then + if( math.random(1,5)==1 ) then + data[a:index( pos.x, pos.y, pos.z)] = c_shrub; + end + + elseif( plant_id ) then -- place the sapling or plant (moretrees uses spawn_tree) + data[a:index( pos.x, pos.y, pos.z)] = plant_id; end end end diff --git a/replacements.lua b/replacements.lua index 4407f38..22be296 100644 --- a/replacements.lua +++ b/replacements.lua @@ -87,20 +87,6 @@ mg_villages.replace_saplings = function( replacements, wood_type ) end -mg_villages.get_sapling_content_id = function( replacements ) - for _,v in ipairs( replacements ) do - -- found the replacement for a sapling - if( v[1]=='default:sapling' ) then - return minetest.get_content_id( v[2] ); - end - end - -- found no repalcement; has to be normal tree growth - return minetest.get_content_id( 'default:sapling' ); -end - - - - -- Note: This function is taken from the villages mod (by Sokomine) -- at least the cottages may come in a variety of building materials -- IMPORTANT: don't add any nodes which have on_construct here UNLESS they where in the original file already diff --git a/villages.lua b/villages.lua index f1b94a6..5f45eb7 100644 --- a/villages.lua +++ b/villages.lua @@ -18,6 +18,33 @@ VILLAGE_MAX_SIZE = 150 FIRST_ROADSIZE = 5 BIG_ROAD_CHANCE = 50]] + +-- on average, every n.th node may be one of these trees - and it will be a relatively dense packed forrest +mg_villages.sapling_probability = {}; + +mg_villages.sapling_probability[ minetest.get_content_id( 'default:sapling' ) ] = 25; -- suitable for a relatively dense forrest of normal trees +mg_villages.sapling_probability[ minetest.get_content_id( 'default:junglesapling' ) ] = 40; -- jungletrees are a bit bigger and need more space +if( minetest.get_modpath( 'mg' )) then + mg_villages.sapling_probability[ minetest.get_content_id( 'mg:savannasapling' ) ] = 30; + mg_villages.sapling_probability[ minetest.get_content_id( 'mg:pinesapling' ) ] = 35; +end +if( minetest.get_modpath( 'moretrees' )) then + mg_villages.sapling_probability[ minetest.get_content_id( 'moretrees:birch_sapling_ongen' ) ] = 200; + mg_villages.sapling_probability[ minetest.get_content_id( 'moretrees:spruce_sapling_ongen' ) ] = 200; + mg_villages.sapling_probability[ minetest.get_content_id( 'moretrees:fir_sapling_ongen' ) ] = 90; + mg_villages.sapling_probability[ minetest.get_content_id( 'moretrees:jungletree_sapling_ongen' ) ] = 200; + mg_villages.sapling_probability[ minetest.get_content_id( 'moretrees:beech_sapling_ongen' ) ] = 30; + mg_villages.sapling_probability[ minetest.get_content_id( 'moretrees:apple_sapling_ongen' ) ] = 380; + mg_villages.sapling_probability[ minetest.get_content_id( 'moretrees:oak_sapling_ongen' ) ] = 380; -- ca 20x20; height: 10 + mg_villages.sapling_probability[ minetest.get_content_id( 'moretrees:sequoia_sapling_ongen' ) ] = 90; -- ca 10x10 + mg_villages.sapling_probability[ minetest.get_content_id( 'moretrees:palm_sapling_ongen' ) ] = 90; + mg_villages.sapling_probability[ minetest.get_content_id( 'moretrees:pine_sapling_ongen' ) ] = 200; + mg_villages.sapling_probability[ minetest.get_content_id( 'moretrees:willow_sapling_ongen' ) ] = 380; + mg_villages.sapling_probability[ minetest.get_content_id( 'moretrees:rubber_tree_sapling_ongen' ) ] = 380; +end + + + local function is_village_block(minp) local x, z = math.floor(minp.x/80), math.floor(minp.z/80) local vcc = VILLAGE_CHECK_COUNT @@ -928,7 +955,7 @@ mg_villages.generate_village = function(village, vnoise) -- only generate a new village if the data is not already stored -- (the algorithm is fast, but village types and houses which are available may change later on, -- and that might easily cause chaos if the village is generated again with diffrent input) - if( village.to_add_data and village.to_add_data.bpos and village.to_add_data.replacements ) then + if( village.to_add_data and village.to_add_data.bpos and village.to_add_data.replacements and village.to_add_data.plantlist) then --print('VILLAGE GENREATION: USING ALREADY GENERATED VILLAGE: Nr. '..tostring( village.nr )); return; end @@ -962,11 +989,51 @@ mg_villages.generate_village = function(village, vnoise) -- if the village is new, replacement_list is nil and a new replacement list will be created local replacements = mg_villages.get_replacement_table( village.village_type, p, nil ); + -- determine which plants will grow in the area around the village + local plantlist = {}; + local sapling_id = replacements.table[ 'default:sapling' ]; + if( not( sapling_id )) then + sapling_id = 'default:sapling'; + end + sapling_id = minetest.get_content_id( sapling_id ); + -- 1/sapling_p = probability of a sapling beeing placed + local sapling_p = 25; + if( mg_villages.sapling_probability[ sapling_id ] ) then + sapling_p = mg_villages.sapling_probability[ sapling_id ]; + end + + -- medieval villages are sourrounded by wheat fields + if( village_type == 'medieval' ) then + local c_wheat = minetest.get_content_id( 'farming:wheat_8'); + plantlist = { + { id=sapling_id, p=sapling_p*10 }, -- trees are rather rare + { id=c_wheat, p=1 }}; + -- lumberjack camps have handy trees nearby + elseif( village_type == 'lumberjack' ) then + local c_junglegrass = minetest.get_content_id( 'default:junglegrass'); + plantlist = { + { id=sapling_id, p=sapling_p }, + { id=c_junglegrass, p=25 }}; + -- the villages of type taoki grow cotton + elseif( village_type == 'taoki' ) then + local c_cotton = minetest.get_content_id( 'farming:cotton_8'); + plantlist = { + { id=sapling_id, p=sapling_p*5 }, -- not too many trees + { id=c_cotton, p=1 }}; + -- default/fallback: grassland + else + local c_grass = minetest.get_content_id( 'default:grass_5'); + plantlist = { + { id=sapling_id, p=sapling_p*10}, -- only few trees + { id=c_grass, p=3 }}; + end + -- store the generated data in the village table village.to_add_data = {}; village.to_add_data.bpos = bpos; village.to_add_data.replacements = replacements.list; village.to_add_data.dirt_roads = dirt_roads; + village.to_add_data.plantlist = plantlist; --print('VILLAGE GENREATION: GENERATING NEW VILLAGE Nr. '..tostring( village.nr )); end @@ -999,7 +1066,8 @@ mg_villages.place_buildings = function(village, minp, maxp, data, param2_data, a end -- replacements are in list format for minetest.place_schematic(..) type spawning - return { extranodes = extranodes, bpos = bpos, replacements = replacements.list, dirt_roads = village.to_add_data.dirt_roads }; + return { extranodes = extranodes, bpos = bpos, replacements = replacements.list, dirt_roads = village.to_add_data.dirt_roads, + plantlist = village.to_add_data.plantlist }; end @@ -1028,3 +1096,4 @@ mg_villages.place_dirt_roads = function(village, minp, maxp, data, param2_data, end end end +