techage/steam_engine/boiler.lua

140 lines
3.3 KiB
Lua
Raw Normal View History

2019-03-02 14:24:48 +03:00
--[[
TechAge
=======
2021-06-05 12:42:30 +03:00
Copyright (C) 2019-2021 Joachim Stolberg
2019-03-02 14:24:48 +03:00
2020-10-19 20:09:17 +03:00
AGPL v3
2019-03-02 14:24:48 +03:00
See LICENSE.txt for more information
2022-01-03 23:40:31 +03:00
2019-03-02 14:24:48 +03:00
TA2 Steam Engine Boiler
]]--
-- for lazy programmers
local M = minetest.get_meta
local S = techage.S
2019-03-02 14:24:48 +03:00
local CYCLE_TIME = 4
2019-03-04 00:19:30 +03:00
local WATER_CONSUMPTION = 0.5
2019-03-08 23:18:55 +03:00
local Pipe = techage.SteamPipe
2020-01-26 01:15:44 +03:00
local boiler = techage.boiler
2019-03-08 23:18:55 +03:00
2020-01-26 01:15:44 +03:00
local function steaming(pos, nvm, temp)
2019-03-05 23:20:44 +03:00
if temp >= 80 then
2020-01-26 01:15:44 +03:00
local wc = WATER_CONSUMPTION * (nvm.power_ratio or 1)
nvm.water_level = math.max((nvm.water_level or 0) - wc, 0)
2019-03-05 23:20:44 +03:00
end
end
local function node_timer(pos, elapsed)
2020-01-26 01:15:44 +03:00
local nvm = techage.get_nvm(pos)
local temp = boiler.water_temperature(pos, nvm)
steaming(pos, nvm, temp)
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", boiler.formspec(pos, nvm))
2019-03-02 14:24:48 +03:00
end
2020-01-26 01:15:44 +03:00
return temp > 20
2019-03-02 14:24:48 +03:00
end
2020-01-26 01:15:44 +03:00
local function after_place_node(pos)
local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
if node.name ~= "techage:boiler1" then
minetest.remove_node(pos)
return true
2019-03-02 14:24:48 +03:00
end
end
2020-01-26 01:15:44 +03:00
local function after_dig_node(pos, oldnode)
Pipe:after_dig_node(pos)
techage.del_mem(pos)
2019-03-02 14:24:48 +03:00
end
2019-03-02 22:51:16 +03:00
-- boiler2: Main part, needed as generator
minetest.register_node("techage:boiler2", {
description = S("TA2 Boiler Top"),
2019-03-02 22:51:16 +03:00
tiles = {"techage_boiler2.png"},
drawtype = "mesh",
mesh = "techage_cylinder_09.obj",
2019-03-02 22:51:16 +03:00
selection_box = {
type = "fixed",
fixed = {-10/32, -48/32, -10/32, 10/32, 16/32, 10/32},
2019-03-02 14:24:48 +03:00
},
2022-01-03 23:40:31 +03:00
2020-01-26 01:15:44 +03:00
can_dig = boiler.can_dig,
2019-03-02 14:24:48 +03:00
on_timer = node_timer,
2020-01-26 01:15:44 +03:00
on_rightclick = boiler.on_rightclick,
after_place_node = after_place_node,
after_dig_node = after_dig_node,
on_punch = boiler.on_punch,
2022-01-03 23:40:31 +03:00
2019-11-05 00:53:04 +03:00
paramtype = "light",
2019-03-05 23:20:44 +03:00
groups = {cracky=1},
2019-03-02 14:24:48 +03:00
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
2020-01-26 01:15:44 +03:00
Pipe:add_secondary_node_names({"techage:boiler2"})
2019-05-21 01:05:53 +03:00
2019-06-08 23:57:01 +03:00
techage.register_node({"techage:boiler2"}, {
on_transfer = function(pos, in_dir, topic, payload)
if topic == "trigger" then
if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name ~= "techage:boiler1" then
return 0
end
2020-01-26 01:15:44 +03:00
local nvm = techage.get_nvm(pos)
nvm.fire_trigger = true
2019-06-08 23:57:01 +03:00
if not minetest.get_node_timer(pos):is_started() then
minetest.get_node_timer(pos):start(CYCLE_TIME)
end
2020-01-26 01:15:44 +03:00
if (nvm.temperature or 20) > 80 then
nvm.power_ratio = techage.transfer(pos, 6, "trigger", nil, Pipe, {
2019-06-16 22:06:16 +03:00
"techage:cylinder", "techage:cylinder_on"}) or 0
2020-01-26 01:15:44 +03:00
return nvm.power_ratio
2019-06-16 22:06:16 +03:00
else
return 0
end
2019-06-08 23:57:01 +03:00
end
2020-01-26 01:15:44 +03:00
end,
2019-06-08 23:57:01 +03:00
})
2019-05-21 01:05:53 +03:00
2020-01-26 01:15:44 +03:00
minetest.register_node("techage:boiler1", {
description = S("TA2 Boiler Base"),
tiles = {"techage_boiler.png"},
drawtype = "mesh",
mesh = "techage_cylinder_09.obj",
selection_box = {
type = "fixed",
fixed = {-8/32, -16/32, -8/32, 8/32, 16/32, 8/32},
},
paramtype = "light",
groups = {cracky=1},
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
2019-04-28 17:04:45 +03:00
minetest.register_craft({
output = "techage:boiler1",
recipe = {
{"techage:iron_ingot", "", "techage:iron_ingot"},
{"default:bronze_ingot", "", "default:bronze_ingot"},
{"techage:iron_ingot", "default:bronze_ingot", "techage:iron_ingot"},
},
})
minetest.register_craft({
output = "techage:boiler2",
recipe = {
{"techage:iron_ingot", "techage:steam_pipeS", "techage:iron_ingot"},
{"default:bronze_ingot", "", "default:bronze_ingot"},
{"techage:iron_ingot", "", "techage:iron_ingot"},
},
})