revision on the way to v2 tubes/shafts

This commit is contained in:
Joachim Stolberg 2018-11-19 19:31:50 +01:00
parent de4f3d166f
commit f91dc4982e
8 changed files with 482 additions and 144 deletions

View File

@ -33,9 +33,9 @@ local function generate_string(sortedList)
default.gui_bg.. default.gui_bg..
default.gui_bg_img.. default.gui_bg_img..
default.gui_slots.. default.gui_slots..
"label[3,0; "..I("Select your destination").."]"} "label[4,0; "..I("Select your destination").."]"}
tRes[2] = "label[1,0.6;"..I("Destination").."]label[5.4,0.6;".. tRes[2] = "label[1,0.6;"..I("Destination").."]label[5,0.6;"..
I("Distance").."]label[7,0.6;"..I("Local Info").."]" I("Distance").."]label[6.6,0.6;"..I("Local Info").."]"
for idx,tDest in ipairs(sortedList) do for idx,tDest in ipairs(sortedList) do
if idx >= 12 then if idx >= 12 then
break break
@ -44,12 +44,12 @@ local function generate_string(sortedList)
local ypos2 = ypos - 0.2 local ypos2 = ypos - 0.2
local name = tDest.name or "<unknown>" local name = tDest.name or "<unknown>"
local distance = tDest.distance or 0 local distance = tDest.distance or 0
local info = tDest.info or "" local info = tDest.booking_info or ""
tRes[#tRes+1] = "button_exit[0,"..ypos2..";1,1;button;"..idx.."]" tRes[#tRes+1] = "button_exit[0,"..ypos2..";1,1;button;"..idx.."]"
tRes[#tRes+1] = "label[1,"..ypos..";"..string.sub(name,1,28).."]" tRes[#tRes+1] = "label[1,"..ypos..";"..string.sub(name,1,28).."]"
tRes[#tRes+1] = "label[5.4,"..ypos..";"..distance.." m]" tRes[#tRes+1] = "label[5,"..ypos..";"..distance.." m]"
tRes[#tRes+1] = "label[7,"..ypos..";"..info.."]" tRes[#tRes+1] = "label[6.6,"..ypos..";"..info.."]"
end end
return table.concat(tRes) return table.concat(tRes)
end end
@ -103,13 +103,14 @@ end
local function booking_machine_update(pos) local function booking_machine_update(pos)
local meta = M(pos) local meta = M(pos)
print("booking_machine_update")
local sStationPos = meta:get_string("sStationPos") local sStationPos = meta:get_string("sStationPos")
if sStationPos ~= "" then if sStationPos ~= "" then
local station_pos = P(sStationPos) local station_pos = P(sStationPos)
local counter = meta:get_int("change_counter") or 0 local counter = meta:get_int("change_counter") or 0
local changed, newcounter = Stations:changed(counter) local changed, newcounter = Stations:changed(counter)
if changed then if changed then
print("booking_machine_update") print("booking_machine_update changed")
meta:set_string("formspec", station_list_as_string(station_pos)) meta:set_string("formspec", station_list_as_string(station_pos))
meta:set_int("change_counter", newcounter) meta:set_int("change_counter", newcounter)
end end

View File

@ -53,6 +53,7 @@ local Shaft = tubelib2.Tube:new({
}) })
hyperloop.Shaft = Shaft hyperloop.Shaft = Shaft
local Elevators = hyperloop.Elevators
minetest.register_node("hyperloop:shaft", { minetest.register_node("hyperloop:shaft", {
description = I("Hyperloop Elevator Shaft"), description = I("Hyperloop Elevator Shaft"),
@ -94,8 +95,8 @@ minetest.register_node("hyperloop:shaft", {
end, end,
climbable = true, climbable = true,
paramtype2 = "facedir", -- important! paramtype2 = "facedir",
on_rotate = screwdriver.disallow, -- important! on_rotate = screwdriver.disallow,
paramtype = "light", paramtype = "light",
light_source = 2, light_source = 2,
sunlight_propagates = true, sunlight_propagates = true,
@ -144,8 +145,8 @@ minetest.register_node("hyperloop:shaftA", {
end, end,
climbable = true, climbable = true,
paramtype2 = "facedir", -- important! paramtype2 = "facedir",
on_rotate = screwdriver.disallow, -- important! on_rotate = screwdriver.disallow,
paramtype = "light", paramtype = "light",
light_source = 2, light_source = 2,
sunlight_propagates = true, sunlight_propagates = true,
@ -186,8 +187,8 @@ minetest.register_node("hyperloop:shaft2", {
end, end,
climbable = true, climbable = true,
paramtype2 = "facedir", -- important! paramtype2 = "facedir",
on_rotate = screwdriver.disallow, -- important! on_rotate = screwdriver.disallow,
paramtype = "light", paramtype = "light",
light_source = 2, light_source = 2,
sunlight_propagates = true, sunlight_propagates = true,
@ -229,8 +230,8 @@ minetest.register_node("hyperloop:shaftA2", {
end, end,
climbable = true, climbable = true,
paramtype2 = "facedir", -- important! paramtype2 = "facedir",
on_rotate = screwdriver.disallow, -- important! on_rotate = screwdriver.disallow,
paramtype = "light", paramtype = "light",
light_source = 2, light_source = 2,
sunlight_propagates = true, sunlight_propagates = true,
@ -265,14 +266,16 @@ local function formspec(pos, lFloors)
end end
local function update_formspec(pos) local function update_formspec(pos)
local meta = M(pos)
local counter = meta:get_int("change_counter") or 0
local changed, newcounter = Elevators:changed(counter)
local sKey = S(pos) local sKey = S(pos)
if not Cache[sKey] or hyperloop.tDatabase.elevator_chng_cnt ~= Cache[sKey].change_counter then if changed or not Cache[sKey] then
local tFloors = hyperloop.get_elevator_table(pos) local lFloors = Elevators:station_list(pos, pos, "level")
local lFloors = hyperloop.sort_based_on_level(tFloors)
Cache[sKey] = {} Cache[sKey] = {}
Cache[sKey].lFloors = lFloors Cache[sKey].lFloors = lFloors
Cache[sKey].formspec = formspec(pos, lFloors) Cache[sKey].formspec = formspec(pos, lFloors)
Cache[sKey].change_counter = hyperloop.tDatabase.elevator_chng_cnt meta:set_int("change_counter", newcounter)
end end
M(pos):set_string("formspec", Cache[sKey].formspec) M(pos):set_string("formspec", Cache[sKey].formspec)
end end
@ -288,7 +291,7 @@ local function update_elevator(pos, out_dir, peer_pos, peer_in_dir)
end end
end end
print("update_elevatorB", S(pos), out_dir, S(peer_pos), peer_in_dir) print("update_elevatorB", S(pos), out_dir, S(peer_pos), peer_in_dir)
hyperloop.update_elevator_conn_table(pos, out_dir, peer_pos) Elevators:update_connections(pos, out_dir, peer_pos)
end end
@ -408,7 +411,7 @@ minetest.register_node("hyperloop:elevator_bottom", {
after_place_node = function(pos, placer, itemstack, pointed_thing) after_place_node = function(pos, placer, itemstack, pointed_thing)
local facedir = hyperloop.get_facedir(placer) local facedir = hyperloop.get_facedir(placer)
hyperloop.update_elevator(pos, "<unknown>", {facedir=facedir, busy=false}) Elevators:set(pos, "<unknown>", {facedir=facedir, busy=false})
Shaft:after_place_node(pos, {5}) Shaft:after_place_node(pos, {5})
@ -417,7 +420,7 @@ minetest.register_node("hyperloop:elevator_bottom", {
local formspec = "size[6,4]".. local formspec = "size[6,4]"..
"label[0,0;"..I("Please insert floor name").."]" .. "label[0,0;"..I("Please insert floor name").."]" ..
"field[0.5,1.5;5,1;floor;"..I("Floor name")..";"..I("Base").."]" .. "field[0.5,1.5;5,1;floor;"..I("Floor name")..";"..I("Base").."]" ..
"button_exit[2,3.6;2,1;exit;"..I("Save").."]" "button_exit[2,3;2,1;exit;"..I("Save").."]"
meta:set_string("formspec", formspec) meta:set_string("formspec", formspec)
-- add upper part of the car -- add upper part of the car
@ -433,12 +436,14 @@ minetest.register_node("hyperloop:elevator_bottom", {
if floor == "" then if floor == "" then
return return
end end
hyperloop.update_elevator(pos, floor, {}) Elevators:update(pos, {name=floor})
update_formspec(pos) update_formspec(pos)
elseif fields.button ~= nil then -- destination selected? elseif fields.button ~= nil then -- destination selected?
update_formspec(pos) update_formspec(pos)
local floor = hyperloop.get_elevator(pos) local floor = Elevators:get(pos)
if floor then if floor then
floor = table.copy(floor)
floor.pos = pos
local sKey = S(pos) local sKey = S(pos)
local idx = tonumber(fields.button) local idx = tonumber(fields.button)
local lFloors = Cache[sKey].lFloors local lFloors = Cache[sKey].lFloors
@ -465,7 +470,7 @@ minetest.register_node("hyperloop:elevator_bottom", {
on_punch = function(pos, node, puncher, pointed_thing) on_punch = function(pos, node, puncher, pointed_thing)
update_formspec(pos) update_formspec(pos)
local floor = hyperloop.get_elevator(pos) local floor = Elevators:get(pos)
--dbg() --dbg()
if floor and floor.busy ~= true then if floor and floor.busy ~= true then
door_command(pos, floor.facedir, "open", true) door_command(pos, floor.facedir, "open", true)
@ -476,7 +481,7 @@ minetest.register_node("hyperloop:elevator_bottom", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
Shaft:after_dig_node(pos, {5}) Shaft:after_dig_node(pos, {5})
hyperloop.delete_elevator(pos) Elevators:delete(pos)
-- remove the bottom also -- remove the bottom also
pos = Shaft:get_pos(pos, 6) pos = Shaft:get_pos(pos, 6)
minetest.remove_node(pos) minetest.remove_node(pos)
@ -560,9 +565,9 @@ minetest.register_node("hyperloop:elevator_door", {
local floor_pos = P(M(pos):get_string("floor_pos")) local floor_pos = P(M(pos):get_string("floor_pos"))
if floor_pos ~= nil then if floor_pos ~= nil then
update_formspec(floor_pos) update_formspec(floor_pos)
local floor = hyperloop.get_elevator(floor_pos) local floor = Elevators:get(floor_pos)
if floor and floor.busy ~= true then if floor and floor.busy ~= true then
door_command(floor.pos, floor.facedir, "open", true) door_command(floor_pos, floor.facedir, "open", true)
end end
end end
end, end,

View File

@ -36,20 +36,17 @@ minetest.register_node("hyperloop:junction", {
M(pos):set_string("infotext", I("Junction")) M(pos):set_string("infotext", I("Junction"))
Stations:set(pos, "Junction", { Stations:set(pos, "Junction", {
owner = placer:get_player_name(), junction = true}) owner = placer:get_player_name(), junction = true})
Tube:after_place_node(pos, {1,2,3,4}) Tube:after_place_node(pos)
end, end,
tubelib2_on_update = function(pos, out_dir, peer_pos, peer_in_dir) tubelib2_on_update = function(pos, out_dir, peer_pos, peer_in_dir)
print("tubelib2_on_update", S(pos), S(peer_pos)) Stations:update_connections(pos, out_dir, peer_pos)
if out_dir <= 4 then local s = hyperloop.get_connection_string(pos)
Stations:update_connections(pos, out_dir, peer_pos) M(pos):set_string("infotext", I("Junction connected with ")..s)
local s = hyperloop.get_connection_string(pos)
M(pos):set_string("infotext", I("Junction connected with ")..s)
end
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
Tube:after_dig_node(pos, {1,2,3,4}) Tube:after_dig_node(pos)
Stations:delete(pos) Stations:delete(pos)
end, end,

View File

@ -117,6 +117,7 @@ minetest.register_node("hyperloop:station_map", {
wield_image = "hyperloop_stations_book.png", wield_image = "hyperloop_stations_book.png",
groups = {cracky=1, book=1}, groups = {cracky=1, book=1},
on_use = map_on_use, on_use = map_on_use,
on_place = map_on_secondary_use,
on_secondary_use = map_on_secondary_use, on_secondary_use = map_on_secondary_use,
stack_max = 1, stack_max = 1,
}) })

View File

@ -23,47 +23,51 @@ local M = minetest.get_meta
local Tube = hyperloop.Tube local Tube = hyperloop.Tube
local Shaft = hyperloop.Shaft local Shaft = hyperloop.Shaft
local Elevators = hyperloop.Elevators
local Stations = hyperloop.Stations
local tLegacyNodeNames = {} local tLegacyNodeNames = {}
-- convert legacy tubes to current tubes -- convert legacy tubes to current tubes
minetest.register_node("hyperloop:tube0", { for idx = 0,2 do
description = "Hyperloop Legacy Tube", minetest.register_node("hyperloop:tube"..idx, {
tiles = { description = "Hyperloop Legacy Tube",
-- up, down, right, left, back, front tiles = {
"hyperloop_tube_locked.png^[transformR90]", -- up, down, right, left, back, front
"hyperloop_tube_locked.png^[transformR90]", "hyperloop_tube_locked.png^[transformR90]",
'hyperloop_tube_closed.png', "hyperloop_tube_locked.png^[transformR90]",
'hyperloop_tube_closed.png', 'hyperloop_tube_closed.png',
'hyperloop_tube_open.png', 'hyperloop_tube_closed.png',
'hyperloop_tube_open.png', 'hyperloop_tube_open.png',
}, 'hyperloop_tube_open.png',
},
after_place_node = function(pos, placer, itemstack, pointed_thing) after_place_node = function(pos, placer, itemstack, pointed_thing)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
node.name = "hyperloop:tube" node.name = "hyperloop:tubeS"
minetest.swap_node(pos, node) minetest.swap_node(pos, node)
if not Tube:after_place_tube(pos, placer, pointed_thing) then if not Tube:after_place_tube(pos, placer, pointed_thing) then
minetest.remove_node(pos) minetest.remove_node(pos)
return true return true
end end
return false return false
end, end,
paramtype2 = "facedir",
node_placement_prediction = "hyperloop:tube",
groups = {cracky=2, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
paramtype2 = "facedir",
node_placement_prediction = "hyperloop:tubeS",
groups = {cracky=2, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_metal_defaults(),
})
end
local function convert_legary_nodes(self, pos, dir) local function convert_legary_nodes(self, pos, dir)
local convert_next_tube = function(self, pos, dir) local convert_next_tube = function(self, pos, dir)
local npos, node = self:get_node(pos, dir) local npos, node = self:get_node(pos, dir)
--print("convert_legary_nodes", S(npos), node.name) print("convert_legary_nodes", S(npos), node.name)
if tLegacyNodeNames[node.name] then if tLegacyNodeNames[node.name] then
local dir1, dir2, num = self:determine_dir1_dir2_and_num_conn(npos) local dir1, dir2, num = self:determine_dir1_dir2_and_num_conn(npos)
--print("convert_legary_nodes", dir1, dir2, num) print("convert_legary_nodes", dir1, dir2, num)
if dir1 then if dir1 then
self.clbk_after_place_tube(self:tube_data_to_table(npos, dir1, self.clbk_after_place_tube(self:tube_data_to_table(npos, dir1,
dir2 or tubelib2.Turn180Deg[dir1], num)) dir2 or tubelib2.Turn180Deg[dir1], num))
@ -100,10 +104,27 @@ local function convert_line(self, pos, dir)
end end
-- local tWifiNodes = {} -- user for pairing
-- Wifi nodes local lWifiNodes = {} -- used for post processing
--
local tWifiNodes = {} local function set_pairing(pos, peer_pos)
print("set_pairing", S(pos), S(peer_pos))
M(pos):set_int("tube_dir", Tube:get_primary_dir(pos))
M(peer_pos):set_int("tube_dir", Tube:get_primary_dir(peer_pos))
local tube_dir1 = Tube:store_teleport_data(pos, peer_pos)
local tube_dir2 = Tube:store_teleport_data(peer_pos, pos)
end
local function wifi_post_processing()
for _,pos in ipairs(lWifiNodes) do
local dir = Tube:get_primary_dir(pos)
local npos = Tube:get_pos(pos, dir)
Tube:tool_repair_tube(npos)
end
end
-- Wifi nodes don't know their counterpart. -- Wifi nodes don't know their counterpart.
-- But by means of the tube head nodes, two -- But by means of the tube head nodes, two
@ -120,7 +141,7 @@ local function determine_wifi_pairs(pos)
if item[1] == pos2 and item[2] == pos1 then if item[1] == pos2 and item[2] == pos1 then
tWifiNodes[k] = nil tWifiNodes[k] = nil
-- start paring -- start paring
Tube:set_pairing(P(k), pos) set_pairing(P(k), pos)
return return
end end
end end
@ -131,10 +152,11 @@ end
local function next_node_on_the_way_to_a_wifi_node(pos) local function next_node_on_the_way_to_a_wifi_node(pos)
local dirs = {} local dirs = {}
for dir = 1, 6 do for dir = 1, 6 do
local npos, node = Tube:get_next_node(pos, dir) local npos, node = Tube:get_node(pos, dir)
if node.name == "hyperloop:tube" or node.name == "hyperloop:tube1" or node.name == "hyperloop:tube2" then if tLegacyNodeNames[node.name] then
dirs[#dirs+1] = dir dirs[#dirs+1] = dir
elseif node and node.name == "hyperloop:tube_wifi1" then elseif node.name == "hyperloop:tube_wifi1" then
lWifiNodes[#lWifiNodes+1] = npos
determine_wifi_pairs(npos) determine_wifi_pairs(npos)
end end
end end
@ -149,7 +171,7 @@ end
local function search_wifi_node(pos, dir) local function search_wifi_node(pos, dir)
local convert_next_tube = function(pos, dir) local convert_next_tube = function(pos, dir)
local npos, node = Tube:get_next_node(pos, dir) local npos, node = Tube:get_node(pos, dir)
local dir1, dir2, num = next_node_on_the_way_to_a_wifi_node(npos) local dir1, dir2, num = next_node_on_the_way_to_a_wifi_node(npos)
if dir1 then if dir1 then
if tubelib2.Turn180Deg[dir] == dir1 then if tubelib2.Turn180Deg[dir] == dir1 then
@ -174,34 +196,25 @@ end
local function search_wifi_node_in_all_dirs(pos) local function search_wifi_node_in_all_dirs(pos)
-- check all positions -- check all positions
for dir = 1, 6 do for dir = 1, 6 do
local npos, node = Tube:get_next_node(pos, dir) local npos, node = Tube:get_node(pos, dir)
if node and node.name == "hyperloop:tube1" then if node and node.name == "hyperloop:tube1" then
search_wifi_node(pos, dir) search_wifi_node(pos, dir)
end end
end end
end end
--
-- Stations/Junctions
--
local function convert_tube_line(pos) local function convert_tube_line(pos)
-- check all positions -- check all positions
for dir = 1, 6 do for dir = 1, 6 do
local npos, node = Tube:get_next_node(pos, dir) local npos, node = Tube:get_node(pos, dir)
if node and node.name == "hyperloop:tube1" then if node and node.name == "hyperloop:tube1" then
local peer = Tube:convert_tube_line(pos, dir) convert_line(Tube, pos, dir)
--local peer = Tube:repair_tube_line(pos, dir)
--print("npos", FoundWifiNodes[S(npos)]) --print("npos", FoundWifiNodes[S(npos)])
end end
end end
end end
--
-- Elevator shafts
--
local function convert_shaft_line(pos) local function convert_shaft_line(pos)
-- check lower position -- check lower position
convert_line(Shaft, pos, 5) convert_line(Shaft, pos, 5)
@ -211,11 +224,42 @@ local function convert_shaft_line(pos)
pos.y = pos.y - 1 pos.y = pos.y - 1
end end
local function station_name(item)
if item.junction == true then
return "Junction"
elseif item.station_name then
return item.station_name
else
return "Station"
end
end
local function add_to_table(tbl, tValues)
local res = table.copy(tbl)
for k,v in pairs(tValues) do
tbl[k] = v
end
return res
end
local function convert_station_data(tAllStations) local function convert_station_data(tAllStations)
tLegacyNodeNames = {
["hyperloop:tube0"] = true,
["hyperloop:tube1"] = true,
["hyperloop:tube2"] = true,
}
local originNodeNames = add_to_table(Tube.primary_node_names, tLegacyNodeNames)
for key,item in pairs(tAllStations) do for key,item in pairs(tAllStations) do
if item.pos and Tube:secondary_node(item.pos) then if item.pos and Tube:secondary_node(item.pos) then
hyperloop.data.tAllStations[key] = item Stations:set(item.pos, station_name(item), {
owner = item.owner or "<unknown>",
junction = item.junction,
facedir = item.facedir,
booking_info = item.booking_info,
booking_pos = item.booking_pos,
})
end end
end end
-- First perform the Wifi node pairing -- First perform the Wifi node pairing
@ -231,9 +275,13 @@ local function convert_station_data(tAllStations)
if item.pos and Tube:secondary_node(item.pos) then if item.pos and Tube:secondary_node(item.pos) then
convert_tube_line(item.pos) convert_tube_line(item.pos)
Tube:after_place_node(item.pos) Tube:after_place_node(item.pos)
hyperloop.update_routes(item.pos) --hyperloop.update_routes(item.pos)
end end
end end
-- Repair the tube lines of wifi nodes
wifi_post_processing()
Tube.primary_node_names = originNodeNames
end end
local function convert_elevator_data(tAllElevators) local function convert_elevator_data(tAllElevators)
@ -241,21 +289,21 @@ local function convert_elevator_data(tAllElevators)
["hyperloop:shaft"] = true, ["hyperloop:shaft"] = true,
["hyperloop:shaft2"] = true, ["hyperloop:shaft2"] = true,
} }
hyperloop.tDatabase.tElevators = {} local originNodeNames = add_to_table(Shaft.primary_node_names, tLegacyNodeNames)
for pos,tElevator in pairs(tAllElevators) do for pos,tElevator in pairs(tAllElevators) do
for _,floor in pairs(tElevator.floors) do for _,floor in pairs(tElevator.floors) do
if floor.pos and Shaft:secondary_node(floor.pos) then if floor.pos and Shaft:secondary_node(floor.pos) then
local new_floor = { Elevators:set(floor.pos, floor.name, {
conn = {},
name = floor.name,
facedir = floor.facedir, facedir = floor.facedir,
} })
local sKey = S(floor.pos)
hyperloop.tDatabase.tElevators[sKey] = new_floor
convert_shaft_line(floor.pos) convert_shaft_line(floor.pos)
M(floor.pos):set_int("change_counter", 0)
end end
end end
end end
Shaft.primary_node_names = originNodeNames
end end
@ -273,26 +321,32 @@ local function migrate()
local data = hyperloop.file2table("mod_hyperloop.data") local data = hyperloop.file2table("mod_hyperloop.data")
if data then if data then
hyperloop.convert = true hyperloop.convert = true
--convert_station_data(data.tAllStations) convert_station_data(data.tAllStations)
convert_elevator_data(data.tAllElevators) convert_elevator_data(data.tAllElevators)
os.remove(wpath..DIR_DELIM.."mod_hyperloop.data") os.remove(wpath..DIR_DELIM.."mod_hyperloop.data")
hyperloop.convert = nil hyperloop.convert = nil
end end
print(dump(hyperloop.tDatabase))
end end
minetest.after(5, migrate) minetest.after(5, migrate)
minetest.register_lbm({
label = "[Hyperloop] booking/seat/door migration",
--function Tube:set_pairing(pos, peer_pos) name = "hyperloop:migrate",
nodenames = {
-- M(pos):set_int("tube_dir", self:get_primary_dir(pos)) "hyperloop:booking", "hyperloop:booking_ground",
-- M(peer_pos):set_int("tube_dir", self:get_primary_dir(peer_pos)) "hyperloop:doorTopPassive", "hyperloop:doorBottom",
"hyperloop:seat",
-- local tube_dir1 = self:store_teleport_data(pos, peer_pos) },
-- local tube_dir2 = self:store_teleport_data(peer_pos, pos) run_at_every_load = true,
action = function(pos, node)
-- self:delete_tube_meta_data(pos, tube_dir1) local meta = M(pos)
-- self:delete_tube_meta_data(peer_pos, tube_dir2) if meta:get_string("key_str") ~= "" then
--end local s = meta:get_string("key_str")
meta:set_string("sStationPos", "("..string.sub(s, 2, -2)..")")
if node.name == "hyperloop:booking" or node.name == "hyperloop:booking_ground" then
meta:set_int("change_counter", 0)
end
end
end
})

View File

@ -91,6 +91,7 @@ end
local function sort_based_on_distance(tStations, pos) local function sort_based_on_distance(tStations, pos)
local lStations = table_to_list(table.copy(tStations)) local lStations = table_to_list(table.copy(tStations))
-- to be able to sort the list, the distance to pos has to be added -- to be able to sort the list, the distance to pos has to be added
print("sort_based_on_distance", S(pos), dump(lStations))
lStations = add_distance_to_list(lStations, pos) lStations = add_distance_to_list(lStations, pos)
table.sort(lStations, function(a,b) return a.distance < b.distance end) table.sort(lStations, function(a,b) return a.distance < b.distance end)
return lStations return lStations
@ -173,6 +174,7 @@ function Network:delete(pos)
end end
function Network:changed(counter) function Network:changed(counter)
print ("changed", self.change_counter, counter)
return self.change_counter > counter, self.change_counter return self.change_counter > counter, self.change_counter
end end

View File

@ -263,12 +263,12 @@ minetest.register_node("hyperloop:station", {
hyperloop.check_network_level(pos, placer) hyperloop.check_network_level(pos, placer)
M(pos):set_string("infotext", I("Station")) M(pos):set_string("infotext", I("Station"))
store_station(pos, placer) store_station(pos, placer)
Tube:after_place_node(pos, {1,2,3,4}) Tube:after_place_node(pos)
end, end,
tubelib2_on_update = function(pos, out_dir, peer_pos, peer_in_dir) tubelib2_on_update = function(pos, out_dir, peer_pos, peer_in_dir)
print("tubelib2_on_update", S(pos), S(peer_pos)) print("tubelib2_on_update", S(pos), S(peer_pos))
if out_dir <= 4 then if out_dir <= 5 then
Stations:update_connections(pos, out_dir, peer_pos) Stations:update_connections(pos, out_dir, peer_pos)
local s = hyperloop.get_connection_string(pos) local s = hyperloop.get_connection_string(pos)
M(pos):set_string("infotext", I("Station connected with ")..s) M(pos):set_string("infotext", I("Station connected with ")..s)
@ -295,7 +295,7 @@ minetest.register_node("hyperloop:station", {
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
Tube:after_dig_node(pos, {1,2,3,4}) Tube:after_dig_node(pos)
Stations:delete(pos) Stations:delete(pos)
end, end,

View File

@ -1,35 +1,313 @@
{ {
-- Junction owner = "JoSto",
["\"426,2,549\""] = { pos = {
owner = "JoSto", y = 2,
pos = {y = 2,x = 426,z = 549}, x = 426,
junction = true, z = 549
routes = { },
{"(426,2,550)","(426,6,551)"}, junction = true,
{"(426,2,548)","(426,2,542)"} routes = {
{
"(426,2,550)",
"(426,6,551)"
},
{
"(426,2,548)",
"(426,2,542)"
}
}
}
{
owner = "JoSto",
pos = {
y = 2,
x = 426,
z = 541
},
junction = true,
routes = {
{
"(426,2,542)",
"(426,2,548)"
}
}
}
{
owner = "JoSto",
pos = {
y = 5,
x = 500,
z = 400
},
routes = {
{
"(501,5,400)",
"(502,5,400)"
},
{
"(499,5,400)",
"(401,5,400)"
},
{
"(500,5,401)",
"(500,5,499)"
},
{
"(500,5,399)",
"(400,5,501)"
} }
}, },
-- Unfinished station junction = true
["\"505,0,400\""] = { }
owner = "JoSto", {
pos = {y = 0,x = 505,z = 400}, owner = "JoSto",
facedir = 2, pos = {
routes = { y = 5,
{"(504,0,400)","(503,4,400)"} x = 400,
}, z = 400
time_blocked = 0 },
}, routes = {
-- Station {
["\"432,2,545\""] = { "(401,5,400)",
owner = "JoSto", "(499,5,400)"
pos = {y = 2,x = 432,z = 545}, },
facedir = 0, {
booking_info = "", "(400,5,401)",
routes = { "(400,5,499)"
{"(432,2,544)","(432,2,534)"} },
}, {
booking_pos = {y = 4,x = 430,z = 545}, "(400,5,399)",
time_blocked = 64894, "(400,5,398)"
station_name = "x" }
}, },
junction = true
}
{
owner = "JoSto",
pos = {
y = 0,
x = 505,
z = 400
},
facedir = 2,
routes = {
{
"(504,0,400)",
"(503,4,400)"
}
},
time_blocked = 0
}
{
owner = "JoSto",
pos = {
y = 2,
x = 432,
z = 545
},
facedir = 0,
booking_info = "",
routes = {
{
"(432,2,544)",
"(432,2,534)"
}
},
booking_pos = {
y = 4,
x = 430,
z = 545
},
time_blocked = 64894,
station_name = "x"
}
{
owner = "JoSto",
pos = {
y = 5,
x = 503,
z = 400
},
facedir = 1,
station_name = "BBB",
routes = {
{
"(503,4,400)",
"(504,0,400)"
},
{
"(502,5,400)",
"(501,5,400)"
}
},
booking_info = "",
time_blocked = 64716,
booking_pos = {
y = 7,
x = 503,
z = 402
}
}
{
owner = "JoSto",
pos = {
y = 5,
x = 400,
z = 500
},
routes = {
{
"(401,5,500)",
"(499,5,500)"
},
{
"(399,5,500)",
"(398,5,500)"
},
{
"(400,5,501)",
"(500,5,399)"
},
{
"(400,5,499)",
"(400,5,401)"
}
},
junction = true
}
{
owner = "JoSto",
pos = {
y = 5,
x = 500,
z = 503
},
facedir = 1,
routes = {
{
"(500,5,502)",
"(500,5,501)"
}
},
time_blocked = 0
}
{
owner = "JoSto",
pos = {
y = 2,
x = 432,
z = 533
},
facedir = 2,
booking_info = "",
routes = {
{
"(432,2,534)",
"(432,2,544)"
}
},
booking_pos = {
y = 4,
x = 434,
z = 533
},
time_blocked = 64894,
station_name = "y"
}
{
owner = "JoSto",
pos = {
y = 5,
x = 397,
z = 500
},
facedir = 0,
routes = {
{
"(398,5,500)",
"(399,5,500)"
},
{
"(396,5,500)",
"(395,8,500)"
}
},
time_blocked = 0
}
{
owner = "JoSto",
pos = {
y = 8,
x = 394,
z = 500
},
facedir = 1,
station_name = "AAA",
routes = {
{
"(395,8,500)",
"(396,5,500)"
}
},
booking_info = "",
time_blocked = 64716,
booking_pos = {
y = 10,
x = 394,
z = 502
}
}
{
owner = "JoSto",
pos = {
y = 5,
x = 500,
z = 500
},
routes = {
{
"(499,5,500)",
"(401,5,500)"
},
{
"(500,5,501)",
"(500,5,502)"
},
{
"(500,5,499)",
"(500,5,401)"
}
},
junction = true
}
{
owner = "JoSto",
pos = {
y = 5,
x = 400,
z = 397
},
facedir = 3,
routes = {
{
"(400,5,398)",
"(400,5,399)"
}
},
time_blocked = 0
}
{
owner = "JoSto",
pos = {
y = 6,
x = 426,
z = 552
},
routes = {
{
"(426,6,551)",
"(426,2,550)"
}
},
junction = true
} }