2019-03-19 00:40:17 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
|
|
|
Copyright (C) 2019 Joachim Stolberg
|
|
|
|
|
2019-08-22 21:49:47 +03:00
|
|
|
GPL v3
|
2019-03-19 00:40:17 +03:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
2019-05-05 23:29:00 +03:00
|
|
|
TA3 Coal Power Station Boiler Top
|
2019-03-19 00:40:17 +03:00
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
|
|
|
local M = minetest.get_meta
|
2019-07-02 22:33:12 +03:00
|
|
|
local S = techage.S
|
2019-03-19 00:40:17 +03:00
|
|
|
|
|
|
|
local CYCLE_TIME = 4
|
|
|
|
local STANDBY_TICKS = 2
|
2019-06-21 00:44:04 +03:00
|
|
|
local COUNTDOWN_TICKS = 20
|
2019-03-19 00:40:17 +03:00
|
|
|
local HEAT_STEP = 10
|
2019-05-21 17:37:05 +03:00
|
|
|
local WATER_CONSUMPTION = 0.1
|
2019-03-19 00:40:17 +03:00
|
|
|
local MAX_WATER = 10
|
|
|
|
|
|
|
|
local Pipe = techage.SteamPipe
|
|
|
|
|
2019-06-16 22:06:16 +03:00
|
|
|
local function transfer(pos, topic, payload)
|
|
|
|
return techage.transfer(pos, "F", topic, payload, Pipe,
|
|
|
|
{"techage:turbine", "techage:turbine_on"})
|
|
|
|
end
|
|
|
|
|
2019-03-19 00:40:17 +03:00
|
|
|
local Water = {
|
|
|
|
["bucket:bucket_river_water"] = true,
|
|
|
|
["bucket:bucket_water"] = true,
|
|
|
|
["bucket:bucket_empty"] = true,
|
|
|
|
}
|
|
|
|
|
|
|
|
local function formspec(self, pos, mem)
|
|
|
|
local temp = mem.temperature or 20
|
2019-06-16 22:06:16 +03:00
|
|
|
local ratio = mem.power_ratio or 0
|
2019-03-19 00:40:17 +03:00
|
|
|
return "size[8,7]"..
|
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"image_button[0,0.2;1,1;techage_form_inventory.png;storage;;true;false;]"..
|
|
|
|
"list[context;water;1,0.2;1,1;]"..
|
|
|
|
"image_button[0,1.6;1,1;techage_form_input.png;input;;true;false;]"..
|
|
|
|
"list[context;input;1,1.6;1,1;]"..
|
|
|
|
"image[1,1.6;1,1;bucket_water.png]"..
|
|
|
|
"image[1,1.6;1,1;techage_form_mask.png]"..
|
|
|
|
"image[2,0.5;1,2;techage_form_temp_bg.png^[lowpart:"..
|
|
|
|
temp..":techage_form_temp_fg.png]"..
|
2019-06-16 22:06:16 +03:00
|
|
|
"image[7,0.5;1,2;"..techage.power.formspec_power_bar(1, ratio).."]"..
|
2019-03-19 00:40:17 +03:00
|
|
|
"image_button[6,1;1,1;".. self:get_state_button_image(mem) ..";state_button;]"..
|
2019-07-02 22:33:12 +03:00
|
|
|
"button[3,1.5;2,1;update;"..S("Update").."]"..
|
2019-03-19 00:40:17 +03:00
|
|
|
"list[current_player;main;0,3;8,4;]"..
|
|
|
|
"listring[current_name;water]"..
|
|
|
|
"listring[current_player;main]"..
|
|
|
|
default.get_hotbar_bg(0, 3)
|
|
|
|
end
|
|
|
|
|
2019-05-06 22:09:13 +03:00
|
|
|
local function can_start(pos, mem, state)
|
2019-06-21 00:44:04 +03:00
|
|
|
return mem.temperature and mem.temperature >= 80
|
2019-05-06 22:09:13 +03:00
|
|
|
end
|
|
|
|
|
2019-03-19 00:40:17 +03:00
|
|
|
local function start_node(pos, mem, state)
|
2019-06-16 22:06:16 +03:00
|
|
|
mem.running = transfer(pos, "start", nil)
|
2019-06-21 00:44:04 +03:00
|
|
|
mem.power_ratio = 0
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function stop_node(pos, mem, state)
|
2019-06-16 22:06:16 +03:00
|
|
|
transfer(pos, "stop", nil)
|
2019-05-21 17:37:05 +03:00
|
|
|
mem.running = false
|
2019-06-21 00:44:04 +03:00
|
|
|
mem.power_ratio = 0
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local State = techage.NodeStates:new({
|
2019-05-05 23:29:00 +03:00
|
|
|
node_name_passive = "techage:coalboiler_top",
|
2019-03-19 00:40:17 +03:00
|
|
|
cycle_time = CYCLE_TIME,
|
|
|
|
standby_ticks = STANDBY_TICKS,
|
|
|
|
has_item_meter = false,
|
|
|
|
formspec_func = formspec,
|
2019-05-06 22:09:13 +03:00
|
|
|
can_start = can_start,
|
2019-03-19 00:40:17 +03:00
|
|
|
start_node = start_node,
|
|
|
|
stop_node = stop_node,
|
|
|
|
})
|
|
|
|
|
|
|
|
local function get_water(pos)
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
local items = inv:get_stack("water", 1)
|
|
|
|
if items:get_count() > 0 then
|
|
|
|
local taken = items:take_item(1)
|
|
|
|
inv:set_stack("water", 1, items)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local function water_temperature(pos, mem)
|
|
|
|
mem.temperature = mem.temperature or 20
|
|
|
|
if mem.fire_trigger then
|
|
|
|
mem.temperature = math.min(mem.temperature + HEAT_STEP, 100)
|
|
|
|
else
|
|
|
|
mem.temperature = math.max(mem.temperature - HEAT_STEP, 20)
|
|
|
|
end
|
|
|
|
mem.fire_trigger = false
|
|
|
|
|
|
|
|
if mem.water_level == 0 then
|
|
|
|
if get_water(pos) then
|
|
|
|
mem.water_level = 100
|
|
|
|
else
|
|
|
|
mem.temperature = 20
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return mem.temperature
|
|
|
|
end
|
|
|
|
|
|
|
|
local function steaming(pos, mem, temp)
|
2019-06-16 22:06:16 +03:00
|
|
|
local wc = WATER_CONSUMPTION * (mem.power_ratio or 1)
|
|
|
|
mem.water_level = math.max((mem.water_level or 0) - wc, 0)
|
|
|
|
mem.running = transfer(pos, "running", nil)
|
2019-06-21 00:44:04 +03:00
|
|
|
if not mem.running then
|
|
|
|
State:fault(pos, mem)
|
|
|
|
elseif temp > 20 then
|
|
|
|
if temp < 80 then
|
|
|
|
State:stop(pos, mem)
|
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
2019-03-19 00:40:17 +03:00
|
|
|
else
|
2019-06-21 00:44:04 +03:00
|
|
|
State:keep_running(pos, mem, COUNTDOWN_TICKS)
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function node_timer(pos, elapsed)
|
|
|
|
local mem = tubelib2.get_mem(pos)
|
|
|
|
local temp = water_temperature(pos, mem)
|
|
|
|
if State:is_active(mem) then
|
|
|
|
steaming(pos, mem, temp)
|
|
|
|
end
|
|
|
|
return mem.temperature > 20
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_receive_fields(pos, formname, fields, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local mem = tubelib2.get_mem(pos)
|
2019-06-16 22:06:16 +03:00
|
|
|
mem.temperature = mem.temperature or 20
|
2019-03-19 00:40:17 +03:00
|
|
|
State:state_button_event(pos, mem, fields)
|
|
|
|
|
|
|
|
if fields.update then
|
2019-05-21 17:37:05 +03:00
|
|
|
if mem.temperature > 20 then
|
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
|
|
|
end
|
2019-03-19 00:40:17 +03:00
|
|
|
M(pos):set_string("formspec", formspec(State, pos, mem))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function on_rightclick(pos)
|
|
|
|
local mem = tubelib2.get_mem(pos)
|
|
|
|
M(pos):set_string("formspec", formspec(State, pos, mem))
|
2019-06-16 22:06:16 +03:00
|
|
|
if not minetest.get_node_timer(pos):is_started() then
|
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
|
|
|
end
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function can_dig(pos, player)
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
local mem = tubelib2.get_mem(pos)
|
2019-06-16 22:06:16 +03:00
|
|
|
return inv:is_empty("input") and not mem.running
|
2019-03-19 00:40:17 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function move_to_water(pos)
|
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
local water_stack = inv:get_stack("water", 1)
|
|
|
|
local input_stack = inv:get_stack("input", 1)
|
|
|
|
|
|
|
|
if input_stack:get_name() == "bucket:bucket_empty" then
|
|
|
|
if input_stack:get_count() == 1 then
|
|
|
|
if water_stack:get_count() > 0 then
|
|
|
|
water_stack:set_count(water_stack:get_count() - 1)
|
|
|
|
input_stack = ItemStack("bucket:bucket_water")
|
|
|
|
inv:set_stack("water", 1, water_stack)
|
|
|
|
inv:set_stack("input", 1, input_stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif water_stack:get_count() < MAX_WATER then
|
|
|
|
if water_stack:get_count() == 0 then
|
|
|
|
water_stack = ItemStack("default:water_source")
|
|
|
|
else
|
|
|
|
water_stack:set_count(water_stack:get_count() + 1)
|
|
|
|
end
|
|
|
|
input_stack = ItemStack("bucket:bucket_empty")
|
|
|
|
inv:set_stack("water", 1, water_stack)
|
|
|
|
inv:set_stack("input", 1, input_stack)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
if listname == "input" and Water[stack:get_name()] then
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
|
|
|
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
if listname == "input" then
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2019-05-05 23:29:00 +03:00
|
|
|
minetest.register_node("techage:coalboiler_top", {
|
2019-07-02 22:33:12 +03:00
|
|
|
description = S("TA3 Boiler Top"),
|
2019-05-05 23:29:00 +03:00
|
|
|
tiles = {"techage_coal_boiler_mesh_top.png"},
|
2019-03-19 00:40:17 +03:00
|
|
|
drawtype = "mesh",
|
|
|
|
mesh = "techage_boiler_large.obj",
|
|
|
|
selection_box = {
|
|
|
|
type = "fixed",
|
2019-05-05 23:29:00 +03:00
|
|
|
fixed = {-13/32, -48/32, -13/32, 13/32, 16/32, 13/32},
|
2019-03-19 00:40:17 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
can_dig = can_dig,
|
|
|
|
on_timer = node_timer,
|
|
|
|
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
|
|
|
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
2019-07-07 23:05:37 +03:00
|
|
|
allow_metadata_inventory_move = function(pos) return 0 end,
|
2019-03-19 00:40:17 +03:00
|
|
|
on_receive_fields = on_receive_fields,
|
|
|
|
on_rightclick = on_rightclick,
|
|
|
|
|
|
|
|
on_construct = function(pos)
|
2019-05-21 17:37:05 +03:00
|
|
|
tubelib2.init_mem(pos)
|
2019-03-19 00:40:17 +03:00
|
|
|
local inv = M(pos):get_inventory()
|
|
|
|
inv:set_size('water', 1)
|
|
|
|
inv:set_size('input', 1)
|
|
|
|
end,
|
|
|
|
|
|
|
|
after_place_node = function(pos, placer)
|
2019-08-31 02:35:46 +03:00
|
|
|
-- secondary 'after_place_node', called by power. Don't use tubelib2.init_mem(pos)!!!
|
|
|
|
local mem = tubelib2.get_mem(pos)
|
2019-03-19 00:40:17 +03:00
|
|
|
State:node_init(pos, mem, "")
|
|
|
|
local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
|
2019-05-05 23:29:00 +03:00
|
|
|
if node.name == "techage:coalboiler_base" then
|
2019-03-19 00:40:17 +03:00
|
|
|
on_rightclick(pos)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_metadata_inventory_put = function(pos)
|
|
|
|
minetest.after(0.5, move_to_water, pos)
|
|
|
|
end,
|
|
|
|
|
2019-05-05 23:29:00 +03:00
|
|
|
paramtype2 = "facedir",
|
2019-03-19 00:40:17 +03:00
|
|
|
groups = {cracky=1},
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_metal_defaults(),
|
|
|
|
})
|
|
|
|
|
2019-05-21 17:37:05 +03:00
|
|
|
techage.power.register_node({"techage:coalboiler_top"}, {
|
|
|
|
conn_sides = {"F"},
|
|
|
|
power_network = Pipe,
|
|
|
|
})
|
2019-06-08 23:57:01 +03:00
|
|
|
|
|
|
|
techage.register_node({"techage:coalboiler_top"}, {
|
|
|
|
on_transfer = function(pos, in_dir, topic, payload)
|
|
|
|
if topic == "trigger" then
|
|
|
|
local mem = tubelib2.get_mem(pos)
|
|
|
|
mem.fire_trigger = true
|
2019-08-19 22:29:55 +03:00
|
|
|
if not minetest.get_node_timer(pos):is_started() then
|
|
|
|
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
|
|
|
end
|
2019-06-17 22:24:48 +03:00
|
|
|
if mem.running then
|
|
|
|
mem.power_ratio = transfer(pos, topic, payload)
|
|
|
|
return mem.power_ratio
|
|
|
|
end
|
2019-06-08 23:57:01 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2019-05-05 23:29:00 +03:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:coalboiler_top",
|
|
|
|
recipe = {
|
|
|
|
{"default:stone", "default:stone", "default:stone"},
|
|
|
|
{"techage:iron_ingot", "", "techage:iron_ingot"},
|
|
|
|
{"default:stone", "", "default:stone"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2019-07-02 22:33:12 +03:00
|
|
|
techage.register_entry_page("ta3ps", "coalboiler_top",
|
|
|
|
S("TA3 Boiler Top"),
|
2019-07-06 21:23:11 +03:00
|
|
|
S("Part of the Power Station. Has to be placed on top of TA3 Power Station Boiler Base.@n"..
|
|
|
|
"(see TA3 Power Station)"),
|
2019-07-02 22:33:12 +03:00
|
|
|
"techage:coalboiler_top")
|