2019-06-10 22:31:58 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019 Joachim Stolberg
|
|
|
|
|
2019-08-22 21:49:47 +03:00
|
|
|
GPL v3
|
2019-06-10 22:31:58 +03:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
TA3 Booster
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
2019-07-02 22:33:12 +03:00
|
|
|
local S = techage.S
|
2019-09-08 22:54:34 +03:00
|
|
|
local D = techage.Debug
|
2019-06-10 22:31:58 +03:00
|
|
|
|
2019-06-16 22:06:16 +03:00
|
|
|
local PWR_NEEDED = 3
|
|
|
|
local CYCLE_TIME = 2
|
2019-06-10 22:31:58 +03:00
|
|
|
|
|
|
|
local Power = techage.ElectricCable
|
2019-08-17 00:44:11 +03:00
|
|
|
local power = techage.power
|
2019-06-10 22:31:58 +03:00
|
|
|
|
|
|
|
local function infotext(pos, state)
|
2019-07-02 22:33:12 +03:00
|
|
|
M(pos):set_string("infotext", S("TA3 Booster")..": "..state)
|
2019-06-10 22:31:58 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function swap_node(pos, name)
|
2019-10-07 01:09:39 +03:00
|
|
|
local node = techage.get_node_lvm(pos)
|
2019-06-10 22:31:58 +03:00
|
|
|
if node.name == name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
node.name = name
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
end
|
|
|
|
|
2019-08-17 00:44:11 +03:00
|
|
|
local function on_power(pos, mem)
|
|
|
|
if mem.running then
|
|
|
|
swap_node(pos, "techage:ta3_booster_on")
|
|
|
|
infotext(pos, "running")
|
2019-08-01 23:31:43 +03:00
|
|
|
end
|
2019-09-08 22:54:34 +03:00
|
|
|
if D.dbg2 then D.dbg("booster on_power") end
|
2019-08-17 14:33:46 +03:00
|
|
|
mem.is_powered = true
|
2019-08-01 23:31:43 +03:00
|
|
|
end
|
|
|
|
|
2019-08-17 00:44:11 +03:00
|
|
|
local function on_nopower(pos, mem)
|
|
|
|
swap_node(pos, "techage:ta3_booster")
|
|
|
|
infotext(pos, "no power")
|
2019-09-08 22:54:34 +03:00
|
|
|
if D.dbg2 then D.dbg("booster on_nopower") end
|
2019-08-17 14:33:46 +03:00
|
|
|
mem.is_powered = false
|
2019-08-01 23:31:43 +03:00
|
|
|
end
|
|
|
|
|
2019-08-17 00:44:11 +03:00
|
|
|
local function node_timer(pos, elapsed)
|
|
|
|
local mem = tubelib2.get_mem(pos)
|
2019-09-08 22:54:34 +03:00
|
|
|
if mem.running and mem.is_powered then
|
2019-08-17 00:44:11 +03:00
|
|
|
minetest.sound_play("techage_booster", {
|
|
|
|
pos = pos,
|
|
|
|
gain = 1,
|
|
|
|
max_hear_distance = 7})
|
2019-06-10 22:31:58 +03:00
|
|
|
end
|
2019-09-08 22:54:34 +03:00
|
|
|
if mem.running then
|
|
|
|
power.consumer_alive(pos, mem)
|
|
|
|
end
|
2019-08-17 00:44:11 +03:00
|
|
|
return mem.running
|
2019-06-10 22:31:58 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_node("techage:ta3_booster", {
|
2019-07-02 22:33:12 +03:00
|
|
|
description = S("TA3 Booster"),
|
2019-06-10 22:31:58 +03:00
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta3.png^techage_appl_arrow.png^techage_frame_ta3.png",
|
|
|
|
"techage_filling_ta3.png^techage_frame_ta3.png",
|
|
|
|
"techage_filling_ta3.png^techage_appl_hole_biogas.png^techage_frame_ta3.png",
|
2019-06-17 20:57:08 +03:00
|
|
|
"techage_filling_ta3.png^techage_appl_hole_electric.png^techage_frame_ta3.png",
|
2019-06-10 22:31:58 +03:00
|
|
|
"techage_filling_ta3.png^techage_appl_compressor.png^techage_frame_ta3.png",
|
|
|
|
"techage_filling_ta3.png^techage_appl_compressor.png^[transformFX^techage_frame_ta3.png",
|
|
|
|
},
|
2019-06-17 20:57:08 +03:00
|
|
|
on_timer = node_timer,
|
2019-06-10 22:31:58 +03:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {cracky=2, crumbly=2, choppy=2},
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_node("techage:ta3_booster_on", {
|
|
|
|
tiles = {
|
|
|
|
-- up, down, right, left, back, front
|
|
|
|
"techage_filling_ta3.png^techage_appl_arrow.png^techage_frame_ta3.png",
|
|
|
|
"techage_filling_ta3.png^techage_frame_ta3.png",
|
|
|
|
"techage_filling_ta3.png^techage_appl_hole_biogas.png^techage_frame_ta3.png",
|
2019-06-17 20:57:08 +03:00
|
|
|
"techage_filling_ta3.png^techage_appl_hole_electric.png^techage_frame_ta3.png",
|
2019-06-10 22:31:58 +03:00
|
|
|
{
|
|
|
|
image = "techage_filling4_ta3.png^techage_appl_compressor4.png^techage_frame4_ta3.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 0.2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
image = "techage_filling4_ta3.png^techage_appl_compressor4.png^[transformFX]^techage_frame4_ta3.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 0.2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-06-17 20:57:08 +03:00
|
|
|
on_timer = node_timer,
|
2019-06-10 22:31:58 +03:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {not_in_creative_inventory = 1},
|
|
|
|
diggable = false,
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
})
|
|
|
|
|
|
|
|
techage.power.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
|
|
|
|
power_network = Power,
|
2019-06-17 20:57:08 +03:00
|
|
|
conn_sides = {"F", "B", "U", "D", "L"},
|
2019-08-01 23:31:43 +03:00
|
|
|
on_power = on_power,
|
2019-08-17 00:44:11 +03:00
|
|
|
on_nopower = on_nopower,
|
2019-10-05 20:19:18 +03:00
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local mem = tubelib2.init_mem(pos)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local indir = techage.side_to_indir("R", node.param2)
|
|
|
|
M(pos):set_int("indir", indir)
|
|
|
|
infotext(pos, "stopped")
|
|
|
|
end,
|
2019-06-10 22:31:58 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
-- for intra machine communication
|
|
|
|
techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
|
|
|
|
on_transfer = function(pos, in_dir, topic, payload)
|
|
|
|
if M(pos):get_int("indir") == in_dir then
|
|
|
|
local mem = tubelib2.get_mem(pos)
|
|
|
|
if topic == "power" then
|
2019-09-08 22:54:34 +03:00
|
|
|
if D.dbg2 then D.dbg("booster power") end
|
|
|
|
return power.power_available(pos, mem, 0)
|
2019-08-17 00:44:11 +03:00
|
|
|
elseif topic == "start" and not mem.running then
|
2019-09-08 22:54:34 +03:00
|
|
|
if D.dbg2 then D.dbg("booster try start", mem.pwr_master_pos, mem.pwr_power_provided_cnt) end
|
2019-08-17 00:44:11 +03:00
|
|
|
if power.power_available(pos, mem, 0) then
|
2019-06-10 22:31:58 +03:00
|
|
|
mem.running = true
|
2019-09-08 22:54:34 +03:00
|
|
|
if D.dbg2 then D.dbg("booster start") end
|
2019-08-17 00:44:11 +03:00
|
|
|
power.consumer_start(pos, mem, CYCLE_TIME, PWR_NEEDED)
|
2019-06-17 20:57:08 +03:00
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
2019-06-10 22:31:58 +03:00
|
|
|
else
|
2019-09-08 22:54:34 +03:00
|
|
|
if D.dbg2 then D.dbg("booster no power") end
|
2019-06-10 22:31:58 +03:00
|
|
|
infotext(pos, "no power")
|
|
|
|
end
|
|
|
|
elseif topic == "stop" then
|
|
|
|
mem.running = false
|
2019-09-08 22:54:34 +03:00
|
|
|
if D.dbg2 then D.dbg("booster stop") end
|
2019-06-10 22:31:58 +03:00
|
|
|
swap_node(pos, "techage:ta3_booster")
|
2019-08-17 00:44:11 +03:00
|
|
|
power.consumer_stop(pos, mem)
|
2019-06-17 20:57:08 +03:00
|
|
|
minetest.get_node_timer(pos):stop()
|
2019-08-17 00:44:11 +03:00
|
|
|
infotext(pos, "stopped")
|
2019-06-10 22:31:58 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:ta3_booster",
|
|
|
|
recipe = {
|
|
|
|
{"basic_materials:steel_bar", "default:wood", "basic_materials:steel_bar"},
|
2019-06-15 17:14:46 +03:00
|
|
|
{"", "basic_materials:gear_steel", ""},
|
2019-06-10 22:31:58 +03:00
|
|
|
{"basic_materials:steel_bar", "default:wood", "basic_materials:steel_bar"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|