mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2026-09-14 11:06:16 +05:00
aefae
This commit is contained in:
parent
08dfb6e30a
commit
1a28f00c3e
@ -1,6 +1,7 @@
|
||||
|
||||
local AR = require("advancedRobot")
|
||||
local event = require("event")
|
||||
local sides = require("sides")
|
||||
local serialization = require("serialization")
|
||||
|
||||
local port = 512
|
||||
@ -29,67 +30,104 @@ while true do
|
||||
if e[1] == "modem_message" and e[6] == "VRScan" then
|
||||
if e[7] == "scan" then
|
||||
local settings = serialization.unserialize(e[8])
|
||||
|
||||
local w, h, l
|
||||
|
||||
AR.positionX = 0
|
||||
AR.positionY = 0
|
||||
AR.positionZ = 0
|
||||
AR.rotation = 0
|
||||
|
||||
print("Scanning with paramerers: " .. e[8])
|
||||
|
||||
local h, w, l, startX, startY, startZ = 0, 0, 0, AR.positionX, AR.positionY, AR.positionZ
|
||||
|
||||
local function move()
|
||||
local distance = settings.radius * 2 + 1
|
||||
local moveX, moveZ = AR.getRotatedPosition(w * distance, l * distance)
|
||||
|
||||
AR.moveToPosition(
|
||||
startX + moveX,
|
||||
startY + h * distance,
|
||||
startZ + moveZ
|
||||
)
|
||||
local function moveChunk(side)
|
||||
for i = 1, settings.radius * 2 + 1 do
|
||||
AR.swingAndMove(side)
|
||||
end
|
||||
end
|
||||
|
||||
while h < settings.height do
|
||||
while w < settings.width do
|
||||
while l < settings.length do
|
||||
print("Scanning chunk " .. w .. " x " .. h .. " x " .. l)
|
||||
local function doChunk()
|
||||
print("Scanning chunk " .. w .. " x " .. h .. " x " .. l)
|
||||
|
||||
local result, column = {
|
||||
x = AR.positionX,
|
||||
y = AR.positionY,
|
||||
z = AR.positionZ,
|
||||
blocks = {}
|
||||
}
|
||||
|
||||
local blockCount = 0
|
||||
for z = -settings.radius, settings.radius do
|
||||
for x = -settings.radius, settings.radius do
|
||||
column = AR.proxies.geolyzer.scan(x, z)
|
||||
|
||||
local result, column = {
|
||||
x = AR.positionX,
|
||||
y = AR.positionY,
|
||||
z = AR.positionZ,
|
||||
blocks = {}
|
||||
}
|
||||
for i = 32 - settings.radius, 32 + settings.radius do
|
||||
if column[i] >= settings.minDensity and column[i] <= settings.maxDensity then
|
||||
local y = i - 33
|
||||
result.blocks[x] = result.blocks[x] or {}
|
||||
result.blocks[x][y] = result.blocks[x][y] or {}
|
||||
result.blocks[x][y][z] = result.blocks[x][y][z] or {}
|
||||
table.insert(result.blocks[x][y][z], round(column[i], 2))
|
||||
|
||||
local blockCount = 0
|
||||
for z = -settings.radius, settings.radius do
|
||||
for x = -settings.radius, settings.radius do
|
||||
column = AR.proxies.geolyzer.scan(x, z)
|
||||
|
||||
for i = 32 - settings.radius, 32 + settings.radius do
|
||||
if column[i] >= settings.minDensity and column[i] <= settings.maxDensity then
|
||||
local y = i - 33
|
||||
result.blocks[x] = result.blocks[x] or {}
|
||||
result.blocks[x][y] = result.blocks[x][y] or {}
|
||||
result.blocks[x][y][z] = result.blocks[x][y][z] or {}
|
||||
table.insert(result.blocks[x][y][z], round(column[i], 2))
|
||||
blockCount = blockCount + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
blockCount = blockCount + 1
|
||||
end
|
||||
end
|
||||
print("Scanning finished. Sending result with blocks size: " .. blockCount)
|
||||
broadcast("result", serialization.serialize(result))
|
||||
end
|
||||
|
||||
local function doLength()
|
||||
l = 1
|
||||
while l <= settings.length do
|
||||
doChunk()
|
||||
if l < settings.length then
|
||||
moveChunk(sides.front)
|
||||
end
|
||||
l = l + 1
|
||||
end
|
||||
end
|
||||
|
||||
h = 1
|
||||
while h <= settings.height do
|
||||
w = 1
|
||||
while w <= settings.width do
|
||||
doLength()
|
||||
|
||||
AR.turnRight()
|
||||
moveChunk(sides.front)
|
||||
AR.turnRight()
|
||||
|
||||
doLength()
|
||||
|
||||
if w < settings.width then
|
||||
AR.turnLeft()
|
||||
moveChunk(sides.front)
|
||||
AR.turnLeft()
|
||||
else
|
||||
AR.turnRight()
|
||||
for i = 1, settings.width * 2 - 1 do
|
||||
moveChunk(sides.front)
|
||||
end
|
||||
AR.turnRight()
|
||||
|
||||
if h < settings.height then
|
||||
moveChunk(sides.up)
|
||||
else
|
||||
for i = 1, settings.height - 1 do
|
||||
moveChunk(sides.down)
|
||||
end
|
||||
end
|
||||
|
||||
print("Scanning finished. Sending result with blocks size: " .. blockCount)
|
||||
broadcast("result", serialization.serialize(result))
|
||||
|
||||
l = l + 1
|
||||
move()
|
||||
end
|
||||
|
||||
w = w + 1
|
||||
move()
|
||||
end
|
||||
|
||||
h = h + 1
|
||||
move()
|
||||
end
|
||||
|
||||
print("Task finished")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -58,18 +58,6 @@ AR.rotation = 0
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
function AR.getRotatedPosition(x, z)
|
||||
if AR.rotation == 0 then
|
||||
return x, z
|
||||
elseif AR.rotation == 1 then
|
||||
return -z, x
|
||||
elseif AR.rotation == 2 then
|
||||
return -x, -z
|
||||
else
|
||||
return z, -x
|
||||
end
|
||||
end
|
||||
|
||||
function AR.updateProxies()
|
||||
local name
|
||||
for name in pairs(AR.requiredProxies) do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user