oil explorer improvements

master
Joachim Stolberg 2020-03-29 22:07:05 +02:00
parent 89b1685bd8
commit c4392723ff
6 changed files with 145 additions and 99 deletions

View File

@ -186,7 +186,7 @@ else
-- Test -- Test
dofile(MP.."/recipe_checker.lua") dofile(MP.."/recipe_checker.lua")
dofile(MP.."/.test/sink.lua") dofile(MP.."/.test/sink.lua")
--dofile(MP.."/.test/state_node.lua") dofile(MP.."/.test/meta_node.lua")
-- Solar -- Solar
dofile(MP.."/solar/minicell.lua") dofile(MP.."/solar/minicell.lua")

View File

@ -21,7 +21,7 @@ local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm
local STANDBY_TICKS = 1 local STANDBY_TICKS = 1
local COUNTDOWN_TICKS = 6 local COUNTDOWN_TICKS = 6
local CYCLE_TIME = 16 local CYCLE_TIME = 2 ---------------------------------------- TODO 16
local formspec0 = "size[5,4]".. local formspec0 = "size[5,4]"..
default.gui_bg.. default.gui_bg..
@ -70,6 +70,7 @@ local function formspec(self, pos, nvm)
"image[3.5,0;1,1;"..techage.get_power_image(pos, nvm).."]".. "image[3.5,0;1,1;"..techage.get_power_image(pos, nvm).."]"..
"image[3.5,1;1,1;techage_form_arrow.png]".. "image[3.5,1;1,1;techage_form_arrow.png]"..
"image_button[3.5,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "image_button[3.5,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[3.5,2;1,1;"..self:get_state_tooltip(nvm).."]"..
"label[6.2,0.5;OUT]".. "label[6.2,0.5;OUT]"..
"list[context;dst;6,1;1,1;]".. "list[context;dst;6,1;1,1;]"..
"button_exit[5,3;3,1;remove;"..S("Remove derrick").."]".. "button_exit[5,3;3,1;remove;"..S("Remove derrick").."]"..
@ -133,6 +134,12 @@ local function drilling(pos, crd, nvm, inv)
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, S("Drill bits missing")) 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", "false")
crd.State:blocked(pos, nvm, S("No oil found"))
elseif node.name == "techage:oilstorage" then -- old oil bubble node?
nvm.drill_pos.y = nvm.drill_pos.y-1
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
elseif node.name == "techage:oil_source" 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
@ -150,7 +157,7 @@ local function drilling(pos, crd, nvm, inv)
if drop_name then if drop_name then
local item = ItemStack(drop_name) local item = ItemStack(drop_name)
if not inv:room_for_item("dst", item) then if not inv:room_for_item("dst", item) then
crd.State:blocked(pos, nvm) crd.State:blocked(pos, nvm, S("item output blocked"))
return return
end end
inv:add_item("dst", item) inv:add_item("dst", item)
@ -159,8 +166,9 @@ local function drilling(pos, crd, nvm, inv)
inv:remove_item("src", ItemStack("techage:oil_drillbit")) inv:remove_item("src", ItemStack("techage:oil_drillbit"))
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 elseif node.name == "ignore" then
crd.State:fault(pos, nvm, S("block can't be dug")) -- load world and pause the drilling for one step
minetest.emerge_area(nvm.drill_pos, nvm.drill_pos)
end end
end end
@ -250,6 +258,7 @@ local tubing = {
on_node_load = function(pos, node) 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) local nvm = techage.get_nvm(pos)
nvm.assemble_locked = false
if nvm.techage_state == techage.RUNNING then if nvm.techage_state == techage.RUNNING then
play_sound(pos) play_sound(pos)
end end

View File

