diff --git a/init.lua b/init.lua index cbdd2bf..857172b 100644 --- a/init.lua +++ b/init.lua @@ -186,7 +186,7 @@ else -- Test dofile(MP.."/recipe_checker.lua") dofile(MP.."/.test/sink.lua") - --dofile(MP.."/.test/state_node.lua") + dofile(MP.."/.test/meta_node.lua") -- Solar dofile(MP.."/solar/minicell.lua") diff --git a/oil/drillbox.lua b/oil/drillbox.lua index 2aaea20..8b68041 100644 --- a/oil/drillbox.lua +++ b/oil/drillbox.lua @@ -21,7 +21,7 @@ local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm local STANDBY_TICKS = 1 local COUNTDOWN_TICKS = 6 -local CYCLE_TIME = 16 +local CYCLE_TIME = 2 ---------------------------------------- TODO 16 local formspec0 = "size[5,4]".. 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,1;1,1;techage_form_arrow.png]".. "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]".. "list[context;dst;6,1;1,1;]".. "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 crd.State:idle(pos, nvm, S("Drill bits missing")) 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") crd.State:stop(pos, nvm) elseif minetest.is_protected(nvm.drill_pos, owner) then @@ -150,7 +157,7 @@ local function drilling(pos, crd, nvm, inv) if drop_name then local item = ItemStack(drop_name) if not inv:room_for_item("dst", item) then - crd.State:blocked(pos, nvm) + crd.State:blocked(pos, nvm, S("item output blocked")) return end inv:add_item("dst", item) @@ -159,8 +166,9 @@ local function drilling(pos, crd, nvm, inv) inv:remove_item("src", ItemStack("techage:oil_drillbit")) nvm.drill_pos.y = nvm.drill_pos.y-1 crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS) - else - crd.State:fault(pos, nvm, S("block can't be dug")) + elseif node.name == "ignore" then + -- load world and pause the drilling for one step + minetest.emerge_area(nvm.drill_pos, nvm.drill_pos) end end @@ -250,6 +258,7 @@ local tubing = { on_node_load = function(pos, node) CRD(pos).State:on_node_load(pos) local nvm = techage.get_nvm(pos) + nvm.assemble_locked = false if nvm.techage_state == techage.RUNNING then play_sound(pos) end diff --git a/oil/explore.lua b/oil/explore.lua index c85d02e..c293b92 100644 --- a/oil/explore.lua +++ b/oil/explore.lua @@ -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 S = techage.S -local PROBABILITY = 80 +local PROBABILITY = 20 local OIL_MIN = 2000 local OIL_MAX = 20000 -local DEPTH_MIN = 8 -local DEPTH_MAX = (16 * 25) + 8 -local DEPTH_STEP = 96 +local DEPTH_MIN = 16 +local DEPTH_MAX = 30*16 +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 = { - "air", + ["air"] = true, +} + +local ValidGroundNodes = { + ["default:cobble"] = true, + ["default:mossycobble"] = true, + ["default:desert_cobble"] = true, } local function oil_amount(pos) + if pos.y > YPOS_MAX then return 0 end local block_key = seed + math.floor((pos.z + 32768) / 16) * 4096 * 4096 + math.floor((pos.y + 32768) / 16) * 4096 + @@ -49,26 +58,29 @@ local function center(coord) return (math.floor(coord/16) * 16) + 8 end -local function gen_oil_slice(pos1, posc, y, radius, data, id) - local y_offs = (y - pos1.y) * 16 - for x = posc.x - radius + 2, posc.x + radius + 2 do - 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 calc_depth(pos, explore_pos) + return pos.y - explore_pos.y + 1 +end + +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 end end - return (radius * 2 + 1) * (radius * 2 + 1) 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("air") - local radius = math.floor(math.pow(amount, 1.0/3) / 2) - local sum = 0 - for y = posC.y - radius, posC.y + radius do - sum = sum + gen_oil_slice(pos1, posC, y, radius + 1, data, id) - if sum >= amount then break end + + gen_oil_slice(1, 3, 12, data, id) + gen_oil_slice(2, 2, 13, data, id) + for offs = 3, 12 do + gen_oil_slice(offs, 1, 14, data, id) end + gen_oil_slice(13, 2, 13, data, id) + gen_oil_slice(14, 3, 12, data, id) end local function useable_stone_block(data) @@ -76,27 +88,33 @@ local function useable_stone_block(data) for _,id in ipairs(data) do if not valid[id] then local itemname = minetest.get_name_from_content_id(id) - local ndef = minetest.registered_nodes[itemname] - if not ndef or not ndef.is_ground_content or InvalidGroundNodes[itemname] then - return false + if not ValidGroundNodes[itemname] then + local ndef = minetest.registered_nodes[itemname] + if InvalidGroundNodes[itemname] or not ndef or ndef.is_ground_content == false then + print("useable_stone_block false", itemname) + return false + end end valid[id] = true end end + print("useable_stone_block true") return true end -local function get_next_depth(pos) +local function get_next_explore_pos(pos) local meta = M(pos) - local depth = meta:get_int("exploration_depth") - if depth == 0 then - depth = DEPTH_MIN + local ypos = meta:get_int("exploration_ypos") + if ypos == 0 then + ypos = math.min(YPOS_MAX, center(pos.y)) end - if depth + DEPTH_STEP < DEPTH_MAX then - depth = depth + DEPTH_STEP - meta:set_int("exploration_depth", depth) + local d = calc_depth(pos, {y = ypos}) + if d + DEPTH_STEP < DEPTH_MAX then + ypos = ypos - DEPTH_STEP + meta:set_int("exploration_ypos", ypos) 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 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) end -local function status(pos, player_name, depth, amount) - depth = depth + pos.y - local posC = {x = center(pos.x), y = pos.y, z = center(pos.z)} +local function status(pos, player_name, explore_pos, amount) + local depth = calc_depth(pos, explore_pos) 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 local function marker(player_name, pos) @@ -122,64 +139,81 @@ local function marker(player_name, pos) techage.switch_region(player_name, pos1, pos2) 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 data = vm:get_data() + print("#data", #data) + if useable_stone_block(data) then - gen_oil_bubble(pos1, posC, amount/10, data) + gen_oil_bubble(data) vm:set_data(data) vm:write_to_map() vm:update_map() - M(pos):set_int("oil_amount", amount) - M(pos):set_int("depth", depth) set_oil_amount(posC, amount) - marker(player_name, pos) - else - amount = 0 + return true end - status(pos, player_name, depth, amount) + return false end -local function emerge_area(pos, node, player_name) - if pos.y < -50 then - minetest.chat_send_player(player_name, - S("[TA Oil] No oil exploration possible at this depth! ")) - elseif get_oil_amount(pos) == 0 then -- nothing found so far? - local depth = get_next_depth(pos) - local posC = {x = center(pos.x), y = center(-depth), z = center(pos.z)} - local radius = 7 - 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}) +-- replace oil by air +local function generate_air_bubble(posC) + 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 data = vm:get_data() + local air = minetest.get_content_id("air") + local oil = minetest.get_content_id("techage:oil_source") + 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" minetest.swap_node(pos, node) 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 get_oil_amount(posC) == 0 then -- not explored so far? - minetest.emerge_area(pos1, pos2) - minetest.after(2, explore_area, pos, pos1, pos2, posC, depth, amount, player_name) - else - M(pos):set_int("oil_amount", amount) - M(pos):set_int("depth", depth) - minetest.after(2, status, pos, player_name, depth, amount) - minetest.after(2, marker, player_name, pos) + if generate_oil_bubble(posC, amount) then + marker(player_name, pos) + else + amount = 0 + end end - else - minetest.after(2, status, pos, player_name, depth, 0) - end + M(pos):set_int("oil_amount", amount) + end + + minetest.after(2, status, pos, player_name, posC, amount) 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) end end @@ -203,7 +237,7 @@ minetest.register_node("techage:oilexplorer", { }, 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, after_dig_node = function(pos, oldnode, oldmetadata, digger) techage.unmark_region(digger:get_player_name()) @@ -216,16 +250,17 @@ minetest.register_node("techage:oilexplorer", { minetest.register_node("techage:oilexplorer_on", { description = S("TA3 Oil Explorer"), tiles = { - { - image = "techage_filling4_ta3.png^techage_appl_oilexplorer_top4.png^techage_frame4_ta3_top.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 1.2, + { + image = "techage_filling4_ta3.png^techage_appl_oilexplorer_top4.png^techage_frame4_ta3_top.png", + backface_culling = false, + animation = { + type = "vertical_frames", + + aspect_w = 32, + aspect_h = 32, + length = 1.2, + }, }, - }, "techage_filling_ta3.png^techage_frame_ta3.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(), }) - minetest.register_craft({ output = "techage:oilexplorer", recipe = { @@ -260,13 +294,13 @@ techage.explore = {} function techage.explore.get_oil_info(pos) local amount = 0 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 - depth = depth + DEPTH_STEP - posC = {x = center(pos.x), y = center(-depth), z = center(pos.z)} amount = get_oil_amount(posC) + depth = calc_depth(pos, posC) + posC.y = posC.y - DEPTH_STEP end - return {depth = center(depth) - 1 + pos.y, amount = amount, storage_pos = posC} + return {depth = depth, amount = amount, storage_pos = posC} end 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) return amount-1 end + +-- generate_air_bubble(posC) +techage.explore.generate_air_bubble = generate_air_bubble \ No newline at end of file diff --git a/oil/pumpjack.lua b/oil/pumpjack.lua index ef7ff30..f709b3c 100644 --- a/oil/pumpjack.lua +++ b/oil/pumpjack.lua @@ -35,6 +35,7 @@ local function has_oil(pos, meta) if amount > 0 then return true end + techage.explore.generate_air_bubble(P(storage_pos)) end end diff --git a/power/schedule.lua b/power/schedule.lua index f7e7cab..03c3982 100644 --- a/power/schedule.lua +++ b/power/schedule.lua @@ -21,7 +21,7 @@ local N = function(pos) return minetest.get_node(pos).name end local power = techage.power local networks = techage.networks -local CYCLE_TIME = 2 +local CYCLE_TIME = 1.8 techage.schedule = {} diff --git a/settingtypes.txt b/settingtypes.txt index eb875ee..ca0002f 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -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) 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 # 1.0 is according to the mapgen generator # 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. # 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 \ No newline at end of file +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 \ No newline at end of file