2020-02-12 00:34:58 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2022-06-05 22:20:43 +03:00
|
|
|
Copyright (C) 2019-2022 Joachim Stolberg
|
2020-02-12 00:34:58 +03:00
|
|
|
|
2020-10-19 20:09:17 +03:00
|
|
|
AGPL v3
|
2020-02-12 00:34:58 +03:00
|
|
|
See LICENSE.txt for more information
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2020-02-12 00:34:58 +03:00
|
|
|
TA4 Water Pump
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2020-02-12 00:34:58 +03:00
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
|
|
|
local S = techage.S
|
|
|
|
|
|
|
|
local Cable = techage.ElectricCable
|
|
|
|
local Pipe = techage.LiquidPipe
|
2021-06-27 19:29:46 +03:00
|
|
|
local power = networks.power
|
|
|
|
local liquid = networks.liquid
|
2020-02-12 00:34:58 +03:00
|
|
|
|
2021-06-27 19:29:46 +03:00
|
|
|
local CYCLE_TIME = 2
|
2020-02-12 00:34:58 +03:00
|
|
|
local STANDBY_TICKS = 3
|
|
|
|
local COUNTDOWN_TICKS = 3
|
|
|
|
local PWR_NEEDED = 4
|
|
|
|
|
|
|
|
local function formspec(self, pos, nvm)
|
|
|
|
return "size[3,2]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"box[0,-0.1;2.8,0.5;#c6e8ff]"..
|
|
|
|
"label[0.5,-0.1;"..minetest.colorize( "#000000", S("Water Pump")).."]"..
|
|
|
|
"image_button[1,1;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
|
|
|
"tooltip[1,1;1,1;"..self:get_state_tooltip(nvm).."]"
|
|
|
|
end
|
|
|
|
|
|
|
|
local function can_start(pos, nvm, state)
|
2020-02-14 00:44:58 +03:00
|
|
|
local outdir = M(pos):get_int("waterdir")
|
|
|
|
local pos1 = vector.add(pos, tubelib2.Dir6dToVector[outdir or 0])
|
|
|
|
if not techage.is_ocean(pos1) then
|
|
|
|
return S("no usable water")
|
|
|
|
end
|
|
|
|
if not power.power_available(pos, Cable) then
|
|
|
|
return S("no power")
|
|
|
|
end
|
|
|
|
return true
|
2020-02-12 00:34:58 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function start_node(pos, nvm, state)
|
2021-06-27 19:29:46 +03:00
|
|
|
nvm.running = true
|
2020-02-12 00:34:58 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function stop_node(pos, nvm, state)
|
|
|
|
nvm.running = false
|
|
|
|
end
|
|
|
|
|
|
|
|
local State = techage.NodeStates:new({
|
|
|
|
node_name_passive = "techage:t4_waterpump",
|
|
|
|
infotext_name = S("TA4 Water Pump"),
|
|
|
|
cycle_time = CYCLE_TIME,
|
|
|
|
standby_ticks = STANDBY_TICKS,
|
|
|
|
formspec_func = formspec,
|
2020-02-14 00:44:58 +03:00
|
|
|
can_start = can_start,
|
2020-02-12 00:34:58 +03:00
|
|
|
start_node = start_node,
|
|
|
|
stop_node = stop_node,
|
|
|
|
})
|
|
|
|
|
2021-06-27 19:29:46 +03:00
|
|
|
local function has_power(pos, nvm)
|
|
|
|
local outdir = networks.Flip[M(pos):get_int("waterdir")]
|
|
|
|
local taken = power.consume_power(pos, Cable, outdir, PWR_NEEDED)
|
|
|
|
if techage.is_running(nvm) then
|
|
|
|
if taken < PWR_NEEDED then
|
|
|
|
State:nopower(pos, nvm)
|
|
|
|
else
|
|
|
|
return true -- keep running
|
|
|
|
end
|
|
|
|
elseif taken == PWR_NEEDED then
|
|
|
|
State:start(pos, nvm)
|
|
|
|
end
|
2020-02-12 00:34:58 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function pumping(pos, nvm)
|
2021-06-27 19:29:46 +03:00
|
|
|
if has_power(pos, nvm) then
|
|
|
|
nvm.ticks = (nvm.ticks or 0) + 1
|
|
|
|
if nvm.ticks % 4 == 0 then
|
|
|
|
local leftover = liquid.put(pos, Pipe, 6, "techage:water", 1)
|
|
|
|
if leftover and leftover > 0 then
|
|
|
|
State:blocked(pos, nvm)
|
|
|
|
return
|
|
|
|
end
|
2020-02-12 00:34:58 +03:00
|
|
|
end
|
2021-06-27 19:29:46 +03:00
|
|
|
State:keep_running(pos, nvm, 1)
|
2020-02-12 00:34:58 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- converts power into hydrogen
|
|
|
|
local function node_timer(pos, elapsed)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
pumping(pos, nvm)
|
|
|
|
return State:is_active(nvm)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_receive_fields(pos, formname, fields, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
State:state_button_event(pos, nvm, fields)
|
|
|
|
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
|
|
|
end
|
|
|
|
|
|
|
|
local function after_place_node(pos)
|
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
nvm.running = false
|
|
|
|
local number = techage.add_node(pos, "techage:t4_waterpump")
|
|
|
|
State:node_init(pos, nvm, number)
|
2020-02-14 00:44:58 +03:00
|
|
|
M(pos):set_int("waterdir", networks.side_to_outdir(pos, "R"))
|
2020-02-12 00:34:58 +03:00
|
|
|
Pipe:after_place_node(pos)
|
|
|
|
Cable:after_place_node(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function after_dig_node(pos, oldnode, oldmetadata, digger)
|
|
|
|
Pipe:after_dig_node(pos)
|
|
|
|
Cable:after_dig_node(pos)
|
|
|
|
techage.del_mem(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("techage:t4_waterpump", {
|
|
|
|
description = S("TA4 Water Pump"),
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta4.png^techage_frame_waterpump_top.png^techage_appl_hole_pipe.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_ta4.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_waterpump.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_waterpump.png^techage_appl_hole_electric.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_waterpump.png",
|
|
|
|
"techage_filling_ta4.png^techage_frame_waterpump.png",
|
|
|
|
},
|
|
|
|
|
|
|
|
after_place_node = after_place_node,
|
|
|
|
after_dig_node = after_dig_node,
|
|
|
|
on_receive_fields = on_receive_fields,
|
|
|
|
on_timer = node_timer,
|
2022-01-03 23:40:31 +03:00
|
|
|
|
2020-02-12 00:34:58 +03:00
|
|
|
paramtype2 = "facedir",
|
2021-02-27 20:29:52 +03:00
|
|
|
groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory = 1},
|
2020-02-12 00:34:58 +03:00
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
is_ground_content = false,
|
|
|
|
})
|
|
|
|
|
2021-06-27 19:29:46 +03:00
|
|
|
power.register_nodes({"techage:t4_waterpump"}, Cable, "con", {"L"})
|
|
|
|
liquid.register_nodes({"techage:t4_waterpump"}, Pipe, "pump", {"U"}, {})
|
2020-02-12 00:34:58 +03:00
|
|
|
|
|
|
|
techage.register_node({"techage:t4_waterpump"}, {
|
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
|
|
|
return State:on_receive_message(pos, topic, payload)
|
|
|
|
end,
|
2022-06-05 22:20:43 +03:00
|
|
|
on_beduino_receive_cmnd = function(pos, src, topic, payload)
|
|
|
|
return State:on_beduino_receive_cmnd(pos, topic, payload)
|
|
|
|
end,
|
|
|
|
on_beduino_request_data = function(pos, src, topic, payload)
|
|
|
|
return State:on_beduino_request_data(pos, topic, payload)
|
|
|
|
end,
|
2022-01-04 21:40:27 +03:00
|
|
|
})
|