explorer improved

This commit is contained in:
Joachim Stolberg 2019-05-27 21:12:17 +02:00
parent d342a3d669
commit 314c32e946
8 changed files with 124 additions and 160 deletions

View File

@ -22,12 +22,13 @@ local I,_ = dofile(MP.."/intllib.lua")
techage.firebox = {}
local BURN_TIME_FACTOR = 2
local BURN_TIME_FACTOR = 1
techage.firebox.Burntime = {
["techage:charcoal"] = true, -- will be replaced by burntime
["default:coal_lump"] = true,
["default:coalblock"] = true,
["techage:oil_source"] = true
}
local function determine_burntimes()

View File

@ -38,7 +38,8 @@ function techage.mark_region(name, pos1, pos2)
if marker ~= nil then
marker:set_properties({
visual_size={x=sizex * 2, y=sizey * 2},
collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness},
--collisionbox = {-sizex, -sizey, -thickness, sizex, sizey, thickness},
collisionbox = {0,0,0, 0,0,0},
})
marker:get_luaentity().player_name = name
table.insert(markers, marker)
@ -51,7 +52,8 @@ function techage.mark_region(name, pos1, pos2)
if marker ~= nil then
marker:set_properties({
visual_size={x=sizez * 2, y=sizey * 2},
collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez},
--collisionbox = {-thickness, -sizey, -sizez, thickness, sizey, sizez},
collisionbox = {0,0,0, 0,0,0},
})
marker:setyaw(math.pi / 2)
marker:get_luaentity().player_name = name
@ -73,10 +75,8 @@ end
minetest.register_entity(":techage:region_cube", {
initial_properties = {
visual = "upright_sprite",
visual_size = {x=1.1, y=1.1},
textures = {"techage_cube_mark.png"},
use_texture_alpha = true,
visual_size = {x=10, y=10},
physical = false,
},
on_step = function(self, dtime)

View File

@ -31,6 +31,7 @@ else
dofile(MP.."/basis/command.lua") -- tubelib replacement
dofile(MP.."/basis/consumer.lua") -- consumer base model
dofile(MP.."/basis/firebox_lib.lua") -- common firebox functions
dofile(MP.."/basis/mark.lua")
-- Overrides
dofile(MP.."/overrides/signs_bot.lua")
@ -89,7 +90,6 @@ else
dofile(MP.."/basic_machines/gravelrinser.lua")
dofile(MP.."/basic_machines/chest.lua")
dofile(MP.."/basic_machines/autocrafter.lua")
dofile(MP.."/basic_machines/mark.lua")
dofile(MP.."/basic_machines/forceload.lua")
dofile(MP.."/basic_machines/electronic_fab.lua")
if techage.basalt_stone_enabled then

View File

@ -30,8 +30,6 @@ minetest.register_craftitem("techage:baborium_ingot", {
inventory_image = "techage_baborium_ingot.png",
})
minetest.register_ore({
ore_type = "scatter",
ore = "techage:stone_with_baborium",
@ -43,3 +41,9 @@ minetest.register_ore({
y_max = -260,
})
minetest.register_craft({
type = 'cooking',
output = 'techage:baborium_ingot',
recipe = 'techage:baborium_lump',
cooktime = 5,
})

View File

@ -8,27 +8,18 @@ local MP = minetest.get_modpath("techage")
local I,IS = dofile(MP.."/intllib.lua")
local PROBABILITY = 2
local OIL_MIN = 1000
local OIL_MAX = 20000
local DEPTH_MIN = (16 * 7) - 8
local DEPTH_MAX = (16 * 60) - 8
local PROBABILITY = 10
local OIL_MIN = 500
local OIL_MAX = 10000
local DEPTH_MIN = 8
local DEPTH_MAX = (16 * 25) + 8
local DEPTH_STEP = 96
local seed = 1234
local function get_node_name(pos)
local node = minetest.get_node_or_nil(pos)
if node then
return node.name
end
local vm = minetest.get_voxel_manip()
local MinEdge, MaxEdge = vm:read_from_map(pos, pos)
local data = vm:get_data()
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
local idx = area:index(pos.x, pos.y, pos.z)
return minetest.get_name_from_content_id(data[idx])
end
local seed = 1234 -- confidental!
local InvalidGroundNodes = {
"air",
}
local function oil_amount(pos)
local block_key = seed +
@ -49,10 +40,6 @@ local function center(coord)
return (math.floor(coord/16) * 16) + 8
end
local Invalid = {
"air",
}
local function gen_oil_slice(pos1, posc, y, radius, data, id)
local y_offs = (y - pos1.y) * 16
for x = posc.x - radius, posc.x + radius do
@ -66,6 +53,7 @@ end
local function gen_oil_bubble(pos1, posC, amount, 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
@ -81,7 +69,7 @@ local function useable_stone_block(data)
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 Invalid[itemname] then
if not ndef or not ndef.is_ground_content or InvalidGroundNodes[itemname] then
return false
end
valid[id] = true
@ -90,77 +78,100 @@ local function useable_stone_block(data)
return true
end
local function explore_area(posS, depth, amount, player_name, pos1, pos2, posC)
if amount > 0 and M(posS):get_int("oil_amount") == 0 then
local vm = minetest.get_voxel_manip(pos1, pos2)
local data = vm:get_data()
if useable_stone_block(data) then
gen_oil_bubble(pos1, posC, amount/10, data)
vm:set_data(data)
vm:write_to_map()
vm:update_map()
print("explore_area", S(pos1), S(pos2))
else
amount = 0
end
end
M(posS):set_int("oil_amount", amount)
minetest.chat_send_player(player_name, "[TA Oil] depth: "..tostring(depth)..
", Oil: "..tostring(amount).." ")
end
local function get_next_depth(pos)
local meta = M(pos)
local name = get_node_name(pos)
local depth = DEPTH_MIN
if name == "techage:oilstorage" then
if meta:get_int("oil_amount") == 0 then
depth = M(pos):get_int("exploration_depth") + 32
else
depth = M(pos):get_int("exploration_depth")
end
else
minetest.set_node(pos, {name = "techage:oilstorage"})
local depth = meta:get_int("exploration_depth")
if depth == 0 then
depth = DEPTH_MIN
end
if depth + DEPTH_STEP < DEPTH_MAX then
depth = depth + DEPTH_STEP
meta:set_int("exploration_depth", depth)
end
M(pos):set_int("exploration_depth", depth)
return depth
end
local function emerge_area(pos, node, player_name)
node.name = "techage:oilexplorer_on"
minetest.swap_node(pos, node)
minetest.get_node_timer(pos):start(2.2)
local function get_oil_amount(pos)
return M(pos):get_int("oil_amount")
end
local function set_oil_amount(pos, amount)
minetest.set_node(pos, {name = "techage:oilstorage"})
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)}
minetest.chat_send_player(player_name,
"[TA Oil] "..S(posC).." depth: "..depth..", Oil: "..amount.." ")
end
local function marker(player_name, pos)
local posC = {x = center(pos.x), y = pos.y, z = center(pos.z)}
local pos1 = {x = posC.x - 1, y = posC.y - 1, z = posC.z - 1}
local pos2 = {x = posC.x + 1, y = posC.y + 3, z = posC.z + 1}
techage.switch_region(player_name, pos1, pos2)
end
local function explore_area(pos, pos1, pos2, posC, depth, amount, player_name)
local vm = minetest.get_voxel_manip(pos1, pos2)
local data = vm:get_data()
-- used to store the depth/amount info
local store_pos = {x = center(pos.x), y = -100, z = center(pos.z)}
local depth = get_next_depth(store_pos)
minetest.sound_play("techage_explore", {
pos = pos,
max_hear_distance = 8})
local posC = {x = center(pos.x), y = center(pos.y-depth), z = center(pos.z)}
local amount = oil_amount(posC)
if amount > 0 then
if useable_stone_block(data) then
gen_oil_bubble(pos1, posC, amount/10, data)
vm:set_data(data)
vm:write_to_map()
vm:update_map()
print("explore_area", S(pos1), S(pos2))
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
end
status(pos, player_name, depth, amount)
end
local function emerge_area(pos, node, player_name)
if 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}
print("emerge_area", S(pos1), S(pos2), S(posC))
minetest.emerge_area(pos1, pos2)
minetest.after(2, explore_area, store_pos, depth, amount, player_name, pos1, pos2, posC)
local amount = oil_amount(posC)
minetest.sound_play("techage_explore", {
pos = pos,
max_hear_distance = 8})
node.name = "techage:oilexplorer_on"
minetest.swap_node(pos, node)
minetest.get_node_timer(pos):start(2.2)
if amount > 0 then
if get_oil_amount(posC) == 0 then -- not explored so far?
print("emerge_area", S(pos1), S(pos2), S(posC))
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)
end
else
minetest.after(2, status, pos, player_name, depth, 0)
end
else
minetest.after(2, explore_area, store_pos, depth, 0, player_name)
end
status(pos, player_name, M(pos):get_int("depth"), M(pos):get_int("oil_amount"))
marker(player_name, pos)
end
end
--local function test(pos)
-- local posC = {x = center(pos.x), y = center(pos.y+20), z = center(pos.z)}
-- local pos1 = {x = posC.x - 8, y = posC.y - 8, z = posC.z - 8}
-- local pos2 = {x = posC.x + 7, y = posC.y + 7, z = posC.z + 7}
-- bubble(pos1, pos2, posC, math.random(10, 200))
--end
-- Used as storage for already explored blocks
-- Will be places -100 in the middle if a block (8,8)
minetest.register_node("techage:oilstorage", {
description = "TA Oil Storage",
tiles = {"default_stone.png"},
@ -196,7 +207,7 @@ minetest.register_node("techage:oilexplorer_on", {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 1.0,
length = 1.2,
},
},
"techage_filling_ta3.png^techage_frame_ta3.png",
@ -209,8 +220,9 @@ minetest.register_node("techage:oilexplorer_on", {
minetest.swap_node(pos, node)
end,
diggable = false,
is_ground_content = false,
groups = {snappy=2,cracky=2,oddly_breakable_by_hand=2},
groups = {not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
})
@ -301,4 +313,19 @@ minetest.register_node("techage:oil_flowing", {
liquid_range = 10,
post_effect_color = {a = 200, r = 1, g = 1, b = 1},
groups = {liquid = 5, not_in_creative_inventory = 1},
})
})
minetest.register_craft({
type = "fuel",
recipe = "techage:oil_source",
burntime = 40,
})
minetest.register_craft({
output = "techage:oilexplorer",
recipe = {
{"group:wood", "default:diamond", "group:wood"},
{"techage:baborium_ingot", "basic_materials:gear_steel", "techage:usmium_nuggets"},
{"group:wood", "techage:vacuum_tube", "group:wood"},
},
})

View File

@ -1,68 +0,0 @@
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local DAYS_VALID = (30 * 72) -- 30 real days
local storage = minetest.get_mod_storage()
local function data_maintenance()
minetest.log("info", "[MOD] minecart maintenance")
local day_count = minetest.get_day_count()
local tbl = storage:to_table()
for key,s in pairs(tbl.fields) do
local route = minetest.deserialize(s)
if not route.waypoints or not route.best_before or route.best_before < day_count then
storage:set_string(key, "")
else
minetest.log("info", "[minecart] Route: start="..key.." length="..#(route.waypoints))
end
end
end
minetest.after(1, data_maintenance)
-- Store data of running carts
minecart.CartsOnRail = {}
for key,val in pairs(minetest.deserialize(storage:get_string("CartsOnRail")) or {}) do
-- use invalid keys to force the cart spawning
minecart.CartsOnRail[-key] = val
end
minetest.register_on_shutdown(function()
data_maintenance()
storage:set_string("CartsOnRail", minetest.serialize(minecart.CartsOnRail))
end)
-- All positions as "pos_to_string" string
--Routes = {
-- start_pos = {
-- waypoints = {{spos, svel}, {spos, svel}, ...},
-- dest_pos = spos,
-- junctions = {
-- {spos = num},
-- {spos = num},
-- },
-- best_before = num
-- },
-- start_pos = {...},
--}
local Routes = {}
local NEW_ROUTE = {waypoints = {}, junctions = {}}
function minecart.store_route(key, route)
Routes[key] = table.copy(route)
Routes[key].best_before = minetest.get_day_count() + DAYS_VALID
storage:set_string(key, minetest.serialize(Routes[key]))
end
function minecart.get_route(key)
Routes[key] = Routes[key] or minetest.deserialize(storage:get_string(key)) or NEW_ROUTE
Routes[key].best_before = minetest.get_day_count() + DAYS_VALID
return Routes[key]
end
function minecart.del_route(key)
Routes[key] = nil -- remove from memory
storage:set_string(key, "") -- and from storage
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 B

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 363 B

After

Width:  |  Height:  |  Size: 393 B