Add influence registry, make sounds fade, add skybox feature detection

This commit is contained in:
Till Affeldt
2020-04-18 08:01:36 +02:00
parent f41d5f259c
commit 18045b1943
10 changed files with 83 additions and 52 deletions

View File

@ -33,9 +33,9 @@ function api.set_effect_cycle(name, cycle)
climate_mod.cycles[name].timespan = cycle
end
--[[function api.register_influence(name, func)
function api.register_influence(name, func)
climate_mod.influences[name] = func
end]]
end
function api.register_abm(config)
local conditions = config.conditions
@ -52,19 +52,9 @@ function api.register_abm(config)
return action(pos, node, env)
end
minetest.log(dump2(env, "env"))
minetest.log(dump2(conditions, "conditions"))
for condition, goal in pairs(conditions) do
local value = env[condition:sub(5)]
if condition:sub(1, 4) == "min_" then
if type(value) == "nil" or goal > value then return end
elseif condition:sub(1, 4) == "max_" then
if type(value) == "nil" or goal <= value then return end
else
value = env[condition]
if type(value) == "nil" or goal ~= value then return end
end
local is_applicable = climate_mod.trigger.test_condition(condition, env, goal)
if not is_applicable then return end
end
return action(pos, node, env)
end

View File

@ -31,13 +31,6 @@ function environment.get_humidity(pos)
local biome = minetest.get_humidity(pos)
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

View File

@ -1,30 +1,43 @@
climate_api.register_influence("heat", function(player)
return climate_mod.get_heat(player:get_pos())
climate_api.register_influence("heat", function(pos)
return climate_api.environment.get_heat(pos)
end)
climate_api.register_influence("humidity", function(player)
return climate_mod.get_humidity(player:get_pos())
climate_api.register_influence("humidity", function(pos)
return climate_api.environment.get_humidity(pos)
end)
climate_api.register_influence("windspeed", function(player)
climate_api.register_influence("biome", function(pos)
local data = minetest.get_biome_data(pos)
local biome = minetest.get_biome_name(data.biome)
return biome
end)
climate_api.register_influence("windspeed", function(_)
local wind_x = climate_mod.state:get_float("wind_x")
local wind_z = climate_mod.state:get_float("wind_z")
return vector.length({x = wind_x, y = 0, z = wind_z})
end)
climate_api.register_influence("wind_x", function(player)
climate_api.register_influence("wind_x", function(_)
return climate_mod.state:get_float("wind_x")
end)
climate_api.register_influence("wind_z", function(player)
climate_api.register_influence("wind_z", function(_)
return climate_mod.state:get_float("wind_z")
end)
climate_api.register_influence("height", function(player)
local ppos = player:get_pos()
return ppos.y
climate_api.register_influence("height", function(pos)
return pos.y
end)
climate_api.register_influence("light", function(player)
return minetest.env:get_node_light(player:get_pos(), 0.5)
climate_api.register_influence("light", function(pos)
return minetest.env:get_node_light(pos)
end)
climate_api.register_influence("daylight", function(pos)
return minetest.env:get_node_light(pos, 0.5)
end)
climate_api.register_influence("time", function(_)
return minetest.get_timeofday()
end)

View File

@ -1,5 +1,5 @@
local GSCYCLE = 0.03
local WORLD_CYCLE = 2
local GSCYCLE = 0.03 * climate_mod.settings.tick_speed
local WORLD_CYCLE = 2 * climate_mod.settings.tick_speed
local gs_timer = 0
local world_timer = 0
@ -20,7 +20,8 @@ minetest.register_globalstep(function(dtime)
local current_effects = climate_mod.trigger.get_active_effects()
for name, effect in pairs(climate_mod.effects) do
if climate_mod.cycles[name].timespan < climate_mod.cycles[name].timer + dtime then
local cycle = climate_mod.cycles[name].timespan * climate_mod.settings.tick_speed
if cycle < climate_mod.cycles[name].timer + dtime then
climate_mod.cycles[name].timer = 0
climate_mod.current_effects[name] = current_effects[name]
climate_mod.trigger.call_handlers(name, current_effects[name], previous_effects[name])

View File

@ -4,7 +4,7 @@ function trigger.get_position_environment(pos)
local wind_x = climate_mod.state:get_float("wind_x")
local wind_z = climate_mod.state:get_float("wind_z")
local env = {}
--[[local env = {}
env.pos = pos
env.height = pos.y
env.wind = vector.new(wind_x, 0, wind_z)
@ -13,7 +13,11 @@ function trigger.get_position_environment(pos)
env.humidity = climate_api.environment.get_humidity(pos)
env.time = minetest.get_timeofday()
env.date = minetest.get_day_count()
env.light = minetest.get_node_light(vector.add(pos, vector.new({x=0,y=1,z=0})), 0.5)
env.light = minetest.get_node_light(vector.add(pos, vector.new({x=0,y=1,z=0})), 0.5)]]
local env = {}
for influence, func in pairs(climate_mod.influences) do
env[influence] = func(pos)
end
return env
end
@ -24,15 +28,21 @@ function trigger.get_player_environment(player)
return env
end
local function test_condition(condition, env, goal)
function trigger.test_condition(condition, env, goal)
local value = env[condition:sub(5)]
if condition:sub(1, 4) == "min_" then
return type(value) ~= "nil" and goal <= value
elseif condition:sub(1, 4) == "max_" then
return type(value) ~= "nil" and goal > value
else
Minetest.log("warning", "[Climate API] Invalid effect condition")
elseif condition:sub(1, 4) == "has_" then
if type(value) == "nil" then return false end
for _, g in ipairs(goal) do
if value == g then return true end
end
return false
else
value = env[condition]
return type(value) ~= "nil" and goal == value
end
end
@ -45,7 +55,7 @@ local function is_weather_active(player, weather, env)
return config.conditions(env)
end
for condition, goal in pairs(config.conditions) do
if not test_condition(condition, env, goal) then
if not trigger.test_condition(condition, env, goal) then
return false
end
end