Skip to content

Commit

Permalink
reorganize into a modpack.
Browse files Browse the repository at this point in the history
  • Loading branch information
FaceDeer committed Jan 17, 2020
1 parent e1a57be commit 8f9c848
Show file tree
Hide file tree
Showing 92 changed files with 1,276 additions and 608 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ This mod adds settlements on world generation. The settlements consist of a clus

With the exception of some optional commoditymarket node support, only nodes from the default minetest_game are used by the base schematics included in this mod.

![Medieval Settlement](screenshot_medieval.jpg)
![Medieval Settlement](settlements_medieval/screenshot.jpg)

The most common settlement type has a medieval flavour to it, with simple houses, blacksmiths, wells, churches, and fortified towers. The material used in the walls of each building is randomized to give each settlement a bit of unique feel. If the [commoditymarket](https://github.com/FaceDeer/commoditymarket) mod is installed, then some rare houses will have a Night Market hidden inside them. There are also more prominent trading posts with King's Markets.

![Desert Settlement](screenshot_desert.jpg)
![Desert Settlement](settlements_desert/screenshot.jpg)

Deserts have a unique settlement type featuring tall watchtowers and walled bazaars, which contain both Kings' Markets and Night Markets - commerce is a bit less constrained by the laws of the crown out in the shifting sand seas.

![Arctic Settlement](screenshot_arctic.jpg)
![Arctic Settlement](settlements_igloo/screenshot.jpg)

Deep arctic environments contain the occasional cluster of igloos, small islands of respite in a harsh climate. They are too small and isolated to have marketplaces.

![Jungle Settlement](screenshot_jungle.jpg)
![Jungle Settlement](settlements_jungle/screenshot.jpg)

Likewise, the deep jungles have platform villages hidden in the canopies of trees - hard to spot while walking through the dense foliage, best located at night when the light from their torches may be seen. These isolated tribes have no marketplaces either.

Expand All @@ -32,7 +32,7 @@ If there's been economic activity in the King's Market, ledgers recording some o

## API

The various types of settlements are defined via an API for registering settlement type definitions. See default_settlements.lua for the various existing examples.
The various types of settlements are defined via an API for registering settlement type definitions. See the included mods for the various existing examples.

## Credits

Expand Down
3 changes: 0 additions & 3 deletions mod.conf

This file was deleted.

2 changes: 2 additions & 0 deletions modpack.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = settlements
description = the settlements API and a collection of default settlement types
File renamed without changes.
4 changes: 2 additions & 2 deletions admin_commands.lua → settlements/admin_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ minetest.register_chatcommand("settlements_rename_nearest", {

if min_id ~= nil then
if param == "" then
local def = settlements.settlement_defs[min_data.settlement_type]
local def = settlements.registered_settlements[min_data.settlement_type]
if not def then
minetest.chat_send_player(name, S("Missing settlement definition for @1", min_data.settlement_type))
return
Expand Down Expand Up @@ -129,7 +129,7 @@ minetest.register_chatcommand("settlements_regenerate_names", {
minetest.chat_send_player(name, S("A non-empty settlement type parameter is required"))
return
end
local settlement_def = settlements.settlement_defs[param]
local settlement_def = settlements.registered_settlements[param]
if not settlement_def then
minetest.chat_send_player(name, S("Unrecognized settlement type"))
return
Expand Down
8 changes: 4 additions & 4 deletions admin_tools.lua → settlements/admin_tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ minetest.register_craftitem("settlements:settlement_tool", {

local center_surface = pointed_thing.under
if center_surface then
local minp = vector.subtract(center_surface, half_map_chunk_size)
local maxp = vector.add(center_surface, half_map_chunk_size)
if settlements.generate_settlement(vector.subtract(minp,16), vector.add(maxp,16)) then -- add borders to simulate mapgen borders
local minp = vector.subtract(center_surface, half_map_chunk_size+16) -- add 16 node border to simulate extended mapgen border
local maxp = vector.add(center_surface, half_map_chunk_size+16)
if settlements.generate_settlement(minp, maxp) then
minetest.chat_send_player(player_name, S("Created new settlement at @1", minetest.pos_to_string(center_surface)))
else
minetest.chat_send_player(player_name, S("Unable to create new settlement at @1", minetest.pos_to_string(center_surface)))
Expand All @@ -38,7 +38,7 @@ local all_schematics
local function get_next_debug_building()
if not all_schematics then
all_schematics = {}
for _, settlement_def in pairs(settlements.settlement_defs) do
for _, settlement_def in pairs(settlements.registered_settlements) do
for _, building_info in ipairs(settlement_def.schematics) do
table.insert(all_schematics, building_info)
end
Expand Down
60 changes: 60 additions & 0 deletions bookgen.lua → settlements/bookgen.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if not (minetest.settings:get_bool("settlements_generate_books", true) and modpath_default) then
return
end

-- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua")
Expand Down Expand Up @@ -29,6 +33,62 @@ local generate_book = function(title, owner, text)
return book
end

----------------------------------------------------------------------------------------------------------------

local half_map_chunk_size = settlements.half_map_chunk_size

minetest.register_abm({
label = "Settlement book authoring",
nodenames = {"default:bookshelf"},
interval = 86400, -- daily
-- Operation interval in seconds
chance = 2,
-- Chance of triggering `action` per-node per-interval is 1.0 / this value
catch_up = true,
-- If true, catch-up behaviour is enabled: The `chance` value is
-- temporarily reduced when returning to an area to simulate time lost
-- by the area being unattended. Note that the `chance` value can often
-- be reduced to 1.

action = function(pos, node, active_object_count, active_object_count_wider)
local inv = minetest.get_inventory( {type="node", pos=pos} )

-- Can we fit a book?
if not inv or not inv:room_for_item("books", "default:book_written") then
return
end

-- find any settlements within the shelf's mapchunk
-- There's probably only ever going to be one, but might as well do a closeness check to be on the safe side.
local min_edge = vector.subtract(pos, half_map_chunk_size)
local max_edge = vector.add(pos, half_map_chunk_size)
local settlement_list = settlements.settlements_in_world:get_areas_in_area(min_edge, max_edge, true, true, true)
local closest_settlement
for id, settlement in pairs(settlement_list) do
local target_pos = settlement.min
if not closest_settlement or vector.distance(pos, target_pos) < vector.distance(pos, closest_settlement.pos) then
closest_settlement = {pos = target_pos, data = settlement.data}
end
end

if not closest_settlement then
return
end

-- Get the settlement def and, if it generate books, generate one
local data = minetest.deserialize(closest_settlement.data)
local town_name = data.name
local town_type = data.settlement_type
local town_def = settlements.registered_settlements[town_type]
if town_def and town_def.generate_book then
local book = town_def.generate_book(closest_settlement.pos, town_name)
if book then
inv:add_item("books", book)
end
end
end,
})

---------------------------------------------------------------------------
-- Commoditymarket ledgers

Expand Down
26 changes: 10 additions & 16 deletions buildings.lua → settlements/buildings.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
local wallmaterial = settlements.wallmaterial
local half_map_chunk_size = settlements.half_map_chunk_size
local schematic_table = settlements.schematic_table

local c_air = minetest.get_content_id("air")

local default_path_material = "default:gravel"
local default_deep_platform = "default:stone"
local default_shallow_platform = "default:dirt"

local surface_mats = settlements.surface_materials

-- function to fill empty space below baseplate when building on a hill
local function ground(pos, data, va, c_shallow, c_deep) -- role model: Wendelsteinkircherl, Brannenburg
local p2 = vector.new(pos)
Expand Down Expand Up @@ -105,8 +99,8 @@ local buildable_to = function(c_node)
end
end

-- TODO: some way to discriminate between settlement_defs? For now, apply ignore_materials universally.
for _, def in pairs(settlements.settlement_defs) do
-- TODO: some way to discriminate between registered_settlements? For now, apply ignore_materials universally.
for _, def in pairs(settlements.registered_settlements) do
if def.ignore_surface_materials then
for _, ignore_material in ipairs(def.ignore_surface_materials) do
buildable_to_set[minetest.get_content_id(ignore_material)] = true
Expand Down Expand Up @@ -261,11 +255,11 @@ end
--------------------------------------------------------------------------------
local function create_site_plan(minp, maxp, data, va, existing_settlement_name)
-- find center of chunk
local center = {
x=maxp.x-half_map_chunk_size,
local center = vector.floor({
x=maxp.x-(maxp.x - minp.x)/2,
y=maxp.y,
z=maxp.z-half_map_chunk_size
}
z=maxp.z-(maxp.z - minp.z)/2,
})
-- find center_surface of chunk
local center_surface_pos, surface_material = find_surface(center, data, va)
if not center_surface_pos then
Expand All @@ -274,21 +268,21 @@ local function create_site_plan(minp, maxp, data, va, existing_settlement_name)

-- get a list of all the settlement defs that can be made on this surface mat
local material_defs = surface_mats[surface_material]
local settlement_defs = {}
local registered_settlements = {}
-- cull out any that have altitude min/max set outside the range of the chunk
for _, def in ipairs(material_defs) do
if (not def.altitude_min or def.altitude_min < maxp.y) and
(not def.altitude_max or def.altitude_max > minp.y) then
table.insert(settlement_defs, def)
table.insert(registered_settlements, def)
end
end
-- Nothing to pick from
if #settlement_defs == 0 then
if #registered_settlements == 0 then
return nil
end

-- pick one at random
local settlement_def = settlement_defs[math.random(1, #settlement_defs)]
local settlement_def = registered_settlements[math.random(1, #registered_settlements)]

-- Get a name for the settlement.
local name = existing_settlement_name or settlement_def.generate_name(center)
Expand Down
1 change: 1 addition & 0 deletions hud.lua → settlements/hud.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
if not minetest.settings:get_bool("settlements_show_in_hud", true) then
settlements.remove_all_hud_markers = function() end
return
end

Expand Down
9 changes: 4 additions & 5 deletions init.lua → settlements/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ settlements = {}
settlements.half_map_chunk_size = tonumber(minetest.get_mapgen_setting("chunksize")) * 16 / 2

settlements.surface_materials = {}
settlements.settlement_defs = {}
settlements.registered_settlements = {}

-- Minimum distance between settlements
settlements.min_dist_settlements = tonumber(minetest.settings:get("settlements_minimum_distance_between_settlements")) or 500
Expand All @@ -15,13 +15,14 @@ local modpath = minetest.get_modpath(minetest.get_current_modname())
dofile(modpath.."/persistence.lua")
dofile(modpath.."/buildings.lua")
dofile(modpath.."/hud.lua")
dofile(modpath.."/bookgen.lua")
dofile(modpath.."/admin_commands.lua")
dofile(modpath.."/admin_tools.lua")

settlements.register_settlement = function(settlement_type_name, settlement_def)
assert(not settlements.settlement_defs[settlement_type_name])
assert(not settlements.registered_settlements[settlement_type_name])
settlement_def.name = settlement_type_name
settlements.settlement_defs[settlement_type_name] = settlement_def
settlements.registered_settlements[settlement_type_name] = settlement_def
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 {}
Expand All @@ -39,8 +40,6 @@ function settlements.convert_mts_to_lua(schem_path)
file:close()
end

dofile(modpath.."/settlements_default.lua")

-------------------------------------------------------------------------------
-- check distance to other settlements
-------------------------------------------------------------------------------
Expand Down
File renamed without changes.
Loading

0 comments on commit 8f9c848

Please sign in to comment.