2019-04-30 23:45:28 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019 Joachim Stolberg
|
|
|
|
|
2020-10-19 20:09:17 +03:00
|
|
|
AGPL v3
|
2019-04-30 23:45:28 +03:00
|
|
|
See LICENSE.txt for more information
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2019-04-30 23:45:28 +03:00
|
|
|
Gravel Sieve basis functions
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2019-04-30 23:45:28 +03:00
|
|
|
]]--
|
|
|
|
|
|
|
|
-- Increase the probability over the natural occurrence
|
|
|
|
local PROBABILITY_FACTOR = 2
|
|
|
|
|
|
|
|
-- Ore probability table (1/n)
|
|
|
|
local ore_probability = {
|
|
|
|
}
|
|
|
|
|
2019-05-03 23:30:06 +03:00
|
|
|
local ProbabilityCorrections = {
|
2020-06-29 20:09:12 +03:00
|
|
|
["default:tin_lump"] = 0.3, -- extensively used
|
|
|
|
["default:coal_lump"] = 0.2, -- extensively used
|
2020-05-01 15:43:08 +03:00
|
|
|
["default:iron_lump"] = 0.5, -- extensively used
|
2019-05-03 23:30:06 +03:00
|
|
|
["techage:baborium_lump"] = 99999, -- mining required
|
|
|
|
}
|
|
|
|
|
2019-04-30 23:45:28 +03:00
|
|
|
-- collect all registered ores and calculate the probability
|
|
|
|
local function add_ores()
|
|
|
|
for _,item in pairs(minetest.registered_ores) do
|
2023-04-16 16:07:29 +03:00
|
|
|
if not ore_probability[item.ore] and minetest.registered_nodes[item.ore] then
|
2019-04-30 23:45:28 +03:00
|
|
|
local drop = minetest.registered_nodes[item.ore].drop
|
|
|
|
if type(drop) == "string"
|
|
|
|
and drop ~= item.ore
|
|
|
|
and drop ~= ""
|
|
|
|
and item.ore_type == "scatter"
|
|
|
|
and item.wherein == "default:stone"
|
2022-01-03 23:40:31 +03:00
|
|
|
and item.clust_scarcity ~= nil and item.clust_scarcity > 0
|
|
|
|
and item.clust_num_ores ~= nil and item.clust_num_ores > 0
|
2019-04-30 23:45:28 +03:00
|
|
|
and item.y_max ~= nil and item.y_min ~= nil then
|
2020-06-29 20:09:12 +03:00
|
|
|
local factor = 0.5
|
2022-01-03 23:40:31 +03:00
|
|
|
if item.y_max < -250 then
|
|
|
|
factor = -250 / item.y_max
|
2019-04-30 23:45:28 +03:00
|
|
|
end
|
2020-06-29 20:09:12 +03:00
|
|
|
local probability = (techage.ore_rarity / PROBABILITY_FACTOR) * item.clust_scarcity /
|
|
|
|
(item.clust_num_ores * factor)
|
|
|
|
-- lower value means higher probability
|
|
|
|
ore_probability[drop] = math.min(ore_probability[drop] or 100000, probability)
|
2019-04-30 23:45:28 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-05-03 23:30:06 +03:00
|
|
|
-- some corrections
|
|
|
|
for key, correction in pairs(ProbabilityCorrections) do
|
|
|
|
if ore_probability[key] then
|
|
|
|
ore_probability[key] = ore_probability[key] * correction
|
2020-06-29 20:09:12 +03:00
|
|
|
-- consider upper and lower level
|
|
|
|
ore_probability[key] = techage.in_range(ore_probability[key], 10, 100000)
|
2019-05-03 23:30:06 +03:00
|
|
|
end
|
|
|
|
end
|
2019-04-30 23:45:28 +03:00
|
|
|
local overall_probability = 0.0
|
|
|
|
for name,probability in pairs(ore_probability) do
|
|
|
|
minetest.log("info", string.format("[techage] %-32s %u", name, probability))
|
|
|
|
overall_probability = overall_probability + 1.0/probability
|
|
|
|
end
|
|
|
|
minetest.log("info", string.format("[techage] Overall probability %g", overall_probability))
|
2022-01-03 23:40:31 +03:00
|
|
|
end
|
2019-04-30 23:45:28 +03:00
|
|
|
|
2023-04-16 16:07:29 +03:00
|
|
|
minetest.register_on_mods_loaded(add_ores)
|
2019-04-30 23:45:28 +03:00
|
|
|
|
2023-04-16 16:07:29 +03:00
|
|
|
--
|
|
|
|
-- Change the probability of ores or register new ores for sieving
|
|
|
|
--
|
|
|
|
function techage.register_ore_for_gravelsieve(ore_name, probability)
|
|
|
|
ore_probability[ore_name] = probability
|
|
|
|
end
|
2019-04-30 23:45:28 +03:00
|
|
|
|
|
|
|
-- determine ore based on the calculated probability
|
|
|
|
function techage.gravelsieve_get_random_gravel_ore()
|
|
|
|
for ore, probability in pairs(ore_probability) do
|
|
|
|
if math.random(probability) == 1 then
|
|
|
|
return ItemStack(ore)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if math.random(2) == 1 then
|
|
|
|
return ItemStack("default:gravel")
|
|
|
|
else
|
|
|
|
return ItemStack("techage:sieved_gravel")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function techage.gravelsieve_get_random_basalt_ore()
|
|
|
|
if math.random(40) == 1 then
|
|
|
|
return ItemStack("default:coal_lump")
|
|
|
|
elseif math.random(40) == 1 then
|
|
|
|
return ItemStack("default:iron_lump")
|
|
|
|
elseif math.random(2) == 1 then
|
|
|
|
return ItemStack("techage:basalt_gravel")
|
|
|
|
else
|
|
|
|
return ItemStack("techage:sieved_basalt_gravel")
|
|
|
|
end
|
2022-01-04 21:40:27 +03:00
|
|
|
end
|