mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-22 15:23:43 +01:00
Merge pull request #30 from obl3pplifp/gravelsieve_tweaks
Further gravelsieve distribution tweaks
This commit is contained in:
commit
4fa5c24813
@ -44,7 +44,16 @@ gravelsieve = {
|
||||
|
||||
dofile(minetest.get_modpath("gravelsieve") .. "/hammer.lua")
|
||||
|
||||
gravelsieve.ore_rarity = tonumber(minetest.setting_get("gravelsieve_ore_rarity")) or 1
|
||||
local settings_get
|
||||
if minetest.setting_get then
|
||||
settings_get = minetest.setting_get
|
||||
else
|
||||
settings_get = function(...) endminetest.settings:get(...) end
|
||||
end
|
||||
gravelsieve.ore_rarity = tonumber(settings_get("gravelsieve_ore_rarity")) or 1.16
|
||||
gravelsieve.ore_max_elevation = tonumber(settings_get("gravelsieve_ore_max_elevation")) or 0
|
||||
gravelsieve.ore_min_elevation = tonumber(settings_get("gravelsieve_ore_min_elevation")) or -30912
|
||||
local y_spread = math.max(1 + gravelsieve.ore_max_elevation - gravelsieve.ore_min_elevation, 1)
|
||||
|
||||
-- Increase the probability over the natural occurrence
|
||||
local PROBABILITY_FACTOR = 3
|
||||
@ -71,6 +80,17 @@ if minetest.get_modpath("pipeworks") and pipeworks ~= nil then
|
||||
pipeworks_after_place = pipeworks.after_place
|
||||
end
|
||||
|
||||
local function harmonic_sum(a, b)
|
||||
return 1 / ((1 / a) + (1 / b))
|
||||
end
|
||||
|
||||
local function calculate_probability(item)
|
||||
local ymax = math.min(item.y_max, gravelsieve.ore_max_elevation)
|
||||
local ymin = math.max(item.y_min, gravelsieve.ore_min_elevation)
|
||||
return (gravelsieve.ore_rarity / PROBABILITY_FACTOR) *
|
||||
item.clust_scarcity / (item.clust_num_ores * ((ymax - ymin) / y_spread))
|
||||
end
|
||||
|
||||
-- collect all registered ores and calculate the probability
|
||||
local function add_ores()
|
||||
for _,item in pairs(minetest.registered_ores) do
|
||||
@ -84,24 +104,24 @@ local function add_ores()
|
||||
and item.clust_scarcity ~= nil and item.clust_scarcity > 0
|
||||
and item.clust_num_ores ~= nil and item.clust_num_ores > 0
|
||||
and item.y_max ~= nil and item.y_min ~= nil then
|
||||
local probability = (gravelsieve.ore_rarity / PROBABILITY_FACTOR) * item.clust_scarcity /
|
||||
(item.clust_num_ores * ((item.y_max - item.y_min) / 65535))
|
||||
if gravelsieve.ore_probability[drop] == nil then
|
||||
gravelsieve.ore_probability[drop] = probability
|
||||
local probability = calculate_probability(item)
|
||||
if probability > 0 then
|
||||
local cur_probability = gravelsieve.ore_probability[drop]
|
||||
if cur_probability then
|
||||
gravelsieve.ore_probability[drop] = harmonic_sum(cur_probability, probability)
|
||||
else
|
||||
-- harmonic sum
|
||||
gravelsieve.ore_probability[drop] = 1.0 / ((1.0 / gravelsieve.ore_probability[drop]) +
|
||||
(1.0 / probability))
|
||||
gravelsieve.ore_probability[drop] = probability
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local overall_probability = 0.0
|
||||
for name,probability in pairs(gravelsieve.ore_probability) do
|
||||
minetest.log("info", string.format("[gravelsieve] %-32s %u", name, probability))
|
||||
minetest.log("info", ("[gravelsieve] %-32s %.02f"):format(name, probability))
|
||||
overall_probability = overall_probability + 1.0/probability
|
||||
end
|
||||
minetest.log("info", string.format("[gravelsieve] Overall probability %g", overall_probability))
|
||||
minetest.log("info", ("[gravelsieve] Overall probability %f"):format(overall_probability))
|
||||
end
|
||||
|
||||
minetest.after(1, add_ores)
|
||||
|
@ -1 +1,4 @@
|
||||
name=gravelsieve
|
||||
description=This mod includes a hammer to produce gravel from Cobblestone and a sieve to sift gravel to find ores.
|
||||
depends=default
|
||||
optional_depends=moreblocks,tubelib,hopper,pipeworks
|
||||
|
@ -2,4 +2,6 @@
|
||||
# 1.0 is according to the mapgen generator
|
||||
# 2.0 means half as many ores as result
|
||||
# 0.5 means twice as many ores as result
|
||||
gravelsieve_ore_rarity (Rarity factor to find ores) float 1.5
|
||||
gravelsieve_ore_rarity (Rarity factor to find ores) float 1.16
|
||||
gravelsieve_ore_max_elevation (Maximum elevation considered when calculating ore distribution) int 0 -30912 30927
|
||||
gravelsieve_ore_min_elevation (Minimum elevation considered when calculating ore distribution) int -30912 -30912 30927
|
||||
|
Loading…
Reference in New Issue
Block a user