12 Commits

12 changed files with 74 additions and 57 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.code-workspace

View File

@ -25,27 +25,35 @@ end
-- load settings from config file -- load settings from config file
climate_mod.settings = { climate_mod.settings = {
damage = get_setting_bool("damage", true), damage = get_setting_bool("damage", true),
raycast = get_setting_bool("raycast", true), raycast = get_setting_bool("raycast", true),
particles = get_setting_bool("particles", true), particles = get_setting_bool("particles", true),
skybox = get_setting_bool("skybox", true), skybox = get_setting_bool("skybox", true),
sound = get_setting_bool("sound", true), sound = get_setting_bool("sound", true),
hud_overlay = get_setting_bool("hud_overlay", true), hud_overlay = get_setting_bool("hud_overlay", true),
wind = get_setting_bool("wind", true), wind = get_setting_bool("wind", true),
seasons = get_setting_bool("seasons", true), seasons = get_setting_bool("seasons", true),
fahrenheit = get_setting_bool("fahrenheit", false), fahrenheit = get_setting_bool("fahrenheit", false),
block_updates = get_setting_bool("block_updates", true), block_updates = get_setting_bool("block_updates", true),
heat = get_setting_number("heat_base", 0), heat = get_setting_number("heat_base", 0),
humidity = get_setting_number("humidity_base", 0), humidity = get_setting_number("humidity_base", 0),
time_spread = get_setting_number("time_spread", 1), time_spread = get_setting_number("time_spread", 1),
particle_count = get_setting_number("particle_count", 1), particle_count = get_setting_number("particle_count", 1),
tick_speed = get_setting_number("tick_speed", 1), tick_speed = get_setting_number("tick_speed", 1),
volume = get_setting_number("volume", 1), volume = get_setting_number("volume", 1),
ceiling_checks = get_setting_number("ceiling_checks", 10), ceiling_checks = get_setting_number("ceiling_checks", 10)
} }
climate_mod.i18n = minetest.get_translator("climate_api") climate_mod.i18n = minetest.get_translator("climate_api")
-- warn about clouds being overriden by MTG weather
if climate_mod.settings.skybox and minetest.get_modpath("weather") and minetest.settings:get_bool("enable_weather") then
minetest.log("warning", "[Regional Weather] " ..
climate_mod.i18n("Disable MTG weather for the best experience. Check the forum for more information."))
-- try to disable MTG weather. may or may not work depending on load order
minetest.settings:set_bool("enable_weather", false)
end
-- initialize empty registers -- initialize empty registers
climate_mod.weathers = {} climate_mod.weathers = {}
climate_mod.effects = {} climate_mod.effects = {}

View File

@ -230,3 +230,17 @@ minetest.register_chatcommand("weather_influences", {
end end
end end
}) })
-- used to debug downfall
minetest.register_chatcommand("explain_humidity", {
description = "Explains how the humidity value got calculated",
func = function(playername)
local base = climate_mod.settings.humidity
local biome = minetest.get_humidity((minetest.get_player_by_name(playername)):get_pos())
local random = climate_mod.state:get_float("humidity_random");
local random_base = climate_mod.state:get_float("humidity_base");
minetest.chat_send_player(playername, dump2(base, "base"))
minetest.chat_send_player(playername, dump2(biome, "biome"))
minetest.chat_send_player(playername, dump2(random, "random"))
end
})

View File

@ -9,7 +9,7 @@ function environment.get_heat(pos)
local height = climate_api.utility.rangelim((-pos.y + 10) / 15, -10, 10) local height = climate_api.utility.rangelim((-pos.y + 10) / 15, -10, 10)
local time = climate_api.utility.normalized_cycle(minetest.get_timeofday()) * 0.6 + 0.7 local time = climate_api.utility.normalized_cycle(minetest.get_timeofday()) * 0.6 + 0.7
local random = climate_mod.state:get_float("heat_random"); local random = climate_mod.state:get_float("heat_random");
return (base + biome + height) * time * random return base + ((biome + height) * time * random)
end end
function environment.get_humidity(pos) function environment.get_humidity(pos)
@ -19,8 +19,7 @@ function environment.get_humidity(pos)
local base = climate_mod.settings.humidity local base = climate_mod.settings.humidity
local biome = minetest.get_humidity(pos) local biome = minetest.get_humidity(pos)
local random = climate_mod.state:get_float("humidity_random"); local random = climate_mod.state:get_float("humidity_random");
local random_base = climate_mod.state:get_float("humidity_base"); return base + ((biome * 0.7 + 40 * 0.3) * random)
return (base + biome * 0.7 + random_base * 0.3) * random
end end
function environment.get_wind(pos) function environment.get_wind(pos)

View File

@ -10,7 +10,7 @@ climate_api.register_influence("humidity",
climate_api.environment.get_humidity climate_api.environment.get_humidity
) )
climate_api.register_influence("base_humidity", climate_api.register_influence("biome_humidity",
minetest.get_humidity minetest.get_humidity
) )

View File

@ -1,9 +1,12 @@
local GSCYCLE = 0.03 * climate_mod.settings.tick_speed -- only process event loop after this amount of time local GSCYCLE = 0.06 * climate_mod.settings.tick_speed -- only process event loop after this amount of time
local WORLD_CYCLE = 30.00 * climate_mod.settings.tick_speed -- only update global environment influences after this amount of time local WORLD_CYCLE = 30.00 * climate_mod.settings.tick_speed -- only update global environment influences after this amount of time
local gs_timer = 0 local gs_timer = 0
local world_timer = 0 local world_timer = 0
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
local player_list = minetest.get_connected_players()
if #player_list == 0 then return end
gs_timer = gs_timer + dtime gs_timer = gs_timer + dtime
world_timer = world_timer + dtime world_timer = world_timer + dtime
@ -26,7 +29,7 @@ minetest.register_globalstep(function(dtime)
end end
end end
local current_effects = climate_mod.trigger.get_active_effects() local current_effects = climate_mod.trigger.get_active_effects(player_list)
for name, effect in pairs(climate_mod.effects) do for name, effect in pairs(climate_mod.effects) do
local cycle = climate_mod.cycles[name].timespan * climate_mod.settings.tick_speed local cycle = climate_mod.cycles[name].timespan * climate_mod.settings.tick_speed

View File

@ -1,3 +1,5 @@
local mod_lighting_monoid = minetest.get_modpath("lighting_monoid") ~= nil
local default_sky = { local default_sky = {
sky_data = { sky_data = {
base_color = nil, base_color = nil,
@ -74,11 +76,15 @@ local function set_skybox(playername, sky)
player:set_moon(sky.moon_data) player:set_moon(sky.moon_data)
player:set_sun(sky.sun_data) player:set_sun(sky.sun_data)
player:set_stars(sky.star_data) player:set_stars(sky.star_data)
if player.set_lighting then local lighting = {
player:set_lighting({ shadows = { intensity = sky.light_data.shadow_intensity },
shadows = { intensity = sky.light_data.shadow_intensity }, saturation = sky.light_data.saturation
saturation = sky.light_data.saturation }
}) if mod_lighting_monoid then
lighting_monoid:add_change(player, lighting, "climate_api:merged_lighting")
lighting_monoid.del_change(player, "lighting_monoid:base_shadow")
elseif player.set_lighting then
player:set_lighting(lighting)
end end
end end

View File

@ -9,7 +9,7 @@ function trigger.get_global_environment()
end end
function trigger.get_position_environment(pos) function trigger.get_position_environment(pos)
local env = table.copy(climate_mod.global_environment) local env = trigger.get_global_environment()
for influence, func in pairs(climate_mod.influences) do for influence, func in pairs(climate_mod.influences) do
env[influence] = func(pos) env[influence] = func(pos)
end end
@ -83,20 +83,18 @@ local function get_weather_effects(player, weather_config, env)
return effects return effects
end end
function trigger.get_active_effects() function trigger.get_active_effects(players)
local environments = {} local environments = {}
local effects = {} local effects = {}
climate_mod.current_weather = {} climate_mod.current_weather = {}
for _, player in ipairs(minetest.get_connected_players()) do for _, player in ipairs(players) do
local pname = player:get_player_name() local pname = player:get_player_name()
local hp = player:get_hp() local hp = player:get_hp()
-- skip weather presets for dead players -- skip weather presets for dead players
if hp ~= nil and hp > 0 then if hp ~= nil and hp > 0 then
environments[pname] = trigger.get_player_environment(player) local env = trigger.get_player_environment(player)
end environments[pname] = env
local env = environments[pname]
if env ~= nil then
for wname, wconfig in pairs(climate_mod.weathers) do for wname, wconfig in pairs(climate_mod.weathers) do
if is_weather_active(player, wname, env) then if is_weather_active(player, wname, env) then
if climate_mod.current_weather[pname] == nil then if climate_mod.current_weather[pname] == nil then

View File

@ -6,9 +6,8 @@ local WIND_SCALE = 2
local HEAT_SPREAD = 400 local HEAT_SPREAD = 400
local HEAT_SCALE = 0.3 local HEAT_SCALE = 0.3
local HUMIDITY_SPREAD = 150 local HUMIDITY_SPREAD = 150
local HUMIDITY_SCALE = 0.5 local HUMIDITY_SCALE = 1
local HUMIDITY_BASE_SPREAD = 800 local HUMIDITY_TIMESCALE = 1
local HUMIDITY_BASE_SCALE = 40
local nobj_wind_x local nobj_wind_x
local nobj_wind_z local nobj_wind_z
@ -47,23 +46,14 @@ local pn_heat = {
} }
local pn_humidity = { local pn_humidity = {
offset = 0, offset = 1,
scale = HUMIDITY_SCALE, scale = HUMIDITY_SCALE,
spread = {x = HUMIDITY_SPREAD, y = HUMIDITY_SPREAD, z = HUMIDITY_SPREAD}, spread = {x = HUMIDITY_SPREAD, y = HUMIDITY_SPREAD, z = HUMIDITY_SPREAD},
seed = 8374061, seed = 8374061,
octaves = 2, octaves = 2,
persist = 0.5, persist = 0.5,
lacunarity = 2 lacunarity = 2,
} flags = "noeased"
local pn_humidity_base = {
offset = 50,
scale = HUMIDITY_BASE_SCALE,
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) local function update_wind(timer)
@ -83,11 +73,8 @@ end
local function update_humidity(timer) local function update_humidity(timer)
nobj_humidity = nobj_humidity or minetest.get_perlin(pn_humidity) nobj_humidity = nobj_humidity or minetest.get_perlin(pn_humidity)
local n_humidity = nobj_humidity:get_2d({x = timer, y = 0}) local n_humidity = nobj_humidity:get_2d({x = timer * HUMIDITY_TIMESCALE, y = 0})
climate_mod.state:set_float("humidity_random", n_humidity) 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 end
function world.update_status(timer) function world.update_status(timer)

View File

@ -1,4 +1,5 @@
# textdomain:climate_api # textdomain:climate_api
Disable MTG weather for the best experience. Check the forum for more information.=Deaktiviere MTG weather für die beste Spielerfahrung. Mehr Informationen im Forum.
Make changes to the current weather=Ändere das aktuelle Wetter Make changes to the current weather=Ändere das aktuelle Wetter
Display weather information=Betrachte Informationen zum Wetter Display weather information=Betrachte Informationen zum Wetter
The following weather presets are active for you:=Die folgenden Wetterklassen sind gerade aktiv The following weather presets are active for you:=Die folgenden Wetterklassen sind gerade aktiv

View File

@ -1,4 +1,5 @@
# textdomain:climate_api # textdomain:climate_api
Disable MTG weather for the best experience=
Make changes to the current weather= Make changes to the current weather=
Display weather information= Display weather information=
The following weather presets are active for you:= The following weather presets are active for you:=

View File

@ -1,8 +1,7 @@
name = climate_api name = climate_api
title = Climate API title = Climate API
author = TestificateMods author = TestificateMods
release = 10001 optional_depends = player_monoids, playerphysics, pova, lighting_monoid
optional_depends = player_monoids, playerphysics, pova
description = """ description = """
A powerful engine for weather presets and visual effects. A powerful engine for weather presets and visual effects.
Use the regional climate to set up different effects for different regions. Use the regional climate to set up different effects for different regions.