initial commit
This commit is contained in:
40
.gitignore
vendored
Normal file
40
.gitignore
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
# Compiled Lua sources
|
||||
luac.out
|
||||
|
||||
# luarocks build files
|
||||
*.src.rock
|
||||
*.zip
|
||||
*.tar.gz
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.os
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
*.def
|
||||
*.exp
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
363
coord
Normal file
363
coord
Normal file
@@ -0,0 +1,363 @@
|
||||
--[[
|
||||
Allows a turtle to keep track of it's
|
||||
location using a coordinate system.
|
||||
|
||||
Use the commands goForward(), goRight(),
|
||||
goLeft(), goUp(), and goDown() to
|
||||
control the turtle while adding to
|
||||
the coordinates.
|
||||
|
||||
goHome() will send the turtle back to
|
||||
it's origin and will point it north:
|
||||
the direction it was originally facing.
|
||||
|
||||
A turtle always faces north when it is placed down
|
||||
]]--
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
z = 0
|
||||
|
||||
saveX = 0
|
||||
saveY = 0
|
||||
saveZ = 0
|
||||
saveDirection = NORTH
|
||||
global map = {}
|
||||
|
||||
NORTH = 1
|
||||
EAST = 2
|
||||
SOUTH = 3
|
||||
WEST = 4
|
||||
|
||||
UP = 5
|
||||
DOWN = 6
|
||||
|
||||
RIGHT = 7
|
||||
LEFT = 8
|
||||
|
||||
direction = NORTH
|
||||
|
||||
--[[sends a turtle forward 1 block
|
||||
and adds to it's X coordinate]]--
|
||||
function goForward()
|
||||
if turtle.forward() then
|
||||
addToCoords(direction)
|
||||
return true
|
||||
else return false
|
||||
end
|
||||
end
|
||||
|
||||
--[[sends a turtle up 1 block
|
||||
and adds to it's Z coordinate]]--
|
||||
function goUp()
|
||||
if turtle.up() then
|
||||
addToCoords(UP)
|
||||
return true
|
||||
else return false
|
||||
end
|
||||
end
|
||||
|
||||
--[[sends a turtle down 1 block
|
||||
and subtracts from it's Z coordinate]]--
|
||||
function goDown()
|
||||
if turtle.down() then
|
||||
addToCoords(DOWN)
|
||||
return true
|
||||
else return false
|
||||
end
|
||||
end
|
||||
|
||||
--[[turns a turtle right and changes
|
||||
it's direction accordingly]]--
|
||||
function goRight()
|
||||
turtle.turnRight()
|
||||
changeDirection(RIGHT)
|
||||
end
|
||||
|
||||
--[[turns a turtle left and changes
|
||||
it's direction accordingly]]--
|
||||
function goLeft()
|
||||
turtle.turnLeft()
|
||||
changeDirection(LEFT)
|
||||
end
|
||||
|
||||
--[[digs the block in front of the turtle and
|
||||
sends it forward, keeping track of it's coordinates]]--
|
||||
function goDig()
|
||||
turtle.dig()
|
||||
goForward()
|
||||
end
|
||||
|
||||
--[[digs the block above the turtle and sends it
|
||||
up, keeping track of the coordinates]]--
|
||||
function goDigUp()
|
||||
turtle.digUp()
|
||||
goUp()
|
||||
end
|
||||
|
||||
--[[digs the block below the turtle and sends it
|
||||
down, keeping track of it's coordinates]]--
|
||||
function goDigDown()
|
||||
turtle.digDown()
|
||||
goUp()
|
||||
end
|
||||
|
||||
--[[sends a turtle home and refuels it from a chest
|
||||
below it's origin]]--
|
||||
function goRefuel()
|
||||
goHome()
|
||||
turtle.suckDown(64)
|
||||
turtle.select(1)
|
||||
turtle.refuel()
|
||||
end
|
||||
|
||||
--[[moves a turtle forward a specified number of blocks]]--
|
||||
function move(distance)
|
||||
for i=1,distance do
|
||||
goForward()
|
||||
end
|
||||
end
|
||||
|
||||
--[[moves a turtle up a specified number of blocks]]--
|
||||
function moveUp(distance)
|
||||
for i=1,distance do
|
||||
goUp()
|
||||
end
|
||||
end
|
||||
|
||||
--[[moves a turtle down a specified number of blocks]]--
|
||||
function moveDown(distance)
|
||||
for i=1,distance do
|
||||
goDown()
|
||||
end
|
||||
end
|
||||
|
||||
function autoGoForward()
|
||||
distanceHome = math.abs(x)+math.abs(y)+math.abs(z)
|
||||
if distanceHome < turtle.getFuelLevel()-1 then
|
||||
goForward()
|
||||
else saveAndFuel() end
|
||||
end
|
||||
|
||||
function autoGoUp()
|
||||
distanceHome = math.abs(x)+math.abs(y)+math.abs(z)
|
||||
if distanceHome < turtle.getFuelLevel()-1 then
|
||||
goUp()
|
||||
else saveAndFuel() end
|
||||
end
|
||||
|
||||
function autoGoDown()
|
||||
distanceHome = math.abs(x)+math.abs(y)+math.abs(z)
|
||||
if distanceHome < turtle.getFuelLevel()-1 then
|
||||
goDown()
|
||||
else saveAndFuel() end
|
||||
end
|
||||
|
||||
function autoMove(distance)
|
||||
for i=1,distance do
|
||||
autoGoForward()
|
||||
end
|
||||
end
|
||||
|
||||
function autoMoveUp(distance)
|
||||
for i=1,distance do
|
||||
autoGoUp()
|
||||
end
|
||||
end
|
||||
|
||||
function autoMoveDown(distance)
|
||||
for i=1,distance do
|
||||
autoGoDown()
|
||||
end
|
||||
end
|
||||
|
||||
--[[takes the direction of the turtle and adds 1
|
||||
to the appropriate coordinate based on that direction]]--
|
||||
function addToCoords(direction)
|
||||
if direction == NORTH then
|
||||
x = x+1
|
||||
elseif direction == EAST then
|
||||
y = y+1
|
||||
elseif direction == SOUTH then
|
||||
x = x-1
|
||||
elseif direction == WEST then
|
||||
y = y-1
|
||||
elseif direction == UP then
|
||||
z = z+1
|
||||
else
|
||||
z = z-1
|
||||
end
|
||||
end
|
||||
|
||||
--[[takes a direction turned (right or left) and changes the
|
||||
direction of the turtle to north, south, east, or west]]--
|
||||
function changeDirection(turned)
|
||||
if turned == RIGHT then
|
||||
if direction == NORTH then
|
||||
direction = EAST
|
||||
elseif direction == EAST then
|
||||
direction = SOUTH
|
||||
elseif direction == SOUTH then
|
||||
direction = WEST
|
||||
else
|
||||
direction = NORTH
|
||||
end
|
||||
else
|
||||
if direction == NORTH then
|
||||
direction = WEST
|
||||
elseif direction == WEST then
|
||||
direction = SOUTH
|
||||
elseif direction == SOUTH then
|
||||
direction = EAST
|
||||
else
|
||||
direction = NORTH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[takes a direction (north, east, south, or west) and turns
|
||||
the turtle in that direction]]--
|
||||
function setDirection(newDirect)
|
||||
while true do
|
||||
if newDirect == direction then
|
||||
break
|
||||
end
|
||||
goRight()
|
||||
end
|
||||
end
|
||||
|
||||
--[[based on the current coordinates of a turtle, send the turtle
|
||||
back on the x axis, then the y axis, then the z axis]]--
|
||||
function goHome()
|
||||
moved = false
|
||||
attempts = 0
|
||||
rightDirection = true
|
||||
leftDirection = false
|
||||
while x~=0 or y~=0 or z~=0 do
|
||||
|
||||
if x > 0 then
|
||||
setDirection(SOUTH)
|
||||
else
|
||||
setDirection(NORTH)
|
||||
end
|
||||
while math.abs(x) > 0 and not turtle.detect() do
|
||||
goForward()
|
||||
moved = true
|
||||
end
|
||||
|
||||
if y > 0 then
|
||||
setDirection(WEST)
|
||||
else
|
||||
setDirection(EAST)
|
||||
end
|
||||
while math.abs(y) > 0 and not turtle.detect() do
|
||||
goForward()
|
||||
moved = true
|
||||
end
|
||||
|
||||
while z > 0 and not turtle.detectDown() do
|
||||
goDown()
|
||||
end
|
||||
while z < 0 and not turtle.detectUp() do
|
||||
goUp()
|
||||
moved = true
|
||||
end
|
||||
|
||||
if moved == false then
|
||||
mazeSolve()
|
||||
end
|
||||
|
||||
moved = false
|
||||
end
|
||||
setDirection(NORTH)
|
||||
end
|
||||
|
||||
function saveAndFuel()
|
||||
saveCoords()
|
||||
goRefuel()
|
||||
returnToCoords()
|
||||
end
|
||||
|
||||
function saveCoords()
|
||||
saveX = x
|
||||
saveY = y
|
||||
saveZ = z
|
||||
saveDirection = direction
|
||||
end
|
||||
|
||||
function returnToCoords()
|
||||
x = -saveX
|
||||
y = -saveY
|
||||
z = -saveZ
|
||||
goHome()
|
||||
setDirection(saveDirection)
|
||||
x = saveX
|
||||
y = saveY
|
||||
z = saveZ
|
||||
end
|
||||
|
||||
--[[write the main code down here]]--
|
||||
|
||||
--[[solves mazes]]--
|
||||
function mazeSolve()
|
||||
layer = 1
|
||||
while not returned() do
|
||||
try(map(layer,map))
|
||||
layer = layer + 1
|
||||
end
|
||||
end
|
||||
|
||||
--[[saves a map of the world around the turtle based on spaces away from the
|
||||
turtle. all the empty spaces will be marked as true and the spaces blocked
|
||||
by a block will be marked as false]]--
|
||||
function map(layer, map)
|
||||
|
||||
print("made it")
|
||||
|
||||
for i=1,layer do
|
||||
|
||||
print("made it")
|
||||
|
||||
saveCoords()
|
||||
move(layer)
|
||||
map[layer][direction] = turtle.detect()
|
||||
returnToCoords()
|
||||
goRight()
|
||||
end
|
||||
|
||||
for i=1,layer do
|
||||
saveCoords()
|
||||
moveUp(layer)
|
||||
map[layer][UP] = turtle.detectUp()
|
||||
returnToCoords()
|
||||
end
|
||||
|
||||
for i=1,layer do
|
||||
saveCoords()
|
||||
moveDown(layer)
|
||||
map[layer][DOWN] = turtle.detectDown()
|
||||
returnToCoords()
|
||||
end
|
||||
return map
|
||||
end
|
||||
|
||||
--[[tries a layer to see if a turtle can go home by unsticking itself]]--
|
||||
function try(map)
|
||||
for i=1,4 do
|
||||
if map[layer][direction] then
|
||||
move(layer)
|
||||
goHome()
|
||||
if returned() then break end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function returned()
|
||||
return x==0 and y==0 and z==0
|
||||
end
|
||||
|
||||
autoMove(15)
|
||||
goRight()
|
||||
autoMove(30)
|
||||
autoMoveUp(15)
|
||||
goHome()
|
||||
192
mazeSolver
Normal file
192
mazeSolver
Normal file
@@ -0,0 +1,192 @@
|
||||
--[[
|
||||
Allows a turtle to keep track of it's
|
||||
location using a coordinate system.
|
||||
|
||||
Use the commands goForward(), goRight(),
|
||||
goLeft(), goUp(), and goDown() to
|
||||
control the turtle while adding to
|
||||
the coordinates.
|
||||
|
||||
goHome() will send the turtle back to
|
||||
it's origin and will point it north:
|
||||
the direction it was originally facing.
|
||||
|
||||
A turtle always faces north when it is placed down
|
||||
]]--
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
z = 0
|
||||
|
||||
saveX = 0
|
||||
saveY = 0
|
||||
saveZ = 0
|
||||
|
||||
ZX = 0
|
||||
ZY = 0
|
||||
ZZ = 0
|
||||
|
||||
saveDirection = NORTH
|
||||
|
||||
NORTH = 1
|
||||
EAST = 2
|
||||
SOUTH = 3
|
||||
WEST = 4
|
||||
|
||||
UP = 5
|
||||
DOWN = 6
|
||||
|
||||
RIGHT = 7
|
||||
LEFT = 8
|
||||
|
||||
direction = NORTH
|
||||
|
||||
--[[sends a turtle forward 1 block
|
||||
and adds to it's X coordinate]]--
|
||||
function goForward()
|
||||
if turtle.forward() then
|
||||
addToCoords(direction)
|
||||
return true
|
||||
else return false
|
||||
end
|
||||
end
|
||||
|
||||
--[[sends a turtle up 1 block
|
||||
and adds to it's Z coordinate]]--
|
||||
function goUp()
|
||||
if turtle.up() then
|
||||
addToCoords(UP)
|
||||
return true
|
||||
else return false
|
||||
end
|
||||
end
|
||||
|
||||
--[[sends a turtle down 1 block
|
||||
and subtracts from it's Z coordinate]]--
|
||||
function goDown()
|
||||
if turtle.down() then
|
||||
addToCoords(DOWN)
|
||||
return true
|
||||
else return false
|
||||
end
|
||||
end
|
||||
|
||||
--[[turns a turtle right and changes
|
||||
it's direction accordingly]]--
|
||||
function goRight()
|
||||
turtle.turnRight()
|
||||
changeDirection(RIGHT)
|
||||
end
|
||||
|
||||
--[[turns a turtle left and changes
|
||||
it's direction accordingly]]--
|
||||
function goLeft()
|
||||
turtle.turnLeft()
|
||||
changeDirection(LEFT)
|
||||
end
|
||||
|
||||
--[[moves a turtle forward a specified number of blocks]]--
|
||||
function move(distance)
|
||||
for i=1,distance do
|
||||
goForward()
|
||||
end
|
||||
end
|
||||
|
||||
--[[moves a turtle up a specified number of blocks]]--
|
||||
function moveUp(distance)
|
||||
for i=1,distance do
|
||||
goUp()
|
||||
end
|
||||
end
|
||||
|
||||
--[[moves a turtle down a specified number of blocks]]--
|
||||
function moveDown(distance)
|
||||
for i=1,distance do
|
||||
goDown()
|
||||
end
|
||||
end
|
||||
|
||||
--[[takes the direction of the turtle and adds 1
|
||||
to the appropriate coordinate based on that direction]]--
|
||||
function addToCoords(direction)
|
||||
if direction == NORTH then
|
||||
x = x+1
|
||||
elseif direction == EAST then
|
||||
y = y+1
|
||||
elseif direction == SOUTH then
|
||||
x = x-1
|
||||
elseif direction == WEST then
|
||||
y = y-1
|
||||
elseif direction == UP then
|
||||
z = z+1
|
||||
else
|
||||
z = z-1
|
||||
end
|
||||
end
|
||||
|
||||
--[[takes a direction turned (right or left) and changes the
|
||||
direction of the turtle to north, south, east, or west]]--
|
||||
function changeDirection(turned)
|
||||
if turned == RIGHT then
|
||||
if direction == NORTH then
|
||||
direction = EAST
|
||||
elseif direction == EAST then
|
||||
direction = SOUTH
|
||||
elseif direction == SOUTH then
|
||||
direction = WEST
|
||||
else
|
||||
direction = NORTH
|
||||
end
|
||||
else
|
||||
if direction == NORTH then
|
||||
direction = WEST
|
||||
elseif direction == WEST then
|
||||
direction = SOUTH
|
||||
elseif direction == SOUTH then
|
||||
direction = EAST
|
||||
else
|
||||
direction = NORTH
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[takes a direction (north, east, south, or west) and turns
|
||||
the turtle in that direction]]--
|
||||
function setDirection(newDirect)
|
||||
while true do
|
||||
if newDirect == direction then
|
||||
break
|
||||
end
|
||||
goRight()
|
||||
end
|
||||
end
|
||||
|
||||
--[[This will solve a three dimensional maze]]--
|
||||
|
||||
WENT_DOWN = 20
|
||||
WENT_UP = 21
|
||||
LAST_MOVE = 0
|
||||
|
||||
|
||||
|
||||
function solve2D()
|
||||
if not goForward() then
|
||||
goLeft()
|
||||
end
|
||||
end
|
||||
|
||||
function solve3D()
|
||||
if not goToZ() then
|
||||
solve2D()
|
||||
end
|
||||
end
|
||||
|
||||
function goToZ(way)
|
||||
if way = UP
|
||||
goUp()
|
||||
LAST_MOVE = WENT_UP
|
||||
else
|
||||
goDown()
|
||||
LAST_MOVE = WENT_DOWN
|
||||
end
|
||||
end
|
||||
157
reactorInfo
Normal file
157
reactorInfo
Normal file
@@ -0,0 +1,157 @@
|
||||
AUTOMATIC = true
|
||||
EJECT = true
|
||||
|
||||
function reactorWrite(monitor, reactor)
|
||||
monitor.clear()
|
||||
|
||||
monitor.setCursorPos(1,1)
|
||||
active = tostring(reactor.getActive())
|
||||
monitor.write("Active: ".. active)
|
||||
|
||||
currentFuel = reactor.getFuelAmount()
|
||||
fuelMax = reactor.getFuelAmountMax()
|
||||
fuel = tostring((currentFuel / fuelMax)*100)
|
||||
monitor.setCursorPos(1,2)
|
||||
monitor.write("Fuel: ".. fuel.."%")
|
||||
|
||||
energy = tostring(reactor.getEnergyProducedLastTick())
|
||||
monitor.setCursorPos(1,3)
|
||||
monitor.write("Energy: ".. energy.." RF")
|
||||
|
||||
curStore = reactor.getEnergyStored()
|
||||
maxEnergy = 10000000
|
||||
energyStore = tostring((curStore / maxEnergy)*100)
|
||||
monitor.setCursorPos(1,4)
|
||||
monitor.write("Energy Buffer: "..energyStore.."%")
|
||||
|
||||
if AUTOMATIC then
|
||||
if tonumber(energyStore) > 95 then
|
||||
reactor.setActive(false)
|
||||
monitor.setBackgroundColor(colors.red)
|
||||
end
|
||||
if tonumber(energyStore) < 95 then
|
||||
reactor.setActive(true)
|
||||
monitor.setBackgroundColor(colors.blue)
|
||||
end
|
||||
end
|
||||
|
||||
caseTemp = tostring(reactor.getCasingTemperature())
|
||||
monitor.setCursorPos(1,5)
|
||||
monitor.write("Temperature: "..caseTemp)
|
||||
|
||||
--[[Fuel Bar Graph]]--
|
||||
barWidth = math.floor((tonumber(fuel)/100)*20)
|
||||
makeBarGraph("Fuel: ", 10, 8, 19, 2, false, barWidth, monitor)
|
||||
|
||||
--[[Energy Bar Graph]]--
|
||||
barWidth = math.floor((tonumber(energyStore)/100)*20)
|
||||
makeBarGraph("Energy: ", 10, 11, 19, 2, false, barWidth, monitor)
|
||||
|
||||
--[[Produced Bar Graph]]--
|
||||
barWidth = math.floor((tonumber(energy)/1000000)*20)
|
||||
makeBarGraph("Produced: ", 10, 14, 19, 2, false, barWidth, monitor)
|
||||
|
||||
--[[Temperature Bar Graph]]--
|
||||
barWidth = math.floor((tonumber(caseTemp)/2000)*20)
|
||||
makeBarGraph("Temp: ", 10, 17, 19, 2, true, barWidth, monitor)
|
||||
|
||||
--[[On/off button]]--
|
||||
if reactor.getActive() then
|
||||
color = colors.white
|
||||
label = "ON"
|
||||
else
|
||||
color = colors.black
|
||||
label = "OFF"
|
||||
end
|
||||
makeButton(label, 31, 1,9, 5, color)
|
||||
|
||||
--[[Auto Button]]--
|
||||
if AUTOMATIC then
|
||||
color = colors.white
|
||||
label = "AUTOMATIC"
|
||||
else
|
||||
color = colors.black
|
||||
label = "MANUAL"
|
||||
end
|
||||
makeButton(label, 31, 8,9, 5, color)
|
||||
|
||||
--[[Eject/Accept]]--
|
||||
if EJECT then
|
||||
color = colors.white
|
||||
label = "EJECT"
|
||||
else
|
||||
color = colors.black
|
||||
label = "INTAKE"
|
||||
end
|
||||
makeButton(label, 31, 15,9, 5, color)
|
||||
end
|
||||
|
||||
--[[makes a bar graph for a big reactor]]--
|
||||
--[[str, num, num, num, num, num, bool, monitor]]--
|
||||
function makeBarGraph(label, xpos, ypos, width, height, inverted, barWidth, monitor)
|
||||
|
||||
--[[stops flickering]]--
|
||||
barStart = xpos + barWidth
|
||||
barEnd = width - barWidth
|
||||
|
||||
--[[makes the label]]--
|
||||
monitor.setCursorPos(1, ypos)
|
||||
monitor.write(label)
|
||||
|
||||
--[[makes the first bar]]--
|
||||
firstBar = window.create(monitor, xpos, ypos, width, height)
|
||||
if inverted then
|
||||
firstBar.setBackgroundColor(colors.green)
|
||||
else
|
||||
firstBar.setBackgroundColor(colors.orange)
|
||||
end
|
||||
firstBar.clear()
|
||||
|
||||
--[[makes the middle bar]]--
|
||||
middleBar = window.create(monitor, xpos+2, ypos, width-2, height)
|
||||
middleBar.setBackgroundColor(colors.yellow)
|
||||
middleBar.clear()
|
||||
|
||||
--[[makes the last bar]]--
|
||||
endBar = window.create(monitor, xpos+8, ypos, width-8, height)
|
||||
if inverted then
|
||||
endBar.setBackgroundColor(colors.orange)
|
||||
else
|
||||
endBar.setBackgroundColor(colors.green)
|
||||
end
|
||||
endBar.clear()
|
||||
|
||||
--[[makes the variable bar]]--
|
||||
varBar = window.create(monitor, barStart, ypos, barEnd, height)
|
||||
varBar.setBackgroundColor(colors.black)
|
||||
varBar.clear()
|
||||
|
||||
monitor.setCursorPos(xpos, ypos+2)
|
||||
monitor.write("0%")
|
||||
monitor.setCursorPos(xpos+16, ypos+2)
|
||||
monitor.write("100%")
|
||||
end
|
||||
|
||||
function makeButton(label, xpos, ypos, width, height, color)
|
||||
labelLength = string.len(label)
|
||||
ycenter = ypos + height/2
|
||||
xcenter = xpos + width/2
|
||||
labelStart = (xcenter - labelLength/2)
|
||||
|
||||
border = window.create(monitor, xpos, ypos+1, width, height)
|
||||
border.setBackgroundColor(color)
|
||||
border.clear()
|
||||
|
||||
monitor.setCursorPos(labelStart, ypos)
|
||||
monitor.setTextColor(colors.black)
|
||||
monitor.write(label)
|
||||
end
|
||||
|
||||
while true do
|
||||
reactor = peripheral.wrap("BigReactors-Reactor_0")
|
||||
monitor = peripheral.wrap("monitor_2")
|
||||
reactorWrite(monitor, reactor)
|
||||
monitor = peripheral.wrap("monitor_1")
|
||||
reactorWrite(monitor, reactor)
|
||||
os.sleep(.1)
|
||||
end
|
||||
Reference in New Issue
Block a user