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"
=========================
version: 0.1 Beta
version: 0.1 alpha
License of source code: WTFPL
-----------------------------
@ -16,8 +16,8 @@ http://sam.zoy.org/wtfpl/COPYING for more details.
Using the mod:
--------------
This mod adds randomly generated buildings in grass lands and forrests
This mod adds settlements on world generation
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 number_of_buildings
local number_built
--
-- build schematic, replace material, rotation
--
function settlements.build_schematic(pos, building, replace_wall, name)
-- get building node material for better integration to surrounding
local balcony_material = minetest.get_node_or_nil(pos).name
@ -132,35 +134,4 @@ function settlements.pick_next_building(pos_surface)
end
end
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

View File

@ -1,3 +1,6 @@
--
-- material to replace cobblestone with
--
wallmaterial = {
"default:junglewood",
"default:pine_wood",
@ -9,9 +12,14 @@ wallmaterial = {
"default:desert_stonebrick",
"default:desert_cobble",
"default:sandstone"
}
}
--
-- path to schematics
--
schem_path = settlements.modpath.."/schematics/"
--
-- list of schematics
--
schematic_table = {
{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"},
@ -21,10 +29,9 @@ schematic_table = {
{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"},
}
c_floor_material = "default:wood" -- not local because doors need it
last_time = os.time()
--
-- baseplate material, to replace dirt with grass and where buildings can be built
--
surface_mat = {
"default:dirt_with_grass",
"default:dirt_with_snow",
@ -32,10 +39,16 @@ surface_mat = {
"default:dirt_with_coniferous_litter",
"default:sand",
-- "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 = {}
--
-- list of settlements, load on server start up
--
settlements_in_world = {}
--
-- min_distance between settlements
--
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 cnt = 0
local mat = "dirt"
@ -15,7 +15,7 @@ function settlements.ground(pos) -- Wendelsteinkircherl, Brannenburg
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)
local p5 = settlements.shallowCopy(pos)

View File

@ -9,12 +9,17 @@ dofile(settlements.modpath.."/const.lua")
dofile(settlements.modpath.."/utils.lua")
dofile(settlements.modpath.."/foundation.lua")
dofile(settlements.modpath.."/buildings.lua")
--
-- load settlements on server
--
settlements_in_world = settlements.load()
--
-- register inhabitants
--
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("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
--
-- 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)
end
end)
--
-- manually place buildings, for debugging
-- manually place buildings, for debugging only
--
minetest.register_craftitem("settlements: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)
local copy = {}
@ -9,7 +9,7 @@ function settlements.shallowCopy(original)
return copy
end
--
-- Function to find surface block y coordinate
-- function to find surface block y coordinate
-- returns surface postion
--
function settlements.find_surface(pos)
@ -52,6 +52,8 @@ function settlements.check_distance(building_pos, building_size)
return true
end
--
-- save list of generated settlements
--
function settlements.save()
local file = io.open(minetest.get_worldpath().."/settlements.txt", "w")
if file then
@ -59,7 +61,9 @@ function settlements.save()
file:close()
end
end
--
-- load list of generated settlements
--
function settlements.load()
local file = io.open(minetest.get_worldpath().."/settlements.txt", "r")
if file then
@ -70,7 +74,9 @@ function settlements.load()
end
return {}
end
--
-- check distance to other settlements
--
function settlements.check_distance_other_settlements(center_new_chunk)
local min_dist_settlements = 300
for i, pos in ipairs(settlements_in_world) do
@ -81,7 +87,9 @@ function settlements.check_distance_other_settlements(center_new_chunk)
end
return true
end
--
-- fill chests
--
function settlements.fill_chest(pos)
-- find chests within radius
local chestpos = minetest.find_node_near(pos, 6, {"default:chest"})