Crowbar added, bugfixes

master
Joachim Stolberg 2017-07-30 15:07:36 +02:00
parent 88634bba95
commit 8683e8917f
9 changed files with 208 additions and 127 deletions

View File

@ -63,6 +63,16 @@ local function valid_station_name(pos, station_name)
return min_key
end
local function naming_formspec(pos)
local meta = minetest.get_meta(pos)
local formspec = "size[6,4]"..
"label[0,0;Please insert station name to which this booking machine belongs]" ..
"field[0.5,1.5;5,1;name;Station name;MyTown]" ..
"field[0.5,2.7;5,1;info;Additional station information;]" ..
"button_exit[2,3.6;2,1;exit;Save]"
meta:set_string("formspec", formspec)
meta:set_int("change_counter", 0)
end
-- Form spec for the station list
-- param key_str: local station key
@ -89,6 +99,84 @@ local function formspec(key_str)
return table.concat(tRes)
end
local function on_receive_fields(pos, formname, fields, player)
local meta = minetest.get_meta(pos)
-- station name entered?
if fields.name ~= nil then
local station_name = string.trim(fields.name)
if station_name == "" then
return
end
-- valid name entered?
local key_str = valid_station_name(pos, station_name)
if key_str ~= nil then
if hyperloop.data.tAllStations[key_str]["booking_pos"] ~= nil then
hyperloop.chat(player, "Station has already a booking machine!")
return
end
-- store meta and generate station formspec
hyperloop.data.tAllStations[key_str]["booking_pos"] = pos
hyperloop.data.tAllStations[key_str]["booking_info"] = string.trim(fields.info)
hyperloop.data.tAllStations[key_str]["station_name"] = station_name
meta:set_string("key_str", key_str)
meta:set_string("infotext", "Station: "..station_name)
meta:set_string("formspec", formspec(key_str))
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
else
hyperloop.chat(player, "Invalid station name!")
end
-- destination selected?
elseif fields.button ~= nil then
local key_str = meta:get_string("key_str")
local idx = tonumber(fields.button)
local destination = get_station_list(key_str)[idx]
-- place booking of not already blocked
if hyperloop.reserve(key_str, destination) then
local dest_pos = hyperloop.data.tAllStations[destination].pos
hyperloop.data.booking[key_str] = hyperloop.get_key_str(dest_pos)
-- open the pod door
hyperloop.open_pod_door(hyperloop.get_station_data(key_str))
else
hyperloop.chat(player, "Station is still blocked. Please try again in a few seconds!")
end
end
end
local function on_destruct(pos)
local meta = minetest.get_meta(pos)
local key_str = meta:get_string("key_str")
if hyperloop.data.tAllStations[key_str] ~= nil
and hyperloop.data.tAllStations[key_str]["booking_pos"] ~= nil then
hyperloop.data.tAllStations[key_str]["station_name"] = nil
hyperloop.data.tAllStations[key_str]["booking_pos"] = nil
hyperloop.data.tAllStations[key_str]["booking_info"] = nil
end
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
end
local function update(pos)
local meta = minetest.get_meta(pos)
local key_str = meta:get_string("key_str")
local stations = get_station_list(key_str)
meta:set_string("formspec", formspec(key_str, stations))
end
-- wap from wall to ground
local function swap_node(pos, placer)
pos.y = pos.y - 1
if minetest.get_node_or_nil(pos).name ~= "air" then
local node = minetest.get_node(pos)
node.name = "hyperloop:booking_ground"
node.param2 = hyperloop.get_facedir(placer)
pos.y = pos.y + 1
minetest.swap_node(pos, node)
else
pos.y = pos.y + 1
end
end
-- wall mounted booking machine
minetest.register_node("hyperloop:booking", {
description = "Hyperloop Booking Machine",
tiles = {
@ -101,78 +189,57 @@ minetest.register_node("hyperloop:booking", {
"hyperloop_booking_front.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -8/16, -8/16, 2/16, 8/16, 8/16, 8/16},
},
},
after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
local formspec = "size[6,4]"..
"label[0,0;Please insert station name to which this booking machine belongs]" ..
"field[0.5,1.5;5,1;name;Station name;MyTown]" ..
"field[0.5,2.7;5,1;info;Additional station information;]" ..
"button_exit[2,3.6;2,1;exit;Save]"
meta:set_string("formspec", formspec)
meta:set_int("change_counter", 0)
naming_formspec(pos)
swap_node(pos, placer)
end,
on_receive_fields = function(pos, formname, fields, player)
local meta = minetest.get_meta(pos)
-- station name entered?
if fields.name ~= nil then
local station_name = string.trim(fields.name)
if station_name == "" then
return
end
-- valid name entered?
local key_str = valid_station_name(pos, station_name)
if key_str ~= nil then
if hyperloop.data.tAllStations[key_str]["booking_pos"] ~= nil then
hyperloop.chat(player, "Station has already a booking machine!")
return
end
-- store meta and generate station formspec
hyperloop.data.tAllStations[key_str]["booking_pos"] = pos
hyperloop.data.tAllStations[key_str]["booking_info"] = string.trim(fields.info)
hyperloop.data.tAllStations[key_str]["station_name"] = station_name
meta:set_string("key_str", key_str)
meta:set_string("infotext", "Station: "..station_name)
meta:set_string("formspec", formspec(key_str))
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
else
hyperloop.chat(player, "Invalid station name!")
end
-- destination selected?
elseif fields.button ~= nil then
local key_str = meta:get_string("key_str")
local idx = tonumber(fields.button)
local destination = get_station_list(key_str)[idx]
-- place booking of not already blocked
if hyperloop.reserve(key_str, destination) then
local dest_pos = hyperloop.data.tAllStations[destination].pos
hyperloop.data.booking[key_str] = hyperloop.get_key_str(dest_pos)
-- open the pod door
hyperloop.open_pod_door(hyperloop.get_station_data(key_str))
else
hyperloop.chat(player, "Station is still blocked. Please try again in a few seconds!")
end
end
on_receive_fields = on_receive_fields,
on_destruct = on_destruct,
update = update,
light_source = 2,
paramtype2 = "facedir",
groups = {cracky=2},
is_ground_content = false,
})
-- ground mounted booking machine
minetest.register_node("hyperloop:booking_ground", {
description = "Hyperloop Booking Machine",
tiles = {
-- up, down, right, left, back, front
"hyperloop_booking.png",
"hyperloop_booking.png",
"hyperloop_booking.png",
"hyperloop_booking.png",
"hyperloop_booking.png",
"hyperloop_booking_front.png",
},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -8/16, -8/16, -3/16, 8/16, 8/16, 3/16},
},
},
after_place_node = function(pos, placer, itemstack, pointed_thing)
naming_formspec(pos)
end,
on_destruct = function(pos)
local meta = minetest.get_meta(pos)
local key_str = meta:get_string("key_str")
if hyperloop.data.tAllStations[key_str] ~= nil
and hyperloop.data.tAllStations[key_str]["booking_pos"] ~= nil then
hyperloop.data.tAllStations[key_str]["station_name"] = nil
hyperloop.data.tAllStations[key_str]["booking_pos"] = nil
hyperloop.data.tAllStations[key_str]["booking_info"] = nil
end
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
end,
update = function(pos)
local meta = minetest.get_meta(pos)
local key_str = meta:get_string("key_str")
local stations = get_station_list(key_str)
meta:set_string("formspec", formspec(key_str, stations))
end,
on_receive_fields = on_receive_fields,
on_destruct = on_destruct,
update = update,
light_source = 2,
paramtype2 = "facedir",

View File

@ -431,6 +431,7 @@ minetest.register_node("hyperloop:elevator_door_top", {
},
drop = "",
paramtype = 'light',
paramtype2 = "facedir",
is_ground_content = false,
groups = {snappy = 3, not_in_creative_inventory=1},
@ -462,6 +463,7 @@ minetest.register_node("hyperloop:elevator_door", {
end,
drop = "",
paramtype = 'light',
paramtype2 = "facedir",
is_ground_content = false,
groups = {snappy = 3, not_in_creative_inventory=1},

View File

@ -25,6 +25,7 @@
hyperloop = {
data = {
version = 1, -- compatibility version
tAllStations = {}, -- tube networks
tAllElevators = {}, -- evevators
tWifi = {}, -- WiFi pairing
@ -33,7 +34,10 @@ hyperloop = {
}
}
hyperloop.debugging = false
-- Configuration settings
hyperloop.debugging = false -- for development only
hyperloop.wifi_enabled = minetest.setting_get("hyperloop_wifi_enabled") or false
hyperloop.free_tube_placement_enabled = minetest.setting_get("hyperloop_free_tube_placement_enabled") or false
dofile(minetest.get_modpath("hyperloop") .. "/utils.lua")
dofile(minetest.get_modpath("hyperloop") .. "/tube.lua")
@ -48,6 +52,7 @@ dofile(minetest.get_modpath("hyperloop") .. "/wifi.lua")
dofile(minetest.get_modpath("hyperloop") .. "/elevator.lua")
dofile(minetest.get_modpath("hyperloop") .. "/shaft.lua")
dofile(minetest.get_modpath("hyperloop") .. "/deco.lua")
dofile(minetest.get_modpath("hyperloop") .. "/tubecrowbar.lua")
dofile(minetest.get_modpath("hyperloop") .. "/recipes.lua")
print ("[MOD] Hyperloop loaded")

View File

@ -13,8 +13,6 @@
]]--
hyperloop.wifi_enabled = minetest.setting_get("hyperloop_wifi_enabled") or false
minetest.register_craftitem("hyperloop:hypersteel_ingot", {
description = "Hypersteel Ingot",

View File

@ -13,11 +13,13 @@
local function enter_display(tStation, text)
-- determine position
local lcd_pos = hyperloop.new_pos(tStation.pos, tStation.facedir, "1F", 2)
-- load map
minetest.forceload_block(lcd_pos)
-- update display
minetest.registered_nodes["hyperloop:lcd"].update(lcd_pos, text)
if tStation ~= nil then
local lcd_pos = hyperloop.new_pos(tStation.pos, tStation.facedir, "1F", 2)
-- load map
minetest.forceload_block(lcd_pos)
-- update display
minetest.registered_nodes["hyperloop:lcd"].update(lcd_pos, text)
end
end
local function on_final_close_door(tStation)

View File

@ -1,2 +1,7 @@
# Enable WiFi block for players (including recipe)
hyperloop_wifi_enabled (WiFi block enabled) bool false
# Enable free tube placement with no level limitation.
# If disabled, connected stations have to be on one level,
# typically underground.
hyperloop_free_tube_placement_enabled (free tube placement enabled) bool false

View File

@ -143,7 +143,7 @@ local function store_station(pos, placer)
-- do a facedir correction
facedir = (facedir + 3) % 4 -- face to LCD
hyperloop.data.tAllStations[key_str] = {
version=2, -- for version checks
version=hyperloop.version, -- for version checks
pos=pos, -- station/junction block
routes={}, -- will be calculated later
time_blocked=0, -- for reservations
@ -155,7 +155,7 @@ end
local function store_junction(pos, placer)
local key_str = hyperloop.get_key_str(pos)
hyperloop.data.tAllStations[key_str] = {
version=2, -- for version checks
version=hyperloop.version, -- for version checks
pos=pos, -- station/junction block
routes={}, -- will be calculated later
owner=placer:get_player_name(),
@ -324,20 +324,25 @@ local function destroy_station(pos, placer)
end
local key_str = hyperloop.get_key_str(pos)
local facedir = hyperloop.data.tAllStations[key_str].facedir
-- remove nodes
local _pos = table.copy(pos)
for _,item in ipairs(AssemblyPlan) do
local y, path, node_name = item[1], item[2], item[4]
_pos = hyperloop.new_pos(_pos, facedir, path, y)
minetest.remove_node(_pos)
if key_str ~= nil and hyperloop.data.tAllStations[key_str] ~= nil then
local facedir = hyperloop.data.tAllStations[key_str].facedir
-- remove nodes
local _pos = table.copy(pos)
for _,item in ipairs(AssemblyPlan) do
local y, path, node_name = item[1], item[2], item[4]
_pos = hyperloop.new_pos(_pos, facedir, path, y)
minetest.remove_node(_pos)
end
-- maintain meta
local meta = minetest.get_meta(pos)
meta:set_string("formspec", station_formspec .. "button_exit[1,3.9;2,1;build;Build Station]")
local inv = meta:get_inventory()
add_inventory_items(inv)
meta:set_int("built", 0)
else
local meta = minetest.get_meta(pos)
meta:set_int("built", 0)
end
-- maintain meta
local meta = minetest.get_meta(pos)
meta:set_string("formspec", station_formspec .. "button_exit[1,3.9;2,1;build;Build Station]")
local inv = meta:get_inventory()
add_inventory_items(inv)
meta:set_int("built", 0)
end
minetest.register_node("hyperloop:station", {

View File

@ -29,6 +29,7 @@
-- 3, nodes - two head nodes available
-- 4, nodes - one link node available
-- 5, nodes - invalid position
-- 12, nodes - two link nodes available
function hyperloop.scan_neighbours(pos)
local nodes = {}
local node, npos, idx
@ -39,19 +40,20 @@ function hyperloop.scan_neighbours(pos)
if string.find(node.name, "hyperloop:tube") then
node.pos = npos
table.insert(nodes, node)
if npos.y ~= pos.y then -- invalid level?
-- tubes on invalid level?
if not hyperloop.free_tube_placement_enabled and npos.y ~= pos.y then
return 5, nodes
end
idx = string.byte(node.name, -1) - 48
if idx == 0 then -- single node?
idx = 1
elseif idx == 2 then -- link node?
return 4, nodes
idx = 4
end
res = res * 2 + idx
end
end
if res > 3 then
if res > 4 and res ~= 12 then
res = 5
end
return res, nodes
@ -100,6 +102,23 @@ function hyperloop.remove_node(pos, node)
minetest.swap_node(pos, node)
end
-- Upgrade the tube and add meta data
-- param node: node to be replaced
-- param peer_pos: peer node position as string
function hyperloop.swap_tube_node(node, peer_pos)
local pos = minetest.pos_to_string(node.pos)
hyperloop.update_head_node(pos, peer_pos)
hyperloop.update_head_node(peer_pos, pos)
-- upgrade
node.diggable = true
if node.name == "hyperloop:tube2" then -- 2 connections?
node.name = "hyperloop:tube1"
elseif node.name == "hyperloop:tube1" then -- 1 connection?
node.name = "hyperloop:tube0"
end
minetest.get_meta(node.pos):set_string("infotext", peer_pos)
minetest.swap_node(node.pos, node)
end
-- Upgrade one node.
-- Needed when a tube node is digged.
@ -109,18 +128,7 @@ function hyperloop.upgrade_node(digged_node_pos)
local new_head_node = nodes[1]
-- copy peer pos first
local peer_pos = minetest.get_meta(digged_node_pos):get_string("peer")
local pos = minetest.pos_to_string(new_head_node.pos)
hyperloop.update_head_node(pos, peer_pos)
hyperloop.update_head_node(peer_pos, pos)
-- upgrade
new_head_node.diggable = true
if new_head_node.name == "hyperloop:tube2" then -- 2 connections?
new_head_node.name = "hyperloop:tube1"
elseif new_head_node.name == "hyperloop:tube1" then -- 1 connection?
new_head_node.name = "hyperloop:tube0"
end
minetest.get_meta(new_head_node.pos):set_string("infotext", peer_pos)
minetest.swap_node(new_head_node.pos, new_head_node)
hyperloop.swap_tube_node(new_head_node, peer_pos)
end
end

View File

@ -139,11 +139,11 @@ end
-- tRes is used for the resulting table (recursive call)
local function get_stations(tStations, key_str, tRes)
if tStations[key_str] == nil then
return nil
return {}
end
local dataSet = table.copy(tStations[key_str])
if dataSet == nil then
return nil
return {}
end
tStations[key_str] = nil
for _,route in ipairs(dataSet["routes"]) do
@ -239,6 +239,11 @@ function hyperloop.reserve(departure, arrival)
end
end
local function get_key_str(pos)
pos = minetest.pos_to_string(pos)
return '"'..string.sub(pos, 2, -2)..'"'
end
-- block the already reserved stations
function hyperloop.block(departure, arrival, seconds)
if hyperloop.data.tAllStations[departure] == nil then
@ -270,30 +275,14 @@ end
-------------------------------------------------------------------------------
local wpath = minetest.get_worldpath()
-- Convert V1 to V2
-- Convert legacy data
local function convert_station_list(tAllStations)
tRes = {}
for key,item in pairs(tAllStations) do
if item.version == nil then
item.version = 2
local pos = minetest.string_to_pos(item.pos)
item.pos = pos
if item.seat == true and item.booking_pos ~= nil then
item.station_name = key
end
key = hyperloop.get_key_str(pos)
-- remove legacy data
if item.version == hyperloop.version then
tRes[key] = item
end
if item.version == 2 then
item.version = 3
if item.placedir ~= nil then
tbl = {[0]=0, [1]=3, [2]=2, [3]=1}
item.facedir = tbl[item.placedir]
item.placedir = nil
elseif item.facedir == nil then
item.facedir = 0
end
end
tRes[key] = item
end
return tRes
end