Implement ABM wrapper, allow environment checks for general positions

This commit is contained in:
Till Affeldt 2020-04-16 19:12:20 +02:00
parent 7f8f1a77f2
commit f41d5f259c
6 changed files with 65 additions and 26 deletions

View File

@ -5,10 +5,7 @@
- Make sure all weather presets are working - Make sure all weather presets are working
## Required for Beta ## Required for Beta
- Implement fallback for sky changes without skylayer
- Ability to register environment conditions dynamically (like the heat) - Ability to register environment conditions dynamically (like the heat)
- Implement ABM system for additional effects
- Implement snow layers, puddles, soil hydration, fire extinguishing
## Planned for first release ## Planned for first release
- Improve test_condition function - Improve test_condition function
@ -20,7 +17,6 @@
## Nice to have ## Nice to have
- Write documentation on how to add weathers and effects - Write documentation on how to add weathers and effects
- Register *Moon Phases* as a weather preset using the *skybox* effect
- Assign meta data (like "downfall", "wind", etc.) to weather presets - Assign meta data (like "downfall", "wind", etc.) to weather presets
- Fog effects - Fog effects
- Optimize performance by replacing some particles with animated texture planes - Optimize performance by replacing some particles with animated texture planes

View File

@ -1,4 +1,4 @@
if not climate_mod.settings.sound then return end if not climate_mod.settings.hud_overlay then return end
local EFFECT_NAME = "climate_api:hud_overlay" local EFFECT_NAME = "climate_api:hud_overlay"

View File

@ -6,13 +6,13 @@ climate_mod = {}
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
local function getBoolSetting(name, default) local function get_setting_bool(name, default)
local value = minetest.settings:get_bool("climate_api_" .. name) local value = minetest.settings:get_bool("climate_api_" .. name)
if type(value) == "nil" then value = default end if type(value) == "nil" then value = default end
return minetest.is_yes(value) return minetest.is_yes(value)
end end
local function getNumericSetting(name, default) local function get_setting_number(name, default)
local value = minetest.settings:get("climate_api_" .. name) local value = minetest.settings:get("climate_api_" .. name)
if type(value) == "nil" then value = default end if type(value) == "nil" then value = default end
return tonumber(value) return tonumber(value)
@ -20,16 +20,17 @@ end
-- load settings from config file -- load settings from config file
climate_mod.settings = { climate_mod.settings = {
particles = getBoolSetting("particles", true), particles = get_setting_bool("particles", true),
skybox = getBoolSetting("skybox", true), skybox = get_setting_bool("skybox", true),
sound = getBoolSetting("sound", true), sound = get_setting_bool("sound", true),
wind = getBoolSetting("wind", true), hud_overlay = get_setting_bool("hud_overlay", true),
seasons = getBoolSetting("seasons", true), wind = get_setting_bool("wind", true),
fahrenheit = getBoolSetting("fahrenheit", false), seasons = get_setting_bool("seasons", true),
heat = getNumericSetting("heat_base", 0), fahrenheit = get_setting_bool("fahrenheit", false),
humidity = getNumericSetting("humidity_base", 0), heat = get_setting_number("heat_base", 0),
time_spread = getNumericSetting("time_spread", 1), humidity = get_setting_number("humidity_base", 0),
particle_count = getNumericSetting("particle_count", 1) time_spread = get_setting_number("time_spread", 1),
particle_count = get_setting_number("particle_count", 1)
} }
-- initiate empty registers -- initiate empty registers

View File

@ -37,4 +37,41 @@ end
climate_mod.influences[name] = func climate_mod.influences[name] = func
end]] end]]
function api.register_abm(config)
local conditions = config.conditions
local action = config.action
local pos_override = config.pos_override
local override = function(pos, node)
local env = climate_mod.trigger.get_position_environment(pos)
if type(pos_override) == "function" then
pos = pos_override(pos)
end
if conditions == nil then
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
end
return action(pos, node, env)
end
config.conditions = nil
config.action = override
minetest.register_abm(config)
end
return api return api

View File

@ -1,21 +1,26 @@
local trigger = {} local trigger = {}
function trigger.get_player_environment(player) function trigger.get_position_environment(pos)
local ppos = player:get_pos()
local wind_x = climate_mod.state:get_float("wind_x") local wind_x = climate_mod.state:get_float("wind_x")
local wind_z = climate_mod.state:get_float("wind_z") local wind_z = climate_mod.state:get_float("wind_z")
local env = {} local env = {}
env.player = player env.pos = pos
env.pos = ppos env.height = pos.y
env.height = ppos.y
env.wind = vector.new(wind_x, 0, wind_z) env.wind = vector.new(wind_x, 0, wind_z)
env.windspeed = vector.length(env.wind) env.windspeed = vector.length(env.wind)
env.heat = climate_api.environment.get_heat(ppos) env.heat = climate_api.environment.get_heat(pos)
env.humidity = climate_api.environment.get_humidity(ppos) env.humidity = climate_api.environment.get_humidity(pos)
env.time = minetest.get_timeofday() env.time = minetest.get_timeofday()
env.date = minetest.get_day_count() env.date = minetest.get_day_count()
env.light = minetest.get_node_light(vector.add(ppos, vector.new({x=0,y=1.5,z=0})), 0.5) env.light = minetest.get_node_light(vector.add(pos, vector.new({x=0,y=1,z=0})), 0.5)
return env
end
function trigger.get_player_environment(player)
local ppos = player:get_pos()
local env = trigger.get_position_environment(ppos)
env.player = player
return env return env
end end

View File

@ -1,7 +1,7 @@
climate_api_particles (Show particle effects) bool true climate_api_particles (Show particle effects) bool true
climate_api_skybox (Allow weather effects to modify the skybox) bool true climate_api_skybox (Allow weather effects to modify the skybox) bool true
climate_api_sound (Allow weather presets to play ambient sounds) bool true climate_api_sound (Allow weather presets to play ambient sounds) bool true
climate_api_clouds (Override clouds to represent current humidity) bool true climate_api_hud_overlay (Allow weather presets to display a HUD overlay) bool true
climate_api_wind (Allow wind to angle rainfall) bool true 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_seasons (Change global temperature based on an annual cycle) bool true
climate_api_heat_base (Global base temperature) float 0 climate_api_heat_base (Global base temperature) float 0