Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add(queue, val)
- queue[(#queue)+1]=val
- end
- function peek(queue)
- if queue==nil or #queue<1 then
- return nil
- end
- return queue[1]
- end
- function shiftDown(queue)
- if queue==nil or #queue<1 then
- return false
- elseif #queue==1 then
- queue[1]=nil
- return true
- end
- while i=2,#queue do
- queue[i-1]=queue[i]
- end
- queue[#queue]=nil
- return true
- end
- -- TODO: Waeten, bis ALLE Loren in den Puffern sind
- local modem=peripheral.wrap("top")
- modem.open(23365)
- -- init
- local bhl={}
- local qus={}
- function ctlbh(bid)
- modem.transmit(23365, 23365, {0,bid,unpack(bhl[bid].rds)})
- end
- function READRS(bid)
- dao=true
- while dao do
- evt={os.pullEvent("modem_message")}
- if (evt[3]==23365) and (evt[4]==23365) and (evt[5][2]==i) then
- bhl[bid].rds={unpack(evt[5],3)}
- dao=false
- else
- os.queueEvent(unpack(evt))
- end
- end
- end
- function setmode(bh,md)
- if md=0 then
- bh=nil
- NS=false
- elseif md=1 then
- modem.transmit(23365, 7, {bh.id}) -- REFRESH
- NS=false
- elseif md=2 then
- bh.rds={false,false,false,true,false,false}
- NS=true
- elseif md=3 then
- bh.rds={false,false,false,true,true,false}
- NS=false
- else
- bh=nil
- NS=false
- end
- if bh~=nil then
- bh.md=md
- end
- end
- --modem.transmit(23365, 7, nil) -- Request ALL Stats!
- for i=1,128 do
- qus[i]={}
- bhl[i]={
- id=i
- md=3 --0/nil=NOT INIT, 1=NORM, 2=NOT!!!!!!!, 3=NOWCLEAN
- rds={false,false,false,true,true,false} --Redstone Panel
- quvs={i-1,i} --Queue dir
- lti={} -- Loren to insert
- }
- darr=true
- warr=true
- while darr do
- bhl[i].rds[4]=warr
- ctlbh(i) -- Send to clean Street
- READRS(i)
- if(evt[5][5])
- darr=false --YEAR, LEER!
- end
- sleep(1)
- warr=not warr
- end
- bhl[i].rds[4]=false
- bhl[i].rds[5]=false
- bhl[i].rds[6]=false
- ctlbh(i)
- bhl[i].md=1
- if bhl[i].quvs[1]==0 then
- bhl[i].quvs[1]==128
- end
- end
- while true do
- for i=1,128 do
- -- Request lors to be transmitted
- modem.transmit(23369,23369,{bhl[i].id})
- evt={os.pullEvent("modem_message")}
- if (evt[3]==23369) and (evt[4]==23369) and (evt[5][1]==i) then
- if(evt[5][2]~=nil) then
- add(bhl[i].lti,evt[5][2])
- end
- else
- os.queueEvent(unpack(evt))
- end
- --/
- --Insert if needed
- pk=peek(bhl[i].lti[2])
- while not((pk==nil) or (#pk<1)) do
- shiftDown(bhl[i].lti) --Raus aus er Req
- add(qus[bhl[i].quvs[2]],pk) --zur Queue
- bhl[i].rds[6]=true --ReinlassAntrieb an
- ctlbh(i)
- oka=true
- while oka do
- READRS(i)
- if bhl[i].rds[2] then
- oka=false
- end
- end --OK, AusSchiene ist an!
- bhl[i].rds[6]=false --ReinlassAntrieb aus
- ctlbh(i)
- oka=true
- while oka do
- READRS(i)
- if not bhl[i].rds[2] then
- oka=false
- end
- end --OK, AusSchiene ist aus!
- end
- --/
- --NOW!!! Let out from Left and distribute!!! BamBamBam Baam!
- tnr=nil
- while bhl[i].rds[3] do
- tnr=peek(qus[bhl[i].quvs[1]])
- shiftDir(qus[bhl[i].quvs[1]])
- if tnr==i then --Rein mit Dir, du hast das Ziel erreicht!!!
- bhl[i].rds[5]=true --CurveCtl reinlassen!
- ctlbh(i) --Update!
- else
- bhl[i].rds[5]=true --CurveCtl aus!
- ctlbh(i) --Update!
- end
- bhl[i].rds[4]=true --Schleuse an!
- ctlbh(i)
- oka=true
- while oka do
- READRS(i)
- if bhl[i].rds[2] then
- oka=false
- end
- end --OK, AusSchiene ist an!
- add(qus[bhl[i].quvs[2]],tnr)
- bhl[i].rds[4]=false --Schleuse aus!
- ctlbh(i)
- oka=true
- while oka do
- READRS(i)
- if not bhl[i].rds[2] then
- oka=false
- end
- end --OK, AusSchiene ist aus!
- end
- --/
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement