elevator and promo blocks added
parent
d324198d53
commit
782e4ecdb4
48
booking.lua
48
booking.lua
|
@ -19,7 +19,7 @@ function hyperloop.update_all_booking_machines()
|
|||
print("update_all_booking_machines")
|
||||
end
|
||||
local t = minetest.get_us_time()
|
||||
for _, dataset in pairs(hyperloop.tAllStations) do
|
||||
for _, dataset in pairs(hyperloop.data.tAllStations) do
|
||||
if dataset.booking_pos ~= nil then
|
||||
local pos = minetest.string_to_pos(dataset.booking_pos)
|
||||
minetest.registered_nodes["hyperloop:booking"].update(pos)
|
||||
|
@ -45,23 +45,23 @@ end
|
|||
-- Form spec for the station list
|
||||
-- param station_name: local station name
|
||||
local function formspec(station_name)
|
||||
local tRes = {"size[10,10]label[3,0; Wähle dein Ziel :: Select your destination]"}
|
||||
tRes[2] = "label[1,0.6;Destination]label[3,0.6;Distance]label[4.5,0.6;Position]label[6,0.6;Local Info]"
|
||||
local local_pos = hyperloop.tAllStations[station_name]["pos"]
|
||||
local tRes = {"size[12,10]label[3,0; Wähle dein Ziel :: Select your destination]"}
|
||||
tRes[2] = "label[1,0.6;Destination]label[3.5,0.6;Distance]label[5,0.6;Position]label[7,0.6;Local Info]"
|
||||
local local_pos = hyperloop.data.tAllStations[station_name]["pos"]
|
||||
for idx,dest_name in ipairs(get_station_list(station_name)) do
|
||||
if idx >= 12 then
|
||||
break
|
||||
end
|
||||
local ypos = 0.5 + idx*0.8
|
||||
local ypos2 = ypos - 0.2
|
||||
local dest_info = hyperloop.tAllStations[dest_name]["booking_info"] or ""
|
||||
local dest_pos = hyperloop.tAllStations[dest_name]["pos"]
|
||||
local dest_info = hyperloop.data.tAllStations[dest_name]["booking_info"] or ""
|
||||
local dest_pos = hyperloop.data.tAllStations[dest_name]["pos"]
|
||||
local distance = hyperloop.distance(local_pos, dest_pos)
|
||||
tRes[#tRes+1] = "button_exit[0,"..ypos2..";1,1;button;"..idx.."]"
|
||||
tRes[#tRes+1] = "label[1,"..ypos..";"..dest_name.."]"
|
||||
tRes[#tRes+1] = "label[3,"..ypos..";"..distance.." m]"
|
||||
tRes[#tRes+1] = "label[4.2,"..ypos..";"..dest_pos.."]"
|
||||
tRes[#tRes+1] = "label[6,"..ypos..";"..dest_info.."]"
|
||||
tRes[#tRes+1] = "label[3.5,"..ypos..";"..distance.." m]"
|
||||
tRes[#tRes+1] = "label[4.7,"..ypos..";"..dest_pos.."]"
|
||||
tRes[#tRes+1] = "label[7,"..ypos..";"..dest_info.."]"
|
||||
end
|
||||
return table.concat(tRes)
|
||||
end
|
||||
|
@ -77,7 +77,7 @@ minetest.register_node("hyperloop:booking", {
|
|||
"hyperloop_booking.png",
|
||||
"hyperloop_booking_front.png",
|
||||
},
|
||||
|
||||
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local formspec = "size[6,4]"..
|
||||
|
@ -98,25 +98,25 @@ minetest.register_node("hyperloop:booking", {
|
|||
return
|
||||
end
|
||||
-- valid name entered?
|
||||
if hyperloop.tAllStations[station_name] ~= nil then
|
||||
if hyperloop.tAllStations[station_name]["booking_pos"] ~= nil then
|
||||
if hyperloop.data.tAllStations[station_name] ~= nil then
|
||||
if hyperloop.data.tAllStations[station_name]["booking_pos"] ~= nil then
|
||||
minetest.chat_send_player(player:get_player_name(),
|
||||
"[Hyperloop] Error: Station has already a booking machine!")
|
||||
return
|
||||
end
|
||||
-- check distance to the named station
|
||||
local station_pos = minetest.string_to_pos(hyperloop.tAllStations[station_name].pos)
|
||||
local station_pos = minetest.string_to_pos(hyperloop.data.tAllStations[station_name].pos)
|
||||
if hyperloop.distance(pos, station_pos) > 30 then
|
||||
minetest.chat_send_player(player:get_player_name(), "[Hyperloop] Error: station too far away!")
|
||||
return
|
||||
end
|
||||
-- store meta and generate station formspec
|
||||
hyperloop.tAllStations[station_name]["booking_pos"] = minetest.pos_to_string(pos)
|
||||
hyperloop.tAllStations[station_name]["booking_info"] = string.trim(fields.info)
|
||||
hyperloop.data.tAllStations[station_name]["booking_pos"] = minetest.pos_to_string(pos)
|
||||
hyperloop.data.tAllStations[station_name]["booking_info"] = string.trim(fields.info)
|
||||
meta:set_string("station_name", station_name)
|
||||
meta:set_string("infotext", "Station: "..station_name)
|
||||
meta:set_string("formspec", formspec(station_name))
|
||||
hyperloop.change_counter = hyperloop.change_counter + 1
|
||||
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
|
||||
else
|
||||
minetest.chat_send_player(player:get_player_name(), "[Hyperloop] Error: Invalid station name!")
|
||||
end
|
||||
|
@ -127,7 +127,7 @@ minetest.register_node("hyperloop:booking", {
|
|||
local destination = get_station_list(station_name)[idx]
|
||||
-- place booking of not already blocked
|
||||
if hyperloop.reserve(station_name, destination) then
|
||||
hyperloop.booking[station_name] = destination
|
||||
hyperloop.data.booking[station_name] = destination
|
||||
-- open the pod door
|
||||
hyperloop.open_pod_door(station_name)
|
||||
else
|
||||
|
@ -140,11 +140,11 @@ minetest.register_node("hyperloop:booking", {
|
|||
on_destruct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local station_name = meta:get_string("station_name")
|
||||
if hyperloop.tAllStations[station_name] ~= nil
|
||||
and hyperloop.tAllStations[station_name]["booking_pos"] ~= nil then
|
||||
hyperloop.tAllStations[station_name]["booking_pos"] = nil
|
||||
if hyperloop.data.tAllStations[station_name] ~= nil
|
||||
and hyperloop.data.tAllStations[station_name]["booking_pos"] ~= nil then
|
||||
hyperloop.data.tAllStations[station_name]["booking_pos"] = nil
|
||||
end
|
||||
hyperloop.change_counter = hyperloop.change_counter + 1
|
||||
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
|
||||
end,
|
||||
|
||||
update = function(pos)
|
||||
|
@ -168,13 +168,13 @@ minetest.register_abm({
|
|||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local counter = meta:get_int("change_counter") or 0
|
||||
if hyperloop.change_counter ~= counter then
|
||||
if hyperloop.data.change_counter ~= counter then
|
||||
local station_name = meta:get_string("station_name") or nil
|
||||
if station_name ~= nil and hyperloop.tAllStations[station_name] ~= nil then
|
||||
if station_name ~= nil and hyperloop.data.tAllStations[station_name] ~= nil then
|
||||
local stations = get_station_list(station_name)
|
||||
meta:set_string("formspec", formspec(station_name, stations))
|
||||
end
|
||||
meta:set_int("change_counter", hyperloop.change_counter)
|
||||
meta:set_int("change_counter", hyperloop.data.change_counter)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
8
door.lua
8
door.lua
|
@ -28,9 +28,9 @@ end
|
|||
-- cmnd: "close", "open", or "animate"
|
||||
function hyperloop.door_command(seat_pos, facedir, cmnd, station_name)
|
||||
-- one step forward
|
||||
local lcd_pos = vector.add(seat_pos, hyperloop.facedir2dir(facedir))
|
||||
local lcd_pos = vector.add(seat_pos, hyperloop.placedir_to_dir(facedir))
|
||||
-- one step left
|
||||
local door_pos1 = vector.add(lcd_pos, hyperloop.facedir2dir(facedir + 1))
|
||||
local door_pos1 = vector.add(lcd_pos, hyperloop.placedir_to_dir(facedir + 1))
|
||||
-- one step up
|
||||
local door_pos2 = vector.add(door_pos1, {x=0, y=1, z=0})
|
||||
|
||||
|
@ -46,7 +46,7 @@ function hyperloop.door_command(seat_pos, facedir, cmnd, station_name)
|
|||
minetest.sound_play("door", {
|
||||
pos = seat_pos,
|
||||
gain = 0.5,
|
||||
max_hear_distance = 5,
|
||||
max_hear_distance = 10,
|
||||
})
|
||||
node1.name = "air"
|
||||
minetest.swap_node(door_pos1, node1)
|
||||
|
@ -56,7 +56,7 @@ function hyperloop.door_command(seat_pos, facedir, cmnd, station_name)
|
|||
minetest.sound_play("door", {
|
||||
pos = seat_pos,
|
||||
gain = 0.5,
|
||||
max_hear_distance = 5,
|
||||
max_hear_distance = 10,
|
||||
})
|
||||
node1.name = "hyperloop:doorBottom"
|
||||
node1.param2 = facedir
|
||||
|
|
BIN
img/intro01.png
BIN
img/intro01.png
Binary file not shown.
Before Width: | Height: | Size: 293 KiB |
BIN
img/intro02.png
BIN
img/intro02.png
Binary file not shown.
Before Width: | Height: | Size: 339 KiB |
BIN
img/intro03.png
BIN
img/intro03.png
Binary file not shown.
Before Width: | Height: | Size: 263 KiB |
BIN
img/intro04.png
BIN
img/intro04.png
Binary file not shown.
Before Width: | Height: | Size: 277 KiB |
BIN
img/intro05.png
BIN
img/intro05.png
Binary file not shown.
Before Width: | Height: | Size: 285 KiB |
18
init.lua
18
init.lua
|
@ -21,25 +21,33 @@
|
|||
|
||||
|
||||
hyperloop = {
|
||||
tAllStations = {}, -- tube networks
|
||||
tWifi = {}, -- WiFi pairing
|
||||
booking = {}, -- placed bookings
|
||||
change_counter = 0, -- used for booking machine updates
|
||||
data = {
|
||||
tAllStations = {}, -- tube networks
|
||||
tAllElevators = {}, -- evevators
|
||||
tWifi = {}, -- WiFi pairing
|
||||
booking = {}, -- placed bookings
|
||||
change_counter = 0, -- used for booking machine updates
|
||||
}
|
||||
}
|
||||
|
||||
hyperloop.min_slope_counter = 10
|
||||
|
||||
hyperloop.debugging = false
|
||||
|
||||
dofile(minetest.get_modpath("hyperloop") .. "/utils.lua")
|
||||
dofile(minetest.get_modpath("hyperloop") .. "/tube.lua")
|
||||
dofile(minetest.get_modpath("hyperloop") .. "/booking.lua")
|
||||
dofile(minetest.get_modpath("hyperloop") .. "/junction.lua")
|
||||
dofile(minetest.get_modpath("hyperloop") .. "/station.lua")
|
||||
dofile(minetest.get_modpath("hyperloop") .. "/map.lua")
|
||||
dofile(minetest.get_modpath("hyperloop") .. "/door.lua")
|
||||
dofile(minetest.get_modpath("hyperloop") .. "/seat.lua")
|
||||
dofile(minetest.get_modpath("hyperloop") .. "/pod.lua")
|
||||
dofile(minetest.get_modpath("hyperloop") .. "/lcd.lua")
|
||||
dofile(minetest.get_modpath("hyperloop") .. "/wifi.lua")
|
||||
--dofile(minetest.get_modpath("hyperloop") .. "/elevator.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") .. "/recipes.lua")
|
||||
|
||||
print ("[MOD] Hyperloop loaded")
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
# Introduction
|
||||
|
||||
Connect two Junction blocks with a line of Tube blocks. The tube itself is automatically protected. You can dig only the ends of a tube line (head blocks). The junction block / station has to be protected manually.
|
||||
|
||||
A Junction block, which is the basis for a station, can have up to four tubes. That means you can build complex networks of tube lines. Each junction/station can be reaches from each point with one trip.
|
||||
|
||||
![Image](https://github.com/joe7575/Minetest-Hyperloop/blob/master/img/intro03.png)
|
||||
|
||||
|
||||
To build a station, give the Junction block a unique station name and place the Pod Seat on top of it.
|
||||
|
||||
![Image](https://github.com/joe7575/Minetest-Hyperloop/blob/master/img/intro01.png)
|
||||
|
||||
Build the pod around the seat according to the following picture. To get the best illusion of traveling, it is important that all pods are look the same from the inside.
|
||||
|
||||
![Image](https://github.com/joe7575/Minetest-Hyperloop/blob/master/img/intro04.png)
|
||||
|
||||
The pod shell is not important for the function, the minimal equipment for testing is: the Tube line with Junction blocks, a Pod Seat on each station, the Display in front of the seat, and the Booking Machine. The Booking Machine has to get the same station name as the Junction block and has to be placed nearby the Junction block (max. 30 blocks difference).
|
||||
|
||||
![Image](https://github.com/joe7575/Minetest-Hyperloop/blob/master/img/intro02.png)
|
||||
|
||||
|
||||
Keep a hole for the door which will be placed automatically when you start your first trip. The door hole has always to be on the left side of the pod (see the following picture).
|
||||
|
||||
![Image](https://github.com/joe7575/Minetest-Hyperloop/blob/master/img/intro05.png)
|
||||
|
||||
|
||||
For traveling you have to use the Booking Machine to select you destination. After booking, the pods (departure and arrival) are reserved for 20 seconds to start the trip. For starting the trip you have to use the Pod Seat. You will be placed on the seat and the door will close automatically.
|
||||
|
||||
|
33
junction.lua
33
junction.lua
|
@ -22,7 +22,7 @@ function hyperloop.update_junction(pos)
|
|||
minetest.registered_nodes["hyperloop:junction"].update(node.pos)
|
||||
end
|
||||
end
|
||||
hyperloop.change_counter = hyperloop.change_counter + 1
|
||||
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
|
||||
end
|
||||
|
||||
local function default_name(pos)
|
||||
|
@ -46,15 +46,20 @@ local function store_routes(pos, owner)
|
|||
end
|
||||
-- store list
|
||||
local spos = minetest.pos_to_string(pos)
|
||||
if hyperloop.tAllStations[station_name] == nil then
|
||||
if hyperloop.data.tAllStations[station_name] == nil then
|
||||
-- add a new station
|
||||
hyperloop.tAllStations[station_name] = {pos=spos, routes=tRoutes, time_blocked=0}
|
||||
hyperloop.data.tAllStations[station_name] = {pos=spos, routes=tRoutes, time_blocked=0}
|
||||
else
|
||||
hyperloop.tAllStations[station_name].routes = tRoutes
|
||||
hyperloop.data.tAllStations[station_name].routes = tRoutes
|
||||
end
|
||||
if owner ~= nil then
|
||||
hyperloop.tAllStations[station_name].owner = owner:get_player_name()
|
||||
hyperloop.data.tAllStations[station_name].owner = owner:get_player_name()
|
||||
end
|
||||
-- update the seat
|
||||
hyperloop.data.tAllStations[station_name]["seat"] = true
|
||||
local pos2 = vector.add(pos, {x=0, y=1, z=0})
|
||||
local meta2 = minetest.get_meta(pos2)
|
||||
meta2:set_string("station_name", station_name)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -72,7 +77,7 @@ minetest.register_node("hyperloop:junction", {
|
|||
meta:set_string("infotext", "Station "..default_name(pos))
|
||||
meta:set_string("formspec", formspec)
|
||||
store_routes(pos, placer)
|
||||
hyperloop.change_counter = hyperloop.change_counter + 1
|
||||
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
|
||||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, player)
|
||||
|
@ -84,11 +89,11 @@ minetest.register_node("hyperloop:junction", {
|
|||
return
|
||||
end
|
||||
-- delete temp name
|
||||
hyperloop.tAllStations[default_name(pos)] = nil
|
||||
hyperloop.data.tAllStations[default_name(pos)] = nil
|
||||
-- check if station already available
|
||||
local spos = minetest.pos_to_string(pos)
|
||||
if hyperloop.tAllStations[station_name] ~= nil
|
||||
and hyperloop.tAllStations[station_name]["pos"] ~= spos then
|
||||
if hyperloop.data.tAllStations[station_name] ~= nil
|
||||
and hyperloop.data.tAllStations[station_name]["pos"] ~= spos then
|
||||
minetest.chat_send_player(player:get_player_name(),
|
||||
"[Hyperloop] Error: Station name already assigned!")
|
||||
return
|
||||
|
@ -98,17 +103,17 @@ minetest.register_node("hyperloop:junction", {
|
|||
meta:set_string("station_name", station_name)
|
||||
meta:set_string("infotext", "Station '"..station_name.."'")
|
||||
store_routes(pos, player)
|
||||
hyperloop.change_counter = hyperloop.change_counter + 1
|
||||
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
|
||||
end,
|
||||
|
||||
on_destruct = function(pos)
|
||||
-- delete station data
|
||||
local meta = minetest.get_meta(pos)
|
||||
local station_name = meta:get_string("station_name")
|
||||
if hyperloop.tAllStations[station_name] ~= nil then
|
||||
hyperloop.tAllStations[station_name] = nil
|
||||
hyperloop.open_pod_door(station_name)
|
||||
hyperloop.change_counter = hyperloop.change_counter + 1
|
||||
if hyperloop.data.tAllStations[station_name] ~= nil then
|
||||
hyperloop.data.tAllStations[station_name] = nil
|
||||
hyperloop.open_pod_door(station_name)
|
||||
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
|
||||
end
|
||||
end,
|
||||
|
||||
|
|
23
lcd.lua
23
lcd.lua
|
@ -151,6 +151,15 @@ local lcd_box = {
|
|||
wall_top = {-8/16, 15/32, -8/16, 8/16, 8/16, 8/16}
|
||||
}
|
||||
|
||||
|
||||
function hyperloop.after_lcd_placed(pos, facedir)
|
||||
local param2 = minetest.get_node(pos).param2
|
||||
if param2 == 0 or param2 == 1 then
|
||||
minetest.add_node(pos, {name = "hyperloop:lcd", param2 = 3})
|
||||
end
|
||||
lcd_update(pos, " | | << Hyperloop >> | be anywhere")
|
||||
end
|
||||
|
||||
minetest.register_node("hyperloop:lcd", {
|
||||
drawtype = "nodebox",
|
||||
description = "Hyperloop Display",
|
||||
|
@ -165,13 +174,13 @@ minetest.register_node("hyperloop:lcd", {
|
|||
selection_box = lcd_box,
|
||||
groups = {choppy = 3, dig_immediate = 2},
|
||||
|
||||
after_place_node = function (pos)
|
||||
local param2 = minetest.get_node(pos).param2
|
||||
if param2 == 0 or param2 == 1 then
|
||||
minetest.add_node(pos, {name = "hyperloop:lcd", param2 = 3})
|
||||
end
|
||||
lcd_update(pos, " | | << Hyperloop >> | be anywhere")
|
||||
end,
|
||||
-- after_place_node = function (pos)
|
||||
-- local param2 = minetest.get_node(pos).param2
|
||||
-- if param2 == 0 or param2 == 1 then
|
||||
-- minetest.add_node(pos, {name = "hyperloop:lcd", param2 = 3})
|
||||
-- end
|
||||
-- lcd_update(pos, " | | << Hyperloop >> | be anywhere")
|
||||
-- end,
|
||||
|
||||
on_destruct = function(pos)
|
||||
clearscreen(pos)
|
||||
|
|
4
map.lua
4
map.lua
|
@ -17,7 +17,7 @@
|
|||
local function station_list_as_string(pos)
|
||||
local sortedList = {}
|
||||
local distance = 0
|
||||
for name, dataSet in pairs(table.copy(hyperloop.tAllStations)) do
|
||||
for name, dataSet in pairs(table.copy(hyperloop.data.tAllStations)) do
|
||||
distance = hyperloop.distance(pos, minetest.string_to_pos(dataSet["pos"]))
|
||||
dataSet.name = name
|
||||
dataSet.distance = distance
|
||||
|
@ -28,7 +28,7 @@ local function station_list_as_string(pos)
|
|||
end)
|
||||
if hyperloop.debugging then
|
||||
print("tAllStations="..dump(sortedList))
|
||||
print("tWifi="..dump(hyperloop.tWifi))
|
||||
print("tWifi="..dump(hyperloop.data.tWifi))
|
||||
end
|
||||
--local tRes = {"(player distance: station name (position) seat/machine/owner => directly connected with)\n\n"}
|
||||
local tRes = {"size[10,10]label[0,0;Dist.]label[0.9,0;Station]label[2.5,0;Position]label[4.2,0;State]label[5.6,0;Owner]label[7.1,0;Connected with]"}
|
||||
|
|
2
pod.lua
2
pod.lua
|
@ -18,7 +18,7 @@ function hyperloop.enter_display(seat_pos, facedir, text)
|
|||
return
|
||||
end
|
||||
-- determine position
|
||||
local pos = vector.add(seat_pos, hyperloop.facedir2dir(facedir))
|
||||
local pos = vector.add(seat_pos, hyperloop.placedir_to_dir(facedir))
|
||||
pos.y = pos.y + 1
|
||||
-- load map
|
||||
minetest.forceload_block(pos)
|
||||
|
|
63
recipes.lua
63
recipes.lua
|
@ -114,3 +114,66 @@ minetest.register_craft({
|
|||
{"hyperloop:hypersteel_ingot", "default:glass", ""},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "hyperloop:shaft 8",
|
||||
recipe = {
|
||||
{"hyperloop:hypersteel_ingot", "", "hyperloop:hypersteel_ingot"},
|
||||
{"", "", ""},
|
||||
{"hyperloop:hypersteel_ingot", "", "hyperloop:hypersteel_ingot"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "hyperloop:elevator_bottom 2",
|
||||
recipe = {
|
||||
{"", "default:glass", "hyperloop:hypersteel_ingot"},
|
||||
{"", "dye:red", "default:mese_crystal"},
|
||||
{"", "default:glass", "hyperloop:hypersteel_ingot"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "hyperloop:sign",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"", "dye:cyan", "hyperloop:hypersteel_ingot"},
|
||||
{"", "default:wood", "default:wood"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "hyperloop:poster1L",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"", "dye:white", "hyperloop:hypersteel_ingot"},
|
||||
{"", "dye:blue", "default:wood"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "hyperloop:poster2L",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"", "dye:white", "hyperloop:hypersteel_ingot"},
|
||||
{"", "dye:cyan", "default:wood"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "hyperloop:poster3L",
|
||||
recipe = {
|
||||
{"", "", ""},
|
||||
{"", "dye:white", "hyperloop:hypersteel_ingot"},
|
||||
{"", "dye:brown", "default:wood"},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "hyperloop:station",
|
||||
recipe = {
|
||||
{"hyperloop:pod_wall", "hyperloop:lcd", ""},
|
||||
{"hyperloop:pod_wall", "", "hyperloop:seat"},
|
||||
{"hyperloop:tube0", "hyperloop:tube0", "hyperloop:junction"},
|
||||
},
|
||||
})
|
||||
|
|
86
seat.lua
86
seat.lua
|
@ -53,7 +53,7 @@ local function on_arrival(player, src_pos, src_facedir, dst_pos, snd, radiant)
|
|||
-- rotate player to look in correct arrival direction
|
||||
-- calculate the look correction
|
||||
local offs = radiant - player:get_look_horizontal()
|
||||
local yaw = hyperloop.facedir2rad(facedir) - offs
|
||||
local yaw = hyperloop.placedir_to_rad(facedir) - offs
|
||||
player:set_look_yaw(yaw)
|
||||
end
|
||||
-- play arrival sound
|
||||
|
@ -61,7 +61,7 @@ local function on_arrival(player, src_pos, src_facedir, dst_pos, snd, radiant)
|
|||
minetest.sound_play("down2", {
|
||||
pos = dst_pos,
|
||||
gain = 0.5,
|
||||
max_hear_distance = 10
|
||||
max_hear_distance = 2
|
||||
})
|
||||
|
||||
minetest.after(6.0, on_open_door, dst_pos, facedir)
|
||||
|
@ -74,7 +74,7 @@ local function on_travel(src_pos, facedir, player, dst_pos, radiant, atime)
|
|||
local snd = minetest.sound_play("normal2", {
|
||||
pos = src_pos,
|
||||
gain = 0.5,
|
||||
max_hear_distance = 1,
|
||||
max_hear_distance = 2,
|
||||
loop = true,
|
||||
})
|
||||
hyperloop.door_command(src_pos, facedir, "animate", nil)
|
||||
|
@ -122,15 +122,15 @@ local function on_start_travel(pos, node, clicker)
|
|||
print("[Hyperloop] Error: station_name == nil!")
|
||||
return
|
||||
end
|
||||
local booking = hyperloop.booking[station_name]
|
||||
local booking = hyperloop.data.booking[station_name]
|
||||
if booking == nil then
|
||||
minetest.chat_send_player(clicker:get_player_name(), "[Hyperloop] No booking entered!")
|
||||
return
|
||||
end
|
||||
|
||||
local dataSet = table.copy(hyperloop.tAllStations[booking])
|
||||
local dataSet = table.copy(hyperloop.data.tAllStations[booking])
|
||||
-- delete booking
|
||||
hyperloop.booking[station_name] = nil
|
||||
hyperloop.data.booking[station_name] = nil
|
||||
if dataSet == nil then
|
||||
return
|
||||
end
|
||||
|
@ -148,14 +148,14 @@ local function on_start_travel(pos, node, clicker)
|
|||
minetest.sound_play("up2", {
|
||||
pos = pos,
|
||||
gain = 0.5,
|
||||
max_hear_distance = 10
|
||||
max_hear_distance = 2
|
||||
})
|
||||
-- close the door at arrival station
|
||||
hyperloop.door_command(dest_pos, dest_facedir, "close", dest_name)
|
||||
-- place player on the seat
|
||||
clicker:setpos(pos)
|
||||
-- rotate player to look in move direction
|
||||
clicker:set_look_horizontal(hyperloop.facedir2rad(facedir))
|
||||
clicker:set_look_horizontal(hyperloop.placedir_to_rad(facedir))
|
||||
|
||||
-- activate display
|
||||
local dist = hyperloop.distance(pos, dest_pos)
|
||||
|
@ -181,13 +181,13 @@ local function on_start_travel(pos, node, clicker)
|
|||
hyperloop.door_command(pos, facedir, "close", station_name)
|
||||
|
||||
atime = atime - 9 -- substract start/arrival time
|
||||
minetest.after(4.9, on_travel, pos, facedir, clicker, dest_pos, hyperloop.facedir2rad(facedir), atime)
|
||||
minetest.after(4.9, on_travel, pos, facedir, clicker, dest_pos, hyperloop.placedir_to_rad(facedir), atime)
|
||||
end
|
||||
|
||||
|
||||
function hyperloop.open_pod_door(station_name)
|
||||
if hyperloop.tAllStations[station_name] ~= nil and hyperloop.tAllStations[station_name].pos ~= nil then
|
||||
local pos = minetest.string_to_pos(hyperloop.tAllStations[station_name].pos)
|
||||
if hyperloop.data.tAllStations[station_name] ~= nil and hyperloop.data.tAllStations[station_name].pos ~= nil then
|
||||
local pos = minetest.string_to_pos(hyperloop.data.tAllStations[station_name].pos)
|
||||
local seat_pos = vector.add(pos, {x=0, y=1, z=0})
|
||||
local meta = minetest.get_meta(seat_pos)
|
||||
local facedir = meta:get_int("facedir")
|
||||
|
@ -197,8 +197,8 @@ function hyperloop.open_pod_door(station_name)
|
|||
end
|
||||
|
||||
function hyperloop.close_pod_door(station_name)
|
||||
if hyperloop.tAllStations[station_name] ~= nil and hyperloop.tAllStations[station_name].pos ~= nil then
|
||||
local pos = minetest.string_to_pos(hyperloop.tAllStations[station_name].pos)
|
||||
if hyperloop.data.tAllStations[station_name] ~= nil and hyperloop.data.tAllStations[station_name].pos ~= nil then
|
||||
local pos = minetest.string_to_pos(hyperloop.data.tAllStations[station_name].pos)
|
||||
local seat_pos = vector.add(pos, {x=0, y=1, z=0})
|
||||
local meta = minetest.get_meta(seat_pos)
|
||||
local facedir = meta:get_int("facedir")
|
||||
|
@ -207,6 +207,12 @@ function hyperloop.close_pod_door(station_name)
|
|||
end
|
||||
end
|
||||
|
||||
function hyperloop.after_seat_placed(pos, facedir)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_int("arrival_time", 0)
|
||||
meta:set_int("facedir", facedir)
|
||||
end
|
||||
|
||||
|
||||
-- Hyperloop Seat
|
||||
minetest.register_node("hyperloop:seat", {
|
||||
|
@ -240,40 +246,40 @@ minetest.register_node("hyperloop:seat", {
|
|||
|
||||
on_timer = display_timer,
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_int("arrival_time", 0)
|
||||
end,
|
||||
-- on_construct = function(pos)
|
||||
-- local meta = minetest.get_meta(pos)
|
||||
-- meta:set_int("arrival_time", 0)
|
||||
-- end,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local yaw = placer:get_look_horizontal()
|
||||
-- facedir according to radiant
|
||||
local facedir = hyperloop.rad2facedir(yaw)
|
||||
-- do a 180 degree correction
|
||||
meta:set_int("facedir", (facedir + 2) % 4)
|
||||
-- store station name locally
|
||||
local pos2 = vector.add(pos, {x=0, y=-1, z=0})
|
||||
local meta2 = minetest.get_meta(pos2)
|
||||
if meta2 ~= nil then
|
||||
local station_name = meta2:get_string("station_name")
|
||||
meta:set_string("station_name", station_name)
|
||||
if hyperloop.tAllStations[station_name] ~= nil then
|
||||
hyperloop.tAllStations[station_name]["seat"] = true
|
||||
end
|
||||
end
|
||||
hyperloop.change_counter = hyperloop.change_counter + 1
|
||||
end,
|
||||
-- after_place_node = function(pos, placer)
|
||||
-- local meta = minetest.get_meta(pos)
|
||||
-- local yaw = placer:get_look_horizontal()
|
||||
-- -- facedir according to radiant
|
||||
-- local facedir = hyperloop.rad_to_placedir(yaw)
|
||||
-- -- do a 180 degree correction
|
||||
-- meta:set_int("facedir", (facedir + 2) % 4)
|
||||
-- -- store station name locally
|
||||
-- local pos2 = vector.add(pos, {x=0, y=-1, z=0})
|
||||
-- local meta2 = minetest.get_meta(pos2)
|
||||
-- if meta2 ~= nil then
|
||||
-- local station_name = meta2:get_string("station_name")
|
||||
-- meta:set_string("station_name", station_name)
|
||||
-- if hyperloop.data.tAllStations[station_name] ~= nil then
|
||||
-- hyperloop.data.tAllStations[station_name]["seat"] = true
|
||||
-- end
|
||||
-- end
|
||||
-- hyperloop.data.change_counter = hyperloop.data.change_counter + 1
|
||||
-- end,
|
||||
|
||||
on_destruct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local station_name = meta:get_string("station_name")
|
||||
if hyperloop.tAllStations[station_name] ~= nil
|
||||
and hyperloop.tAllStations[station_name]["seat"] ~= nil then
|
||||
hyperloop.tAllStations[station_name]["seat"] = nil
|
||||
if hyperloop.data.tAllStations[station_name] ~= nil
|
||||
and hyperloop.data.tAllStations[station_name]["seat"] ~= nil then
|
||||
hyperloop.data.tAllStations[station_name]["seat"] = nil
|
||||
hyperloop.open_pod_door(station_name)
|
||||
end
|
||||
hyperloop.change_counter = hyperloop.change_counter + 1
|
||||
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
|
||||
end,
|
||||
|
||||
on_rightclick = on_start_travel,
|
||||
|
|
105
tube.lua
105
tube.lua
|
@ -54,6 +54,16 @@ function hyperloop.scan_neighbours(pos)
|
|||
return res, nodes
|
||||
end
|
||||
|
||||
local function get_slope_counter(pos)
|
||||
if pos ~= nil then
|
||||
local slope_cnt = minetest.get_meta(pos):get_int("slope_cnt")
|
||||
if slope_cnt ~= nil then
|
||||
return slope_cnt
|
||||
end
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
|
||||
-- update head tube meta data
|
||||
-- param pos: position as string
|
||||
|
@ -79,6 +89,7 @@ function hyperloop.degrade_tupe_node(node)
|
|||
elseif node.name == "hyperloop:tube1" then
|
||||
node.name = "hyperloop:tube2"
|
||||
node.diggable = false
|
||||
minetest.get_meta(node.pos):from_table(nil)
|
||||
else
|
||||
return
|
||||
end
|
||||
|
@ -102,6 +113,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 slope_cnt = get_slope_counter(digged_node_pos)
|
||||
local pos = minetest.pos_to_string(new_head_node.pos)
|
||||
hyperloop.update_head_node(pos, peer_pos)
|
||||
hyperloop.update_head_node(peer_pos, pos)
|
||||
|
@ -112,6 +124,14 @@ function hyperloop.upgrade_node(digged_node_pos)
|
|||
elseif new_head_node.name == "hyperloop:tube1" then -- 1 connection?
|
||||
new_head_node.name = "hyperloop:tube0"
|
||||
end
|
||||
-- slope counter correction
|
||||
if digged_node_pos.y ~= new_head_node.pos.y then
|
||||
slope_cnt = 0
|
||||
else
|
||||
slope_cnt = math.min(slope_cnt + 1, hyperloop.min_slope_counter)
|
||||
end
|
||||
minetest.get_meta(new_head_node.pos):set_int("slope_cnt", slope_cnt)
|
||||
minetest.get_meta(new_head_node.pos):set_string("infotext", pos.." : "..slope_cnt)
|
||||
minetest.swap_node(new_head_node.pos, new_head_node)
|
||||
end
|
||||
end
|
||||
|
@ -119,55 +139,81 @@ end
|
|||
-- Place a node without neighbours
|
||||
local function single_node(node)
|
||||
local meta = minetest.get_meta(node.pos)
|
||||
meta:set_string("peer", minetest.pos_to_string(node.pos))
|
||||
local str_pos = minetest.pos_to_string(node.pos)
|
||||
meta:set_string("peer", str_pos)
|
||||
meta:set_int("slope_cnt", hyperloop.min_slope_counter)
|
||||
minetest.get_meta(node.pos):set_string("infotext", str_pos.." : "..hyperloop.min_slope_counter)
|
||||
-- upgrade self to single node
|
||||
node.name = "hyperloop:tube0"
|
||||
minetest.swap_node(node.pos, node)
|
||||
return true
|
||||
end
|
||||
|
||||
-- Place a node with one neighbor
|
||||
local function head_node(node, old_head)
|
||||
-- determine peer pos
|
||||
local peer_pos = minetest.get_meta(old_head.pos):get_string("peer")
|
||||
-- update self
|
||||
hyperloop.update_head_node(minetest.pos_to_string(node.pos), peer_pos)
|
||||
-- update peer
|
||||
hyperloop.update_head_node(peer_pos, minetest.pos_to_string(node.pos))
|
||||
-- upgrade self
|
||||
node.name = "hyperloop:tube1"
|
||||
minetest.swap_node(node.pos, node)
|
||||
-- degrade old head
|
||||
hyperloop.degrade_tupe_node(old_head)
|
||||
local slope_cnt = get_slope_counter(old_head.pos)
|
||||
-- both nodes on the same level OR slope OK?
|
||||
if node.pos.y == old_head.pos.y or slope_cnt == 0 then
|
||||
-- update self
|
||||
local str_pos = minetest.pos_to_string(node.pos)
|
||||
hyperloop.update_head_node(str_pos, peer_pos)
|
||||
-- update peer
|
||||
hyperloop.update_head_node(peer_pos, str_pos)
|
||||
-- slope correction
|
||||
if node.pos.y ~= old_head.pos.y then
|
||||
slope_cnt = hyperloop.min_slope_counter
|
||||
else
|
||||
slope_cnt = math.max(slope_cnt - 1, 0)
|
||||
end
|
||||
-- upgrade self
|
||||
minetest.get_meta(node.pos):set_int("slope_cnt", slope_cnt)
|
||||
minetest.get_meta(node.pos):set_string("infotext", str_pos.." : "..slope_cnt)
|
||||
node.name = "hyperloop:tube1"
|
||||
minetest.swap_node(node.pos, node)
|
||||
-- degrade old head
|
||||
hyperloop.degrade_tupe_node(old_head)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function link_node(node, node1, node2)
|
||||
-- determine the meta data from both head nodes
|
||||
local pos1 = minetest.get_meta(node1.pos):get_string("peer")
|
||||
local pos2 = minetest.get_meta(node2.pos):get_string("peer")
|
||||
-- exchange position data
|
||||
hyperloop.update_head_node(pos1, pos2)
|
||||
hyperloop.update_head_node(pos2, pos1)
|
||||
-- set to tube2
|
||||
node.name = "hyperloop:tube2"
|
||||
node.diggable = true
|
||||
minetest.swap_node(node.pos, node)
|
||||
-- degrade both nodes
|
||||
hyperloop.degrade_tupe_node(node1)
|
||||
hyperloop.degrade_tupe_node(node2)
|
||||
-- both nodes on the same level?
|
||||
if node1.pos.y == node2.pos.y then
|
||||
-- determine the meta data from both head nodes
|
||||
local pos1 = minetest.get_meta(node1.pos):get_string("peer")
|
||||
local pos2 = minetest.get_meta(node2.pos):get_string("peer")
|
||||
-- exchange position data
|
||||
hyperloop.update_head_node(pos1, pos2)
|
||||
hyperloop.update_head_node(pos2, pos1)
|
||||
-- set to tube2
|
||||
node.name = "hyperloop:tube2"
|
||||
node.diggable = true
|
||||
minetest.swap_node(node.pos, node)
|
||||
-- degrade both nodes
|
||||
hyperloop.degrade_tupe_node(node1)
|
||||
hyperloop.degrade_tupe_node(node2)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- called when a new node is placed
|
||||
local function node_placed(pos)
|
||||
local function node_placed(pos, itemstack)
|
||||
local res, nodes = hyperloop.scan_neighbours(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
local placed = false
|
||||
node.pos = pos
|
||||
if res == 0 then -- no neighbor available?
|
||||
single_node(node)
|
||||
placed = single_node(node)
|
||||
elseif res == 1 then -- one neighbor available?
|
||||
head_node(node, nodes[1])
|
||||
placed = head_node(node, nodes[1])
|
||||
elseif res == 3 then -- two neighbours available?
|
||||
link_node(node, nodes[1], nodes[2])
|
||||
else -- invalid position
|
||||
placed = link_node(node, nodes[1], nodes[2])
|
||||
end
|
||||
if not placed then
|
||||
hyperloop.remove_node(pos, node)
|
||||
return itemstack
|
||||
end
|
||||
|
@ -191,6 +237,7 @@ minetest.register_node("hyperloop:tube2", {
|
|||
paramtype2 = "facedir",
|
||||
groups = {cracky=1, not_in_creative_inventory=1},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
})
|
||||
|
||||
-- single-node and head-node with meta data about the peer head node position
|
||||
|
@ -210,7 +257,7 @@ for idx = 0,1 do
|
|||
},
|
||||
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
return node_placed(pos)
|
||||
return node_placed(pos, itemstack)
|
||||
end,
|
||||
|
||||
on_destruct = function(pos)
|
||||
|
|
156
utils.lua
156
utils.lua
|
@ -35,57 +35,88 @@ hyperloop.NeighborPos = {
|
|||
{ x=0, y=0, z=-1},
|
||||
}
|
||||
|
||||
function hyperloop.rad2facedir(yaw)
|
||||
-- radiant (0..2*PI) to my facedir (0..3) from N, W, S to E
|
||||
function hyperloop.rad_to_placedir(yaw)
|
||||
-- radiant (0..2*PI) to my placedir (0..3) from N, W, S, E
|
||||
return math.floor((yaw + PI/4) / PI * 2) % 4
|
||||
end
|
||||
|
||||
function hyperloop.facedir2rad(facedir)
|
||||
-- my facedir (0..3) from N, W, S to E to radiant (0..2*PI)
|
||||
return facedir / 2 * PI
|
||||
function hyperloop.placedir_to_rad(placedir)
|
||||
-- my placedir (0..3) from N, W, S, E to radiant (0..2*PI)
|
||||
return placedir / 2 * PI
|
||||
end
|
||||
|
||||
function hyperloop.facedir2dir(facedir)
|
||||
-- my facedir (0..3) from N, W, S to E to dir vector
|
||||
function hyperloop.placedir_to_dir(placedir)
|
||||
-- my placedir (0..3) from N, W, S to E to dir vector
|
||||
local tbl = {
|
||||
[0] = { x=0, y=0, z=1},
|
||||
[1] = { x=-1, y=0, z=0},
|
||||
[2] = { x=0, y=0, z=-1},
|
||||
[3] = { x=1, y=0, z=0},
|
||||
}
|
||||
return tbl[facedir % 4]
|
||||
return tbl[placedir % 4]
|
||||
end
|
||||
|
||||
-- switch from original facedir to radiant oriented placedir
|
||||
function hyperloop.facedir_to_placedir(facedir)
|
||||
local tbl = {[0]=0, [1]=3, [2]=2, [3]=1}
|
||||
return tbl[facedir]
|
||||
end
|
||||
|
||||
-- switch from radiant oriented placedir to original facedir
|
||||
function hyperloop.placedir_to_facedir(placedir)
|
||||
local tbl = {[0]=0, [1]=3, [2]=2, [3]=1}
|
||||
return tbl[placedir]
|
||||
end
|
||||
|
||||
function hyperloop.get_facedir(placer)
|
||||
local yaw = placer:get_look_horizontal()
|
||||
local placedir = hyperloop.rad_to_placedir(yaw)
|
||||
return hyperloop.placedir_to_facedir(placedir)
|
||||
end
|
||||
|
||||
-- calculate the new pos based on the given pos, the players placedir
|
||||
-- and the given walk path like "3F2L" (F-orward, L-eft, R-ight, B-ack).
|
||||
function hyperloop.new_pos(pos, placedir, path)
|
||||
local _pos = table.copy(pos)
|
||||
while path:len() > 0 do
|
||||
local num = tonumber(path:sub(1,1))
|
||||
local dir = path:sub(2,2)
|
||||
path = path:sub(3)
|
||||
if dir == "B" then
|
||||
placedir = (placedir + 2) % 4
|
||||
elseif dir == "L" then
|
||||
placedir = (placedir + 1) % 4
|
||||
elseif dir == "R" then
|
||||
placedir = (placedir + 3) % 4
|
||||
end
|
||||
dir = hyperloop.placedir_to_dir(placedir)
|
||||
_pos = vector.add(_pos, vector.multiply(dir, num))
|
||||
end
|
||||
return _pos
|
||||
end
|
||||
|
||||
|
||||
function hyperloop.turnright(dir)
|
||||
local facedir = minetest.dir_to_facedir(dir)
|
||||
return minetest.facedir_to_dir((facedir + 1) % 4)
|
||||
return minetest.placedir_to_dir((facedir + 1) % 4)
|
||||
end
|
||||
|
||||
function hyperloop.turnleft(dir)
|
||||
local facedir = minetest.dir_to_facedir(dir)
|
||||
return minetest.facedir_to_dir((facedir + 3) % 4)
|
||||
return minetest.placedir_to_dir((facedir + 3) % 4)
|
||||
end
|
||||
|
||||
-- File writing / reading utilities
|
||||
local wpath = minetest.get_worldpath()
|
||||
|
||||
function hyperloop.file2table(filename)
|
||||
local f = io.open(wpath..DIR_DELIM..filename, "r")
|
||||
if f == nil then return {} end
|
||||
local t = f:read("*all")
|
||||
f:close()
|
||||
if t == "" or t == nil then return {} end
|
||||
return minetest.deserialize(t)
|
||||
end
|
||||
|
||||
function hyperloop.table2file(filename, table)
|
||||
local f = io.open(wpath..DIR_DELIM..filename, "w")
|
||||
f:write(minetest.serialize(table))
|
||||
f:close()
|
||||
end
|
||||
|
||||
function hyperloop.store_station_list()
|
||||
hyperloop.table2file("hyperloop_station_list", hyperloop.tAllStations)
|
||||
-- determine facedir and pos on the right hand side from the given pos
|
||||
function hyperloop.right_hand_side(pos, placer)
|
||||
local yaw = placer:get_look_horizontal()
|
||||
-- placedir according to radiant
|
||||
local placedir = hyperloop.rad_to_placedir(yaw)
|
||||
local dir = (placedir + 3) % 4 -- first turn right
|
||||
dir = hyperloop.placedir_to_dir(dir)
|
||||
-- switch from the radian following facedir to the silly original one
|
||||
local tbl = {[0]=0, [1]=3, [2]=2, [3]=1}
|
||||
local facedir = tbl[placedir]
|
||||
return facedir, vector.add(pos, dir)
|
||||
end
|
||||
|
||||
-- distance between two points in (tube) blocks
|
||||
|
@ -175,10 +206,10 @@ end
|
|||
-- Return a table with all network station names, the given 'sStation' belongs too
|
||||
function hyperloop.get_network_stations(sStation)
|
||||
local tRes = {}
|
||||
local tStations = table.copy(hyperloop.tAllStations)
|
||||
local tStations = table.copy(hyperloop.data.tAllStations)
|
||||
local tOut = {}
|
||||
for _,name in ipairs(get_stations(tStations, sStation, tRes)) do
|
||||
if hyperloop.tAllStations[name].seat == true then
|
||||
if hyperloop.data.tAllStations[name].seat == true then
|
||||
tOut[#tOut+1] = name
|
||||
end
|
||||
end
|
||||
|
@ -188,13 +219,13 @@ end
|
|||
-- Return a table with all station names, the given 'sStation' is directly connected with
|
||||
function hyperloop.get_connections(sStation)
|
||||
local tRes = {}
|
||||
local dataSet = hyperloop.tAllStations[sStation]
|
||||
local dataSet = hyperloop.data.tAllStations[sStation]
|
||||
if dataSet == nil then
|
||||
return nil
|
||||
end
|
||||
for _,route in ipairs(dataSet["routes"]) do
|
||||
local rev_route = {route[2], route[1]}
|
||||
local s = get_peer_station(hyperloop.tAllStations, rev_route)
|
||||
local s = get_peer_station(hyperloop.data.tAllStations, rev_route)
|
||||
if s ~= nil then
|
||||
tRes[#tRes + 1] = s
|
||||
end
|
||||
|
@ -205,7 +236,7 @@ end
|
|||
-- Return the networks table with all station names per network
|
||||
function hyperloop.get_networks()
|
||||
local tNetwork = {}
|
||||
local tStations = table.copy(hyperloop.tAllStations)
|
||||
local tStations = table.copy(hyperloop.data.tAllStations)
|
||||
local sStation,_ = next(tStations, nil)
|
||||
while sStation ~= nil do
|
||||
tNetwork[#tNetwork+1] = get_stations(tStations, sStation, {sStation})
|
||||
|
@ -221,13 +252,13 @@ end
|
|||
|
||||
-- reserve departure and arrival stations for some time
|
||||
function hyperloop.reserve(departure, arrival)
|
||||
if hyperloop.tAllStations[departure] == nil then
|
||||
if hyperloop.data.tAllStations[departure] == nil then
|
||||
return false
|
||||
elseif hyperloop.tAllStations[arrival] == nil then
|
||||
elseif hyperloop.data.tAllStations[arrival] == nil then
|
||||
return false
|
||||
else
|
||||
local t1 = hyperloop.tAllStations[departure].time_blocked or 0
|
||||
local t2 = hyperloop.tAllStations[arrival].time_blocked or 0
|
||||
local t1 = hyperloop.data.tAllStations[departure].time_blocked or 0
|
||||
local t2 = hyperloop.data.tAllStations[arrival].time_blocked or 0
|
||||
|
||||
if t1 > minetest.get_gametime() then
|
||||
return false
|
||||
|
@ -235,8 +266,8 @@ function hyperloop.reserve(departure, arrival)
|
|||
return false
|
||||
else
|
||||
-- place a reservation for 20 seconds to start the trip
|
||||
hyperloop.tAllStations[departure].time_blocked = minetest.get_gametime() + 20
|
||||
hyperloop.tAllStations[arrival].time_blocked = minetest.get_gametime() + 20
|
||||
hyperloop.data.tAllStations[departure].time_blocked = minetest.get_gametime() + 20
|
||||
hyperloop.data.tAllStations[arrival].time_blocked = minetest.get_gametime() + 20
|
||||
if hyperloop.debugging then
|
||||
print(departure.." and ".. arrival.." stations are reserved")
|
||||
end
|
||||
|
@ -247,13 +278,13 @@ end
|
|||
|
||||
-- block the already reserved stations
|
||||
function hyperloop.block(departure, arrival, seconds)
|
||||
if hyperloop.tAllStations[departure] == nil then
|
||||
if hyperloop.data.tAllStations[departure] == nil then
|
||||
return false
|
||||
elseif hyperloop.tAllStations[arrival] == nil then
|
||||
elseif hyperloop.data.tAllStations[arrival] == nil then
|
||||
return false
|
||||
else
|
||||
hyperloop.tAllStations[departure].time_blocked = minetest.get_gametime() + seconds
|
||||
hyperloop.tAllStations[arrival].time_blocked = minetest.get_gametime() + seconds
|
||||
hyperloop.data.tAllStations[departure].time_blocked = minetest.get_gametime() + seconds
|
||||
hyperloop.data.tAllStations[arrival].time_blocked = minetest.get_gametime() + seconds
|
||||
if hyperloop.debugging then
|
||||
print(departure.." and ".. arrival.." stations are blocked")
|
||||
end
|
||||
|
@ -263,20 +294,49 @@ end
|
|||
|
||||
-- check if station is blocked
|
||||
function hyperloop.is_blocked(station)
|
||||
if hyperloop.tAllStations[station] == nil then
|
||||
if hyperloop.data.tAllStations[station] == nil then
|
||||
return false
|
||||
else
|
||||
local t = hyperloop.tAllStations[station].time_blocked or 0
|
||||
local t = hyperloop.data.tAllStations[station].time_blocked or 0
|
||||
print(t, minetest.get_gametime())
|
||||
return t > minetest.get_gametime()
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
---- Station File writing / reading utilities
|
||||
-------------------------------------------------------------------------------
|
||||
local wpath = minetest.get_worldpath()
|
||||
|
||||
function hyperloop.file2table(filename)
|
||||
local f = io.open(wpath..DIR_DELIM..filename, "r")
|
||||
if f == nil then return {} end
|
||||
local t = f:read("*all")
|
||||
f:close()
|
||||
if t == "" or t == nil then return {} end
|
||||
return minetest.deserialize(t)
|
||||
end
|
||||
|
||||
function hyperloop.table2file(filename, table)
|
||||
local f = io.open(wpath..DIR_DELIM..filename, "w")
|
||||
f:write(minetest.serialize(table))
|
||||
f:close()
|
||||
end
|
||||
-- Store and read the station list to / from a file
|
||||
-- so that upcoming actions are remembered when the game
|
||||
-- is restarted
|
||||
hyperloop.tAllStations = hyperloop.file2table("hyperloop_station_list")
|
||||
function hyperloop.store_station_list()
|
||||
hyperloop.table2file("mod_hyperloop.data", hyperloop.data)
|
||||
end
|
||||
|
||||
local data = hyperloop.file2table("mod_hyperloop.data")
|
||||
if next(data) ~= nil then
|
||||
hyperloop.data = data
|
||||
print("jetzt aber")
|
||||
else
|
||||
print("nix da")
|
||||
hyperloop.data.tAllStations = hyperloop.file2table("hyperloop_station_list")
|
||||
end
|
||||
minetest.register_on_shutdown(hyperloop.store_station_list)
|
||||
|
||||
-- store ring list once a day
|
||||
|
|
22
wifi.lua
22
wifi.lua
|
@ -18,10 +18,10 @@
|
|||
[H1]----[H2][W1] [W2][H3]----[H4]
|
||||
pairing:
|
||||
- W1 placed:
|
||||
hyperloop.tWifi[channel] = pos_W1
|
||||
hyperloop.data.tWifi[channel] = pos_W1
|
||||
|
||||
- W2 placed:
|
||||
pos_W1 = hyperloop.tWifi[channel]
|
||||
pos_W1 = hyperloop.data.tWifi[channel]
|
||||
wifi_pairing(pos_W2, pos_W1)
|
||||
determine pos_H4 via H3
|
||||
call W1.update(pos_H4)
|
||||
|
@ -64,12 +64,12 @@ local function read_peer_pos(pos)
|
|||
end
|
||||
|
||||
local function wifi_register(pos, channel)
|
||||
if hyperloop.tWifi[channel] == nil then
|
||||
hyperloop.tWifi[channel] = pos
|
||||
if hyperloop.data.tWifi[channel] == nil then
|
||||
hyperloop.data.tWifi[channel] = pos
|
||||
return nil
|
||||
else
|
||||
local pos = hyperloop.tWifi[channel]
|
||||
hyperloop.tWifi[channel] = nil
|
||||
local pos = hyperloop.data.tWifi[channel]
|
||||
hyperloop.data.tWifi[channel] = nil
|
||||
return pos
|
||||
end
|
||||
end
|
||||
|
@ -78,9 +78,9 @@ local function wifi_unregister(pos)
|
|||
-- delete channel registration
|
||||
local meta = minetest.get_meta(pos)
|
||||
local channel = meta:get_string("channel")
|
||||
if channel ~= nil and hyperloop.tWifi[channel] ~= nil
|
||||
and vector.equals(hyperloop.tWifi[channel], pos) then
|
||||
hyperloop.tWifi[channel] = nil
|
||||
if channel ~= nil and hyperloop.data.tWifi[channel] ~= nil
|
||||
and vector.equals(hyperloop.data.tWifi[channel], pos) then
|
||||
hyperloop.data.tWifi[channel] = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -186,7 +186,7 @@ minetest.register_node("hyperloop:tube_wifi1", {
|
|||
"[Hyperloop] Pairing fault. Retry please!")
|
||||
end
|
||||
end
|
||||
hyperloop.change_counter = hyperloop.change_counter + 1
|
||||
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
|
||||
end,
|
||||
|
||||
on_destruct = function(pos)
|
||||
|
@ -201,7 +201,7 @@ minetest.register_node("hyperloop:tube_wifi1", {
|
|||
end
|
||||
-- unpair local wifi node
|
||||
hyperloop.upgrade_node(pos)
|
||||
hyperloop.change_counter = hyperloop.change_counter + 1
|
||||
hyperloop.data.change_counter = hyperloop.data.change_counter + 1
|
||||
end,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
|
|
Loading…
Reference in New Issue