Commit 1.6.2

- Add some more stuff to API for LuaATC rails
- Warn on strange events even if debug info is disabled
- save atlatc on shutdown too
- fix detector rails in unloaded chunks
- do not fail silently in simple ATC rails
This commit is contained in:
orwell96 2017-02-04 18:35:34 +01:00
parent 1e3bd3a5fd
commit 61e48fff28
8 changed files with 75 additions and 38 deletions

Binary file not shown.

View File

@ -41,10 +41,22 @@ function atc.send_command(pos)
) )
advtrains.trains[train_id].atc_command=atc.controllers[pts].command advtrains.trains[train_id].atc_command=atc.controllers[pts].command
atprint("Sending ATC Command: "..atc.controllers[pts].command) atprint("Sending ATC Command: "..atc.controllers[pts].command)
return true
end end
end end
atwarn("ATC rail at", pos, ": Rail not on train's path! Can't determine arrow direction. Assuming +!")
advtrains.trains[train_id].atc_arrow=true
advtrains.trains[train_id].atc_command=atc.controllers[pts].command
atprint("Sending ATC Command: "..atc.controllers[pts].command)
else
atwarn("ATC rail at", pos, ": Sending command failed: The train",train_id,"does not exist. This seems to be a bug.")
end end
else
atwarn("ATC rail at", pos, ": Sending command failed: There's no train at this position. This seems to be a bug.")
end end
else
atwarn("ATC rail at", pos, ": Sending command failed: Entry for controller not found.")
atwarn("ATC rail at", pos, ": Please visit controller and click 'Save'")
end end
return false return false
end end
@ -182,7 +194,7 @@ local matchptn={
train.movedir=train.movedir*-1 train.movedir=train.movedir*-1
train.atc_arrow = not train.atc_arrow train.atc_arrow = not train.atc_arrow
else else
minetest.chat_send_all(attrans("ATC Reverse command warning: didn't reverse train, train moving!")) atwarn(sid(id), attrans("ATC Reverse command warning: didn't reverse train, train moving!"))
end end
return 1 return 1
end, end,
@ -241,7 +253,7 @@ function atc.execute_atc_command(id, train)
local nest, pos, elsepos=0, 1 local nest, pos, elsepos=0, 1
while nest>=0 do while nest>=0 do
if pos>#rest then if pos>#rest then
minetest.chat_send_all(attrans("ATC command syntax error: I statement not closed: @1",command)) atwarn(sid(id), attrans("ATC command syntax error: I statement not closed: @1",command))
atc.train_reset_command(id) atc.train_reset_command(id)
return return
end end
@ -284,7 +296,7 @@ function atc.execute_atc_command(id, train)
end end
end end
end end
minetest.chat_send_all(attrans("ATC command parse error: Unknown command: @1", command)) atwarn(sid(id), attrans("ATC command parse error: Unknown command: @1", command))
atc.train_reset_command(id) atc.train_reset_command(id)
end end

View File

@ -49,6 +49,11 @@ if minetest.setting_getbool("advtrains_debug") then
minetest.chat_send_all("[advtrains]"..text) minetest.chat_send_all("[advtrains]"..text)
end end
end end
atwarn=function(t, ...)
local text=advtrains.print_concat_table({t, ...})
minetest.log("warning", "[advtrains]"..text)
minetest.chat_send_all("[advtrains] -!- "..text)
end
sid=function(id) return string.sub(id, -4) end sid=function(id) return string.sub(id, -4) end
dofile(advtrains.modpath.."/helpers.lua"); dofile(advtrains.modpath.."/helpers.lua");

View File

@ -615,7 +615,7 @@ if mesecon then
}, },
advtrains = { advtrains = {
on_train_enter=function(pos, train_id) on_train_enter=function(pos, train_id)
minetest.swap_node(pos, {name="advtrains:dtrack_detector_on".."_"..suffix..rotation, param2=minetest.get_node(pos).param2}) advtrains.ndb.swap_node(pos, {name="advtrains:dtrack_detector_on".."_"..suffix..rotation, param2=minetest.get_node(pos).param2})
mesecon.receptor_on(pos, advtrains.meseconrules) mesecon.receptor_on(pos, advtrains.meseconrules)
end end
} }
@ -640,7 +640,7 @@ if mesecon then
}, },
advtrains = { advtrains = {
on_train_leave=function(pos, train_id) on_train_leave=function(pos, train_id)
minetest.swap_node(pos, {name="advtrains:dtrack_detector_off".."_"..suffix..rotation, param2=minetest.get_node(pos).param2}) advtrains.ndb.swap_node(pos, {name="advtrains:dtrack_detector_off".."_"..suffix..rotation, param2=minetest.get_node(pos).param2})
mesecon.receptor_off(pos, advtrains.meseconrules) mesecon.receptor_off(pos, advtrains.meseconrules)
end end
} }

