This commit is contained in:
root 2021-02-19 14:15:18 +01:00
parent 067fadf85d
commit 42a97930ec
327 changed files with 2306 additions and 1054 deletions

View File

@ -182,9 +182,11 @@ minetest.register_node(nodename, {
^- called when a train leaves the rail ^- called when a train leaves the rail
-- The following function is only in effect when interlocking is enabled: -- The following function is only in effect when interlocking is enabled:
on_train_approach = function(pos, train_id, train, index, lzbdata) on_train_approach = function(pos, train_id, train, index, has_entered, lzbdata)
^- called when a train is approaching this position, called exactly once for every path recalculation (which can happen at any time) ^- called when a train is approaching this position, called exactly once for every path recalculation (which can happen at any time)
^- This is called so that if the train would start braking now, it would come to halt about(wide approx) 5 nodes before the rail. ^- This is called so that if the train would start braking now, it would come to halt about(wide approx) 5 nodes before the rail.
^- has_entered: when true, the train is already standing on this node with its front tip, and the enter callback has already been called.
Possibly, some actions need not to be taken in this case. Only set if it's the very first node the train is standing on.
^- lzbdata should be ignored and nothing should be assigned to it ^- lzbdata should be ignored and nothing should be assigned to it
} }
}) })

View File

@ -72,6 +72,12 @@ function atc.send_command(pos, par_tid)
end end
else else
atwarn("ATC rail at", pos, ": Sending command failed: There's no train at this position. This seems to be a bug.") atwarn("ATC rail at", pos, ": Sending command failed: There's no train at this position. This seems to be a bug.")
-- huch
--local train = advtrains.trains[train_id_temp_debug]
--atlog("Train speed is",train.velocity,", have moved",train.dist_moved_this_step,", lever",train.lever)
--advtrains.path_print(train, atlog)
-- TODO track again when ATC bugs occur...
end end
else else
atwarn("ATC rail at", pos, ": Sending command failed: Entry for controller not found.") atwarn("ATC rail at", pos, ": Sending command failed: Entry for controller not found.")
@ -108,57 +114,53 @@ advtrains.atc_function = function(def, preset, suffix, rotation)
return { return {
after_place_node=apn_func, after_place_node=apn_func,
after_dig_node=function(pos) after_dig_node=function(pos)
return advtrains.pcall(function() advtrains.invalidate_all_paths(pos)
advtrains.invalidate_all_paths(pos) advtrains.ndb.clear(pos)
advtrains.ndb.clear(pos) local pts=minetest.pos_to_string(pos)
local pts=minetest.pos_to_string(pos) atc.controllers[pts]=nil
atc.controllers[pts]=nil
end)
end, end,
on_receive_fields = function(pos, formname, fields, player) on_receive_fields = function(pos, formname, fields, player)
return advtrains.pcall(function() if advtrains.is_protected(pos, player:get_player_name()) then
if advtrains.is_protected(pos, player:get_player_name()) then minetest.record_protection_violation(pos, player:get_player_name())
minetest.record_protection_violation(pos, player:get_player_name()) return
end
local meta=minetest.get_meta(pos)
if meta then
if not fields.save then
--[[--maybe only the dropdown changed
if fields.mode then
meta:set_string("mode", idxtrans[fields.mode])
if fields.mode=="digiline" then
meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", fields.mode, meta:get_string("command")) )
else
meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", fields.mode, meta:get_string("command")) )
end
meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta))
end]]--
return return
end end
local meta=minetest.get_meta(pos) --meta:set_string("mode", idxtrans[fields.mode])
if meta then meta:set_string("command", fields.command)
if not fields.save then --meta:set_string("command_on", fields.command_on)
--maybe only the dropdown changed meta:set_string("channel", fields.channel)
if fields.mode then --if fields.mode=="digiline" then
meta:set_string("mode", idxtrans[fields.mode]) -- meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", fields.mode, meta:get_string("command")) )
if fields.mode=="digiline" then --else
meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", (fields.mode or "?"), meta:get_string("command")) ) meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", "-", meta:get_string("command")) )
else --end
meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", (fields.mode or "?"), meta:get_string("command")) ) meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta))
end
meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta)) local pts=minetest.pos_to_string(pos)
end local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes)
return atc.controllers[pts]={command=fields.command}
end if #advtrains.occ.get_trains_at(pos) > 0 then
meta:set_string("mode", idxtrans[fields.mode]) atc.send_command(pos)
meta:set_string("command", fields.command)
meta:set_string("command_on", fields.command_on)
meta:set_string("channel", fields.channel)
if fields.mode=="digiline" then
meta:set_string("infotext", attrans("ATC controller, mode @1\nChannel: @2", (fields.mode or "?"), meta:get_string("command")) )
else
meta:set_string("infotext", attrans("ATC controller, mode @1\nCommand: @2", (fields.mode or "?"), meta:get_string("command")) )
end
meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta))
local pts=minetest.pos_to_string(pos)
local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes)
atc.controllers[pts]={command=fields.command}
if #advtrains.occ.get_trains_at(pos) > 0 then
atc.send_command(pos)
end
end end
end) end
end, end,
advtrains = { advtrains = {
on_train_enter = function(pos, train_id) on_train_enter = function(pos, train_id)
atc.send_command(pos) atc.send_command(pos, train_id)
end, end,
}, },
} }
@ -256,6 +258,11 @@ local matchptn={
end end
return 1 return 1
end, end,
["A([01])"]=function(id, train, match)
if not advtrains.interlocking then return 2 end
advtrains.interlocking.ars_set_disable(train, match=="0")
return 2
end,
} }
eval_conditional = function(command, arrow, speed) eval_conditional = function(command, arrow, speed)

View File

@ -13,76 +13,74 @@ minetest.register_tool("advtrains:copytool", {
-- The front of the train is used as the start of the new train and it proceeds backwards from -- The front of the train is used as the start of the new train and it proceeds backwards from
-- the direction of travel. -- the direction of travel.
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
return advtrains.pcall(function() if ((not pointed_thing.type == "node") or (not placer.get_player_name)) then
if ((not pointed_thing.type == "node") or (not placer.get_player_name)) then
return
end
local pname = placer:get_player_name()
local node=minetest.get_node_or_nil(pointed_thing.under)
if not node then atprint("[advtrains]Ignore at placer position") return itemstack end
local nodename=node.name
if(not advtrains.is_track_and_drives_on(nodename, {default=true})) then
atprint("no track here, not placing.")
return itemstack
end
if not minetest.check_player_privs(placer, {train_operator = true }) then
minetest.chat_send_player(pname, "You don't have the train_operator privilege.")
return itemstack
end
if not minetest.check_player_privs(placer, {train_admin = true }) and minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
return itemstack
end
local tconns=advtrains.get_track_connections(node.name, node.param2)
local yaw = placer:get_look_horizontal()
local plconnid = advtrains.yawToClosestConn(yaw, tconns)
local prevpos = advtrains.get_adjacent_rail(pointed_thing.under, tconns, plconnid, {default=true})
if not prevpos then
minetest.chat_send_player(pname, "The track you are trying to place the wagon on is not long enough!")
return
end
local meta = itemstack:get_meta()
if not meta then
minetest.chat_send_player(pname, attrans("The clipboard couldn't access the metadata. Paste failed."))
return return
end end
local clipboard = meta:get_string("clipboard") local pname = placer:get_player_name()
if (clipboard == "") then
minetest.chat_send_player(pname, "The clipboard is empty.");
return
end
clipboard = minetest.deserialize(clipboard)
if (clipboard.wagons == nil) then
minetest.chat_send_player(pname, "The clipboard is empty.");
return
end
local wagons = {} local node=minetest.get_node_or_nil(pointed_thing.under)
local n = 1 if not node then atprint("[advtrains]Ignore at placer position") return itemstack end
for _, wagonProto in pairs(clipboard.wagons) do local nodename=node.name
local wagon = advtrains.create_wagon(wagonProto.type, pname) if(not advtrains.is_track_and_drives_on(nodename, {default=true})) then
advtrains.wagons[wagon].wagon_flipped = wagonProto.wagon_flipped atprint("no track here, not placing.")
wagons[n] = wagon return itemstack
n = n + 1 end
end if not minetest.check_player_privs(placer, {train_operator = true }) then
minetest.chat_send_player(pname, "You don't have the train_operator privilege.")
local id=advtrains.create_new_train_at(pointed_thing.under, plconnid, 0, wagons) return itemstack
local train = advtrains.trains[id] end
train.off_track = train.end_index<train.path_trk_b if not minetest.check_player_privs(placer, {train_admin = true }) and minetest.is_protected(pointed_thing.under, placer:get_player_name()) then
if (train.off_track) then return itemstack
minetest.chat_send_player(pname, "Back of train would end up off track, cancelling.") end
advtrains.remove_train(id) local tconns=advtrains.get_track_connections(node.name, node.param2)
return local yaw = placer:get_look_horizontal()
end local plconnid = advtrains.yawToClosestConn(yaw, tconns)
train.text_outside = clipboard.text_outside
train.text_inside = clipboard.text_inside
train.routingcode = clipboard.routingcode
train.line = clipboard.line
local prevpos = advtrains.get_adjacent_rail(pointed_thing.under, tconns, plconnid, {default=true})
if not prevpos then
minetest.chat_send_player(pname, "The track you are trying to place the wagon on is not long enough!")
return return
end) end
local meta = itemstack:get_meta()
if not meta then
minetest.chat_send_player(pname, attrans("The clipboard couldn't access the metadata. Paste failed."))
return
end
local clipboard = meta:get_string("clipboard")
if (clipboard == "") then
minetest.chat_send_player(pname, "The clipboard is empty.");
return
end
clipboard = minetest.deserialize(clipboard)
if (clipboard.wagons == nil) then
minetest.chat_send_player(pname, "The clipboard is empty.");
return
end
local wagons = {}
local n = 1
for _, wagonProto in pairs(clipboard.wagons) do
local wagon = advtrains.create_wagon(wagonProto.type, pname)
advtrains.wagons[wagon].wagon_flipped = wagonProto.wagon_flipped
wagons[n] = wagon
n = n + 1
end
local id=advtrains.create_new_train_at(pointed_thing.under, plconnid, 0, wagons)
local train = advtrains.trains[id]
train.off_track = train.end_index<train.path_trk_b
if (train.off_track) then
minetest.chat_send_player(pname, "Back of train would end up off track, cancelling.")
advtrains.remove_train(id)
return
end
train.text_outside = clipboard.text_outside
train.text_inside = clipboard.text_inside
train.routingcode = clipboard.routingcode
train.line = clipboard.line
return
end, end,
-- Copy: Take the pointed-at train and put it on the clipboard -- Copy: Take the pointed-at train and put it on the clipboard
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
@ -182,4 +180,4 @@ minetest.register_tool("advtrains:copytool", {
minetest.chat_send_player(user:get_player_name(), attrans("Train copied!")) minetest.chat_send_player(user:get_player_name(), attrans("Train copied!"))
return itemstack return itemstack
end end
}) })

View File

