multi.lua

121 lines · 3.6 KB

Open raw

Send coordinated eDig jobs to multiple turtles

Copy & run

wget https://perlytiara.github.io/turtles.tips/raw/programs/perlytiara/eDig/multi.lua
1-- multi.lua - Send coordinated eDig jobs to multiple turtles
2local function findModem()
3 for _, side in pairs(rs.getSides()) do
4 if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
5 return side
6 end
7 end
8 error("No modem found!")
9end
10
11rednet.open(findModem())
12
13print("Multi-Turtle eDig Coordinator")
14print("Supports simultaneous row-based coordination")
15
16write("Tunnel type (straight/dome/size2) [straight]: ")
17local shape = string.lower(read())
18if shape ~= "dome" and shape ~= "size2" then
19 shape = "straight"
20end
21
22local height, width, length
23if shape == "straight" then
24 write("Tunnel height (blocks) [3]: ")
25 height = tonumber(read()) or 3
26
27 write("Tunnel width (blocks) [3]: ")
28 width = tonumber(read()) or 3
29else
30 if shape == "size2" then
31 height = 3
32 width = 7
33 print("Dome shape: size2 (7 wide, max 7 turtles)")
34 else
35 height = 3
36 width = 5
37 print("Dome shape: custom (5 wide, max 5 turtles)")
38 end
39end
40
41write("Tunnel length (blocks) [32]: ")
42length = tonumber(read()) or 32
43
44write("Place floor blocks? (y/n) [n]: ")
45local place = string.lower(read()) == "y" and "place" or ""
46
47write("Turtle IDs (space-separated): ")
48local idStr = read()
49local ids = {}
50for id in idStr:gmatch("%S+") do
51 local num = tonumber(id)
52 if num then table.insert(ids, num) end
53end
54
55if #ids == 0 then
56 print("No valid turtle IDs")
57 return
58end
59
60-- Limit turtles based on shape
61local maxTurtles = shape == "straight" and width or (shape == "size2" and 7 or 5)
62if #ids > maxTurtles then
63 print("Warning: " .. shape .. " shape supports max " .. maxTurtles .. " turtles")
64 print("Using first " .. maxTurtles .. " turtles")
65 while #ids > maxTurtles do
66 table.remove(ids)
67 end
68end
69
70write("Coordination mode:")
71print("1. Row-based (turtles work on different rows simultaneously)")
72print("2. Segment-based (turtles work on different segments)")
73write("Choose (1/2) [1]: ")
74local coordMode = read()
75if coordMode ~= "2" then coordMode = "1" end
76
77local segmentLength = 0
78if coordMode == "2" then
79 write("Segment length (blocks per turtle) [8]: ")
80 segmentLength = tonumber(read()) or 8
81end
82
83-- Build command
84local cmd = tostring(height) .. " " .. tostring(length) .. " " .. tostring(width)
85if place ~= "" then cmd = cmd .. " " .. place end
86if shape ~= "straight" then cmd = cmd .. " " .. shape end
87
88-- Send to turtles with coordination
89print("\nSending coordinated jobs to " .. #ids .. " turtles...")
90
91if coordMode == "2" then
92 -- Segment-based coordination
93 print("Segment-based coordination")
94 local totalLength = length
95 local segments = math.ceil(totalLength / segmentLength)
96
97 for i = 1, #ids do
98 local turtleId = ids[i]
99 local segmentStart = (i - 1) * segmentLength
100 local segmentEnd = math.min(segmentStart + segmentLength, totalLength)
101 local segmentLengthActual = segmentEnd - segmentStart
102
103 if segmentLengthActual > 0 then
104 local segmentCmd = cmd .. " " .. tostring(i)
105 print("Turtle " .. turtleId .. " (Segment " .. i .. "): " .. segmentLengthActual .. " blocks")
106 rednet.send(turtleId, {command = "RUN", args = segmentCmd})
107 end
108 end
109else
110 -- Row-based coordination (simultaneous)
111 print("Row-based coordination - all turtles start simultaneously")
112 for i = 1, #ids do
113 local turtleId = ids[i]
114 local rowCmd = cmd .. " " .. tostring(i) .. " " .. tostring(width)
115 print("Turtle " .. turtleId .. " (Row " .. i .. "): " .. width .. " blocks wide")
116 rednet.send(turtleId, {command = "RUN", args = rowCmd})
117 end
118end
119
120print("\nJobs sent! All turtles starting simultaneously...")
121print("Monitor individual turtle progress for coordination status.")