add old bones to the underworld

This commit is contained in:
FaceDeer 2019-08-07 01:12:12 -06:00
parent 1db8158509
commit 534de2ffe1
18 changed files with 277 additions and 9 deletions

3
bones_loot/depends.txt Normal file
View File

@ -0,0 +1,3 @@
bones
dungeon_loot?
intllib?

82
bones_loot/init.lua Normal file
View File

@ -0,0 +1,82 @@
-- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua")
bones_loot = {}
local dungeon_loot_path = minetest.get_modpath("dungeon_loot")
if dungeon_loot_path then
local shuffle = function(tbl)
for i = #tbl, 2, -1 do
local rand = math.random(i)
tbl[i], tbl[rand] = tbl[rand], tbl[i]
end
return tbl
end
bones_loot.get_loot = function(pos, loot_type, max_stacks)
local item_list = {}
local pos_y = pos.y
for _, loot in ipairs(dungeon_loot.registered_loot) do
if loot.y == nil or (pos_y >= loot.y[1] and pos_y <= loot.y[2]) then
if loot.types == nil or table.indexof(loot.types, loot_type) ~= -1 then
table.insert(item_list, loot)
end
end
end
shuffle(item_list)
-- apply chances / randomized amounts and collect resulting items
local items = {}
for _, loot in ipairs(item_list) do
if math.random() <= loot.chance then
local itemdef = minetest.registered_items[loot.name]
local amount = 1
if loot.count ~= nil then
amount = math.random(loot.count[1], loot.count[2])
end
if itemdef.tool_capabilities then
for n = 1, amount do
local wear = math.random(0.20 * 65535, 0.75 * 65535) -- 20% to 75% wear
table.insert(items, ItemStack({name = loot.name, wear = wear}))
max_stacks = max_stacks - 1
if max_stacks <= 0 then break end
end
else
local stack_max = itemdef.stack_max
while amount > 0 do
table.insert(items, ItemStack({name = loot.name, count = math.min(stack_max, amount)}))
amount = amount - stack_max
max_stacks = max_stacks - 1
if max_stacks <= 0 then break end
end
end
end
if max_stacks <= 0 then break end
end
return items
end
end
bones_loot.place_bones = function(pos, loot_type, max_stacks, infotext)
minetest.set_node(pos, {name="bones:bones", param2 = math.random(1,4)-1})
local meta = minetest.get_meta(pos)
if infotext == nil then
infotext = S("Someone's old bones")
end
meta:set_string("infotext", infotext)
if bones_loot.get_loot and loot_type and max_stacks then
local loot = bones_loot.get_loot(pos, loot_type, max_stacks)
local inv = meta:get_inventory()
inv:set_size("main", 8 * 4)
for _, item in ipairs(loot) do
inv:add_item("main", item)
end
end
end

45
bones_loot/intllib.lua Normal file
View File

@ -0,0 +1,45 @@
-- Fallback functions for when `intllib` is not installed.
-- Code released under Unlicense <http://unlicense.org>.
-- Get the latest version of this file at:
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
local function format(str, ...)
local args = { ... }
local function repl(escape, open, num, close)
if escape == "" then
local replacement = tostring(args[tonumber(num)])
if open == "" then
replacement = replacement..close
end
return replacement
else
return "@"..open..num..close
end
end
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
end
local gettext, ngettext
if minetest.get_modpath("intllib") then
if intllib.make_gettext_pair then
-- New method using gettext.
gettext, ngettext = intllib.make_gettext_pair()
else
-- Old method using text files.
gettext = intllib.Getter()
end
end
-- Fill in missing functions.
gettext = gettext or function(msgid, ...)
return format(msgid, ...)
end
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
return format(n==1 and msgid or msgid_plural, ...)
end
return gettext, ngettext

View File

@ -0,0 +1,22 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-08-07 00:58-0600\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: bones_loot\init.lua:65
msgid "Someone's old bones"
msgstr ""

View File

@ -0,0 +1,6 @@
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
cd ..
set LIST=
for /r %%X in (*.lua) do set LIST=!LIST! %%X
..\..\intllib\tools\xgettext.bat %LIST%

4
bones_loot/mod.conf Normal file
View File

@ -0,0 +1,4 @@
name = bones_loot
description = An API that allows bones to be placed procedurally with randomly generated loot
depends = bones
optional_depends = dungeon_loot, intllib

View File

@ -6,4 +6,5 @@ df_mapitems
ice_sprites?
oil?
df_underworld_items?
magma_conduits?
magma_conduits?
bones_loot?

View File

@ -0,0 +1,44 @@
if not minetest.get_modpath("dungeon_loot") then
return
end
if df_caverns.config.enable_underworld then
dungeon_loot.register({
{name = "df_underworld_items:glow_amethyst", chance = 0.3, count = {1, 12}, y = {-32768, df_caverns.config.lava_sea_level}},
})
end
if df_caverns.config.enable_oil_sea and minetest.get_modpath("bucket") then
dungeon_loot.register({
{name = "oil:oil_bucket", chance = 0.5, count = {1, 3}, y = {-32768, df_caverns.config.ymax}},
})
end
if df_caverns.config.enable_lava_sea then
dungeon_loot.register({
{name = "df_mapitems:mese_crystal", chance = 0.25, count = {1, 5}, y = {-32768, df_caverns.config.sunless_sea_min}},
{name = "df_mapitems:glow_mese", chance = 0.1, count = {1, 3}, y = {-32768, df_caverns.config.sunless_sea_min}},
})
end
dungeon_loot.register({
{name = "df_farming:cave_wheat_seed", chance = 0.5, count = {1, 10}, y = {-32768, df_caverns.config.ymax}},
{name = "df_farming:cave_bread", chance = 0.8, count = {1, 10}, y = {-32768, df_caverns.config.ymax}},
{name = "df_farming:pig_tail_thread", chance = 0.7, count = {1, 10}, y = {-32768, df_caverns.config.ymax}},
{name = "df_farming:plump_helmet_spawn", chance = 0.4, count = {1, 8}, y = {-32768, df_caverns.config.ymax}},
{name = "df_farming:plump_helmet_4_picked", chance = 0.8, count = {1, 15}, y = {-32768, df_caverns.config.ymax}},
{name = "df_trees:glowing_bottle_red", chance = 0.6, count = {1, 20}, y = {-32768, df_caverns.config.ymax}},
{name = "df_trees:glowing_bottle_green", chance = 0.5, count = {1, 20}, y = {-32768, df_caverns.config.ymax}},
{name = "df_trees:glowing_bottle_cyan", chance = 0.4, count = {1, 15}, y = {-32768, df_caverns.config.ymax}},
{name = "df_trees:glowing_bottle_golden", chance = 0.3, count = {1, 5}, y = {-32768, df_caverns.config.ymax}},
{name = "df_farming:pig_tail_seed", chance = 0.5, count = {1, 10}, y = {-32768, df_caverns.config.level1_min}},
{name = "df_mapitems:med_crystal", chance = 0.2, count = {1, 2}, y = {-32768, df_caverns.config.level1_min}},
{name = "df_farming:dimple_cup_seed", chance = 0.3, count = {1, 10}, y = {-32768, df_caverns.config.level2_min}},
{name = "df_farming:quarry_bush_seed", chance = 0.3, count = {1, 5}, y = {-32768, df_caverns.config.level2_min}},
{name = "df_farming:sweet_pod_seed", chance = 0.3, count = {1, 5}, y = {-32768, df_caverns.config.level2_min}},
{name = "df_mapitems:big_crystal", chance = 0.1, count = {1, 1}, y = {-32768, df_caverns.config.level2_min}},
{name = "df_trees:torchspine_ember", chance = 0.3, count = {1, 3}, y = {-32768, df_caverns.config.level2_min}},
{name = "ice_sprites:ice_sprite_bottle", chance = 0.1, count = {1, 1}, y = {-32768, df_caverns.config.level2_min}},
})

View File

@ -15,3 +15,4 @@ dofile(modpath.."/sunless_sea.lua")
dofile(modpath.."/oil_sea.lua")
dofile(modpath.."/lava_sea.lua")
dofile(modpath.."/underworld.lua")
dofile(modpath.."/dungeon_loot.lua")

View File

