2017-02-02 16:40:51 +01:00
|
|
|
-- atc_rail.lua
|
|
|
|
-- registers and handles the ATC rail. Active component.
|
|
|
|
-- This is the only component that can interface with trains, so train interface goes here too.
|
|
|
|
|
|
|
|
--Using subtable
|
|
|
|
local r={}
|
|
|
|
|
|
|
|
function r.fire_event(pos, evtdata)
|
|
|
|
|
2017-02-03 20:40:30 +01:00
|
|
|
local ph=minetest.pos_to_string(pos)
|
|
|
|
local railtbl = atlatc.active.nodes[ph]
|
|
|
|
|
|
|
|
if not railtbl then
|
2017-02-04 18:35:34 +01:00
|
|
|
atwarn("LuaAutomation ATC interface rail at",ph,": Data not in memory! Please visit position and click 'Save'!")
|
2017-02-03 20:40:30 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-02-02 16:40:51 +01:00
|
|
|
|
|
|
|
local arrowconn = railtbl.arrowconn
|
2017-05-22 15:01:38 +02:00
|
|
|
if not arrowconn then
|
|
|
|
atwarn("LuaAutomation ATC interface rail at",ph,": Incomplete Data! Please visit position and click 'Save'!")
|
|
|
|
return
|
|
|
|
end
|
2017-02-02 16:40:51 +01:00
|
|
|
|
|
|
|
--prepare ingame API for ATC. Regenerate each time since pos needs to be known
|
2017-02-04 18:35:34 +01:00
|
|
|
--If no train, then return false.
|
2018-05-17 21:37:01 +02:00
|
|
|
local train_id=advtrains.get_train_at_pos(pos)
|
2017-02-04 18:35:34 +01:00
|
|
|
local train, atc_arrow, tvel
|
|
|
|
if train_id then train=advtrains.trains[train_id] end
|
|
|
|
if train then
|
|
|
|
if not train.path then
|
|
|
|
--we happened to get in between an invalidation step
|
|
|
|
--delay
|
|
|
|
atlatc.interrupt.add(0,pos,evtdata)
|
|
|
|
return
|
|
|
|
end
|
2018-05-17 21:37:01 +02:00
|
|
|
local index = advtrains.path_lookup(train, pos)
|
|
|
|
|
|
|
|
local iconnid = 1
|
|
|
|
if index then
|
|
|
|
iconnid = train.path_cn[index]
|
|
|
|
else
|
|
|
|
atwarn("ATC rail at", pos, ": Rail not on train's path! Can't determine arrow direction. Assuming +!")
|
2017-02-02 16:40:51 +01:00
|
|
|
end
|
2018-05-17 21:37:01 +02:00
|
|
|
atc_arrow = iconnid == 1
|
|
|
|
|
2017-02-04 21:07:18 +01:00
|
|
|
tvel=train.velocity
|
2017-02-02 16:40:51 +01:00
|
|
|
end
|
|
|
|
local customfct={
|
|
|
|
atc_send = function(cmd)
|
2017-02-04 18:35:34 +01:00
|
|
|
if not train_id then return false end
|
2017-03-30 21:59:30 +02:00
|
|
|
assertt(cmd, "string")
|
2018-10-10 21:49:52 +02:00
|
|
|
advtrains.atc.train_set_command(train, cmd, atc_arrow)
|
2017-02-04 18:35:34 +01:00
|
|
|
return true
|
2017-02-02 16:40:51 +01:00
|
|
|
end,
|
2017-10-23 13:33:27 +02:00
|
|
|
set_line = function(line)
|
2018-11-20 11:57:46 +01:00
|
|
|
if type(line)~="string" and type(line)~="number" then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
train.line = line .. ""
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
get_line = function()
|
|
|
|
return train.line
|
2017-10-23 13:33:27 +02:00
|
|
|
end,
|
2019-01-15 17:54:13 +01:00
|
|
|
set_rc = function(rc)
|
|
|
|
if type(rc)~="string"then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
train.routingcode = rc
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
get_rc = function()
|
|
|
|
return train.routingcode
|
|
|
|
end,
|
2017-02-02 16:40:51 +01:00
|
|
|
atc_reset = function(cmd)
|
2017-02-04 18:35:34 +01:00
|
|
|
if not train_id then return false end
|
2017-03-30 21:59:30 +02:00
|
|
|
assertt(cmd, "string")
|
2018-10-10 21:49:52 +02:00
|
|
|
advtrains.atc.train_reset_command(train)
|
2017-02-02 16:40:51 +01:00
|
|
|
return true
|
|
|
|
end,
|
2017-02-04 18:35:34 +01:00
|
|
|
atc_arrow = atc_arrow,
|
|
|
|
atc_id = train_id,
|
|
|
|
atc_speed = tvel,
|
2017-03-30 21:51:45 +02:00
|
|
|
atc_set_text_outside = function(text)
|
|
|
|
if not train_id then return false end
|
2017-03-30 21:59:30 +02:00
|
|
|
if text then assertt(text, "string") end
|
2017-03-30 21:51:45 +02:00
|
|
|
advtrains.trains[train_id].text_outside=text
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
atc_set_text_inside = function(text)
|
|
|
|
if not train_id then return false end
|
2017-03-30 21:59:30 +02:00
|
|
|
if text then assertt(text, "string") end
|
2017-03-30 21:51:45 +02:00
|
|
|
advtrains.trains[train_id].text_inside=text
|
|
|
|
return true
|
|
|
|
end,
|
2017-02-02 16:40:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
atlatc.active.run_in_env(pos, evtdata, customfct)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
advtrains.register_tracks("default", {
|
|
|
|
nodename_prefix="advtrains_luaautomation:dtrack",
|
|
|
|
texture_prefix="advtrains_dtrack_atc",
|
2017-03-09 11:09:01 +01:00
|
|
|
models_prefix="advtrains_dtrack",
|
2017-02-02 16:40:51 +01:00
|
|
|
models_suffix=".b3d",
|
2017-03-09 11:09:01 +01:00
|
|
|
shared_texture="advtrains_dtrack_shared_atc.png",
|
2017-02-02 16:40:51 +01:00
|
|
|
description=atltrans("LuaAutomation ATC Rail"),
|
|
|
|
formats={},
|
|
|
|
get_additional_definiton = function(def, preset, suffix, rotation)
|
|
|
|
return {
|
|
|
|
after_place_node = atlatc.active.after_place_node,
|
|
|
|
after_dig_node = atlatc.active.after_dig_node,
|
|
|
|
|
|
|
|
on_receive_fields = function(pos, ...)
|
|
|
|
atlatc.active.on_receive_fields(pos, ...)
|
|
|
|
|
|
|
|
--set arrowconn (for ATC)
|
2017-02-03 20:40:30 +01:00
|
|
|
local ph=minetest.pos_to_string(pos)
|
2017-12-18 21:44:36 +01:00
|
|
|
local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes)
|
|
|
|
atlatc.active.nodes[ph].arrowconn=conns[1].c
|
2017-02-02 16:40:51 +01:00
|
|
|
end,
|
|
|
|
|
|
|
|
advtrains = {
|
|
|
|
on_train_enter = function(pos, train_id)
|
|
|
|
--do async. Event is fired in train steps
|
2017-02-02 21:14:20 +01:00
|
|
|
atlatc.interrupt.add(0, pos, {type="train", train=true, id=train_id})
|
2017-02-02 16:40:51 +01:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
luaautomation = {
|
|
|
|
fire_event=r.fire_event
|
2018-04-25 17:14:03 +02:00
|
|
|
},
|
|
|
|
digiline = {
|
|
|
|
receptor = {},
|
|
|
|
effector = {
|
|
|
|
action = atlatc.active.on_digiline_receive
|
|
|
|
},
|
|
|
|
},
|
2017-02-02 16:40:51 +01:00
|
|
|
}
|
2018-04-25 17:14:03 +02:00
|
|
|
end,
|
2017-02-02 16:40:51 +01:00
|
|
|
}, advtrains.trackpresets.t_30deg_straightonly)
|
|
|
|
|
|
|
|
|
|
|
|
atlatc.rail = r
|