code cleanup, more comments

master
Rochambeau 2018-07-07 13:39:28 +02:00
parent 396f2c0bea
commit ebde8f21ec
7 changed files with 50 additions and 54 deletions

View File

@ -1,6 +1,6 @@
Minetest mod "Settlements" Minetest mod "Settlements"
========================= =========================
version: 0.1 Beta version: 0.1 alpha
License of source code: WTFPL License of source code: WTFPL
----------------------------- -----------------------------
@ -16,8 +16,8 @@ http://sam.zoy.org/wtfpl/COPYING for more details.
Using the mod: Using the mod:
-------------- --------------
This mod adds randomly generated buildings in grass lands and forrests This mod adds settlements on world generation
Credits: Credits:
-------------- --------------
This mod is heavily based on "ruins" by BlockMen This mod is based on "ruins" by BlockMen

View File

@ -8,7 +8,9 @@ end
local building_all_info local building_all_info
local number_of_buildings local number_of_buildings
local number_built local number_built
--
-- build schematic, replace material, rotation
--
function settlements.build_schematic(pos, building, replace_wall, name) function settlements.build_schematic(pos, building, replace_wall, name)
-- get building node material for better integration to surrounding -- get building node material for better integration to surrounding
local balcony_material = minetest.get_node_or_nil(pos).name local balcony_material = minetest.get_node_or_nil(pos).name
@ -132,35 +134,4 @@ function settlements.pick_next_building(pos_surface)
end end
end end
return nil return nil
end--
-- everything necessary to pick a fitting next building
--
function settlements.pick_next_building_old(pos_surface)
-- building_all_info = schematic_table[keyset[math.random(#keyset)]]
-- pick schematic based on chance
local random_number = math.random(1,100)
if random_number > 85 and count_buildings["garden"] < schematic_table["garden"]["max_num"]*number_of_buildings then
building_all_info = schematic_table["garden"]
elseif random_number > 75 and count_buildings["tower"] < schematic_table["tower"]["max_num"]*number_of_buildings then
building_all_info = schematic_table["tower"]
elseif random_number > 65 and count_buildings["lamp"] < schematic_table["lamp"]["max_num"]*number_of_buildings then
building_all_info = schematic_table["lamp"]
elseif random_number > 55 and count_buildings["church"] < schematic_table["church"]["max_num"]*number_of_buildings then
building_all_info = schematic_table["church"]
elseif random_number > 45 and count_buildings["blacksmith"] < schematic_table["blacksmith"]["max_num"]*number_of_buildings then
building_all_info = schematic_table["blacksmith"]
else
building_all_info = schematic_table["hut"]
end
-- before placing, check_distance to other buildings
local distance_to_other_buildings_ok = settlements.check_distance(pos_surface, building_all_info["hsize"])
if distance_to_other_buildings_ok then
-- count built houses
count_buildings[building_all_info["name"]] = count_buildings[building_all_info["name"]] +1
return building_all_info["mts"]
--todo hier den count_up einfügen
else
return nil
end
end end

View File

@ -1,3 +1,6 @@
--
-- material to replace cobblestone with
--
wallmaterial = { wallmaterial = {
"default:junglewood", "default:junglewood",
"default:pine_wood", "default:pine_wood",
@ -9,9 +12,14 @@ wallmaterial = {
"default:desert_stonebrick", "default:desert_stonebrick",
"default:desert_cobble", "default:desert_cobble",
"default:sandstone" "default:sandstone"
} }
--
-- path to schematics
--
schem_path = settlements.modpath.."/schematics/" schem_path = settlements.modpath.."/schematics/"
--
-- list of schematics -- list of schematics
--
schematic_table = { schematic_table = {
{name = "well", mts = schem_path.."well.mts", hsize = 11, max_num = 0, rplc = "n"}, {name = "well", mts = schem_path.."well.mts", hsize = 11, max_num = 0, rplc = "n"},
{name = "hut", mts = schem_path.."hut.mts", hsize = 11, max_num = 0.9, rplc = "y"}, {name = "hut", mts = schem_path.."hut.mts", hsize = 11, max_num = 0.9, rplc = "y"},
@ -21,10 +29,9 @@ schematic_table = {
{name = "church", mts = schem_path.."church.mts", hsize = 17, max_num = 0.050, rplc = "n"}, {name = "church", mts = schem_path.."church.mts", hsize = 17, max_num = 0.050, rplc = "n"},
{name = "blacksmith", mts = schem_path.."blacksmith.mts", hsize = 11, max_num = 0.055, rplc = "n"}, {name = "blacksmith", mts = schem_path.."blacksmith.mts", hsize = 11, max_num = 0.055, rplc = "n"},
} }
--
c_floor_material = "default:wood" -- not local because doors need it -- baseplate material, to replace dirt with grass and where buildings can be built
last_time = os.time() --
surface_mat = { surface_mat = {
"default:dirt_with_grass", "default:dirt_with_grass",
"default:dirt_with_snow", "default:dirt_with_snow",
@ -32,10 +39,16 @@ surface_mat = {
"default:dirt_with_coniferous_litter", "default:dirt_with_coniferous_litter",
"default:sand", "default:sand",
-- "default:snow" -- "default:snow"
} }
above_surface_mat = {"default:air","default:dirt_with_snow"} --
under_surface_mat = {"default:stone","default:dirt"} -- temporary info for currentliy built settlement (position of each building)
--
settlement_info = {} settlement_info = {}
--
-- list of settlements, load on server start up
--
settlements_in_world = {} settlements_in_world = {}
--
-- min_distance between settlements -- min_distance between settlements
--
min_dist_settlements = 150 min_dist_settlements = 150

View File

@ -1,7 +1,7 @@
-- --
-- Function to fill empty space below baseplate when building on a hill -- function to fill empty space below baseplate when building on a hill
-- --
function settlements.ground(pos) -- Wendelsteinkircherl, Brannenburg function settlements.ground(pos) -- role model: Wendelsteinkircherl, Brannenburg
local p2 = pos local p2 = pos
local cnt = 0 local cnt = 0
local mat = "dirt" local mat = "dirt"
@ -15,7 +15,7 @@ function settlements.ground(pos) -- Wendelsteinkircherl, Brannenburg
end end
end end
-- --
-- Function to fill empty space below baseplate when building on a hill -- function to fill empty space below baseplate when building on a hill
-- --
function settlements.foundation(pos, width, depth, height, rotation) function settlements.foundation(pos, width, depth, height, rotation)
local p5 = settlements.shallowCopy(pos) local p5 = settlements.shallowCopy(pos)

View File

@ -9,12 +9,17 @@ dofile(settlements.modpath.."/const.lua")
dofile(settlements.modpath.."/utils.lua") dofile(settlements.modpath.."/utils.lua")
dofile(settlements.modpath.."/foundation.lua") dofile(settlements.modpath.."/foundation.lua")
dofile(settlements.modpath.."/buildings.lua") dofile(settlements.modpath.."/buildings.lua")
--
-- load settlements on server -- load settlements on server
--
settlements_in_world = settlements.load() settlements_in_world = settlements.load()
--
-- register inhabitants
--
if minetest.get_modpath("mobs_npc") ~= nil then if minetest.get_modpath("mobs_npc") ~= nil then
--mobs:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height, day_toggle) --mobs:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height, day_toggle)
mobs:register_spawn("mobs_npc:npc", {"default:junglewood"}, 20, 0, 1, 7, 31000, nil) mobs:register_spawn("mobs_npc:npc", {"default:junglewood"}, 20, 0, 1, 7, 31000, nil)
-- mobs:register_spawn("mobs_npc:trader", {"default:junglewood"}, 20, 0, 1, 7, 31000, nil) mobs:register_spawn("mobs_npc:trader", {"default:junglewood"}, 20, 0, 1, 7, 31000, nil)
end end
-- --
-- on map generation, try to build a settlement -- on map generation, try to build a settlement
@ -33,9 +38,8 @@ minetest.register_on_generated(function(minp, maxp)
settlements.place_settlement_circle(minp, maxp) settlements.place_settlement_circle(minp, maxp)
end end
end) end)
-- --
-- manually place buildings, for debugging -- manually place buildings, for debugging only
-- --
minetest.register_craftitem("settlements:tool", { minetest.register_craftitem("settlements:tool", {
description = "settlements build tool", description = "settlements build tool",

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

View File

@ -1,5 +1,5 @@
-- --
-- Function to copy tables -- function to copy tables
-- --
function settlements.shallowCopy(original) function settlements.shallowCopy(original)
local copy = {} local copy = {}
@ -9,7 +9,7 @@ function settlements.shallowCopy(original)
return copy return copy
end end
-- --
-- Function to find surface block y coordinate -- function to find surface block y coordinate
-- returns surface postion -- returns surface postion
-- --
function settlements.find_surface(pos) function settlements.find_surface(pos)
@ -52,6 +52,8 @@ function settlements.check_distance(building_pos, building_size)
return true return true
end end
-- --
-- save list of generated settlements
--
function settlements.save() function settlements.save()
local file = io.open(minetest.get_worldpath().."/settlements.txt", "w") local file = io.open(minetest.get_worldpath().."/settlements.txt", "w")
if file then if file then
@ -59,7 +61,9 @@ function settlements.save()
file:close() file:close()
end end
end end
--
-- load list of generated settlements
--
function settlements.load() function settlements.load()
local file = io.open(minetest.get_worldpath().."/settlements.txt", "r") local file = io.open(minetest.get_worldpath().."/settlements.txt", "r")
if file then if file then
@ -70,7 +74,9 @@ function settlements.load()
end end
return {} return {}
end end
--
-- check distance to other settlements
--
function settlements.check_distance_other_settlements(center_new_chunk) function settlements.check_distance_other_settlements(center_new_chunk)
local min_dist_settlements = 300 local min_dist_settlements = 300
for i, pos in ipairs(settlements_in_world) do for i, pos in ipairs(settlements_in_world) do
@ -81,7 +87,9 @@ function settlements.check_distance_other_settlements(center_new_chunk)
end end
return true return true
end end
--
-- fill chests
--
function settlements.fill_chest(pos) function settlements.fill_chest(pos)
-- find chests within radius -- find chests within radius
local chestpos = minetest.find_node_near(pos, 6, {"default:chest"}) local chestpos = minetest.find_node_near(pos, 6, {"default:chest"})