mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2026-03-26 17:52:47 +01:00
))
This commit is contained in:
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
local robotAPI = require("robotAPI")
|
||||
local AR = require("AR")
|
||||
local args = {...}
|
||||
|
||||
if #args < 0 then
|
||||
@@ -10,23 +10,23 @@ print("Task stated")
|
||||
|
||||
local function execute(symbol)
|
||||
if symbol == "f" then
|
||||
print("Moving forward:", robotAPI.moveForward())
|
||||
print("Moving forward:", AR.moveForward())
|
||||
elseif symbol == "b" then
|
||||
print("Moving backward:", robotAPI.moveBackward())
|
||||
print("Moving backward:", AR.moveBackward())
|
||||
elseif symbol == "u" then
|
||||
print("Moving up:", robotAPI.moveUp())
|
||||
print("Moving up:", AR.moveUp())
|
||||
elseif symbol == "d" then
|
||||
print("Moving down:", robotAPI.moveDown())
|
||||
print("Moving down:", AR.moveDown())
|
||||
elseif symbol == "r" then
|
||||
print("Turning right:", robotAPI.turnRight())
|
||||
print("Turning right:", AR.turnRight())
|
||||
elseif symbol == "l" then
|
||||
print("Turning left:", robotAPI.turnLeft())
|
||||
print("Turning left:", AR.turnLeft())
|
||||
elseif symbol == "t" then
|
||||
print("Turning around:", robotAPI.turnAround())
|
||||
print("Turning around:", AR.turnAround())
|
||||
elseif symbol == "s" then
|
||||
print("Swinging:", robotAPI.swing())
|
||||
print("Swinging:", AR.swingForward())
|
||||
elseif symbol == "e" then
|
||||
print("Swinging:", robotAPI.use())
|
||||
print("Swinging:", AR.useForward())
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
|
||||
_G.robotAPI, package.loaded.robotAPI = nil, nil
|
||||
|
||||
local robotAPI = require("robotAPI")
|
||||
local sides = require("sides")
|
||||
local component = require("component")
|
||||
local inventoryController = component.inventory_controller
|
||||
local robotComponent = component.robot
|
||||
|
||||
-----------------------------------------------------------------
|
||||
|
||||
local args = {...}
|
||||
if not (args[1] and args[2] and args[3]) then
|
||||
print("Usage: diamonds <length> <height> <width> <torch cyka>")
|
||||
return
|
||||
end
|
||||
|
||||
local length, height, width, torchFrequency = tonumber(args[1]), tonumber(args[2]), tonumber(args[3]), tonumber(args[4] or 7)
|
||||
local torchCount, torchSlot
|
||||
|
||||
-----------------------------------------------------------------
|
||||
|
||||
local function getItemSlotAndCount(item)
|
||||
for slot = 1, robotComponent.inventorySize() do
|
||||
local stack = inventoryController.getStackInInternalSlot(slot)
|
||||
if stack and stack.name == item then
|
||||
return slot, stack.size
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function doLength()
|
||||
for l = 1, length do
|
||||
robotAPI.moveForward()
|
||||
robotAPI.swingUp()
|
||||
robotAPI.swingDown()
|
||||
if l % torchFrequency == 0 and torchSlot and torchCount > 0 and robotAPI.robotPosition.y == 0 then
|
||||
robotComponent.select(torchSlot)
|
||||
robotComponent.place(sides.down)
|
||||
torchCount = torchCount - 1
|
||||
end
|
||||
end
|
||||
|
||||
robotAPI.tryToDropShittyResources()
|
||||
robotAPI.checkGeneratorStatus()
|
||||
robotAPI.checkEnergyStatus()
|
||||
robotAPI.checkToolStatus()
|
||||
end
|
||||
|
||||
local function doHeight()
|
||||
for h = 1, height do
|
||||
doLength()
|
||||
for i = 1, 3 do robotAPI.moveUp() end
|
||||
robotAPI.turnAround()
|
||||
doLength()
|
||||
robotAPI.turnAround()
|
||||
if h < height then for i = 1, 3 do robotAPI.moveUp() end end
|
||||
end
|
||||
end
|
||||
|
||||
local function doWidth()
|
||||
for w = 1, width do
|
||||
doHeight()
|
||||
for i = 1, height * 3 * 2 - 3 do robotAPI.moveDown() end
|
||||
|
||||
if w < width then
|
||||
robotAPI.turnRight()
|
||||
for i = 1, 3 do robotAPI.moveForward() end
|
||||
robotAPI.turnLeft()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------
|
||||
|
||||
-- Ставим стартовый сундук
|
||||
local chestSlot = getItemSlotAndCount("minecraft:chest")
|
||||
if chestSlot then
|
||||
robotAPI.turnAround()
|
||||
robotComponent.select(chestSlot)
|
||||
robotComponent.place(sides.front)
|
||||
robotAPI.turnAround()
|
||||
end
|
||||
|
||||
-- Получаем слот факела
|
||||
torchSlot, torchCount = getItemSlotAndCount("minecraft:torch")
|
||||
|
||||
-- Ебошим
|
||||
doWidth()
|
||||
|
||||
-- Пиздуем назад
|
||||
robotAPI.returnToStartPoint()
|
||||
|
||||
-- Скидываем говно в сундук, если он ваще был
|
||||
if chestSlot then
|
||||
robotAPI.turnAround()
|
||||
robotAPI.dropAllResources(sides.front)
|
||||
robotAPI.turnAround()
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,43 +1,46 @@
|
||||
|
||||
local component = require("component")
|
||||
local robot = require("robot")
|
||||
local currentToolSlot = 1
|
||||
local counter = 0
|
||||
local inventorySize = robot.inventorySize()
|
||||
|
||||
local args = {...}
|
||||
|
||||
robot.select(1)
|
||||
local success
|
||||
while true do
|
||||
success = robot.swing()
|
||||
if success then
|
||||
robot.place()
|
||||
end
|
||||
counter = counter + 1
|
||||
if counter > 50 then
|
||||
local durability = robot.durability() or 500000000
|
||||
counter = 0
|
||||
print("Текущая экспа: " .. robot.level())
|
||||
print("Текущий слот: " .. currentToolSlot)
|
||||
print("Текущая прочность: " .. durability)
|
||||
print(" ")
|
||||
if durability < 0.1 then
|
||||
currentToolSlot = currentToolSlot + 1
|
||||
if currentToolSlot > inventorySize then currentToolSlot = inventorySize end
|
||||
robot.select(currentToolSlot)
|
||||
component.inventory_controller.equip()
|
||||
robot.select(1)
|
||||
end
|
||||
end
|
||||
local function printUsage()
|
||||
print("Usages:")
|
||||
print("exp")
|
||||
print(" Gets the current level.")
|
||||
print("exp <slot>")
|
||||
print(" Tries to consume an enchanted item to add")
|
||||
print(" expierence to the upgrade")
|
||||
print(" from the specified slot.")
|
||||
print("exp all")
|
||||
print(" from all slots.")
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if component.isAvailable("experience") then
|
||||
local e = component.experience
|
||||
if #args == 0 then
|
||||
print("Level: "..e.level())
|
||||
elseif tonumber(args[1]) ~= nil then
|
||||
local slot = tonumber(args[1])
|
||||
robot.select(slot)
|
||||
io.write("Experience from slot "..slot.."... ")
|
||||
local success, msg = e.consume()
|
||||
if success then
|
||||
print("success.")
|
||||
else
|
||||
print("failed: "..msg)
|
||||
end
|
||||
robot.select(1)
|
||||
elseif string.lower(args[1]) == "all" then
|
||||
io.write("Experience from all slots... ")
|
||||
for i = 1, robot.inventorySize() do
|
||||
robot.select(i)
|
||||
e.consume()
|
||||
end
|
||||
robot.select(1)
|
||||
print("done.")
|
||||
else
|
||||
printUsage()
|
||||
end
|
||||
else
|
||||
print("This program requires the experience upgrade to be installed.")
|
||||
end
|
||||
@@ -1,413 +0,0 @@
|
||||
|
||||
local computer = require("computer")
|
||||
local component = require("component")
|
||||
local robot = require("robot")
|
||||
local event = require("event")
|
||||
local sides = require("sides")
|
||||
local geo = component.geolyzer
|
||||
local inventoryController = component.inventory_controller
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local fuels = {
|
||||
"minecraft:coal",
|
||||
"minecraft:lava_bucket",
|
||||
"minecraft:coal_block",
|
||||
}
|
||||
|
||||
local shittyResources = {
|
||||
"minecraft:cobblestone",
|
||||
"minecraft:grass",
|
||||
"minecraft:dirt",
|
||||
"minecraft:gravel",
|
||||
"minecraft:sand",
|
||||
"minecraft:sandstone",
|
||||
"minecraft:torch",
|
||||
"minecraft:planks",
|
||||
"minecraft:fence",
|
||||
"minecraft:chest",
|
||||
"minecraft:monster_egg",
|
||||
"minecraft:stonebrick",
|
||||
}
|
||||
|
||||
local oreSearchRadius = 24
|
||||
local searchPassesCount = 5
|
||||
local minimumOreHardness = 2.5
|
||||
local maximumOreHardness = 9
|
||||
local replaceToolDurabilityTrigger = 0.05
|
||||
local replaceToolRegex = "(minecraft:).+(_pickaxe)"
|
||||
local rechargeTrigger = 0.1
|
||||
local dropShittyResourcesOnEmptySlots = 5
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
local program = {}
|
||||
local robotPosition = {x = 0, y = 0, z = 0, rotation = 0}
|
||||
local energyStatusCheckEnabled = true
|
||||
local toolStatusCheckEnabled = true
|
||||
local generatorIsAvailable = component.isAvailable("generator")
|
||||
|
||||
function program.scan(radius, passes, minHardness, maxHardness)
|
||||
local ores = {}
|
||||
|
||||
-- Заносим все руды в массивыч руд
|
||||
for pass = 1, passes do
|
||||
print("Scan pass " .. pass .. " started...")
|
||||
for x = -radius, radius do
|
||||
for z = -radius, radius do
|
||||
local stack = geo.scan(x, z, true)
|
||||
for y = 1, #stack do
|
||||
if stack[y] >= minHardness and stack[y] <= maxHardness then
|
||||
-- Заполняем координатную сетку, если массивов еще не существует
|
||||
ores[x] = ores[x] or {}
|
||||
ores[x][y] = ores[x][y] or {}
|
||||
|
||||
-- Если мы уже сканировали этот блок, то получаем среднюю плотность из двух значений
|
||||
-- Если нет, то банально ставим полученное значение
|
||||
if ores[x][y][z] then
|
||||
ores[x][y][z] = (ores[x][y][z] + stack[y]) / 2
|
||||
else
|
||||
ores[x][y][z] = stack[y]
|
||||
end
|
||||
|
||||
-- print("x=" .. x .. ", y=" .. y .. ", z=" .. z .. ", hardness=" .. stack[y])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Проверяем энергосостояние, а то уже один раз вылетело с ошибкой нот еаугх ЕНЕРГИ, БЛЯДЬ!!11
|
||||
program.checkEnergyStatus()
|
||||
end
|
||||
end
|
||||
|
||||
-- Переебошиваем массив руд для более удобной работы с ним в линейном формате
|
||||
-- Не забываем подчищать говнище за собой, а то роботы не резиновые
|
||||
local newOres = {}
|
||||
for x in pairs(ores) do
|
||||
for y in pairs(ores[x]) do
|
||||
for z in pairs(ores[x][y]) do
|
||||
table.insert(newOres, {x = robotPosition.x + x, y = robotPosition.y + y - 33, z = robotPosition.z + z})
|
||||
ores[x][y][z] = nil
|
||||
end
|
||||
ores[x][y] = nil
|
||||
end
|
||||
ores[x]= nil
|
||||
end
|
||||
|
||||
return newOres
|
||||
end
|
||||
|
||||
local function getHardness(x, z)
|
||||
local stack = geo.scan(x, z)
|
||||
for i = 1, #stack do
|
||||
print("i=" .. i .. ", val=" .. stack[i])
|
||||
event.pull("key_down")
|
||||
end
|
||||
end
|
||||
|
||||
function program.move(direction)
|
||||
while true do
|
||||
local swingSuccess, swingReason = component.robot.swing(direction)
|
||||
if swingSuccess or swingReason == "air" then
|
||||
local moveSuccess, moveReason = component.robot.move(direction)
|
||||
if moveSuccess then
|
||||
break
|
||||
end
|
||||
else
|
||||
if swingReason == "block" then
|
||||
print("Unbreakable block detected, going to base")
|
||||
program.returnToBase()
|
||||
os.exit()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if direction == sides.front or direction == sides.back then
|
||||
local directionOffset = direction == sides.front and 1 or -1
|
||||
|
||||
if robotPosition.rotation == 0 then
|
||||
robotPosition.x = robotPosition.x + directionOffset
|
||||
elseif robotPosition.rotation == 1 then
|
||||
robotPosition.z = robotPosition.z + directionOffset
|
||||
elseif robotPosition.rotation == 2 then
|
||||
robotPosition.x = robotPosition.x - directionOffset
|
||||
elseif robotPosition.rotation == 3 then
|
||||
robotPosition.z = robotPosition.z - directionOffset
|
||||
end
|
||||
elseif direction == sides.up or direction == sides.down then
|
||||
local directionOffset = direction == sides.up and 1 or -1
|
||||
robotPosition.y = robotPosition.y + directionOffset
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function program.returnToBase()
|
||||
program.gotoPoint(0, robotPosition.y, 0)
|
||||
program.turnToRequiredRotation(0)
|
||||
program.gotoPoint(0, -2, 0)
|
||||
program.tryToDropShittyResources()
|
||||
program.gotoPoint(0, 0, 0)
|
||||
program.dropAllResoucesIntoBaseChest()
|
||||
end
|
||||
|
||||
function program.getSlotWithFuel()
|
||||
for slot = 1, component.robot.inventorySize() do
|
||||
local stack = inventoryController.getStackInInternalSlot(slot)
|
||||
if stack then
|
||||
for fuel = 1, #fuels do
|
||||
if stack.name == fuels[fuel] then
|
||||
return slot
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function program.tryToRechargeByGenerator()
|
||||
if generatorIsAvailable then
|
||||
if component.generator.count() == 0 then
|
||||
print("Generator is empty, trying to find some fuel in inventory")
|
||||
local slot = program.getSlotWithFuel()
|
||||
if slot then
|
||||
print("Found slot with fuel: " .. slot)
|
||||
local oldSlot = robot.select(slot)
|
||||
component.generator.insert()
|
||||
robot.select(oldSlot)
|
||||
return
|
||||
else
|
||||
print("Slot with fuel not found")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function program.checkEnergyStatus()
|
||||
if computer.energy() / computer.maxEnergy() < rechargeTrigger then
|
||||
print("Low energy level detected")
|
||||
energyStatusCheckEnabled = false
|
||||
-- Запоминаем старую позицию, шобы суда вернуться
|
||||
local oldPosition = {x = robotPosition.x, y = robotPosition.y, z = robotPosition.z, rotation = robotPosition.rotation}
|
||||
-- Пиздуем на базу за зарядкой
|
||||
program.returnToBase()
|
||||
-- Заряжаемся, пока энергия не достигнет более-менее максимума
|
||||
while computer.energy() / computer.maxEnergy() < 0.99 do
|
||||
print("Charging up: " .. math.floor(computer.energy() / computer.maxEnergy() * 100) .. "%")
|
||||
os.sleep(1)
|
||||
end
|
||||
-- Пиздуем обратно
|
||||
program.gotoPoint(oldPosition.x, oldPosition.y, oldPosition.z)
|
||||
program.turnToRequiredRotation(oldPosition.rotation)
|
||||
energyStatusCheckEnabled = true
|
||||
end
|
||||
end
|
||||
|
||||
function program.turn(clockwise)
|
||||
component.robot.turn(clockwise)
|
||||
robotPosition.rotation = robotPosition.rotation + (clockwise and 1 or -1)
|
||||
if robotPosition.rotation > 3 then
|
||||
robotPosition.rotation = 0
|
||||
elseif robotPosition.rotation < 0 then
|
||||
robotPosition.rotation = 3
|
||||
end
|
||||
end
|
||||
|
||||
function program.turnToRequiredRotation(requiredRotation)
|
||||
local difference = robotPosition.rotation - requiredRotation
|
||||
|
||||
if difference ~= 0 then
|
||||
local fastestWay
|
||||
if difference > 0 then
|
||||
if difference > 2 then fastestWay = true else fastestWay = false end
|
||||
else
|
||||
if -difference > 2 then fastestWay = false else fastestWay = true end
|
||||
end
|
||||
|
||||
while robotPosition.rotation ~= requiredRotation do
|
||||
program.turn(fastestWay)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function program.gotoPoint(xTarget, yTarget, zTarget)
|
||||
local xDistance = xTarget - robotPosition.x
|
||||
local yDistance = yTarget - robotPosition.y
|
||||
local zDistance = zTarget - robotPosition.z
|
||||
|
||||
if yDistance ~= 0 then
|
||||
local direction = yDistance > 0 and sides.up or sides.down
|
||||
for i = 1, math.abs(yDistance) do program.move(direction) end
|
||||
end
|
||||
|
||||
if xDistance ~= 0 then
|
||||
program.turnToRequiredRotation(xDistance > 0 and 0 or 2)
|
||||
for i = 1, math.abs(xDistance) do program.move(sides.front) end
|
||||
end
|
||||
|
||||
if zDistance ~= 0 then
|
||||
program.turnToRequiredRotation(zDistance > 0 and 1 or 3)
|
||||
for i = 1, math.abs(zDistance) do program.move(sides.front) end
|
||||
end
|
||||
|
||||
-- Если количество пустых слотов меньше, чем лимит пустых слотов,
|
||||
-- то выбрасываем весь дерьмовый шмот, указанный в массиве дерьмового шмота
|
||||
program.tryToDropShittyResources()
|
||||
|
||||
-- Если включена проверка энергосостояния, то делаем ее и возвращаемся на базу
|
||||
-- для подзарядки, если требуется
|
||||
if energyStatusCheckEnabled then program.checkEnergyStatus() end
|
||||
|
||||
-- Проверяем также состояние инструментов
|
||||
if toolStatusCheckEnabled then program.checkToolStatus() end
|
||||
|
||||
-- А еще заправляем генератор
|
||||
program.tryToRechargeByGenerator()
|
||||
end
|
||||
|
||||
function program.findNearestOre(ores)
|
||||
local nearest
|
||||
for i = 1, #ores do
|
||||
local distance = math.sqrt((ores[i].x - robotPosition.x) ^ 2 + (ores[i].y - robotPosition.y) ^ 2 + (ores[i].z - robotPosition.z) ^ 2)
|
||||
if not nearest or distance < nearest.distance then
|
||||
nearest = {x = ores[i].x, y = ores[i].y, z = ores[i].z, distance = distance, oreIndex = i}
|
||||
end
|
||||
end
|
||||
return nearest
|
||||
end
|
||||
|
||||
function program.scanAndDig(radius, passes, minHardness, maxHardness, bedrockLocation)
|
||||
local ores = program.scan(radius, passes, minHardness, maxHardness)
|
||||
print("Scanning finished, count of resources to mine: " .. #ores)
|
||||
while #ores > 0 do
|
||||
local nearest = program.findNearestOre(ores)
|
||||
if nearest.y >= bedrockLocation and nearest.y < 0 then
|
||||
-- print("Found next nearest ore: (" .. nearest.x .. "; " .. nearest.y .. "; " .. nearest.z .. ")")
|
||||
program.gotoPoint(nearest.x, nearest.y, nearest.z)
|
||||
end
|
||||
table.remove(ores, nearest.oreIndex)
|
||||
end
|
||||
end
|
||||
|
||||
function program.getBedrockLocation()
|
||||
while true do
|
||||
local success, reason = component.robot.swing(sides.down)
|
||||
if success or reason == "air" then
|
||||
program.move(sides.down)
|
||||
else
|
||||
if reason == "block" then
|
||||
print("Bedrock location is: " .. robotPosition.y)
|
||||
return robotPosition.y
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function program.getEmptySlotsCount()
|
||||
local count = 0
|
||||
for slot = 1, robot.inventorySize() do
|
||||
count = count + (robot.count(slot) == 0 and 1 or 0)
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
function program.tryToDropShittyResources()
|
||||
if program.getEmptySlotsCount() < dropShittyResourcesOnEmptySlots then
|
||||
print("Trying to drop all shitty resources to free some slots for mining")
|
||||
for slot = 1, robot.inventorySize() do
|
||||
local stack = inventoryController.getStackInInternalSlot(slot)
|
||||
if stack then
|
||||
for i = 1, #shittyResources do
|
||||
if stack.name == shittyResources[i] then
|
||||
robot.select(slot)
|
||||
robot.drop()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if program.getEmptySlotsCount() < dropShittyResourcesOnEmptySlots - 2 then
|
||||
local oldPosition = {x = robotPosition.x, y = robotPosition.y, z = robotPosition.z, rotation = robotPosition.rotation}
|
||||
program.returnToBase()
|
||||
program.gotoPoint(oldPosition.x, oldPosition.y, oldPosition.z)
|
||||
program.turnToRequiredRotation(oldPosition.rotation)
|
||||
end
|
||||
|
||||
robot.select(1)
|
||||
end
|
||||
end
|
||||
|
||||
function program.dropAllResoucesIntoBaseChest()
|
||||
print("Dropping all mined resources to chest on base")
|
||||
for slot = 1, robot.inventorySize() do
|
||||
local stack = inventoryController.getStackInInternalSlot(slot)
|
||||
if stack then
|
||||
if not string.match(stack.name, replaceToolRegex) then
|
||||
robot.select(slot)
|
||||
robot.drop()
|
||||
end
|
||||
end
|
||||
end
|
||||
robot.select(1)
|
||||
end
|
||||
|
||||
function program.checkToolStatus()
|
||||
if robot.durability() < replaceToolDurabilityTrigger then
|
||||
print("Equipped tool durability lesser then " .. replaceToolDurabilityTrigger)
|
||||
local success = false
|
||||
|
||||
for slot = 1, robot.inventorySize() do
|
||||
local stack = inventoryController.getStackInInternalSlot(slot)
|
||||
if stack then
|
||||
if string.match(stack.name, replaceToolRegex) and stack.damage / stack.maxDamage < replaceToolDurabilityTrigger then
|
||||
local oldSlot = robot.select(slot)
|
||||
inventoryController.equip()
|
||||
robot.select(oldSlot)
|
||||
success = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not success and toolStatusCheckEnabled then
|
||||
toolStatusCheckEnabled = false
|
||||
returnToBase()
|
||||
print("No one useable tool are found in inventory, going back to base")
|
||||
os.exit()
|
||||
else
|
||||
print("Successfullty switched tool to another from inventory")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
-- getHardness(1, 0)
|
||||
-- program.checkToolStatus()
|
||||
-- program.move(sides.front)
|
||||
|
||||
-- Выбираем сразу первый слотик по умолчанию
|
||||
robot.select(1)
|
||||
-- Определяем позицию говна
|
||||
print("Going deeper to determine bedrock location...")
|
||||
local bedrockLocation = program.getBedrockLocation() + 4
|
||||
-- Ебошим стартовую точку после определения позиции говна, и если она слишком высоко, то робот начнет как раз от нее же
|
||||
local startPoint = bedrockLocation + 32
|
||||
if startPoint > 0 then startPoint = 0 end
|
||||
|
||||
-- Пиздуем на старт и вкалываем до посинения
|
||||
program.gotoPoint(0, startPoint, 0)
|
||||
program.scanAndDig(oreSearchRadius, searchPassesCount, minimumOreHardness, maximumOreHardness, bedrockLocation)
|
||||
|
||||
-- В конце возвращаемся на начало и ожидаем, че уж там
|
||||
program.returnToBase()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
local robot = require("robot")
|
||||
local component = require("component")
|
||||
local robotAPI = require("robotAPI")
|
||||
local inventory = component.inventory_controller
|
||||
|
||||
local args = { ... }
|
||||
if #args < 2 then print(" "); print("Использование: laser <длина> <ширина>"); print(" "); return end
|
||||
|
||||
local width = tonumber(args[2])
|
||||
local length = tonumber(args[1])
|
||||
|
||||
for w = 1, width/2 do
|
||||
for h = 1, length do
|
||||
robot.useDown()
|
||||
if h < length then robotAPI.move("forward") end
|
||||
end
|
||||
|
||||
robot.turnRight()
|
||||
robotAPI.move("forward")
|
||||
robot.turnRight()
|
||||
|
||||
for h = 1, length do
|
||||
robot.useDown()
|
||||
if h < length then robotAPI.move("forward") end
|
||||
end
|
||||
|
||||
robot.turnLeft()
|
||||
robotAPI.move("forward")
|
||||
robot.turnLeft()
|
||||
end
|
||||
|
||||
Binary file not shown.
@@ -1,8 +0,0 @@
|
||||
local shell = require("shell")
|
||||
|
||||
shell.execute("wget https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Robot/robotAPI.lua lib/robotAPI.lua -f")
|
||||
|
||||
shell.execute("wget https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Robot/Diamonds.lua d.lua -f")
|
||||
shell.execute("wget https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Robot/Laser.lua l.lua -f")
|
||||
shell.execute("wget https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Robot/HorizontalLazer.lua hl.lua -f")
|
||||
shell.execute("wget https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/Applications/Robot/Quarry.lua q.lua -f")
|
||||
@@ -1,31 +0,0 @@
|
||||
local robot = require("robot")
|
||||
local component = require("component")
|
||||
local robotAPI = require("robotAPI")
|
||||
local inventory = component.inventory_controller
|
||||
|
||||
local args = { ... }
|
||||
if #args < 2 then print(" "); print("Использование: laser <ширина> <высота>"); print(" "); return end
|
||||
|
||||
local width = tonumber(args[1])
|
||||
local height = tonumber(args[2])
|
||||
|
||||
for w = 1, width/2 do
|
||||
for h = 1, height do
|
||||
robot.use()
|
||||
if h < height then robotAPI.move("up") end
|
||||
end
|
||||
|
||||
robot.turnRight()
|
||||
robotAPI.move("forward")
|
||||
robot.turnLeft()
|
||||
|
||||
for h = 1, height do
|
||||
robot.use()
|
||||
if h < height then robotAPI.move("down") end
|
||||
end
|
||||
|
||||
robot.turnRight()
|
||||
robotAPI.move("forward")
|
||||
robot.turnLeft()
|
||||
end
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
local robot = require("robot")
|
||||
local component = require("component")
|
||||
local robotAPI = require("robotAPI")
|
||||
local inventory = component.inventory_controller
|
||||
|
||||
local args = { ... }
|
||||
if #args < 3 then print(" "); print("Использование: diamonds <длина> <высота> <ширина>"); print(" "); return end
|
||||
|
||||
local length = args[1]
|
||||
local height = args[2]
|
||||
local width = args[3]
|
||||
|
||||
local function swingForLength()
|
||||
for i = 1, length do
|
||||
robotAPI.move("forward")
|
||||
robot.swingDown()
|
||||
robot.swingUp()
|
||||
end
|
||||
end
|
||||
|
||||
local function swingForUp()
|
||||
for i = 1, 3 do
|
||||
robotAPI.move("up")
|
||||
end
|
||||
end
|
||||
|
||||
local function swingForDown()
|
||||
for i = 1, 3 do
|
||||
robotAPI.move("down")
|
||||
end
|
||||
end
|
||||
|
||||
--Перебираем все ширины
|
||||
for i = 1, width do
|
||||
--Перебираем все высоты для конкретной ширины
|
||||
for i = 1, height do
|
||||
swingForLength()
|
||||
robot.turnAround()
|
||||
swingForUp()
|
||||
swingForLength()
|
||||
robot.turnAround()
|
||||
swingForUp()
|
||||
--Выбрасываем говно
|
||||
robotAPI.dropShmot()
|
||||
end
|
||||
|
||||
--Возвращаемся по высоте на конкретной ширине
|
||||
for i = 1, (height * 2) do
|
||||
swingForDown()
|
||||
end
|
||||
|
||||
--Двигаемся к следующей ширине
|
||||
robot.turnRight()
|
||||
|
||||
robotAPI.move("forward")
|
||||
|
||||
robot.turnLeft()
|
||||
end
|
||||
|
||||
--Возвращаемся домой из последней ширины
|
||||
robot.turnLeft()
|
||||
|
||||
for i = 1, width do
|
||||
robotAPI.move("forward")
|
||||
end
|
||||
|
||||
robot.turnRight()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,652 +0,0 @@
|
||||
|
||||
local component = require("component")
|
||||
local buffer = require("doubleBuffering")
|
||||
local unicode = require("unicode")
|
||||
local serialization = require("serialization")
|
||||
local context = require("context")
|
||||
local event = require("event")
|
||||
local keyboard = require("keyboard")
|
||||
local ecs = require("ECSAPI")
|
||||
local modem = component.modem
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
buffer.start()
|
||||
local xStart = math.floor(buffer.screen.width / 2)
|
||||
local yStart = math.floor(buffer.screen.height / 2 + 2)
|
||||
local port = 1337
|
||||
|
||||
local topBarElements = { "Карта", "Скрипт", "Инвентарь", "Редстоун", "Геоанализатор", "Бак" }
|
||||
local currentTopBarElement = 1
|
||||
|
||||
local drawInventoryFrom = 1
|
||||
local currentInventoryType = "internal"
|
||||
|
||||
local map = {
|
||||
robot = {
|
||||
x = 0, y = 0, z = 0,
|
||||
rotation = 1,
|
||||
status = "Ожидание",
|
||||
energy = 1,
|
||||
maxEnergy = 1,
|
||||
redstone = {
|
||||
[0] = 0,
|
||||
[1] = 0,
|
||||
[2] = 0,
|
||||
[3] = 0,
|
||||
[4] = 0,
|
||||
[5] = 0,
|
||||
}
|
||||
},
|
||||
currentLayer = 0,
|
||||
{ type = "empty", x = 0, y = 0, z = 0 },
|
||||
}
|
||||
|
||||
local robotPicture = {
|
||||
"▲", "►", "▼", "◄"
|
||||
}
|
||||
local robotFront = image.load("Robot.pic")
|
||||
local robotSide = image.load("RobotSide.pic")
|
||||
local robotTop = image.load("RobotTop.pic")
|
||||
local chest = image.load("Chest.pic")
|
||||
|
||||
local colors = {
|
||||
white = 0xFFFFFF,
|
||||
lightGray = 0xCCCCCC,
|
||||
gray = 0x333333,
|
||||
black = 0x000000,
|
||||
robot = 0xFF3333,
|
||||
entity = 0xFFCC33,
|
||||
homePoint = 0x6699FF,
|
||||
passable = 0xFF3333,
|
||||
keyPoint = 0xFF3333,
|
||||
keyPointText = 0xFFFFFF,
|
||||
}
|
||||
|
||||
modem.open(port)
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
--OBJECTS, CYKA
|
||||
local obj = {}
|
||||
local function newObj(class, name, ...)
|
||||
obj[class] = obj[class] or {}
|
||||
obj[class][name] = {...}
|
||||
end
|
||||
|
||||
local function isNumberInRange(n, min, max)
|
||||
if n > min and n <= max then return true end
|
||||
end
|
||||
|
||||
local function sendMessage(...)
|
||||
modem.broadcast(port, "ECSRobotControl", ...)
|
||||
end
|
||||
|
||||
local function drawMultiColorProgressBar(x, y, width, currentValue, maxValue, fat)
|
||||
local percent = currentValue / maxValue
|
||||
local valueWidth = math.ceil(percent * width)
|
||||
local color = 0x33CC33
|
||||
if isNumberInRange(percent, 0.5, 0.7) then
|
||||
color = 0xFFFF33
|
||||
elseif isNumberInRange(percent, 0.3, 0.5) then
|
||||
color = 0xFFCC33
|
||||
elseif isNumberInRange(percent, 0.1, 0.3) then
|
||||
color = 0xFF3333
|
||||
elseif isNumberInRange(percent, -10, 0.1) then
|
||||
color = 0x663300
|
||||
end
|
||||
|
||||
buffer.text(x, y, 0x000000, string.rep(fat and "▄" or "━", width))
|
||||
buffer.text(x, y, color, string.rep(fat and "▄" or "━", valueWidth))
|
||||
end
|
||||
|
||||
local function drawRobotStatus()
|
||||
local width, height = 10, 7
|
||||
local x, y = buffer.screen.width - width, buffer.screen.height - height
|
||||
|
||||
buffer.square(x, y, width, height, colors.lightGray)
|
||||
buffer.text(x, y, colors.gray, map.robot.status or "N/A")
|
||||
y = y + 2
|
||||
buffer.image(x, y, robotFront)
|
||||
y = y + robotFront.height
|
||||
drawMultiColorProgressBar(x - 1, y, 10, map.robot.energy, map.robot.maxEnergy, true)
|
||||
end
|
||||
|
||||
local function drawTopBar()
|
||||
obj.TopBar = {}
|
||||
buffer.square(1, 1, buffer.screen.width, 3, colors.gray)
|
||||
local x = 1
|
||||
for i = 1, #topBarElements do
|
||||
local textLength = unicode.len(topBarElements[i]) + 4
|
||||
if i == currentTopBarElement then
|
||||
buffer.square(x, 1, textLength, 3, colors.lightGray)
|
||||
buffer.text(x + 2, 2, colors.gray, topBarElements[i])
|
||||
else
|
||||
buffer.text(x + 2, 2, colors.lightGray, topBarElements[i])
|
||||
end
|
||||
|
||||
newObj("TopBar", i, x, 1, x + textLength - 1, 3)
|
||||
x = x + textLength
|
||||
end
|
||||
end
|
||||
|
||||
local function drawMap()
|
||||
buffer.setDrawLimit(1, 4, buffer.screen.width, buffer.screen.height - 3)
|
||||
|
||||
--Рисуем карту под роботом
|
||||
for i = 1, #map do
|
||||
if map[i].y < map.currentLayer then
|
||||
buffer.set(xStart + map[i].x, yStart - map[i].z, colors.lightGray, colors.gray, "░")
|
||||
end
|
||||
end
|
||||
|
||||
--Рисуем текущий слой
|
||||
for i = 1, #map do
|
||||
--Если слой совпадает с текущим Y
|
||||
if map[i].y == map.currentLayer then
|
||||
--Если координаты в границах экрана
|
||||
if map[i].type == "empty" then
|
||||
buffer.set(xStart + map[i].x, yStart - map[i].z, colors.gray, 0x000000, " ")
|
||||
elseif map[i].type == "solid" then
|
||||
buffer.set(xStart + map[i].x, yStart - map[i].z, colors.lightGray, colors.gray, "▒")
|
||||
elseif map[i].type == "passable" then
|
||||
buffer.set(xStart + map[i].x, yStart - map[i].z, colors.lightGray, colors.passable, "▒")
|
||||
elseif map[i].type == "entity" then
|
||||
buffer.set(xStart + map[i].x, yStart - map[i].z, colors.lightGray, colors.gray, "☺")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--Рисуем точку дома
|
||||
if map.currentLayer == 0 then buffer.set(xStart, yStart, colors.homePoint, colors.gray, "⌂") end
|
||||
|
||||
--Рисуем ключевые точки
|
||||
if map.keyPoints and #map.keyPoints > 0 then
|
||||
for i = 1, #map.keyPoints do
|
||||
buffer.set(xStart + map.keyPoints[i].x, yStart + map.keyPoints[i].z, colors.keyPoint, colors.keyPointText, "*")
|
||||
end
|
||||
end
|
||||
|
||||
--Рисуем робота
|
||||
buffer.text(xStart + map.robot.x, yStart - map.robot.z, colors.robot, robotPicture[map.robot.rotation])
|
||||
|
||||
buffer.resetDrawLimit()
|
||||
|
||||
drawRobotStatus()
|
||||
end
|
||||
|
||||
local function requestInfoAboutInventory()
|
||||
sendMessage("giveMeInfoAboutInventory", currentInventoryType)
|
||||
end
|
||||
|
||||
local function requestInfoAboutRobot()
|
||||
sendMessage("giveMeInfoAboutRobot")
|
||||
end
|
||||
|
||||
local function highlight(x, y, width, height, color)
|
||||
buffer.square(x, y + 1, width, height - 2, color)
|
||||
buffer.text(x, y, color, string.rep("▄", width))
|
||||
buffer.text(x, y + height - 1, color, string.rep("▀", width))
|
||||
end
|
||||
|
||||
local function drawCloud(x, y, width, height, text)
|
||||
local cloudColor = 0xFFFFFF
|
||||
local textColor = colors.gray
|
||||
|
||||
buffer.square(x, y + 1, width, height - 2, cloudColor, textColor, " ")
|
||||
buffer.square(x + 1, y, width - 2, height, cloudColor, textColor, " ")
|
||||
|
||||
buffer.text(x, y, cloudColor, "▄")
|
||||
buffer.text(x + width - 1, y, cloudColor, "▄")
|
||||
buffer.text(x, y + height - 1, cloudColor, "▀")
|
||||
buffer.text(x + width - 1, y + height - 1, cloudColor, "▀")
|
||||
|
||||
local lines = {
|
||||
"▄",
|
||||
"██▄",
|
||||
"████▄",
|
||||
"████▀",
|
||||
"██▀",
|
||||
"▀",
|
||||
}
|
||||
local xLine, yLine = x + width, math.floor(y + height / 2 - #lines / 2)
|
||||
for i = 1, #lines do buffer.text(xLine, yLine, cloudColor, lines[i]); yLine = yLine + 1 end
|
||||
|
||||
y = math.floor(y + height / 2)
|
||||
x = math.floor(x + width / 2 - unicode.len(text) / 2)
|
||||
buffer.text(x, y, textColor, text)
|
||||
end
|
||||
|
||||
local function drawInventory()
|
||||
|
||||
obj.InventorySlots = {}
|
||||
|
||||
local x, y = 3, 5
|
||||
local inventoryWidth, inventoryHeight = 42, 19
|
||||
local xPos, yPos = x, y
|
||||
local counter = 1
|
||||
|
||||
if map.robotInventory then
|
||||
if not map.robotInventory.noInventory then
|
||||
|
||||
-- highlight(x - 1, y - 1, inventoryWidth + 2, inventoryHeight + 2, 0xFFFFFF)
|
||||
--Рисуем скроллбар
|
||||
buffer.scrollBar(x + inventoryWidth - 2, y, 2, inventoryHeight, map.robotInventory.inventorySize, drawInventoryFrom, colors.gray, 0xFF3333)
|
||||
--Рисуем слотики
|
||||
for i = drawInventoryFrom, map.robotInventory.inventorySize do
|
||||
--Выделение слота
|
||||
if i == map.robotInventory.currentSlot then
|
||||
highlight(xPos - 1, yPos - 1, 10, 6, 0xFF3333)
|
||||
end
|
||||
--Квадратик
|
||||
buffer.square(xPos, yPos, 8, 4, colors.gray, colors.lightGray, " ")
|
||||
--Записываем обжект, чо уж там
|
||||
newObj("InventorySlots", i, xPos, yPos, xPos + 7, yPos + 3)
|
||||
--Если такой слот ваще есть, то рисуем инфу о нем, а иначе рисуем пустой слот
|
||||
if map.robotInventory[i] then
|
||||
--Имя шмотки
|
||||
local name = unicode.sub(map.robotInventory[i].label, 1, 16)
|
||||
local firstPart = unicode.sub(name, 1, 8)
|
||||
local secondPart = unicode.sub(name, 9, 16) or ""
|
||||
buffer.text(xPos, yPos, colors.lightGray, firstPart)
|
||||
buffer.text(xPos, yPos + 1, colors.lightGray, secondPart)
|
||||
--Колво шмотки
|
||||
local stringSize = tostring(map.robotInventory[i].size)
|
||||
buffer.text(xPos + math.floor(4 - unicode.len(stringSize) / 2), yPos + 2, 0xFFFFFF, stringSize)
|
||||
--Процент износа
|
||||
if map.robotInventory[i].maxDamage ~= 0 then
|
||||
drawMultiColorProgressBar(xPos + 1, yPos + 3, 6, map.robotInventory[i].damage, map.robotInventory[i].maxDamage)
|
||||
end
|
||||
else
|
||||
buffer.text(xPos + 1, yPos + 1, colors.lightGray, "Пусто")
|
||||
end
|
||||
|
||||
xPos = xPos + 10
|
||||
counter = counter + 1
|
||||
if i % 4 == 0 then xPos = x; yPos = yPos + 5 end
|
||||
if counter > 16 then break end
|
||||
end
|
||||
else
|
||||
drawCloud(x, y, inventoryWidth, inventoryHeight + 1, "Где инвентарь, сука? Кто ответственный?")
|
||||
end
|
||||
else
|
||||
drawCloud(x, y, inventoryWidth, inventoryHeight + 1, "Запрашиваю у робота массив инвентаря")
|
||||
end
|
||||
|
||||
--Рисуем выбор типа инвентаря
|
||||
local width = 17
|
||||
local height = 13
|
||||
x = buffer.screen.width - width - 7
|
||||
y = math.floor(4 + (buffer.screen.height - 4) / 2 - height / 2 )
|
||||
|
||||
--Коорды все нужные
|
||||
local inventoryPositions = {
|
||||
top = { x = x + 10, y = y },
|
||||
front = { x = x, y = y + 5 },
|
||||
bottom = { x = x + 10, y = y + 10 },
|
||||
internal = { x = x + 10, y = y + 5}
|
||||
}
|
||||
--Подсветочка
|
||||
highlight(inventoryPositions[currentInventoryType].x - 1, inventoryPositions[currentInventoryType].y - 1, 10, 6, 0xFF3333)
|
||||
--Верхний сундук
|
||||
buffer.image(inventoryPositions.top.x, inventoryPositions.top.y, chest)
|
||||
--Средний сундук и роботСайд
|
||||
buffer.image(inventoryPositions.front.x, inventoryPositions.front.y, chest)
|
||||
buffer.image(inventoryPositions.internal.x, inventoryPositions.internal.y, robotSide)
|
||||
--Нижний
|
||||
buffer.image(inventoryPositions.bottom.x, inventoryPositions.bottom.y, chest)
|
||||
--Обжекты
|
||||
obj.InventoryTypeSelectors = {}
|
||||
for key in pairs(inventoryPositions) do newObj("InventoryTypeSelectors", key, inventoryPositions[key].x, inventoryPositions[key].y, inventoryPositions[key].x + 9, inventoryPositions[key].y + 5) end
|
||||
end
|
||||
|
||||
local function drawScript()
|
||||
|
||||
end
|
||||
|
||||
local function getSizeOfRedstoneWire(size, side)
|
||||
local percent = (map.robot.redstone[side]) / 15
|
||||
return math.floor(size * percent)
|
||||
end
|
||||
|
||||
local function sendRedstoneRequest()
|
||||
sendMessage("giveMeInfoAboutRedstone")
|
||||
end
|
||||
|
||||
local function drawRedstone()
|
||||
local x, y = 6, 5
|
||||
local width, side
|
||||
|
||||
obj.Redstone = {}
|
||||
|
||||
--Левая гориз черта
|
||||
side = 5
|
||||
width = getSizeOfRedstoneWire(16, side)
|
||||
newObj("Redstone", side, x, y + 9, x + 15, y + 10)
|
||||
buffer.text(x, y + 9, 0x000000, string.rep("▄", 16))
|
||||
buffer.text(x, y + 10, 0x000000, string.rep("▀", 16))
|
||||
buffer.text(x + 16 - width, y + 9, 0xFF3333, string.rep("▄", width))
|
||||
buffer.text(x + 16 - width, y + 10, 0xFF3333, string.rep("▀", width))
|
||||
|
||||
--Правая гориз черта
|
||||
side = 4
|
||||
newObj("Redstone", side, x + 24, y + 9, x + 39, y + 10)
|
||||
width = getSizeOfRedstoneWire(16, side)
|
||||
buffer.text(x + 24, y + 9, 0x000000, string.rep("▄", 16))
|
||||
buffer.text(x + 24, y + 10, 0x000000, string.rep("▀", 16))
|
||||
buffer.text(x + 24, y + 9, 0xFF3333, string.rep("▄", width))
|
||||
buffer.text(x + 24, y + 10, 0xFF3333, string.rep("▀", width))
|
||||
|
||||
--Верхняя верт черта
|
||||
side = 3
|
||||
newObj("Redstone", side, x + 19, y, x + 20, y + 7)
|
||||
width = getSizeOfRedstoneWire(8, side)
|
||||
buffer.square(x + 19, y, 2, 8, 0x000000)
|
||||
buffer.square(x + 19, y + 8 - width, 2, width, 0xFF3333)
|
||||
|
||||
--Нижняя верт черта
|
||||
side = 2
|
||||
newObj("Redstone", side, x + 19, y + 12, x + 20, y + 19)
|
||||
buffer.square(x + 19, y + 12, 2, 8, 0x000000)
|
||||
buffer.square(x + 19, y + 12, 2, getSizeOfRedstoneWire(8, side), 0xFF3333)
|
||||
|
||||
buffer.image(x + 16, y + 8, robotTop)
|
||||
|
||||
x = x + 41
|
||||
|
||||
--Верхняя верт черта
|
||||
side = 1
|
||||
newObj("Redstone", side, x + 19, y, x + 20, y + 7)
|
||||
width = getSizeOfRedstoneWire(8, side)
|
||||
buffer.square(x + 19, y, 2, 8, 0x000000)
|
||||
buffer.square(x + 19, y + 8 - width, 2, width, 0xFF3333)
|
||||
|
||||
--Нижняя верт черта
|
||||
side = 0
|
||||
newObj("Redstone", side, x + 19, y + 12, x + 20, y + 19)
|
||||
buffer.square(x + 19, y + 12, 2, 8, 0x000000)
|
||||
buffer.square(x + 19, y + 12, 2, getSizeOfRedstoneWire(8, side), 0xFF3333)
|
||||
|
||||
buffer.image(x + 16, y + 8, robotFront)
|
||||
|
||||
end
|
||||
|
||||
local function drawMain()
|
||||
--Очищаем главную зону
|
||||
buffer.square(1, 4, buffer.screen.width, buffer.screen.height - 3, colors.lightGray)
|
||||
|
||||
if topBarElements[currentTopBarElement] == "Карта" then
|
||||
drawMap()
|
||||
elseif topBarElements[currentTopBarElement] == "Инвентарь" then
|
||||
drawInventory()
|
||||
elseif topBarElements[currentTopBarElement] == "Редстоун" then
|
||||
drawRedstone()
|
||||
end
|
||||
end
|
||||
|
||||
local function drawAll()
|
||||
drawTopBar()
|
||||
drawMain()
|
||||
buffer.draw()
|
||||
end
|
||||
|
||||
local function getTargetCoords(direction)
|
||||
if direction == "forward" then
|
||||
if map.robot.rotation == 1 then
|
||||
return map.robot.x, map.robot.y, map.robot.z + 1, xStart, yStart + 1
|
||||
elseif map.robot.rotation == 2 then
|
||||
return map.robot.x + 1, map.robot.y, map.robot.z, xStart - 1, yStart
|
||||
elseif map.robot.rotation == 3 then
|
||||
return map.robot.x, map.robot.y, map.robot.z - 1, xStart, yStart - 1
|
||||
elseif map.robot.rotation == 4 then
|
||||
return map.robot.x - 1, map.robot.y, map.robot.z, xStart + 1, yStart
|
||||
end
|
||||
elseif direction == "back" then
|
||||
if map.robot.rotation == 1 then
|
||||
return map.robot.x, map.robot.y, map.robot.z - 1, xStart, yStart - 1
|
||||
elseif map.robot.rotation == 2 then
|
||||
return map.robot.x - 1, map.robot.y, map.robot.z, xStart + 1, yStart
|
||||
elseif map.robot.rotation == 3 then
|
||||
return map.robot.x, map.robot.y, map.robot.z + 1, xStart, yStart + 1
|
||||
elseif map.robot.rotation == 4 then
|
||||
return map.robot.x + 1, map.robot.y, map.robot.z, xStart - 1, yStart
|
||||
end
|
||||
elseif direction == "up" then
|
||||
return map.robot.x, map.robot.y + 1, map.robot.z, xStart, yStart
|
||||
elseif direction == "down" then
|
||||
return map.robot.x, map.robot.y - 1, map.robot.z, xStart, yStart
|
||||
end
|
||||
end
|
||||
|
||||
local function getOptimalKeyPoint()
|
||||
local optimalID
|
||||
local optimalDistance = math.huge
|
||||
for i = 1, #map.keyPoints do
|
||||
local distance = math.sqrt(map.keyPoints.x ^ 2 + map.keyPoints.y ^ 2 + map.keyPoints.x ^ z)
|
||||
if distance < optimalDistance then
|
||||
optimalID = i
|
||||
optimalDistance = distance
|
||||
end
|
||||
end
|
||||
return optimalID
|
||||
end
|
||||
|
||||
local function clicked(x, y, object)
|
||||
if x >= object[1] and y >= object[2] and x <= object[3] and y <= object[4] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
drawAll()
|
||||
requestInfoAboutRobot()
|
||||
|
||||
while true do
|
||||
local e = { event.pull() }
|
||||
if e[1] == "touch" then
|
||||
--СОздание ключевых точек
|
||||
if e[4] >= 4 and topBarElements[currentTopBarElement] == "Карта" then
|
||||
map.keyPoints = map.keyPoints or {}
|
||||
table.insert(map.keyPoints, { x = e[3] - xStart, y = map.currentLayer, z = e[4] - yStart })
|
||||
drawAll()
|
||||
end
|
||||
|
||||
--Выбор верхнего тулбара
|
||||
for key in pairs(obj.TopBar) do
|
||||
if clicked(e[3], e[4], obj.TopBar[key]) then
|
||||
currentTopBarElement = key
|
||||
|
||||
requestInfoAboutRobot()
|
||||
|
||||
if topBarElements[currentTopBarElement] == "Инвентарь" then
|
||||
map.robotInventory = nil
|
||||
currentInventoryType = "internal";
|
||||
drawInventoryFrom = 1
|
||||
requestInfoAboutInventory()
|
||||
elseif topBarElements[currentTopBarElement] == "Редстоун" then
|
||||
sendRedstoneRequest()
|
||||
end
|
||||
|
||||
drawAll()
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
--Редстоун
|
||||
if topBarElements[currentTopBarElement] == "Редстоун" then
|
||||
if obj.Redstone then
|
||||
for key in pairs(obj.Redstone) do
|
||||
if clicked(e[3], e[4], obj.Redstone[key]) then
|
||||
local newValue
|
||||
--Если низ или жопка
|
||||
if key == 0 or key == 2 then
|
||||
newValue = (e[4] - obj.Redstone[key][2] + 1) * 2
|
||||
if e[4] == obj.Redstone[key][2] then newValue = 0 end
|
||||
--Ебало или верх
|
||||
elseif key == 1 or key == 3 then
|
||||
newValue = (obj.Redstone[key][4] - e[4] + 1) * 2
|
||||
if e[4] == obj.Redstone[key][4] then newValue = 0 end
|
||||
--Если лево
|
||||
elseif key == 5 then
|
||||
newValue = (obj.Redstone[key][3] - e[3])
|
||||
if e[3] == obj.Redstone[key][3] then newValue = 0 end
|
||||
elseif key == 4 then
|
||||
newValue = (e[3] - obj.Redstone[key][1])
|
||||
if e[3] == obj.Redstone[key][1] then newValue = 0 end
|
||||
|
||||
end
|
||||
|
||||
if newValue > 15 then newValue = 15 elseif newValue < 0 then newValue = 0 end
|
||||
-- ecs.error(newValue)
|
||||
sendMessage("changeRedstoneOutput", key, newValue)
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--Выбор слотов
|
||||
if topBarElements[currentTopBarElement] == "Инвентарь" then
|
||||
--Тип инвентаря
|
||||
if obj.InventoryTypeSelectors then
|
||||
for key in pairs(obj.InventoryTypeSelectors) do
|
||||
if clicked(e[3], e[4], obj.InventoryTypeSelectors[key]) then
|
||||
map.robotInventory = nil
|
||||
currentInventoryType = key
|
||||
drawInventoryFrom = 1
|
||||
requestInfoAboutInventory()
|
||||
drawAll()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--Слотики
|
||||
if obj.InventorySlots then
|
||||
for key in pairs(obj.InventorySlots) do
|
||||
if clicked(e[3], e[4], obj.InventorySlots[key]) then
|
||||
if e[5] ~= 1 then
|
||||
if currentInventoryType == "internal" then
|
||||
sendMessage("selectSlot", key)
|
||||
end
|
||||
else
|
||||
if currentInventoryType == "internal" then
|
||||
if map.robotInventory[key] then
|
||||
local action = context.menu(e[3], e[4], {"Экипировать"}, {"Выбросить"}, "-", {"Инфо", true})
|
||||
if action == "Экипировать" then
|
||||
sendMessage("equip", key)
|
||||
elseif action == "Выбросить" then
|
||||
sendMessage("drop", nil, key)
|
||||
end
|
||||
end
|
||||
else
|
||||
local action = context.menu(e[3], e[4], {"Соснуть", map.robotInventory[key] == nil}, {"Положить суда", map.robotInventory[key] ~= nil}, "-", {"Инфо", true})
|
||||
if action == "Соснуть" then
|
||||
sendMessage("suckFromSlot", currentInventoryType, key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif e[1] == "key_down" then
|
||||
if topBarElements[currentTopBarElement] == "Карта" then
|
||||
--W
|
||||
if e[4] == 17 then
|
||||
sendMessage("forward")
|
||||
--S
|
||||
elseif e[4] == 31 then
|
||||
sendMessage("back")
|
||||
--SHIFT
|
||||
elseif e[4] == 42 then
|
||||
sendMessage("down")
|
||||
--SPACE
|
||||
elseif e[4] == 57 then
|
||||
sendMessage("up")
|
||||
--A
|
||||
elseif e[4] == 30 then
|
||||
sendMessage("turnLeft")
|
||||
--D
|
||||
elseif e[4] == 32 then
|
||||
sendMessage("turnRight")
|
||||
--E
|
||||
elseif e[4] == 18 then
|
||||
if keyboard.isControlDown() then sendMessage("use") else sendMessage("swing") end
|
||||
--Q
|
||||
elseif e[4] == 16 then
|
||||
sendMessage("place", 1)
|
||||
--C
|
||||
elseif e[4] == 46 then
|
||||
local color = require("palette").draw("auto", "auto")
|
||||
sendMessage("changeColor", color or 0xFFFFFF)
|
||||
elseif e[4] == 28 then
|
||||
-- if map.keyPoints and #map.keyPoints > 0 then
|
||||
-- sendMessage("executeKeyPoints", serialization.serialize(map.keyPoints))
|
||||
-- end
|
||||
end
|
||||
end
|
||||
elseif e[1] == "modem_message" then
|
||||
if e[4] == port then
|
||||
if e[6] == "ECSRobotAnswer" then
|
||||
if e[7] == "cantMoveTo" then
|
||||
local x, y, z = getTargetCoords(e[8])
|
||||
table.insert(map, { type = e[9], x = x, y = y, z = z })
|
||||
drawAll()
|
||||
elseif e[7] == "successfullyMovedTo" then
|
||||
local x, y, z; x, y, z, xStart, yStart = getTargetCoords(e[8])
|
||||
if e[8] == "up" then
|
||||
map.currentLayer = map.currentLayer + 1
|
||||
elseif e[8] == "down" then
|
||||
map.currentLayer = map.currentLayer - 1
|
||||
end
|
||||
map.robot.x = x; map.robot.y = y; map.robot.z = z
|
||||
table.insert(map, { type = "empty", x = x, y = y, z = z })
|
||||
drawAll()
|
||||
elseif e[7] == "successfullyRotatedTo" then
|
||||
local adder = -1; if e[8] == "turnRight" then adder = 1 end
|
||||
map.robot.rotation = map.robot.rotation + adder
|
||||
if map.robot.rotation < 1 then
|
||||
map.robot.rotation = 4
|
||||
elseif map.robot.rotation > 4 then
|
||||
map.robot.rotation = 1
|
||||
end
|
||||
drawAll()
|
||||
elseif e[7] == "successfullySwingedTo" then
|
||||
if e[8] == "swing" then e[8] = "forward" elseif e[8] == "swingUp" then e[8] = "up" elseif e[8] == "swingDown" then e[8] = "down" end
|
||||
local x, y, z = getTargetCoords(e[8])
|
||||
table.insert(map, { type = "empty", x = x, y = y, z = z })
|
||||
drawAll()
|
||||
elseif e[7] == "inventoryInfo" then
|
||||
map.robotInventory = serialization.unserialize(e[8])
|
||||
drawAll()
|
||||
elseif e[7] == "selectedSlot" then
|
||||
map.robotInventory.currentSlot = e[8]
|
||||
if topBarElements[currentTopBarElement] == "Инвентарь" then drawAll() end
|
||||
elseif e[7] == "infoAboutRobot" then
|
||||
map.robot.energy = e[8]
|
||||
map.robot.maxEnergy = e[9]
|
||||
map.robot.status = e[10]
|
||||
if topBarElements[currentTopBarElement] == "Карта" then drawRobotStatus(); buffer.draw() end
|
||||
elseif e[7] == "infoAboutRedstone" then
|
||||
map.robot.redstone = serialization.unserialize(e[8])
|
||||
if topBarElements[currentTopBarElement] == "Редстоун" then drawAll() end
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif e[1] == "scroll" then
|
||||
if topBarElements[currentTopBarElement] == "Инвентарь" then
|
||||
if e[5] == 1 then
|
||||
if drawInventoryFrom > 4 then drawInventoryFrom = drawInventoryFrom - 4; drawAll() end
|
||||
else
|
||||
if drawInventoryFrom < (map.robotInventory.inventorySize - 3) then drawInventoryFrom = drawInventoryFrom + 4; drawAll() end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,134 +0,0 @@
|
||||
|
||||
|
||||
local event = require("event")
|
||||
local robot = require("robot")
|
||||
local computer = require("computer")
|
||||
local component = require("component")
|
||||
local serialization = require("serialization")
|
||||
local modem = component.modem
|
||||
local inventoryController = component.inventory_controller
|
||||
local port = 1337
|
||||
local moveSleepDelay = 0.05
|
||||
local sides = {front = 3, bottom = 0, top = 1}
|
||||
|
||||
modem.open(port)
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
local function sendMessage(...)
|
||||
modem.broadcast(port, "ECSRobotAnswer", ...)
|
||||
end
|
||||
|
||||
local function try(functionName, successMessage, errorMessage)
|
||||
local success, reason = robot[functionName]()
|
||||
if success then
|
||||
sendMessage(successMessage, functionName)
|
||||
else
|
||||
print("Ошибка try: " .. tostring(functionName) .. " " .. tostring(reason))
|
||||
sendMessage(errorMessage, functionName, reason)
|
||||
end
|
||||
-- os.sleep(moveSleepDelay)
|
||||
end
|
||||
|
||||
local function sendInventoryInfo(type)
|
||||
local inventory = {}
|
||||
local inventorySize
|
||||
|
||||
if type == "internal" then
|
||||
inventorySize = robot.inventorySize()
|
||||
elseif type == "front" or type == "bottom" or type == "top" then
|
||||
inventorySize = inventoryController.getInventorySize(sides[type])
|
||||
end
|
||||
|
||||
if inventorySize then
|
||||
inventory.inventorySize = inventorySize
|
||||
inventory.type = type
|
||||
|
||||
if type == "internal" then
|
||||
inventory.currentSlot = robot.select()
|
||||
for slot = 1, inventorySize do
|
||||
-- if robot.count(i) > 0 then
|
||||
inventory[slot] = inventoryController.getStackInInternalSlot(slot)
|
||||
-- end
|
||||
end
|
||||
elseif type == "front" or type == "bottom" or type == "top" then
|
||||
for slot = 1, inventorySize do
|
||||
inventory[slot] = inventoryController.getStackInSlot(sides[type], slot)
|
||||
end
|
||||
end
|
||||
else
|
||||
inventory.noInventory = true
|
||||
end
|
||||
|
||||
sendMessage("inventoryInfo", serialization.serialize(inventory))
|
||||
end
|
||||
|
||||
local function sendInfoAboutRobot()
|
||||
sendMessage("infoAboutRobot", computer.energy(), computer.maxEnergy(), "Статус")
|
||||
end
|
||||
|
||||
local function sendInfoAboutRedstone()
|
||||
local redstoneInfo = {}
|
||||
for i = 0, 5 do
|
||||
redstoneInfo[i] = component.redstone.getOutput(i)
|
||||
end
|
||||
sendMessage("infoAboutRedstone", serialization.serialize(redstoneInfo))
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------------------
|
||||
|
||||
while true do
|
||||
local e = { event.pull() }
|
||||
if e[1] == "modem_message" then
|
||||
if e[4] == port then
|
||||
if e[6] == "ECSRobotControl" then
|
||||
if e[7] == "forward" or e[7] == "back" or e[7] == "up" or e[7] == "down" then
|
||||
try(e[7], "successfullyMovedTo", "cantMoveTo")
|
||||
elseif e[7] == "turnLeft" or e[7] == "turnRight" then
|
||||
try(e[7], "successfullyRotatedTo", "")
|
||||
elseif e[7] == "swing" then
|
||||
try(e[7], "successfullySwingedTo", "cantSwingTo")
|
||||
elseif e[7] == "use" then
|
||||
robot.use()
|
||||
elseif e[7] == "place" then
|
||||
try(e[7], "successfullyPlacedTo", "cantPlaceTo")
|
||||
elseif e[7] == "changeColor" then
|
||||
component.robot.setLightColor(e[8])
|
||||
elseif e[7] == "drop" then
|
||||
local oldSlot
|
||||
if e[9] then robot.select(e[9]); oldSlot = robot.select() end
|
||||
robot.drop(e[8])
|
||||
sendInventoryInfo("internal")
|
||||
if oldSlot then robot.select(oldSlot) end
|
||||
elseif e[7] == "giveMeInfoAboutInventory" then
|
||||
sendInventoryInfo(e[8])
|
||||
elseif e[7] == "selectSlot" then
|
||||
robot.select(e[8])
|
||||
sendMessage("selectedSlot", e[8])
|
||||
elseif e[7] == "equip" then
|
||||
local success = inventoryController.equip(e[8])
|
||||
if success then sendInventoryInfo("internal") end
|
||||
elseif e[7] == "giveMeInfoAboutRobot" then
|
||||
sendInfoAboutRobot()
|
||||
elseif e[7] == "giveMeInfoAboutRedstone" then
|
||||
sendInfoAboutRedstone()
|
||||
elseif e[7] == "suckFromSlot" then
|
||||
local success = inventoryController.suckFromSlot(sides[e[8]], e[9])
|
||||
if success then sendInventoryInfo(e[8]) end
|
||||
elseif e[7] == "changeRedstoneOutput" then
|
||||
component.redstone.setOutput(e[8], e[9])
|
||||
sendInfoAboutRedstone()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
381
Applications/Robot/advancedRobot.lua
Normal file
381
Applications/Robot/advancedRobot.lua
Normal file
@@ -0,0 +1,381 @@
|
||||
|
||||
local computer = require("computer")
|
||||
local event = require("event")
|
||||
local sides = require("sides")
|
||||
|
||||
local AR = {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
AR.proxies = {}
|
||||
AR.requiredProxies = {
|
||||
"robot",
|
||||
"generator",
|
||||
"inventory_controller",
|
||||
"modem",
|
||||
"geolyzer",
|
||||
"redstone",
|
||||
}
|
||||
|
||||
AR.fuels = {
|
||||
"minecraft:coal",
|
||||
"minecraft:coal_block",
|
||||
"minecraft:lava_bucket",
|
||||
"minecraft:coal_block",
|
||||
}
|
||||
|
||||
AR.droppables = {
|
||||
"minecraft:cobblestone",
|
||||
"minecraft:grass",
|
||||
"minecraft:dirt",
|
||||
"minecraft:gravel",
|
||||
"minecraft:sand",
|
||||
"minecraft:sandstone",
|
||||
"minecraft:torch",
|
||||
"minecraft:planks",
|
||||
"minecraft:fence",
|
||||
"minecraft:chest",
|
||||
"minecraft:monster_egg",
|
||||
"minecraft:stonebrick",
|
||||
}
|
||||
|
||||
AR.tools = {
|
||||
"minecraft:diamond_pickaxe",
|
||||
"minecraft:iron_pickaxe",
|
||||
}
|
||||
|
||||
AR.toolReplaceDurability = 0.05
|
||||
AR.zeroPositionReturnEnergy = 0.1
|
||||
AR.emptySlotsCountDropping = 4
|
||||
|
||||
AR.positionX = 0
|
||||
AR.positionY = 0
|
||||
AR.positionZ = 0
|
||||
AR.rotation = 0
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
function AR.updateProxies()
|
||||
local name
|
||||
for i = 1, #AR.requiredProxies do
|
||||
name = AR.requiredProxies[i]
|
||||
|
||||
AR.proxies[name] = component.list(name)()
|
||||
if AR.proxies[name] then
|
||||
AR.proxies[name] = component.proxy(AR.proxies[name])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function AR.moveToZeroPosition()
|
||||
AR.moveToRequiredPosition(0, AR.positionY, 0)
|
||||
AR.turnToRequiredRotation(0)
|
||||
AR.tryToDropDroppables()
|
||||
AR.moveToRequiredPosition(0, 0, 0)
|
||||
end
|
||||
|
||||
function AR.move(direction)
|
||||
while true do
|
||||
local swingSuccess, swingReason = AR.proxies.robot.swing(direction)
|
||||
if swingSuccess or swingReason == "air" then
|
||||
local moveSuccess, moveReason = AR.proxies.robot.move(direction)
|
||||
if moveSuccess then
|
||||
break
|
||||
end
|
||||
else
|
||||
if swingReason == "block" then
|
||||
AR.moveToZeroPosition()
|
||||
error("Unbreakable block detected, going to base")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if direction == sides.front or direction == sides.back then
|
||||
local directionOffset = direction == sides.front and 1 or -1
|
||||
|
||||
if AR.rotation == 0 then
|
||||
AR.positionX = AR.positionX + directionOffset
|
||||
elseif AR.rotation == 1 then
|
||||
AR.positionZ = AR.positionZ + directionOffset
|
||||
elseif AR.rotation == 2 then
|
||||
AR.positionX = AR.positionX - directionOffset
|
||||
elseif AR.rotation == 3 then
|
||||
AR.positionZ = AR.positionZ - directionOffset
|
||||
end
|
||||
elseif direction == sides.up or direction == sides.down then
|
||||
local directionOffset = direction == sides.up and 1 or -1
|
||||
AR.positionY = AR.positionY + directionOffset
|
||||
end
|
||||
end
|
||||
|
||||
function AR.turn(clockwise)
|
||||
AR.proxies.robot.turn(clockwise)
|
||||
AR.rotation = AR.rotation + (clockwise and 1 or -1)
|
||||
if AR.rotation > 3 then
|
||||
AR.rotation = 0
|
||||
elseif AR.rotation < 0 then
|
||||
AR.rotation = 3
|
||||
end
|
||||
end
|
||||
|
||||
function AR.turnToRequiredRotation(requiredRotation)
|
||||
local difference = AR.rotation - requiredRotation
|
||||
|
||||
if difference ~= 0 then
|
||||
local fastestWay
|
||||
if difference > 0 then
|
||||
if difference > 2 then fastestWay = true else fastestWay = false end
|
||||
else
|
||||
if -difference > 2 then fastestWay = false else fastestWay = true end
|
||||
end
|
||||
|
||||
while AR.rotation ~= requiredRotation do
|
||||
AR.turn(fastestWay)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function AR.moveToRequiredPosition(xTarget, yTarget, zTarget)
|
||||
local xDistance = xTarget - AR.positionX
|
||||
local yDistance = yTarget - AR.positionY
|
||||
local zDistance = zTarget - AR.positionZ
|
||||
|
||||
if yDistance ~= 0 then
|
||||
local direction = yDistance > 0 and sides.up or sides.down
|
||||
for i = 1, math.abs(yDistance) do AR.move(direction) end
|
||||
end
|
||||
|
||||
if xDistance ~= 0 then
|
||||
AR.turnToRequiredRotation(xDistance > 0 and 0 or 2)
|
||||
for i = 1, math.abs(xDistance) do AR.move(sides.front) end
|
||||
end
|
||||
|
||||
if zDistance ~= 0 then
|
||||
AR.turnToRequiredRotation(zDistance > 0 and 1 or 3)
|
||||
for i = 1, math.abs(zDistance) do AR.move(sides.front) end
|
||||
end
|
||||
end
|
||||
|
||||
function AR.getEmptySlotsCount()
|
||||
local count = 0
|
||||
for slot = 1, AR.inventorySize() do
|
||||
if AR.count(slot) == 0 then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
|
||||
return count
|
||||
end
|
||||
|
||||
function AR.tryToDropDroppables(side)
|
||||
if AR.getEmptySlotsCount() < AR.emptySlotsCountDropping then
|
||||
print("Trying to drop all shitty resources to free some slots for mining")
|
||||
for slot = 1, AR.inventorySize() do
|
||||
local stack = AR.getStackInInternalSlot(slot)
|
||||
if stack then
|
||||
for i = 1, #AR.droppables do
|
||||
if stack.name == AR.droppables[i] then
|
||||
AR.select(slot)
|
||||
AR.drop(side or sides.down)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
AR.select(1)
|
||||
end
|
||||
end
|
||||
|
||||
function AR.dropAllResources(side, exceptArray)
|
||||
side = side or sides.front
|
||||
exceptArray = exceptArray or AR.tools
|
||||
print("Dropping all mined resources...")
|
||||
|
||||
for slot = 1, AR.inventorySize() do
|
||||
local stack = AR.getStackInInternalSlot(slot)
|
||||
if stack then
|
||||
local thisIsAShittyItem = true
|
||||
|
||||
for exceptItem = 1, #exceptArray do
|
||||
if stack.name == exceptArray[exceptItem] then
|
||||
thisIsAShittyItem = false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if thisIsAShittyItem then
|
||||
AR.select(slot)
|
||||
AR.drop(side)
|
||||
end
|
||||
end
|
||||
end
|
||||
AR.select(1)
|
||||
end
|
||||
|
||||
function AR.checkToolStatus()
|
||||
if AR.durability() < AR.toolReplaceDurability then
|
||||
print("Equipped tool durability lesser then " .. AR.toolReplaceDurability)
|
||||
local success = false
|
||||
|
||||
for slot = 1, AR.inventorySize() do
|
||||
local stack = AR.getStackInInternalSlot(slot)
|
||||
if stack then
|
||||
for tool = 1, #AR.tools do
|
||||
if stack.name == AR.tools[tool] and stack.damage / stack.maxDamage < AR.toolReplaceDurability then
|
||||
local oldSlot = AR.select()
|
||||
AR.select(slot)
|
||||
AR.equip()
|
||||
AR.select(oldSlot)
|
||||
success = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not success then
|
||||
AR.moveToZeroPosition()
|
||||
error("No one useable tool are found in inventory, going back to base")
|
||||
else
|
||||
print("Successfullty switched tool to another from inventory")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function AR.checkEnergyStatus()
|
||||
if computer.energy() / computer.maxEnergy() < AR.zeroPositionReturnEnergy then
|
||||
print("Low energy level detected")
|
||||
-- Запоминаем старую позицию, шобы суда вернуться
|
||||
local oldPosition = AR.getRobotPosition()
|
||||
-- Пиздуем на базу за зарядкой
|
||||
AR.moveToZeroPosition()
|
||||
-- Заряжаемся, пока энергия не достигнет более-менее максимума
|
||||
while computer.energy() / computer.maxEnergy() < 0.99 do
|
||||
print("Charging up: " .. math.floor(computer.energy() / computer.maxEnergy() * 100) .. "%")
|
||||
os.sleep(1)
|
||||
end
|
||||
-- Пиздуем обратно
|
||||
AR.moveToRequiredPosition(oldPosition.x, oldPosition.y, oldPosition.z)
|
||||
AR.turnToRequiredRotation(oldPosition.rotation)
|
||||
end
|
||||
end
|
||||
|
||||
function AR.getSlotWithFuel()
|
||||
for slot = 1, AR.inventorySize() do
|
||||
local stack = AR.getStackInInternalSlot(slot)
|
||||
if stack then
|
||||
for fuel = 1, #AR.fuels do
|
||||
if stack.name == AR.fuels[fuel] then
|
||||
return slot
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function AR.checkGeneratorStatus()
|
||||
if component.isAvailable("generator") then
|
||||
if component.generator.count() == 0 then
|
||||
print("Generator is empty, trying to find some fuel in inventory")
|
||||
local slot = AR.getSlotWithFuel()
|
||||
if slot then
|
||||
print("Found slot with fuel: " .. slot)
|
||||
local oldSlot = AR.select()
|
||||
AR.select(slot)
|
||||
component.generator.insert()
|
||||
AR.select(oldSlot)
|
||||
return
|
||||
else
|
||||
print("Slot with fuel not found")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- Swing
|
||||
function AR.swingForward()
|
||||
return AR.proxies.robot.swing(sides.front)
|
||||
end
|
||||
|
||||
function AR.swingUp()
|
||||
return AR.proxies.robot.swing(sides.up)
|
||||
end
|
||||
|
||||
function AR.swingDown()
|
||||
return AR.proxies.robot.swing(sides.down)
|
||||
end
|
||||
--Use
|
||||
function AR.useForward()
|
||||
return AR.proxies.robot.use(sides.front)
|
||||
end
|
||||
|
||||
function AR.useUp()
|
||||
return AR.proxies.robot.use(sides.up)
|
||||
end
|
||||
|
||||
function AR.useDown()
|
||||
return AR.proxies.robot.use(sides.down)
|
||||
end
|
||||
-- Move
|
||||
function AR.moveForward()
|
||||
return AR.move(sides.front)
|
||||
end
|
||||
|
||||
function AR.moveBackward()
|
||||
return AR.move(sides.back)
|
||||
end
|
||||
|
||||
function AR.moveUp()
|
||||
return AR.move(sides.up)
|
||||
end
|
||||
|
||||
function AR.moveDown()
|
||||
return AR.move(sides.down)
|
||||
end
|
||||
-- Turn
|
||||
function AR.turnLeft()
|
||||
return AR.turn(false)
|
||||
end
|
||||
|
||||
function AR.turnRight()
|
||||
return AR.turn(true)
|
||||
end
|
||||
|
||||
function AR.turnAround()
|
||||
AR.turn(true)
|
||||
AR.turn(true)
|
||||
end
|
||||
|
||||
AR.select = AR.proxies.robot.select
|
||||
AR.drop = AR.proxies.robot.drop
|
||||
AR.durability = AR.proxies.robot.durability
|
||||
AR.inventorySize = AR.proxies.robot.inventorySize
|
||||
AR.count = AR.proxies.robot.count
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local function callProxyMethod(proxyName, methodName, ...)
|
||||
if AR.proxies[proxyName] then
|
||||
return AR.proxies[proxyName][methodName](...)
|
||||
else
|
||||
return false, proxyName .. " component is not available"
|
||||
end
|
||||
end
|
||||
|
||||
function AR.equip(...)
|
||||
return callProxyMethod("inventory_controller", "equip", ...)
|
||||
end
|
||||
|
||||
function AR.getStackInInternalSlot(...)
|
||||
return callProxyMethod("inventory_controller", "getStackInInternalSlot", ...)
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
AR.updateProxies()
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
return AR
|
||||
@@ -1,354 +0,0 @@
|
||||
|
||||
local computer = require("computer")
|
||||
local event = require("event")
|
||||
local sides = require("sides")
|
||||
local component = require("component")
|
||||
|
||||
local robotComponent = component.robot
|
||||
local inventoryController = component.inventory_controller
|
||||
|
||||
local robotAPI = {}
|
||||
|
||||
-------------------------------------------------- Some variables that user can change for himself --------------------------------------------------
|
||||
|
||||
robotAPI.fuels = {
|
||||
"minecraft:coal",
|
||||
"minecraft:lava_bucket",
|
||||
"minecraft:coal_block",
|
||||
}
|
||||
|
||||
robotAPI.shittyResources = {
|
||||
"minecraft:cobblestone",
|
||||
"minecraft:grass",
|
||||
"minecraft:dirt",
|
||||
"minecraft:gravel",
|
||||
"minecraft:sand",
|
||||
"minecraft:sandstone",
|
||||
"minecraft:torch",
|
||||
"minecraft:planks",
|
||||
"minecraft:fence",
|
||||
"minecraft:chest",
|
||||
"minecraft:monster_egg",
|
||||
"minecraft:stonebrick",
|
||||
}
|
||||
|
||||
robotAPI.tools = {
|
||||
"minecraft:diamond_pickaxe",
|
||||
"minecraft:iron_pickaxe",
|
||||
}
|
||||
|
||||
robotAPI.replaceToolOnDurabilityLesserThen = 0.05
|
||||
robotAPI.returnToHomeOnEneryLowerThen = 0.1
|
||||
robotAPI.dropShittyResourcesOnCountOfEmptySlotsLesserThen = 4
|
||||
|
||||
-------------------------------------------------- API-related stuff --------------------------------------------------
|
||||
|
||||
robotAPI.robotPosition = {x = 0, y = 0, z = 0, rotation = 0}
|
||||
|
||||
function robotAPI.getRobotPosition()
|
||||
return {
|
||||
x = robotAPI.robotPosition.x,
|
||||
y = robotAPI.robotPosition.y,
|
||||
z = robotAPI.robotPosition.z,
|
||||
rotation =robotAPI.robotPosition.rotation
|
||||
}
|
||||
end
|
||||
|
||||
-------------------------------------------------- Move-related functions --------------------------------------------------
|
||||
|
||||
function robotAPI.returnToStartPoint()
|
||||
robotAPI.moveToRequiredPoint(0, robotAPI.robotPosition.y, 0)
|
||||
robotAPI.turnToRequiredRotation(0)
|
||||
robotAPI.tryToDropShittyResources()
|
||||
robotAPI.moveToRequiredPoint(0, 0, 0)
|
||||
end
|
||||
|
||||
function robotAPI.move(direction)
|
||||
while true do
|
||||
local swingSuccess, swingReason = robotComponent.swing(direction)
|
||||
if swingSuccess or swingReason == "air" then
|
||||
local moveSuccess, moveReason = robotComponent.move(direction)
|
||||
if moveSuccess then
|
||||
break
|
||||
end
|
||||
else
|
||||
if swingReason == "block" then
|
||||
robotAPI.returnToStartPoint()
|
||||
error("Unbreakable block detected, going to base")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if direction == sides.front or direction == sides.back then
|
||||
local directionOffset = direction == sides.front and 1 or -1
|
||||
|
||||
if robotAPI.robotPosition.rotation == 0 then
|
||||
robotAPI.robotPosition.x = robotAPI.robotPosition.x + directionOffset
|
||||
elseif robotAPI.robotPosition.rotation == 1 then
|
||||
robotAPI.robotPosition.z = robotAPI.robotPosition.z + directionOffset
|
||||
elseif robotAPI.robotPosition.rotation == 2 then
|
||||
robotAPI.robotPosition.x = robotAPI.robotPosition.x - directionOffset
|
||||
elseif robotAPI.robotPosition.rotation == 3 then
|
||||
robotAPI.robotPosition.z = robotAPI.robotPosition.z - directionOffset
|
||||
end
|
||||
elseif direction == sides.up or direction == sides.down then
|
||||
local directionOffset = direction == sides.up and 1 or -1
|
||||
robotAPI.robotPosition.y = robotAPI.robotPosition.y + directionOffset
|
||||
end
|
||||
end
|
||||
|
||||
function robotAPI.turn(clockwise)
|
||||
robotComponent.turn(clockwise)
|
||||
robotAPI.robotPosition.rotation = robotAPI.robotPosition.rotation + (clockwise and 1 or -1)
|
||||
if robotAPI.robotPosition.rotation > 3 then
|
||||
robotAPI.robotPosition.rotation = 0
|
||||
elseif robotAPI.robotPosition.rotation < 0 then
|
||||
robotAPI.robotPosition.rotation = 3
|
||||
end
|
||||
end
|
||||
|
||||
function robotAPI.turnToRequiredRotation(requiredRotation)
|
||||
local difference = robotAPI.robotPosition.rotation - requiredRotation
|
||||
|
||||
if difference ~= 0 then
|
||||
local fastestWay
|
||||
if difference > 0 then
|
||||
if difference > 2 then fastestWay = true else fastestWay = false end
|
||||
else
|
||||
if -difference > 2 then fastestWay = false else fastestWay = true end
|
||||
end
|
||||
|
||||
while robotAPI.robotPosition.rotation ~= requiredRotation do
|
||||
robotAPI.turn(fastestWay)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function robotAPI.moveToRequiredPoint(xTarget, yTarget, zTarget)
|
||||
local xDistance = xTarget - robotAPI.robotPosition.x
|
||||
local yDistance = yTarget - robotAPI.robotPosition.y
|
||||
local zDistance = zTarget - robotAPI.robotPosition.z
|
||||
|
||||
if yDistance ~= 0 then
|
||||
local direction = yDistance > 0 and sides.up or sides.down
|
||||
for i = 1, math.abs(yDistance) do robotAPI.move(direction) end
|
||||
end
|
||||
|
||||
if xDistance ~= 0 then
|
||||
robotAPI.turnToRequiredRotation(xDistance > 0 and 0 or 2)
|
||||
for i = 1, math.abs(xDistance) do robotAPI.move(sides.front) end
|
||||
end
|
||||
|
||||
if zDistance ~= 0 then
|
||||
robotAPI.turnToRequiredRotation(zDistance > 0 and 1 or 3)
|
||||
for i = 1, math.abs(zDistance) do robotAPI.move(sides.front) end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------- Inventory-related functions --------------------------------------------------
|
||||
|
||||
function robotAPI.getEmptySlotsCount()
|
||||
local count = 0
|
||||
for slot = 1, robotComponent.inventorySize() do
|
||||
count = count + (robotComponent.count(slot) == 0 and 1 or 0)
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
function robotAPI.tryToDropShittyResources(side)
|
||||
if robotAPI.getEmptySlotsCount() < robotAPI.dropShittyResourcesOnCountOfEmptySlotsLesserThen then
|
||||
print("Trying to drop all shitty resources to free some slots for mining")
|
||||
for slot = 1, robotComponent.inventorySize() do
|
||||
local stack = inventoryController.getStackInInternalSlot(slot)
|
||||
if stack then
|
||||
for i = 1, #robotAPI.shittyResources do
|
||||
if stack.name == robotAPI.shittyResources[i] then
|
||||
robotComponent.select(slot)
|
||||
robotComponent.drop(side or sides.down)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
robotComponent.select(1)
|
||||
end
|
||||
end
|
||||
|
||||
function robotAPI.dropAllResources(side, exceptArray)
|
||||
side = side or sides.front
|
||||
exceptArray = exceptArray or robotAPI.tools
|
||||
print("Dropping all mined resources...")
|
||||
|
||||
for slot = 1, robotComponent.inventorySize() do
|
||||
local stack = inventoryController.getStackInInternalSlot(slot)
|
||||
if stack then
|
||||
local thisIsAShittyItem = true
|
||||
|
||||
for exceptItem = 1, #exceptArray do
|
||||
if stack.name == exceptArray[exceptItem] then
|
||||
thisIsAShittyItem = false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if thisIsAShittyItem then
|
||||
robotComponent.select(slot)
|
||||
robotComponent.drop(side)
|
||||
end
|
||||
end
|
||||
end
|
||||
robotComponent.select(1)
|
||||
end
|
||||
|
||||
function robotAPI.checkToolStatus()
|
||||
if robotComponent.durability() < robotAPI.replaceToolOnDurabilityLesserThen then
|
||||
print("Equipped tool durability lesser then " .. robotAPI.replaceToolOnDurabilityLesserThen)
|
||||
local success = false
|
||||
|
||||
for slot = 1, robotComponent.inventorySize() do
|
||||
local stack = inventoryController.getStackInInternalSlot(slot)
|
||||
if stack then
|
||||
for tool = 1, #robotAPI.tools do
|
||||
if stack.name == robotAPI.tools[tool] and stack.damage / stack.maxDamage < robotAPI.replaceToolOnDurabilityLesserThen then
|
||||
local oldSlot = robotComponent.select()
|
||||
robotComponent.select(slot)
|
||||
inventoryController.equip()
|
||||
robotComponent.select(oldSlot)
|
||||
success = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not success then
|
||||
robotAPI.returnToStartPoint()
|
||||
error("No one useable tool are found in inventory, going back to base")
|
||||
else
|
||||
print("Successfullty switched tool to another from inventory")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------- Energy-related functions --------------------------------------------------
|
||||
|
||||
function robotAPI.checkEnergyStatus()
|
||||
if computer.energy() / computer.maxEnergy() < robotAPI.returnToHomeOnEneryLowerThen then
|
||||
print("Low energy level detected")
|
||||
-- Запоминаем старую позицию, шобы суда вернуться
|
||||
local oldPosition = robotAPI.getRobotPosition()
|
||||
-- Пиздуем на базу за зарядкой
|
||||
robotAPI.returnToStartPoint()
|
||||
-- Заряжаемся, пока энергия не достигнет более-менее максимума
|
||||
while computer.energy() / computer.maxEnergy() < 0.99 do
|
||||
print("Charging up: " .. math.floor(computer.energy() / computer.maxEnergy() * 100) .. "%")
|
||||
os.sleep(1)
|
||||
end
|
||||
-- Пиздуем обратно
|
||||
robotAPI.moveToRequiredPoint(oldPosition.x, oldPosition.y, oldPosition.z)
|
||||
robotAPI.turnToRequiredRotation(oldPosition.rotation)
|
||||
end
|
||||
end
|
||||
|
||||
function robotAPI.getSlotWithFuel()
|
||||
for slot = 1, robotComponent.inventorySize() do
|
||||
local stack = inventoryController.getStackInInternalSlot(slot)
|
||||
if stack then
|
||||
for fuel = 1, #robotAPI.fuels do
|
||||
if stack.name == robotAPI.fuels[fuel] then
|
||||
return slot
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function robotAPI.checkGeneratorStatus()
|
||||
if component.isAvailable("generator") then
|
||||
if component.generator.count() == 0 then
|
||||
print("Generator is empty, trying to find some fuel in inventory")
|
||||
local slot = robotAPI.getSlotWithFuel()
|
||||
if slot then
|
||||
print("Found slot with fuel: " .. slot)
|
||||
local oldSlot = robotComponent.select()
|
||||
robotComponent.select(slot)
|
||||
component.generator.insert()
|
||||
robotComponent.select(oldSlot)
|
||||
return
|
||||
else
|
||||
print("Slot with fuel not found")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------- Shortcut functions --------------------------------------------------
|
||||
|
||||
-- Swing
|
||||
function robotAPI.swingForward()
|
||||
return robotComponent.swing(sides.front)
|
||||
end
|
||||
|
||||
function robotAPI.swingUp()
|
||||
return robotComponent.swing(sides.up)
|
||||
end
|
||||
|
||||
function robotAPI.swingDown()
|
||||
return robotComponent.swing(sides.down)
|
||||
end
|
||||
|
||||
--Use
|
||||
function robotAPI.useForward()
|
||||
return robotComponent.use(sides.front)
|
||||
end
|
||||
|
||||
function robotAPI.useUp()
|
||||
return robotComponent.use(sides.up)
|
||||
end
|
||||
|
||||
function robotAPI.useDown()
|
||||
return robotComponent.use(sides.down)
|
||||
end
|
||||
|
||||
-- Move
|
||||
function robotAPI.moveForward()
|
||||
robotAPI.move(sides.front)
|
||||
end
|
||||
|
||||
function robotAPI.moveBackward()
|
||||
robotAPI.move(sides.back)
|
||||
end
|
||||
|
||||
function robotAPI.moveUp()
|
||||
robotAPI.move(sides.up)
|
||||
end
|
||||
|
||||
function robotAPI.moveDown()
|
||||
robotAPI.move(sides.down)
|
||||
end
|
||||
|
||||
-- Turn
|
||||
function robotAPI.turnLeft()
|
||||
robotAPI.turn(false)
|
||||
end
|
||||
|
||||
function robotAPI.turnRight()
|
||||
robotAPI.turn(true)
|
||||
end
|
||||
|
||||
function robotAPI.turnAround()
|
||||
robotAPI.turn(true)
|
||||
robotAPI.turn(true)
|
||||
end
|
||||
|
||||
-------------------------------------------------- End of shit --------------------------------------------------
|
||||
|
||||
return robotAPI
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user