This commit is contained in:
Joachim Stolberg 2020-02-01 22:00:58 +01:00
parent f049f7b18c
commit 4a9ca006d6
29 changed files with 543 additions and 307 deletions

View File

@ -29,6 +29,8 @@ local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).
local power = techage.power local power = techage.power
local networks = techage.networks local networks = techage.networks
local Pipe = techage.LiquidPipe
local liquid = techage.liquid
local function has_power(pos, nvm, state) local function has_power(pos, nvm, state)
local crd = CRD(pos) local crd = CRD(pos)
@ -115,19 +117,22 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
power_png = 'techage_appl_hole_electric.png' power_png = 'techage_appl_hole_electric.png'
tNetworks = { tNetworks = {
ele1 = { ele1 = {
sides = tNode.power_sides or {F=1, B=1}, sides = tNode.power_sides or {F=1, B=1, U=1, D=1},
ntype = "con1", ntype = "con1",
nominal = tNode.power_consumption[stage], nominal = tNode.power_consumption[stage],
on_power = on_power, on_power = on_power,
on_nopower = on_nopower, on_nopower = on_nopower,
}, },
} }
if tNode.networks and tNode.networks.pipe2 then
tNetworks.pipe2 = tNode.networks.pipe2
end
else else
power_network = techage.Axle power_network = techage.Axle
power_png = 'techage_axle_clutch.png' power_png = 'techage_axle_clutch.png'
tNetworks = { tNetworks = {
axle = { axle = {
sides = tNode.power_sides or {F=1, B=1}, sides = tNode.power_sides or {F=1, B=1, U=1, D=1},
ntype = "con1", ntype = "con1",
nominal = tNode.power_consumption[stage], nominal = tNode.power_consumption[stage],
on_power = on_power, on_power = on_power,
@ -196,7 +201,12 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
end end
local tubelib2_on_update2 = function(pos, outdir, tlib2, node) local tubelib2_on_update2 = function(pos, outdir, tlib2, node)
power.update_network(pos, outdir, tlib2) print("tubelib2_on_update2", tlib2.tube_type)
if tlib2.tube_type == "pipe2" then
liquid.update_network(pos, outdir, tlib2)
else
power.update_network(pos, outdir, tlib2)
end
end end
tNode.groups.not_in_creative_inventory = 0 tNode.groups.not_in_creative_inventory = 0

View File

@ -51,8 +51,8 @@ local function build(pos, param2, AssemblyPlan, idx)
minetest.add_node(pos1, {name=node_name, param2=(param2 + fd_offs) % 4}) minetest.add_node(pos1, {name=node_name, param2=(param2 + fd_offs) % 4})
minetest.after(0.5, build, pos, param2, AssemblyPlan, idx+1) minetest.after(0.5, build, pos, param2, AssemblyPlan, idx+1)
else else
local mem = techage.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.assemble_locked = false nvm.assemble_locked = false
end end
end end
@ -65,8 +65,8 @@ local function remove(pos, param2, AssemblyPlan, idx)
minetest.remove_node(pos1) minetest.remove_node(pos1)
minetest.after(0.5, remove, pos, param2, AssemblyPlan, idx-1) minetest.after(0.5, remove, pos, param2, AssemblyPlan, idx-1)
else else
local mem = techage.get_mem(pos) local nvm = techage.get_nvm(pos)
mem.assemble_locked = false nvm.assemble_locked = false
end end
end end
@ -91,22 +91,22 @@ end
-- Two important flags: -- Two important flags:
-- 1) mem.assemble_locked is true while the object is being assembled/disassembled -- 1) nvm.assemble_locked is true while the object is being assembled/disassembled
-- 2) mem.assemble_build is true if the object is assembled -- 2) nvm.assemble_build is true if the object is assembled
function techage.assemble.build(pos, AssemblyPlan, player_name) function techage.assemble.build(pos, AssemblyPlan, player_name)
-- check protection -- check protection
if minetest.is_protected(pos, player_name) then if minetest.is_protected(pos, player_name) then
return return
end end
local mem = techage.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.assemble_locked then if nvm.assemble_locked then
return return
end end
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if check_space(pos, node.param2, AssemblyPlan, player_name) then if check_space(pos, node.param2, AssemblyPlan, player_name) then
mem.assemble_locked = true nvm.assemble_locked = true
build(pos, node.param2, AssemblyPlan, 1) build(pos, node.param2, AssemblyPlan, 1)
mem.assemble_build = true nvm.assemble_build = true
end end
end end
@ -115,12 +115,12 @@ function techage.assemble.remove(pos, AssemblyPlan, player_name)
if minetest.is_protected(pos, player_name) then if minetest.is_protected(pos, player_name) then
return return
end end
local mem = techage.get_mem(pos) local nvm = techage.get_nvm(pos)
if mem.assemble_locked then if nvm.assemble_locked then
return return
end end
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
mem.assemble_locked = true nvm.assemble_locked = true
remove(pos, node.param2, AssemblyPlan, #AssemblyPlan) remove(pos, node.param2, AssemblyPlan, #AssemblyPlan)
mem.assemble_build = false nvm.assemble_build = false
end end

View File

@ -97,6 +97,20 @@ function techage.boiler.can_dig(pos, player)
return nvm.num_water == 0 return nvm.num_water == 0
end end
local function space_in_inventory(wielded_item, item_count, puncher)
-- check if holding more than 1 empty container
if item_count > 1 then
local inv = puncher:get_inventory()
local item = ItemStack({name=wielded_item, count = item_count - 1})
if inv:room_for_item("main", item) then
inv:add_item("main", item)
return true
end
return false
end
return true
end
function techage.boiler.on_punch(pos, node, puncher, pointed_thing) function techage.boiler.on_punch(pos, node, puncher, pointed_thing)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
@ -107,15 +121,27 @@ function techage.boiler.on_punch(pos, node, puncher, pointed_thing)
nvm.num_water = nvm.num_water or 0 nvm.num_water = nvm.num_water or 0
local wielded_item = puncher:get_wielded_item():get_name() local wielded_item = puncher:get_wielded_item():get_name()
local item_count = puncher:get_wielded_item():get_count()
if IsWater[wielded_item] and nvm.num_water < MAX_WATER then if IsWater[wielded_item] and nvm.num_water < MAX_WATER then
mem.blocking_time = techage.SystemTime + BLOCKING_TIME mem.blocking_time = techage.SystemTime + BLOCKING_TIME
nvm.num_water = nvm.num_water + 1 nvm.num_water = nvm.num_water + 1
puncher:set_wielded_item(ItemStack("bucket:bucket_empty")) puncher:set_wielded_item(ItemStack("bucket:bucket_empty"))
M(pos):set_string("formspec", techage.boiler.formspec(pos, nvm)) M(pos):set_string("formspec", techage.boiler.formspec(pos, nvm))
elseif IsBucket[wielded_item] and nvm.num_water > 0 then elseif IsBucket[wielded_item] and nvm.num_water > 0 then
mem.blocking_time = techage.SystemTime + BLOCKING_TIME if item_count > 1 then
nvm.num_water = nvm.num_water - 1 local inv = puncher:get_inventory()
puncher:set_wielded_item(ItemStack("bucket:bucket_water")) local item = ItemStack("bucket:bucket_water")
if inv:room_for_item("main", item) then
inv:add_item("main", item)
puncher:set_wielded_item({name=wielded_item, count = item_count - 1})
mem.blocking_time = techage.SystemTime + BLOCKING_TIME
nvm.num_water = nvm.num_water - 1
end
else
mem.blocking_time = techage.SystemTime + BLOCKING_TIME
nvm.num_water = nvm.num_water - 1
puncher:set_wielded_item(ItemStack("bucket:bucket_water"))
end
M(pos):set_string("formspec", techage.boiler.formspec(pos, nvm)) M(pos):set_string("formspec", techage.boiler.formspec(pos, nvm))
end end
end end

View File

@ -335,8 +335,10 @@ function techage.networks.get_network(tube_type, netID)
end end
function techage.networks.delete_network(tube_type, netID) function techage.networks.delete_network(tube_type, netID)
print("delete_network", tube_type, string.format("%012X", netID))
if Networks[tube_type] and Networks[tube_type][netID] then if Networks[tube_type] and Networks[tube_type][netID] then
Networks[tube_type][netID] = nil Networks[tube_type][netID] = nil
print("deleted")
end end
end end

View File

@ -273,7 +273,7 @@ function NodeStates:start(pos, nvm)
return false return false
end end
function NodeStates:standby(pos, nvm) function NodeStates:standby(pos, nvm, err_string)
local state = nvm.techage_state or STOPPED local state = nvm.techage_state or STOPPED
if state == RUNNING then if state == RUNNING then
nvm.techage_state = STANDBY nvm.techage_state = STANDBY
@ -282,10 +282,10 @@ function NodeStates:standby(pos, nvm)
end end
if self.infotext_name then if self.infotext_name then
local number = M(pos):get_string("node_number") local number = M(pos):get_string("node_number")
M(pos):set_string("infotext", self.infotext_name.." "..number..": standby") M(pos):set_string("infotext", self.infotext_name.." "..number..": "..(err_string or "standby"))
end end
if self.formspec_func then if self.formspec_func then
nvm.ta_state_tooltip = "standby" nvm.ta_state_tooltip = err_string or "standby"
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm)) M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end end
if self.on_state_change then if self.on_state_change then
@ -331,7 +331,7 @@ function NodeStates:nopower(pos, nvm, err_string)
end end
if self.infotext_name then if self.infotext_name then
local number = M(pos):get_string("node_number") local number = M(pos):get_string("node_number")
M(pos):set_string("infotext", self.infotext_name.." "..number..": no power") M(pos):set_string("infotext", self.infotext_name.." "..number..": "..(err_string or "no power"))
end end
if self.formspec_func then if self.formspec_func then
nvm.ta_state_tooltip = err_string or "no power" nvm.ta_state_tooltip = err_string or "no power"
@ -514,15 +514,6 @@ function NodeStates:on_node_load(pos, not_start_timer)
elseif state == BLOCKED then elseif state == BLOCKED then
minetest.get_node_timer(pos):start(self.cycle_time * self.standby_ticks) minetest.get_node_timer(pos):start(self.cycle_time * self.standby_ticks)
end end
if self.formspec_func then
M(pos):set_string("formspec", self.formspec_func(self, pos, nvm))
end
-- power available?
if nvm.techage_state == RUNNING and not self.has_power(pos, nvm, state) then
self:nopower(pos, nvm)
end
end end
minetest.register_node("techage:defect_dummy", { minetest.register_node("techage:defect_dummy", {

View File

@ -39,13 +39,15 @@ end
local function play_sound(pos) local function play_sound(pos)
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
mem.handle = minetest.sound_play("techage_turbine", { if not mem.handle or mem.handle == -1 then
pos = pos, mem.handle = minetest.sound_play("techage_turbine", {
gain = 1, pos = pos,
max_hear_distance = 15, gain = 1,
loop = true}) max_hear_distance = 15,
if mem.handle == -1 then loop = true})
minetest.after(1, play_sound, pos) if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end end
end end

View File

@ -69,20 +69,24 @@ local function inlet_cmnd(pos, cmnd, payload)
end end
local function play_sound(pos) local function play_sound(pos)
local nvm = techage.get_nvm(pos) local mem = techage.get_mem(pos)
if nvm.running then if not mem.handle or mem.handle == -1 then
nvm.handle = minetest.sound_play("techage_booster", { mem.handle = minetest.sound_play("techage_booster", {
pos = pos, pos = pos,
gain = 0.5, gain = 0.5,
max_hear_distance = 10}) max_hear_distance = 10,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end end
end end
local function stop_sound(pos) local function stop_sound(pos)
local nvm = techage.get_nvm(pos) local mem = techage.get_mem(pos)
if nvm.running and nvm.handle then if mem.handle then
minetest.sound_stop(nvm.handle) minetest.sound_stop(mem.handle)
nvm.handle = nil mem.handle = nil
end end
end end

View File

@ -30,20 +30,24 @@ local function swap_node(pos, name)
end end
local function play_sound(pos) local function play_sound(pos)
local nvm = techage.get_nvm(pos) local mem = techage.get_mem(pos)
if nvm.running then if not mem.handle or mem.handle == -1 then
nvm.handle = minetest.sound_play("techage_turbine", { mem.handle = minetest.sound_play("techage_turbine", {
pos = pos, pos = pos,
gain = 0.5, gain = 0.5,
max_hear_distance = 10}) max_hear_distance = 10,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end end
end end
local function stop_sound(pos) local function stop_sound(pos)
local nvm = techage.get_nvm(pos) local mem = techage.get_mem(pos)
if nvm.running and nvm.handle then if mem.handle then
minetest.sound_stop(nvm.handle) minetest.sound_stop(mem.handle)
nvm.handle = nil mem.handle = nil
end end
end end

View File

@ -39,13 +39,15 @@ end
local function play_sound(pos) local function play_sound(pos)
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
mem.handle = minetest.sound_play("techage_booster", { if not mem.handle or mem.handle == -1 then
pos = pos, mem.handle = minetest.sound_play("techage_booster", {
gain = 1, pos = pos,
max_hear_distance = 7, gain = 1,
loop = true}) max_hear_distance = 7,
if mem.handle == -1 then loop = true})
minetest.after(1, play_sound, pos) if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end end
end end
@ -179,7 +181,8 @@ techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
if M(pos):get_int("indir") == in_dir then if M(pos):get_int("indir") == in_dir then
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
if topic == "power" then if topic == "power" then
return techage.get_node_lvm(pos).name == "techage:ta3_booster_on" return techage.get_node_lvm(pos).name == "techage:ta3_booster_on" or
power.power_available(pos, Cable)
elseif topic == "start" and not nvm.running then elseif topic == "start" and not nvm.running then
if power.power_available(pos, Cable) then if power.power_available(pos, Cable) then
nvm.running = true nvm.running = true
@ -197,7 +200,12 @@ techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, {
stop_sound(pos) stop_sound(pos)
end end
end end
end end,
on_node_load = function(pos, node)
if node.name == "techage:ta3_booster_on" then
play_sound(pos)
end
end,
}) })
minetest.register_craft({ minetest.register_craft({

View File

@ -26,7 +26,6 @@ local EFFICIENCY = 2 -- burn cycles
local CATEGORY = 3 local CATEGORY = 3
local function has_fuel(pos, nvm) local function has_fuel(pos, nvm)
print("has_fuel", nvm.burn_cycles, topic, payload)
return nvm.burn_cycles > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0) return nvm.burn_cycles > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0)
end end
@ -55,8 +54,11 @@ local function node_timer(pos, elapsed)
return false return false
end end
end end
return true
end end
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", fuel.formspec(nvm))
end
return true
end end
local function start_firebox(pos, nvm) local function start_firebox(pos, nvm)
@ -85,11 +87,23 @@ local _liquid = {
peek = liquid.srv_peek, peek = liquid.srv_peek,
put = function(pos, indir, name, amount) put = function(pos, indir, name, amount)
if fuel.valid_fuel(name, fuel.BT_OIL) then if fuel.valid_fuel(name, fuel.BT_OIL) then
return liquid.srv_put(pos, indir, name, amount) local res = liquid.srv_put(pos, indir, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", fuel.formspec(nvm))
end
return res
end end
return amount return amount
end, end,
take = liquid.srv_take, take = function(pos, indir, name, amount)
amount, name = liquid.srv_take(pos, indir, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", fuel.formspec(nvm))
end
return amount, name
end
} }
local _networks = { local _networks = {
@ -121,6 +135,7 @@ minetest.register_node("techage:furnace_firebox", {
allow_metadata_inventory_take = fuel.allow_metadata_inventory_take, allow_metadata_inventory_take = fuel.allow_metadata_inventory_take,
allow_metadata_inventory_put = fuel.allow_metadata_inventory_put, allow_metadata_inventory_put = fuel.allow_metadata_inventory_put,
on_metadata_inventory_put = fuel.on_metadata_inventory_put, on_metadata_inventory_put = fuel.on_metadata_inventory_put,
on_punch = fuel.on_punch,
on_receive_fields = fuel.on_receive_fields, on_receive_fields = fuel.on_receive_fields,
on_rightclick = fuel.on_rightclick, on_rightclick = fuel.on_rightclick,
liquid = _liquid, liquid = _liquid,
@ -174,6 +189,7 @@ minetest.register_node("techage:furnace_firebox_on", {
allow_metadata_inventory_put = fuel.allow_metadata_inventory_put, allow_metadata_inventory_put = fuel.allow_metadata_inventory_put,
allow_metadata_inventory_take = fuel.allow_metadata_inventory_take, allow_metadata_inventory_take = fuel.allow_metadata_inventory_take,
on_receive_fields = fuel.on_receive_fields, on_receive_fields = fuel.on_receive_fields,
on_punch = fuel.on_punch,
on_rightclick = fuel.on_rightclick, on_rightclick = fuel.on_rightclick,
liquid = _liquid, liquid = _liquid,
networks = _networks, networks = _networks,
@ -215,7 +231,6 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"},
on_transfer = function(pos, in_dir, topic, payload) on_transfer = function(pos, in_dir, topic, payload)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
if topic == "fuel" then if topic == "fuel" then
print(dump(nvm))
return has_fuel(pos, nvm) and booster_cmnd(pos, "power") return has_fuel(pos, nvm) and booster_cmnd(pos, "power")
elseif topic == "running" then elseif topic == "running" then
return nvm.running and booster_cmnd(pos, "power") return nvm.running and booster_cmnd(pos, "power")

View File

@ -100,7 +100,7 @@ local function cooking(pos, crd, nvm, elapsed)
crd.State:idle(pos, nvm) crd.State:idle(pos, nvm)
end end
else else
crd.State:idle(pos, nvm) crd.State:standby(pos, nvm, S("no fuel or no power"))
end end
end end
end end
@ -113,7 +113,6 @@ local function keep_running(pos, elapsed)
if nvm.toggle then -- progress bar/arrow if nvm.toggle then -- progress bar/arrow
M(pos):set_string("formspec", formspec(crd.State, pos, nvm)) M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
end end
return crd.State:is_active(nvm)
end end
local function allow_metadata_inventory_put(pos, listname, index, stack, player) local function allow_metadata_inventory_put(pos, listname, index, stack, player)
@ -186,6 +185,7 @@ local function can_start(pos, nvm, state)
end end
local function on_node_state_change(pos, old_state, new_state) local function on_node_state_change(pos, old_state, new_state)
print("on_node_state_change")
local pwr1 = techage.needs_power2(old_state) local pwr1 = techage.needs_power2(old_state)
local pwr2 = techage.needs_power2(new_state) local pwr2 = techage.needs_power2(new_state)
if pwr1 ~= pwr2 then if pwr1 ~= pwr2 then

View File

@ -85,6 +85,12 @@ else
dofile(MP.."/steam_engine/cylinder.lua") dofile(MP.."/steam_engine/cylinder.lua")
dofile(MP.."/steam_engine/flywheel.lua") dofile(MP.."/steam_engine/flywheel.lua")
-- Liquids I
dofile(MP.."/liquids/liquid_pipe.lua")
dofile(MP.."/liquids/liquid.lua")
dofile(MP.."/liquids/liquid_lib.lua")
dofile(MP.."/liquids/fuel_lib.lua")
-- Basic Machines -- Basic Machines
dofile(MP.."/basic_machines/consumer.lua") -- consumer base model dofile(MP.."/basic_machines/consumer.lua") -- consumer base model
dofile(MP.."/basic_machines/source.lua") dofile(MP.."/basic_machines/source.lua")
@ -100,14 +106,10 @@ else
dofile(MP.."/basic_machines/funnel.lua") dofile(MP.."/basic_machines/funnel.lua")
dofile(MP.."/basic_machines/liquidsampler.lua") dofile(MP.."/basic_machines/liquidsampler.lua")
-- -- Liquids -- Liquids II
dofile(MP.."/liquids/liquid_pipe.lua")
dofile(MP.."/liquids/liquid.lua")
dofile(MP.."/liquids/liquid_lib.lua")
dofile(MP.."/liquids/tank.lua") dofile(MP.."/liquids/tank.lua")
dofile(MP.."/liquids/silo.lua") dofile(MP.."/liquids/silo.lua")
dofile(MP.."/liquids/pump.lua") dofile(MP.."/liquids/pump.lua")
dofile(MP.."/liquids/fuel_lib.lua")
-- Coal power station -- Coal power station
dofile(MP.."/coal_power_station/firebox.lua") dofile(MP.."/coal_power_station/firebox.lua")
@ -141,17 +143,17 @@ else
dofile(MP.."/lamps/industriallamp3.lua") dofile(MP.."/lamps/industriallamp3.lua")
-- -- Oil -- -- Oil
-- dofile(MP.."/oil/explore.lua") dofile(MP.."/oil/explore.lua")
-- dofile(MP.."/oil/tower.lua") dofile(MP.."/oil/tower.lua")
-- dofile(MP.."/oil/drillbox.lua") dofile(MP.."/oil/drillbox.lua")
-- dofile(MP.."/oil/pumpjack.lua") dofile(MP.."/oil/pumpjack.lua")
-- dofile(MP.."/oil/distiller.lua") dofile(MP.."/oil/distiller.lua")
-- dofile(MP.."/oil/reboiler.lua") dofile(MP.."/oil/reboiler.lua")
-- dofile(MP.."/oil/gasflare.lua") -- dofile(MP.."/oil/gasflare.lua")
-- TA3 power based -- TA3 power based
--dofile(MP.."/ta3_power/tiny_generator.lua") dofile(MP.."/ta3_power/tiny_generator.lua")
--dofile(MP.."/ta3_power/akkubox.lua") dofile(MP.."/ta3_power/akkubox.lua")
-- Logic -- Logic
dofile(MP.."/logic/lib.lua") dofile(MP.."/logic/lib.lua")

43
items/hydrogen.lua Normal file
View File

@ -0,0 +1,43 @@
--[[
TechAge
=======
Copyright (C) 2019 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
TA4 Hydrogen
]]--
local S = techage.S
minetest.register_craftitem("techage:hydrogen", {
description = S("TA4 Hydrogen"),
inventory_image = "techage_hydrogen_inv.png",
})
minetest.register_craftitem("techage:cylinder_small_hydrogen", {
description = S("Hydrogen Cylinder Small"),
inventory_image = "techage_gas_cylinder_small.png^[colorize:#00528A:120",
stack_max = 1,
})
minetest.register_craftitem("techage:cylinder_large_hydrogen", {
description = S("Hydrogen Cylinder Large"),
inventory_image = "techage_gas_cylinder_large.png^[colorize:#00528A:120",
stack_max = 1,
})
techage.register_liquid("techage:hydrogen", "", 1, "techage:hydrogen")
techage.register_liquid("techage:cylinder_small_hydrogen", "techage:ta3_cylinder_small", 1, "techage:hydrogen")
techage.register_liquid("techage:cylinder_large_hydrogen", "techage:ta3_cylinder_large", 6, "techage:hydrogen")
techage.recipes.add("ta4_doser", {
output = "techage:hydrogen 1",
input = {
"techage:gas 1",
}
})

View File

@ -25,6 +25,7 @@ local Burntime = techage.firebox.Burntime
techage.fuel = {} techage.fuel = {}
local CAPACITY = 50 local CAPACITY = 50
local BLOCKING_TIME = 0.3 -- 300ms
techage.fuel.CAPACITY = CAPACITY techage.fuel.CAPACITY = CAPACITY
@ -35,7 +36,7 @@ techage.fuel.BT_FUELOIL = 2
techage.fuel.BT_NAPHTHA = 1 techage.fuel.BT_NAPHTHA = 1
local function formspec_fuel(x, y, nvm) function techage.fuel.fuel_container(x, y, nvm)
local itemname = "" local itemname = ""
if nvm.liquid and nvm.liquid.name and nvm.liquid.amount and nvm.liquid.amount > 0 then if nvm.liquid and nvm.liquid.name and nvm.liquid.amount and nvm.liquid.amount > 0 then
itemname = nvm.liquid.name.." "..nvm.liquid.amount itemname = nvm.liquid.name.." "..nvm.liquid.amount
@ -44,27 +45,25 @@ local function formspec_fuel(x, y, nvm)
if nvm.running then if nvm.running then
fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1) fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
end end
local tooltip = S("To add fuel punch\nthis block\nwith a fuel container")
return "container["..x..","..y.."]".. return "container["..x..","..y.."]"..
"background[0,0;3,1.05;techage_form_grey.png]".. "box[0,0;1.05,2.1;#000000]"..
"list[context;fuel;0,0;1,1;]".. "tooltip[0,0;1.1,1.1;"..tooltip..";#0C3D32;#FFFFFF]"..
techage.item_image(1, 0, itemname).. "image[0.1,0.1;1,1;default_furnace_fire_bg.png^[lowpart:"..
"image[2,0;1,1;default_furnace_fire_bg.png^[lowpart:"..
fuel_percent..":default_furnace_fire_fg.png]".. fuel_percent..":default_furnace_fire_fg.png]"..
techage.item_image(0.1, 1.1, itemname)..
"container_end[]" "container_end[]"
end end
techage.fuel.formspec_fuel = formspec_fuel
function techage.fuel.formspec(nvm) function techage.fuel.formspec(nvm)
local update = ((nvm.countdown or 0) > 0 and nvm.countdown) or S("Update") local title = S("Fuel Menu")
return "size[8,5]".. return "size[4,3]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
formspec_fuel(1, 0, nvm).. "box[0,-0.1;3.8,0.5;#c6e8ff]"..
"button[5,0;2,1;update;"..update.."]".. "label[1,-0.1;"..minetest.colorize("#000000", title).."]"..
"list[current_player;main;0,1.3;8,4;]" techage.fuel.fuel_container(1.5, 1, nvm)
end end
local function fill_container(pos, inv, nvm) local function fill_container(pos, inv, nvm)
@ -163,9 +162,9 @@ function techage.fuel.can_dig(pos, player)
return inv:is_empty("fuel") and nvm.liquid.amount == 0 return inv:is_empty("fuel") and nvm.liquid.amount == 0
end end
function techage.fuel.on_rightclick(pos) function techage.fuel.on_rightclick(pos, node, clicker)
techage.set_activeformspec(pos, clicker)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
nvm.countdown = 10
M(pos):set_string("formspec", techage.fuel.formspec(nvm)) M(pos):set_string("formspec", techage.fuel.formspec(nvm))
end end
@ -196,3 +195,69 @@ end
function techage.fuel.valid_fuel(name, category) function techage.fuel.valid_fuel(name, category)
return ValidOilFuels[name] and ValidOilFuels[name] <= category return ValidOilFuels[name] and ValidOilFuels[name] <= category
end end
-- check if the given empty container can be replaced by a full
-- container and added to the players inventory
local function fill(nvm, empty_container, item_count, puncher)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
local full_container = liquid.get_full_container(empty_container, nvm.liquid.name)
if empty_container and full_container then
local item = ItemStack(full_container) -- to be added
local ldef = liquid.get_liquid_def(full_container)
if ldef and nvm.liquid.amount - ldef.size >= 0 then
if item_count > 1 then -- can't be simply replaced?
-- check for extra free space
local inv = puncher:get_inventory()
if inv:room_for_item("main", item) then
-- add full container and return
-- the empty once - 1
inv:add_item("main", item)
item = {name = empty_container, count = item_count - 1}
else
return -- no free space
end
end
nvm.liquid.amount = nvm.liquid.amount - ldef.size
if nvm.liquid.amount == 0 then
nvm.liquid.name = nil
end
return item -- to be added to the players inv.
end
end
end
local function empty(nvm, full_container)
nvm.liquid = nvm.liquid or {}
nvm.liquid.amount = nvm.liquid.amount or 0
local ldef = liquid.get_liquid_def(full_container)
if ldef and ValidOilFuels[ldef.inv_item] then
if not nvm.liquid.name or ldef.inv_item == nvm.liquid.name then
if nvm.liquid.amount + ldef.size <= CAPACITY then
nvm.liquid.amount = nvm.liquid.amount + ldef.size
nvm.liquid.name = ldef.inv_item
return ItemStack(ldef.container)
end
end
end
end
function techage.fuel.on_punch(pos, node, puncher, pointed_thing)
local nvm = techage.get_nvm(pos)
local mem = techage.get_mem(pos)
mem.blocking_time = mem.blocking_time or 0
if mem.blocking_time > techage.SystemTime then
return
end
local wielded_item = puncher:get_wielded_item():get_name()
local item_count = puncher:get_wielded_item():get_count()
local new_item = fill(nvm, wielded_item, item_count, puncher)
or empty(nvm, wielded_item)
if new_item then
puncher:set_wielded_item(ItemStack(new_item))
M(pos):set_string("formspec", techage.fuel.formspec(pos, nvm))
mem.blocking_time = techage.SystemTime + BLOCKING_TIME
return
end
end

View File

@ -74,7 +74,7 @@ local function delete_netID(pos, outdir)
end end
end end
end) end)
networks.delete_network(netID, Pipe) networks.delete_network("pipe2", netID)
end end
local function get_netID(pos, outdir) local function get_netID(pos, outdir)
@ -88,16 +88,19 @@ end
local function get_network_table(pos, outdir, ntype) local function get_network_table(pos, outdir, ntype)
local netID = get_netID(pos, outdir) local netID = get_netID(pos, outdir)
print(1)
if netID then if netID then
print(2)
local netw = networks.get_network("pipe2", netID) local netw = networks.get_network("pipe2", netID)
if not netw then if not netw then
print(3)
netw = networks.collect_network_nodes(pos, outdir, Pipe) netw = networks.collect_network_nodes(pos, outdir, Pipe)
networks.set_network("pipe2", netID, netw) networks.set_network("pipe2", netID, netw)
end end
local s = minetest.pos_to_string(minetest.get_position_from_hash(netID)) print("netw", string.format("%012X", netID), dump(netw))
--print("netw", string.format("%012X", netID), s, dump(netw))
return netw[ntype] or {} return netw[ntype] or {}
end end
print(4)
return {} return {}
end end

View File

@ -77,7 +77,7 @@ Oil Drill Box=Ölbohrkiste
Oil Pumpjack=Ölpumpe Oil Pumpjack=Ölpumpe
Oil Source=Erdöl Oil Source=Erdöl
Oil Tank=Öltank Oil Tank=Öltank
Oil amount:=Ölmenge: Oil amount=Ölmenge
Other consumers=Weitere Verbraucher Other consumers=Weitere Verbraucher
Outp=Ergeb. Outp=Ergeb.
Plan=Plan Plan=Plan

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -19,7 +19,7 @@ local S = techage.S
-- Consumer Related Data -- Consumer Related Data
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
local STANDBY_TICKS = 4 local STANDBY_TICKS = 1
local COUNTDOWN_TICKS = 6 local COUNTDOWN_TICKS = 6
local CYCLE_TIME = 16 local CYCLE_TIME = 16
@ -31,21 +31,24 @@ local formspec0 = "size[5,4]"..
"button_exit[1,3.2;3,1;build;"..S("Build derrick").."]" "button_exit[1,3.2;3,1;build;"..S("Build derrick").."]"
local function play_sound(pos) local function play_sound(pos)
local nvm = techage.get_nvm(pos) local mem = techage.get_mem(pos)
if nvm.techage_state == techage.RUNNING then if not mem.handle or mem.handle == -1 then
nvm.handle = minetest.sound_play("techage_oildrill", { mem.handle = minetest.sound_play("techage_oildrill", {
pos = pos, pos = pos,
gain = 1, gain = 1,
max_hear_distance = 15}) max_hear_distance = 15,
minetest.after(4, play_sound, pos) loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end end
end end
local function stop_sound(pos) local function stop_sound(pos)
local nvm = techage.get_nvm(pos) local mem = techage.get_mem(pos)
if nvm.handle then if mem.handle then
minetest.sound_stop(nvm.handle) minetest.sound_stop(mem.handle)
nvm.handle = nil mem.handle = nil
end end
end end
@ -104,8 +107,9 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
return stack:get_count() return stack:get_count()
end end
local function on_rightclick(pos) local function on_rightclick(pos, node, clicker)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
techage.set_activeformspec(pos, clicker)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm)) M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
end end
@ -118,6 +122,7 @@ local function on_node_state_change(pos, old_state, new_state)
end end
local function drilling(pos, crd, nvm, inv) local function drilling(pos, crd, nvm, inv)
print("drilling")
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm)) M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
nvm.drill_pos = nvm.drill_pos or {x=pos.x, y=pos.y-1, z=pos.z} nvm.drill_pos = nvm.drill_pos or {x=pos.x, y=pos.y-1, z=pos.z}
local owner = M(pos):get_string("owner") local owner = M(pos):get_string("owner")
@ -127,12 +132,12 @@ local function drilling(pos, crd, nvm, inv)
local ndef = minetest.registered_nodes[node.name] local ndef = minetest.registered_nodes[node.name]
if not inv:contains_item("src", ItemStack("techage:oil_drillbit")) then if not inv:contains_item("src", ItemStack("techage:oil_drillbit")) then
crd.State:idle(pos, nvm) crd.State:idle(pos, nvm, S("Drill bits missing"))
elseif curr_depth >= depth then elseif curr_depth >= depth then
M(pos):set_string("oil_found", "true") M(pos):set_string("oil_found", "true")
crd.State:stop(pos, nvm) crd.State:stop(pos, nvm)
elseif minetest.is_protected(nvm.drill_pos, owner) then elseif minetest.is_protected(nvm.drill_pos, owner) then
crd.State:fault(pos, nvm) crd.State:fault(pos, nvm, S("Drill area is protected"))
elseif node.name == "techage:oil_drillbit2" then elseif node.name == "techage:oil_drillbit2" then
nvm.drill_pos.y = nvm.drill_pos.y-1 nvm.drill_pos.y = nvm.drill_pos.y-1
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
@ -156,7 +161,7 @@ local function drilling(pos, crd, nvm, inv)
nvm.drill_pos.y = nvm.drill_pos.y-1 nvm.drill_pos.y = nvm.drill_pos.y-1
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
else else
crd.State:fault(pos, nvm) crd.State:fault(pos, nvm, S("block can't be dug"))
end end
end end
@ -167,7 +172,9 @@ local function keep_running(pos, elapsed)
if inv then if inv then
drilling(pos, crd, nvm, inv) drilling(pos, crd, nvm, inv)
end end
return crd.State:is_active(nvm) if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
end
end end
local function can_dig(pos, player) local function can_dig(pos, player)
@ -196,6 +203,7 @@ local function on_receive_fields(pos, formname, fields, player)
else else
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
if not nvm.assemble_locked and M(pos):get_string("oil_found") ~= "true" then if not nvm.assemble_locked and M(pos):get_string("oil_found") ~= "true" then
local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, nvm, fields) CRD(pos).State:state_button_event(pos, nvm, fields)
end end
end end
@ -245,8 +253,12 @@ local tubing = {
return "unsupported" return "unsupported"
end end
end, end,
on_node_load = function(pos) on_node_load = function(pos, node)
CRD(pos).State:on_node_load(pos) CRD(pos).State:on_node_load(pos)
local nvm = techage.get_nvm(pos)
if nvm.techage_state == techage.RUNNING then
play_sound(pos)
end
end, end,
} }
@ -295,17 +307,3 @@ minetest.register_craft({
{"default:steel_ingot", "techage:vacuum_tube", "default:steel_ingot"}, {"default:steel_ingot", "techage:vacuum_tube", "default:steel_ingot"},
}, },
}) })
minetest.register_lbm({
label = "[techage] Oil Tower sound",
name = "techage:oil_tower",
nodenames = {"techage:ta3_drillbox_pas", "techage:ta3_drillbox_act"},
run_at_every_load = true,
action = function(pos, node)
local nvm = techage.get_nvm(pos)
nvm.assemble_locked = false
if nvm.techage_state == techage.RUNNING then
play_sound(pos)
end
end
})

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -24,7 +24,7 @@ local liquid = techage.liquid
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).consumer end local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).consumer end
local STANDBY_TICKS = 10 local STANDBY_TICKS = 1
local COUNTDOWN_TICKS = 10 local COUNTDOWN_TICKS = 10
local CYCLE_TIME = 8 local CYCLE_TIME = 8
@ -52,53 +52,85 @@ local function formspec(self, pos, nvm)
amount = techage.explore.get_oil_amount(P(storage_pos)) amount = techage.explore.get_oil_amount(P(storage_pos))
end end
return "size[5,3]".. return "size[5,3]"..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"image[0.5,0;1,1;techage_liquid2_inv.png^[colorize:#000000^techage_liquid1_inv.png]".. "box[0,-0.1;4.8,0.5;#c6e8ff]"..
"image[2,0;1,1;"..techage.get_power_image(pos, nvm).."]".. "label[1.5,-0.1;"..minetest.colorize( "#000000", S("Pumpjack")).."]"..
"label[0,1.3;"..S("Oil amount:")..": "..amount.."]".. "image[0.5,1.4;1,1;techage_liquid2_inv.png^[colorize:#000000^techage_liquid1_inv.png]"..
"button[3,1.1;2,1;update;"..S("Update").."]".. "image[4,0.8;1,1;"..techage.get_power_image(pos, nvm).."]"..
"image_button[2,2.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]" "tooltip[4,0.8;1,1;"..S("needs power").."]"..
"label[0,2.5;"..S("Oil amount")..": "..amount.."]"..
"image_button[2.5,2.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"
end
local function play_sound(pos)
local mem = techage.get_mem(pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_reboiler", {
pos = pos,
gain = 1,
max_hear_distance = 15,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end
local function stop_sound(pos)
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end
local function on_node_state_change(pos, old_state, new_state)
if new_state == techage.RUNNING then
play_sound(pos)
else
stop_sound(pos)
end
end end
local function on_rightclick(pos, node, clicker) local function on_rightclick(pos, node, clicker)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
techage.set_activeformspec(pos, clicker)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm)) M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
end end
local function pumping(pos, crd, meta, nvm) local function pumping(pos, crd, meta, nvm)
if has_oil(pos, meta) then if has_oil(pos, meta) then
local leftover = liquid.put(pos, 6, "techage:oil_source", 1) local leftover = liquid.put(pos, 6, "techage:oil_source", 1)
print("pumping", dump(leftover))
if leftover and leftover > 0 then if leftover and leftover > 0 then
crd.State:blocked(pos, nvm) crd.State:blocked(pos, nvm)
stop_sound(pos)
return return
end end
dec_oil_item(pos, meta) dec_oil_item(pos, meta)
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
return return
end end
crd.State:fault(pos, nvm) crd.State:fault(pos, nvm, S("no oil"))
end end
local function keep_running(pos, elapsed) local function keep_running(pos, elapsed)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local crd = CRD(pos) local crd = CRD(pos)
pumping(pos, crd, M(pos), nvm) pumping(pos, crd, M(pos), nvm)
return crd.State:is_active(nvm) if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
end
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
if fields.update then local nvm = techage.get_nvm(pos)
local nvm = techage.get_nvm(pos) CRD(pos).State:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
else
local nvm = techage.get_nvm(pos)
CRD(pos).State:state_button_event(pos, nvm, fields)
end
end end
local tiles = {} local tiles = {}
@ -149,8 +181,11 @@ local tubing = {
return "unsupported" return "unsupported"
end end
end, end,
on_node_load = function(pos) on_node_load = function(pos, node)
CRD(pos).State:on_node_load(pos) CRD(pos).State:on_node_load(pos)
if node.name == "techage:ta3_pumpjack_act" then
play_sound(pos)
end
end, end,
} }
@ -160,6 +195,7 @@ local _, node_name_ta3, _ =
standby_ticks = STANDBY_TICKS, standby_ticks = STANDBY_TICKS,
formspec = formspec, formspec = formspec,
tubing = tubing, tubing = tubing,
on_state_change = on_node_state_change,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}) local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
if node.name == "techage:oil_drillbit2" then if node.name == "techage:oil_drillbit2" then
@ -176,9 +212,7 @@ local _, node_name_ta3, _ =
ntype = "pump", ntype = "pump",
}, },
}, },
tubelib2_on_update2 = function(pos, outdir, tlib2, node) power_sides = {F=1, B=1, L=1, R=1, D=1},
liquid.update_network(pos, outdir)
end,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
node_timer = keep_running, node_timer = keep_running,

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -27,6 +27,28 @@ local CYCLE_TIME = 6
local CAPA = 12 local CAPA = 12
local PWR_NEEDED = 14 local PWR_NEEDED = 14
local function play_sound(pos)
local mem = techage.get_mem(pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_reboiler", {
pos = pos,
gain = 1,
max_hear_distance = 15,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end
local function stop_sound(pos)
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end
local function swap_node(pos, on) local function swap_node(pos, on)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
if on then if on then
@ -34,10 +56,7 @@ local function swap_node(pos, on)
node.name = "techage:ta3_reboiler_on" node.name = "techage:ta3_reboiler_on"
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
minetest.get_node_timer(pos):start(CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME)
minetest.sound_play("techage_reboiler", { play_sound(pos)
pos = pos,
gain = 1,
max_hear_distance = 10})
elseif not on and nvm.running then elseif not on and nvm.running then
local node = techage.get_node_lvm(pos) local node = techage.get_node_lvm(pos)
node.name = "techage:ta3_reboiler" node.name = "techage:ta3_reboiler"
@ -45,16 +64,15 @@ local function swap_node(pos, on)
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
nvm.running = false nvm.running = false
power.consumer_stop(pos, Cable) power.consumer_stop(pos, Cable)
stop_sound(pos)
end end
end end
local function on_power(pos, nvm) local function on_power(pos)
if nvm.running then swap_node(pos, true)
swap_node(pos, true)
end
end end
local function on_nopower(pos, nvm) local function on_nopower(pos)
swap_node(pos, false) swap_node(pos, false)
end end
@ -99,34 +117,32 @@ local function node_timer(pos, elapsed)
swap_node(pos, false) swap_node(pos, false)
return false return false
end end
minetest.sound_play("techage_reboiler", {
pos = pos,
gain = 1,
max_hear_distance = 10})
return true return true
end end
swap_node(pos, false) swap_node(pos, false)
return false return false
end end
-- liquid local function after_place_node(pos)
local function tubelib2_on_update2(pos, outdir, tlib2, node) Pipe:after_place_node(pos)
liquid.update_network(pos, outdir) Cable:after_place_node(pos)
end end
-- power local function after_dig_node(pos, oldnode)
local function after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir)
power.after_tube_update2(node, pos, out_dir, peer_pos, peer_in_dir)
end
local function after_dig_node(pos, oldnode, oldmetadata, digger)
Pipe:after_dig_node(pos) Pipe:after_dig_node(pos)
power.after_dig_node(pos, oldnode) Cable:after_dig_node(pos)
techage.del_mem(pos) techage.del_mem(pos)
end end
local _liquid = { local function tubelib2_on_update2(pos, outdir, tlib2, node)
if tlib2 == Pipe then
liquid.update_network(pos, outdir)
else
power.update_network(pos, outdir, tlib2)
end
end
local liquid_def = {
capa = CAPA, capa = CAPA,
peek = liquid.srv_peek, peek = liquid.srv_peek,
put = function(pos, indir, name, amount) put = function(pos, indir, name, amount)
@ -148,11 +164,18 @@ local _liquid = {
take = liquid.srv_take, take = liquid.srv_take,
} }
local _networks = { local net_def = {
pipe2 = { pipe2 = {
sides = {L = true, R = true}, -- Pipe connection sides sides = {L = true, R = true}, -- Pipe connection sides
ntype = "tank", ntype = "tank",
}, },
ele1 = {
sides = techage.networks.AllSides, -- Cable connection sides
ntype = "con1",
on_power = on_power,
on_nopower = on_nopower,
nominal = PWR_NEEDED,
},
} }
minetest.register_node("techage:ta3_reboiler", { minetest.register_node("techage:ta3_reboiler", {
@ -177,12 +200,13 @@ minetest.register_node("techage:ta3_reboiler", {
power.after_place_node(pos) power.after_place_node(pos)
end, end,
tubelib2_on_update2 = tubelib2_on_update2, -- liquid tubelib2_on_update2 = tubelib2_on_update2,
after_tube_update = after_tube_update, -- power
on_timer = node_timer, on_timer = node_timer,
after_place_node = after_place_node,
after_dig_node = after_dig_node, after_dig_node = after_dig_node,
liquid = _liquid, after_dig_node = after_dig_node,
networks = _networks, liquid = liquid_def,
networks = net_def,
paramtype2 = "facedir", paramtype2 = "facedir",
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
@ -199,34 +223,32 @@ minetest.register_node("techage:ta3_reboiler_on", {
"techage_filling_ta3.png^techage_frame_ta3.png", "techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_hole_pipe.png^techage_frame_ta3.png", "techage_filling_ta3.png^techage_appl_hole_pipe.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_appl_hole_pipe.png^techage_frame_ta3.png", "techage_filling_ta3.png^techage_appl_hole_pipe.png^techage_frame_ta3.png",
{ {
image = "techage_filling4_ta3.png^techage_appl_reboiler4.png^techage_frame4_ta3.png^[transformFX", image = "techage_filling4_ta3.png^techage_appl_reboiler4.png^techage_frame4_ta3.png^[transformFX",
backface_culling = false, backface_culling = false,
animation = { animation = {
type = "vertical_frames", type = "vertical_frames",
aspect_w = 32, aspect_w = 32,
aspect_h = 32, aspect_h = 32,
length = 2.0, length = 2.0,
},
}, },
}, {
{ image = "techage_filling4_ta3.png^techage_appl_reboiler4.png^techage_frame4_ta3.png",
image = "techage_filling4_ta3.png^techage_appl_reboiler4.png^techage_frame4_ta3.png", backface_culling = false,
backface_culling = false, animation = {
animation = { type = "vertical_frames",
type = "vertical_frames", aspect_w = 32,
aspect_w = 32, aspect_h = 32,
aspect_h = 32, length = 2.0,
length = 2.0, },
}, },
}, },
},
tubelib2_on_update2 = tubelib2_on_update2, -- liquid tubelib2_on_update2 = tubelib2_on_update2,
after_tube_update = after_tube_update, -- power
on_timer = node_timer, on_timer = node_timer,
after_dig_node = after_dig_node, liquid = liquid_def,
liquid = _liquid, networks = net_def,
networks = _networks,
paramtype2 = "facedir", paramtype2 = "facedir",
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
@ -236,19 +258,8 @@ minetest.register_node("techage:ta3_reboiler_on", {
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
}) })
--
-- Liquids
--
Pipe:add_secondary_node_names({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}) Pipe:add_secondary_node_names({"techage:ta3_reboiler", "techage:ta3_reboiler_on"})
Cable:add_secondary_node_names({"techage:ta3_reboiler", "techage:ta3_reboiler_on"})
--
-- Power
--
techage.power.enrich_node({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, {
power_network = Cable,
on_power = on_power,
on_nopower = on_nopower,
})
minetest.register_craft({ minetest.register_craft({
output = "techage:ta3_reboiler", output = "techage:ta3_reboiler",

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2020 Joachim Stolberg
GPL v3 GPL v3
See LICENSE.txt for more information See LICENSE.txt for more information

View File

@ -72,7 +72,7 @@ local function delete_netID(pos, outdir, Cable)
end end
end end
end) end)
networks.delete_network(netID, Cable) networks.delete_network(Cable.tube_type, netID)
end end
-- Keep the network up and running -- Keep the network up and running

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -34,13 +34,15 @@ end
local function play_sound(pos) local function play_sound(pos)
local mem = techage.get_mem(pos) local mem = techage.get_mem(pos)
mem.handle = minetest.sound_play("techage_steamengine", { if not mem.handle or mem.handle == -1 then
pos = pos, mem.handle = minetest.sound_play("techage_steamengine", {
gain = 0.5, pos = pos,
max_hear_distance = 10, gain = 0.5,
loop = true}) max_hear_distance = 10,
if mem.handle == -1 then loop = true})
minetest.after(1, play_sound, pos) if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end end
end end

View File

@ -29,45 +29,61 @@ local PWR_CAPA = 12
local EFFICIENCY = 2.5 local EFFICIENCY = 2.5
local function formspec(self, pos, nvm) local function formspec(self, pos, nvm)
local fuel_percent = 0 return "size[5,4]"..
if nvm.running then
fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
end
return "size[8,6]"..
--"box[0,-0.1;3.8,0.5;#c6e8ff]"..
--"label[1,-0.1;"..minetest.colorize( "#000000", S("Tiny Generator")).."]"..
--power.formspec_label_bar(0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
fuel.formspec_fuel(1, 0, nvm).. "box[0,-0.1;4.8,0.5;#c6e8ff]"..
"button[1.6,1;1.8,1;update;"..S("Update").."]".. "label[1.5,-0.1;"..minetest.colorize( "#000000", S("Tiny Generator")).."]"..
"image_button[5.5,0.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. fuel.fuel_container(0, 0.9, nvm)..
"image[6.5,0;1,2;"..power.formspec_power_bar(PWR_CAPA, nvm.provided).."]".. "image[1.4,1.6;1,1;techage_form_arrow_bg.png^[transformR270]"..
"list[current_player;main;0,2.3;8,4;]".. "image_button[1.4,3.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
default.get_hotbar_bg(0, 3) "tooltip[1.5,3;1,1;"..self:get_state_tooltip(nvm).."]"..
power.formspec_label_bar(2.5, 0.8, S("power"), PWR_CAPA, nvm.provided)
end
local function play_sound(pos)
local mem = techage.get_mem(pos)
if not mem.handle or mem.handle == -1 then
mem.handle = minetest.sound_play("techage_generator", {
pos = pos,
gain = 1,
max_hear_distance = 10,
loop = true})
if mem.handle == -1 then
minetest.after(1, play_sound, pos)
end
end
end
local function stop_sound(pos)
local mem = techage.get_mem(pos)
if mem.handle then
minetest.sound_stop(mem.handle)
mem.handle = nil
end
end end
local function can_start(pos, nvm, state) local function can_start(pos, nvm, state)
if nvm.burn_cycles > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0) then if nvm.burn_cycles > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0) then
return true return true
end end
return false return S("no fuel")
end end
local function start_node(pos, nvm, state) local function start_node(pos, nvm, state)
nvm.running = true nvm.running = true -- needed by fuel_lib
power.generator_start(pos, nvm, PWR_CAPA) local outdir = M(pos):get_int("outdir")
minetest.sound_play("techage_generator", { power.generator_start(pos, Cable, CYCLE_TIME, outdir)
pos = pos, play_sound(pos)
gain = 1,
max_hear_distance = 10})
end end
local function stop_node(pos, nvm, state) local function stop_node(pos, nvm, state)
nvm.running = false nvm.running = false
nvm.provided = 0 nvm.provided = 0
power.generator_stop(pos, nvm) local outdir = M(pos):get_int("outdir")
power.generator_stop(pos, Cable, outdir)
stop_sound(pos)
end end
local State = techage.NodeStates:new({ local State = techage.NodeStates:new({
@ -96,7 +112,8 @@ local function burning(pos, nvm)
return true return true
else else
nvm.liquid.name = nil nvm.liquid.name = nil
State:fault(pos, nvm) State:fault(pos, nvm, S("no fuel"))
stop_sound(pos)
return false return false
end end
else else
@ -106,17 +123,16 @@ end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local outdir = M(pos):get_int("outdir")
if nvm.running and burning(pos, nvm) then if nvm.running and burning(pos, nvm) then
nvm.provided = power.generator_alive(pos, nvm) nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir)
minetest.sound_play("techage_generator", {
pos = pos,
gain = 1,
max_hear_distance = 10})
return true
else else
nvm.provided = 0 nvm.provided = 0
end end
return false if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return true
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
@ -125,42 +141,50 @@ local function on_receive_fields(pos, formname, fields, player)
end end
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
State:state_button_event(pos, nvm, fields) State:state_button_event(pos, nvm, fields)
M(pos):set_string("formspec", formspec(State, pos, nvm)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
local function on_rightclick(pos, node, clicker)
local function formspec_clbk(pos, nvm) techage.set_activeformspec(pos, clicker)
return formspec(State, pos, nvm)
end
local function on_metadata_inventory_put(pos, listname, index, stack, player)
minetest.after(0.5, fuel.move_item, pos, stack, formspec_clbk)
end
local function on_rightclick(pos)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm)) M(pos):set_string("formspec", formspec(State, pos, nvm))
end end
local _liquid = { local liquid_def = {
fuel_cat = fuel.BT_NAPHTHA, fuel_cat = fuel.BT_NAPHTHA,
capa = fuel.CAPACITY, capa = fuel.CAPACITY,
peek = liquid.srv_peek, peek = liquid.srv_peek,
put = function(pos, indir, name, amount) put = function(pos, indir, name, amount)
if fuel.valid_fuel(name, fuel.BT_NAPHTHA) then if fuel.valid_fuel(name, fuel.BT_OIL) then
return liquid.srv_put(pos, indir, name, amount) local res = liquid.srv_put(pos, indir, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return res
end end
return amount return amount
end, end,
take = liquid.srv_take, take = function(pos, indir, name, amount)
amount, name = liquid.srv_take(pos, indir, name, amount)
if techage.is_activeformspec(pos) then
local nvm = techage.get_nvm(pos)
M(pos):set_string("formspec", formspec(State, pos, nvm))
end
return amount, name
end
} }
local _networks = { local net_def = {
pipe = { pipe2 = {
sides = techage.networks.AllSides, -- Pipe connection sides sides = techage.networks.AllSides, -- Pipe connection sides
ntype = "tank", ntype = "tank",
}, },
ele1 = {
sides = {R = 1},
ntype = "gen1",
nominal = PWR_CAPA,
},
} }
minetest.register_node("techage:tiny_generator", { minetest.register_node("techage:tiny_generator", {
@ -179,28 +203,23 @@ minetest.register_node("techage:tiny_generator", {
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
is_ground_content = false, is_ground_content = false,
on_construct = function(pos) after_place_node = function(pos)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local number = techage.add_node(pos, "techage:tiny_generator") local number = techage.add_node(pos, "techage:tiny_generator")
nvm.running = false nvm.running = false
nvm.burn_cycles = 0 nvm.burn_cycles = 0
State:node_init(pos, nvm, number) State:node_init(pos, nvm, number)
local meta = M(pos) M(pos):set_string("formspec", formspec(State, pos, nvm))
meta:set_string("formspec", formspec(State, pos, nvm)) M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
end, end,
allow_metadata_inventory_put = fuel.allow_metadata_inventory_put,
allow_metadata_inventory_take = fuel.allow_metadata_inventory_take,
on_metadata_inventory_put = on_metadata_inventory_put,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
on_punch = fuel.on_punch,
on_timer = node_timer, on_timer = node_timer,
can_dig = fuel.can_dig, can_dig = fuel.can_dig,
liquid = _liquid, liquid = liquid_def,
networks = _networks, networks = net_def,
}) })
minetest.register_node("techage:tiny_generator_on", { minetest.register_node("techage:tiny_generator_on", {
@ -241,23 +260,17 @@ minetest.register_node("techage:tiny_generator_on", {
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
is_ground_content = false, is_ground_content = false,
allow_metadata_inventory_put = fuel.allow_metadata_inventory_put,
allow_metadata_inventory_take = fuel.allow_metadata_inventory_take,
on_metadata_inventory_put = on_metadata_inventory_put,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
on_punch = fuel.on_punch,
on_timer = node_timer, on_timer = node_timer,
can_dig = fuel.can_dig, can_dig = fuel.can_dig,
liquid = _liquid, liquid = liquid_def,
networks = _networks, networks = net_def,
}) })
Pipe:add_secondary_node_names({"techage:tiny_generator", "techage:tiny_generator_on"}) Pipe:add_secondary_node_names({"techage:tiny_generator", "techage:tiny_generator_on"})
Cable:add_secondary_node_names({"techage:tiny_generator", "techage:tiny_generator_on"})
techage.power.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, {
conn_sides = {"R"},
power_network = Power,
})
techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, { techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, {
on_recv_message = function(pos, src, topic, payload) on_recv_message = function(pos, src, topic, payload)
@ -268,8 +281,11 @@ techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, {
return State:on_receive_message(pos, topic, payload) return State:on_receive_message(pos, topic, payload)
end end
end, end,
on_node_load = function(pos) on_node_load = function(pos, node)
State:on_node_load(pos) State:on_node_load(pos)
if node.name == "techage:tiny_generator_on" then
play_sound(pos)
end
end, end,
}) })