cleaned up unneccessary global variables and made most local
parent
29b803901e
commit
01b19637f2
|
@ -66,7 +66,9 @@ 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
|
||||
mg_villages.moretrees_treelist = nil;
|
||||
if( minetest.get_modpath( 'moretrees' )) then
|
||||
mg_villages.moretrees_treelist = moretrees.treelist;
|
||||
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;
|
||||
|
|
|
@ -110,7 +110,7 @@ ADD_RCC({'cottages:anvil', 80, 1, 2, forge=1 });
|
|||
|
||||
ADD_RCC({'currency:minegeld', 80, 10, 2, chest_private=1, chest_work=1 }); -- TODO: could be in any chest with a certain chance
|
||||
|
||||
ADD_RCC({'farming:hoe_stone', 80, 1, 2, farm_tiny=2, farm_full=2, chest_work });
|
||||
ADD_RCC({'farming:hoe_stone', 80, 1, 2, farm_tiny=2, farm_full=2, chest_work=2 });
|
||||
|
||||
ADD_RCC({'homedecor:beer_mug', 50, 1, 2, tavern=5, inn=3});
|
||||
ADD_RCC({'homedecor:book_blue', 50, 1, 2, church=1, library=1, chest_private=1});
|
||||
|
|
39
mapgen.lua
39
mapgen.lua
|
@ -76,7 +76,9 @@ mg_villages.check_if_ground = function( ci )
|
|||
-- store information about this node type for later use
|
||||
if( not( def )) then
|
||||
mg_villages.node_is_ground[ ci ] = false;
|
||||
elseif( def.groups and def.groups.tree) then
|
||||
elseif( not( def.walkable)) then
|
||||
mg_villages.node_is_ground[ ci ] = false;
|
||||
elseif( def.groups and def.groups.tree ) then
|
||||
mg_villages.node_is_ground[ ci ] = false;
|
||||
elseif( def.drop and def.drop == 'default:dirt') then
|
||||
mg_villages.node_is_ground[ ci ] = true;
|
||||
|
@ -97,7 +99,7 @@ mg_villages.lower_or_raise_terrain_at_point = function( x, z, target_height, min
|
|||
local tree = false;
|
||||
local jtree = false;
|
||||
local old_height = maxp.y;
|
||||
y = maxp.y;
|
||||
local y = maxp.y;
|
||||
-- search for a surface and set everything above target_height to air
|
||||
while( y > minp.y) do
|
||||
local ci = data[a:index(x, y, z)];
|
||||
|
@ -127,7 +129,7 @@ mg_villages.lower_or_raise_terrain_at_point = function( x, z, target_height, min
|
|||
end
|
||||
|
||||
if( not( surface_node ) and old_height == maxp.y ) then
|
||||
if( data[a:index( x, minp.y, z)]==c_air) then
|
||||
if( data[a:index( x, minp.y, z)]==cid.c_air) then
|
||||
old_height = vh - 2;
|
||||
elseif( minp.y < 0 ) then
|
||||
old_height = minp.y;
|
||||
|
@ -265,6 +267,7 @@ mg_villages.repair_outer_shell = function( villages, minp, maxp, vm, data, param
|
|||
for x = minp.x, maxp.x do
|
||||
-- inside a village
|
||||
if( village_area[ x ][ z ][ 2 ] > 0 ) then
|
||||
local y;
|
||||
local village = villages[ village_area[ x ][ z ][ 1 ]];
|
||||
-- the current node at the ground
|
||||
local node = data[a:index(x,village.vh,z)];
|
||||
|
@ -299,7 +302,7 @@ mg_villages.repair_outer_shell = function( villages, minp, maxp, vm, data, param
|
|||
if( ci ~= cid.c_ignore and (ci==cid.c_dirt or ci==cid.c_dirt_with_grass or ci==cid.c_sand or ci==cid.c_desert_sand)) then
|
||||
data[a:index(x,y,z)] = cid.c_air;
|
||||
-- if there was a moresnow cover, add a snow on top of the new floor node
|
||||
elseif( moresnow and ci ~= cid.c_ignore
|
||||
elseif( ci ~= cid.c_ignore
|
||||
and (ci==cid.c_msnow_1 or ci==cid.c_msnow_2 or ci==cid.c_msnow_3 or ci==cid.c_msnow_4 or
|
||||
ci==cid.c_msnow_5 or ci==cid.c_msnow_6 or ci==cid.c_msnow_7 or ci==cid.c_msnow_8 or
|
||||
ci==cid.c_msnow_9 or ci==cid.c_msnow_10 or ci==cid.c_msnow_11)) then
|
||||
|
@ -441,7 +444,7 @@ mg_villages.village_area_get_height = function( village_area, villages, minp, ma
|
|||
or ( z==minp.z-1 and village_area[ x ][ z-1 ][ 1 ] >= 0 )
|
||||
or ( z==maxp.z+1 and village_area[ x ][ z+1 ][ 1 ] >= 0 )) then
|
||||
|
||||
y = maxp.y;
|
||||
local y = maxp.y;
|
||||
while( y > minp.y and y >= 0) do
|
||||
local ci = data[a:index(x, y, z)];
|
||||
if(( ci ~= cid.c_air and ci ~= cid.c_ignore and mg_villages.check_if_ground( ci ) == true) or (y==0)) then
|
||||
|
@ -494,6 +497,7 @@ mg_villages.village_area_get_height = function( village_area, villages, minp, ma
|
|||
-- in some cases, choose that height which was counted most often
|
||||
elseif( topt and (tmax - tmin ) > 8 and height_count[ village_nr ] > 0) then
|
||||
|
||||
local qmw;
|
||||
if( ( tmax - topt ) > ( topt - tmin )) then
|
||||
qmw = tmax;
|
||||
else
|
||||
|
@ -545,6 +549,11 @@ print('CHANGING HEIGHT from '..tostring( village.vh )..' to '..tostring( new_hei
|
|||
end
|
||||
|
||||
|
||||
-- those functions from the mg mod do not have their own namespace
|
||||
if( minetest.get_modpath( 'mg' )) then
|
||||
mg_villages.add_savannatree = add_savannatree;
|
||||
mg_villages.add_pinetree = add_pinetree;
|
||||
end
|
||||
|
||||
mg_villages.grow_a_tree = function( pos, plant_id, minp, maxp, data, a, cid, pr )
|
||||
-- a normal tree; sometimes comes with apples
|
||||
|
@ -556,12 +565,12 @@ mg_villages.grow_a_tree = function( pos, plant_id, minp, maxp, data, a, cid, pr
|
|||
mg_villages.grow_jungletree( data, a, pos, math.random(1,100000))
|
||||
return true;
|
||||
-- a savannatree from the mg mod
|
||||
elseif( plant_id == cid.c_savannasapling and add_savannatree) then
|
||||
add_savannatree( data, a, pos.x, pos.y, pos.z, minp, maxp, pr)
|
||||
elseif( plant_id == cid.c_savannasapling and mg_villages.add_savannatree) then
|
||||
mg_villages.add_savannatree( data, a, pos.x, pos.y, pos.z, minp, maxp, pr)
|
||||
return true;
|
||||
-- a pine tree from the mg mod
|
||||
elseif( plant_id == cid.c_pinesapling and add_pinetree ) then
|
||||
add_pinetree( data, a, pos.x, pos.y, pos.z, minp, maxp, pr)
|
||||
elseif( plant_id == cid.c_pinesapling and mg_villages.add_pinetree ) then
|
||||
mg_villages.add_pinetree( data, a, pos.x, pos.y, pos.z, minp, maxp, pr)
|
||||
return true;
|
||||
end
|
||||
return false;
|
||||
|
@ -639,7 +648,7 @@ mg_villages.village_area_fill_with_plants = function( village_area, villages, mi
|
|||
data[a:index( x, h, z)] = cid.c_soil_wet;
|
||||
|
||||
-- put a snow cover on plants where needed
|
||||
if( g==cid.c_dirt_with_snow and moresnow ) then
|
||||
if( g==cid.c_dirt_with_snow and cid.c_msnow_1 ~= cid.c_ignore ) then
|
||||
data[a:index( x, h+2, z)] = cid.c_msnow_1;
|
||||
end
|
||||
|
||||
|
@ -666,9 +675,9 @@ end
|
|||
|
||||
|
||||
time_elapsed = function( t_last, msg )
|
||||
t_now = minetest.get_us_time();
|
||||
print( 'TIME ELAPSED: '..tostring( t_now - t_last )..' '..msg );
|
||||
return t_now;
|
||||
mg_villages.t_now = minetest.get_us_time();
|
||||
print( 'TIME ELAPSED: '..tostring( mg_villages.t_now - t_last )..' '..msg );
|
||||
return mg_villages.t_now;
|
||||
end
|
||||
|
||||
|
||||
|
@ -749,6 +758,8 @@ mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm,
|
|||
end
|
||||
end
|
||||
|
||||
local emin;
|
||||
local emax;
|
||||
-- if no voxelmanip data was passed on, read the data here
|
||||
if( not( vm ) or not( a) or not( data ) or not( param2_data ) ) then
|
||||
vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||
|
@ -830,7 +841,7 @@ mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm,
|
|||
|
||||
-- grow trees which are part of buildings into saplings
|
||||
for _,v in ipairs( village.to_add_data.extra_calls.trees ) do
|
||||
mg_villages.grow_a_tree( v, v.typ, minp, maxp, data, a, cid, pr );
|
||||
mg_villages.grow_a_tree( v, v.typ, minp, maxp, data, a, cid, nil ); -- TODO: supply pseudorandom value?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ end
|
|||
mg_villages.mg_drop_moresnow = function( x, z, y_top, y_bottom, a, data, param2_data)
|
||||
|
||||
-- this only works if moresnow is installed
|
||||
if( not( moresnow ) or not( moresnow.suggest_snow_type )) then
|
||||
if( not( mg_villages.moresnow_installed )) then
|
||||
return;
|
||||
end
|
||||
|
||||
|
@ -76,7 +76,7 @@ end
|
|||
|
||||
|
||||
|
||||
local function generate_building(pos, minp, maxp, data, param2_data, a, pr, extranodes, replacements, cid, extra_calls, building_nr_in_bpos)
|
||||
local function generate_building(pos, minp, maxp, data, param2_data, a, extranodes, replacements, cid, extra_calls, building_nr_in_bpos)
|
||||
local binfo = mg_villages.BUILDINGS[pos.btype]
|
||||
local scm
|
||||
|
||||
|
@ -182,11 +182,13 @@ local function generate_building(pos, minp, maxp, data, param2_data, a, pr, extr
|
|||
local has_snow = false;
|
||||
local ground_type = c_dirt_with_grass;
|
||||
for y = 0, binfo.ysize-1 do
|
||||
ax, ay, az = pos.x+x, pos.y+y+binfo.yoff, pos.z+z
|
||||
local ax = pos.x+x;
|
||||
local ay = pos.y+y+binfo.yoff;
|
||||
local az = pos.z+z;
|
||||
if (ax >= minp.x and ax <= maxp.x) and (ay >= minp.y and ay <= maxp.y) and (az >= minp.z and az <= maxp.z) then
|
||||
|
||||
local new_content = c_air;
|
||||
t = scm[y+1][xoff][zoff];
|
||||
local t = scm[y+1][xoff][zoff];
|
||||
|
||||
if( binfo.yoff+y == 0 ) then
|
||||
local node_content = data[a:index(ax, ay, az)];
|
||||
|
@ -523,7 +525,7 @@ mg_villages.place_buildings = function(village, minp, maxp, data, param2_data, a
|
|||
end
|
||||
end
|
||||
|
||||
local replacements = mg_villages.get_replacement_table( village.village_type, p, village.to_add_data.replacements );
|
||||
local replacements = mg_villages.get_replacement_table( village.village_type, nil, village.to_add_data.replacements );
|
||||
|
||||
cid.c_chest = mg_villages.get_content_id_replaced( 'default:chest', replacements );
|
||||
cid.c_chest_locked = mg_villages.get_content_id_replaced( 'default:chest_locked', replacements );
|
||||
|
@ -561,7 +563,7 @@ mg_villages.place_buildings = function(village, minp, maxp, data, param2_data, a
|
|||
-- roads are only placed if there are at least mg_villages.MINIMAL_BUILDUNGS_FOR_ROAD_PLACEMENT buildings in the village
|
||||
if( not(pos.btype) or pos.btype ~= 'road' or anz_buildings > mg_villages.MINIMAL_BUILDUNGS_FOR_ROAD_PLACEMENT )then
|
||||
-- replacements are in table format for mapgen-based building spawning
|
||||
generate_building(pos, minp, maxp, data, param2_data, a, pr_village, extranodes, replacements, cid, extra_calls, i )
|
||||
generate_building(pos, minp, maxp, data, param2_data, a, extranodes, replacements, cid, extra_calls, i )
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -584,7 +586,7 @@ mg_villages.place_dirt_roads = function(village, minp, maxp, data, param2_data,
|
|||
local ax = pos.x+x;
|
||||
local az = pos.z+z;
|
||||
|
||||
if (ax >= minp.x and ax <= maxp.x) and (ay >= minp.y and ay <= maxp.y) and (az >= minp.z and az <= maxp.z) then
|
||||
if (ax >= minp.x and ax <= maxp.x) and (pos.y >= minp.y and pos.y <= maxp.y-2) and (az >= minp.z and az <= maxp.z) then
|
||||
-- roads have a height of 1 block
|
||||
data[ a:index( ax, pos.y, az)] = c_road_node;
|
||||
param2_data[ a:index( ax, pos.y, az)] = param2;
|
||||
|
@ -597,3 +599,6 @@ mg_villages.place_dirt_roads = function(village, minp, maxp, data, param2_data,
|
|||
end
|
||||
end
|
||||
|
||||
if( minetest.get_modpath('moresnow' )) then
|
||||
mg_villages.moresnow_installed = true;
|
||||
end
|
||||
|
|
|
@ -67,8 +67,8 @@ mg_villages.replace_materials = function( replacements, pr, original_materials,
|
|||
end
|
||||
|
||||
-- support wooden planks from moretrees
|
||||
if( wood_found and moretrees and moretrees.treelist ) then
|
||||
for _,v in ipairs( moretrees.treelist ) do
|
||||
if( wood_found and mg_villages.moretrees_treelist ) then
|
||||
for _,v in ipairs( mg_villages.moretrees_treelist ) do
|
||||
if( minetest.registered_nodes[ "moretrees:"..v[1].."_planks"] ) then
|
||||
table.insert( known_materials, "moretrees:"..v[1].."_planks" );
|
||||
end
|
||||
|
@ -144,8 +144,8 @@ mg_villages.replace_tree_trunk = function( replacements, wood_type )
|
|||
elseif( wood_type == 'mg:pinewood' ) then
|
||||
table.insert( replacements, {'default:tree', 'mg:pinetree'});
|
||||
|
||||
elseif( moretrees and moretrees.treelist ) then
|
||||
for _,v in ipairs( moretrees.treelist ) do
|
||||
elseif( mg_villages.moretrees_treelist ) then
|
||||
for _,v in ipairs( mg_villages.moretrees_treelist ) do
|
||||
if( wood_type == "moretrees:"..v[1].."_planks" ) then
|
||||
table.insert( replacements, {'default:tree', "moretrees:"..v[1].."_trunk"});
|
||||
table.insert( replacements, {'default:leaves', "moretrees:"..v[1].."_leaves"});
|
||||
|
@ -225,8 +225,8 @@ mg_villages.replace_saplings = function( replacements, wood_type )
|
|||
table.insert( replacements, {'default:sapling', 'mg:savannasapling'});
|
||||
elseif( wood_type == 'mg:pinewood' ) then
|
||||
table.insert( replacements, {'default:sapling', 'mg:pinesapling'});
|
||||
elseif( moretrees and moretrees.treelist ) then
|
||||
for _,v in ipairs( moretrees.treelist ) do
|
||||
elseif( mg_villages.moretrees_treelist ) then
|
||||
for _,v in ipairs( mg_villages.moretrees_treelist ) do
|
||||
if( wood_type == "moretrees:"..v[1].."_planks" ) then
|
||||
table.insert( replacements, {'default:sapling', "moretrees:"..v[1].."_sapling_ongen"});
|
||||
end
|
||||
|
|
|
@ -59,7 +59,7 @@ mg_villages.add_mirrored_node_type = function( name, mirrored_name )
|
|||
local id = minetest.get_content_id( name );
|
||||
local id_mi = minetest.get_content_id( mirrored_name );
|
||||
local c_ignore = minetest.get_content_id( 'ignore' );
|
||||
if( id and id_mi and id ~= c_ignore and id_mi2 ~= c_ignore ) then
|
||||
if( id and id_mi and id ~= c_ignore and id_mi ~= c_ignore ) then
|
||||
mg_villages.mirrored_node[ id ] = id_mi;
|
||||
end
|
||||
end
|
||||
|
|
19
villages.lua
19
villages.lua
|
@ -192,6 +192,11 @@ local function generate_road(village, l, pr, roadsize, rx, rz, rdx, rdz, vnoise,
|
|||
orient1 = 3
|
||||
orient2 = 1
|
||||
end
|
||||
local btype;
|
||||
local rotation;
|
||||
local bsizex;
|
||||
local bsizez;
|
||||
local mirror;
|
||||
-- we have one more road
|
||||
mg_villages.road_nr = mg_villages.road_nr + 1;
|
||||
while mg_villages.inside_village(rx, rz, village, vnoise) and not road_in_building(rx, rz, rdx, rdz, roadsize, l) do
|
||||
|
@ -296,6 +301,10 @@ local function generate_road(village, l, pr, roadsize, rx, rz, rdx, rdz, vnoise,
|
|||
end
|
||||
mx = mmx or rdx*math.max(rdx*mx, rdx*m2x)
|
||||
mz = mmz or rdz*math.max(rdz*mz, rdz*m2z)
|
||||
local rxmin;
|
||||
local rxmax;
|
||||
local rzmin;
|
||||
local rzmax;
|
||||
if rdx == 0 then
|
||||
rxmin = rx - roadsize + 1
|
||||
rxmax = rx + roadsize - 1
|
||||
|
@ -419,7 +428,7 @@ local function generate_bpos(village, pr, vnoise, space_between_buildings)
|
|||
-- the function below is recursive; we need a way to count roads
|
||||
mg_villages.road_nr = 0;
|
||||
generate_road(village, l, pr, mg_villages.FIRST_ROADSIZE, rx, rz, 1, 0, vnoise, space_between_buildings)
|
||||
i = 1
|
||||
local i = 1
|
||||
while i < calls.index do
|
||||
generate_road(unpack(calls[i]))
|
||||
i = i+1
|
||||
|
@ -442,6 +451,10 @@ local function generate_dirt_roads( village, vnoise, bpos, secondary_dirt_roads
|
|||
local sizex = pos.bsizex;
|
||||
local sizez = 2;
|
||||
local orientation = 0;
|
||||
local vx;
|
||||
local vz;
|
||||
local vsx;
|
||||
local vsz;
|
||||
-- prolong the roads; start with a 3x2 piece of road for testing
|
||||
if( pos.btype == 'road' ) then
|
||||
-- the road streches in x direction
|
||||
|
@ -495,7 +508,7 @@ local function generate_dirt_roads( village, vnoise, bpos, secondary_dirt_roads
|
|||
sizez = pos.bsizez+1;
|
||||
vx = 0; vz = -1; vsx = 0; vsz = 1;
|
||||
|
||||
elseif( pos.o == 3 ) then
|
||||
else --if( pos.o == 3 ) then
|
||||
x = pos.x-2;
|
||||
z = pos.z-pos.side;
|
||||
sizex = 2;
|
||||
|
@ -624,7 +637,7 @@ mg_villages.generate_village = function(village, vnoise)
|
|||
|
||||
-- determine which plants will grow in the area around the village
|
||||
local plantlist = {};
|
||||
sapling_id = mg_villages.get_content_id_replaced( 'default:sapling', replacements );
|
||||
local sapling_id = mg_villages.get_content_id_replaced( 'default:sapling', replacements );
|
||||
-- 1/sapling_p = probability of a sapling beeing placed
|
||||
local sapling_p = 25;
|
||||
if( mg_villages.sapling_probability[ sapling_id ] ) then
|
||||
|
|
2
we.lua
2
we.lua
|
@ -42,7 +42,7 @@ mg_villages.import_scm = function(scm)
|
|||
return {};
|
||||
end
|
||||
|
||||
value = f:read("*a")
|
||||
local value = f:read("*a")
|
||||
f:close()
|
||||
value = value:gsub("return%s*{", "", 1):gsub("}%s*$", "", 1)
|
||||
local escaped = value:gsub("\\\\", "@@"):gsub("\\\"", "@@"):gsub("(\"[^\"]*\")", function(s) return string.rep("@", #s) end)
|
||||
|
|
Loading…
Reference in New Issue