2019-06-09 18:20:40 +03:00
|
|
|
--[[
|
|
|
|
|
|
|
|
TechAge
|
|
|
|
=======
|
|
|
|
|
2020-02-02 00:00:58 +03:00
|
|
|
Copyright (C) 2019-2020 Joachim Stolberg
|
2019-06-09 18:20:40 +03:00
|
|
|
|
2019-08-22 21:49:47 +03:00
|
|
|
GPL v3
|
2019-06-09 18:20:40 +03:00
|
|
|
See LICENSE.txt for more information
|
|
|
|
|
|
|
|
TA3 Pumpjack
|
|
|
|
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- for lazy programmers
|
2019-07-05 22:44:18 +03:00
|
|
|
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
2019-06-09 18:20:40 +03:00
|
|
|
local M = minetest.get_meta
|
2019-07-02 22:33:12 +03:00
|
|
|
local P = minetest.string_to_pos
|
|
|
|
local S = techage.S
|
2019-11-03 01:39:10 +03:00
|
|
|
local Pipe = techage.LiquidPipe
|
|
|
|
local liquid = techage.liquid
|
2019-07-02 22:33:12 +03:00
|
|
|
|
2019-06-09 18:20:40 +03:00
|
|
|
-- Consumer Related Data
|
2019-10-07 01:09:39 +03:00
|
|
|
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
|
2019-06-09 18:20:40 +03:00
|
|
|
local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).consumer end
|
|
|
|
|
2020-02-02 00:00:58 +03:00
|
|
|
local STANDBY_TICKS = 1
|
2019-06-09 18:20:40 +03:00
|
|
|
local COUNTDOWN_TICKS = 10
|
|
|
|
local CYCLE_TIME = 8
|
|
|
|
|
2019-11-03 01:39:10 +03:00
|
|
|
local function has_oil(pos, meta)
|
2019-06-09 18:20:40 +03:00
|
|
|
local storage_pos = meta:get_string("storage_pos")
|
|
|
|
if storage_pos ~= "" then
|
|
|
|
local amount = techage.explore.get_oil_amount(P(storage_pos))
|
|
|
|
if amount > 0 then
|
2019-11-03 01:39:10 +03:00
|
|
|
return true
|
2019-06-09 18:20:40 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function dec_oil_item(pos, meta)
|
|
|
|
local storage_pos = meta:get_string("storage_pos")
|
|
|
|
if storage_pos ~= "" then
|
|
|
|
techage.explore.dec_oil_amount(P(storage_pos))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
local function formspec(self, pos, nvm)
|
2019-06-09 21:43:41 +03:00
|
|
|
local amount = 0
|
|
|
|
local storage_pos = M(pos):get_string("storage_pos")
|
|
|
|
if storage_pos ~= "" then
|
|
|
|
amount = techage.explore.get_oil_amount(P(storage_pos))
|
|
|
|
end
|
|
|
|
return "size[5,3]"..
|
2020-02-02 00:00:58 +03:00
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
|
|
|
"box[0,-0.1;4.8,0.5;#c6e8ff]"..
|
|
|
|
"label[1.5,-0.1;"..minetest.colorize( "#000000", S("Pumpjack")).."]"..
|
|
|
|
"image[0.5,1.4;1,1;techage_liquid2_inv.png^[colorize:#000000^techage_liquid1_inv.png]"..
|
|
|
|
"image[4,0.8;1,1;"..techage.get_power_image(pos, nvm).."]"..
|
|
|
|
"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
|
2019-06-09 21:43:41 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function on_rightclick(pos, node, clicker)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2020-02-02 00:00:58 +03:00
|
|
|
techage.set_activeformspec(pos, clicker)
|
2020-01-31 21:55:10 +03:00
|
|
|
M(pos):set_string("formspec", formspec(CRD(pos).State, pos, nvm))
|
2019-06-09 21:43:41 +03:00
|
|
|
end
|
|
|
|
|
2020-01-31 21:55:10 +03:00
|
|
|
local function pumping(pos, crd, meta, nvm)
|
2019-11-03 01:39:10 +03:00
|
|
|
if has_oil(pos, meta) then
|
2019-11-22 01:21:44 +03:00
|
|
|
local leftover = liquid.put(pos, 6, "techage:oil_source", 1)
|
2020-02-02 00:00:58 +03:00
|
|
|
print("pumping", dump(leftover))
|
2019-11-22 01:21:44 +03:00
|
|
|
if leftover and leftover > 0 then
|
2020-01-31 21:55:10 +03:00
|
|
|
crd.State:blocked(pos, nvm)
|
2020-02-02 00:00:58 +03:00
|
|
|
stop_sound(pos)
|
2019-06-09 18:20:40 +03:00
|
|
|
return
|
|
|
|
end
|
|
|
|
dec_oil_item(pos, meta)
|
2020-01-31 21:55:10 +03:00
|
|
|
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
2019-06-09 18:20:40 +03:00
|
|
|
return
|
|
|
|
end
|
2020-02-02 00:00:58 +03:00
|
|
|
crd.State:fault(pos, nvm, S("no oil"))
|
2019-06-09 18:20:40 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local function keep_running(pos, elapsed)
|
2020-01-31 21:55:10 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
2019-06-09 18:20:40 +03:00
|
|
|
local crd = CRD(pos)
|
2020-01-31 21:55:10 +03:00
|
|
|
pumping(pos, crd, M(pos), nvm)
|
2020-02-02 00:00:58 +03:00
|
|
|
if techage.is_activeformspec(pos) then
|
|
|
|
M(pos):set_string("formspec", formspec(crd.State, pos, nvm))
|
|
|
|
end
|
2019-06-09 18:20:40 +03:00
|
|
|
end
|
|
|
|
|
2019-06-09 21:43:41 +03:00
|
|
|
local function on_receive_fields(pos, formname, fields, player)
|
|
|
|
if minetest.is_protected(pos, player:get_player_name()) then
|
|
|
|
return
|
2019-06-09 18:20:40 +03:00
|
|
|
end
|
2020-02-02 00:00:58 +03:00
|
|
|
local nvm = techage.get_nvm(pos)
|
|
|
|
CRD(pos).State:state_button_event(pos, nvm, fields)
|
2019-06-09 18:20:40 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local tiles = {}
|
2019-06-09 21:43:41 +03:00
|
|
|
|
2019-06-09 18:20:40 +03:00
|
|
|
-- '#' will be replaced by the stage number
|
|
|
|
tiles.pas = {
|
2019-11-03 01:39:10 +03:00
|
|
|
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_hole_pipe.png",
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_hole_pipe.png",
|
2019-06-09 18:20:40 +03:00
|
|
|
"techage_appl_pumpjack.png^techage_frame_ta#.png",
|
|
|
|
"techage_appl_pumpjack.png^techage_frame_ta#.png",
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.png^[transformR90]",
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.png^[transformR90]",
|
|
|
|
}
|
|
|
|
tiles.act = {
|
|
|
|
-- up, down, right, left, back, front
|
2019-11-03 01:39:10 +03:00
|
|
|
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_hole_pipe.png",
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#.png^techage_appl_hole_pipe.png",
|
2019-06-09 18:20:40 +03:00
|
|
|
{
|
|
|
|
image = "techage_appl_pumpjack14.png^techage_frame14_ta#.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 2.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
image = "techage_appl_pumpjack14.png^techage_frame14_ta#.png",
|
|
|
|
backface_culling = false,
|
|
|
|
animation = {
|
|
|
|
type = "vertical_frames",
|
|
|
|
aspect_w = 32,
|
|
|
|
aspect_h = 32,
|
|
|
|
length = 2.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.png^[transformR90]",
|
|
|
|
"techage_filling_ta#.png^techage_frame_ta#_top.png^techage_appl_arrow.png^[transformR90]",
|
|
|
|
}
|
|
|
|
|
|
|
|
local tubing = {
|
2019-08-25 19:08:30 +03:00
|
|
|
on_recv_message = function(pos, src, topic, payload)
|
2019-06-09 18:20:40 +03:00
|
|
|
local resp = CRD(pos).State:on_receive_message(pos, topic, payload)
|
|
|
|
if resp then
|
|
|
|
return resp
|
|
|
|
else
|
|
|
|
return "unsupported"
|
|
|
|
end
|
|
|
|
end,
|
2020-02-02 00:00:58 +03:00
|
|
|
on_node_load = function(pos, node)
|
2019-06-09 18:20:40 +03:00
|
|
|
CRD(pos).State:on_node_load(pos)
|
2020-02-02 00:00:58 +03:00
|
|
|
if node.name == "techage:ta3_pumpjack_act" then
|
|
|
|
play_sound(pos)
|
|
|
|
end
|
2019-06-09 18:20:40 +03:00
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
local _, node_name_ta3, _ =
|
2019-08-26 23:19:59 +03:00
|
|
|
techage.register_consumer("pumpjack", S("Oil Pumpjack"), tiles, {
|
2019-06-09 18:20:40 +03:00
|
|
|
cycle_time = CYCLE_TIME,
|
|
|
|
standby_ticks = STANDBY_TICKS,
|
2019-06-09 21:43:41 +03:00
|
|
|
formspec = formspec,
|
2019-06-09 18:20:40 +03:00
|
|
|
tubing = tubing,
|
2020-02-02 00:00:58 +03:00
|
|
|
on_state_change = on_node_state_change,
|
2019-06-09 18:20:40 +03:00
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local node = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
|
|
|
|
if node.name == "techage:oil_drillbit2" then
|
|
|
|
local info = techage.explore.get_oil_info(pos)
|
|
|
|
if info then
|
2019-07-05 22:44:18 +03:00
|
|
|
M(pos):set_string("storage_pos", P2S(info.storage_pos))
|
2019-06-09 18:20:40 +03:00
|
|
|
end
|
|
|
|
end
|
2019-11-22 01:21:44 +03:00
|
|
|
Pipe:after_place_node(pos)
|
2019-06-09 18:20:40 +03:00
|
|
|
end,
|
2019-11-03 01:39:10 +03:00
|
|
|
networks = {
|
2020-01-31 21:55:10 +03:00
|
|
|
pipe2 = {
|
2019-11-03 01:39:10 +03:00
|
|
|
sides = {U = 1}, -- Pipe connection side
|
|
|
|
ntype = "pump",
|
|
|
|
},
|
|
|
|
},
|
2020-02-02 00:00:58 +03:00
|
|
|
power_sides = {F=1, B=1, L=1, R=1, D=1},
|
2019-06-09 18:20:40 +03:00
|
|
|
on_rightclick = on_rightclick,
|
2019-06-09 21:43:41 +03:00
|
|
|
on_receive_fields = on_receive_fields,
|
2019-06-09 18:20:40 +03:00
|
|
|
node_timer = keep_running,
|
|
|
|
on_rotate = screwdriver.disallow,
|
|
|
|
|
2019-11-22 01:21:44 +03:00
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
|
|
|
Pipe:after_dig_node(pos)
|
|
|
|
end,
|
|
|
|
|
2019-06-09 18:20:40 +03:00
|
|
|
groups = {choppy=2, cracky=2, crumbly=2},
|
|
|
|
is_ground_content = false,
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
num_items = {0,1,1,1},
|
2019-06-09 22:24:39 +03:00
|
|
|
power_consumption = {0,16,16,16},
|
2019-06-09 18:20:40 +03:00
|
|
|
},
|
|
|
|
{false, false, true, false}) -- TA3 only
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "techage:ta3_pumpjack_pas",
|
|
|
|
recipe = {
|
2019-06-17 22:24:48 +03:00
|
|
|
{"", "techage:usmium_nuggets", ""},
|
2019-06-09 18:20:40 +03:00
|
|
|
{"dye:red", "techage:ta3_pusher_pas", "dye:red"},
|
|
|
|
{"", "techage:oil_drillbit", ""},
|
|
|
|
},
|
|
|
|
})
|
2019-06-11 21:31:53 +03:00
|
|
|
|
2019-11-03 01:39:10 +03:00
|
|
|
Pipe:add_secondary_node_names({"techage:ta3_pumpjack_pas", "techage:ta3_pumpjack_act"})
|
|
|
|
|