Advertisement
Miner8149

Agricraft Opencomputers Computer 10/10/10

Dec 8th, 2021 (edited)
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.52 KB | None | 0 0
  1. --Miner8149
  2. --12/7/2021
  3.  
  4. -- Visit my github for a more detailed set of instructions https://github.com/Miner8149/Agricraft-10-10-10-seed-breeder
  5. -- https://pastebin.com/VrrGhuKT
  6. -- Copyright 2020 Miner8149
  7. --
  8. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  9. -- of this software and associated documentation files (the "Software"), to deal
  10. -- in the Software without restriction, including without limitation the rights
  11. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. -- copies of the Software, and to permit persons to whom the Software is
  13. -- furnished to do so, subject to the following conditions:
  14. --
  15. -- The above copyright notice and this permission notice shall be included in all
  16. -- copies or substantial portions of the Software.
  17. --
  18. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. -- SOFTWARE.
  25. --
  26. -- I am not responible for exploding robots, or missing limbs. Do note that if the
  27. -- robot gains sentience, that is would be in your best interest to run
  28.  
  29. --this is for the COMPUTER
  30. local com = require("component")
  31. local event = require("event")
  32. --local s = require("sides")
  33. local m = com.modem
  34.  
  35. --first 3 of address
  36. an1 = com.proxy(com.get("6352f")) --Parent 1
  37. an2 = com.proxy(com.get("fb213")) --Child
  38. an3 = com.proxy(com.get("db467")) --Parent 2
  39. an4 = com.proxy(com.get("42689")) --Analyzer
  40.  
  41.  
  42. curentPlant = nil
  43. Par1Gro = 0 --Par1 is in slot -1
  44. Par1Gai = 0
  45. Par1Str = 0
  46. Par1    = 0
  47. Par2Gro = 0 --Par 2 is in slot 1
  48. Par2Gai = 0
  49. Par2Str = 0
  50. Par2    = 0
  51. Chi0Gro = 0 --child is in slot 0
  52. Chi0Gai = 0
  53. Chi0Str = 0
  54. Chi0    = 0
  55. incommingMsgFunct = nil
  56. incommingMsgSlot  = nil
  57. stateVarToBroadcast = nil
  58.  
  59. function getMyPlant(slot)
  60.   local plant = nil
  61.   local analyzerTemp = nil
  62.   if (slot == -1) then
  63.     analyzerTemp = an1
  64.     print("an1")
  65.   elseif (slot == 0) then
  66.     analyzerTemp = an2
  67.     print("an2")
  68.   elseif (slot == 1) then
  69.     analyzerTemp = an3
  70.     print("an3")
  71.   else
  72.     print("analyzer - nil")
  73.     return nil
  74.   end
  75.   plant = analyzerTemp.getPlant("SOUTH")
  76.   print(plant)
  77.   if (plant==nil) or (plant=="None") then
  78.     print("false")
  79.     return false
  80.   else
  81.     print("true")
  82.     return true
  83.   end
  84. end
  85.  
  86. function initializeParents()
  87.   print("NewLine")
  88.   print("NewLine")
  89.   print("Initializing Parent Seeds")
  90.   local status = analyzePlant()
  91.   Par1Gro, Par1Gai, Par1Str = an4.getSpecimenStats()
  92.   Par2Gro, Par2Gai, Par2Str = Par1Gro, Par1Gai, Par1Str
  93.   Par2 = Par1Gro + Par1Gai + Par1Str
  94.   Par1 = Par2
  95.   Chi0Gro, Chi0Gai, Chi0Str, Chi0 = 0, 0, 0, 0
  96.   print("Parents Stats Sum: ", Par1)
  97.   return status
  98. end
  99.  
  100. function decideLocation()
  101.   print("Deciding Location")
  102.   local plantInAnalyzer = nil
  103.   plantInAnalyzer = an4.getSpecimen()
  104.   print("Plant in Analyzer: ", plantInAnalyzer)
  105.   if (plantInAnalyzer == nil) or (plantInAnalyzer == "Air") then
  106.     return nil
  107.   end
  108.   print("About to Analyze")
  109.   local isAnalyzedAlready = an4.isAnalyzed()
  110.   if not (isAnalyzedAlready) then
  111.     print("Not Yet Analyzed.")
  112.     analyzePlant()
  113.   else
  114.     print("Already Analyzed.")
  115.   end
  116.   Chi0Gro, Chi0Gai, Chi0Str = an4.getSpecimenStats()
  117.   Chi0 = Chi0Gro + Chi0Gai + Chi0Str
  118.   print("Child Stat Sum: ", Chi0)
  119.   print("Parent 1 Stat Sum: ", Par1)
  120.   print("Parent 2 Stat Sum: ", Par2)
  121.   if (Chi0 == 30) then
  122.     return 2
  123.   end
  124.   if (Par1 < Par2) then   --parent 1 less than parent 2
  125.     if (Par1 < Chi0) then
  126.       Par1Gro, Par1Gai, Par1Str = Chi0Gro, Chi0Gai, Chi0Str
  127.       Par1 = Chi0
  128.       return -1           --parent 1 (slot -1) is least
  129.     else
  130.       return 0            --child is least
  131.     end
  132.   else                    --parent 2 less than parent 1
  133.     if (Par2 < Chi0) then
  134.       Par2Gro, Par2Gai, Par2Str = Chi0Gro, Chi0Gai, Chi0Str
  135.       Par2 = Chi0
  136.       return 1            --parent 2 (slot 1) is least
  137.     else
  138.       return 0            --child is least
  139.     end
  140.   end
  141. end
  142.  
  143. function analyzePlant()
  144.   print("Analyzing plant")
  145.   local plant = an4.getSpecimen()
  146.   if (plant==nil) or (plant=="Air") then
  147.     print("no plant: ", plant)
  148.     return false
  149.   end
  150.   while (not an4.isAnalyzed()) do
  151.     plant = an4.getSpecimen()
  152.     if (plant==nil) or (plant=="Air") then
  153.       print("Plant went Missing: ", plant)
  154.       return false
  155.     end
  156.     print("Analyzing...")
  157.     an4.analyze()
  158.     os.sleep(1)
  159.   end
  160.   return true
  161. end
  162.  
  163. function cropStickState(slot)
  164.   local analyzerTemp = nil
  165.   local state = nil
  166.   if (slot == -1) then
  167.     print("Sticks an1")
  168.     analyzerTemp = an1
  169.   elseif (slot == 0) then
  170.     print("Sticks an2")
  171.     analyzerTemp = an2
  172.   elseif (slot == 1) then
  173.     print("Sticks an3")
  174.     analyzerTemp = an3
  175.   else
  176.     print("Sticks Nil")
  177.     return nil
  178.   end
  179.   state = analyzerTemp.isCrossCrop("SOUTH")
  180.   if (state == nil) then
  181.     print("No sticks")
  182.     return 0 --no sticks
  183.   elseif (state == false) then
  184.     print("1 Stick")
  185.     return 1 -- 1 stick
  186.   elseif (state == true) then
  187.     print("2 Sticks")
  188.     return 2 -- 2 sticks
  189.   else
  190.     print("nil Sticks")
  191.     return nil
  192.   end
  193. end
  194.  
  195. function setup()
  196.   m.open(111)
  197.   print("Ready")
  198. end
  199.  
  200. setup()
  201. while true do
  202.   _, _, _, _, _, incommingMsgFunct, incommingMsgSlot = event.pull("modem_message")
  203.   --print("Recived: ", incommingMsgFunct, ", ", incommingMsgSlot)
  204.  
  205.   if (incommingMsgFunct == 0) then --wants me to init parents
  206.     stateVarToBroadcast = initializeParents()
  207.     print("init")
  208.   elseif (incommingMsgFunct == 1) then --wants me to check for plant at slot
  209.     stateVarToBroadcast = getMyPlant(incommingMsgSlot)
  210.     print("plant")
  211.   elseif (incommingMsgFunct == 2) then --wants me to check for cropsticks at slot
  212.     stateVarToBroadcast = cropStickState(incommingMsgSlot)
  213.     print("cropsticks")
  214.   elseif (incommingMsgFunct == 3) then --wants me to analyze crop
  215.     stateVarToBroadcast = analyzePlant()
  216.     print("analyze")
  217.   elseif (incommingMsgFunct == 4) then --wants me to decide what to do with new plant
  218.     stateVarToBroadcast = decideLocation()
  219.     print("decide")
  220.   else
  221.     stateVarToBroadcast = nil
  222.   end
  223.   os.sleep(1)
  224.   m.broadcast(112, stateVarToBroadcast)
  225.   print("Sending: ", stateVarToBroadcast)
  226. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement