add new weather types and a function to unregister them

This commit is contained in:
theFox6 2020-04-13 07:32:04 +02:00
parent be14c21fa6
commit 4097350753
Signed by: theFox6
GPG Key ID: C884FE8D3BCE128A
11 changed files with 107 additions and 86 deletions

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<buildpath> <buildpath>
<buildpathentry excluding="development/" kind="src" path="weather"/>
</buildpath> </buildpath>

View File

@ -1,23 +0,0 @@
language: generic
sudo: false
addons:
apt:
packages:
- luarocks
before_install:
- luarocks install --local luacheck
env:
- CONFIG=.luacheckrc
- CONFIG=.luacheck_tidy
matrix:
exclude:
- name: "health check"
env: CONFIG=.luacheckrc
allow_failures:
- name: "beauty check"
env: CONFIG=.luacheck_tidy
script:
- $HOME/.luarocks/bin/luacheck --config $CONFIG .
notifications:
email:
on_failure: change

View File

@ -38,19 +38,21 @@ end
local default_downfall = { local default_downfall = {
--minimum starting position --minimum starting position
min_pos = {x=-9, y=10, z=-9}, min_pos = {x=-15, y=10, z=-15},
--maximum starting position --maximum starting position
max_pos = {x=9, y=10, z=9}, max_pos = {x=15, y=10, z=15},
--y falling speed --y falling speed
falling_speed = 10, falling_speed = 10,
--number of textures spawned --number of textures spawned
amount = 10, amount = 15,
--the texture size --the texture size
size = 25, size = 25,
--whether lightning schould be enabled --whether lightning schould be enabled
enable_lightning=false, enable_lightning=false,
--whether to damage the player --whether to damage the player
damage_player=false damage_player=false,
--how much wind is needed to trigger the weather
min_wind = 0,
} }
local default_damage = { local default_damage = {
@ -73,7 +75,7 @@ function weather_mod.register_downfall(id,def)
end end
set_defaults(ndef,default_downfall) set_defaults(ndef,default_downfall)
--when to delete the particles --when to delete the particles
if not ndef.exptime then if not ndef.exptime then
ndef.exptime = ndef.max_pos.y / (math.sqrt(ndef.falling_acceleration) + ndef.falling_speed) ndef.exptime = ndef.max_pos.y / (math.sqrt(ndef.falling_acceleration) + ndef.falling_speed)
end end
if ndef.damage_player then if ndef.damage_player then
@ -83,20 +85,23 @@ function weather_mod.register_downfall(id,def)
weather_mod.registered_downfalls[name]=ndef weather_mod.registered_downfalls[name]=ndef
end end
function weather_mod.unregister_downfall(id)
weather_mod.registered_downfalls[id] = nil
end
if minetest.get_modpath("lightning") then if minetest.get_modpath("lightning") then
--same as lightning.auto = false --same as lightning.auto = false
rawset(lightning,"auto",false) rawset(lightning,"auto",false)
end end
function weather_mod.handle_lightning() function weather_mod.handle_lightning(current_weather)
if not minetest.get_modpath("lightning") then return end if not minetest.get_modpath("lightning") then return end
local current_downfall = weather_mod.registered_downfalls[weather.type] if not current_weather then return end
if not current_downfall then return end rawset(lightning,"auto",current_weather.enable_lightning)
rawset(lightning,"auto",current_downfall.enable_lightning) if current_weather.enable_lightning and math.random(1,2) == 1 then
if current_downfall.enable_lightning and math.random(1,2) == 1 then local time = math.floor(math.random(lightning.interval_low/2,lightning.interval_low))
local time = math.floor(math.random(lightning.interval_low/2,lightning.interval_low)) minetest.after(time, lightning.strike)
minetest.after(time, lightning.strike) end
end
end end
local do_raycasts = minetest.is_yes(minetest.settings:get_bool('raycast_hitcheck')) local do_raycasts = minetest.is_yes(minetest.settings:get_bool('raycast_hitcheck'))
@ -132,52 +137,57 @@ local function handle_damage(damage,player, downfall_origin)
end end
minetest.register_globalstep(function() minetest.register_globalstep(function()
if weather.type=="none" then if math.random(1, 10000) == 1 then
for id,_ in pairs(weather_mod.registered_downfalls) do weather.type = "none"
if math.random(1, 50000) == 1 then if minetest.get_modpath("lightning") then
weather.wind = {} rawset(lightning,"auto",false)
weather.wind.x = math.random(0,10) end
weather.wind.y = 0 else
weather.wind.z = math.random(0,10) for id,w in pairs(weather_mod.registered_downfalls) do
weather.type = id if math.random(1, 50000) == 1 then
weather_mod.handle_lightning() weather.wind = {}
end weather.wind.x = math.random(0,10)
end weather.wind.y = 0
else weather.wind.z = math.random(0,10)
if math.random(1, 10000) == 1 then if vector.length(weather.wind) >= w.min_wind then
weather.type = "none" weather.type = id
if minetest.get_modpath("lightning") then weather_mod.handle_lightning(w)
rawset(lightning,"auto",false) break
end end
end end
end end
local current_downfall = weather_mod.registered_downfalls[weather.type] end
if current_downfall==nil then return end
for _, player in ipairs(minetest.get_connected_players()) do
local ppos = player:getpos()
if ppos.y > 120 then return end local current_downfall = weather_mod.registered_downfalls[weather.type]
if current_downfall==nil then return end
for _, player in ipairs(minetest.get_connected_players()) do
local ppos = player:getpos()
local wind_pos = vector.multiply(weather.wind,-1) if ppos.y > 120 then return end
local minp = vector.add(vector.add(ppos, current_downfall.min_pos),wind_pos) local wind_pos = vector.multiply(weather.wind,-1)
local maxp = vector.add(vector.add(ppos, current_downfall.max_pos),wind_pos)
local vel = {x=weather.wind.x,y=-current_downfall.falling_speed,z=weather.wind.z} local minp = vector.add(vector.add(ppos, current_downfall.min_pos),wind_pos)
local acc = {x=0, y=0, z=0} local maxp = vector.add(vector.add(ppos, current_downfall.max_pos),wind_pos)
local exp = current_downfall.exptime local vel = {x=weather.wind.x,y=-current_downfall.falling_speed,z=weather.wind.z}
local acc = {x=0, y=0, z=0}
minetest.add_particlespawner({amount=current_downfall.amount, time=0.5, local exp = current_downfall.exptime
minpos=minp, maxpos=maxp,
minvel=vel, maxvel=vel, minetest.add_particlespawner({
minacc=acc, maxacc=acc, amount=current_downfall.amount, time=0.5,
minexptime=exp, maxexptime=exp, minpos=minp, maxpos=maxp,
minsize=current_downfall.size, maxsize=current_downfall.size, minvel=vel, maxvel=vel,
collisiondetection=true, collision_removal=true, minacc=acc, maxacc=acc,
vertical=true, minexptime=exp, maxexptime=exp,
texture=current_downfall.texture, player=player:get_player_name()}) minsize=current_downfall.size, maxsize=current_downfall.size,
local downfall_origin = vector.divide(vector.add(minp,maxp),2) collisiondetection=true, collision_removal=true,
handle_damage(current_downfall.damage_player,player,downfall_origin) vertical=true,
end texture=current_downfall.texture, player=player:get_player_name()
})
local downfall_origin = vector.divide(vector.add(minp,maxp),2)
handle_damage(current_downfall.damage_player,player,downfall_origin)
end
end) end)

View File

@ -3,7 +3,7 @@
-- * snow -- * snow
-- * wind -- * wind
assert(minetest.add_particlespawner, "You have some really old minetest...") assert(minetest.add_particlespawner, "Weather doesn't work with this really old minetest.")
weather_mod={ weather_mod={
modpath=minetest.get_modpath("weather"), modpath=minetest.get_modpath("weather"),
@ -32,6 +32,7 @@ end) ()
dofile(weather_mod.modpath.."/api.lua") dofile(weather_mod.modpath.."/api.lua")
dofile(weather_mod.modpath.."/rain.lua") dofile(weather_mod.modpath.."/rain.lua")
dofile(weather_mod.modpath.."/sand.lua")
dofile(weather_mod.modpath.."/snow.lua") dofile(weather_mod.modpath.."/snow.lua")
dofile(weather_mod.modpath.."/command.lua") dofile(weather_mod.modpath.."/command.lua")

View File

@ -1,7 +1,7 @@
-- Rain -- Rain
weather_mod.register_downfall("weather:rain",{ weather_mod.register_downfall("weather:rain",{
min_pos = {x=-9, y=7, z=-9}, min_pos = {x=-15, y=7, z=-15},
max_pos = {x= 9, y=7, z= 9}, max_pos = {x= 15, y=7, z= 15},
falling_speed=10, falling_speed=10,
amount=25, amount=25,
exptime=0.8, exptime=0.8,
@ -9,3 +9,14 @@ weather_mod.register_downfall("weather:rain",{
texture="weather_rain.png", texture="weather_rain.png",
enable_lightning=true, enable_lightning=true,
}) })
weather_mod.register_downfall("weather:storm",{
min_pos = {x = -15, y = 7, z = -15},
max_pos = {x = 15, y = 7, z = 15},
falling_speed = 10,
amount = 30,
exptime = 0.8,
size = 30,
texture = "weather_rain_dark.png",
enable_lightning = true,
})

10
weather/sand.lua Normal file
View File

@ -0,0 +1,10 @@
weather_mod.register_downfall("weather:sandstorm",{
min_pos = {x=-20, y=0, z=-20},
max_pos = {x= 20, y=2, z= 20},
falling_speed=-1,
amount=20,
exptime=1,
size=25,
texture="weather_sand.png",
min_wind = 5,
})

BIN
weather/screenshot.5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 KiB

View File

@ -1,12 +1,23 @@
-- Snow -- Snow
weather_mod.register_downfall("weather:snow",{ weather_mod.register_downfall("weather:snow",{
min_pos = {x=-9, y=7, z=-9}, min_pos = {x=-15, y=7, z=-15},
max_pos = {x= 9, y=7, z= 9}, max_pos = {x= 15, y=7, z= 15},
falling_speed=5, falling_speed=5,
amount=10, amount=15,
exptime=5, exptime=5,
size=25, size=25,
texture="weather_snow.png" texture="weather_snow.png",
})
weather_mod.register_downfall("weather:hail",{
min_pos = {x=-15, y=7, z=-15},
max_pos = {x= 15, y=7, z= 15},
falling_speed=25,
amount=15,
exptime=0.8,
size=25,
texture="weather_hail.png",
enable_lightning = true,
}) })
local snow_box = local snow_box =

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB