Advertisement
SkullDrago

Dano742 Bahnhof

Mar 27th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.59 KB | None | 0 0
  1. -- Vollautomatischer Computercraft-Bahnhof von Dano742, www.youtube.com/dano742
  2.  
  3.  
  4. -- Das Programm startet um 00:00 Uhr einmal neu, im Zeitraum von 23:50 bis 00:30 Uhr sollten daher keine Züge liegen !
  5. -- Um Probleme zu vermeiden, sollten die Abfahrtszeiten min. 20 min auseinanderliegen
  6.  
  7. -- Fahrplan für die Züge nach dem Schema plan[n] ändern --
  8.  
  9. --plan[n] = {Uhrzeit komplett,Stunde,Uhrzeit,Fahrziel,Weiche,Zustand(Bereit/Verspätung)}
  10. plan = {}
  11.  
  12. plan[1] = {0620,06,"06:20","Raffinerie+Holzfäller", colors.combine(colors.green)," "}
  13. plan[2] = {0700,07,"07:00","Bienen", colors.combine(colors.yellow)," "}
  14. plan[3] = {0730,07,"07:30","Bienen", colors.combine(colors.yellow)," "}
  15. plan[4] = {1030,10,"10:30","Raffinerie+Holzfäller", colors.combine(colors.green)," "}
  16. plan[5] = {1200,12,"12:00","Raffinerie+Holzfäller", colors.combine(colors.green)," "}
  17. plan[6] = {1500,15,"15:00","Raffinerie+Holzfäller", colors.combine(colors.green)," "}
  18. plan[7] = {1730,17,"17:30","Bienen", colors.combine(colors.yellow)," "}
  19. plan[8] = {1330,13,"13:30","Bienen", colors.combine(colors.yellow)," "}
  20. plan[9] = {1825,18,"18:25","Raffinerie+Holzfäller", colors.combine(colors.green)," "}
  21.  
  22.  
  23. -- Lager für die Züge --
  24.  
  25. -- zug[n] = {Zug steht auf dem Gleis(Signal Receiver), Zug losschicken }
  26. zug = {}
  27. zug[1] = {colors.combine(colors.white),colors.combine(colors.red),}
  28. zug[2] = {colors.combine(colors.black),colors.combine(colors.gray),}
  29. zug[3] = {colors.combine(colors.blue),colors.combine(colors.orange),}
  30.  
  31. -- Passwort für den Wartungsmodus, Reihenfolge der Zahlen wird mit 1,2,3,4 festgelegt, der Rest muss 0 sein.
  32.  
  33. Passwort1 = 0 -- Passwort: 2589 --
  34. Passwort2 = 1
  35. Passwort3 = 0
  36. Passwort4 = 0
  37. Passwort5 = 2
  38. Passwort6 = 0
  39. Passwort7 = 0
  40. Passwort8 = 3
  41. Passwort9 = 4
  42.  
  43.  
  44.  
  45. -- Interner Plan NICHT ändern --
  46.  
  47. planint = {}
  48. planint[1] = {2400,24,"loading"," "," "," "}
  49. planint[2] = {2400,24," "," "," "," "}
  50.  
  51. made = {}
  52.  
  53. made[1] = {"m","a","d","e"," ","b","y"," ","D","a","n","o","7","4","2"}
  54.  
  55. -- Festlegen von wichtigen Variablen --
  56.  
  57. -- Bildschirme
  58. mt = peripheral.wrap("top")
  59. mb = peripheral.wrap("bottom")
  60.  
  61. -- Animation Zug fährt über den Bildschirm
  62. animation = false --AN/Aus - Schalter (true/false)
  63. animation_length = 4 --Dauer der Animation (>= 5 - sonst kann es probleme beim berechnen der Prozente geben)
  64. pos = -25 --Startposition
  65. pos_max = 70 --Endposition
  66.  
  67. -- Bild animation
  68. Bild_Saege= paintutils.loadImage("Dano742.img")
  69. Bild_Drill= paintutils.loadImage("Dano742_2.img")
  70.  
  71. x_1 = -45 --Säge Koordinaten
  72. y_1 = 4
  73.  
  74. x_2 = 146 -- Drill Koordinaten
  75. y_2 = 4
  76.  
  77. --Nicht verändern
  78.  
  79. count_storage = 0
  80. count_send = 0
  81. wartungsmodus = false
  82. passwort = false
  83. count = 0
  84. a = 0
  85. timer1 = 5
  86. text = false
  87.  
  88. -- Laden des gespeicherten Wartungsmoduses true/false --
  89.  
  90.  
  91. local handle = fs.open("save_passwort", "r")
  92.  
  93. if handle then
  94. text = handle.readAll()
  95. handle.close()
  96. end
  97. if text == "false" then
  98.  
  99. passwort = false
  100.  
  101. elseif text == "true" then
  102.  
  103. passwort = true
  104.  
  105. end
  106.  
  107.  
  108. -- Animation beim starten --
  109.  
  110. function Animation()
  111. if animation == true then
  112.  
  113. pos2 = math.abs(pos_max - pos) / (animation_length * 10) -- Wert um den die Position gehoben wird pro Sekunde
  114. percent = 100 / math.abs(pos_max - pos)
  115. weg = pos
  116.  
  117. while pos < pos_max do
  118.  
  119. mb.clear()
  120. mb.setBackgroundColor(128)
  121.  
  122. mb.setCursorPos(pos+7,4)
  123. mb.write("##")
  124. mb.setCursorPos(pos+8,5)
  125. mb.write("###")
  126. mb.setCursorPos(pos+8,6)
  127. mb.write("|###|")
  128. mb.setCursorPos(pos,7)
  129. mb.write("________|###|_____")
  130. mb.setCursorPos(pos,8)
  131. mb.write("| | |")
  132. mb.setCursorPos(pos,9)
  133. mb.write("| |____|")
  134. mb.setCursorPos(pos,10)
  135. mb.write("| |")
  136. mb.setCursorPos(pos,11)
  137. mb.write("|________________|")
  138. mb.setCursorPos(pos+2,12)
  139. mb.write("O O")
  140. mb.setBackgroundColor(32768)
  141.  
  142. pos = pos + pos2
  143. strecke = pos_max +(math.abs(pos_max - weg) - pos_max ) - math.abs(pos_max - pos)
  144. loading = ((math.ceil(strecke*percent*100))/100)
  145. mt.clear()
  146. mt.setCursorPos(5,5)
  147. mt.write("Loading: "..loading.."%")
  148.  
  149. mb.setCursorPos(15,1)
  150. mb.write("Loading: "..loading.."%")
  151.  
  152.  
  153. sleep(0.1)
  154. end
  155. sleep(1.5)
  156. end
  157. end
  158. Animation()
  159.  
  160.  
  161. -- Animation (Dano742) --
  162.  
  163.  
  164.  
  165. function Animation_Dano742()
  166.  
  167. mb.setTextScale(0.5)
  168.  
  169. while x_1 <= 25 do
  170. mb.clear()
  171. term.redirect(mb)
  172. paintutils.drawImage(Bild_Saege,x_1,y_1)
  173. paintutils.drawImage(Bild_Drill,x_2,y_2)
  174. mb.setBackgroundColor(32768)
  175. term.restore()
  176. x_1 = x_1 +1
  177. x_2 = x_2 -1.5
  178. sleep(0.01)
  179.  
  180. end
  181.  
  182. i = 1
  183. while i <= 15 do
  184.  
  185. mb.setCursorPos(48+i,19)
  186. mb.write(""..made[1][i].."")
  187. sleep(0.1)
  188. mb.setCursorPos(48+i,18)
  189. mb.write(""..made[1][i].."")
  190.  
  191. mb.setCursorPos(48+i,19)
  192. mb.write(" ")
  193. i = i +1
  194.  
  195. end
  196. sleep(3)
  197. mb.clear()
  198. mb.setTextScale(1)
  199.  
  200. end
  201.  
  202. Animation_Dano742()
  203.  
  204.  
  205.  
  206. -- Zeit auslesung und Umrechnung ins richtige Format
  207.  
  208.  
  209. function ftime()
  210.  
  211. nHour = math.floor(os.time())
  212. nMinute = math.floor((os.time() - nHour)*60)
  213.  
  214. if nHour < 10 then
  215. nHour = ("0"..nHour.."")
  216. end
  217.  
  218. if nMinute < 10 then
  219. nMinute = ("0"..nMinute.."")
  220. end
  221.  
  222. zeit = nHour.. nMinute
  223. end
  224.  
  225. -- Fahrplan festlegen 1ter Zug (nur beim ersten Start) --
  226. ftime()
  227.  
  228.  
  229. for i = 1, #plan, 1 do
  230.  
  231. if ((zeit - plan[i] [1])^2)^0.5 <= ((zeit - planint[1] [1])^2)^0.5 and (zeit - plan[i][1]) <= 0 then
  232. planint[1] = plan[i]
  233. end
  234.  
  235. end
  236.  
  237.  
  238. if planint[1] [3] == "loading" then
  239. zeit = 0000
  240. for i = 1, #plan, 1 do
  241.  
  242. if ((zeit - plan[i] [1])^2)^0.5 <= ((zeit - planint[1] [1])^2)^0.5 and (zeit - plan[i][1]) <= 0 then
  243. planint[1] = plan[i]
  244. end
  245.  
  246. end
  247. end
  248.  
  249.  
  250. -- Berechnung des 2ten Zuges --
  251.  
  252.  
  253. function zug_plan2()
  254. ftime()
  255. planint[2] [1] = 2400
  256. for i = 1, #plan, 1 do
  257. if ((zeit - plan[i] [1])^2)^0.5 <= ((zeit - planint[2] [1])^2)^0.5 and plan[i] [1] > planint[1] [1] and (zeit - plan[i] [1]) <= 0 then
  258. planint[2] = plan[i]
  259. end
  260.  
  261. end
  262.  
  263.  
  264. if planint[2] [1] == 2400 then
  265. zeit = 0000
  266. for i = 1, #plan, 1 do
  267.  
  268. if ((zeit - plan[i] [1])^2)^0.5 <= ((zeit - planint[2] [1])^2)^0.5 and (zeit - plan[i][1]) <= 0 then
  269. planint[2] = plan[i]
  270. end
  271.  
  272.  
  273. end
  274.  
  275.  
  276. end
  277.  
  278. if planint[1][1] == planint[2][1] then
  279. zeit = planint[1][1]
  280. planint[2] [1] = 2400
  281.  
  282. for i = 1, #plan, 1 do
  283.  
  284. if ((zeit - plan[i] [1])^2)^0.5 <= ((zeit - planint[2] [1])^2)^0.5 and (zeit - plan[i][1]) <= 0 then
  285. planint[2] = plan[i]
  286. end
  287.  
  288.  
  289. end
  290. end
  291.  
  292. mb.clear()
  293. end
  294.  
  295. zug_plan2() -- (Wird nur beim "ersten Start" ausgeführt) --
  296.  
  297.  
  298. -- Check der verfügbaren Züge --
  299.  
  300.  
  301. function zug_check(zug)
  302.  
  303. for i = 1, #zug, 1 do
  304.  
  305. if redstone.testBundledInput("right",zug [i] [1]) == true then
  306. count_storage = count_storage +1
  307. zug [i] [3] = "true"
  308. else
  309. zug [i] [3] = "false"
  310. end
  311.  
  312. end
  313.  
  314. end
  315.  
  316.  
  317. -- Schicke Zug aus dem Lager --
  318.  
  319.  
  320. function zug_send(zug)
  321.  
  322. for i = 1, #zug, 1 do
  323.  
  324. if zug [i] [3] == "true" and count_send == 0 then
  325. count_send = 1
  326. rs.setBundledOutput("right",zug [i] [2])
  327. sleep(1)
  328. rs.setBundledOutput("right",0)
  329. sleep(4)
  330. end
  331.  
  332. end
  333.  
  334. end
  335.  
  336. -- Hier wird der Zug auf seine Reise geschickt, die Weichen gestellt oder ein neuer Zug aus dem Lager angefordert --
  337.  
  338. function bahnhof()
  339.  
  340. if planint[1][6] == "Verspätung" then
  341.  
  342. if zeit - planint[1][1] >= 200 then
  343.  
  344. while zeit - planint[1][1] > 0 do
  345. planint[1] = planint [2]
  346. planint[2] = {}
  347. zug_plan2()
  348. sleep(0.75)
  349. end
  350.  
  351. end
  352.  
  353. else
  354.  
  355. if planint[1][2] - nHour == 1 then
  356.  
  357. if math.abs(zeit - planint[1] [1] ) <= 65 and redstone.testBundledInput("left",colors.combine(colors.orange)) == true then
  358. planint[1][6] = "Bereit"
  359. else
  360. planint[1][6] = " "
  361. end
  362.  
  363. elseif planint[1][2] - nHour == 0 then
  364.  
  365. if math.abs(zeit - planint[1] [1] ) <= 25 and redstone.testBundledInput("left",colors.combine(colors.orange)) == true then
  366. planint[1][6] = "Bereit"
  367. else
  368. planint[1][6] = " "
  369. end
  370. end
  371.  
  372. end
  373.  
  374. if planint[1][6] == "Bereit" and (zeit - planint[1] [1]) >= 0 then
  375. redstone.setBundledOutput("left",colors.combine(colors.red))
  376. sleep(0.5)
  377. redstone.setBundledOutput("left",0)
  378. redstone.setBundledOutput("left",planint[1] [5])
  379. sleep(0.5)
  380. redstone.setBundledOutput("left",0)
  381.  
  382. planint[1] = planint [2]
  383. planint[2] = {}
  384. zug_plan2()
  385. end
  386.  
  387.  
  388.  
  389.  
  390. if redstone.testBundledInput("left",colors.combine(colors.orange)) == false and count_storage > 0 then
  391. zug_send(zug)
  392. end
  393.  
  394.  
  395. if planint[1][2] - nHour == 1 then
  396.  
  397. if math.abs(zeit - planint[1] [1] ) <= 65 and redstone.testBundledInput("left",colors.combine(colors.orange)) == false then
  398. planint[1][6] = "Verspätung"
  399. end
  400. elseif planint[1][2] - nHour == 0 then
  401.  
  402. if math.abs(zeit - planint[1] [1] ) <= 25 and redstone.testBundledInput("left",colors.combine(colors.orange)) == false then
  403. planint[1][6] = "Verspätung"
  404. end
  405.  
  406. end
  407.  
  408.  
  409.  
  410.  
  411.  
  412. if redstone.testBundledInput("left",colors.combine(colors.orange)) == true and planint[1][6] == "Verspätung" and (zeit - planint[1] [1]) >= 0 then
  413. sleep(15)
  414. redstone.setBundledOutput("left",colors.combine(colors.red))
  415. sleep(0.5)
  416. redstone.setBundledOutput("left",0)
  417. redstone.setBundledOutput("left",planint[1] [5])
  418. sleep(0.5)
  419. redstone.setBundledOutput("left",0)
  420.  
  421. planint[1] = planint [2]
  422. planint[2] = {}
  423. zug_plan2()
  424. end
  425.  
  426.  
  427. end
  428.  
  429.  
  430. -- Unterer Monitor/Fahrplan
  431.  
  432.  
  433. function draw_mb()
  434.  
  435. mb.setTextScale(1)
  436. mb.setCursorPos(1,1)
  437. mb.write(""..nHour.." : "..nMinute.."")
  438.  
  439.  
  440. mb.setCursorPos(1,2)
  441. mb.write("-------------------------------------------------------------")
  442. mb.setCursorPos(1,3)
  443. mb.write("|"..planint[1][3].."|"..planint[1][4].."|")
  444. mb.setCursorPos(1,4)
  445. mb.write("-------------------------------------------------------------")
  446.  
  447. if planint[1][6] == "Bereit" then
  448. mb.setTextColor(32)
  449. else
  450. mb.setTextColor(16384)
  451. end
  452.  
  453.  
  454. mb.setCursorPos(50,3)
  455. mb.write(""..planint[1][6].."")
  456. mb.setTextColor(1)
  457.  
  458. mb.setCursorPos(1,5)
  459. mb.write("-------------------------------------------------------------")
  460. mb.setCursorPos(1,6)
  461. mb.write("|"..planint[2][3].."|"..planint[2][4].."|")
  462. mb.setCursorPos(1,7)
  463. mb.write("-------------------------------------------------------------")
  464.  
  465. end
  466.  
  467.  
  468.  
  469. ---- Oberer Monitor ----
  470.  
  471.  
  472. function draw_mt()
  473. mt.setTextScale(1)
  474. mt.setCursorPos(1,1)
  475. mt.write(""..nHour.." : "..nMinute.."")
  476. mt.setCursorPos(1,2)
  477. mt.write("Züge im Lager: ")
  478.  
  479. if count_storage > 1 then
  480. mt.setTextColor(32)
  481. elseif count_storage == 1 then
  482. mt.setTextColor(2)
  483. elseif count_storage == 0 then
  484. mt.setTextColor(16384)
  485. end
  486.  
  487. mt.write(""..count_storage.."")
  488. mt.setTextColor(1)
  489.  
  490.  
  491.  
  492. mt.setCursorPos(1,3)
  493. mt.write("Zug im Bahnhof: ")
  494.  
  495. if redstone.testBundledInput("left",colors.combine(colors.orange)) == true then
  496. mt.setTextColor(32)
  497. mt.write("JA")
  498. else
  499. mt.setTextColor(16384)
  500. mt.write("Nein")
  501. end
  502. mt.setTextColor(1)
  503.  
  504. if wartungsmodus == false and passwort == false then
  505. mt.setCursorPos(14,10)
  506. mt.write("Wartungsmodus")
  507.  
  508. mt.setCursorPos(27,10)
  509. mt.write("[") mt.setTextColor(2) mt.write("+") mt.setTextColor(1) mt.write("]")
  510.  
  511. elseif wartungsmodus == false and passwort == true then
  512. mt.setCursorPos(14,10)
  513. mt.write("Wartungsmodus")
  514.  
  515. mt.setCursorPos(27,10)
  516. mt.write("[") mt.setTextColor(32) mt.write("-") mt.setTextColor(1) mt.write("]")
  517. end
  518.  
  519.  
  520. -- Passwortabfrage --
  521.  
  522. if (wartungsmodus == true or ( x == 28 and y == 10 )) and passwort == false then -- Startet nur die Passwortabfrage nicht den Wartungmodus ansich
  523.  
  524.  
  525. mt.setCursorPos(14,10)
  526. mt.write(" ")
  527.  
  528. mt.setCursorPos(24,9)
  529. mt.write("1 2 3")
  530. mt.setCursorPos(24,10)
  531. mt.write("4 5 6")
  532. mt.setCursorPos(24,11)
  533. mt.write("7 8 9")
  534.  
  535. if wartungsmodus == true then
  536.  
  537.  
  538. if x == 24 and y == 9 then
  539. a = a+Passwort1
  540. count = count +1
  541. end
  542. if x == 26 and y == 9 then
  543. a = a+Passwort2
  544. count = count +1
  545. end
  546. if x == 28 and y == 9 then
  547. a = a+Passwort3
  548. count = count +1
  549. end
  550. if x == 24 and y == 10 then
  551. a = a+Passwort4
  552. count = count +1
  553. end
  554. if x == 26 and y == 10 then
  555. a = a+Passwort5
  556. count = count +1
  557. end
  558. if x == 28 and y == 10 then
  559. a = a+Passwort6
  560. count = count +1
  561. end
  562. if x == 24 and y == 11 then
  563. a = a+Passwort7
  564. count = count +1
  565. end
  566. if x == 26 and y == 11 then
  567. a = a+Passwort8
  568. count = count +1
  569. end
  570. if x == 28 and y == 11 then
  571. a = a+Passwort9
  572. count = count +1
  573. end
  574.  
  575. if count == 1 then
  576. mt.setCursorPos(24,12)
  577. mt.write("*")
  578. end
  579. if count == 2 then
  580. mt.setCursorPos(24,12)
  581. mt.write("**")
  582. end
  583. if count == 3 then
  584. mt.setCursorPos(24,12)
  585. mt.write("***")
  586. end
  587. if count == 4 then
  588. mt.setCursorPos(24,12)
  589. mt.write("****")
  590. end
  591.  
  592.  
  593. end
  594. wartungsmodus = true
  595.  
  596. if count == 4 then
  597.  
  598. if a == 10 then
  599. a = 0
  600. count = 0
  601. wartungsmodus = false
  602. passwort = true
  603.  
  604. else
  605. a = 0
  606. count = 0
  607. wartungsmodus = false
  608. passwort = false
  609.  
  610. end
  611. end
  612.  
  613.  
  614. end
  615.  
  616.  
  617.  
  618.  
  619. end -- Funktionsende
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626. function Touch()
  627. while true do
  628. event,side,x,y = os.pullEvent()
  629.  
  630. if event == "monitor_touch" then
  631.  
  632. if side == bottom then
  633. x = 0
  634. y= 0
  635. end
  636.  
  637. end
  638. end
  639. end
  640.  
  641.  
  642. function Bahn()
  643.  
  644. while true do
  645. if passwort == false then
  646. zug_check(zug)
  647. ftime()
  648. bahnhof()
  649.  
  650.  
  651.  
  652. mb.clear()
  653. mb.setBackgroundColor(32768)
  654. draw_mb()
  655.  
  656. mt.clear()
  657. draw_mt() --(Wartungsmodus)
  658.  
  659.  
  660. count_storage = 0
  661. count_send = 0
  662. x = 0
  663. y = 0
  664. sleep(0.3)
  665.  
  666. elseif passwort == true then
  667.  
  668. mb.clear()
  669. mb.setBackgroundColor(2048)
  670. mb.setCursorPos(10,6)
  671. mb.write("Der Bahnhof wird gewartet")
  672.  
  673. mt.clear()
  674. mt.setCursorPos(10,6)
  675. mt.write("Wartung: AN")
  676. mt.setCursorPos(14,10)
  677. mt.write("Wartungsmodus")
  678.  
  679. mt.setCursorPos(27,10)
  680. mt.write("[") mt.setTextColor(32) mt.write("-") mt.setTextColor(1) mt.write("]")
  681.  
  682.  
  683. if x == 28 and y == 10 then
  684. passwort = false
  685. while timer1 > 0 do
  686. mt.setCursorPos(10,6)
  687. mt.write("Neustart in: "..timer1.."")
  688. timer1 = timer1 -1
  689. sleep(1)
  690. end
  691. os.reboot()
  692. end
  693.  
  694. x = 0
  695. y = 0
  696. sleep(0.3)
  697. end
  698.  
  699. end
  700.  
  701. end
  702.  
  703. function Restart()
  704. while true do
  705.  
  706. -- Speicherfunktion für den Wartungsmodus --
  707.  
  708. file = fs.open("save_passwort", "w")
  709.  
  710. if file then
  711. file.write(passwort)
  712. file.close()
  713. end
  714.  
  715. -- Restart wenn der Wartungsmodus aus ist (Wenn 00:00 Uhr oder sich die Zeit um mehr als 5 min ändert)
  716.  
  717. if passwort == false then
  718.  
  719. if math.floor(os.time()) == 00 and math.floor((os.time() - nHour)*60) == 00 and passwort == false then
  720. os.reboot()
  721. end
  722.  
  723.  
  724. Hour = math.floor(os.time())
  725. Minute = math.floor((os.time() - Hour)*60)
  726.  
  727. if Minute == 59 or Minute == 58 then
  728. abstand = 65
  729. else
  730. abstand = 5
  731. end
  732.  
  733. sleep(0.6)
  734.  
  735. if math.abs(math.floor(os.time()) - Hour) > 1 or math.abs(math.floor((os.time() - nHour)*60) - Minute) >= abstand then
  736. sleep(1)
  737. os.reboot()
  738. end
  739.  
  740. else
  741. sleep(1)
  742. end
  743.  
  744.  
  745. end
  746. end
  747.  
  748. parallel.waitForAny(Bahn, Touch,Restart)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement