init.lua
181 lines · 4.8 KB
eHydra Initialization System
Copy & run
wget https://perlytiara.github.io/turtles.tips/raw/programs/perlytiara/eHydra_wip/init.lua
| 1 | -- eHydra Initialization System |
| 2 | -- Manages advanced mining turtle deployment and initialization |
| 3 | |
| 4 | local function findModem() |
| 5 | for _, side in pairs(rs.getSides()) do |
| 6 | if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then |
| 7 | return side |
| 8 | end |
| 9 | end |
| 10 | return nil |
| 11 | end |
| 12 | |
| 13 | local function deployTurtle(turtleType, position) |
| 14 | print("Deploying " .. turtleType .. " at position " .. position .. "...") |
| 15 | |
| 16 | -- Look for turtle in inventory |
| 17 | for slot = 1, 16 do |
| 18 | local item = turtle.getItemDetail(slot) |
| 19 | if item then |
| 20 | if item.name == "computercraft:turtle_advanced" or |
| 21 | item.name == "computercraft:" .. turtleType then |
| 22 | turtle.select(slot) |
| 23 | |
| 24 | -- Place the turtle |
| 25 | if turtle.place() then |
| 26 | print("✓ Turtle deployed successfully") |
| 27 | return true |
| 28 | else |
| 29 | print("✗ Failed to place turtle - check space") |
| 30 | return false |
| 31 | end |
| 32 | end |
| 33 | end |
| 34 | end |
| 35 | |
| 36 | print("✗ No " .. turtleType .. " found in inventory") |
| 37 | return false |
| 38 | end |
| 39 | |
| 40 | local function initializeTurtle(id, program) |
| 41 | print("Initializing turtle " .. id .. " with " .. program .. "...") |
| 42 | |
| 43 | -- Send initialization command |
| 44 | rednet.send(id, { |
| 45 | command = "INIT", |
| 46 | program = program, |
| 47 | autostart = true |
| 48 | }) |
| 49 | |
| 50 | -- Wait for response |
| 51 | local senderId, response = rednet.receive(5) |
| 52 | if senderId == id and response and response.status == "READY" then |
| 53 | print("✓ Turtle " .. id .. " initialized successfully") |
| 54 | return true |
| 55 | else |
| 56 | print("✗ Turtle " .. id .. " initialization failed or timed out") |
| 57 | return false |
| 58 | end |
| 59 | end |
| 60 | |
| 61 | local function setupGPS() |
| 62 | print("Setting up GPS system...") |
| 63 | |
| 64 | -- Try to get GPS coordinates |
| 65 | local x, y, z = gps.locate() |
| 66 | if x then |
| 67 | print("✓ GPS location: " .. x .. ", " .. y .. ", " .. z) |
| 68 | return true |
| 69 | else |
| 70 | print("⚠ GPS not available - manual positioning required") |
| 71 | return false |
| 72 | end |
| 73 | end |
| 74 | |
| 75 | print("eHydra Initialization System v1.0") |
| 76 | print("=================================") |
| 77 | print() |
| 78 | |
| 79 | -- Check for modem |
| 80 | local modemSide = findModem() |
| 81 | if modemSide then |
| 82 | rednet.open(modemSide) |
| 83 | print("✓ Modem found on " .. modemSide .. " side") |
| 84 | else |
| 85 | print("⚠ No modem found - limited functionality") |
| 86 | end |
| 87 | |
| 88 | print() |
| 89 | print("Select operation:") |
| 90 | print("1. Deploy Advanced Mining Turtle") |
| 91 | print("2. Deploy Advanced Wireless Chunky Turtle") |
| 92 | print("3. Initialize existing turtle") |
| 93 | print("4. Setup GPS system") |
| 94 | print("5. Full deployment sequence") |
| 95 | print() |
| 96 | |
| 97 | write("Choice [1-5]: ") |
| 98 | local choice = tonumber(read()) or 1 |
| 99 | |
| 100 | if choice == 1 then |
| 101 | print() |
| 102 | print("Deploying Advanced Mining Turtle...") |
| 103 | deployTurtle("turtle_advanced", "current") |
| 104 | |
| 105 | elseif choice == 2 then |
| 106 | print() |
| 107 | print("Deploying Advanced Wireless Chunky Turtle...") |
| 108 | deployTurtle("turtle_advanced", "current") |
| 109 | |
| 110 | -- Additional setup for chunky turtles |
| 111 | print("Configuring chunky loading...") |
| 112 | -- This would require specific chunky turtle setup |
| 113 | |
| 114 | elseif choice == 3 then |
| 115 | if not modemSide then |
| 116 | print("Error: Modem required for turtle initialization") |
| 117 | return |
| 118 | end |
| 119 | |
| 120 | print() |
| 121 | write("Turtle ID: ") |
| 122 | local id = tonumber(read()) |
| 123 | |
| 124 | write("Program to load [quarry]: ") |
| 125 | local program = read() |
| 126 | if program == "" then program = "quarry" end |
| 127 | |
| 128 | initializeTurtle(id, program) |
| 129 | |
| 130 | elseif choice == 4 then |
| 131 | setupGPS() |
| 132 | |
| 133 | elseif choice == 5 then |
| 134 | print() |
| 135 | print("Full Deployment Sequence") |
| 136 | print("=======================") |
| 137 | |
| 138 | -- Setup GPS |
| 139 | setupGPS() |
| 140 | |
| 141 | print() |
| 142 | write("Number of turtles to deploy [1]: ") |
| 143 | local count = tonumber(read()) or 1 |
| 144 | |
| 145 | write("Turtle type (mining/chunky) [mining]: ") |
| 146 | local turtleType = read() |
| 147 | if turtleType == "" then turtleType = "mining" end |
| 148 | |
| 149 | write("Mining program [quarry]: ") |
| 150 | local program = read() |
| 151 | if program == "" then program = "quarry" end |
| 152 | |
| 153 | print() |
| 154 | print("Deploying " .. count .. " " .. turtleType .. " turtle(s)...") |
| 155 | |
| 156 | for i = 1, count do |
| 157 | print() |
| 158 | print("Deploying turtle " .. i .. "/" .. count .. "...") |
| 159 | |
| 160 | if deployTurtle("turtle_advanced", i) then |
| 161 | -- Wait a moment for turtle to boot |
| 162 | sleep(2) |
| 163 | |
| 164 | if modemSide then |
| 165 | -- Try to initialize the turtle |
| 166 | -- This would require the turtle to have a known ID or auto-discovery |
| 167 | print("Turtle deployed - manual initialization may be required") |
| 168 | end |
| 169 | end |
| 170 | end |
| 171 | |
| 172 | print() |
| 173 | print("Deployment sequence complete!") |
| 174 | |
| 175 | else |
| 176 | print("Invalid choice") |
| 177 | end |
| 178 | |
| 179 | print() |
| 180 | print("eHydra initialization finished.") |
| 181 |