diff --git a/README.txt b/README.txt index d027f74..8463a1f 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,11 @@ snowdrift 0.5.0 by paramat -For Minetest 0.4.12 and later +For Minetest 0.4.15 and later Depends default -Licenses: Source code MIT. Media (textures) CC BY-SA (3.0) + +Licenses: +Source code: +MIT by paramat +Media: +Textures CC BY-SA (3.0) by paramat +Sounds CC BY (3.0) by inchadney +http://freesound.org/people/inchadney/sounds/58835/ diff --git a/init.lua b/init.lua index 19a439c..aa10cd3 100644 --- a/init.lua +++ b/init.lua @@ -1,10 +1,10 @@ -- Parameters -local PRECSPR = 11 -- Time scale for precipitation variation in minutes -local PRECOFF = 0.8 -- Precipitation noise threshold offset -local PROCHA = 0.2 -- Per player per globalstep processing chance -local FLAKES = 8 -- Snowflake density -local DROPS = 16 -- Rainfall density +local PRECSPR = 6 -- Time scale for precipitation variation in minutes +local PRECOFF = -0.4 -- Precipitation offset, higher = rains more often +local GSCYCLE = 0.5 -- Globalstep cycle (seconds) +local FLAKES = 16 -- Snowflakes per cycle +local DROPS = 32 -- Raindrops per cycle local NISVAL = 39 -- Clouds RGB value at night local DASVAL = 175 -- Clouds RGB value in daytime @@ -58,17 +58,25 @@ local nobj_prec = nil -- Globalstep function +local handles = {} +local timer = 0 + minetest.register_globalstep(function(dtime) + timer = timer + dtime + if timer < GSCYCLE then + return + end + + timer = 0 + for _, player in ipairs(minetest.get_connected_players()) do - -- Randomise and spread processing load - if math.random() > PROCHA then - return - end + local player_name = player:get_player_name() local ppos = player:getpos() local pposx = math.floor(ppos.x) - local pposy = math.floor(ppos.y) + local pposy = math.floor(ppos.y) + 2 -- Precipitation when swimming local pposz = math.floor(ppos.z) + local ppos = {x = pposx, y = pposy, z = pposz} local nobj_temp = nobj_temp or minetest.get_perlin(np_temp) local nobj_humid = nobj_humid or minetest.get_perlin(np_humid) @@ -78,16 +86,22 @@ minetest.register_globalstep(function(dtime) local nval_humid = nobj_humid:get2d({x = pposx, y = pposz}) local nval_prec = nobj_prec:get2d({x = os.clock() / 60, y = 0}) - -- Biome system: frozen biomes below heat 35, - -- deserts below humidity 20 + -- Biome system: frozen biomes below heat 35. + -- deserts below line 14 * t - 95 * h = -1496 + -- h = (14 * t + 1496) / 95 + -- h = 14/95 * t + 1496/95 where 1496/95 is y intersection + -- h - 14/95 t = 1496/95 y intersection + -- so area above line is + -- h - 14/95 t > 1496/95 local freeze = nval_temp < 35 - local precip = nval_prec > (nval_humid - 50) / 50 + PRECOFF + local precip = nval_prec < (nval_humid - 50) / 50 + PRECOFF and + nval_humid - (14 / 95) * nval_temp > 1496 / 95 -- Check if player is outside local outside = minetest.get_node_light(ppos, 0.5) == 15 -- Occasionally reset player sky - if math.random() < 0.05 then + if math.random() < 0.1 then if precip then -- Set overcast sky local sval @@ -114,6 +128,14 @@ minetest.register_globalstep(function(dtime) end end + if not precip or not outside or freeze then + if handles[player_name] then + -- Stop sound if playing + minetest.sound_stop(handles[player_name]) + handles[player_name] = nil + end + end + if precip and outside then -- Precipitation if freeze then @@ -162,6 +184,21 @@ minetest.register_globalstep(function(dtime) playername = player:get_player_name() }) end + + if not handles[player_name] then + -- Start sound if not playing + local handle = minetest.sound_play( + "snowdrift_rain", + { + to_player = player_name, + gain = 0.2, + loop = true, + } + ) + if handle then + handles[player_name] = handle + end + end end end end diff --git a/license.txt b/license.txt index 207c0a5..180c44a 100644 --- a/license.txt +++ b/license.txt @@ -2,7 +2,7 @@ License of source code ---------------------- The MIT License (MIT) -Copyright (C) 2014-2016 paramat +Copyright (C) 2017 paramat Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software @@ -22,3 +22,70 @@ DEALINGS IN THE SOFTWARE. For more details: https://opensource.org/licenses/MIT + + +License of media (textures) +--------------------------- + +Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) +Copyright (C) 2017 paramat + +You are free to: +Share — copy and redistribute the material in any medium or format. +Adapt — remix, transform, and build upon the material for any purpose, even commercially. +The licensor cannot revoke these freedoms as long as you follow the license terms. + +Under the following terms: + +Attribution — You must give appropriate credit, provide a link to the license, and +indicate if changes were made. You may do so in any reasonable manner, but not in any way +that suggests the licensor endorses you or your use. + +ShareAlike — If you remix, transform, or build upon the material, you must distribute +your contributions under the same license as the original. + +No additional restrictions — You may not apply legal terms or technological measures that +legally restrict others from doing anything the license permits. + +Notices: + +You do not have to comply with the license for elements of the material in the public +domain or where your use is permitted by an applicable exception or limitation. +No warranties are given. The license may not give you all of the permissions necessary +for your intended use. For example, other rights such as publicity, privacy, or moral +rights may limit how you use the material. + +For more details: +http://creativecommons.org/licenses/by-sa/3.0/ + + +License of media (sounds) +------------------------- + +Attribution 3.0 Unported (CC BY 3.0) +Copyright (C) 2008 inchadney + +You are free to: +Share — copy and redistribute the material in any medium or format. +Adapt — remix, transform, and build upon the material for any purpose, even commercially. +The licensor cannot revoke these freedoms as long as you follow the license terms. + +Under the following terms: + +Attribution — You must give appropriate credit, provide a link to the license, and +indicate if changes were made. You may do so in any reasonable manner, but not in any way +that suggests the licensor endorses you or your use. + +No additional restrictions — You may not apply legal terms or technological measures that +legally restrict others from doing anything the license permits. + +Notices: + +You do not have to comply with the license for elements of the material in the public +domain or where your use is permitted by an applicable exception or limitation. +No warranties are given. The license may not give you all of the permissions necessary +for your intended use. For example, other rights such as publicity, privacy, or moral +rights may limit how you use the material. + +For more details: +http://creativecommons.org/licenses/by/3.0/ diff --git a/sounds/snowdrift_rain.ogg b/sounds/snowdrift_rain.ogg new file mode 100644 index 0000000..b86eb5b Binary files /dev/null and b/sounds/snowdrift_rain.ogg differ diff --git a/textures/snowdrift_raindrop.png b/textures/snowdrift_raindrop.png index 081f531..1e4d3ac 100644 Binary files a/textures/snowdrift_raindrop.png and b/textures/snowdrift_raindrop.png differ