From 534de2ffe119eab1b5ab02f9eab6c71e70901020 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Wed, 7 Aug 2019 01:12:12 -0600 Subject: [PATCH] add old bones to the underworld --- bones_loot/depends.txt | 3 ++ bones_loot/init.lua | 82 ++++++++++++++++++++++++++++++++++ bones_loot/intllib.lua | 45 +++++++++++++++++++ bones_loot/locale/template.pot | 22 +++++++++ bones_loot/locale/update.bat | 6 +++ bones_loot/mod.conf | 4 ++ df_caverns/depends.txt | 3 +- df_caverns/dungeon_loot.lua | 44 ++++++++++++++++++ df_caverns/init.lua | 1 + df_caverns/mod.conf | 5 ++- df_caverns/underworld.lua | 36 +++++++++++++++ df_farming/mod.conf | 5 ++- df_mapitems/mod.conf | 5 ++- df_trees/mod.conf | 5 ++- df_underworld_items/mod.conf | 5 ++- ice_sprites/mod.conf | 5 ++- mine_gas/mod.conf | 5 ++- oil/mod.conf | 5 ++- 18 files changed, 277 insertions(+), 9 deletions(-) create mode 100644 bones_loot/depends.txt create mode 100644 bones_loot/init.lua create mode 100644 bones_loot/intllib.lua create mode 100644 bones_loot/locale/template.pot create mode 100644 bones_loot/locale/update.bat create mode 100644 bones_loot/mod.conf create mode 100644 df_caverns/dungeon_loot.lua diff --git a/bones_loot/depends.txt b/bones_loot/depends.txt new file mode 100644 index 0000000..ef795e4 --- /dev/null +++ b/bones_loot/depends.txt @@ -0,0 +1,3 @@ +bones +dungeon_loot? +intllib? \ No newline at end of file diff --git a/bones_loot/init.lua b/bones_loot/init.lua new file mode 100644 index 0000000..8f75e7e --- /dev/null +++ b/bones_loot/init.lua @@ -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 + diff --git a/bones_loot/intllib.lua b/bones_loot/intllib.lua new file mode 100644 index 0000000..6669d72 --- /dev/null +++ b/bones_loot/intllib.lua @@ -0,0 +1,45 @@ + +-- Fallback functions for when `intllib` is not installed. +-- Code released under Unlicense . + +-- 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 diff --git a/bones_loot/locale/template.pot b/bones_loot/locale/template.pot new file mode 100644 index 0000000..376e93f --- /dev/null +++ b/bones_loot/locale/template.pot @@ -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 , 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 \n" +"Language-Team: LANGUAGE \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 "" diff --git a/bones_loot/locale/update.bat b/bones_loot/locale/update.bat new file mode 100644 index 0000000..48b25ab --- /dev/null +++ b/bones_loot/locale/update.bat @@ -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% \ No newline at end of file diff --git a/bones_loot/mod.conf b/bones_loot/mod.conf new file mode 100644 index 0000000..a5497d0 --- /dev/null +++ b/bones_loot/mod.conf @@ -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 \ No newline at end of file diff --git a/df_caverns/depends.txt b/df_caverns/depends.txt index be228ff..575eaae 100644 --- a/df_caverns/depends.txt +++ b/df_caverns/depends.txt @@ -6,4 +6,5 @@ df_mapitems ice_sprites? oil? df_underworld_items? -magma_conduits? \ No newline at end of file +magma_conduits? +bones_loot? \ No newline at end of file diff --git a/df_caverns/dungeon_loot.lua b/df_caverns/dungeon_loot.lua new file mode 100644 index 0000000..02ed0e4 --- /dev/null +++ b/df_caverns/dungeon_loot.lua @@ -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}}, +}) diff --git a/df_caverns/init.lua b/df_caverns/init.lua index f369ac4..06b68d7 100644 --- a/df_caverns/init.lua +++ b/df_caverns/init.lua @@ -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") \ No newline at end of file diff --git a/df_caverns/mod.conf b/df_caverns/mod.conf index 97c933a..40b0992 100644 --- a/df_caverns/mod.conf +++ b/df_caverns/mod.conf @@ -1 +1,4 @@ -name = df_caverns \ No newline at end of file +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 \ No newline at end of file diff --git a/df_caverns/underworld.lua b/df_caverns/underworld.lua index 7a39b39..e24d3f9 100644 --- a/df_caverns/underworld.lua +++ b/df_caverns/underworld.lua @@ -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 diff --git a/df_farming/mod.conf b/df_farming/mod.conf index 1c25a9a..b489d96 100644 --- a/df_farming/mod.conf +++ b/df_farming/mod.conf @@ -1 +1,4 @@ -name = df_farming \ No newline at end of file +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 diff --git a/df_mapitems/mod.conf b/df_mapitems/mod.conf index 20d5019..d18cf0e 100644 --- a/df_mapitems/mod.conf +++ b/df_mapitems/mod.conf @@ -1 +1,4 @@ -name = df_mapitems \ No newline at end of file +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 \ No newline at end of file diff --git a/df_trees/mod.conf b/df_trees/mod.conf index fb96131..902b5ef 100644 --- a/df_trees/mod.conf +++ b/df_trees/mod.conf @@ -1 +1,4 @@ -name = df_trees \ No newline at end of file +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 \ No newline at end of file diff --git a/df_underworld_items/mod.conf b/df_underworld_items/mod.conf index be3dd5e..1a841d5 100644 --- a/df_underworld_items/mod.conf +++ b/df_underworld_items/mod.conf @@ -1 +1,4 @@ -name = df_underworld_items \ No newline at end of file +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 diff --git a/ice_sprites/mod.conf b/ice_sprites/mod.conf index a7a79f2..b4adb34 100644 --- a/ice_sprites/mod.conf +++ b/ice_sprites/mod.conf @@ -1 +1,4 @@ -name = ice_sprites \ No newline at end of file +name = ice_sprites +description = Glowing blue firefly-like nodes +depends = +optional_depends = fireflies, vessels, doc, intllib \ No newline at end of file diff --git a/mine_gas/mod.conf b/mine_gas/mod.conf index 444e665..df1730e 100644 --- a/mine_gas/mod.conf +++ b/mine_gas/mod.conf @@ -1 +1,4 @@ -name = mine_gas \ No newline at end of file +name = mine_gas +description = An explosive, asphyxiating heavier-than-air gas to add hazards to caves +depends = default +optional_depends = tnt, doc \ No newline at end of file diff --git a/oil/mod.conf b/oil/mod.conf index 457cbcb..e262a4e 100644 --- a/oil/mod.conf +++ b/oil/mod.conf @@ -1 +1,4 @@ -name = oil \ No newline at end of file +name = oil +description = Oil liquid type +depends = default +optional_depends = dynamic_liquid, bucket, doc, basic_materials \ No newline at end of file