@ -32,7 +32,6 @@ minetest.register_entity("advtrains:discouple", {
end, end,
get_staticdata=function() return "DISCOUPLE" end, get_staticdata=function() return "DISCOUPLE" end,
on_punch=function(self, player) on_punch=function(self, player)
return advtrains.pcall(function()
local pname = player:get_player_name() local pname = player:get_player_name()
if pname and pname~="" and self.wagon then if pname and pname~="" and self.wagon then
if advtrains.safe_decouple_wagon(self.wagon.id, pname) then if advtrains.safe_decouple_wagon(self.wagon.id, pname) then
@ -41,16 +40,14 @@ minetest.register_entity("advtrains:discouple", {
minetest.add_entity(self.object:getpos(), "advtrains:lockmarker") minetest.add_entity(self.object:getpos(), "advtrains:lockmarker")
end end
end end
end)
end, end,
on_step=function(self, dtime) on_step=function(self, dtime)
return advtrains.pcall(function()
if not self.wagon then if not self.wagon then
self.object:remove() self.object:remove()
return return
end end
--getyaw seems to be a reliable method to check if an object is loaded...if it returns nil, it is not. --getyaw seems to be a reliable method to check if an object is loaded...if it returns nil, it is not.
if not self.wagon.object:getyaw() then if not self.wagon.object:get_yaw() then
self.object:remove() self.object:remove()
return return
end end
@ -58,7 +55,6 @@ minetest.register_entity("advtrains:discouple", {
self.object:remove() self.object:remove()
return return
end end
end)
end, end,
}) })
@ -79,7 +75,6 @@ minetest.register_entity("advtrains:couple", {
is_couple=true, is_couple=true,
static_save = false, static_save = false,
on_activate=function(self, staticdata) on_activate=function(self, staticdata)
return advtrains.pcall(function()
if staticdata=="COUPLE" then if staticdata=="COUPLE" then
--couple entities have no right to exist further... --couple entities have no right to exist further...
atprint("Couple loaded from staticdata, destroying") atprint("Couple loaded from staticdata, destroying")
@ -87,11 +82,9 @@ minetest.register_entity("advtrains:couple", {
return return
end end
self.object:set_armor_groups({immmortal=1}) self.object:set_armor_groups({immmortal=1})
end)
end, end,
get_staticdata=function(self) return "COUPLE" end, get_staticdata=function(self) return "COUPLE" end,
on_rightclick=function(self, clicker) on_rightclick=function(self, clicker)
return advtrains.pcall(function()
if not self.train_id_1 or not self.train_id_2 then return end if not self.train_id_1 or not self.train_id_2 then return end
local pname=clicker local pname=clicker
@ -102,15 +95,12 @@ minetest.register_entity("advtrains:couple", {
else else
lockmarker(self.object) lockmarker(self.object)
end end
end)
end, end,
on_step=function(self, dtime) on_step=function(self, dtime)
return advtrains.pcall(function()
if advtrains.wagon_outside_range(self.object:getpos()) then if advtrains.wagon_outside_range(self.object:getpos()) then
self.object:remove() self.object:remove()
return return
end end
advtrains.atprint_context_tid=self.train_id_1
if not self.train_id_1 or not self.train_id_2 then atprint("Couple: train ids not set!") self.object:remove() return end if not self.train_id_1 or not self.train_id_2 then atprint("Couple: train ids not set!") self.object:remove() return end
local train1=advtrains.trains[self.train_id_1] local train1=advtrains.trains[self.train_id_1]
@ -155,14 +145,12 @@ minetest.register_entity("advtrains:couple", {
end end
local pos_median=advtrains.pos_median(tp1, tp2) local pos_median=advtrains.pos_median(tp1, tp2)
if not vector.equals(pos_median, self.object:getpos()) then if not vector.equals(pos_median, self.object:getpos()) then
self.object:setpos(pos_median) self.object:set_pos(pos_median)
end end
self.position_set=true self.position_set=true
end end
atprintbm("couple step", t) atprintbm("couple step", t)
advtrains.atprint_context_tid=nil advtrains.atprint_context_tid=nil
end)
end, end,
}) })
minetest.register_entity("advtrains:lockmarker", { minetest.register_entity("advtrains:lockmarker", {
@ -175,7 +163,6 @@ minetest.register_entity("advtrains:lockmarker", {
is_lockmarker=true, is_lockmarker=true,
static_save = false, static_save = false,
on_activate=function(self, staticdata) on_activate=function(self, staticdata)
return advtrains.pcall(function()
if staticdata=="COUPLE" then if staticdata=="COUPLE" then
--couple entities have no right to exist further... --couple entities have no right to exist further...
atprint("Couple loaded from staticdata, destroying") atprint("Couple loaded from staticdata, destroying")
@ -184,7 +171,6 @@ minetest.register_entity("advtrains:lockmarker", {
end end
self.object:set_armor_groups({immmortal=1}) self.object:set_armor_groups({immmortal=1})
self.life=5 self.life=5
end)
end, end,
get_staticdata=function(self) return "COUPLE" end, get_staticdata=function(self) return "COUPLE" end,
on_step=function(self, dtime) on_step=function(self, dtime)

View File

@ -24,7 +24,10 @@ function advtrains.drb_dump(tid)
return return
end end
repeat repeat
atdebug(ringbufs[tid][ringbufcnt[tid]]) local t = ringbufs[tid][ringbufcnt[tid]]
if t then
atdebug(t)
end
ringbufcnt[tid]=ringbufcnt[tid]+1 ringbufcnt[tid]=ringbufcnt[tid]+1
if ringbufcnt[tid] > ringbuflen then if ringbufcnt[tid] > ringbuflen then
ringbufcnt[tid]=0 ringbufcnt[tid]=0

View File

@ -26,15 +26,37 @@ minetest.log("action", "[advtrains] Loading...")
attrans = minetest.get_translator ("advtrains") attrans = minetest.get_translator ("advtrains")
--advtrains --advtrains
advtrains = {trains={}, player_to_train_mapping={}}
DUMP_DEBUG_SAVE = false -- =======================Development/debugging settings=====================
GENERATE_ATRICIFIAL_LAG = false -- DO NOT USE FOR NORMAL OPERATION
local DUMP_DEBUG_SAVE = false
-- dump the save files in human-readable format into advtrains_DUMP
local GENERATE_ATRICIFIAL_LAG = false
local HOW_MANY_LAG = 1.0
-- Simulate a higher server step interval, as it occurs when the server is on high load
advtrains.IGNORE_WORLD = false
-- Run advtrains without respecting the world map
-- - No world collision checks occur
-- - The NDB forcibly places all nodes stored in it into the world regardless of the world's content.
-- - Rails do not set the 'attached_node' group
-- This mode can be useful for debugging/testing a world without the map data available
-- In this case, choose 'singlenode' as mapgen
local NO_SAVE = false
-- Do not save any data to advtrains save files
-- ==========================================================================
-- Use a global slowdown factor to slow down train movements. Now a setting
advtrains.DTIME_LIMIT = tonumber(minetest.settings:get("advtrains_dtime_limit")) or 0.2
advtrains.SAVE_INTERVAL = tonumber(minetest.settings:get("advtrains_save_interval")) or 60
--Constant for maximum connection value/division of the circle --Constant for maximum connection value/division of the circle
AT_CMAX = 16 AT_CMAX = 16
advtrains = {trains={}, player_to_train_mapping={}}
-- get wagon loading range -- get wagon loading range
advtrains.wagon_load_range = tonumber(minetest.settings:get("advtrains_wagon_load_range")) advtrains.wagon_load_range = tonumber(minetest.settings:get("advtrains_wagon_load_range"))
if not advtrains.wagon_load_range then if not advtrains.wagon_load_range then
@ -61,25 +83,6 @@ local function reload_saves()
end) end)
end end
function advtrains.pcall(fun)
if no_action then return end
local succ, return1, return2, return3, return4=xpcall(fun, function(err)
atwarn("Lua Error occured: ", err)
atwarn(debug.traceback())
if advtrains.atprint_context_tid then
advtrains.path_print(advtrains.trains[advtrains.atprint_context_tid], atdebug)
atwarn(advtrains.trains[advtrains.atprint_context_tid].debug)
end
end)
if not succ then
reload_saves()
else
return return1, return2, return3, return4
end
end
advtrains.modpath = minetest.get_modpath("advtrains") advtrains.modpath = minetest.get_modpath("advtrains")
--Advtrains dump (special treatment of pos and sigd) --Advtrains dump (special treatment of pos and sigd)
@ -464,7 +467,8 @@ advtrains.avt_save = function(remove_players_from_wagons)
"trainparts", "recently_collided_with_env", "trainparts", "recently_collided_with_env",
"atc_brake_target", "atc_wait_finish", "atc_command", "atc_delay", "door_open", "atc_brake_target", "atc_wait_finish", "atc_command", "atc_delay", "door_open",
"text_outside", "text_inside", "line", "routingcode", "text_outside", "text_inside", "line", "routingcode",
"il_sections", "speed_restriction", "is_shunt", "points_split", "autocouple" "il_sections", "speed_restriction", "is_shunt",
"points_split", "autocouple", "ars_disable",
}) })
--then save it --then save it
tmp_trains[id]=v tmp_trains[id]=v
@ -560,14 +564,17 @@ end
--## MAIN LOOP ##-- --## MAIN LOOP ##--
--Calls all subsequent main tasks of both advtrains and atlatc --Calls all subsequent main tasks of both advtrains and atlatc
local init_load=false local init_load=false
local save_interval=60 local save_timer = advtrains.SAVE_INTERVAL
local save_timer=save_interval
advtrains.mainloop_runcnt=0 advtrains.mainloop_runcnt=0
advtrains.global_slowdown = 1
local t = 0 local t = 0
minetest.register_globalstep(function(dtime_mt) minetest.register_globalstep(function(dtime_mt)
return advtrains.pcall(function() if no_action then
-- the advtrains globalstep is skipped by command. Return immediately
return
end
advtrains.mainloop_runcnt=advtrains.mainloop_runcnt+1 advtrains.mainloop_runcnt=advtrains.mainloop_runcnt+1
--atprint("Running the main loop, runcnt",advtrains.mainloop_runcnt) --atprint("Running the main loop, runcnt",advtrains.mainloop_runcnt)
--call load once. see advtrains.load() comment --call load once. see advtrains.load() comment
@ -575,24 +582,30 @@ minetest.register_globalstep(function(dtime_mt)
advtrains.load() advtrains.load()
end end
local dtime local dtime = dtime_mt * advtrains.global_slowdown
if GENERATE_ATRICIFIAL_LAG then if GENERATE_ATRICIFIAL_LAG then
dtime = 0.2 dtime = HOW_MANY_LAG
if os.clock()<t then if os.clock()<t then
return return
end end
t = os.clock()+0.2 t = os.clock()+HOW_MANY_LAG
else end
--limit dtime: if trains move too far in one step, automation may cause stuck and wrongly braking trains -- if dtime is too high, decrease global slowdown
dtime=dtime_mt if advtrains.DTIME_LIMIT~=0 then
if dtime>0.2 then if dtime > advtrains.DTIME_LIMIT then
atprint("Limiting dtime to 0.2!") if advtrains.global_slowdown > 0.1 then
dtime=0.2 advtrains.global_slowdown = advtrains.global_slowdown - 0.05
else
advtrains.global_slowdown = advtrains.global_slowdown / 2
end
dtime = advtrains.DTIME_LIMIT
end end
-- recover global slowdown slowly over time
advtrains.global_slowdown = math.min(advtrains.global_slowdown*1.02, 1)
end end
advtrains.mainloop_trainlogic(dtime) advtrains.mainloop_trainlogic(dtime,advtrains.mainloop_runcnt)
if advtrains_itm_mainloop then if advtrains_itm_mainloop then
advtrains_itm_mainloop(dtime) advtrains_itm_mainloop(dtime)
end end
@ -610,10 +623,9 @@ minetest.register_globalstep(function(dtime_mt)
local t=os.clock() local t=os.clock()
--save --save
advtrains.save() advtrains.save()
save_timer=save_interval save_timer = advtrains.SAVE_INTERVAL
atprintbm("saving", t) atprintbm("saving", t)
end end
end)
end) end)
--if something goes wrong in these functions, there is no help. no pcall here. --if something goes wrong in these functions, there is no help. no pcall here.
@ -642,12 +654,27 @@ function advtrains.save(remove_players_from_wagons)
atwarn("Instructed to save() but load() was never called!") atwarn("Instructed to save() but load() was never called!")
return return
end end
if advtrains.IGNORE_WORLD then
advtrains.ndb.restore_all()
end
if NO_SAVE then
return
end
if no_action then
atlog("[save] Saving requested externally, but Advtrains step is disabled. Not saving any data as state may be inconsistent.")
return
end
local t1 = os.clock()
advtrains.avt_save(remove_players_from_wagons) --saving advtrains. includes ndb at advtrains.ndb.save_data() advtrains.avt_save(remove_players_from_wagons) --saving advtrains. includes ndb at advtrains.ndb.save_data()
if atlatc then if atlatc then
atlatc.save() atlatc.save()
end end
atprint("[save_all]Saved advtrains save files") atlog("Saved advtrains save files, took",math.floor((os.clock()-t1) * 1000),"ms")
-- Cleanup actions
--TODO very simple yet hacky workaround for the "green signals" bug --TODO very simple yet hacky workaround for the "green signals" bug
advtrains.invalidate_all_paths() advtrains.invalidate_all_paths()
end end
@ -662,11 +689,9 @@ minetest.register_chatcommand("at_empty_seats",
description = "Detach all players, especially the offline ones, from all trains. Use only when no one serious is on a train.", -- Full description description = "Detach all players, especially the offline ones, from all trains. Use only when no one serious is on a train.", -- Full description
privs = {train_operator=true, server=true}, -- Require the "privs" privilege to run privs = {train_operator=true, server=true}, -- Require the "privs" privilege to run
func = function(name, param) func = function(name, param)
return advtrains.pcall(function()
atwarn("Data is being saved. While saving, advtrains will remove the players from trains. Save files will be reloaded afterwards!") atwarn("Data is being saved. While saving, advtrains will remove the players from trains. Save files will be reloaded afterwards!")
advtrains.save(true) advtrains.save(true)
reload_saves() reload_saves()
end)
end, end,
}) })
-- This chat command solves another problem: Trains getting randomly stuck. -- This chat command solves another problem: Trains getting randomly stuck.
@ -676,13 +701,36 @@ minetest.register_chatcommand("at_reroute",
description = "Delete all train routes, force them to recalculate", description = "Delete all train routes, force them to recalculate",
privs = {train_operator=true}, -- Only train operator is required, since this is relatively safe. privs = {train_operator=true}, -- Only train operator is required, since this is relatively safe.
func = function(name, param) func = function(name, param)
return advtrains.pcall(function()
advtrains.invalidate_all_paths() advtrains.invalidate_all_paths()
return true, "Successfully invalidated train routes" return true, "Successfully invalidated train routes"
end)
end, end,
}) })
minetest.register_chatcommand("at_disable_step",
{
params = "<yes/no>",
description = "Disable the advtrains globalstep temporarily",
privs = {server=true},
func = function(name, param)
if minetest.is_yes(param) then
-- disable everything, and turn off saving
no_action = true;
atwarn("The advtrains globalstep has been disabled. Trains are not moving, and no data is saved! Run '/at_disable_step no' to enable again!")
return true, "Disabled advtrains successfully"
elseif no_action then
atwarn("Re-enabling advtrains globalstep...")
reload_saves()
return true
else
return false, "Advtrains is already running normally!"
end
end,
})
advtrains.is_no_action = function()
return no_action
end
local tot=(os.clock()-lot)*1000 local tot=(os.clock()-lot)*1000
minetest.log("action", "[advtrains] Loaded in "..tot.."ms") minetest.log("action", "[advtrains] Loaded in "..tot.."ms")

View File

@ -4,20 +4,36 @@
--[[ --[[
Documentation of train.lzb table Documentation of train.lzb table
train.lzb = { train.lzb = {
trav = Current index that the traverser has advanced so far trav_index = Current index that the traverser has advanced so far
oncoming = table containing oncoming signals, in order of appearance on the path checkpoints = table containing oncoming signals, in order of index
{ {
pos = position of the point pos = position of the point
idx = where this is on the path index = where this is on the path
spd = speed allowed to pass speed = speed allowed to pass. nil = no effect
fun = function(pos, id, train, index, speed, lzbdata) callback = function(pos, id, train, index, speed, lzbdata)
-- Function that determines what to do on the train in the moment it drives over that point. -- Function that determines what to do on the train in the moment it drives over that point.
-- When spd==0, called instead when train has stopped in front
-- nil = no effect
lzbdata = {}
-- Table of custom data filled in by approach callbacks
-- Whenever an approach callback inserts an LZB checkpoint with changed lzbdata,
-- all consecutive approach callbacks will see these passed as lzbdata table.
udata = arbitrary user data, no official way to retrieve (do not use)
} }
trav_lzbdata = currently active lzbdata table at traverser index
} }
each step, for every item in "oncoming", we need to determine the location to start braking (+ some safety margin) The LZB subsystem keeps track of "checkpoints" the train will pass in the future, and has two main tasks:
and, if we passed this point for at least one of the items, initiate brake. 1. run approach callbacks, and run callbacks when passing LZB checkpoints
When speed has dropped below, say 3, decrease the margin to zero, so that trains actually stop at the signal IP. 2. keep track of the permitted speed at checkpoints, and make sure that the train brakes accordingly
The spd variable and travsht need to be updated on every aspect change. it's probably best to reset everything when any aspect changes To perform 2, it populates the train.path_speed table which is handled along with the path subsystem.
This table is used in trainlogic.lua/train_step_b() and applied to the velocity calculations.
Note: in contrast to node enter callbacks, which are called when the train passes the .5 index mark, LZB callbacks are executed on passing the .0 index mark!
If an LZB checkpoint has speed 0, the train will still enter the node (the enter callback will be called), but will stop at the 0.9 index mark (for details, see SLOW_APPROACH in trainlogic.lua)
The start point for the LZB traverser (and thus the first node that will receive an approach callback) is floor(train.index) + 1. This means, once the LZB checkpoint callback has fired,
this path node will not receive any further approach callbacks for the same approach situation
]] ]]
@ -45,42 +61,130 @@ function advtrains.set_lzb_param(par, val)
end end
end end
local function resolve_latest_lzbdata(ckp, index)
local i = #ckp
local ckpi
while i>0 do
ckpi = ckp[i]
if ckpi.index <= index and ckpi.lzbdata then
return ckpi.lzbdata
end
i=i-1
end
return {}
end
local function look_ahead(id, train) local function look_ahead(id, train)
local lzb = train.lzb
if lzb.zero_checkpoint then
-- if the checkpoints list contains a zero checkpoint, don't look ahead
-- in order to not trigger approach callbacks on the wrong path
return
end
local acc = advtrains.get_acceleration(train, 1) local acc = advtrains.get_acceleration(train, 1)
local vel = train.velocity -- worst-case: the starting point is maximum speed
local vel = train.max_speed or train.velocity
local brakedst = ( -(vel*vel) / (2*acc) ) * params.DST_FACTOR local brakedst = ( -(vel*vel) / (2*acc) ) * params.DST_FACTOR
local brake_i = advtrains.path_get_index_by_offset(train, train.index, brakedst + params.BRAKE_SPACE) --local brake_i = advtrains.path_get_index_by_offset(train, train.index, brakedst + params.BRAKE_SPACE)
-- worst case (don't use index_by_offset)
local brake_i = atfloor(train.index + brakedst + params.BRAKE_SPACE)
atprint("LZB: looking ahead up to ", brake_i)
--local aware_i = advtrains.path_get_index_by_offset(train, brake_i, AWARE_ZONE) --local aware_i = advtrains.path_get_index_by_offset(train, brake_i, AWARE_ZONE)
local lzb = train.lzb local trav = lzb.trav_index
local trav = lzb.trav -- retrieve latest lzbdata
if not lzb.trav_lzbdata then
lzb.trav_lzbdata = resolve_latest_lzbdata(lzb.checkpoints, trav)
end
--train.debug = lspd if lzb.trav_lzbdata.off_track then
--previous position was off track, do not scan any further
end
while trav <= brake_i do while trav <= brake_i and not lzb.zero_checkpoint do
trav = trav + 1
local pos = advtrains.path_get(train, trav) local pos = advtrains.path_get(train, trav)
-- check offtrack -- check offtrack
if trav > train.path_trk_f then if trav - 1 == train.path_trk_f then
table.insert(lzb.oncoming, { lzb.trav_lzbdata.off_track = true
pos = pos, advtrains.lzb_add_checkpoint(train, trav - 1, 0, nil, lzb.trav_lzbdata)
idx = trav-1,
spd = 0,
})
else else
-- run callbacks -- run callbacks
-- Note: those callbacks are defined in trainlogic.lua for consistency with the other node callbacks -- Note: those callbacks are defined in trainlogic.lua for consistency with the other node callbacks
advtrains.tnc_call_approach_callback(pos, id, train, trav, lzb.data) advtrains.tnc_call_approach_callback(pos, id, train, trav, lzb.trav_lzbdata)
end end
trav = trav + 1
end end
lzb.trav = trav lzb.trav_index = trav
end end
advtrains.lzb_look_ahead = look_ahead
local function call_runover_callbacks(id, train)
if not train.lzb then return end
local i = 1
local idx = atfloor(train.index)
local ckp = train.lzb.checkpoints
while ckp[i] do
if ckp[i].index <= idx then
atprint("LZB: checkpoint run over: i=",ckp[i].index,"s=",ckp[i].speed)
-- call callback
local it = ckp[i]
if it.callback then
it.callback(it.pos, id, train, it.index, it.speed, train.lzb.lzbdata)
end
-- note: lzbdata is always defined as look_ahead was called before
table.remove(ckp, i)
else
i = i + 1
end
end
end
-- Flood-fills train.path_speed, based on this checkpoint
local function apply_checkpoint_to_path(train, checkpoint)
if not checkpoint.speed then
return
end
atprint("LZB: applying checkpoint: i=",checkpoint.index,"s=",checkpoint.speed)
if checkpoint.speed == 0 then
train.lzb.zero_checkpoint = true
end
-- make sure path exists until checkpoint
local pos = advtrains.path_get(train, checkpoint.index)
local brake_accel = advtrains.get_acceleration(train, 11)
-- start with the checkpoint index at specified speed
local index = checkpoint.index
local p_speed -- speed in path_speed
local c_speed = checkpoint.speed -- calculated speed at current index
while true do
p_speed = train.path_speed[index]
if (p_speed and p_speed <= c_speed) or index < train.index then
--we're done. train already slower than wanted at this position
return
end
-- insert calculated target speed
train.path_speed[index] = c_speed
-- calculate c_speed at previous index
advtrains.path_get(train, index-1)
local eldist = train.path_dist[index] - train.path_dist[index-1]
-- Calculate the start velocity the train would have if it had a end velocity of c_speed and accelerating with brake_accel, after a distance of eldist:
-- v0² = v1² - 2*a*s
c_speed = math.sqrt( (c_speed * c_speed) - (2 * brake_accel * eldist) )
index = index - 1
end
end
--[[ --[[
Distance needed to accelerate from v0 to v1 with constant acceleration a: Distance needed to accelerate from v0 to v1 with constant acceleration a:
@ -90,95 +194,74 @@ s = v0 * ------- + - * | ------- | = -----------
a 2 \ a / 2*a a 2 \ a / 2*a
]] ]]
local function apply_control(id, train) -- Removes all LZB checkpoints and restarts the traverser at the current train index
local lzb = train.lzb function advtrains.lzb_invalidate(train)
local i = 1
while i<=#lzb.oncoming do
if lzb.oncoming[i].idx < train.index then
local ent = lzb.oncoming[i]
if ent.fun then
ent.fun(ent.pos, id, train, ent.idx, ent.spd, lzb.data)
end
table.remove(lzb.oncoming, i)
else
i = i + 1
end
end
for i, it in ipairs(lzb.oncoming) do
local a = advtrains.get_acceleration(train, 1) --should be negative
local v0 = train.velocity
local v1 = it.spd
if v1 and v1 <= v0 then
local s = (v1*v1 - v0*v0) / (2*a)
local st = s + params.ADD_SLOW
if v0 > 3 then
st = s + params.ADD_FAST
end
if v0<=0 then
st = s + params.ADD_STAND
end
local i = advtrains.path_get_index_by_offset(train, it.idx, -st)
--train.debug = dump({v0f=v0*f, aff=a*f*f,v0=v0, v1=v1, f=f, a=a, s=s, st=st, i=i, idx=train.index})
if i <= train.index then
-- Gotcha! Braking...
train.ctrl.lzb = 1
--train.debug = train.debug .. "BRAKE!!!"
return
end
i = advtrains.path_get_index_by_offset(train, i, -params.ZONE_ROLL)
if i <= train.index and v0>1 then
-- roll control
train.ctrl.lzb = 2
return
end
i = advtrains.path_get_index_by_offset(train, i, -params.ZONE_HOLD)
if i <= train.index and v0>1 then
-- hold speed
train.ctrl.lzb = 3
return
end
end
end
train.ctrl.lzb = nil
end
local function invalidate(train)
train.lzb = { train.lzb = {
trav = atfloor(train.index), trav_index = atfloor(train.index) + 1,
data = {}, checkpoints = {},
oncoming = {},
} }
end end
function advtrains.lzb_invalidate(train) -- LZB part of path_invalidate_ahead. Clears all checkpoints that are ahead of start_idx
invalidate(train) -- in contrast to path_inv_ahead, doesn't complain if start_idx is behind train.index, clears everything then
function advtrains.lzb_invalidate_ahead(train, start_idx)
if train.lzb then
local idx = atfloor(start_idx)
local i = 1
while train.lzb.checkpoints[i] do
if train.lzb.checkpoints[i].index >= idx then
table.remove(train.lzb.checkpoints, i)
else
i=i+1
end
end
train.lzb.trav_index = idx
-- FIX reset trav_lzbdata (look_ahead fetches these when required)
train.lzb.trav_lzbdata = nil
-- re-apply all checkpoints to path_speed
train.path_speed = {}
train.lzb.zero_checkpoint = false
for _,ckp in ipairs(train.lzb.checkpoints) do
apply_checkpoint_to_path(train, ckp)
end
end
end end
-- Add LZB control point -- Add LZB control point
-- udata: User-defined additional data -- lzbdata: If you modify lzbdata in an approach callback, you MUST add a checkpoint AND pass the (modified) lzbdata into it.
function advtrains.lzb_add_checkpoint(train, index, speed, callback, udata) -- If you DON'T modify lzbdata, you MUST pass nil as lzbdata. Always modify the lzbdata table in place, never overwrite it!
-- udata: user-defined data, do not use externally
function advtrains.lzb_add_checkpoint(train, index, speed, callback, lzbdata, udata)
local lzb = train.lzb local lzb = train.lzb
local pos = advtrains.path_get(train, index) local pos = advtrains.path_get(train, index)
table.insert(lzb.oncoming, { local lzbdata_c = nil
if lzbdata then
-- make a shallow copy of lzbdata
lzbdata_c = {}
for k,v in pairs(lzbdata) do lzbdata_c[k] = v end
end
local ckp = {
pos = pos, pos = pos,
idx = index, index = index,
spd = speed, speed = speed,
fun = callback, callback = callback,
lzbdata = lzbdata_c,
udata = udata, udata = udata,
}) }
table.insert(lzb.checkpoints, ckp)
apply_checkpoint_to_path(train, ckp)
end end
advtrains.te_register_on_new_path(function(id, train) advtrains.te_register_on_new_path(function(id, train)
invalidate(train) advtrains.lzb_invalidate(train)
look_ahead(id, train) -- Taken care of in pre-move hook (see train_step_b)
--look_ahead(id, train)
end)
advtrains.te_register_on_invalidate_ahead(function(id, train, start_idx)
advtrains.lzb_invalidate_ahead(train, start_idx)
end) end)
advtrains.te_register_on_update(function(id, train) advtrains.te_register_on_update(function(id, train)
@ -186,6 +269,8 @@ advtrains.te_register_on_update(function(id, train)
atprint("LZB run: no path on train, skip step") atprint("LZB run: no path on train, skip step")
return return
end end
look_ahead(id, train) -- Note: look_ahead called from train_step_b before applying movement
apply_control(id, train) -- TODO: if more pre-move hooks are added, make a separate callback hook
--look_ahead(id, train)
call_runover_callbacks(id, train)
end, true) end, true)

View File

@ -246,7 +246,7 @@ function ndb.update(pos, pnode)
local resid = (nid * 4) + (l2b(node.param2 or 0)) local resid = (nid * 4) + (l2b(node.param2 or 0))
ndbset(pos.x, pos.y, pos.z, resid ) ndbset(pos.x, pos.y, pos.z, resid )
--atdebug("nodedb: updating node", pos, "stored nid",nid,"assigned",ndb_nodeids[nid],"resulting cid",resid) --atdebug("nodedb: updating node", pos, "stored nid",nid,"assigned",ndb_nodeids[nid],"resulting cid",resid)
minetest.after(0, advtrains.invalidate_all_paths, pos) advtrains.invalidate_all_paths_ahead(pos)
else else
--at this position there is no longer a node that needs to be tracked. --at this position there is no longer a node that needs to be tracked.
--atdebug("nodedb: updating node", pos, "cleared") --atdebug("nodedb: updating node", pos, "cleared")
@ -281,8 +281,9 @@ function advtrains.get_rail_info_at(pos, drives_on)
return true, conns, railheight return true, conns, railheight
end end
local IGNORE_WORLD = advtrains.IGNORE_WORLD
ndb.run_lbm = function(pos, node) ndb.run_lbm = function(pos, node)
return advtrains.pcall(function()
local cid=ndbget(pos.x, pos.y, pos.z) local cid=ndbget(pos.x, pos.y, pos.z)
if cid then if cid then
--if in database, detect changes and apply. --if in database, detect changes and apply.
@ -310,7 +311,6 @@ ndb.run_lbm = function(pos, node)
ndb.update(pos, node) ndb.update(pos, node)
end end
return false return false
end)
end end
@ -327,6 +327,7 @@ minetest.register_lbm({
--used when restoring stuff after a crash --used when restoring stuff after a crash
ndb.restore_all = function() ndb.restore_all = function()
--atlog("Updating the map from the nodedb, this may take a while") --atlog("Updating the map from the nodedb, this may take a while")
local t1 = os.clock()
local cnt=0 local cnt=0
local dcnt=0 local dcnt=0
for y, ny in pairs(ndb_nodes) do for y, ny in pairs(ndb_nodes) do
@ -337,7 +338,7 @@ ndb.restore_all = function()
if node then if node then
local ori_ndef=minetest.registered_nodes[node.name] local ori_ndef=minetest.registered_nodes[node.name]
local ndbnode=ndb.get_node_raw(pos) local ndbnode=ndb.get_node_raw(pos)
if ori_ndef and ori_ndef.groups.save_in_at_nodedb then --check if this node has been worldedited, and don't replace then if (ori_ndef and ori_ndef.groups.save_in_at_nodedb) or IGNORE_WORLD then --check if this node has been worldedited, and don't replace then
if (ndbnode.name~=node.name or ndbnode.param2~=node.param2) then if (ndbnode.name~=node.name or ndbnode.param2~=node.param2) then
minetest.swap_node(pos, ndbnode) minetest.swap_node(pos, ndbnode)
--atlog("Replaced",node.name,"@",pos,"with",ndbnode.name) --atlog("Replaced",node.name,"@",pos,"with",ndbnode.name)
@ -352,15 +353,13 @@ ndb.restore_all = function()
end end
end end
end end
local text="Restore node database: Replaced "..cnt.." nodes, removed "..dcnt.." ghost nodes." local text="Restore node database: Replaced "..cnt.." nodes, removed "..dcnt.." ghost nodes. (took "..math.floor((os.clock()-t1) * 1000).."ms)"
atlog(text) atlog(text)
return text return text
end end
minetest.register_on_dignode(function(pos, oldnode, digger) minetest.register_on_dignode(function(pos, oldnode, digger)
return advtrains.pcall(function()
ndb.clear(pos) ndb.clear(pos)
end)
end) end)
function ndb.get_nodes() function ndb.get_nodes()
@ -381,14 +380,12 @@ minetest.register_chatcommand("at_sync_ndb",
description = "Write node db back to map and find ghost nodes", -- Full description description = "Write node db back to map and find ghost nodes", -- Full description
privs = {train_operator=true}, privs = {train_operator=true},
func = function(name, param) func = function(name, param)
return advtrains.pcall(function() if os.time() < ptime+30 and not minetest.get_player_privs(name, "server") then
if os.time() < ptime+30 then
return false, "Please wait at least 30s from the previous execution of /at_restore_ndb!" return false, "Please wait at least 30s from the previous execution of /at_restore_ndb!"
end end
local text = ndb.restore_all() local text = ndb.restore_all()
ptime=os.time() ptime=os.time()
return true, text return true, text
end)
end, end,
}) })

View File

@ -196,7 +196,6 @@ function o.get_trains_over(ppos)
local r = {} local r = {}
local i = 1 local i = 1
while t[i] do while t[i] do
local train = advtrains.trains[t[i]]
local idx = t[i+1] local idx = t[i+1]
r[t[i]] = idx r[t[i]] = idx
i = i + 2 i = i + 2

View File

@ -19,6 +19,8 @@
-- When the day comes on that path!=node, these will only be set if this index represents a transition between rail nodes -- When the day comes on that path!=node, these will only be set if this index represents a transition between rail nodes
-- path_dist - The total distance of this path element from path element 0 -- path_dist - The total distance of this path element from path element 0
-- path_dir - The direction of this path item's transition to the next path item, which is the angle of conns[path_cn[i]].c -- path_dir - The direction of this path item's transition to the next path item, which is the angle of conns[path_cn[i]].c
-- path_speed- Populated by the LZB system. The maximum speed (velocity) permitted in the moment this path item is passed.
-- (this saves brake distance calculations every step to determine LZB control). nil means no limit.
--Variables: --Variables:
-- path_ext_f/b - how far path[i] is set -- path_ext_f/b - how far path[i] is set
-- path_trk_f/b - how far the path extends along a track. beyond those values, paths are generated in a straight line. -- path_trk_f/b - how far the path extends along a track. beyond those values, paths are generated in a straight line.
@ -52,6 +54,8 @@ function advtrains.path_create(train, pos, connid, rel_index)
[0] = advtrains.conn_angle_median(conns[mconnid].c, conns[connid].c) [0] = advtrains.conn_angle_median(conns[mconnid].c, conns[connid].c)
} }
train.path_speed = { }
train.path_ext_f=0 train.path_ext_f=0
train.path_ext_b=0 train.path_ext_b=0
train.path_trk_f=0 train.path_trk_f=0
@ -123,6 +127,7 @@ function advtrains.path_invalidate(train, ignore_lock)
train.path_cp = nil train.path_cp = nil
train.path_cn = nil train.path_cn = nil
train.path_dir = nil train.path_dir = nil
train.path_speed = nil
train.path_ext_f=0 train.path_ext_f=0
train.path_ext_b=0 train.path_ext_b=0
train.path_trk_f=0 train.path_trk_f=0
@ -131,6 +136,40 @@ function advtrains.path_invalidate(train, ignore_lock)
train.path_req_b=0 train.path_req_b=0
train.dirty = true train.dirty = true
--atdebug(train.id, "Path invalidated")
end
-- Keeps the path intact, but invalidates all path nodes from the specified index (inclusive)
-- onwards. This has the advantage that we don't need to recalculate the whole path, and we can do it synchronously.
function advtrains.path_invalidate_ahead(train, start_idx, ignore_when_passed)
if not train.path then
-- the path wasn't even initialized. Nothing to do
return
end
local idx = atfloor(start_idx)
--atdebug("Invalidate_ahead:",train.id,"start_index",start_idx,"cur_idx",train.index)
if(idx <= train.index - 0.5) then
if ignore_when_passed then
--atdebug("ignored passed")
return
end
advtrains.path_print(train, atwarn)
error("Train "+train.id+": Cannot path_invalidate_ahead start_idx="+idx+" as train has already passed!")
end
-- leave current node in path, it won't change. What might change is the path onward from here (e.g. switch)
local i = idx + 1
while train.path[i] do
advtrains.occ.clear_item(train.id, advtrains.round_vector_floor_y(train.path[i]))
i = i+1
end
train.path_ext_f=idx
train.path_trk_f=math.min(idx, train.path_trk_f)
-- callbacks called anyway for current node, because of LZB
advtrains.run_callbacks_invahead(train.id, train, idx)
end end
-- Prints a path using the passed print function -- Prints a path using the passed print function
@ -141,12 +180,12 @@ function advtrains.path_print(train, printf)
printf("path_print: Path is invalidated/inexistant.") printf("path_print: Path is invalidated/inexistant.")
return return
end end
printf("i: CP Position Dir CN Dist") printf("i: CP Position Dir CN Dist Speed")
for i = train.path_ext_b, train.path_ext_f do for i = train.path_ext_b, train.path_ext_f do
if i==train.path_trk_b then if i==train.path_trk_b then
printf("--Back on-track border here--") printf("--Back on-track border here--")
end end
printf(i,": ",train.path_cp[i]," ",train.path[i]," ",train.path_dir[i]," ",train.path_cn[i]," ",train.path_dist[i],"") printf(i,": ",train.path_cp[i]," ",train.path[i]," ",train.path_dir[i]," ",train.path_cn[i]," ",train.path_dist[i]," ",train.path_speed[i])
if i==train.path_trk_f then if i==train.path_trk_f then
printf("--Front on-track border here--") printf("--Front on-track border here--")
end end
@ -350,6 +389,7 @@ function advtrains.path_clear_unused(train)
train.path_ext_b = i + 1 train.path_ext_b = i + 1
end end
--[[ Why exactly are we clearing path from the front? This doesn't make sense!
for i = train.path_ext_f,train.path_req_f + PATH_CLEAR_KEEP,-1 do for i = train.path_ext_f,train.path_req_f + PATH_CLEAR_KEEP,-1 do
advtrains.occ.clear_item(train.id, advtrains.round_vector_floor_y(train.path[i])) advtrains.occ.clear_item(train.id, advtrains.round_vector_floor_y(train.path[i]))
train.path[i] = nil train.path[i] = nil
@ -358,14 +398,16 @@ function advtrains.path_clear_unused(train)
train.path_cn[i] = nil train.path_cn[i] = nil
train.path_dir[i+1] = nil train.path_dir[i+1] = nil
train.path_ext_f = i - 1 train.path_ext_f = i - 1
end end ]]
train.path_trk_b = math.max(train.path_trk_b, train.path_ext_b) train.path_trk_b = math.max(train.path_trk_b, train.path_ext_b)
train.path_trk_f = math.min(train.path_trk_f, train.path_ext_f) --train.path_trk_f = math.min(train.path_trk_f, train.path_ext_f)
train.path_req_f = math.ceil(train.index) train.path_req_f = math.ceil(train.index)
train.path_req_b = math.floor(train.end_index or train.index) train.path_req_b = math.floor(train.end_index or train.index)
end end
-- Scan the path of the train for position, without querying the occupation table
-- returns index, or nil if pos is not on the path
function advtrains.path_lookup(train, pos) function advtrains.path_lookup(train, pos)
local cp = advtrains.round_vector_floor_y(pos) local cp = advtrains.round_vector_floor_y(pos)
for i = train.path_ext_b, train.path_ext_f do for i = train.path_ext_b, train.path_ext_f do

View File

@ -45,3 +45,14 @@ advtrains_overrun_mode (Overrun mode) enum drop none,drop,normal
# When a wagon leaves this range + 32 nodes, it is unloaded # When a wagon leaves this range + 32 nodes, it is unloaded
# If unset, defaults to active_block_range*16 # If unset, defaults to active_block_range*16
advtrains_wagon_load_range (Wagon Entity Load/Unload Range) int 96 32 512 advtrains_wagon_load_range (Wagon Entity Load/Unload Range) int 96 32 512
# Simulation DTime Limit after which slow-down becomes effective
# When the dtime value (time since last server step) is higher than this value,
# advtrains applies a global slow-down factor to the dtime and to the velocity and
# acceleration of wagons to decrease server load.
# A value of 0 (default) disables this behavior.
advtrains_dtime_limit (DTime Limit for slow-down) float 0.2 0 5
# Time interval in seconds in which advtrains stores its save data to disk
# Nevertheless, advtrains saves all data when shutting down the server.
advtrains_save_interval (Save Interval) int 60 20 3600

View File

@ -12,22 +12,26 @@ end
local function aspect(b) local function aspect(b)
return { return {
main = { main = (not b) and 0, -- b ? false : 0
free = b, shunt = false,
speed = -1, proceed_as_main = true,
}, dst = false,
shunt = {
free = false,
proceed_as_main = true
},
dst = {
free = true,
speed = -1,
},
info = {} info = {}
} }
end end
local suppasp = {
main = {0, false},
dst = {false},
shunt = nil,
proceed_as_main = true,
info = {
call_on = false,
dead_end = false,
w_speed = nil,
}
}
for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", als="green"}}) do for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red", als="green"}}) do
advtrains.trackplacer.register_tracktype("advtrains:retrosignal", "") advtrains.trackplacer.register_tracktype("advtrains:retrosignal", "")
@ -63,6 +67,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
rules=advtrains.meseconrules, rules=advtrains.meseconrules,
["action_"..f.as] = function (pos, node) ["action_"..f.as] = function (pos, node)
advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true) advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true)
advtrains.interlocking.signal_on_aspect_changed(pos)
end end
}}, }},
on_rightclick=function(pos, node, player) on_rightclick=function(pos, node, player)
@ -74,12 +79,13 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
advtrains.interlocking.show_ip_form(pos, pname) advtrains.interlocking.show_ip_form(pos, pname)
elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true) advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_"..f.as..rotation, param2 = node.param2}, true)
advtrains.interlocking.signal_on_aspect_changed(pos)
end end
end, end,
-- new signal API -- new signal API
advtrains = { advtrains = {
set_aspect = function(pos, node, asp) set_aspect = function(pos, node, asp)
if asp.main.free then if asp.main ~= 0 then
advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_on"..rotation, param2 = node.param2}, true) advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_on"..rotation, param2 = node.param2}, true)
else else
advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_off"..rotation, param2 = node.param2}, true) advtrains.ndb.swap_node(pos, {name = "advtrains:retrosignal_off"..rotation, param2 = node.param2}, true)
@ -87,7 +93,8 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
end, end,
get_aspect = function(pos, node) get_aspect = function(pos, node)
return aspect(r=="on") return aspect(r=="on")
end end,
supported_aspects = suppasp,
}, },
can_dig = can_dig_func, can_dig = can_dig_func,
}) })
@ -120,6 +127,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
rules=advtrains.meseconrules, rules=advtrains.meseconrules,
["action_"..f.as] = function (pos, node) ["action_"..f.as] = function (pos, node)
advtrains.setstate(pos, f.als, node) advtrains.setstate(pos, f.als, node)
advtrains.interlocking.signal_on_aspect_changed(pos)
end end
}}, }},
on_rightclick=function(pos, node, player) on_rightclick=function(pos, node, player)
@ -131,12 +139,13 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
advtrains.interlocking.show_ip_form(pos, pname) advtrains.interlocking.show_ip_form(pos, pname)
elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then elseif advtrains.check_turnout_signal_protection(pos, player:get_player_name()) then
advtrains.setstate(pos, f.als, node) advtrains.setstate(pos, f.als, node)
advtrains.interlocking.signal_on_aspect_changed(pos)
end end
end, end,
-- new signal API -- new signal API
advtrains = { advtrains = {
set_aspect = function(pos, node, asp) set_aspect = function(pos, node, asp)
if asp.main.free then if asp.main ~= 0 then
advtrains.ndb.swap_node(pos, {name = "advtrains:signal_on"..rotation, param2 = node.param2}, true) advtrains.ndb.swap_node(pos, {name = "advtrains:signal_on"..rotation, param2 = node.param2}, true)
else else
advtrains.ndb.swap_node(pos, {name = "advtrains:signal_off"..rotation, param2 = node.param2}, true) advtrains.ndb.swap_node(pos, {name = "advtrains:signal_off"..rotation, param2 = node.param2}, true)
@ -145,6 +154,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
get_aspect = function(pos, node) get_aspect = function(pos, node)
return aspect(r=="on") return aspect(r=="on")
end, end,
supported_aspects = suppasp,
getstate = f.ls, getstate = f.ls,
setstate = function(pos, node, newstate) setstate = function(pos, node, newstate)
if newstate == f.als then if newstate == f.als then
@ -204,7 +214,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
-- new signal API -- new signal API
advtrains = { advtrains = {
set_aspect = function(pos, node, asp) set_aspect = function(pos, node, asp)
if asp.main.free then if asp.main ~= 0 then
advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_on", param2 = node.param2}, true) advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_on", param2 = node.param2}, true)
else else
advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_off", param2 = node.param2}, true) advtrains.ndb.swap_node(pos, {name = "advtrains:signal_wall_"..loc.."_off", param2 = node.param2}, true)
@ -213,6 +223,7 @@ for r,f in pairs({on={as="off", ls="green", als="red"}, off={as="on", ls="red",
get_aspect = function(pos, node) get_aspect = function(pos, node)
return aspect(r=="on") return aspect(r=="on")
end, end,
supported_aspects = suppasp,
getstate = f.ls, getstate = f.ls,
setstate = function(pos, node, newstate) setstate = function(pos, node, newstate)
if newstate == f.als then if newstate == f.als then

View File

@ -275,8 +275,7 @@ function tp.register_track_placer(nnprefix, imgprefix, dispname, def)
groups={advtrains_trackplacer=1, digtron_on_place=1}, groups={advtrains_trackplacer=1, digtron_on_place=1},
liquids_pointable = def.liquids_pointable, liquids_pointable = def.liquids_pointable,
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
return advtrains.pcall(function() local name = placer:get_player_name()
local name = placer:get_player_name()
if not name then if not name then
return itemstack, false return itemstack, false
end end
@ -303,7 +302,6 @@ function tp.register_track_placer(nnprefix, imgprefix, dispname, def)
end end
end end
return itemstack, true return itemstack, true
end)
end, end,
}) })
end end
@ -317,7 +315,6 @@ minetest.register_craftitem("advtrains:trackworker",{
wield_image = "advtrains_trackworker.png", wield_image = "advtrains_trackworker.png",
stack_max = 1, stack_max = 1,
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
return advtrains.pcall(function()
local name = placer:get_player_name() local name = placer:get_player_name()
if not name then if not name then
return return
@ -382,10 +379,8 @@ minetest.register_craftitem("advtrains:trackworker",{
advtrains.ndb.swap_node(pos, {name=nnprefix.."_"..suffix..modext[modpos+1], param2=node.param2}) advtrains.ndb.swap_node(pos, {name=nnprefix.."_"..suffix..modext[modpos+1], param2=node.param2})
end end
end end
end)
end, end,
on_use=function(itemstack, user, pointed_thing) on_use=function(itemstack, user, pointed_thing)
return advtrains.pcall(function()
local name = user:get_player_name() local name = user:get_player_name()
if not name then if not name then
return return
@ -430,7 +425,6 @@ minetest.register_craftitem("advtrains:trackworker",{
else else
atprint(name, dump(tp.tracks)) atprint(name, dump(tp.tracks))
end end
end)
end, end,
}) })

View File

@ -469,7 +469,7 @@ function advtrains.register_tracks(tracktype, def, preset)
tiles = {def.shared_texture or (def.texture_prefix.."_"..img_suffix..".png"), def.second_texture}, tiles = {def.shared_texture or (def.texture_prefix.."_"..img_suffix..".png"), def.second_texture},
groups = { groups = {
attached_node=1, attached_node = advtrains.IGNORE_WORLD and 0 or 1,
advtrains_track=1, advtrains_track=1,
["advtrains_track_"..tracktype]=1, ["advtrains_track_"..tracktype]=1,
save_in_at_nodedb=1, save_in_at_nodedb=1,

View File

@ -43,7 +43,7 @@ function advtrains.on_control_change(pc, train, flip)
else else
local act=false local act=false
if pc.jump then if pc.jump then
train.ctrl.user = 1 train.ctrl_user = 1
act=true act=true
end end
-- If atc command set, only "Jump" key can clear command. To prevent accidental control. -- If atc command set, only "Jump" key can clear command. To prevent accidental control.
@ -51,15 +51,15 @@ function advtrains.on_control_change(pc, train, flip)
return return
end end
if pc.up then if pc.up then
train.ctrl.user=4 train.ctrl_user=4
act=true act=true
end end
if pc.down then if pc.down then
if train.velocity>0 then if train.velocity>0 then
if pc.jump then if pc.jump then
train.ctrl.user = 0 train.ctrl_user = 0
else else
train.ctrl.user = 2 train.ctrl_user = 2
end end
act=true act=true
else else
@ -82,7 +82,7 @@ function advtrains.on_control_change(pc, train, flip)
end end
end end
if not act then if not act then
train.ctrl.user = nil train.ctrl_user = nil
end end
end end
end end
@ -186,6 +186,9 @@ function advtrains.hud_train_format(train, flip)
local tlev=train.lever or 1 local tlev=train.lever or 1
if train.velocity==0 and not train.active_control then tlev=1 end if train.velocity==0 and not train.active_control then tlev=1 end
if train.hud_lzb_effect_tmr then
tlev=1
end
local ht = {"[combine:440x110:0,0=(advtrains_hud_bg.png^[resize\\:440x110)"} local ht = {"[combine:440x110:0,0=(advtrains_hud_bg.png^[resize\\:440x110)"}
local st = {} local st = {}
@ -245,7 +248,7 @@ function advtrains.hud_train_format(train, flip)
if train.tarvelocity or train.atc_command then if train.tarvelocity or train.atc_command then
ht[#ht+1] = "10,10=(advtrains_hud_atc.png^[resize\\:30x30^[multiply\\:cyan)" ht[#ht+1] = "10,10=(advtrains_hud_atc.png^[resize\\:30x30^[multiply\\:cyan)"
end end
if train.ctrl.lzb then if train.hud_lzb_effect_tmr then
ht[#ht+1] = "50,10=(advtrains_hud_lzb.png^[resize\\:30x30^[multiply\\:red)" ht[#ht+1] = "50,10=(advtrains_hud_lzb.png^[resize\\:30x30^[multiply\\:red)"
end end
if train.is_shunt then if train.is_shunt then
@ -274,10 +277,10 @@ function advtrains.hud_train_format(train, flip)
ht[#ht+1] = sformat("%d,85=(advtrains_hud_arrow.png^[multiply\\:cyan^[transformFY^[makealpha\\:#000000)", 1+train.tarvelocity*11) ht[#ht+1] = sformat("%d,85=(advtrains_hud_arrow.png^[multiply\\:cyan^[transformFY^[makealpha\\:#000000)", 1+train.tarvelocity*11)
end end
local lzb = train.lzb local lzb = train.lzb
if lzb and lzb.oncoming then if lzb and lzb.checkpoints then
local oc = lzb.oncoming local oc = lzb.checkpoints
for i = 1, #oc do for i = 1, #oc do
local spd = oc[i].spd local spd = oc[i].speed
local c = not spd and "lime" or (type(spd) == "number" and (spd == 0) and "red" or "orange") or nil local c = not spd and "lime" or (type(spd) == "number" and (spd == 0) and "red" or "orange") or nil
if c then if c then
ht[#ht+1] = sformat("130,10=(advtrains_hud_bg.png^[resize\\:30x5^[colorize\\:%s)",c) ht[#ht+1] = sformat("130,10=(advtrains_hud_bg.png^[resize\\:30x5^[colorize\\:%s)",c)
@ -286,7 +289,7 @@ function advtrains.hud_train_format(train, flip)
ht[#ht+1] = sformat("%d,50=(advtrains_hud_arrow.png^[multiply\\:red^[makealpha\\:#000000)", 1+spd*11) ht[#ht+1] = sformat("%d,50=(advtrains_hud_arrow.png^[multiply\\:red^[makealpha\\:#000000)", 1+spd*11)
end end
local floor = math.floor local floor = math.floor
local dist = floor(((oc[i].idx or train.index)-train.index)) local dist = floor(((oc[i].index or train.index)-train.index))
dist = math.max(0, math.min(999, dist)) dist = math.max(0, math.min(999, dist))
for j = 1, 3, 1 do for j = 1, 3, 1 do
sevenseg(floor((dist/10^(3-j))%10), 119+j*11, 18, 4, 2, "[colorize\\:"..c) sevenseg(floor((dist/10^(3-j))%10), 119+j*11, 18, 4, 2, "[colorize\\:"..c)
@ -326,4 +329,4 @@ minetest.register_craft {
{"default:paper", "advtrains:trackworker", "default:paper"}, {"default:paper", "advtrains:trackworker", "default:paper"},
{"default:paper", "default:paper", "default:paper"}, {"default:paper", "default:paper", "default:paper"},
} }
} }

View File

@ -36,6 +36,7 @@ end
local t_accel_all={ local t_accel_all={
[0] = -10, [0] = -10,
[1] = -3, [1] = -3,
[11] = -2, -- calculation base for LZB
[2] = -0.5, [2] = -0.5,
[4] = 0.5, [4] = 0.5,
} }
@ -43,19 +44,35 @@ local t_accel_all={
local t_accel_eng={ local t_accel_eng={
[0] = 0, [0] = 0,
[1] = 0, [1] = 0,
[11] = 0,
[2] = 0, [2] = 0,
[4] = 1.5, [4] = 1.5,
} }
local VLEVER_EMERG = 0
local VLEVER_BRAKE = 1
local VLEVER_LZBCALC = 11
local VLEVER_ROLL = 2
local VLEVER_HOLD = 3
local VLEVER_ACCEL = 4
-- How far in front of a whole index with LZB 0 restriction the train should come to a halt
-- value must be between 0 and 0.5, exclusively
local LZB_ZERO_APPROACH_DIST = 0.1
-- Speed the train temporarily approaches the stop point with
local LZB_ZERO_APPROACH_SPEED = 0.2
tp_player_tmr = 0 tp_player_tmr = 0
advtrains.mainloop_trainlogic=function(dtime) advtrains.mainloop_trainlogic=function(dtime, stepno)
--build a table of all players indexed by pts. used by damage and door system. --build a table of all players indexed by pts. used by damage and door system.
advtrains.playersbypts={} advtrains.playersbypts={}
for _, player in pairs(minetest.get_connected_players()) do for _, player in pairs(minetest.get_connected_players()) do
if not advtrains.player_to_train_mapping[player:get_player_name()] then if not advtrains.player_to_train_mapping[player:get_player_name()] then
--players in train are not subject to damage --players in train are not subject to damage
local ptspos=minetest.pos_to_string(vector.round(player:getpos())) local ptspos=minetest.pos_to_string(vector.round(player:get_pos()))
advtrains.playersbypts[ptspos]=player advtrains.playersbypts[ptspos]=player
end end
end end
@ -81,6 +98,7 @@ advtrains.mainloop_trainlogic=function(dtime)
for k,v in pairs(advtrains.trains) do for k,v in pairs(advtrains.trains) do
advtrains.atprint_context_tid=k advtrains.atprint_context_tid=k
--atprint("=== Step",stepno,"===")
advtrains.train_ensure_init(k, v) advtrains.train_ensure_init(k, v)
end end
@ -113,11 +131,10 @@ function advtrains.tp_player_to_train(player)
--set the player to the train position. --set the player to the train position.
--minetest will emerge the area and load the objects, which then will call reattach_all(). --minetest will emerge the area and load the objects, which then will call reattach_all().
--because player is in mapping, it will not be subject to dying. --because player is in mapping, it will not be subject to dying.
player:setpos(train.last_pos) player:set_pos(train.last_pos)
end end
end end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
return advtrains.pcall(function()
advtrains.hud[player:get_player_name()] = nil advtrains.hud[player:get_player_name()] = nil
advtrains.hhud[player:get_player_name()] = nil advtrains.hhud[player:get_player_name()] = nil
--independent of this, cause all wagons of the train which are loaded to reattach their players --independent of this, cause all wagons of the train which are loaded to reattach their players
@ -127,12 +144,10 @@ minetest.register_on_joinplayer(function(player)
wagon:reattach_all() wagon:reattach_all()
end end
end end
end)
end) end)
minetest.register_on_dieplayer(function(player) minetest.register_on_dieplayer(function(player)
return advtrains.pcall(function()
local pname=player:get_player_name() local pname=player:get_player_name()
local id=advtrains.player_to_train_mapping[pname] local id=advtrains.player_to_train_mapping[pname]
if id then if id then
@ -146,7 +161,6 @@ minetest.register_on_dieplayer(function(player)
end end
end end
end end
end)
end) end)
--[[ --[[
@ -190,6 +204,8 @@ end
function advtrains.get_acceleration(train, lever) function advtrains.get_acceleration(train, lever)
local acc_all = t_accel_all[lever] local acc_all = t_accel_all[lever]
if not acc_all then return 0 end
local acc_eng = t_accel_eng[lever] local acc_eng = t_accel_eng[lever]
local nwagons = #train.trainparts local nwagons = #train.trainparts
if nwagons == 0 then if nwagons == 0 then
@ -215,14 +231,16 @@ local function mkcallback(name)
assertt(func, "function") assertt(func, "function")
table.insert(callt, func) table.insert(callt, func)
end end
return callt, function(id, train) return callt, function(id, train, param1, param2, param3)
for _,f in ipairs(callt) do for _,f in ipairs(callt) do
f(id, train) f(id, train, param1, param2, param3)
end end
end end
end end
local callbacks_new_path, run_callbacks_new_path = mkcallback("new_path") local callbacks_new_path, run_callbacks_new_path = mkcallback("new_path")
local callbacks_invahead
callbacks_invahead, advtrains.run_callbacks_invahead = mkcallback("invalidate_ahead") -- (id, train, start_idx)
local callbacks_update, run_callbacks_update = mkcallback("update") local callbacks_update, run_callbacks_update = mkcallback("update")
local callbacks_create, run_callbacks_create = mkcallback("create") local callbacks_create, run_callbacks_create = mkcallback("create")
local callbacks_remove, run_callbacks_remove = mkcallback("remove") local callbacks_remove, run_callbacks_remove = mkcallback("remove")
@ -240,21 +258,25 @@ function advtrains.train_ensure_init(id, train)
end end
train.dirty = true train.dirty = true
if train.no_step then return nil end if train.no_step then
--atprint("in ensure_init: no_step set, train step ignored!")
return nil
end
assertdef(train, "velocity", 0) assertdef(train, "velocity", 0)
--assertdef(train, "tarvelocity", 0) --assertdef(train, "tarvelocity", 0)
assertdef(train, "acceleration", 0) assertdef(train, "acceleration", 0)
assertdef(train, "id", id) assertdef(train, "id", id)
assertdef(train, "ctrl", {})
if not train.drives_on or not train.max_speed then if not train.drives_on or not train.max_speed then
--atprint("in ensure_init: missing properties, updating!")
advtrains.update_trainpart_properties(id) advtrains.update_trainpart_properties(id)
end end
--restore path --restore path
if not train.path then if not train.path then
--atprint("in ensure_init: Needs restoring path...")
if not train.last_pos then if not train.last_pos then
atlog("Train",id,": Restoring path failed, no last_pos set! Train will be disabled. You can try to fix the issue in the save file.") atlog("Train",id,": Restoring path failed, no last_pos set! Train will be disabled. You can try to fix the issue in the save file.")
train.no_step = true train.no_step = true
@ -277,6 +299,8 @@ function advtrains.train_ensure_init(id, train)
local result = advtrains.path_create(train, train.last_pos, train.last_connid or 1, train.last_frac or 0) local result = advtrains.path_create(train, train.last_pos, train.last_connid or 1, train.last_frac or 0)
--atprint("in ensure_init: path_create result ",result)
if result==false then if result==false then
atlog("Train",id,": Restoring path failed, node at",train.last_pos,"is gone! Train will be disabled. You can try to place a rail at this position and restart the server.") atlog("Train",id,": Restoring path failed, node at",train.last_pos,"is gone! Train will be disabled. You can try to place a rail at this position and restart the server.")
train.no_step = true train.no_step = true
@ -304,6 +328,10 @@ function advtrains.train_ensure_init(id, train)
return true return true
end end
local function v_target_apply(v_targets, lever, vel)
v_targets[lever] = v_targets[lever] and math.min(v_targets[lever], vel) or vel
end
function advtrains.train_step_b(id, train, dtime) function advtrains.train_step_b(id, train, dtime)
if train.no_step or train.wait_for_path or not train.path then return end if train.no_step or train.wait_for_path or not train.path then return end
@ -311,25 +339,49 @@ function advtrains.train_step_b(id, train, dtime)
advtrains.path_get(train, atfloor(train.index + 2)) advtrains.path_get(train, atfloor(train.index + 2))
advtrains.path_get(train, atfloor(train.end_index - 1)) advtrains.path_get(train, atfloor(train.end_index - 1))
-- run pre-move hooks
-- TODO: if more pre-move hooks are added, make a separate callback hook
advtrains.lzb_look_ahead(id, train)
--[[ again, new velocity control:
There are two heterogenous means of control:
-> set a fixed acceleration and ignore speed (user)
-> steer towards a target speed, distance doesn't matter
-> needs to specify the maximum acceleration/deceleration values they are willing to accelerate/brake with
-> Reach a target speed after a certain distance (LZB, handled specially)
]]--
--- 3. handle velocity influences --- --- 3. handle velocity influences ---
local train_moves=(train.velocity~=0)
local tarvel_cap = train.speed_restriction local v0 = train.velocity
local sit_v_cap = train.max_speed -- Maximum speed in current situation (multiple limit factors)
-- The desired speed change issued by the active control (user or atc)
local ctrl_v_tar -- desired speed which should not be crossed by braking or accelerating
local ctrl_accelerating = false -- whether the train should accelerate
local ctrl_braking = false -- whether the train should brake
local ctrl_lever -- the lever value to use to calculate the acceleration
-- the final speed change after applying LZB
local v_cap -- absolute maximum speed
local v_tar -- desired speed which should not be crossed by braking or accelerating
local accelerating = false-- whether the train should accelerate
local braking = false -- whether the train should brake
local lever -- the lever value to use to calculate the acceleration
local train_moves = (v0 > 0)
if train.recently_collided_with_env then if train.recently_collided_with_env then
tarvel_cap=0
if not train_moves then if not train_moves then
train.recently_collided_with_env=nil--reset status when stopped train.recently_collided_with_env=nil--reset status when stopped
end end
end --atprint("in train_step_b: applying collided_with_env")
if train.locomotives_in_train==0 then sit_v_cap = 0
tarvel_cap=0 elseif train.locomotives_in_train==0 then
end --atprint("in train_step_b: applying no_locomotives")
sit_v_cap = 0
--- 3a. this can be useful for debugs/warnings and is used for check_trainpartload --- -- interlocking speed restriction
local t_info, train_pos=sid(id), advtrains.path_get(train, atfloor(train.index)) elseif train.speed_restriction then
if train_pos then --atprint("in train_step_b: applying interlocking speed restriction",train.speed_restriction)
t_info=t_info.." @"..minetest.pos_to_string(train_pos) sit_v_cap = train.speed_restriction
--atprint("train_pos:",train_pos)
end end
--apply off-track handling: --apply off-track handling:
@ -337,38 +389,47 @@ function advtrains.train_step_b(id, train, dtime)
local back_off_track=train.end_index<train.path_trk_b local back_off_track=train.end_index<train.path_trk_b
train.off_track = front_off_track or back_off_track train.off_track = front_off_track or back_off_track
if front_off_track then if back_off_track and (not v_cap or v_cap > 1) then
tarvel_cap=0 --atprint("in train_step_b: applying back_off_track")
end sit_v_cap = 1
if back_off_track then -- eventually overrides front_off_track restriction elseif front_off_track then
tarvel_cap=1 --atprint("in train_step_b: applying front_off_track")
sit_v_cap = 0
end end
-- Driving control rework:
--[[
Items are only defined when something is controlling them.
In order of precedence.
train.ctrl = {
lzb = restrictive override from LZB
user = User input from driverstand
atc = ATC command override (determined here)
}
The code here determines the precedence and writes the final control into train.lever
]]
--interpret ATC command and apply auto-lever control when not actively controlled --interpret ATC command and apply auto-lever control when not actively controlled
local trainvelocity = train.velocity local userc = train.ctrl_user
if userc then
if train.ctrl.user then --atprint("in train_step_b: ctrl_user active",userc)
advtrains.atc.train_reset_command(train) advtrains.atc.train_reset_command(train)
if userc >= VLEVER_ACCEL then
ctrl_accelerating = true
else
ctrl_braking = true
end
ctrl_lever = userc
else else
if train.atc_command then
if (not train.atc_delay or train.atc_delay<=0) and not train.atc_wait_finish then
advtrains.atc.execute_atc_command(id, train)
else
train.atc_delay=train.atc_delay-dtime
end
elseif train.atc_delay then
train.atc_delay = nil
end
local braketar = train.atc_brake_target local braketar = train.atc_brake_target
local emerg = false -- atc_brake_target==-1 means emergency brake (BB command) local emerg = false -- atc_brake_target==-1 means emergency brake (BB command)
if braketar == -1 then if braketar == -1 then
braketar = 0 braketar = 0
emerg = true emerg = true
end end
if braketar and braketar>=trainvelocity then --atprint("in train_step_b: ATC: brake state braketar=",braketar,"emerg=",emerg)
if braketar and braketar>=v0 then
--atprint("in train_step_b: ATC: brake target cleared")
train.atc_brake_target=nil train.atc_brake_target=nil
braketar = nil braketar = nil
end end
@ -380,111 +441,175 @@ function advtrains.train_step_b(id, train, dtime)
train.atc_wait_finish=nil train.atc_wait_finish=nil
end end
end end
if train.atc_command then
if (not train.atc_delay or train.atc_delay<=0) and not train.atc_wait_finish then
advtrains.atc.execute_atc_command(id, train)
else
train.atc_delay=train.atc_delay-dtime
end
elseif train.atc_delay then
train.atc_delay = nil
end
train.ctrl.atc = nil if train.tarvelocity and train.tarvelocity>v0 then
if train.tarvelocity and train.tarvelocity>trainvelocity then --atprint("in train_step_b: applying ATC ACCEL", train.tarvelocity)
train.ctrl.atc=4 ctrl_accelerating = true
end ctrl_lever = VLEVER_ACCEL
if train.tarvelocity and train.tarvelocity<trainvelocity then elseif train.tarvelocity and train.tarvelocity<v0 then
if (braketar and braketar<trainvelocity) then ctrl_braking = true
if (braketar and braketar<v0) then
if emerg then if emerg then
train.ctrl.atc = 0 --atprint("in train_step_b: applying ATC EMERG", train.tarvelocity)
ctrl_lever = VLEVER_EMERG
else else
train.ctrl.atc=1 --atprint("in train_step_b: applying ATC BRAKE", train.tarvelocity)
ctrl_v_tar = braketar
ctrl_lever = VLEVER_BRAKE
end end
else else
train.ctrl.atc=2 --atprint("in train_step_b: applying ATC ROLL", train.tarvelocity)
ctrl_v_tar = train.tarvelocity
ctrl_lever = VLEVER_ROLL
end end
end end
end end
--if tarvel_cap and train.tarvelocity and tarvel_cap<train.tarvelocity then --- 2b. look at v_target, determine the effective v_target and desired acceleration ---
-- train.tarvelocity=tarvel_cap --atprint("in train_step_b: Resulting control before LZB: accelerating",ctrl_accelerating,"braking",ctrl_braking,"lever", ctrl_lever, "target", ctrl_v_tar)
--end --train.debug = dump({tv_target,tv_lever})
local tmp_lever --atprint("in train_step_b: Current index",train.index,"end",train.end_index,"vel",v0)
--- 3a. calculate the acceleration required to reach the speed restriction in path_speed (LZB) ---
-- Iterates over the path nodes we WOULD pass if we were continuing with the current speed
-- and determines the MINIMUM of path_speed in this range.
-- Then, determines acceleration so that we can reach this 'overridden' target speed in this step (but short-circuited)
local lzb_next_zero_barrier -- if defined, train should not pass this point as it's a 0-LZB
local new_index_curr_tv -- pre-calculated new train index in lzb check
local lzb_v_cap -- the maximum speed that LZB dictates
for _, lev in pairs(train.ctrl) do local dst_curr_v = v0 * dtime
-- use the most restrictive of all control overrides new_index_curr_tv = advtrains.path_get_index_by_offset(train, train.index, dst_curr_v)
tmp_lever = math.min(tmp_lever or 4, lev) local i = atfloor(train.index)
end local psp
while true do
if not tmp_lever then psp = train.path_speed[i]
-- if there was no control at all, default to 3 if psp then
tmp_lever = 3 lzb_v_cap = lzb_v_cap and math.min(lzb_v_cap, psp) or psp
end if psp == 0 and not lzb_next_zero_barrier then
--atprint("in train_step_b: Found zero barrier: ",i)
if tarvel_cap and trainvelocity>tarvel_cap then lzb_next_zero_barrier = i - LZB_ZERO_APPROACH_DIST
tmp_lever = 0
end
train.lever = tmp_lever
--- 3a. actually calculate new velocity ---
if tmp_lever~=3 then
local accel = advtrains.get_acceleration(train, tmp_lever)
local vdiff = accel*dtime
-- This should only be executed when we are accelerating
-- I suspect that this causes the braking bugs
if tmp_lever == 4 then
-- ATC control exception: don't cross tarvelocity if
-- atc provided a target_vel
if train.tarvelocity then
local tvdiff = train.tarvelocity - trainvelocity
if tvdiff~=0 and math.abs(vdiff) > math.abs(tvdiff) then
--applying this change would cross tarvelocity
--atdebug("In Tvdiff condition, clipping",vdiff,"to",tvdiff)
--atdebug("vel=",trainvelocity,"tvel=",train.tarvelocity)
vdiff=tvdiff
end
end
if tarvel_cap and trainvelocity<=tarvel_cap and trainvelocity+vdiff>tarvel_cap then
vdiff = tarvel_cap - train.velocity
end
local mspeed = (train.max_speed or 10)
if trainvelocity+vdiff > mspeed then
vdiff = mspeed - trainvelocity
end end
end end
if i > new_index_curr_tv then
if trainvelocity+vdiff < 0 then break
vdiff = - trainvelocity
end end
i = i + 1
end
train.acceleration=vdiff
train.velocity=train.velocity+vdiff if lzb_next_zero_barrier and train.index < lzb_next_zero_barrier then
--if train.ctrl.user then lzb_v_cap = LZB_ZERO_APPROACH_SPEED
-- train.tarvelocity = train.velocity end
--end
else --atprint("in train_step_b: LZB calculation yields newindex=",new_index_curr_tv,"lzbtarget=",lzb_v_cap,"zero_barr=",lzb_next_zero_barrier,"")
-- LZB HUD: decrement timer and delete when 0
if train.hud_lzb_effect_tmr then
if train.hud_lzb_effect_tmr <=0 then
train.hud_lzb_effect_tmr = nil
else
train.hud_lzb_effect_tmr = train.hud_lzb_effect_tmr - 1
end
end
-- We now need to bring ctrl_*, sit_v_cap and lzb_v_cap together to determine the final controls.
local v_cap = sit_v_cap -- always defined, by default train.max_speed
if lzb_v_cap and lzb_v_cap < v_cap then
v_cap = lzb_v_cap
lever = VLEVER_BRAKE -- actually irrelevant, acceleration is not considered anyway unless v_tar is also set.
-- display LZB control override in the HUD
if lzb_v_cap <= v0 then
train.hud_lzb_effect_tmr = 1
-- This is to signal the HUD that LZB is active. This works as a timer to avoid HUD blinking
end
end
v_tar = ctrl_v_tar
-- if v_cap is smaller than the current speed, we need to brake in all cases.
if v_cap < v0 then
braking = true
lever = VLEVER_BRAKE
-- set v_tar to v_cap to not slow down any further than required.
-- unless control wants us to brake too, then we use control's v_tar.
if not ctrl_v_tar or ctrl_v_tar > v_cap then
v_tar = v_cap
end
else -- else, use what the ctrl says
braking = ctrl_braking
accelerating = ctrl_accelerating and not braking
lever = ctrl_lever
end
train.lever = lever
--atprint("in train_step_b: final control: accelerating",accelerating,"braking",braking,"lever", lever, "target", v_tar)
-- reset train acceleration when holding speed
if not braking and not accelerating then
train.acceleration = 0 train.acceleration = 0
end end
--- 3b. if braking, modify the velocity BEFORE the movement
if braking then
local dv = advtrains.get_acceleration(train, lever) * dtime
local v1 = v0 + dv
if v_tar and v1 < v_tar then
--atprint("in train_step_b: Braking: Hit v_tar!")
v1 = v_tar
end
if v1 > v_cap then
--atprint("in train_step_b: Braking: Hit v_cap!")
v1 = v_cap
end
if v1 < 0 then
--atprint("in train_step_b: Braking: Hit 0!")
v1 = 0
end
train.acceleration = (v1 - v0) / dtime
train.velocity = v1
--atprint("in train_step_b: Braking: New velocity",v1," (yields acceleration",train.acceleration,")")
-- make saved new_index_curr_tv invalid because speed has changed
new_index_curr_tv = nil
end
--- 4. move train --- --- 4. move train ---
-- if we have calculated the new end index before, don't do that again
if not new_index_curr_tv then
local dst_curr_v = train.velocity * dtime
new_index_curr_tv = advtrains.path_get_index_by_offset(train, train.index, dst_curr_v)
--atprint("in train_step_b: movement calculation (re)done, yields newindex=",new_index_curr_tv)
else
--atprint("in train_step_b: movement calculation reusing from LZB newindex=",new_index_curr_tv)
end
local idx_floor = math.floor(train.index) -- if the zeroappr mechanism has hit, go no further than zeroappr index
local pdist = (train.path_dist[idx_floor+1] - train.path_dist[idx_floor]) if lzb_next_zero_barrier and new_index_curr_tv > lzb_next_zero_barrier then
local distance = (train.velocity*dtime) / pdist --atprint("in train_step_b: Zero barrier hit, clipping to newidx_tv=",new_index_curr_tv, "zb_idx=",lzb_next_zero_barrier)
new_index_curr_tv = lzb_next_zero_barrier
--debugging code end
--train.debug = atdump(train.ctrl).."step_dist: "..math.floor(distance*1000) train.index = new_index_curr_tv
train.index=train.index+distance
recalc_end_index(train) recalc_end_index(train)
--atprint("in train_step_b: New index",train.index,"end",train.end_index,"vel",train.velocity)
--- 4a. if accelerating, modify the velocity AFTER the movement
if accelerating then
local dv = advtrains.get_acceleration(train, lever) * dtime
local v1 = v0 + dv
if v_tar and v1 > v_tar then
--atprint("in train_step_b: Accelerating: Hit v_tar!")
v1 = v_tar
end
if v1 > v_cap then
--atprint("in train_step_b: Accelerating: Hit v_cap!")
v1 = v_cap
end
train.acceleration = (v1 - v0) / dtime
train.velocity = v1
--atprint("in train_step_b: Accelerating: New velocity",v1," (yields acceleration",train.acceleration,")")
end
end end
function advtrains.train_step_c(id, train, dtime) function advtrains.train_step_c(id, train, dtime)
@ -609,8 +734,9 @@ local callbacks_enter_node, run_callbacks_enter_node = mknodecallback("enter")
local callbacks_leave_node, run_callbacks_leave_node = mknodecallback("leave") local callbacks_leave_node, run_callbacks_leave_node = mknodecallback("leave")
-- Node callback for approaching -- Node callback for approaching
-- Might be called multiple times, whenever path is recalculated -- Might be called multiple times, whenever path is recalculated. Also called for the first node the train is standing on, then has_entered is true.
-- signature is function(pos, id, train, index, lzbdata) -- signature is function(pos, id, train, index, has_entered, lzbdata)
-- has_entered: true if the "enter" callback has already been executed for this train in this location
-- lzbdata: arbitrary data (shared between all callbacks), deleted when LZB is restarted. -- lzbdata: arbitrary data (shared between all callbacks), deleted when LZB is restarted.
-- These callbacks are called in order of distance as train progresses along tracks, so lzbdata can be used to -- These callbacks are called in order of distance as train progresses along tracks, so lzbdata can be used to
-- keep track of a train's state once it passes this point -- keep track of a train's state once it passes this point
@ -666,16 +792,19 @@ end
function advtrains.tnc_call_approach_callback(pos, train_id, train, index, lzbdata) function advtrains.tnc_call_approach_callback(pos, train_id, train, index, lzbdata)
--atdebug("tnc approach",pos,train_id, lzbdata) --atdebug("tnc approach",pos,train_id, lzbdata)
local has_entered = atround(train.index) == index
local node = advtrains.ndb.get_node(pos) --this spares the check if node is nil, it has a name in any case local node = advtrains.ndb.get_node(pos) --this spares the check if node is nil, it has a name in any case
local mregnode=minetest.registered_nodes[node.name] local mregnode=minetest.registered_nodes[node.name]
if mregnode and mregnode.advtrains and mregnode.advtrains.on_train_approach then if mregnode and mregnode.advtrains and mregnode.advtrains.on_train_approach then
mregnode.advtrains.on_train_approach(pos, train_id, train, index, lzbdata) mregnode.advtrains.on_train_approach(pos, train_id, train, index, has_entered, lzbdata)
end end
-- call other registered callbacks -- call other registered callbacks
run_callbacks_approach_node(pos, train_id, train, index, lzbdata) run_callbacks_approach_node(pos, train_id, train, index, has_entered, lzbdata)
end end
-- === te callback definition for tnc node callbacks ===
advtrains.te_register_on_new_path(function(id, train) advtrains.te_register_on_new_path(function(id, train)
train.tnc = { train.tnc = {
@ -865,7 +994,7 @@ function advtrains.spawn_wagons(train_id)
atwarn("Train",train_id,"Wagon #",i,": Saved train ID",data.train_id,"did not match!") atwarn("Train",train_id,"Wagon #",i,": Saved train ID",data.train_id,"did not match!")
data.train_id = train_id data.train_id = train_id
end end
if not advtrains.wagon_objects[w_id] or not advtrains.wagon_objects[w_id]:getyaw() then if not advtrains.wagon_objects[w_id] or not advtrains.wagon_objects[w_id]:get_yaw() then
-- eventually need to spawn new object. check if position is loaded. -- eventually need to spawn new object. check if position is loaded.
local index = advtrains.path_get_index_by_offset(train, train.index, -data.pos_in_train) local index = advtrains.path_get_index_by_offset(train, train.index, -data.pos_in_train)
local pos = advtrains.path_get(train, atfloor(index)) local pos = advtrains.path_get(train, atfloor(index))
@ -1017,7 +1146,7 @@ end
function advtrains.train_check_couples(train) function advtrains.train_check_couples(train)
--atdebug("rechecking couples") --atdebug("rechecking couples")
if train.cpl_front then if train.cpl_front then
if not train.cpl_front:getyaw() then if not train.cpl_front:get_yaw() then
-- objectref is no longer valid. reset. -- objectref is no longer valid. reset.
train.cpl_front = nil train.cpl_front = nil
end end
@ -1047,7 +1176,7 @@ function advtrains.train_check_couples(train)
end end
end end
if train.cpl_back then if train.cpl_back then
if not train.cpl_back:getyaw() then if not train.cpl_back:get_yaw() then
-- objectref is no longer valid. reset. -- objectref is no longer valid. reset.
train.cpl_back = nil train.cpl_back = nil
end end
@ -1195,6 +1324,18 @@ function advtrains.invalidate_all_paths(pos)
advtrains.invalidate_path(id) advtrains.invalidate_path(id)
end end
end end
-- Calls invalidate_path_ahead on all trains occupying (having paths over) this node
-- Can be called during train step.
function advtrains.invalidate_all_paths_ahead(pos)
local tab = advtrains.occ.get_trains_over(pos)
for id,index in pairs(tab) do
local train = advtrains.trains[id]
advtrains.path_invalidate_ahead(train, index, true)
end
end
function advtrains.invalidate_path(id) function advtrains.invalidate_path(id)
--atdebug("Path invalidate:",id) --atdebug("Path invalidate:",id)
local v=advtrains.trains[id] local v=advtrains.trains[id]

View File

@ -10,6 +10,8 @@
-- TP delay when getting off wagon -- TP delay when getting off wagon
local GETOFF_TP_DELAY = 0.5 local GETOFF_TP_DELAY = 0.5
local IGNORE_WORLD = advtrains.IGNORE_WORLD
advtrains.wagons = {} advtrains.wagons = {}
advtrains.wagon_prototypes = {} advtrains.wagon_prototypes = {}
advtrains.wagon_objects = {} advtrains.wagon_objects = {}
@ -154,7 +156,7 @@ function wagon:ensure_init()
atwarn("wagon",self.id,"uninitialized, removing") atwarn("wagon",self.id,"uninitialized, removing")
self:destroy() self:destroy()
else else
self.object:setvelocity({x=0,y=0,z=0}) self.object:set_velocity({x=0,y=0,z=0})
end end
return false return false
end end
@ -166,7 +168,6 @@ end
-- Remove the wagon -- Remove the wagon
function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direction) function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
return advtrains.pcall(function()
if not self:ensure_init() then return end if not self:ensure_init() then return end
local data = advtrains.wagons[self.id] local data = advtrains.wagons[self.id]
@ -223,7 +224,6 @@ function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direct
for _,item in ipairs(self.drops or {self.name}) do for _,item in ipairs(self.drops or {self.name}) do
inv:add_item("main", item) inv:add_item("main", item)
end end
end)
end end
function wagon:destroy() function wagon:destroy()
--some rules: --some rules:
@ -268,11 +268,15 @@ function wagon:is_driver_stand(seat)
end end
function wagon:on_step(dtime) function wagon:on_step(dtime)
return advtrains.pcall(function()
if not self:ensure_init() then return end if not self:ensure_init() then return end
if advtrains.is_no_action() then
self.object:remove()
return
end
local t=os.clock() local t=os.clock()
local pos = self.object:getpos() local pos = self.object:get_pos()
local data = advtrains.wagons[self.id] local data = advtrains.wagons[self.id]
if not pos then if not pos then
@ -400,8 +404,8 @@ function wagon:on_step(dtime)
--for path to be available. if not, skip step --for path to be available. if not, skip step
if not train.path or train.no_step then if not train.path or train.no_step then
self.object:setvelocity({x=0, y=0, z=0}) self.object:set_velocity({x=0, y=0, z=0})
self.object:setacceleration({x=0, y=0, z=0}) self.object:set_acceleration({x=0, y=0, z=0})
return return
end end
if not data.pos_in_train then if not data.pos_in_train then
@ -444,7 +448,7 @@ function wagon:on_step(dtime)
end end
--checking for environment collisions(a 3x3 cube around the center) --checking for environment collisions(a 3x3 cube around the center)
if is_in_loaded_area and not train.recently_collided_with_env then if not IGNORE_WORLD and is_in_loaded_area and not train.recently_collided_with_env then
local collides=false local collides=false
local exh = self.extent_h or 1 local exh = self.extent_h or 1
local exv = self.extent_v or 2 local exv = self.extent_v or 2
@ -470,7 +474,7 @@ function wagon:on_step(dtime)
-- FIX: Need to do this after the yaw calculation -- FIX: Need to do this after the yaw calculation
if is_in_loaded_area and data.pos_in_trainparts and data.pos_in_trainparts>1 then if is_in_loaded_area and data.pos_in_trainparts and data.pos_in_trainparts>1 then
if train.velocity==0 then if train.velocity==0 then
if not self.discouple or not self.discouple.object:getyaw() then if not self.discouple or not self.discouple.object:get_yaw() then
atprint(self.id,"trying to spawn discouple") atprint(self.id,"trying to spawn discouple")
local dcpl_pos = vector.add(pos, {y=0, x=-math.sin(yaw)*self.wagon_span, z=math.cos(yaw)*self.wagon_span}) local dcpl_pos = vector.add(pos, {y=0, x=-math.sin(yaw)*self.wagon_span, z=math.cos(yaw)*self.wagon_span})
local object=minetest.add_entity(dcpl_pos, "advtrains:discouple") local object=minetest.add_entity(dcpl_pos, "advtrains:discouple")
@ -483,7 +487,7 @@ function wagon:on_step(dtime)
end end
end end
else else
if self.discouple and self.discouple.object:getyaw() then if self.discouple and self.discouple.object:get_yaw() then
self.discouple.object:remove() self.discouple.object:remove()
atprint(self.id," removing discouple") atprint(self.id," removing discouple")
end end
@ -491,8 +495,8 @@ function wagon:on_step(dtime)
end end
--FIX: use index of the wagon, not of the train. --FIX: use index of the wagon, not of the train.
local velocity = train.velocity local velocity = train.velocity * advtrains.global_slowdown
local acceleration = (train.acceleration or 0) local acceleration = (train.acceleration or 0) * (advtrains.global_slowdown*advtrains.global_slowdown)
local velocityvec = vector.multiply(vdir, velocity) local velocityvec = vector.multiply(vdir, velocity)
local accelerationvec = vector.multiply(vdir, acceleration) local accelerationvec = vector.multiply(vdir, acceleration)
@ -539,9 +543,9 @@ function wagon:on_step(dtime)
or self.old_yaw~=yaw or self.old_yaw~=yaw
or updatepct_timer_elapsed then--only send update packet if something changed or updatepct_timer_elapsed then--only send update packet if something changed
self.object:setpos(pos) self.object:set_pos(pos)
self.object:setvelocity(velocityvec) self.object:set_velocity(velocityvec)
self.object:setacceleration(accelerationvec) self.object:set_acceleration(accelerationvec)
if #self.seats > 0 and self.old_yaw ~= yaw then if #self.seats > 0 and self.old_yaw ~= yaw then
if not self.player_yaw then if not self.player_yaw then
@ -574,7 +578,7 @@ function wagon:on_step(dtime)
end end
self.object:set_rotation({x=pitch, y=yaw, z=0}) self.object:set_rotation({x=pitch, y=yaw, z=0})
else else
self.object:setyaw(yaw) self.object:set_yaw(yaw)
end end
if self.update_animation then if self.update_animation then
@ -595,11 +599,9 @@ function wagon:on_step(dtime)
self.old_acceleration_vector=accelerationvec self.old_acceleration_vector=accelerationvec
self.old_yaw=yaw self.old_yaw=yaw
atprintbm("wagon step", t) atprintbm("wagon step", t)
end)
end end
function wagon:on_rightclick(clicker) function wagon:on_rightclick(clicker)
return advtrains.pcall(function()
if not self:ensure_init() then return end if not self:ensure_init() then return end
if not clicker or not clicker:is_player() then if not clicker or not clicker:is_player() then
return return
@ -687,7 +689,6 @@ function wagon:on_rightclick(clicker)
self:show_get_on_form(pname) self:show_get_on_form(pname)
end end
end end
end)
end end
function wagon:get_on(clicker, seatno) function wagon:get_on(clicker, seatno)
@ -770,7 +771,7 @@ function wagon:get_off(seatno)
--atdebug("platpos:", platpos, "offpos:", offpos) --atdebug("platpos:", platpos, "offpos:", offpos)
if minetest.get_item_group(minetest.get_node(platpos).name, "platform")>0 then if minetest.get_item_group(minetest.get_node(platpos).name, "platform")>0 then
minetest.after(GETOFF_TP_DELAY, function() clicker:setpos(offpos) end) minetest.after(GETOFF_TP_DELAY, function() clicker:set_pos(offpos) end)
--atdebug("tp",offpos) --atdebug("tp",offpos)
return return
end end
@ -790,7 +791,7 @@ function wagon:get_off(seatno)
offp=vector.add({x=isx and r*2 or 0, y=1, z=not isx and r*2 or 0}, objpos) offp=vector.add({x=isx and r*2 or 0, y=1, z=not isx and r*2 or 0}, objpos)
--atdebug("platpos:", p, "offpos:", offp) --atdebug("platpos:", p, "offpos:", offp)
if minetest.get_item_group(minetest.get_node(p).name, "platform")>0 then if minetest.get_item_group(minetest.get_node(p).name, "platform")>0 then
minetest.after(GETOFF_TP_DELAY, function() clicker:setpos(offp) end) minetest.after(GETOFF_TP_DELAY, function() clicker:set_pos(offp) end)
--atdebug("tp",offp) --atdebug("tp",offp)
return return
end end
@ -987,10 +988,10 @@ function wagon:show_bordcom(pname)
-- Interlocking functionality: If the interlocking module is loaded, you can set the signal aspect -- Interlocking functionality: If the interlocking module is loaded, you can set the signal aspect
-- from inside the train -- from inside the train
if advtrains.interlocking and train.lzb and #train.lzb.oncoming > 0 then if advtrains.interlocking and train.lzb and #train.lzb.checkpoints > 0 then
local i=1 local i=1
while train.lzb.oncoming[i] do while train.lzb.checkpoints[i] do
local oci = train.lzb.oncoming[i] local oci = train.lzb.checkpoints[i]
if oci.udata and oci.udata.signal_pos then if oci.udata and oci.udata.signal_pos then
if advtrains.interlocking.db.get_sigd_for_signal(oci.udata.signal_pos) then if advtrains.interlocking.db.get_sigd_for_signal(oci.udata.signal_pos) then
form = form .. "button[4.5,8;5,1;ilrs;Remote Routesetting]" form = form .. "button[4.5,8;5,1;ilrs;Remote Routesetting]"
@ -999,6 +1000,9 @@ function wagon:show_bordcom(pname)
end end
i=i+1 i=i+1
end end
if train.ars_disable then
form = form .. "button[4.5,7;5,1;ilarsenable;Clear 'Disable ARS' flag]"
end
end end
minetest.show_formspec(pname, "advtrains_bordcom_"..self.id, form) minetest.show_formspec(pname, "advtrains_bordcom_"..self.id, form)
@ -1071,18 +1075,23 @@ function wagon:handle_bordcom_fields(pname, formname, fields)
-- Interlocking functionality: If the interlocking module is loaded, you can set the signal aspect -- Interlocking functionality: If the interlocking module is loaded, you can set the signal aspect
-- from inside the train -- from inside the train
if fields.ilrs and advtrains.interlocking and train.lzb and #train.lzb.oncoming > 0 then if advtrains.interlocking then
local i=1 if fields.ilrs and train.lzb and #train.lzb.checkpoints > 0 then
while train.lzb.oncoming[i] do local i=1
local oci = train.lzb.oncoming[i] while train.lzb.checkpoints[i] do
if oci.udata and oci.udata.signal_pos then local oci = train.lzb.checkpoints[i]
local sigd = advtrains.interlocking.db.get_sigd_for_signal(oci.udata.signal_pos) if oci.udata and oci.udata.signal_pos then
if sigd then local sigd = advtrains.interlocking.db.get_sigd_for_signal(oci.udata.signal_pos)
advtrains.interlocking.show_signalling_form(sigd, pname) if sigd then
return advtrains.interlocking.show_signalling_form(sigd, pname)
return
end
end end
i=i+1
end end
i=i+1 end
if fields.ilarsenable then
advtrains.interlocking.ars_set_disable(train, false)
end end
end end
@ -1093,7 +1102,6 @@ function wagon:handle_bordcom_fields(pname, formname, fields)
end end
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
return advtrains.pcall(function()
local uid=string.match(formname, "^advtrains_geton_(.+)$") local uid=string.match(formname, "^advtrains_geton_(.+)$")
if uid then if uid then
for _,wagon in pairs(minetest.luaentities) do for _,wagon in pairs(minetest.luaentities) do
@ -1177,7 +1185,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
end end
end end
end)
end) end)
function wagon:seating_from_key_helper(pname, fields, no) function wagon:seating_from_key_helper(pname, fields, no)
local data = advtrains.wagons[self.id] local data = advtrains.wagons[self.id]
@ -1381,7 +1388,6 @@ function advtrains.register_wagon(sysname_p, prototype, desc, inv_img, nincreati
groups = { not_in_creative_inventory = nincreative and 1 or 0}, groups = { not_in_creative_inventory = nincreative and 1 or 0},
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
return advtrains.pcall(function()
if not pointed_thing.type == "node" then if not pointed_thing.type == "node" then
return return
end end
@ -1419,8 +1425,6 @@ function advtrains.register_wagon(sysname_p, prototype, desc, inv_img, nincreati
itemstack:take_item() itemstack:take_item()
end end
return itemstack return itemstack
end)
end, end,
}) })
end end

View File

@ -19,38 +19,50 @@ local function get_over_function(speed, shunt)
if speed == 0 and minetest.settings:get_bool("at_il_force_lzb_halt") then if speed == 0 and minetest.settings:get_bool("at_il_force_lzb_halt") then
atwarn(id,"overrun LZB 0 restriction (red signal) ",pos) atwarn(id,"overrun LZB 0 restriction (red signal) ",pos)
-- Set train 1 index backward. Hope this does not lead to bugs... -- Set train 1 index backward. Hope this does not lead to bugs...
train.index = index - 0.5 --train.index = index - 0.5
train.velocity = 0 train.speed_restriction = 0
train.ctrl.lzb = 0
minetest.after(0, advtrains.invalidate_path, id) --TODO temporary
--advtrains.drb_dump(id)
--error("Debug: "..id.." triggered LZB-0")
else else
train.speed_restriction = speed train.speed_restriction = speed
train.is_shunt = shunt train.is_shunt = shunt
end end
--atdebug("train drove over IP: speed=",speed,"shunt=",shunt)
end end
end end
advtrains.tnc_register_on_approach(function(pos, id, train, index, lzbdata) advtrains.tnc_register_on_approach(function(pos, id, train, index, has_entered, lzbdata)
--atdebug(id,"IL ApprC",pos,index,lzbdata) --atdebug(id,"IL ApprC",pos,index,lzbdata)
--train.debug = advtrains.print_concat_table({train.is_shunt,"|",index,"|",lzbdata}) --train.debug = advtrains.print_concat_table({train.is_shunt,"|",index,"|",lzbdata})
local pts = advtrains.roundfloorpts(pos) local pts = advtrains.roundfloorpts(pos)
local cn = train.path_cn[index] local cn = train.path_cn[index]
local travsht = lzbdata.travsht local travsht = lzbdata.il_shunt
local travspd = lzbdata.il_speed
if travsht==nil then if travsht==nil then
travsht = train.is_shunt -- lzbdata has reset
travspd = train.speed_restriction
travsht = train.is_shunt or false
end end
local travspd = lzbdata.travspd
local travwspd = lzbdata.travwspd
-- check for signal -- check for signal
local asp, spos = il.db.get_ip_signal_asp(pts, cn) local asp, spos = il.db.get_ip_signal_asp(pts, cn)
-- do ARS if needed -- do ARS if needed
if spos then local ars_enabled = not train.ars_disable
-- Note on ars_disable:
-- Theoretically, the ars_disable flag would need to behave like the speed restriction field: it should be
-- stored in lzbdata and updated once the train drives over. However, for the sake of simplicity, it is simply
-- a value in the train. In this case, this is sufficient because once a train triggers ARS for the first time,
-- resetting the path does not matter to the set route and ARS doesn't need to be called again.
if spos and ars_enabled then
--atdebug(id,"IL Spos (ARS)",spos,asp) --atdebug(id,"IL Spos (ARS)",spos,asp)
local sigd = il.db.get_sigd_for_signal(spos) local sigd = il.db.get_sigd_for_signal(spos)
if sigd then if sigd then
@ -60,22 +72,22 @@ advtrains.tnc_register_on_approach(function(pos, id, train, index, lzbdata)
--atdebug("trav: ",pos, cn, asp, spos, "travsht=", lzb.travsht) --atdebug("trav: ",pos, cn, asp, spos, "travsht=", lzb.travsht)
local lspd local lspd
if asp then if asp then
--atdebug(id,"IL Signal",spos,asp) --atdebug(id,"IL Signal",spos, asp, lzbdata, "trainstate", train.speed_restriction, train.is_shunt)
local nspd = 0 local nspd = 0
--interpreting aspect and determining speed to proceed --interpreting aspect and determining speed to proceed
if travsht then if travsht then
--shunt move --shunt move
if asp.shunt.free then if asp.shunt then
nspd = SHUNT_SPEED_MAX nspd = SHUNT_SPEED_MAX
elseif asp.shunt.proceed_as_main and asp.main.free then elseif asp.proceed_as_main and asp.main ~= 0 then
nspd = asp.main.speed nspd = asp.main
travsht = false travsht = false
end end
else else
--train move --train move
if asp.main.free then if asp.main ~= 0 then
nspd = asp.main.speed nspd = asp.main
elseif asp.shunt.free then elseif asp.shunt then
nspd = SHUNT_SPEED_MAX nspd = SHUNT_SPEED_MAX
travsht = true travsht = true
end end
@ -89,25 +101,26 @@ advtrains.tnc_register_on_approach(function(pos, id, train, index, lzbdata)
end end
end end
local nwspd = asp.info.w_speed --atdebug("ns,ts", nspd, travspd)
if nwspd then
if nwspd == -1 then
travwspd = nil
else
travwspd = nwspd
end
end
--atdebug("ns,wns,ts,wts", nspd, nwspd, travspd, travwspd)
lspd = travspd lspd = travspd
if travwspd and (not lspd or lspd>travwspd) then
lspd = travwspd
end
local udata = {signal_pos = spos} local udata = {signal_pos = spos}
local callback = get_over_function(lspd, travsht) local callback = get_over_function(lspd, travsht)
advtrains.lzb_add_checkpoint(train, index, lspd, callback, udata) lzbdata.il_shunt = travsht
lzbdata.il_speed = travspd
--atdebug("new lzbdata",lzbdata)
advtrains.lzb_add_checkpoint(train, index, lspd, callback, lzbdata, udata)
end end
lzbdata.travsht = travsht
lzbdata.travspd = travspd
lzbdata.travwspd = travwspd
end) end)
-- Set the ars_disable flag to the value passed
-- Triggers a path invalidation if set to false
function advtrains.interlocking.ars_set_disable(train, value)
if value then
train.ars_disable = true
else
train.ars_disable = nil
minetest.after(0, advtrains.path_invalidate, train)
end
end

View File

@ -131,6 +131,37 @@ function ildb.load(data)
if data.npr_rails then if data.npr_rails then
advtrains.interlocking.npr_rails = data.npr_rails advtrains.interlocking.npr_rails = data.npr_rails
end end
--COMPATIBILITY to Signal aspect format
-- TODO remove in time...
for pts,tcb in pairs(track_circuit_breaks) do
for connid, tcbs in ipairs(tcb) do
if tcbs.routes then
for _,route in ipairs(tcbs.routes) do
if route.aspect then
-- transform the signal aspect format
local asp = route.aspect
if type(asp.main) == "table" then
atwarn("Transforming route aspect of signal",pts,"/",connid,"")
if asp.main.free then
asp.main = asp.main.speed
else
asp.main = 0
end
if asp.dst.free then
asp.dst = asp.dst.speed
else
asp.dst = 0
end
asp.proceed_as_main = asp.shunt.proceed_as_main
asp.shunt = asp.shunt.free
-- Note: info table not transferred, it's not used right now
end
end
end
end
end
end
end end
function ildb.save() function ildb.save()
@ -149,6 +180,7 @@ end
--[[ --[[
TCB data structure TCB data structure
{ {
-- This is the "A" side of the TCB
[1] = { -- Variant: with adjacent TCs. [1] = { -- Variant: with adjacent TCs.
ts_id = <id> -- ID of the assigned track section ts_id = <id> -- ID of the assigned track section
signal = <pos> -- optional: when set, routes can be set from this tcb/direction and signal signal = <pos> -- optional: when set, routes can be set from this tcb/direction and signal
@ -164,6 +196,7 @@ TCB data structure
routes = { <route definition> } -- a collection of routes from this signal routes = { <route definition> } -- a collection of routes from this signal
route_auto = <boolean> -- When set, we will automatically re-set the route (designated by routeset) route_auto = <boolean> -- When set, we will automatically re-set the route (designated by routeset)
}, },
-- This is the "B" side of the TCB
[2] = { -- Variant: end of track-circuited area (initial state of TC) [2] = { -- Variant: end of track-circuited area (initial state of TC)
ts_id = nil, -- this is the indication for end_of_interlocking ts_id = nil, -- this is the indication for end_of_interlocking
section_free = <boolean>, --this can be set by an exit node via mesecons or atlatc, section_free = <boolean>, --this can be set by an exit node via mesecons or atlatc,

View File

@ -6,10 +6,10 @@
local setaspect = function(pos, node, asp) local setaspect = function(pos, node, asp)
if not asp.main.free then if asp.main == 0 then
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_danger"}) advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_danger"})
else else
if asp.dst.free and asp.main.speed == -1 then if asp.dst ~= 0 and asp.main == -1 then
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_free"}) advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_free"})
else else
advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_slow"}) advtrains.ndb.swap_node(pos, {name="advtrains_interlocking:ds_slow"})
@ -22,18 +22,10 @@ local setaspect = function(pos, node, asp)
end end
local suppasp = { local suppasp = {
main = { main = {0, 6, -1},
free = nil, dst = {0, false},
speed = {6, -1}, shunt = false,
}, proceed_as_main = true,
dst = {
free = nil,
speed = nil,
},
shunt = {
free = false,
proceed_as_main = true,
},
info = { info = {
call_on = false, call_on = false,
dead_end = false, dead_end = false,
@ -74,10 +66,7 @@ minetest.register_node("advtrains_interlocking:ds_free", {
supported_aspects = suppasp, supported_aspects = suppasp,
get_aspect = function(pos, node) get_aspect = function(pos, node)
return { return {
main = { main = -1,
free = true,
speed = -1,
}
} }
end, end,
}, },
@ -98,10 +87,7 @@ minetest.register_node("advtrains_interlocking:ds_slow", {
supported_aspects = suppasp, supported_aspects = suppasp,
get_aspect = function(pos, node) get_aspect = function(pos, node)
return { return {
main = { main = 6,
free = true,
speed = 6,
}
} }
end, end,
}, },

View File

@ -112,7 +112,8 @@ route = {
next = <sigd>, -- of the next (note: next) TCB on the route next = <sigd>, -- of the next (note: next) TCB on the route
locks = {<pts> = "state"} -- route locks of this route segment locks = {<pts> = "state"} -- route locks of this route segment
} }
terminal = terminal = <sigd>,
aspect = <signal aspect>,--note, might change in future
} }
The first item in the TCB path (namely i=0) is always the start signal of this route, The first item in the TCB path (namely i=0) is always the start signal of this route,
so this is left out. so this is left out.

View File

@ -129,7 +129,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
advtrains.interlocking.show_route_edit_form(pname, sigd, routeid) advtrains.interlocking.show_route_edit_form(pname, sigd, routeid)
end end
advtrains.interlocking.show_signal_aspect_selector(pname, suppasp, route.name, callback, route.aspect) advtrains.interlocking.show_signal_aspect_selector(pname, suppasp, route.name, callback, route.aspect or advtrains.interlocking.GENERIC_FREE)
return return
end end
if fields.delete then if fields.delete then

View File

@ -6,21 +6,6 @@ local function sigd_to_string(sigd)
return minetest.pos_to_string(sigd.p).." / "..lntrans[sigd.s] return minetest.pos_to_string(sigd.p).." / "..lntrans[sigd.s]
end end
local asp_generic_free = {
main = {
free = true,
speed = -1,
},
shunt = {
free = false,
},
dst = {
free = true,
speed = -1,
},
info = {}
}
local ildb = advtrains.interlocking.db local ildb = advtrains.interlocking.db
local ilrs = {} local ilrs = {}
@ -127,7 +112,7 @@ function ilrs.set_route(signal, route, try)
} }
if c_tcbs.signal then if c_tcbs.signal then
c_tcbs.route_committed = true c_tcbs.route_committed = true
c_tcbs.aspect = route.aspect or asp_generic_free c_tcbs.aspect = route.aspect or advtrains.interlocking.GENERIC_FREE
c_tcbs.route_origin = signal c_tcbs.route_origin = signal
advtrains.interlocking.update_signal_aspect(c_tcbs) advtrains.interlocking.update_signal_aspect(c_tcbs)
end end

View File

@ -3,42 +3,46 @@
--[[ --[[
Signal aspect table: Signal aspect table:
Note: All speeds are measured in m/s, aka the number of + signs in the HUD.
asp = { asp = {
main = { main = <int speed>,
free = <boolean>, -- Main signal aspect, tells state and permitted speed of next section
speed = <int km/h>, -- 0 = section is blocked
}, -- >0 = section is free, speed limit is this value
shunt = { -- -1 = section is free, maximum speed permitted
free = <boolean>, -- false/nil = Signal doesn't provide main signal information, retain current speed limit.
shunt = <boolean>,
-- Whether train may proceed as shunt move, on sight -- Whether train may proceed as shunt move, on sight
-- main aspect takes precedence over this -- main aspect takes precedence over this
proceed_as_main = <boolean>, -- When main==0, train switches to shunt move and is restricted to speed 6
-- If an approaching train is a shunt move and "main.free" is set, proceed_as_main = <boolean>,
-- If an approaching train is a shunt move and 'shunt' is false,
-- the train may proceed as a train move under the "main" aspect -- the train may proceed as a train move under the "main" aspect
-- if the main aspect permits it (i.e. main!=0)
-- If this is not set, shunt moves are NOT allowed to switch to -- If this is not set, shunt moves are NOT allowed to switch to
-- a train move, and must stop even if "main.free" is set. -- a train move, and must stop even if "main" would permit passing.
-- This is intended to be used for "Halt for shunt moves" signs. -- This is intended to be used for "Halt for shunt moves" signs.
}
dst = { dst = <int speed>,
free = <boolean>, -- Distant signal aspect, tells state and permitted speed of the section after next section
speed = <int km/h>, -- The character of these information is purely informational
} -- At this time, this field is not actively used
info = { -- 0 = section is blocked
call_on = <boolean>, -- Call-on route, expect train in track ahead (not implemented yet) -- >0 = section is free, speed limit is this value
dead_end = <boolean>, -- Route ends on a dead end (e.g. bumper) (not implemented yet) -- -1 = section is free, maximum speed permitted
w_speed = <integer>, -- false/nil = Signal doesn't provide distant signal information.
-- "Warning speed restriction". Supposed for short-term speed
-- restrictions which always override any other restrictions -- the character of call_on and dead_end is purely informative
-- imposed by "speed" fields, until lifted by a value of -1 call_on = <boolean>, -- Call-on route, expect train in track ahead (not implemented yet)
-- (Example: german Langsamfahrstellen-Signale) dead_end = <boolean>, -- Route ends on a dead end (e.g. bumper) (not implemented yet)
w_speed = <integer>,
-- "Warning speed restriction". Supposed for short-term speed
-- restrictions which always override any other restrictions
-- imposed by "speed" fields, until lifted by a value of -1
-- (Example: german Langsamfahrstellen-Signale)
} }
} }
-- For "speed" and "w_speed" fields, a value of -1 means that the
-- restriction is lifted. If they are omitted, the value imposed at
-- the last aspect received remains valid.
-- The "dst" subtable can be completely omitted when no explicit dst
-- aspect should be signalled to the train. In this case, the last
-- signalled dst aspect remains valid.
== How signals actually work in here == == How signals actually work in here ==
Each signal (in the advtrains universe) is some node that has at least the Each signal (in the advtrains universe) is some node that has at least the
@ -60,10 +64,16 @@ advtrains = {
-- This function gets called whenever the signal should display -- This function gets called whenever the signal should display
-- a new or changed signal aspect. It is not required that -- a new or changed signal aspect. It is not required that
-- the signal actually displays the exact same aspect, since -- the signal actually displays the exact same aspect, since
-- some signals can not do this by design. -- some signals can not do this by design. However, it must
-- Example: pure shunt signals can not display a "main" aspect -- display an aspect that is at least as restrictive as the passed
-- and have no effect on train moves, so they will only ever -- aspect as far as it is capable of doing so.
-- honor the shunt.free field for their aspect. -- Examples:
-- - pure shunt signals can not display a "main" aspect
-- and have no effect on train moves, so they will only ever
-- honor the shunt.free field for their aspect.
-- - the german Hl system can only signal speeds of 40, 60
-- and 100 km/h, a speed of 80km/h should then be signalled
-- as 60 km/h instead.
-- In turn, it is not guaranteed that the aspect will fulfill the -- In turn, it is not guaranteed that the aspect will fulfill the
-- criteria put down in supported_aspects. -- criteria put down in supported_aspects.
-- If set_aspect is present, supported_aspects should also be declared. -- If set_aspect is present, supported_aspects should also be declared.
@ -87,51 +97,52 @@ advtrains = {
false: always shows "blocked", unchangable false: always shows "blocked", unchangable
true: always shows "free", unchangable true: always shows "free", unchangable
-- Any of the "speed" fields should contain a list of possible values -- Any of the "speed" fields should contain a list of possible values
-- to be set as restriction. If omitted, this signal should never -- to be set as restriction. If omitted, the value of the described
-- set the corresponding "speed" field in the aspect, which means -- field is always assumed to be false (no information)
-- that the previous speed limit stays valid -- A speed of 0 means that the signal can show a "blocked" aspect
-- (which is probably the case for most signals)
-- If the signal can signal "no information" on one of the fields
-- (thus false is an acceptable value), include false in the list
-- If your signal can only display a single speed (may it be -1), -- If your signal can only display a single speed (may it be -1),
-- always enclose that single value into a list. (such as {-1}) -- always enclose that single value into a list. (such as {-1})
main = { main = {<speed1>, ..., <speedn>} or nil,
free = <boolean/nil>, dst = {<speed1>, ..., <speedn>} or nil,
speed = {<speed1>, ..., <speedn>} or nil, shunt = <boolean/nil>,
},
dst = { call_on = <boolean/nil>,
free = <boolean/nil>, dead_end = <boolean/nil>,
speed = {<speed1>, ..., <speedn>} or nil, w_speed = {<speed1>, ..., <speedn>} or nil,
},
shunt = {
free = <boolean/nil>,
},
info = {
call_on = <boolean/nil>,
dead_end = <boolean/nil>,
w_speed = {<speed1>, ..., <speedn>} or nil,
}
}, },
Example for supported_aspects:
supported_aspects = {
main = {0, 6, -1}, -- can show either "Section blocked", "Proceed at speed 6" or "Proceed at maximum speed"
dst = {0, false}, -- can show only if next signal shows "blocked", no other information.
shunt = false, -- shunting by this signal is never allowed.
call_on = false,
dead_end = false,
w_speed = nil,
-- none of the information can be shown by the signal
},
get_aspect = function(pos, node) get_aspect = function(pos, node)
-- This function gets called by the train safety system. It -- This function gets called by the train safety system. It
should return the aspect that this signal actually displays, should return the aspect that this signal actually displays,
not preferably the input of set_aspect. not preferably the input of set_aspect.
-- For regular, full-featured light signals, they will probably -- For regular, full-featured light signals, they will probably
honor all entries in the original aspect, however, e.g. honor all entries in the original aspect, however, e.g.
simple shunt signals always return main.free=true regardless of simple shunt signals always return main=false regardless of
the set_aspect input because they can not signal "Halt" to the set_aspect input because they can not signal "Halt" to
train moves. train moves.
-- advtrains.interlocking.DANGER contains a default "all-danger" aspect. -- advtrains.interlocking.DANGER contains a default "all-danger" aspect.
-- If your signal does not cover certain sub-tables of the aspect, -- If your signal does not cover certain sub-tables of the aspect,
the following reasonable defaults are automatically assumed: the following reasonable defaults are automatically assumed:
main = { main = false (unchanged)
free = true, dst = false (unchanged)
} shunt = false (shunting not allowed)
dst = { info = {} (no further information)
free = true,
}
shunt = {
free = false,
proceed_as_main = false,
}
end, end,
} }
on_rightclick = advtrains.interlocking.signal_rc_handler on_rightclick = advtrains.interlocking.signal_rc_handler
@ -155,51 +166,37 @@ This function will query get_aspect to retrieve the new aspect.
]]-- ]]--
local DANGER = { local DANGER = {
main = { main = 0,
free = false, dst = false,
speed = 0, shunt = false,
},
shunt = {
free = false,
},
dst = {
free = false,
speed = 0,
},
info = {}
} }
advtrains.interlocking.DANGER = DANGER advtrains.interlocking.DANGER = DANGER
local function fillout_aspect(asp) advtrains.interlocking.GENERIC_FREE = {
if not asp.main then main = -1,
asp.main = { shunt = false,
free = true, dst = false,
} }
elseif type(asp.main) ~= "table" then
asp.main = { local function convert_aspect_if_necessary(asp)
free = asp.main~=0, if type(asp.main) == "table" then
speed = asp.main, local newasp = {}
} if asp.main.free then
end newasp.main = asp.main.speed
if not asp.dst then else
asp.dst = { newasp.main = 0
free = true, end
} if asp.dst and asp.dst.free then
end newasp.dst = asp.dst.speed
if not asp.shunt then else
asp.shunt = { newasp.dst = 0
free = false, end
proceed_as_main = false, newasp.proceed_as_main = asp.shunt.proceed_as_main
} newasp.shunt = asp.shunt.free
elseif type(asp.shunt) ~= "table" then -- Note: info table not transferred, it's not used right now
asp.shunt = { return newasp
free = asp.shunt,
proceed_as_main = asp.proceed_as_main,
}
end
if not asp.info then
asp.info = {}
end end
return asp
end end
function advtrains.interlocking.update_signal_aspect(tcbs) function advtrains.interlocking.update_signal_aspect(tcbs)
@ -219,7 +216,7 @@ function advtrains.interlocking.signal_after_dig(pos)
end end
function advtrains.interlocking.signal_set_aspect(pos, asp) function advtrains.interlocking.signal_set_aspect(pos, asp)
fillout_aspect(asp) asp = convert_aspect_if_necessary(asp)
local node=advtrains.ndb.get_node(pos) local node=advtrains.ndb.get_node(pos)
local ndef=minetest.registered_nodes[node.name] local ndef=minetest.registered_nodes[node.name]
if ndef and ndef.advtrains and ndef.advtrains.set_aspect then if ndef and ndef.advtrains and ndef.advtrains.set_aspect then
@ -234,17 +231,17 @@ function advtrains.interlocking.signal_on_aspect_changed(pos)
if not ipts then return end if not ipts then return end
local ipos = minetest.string_to_pos(ipts) local ipos = minetest.string_to_pos(ipts)
local tns = advtrains.occ.get_trains_over(ipos) advtrains.invalidate_all_paths_ahead(ipos)
for id, sidx in pairs(tns) do
-- local train = advtrains.trains[id]
--if train.index <= sidx then
minetest.after(0, advtrains.invalidate_path, id)
--end
end
end end
function advtrains.interlocking.signal_rc_handler(pos, node, player, itemstack, pointed_thing) function advtrains.interlocking.signal_rc_handler(pos, node, player, itemstack, pointed_thing)
local pname = player:get_player_name() local pname = player:get_player_name()
local control = player:get_player_control()
if control.aux1 then
advtrains.interlocking.show_ip_form(pos, pname)
return
end
local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos) local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos)
if sigd then if sigd then
advtrains.interlocking.show_signalling_form(sigd, pname) advtrains.interlocking.show_signalling_form(sigd, pname)
@ -252,7 +249,16 @@ function advtrains.interlocking.signal_rc_handler(pos, node, player, itemstack,
local ndef = minetest.registered_nodes[node.name] local ndef = minetest.registered_nodes[node.name]
if ndef.advtrains and ndef.advtrains.set_aspect then if ndef.advtrains and ndef.advtrains.set_aspect then
-- permit to set aspect manually -- permit to set aspect manually
minetest.show_formspec(pname, "at_il_sigasp_"..minetest.pos_to_string(pos), "field[aspect;Set Aspect ('A' to assign IP);D0D0D]") local function callback(pname, aspect)
advtrains.interlocking.signal_set_aspect(pos, aspect)
end
local isasp = ndef.advtrains.get_aspect(pos, node)
advtrains.interlocking.show_signal_aspect_selector(
pname,
ndef.advtrains.supported_aspects,
"Set aspect manually", callback,
isasp)
else else
--static signal - only IP --static signal - only IP
advtrains.interlocking.show_ip_form(pos, pname) advtrains.interlocking.show_ip_form(pos, pname)
@ -260,45 +266,13 @@ function advtrains.interlocking.signal_rc_handler(pos, node, player, itemstack,
end end
end end
minetest.register_on_player_receive_fields(function(player, formname, fields)
local pname = player:get_player_name()
local pts = string.match(formname, "^at_il_sigasp_(.+)$")
local pos
if pts then pos = minetest.string_to_pos(pts) end
if pos and fields.aspect then
if fields.aspect == "A" then
advtrains.interlocking.show_ip_form(pos, pname)
return
end
local mfs, msps, dfs, dsps, shs = string.match(fields.aspect, "^([FD])([-0-9]+)([FD])([-0-9]+)([FD])$")
local asp = {
main = {
free = mfs=="F",
speed = tonumber(msps),
},
shunt = {
free = shs=="F",
},
dst = {
free = dfs=="F",
speed = tonumber(dsps),
},
info = {
call_on = false, -- Call-on route, expect train in track ahead
dead_end = false, -- Route ends on a dead end (e.g. bumper)
}
}
advtrains.interlocking.signal_set_aspect(pos, asp)
end
end)
-- Returns the aspect the signal at pos is supposed to show -- Returns the aspect the signal at pos is supposed to show
function advtrains.interlocking.signal_get_supposed_aspect(pos) function advtrains.interlocking.signal_get_supposed_aspect(pos)
local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos) local sigd = advtrains.interlocking.db.get_sigd_for_signal(pos)
if sigd then if sigd then
local tcbs = advtrains.interlocking.db.get_tcbs(sigd) local tcbs = advtrains.interlocking.db.get_tcbs(sigd)
if tcbs.aspect then if tcbs.aspect then
return tcbs.aspect return convert_aspect_if_necessary(tcbs.aspect)
end end
end end
return DANGER; return DANGER;
@ -312,8 +286,7 @@ function advtrains.interlocking.signal_get_aspect(pos)
if ndef and ndef.advtrains and ndef.advtrains.get_aspect then if ndef and ndef.advtrains and ndef.advtrains.get_aspect then
local asp = ndef.advtrains.get_aspect(pos, node) local asp = ndef.advtrains.get_aspect(pos, node)
if not asp then asp = DANGER end if not asp then asp = DANGER end
fillout_aspect(asp) return convert_aspect_if_necessary(asp)
return asp
end end
return nil return nil
end end
@ -447,42 +420,45 @@ local players_aspsel = {}
suppasp: "supported_aspects" table suppasp: "supported_aspects" table
purpose: form title string purpose: form title string
callback: func(pname, aspect) called on form submit callback: func(pname, aspect) called on form submit
isasp: aspect currently set
]] ]]
function advtrains.interlocking.show_signal_aspect_selector(pname, p_suppasp, p_purpose, callback, p_isasp) function advtrains.interlocking.show_signal_aspect_selector(pname, p_suppasp, p_purpose, callback, isasp)
local suppasp = p_suppasp or { local suppasp = p_suppasp or {
main = {}, dst = {}, shunt = {}, info = {}, main = {0, -1}, dst = {false}, shunt = false, info = {},
} }
local purpose = p_purpose or "" local purpose = p_purpose or ""
local isasp = p_isasp and fillout_aspect(p_isasp)
local form = "size[7,5]label[0.5,0.5;Select Signal Aspect:]" local form = "size[7,5]label[0.5,0.5;Select Signal Aspect:]"
form = form.."label[0.5,1;"..purpose.."]" form = form.."label[0.5,1;"..purpose.."]"
form = form.."label[0.5,1.5;== Main Signal ==]" form = form.."label[0.5,1.5;== Main Signal ==]"
if suppasp.main.free == nil then local selid = 1
local st = 2 local entries = {}
if isasp and not isasp.main.free then st=1 end for idx, spv in ipairs(suppasp.main) do
form = form.."dropdown[0.5,2;2;main_free;danger,free;"..st.."]" local entry
end if spv == 0 then
if suppasp.main.speed then entry = "Halt"
local selid = 1 elseif spv == -1 then
if isasp and isasp.main.speed then entry = "Continue at maximum speed"
for idx, spv in ipairs(suppasp.main.speed) do elseif not spv then
if spv == isasp.main.speed then entry = "Continue\\, speed limit unchanged (no info)"
selid = idx else
break entry = "Continue at speed of "..spv
end end
end -- hack: the crappy formspec system returns the label, not the index. save the index in it.
entries[idx] = idx.."| "..entry
if isasp and spv == (isasp.main or false) then
selid = idx
end end
form = form.."label[2.3,1;Speed:]"
form = form.."dropdown[3,2;2;main_speed;"..table.concat(suppasp.main.speed, ",")..";"..selid.."]"
end end
form = form.."dropdown[0.5,2;6;main;"..table.concat(entries, ",")..";"..selid.."]"
form = form.."label[0.5,3;== Shunting ==]" form = form.."label[0.5,3;== Shunting ==]"
if suppasp.shunt.free == nil then if suppasp.shunt == nil then
local st = 1 local st = 1
if isasp and isasp.shunt.free then st=2 end if isasp and isasp.shunt then st=2 end
form = form.."dropdown[0.5,3.5;2;shunt_free;---,allowed;"..st.."]" form = form.."dropdown[0.5,3.5;6;shunt_free;---,allowed;"..st.."]"
end end
form = form.."button_exit[0.5,4.5; 5,1;save;OK]" form = form.."button_exit[0.5,4.5; 5,1;save;OK]"
@ -507,12 +483,10 @@ local function usebool(sup, val, free)
return sup return sup
end end
end end
local function usespeed(sup, val)
if sup then -- other side of hack: extract the index
return tonumber(val) local function ddindex(val)
else return tonumber(string.match(val, "^(%d+)|"))
return nil
end
end end
-- TODO use non-hacky way to parse outputs -- TODO use non-hacky way to parse outputs
@ -523,17 +497,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if psl then if psl then
if formname == "at_il_sigaspdia_"..psl.token then if formname == "at_il_sigaspdia_"..psl.token then
if fields.save then if fields.save then
local maini = ddindex(fields.main)
if not maini then return end
local asp = { local asp = {
main = { main = psl.suppasp.main[maini],
free = usebool(psl.suppasp.main.free, fields.main_free, "free"), dst = false,
speed = usespeed(psl.suppasp.main.speed, fields.main_speed), shunt = usebool(psl.suppasp.shunt, fields.shunt_free, "allowed"),
},
dst = {
free = true, speed = -1,
},
shunt = {
free = usebool(psl.suppasp.shunt.free, fields.shunt_free, "allowed"),
},
info = {} info = {}
} }
psl.callback(pname, asp) psl.callback(pname, asp)

View File

@ -558,7 +558,7 @@ local sig_pselidx = {}
-- Players having a signalling form open -- Players having a signalling form open
local p_open_sig_form = {} local p_open_sig_form = {}
function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte) function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte, called_from_form_update)
if not minetest.check_player_privs(pname, "train_operator") then if not minetest.check_player_privs(pname, "train_operator") then
minetest.chat_send_player(pname, "Insufficient privileges to use this!") minetest.chat_send_player(pname, "Insufficient privileges to use this!")
return return
@ -651,7 +651,10 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte)
p_open_sig_form[pname] = sigd p_open_sig_form[pname] = sigd
-- always a good idea to update the signal aspect -- always a good idea to update the signal aspect
advtrains.interlocking.update_signal_aspect(tcbs) if not called_from_form_update then
-- FIX prevent a callback loop
advtrains.interlocking.update_signal_aspect(tcbs)
end
end end
function advtrains.interlocking.update_player_forms(sigd) function advtrains.interlocking.update_player_forms(sigd)
@ -763,7 +766,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
tcbs.route_auto = false tcbs.route_auto = false
end end
advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte) advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte, true)
return return
end end

View File

@ -169,7 +169,8 @@ local adefunc = function(def, preset, suffix, rotation)
show_stoprailform(pos, player) show_stoprailform(pos, player)
end, end,
advtrains = { advtrains = {
on_train_approach = function(pos,train_id, train, index) on_train_approach = function(pos,train_id, train, index, has_entered)
if has_entered then return end -- do not stop again!
if train.path_cn[index] == 1 then if train.path_cn[index] == 1 then
local pe = advtrains.encode_pos(pos) local pe = advtrains.encode_pos(pos)
local stdata = advtrains.lines.stops[pe] local stdata = advtrains.lines.stops[pe]
@ -184,6 +185,7 @@ local adefunc = function(def, preset, suffix, rotation)
local stn = advtrains.lines.stations[stdata.stn] local stn = advtrains.lines.stations[stdata.stn]
local stnname = stn and stn.name or "Unknown Station" local stnname = stn and stn.name or "Unknown Station"
train.text_inside = "Next Stop:\n"..stnname train.text_inside = "Next Stop:\n"..stnname
advtrains.interlocking.ars_set_disable(train, true)
end end
end end
end end
@ -201,7 +203,7 @@ local adefunc = function(def, preset, suffix, rotation)
local stnname = stn and stn.name or "Unknown Station" local stnname = stn and stn.name or "Unknown Station"
-- Send ATC command and set text -- Send ATC command and set text
advtrains.atc.train_set_command(train, "B0 W O"..stdata.doors..(stdata.kick and "K" or "").." D"..stdata.wait.." OC "..(stdata.reverse and "R" or "").."D"..(stdata.ddelay or 1) .. "S" ..(stdata.speed or "M"), true) advtrains.atc.train_set_command(train, "B0 W O"..stdata.doors..(stdata.kick and "K" or "").." D"..stdata.wait.." OC "..(stdata.reverse and "R" or "").."D"..(stdata.ddelay or 1) .. " A1 S" ..(stdata.speed or "M"), true)
train.text_inside = stnname train.text_inside = stnname
if tonumber(stdata.wait) then if tonumber(stdata.wait) then
minetest.after(tonumber(stdata.wait), function() train.text_inside = "" end) minetest.after(tonumber(stdata.wait), function() train.text_inside = "" end)

View File

@ -1,7 +1,9 @@
# Advtrains - Lua Automation features # Advtrains - Lua Automation features
This mod offers components that run LUA code and interface with each other through a global environment. It makes complex automated railway systems possible. The mod is sometimes abbreviated as 'atlatc'. This stands for AdvTrainsLuaATC. This short name has been chosen for user convenience, since the name of this mod ('advtrains_luaautomation') is very long. This mod offers components that run LUA code and interface with each other through a global environment. It makes complex automated railway systems possible. The mod is sometimes abbreviated as 'LuaATC' or 'atlatc'. This stands for AdvTrainsLuaATC. This short name has been chosen for user convenience, since the name of this mod ('advtrains_luaautomation') is very long.
A probably more complete documentation of LuaATC is found on the [Advtrains Wiki](http://advtrains.de/wiki/doku.php?id=usage:atlatc:start)
## Privileges ## Privileges
To perform any operations using this mod (except executing operation panels), players need the "atlatc" privilege. To perform any operations using this mod (except executing operation panels), players need the "atlatc" privilege.
@ -18,6 +20,13 @@ Create environment with the given name. To be able to do anything, you first nee
- `/env_setup <env_name>`: - `/env_setup <env_name>`:
Invoke the form to edit the environment's initialization code. For more information, see the section on active components. You can also delete an environment from here. Invoke the form to edit the environment's initialization code. For more information, see the section on active components. You can also delete an environment from here.
- `/env_subscribe <env_name>`, `/env_unsubscribe <env_name>`:
Subscribe or unsubscribe from log/error messages originating from this environment
- `/env_subscriptions [env_name]`:
List your subscriptions or players subscribed to an environment.
## Functions and variables ## Functions and variables
### General Functions and Variables ### General Functions and Variables
The following standard Lua libraries are available: The following standard Lua libraries are available:
@ -40,41 +49,6 @@ The following standard Lua functions are available:
Any attempt to overwrite the predefined values results in an error. Any attempt to overwrite the predefined values results in an error.
## Components and Events
### Components
Atlac components introduce automation-capable components that fall within two categories:
- Active Components are components that are able to run Lua code, triggered by specific events.
- Passive Components can't perform actions themselves. Their state can be read and set by active components or manually by the player.
## Functions and Variables
### Events
The event table is a variable created locally by the component being triggered. It is a table with the following format:
```lua
event = {
type = "<event type>",
<event type> = true,
--additional event-specific content
}
```
You can check the event type by using the following:
```lua
if event.type == "wanted" then
--do stuff
end
```
or
```lua
if event.wanted then
--do stuff
end
````
where `wanted` is the event type to check for.
See the "Active Components" section below for details on the various event types as not all of them are applicable to all components.
### LuaAutomation Global Variables ### LuaAutomation Global Variables
- `S` - `S`
The variable 'S' contains a table which is shared between all components of the environment. Its contents are persistent over server restarts. May not contain functions, every other value is allowed. The variable 'S' contains a table which is shared between all components of the environment. Its contents are persistent over server restarts. May not contain functions, every other value is allowed.
@ -104,11 +78,17 @@ Set the state of the passive component at position `pos`.
Checks whether there is a passive component at the position pos (and/or whether a passive component with this name exists) Checks whether there is a passive component at the position pos (and/or whether a passive component with this name exists)
- `interrupt(time, message)` - `interrupt(time, message)`
Cause LuaAutomation to trigger an `int` event on this component after the given time in seconds with the specified `message` field. `message` can be of any Lua data type. *Not available in init code.* Cause LuaAutomation to trigger an `int` event on this component after the given time in seconds with the specified `message` field. `message` can be of any Lua data type. Returns true. *Not available in init code.*
- `interrupt_safe(time, message)`
Like `interrupt()`, but does not add an interrupt and returns false when an interrupt (of any type) is already present for this component. Returns true when interrupt was successfully added.
- `interrupt_pos(pos, message)` - `interrupt_pos(pos, message)`
Immediately trigger an `ext_int` event on the active component at position pos. `message` is like in interrupt(). Use with care, or better **_don't use_**! Incorrect use can result in **_expotential growth of interrupts_**. Immediately trigger an `ext_int` event on the active component at position pos. `message` is like in interrupt(). Use with care, or better **_don't use_**! Incorrect use can result in **_expotential growth of interrupts_**.
- `clear_interrupts()`
Removes any pending interrupts of this node.
- `digiline_send(channel, message)` - `digiline_send(channel, message)`
Make this active component send a digiline message on the specified channel. Make this active component send a digiline message on the specified channel.
Not available in init code. Not available in init code.
@ -128,52 +108,105 @@ Cancels the route that is set from the signal at pos. Has the same effect as cli
- `get_aspect(pos)` - `get_aspect(pos)`
Returns the signal aspect of the signal at pos. A signal aspect has the following format: Returns the signal aspect of the signal at pos. A signal aspect has the following format:
```lua ```lua
{ asp = {
main = { -- the next track section in line. Shows blocked for shunt routes main = <int speed>,
free = <boolean>, -- Main signal aspect, tells state and permitted speed of next section
speed = <int km/h>, -- 0 = section is blocked
}, -- >0 = section is free, speed limit is this value
shunt = { -- whether a "shunting allowed" aspect should be shown -- -1 = section is free, maximum speed permitted
free = <boolean>, -- false = Signal doesn't provide main signal information, retain current speed limit.
}, shunt = <boolean>,
dst = { -- the aspect of the next main signal on (at end of) route -- Whether train may proceed as shunt move, on sight
free = <boolean>, -- main aspect takes precedence over this
speed = <int km/h>, -- When main==0, train switches to shunt move and is restricted to speed 8
}, proceed_as_main = <boolean>,
info = { -- If an approaching train is a shunt move and 'shunt' is false,
call_on = <boolean>, -- Call-on route, expect train in track ahead -- the train may proceed as a train move under the "main" aspect
dead_end = <boolean>, -- Route ends on a dead end (e.g. bumper) -- if the main aspect permits it (i.e. main!=0)
} -- If this is not set, shunt moves are NOT allowed to switch to
-- a train move, and must stop even if "main" would permit passing.
-- This is intended to be used for "Halt for shunt moves" signs.
dst = <int speed>,
-- Distant signal aspect, tells state and permitted speed of the section after next section
-- The character of these information is purely informational
-- At this time, this field is not actively used
-- 0 = section is blocked
-- >0 = section is free, speed limit is this value
-- -1 = section is free, maximum speed permitted
-- false = Signal doesn't provide distant signal information.
-- the character of call_on and dead_end is purely informative
call_on = <boolean>, -- Call-on route, expect train in track ahead (not implemented yet)
dead_end = <boolean>, -- Route ends on a dead end (e.g. bumper) (not implemented yet)
w_speed = <integer>,
-- "Warning speed restriction". Supposed for short-term speed
-- restrictions which always override any other restrictions
-- imposed by "speed" fields, until lifted by a value of -1
-- (Example: german Langsamfahrstellen-Signale)
} }
``` ```
As of August 2018 (git commit d837e7e), only the aspect.main.free field is ever used by the interlocking system. As of January 2020, the 'dst', 'call_on' and 'dead_end' fields are not used.
### Active Component #### Lines
#### Lua ATC Rails
Lua ATC rails are the only components that can actually interface with trains. The following event types are available to the Lua ATC rails: The advtrains_line_automation component adds a few contraptions that should make creating timeable systems easier.
- ```lua Part of its functionality is also available in LuaATC:
{type="train", train=true, id="<train_id>"}
- `rwt.*` - all Railway Time functions are included as documented in [the wiki](https://advtrains.de/wiki/doku.php?id=dev:lines:rwt)
- `schedule(rw_time, msg)`, `schedule_in(rw_dtime, msg)`
Schedules an event of type {type="schedule", schedule=true, msg=msg} at (resp. after) the specified railway time (which can be in any format). You can only schedule one event this way. (uses the new lines-internal scheduler)
Note: Using the lines scheduler is preferred over using `interrupt()`, as it's more performant and safer to use.
## Events
The event table is a variable created locally by the component being triggered. It is a table with the following format:
```lua
event = {
type = "<event type>",
<event type> = true,
--additional event-specific content
}
``` ```
You can check the event type by using the following:
```lua
if event.type == "wanted" then
--do stuff
end
```
or
```lua
if event.wanted then
--do stuff
end
```
where `wanted` is the event type to check for.
See the "Active Components" section below for details on the various event types as not all of them are applicable to all components.
## Components
Atlac components introduce automation-capable components that fall within two categories:
- Active Components are components that are able to run Lua code, triggered by specific events.
- Passive Components can't perform actions themselves. Their state can be read and set by active components or manually by the player.
### Lua ATC Rails
Lua ATC rails are the only components that can actually interface with trains. The following event types are available to the Lua ATC rails:
- `{type="train", train=true, id="<train_id>"}`
* This event is fired when a train enters the rail. The field `id` is the unique train ID, which is 6-digit random numerical string. * This event is fired when a train enters the rail. The field `id` is the unique train ID, which is 6-digit random numerical string.
* If the world contains trains from an older advtrains version, this string may be longer and contain a dot `.` * If the world contains trains from an older advtrains version, this string may be longer and contain a dot `.`
- ```lua - `{type="int", int=true, msg=<message>}`
{type="int", int=true, msg=<message>}
```
* Fired when an interrupt set by the `interrupt` function runs out. `<message>` is the message passed to the interrupt function. * Fired when an interrupt set by the `interrupt` function runs out. `<message>` is the message passed to the interrupt function.
* For backwards compatiblity reasons, `<message>` is also contained in an `event.message` variable. * For backwards compatiblity reasons, `<message>` is also contained in an `event.message` variable.
- ```lua - `{type="ext_int", ext_int=true, message=<message>}`
{type="ext_int", ext_int=true, message=<message>}
```
* Fired when another node called `interrupt_pos` on this position. `message` is the message passed to the interrupt_pos function. * Fired when another node called `interrupt_pos` on this position. `message` is the message passed to the interrupt_pos function.
- ```lua - `{type="digiline", digiline=true, channel=<channel>, msg=<message>}`
{type="digiline", digiline=true, channel=<channel>, msg=<message>}
```
* Fired when the controller receives a digiline message. * Fired when the controller receives a digiline message.
##### Basic Lua Rail Functions and Variables #### Basic Lua Rail Functions and Variables
In addition to the above environment functions, the following functions are available to whilst the train is in contact with the LuaATC rail: In addition to the above environment functions, the following functions are available to whilst the train is in contact with the LuaATC rail:
- `atc_send(<atc_command>)` - `atc_send(<atc_command>)`
@ -215,7 +248,7 @@ In addition to the above environment functions, the following functions are avai
Sets the "Routingcode" property of the train (a string). Sets the "Routingcode" property of the train (a string).
The interlocking system uses this property for Automatic Routesetting. The interlocking system uses this property for Automatic Routesetting.
##### Shunting Functions and Variables #### Shunting Functions and Variables
There are several functions available especially for shunting operations. Some of these functions make use of Freight Codes (FC) set in the Wagon Properties of each wagon and/or locomotive: There are several functions available especially for shunting operations. Some of these functions make use of Freight Codes (FC) set in the Wagon Properties of each wagon and/or locomotive:
- `split_at_index(index, atc_command)` - `split_at_index(index, atc_command)`
@ -241,8 +274,6 @@ There are several functions available especially for shunting operations. Some o
Result: `"foo" "foo" "foo"` and `"foo" "bar" "bar"` Result: `"foo" "foo" "foo"` and `"foo" "bar" "bar"`
The function returns `"foo"` in this case. The function returns `"foo"` in this case.
- `split_off_locomotive(command, len)` - `split_off_locomotive(command, len)`
Splits off the locomotives at the front of the train, which are Splits off the locomotives at the front of the train, which are
identified by an empty FC. `command` specifies the ATC command to be identified by an empty FC. `command` specifies the ATC command to be
@ -269,10 +300,56 @@ There are several functions available especially for shunting operations. Some o
Unsets autocouple mode Unsets autocouple mode
Deprecated: Deprecated:
- `set_shunt()`, `unset_shunt()` - `set_shunt()`, `unset_shunt()`
deprecated aliases for set_autocouple() and unset_autocouple(), will be removed from a later release. deprecated aliases for set_autocouple() and unset_autocouple(), will be removed from a later release.
##### Timetable Automation
#### Interlocking
This additional function is available when advtrains_interlocking is enabled:
- `atc_set_disable_ars(boolean)`
Disables (true) or enables (false) the use of ARS for this train. The train will not trigger ARS (automatic route setting) on signals then.
Note: If you want to disable ARS from an approach callback, the call to `atc_set_disable_ars(true)` *must* happen during the approach callback, and may not be deferred to an interrupt(). Else the train might trigger an ARS before the interrupt fires.
#### Approach callbacks
The LuaATC interface provides a way to hook into the approach callback system, which is for example used in the TSR rails (provided by advtrains_interlocking) or the station tracks (provided by advtrains_lines). However, for compatibility reasons, this behavior needs to be explicitly enabled.
Enabling the receiving of approach events works by setting a variable in the local environment of the ATC rail, by inserting the following code:
```lua
__approach_callback_mode = 1
-- to receive approach callbacks only in arrow direction
-- or alternatively
__approach_callback_mode = 2
-- to receive approach callbacks in both directions
```
The following event will be emitted when a train approaches:
```lua
{type="approach", approach=true, id="<train_id>"}
```
Please note these important considerations when using approach callbacks:
- Approach events might be generated multiple times for the same approaching train. If you are using atc_set_lzb_tsr(), you need to call this function on every run of the approach callback, even if you issued it before for the same train.
- A reference to the train is available while executing this event, so that functions such as atc_send() or atc_set_text_outside() can be called. On any consecutive interrupts, that reference will no longer be available until the train enters the track ("train" event)
- Unlike all other callbacks, approach callbacks are executed synchronous during the train step. This may cause unexpected side effects when performing certain actions (such as switching turnouts, setting signals/routes) from inside such a callback. I strongly encourage you to only run things that are absolutely necessary at this point in time, and defer anything else to an interrupt(). Be aware that certain things might trigger unexpected behavior.
Operations that are safe to execute in approach callbacks:
- anything related only to the global environment (setting things in S)
- digiline_send()
- atc_set_text_*()
- atc_set_lzb_tsr() (see below)
In the context of approach callbacks, one more function is available:
- `atc_set_lzb_tsr(speed)`
Impose a Temporary Speed Restriction at the location of this rail, making the train pass this rail at the specified speed. (Causes the same behavior as the TSR rail)
#### Timetable Automation
The advtrains_line_automation component adds a few contraptions that should make creating timeable systems easier. The advtrains_line_automation component adds a few contraptions that should make creating timeable systems easier.
Part of its functionality is also available in LuaATC: Part of its functionality is also available in LuaATC:
@ -284,12 +361,12 @@ All Railway Time functions are included as documented in https://advtrains.de/wi
- `schedule_in(rw_dtime, msg)` - `schedule_in(rw_dtime, msg)`
Schedules the following event `{type="schedule", schedule=true, msg=msg}` at (resp. after) the specified railway time (which can be in any format). You can only schedule one event this way. Uses the new lines-internal scheduler. Schedules the following event `{type="schedule", schedule=true, msg=msg}` at (resp. after) the specified railway time (which can be in any format). You can only schedule one event this way. Uses the new lines-internal scheduler.
#### 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. It can also be connected to by the`digilines` mod. This simple node executes its actions when punched. It can be used to change a switch and update the corresponding signals or similar applications. It can also be connected to by the`digilines` mod.
The event fired is `{type="punch", punch=true}` by default. In case of an interrupt or a digiline message, the events are similar to the ones of the ATC rail. The event fired is `{type="punch", punch=true}` by default. In case of an interrupt or a digiline message, the events are similar to the ones of the ATC rail.
#### Init code ### Init code
The initialization code is not a component as such, but rather a part of the whole environment. It can (and should) be used to make definitions that other components can refer to. The initialization code is not a component as such, but rather a part of the whole environment. It can (and should) be used to make definitions that other components can refer to.
A basic example function to define behavior for trains in stations: A basic example function to define behavior for trains in stations:
```lua ```lua
@ -304,12 +381,12 @@ function F.station(station_name)
atc_send("OCD1SM") atc_send("OCD1SM")
end end
end end
```` ```
The corresponding Lua ATC Rail(s) would then contain the following or similar: The corresponding Lua ATC Rail(s) would then contain the following or similar:
````lua ```lua
F.station("Main Station") F.station("Main Station")
```` ```
The init code is run whenever the F table needs to be refilled with data. This is the case on server startup and whenever the init code is changed and you choose to run it. The init code is run whenever the F table needs to be refilled with data. This is the case on server startup and whenever the init code is changed and you choose to run it.
The event table of the init code is always `{type="init", init=true}` and can not be anything else. The event table of the init code is always `{type="init", init=true}` and can not be anything else.
@ -322,15 +399,18 @@ Each node below has been mapped to specific "states":
#### Signals #### Signals
The red/green light signals `advtrains:signal_on/off` are interfaceable. Others such as `advtrains:retrosignal_on/off` are not. If advtrains_interlocking is enabled, trains will obey the signal if the influence point is set. The red/green light signals `advtrains:signal_on/off` are interfaceable. Others such as `advtrains:retrosignal_on/off` are not. If advtrains_interlocking is enabled, trains will obey the signal if the influence point is set.
- "green" - Signal shows green light - "green" - Signal shows green light
- "red" - Signal shows red light - "red" - Signal shows red light
#### Switches/Turnouts #### Switches/Turnouts
All default rail switches are interfaceable, independent of orientation. All default rail switches are interfaceable, independent of orientation.
- "cr" The switch is set in the direction that is not straight. - "cr" The switch is set in the direction that is not straight.
- "st" The switch is set in the direction that is straight. - "st" The switch is set in the direction that is straight.
The "Y" and "3-Way" switches have custom states. Looking from the convergence point: The "Y" and "3-Way" switches have custom states. Looking from the convergence point:
- "l" The switch is set towards the left. - "l" The switch is set towards the left.
- "c" The switch is set towards the center (3-way only). - "c" The switch is set towards the center (3-way only).
- "r" The switch is set towards the right. - "r" The switch is set towards the right.
@ -338,10 +418,12 @@ The "Y" and "3-Way" switches have custom states. Looking from the convergence po
#### Mesecon Switch #### Mesecon Switch
The Mesecon switch can be switched using LuaAutomation. Note that this is not possible on levers or protected mesecon switches, only the unprotected full-node 'Switch' block `mesecons_switch:mesecon_switch_on/off`. The Mesecon switch can be switched using LuaAutomation. Note that this is not possible on levers or protected mesecon switches, only the unprotected full-node 'Switch' block `mesecons_switch:mesecon_switch_on/off`.
- "on" - the switch is switched on. - "on" - the switch is switched on.
- "off" - the switch is switched off. - "off" - the switch is switched off.
#### Andrew's Cross #### Andrew's Cross
- "on" - it blinks. - "on" - it blinks.
- "off" - it does not blink. - "off" - it does not blink.
@ -356,4 +438,3 @@ Use `setstate("Stn_P1_out", "green")` instead of `setstate(POS(1,2,3), "green")`
If `advtrains_interlocking` is enabled, PC-Naming can also be used to name interlocking signals for route setting via the `set_route()` functions. If `advtrains_interlocking` is enabled, PC-Naming can also be used to name interlocking signals for route setting via the `set_route()` functions.
**Important**: The "Signal Name" field in the signalling formspec is completely independent from PC-Naming and can't be used to look up the position. You need to explicitly use the PC-Naming tool. **Important**: The "Signal Name" field in the signalling formspec is completely independent from PC-Naming and can't be used to look up the position. You need to explicitly use the PC-Naming tool.
--TODO: Ein paar mehr Codebeispiele wären schön, insbesondere mit os.date und so...

View File

@ -109,8 +109,9 @@ function ac.run_in_env(pos, evtdata, customfct_p)
atwarn("LuaAutomation component at",ph,": Not an existing environment: "..(nodetbl.env or "<nil>")) atwarn("LuaAutomation component at",ph,": Not an existing environment: "..(nodetbl.env or "<nil>"))
return false return false
end end
local env = atlatc.envs[nodetbl.env]
if not nodetbl.code or nodetbl.code=="" then if not nodetbl.code or nodetbl.code=="" then
atwarn("LuaAutomation component at",ph,": No code to run! (insert -- to suppress warning)") env:log("warning", "LuaAutomation component at",ph,": No code to run! (insert -- to suppress warning)")
return false return false
end end
@ -121,6 +122,18 @@ function ac.run_in_env(pos, evtdata, customfct_p)
assert(t >= 0) assert(t >= 0)
atlatc.interrupt.add(t, pos, {type="int", int=true, message=imesg, msg=imesg}) --Compatiblity "message" field. atlatc.interrupt.add(t, pos, {type="int", int=true, message=imesg, msg=imesg}) --Compatiblity "message" field.
end end
customfct.interrupt_safe=function(t, imesg)
assertt(t, "number")
assert(t >= 0)
if atlatc.interrupt.has_at_pos(pos) then
return false
end
atlatc.interrupt.add(t, pos, {type="int", int=true, message=imesg, msg=imesg}) --Compatiblity "message" field.
return true
end
customfct.clear_interrupts=function()
atlatc.interrupt.clear_ints_at_pos(pos)
end
-- add digiline_send function, if digiline is loaded -- add digiline_send function, if digiline is loaded
if minetest.global_exists("digiline") then if minetest.global_exists("digiline") then
customfct.digiline_send=function(channel, msg) customfct.digiline_send=function(channel, msg)
@ -141,15 +154,20 @@ function ac.run_in_env(pos, evtdata, customfct_p)
end end
local datain=nodetbl.data or {} local datain=nodetbl.data or {}
local succ, dataout = atlatc.envs[nodetbl.env]:execute_code(datain, nodetbl.code, evtdata, customfct) local succ, dataout = env:execute_code(datain, nodetbl.code, evtdata, customfct)
if succ then if succ then
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) env:log("error", "LuaATC component 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", "LuaATC component, ERROR:"..dataout)
end end
--TODO temporary
--if customfct.atc_id then
-- advtrains.drb_dump(customfct.atc_id)
-- error("Debug: LuaATC error hit!")
--end
end end
if meta then if meta then
meta:set_string("formspec", ac.getform(pos, meta)) meta:set_string("formspec", ac.getform(pos, meta))

View File

@ -5,7 +5,10 @@
--Using subtable --Using subtable
local r={} local r={}
function r.fire_event(pos, evtdata) -- Note on appr_internal:
-- The Approach callback is a special corner case: the train is not on the node, and it is executed synchronized
-- (in the train step right during LZB traversal). We therefore need access to the train id and the lzbdata table
function r.fire_event(pos, evtdata, appr_internal)
local ph=minetest.pos_to_string(pos) local ph=minetest.pos_to_string(pos)
local railtbl = atlatc.active.nodes[ph] local railtbl = atlatc.active.nodes[ph]
@ -15,37 +18,34 @@ function r.fire_event(pos, evtdata)
return return
end end
local arrowconn = railtbl.arrowconn
if not arrowconn then
atwarn("LuaAutomation ATC interface rail at",ph,": Incomplete Data! Please visit position and click 'Save'!")
return
end
--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
--If no train, then return false. --If no train, then return false.
local train_id=advtrains.get_train_at_pos(pos)
local train, atc_arrow, tvel -- try to get the train from the event data
if train_id then train=advtrains.trains[train_id] end -- This workaround is required because the callback is one step delayed, and a fast train may have already left the node.
if train then -- Also used for approach callback
if not train.path then local train_id = evtdata._train_id
--we happened to get in between an invalidation step local atc_arrow = evtdata._train_arrow
--delay local train, tvel
atlatc.interrupt.add(0,pos,evtdata)
return if train_id then
end train=advtrains.trains[train_id]
local index = advtrains.path_lookup(train, pos) -- speed
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 +!")
end
atc_arrow = iconnid == 1
tvel=train.velocity tvel=train.velocity
-- if still no train_id available, try to get the train at my position
else
train_id=advtrains.get_train_at_pos(pos)
if train_id then
train=advtrains.trains[train_id]
advtrains.train_ensure_init(train_id, train)
-- look up atc_arrow
local index = advtrains.path_lookup(train, pos)
atc_arrow = (train.path_cn[index] == 1)
-- speed
tvel=train.velocity
end
end end
local customfct={ local customfct={
atc_send = function(cmd) atc_send = function(cmd)
if not train_id then return false end if not train_id then return false end
@ -92,12 +92,13 @@ function r.fire_event(pos, evtdata)
advtrains.train_step_fc(train) advtrains.train_step_fc(train)
end, end,
set_shunt = function() set_shunt = function()
-- enable shunting mode
if not train_id then return false end if not train_id then return false end
train.autocouple = true train.is_shunt = true
end, end,
unset_shunt = function() unset_shunt = function()
if not train_id then return false end if not train_id then return false end
train.autocouple = nil train.is_shunt = nil
end, end,
set_autocouple = function () set_autocouple = function ()
if not train_id then return false end if not train_id then return false end
@ -106,7 +107,7 @@ function r.fire_event(pos, evtdata)
unset_autocouple = function () unset_autocouple = function ()
if not train_id then return false end if not train_id then return false end
train.autocouple = nil train.autocouple = nil
end, end,
set_line = function(line) set_line = function(line)
if type(line)~="string" and type(line)~="number" then if type(line)~="string" and type(line)~="number" then
return false return false
@ -150,45 +151,89 @@ function r.fire_event(pos, evtdata)
advtrains.trains[train_id].text_inside=text advtrains.trains[train_id].text_inside=text
return true return true
end, end,
atc_set_lzb_tsr = function(speed)
if not appr_internal then
error("atc_set_lzb_tsr() can only be used during 'approach' events!")
end
assert(tonumber(speed), "Number expected!")
local index = appr_internal.index
advtrains.lzb_add_checkpoint(train, index, speed, nil)
return true
end,
} }
-- interlocking specific
if advtrains.interlocking then
customfct.atc_set_ars_disable = function(value)
advtrains.interlocking.ars_set_disable(train, value)
end
end
atlatc.active.run_in_env(pos, evtdata, customfct) atlatc.active.run_in_env(pos, evtdata, customfct)
end end
if minetest.get_modpath("advtrains_train_track") ~= nil then advtrains.register_tracks("default", {
advtrains.register_tracks("default", { nodename_prefix="advtrains_luaautomation:dtrack",
nodename_prefix="advtrains_luaautomation:dtrack", texture_prefix="advtrains_dtrack_atc",
texture_prefix="advtrains_dtrack_atc", models_prefix="advtrains_dtrack",
models_prefix="advtrains_dtrack", models_suffix=".b3d",
models_suffix=".b3d", shared_texture="advtrains_dtrack_shared_atc.png",
shared_texture="advtrains_dtrack_shared_atc.png", description=atltrans("LuaAutomation ATC Rail"),
description=atltrans("LuaAutomation ATC Rail"), formats={},
formats={}, get_additional_definiton = function(def, preset, suffix, rotation)
get_additional_definiton = function(def, preset, suffix, rotation) return {
return { after_place_node = atlatc.active.after_place_node,
after_place_node = atlatc.active.after_place_node, after_dig_node = atlatc.active.after_dig_node,
after_dig_node = atlatc.active.after_dig_node,
on_receive_fields = function(pos, ...) on_receive_fields = function(pos, ...)
atlatc.active.on_receive_fields(pos, ...) atlatc.active.on_receive_fields(pos, ...)
--set arrowconn (for ATC)
local ph=minetest.pos_to_string(pos) --set arrowconn (for ATC)
local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes) local ph=minetest.pos_to_string(pos)
atlatc.active.nodes[ph].arrowconn=conns[1].c local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes)
atlatc.active.nodes[ph].arrowconn=conns[1].c
end,
advtrains = {
on_train_enter = function(pos, train_id, train, index)
--do async. Event is fired in train steps
atlatc.interrupt.add(0, pos, {type="train", train=true, id=train_id,
_train_id = train_id, _train_arrow = (train.path_cn[index] == 1)})
end, end,
advtrains = atlatc.active.trackdef_advtrains_defs, on_train_approach = function(pos, train_id, train, index, has_entered, lzbdata)
luaautomation = { -- Insert an event only if the rail indicated that it supports approach callbacks
fire_event=r.fire_event local ph=minetest.pos_to_string(pos)
local railtbl = atlatc.active.nodes[ph]
-- uses a "magic variable" in the local environment of the node
-- This hack is necessary because code might not be prepared to get approach events...
if railtbl and railtbl.data and railtbl.data.__approach_callback_mode then
local acm = railtbl.data.__approach_callback_mode
local in_arrow = (train.path_cn[index] == 1)
if acm==2 or (acm==1 and in_arrow) then
local evtdata = {type="approach", approach=true, id=train_id, has_entered = has_entered,
_train_id = train_id, _train_arrow = in_arrow} -- reuses code from train_enter
-- This event is *required* to run synchronously, because it might set the ars_disable flag on the train and add LZB checkpoints,
-- although this is generally discouraged because this happens right in a train step
-- At this moment, I am not aware whether this may cause side effects, and I must encourage users not to do expensive calculations here.
r.fire_event(pos, evtdata, {train_id = train_id, train = train, index = index, lzbdata = lzbdata})
end
end
end,
},
luaautomation = {
fire_event=r.fire_event
},
digiline = {
receptor = {},
effector = {
action = atlatc.active.on_digiline_receive
}, },
digiline = { },
receptor = {}, }
effector = { end,
action = atlatc.active.on_digiline_receive }, advtrains.trackpresets.t_30deg_straightonly)
},
},
}
end,
}, advtrains.trackpresets.t_30deg_straightonly)
end
atlatc.rail = r atlatc.rail = r

View File

@ -43,12 +43,78 @@ core.register_chatcommand("env_create", {
privs = {atlatc=true}, privs = {atlatc=true},
func = function(name, param) func = function(name, param)
if not param or param=="" then return false, "Name required!" end if not param or param=="" then return false, "Name required!" end
if string.find(param, "[^a-zA-Z0-9-_]") then return false, "Invalid name (only common characters)" end
if atlatc.envs[param] then return false, "Environment already exists!" end if atlatc.envs[param] then return false, "Environment already exists!" end
atlatc.envs[param] = atlatc.env_new(param) atlatc.envs[param] = atlatc.env_new(param)
atlatc.envs[param].subscribers = {name}
return true, "Created environment '"..param.."'. Use '/env_setup "..param.."' to define global initialization code, or start building LuaATC components!" return true, "Created environment '"..param.."'. Use '/env_setup "..param.."' to define global initialization code, or start building LuaATC components!"
end, end,
}) })
core.register_chatcommand("env_subscribe", {
params = "<environment name>",
description = "Subscribe to the log of an Advtrains LuaATC environment",
privs = {atlatc=true},
func = function(name, param)
local env=atlatc.envs[param]
if not env then return false,"Invalid environment name!" end
for _,pname in ipairs(env.subscribers) do
if pname==name then
return false, "Already subscribed!"
end
end
table.insert(env.subscribers, name)
return true, "Subscribed to environment '"..param.."'."
end,
})
core.register_chatcommand("env_unsubscribe", {
params = "<environment name>",
description = "Unubscribe to the log of an Advtrains LuaATC environment",
privs = {atlatc=true},
func = function(name, param)
local env=atlatc.envs[param]
if not env then return false,"Invalid environment name!" end
for index,pname in ipairs(env.subscribers) do
if pname==name then
table.remove(env.subscribers, index)
return true, "Successfully unsubscribed!"
end
end
return false, "Not subscribed to environment '"..param.."'."
end,
})
core.register_chatcommand("env_subscriptions", {
params = "[environment name]",
description = "List Advtrains LuaATC environments you are subscribed to (no parameters) or subscribers of an environment (giving an env name).",
privs = {atlatc=true},
func = function(name, param)
if not param or param=="" then
local none=true
for envname, env in pairs(atlatc.envs) do
for _,pname in ipairs(env.subscribers) do
if pname==name then
none=false
minetest.chat_send_player(name, envname)
end
end
end
if none then
return false, "Not subscribed to any!"
end
return true
end
local env=atlatc.envs[param]
if not env then return false,"Invalid environment name!" end
local none=true
for index,pname in ipairs(env.subscribers) do
none=false
minetest.chat_send_player(name, pname)
end
if none then
return false, "No subscribers!"
end
return true
end,
})
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)

View File

@ -33,12 +33,12 @@ local env_proto={
self.sdata=data.sdata and atlatc.remove_invalid_data(data.sdata) or {} self.sdata=data.sdata and atlatc.remove_invalid_data(data.sdata) or {}
self.fdata={} self.fdata={}
self.init_code=data.init_code or "" self.init_code=data.init_code or ""
self.step_code=data.step_code or "" self.subscribers=data.subscribers or {}
end, end,
save = function(self) save = function(self)
-- throw any function values out of the sdata table -- throw any function values out of the sdata table
self.sdata = atlatc.remove_invalid_data(self.sdata) self.sdata = atlatc.remove_invalid_data(self.sdata)
return {sdata = self.sdata, init_code=self.init_code, step_code=self.step_code} return {sdata = self.sdata, init_code=self.init_code, subscribers=self.subscribers}
end, end,
} }
@ -50,14 +50,6 @@ local safe_globals = {
"tonumber", "tostring", "type", "unpack", "_VERSION" "tonumber", "tostring", "type", "unpack", "_VERSION"
} }
--print is actually minetest.chat_send_all()
--using advtrains.print_concat_table because it's cool
local function safe_print(t, ...)
local str=advtrains.print_concat_table({t, ...})
minetest.log("action", "[atlatc] "..str)
minetest.chat_send_all(str)
end
local function safe_date(f, t) local function safe_date(f, t)
if not f then if not f then
-- fall back to old behavior -- fall back to old behavior
@ -95,7 +87,6 @@ local mp=minetest.get_modpath("advtrains_luaautomation")
local static_env = { local static_env = {
--core LUA functions --core LUA functions
print = safe_print,
string = { string = {
byte = string.byte, byte = string.byte,
char = string.char, char = string.char,
@ -252,7 +243,6 @@ for _, name in pairs(safe_globals) do
static_env[name] = _G[name] static_env[name] = _G[name]
end end
--The environment all code calls get is a table that has set static_env as metatable. --The environment all code calls get is a table that has set static_env as metatable.
--In general, every variable is local to a single code chunk, but kept persistent over code re-runs. Data is also saved, but functions and userdata and circular references are removed --In general, every variable is local to a single code chunk, but kept persistent over code re-runs. Data is also saved, but functions and userdata and circular references are removed
--Init code and step code's environments are not saved --Init code and step code's environments are not saved
@ -265,6 +255,14 @@ local proxy_env={}
-- returns: true, fenv if successful; nil, error if error -- returns: true, fenv if successful; nil, error if error
function env_proto:execute_code(localenv, code, evtdata, customfct) function env_proto:execute_code(localenv, code, evtdata, customfct)
-- create us a print function specific for this environment
if not self.safe_print_func then
local myenv = self
self.safe_print_func = function(...)
myenv:log("info", ...)
end
end
local metatbl ={ local metatbl ={
__index = function(t, i) __index = function(t, i)
if i=="S" then if i=="S" then
@ -277,6 +275,8 @@ function env_proto:execute_code(localenv, code, evtdata, customfct)
return customfct[i] return customfct[i]
elseif localenv and localenv[i] then elseif localenv and localenv[i] then
return localenv[i] return localenv[i]
elseif i=="print" then
return self.safe_print_func
end end
return static_env[i] return static_env[i]
end, end,
@ -306,35 +306,39 @@ function env_proto:run_initcode()
if self.init_code and self.init_code~="" then if self.init_code and self.init_code~="" then
local old_fdata=self.fdata local old_fdata=self.fdata
self.fdata = {} self.fdata = {}
atprint("[atlatc]Running initialization code for environment '"..self.name.."'") --atprint("[atlatc]Running initialization code for environment '"..self.name.."'")
local succ, err = self:execute_code({}, self.init_code, {type="init", init=true}) local succ, err = self:execute_code({}, self.init_code, {type="init", init=true})
if not succ then if not succ then
atwarn("[atlatc]Executing InitCode for '"..self.name.."' failed:"..err) self:log("error", "Executing InitCode for '"..self.name.."' failed:"..err)
self.init_err=err self.init_err=err
if old_fdata then if old_fdata then
self.fdata=old_fdata self.fdata=old_fdata
atwarn("[atlatc]The 'F' table has been restored to the previous state.") self:log("warning", "The 'F' table has been restored to the previous state.")
end end
end end
end end
end end
function env_proto:run_stepcode()
if self.step_code and self.step_code~="" then -- log to environment subscribers. severity can be "error", "warning" or "info" (used by internal print)
local succ, err = self:execute_code({}, self.step_code, nil, {}) function env_proto:log(severity, ...)
if not succ then local text=advtrains.print_concat_table({"[atlatc "..self.name.." "..severity.."]", ...})
--TODO minetest.log("action", text)
end for _, pname in ipairs(self.subscribers) do
minetest.chat_send_player(pname, text)
end end
end end
-- env.subscribers table may be directly altered by callers.
--- class interface --- class interface
function atlatc.env_new(name) function atlatc.env_new(name)
local newenv={ local newenv={
name=name, name=name,
init_code="", init_code="",
step_code="", sdata={},
sdata={} subscribers={},
} }
setmetatable(newenv, {__index=env_proto}) setmetatable(newenv, {__index=env_proto})
return newenv return newenv
@ -351,11 +355,6 @@ function atlatc.run_initcode()
env:run_initcode() env:run_initcode()
end end
end end
function atlatc.run_stepcode()
for envname, env in pairs(atlatc.envs) do
env:run_stepcode()
end
end

View File

@ -16,6 +16,30 @@ function iq.save()
return {queue = queue, timer=timer} return {queue = queue, timer=timer}
end end
function iq.has_at_pos(pos)
for i=1,#queue do
local qe=queue[i]
if vector.equals(pos, qe.p) then
return true
end
end
return false
end
function iq.clear_ints_at_pos(pos)
local i=1
while i<=#queue do
local qe=queue[i]
if not qe then
table.remove(queue, i)
elseif vector.equals(pos, qe.p) and (qe.e.int or qe.e.ext_int) then
table.remove(queue, i)
else
i=i+1
end
end
end
function iq.add(t, pos, evtdata) function iq.add(t, pos, evtdata)
queue[#queue+1]={t=t+timer, p=pos, e=evtdata} queue[#queue+1]={t=t+timer, p=pos, e=evtdata}
run=true run=true
@ -23,13 +47,14 @@ end
function iq.mainloop(dtime) function iq.mainloop(dtime)
timer=timer + math.min(dtime, 0.2) timer=timer + math.min(dtime, 0.2)
for i=1,#queue do local i=1
while i<=#queue do
local qe=queue[i] local qe=queue[i]
if not qe then if not qe then
table.remove(queue, i) table.remove(queue, i)
i=i-1
elseif timer>qe.t then elseif timer>qe.t then
local pos, evtdata=queue[i].p, queue[i].e table.remove(queue, i)
local pos, evtdata=qe.p, qe.e
local node=advtrains.ndb.get_node(pos) local node=advtrains.ndb.get_node(pos)
local ndef=minetest.registered_nodes[node.name] local ndef=minetest.registered_nodes[node.name]
if ndef and ndef.luaautomation and ndef.luaautomation.fire_event then if ndef and ndef.luaautomation and ndef.luaautomation.fire_event then
@ -37,8 +62,8 @@ function iq.mainloop(dtime)
else else
atwarn("[atlatc][interrupt] Couldn't run event",evtdata.type,"on",pos,", something wrong with the node",node) atwarn("[atlatc][interrupt] Couldn't run event",evtdata.type,"on",pos,", something wrong with the node",node)
end end
table.remove(queue, i) else
i=i-1 i=i+1
end end
end end
end end

View File

@ -7,7 +7,7 @@ Displays
Mesecon Transmitter Mesecon Transmitter
Those passive components can also be used inside interlocking systems. Those passive components can also be used inside interlocking systems.
All passive components have a table called 'advtrains' in their node definition and have the group 'save_in_nodedb' set, so they work in unloaded chunks. All passive components have a table called 'advtrains' in their node definition and have the group 'save_in_at_nodedb' set, so they work in unloaded chunks.
Example for a switch: Example for a switch:
advtrains = { advtrains = {
getstate = function(pos, node) getstate = function(pos, node)

View File

@ -6,14 +6,14 @@
local setaspectf = function(rot) local setaspectf = function(rot)
return function(pos, node, asp) return function(pos, node, asp)
if not asp.main.free then if asp.main == 0 then
if asp.shunt.free then if asp.shunt then
advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_shunt_"..rot, param2 = node.param2}) advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_shunt_"..rot, param2 = node.param2})
else else
advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_danger_"..rot, param2 = node.param2}) advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_danger_"..rot, param2 = node.param2})
end end
else else
if asp.dst.free and asp.main.speed == -1 then if asp.dst ~= 0 and asp.main == -1 then
advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_free_"..rot, param2 = node.param2}) advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_free_"..rot, param2 = node.param2})
else else
advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_slow_"..rot, param2 = node.param2}) advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_slow_"..rot, param2 = node.param2})
@ -22,19 +22,12 @@ local setaspectf = function(rot)
end end
end end
local suppasp = { local suppasp = {
main = { main = {0, 6, -1},
free = nil, dst = {0, false},
speed = {6, -1}, shunt = nil,
}, proceed_as_main = true,
dst = {
free = nil,
speed = nil,
},
shunt = {
free = nil,
proceed_as_main = true,
},
info = { info = {
call_on = false, call_on = false,
dead_end = false, dead_end = false,
@ -45,7 +38,7 @@ local suppasp = {
--Rangiersignal --Rangiersignal
local setaspectf_ra = function(rot) local setaspectf_ra = function(rot)
return function(pos, node, asp) return function(pos, node, asp)
if asp.shunt.free then if asp.shunt then
advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:ra_shuntd_"..rot, param2 = node.param2}) advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:ra_shuntd_"..rot, param2 = node.param2})
else else
advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:ra_danger_"..rot, param2 = node.param2}) advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:ra_danger_"..rot, param2 = node.param2})
@ -58,17 +51,11 @@ local setaspectf_ra = function(rot)
end end
local suppasp_ra = { local suppasp_ra = {
main = { main = { false },
free = true, dst = { false },
}, shunt = nil,
dst = { proceed_as_main = false,
free = nil,
speed = nil,
},
shunt = {
free = nil,
proceed_as_main = false,
},
info = { info = {
call_on = false, call_on = false,
dead_end = false, dead_end = false,
@ -90,9 +77,9 @@ for _, rtab in ipairs({
local rot = rtab.rot local rot = rtab.rot
for typ, prts in pairs({ for typ, prts in pairs({
danger = {asp = advtrains.interlocking.DANGER, n = "slow", ici=true}, danger = {asp = advtrains.interlocking.DANGER, n = "slow", ici=true},
slow = {asp = { main = { free = true, speed = 6 }, shunt = {proceed_as_main = true}} , n = "free"}, slow = {asp = { main = 6, proceed_as_main = true} , n = "free"},
free = {asp = { main = { free = true, speed = -1 }, shunt = {proceed_as_main = true}} , n = "shunt"}, free = {asp = { main = -1, proceed_as_main = true} , n = "shunt"},
shunt = {asp = { main = {free = false}, shunt = {free = true} } , n = "danger"}, shunt = {asp = { main = 0, shunt = true} , n = "danger"},
}) do }) do
minetest.register_node("advtrains_signals_ks:hs_"..typ.."_"..rot, { minetest.register_node("advtrains_signals_ks:hs_"..typ.."_"..rot, {
description = "Ks Main Signal", description = "Ks Main Signal",
@ -136,8 +123,8 @@ for _, rtab in ipairs({
--Rangiersignale: --Rangiersignale:
for typ, prts in pairs({ for typ, prts in pairs({
danger = {asp = { main = {free = true}, shunt = {free = false} }, n = "shuntd", ici=true}, danger = {asp = { main = false, shunt = false }, n = "shuntd", ici=true},
shuntd = {asp = { main = {free = true}, shunt = {free = true} } , n = "danger"}, shuntd = {asp = { main = false, shunt = true } , n = "danger"},
}) do }) do
minetest.register_node("advtrains_signals_ks:ra_"..typ.."_"..rot, { minetest.register_node("advtrains_signals_ks:ra_"..typ.."_"..rot, {
description = "Ks Shunting Signal", description = "Ks Shunting Signal",
@ -181,13 +168,14 @@ for _, rtab in ipairs({
--Schilder: --Schilder:
for typ, prts in pairs({ for typ, prts in pairs({
-- Speed restrictions: -- Speed restrictions:
["8"] = {asp = { main = {free = true, speed = 8}, shunt = {free = true} }, n = "12", ici=true}, ["8"] = {asp = { main = 8, shunt = true }, n = "12", ici=true},
["12"] = {asp = { main = {free = true, speed = 12}, shunt = {free = true} }, n = "16"}, ["12"] = {asp = { main = 12, shunt = true }, n = "16"},
["16"] = {asp = { main = {free = true, speed = 16}, shunt = {free = true} }, n = "e"}, ["16"] = {asp = { main = 16, shunt = true }, n = "e"},
-- Speed restriction lifted -- Speed restriction lifted
["e"] = {asp = { main = {free = true, speed = -1}, shunt = {free = true} }, n = "hfs"}, ["e"] = {asp = { main = -1, shunt = true }, n = "hfs"},
-- Halt for shunt moves: -- Halt for shunt moves:
["hfs"] = {asp = { main = {free = true}, shunt = {free = false} }, n = "8"}, ["hfs"] = {asp = { main = false, shunt = false }, n = "pam"},
["pam"] = {asp = { main = -1, shunt = false, proceed_as_main = true}, n = "8"},
}) do }) do
minetest.register_node("advtrains_signals_ks:sign_"..typ.."_"..rot, { minetest.register_node("advtrains_signals_ks:sign_"..typ.."_"..rot, {
description = "Signal Sign", description = "Signal Sign",

View File

@ -1,5 +1,5 @@
-- Ks Signals for advtrains -- Ks Signals for advtrains
-- will implement the advtrains signal API (which does not exist yet) -- will implement the advtrains signal API
local function place_degrotate(pos, placer, itemstack, pointed_thing) local function place_degrotate(pos, placer, itemstack, pointed_thing)
local yaw = placer:get_look_horizontal() local yaw = placer:get_look_horizontal()

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

View File

@ -72,12 +72,15 @@ If the train drives in the 'wrong' direction, stop and reverse; independently ac
I<8 S8 ; I<8 S8 ;
If the train is slower than 8, accelerate to 8. If the train is slower than 8, accelerate to 8.
# ATC controller operation modes # Interlocking
static: Only give 1 static command.
mesecon: Give 2 different commands depending on if the controller is mesecon-powered or not With advtrains_interlocking, there's one more available command:
digiline: Don't give any commands by itself. When a train passes, a digiline message in the form of "[+/-][speed]" is sent on the set channel (where +/- means the same as with conditions). Any digiline message sent to the controller will be interpreted as ATC command and sent to the train.
** the latter two are not yet implemented. A0
Disable ARS on the train.
A1
Enable ARS on the train.
When disabled, the train will not trigger automatic route setting on signals based on ARS.
# Persistence # Persistence
ATC controllers that are configured as 'static' or 'mesecon' are persistent over mapblock unloads and will even command the train when the mapblock is unloaded. This is not possible with digilines since these do not work in unloaded mapchunks. ATC controllers that are configured as 'static' or 'mesecon' are persistent over mapblock unloads and will even command the train when the mapblock is unloaded. This is not possible with digilines since these do not work in unloaded mapchunks.

View File

@ -4,7 +4,7 @@ edited by TenPlus1
Features: Features:
- Items are destroyed by lava - Items are destroyed by lava
- Items are pushed along by flowing water (thanks to QwertyMine3) - Items are pushed along by flowing water (thanks to QwertyMine3 and Gustavo6046)
- Items are removed after 900 seconds or the time that is specified by - Items are removed after 900 seconds or the time that is specified by
remove_items in minetest.conf (-1 disables it) remove_items in minetest.conf (-1 disables it)
- Particle effects added - Particle effects added

View File

@ -1,8 +1,10 @@
-- Minetest: builtin/item_entity.lua -- Minetest: builtin/item_entity.lua
-- override ice to make slippery for 0.4.16 -- override ice to make slippery for 0.4.16
minetest.override_item("default:ice", { if not minetest.raycast then
groups = {cracky = 3, puts_out_fire = 1, cools_lava = 1, slippery = 3}}) minetest.override_item("default:ice", {
groups = {cracky = 3, puts_out_fire = 1, cools_lava = 1, slippery = 3}})
end
function core.spawn_item(pos, item) function core.spawn_item(pos, item)
@ -27,23 +29,28 @@ local destroy_item = core.settings:get_bool("destroy_item") ~= false
-- water flow functions by QwertyMine3, edited by TenPlus1 -- water flow functions by QwertyMine3, edited by TenPlus1
local inv_roots = {
[0] = 1
}
local function to_unit_vector(dir_vector) local function to_unit_vector(dir_vector)
local inv_roots = {
[0] = 1,
[1] = 1,
[2] = 0.70710678118655,
[4] = 0.5,
[5] = 0.44721359549996,
[8] = 0.35355339059327
}
local sum = dir_vector.x * dir_vector.x + dir_vector.z * dir_vector.z local sum = dir_vector.x * dir_vector.x + dir_vector.z * dir_vector.z
local invr_sum = 0
-- find inverse square root if possible
if inv_roots[sum] ~= nil then
invr_sum = inv_roots[sum]
else
-- not found, compute and save the inverse square root
invr_sum = 1.0 / math.sqrt(sum)
inv_roots[sum] = invr_sum
end
return { return {
x = dir_vector.x * inv_roots[sum], x = dir_vector.x * invr_sum,
y = dir_vector.y, y = dir_vector.y,
z = dir_vector.z * inv_roots[sum] z = dir_vector.z * invr_sum
} }
end end
@ -63,6 +70,11 @@ end
local function quick_flow_logic(node, pos_testing, direction) local function quick_flow_logic(node, pos_testing, direction)
local node_testing = node_ok(pos_testing) local node_testing = node_ok(pos_testing)
local param2 = node.param2
if not minetest.registered_nodes[node.name].groups.liquid then
param2 = 0
end
if minetest.registered_nodes[node_testing.name].liquidtype ~= "flowing" if minetest.registered_nodes[node_testing.name].liquidtype ~= "flowing"
and minetest.registered_nodes[node_testing.name].liquidtype ~= "source" then and minetest.registered_nodes[node_testing.name].liquidtype ~= "source" then
@ -71,17 +83,17 @@ local function quick_flow_logic(node, pos_testing, direction)
local param2_testing = node_testing.param2 local param2_testing = node_testing.param2
if param2_testing < node.param2 then if param2_testing < param2 then
if (node.param2 - param2_testing) > 6 then if (param2 - param2_testing) > 6 then
return -direction return -direction
else else
return direction return direction
end end
elseif param2_testing > node.param2 then elseif param2_testing > param2 then
if (param2_testing - node.param2) > 6 then if (param2_testing - param2) > 6 then
return direction return direction
else else
return -direction return -direction
@ -92,13 +104,12 @@ local function quick_flow_logic(node, pos_testing, direction)
end end
-- reciprocal of the length of an unit square's diagonal
local DIAG_WEIGHT = 2 / math.sqrt(2)
local function quick_flow(pos, node) local function quick_flow(pos, node)
if not minetest.registered_nodes[node.name].groups.liquid then local x, z = 0.0, 0.0
return {x = 0, y = 0, z = 0}
end
local x, z = 0, 0
x = x + quick_flow_logic(node, {x = pos.x - 1, y = pos.y, z = pos.z},-1) x = x + quick_flow_logic(node, {x = pos.x - 1, y = pos.y, z = pos.z},-1)
x = x + quick_flow_logic(node, {x = pos.x + 1, y = pos.y, z = pos.z}, 1) x = x + quick_flow_logic(node, {x = pos.x + 1, y = pos.y, z = pos.z}, 1)
@ -131,6 +142,10 @@ local function add_effects(pos)
end end
local water_force = 0.8
local water_friction = 0.8
local dry_friction = 2.5
core.register_entity(":__builtin:item", { core.register_entity(":__builtin:item", {
initial_properties = { initial_properties = {
@ -270,7 +285,7 @@ core.register_entity(":__builtin:item", {
return true return true
end, end,
on_step = function(self, dtime) on_step = function(self, dtime, moveresult)
local pos = self.object:get_pos() local pos = self.object:get_pos()
@ -295,11 +310,22 @@ core.register_entity(":__builtin:item", {
self.def_inside = self.node_inside self.def_inside = self.node_inside
and core.registered_nodes[self.node_inside.name] and core.registered_nodes[self.node_inside.name]
self.node_under = minetest.get_node_or_nil({ -- get ground node for collision
x = pos.x, self.node_under = nil
y = pos.y + self.object:get_properties().collisionbox[2] - 0.05,
z = pos.z if moveresult.touching_ground then
})
for _, info in ipairs(moveresult.collisions) do
if info.axis == "y" then
self.node_under = core.get_node(info.node_pos)
break
end
end
end
self.def_under = self.node_under self.def_under = self.node_under
and core.registered_nodes[self.node_under.name] and core.registered_nodes[self.node_under.name]
@ -352,10 +378,39 @@ core.register_entity(":__builtin:item", {
-- water flowing -- water flowing
if def and def.liquidtype == "flowing" then if def and def.liquidtype == "flowing" then
-- force applies on acceleration over time, thus multiply
local force = water_force * dtime
-- friction applies on velocity over time, thus exponentiate
local friction = (1.0 + water_friction) ^ dtime
-- get flow velocity and current vel/acc state
local vec = quick_flow(pos, node) local vec = quick_flow(pos, node)
local a = self.object:get_acceleration()
self.object:set_acceleration({
x = a.x + vec.x * force,
y = a.y,
z = a.z + vec.z * force
})
-- apply friction to prevent items going too fast, and also to make
-- water flow override previous horizontal momentum more quickly
local v = self.object:get_velocity() local v = self.object:get_velocity()
self.object:set_velocity({x = vec.x, y = v.y, z = vec.z}) -- adjust friction for going against the current
local v_horz = { x = v.x, y = 0, z = v.z }
local v_dir = to_unit_vector(v_horz)
local flow_dot = v_dir.x * vec.x + v_dir.y * vec.y
-- also maps flow_dot from [-1,0] to [0.5,2.5]
friction = 1.0 + ((friction - 1.0) * (flow_dot + 1.5))
self.object:set_velocity({
x = v.x / friction,
y = v.y / friction,
z = v.z / friction
})
return return
end end
@ -412,11 +467,26 @@ core.register_entity(":__builtin:item", {
self.moving_state = is_moving self.moving_state = is_moving
self.slippery_state = is_slippery self.slippery_state = is_slippery
local a_curr = self.object:get_acceleration()
local v_curr = self.object:get_velocity()
if is_moving then if is_moving then
self.object:set_acceleration({x = 0, y = -gravity, z = 0})
self.object:set_acceleration({
x = a_curr.x,
y = a_curr.y - gravity,
z = a_curr.z
})
else else
self.object:set_acceleration({x = 0, y = 0, z = 0}) self.object:set_acceleration({x = 0, y = 0, z = 0})
self.object:set_velocity({x = 0, y = 0, z = 0})
-- preserve *some* velocity so items don't get stuck on the very ledges
-- of nodes once they move just enough to leave the hitbox of flowing water
self.object:set_velocity({
x = v_curr.x / dry_friction,
y = v_curr.y / dry_friction,
z = v_curr.z / dry_friction
})
end end
--Only collect items if not moving --Only collect items if not moving

View File

@ -13,7 +13,7 @@ This mod works by adding your new plant to the {growing=1} group and numbering t
### Changelog: ### Changelog:
- 1.46 - Added min/max default light settings, added lettuce and blackberries with food items (thanks OgelGames), added soya and vanilla (thanks Felfa), added tofu - 1.46 - Added min/max default light settings, added lettuce and blackberries with food items (thanks OgelGames), added soya and vanilla (thanks Felfa), added tofu, added salt crystals (thanks gorlock)
- 1.45 - Dirt and Hoes are more in line with default by using dry/wet/base, added cactus juice, added pasta, spaghetti, cabbage, korean bibimbap, code tidy - 1.45 - Dirt and Hoes are more in line with default by using dry/wet/base, added cactus juice, added pasta, spaghetti, cabbage, korean bibimbap, code tidy
options, onion soup added (thanks edcrypt), Added apple pie, added wild cotton to savanna options, onion soup added (thanks edcrypt), Added apple pie, added wild cotton to savanna
- 1.44 - Added 'farming_stage_length' in mod settings for speed of crop growth, also thanks to TheDarkTiger for translation updates - 1.44 - Added 'farming_stage_length' in mod settings for speed of crop growth, also thanks to TheDarkTiger for translation updates

View File

@ -33,7 +33,48 @@ minetest.register_node("farming:salt", {
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25} fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
} },
-- special function to make salt crystals form inside water
dropped_step = function(self, pos, dtime)
self.ctimer = (self.ctimer or 0) + dtime
if self.ctimer < 15.0 then return end
self.ctimer = 0
local needed
if self.node_inside
and self.node_inside.name == "default:water_source" then
needed = 8
elseif self.node_inside
and self.node_inside.name == "default:river_water_source" then
needed = 9
end
if not needed then return end
local objs = core.get_objects_inside_radius(pos, 0.5)
if not objs or #objs ~= 1 then return end
local salt, ent = nil, nil
for k, obj in pairs(objs) do
ent = obj:get_luaentity()
if ent and ent.name == "__builtin:item"
and ent.itemstring == "farming:salt " .. needed then
obj:remove()
core.add_item(pos, "farming:salt_crystal")
return false -- return with no further action
end
end
end
}) })
minetest.register_craft({ minetest.register_craft({
@ -44,6 +85,40 @@ minetest.register_craft({
replacements = {{"bucket:bucket_water", "bucket:bucket_empty"}} replacements = {{"bucket:bucket_water", "bucket:bucket_empty"}}
}) })
--= Salt Crystal
minetest.register_node("farming:salt_crystal", {
description = ("Salt crystal"),
inventory_image = "farming_salt_crystal.png",
wield_image = "farming_salt_crystal.png",
drawtype = "plantlike",
visual_scale = 0.8,
paramtype = "light",
light_source = 1,
tiles = {"farming_salt_crystal.png"},
groups = { dig_immediate = 3, attached_node = 1},
sounds = default.node_sound_defaults(),
selection_box = {
type = "fixed",
fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
},
})
minetest.register_craft({
type = "shapeless",
output = "farming:salt 9",
recipe = {"farming:salt_crystal", "farming:mortar_pestle"},
replacements = {{"farming:mortar_pestle", "farming:mortar_pestle"}}
})
minetest.register_craft({
output = "farming:salt_crystal",
recipe = {
{"farming:salt", "farming:salt", "farming:salt"},
{"farming:salt", "farming:salt", "farming:salt"},
{"farming:salt", "farming:salt", "farming:salt"}
}
})
--= Rose Water --= Rose Water
minetest.register_node("farming:rose_water", { minetest.register_node("farming:rose_water", {

View File

@ -145,13 +145,16 @@ Created by mDiyo (Natura), modified by TenPlus1 (License: CC BY-SA 3.0):
farming_barley.png farming_barley.png
Created by OgelGames (CC BY-SA 4.0) Created by OgelGames (CC BY-SA 4.0)
farming_berry_smoothie.png farming_berry_smoothie.png
farming_cactus_juice.png farming_cactus_juice.png
farming_salad.png farming_salad.png
Created by Felfa (CC0) Created by Felfa (CC0)
farming_blackberry*.png farming_blackberry*.png
farming_lettuce*.png farming_lettuce*.png
farming_burger.png farming_burger.png
farming_soy*.png farming_soy*.png
farming_vanilla*.png farming_vanilla*.png
Created by gorlock (CC0)
farming_salt_crystal.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

View File

@ -298,6 +298,21 @@ minetest.register_craft({
} }
}) })
minetest.register_craft({
type = "shapeless",
output = "default:cobble 8",
recipe = {
"gloopblocks:pumice",
"gloopblocks:pumice",
"gloopblocks:pumice",
"gloopblocks:pumice",
"gloopblocks:basalt",
"gloopblocks:basalt",
"gloopblocks:basalt",
"gloopblocks:basalt"
}
})
minetest.register_craft({ minetest.register_craft({
output = "gloopblocks:fence_steel 1", output = "gloopblocks:fence_steel 1",
recipe = { recipe = {

View File

@ -245,7 +245,7 @@ minetest.register_privilege("no_knockback", {
give_to_singleplayer = false}) give_to_singleplayer = false})
-- is player knock-back effect enabled? -- is player knock-back effect enabled?
if minetest.settings:get_bool("player_knockback") ~= false then if minetest.settings:get_bool("player_knockback") == true then
minetest.register_entity("playerplus:temp", { minetest.register_entity("playerplus:temp", {
physical = true, physical = true,

View File

@ -1,4 +1,4 @@
# If enabled players are knocked back when hit by mobs or other players # If enabled players are knocked back when hit by mobs or other players
player_knockback (Player knockback) bool true player_knockback (Player knockback) bool false
# If enabled the players use the old sneak glitch and movements # If enabled the players use the old sneak glitch and movements
old_sneak (Use old sneak glitch) bool false old_sneak (Use old sneak glitch) bool false

View File

@ -155,6 +155,7 @@ signs_lib.flip_walldir = {
-- Initialize character texture cache -- Initialize character texture cache
local ctexcache = {} local ctexcache = {}
local ctexcache_wide = {}
-- entity handling -- entity handling
@ -251,7 +252,10 @@ function signs_lib.set_obj_text(pos, text)
local text_ansi = Utf8ToAnsi(text) local text_ansi = Utf8ToAnsi(text)
local n = minetest.registered_nodes[minetest.get_node(pos).name] local n = minetest.registered_nodes[minetest.get_node(pos).name]
signs_lib.delete_objects(pos) signs_lib.delete_objects(pos)
signs_lib.spawn_entity(pos, signs_lib.make_sign_texture(split(text_ansi), pos) ) -- only create sign entity for actual text
if text_ansi and text_ansi ~= "" then
signs_lib.spawn_entity(pos, signs_lib.make_sign_texture(split(text_ansi), pos) )
end
end end
-- rotation -- rotation
@ -330,8 +334,10 @@ end
local TP = signs_lib.path .. "/textures" local TP = signs_lib.path .. "/textures"
-- Font file formatter -- Font file formatter
local CHAR_FILE = "%s_%02x.png" local CHAR_FILE = "%s_%02x.png"
local CHAR_FILE_WIDE = "%s_%s.png"
-- Fonts path -- Fonts path
local CHAR_PATH = TP .. "/" .. CHAR_FILE local CHAR_PATH = TP .. "/" .. CHAR_FILE
local CHAR_PATH_WIDE = TP .. "/" .. CHAR_FILE_WIDE
-- Lots of overkill here. KISS advocates, go away, shoo! ;) -- kaeza -- Lots of overkill here. KISS advocates, go away, shoo! ;) -- kaeza
@ -391,6 +397,7 @@ end
local function build_char_db(font_size) local function build_char_db(font_size)
local cw = {} local cw = {}
local cw_wide = {}
-- To calculate average char width. -- To calculate average char width.
local total_width = 0 local total_width = 0
@ -406,20 +413,32 @@ local function build_char_db(font_size)
end end
end end
for i = 1, #signs_lib.wide_character_codes do
local ch = signs_lib.wide_character_codes[i]
local w, h = signs_lib.read_image_size(CHAR_PATH_WIDE:format("signs_lib_font_"..font_size.."px", ch))
if w and h then
cw_wide[ch] = w
total_width = total_width + w
char_count = char_count + 1
end
end
local cbw, cbh = signs_lib.read_image_size(TP.."/signs_lib_color_"..font_size.."px_n.png") local cbw, cbh = signs_lib.read_image_size(TP.."/signs_lib_color_"..font_size.."px_n.png")
assert(cbw and cbh, "error reading bg dimensions") assert(cbw and cbh, "error reading bg dimensions")
return cw, cbw, cbh, (total_width / char_count) return cw, cbw, cbh, (total_width / char_count), cw_wide
end end
signs_lib.charwidth15, signs_lib.charwidth15,
signs_lib.colorbgw15, signs_lib.colorbgw15,
signs_lib.lineheight15, signs_lib.lineheight15,
signs_lib.avgwidth15 = build_char_db(15) signs_lib.avgwidth15,
signs_lib.charwidth_wide15 = build_char_db(15)
signs_lib.charwidth31, signs_lib.charwidth31,
signs_lib.colorbgw31, signs_lib.colorbgw31,
signs_lib.lineheight31, signs_lib.lineheight31,
signs_lib.avgwidth31 = build_char_db(31) signs_lib.avgwidth31,
signs_lib.charwidth_wide31 = build_char_db(31)
local sign_groups = {choppy=2, dig_immediate=2} local sign_groups = {choppy=2, dig_immediate=2}
local fences_with_sign = { } local fences_with_sign = { }
@ -455,7 +474,22 @@ local function char_tex(font_name, ch)
end end
end end
local function make_line_texture(line, lineno, pos, line_width, line_height, cwidth_tab, font_size, colorbgw) local function char_tex_wide(font_name, ch)
if ctexcache_wide[font_name..ch] then
return ctexcache_wide[font_name..ch], true
else
local exists, tex = file_exists(CHAR_PATH_WIDE:format(font_name, ch))
if exists then
tex = CHAR_FILE_WIDE:format(font_name, ch)
else
tex = CHAR_FILE:format(font_name, 0x5f)
end
ctexcache_wide[font_name..ch] = tex
return tex, exists
end
end
local function make_line_texture(line, lineno, pos, line_width, line_height, cwidth_tab, font_size, colorbgw, cwidth_tab_wide)
local width = 0 local width = 0
local maxw = 0 local maxw = 0
local font_name = "signs_lib_font_"..font_size.."px" local font_name = "signs_lib_font_"..font_size.."px"
@ -492,6 +526,27 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
local word_l = #word local word_l = #word
local i = 1 local i = 1
while i <= word_l do while i <= word_l do
local wide_c
if "&#x" == word:sub(i, i + 2) then
local j = i + 3
local collected = ""
while j <= word_l do
local c = word:sub(j, j)
if c == ";" then
wide_c = collected
break
elseif c < "0" then
break
elseif "f" < c then
break
elseif ("9" < c) and (c < "a") then
break
else
collected = collected .. c
j = j + 1
end
end
end
local c = word:sub(i, i) local c = word:sub(i, i)
if c == "#" then if c == "#" then
local cc = tonumber(word:sub(i+1, i+1), 16) local cc = tonumber(word:sub(i+1, i+1), 16)
@ -499,6 +554,25 @@ local function make_line_texture(line, lineno, pos, line_width, line_height, cwi
i = i + 1 i = i + 1
cur_color = cc cur_color = cc
end end
elseif wide_c then
local w = cwidth_tab_wide[wide_c]
if w then
width = width + w + 1
if width >= (line_width - cwidth_tab[" "]) then
width = 0
else
maxw = math_max(width, maxw)
end
if #chars < MAX_INPUT_CHARS then
table.insert(chars, {
off = ch_offs,
tex = char_tex_wide(font_name, wide_c),
col = ("%X"):format(cur_color),
})
end
ch_offs = ch_offs + w
end
i = i + #wide_c + 3
else else
local w = cwidth_tab[c] local w = cwidth_tab[c]
if w then if w then
@ -578,6 +652,7 @@ function signs_lib.make_sign_texture(lines, pos)
local line_width local line_width
local line_height local line_height
local char_width local char_width
local char_width_wide
local colorbgw local colorbgw
local widemult = 1 local widemult = 1
@ -590,12 +665,14 @@ function signs_lib.make_sign_texture(lines, pos)
line_width = math.floor(signs_lib.avgwidth31 * def.chars_per_line) * (def.horiz_scaling * widemult) line_width = math.floor(signs_lib.avgwidth31 * def.chars_per_line) * (def.horiz_scaling * widemult)
line_height = signs_lib.lineheight31 line_height = signs_lib.lineheight31
char_width = signs_lib.charwidth31 char_width = signs_lib.charwidth31
char_width_wide = signs_lib.charwidth_wide31
colorbgw = signs_lib.colorbgw31 colorbgw = signs_lib.colorbgw31
else else
font_size = 15 font_size = 15
line_width = math.floor(signs_lib.avgwidth15 * def.chars_per_line) * (def.horiz_scaling * widemult) line_width = math.floor(signs_lib.avgwidth15 * def.chars_per_line) * (def.horiz_scaling * widemult)
line_height = signs_lib.lineheight15 line_height = signs_lib.lineheight15
char_width = signs_lib.charwidth15 char_width = signs_lib.charwidth15
char_width_wide = signs_lib.charwidth_wide15
colorbgw = signs_lib.colorbgw15 colorbgw = signs_lib.colorbgw15
end end
@ -604,7 +681,7 @@ function signs_lib.make_sign_texture(lines, pos)
local lineno = 0 local lineno = 0
for i = 1, #lines do for i = 1, #lines do
if lineno >= def.number_of_lines then break end if lineno >= def.number_of_lines then break end
local linetex, ln = make_line_texture(lines[i], lineno, pos, line_width, line_height, char_width, font_size, colorbgw) local linetex, ln = make_line_texture(lines[i], lineno, pos, line_width, line_height, char_width, font_size, colorbgw, char_width_wide)
table.insert(texture, linetex) table.insert(texture, linetex)
lineno = ln + 1 lineno = ln + 1
end end

View File

@ -203,6 +203,32 @@ local utf8_decode = {
[210] = {[144] = "\165", [145] = "\180"} [210] = {[144] = "\165", [145] = "\180"}
} }
local wide_character_codes = {
}
signs_lib.unicode_install = function(
numbers
)
local scope = utf8_decode
for i = 1,#numbers-2 do
if not scope[numbers[i]] then
scope[numbers[i]] = {}
end
scope = scope[numbers[i]]
end
scope[numbers[#numbers-1]] = "&#x" .. numbers[#numbers] .. ";"
table.insert(
wide_character_codes,
numbers[#numbers]
)
end
signs_lib.unicode_install({38,"26"})
dofile(signs_lib.path.."/nonascii-de.lua")
dofile(signs_lib.path.."/nonascii-fr.lua")
dofile(signs_lib.path.."/nonascii-pl.lua")
local nmdc = { local nmdc = {
[36] = "$", [36] = "$",
[124] = "|" [124] = "|"
@ -230,36 +256,33 @@ function AnsiToUtf8(s)
end end
function Utf8ToAnsi(s) function Utf8ToAnsi(s)
local a, j, r, b = 0, 0, "" local a, j, r, b, scope = 0, 0, ""
for i = 1, s and s:len() or 0 do for i = 1, s and s:len() or 0 do
b = s:byte(i) b = s:byte(i)
if b < 128 then if b == 0x26 then
r = r .. "&#x26;"
elseif b < 128 then
if nmdc[b] then if nmdc[b] then
r = r .. nmdc[b] r = r .. nmdc[b]
else else
r = r .. string.char(b) r = r .. string.char(b)
end end
elseif a == 2 then elseif scope then
a, j = a - 1, b if scope[b] then
elseif a == 1 then scope = scope[b]
--if j == nil or b == nil then return r end if "string" == type(scope) then
--print(j) r, scope = r .. scope
--print(b)
--local ansi = utf8_decode[j]
--if ansi == nil then return r end
--if ansi[b] == nil then return r end
if utf8_decode[j] then
if utf8_decode[j][b] then
a, r = a - 1, r .. utf8_decode[j][b]
end end
else
r, scope = r .. "_"
end end
elseif b == 226 then elseif utf8_decode[b] then
a = 2 scope = utf8_decode[b]
elseif b == 194 or b == 208 or b == 209 or b == 210 then
j, a = b, 1
else else
r = r .. "_" r = r .. "_"
end end
end end
return r return r
end end
signs_lib.wide_character_codes = wide_character_codes

View File

@ -10,7 +10,7 @@ signs_lib.path = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(signs_lib.path .. "/intllib.lua") local S, NS = dofile(signs_lib.path .. "/intllib.lua")
signs_lib.gettext = S signs_lib.gettext = S
dofile(signs_lib.path.."/api.lua")
dofile(signs_lib.path.."/encoding.lua") dofile(signs_lib.path.."/encoding.lua")
dofile(signs_lib.path.."/api.lua")
dofile(signs_lib.path.."/standard_signs.lua") dofile(signs_lib.path.."/standard_signs.lua")
dofile(signs_lib.path.."/compat.lua") dofile(signs_lib.path.."/compat.lua")

View File

@ -0,0 +1,7 @@
signs_lib.unicode_install({195,132,"00c4"})
signs_lib.unicode_install({195,150,"00d6"})
signs_lib.unicode_install({195,156,"00dc"})
signs_lib.unicode_install({195,159,"00df"})
signs_lib.unicode_install({195,164,"00e4"})
signs_lib.unicode_install({195,182,"00f6"})
signs_lib.unicode_install({195,188,"00fc"})

View File

@ -0,0 +1,16 @@
signs_lib.unicode_install({195,128,"00c0"})
signs_lib.unicode_install({195,134,"00c6"})
signs_lib.unicode_install({195,135,"00c7"})
signs_lib.unicode_install({195,136,"00c8"})
signs_lib.unicode_install({195,137,"00c9"})
signs_lib.unicode_install({195,138,"00ca"})
signs_lib.unicode_install({195,148,"00d4"})
signs_lib.unicode_install({195,153,"00d9"})
signs_lib.unicode_install({195,160,"00e0"})
signs_lib.unicode_install({195,166,"00e6"})
signs_lib.unicode_install({195,167,"00e7"})
signs_lib.unicode_install({195,168,"00e8"})
signs_lib.unicode_install({195,169,"00e9"})
signs_lib.unicode_install({195,170,"00ea"})
signs_lib.unicode_install({195,180,"00f4"})
signs_lib.unicode_install({195,185,"00f9"})

View File

@ -0,0 +1,16 @@
signs_lib.unicode_install({195,147,"00d3"})
signs_lib.unicode_install({195,179,"00f3"})
signs_lib.unicode_install({196,132,"0104"})
signs_lib.unicode_install({196,133,"0105"})
signs_lib.unicode_install({196,134,"0106"})
signs_lib.unicode_install({196,135,"0107"})
signs_lib.unicode_install({196,152,"0118"})
signs_lib.unicode_install({196,153,"0119"})
signs_lib.unicode_install({197,129,"0141"})
signs_lib.unicode_install({197,130,"0142"})
signs_lib.unicode_install({197,154,"015a"})
signs_lib.unicode_install({197,155,"015b"})
signs_lib.unicode_install({197,185,"0179"})
signs_lib.unicode_install({197,186,"017a"})
signs_lib.unicode_install({197,187,"017b"})
signs_lib.unicode_install({197,188,"017c"})

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 B

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 B

After

Width:  |  Height:  |  Size: 296 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 B

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 B

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 125 B

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 B

After

Width:  |  Height:  |  Size: 341 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 B

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 B

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 B

After

Width:  |  Height:  |  Size: 312 B

Some files were not shown because too many files have changed in this diff Show More