Update mg_villages, Fix floating buildings bug

pull/14/head
Brandon 2015-07-20 23:04:55 -05:00
parent 0346e08007
commit a266d37116
16 changed files with 108 additions and 245 deletions

View File

@ -1 +1,2 @@
default
default
hunger?

View File

@ -165,6 +165,11 @@ print('FILE SIZE: '..tostring( string.len( data_string ))); -- TODO
return nil;
end
local translation_function = handle_schematics.findMC2MTConversion;
if( minetest.get_modpath('mccompat')) then
translation_function = mccompat.findMC2MTConversion;
end
local max_msg = 40; -- just for error handling
local size = {x=mc_schematic_data.Width, y=mc_schematic_data.Height, z=mc_schematic_data.Length};
local scm = {};
@ -175,10 +180,19 @@ print('FILE SIZE: '..tostring( string.len( data_string ))); -- TODO
for x=1,size.x do
scm[y][x] = {};
for z =1,size.z do
local new_node = handle_schematics.findMC2MTConversion(
local new_node = translation_function(
-- (Y×length + Z)×width + X.
mc_schematic_data.Blocks[ ((y-1)*size.z + (z-1) )*size.x + (size.x-x) +1],
mc_schematic_data.Data[ ((y-1)*size.z + (z-1) )*size.x + (size.x-x) +1] );
-- some MC nodes store the information about a node in TWO block and data fields (doors, large flowers, ...)
if( new_node[3] and new_node[3]~=0 ) then
new_node = translation_function(
-- (Y×length + Z)×width + X.
mc_schematic_data.Blocks[ ((y-1)*size.z + (z-1) )*size.x + (size.x-x) +1],
mc_schematic_data.Data[ ((y-1)*size.z + (z-1) )*size.x + (size.x-x) +1],
mc_schematic_data.Blocks[ ((y-1+new_node[3])*size.z + (z-1) )*size.x + (size.x-x) +1],
mc_schematic_data.Data[ ((y-1+new_node[3])*size.z + (z-1) )*size.x + (size.x-x) +1] );
end
if( not( nodenames_id[ new_node[1]] )) then
nodenames_id[ new_node[1] ] = #nodenames + 1;
nodenames[ nodenames_id[ new_node[1] ]] = new_node[1];

View File

@ -20,3 +20,4 @@ moreblocks?
bell?
mobf_trader?
docfarming?
mccompat?

View File

@ -51,9 +51,6 @@ dofile(handle_schematics.modpath.."/build_chest_add_schems_from_file.lua");
-- locate schematics through directories
dofile(handle_schematics.modpath.."/build_chest_add_schems_by_directory.lua");
-- chooses traders and spawn positions for buildings
dofile(handle_schematics.modpath.."/village_traders.lua")
-- the main functionality of the mod;
-- provides the function handle_schematics.place_building_from_file
-- (and also place_buildings for mg_villages)

View File

@ -164,7 +164,7 @@ local function generate_building_translate_nodenames( nodenames, replacements, c
-- place a normal chest here
new_nodes[ i ].new_content = cid.c_chest;
new_nodes[ i ].special_chest = node_name;
new_node_name = 'default:npc_chest';
new_node_name = 'default:chest';
elseif(new_node_name == 'cottages:chest_private'
or new_node_name == 'cottages:chest_work'
@ -258,7 +258,7 @@ local function generate_building_translate_nodenames( nodenames, replacements, c
end
local function generate_building(pos, minp, maxp, data, param2_data, a, extranodes, replacements, cid, extra_calls, building_nr_in_bpos, village_id, binfo_extra, road_node, keep_ground, barbarians)
local function generate_building(pos, minp, maxp, data, param2_data, a, extranodes, replacements, cid, extra_calls, building_nr_in_bpos, village_id, binfo_extra, road_node, keep_ground)
local binfo = binfo_extra;
if( not( binfo ) and mg_villages) then
@ -319,21 +319,6 @@ local function generate_building(pos, minp, maxp, data, param2_data, a, extranod
mg_villages.get_fruit_replacements( replacements, pos.fruit);
end
local traders = {};
if( handle_schematics.choose_traders ) then
local village_type = "";
if( village_id and mg_villages and mg_villages.all_villages and mg_villages.all_villages[ village_id ] ) then
village_type = mg_villages.all_villages[ village_id ].village_type;
end
local building_type = "";
if( binfo.typ ) then
building_type = binfo.typ;
end
if( not( pos.traders )) then
traders = handle_schematics.choose_traders( village_type, building_type, replacements )
end
end
local c_ignore = minetest.get_content_id("ignore")
local c_air = minetest.get_content_id("air")
local c_snow = minetest.get_content_id( "default:snow");
@ -553,16 +538,6 @@ local function generate_building(pos, minp, maxp, data, param2_data, a, extranod
end
end
end
-- spawn our NPCs
mobs.spawn_npc_and_spawner(pos,barbarians)
-- determine suitable positions for the traders
if( handle_schematics.choose_trader_pos and #traders>0) then
extra_calls.traders = handle_schematics.choose_trader_pos(pos, minp, maxp, data, param2_data, a, extranodes, replacements, cid, extra_calls, building_nr_in_bpos, village_id, binfo_extra, road_node, traders);
print('TRADERS CHOOSEN FOR '..tostring( binfo.scm )..': '..minetest.serialize( extra_calls.traders ));
end
end
@ -607,11 +582,10 @@ handle_schematics.place_buildings = function(village, minp, maxp, data, param2_d
if( pos.road_material ) then
road_material = pos.road_material;
end
generate_building(pos, minp, maxp, data, param2_data, a, extranodes, replacements, cid, extra_calls, i, village_id, nil, road_material, true, village.barbarians )
generate_building(pos, minp, maxp, data, param2_data, a, extranodes, replacements, cid, extra_calls, i, village_id, nil, road_material, true )
end
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,
plantlist = village.to_add_data.plantlist, extra_calls = extra_calls };

View File

@ -1,146 +0,0 @@
handle_schematics.choose_traders = function( village_type, building_type, replacements )
if( not( building_type ) or not( village_type )) then
return;
end
-- some jobs are obvious
if( building_type == 'mill' ) then
return { 'miller' };
elseif( building_type == 'bakery' ) then
return { 'baker' };
elseif( building_type == 'school' ) then
return { 'teacher' };
elseif( building_type == 'forge' ) then
local traders = {'blacksmith', 'bronzesmith' };
return { traders[ math.random(#traders)] };
elseif( building_type == 'shop' ) then
local traders = {'seeds','flowers','misc','default','ore', 'fruit trader', 'wood'};
return { traders[ math.random(#traders)] };
-- there are no traders for these jobs - they'd require specialized mobs
elseif( building_type == 'tower'
or building_type == 'church'
or building_type == 'secular'
or building_type == 'tavern' ) then
return {};
end
if( village_type == 'charachoal' ) then
return { 'charachoal' };
elseif( village_type == 'claytrader' ) then
return { 'clay' };
end
local res = {};
if( building_type == 'shed'
or building_type == 'farm_tiny'
or building_type == 'house'
or building_type == 'house_large'
or building_type=='hut') then
local traders = { 'stonemason', 'stoneminer', 'carpenter', 'toolmaker',
'doormaker', 'furnituremaker', 'stairmaker', 'cooper', 'wheelwright',
'saddler', 'roofer', 'iceman', 'potterer', 'bricklayer', 'dyemaker',
'dyemakerl', 'glassmaker' }
-- sheds and farms both contain craftmen
res = { traders[ math.random( #traders )] };
if( building_type == 'shed'
or building_type == 'house'
or building_type == 'house_large'
or building_type == 'hut' ) then
return res;
end
end
if( building_type == 'field'
or building_type == 'farm_full'
or building_type == 'farm_tiny' ) then
local fruit = 'farming:cotton';
if( 'farm_full' ) then
-- RealTest
fruit = 'farming:wheat';
if( replacements_group['farming'].traders[ 'farming:soy']) then
fruit_item = 'farming:soy';
end
if( minetest.get_modpath("mobf") ) then
local animal_trader = {'animal_cow', 'animal_sheep', 'animal_chicken', 'animal_exotic'};
res[1] = animal_trader[ math.random( #animal_trader )];
end
return { res[1], replacements_group['farming'].traders[ fruit_item ]};
elseif( #replacements_group['farming'].found > 0 ) then
-- get a random fruit to grow
fruit = replacements_group['farming'].found[ math.random( #replacements_group['farming'].found) ];
return { res[1], replacements_group['farming'].traders[ fruit_item ]};
else
return res;
end
end
if( building_type == 'pasture' and minetest.get_modpath("mobf")) then
local animal_trader = {'animal_cow', 'animal_sheep', 'animal_chicken', 'animal_exotic'};
return { animal_trader[ math.random( #animal_trader )] };
end
-- TODO: banana,cocoa,rubber from farming_plus?
-- TODO: sawmill
if( building_type == 'lumberjack' or village_type == 'lumberjack' ) then
-- TODO: limit this to single houses
if( replacements.table and replacements.table[ 'default:wood' ] ) then
return { replacements_group['wood'].traders[ replacements.table[ 'default:wood' ]] };
elseif( #replacements_group['wood'].traders > 0 ) then
return { replacements_group['wood'].traders[ math.random( #replacements_group['wood'].traders) ]};
else
return { 'common_wood'};
end
end
-- tent, chateau: places for living at; no special jobs associated
-- nore,taoki,medieval,lumberjack,logcabin,canadian,grasshut,tent: further village types
return res;
end
handle_schematics.choose_trader_pos = function(pos, minp, maxp, data, param2_data, a, extranodes, replacements, cid, extra_calls, building_nr_in_bpos, village_id, binfo_extra, road_node, traders)
local trader_pos = {};
-- determine spawn positions for the mobs
for i,tr in ipairs( traders ) do
local tries = 0;
local found = false;
local pt = {x=pos.x, y=pos.y, z=pos.z};
while( tries < 10 and not(found)) do
-- get a random position for the trader
pt.x = pos.x+math.random(pos.bsizex);
pt.z = pos.z+math.random(pos.bsizez);
-- check if it is inside the area contained in data
if (pt.x >= minp.x and pt.x <= maxp.x) and (pt.y >= minp.y and pt.y <= maxp.y) and (pt.z >= minp.z and pt.z <= maxp.z) then
while( pt.y < maxp.y
and (data[ a:index( pt.x, pt.y, pt.z)]~=cid.c_air
or data[ a:index( pt.x, pt.y+1, pt.z)]~=cid.c_air )) do
pt.y = pt.y + 1;
end
-- TODO: check if this position is really suitable? traders standing on the roof are a bit odd
found = true;
end
tries = tries+1;
-- check if this position has already been assigned to another trader
for j,t in ipairs( trader_pos ) do
if( t.x==pt.x and t.y==pt.y and t.z==pt.z ) then
found = false;
end
end
end
if( found ) then
table.insert( trader_pos, {x=pt.x, y=pt.y, z=pt.z, typ=tr, bpos_i = building_nr_in_bpos} );
end
end
return trader_pos;
end

View File

@ -8,7 +8,7 @@ minetest.register_biome({
depth_filler = 15,
node_dust = "air",
node_underwater = "default:dirt",
y_min = 3,
y_min = 2,
y_max = 230,
node_shore_filler = "default:sand",
heat_point = 45,
@ -54,7 +54,7 @@ minetest.register_biome({
node_dust = "air",
node_underwater = "default:dirt",
y_min = -25,
y_max = 3,
y_max = 1,
node_shore_filler = "default:gravel",
heat_point = 45,
humidity_point = 45,
@ -85,7 +85,7 @@ minetest.register_biome({
node_dust = "air",
node_underwater = "default:dirt",
y_min = -25,
y_max = 2,
y_max = 1,
node_shore_filler = "default:gravel",
heat_point = 45,
humidity_point = 65,

View File

@ -1 +1,2 @@
default
default
mg_villages?

View File

@ -43,6 +43,7 @@ c_papyrus = minetest.get_content_id("default:papyrus")
dofile(mgpath.."/trees.lua")
dofile(mgpath.."/biomes.lua")
dofile(mgpath.."/decorations.lua")
dofile(mgpath.."/villages.lua")
minetest.register_on_mapgen_init(function(params)
minetest.set_mapgen_params({

31
mods/mg/villages.lua Executable file
View File

@ -0,0 +1,31 @@
mg_villages.new_village_spawned = function( village_id )
-- determine whether it's a peaceful or barbarian village
local vx = mg_villages.all_villages[ village_id ].vx
local vz = mg_villages.all_villages[ village_id ].vz
local seed = vx * vz
local pr_vtype = PseudoRandom(seed)
local rptype = pr_vtype:next(1,10)
if mg_villages.anz_villages < 2 then
mg_villages.all_villages[ village_id ].barbarians = false
else
if rptype <= 3 then
mg_villages.all_villages[ village_id ].barbarians = true
else
mg_villages.all_villages[ village_id ].barbarians = false
end
end
end
mg_villages.part_of_village_spawned = function( village, minp, maxp, data, param2_data, a, cid )
--print("New building around "..minetest.pos_to_string(pos))
for i,bpos in pairs(village.to_add_data.bpos) do
-- get data about the building
local building_data = mg_villages.BUILDINGS[ bpos.btype ];
-- only handle buildings that are at least partly contained in that part of the
-- village that got spawned in this mapchunk
if not( bpos.x > maxp.x or bpos.x + bpos.bsizex < minp.x or bpos.z > maxp.z or bpos.z + bpos.bsizez < minp.z ) then
mobs.spawn_npc_and_spawner(bpos,village.barbarians)
end
end
end

View File

@ -6,10 +6,10 @@ mg_villages.ENABLE_VILLAGES = true;
-- generate one random building for each mg_villages.INVERSE_HOUSE_DENSITY th mapchunk;
-- set to 0 in order to disable spawning of these lone buildings outside villages
mg_villages.INVERSE_HOUSE_DENSITY = 0;
mg_villages.INVERSE_HOUSE_DENSITY = 4;
-- cover some villages with artificial snow; probability: 1/mg_villages.artificial_snow_probability
mg_villages.artificial_snow_probability = 0;
mg_villages.artificial_snow_probability = 10;
-- if set to true, soil around villaes will get special soil-snow instead of plant + snow cover
mg_villages.use_soil_snow = false;
@ -24,16 +24,16 @@ mg_villages.VILLAGE_DETECT_RANGE = 400;
-- if set to true, only players which have the mg_villages priv can use the "/visit <village nr>"
-- command which allows teleporting to the village with the given number
mg_villages.REQUIRE_PRIV_FOR_TELEPORT = true;
mg_villages.REQUIRE_PRIV_FOR_TELEPORT = false;
-- if set to true, players cannot modify spawned villages without buying the house from the village first
mg_villages.ENABLE_PROTECTION = true;
-- the first village - the one the player spawns in - will be of this type
mg_villages.FIRST_VILLAGE_TYPE = 'taoki';
mg_villages.FIRST_VILLAGE_TYPE = 'medieval';
-- choose the debug level you want
mg_villages.DEBUG_LEVEL = mg_villages.DEBUG_LEVEL_NONE
mg_villages.DEBUG_LEVEL = mg_villages.DEBUG_LEVEL_NORMAL
-- background image for the /vmap command
-- RealTest comes with a diffrent texture

View File

@ -19,5 +19,3 @@ metals?
grounds?
moreblocks?
bell?
mobf_trader?
mg?

View File

@ -13,11 +13,7 @@ end
-- things that can be found in private, not locked chests belonging to npc
-- contains tables of the following structure: { node_name, probability (in percent, 100=always, 0=never), max_amount, repeat (for more than one stack) }
mg_villages.random_chest_content = {};
ADD_RCC({"farming:bread", 60, 5, 2})
ADD_RCC({"mobs:meat", 50, 3, 2})
ADD_RCC({"bushes:strawberry", 30, 2, 1})
ADD_RCC({"bushes:berry_pie_cooked", 35, 2, 1})
ADD_RCC({"throwing:arrow", 20, 1, 4})
ADD_RCC({"default:pick_stone", 10, 1, 3, farm_tiny=1, farm_full=1, shed=1, lumberjack=1, hut=1, chest_work=1, lumberjack=1 });
ADD_RCC({"default:pick_steel", 5, 1, 2, forge=1 });
ADD_RCC({"default:pick_mese", 2, 1, 2, forge=1, lumberjack=1 });
@ -34,7 +30,7 @@ ADD_RCC({"default:torch", 50, 10, 4, church=1, library=1, chest
ADD_RCC({"default:book", 60, 1, 2, church=1, library=1 });
ADD_RCC({"default:paper", 60, 6, 4, church=1, library=1 });
ADD_RCC({"default:apple", 70, 10, 2, all=1});
ADD_RCC({"default:apple", 50, 10, 2, chest_storage=4, chest_private=1, shelf=5});
ADD_RCC({"default:ladder", 20, 1, 2, church=1, library=1, shed=1, lumberjack=1, hut=1 });
ADD_RCC({"default:coal_lump", 80, 30, 1, forge=1, shed=1, lumberjack=1, hut=1});
@ -43,6 +39,7 @@ ADD_RCC({"default:mese_crystal_fragment", 10, 3, 1, forge=1, chest_storage=1 }
ADD_RCC({"bucket:bucket_empty", 10, 3, 2, chest_work=1, forge=1, shed=1, hut=1 });
ADD_RCC({"bucket:bucket_water", 5, 3, 2, chest_work=1, forge=1 });
ADD_RCC({"bucket:bucket_lava", 3, 3, 2, forge=1 });
ADD_RCC({"vessels:glass_bottle", 10, 10, 2, church=1, library=1, shelf=1 });
ADD_RCC({"vessels:drinking_glass", 20, 2, 1, church=1, library=1, shelf=1 });
@ -155,12 +152,6 @@ mg_villages.fill_chest_random = function( pos, pr, building_nr, building_typ )
local meta = minetest.env:get_meta( pos );
local inv = meta:get_inventory();
local cexp = math.random(0,25)
local expitem = experience.exp_to_items(cexp)
for _,e in pairs(expitem) do
inv:add_item("main",e)
end
local count = 0;
local typ = minetest.get_name_from_content_id( pos.typ );
@ -176,7 +167,7 @@ mg_villages.fill_chest_random = function( pos, pr, building_nr, building_typ )
if( typ == 'cottages:chest_work' and building_data.typ ) then
typ2 = building_data.typ;
end
--print('FILLING chest of type '..tostring( typ )..' and '..tostring( typ2));
if( not( typ ) or typ=='' ) then
return;
end
@ -188,7 +179,7 @@ mg_villages.fill_chest_random = function( pos, pr, building_nr, building_typ )
-- to avoid too many things inside a chest, lower probability
if( count<30 -- make sure it does not get too much and there is still room for a new stack
and (v[ typ ] or (typ2 and v[ typ2 ]) or v.all )
and (v[ typ ] or (typ2 and v[ typ2 ]))
and inv_size and inv_size > 0 and v[ 2 ] > pr:next( 1, 200 )) then
--inv:add_item('main', v[ 1 ].." "..tostring( math.random( 1, tonumber(v[ 3 ]) )));

View File

@ -1,4 +1,30 @@
------------------------------------------------------------------------------
-- Interface for other mdos
-- this function gets executed only once per village - namely when the first
-- part of a village is generated;
-- relevant data about the vilalge can be found in the following data structure:
-- mg_villages.all_villages[ village_id ]
mg_villages.new_village_spawned = function( village_id )
-- dummy function
end
-- use this function if you want to i.e. spawn mobs/traders/etc;
-- the village data structure contains information about the entire village;
-- minp, maxp indicates which part has actually been spawned;
-- the function may add information to the village data structure if needed;
-- the voxelmanip data (data, param2_data, a) is just for reading, i.e. finding
-- a good spawning position for the trader
mg_villages.part_of_village_spawned = function( village, minp, maxp, data, param2_data, a, cid )
-- mobf needs a way to spawn its traders
if( minetest.get_modpath( 'mobf_trader' )) then
mob_village_traders.part_of_village_spawned( village, minp, maxp, data, param2_data, a, cid );
end
end
------------------------------------------------------------------------------
mg_villages.wseed = 0;
@ -931,11 +957,7 @@ mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm,
vm:set_param2_data(param2_data)
t1 = time_elapsed( t1, 'vm data set' );
vm:calc_lighting(
tmin, tmax
-- {x=minp.x-16, y=minp.y, z=minp.z-16},
-- {x=maxp.x+16, y=maxp.y, z=maxp.z+16}
)
vm:calc_lighting()
t1 = time_elapsed( t1, 'vm calc lighting' );
vm:write_to_map(data)
@ -967,23 +989,11 @@ mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm,
-- TODO: extra_calls.signs
-- spawn traders
-- useful for spawning mobs etc.
for _, village in ipairs(villages) do
if( mob_basics and mob_basics.spawn_mob ) then
local traderlist = village.to_add_data.extra_calls.traders;
-- for each trader
for _,v in ipairs( traderlist) do
-- spawn the trader
mob_basics.spawn_mob( {x=v.x, y=v.y, z=v.z}, v.typ, nil, nil, nil, nil );
end
-- store the traders
if( traderlist and #traderlist > 0 ) then
village.to_add_data.bpos[ traderlist[1].bpos_i ].traders = traderlist;
end
end
mg_villages.part_of_village_spawned( village, minp, maxp, data, param2_data, a, cid );
end
-- initialize the pseudo random generator so that the chests will be filled in a reproducable pattern
local meta
for _, village in ipairs(villages) do
@ -1014,6 +1024,9 @@ mg_villages.place_villages_via_voxelmanip = function( villages, minp, maxp, vm,
tostring( village.village_type ).."\' of size "..tostring( village.vs )..
" spawned at: x = "..village.vx..", z = "..village.vz)
village_data_updated = true;
-- hook for doing stuff that needs to be done exactly once per village
mg_villages.new_village_spawned( village_id );
end
end
-- always save the changed village data

View File

@ -629,19 +629,6 @@ mg_villages.generate_village = function(village, vnoise)
return;
end
if (not( mg_villages.all_villages ) or mg_villages.anz_villages < 1) then
village.barbarians = false
else
local pr_vtype = PseudoRandom(seed)
local rptype = pr_vtype:next(1,10)
if rptype <= 3 then
village.barbarians = true
else
village.barbarians = false
end
end
-- in the case of medieval villages, we later on want to add wheat fields with dirt roads; 1 wide dirt roads look odd
local space_between_buildings = 1;
if( mg_villages.village_type_data[ village_type ] and mg_villages.village_type_data[ village_type ].space_between_buildings) then

View File

@ -119,10 +119,10 @@ local numNPCs = math.random(0,1)
--print("Spawning "..tostring(numNPCs).." NPCs")
if numNPCs > 0 then
for i=0,numNPCs,1 do
local npos = pos
npos.x = npos.x + math.random(-8,8)
npos.y = npos.y + 2
npos.z = npos.z + math.random(-8,8)
local npos = {}
npos.x = pos.x + math.random(-8,8)
npos.y = pos.y + 2
npos.z = pos.z + math.random(-8,8)
local spawnerpos = {x=npos.x, y=npos.y, z=npos.z}
spawnerpos.y = spawnerpos.y - 5
@ -130,7 +130,7 @@ local numNPCs = math.random(0,1)
if barbarian_village == true then
local barbarian = mobs:get_random('barbarian')
minetest.log("action","Spawning "..barbarian.." at "..minetest.pos_to_string(npos))
local mob = minetest.add_entity(pos, barbarian)
local mob = minetest.add_entity(npos, barbarian)
if mob then
local distance_rating = ( ( get_distance({x=0,y=0,z=0},npos) ) / 15000 )
mob = mob:get_luaentity()
@ -143,11 +143,11 @@ local numNPCs = math.random(0,1)
local npc = mobs:get_random('npc')
minetest.log("action","Spawning "..npc.." at "..minetest.pos_to_string(npos))
local mob = minetest.add_entity(pos, npc)
local mob = minetest.add_entity(npos, npc)
if mob then
mob = mob:get_luaentity()
local p = mob.object:getpos()
math.randomseed( ( p.x * p.y * p.z ) )
--math.randomseed( ( p.x * p.y * p.z ) )
local metatable = { fields = { entity = npc, active_objects = 6 } }
--table.insert(extranodes, {node={name="mobs:spawner",param1=0, param2=0}, pos=spawnerpos, mob="npc"})
end