refactor + cleanup

This commit is contained in:
kepler155c
2017-10-27 20:25:16 -04:00
parent 9939c75fc3
commit d97a9d7468
17 changed files with 261 additions and 299 deletions

View File

@@ -1 +1 @@
turtle.abortAction()
turtle.abort(true)

View File

@@ -1,12 +1,15 @@
local os = _G.os
local turtle = _G.turtle
local function follow(id)
requireInjector(getfenv(1))
_G.requireInjector()
local Event = require('event')
local Point = require('point')
local Socket = require('socket')
turtle.status = 'follow ' .. id
turtle.setStatus('follow ' .. id)
if not turtle.enableGPS() then
error('turtle: No GPS found')
@@ -55,7 +58,7 @@ local function follow(id)
Event.onInterval(.5, function()
local function getRemotePoint()
if not turtle.abort then
if not turtle.isAborted() then
if socket:write({ type = 'gps' }) then
return socket:read(3)
end
@@ -65,7 +68,7 @@ local function follow(id)
-- sometimes gps will fail if moving
local pt, d
for i = 1, 3 do
for _ = 1, 3 do
pt, d = getRemotePoint()
if pt then
break
@@ -73,18 +76,18 @@ local function follow(id)
os.sleep(.5)
end
if not pt or turtle.abort then
if not pt or turtle.isAborted() then
error('Did not receive GPS location')
end
if not lastPoint or (lastPoint.x ~= pt.x or lastPoint.y ~= pt.y or lastPoint.z ~= pt.z) then
if following then
turtle.abort = true
turtle.getState().abort = true
while following do
os.sleep(.1)
end
turtle.abort = false
turtle.getState().abort = false
end
-- check if gps is inaccurate (player moving too fast)

View File

@@ -70,7 +70,7 @@ local function findObsidian()
if not turtle.gotoPoint(node) then
break
end
until turtle.abort
until turtle.isAborted()
end
turtle.run(function()
@@ -97,7 +97,7 @@ turtle.run(function()
turtle.placeDown()
turtle.down()
turtle.select(1)
until turtle.abort
until turtle.isAborted()
end)
if not s and m then

View File

@@ -6,7 +6,7 @@ local function summon(id)
local Point = require('point')
local Socket = require('socket')
turtle.status = 'GPSing'
turtle.setStatus('GPSing')
turtle.setPoint({ x = 0, y = 0, z = 0, heading = 0 })
local pts = {
@@ -64,7 +64,7 @@ local function summon(id)
local pt = { x = pos.x, y = pos.y, z = pos.z }
local _, h = Point.calculateMoves(turtle.getPoint(), pt)
local hi = turtle.getHeadingInfo(h)
turtle.status = 'recalling'
turtle.setStatus('recalling')
turtle.pathfind({ x = pt.x - hi.xd, z = pt.z - hi.zd, y = pt.y - hi.yd, heading = h })
else
error("turtle: Could not determine position")