open pod door on punch added

This commit is contained in:
Joachim Stolberg 2017-07-16 20:53:24 +02:00
parent 78b1905bdc
commit 09b35998b0
6 changed files with 49 additions and 14 deletions

View File

@ -13,11 +13,20 @@
]]--
-- Open the door for an emergency
local function door_on_punch(pos, node, puncher, pointed_thing)
local meta = minetest.get_meta(pos)
local station_name = meta:get_string("station_name")
if not hyperloop.is_blocked(station_name) then
hyperloop.open_pod_door(station_name)
end
end
-- Open/close/animate the pod door
-- seat_pos: position of the seat
-- facedir: direction to the display
-- cmnd: "close", "open", or "animate"
function hyperloop.door_command(seat_pos, facedir, cmnd)
function hyperloop.door_command(seat_pos, facedir, cmnd, station_name)
-- one step forward
local lcd_pos = vector.add(seat_pos, hyperloop.facedir2dir(facedir))
-- one step left
@ -52,9 +61,17 @@ function hyperloop.door_command(seat_pos, facedir, cmnd)
node1.name = "hyperloop:doorBottom"
node1.param2 = facedir
minetest.swap_node(door_pos1, node1)
if station_name ~= nil then
local meta = minetest.get_meta(door_pos1)
meta:set_string("station_name", station_name)
end
node2.name = "hyperloop:doorTopPassive"
node2.param2 = facedir
minetest.swap_node(door_pos2, node2)
if station_name ~= nil then
meta = minetest.get_meta(door_pos2)
meta:set_string("station_name", station_name)
end
elseif cmnd == "animate" then
node2.name = "hyperloop:doorTopActive"
node2.param2 = facedir
@ -78,6 +95,9 @@ minetest.register_node("hyperloop:doorTopPassive", {
type = "fixed",
fixed = {-8/16, -8/16, -5/16, 8/16, 8/16, 5/16},
},
on_punch = door_on_punch,
paramtype2 = "facedir",
diggable = false,
sounds = default.node_sound_metal_defaults(),
@ -133,6 +153,9 @@ minetest.register_node("hyperloop:doorBottom", {
type = "fixed",
fixed = {-8/16, -8/16, -5/16, 8/16, 8/16, 5/16},
},
on_punch = door_on_punch,
paramtype2 = "facedir",
diggable = false,
sounds = default.node_sound_metal_defaults(),

View File

@ -38,6 +38,7 @@ 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") .. "/recipes.lua")
print ("[MOD] Hyperloop loaded")

View File

@ -1,8 +1,8 @@
# 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 by manually.
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 on trip.
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)

View File

@ -31,13 +31,13 @@ local function station_list_as_string(pos)
print("tWifi="..dump(hyperloop.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.8,0;Station]label[2.5,0;Position]label[4.2,0;State]label[5.7,0;Owner]label[7.1,0;Connected with]"}
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]"}
local state, owner
for idx,dataSet in ipairs(sortedList) do
if idx == 18 then
break
end
ypos = 0.2 + idx * 0.4
local ypos = 0.2 + idx * 0.4
if dataSet.seat == true and dataSet.booking_pos ~= nil then
state = "completed"
elseif dataSet.seat == true then
@ -51,10 +51,10 @@ local function station_list_as_string(pos)
owner = "unknown"
end
tRes[#tRes+1] = "label[0,"..ypos..";"..dataSet.distance.." m]"
tRes[#tRes+1] = "label[0.8,"..ypos..";"..dataSet.name.."]"
tRes[#tRes+1] = "label[0.9,"..ypos..";"..dataSet.name.."]"
tRes[#tRes+1] = "label[2.5,"..ypos..";"..dataSet.pos.."]"
tRes[#tRes+1] = "label[4.2,"..ypos..";"..state.."]"
tRes[#tRes+1] = "label[5.7,"..ypos..";"..owner.."]"
tRes[#tRes+1] = "label[5.6,"..ypos..";"..owner.."]"
tRes[#tRes+1] = "label[7.1,"..ypos..";"
for _,s in ipairs(hyperloop.get_connections(dataSet.name)) do
tRes[#tRes + 1] = s

View File

@ -20,7 +20,7 @@ local function on_final_close_door(pos, facedir)
-- try again later
minetest.after(3.0, on_final_close_door, pos, facedir)
else
hyperloop.door_command(pos, facedir, "close")
hyperloop.door_command(pos, facedir, "close", nil)
end
end
@ -29,7 +29,7 @@ local function on_open_door(pos, facedir)
local meta = minetest.get_meta(pos)
meta:set_int("arrival_time", 0) -- finished
-- open door
hyperloop.door_command(pos, facedir, "open")
hyperloop.door_command(pos, facedir, "open", nil)
-- prepare dislay for the next trip
hyperloop.enter_display(pos, facedir, "Thank you | for | travelling | with | Hyperloop.")
minetest.after(5.0, on_final_close_door, pos, facedir)
@ -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.facedir2rad(facedir) - offs
player:set_look_yaw(yaw)
end
-- play arrival sound
@ -77,7 +77,7 @@ local function on_travel(src_pos, facedir, player, dst_pos, radiant, atime)
max_hear_distance = 1,
loop = true,
})
hyperloop.door_command(src_pos, facedir, "animate")
hyperloop.door_command(src_pos, facedir, "animate", nil)
minetest.after(atime, on_arrival, player, src_pos, facedir, dst_pos, snd, radiant)
minetest.after(atime, on_final_close_door, src_pos, facedir)
end
@ -151,7 +151,7 @@ local function on_start_travel(pos, node, clicker)
max_hear_distance = 10
})
-- close the door at arrival station
hyperloop.door_command(dest_pos, dest_facedir, "close")
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
@ -178,7 +178,7 @@ local function on_start_travel(pos, node, clicker)
meta:set_string("lcd_text", text)
minetest.get_node_timer(pos):start(1.0)
hyperloop.door_command(pos, facedir, "close")
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)
@ -202,7 +202,7 @@ function hyperloop.close_pod_door(station_name)
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")
hyperloop.door_command(seat_pos, facedir, "close")
hyperloop.door_command(seat_pos, facedir, "close", station_name)
hyperloop.enter_display(seat_pos, facedir, " | | << Hyperloop >> | be anywhere")
end
end

View File

@ -261,6 +261,17 @@ function hyperloop.block(departure, arrival, seconds)
end
end
-- check if station is blocked
function hyperloop.is_blocked(station)
if hyperloop.tAllStations[station] == nil then
return false
else
local t = hyperloop.tAllStations[station].time_blocked or 0
print(t, minetest.get_gametime())
return t > minetest.get_gametime()
end
end
-- Store and read the station list to / from a file
-- so that upcoming actions are remembered when the game
-- is restarted