@ -1 +1,4 @@
name = df_caverns
name = df_caverns
description = Adds vast underground caverns in the style of Dwarf Fortress, complete with underground flora in diverse biomes. Also adds stalactite/stalagmite decorations in the smaller tunnels.
depends = default, subterrane, df_trees, df_mapitems
optional_depends = df_farming, ice_sprites, oil, df_underworld_items, magma_conduits, bones_loot

View File

@ -2,6 +2,8 @@ if not df_caverns.config.enable_underworld then
return
end
local bones_loot_path = minetest.get_modpath("bones_loot")
local c_slade = minetest.get_content_id("df_underworld_items:slade")
local c_air = minetest.get_content_id("air")
local c_water = minetest.get_content_id("default:water_source")
@ -386,6 +388,40 @@ minetest.register_on_generated(function(minp, maxp, seed)
--write it to world
vm:write_to_map()
if bones_loot_path then
for i = 1, 15 do
local x = math.random(minp.x, maxp.x)
local z = math.random(minp.z, maxp.z)
local index2d = mapgen_helper.index2d(emin, emax, x, z)
local abs_cave = math.abs(nvals_cave[index2d]) -- range is from 0 to approximately 2, with 0 being connected and 2s being islands
local wave = nvals_wave[index2d] * wave_mult
local floor_height = math.floor(abs_cave * floor_mult + median + floor_displace + wave)
local ceiling_height = math.floor(abs_cave * ceiling_mult + median + ceiling_displace + wave)
if floor_height < ceiling_height then
local zone = math.abs(nvals_zone[index2d])
if math.random() < zone then -- bones are more common in the built-up areas
local floor_node = minetest.get_node({x=x, y=floor_height, z=z})
local floor_node_def = minetest.registered_nodes[floor_node.name]
if floor_node_def and not floor_node_def.buildable_to then
local y = floor_height + 1
while y < ceiling_height do
local target_pos = {x=x, y=y, z=z}
local target_node = minetest.get_node(target_pos)
if target_node.name == "air" then
bones_loot.place_bones(target_pos, "normal", math.random(5, 15))
break
elseif target_node.name == "bones:bones" then
-- don't stack bones on bones, it looks silly
break
end
y = y + 1
end
end
end
end
end
end
local chunk_generation_time = math.ceil((os.clock() - t_start) * 1000) --grab how long it took
if chunk_generation_time < 1000 then
minetest.log("info", "[df_caverns] underworld mapblock generation took "..chunk_generation_time.." ms") --tell people how long

View File

@ -1 +1,4 @@
name = df_farming
name = df_farming
description = Adds farmable underground plants that die in sunlight. Also includes various cooking reactions.
depends = default
optional_depends = farming, cottages, bucket, dynamic_liquid, wool, intllib, doc, crafting

View File

@ -1 +1,4 @@
name = df_mapitems
name = df_mapitems
description = Various node types used by the dfcaverns mapgen mod. Includes cave coral, flowstone, glowing crystals, glow worms, moss and fungi ground cover, and snare weed.
depends = default, subterrane
optional_depends = df_farming, farming, intllib, doc, radiant_damage

View File

@ -1 +1,4 @@
name = df_trees
name = df_trees
description = Adds various types of underground fungal "trees". Light kills their saplings, they only grow in the dark.
depends = default
optional_depends = intllib, doc, moreblocks, stairs, vessels

View File

@ -1 +1,4 @@
name = df_underworld_items
name = df_underworld_items
description = Various node types used by the dfcaverns mapgen mod for its underworld layer.
depends = default, stairs
optional_depends = intllib, doc, radiant_damage, mesecons_mvps, tnt

View File

@ -1 +1,4 @@
name = ice_sprites
name = ice_sprites
description = Glowing blue firefly-like nodes
depends =
optional_depends = fireflies, vessels, doc, intllib

View File

@ -1 +1,4 @@
name = mine_gas
name = mine_gas
description = An explosive, asphyxiating heavier-than-air gas to add hazards to caves
depends = default
optional_depends = tnt, doc

View File

@ -1 +1,4 @@
name = oil
name = oil
description = Oil liquid type
depends = default
optional_depends = dynamic_liquid, bucket, doc, basic_materials