View File

@ -117,13 +117,15 @@ Fired when another node called 'interrupt_pos' on this position. 'message' is th
In addition to the default environment functions, the following functions are available: In addition to the default environment functions, the following functions are available:
atc_send(<atc_command>) atc_send(<atc_command>)
Sends the specified ATC command to the train and returns true. If there is no train, returns false and does nothing. Sends the specified ATC command to the train and returns true. If there is no train, returns false and does nothing.
atc_reset() atc_reset()
Resets the train's current ATC command Resets the train's current ATC command. If there is no train, returns false and does nothing.
atc_arrow atc_arrow
Boolean, true when the train is driving in the direction of the arrows of the ATC rail Boolean, true when the train is driving in the direction of the arrows of the ATC rail. Nil if there is no train.
atc_id
Train ID of the train currently passing the controller. Nil if there's no train.
atc_speed
Speed of the train, or nil if there is no train.
# Operator panel # Operator panel
This simple node executes its actions when punched. It can be used to change a switch and update the corresponding signals or similar applications. This simple node executes its actions when punched. It can be used to change a switch and update the corresponding signals or similar applications.

View File

@ -76,9 +76,10 @@ function ac.on_receive_fields(pos, formname, fields, player)
if fields.cle then if fields.cle then
nodetbl.data={} nodetbl.data={}
end end
meta:set_string("formspec", ac.getform(pos, meta))
ac.nodes[ph]=nodetbl ac.nodes[ph]=nodetbl
meta:set_string("formspec", ac.getform(pos, meta))
if nodetbl.env then if nodetbl.env then
meta:set_string("infotext", "LuaAutomation component, assigned to environment '"..nodetbl.env.."'") meta:set_string("infotext", "LuaAutomation component, assigned to environment '"..nodetbl.env.."'")
else else
@ -88,7 +89,11 @@ end
function ac.run_in_env(pos, evtdata, customfct_p) function ac.run_in_env(pos, evtdata, customfct_p)
local ph=minetest.pos_to_string(pos) local ph=minetest.pos_to_string(pos)
local nodetbl = ac.nodes[ph] or {} local nodetbl = ac.nodes[ph]
if not nodetbl then
atwarn("LuaAutomation component at",ph,": Data not in memory! Please visit component and click 'Save'!")
return
end
local meta local meta
if minetest.get_node(pos) then if minetest.get_node(pos) then
@ -96,10 +101,12 @@ function ac.run_in_env(pos, evtdata, customfct_p)
end end
if not nodetbl.env or not atlatc.envs[nodetbl.env] then if not nodetbl.env or not atlatc.envs[nodetbl.env] then
return false, "Not an existing environment: "..(nodetbl.env or "<nil>") atwarn("LuaAutomation component at",ph,": Not an existing environment: "..(nodetbl.env or "<nil>"))
return false
end end
if not nodetbl.code or nodetbl.code=="" then if not nodetbl.code or nodetbl.code=="" then
return false, "No code to run!" atwarn("LuaAutomation component at",ph,": No code to run! (insert -- to suppress warning)")
return false
end end
local customfct=customfct_p or {} local customfct=customfct_p or {}
@ -113,6 +120,7 @@ function ac.run_in_env(pos, evtdata, customfct_p)
atlatc.active.nodes[ph].data=atlatc.remove_invalid_data(dataout) atlatc.active.nodes[ph].data=atlatc.remove_invalid_data(dataout)
else else
atlatc.active.nodes[ph].err=dataout atlatc.active.nodes[ph].err=dataout
atwarn("LuaAutomation ATC interface rail at",ph,": LUA Error:",dataout)
if meta then if meta then
meta:set_string("infotext", "LuaAutomation ATC interface rail, ERROR:"..dataout) meta:set_string("infotext", "LuaAutomation ATC interface rail, ERROR:"..dataout)
end end