@ -17,20 +17,29 @@ local M = minetest.get_meta
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local S = techage.S local S = techage.S
local PROBABILITY = 80 local PROBABILITY = 20
local OIL_MIN = 2000 local OIL_MIN = 2000
local OIL_MAX = 20000 local OIL_MAX = 20000
local DEPTH_MIN = 8 local DEPTH_MIN = 16
local DEPTH_MAX = (16 * 25) + 8 local DEPTH_MAX = 30*16
local DEPTH_STEP = 96 local DEPTH_STEP = 16
local YPOS_MAX = -6*16
local RADIUS = 8
local seed = 1234 -- confidental! local seed = tonumber(minetest.settings:get("techage_oil_exploration_seed")) or 1234 -- confidental!
local InvalidGroundNodes = { local InvalidGroundNodes = {
"air", ["air"] = true,
}
local ValidGroundNodes = {
["default:cobble"] = true,
["default:mossycobble"] = true,
["default:desert_cobble"] = true,
} }
local function oil_amount(pos) local function oil_amount(pos)
if pos.y > YPOS_MAX then return 0 end
local block_key = seed + local block_key = seed +
math.floor((pos.z + 32768) / 16) * 4096 * 4096 + math.floor((pos.z + 32768) / 16) * 4096 * 4096 +
math.floor((pos.y + 32768) / 16) * 4096 + math.floor((pos.y + 32768) / 16) * 4096 +
@ -49,26 +58,29 @@ local function center(coord)
return (math.floor(coord/16) * 16) + 8 return (math.floor(coord/16) * 16) + 8
end end
local function gen_oil_slice(pos1, posc, y, radius, data, id) local function calc_depth(pos, explore_pos)
local y_offs = (y - pos1.y) * 16 return pos.y - explore_pos.y + 1
for x = posc.x - radius + 2, posc.x + radius + 2 do end
for z = posc.z - radius + 1, posc.z + radius + 1 do
local idx = x - pos1.x + y_offs + (z - pos1.z) * 16 * 16 local function gen_oil_slice(ypos, from, to, data, id)
for x = from, to do
for z = from, to do
local idx = (x + (ypos * 16) + (z * 16 * 16)) + 1
data[idx] = id data[idx] = id
end end
end end
return (radius * 2 + 1) * (radius * 2 + 1)
end end
local function gen_oil_bubble(pos1, posC, amount, data) local function gen_oil_bubble(data)
local id = minetest.get_content_id("techage:oil_source") local id = minetest.get_content_id("techage:oil_source")
--local id = minetest.get_content_id("air")
local radius = math.floor(math.pow(amount, 1.0/3) / 2) gen_oil_slice(1, 3, 12, data, id)
local sum = 0 gen_oil_slice(2, 2, 13, data, id)
for y = posC.y - radius, posC.y + radius do for offs = 3, 12 do
sum = sum + gen_oil_slice(pos1, posC, y, radius + 1, data, id) gen_oil_slice(offs, 1, 14, data, id)
if sum >= amount then break end
end end
gen_oil_slice(13, 2, 13, data, id)
gen_oil_slice(14, 3, 12, data, id)
end end
local function useable_stone_block(data) local function useable_stone_block(data)
@ -76,27 +88,33 @@ local function useable_stone_block(data)
for _,id in ipairs(data) do for _,id in ipairs(data) do
if not valid[id] then if not valid[id] then
local itemname = minetest.get_name_from_content_id(id) local itemname = minetest.get_name_from_content_id(id)
local ndef = minetest.registered_nodes[itemname] if not ValidGroundNodes[itemname] then
if not ndef or not ndef.is_ground_content or InvalidGroundNodes[itemname] then local ndef = minetest.registered_nodes[itemname]
return false if InvalidGroundNodes[itemname] or not ndef or ndef.is_ground_content == false then
print("useable_stone_block false", itemname)
return false
end
end end
valid[id] = true valid[id] = true
end end
end end
print("useable_stone_block true")
return true return true
end end
local function get_next_depth(pos) local function get_next_explore_pos(pos)
local meta = M(pos) local meta = M(pos)
local depth = meta:get_int("exploration_depth") local ypos = meta:get_int("exploration_ypos")
if depth == 0 then if ypos == 0 then
depth = DEPTH_MIN ypos = math.min(YPOS_MAX, center(pos.y))
end end
if depth + DEPTH_STEP < DEPTH_MAX then local d = calc_depth(pos, {y = ypos})
depth = depth + DEPTH_STEP if d + DEPTH_STEP < DEPTH_MAX then
meta:set_int("exploration_depth", depth) ypos = ypos - DEPTH_STEP
meta:set_int("exploration_ypos", ypos)
end end
return depth print(minetest.pos_to_string({x = center(pos.x), y = center(ypos), z = center(pos.z)}))
return {x = center(pos.x), y = center(ypos), z = center(pos.z)}
end end
local function get_oil_amount(pos) local function get_oil_amount(pos)
@ -108,11 +126,10 @@ local function set_oil_amount(pos, amount)
return M(pos):set_int("oil_amount", amount) return M(pos):set_int("oil_amount", amount)
end end
local function status(pos, player_name, depth, amount) local function status(pos, player_name, explore_pos, amount)
depth = depth + pos.y local depth = calc_depth(pos, explore_pos)
local posC = {x = center(pos.x), y = pos.y, z = center(pos.z)}
minetest.chat_send_player(player_name, minetest.chat_send_player(player_name,
"[TA Oil] "..P2S(posC).." "..S("depth")..": "..depth..", "..S("Oil")..": "..amount.." ") "[TA Oil] "..P2S(explore_pos).." "..S("depth")..": "..depth..", "..S("Oil")..": "..amount.." ")
end end
local function marker(player_name, pos) local function marker(player_name, pos)
@ -122,64 +139,81 @@ local function marker(player_name, pos)
techage.switch_region(player_name, pos1, pos2) techage.switch_region(player_name, pos1, pos2)
end end
local function explore_area(pos, pos1, pos2, posC, depth, amount, player_name) -- check if oil can be placed and if so, do it and return true
local function generate_oil_bubble(posC, amount)
local pos1 = {x = posC.x - RADIUS, y = posC.y - RADIUS, z = posC.z - RADIUS}
local pos2 = {x = posC.x + RADIUS - 1, y = posC.y + RADIUS - 1, z = posC.z + RADIUS - 1}
local vm = minetest.get_voxel_manip(pos1, pos2) local vm = minetest.get_voxel_manip(pos1, pos2)
local data = vm:get_data() local data = vm:get_data()
print("#data", #data)
if useable_stone_block(data) then if useable_stone_block(data) then
gen_oil_bubble(pos1, posC, amount/10, data) gen_oil_bubble(data)
vm:set_data(data) vm:set_data(data)
vm:write_to_map() vm:write_to_map()
vm:update_map() vm:update_map()
M(pos):set_int("oil_amount", amount)
M(pos):set_int("depth", depth)
set_oil_amount(posC, amount) set_oil_amount(posC, amount)
marker(player_name, pos) return true
else
amount = 0
end end
status(pos, player_name, depth, amount) return false
end end
local function emerge_area(pos, node, player_name) -- replace oil by air
if pos.y < -50 then local function generate_air_bubble(posC)
minetest.chat_send_player(player_name, local pos1 = {x = posC.x - RADIUS, y = posC.y - RADIUS, z = posC.z - RADIUS}
S("[TA Oil] No oil exploration possible at this depth! ")) local pos2 = {x = posC.x + RADIUS - 1, y = posC.y + RADIUS - 1, z = posC.z + RADIUS - 1}
elseif get_oil_amount(pos) == 0 then -- nothing found so far? local vm = minetest.get_voxel_manip(pos1, pos2)
local depth = get_next_depth(pos) local data = vm:get_data()
local posC = {x = center(pos.x), y = center(-depth), z = center(pos.z)} local air = minetest.get_content_id("air")
local radius = 7 local oil = minetest.get_content_id("techage:oil_source")
local pos1 = {x = posC.x - radius, y = posC.y - radius, z = posC.z - radius}
local pos2 = {x = posC.x + radius, y = posC.y + radius, z = posC.z + radius}
local amount = oil_amount(posC)
if creative and creative.is_enabled_for and
creative.is_enabled_for(player_name) then
amount = 10000
end
minetest.sound_play("techage_explore", {
pos = pos,
max_hear_distance = 8})
for i = 1, #data do
if date[i] == oil then
data[i] = air
end
end
vm:set_data(data)
vm:write_to_map()
vm:update_map()
end
local function explore_area(pos, node, player_name)
if M(pos):get_int("oil_amount") == 0 then -- nothing found so far?
local posC, amount
node.name = "techage:oilexplorer_on" node.name = "techage:oilexplorer_on"
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
minetest.get_node_timer(pos):start(2.2) minetest.get_node_timer(pos):start(2.2)
minetest.sound_play("techage_explore", {
pos = pos,
max_hear_distance = 8})
for i = 1,4 do
posC = get_next_explore_pos(pos)
amount = oil_amount(posC)
print("explore", P2S(posC), amount)
if amount > 0 then
break
end
end
if amount > 0 then if amount > 0 then
if get_oil_amount(posC) == 0 then -- not explored so far? if get_oil_amount(posC) == 0 then -- not explored so far?
minetest.emerge_area(pos1, pos2) if generate_oil_bubble(posC, amount) then
minetest.after(2, explore_area, pos, pos1, pos2, posC, depth, amount, player_name) marker(player_name, pos)
else else
M(pos):set_int("oil_amount", amount) amount = 0
M(pos):set_int("depth", depth) end
minetest.after(2, status, pos, player_name, depth, amount)
minetest.after(2, marker, player_name, pos)
end end
else M(pos):set_int("oil_amount", amount)
minetest.after(2, status, pos, player_name, depth, 0) end
end
minetest.after(2, status, pos, player_name, posC, amount)
else else
status(pos, player_name, M(pos):get_int("depth"), M(pos):get_int("oil_amount")) local explore_pos = {x = center(pos.x), y = M(pos):get_int("exploration_ypos"), z = center(pos.z)}
status(pos, player_name, explore_pos, M(pos):get_int("oil_amount"))
marker(player_name, pos) marker(player_name, pos)
end end
end end
@ -203,7 +237,7 @@ minetest.register_node("techage:oilexplorer", {
}, },
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
emerge_area(pos, node, clicker:get_player_name()) explore_area(pos, node, clicker:get_player_name())
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
techage.unmark_region(digger:get_player_name()) techage.unmark_region(digger:get_player_name())
@ -216,16 +250,17 @@ minetest.register_node("techage:oilexplorer", {
minetest.register_node("techage:oilexplorer_on", { minetest.register_node("techage:oilexplorer_on", {
description = S("TA3 Oil Explorer"), description = S("TA3 Oil Explorer"),
tiles = { tiles = {
{ {
image = "techage_filling4_ta3.png^techage_appl_oilexplorer_top4.png^techage_frame4_ta3_top.png", image = "techage_filling4_ta3.png^techage_appl_oilexplorer_top4.png^techage_frame4_ta3_top.png",
backface_culling = false, backface_culling = false,
animation = { animation = {
type = "vertical_frames", type = "vertical_frames",
aspect_w = 32,
aspect_h = 32, aspect_w = 32,
length = 1.2, aspect_h = 32,
length = 1.2,
},
}, },
},
"techage_filling_ta3.png^techage_frame_ta3.png", "techage_filling_ta3.png^techage_frame_ta3.png",
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_oilexplorer.png", "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_oilexplorer.png",
}, },
@ -244,7 +279,6 @@ minetest.register_node("techage:oilexplorer_on", {
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
minetest.register_craft({ minetest.register_craft({
output = "techage:oilexplorer", output = "techage:oilexplorer",
recipe = { recipe = {
@ -260,13 +294,13 @@ techage.explore = {}
function techage.explore.get_oil_info(pos) function techage.explore.get_oil_info(pos)
local amount = 0 local amount = 0
local depth = DEPTH_MIN local depth = DEPTH_MIN
local posC local posC = {x = center(pos.x), y = center(pos.y) - DEPTH_MIN, z = center(pos.z)}
while amount == 0 and depth < DEPTH_MAX do while amount == 0 and depth < DEPTH_MAX do
depth = depth + DEPTH_STEP
posC = {x = center(pos.x), y = center(-depth), z = center(pos.z)}
amount = get_oil_amount(posC) amount = get_oil_amount(posC)
depth = calc_depth(pos, posC)
posC.y = posC.y - DEPTH_STEP
end end
return {depth = center(depth) - 1 + pos.y, amount = amount, storage_pos = posC} return {depth = depth, amount = amount, storage_pos = posC}
end end
function techage.explore.get_oil_amount(posC) function techage.explore.get_oil_amount(posC)
@ -279,3 +313,6 @@ function techage.explore.dec_oil_amount(posC)
meta:set_int("oil_amount", amount-1) meta:set_int("oil_amount", amount-1)
return amount-1 return amount-1
end end
-- generate_air_bubble(posC)
techage.explore.generate_air_bubble = generate_air_bubble

View File

@ -35,6 +35,7 @@ local function has_oil(pos, meta)
if amount > 0 then if amount > 0 then
return true return true
end end
techage.explore.generate_air_bubble(P(storage_pos))
end end
end end

View File

@ -21,7 +21,7 @@ local N = function(pos) return minetest.get_node(pos).name end
local power = techage.power local power = techage.power
local networks = techage.networks local networks = techage.networks
local CYCLE_TIME = 2 local CYCLE_TIME = 1.8
techage.schedule = {} techage.schedule = {}

View File

@ -4,11 +4,6 @@ techage_max_num_forceload_blocks (Max. number of Forceload Blocks) int 20
# Enable Basalt Stone (and disable ore generation via cobble generator) # Enable Basalt Stone (and disable ore generation via cobble generator)
techage_basalt_stone_enabled (Basalt Stone enabled) bool false techage_basalt_stone_enabled (Basalt Stone enabled) bool false
# This aging value is used to calculate the lifetime of machines before
# they go defect . The value 200 (default) results in a lifetime
# for standard machines of about 2000 - 8000 item processing cycles.
techage_machine_aging_value (MKachine aging value) int 200
# Rarity factor to find ores when sieving with the Gravel Sieve # Rarity factor to find ores when sieving with the Gravel Sieve
# 1.0 is according to the mapgen generator # 1.0 is according to the mapgen generator
# 2.0 means half as many ores as result # 2.0 means half as many ores as result
@ -17,4 +12,8 @@ techage_ore_rarity (Rarity factor to find ores) float 1.0
# Enable alternative recipes for steel and bronze. # Enable alternative recipes for steel and bronze.
# Instead of the furnace the player has to use the Coal Burner. # Instead of the furnace the player has to use the Coal Burner.
techage_modified_recipes_enabled (Enable alternative recipes for steel and bronze) bool false techage_modified_recipes_enabled (Enable alternative recipes for steel and bronze) bool false
# Seed for the oil exploration random function.
# Change this for your server in order not to be able to predict the oil reserves!
techage_oil_exploration_seed (techage oil exploration seed) int 1234