Fix bugs, tweak weather configs, fix noise generator

This commit is contained in:
Till Affeldt 2020-04-13 13:40:05 +02:00
parent 49242573f2
commit 47530bb07e
9 changed files with 77 additions and 61 deletions

View File

@ -9,12 +9,13 @@ end
local function spawn_particles(player, particles)
local ppos = player:getpos()
local wind_x = climate_mod.state:get_int("wind_x")
local wind_z = climate_mod.state:get_int("wind_z")
local wind_x = climate_mod.state:get_float("wind_x")
local wind_z = climate_mod.state:get_float("wind_z")
local wind = vector.new(wind_x, 0, wind_z)
local wind_pos = vector.multiply(wind, -1)
local wind_speed = vector.length(wind)
local amount = particles.amount * climate_mod.settings.particle_count
local texture = get_particle_texture(particles)
local minp = vector.add(vector.add(ppos, particles.min_pos), wind_pos)
@ -31,7 +32,7 @@ local function spawn_particles(player, particles)
local vertical = math.abs(vector.normalize(vel).y) >= 0.6
minetest.add_particlespawner({
amount = particles.amount,
amount = amount,
time = 0.5,
minpos = minp,
maxpos = maxp,
@ -53,7 +54,6 @@ end
local function handle_effect(player_data)
for playername, data in pairs(player_data) do
minetest.chat_send_player(playername, "spam")
local player = minetest.get_player_by_name(playername)
for weather, value in pairs(data) do
spawn_particles(player, value)

View File

@ -22,7 +22,9 @@ climate_mod.settings = {
wind = getBoolSetting("wind", true),
seasons = getBoolSetting("seasons", true),
heat = getNumericSetting("heat_base", 0),
humidity = getNumericSetting("humidity_base", 0)
humidity = getNumericSetting("humidity_base", 0),
time_spread = getNumericSetting("time_spread", 1),
particle_count = getNumericSetting("particle_count", 1)
}
climate_mod.current_weather = {}

View File

@ -1,8 +1,8 @@
local api = {}
api.SHORT_CYCLE = 0 -- for particles and fast animations
api.DEFAULT_CYCLE = 0 -- for most effect types
api.LONG_CYCLE = 0 -- for write operations and skybox changes
api.SHORT_CYCLE = 0.03 -- for particles and fast animations
api.DEFAULT_CYCLE = 0.1 -- for most effect types
api.LONG_CYCLE = 0.5 -- for write operations and skybox changes
climate_mod.weathers = {}
climate_mod.effects = {}

View File

@ -14,7 +14,7 @@ function utility.merge_tables(a, b)
if type(a) == "table" and type(b) == "table" then
for k,v in pairs(b) do
if type(v)=="table" and type(a[k] or false)=="table" then
merge(a[k],v)
utility.merge_tables(a[k],v)
else a[k]=v end
end
end

View File

@ -2,18 +2,18 @@ local environment = {}
local function get_heat_time()
local time = minetest.get_timeofday()
return climate_api.utility.normalized_cycle(time) * 0.4 + 0.3
return climate_api.utility.normalized_cycle(time) * 0.6 + 0.7
end
local function get_heat_calendar()
-- European heat center in August instead of June
local day = climate_mod.state:get("time_current_day")
local progression = ((day + 61) % 365) / 365
return climate_api.utility.normalized_cycle(progression) * 0.4 + 0.3
local day = minetest.get_day_count()
local progression = (day + 61) / 365
return climate_api.utility.normalized_cycle(progression) * 0.6 + 0.7
end
local function get_heat_height(y)
return climate_api.utility.rangelim(-y / 15, -10, 10)
return climate_api.utility.rangelim((-y + 10) / 15, -10, 10)
end
function environment.get_heat(pos)
@ -22,15 +22,23 @@ function environment.get_heat(pos)
local height = get_heat_height(pos.y)
local time = get_heat_time()
local date = get_heat_calendar()
local random = climate_mod.state:get_int("heat_random");
return (base + biome + height) * time * date
local random = climate_mod.state:get_float("heat_random");
return (base + biome + height) * time * date * random
end
function environment.get_humidity(pos)
local base = climate_mod.settings.humidity
local biome = minetest.get_humidity(pos)
local random = climate_mod.state:get_int("humidity_random");
return (base + biome)
local random = climate_mod.state:get_float("humidity_random");
local random_base = climate_mod.state:get_float("humidity_base");
--[[for _, player in ipairs(minetest.get_connected_players()) do
local pname = player:get_player_name()
minetest.chat_send_player(pname, dump2(biome, "biome"))
minetest.chat_send_player(pname, dump2(random_base, "random_base"))
minetest.chat_send_player(pname, dump2(random, "random"))
minetest.chat_send_player(pname, dump2((base + biome * 0.7 + random_base * 0.3) * random, "total"))
end]]
return (base + biome * 0.7 + random_base * 0.3) * random
end
return environment

View File

@ -1,5 +1,5 @@
local GSCYCLE = 0
local WORLD_CYCLE = 0
local GSCYCLE = 0.01
local WORLD_CYCLE = 0.5
local gs_timer = 0
local world_timer = 0

View File

@ -1,28 +1,26 @@
local trigger = {}
local function get_player_environment(player)
function trigger.get_player_environment(player)
local ppos = player:get_pos()
local wind_x = climate_mod.state:get_int("wind_x")
local wind_z = climate_mod.state:get_int("wind_z")
local wind_x = climate_mod.state:get_float("wind_x")
local wind_z = climate_mod.state:get_float("wind_z")
local env = {}
env.player = player
env.pos = pos
env.pos = ppos
env.height = ppos.y
env.wind = vector.new(wind_x, 0, wind_z)
env.windspeed = vector.length(env.wind)
env.heat = climate_api.environment.get_heat(ppos)
env.humidity = climate_api.environment.get_humidity(ppos)
env.time = minetest.get_timeofday()
env.date = climate_mod.state:get_int("time_current_day")
env.date = minetest.get_day_count()
return env
end
local function test_condition(condition, env, goal)
local value = env[condition:sub(5)]
if condition:sub(1, 4) == "min_" then
for _, player in ipairs(minetest.get_connected_players()) do
minetest.chat_send_player(player:get_player_name(), dump2(value, goal))
end
return type(value) ~= "nil" and goal <= value
elseif condition:sub(1, 4) == "max_" then
return type(value) ~= "nil" and goal > value
@ -54,7 +52,7 @@ end
function trigger.get_active_effects()
local environments = {}
for _, player in ipairs(minetest.get_connected_players()) do
environments[player:get_player_name()] = get_player_environment(player)
environments[player:get_player_name()] = trigger.get_player_environment(player)
end
local effects = {}

View File

@ -1,20 +1,23 @@
local world = {}
local WIND_SPREAD = 600
local WIND_SCALE = 3
local HEAT_SPREAD = 2400
local HEAT_SCALE = 0.2
local HUMIDITY_SPREAD = 1200
local HUMIDITY_SCALE = 0.18
local WIND_SCALE = 2
local HEAT_SPREAD = 200
local HEAT_SCALE = 0.3
local HUMIDITY_SPREAD = 60
local HUMIDITY_SCALE = 0.5
local HUMIDITY_BASE_SPREAD = 600
local HUMIDITY_BASE_SCALE = 40
local nobj_wind_x
local nobj_wind_z
local nobj_heat
local nobj_humidity
local nobj_humidity_base
local pn_wind_speed_x = {
offset = 0,
scale = WIND_SCALE,
scale = WIND_SCALE * climate_mod.settings.time_spread,
spread = {x = WIND_SPREAD, y = WIND_SPREAD, z = WIND_SPREAD},
seed = 31441,
octaves = 2,
@ -24,7 +27,7 @@ local pn_wind_speed_x = {
local pn_wind_speed_z = {
offset = 0,
scale = WIND_SCALE,
scale = WIND_SCALE * climate_mod.settings.time_spread,
spread = {x = WIND_SPREAD, y = WIND_SPREAD, z = WIND_SPREAD},
seed = 938402,
octaves = 2,
@ -33,8 +36,8 @@ local pn_wind_speed_z = {
}
local pn_heat = {
offset = 0,
scale = HEAT_SCALE,
offset = 1,
scale = HEAT_SCALE * climate_mod.settings.time_spread,
spread = {x = HEAT_SPREAD, y = HEAT_SPREAD, z = HEAT_SPREAD},
seed = 24,
octaves = 2,
@ -43,8 +46,8 @@ local pn_heat = {
}
local pn_humidity = {
offset = 0,
scale = HUMIDITY_SCALE,
offset = 1,
scale = HUMIDITY_SCALE * climate_mod.settings.time_spread,
spread = {x = HUMIDITY_SPREAD, y = HUMIDITY_SPREAD, z = HUMIDITY_SPREAD},
seed = 8374061,
octaves = 3,
@ -52,38 +55,41 @@ local pn_humidity = {
lacunarity = 2
}
local pn_humidity_base = {
offset = 50,
scale = HUMIDITY_BASE_SCALE * climate_mod.settings.time_spread,
spread = {x = HUMIDITY_BASE_SPREAD, y = HUMIDITY_BASE_SPREAD, z = HUMIDITY_BASE_SPREAD},
seed = 3803465,
octaves = 2,
persist = 0.5,
lacunarity = 2
}
local function update_wind(timer)
nobj_wind_x = nobj_wind_x or minetest.get_perlin(pn_wind_speed_x)
nobj_wind_z = nobj_wind_z or minetest.get_perlin(pn_wind_speed_z)
local n_wind_x = nobj_wind_x:get_2d({x = timer, y = 0})
local n_wind_z = nobj_wind_z:get_2d({x = timer, y = 0})
climate_mod.state:set_int("wind_x", n_wind_x)
climate_mod.state:set_int("wind_z", n_wind_z)
climate_mod.state:set_float("wind_x", n_wind_x)
climate_mod.state:set_float("wind_z", n_wind_z)
end
local function update_heat(timer)
nobj_heat = nobj_heat or minetest.get_perlin(pn_heat)
local n_heat = nobj_heat:get_2d({x = timer, y = 0})
climate_mod.state:set_int("heat_random", n_heat)
climate_mod.state:set_float("heat_random", n_heat)
end
local function update_humidity(timer)
nobj_humidity = nobj_humidity or minetest.get_perlin(pn_humidity)
local n_humidity = nobj_humidity:get_2d({x = timer, y = 0})
climate_mod.state:set_int("humidity_random", n_humidity)
end
local function update_date()
local time = minetest.get_timeofday()
if time < climate_mod.state:get_int("time_last_check") then
local day = climate_mod.state:get_int("time_current_day")
climate_mod.state:set_int("time_current_day ", day + 1)
end
climate_mod.state:set_int("time_last_check", time)
climate_mod.state:set_float("humidity_random", n_humidity)
nobj_humidity_base = nobj_humidity_base or minetest.get_perlin(pn_humidity_base)
local n_humidity_base = nobj_humidity_base:get_2d({x = timer, y = 0})
climate_mod.state:set_float("humidity_base", n_humidity_base)
end
function world.update_status(timer)
update_date()
update_wind(timer)
update_heat(timer)
update_humidity(timer)

View File

@ -6,3 +6,5 @@ climate_api_wind (Allow wind to angle rainfall) bool true
climate_api_seasons (Change global temperature based on an annual cycle) bool true
climate_api_heat_base (Global base temperature) float 0
climate_api_humidity_base (Global base humidity) float 0
climate_api_time_spread (Regulates how quickly the weather changes) float 1 0.1 10
climate_api_particle_count (Multiplicator for used particles) float 1 0.1 2