View File

@ -11,7 +11,7 @@ function r.fire_event(pos, evtdata)
local railtbl = atlatc.active.nodes[ph] local railtbl = atlatc.active.nodes[ph]
if not railtbl then if not railtbl then
atprint("missing rail table entry!") atwarn("LuaAutomation ATC interface rail at",ph,": Data not in memory! Please visit position and click 'Save'!")
return return
end end
@ -19,40 +19,48 @@ function r.fire_event(pos, evtdata)
local arrowconn = railtbl.arrowconn local arrowconn = railtbl.arrowconn
--prepare ingame API for ATC. Regenerate each time since pos needs to be known --prepare ingame API for ATC. Regenerate each time since pos needs to be known
local atc_valid, atc_arrow --If no train, then return false.
local train_id=advtrains.detector.on_node[ph] local train_id=advtrains.detector.on_node[ph]
local train=advtrains.trains[train_id] local train, atc_arrow, tvel
if not train then return false end if train_id then train=advtrains.trains[train_id] end
if not train.path then if train then
--we happened to get in between an invalidation step if not train.path then
--delay --we happened to get in between an invalidation step
atlatc.interrupt.add(0,pos,evtdata) --delay
return atlatc.interrupt.add(0,pos,evtdata)
end return
for index, ppos in pairs(train.path) do end
if vector.equals(advtrains.round_vector_floor_y(ppos), pos) then for index, ppos in pairs(train.path) do
atc_arrow = if vector.equals(advtrains.round_vector_floor_y(ppos), pos) then
vector.equals( atc_arrow =
advtrains.dirCoordSet(pos, arrowconn), vector.equals(
advtrains.round_vector_floor_y(train.path[index+train.movedir]) advtrains.dirCoordSet(pos, arrowconn),
) advtrains.round_vector_floor_y(train.path[index+train.movedir])
atc_valid = true )
end
end
if atc_arrow==nil then
atwarn("LuaAutomation ATC rail at", pos, ": Rail not on train's path! Can't determine arrow direction. Assuming +!")
atc_arrow=true
tvel=train.velocity
end end
end end
local customfct={ local customfct={
atc_send = function(cmd) atc_send = function(cmd)
if not train_id then return false end
advtrains.atc.train_reset_command(train_id) advtrains.atc.train_reset_command(train_id)
if atc_valid then train.atc_command=cmd
train.atc_command=cmd train.atc_arrow=atc_arrow
train.atc_arrow=atc_arrow return true
return atc_valid
end
end, end,
atc_reset = function(cmd) atc_reset = function(cmd)
if not train_id then return false end
advtrains.atc.train_reset_command(train_id) advtrains.atc.train_reset_command(train_id)
return true return true
end, end,
atc_arrow = atc_arrow atc_arrow = atc_arrow,
atc_id = train_id,
atc_speed = tvel,
} }
atlatc.active.run_in_env(pos, evtdata, customfct) atlatc.active.run_in_env(pos, evtdata, customfct)

View File

@ -85,6 +85,8 @@ atlatc.save = function()
file:close() file:close()
end end
minetest.register_on_shutdown(atlatc.save)
-- globalstep for step code -- globalstep for step code
local timer, step_int=0, 2 local timer, step_int=0, 2
local stimer, sstep_int=0, 10 local stimer, sstep_int=0, 10