Add overheating mechanics.
parent
2da87e9372
commit
e0150340a2
|
@ -1,6 +1,8 @@
|
|||
-- © 2017 numberZero
|
||||
-- License: GNU Lesser General Public License, version 2 (or any later version)
|
||||
|
||||
local OVERLOAD_THRESHOLD = 20.0
|
||||
|
||||
local rules_in = {
|
||||
[0] = {{x = -1, y = 0, z = 0}},
|
||||
[1] = {{x = 0, y = 0, z = 1}},
|
||||
|
@ -24,6 +26,12 @@ local function diode_rules_out(node)
|
|||
end
|
||||
|
||||
local function diode_action(pos, node, channel, msg)
|
||||
if digiline_routing.overheat.heat(pos) > OVERLOAD_THRESHOLD then
|
||||
digiline_routing.overheat.forget(pos)
|
||||
minetest.dig_node(pos)
|
||||
minetest.add_item(pos, node.name)
|
||||
return
|
||||
end
|
||||
digiline:receptor_send(pos, diode_rules_out(node), channel, msg)
|
||||
end
|
||||
|
||||
|
@ -45,6 +53,7 @@ minetest.register_node("digiline_routing:diode", {
|
|||
{ -1/16, -8/16, -3/16, 1/16, -6/16, 3/16 },
|
||||
},
|
||||
},
|
||||
on_destruct = digiline_routing.overheat.forget,
|
||||
digiline = {
|
||||
effector = {
|
||||
action = diode_action,
|
||||
|
|
4
init.lua
4
init.lua
|
@ -2,8 +2,10 @@
|
|||
-- License: GNU Lesser General Public License, version 2 (or any later version)
|
||||
-- License for textures: CreativeCommoms BY-ShareAlike
|
||||
|
||||
digiline_routing = {}
|
||||
|
||||
local MODNAME = "digiline_routing"
|
||||
local MODPATH = minetest.get_modpath(MODNAME)
|
||||
|
||||
-- dofile(MODPATH.."/overheating.lua")
|
||||
dofile(MODPATH.."/overheating.lua")
|
||||
dofile(MODPATH.."/diode.lua")
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
-- © 2017 numberZero
|
||||
-- License: GNU Lesser General Public License, version 2 (or any later version)
|
||||
|
||||
local COOLDOWN_STEP = 0.5
|
||||
local DEFAULT_MAX_RATE = 20.0
|
||||
local hot_objects = {}
|
||||
local timer = 0.0
|
||||
|
||||
digiline_routing.overheat = {}
|
||||
|
||||
digiline_routing.overheat.heat = function(pos, heat)
|
||||
local id = minetest.hash_node_position(pos)
|
||||
local temperature = (hot_objects[id] or 0) + (heat or 1)
|
||||
hot_objects[id] = temperature
|
||||
return temperature
|
||||
end
|
||||
|
||||
digiline_routing.overheat.forget = function(pos)
|
||||
local id = minetest.hash_node_position(pos)
|
||||
hot_objects[id] = nil
|
||||
end
|
||||
|
||||
local global_cooldown = function(dtime)
|
||||
timer = timer + dtime
|
||||
if timer < COOLDOWN_STEP then -- don't overload the CPU
|
||||
return
|
||||
end
|
||||
local cooldown = DEFAULT_MAX_RATE * timer
|
||||
timer = 0
|
||||
for id, temperature in pairs(hot_objects) do
|
||||
temperature = temperature - cooldown
|
||||
if temperature <= 0 then
|
||||
hot_objects[id] = nil
|
||||
else
|
||||
hot_objects[id] = temperature
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_globalstep(global_cooldown)
|
Loading…
Reference in New Issue