settlements/init.lua

141 lines
5.1 KiB
Lua
Raw Normal View History

Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
settlements = {}
2019-07-14 11:32:10 -07:00
2020-02-16 19:23:54 -08:00
local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname)
2020-02-16 19:23:54 -08:00
settlements.S = minetest.get_translator(modname)
settlements.half_map_chunk_size = tonumber(minetest.get_mapgen_setting("chunksize")) * 16 / 2
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
settlements.surface_materials = {}
2020-01-16 20:12:09 -08:00
settlements.registered_settlements = {}
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
-- Minimum distance between settlements
settlements.min_dist_settlements = tonumber(minetest.settings:get("settlements_minimum_distance_between_settlements")) or 500
-- maximum allowed difference in height for building a settlement
local max_height_difference = tonumber(minetest.settings:get("settlements_maximum_height_difference")) or 10
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
dofile(modpath.."/upgrades.lua")
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
dofile(modpath.."/buildings.lua")
2020-01-16 20:12:09 -08:00
dofile(modpath.."/bookgen.lua")
dofile(modpath.."/admin_commands.lua")
dofile(modpath.."/admin_tools.lua")
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
settlements.register_settlement = function(settlement_type_name, settlement_def)
2020-01-16 20:12:09 -08:00
assert(not settlements.registered_settlements[settlement_type_name])
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
settlement_def.name = settlement_type_name
2020-01-16 20:12:09 -08:00
settlements.registered_settlements[settlement_type_name] = settlement_def
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
for _, material in ipairs(settlement_def.surface_materials) do
local c_mat = minetest.get_content_id(material)
local material_list = settlements.surface_materials[c_mat] or {}
settlements.surface_materials[c_mat] = material_list
table.insert(material_list, settlement_def)
end
end
-- Interconverting lua and mts formatted schematics
-- Useful for modders adding existing schematics that are in mts format
function settlements.convert_mts_to_lua(schem_path)
local str = minetest.serialize_schematic(schem_path, "lua", {lua_use_comments = true})
local file = io.open(schem_path:sub(1,-4).."lua", "w")
file:write(str.."\nreturn schematic")
file:close()
end
-------------------------------------------------------------------------------
-- check distance to other settlements
-------------------------------------------------------------------------------
local function check_distance_other_settlements(center_new_chunk)
local min_edge = vector.subtract(center_new_chunk, settlements.min_dist_settlements)
local max_edge = vector.add(center_new_chunk, settlements.min_dist_settlements)
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
-- This gets all neighbors within a cube-shaped volume
local neighbors = named_waypoints.get_waypoints_in_area("settlements", min_edge, max_edge)
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
-- Search through those to find any that are within a spherical volume
for i, settlement in pairs(neighbors) do
local distance = vector.distance(center_new_chunk, settlement.pos)
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
if distance < settlements.min_dist_settlements then
return false
end
end
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
return true
end
-------------------------------------------------------------------------------
-- evaluate heightmap
-------------------------------------------------------------------------------
local function evaluate_heightmap(heightmap)
-- max height and min height, initialize with impossible values for easier first time setting
local max_y = -50000
local min_y = 50000
-- only evaluate the center square of heightmap 40 x 40
local square_start = 1621
local square_end = 1661
for j = 1, 40 do
for i = square_start, square_end do
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
-- skip buggy heightmaps, return high value
if heightmap[i] == -31000 or
heightmap[i] == 31000 then
return max_height_difference + 1
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
end
if heightmap[i] < min_y then
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
min_y = heightmap[i]
end
if heightmap[i] > max_y then
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
max_y = heightmap[i]
end
end
-- set next line
square_start = square_start + 80
square_end = square_end + 80
end
-- return the difference between highest and lowest pos in chunk
local height_diff = max_y - min_y
-- filter buggy heightmaps
if height_diff < 0 then
return max_height_difference + 1
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
end
return height_diff
end
local half_map_chunk_size = settlements.half_map_chunk_size
minetest.register_on_generated(function(minp, maxp)
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
-- don't build settlement underground
if maxp.y < -100 then
return
end
local existing_settlements = named_waypoints.get_waypoints_in_area("settlements", minp, maxp)
local id, data = next(existing_settlements)
if id ~= nil then
-- There's already a settlement in this chunk despite us being in mapgen.
-- This chunk must have been previously generated and is now being re-generated. Override
-- any further checks and try building a settlement here.
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local va = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
data = data.data
settlements.generate_settlement_vm(vm, va, minp, maxp, data.name)
return
end
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
-- don't build settlements too close to each other
local center_of_chunk = vector.subtract(maxp, half_map_chunk_size)
local dist_ok = check_distance_other_settlements(center_of_chunk)
if dist_ok == false then
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
return
end
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
-- don't build settlements on (too) uneven terrain
local heightmap = minetest.get_mapgen_object("heightmap")
local height_difference = evaluate_heightmap(heightmap)
if height_difference > max_height_difference then
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
return
end
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
local va = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
Major rewrite - refactor code for efficiency, add API and new settlement types, HUD waypoints (#1) * initial pass at major refactoring * fixed find_surface * switch over to lua table schematics for better node replacement, remove _lvm suffixes * optimize screenshots * dynamic count array * various further trimmings, add settingtypes * move more code out of globals, get schematic dimensions directly from schematic * greatly reducing public method exposure and global variables, fix vm data memory management * fix evaluate_heightmaps call, add dependencies from schematic node types * fix undeclared local * start searching for surace closer to the centerline * split generate settlement up into mapgen and non-mapgen, fix debug tool's building placer * reformat schematics, add separate nightmarket * fix map lighting, test out shared wall materials to give towns separate character * add namegen support * add town discovery and waypoint display features * make commoditymarket an optional dependency * add random books to shelves * make w1, w2 local * first pass at settlement definition registration. * support multiple waypoints * move node initialization into settlement def, add discovery popup and chime * igloo clusters * put altitude check into settlement def * stress-test api a bit more by adding underwater settlements * adjust positions of schematics to reduce prominence of terraforming platforms * rename const.lua * fix well height adjust * use an areastore for laying out settlement buildings * add jungle-specific settlement * add a more substansive central jungle settlement structure * add a namegen for the jungle camps * switch over to areastore-based mapping, add desert settlements * reduce footprint of king's market * allow market schematics when commoditymarket is not installed * remove bookgen for now - will come up with something better later * remove some old debug stuff, put a guard on the debugging tool just in case one falls into the wrong hands * add a separate list for "central" buildings * typo in chatcommand description field name * add option to require mapping kit to see hud waypoints * add a little more namegen diversity * fix optional replacements * turn on some of the specialized settlements by default * add some non-gibberish book generators * enhance travel guide directions, add ABM to auto-author books every once in a while * update locale * add an option for book generation * update documentation
2020-01-13 21:23:02 -08:00
settlements.generate_settlement_vm(vm, va, minp, maxp)
end)