Add "discard all" function to scheduler events and use it to clear schedules in luaatc rails

master
orwell96 2019-11-06 22:07:10 +01:00
parent 43b4d863ec
commit 8c55442076
2 changed files with 16 additions and 0 deletions

View File

@ -116,4 +116,15 @@ function sched.enqueue_in(rwtime, handler, evtdata, unitid, unitlim)
sched.enqueue(ctime + rwtime, handler, evtdata, unitid, unitlim)
end
-- Discards all schedules for unit "unitid" (removes them from the queue)
function sched.discard_all(unitid)
for i=1,#queue do
if queue[i].u == unitid then
table.remove(queue,i)
i=i-1
end
end
units_cnt[unitid] = 0
end
ln.sched = sched

View File

@ -71,7 +71,12 @@ function ac.on_receive_fields(pos, formname, fields, player)
nodetbl.code=fields.code
end
if fields.save then
-- reset certain things
nodetbl.err=nil
if advtrains.lines and advtrains.lines.sched then
-- discard all schedules for this node
advtrains.lines.sched.discard_all(advtrains.encode_pos(pos))
end
end
if fields.cle then
nodetbl.data={}