rework turtle policies

This commit is contained in:
kepler155c@gmail.com
2019-01-17 13:31:43 -05:00
parent 7914990d6c
commit 6416e67130
10 changed files with 71 additions and 46 deletions

View File

@@ -609,7 +609,10 @@ function TurtleBuilder:gotoSupplyPoint()
-- pathfind the rest of the way
local pt = self:getBuildingCorner(turtle.point.y)
turtle._goto({ x = pt.x, z = pt.z })
turtle.setPolicy('none')
turtle.set({
digPolicy = 'digNone',
attackPolicy = 'attackNone',
})
turtle.pathfind(self.supplyPoint)
os.sleep(.1) -- random 'Computer is not connected' error...
end
@@ -1106,7 +1109,10 @@ function TurtleBuilder:build()
local pt = self:getBuildingCorner(travelPlane)
turtle.pathfind({ x = pt.x, z = pt.z, y = travelPlane })
turtle.setPolicy('digAttack')
turtle.set({
digPolicy = 'dig',
attackPolicy = 'attack',
})
for i = self.index, last, direction do
self.index = i

View File

@@ -133,7 +133,12 @@ function turtle.level(startPt, endPt, firstPt, verbose)
error('failed to reach starting point')
end
turtle.setPolicy("attack", { dig = dig }, "assuredMove")
turtle.set({
digPolicy = dig,
attackPolicy = 'attack',
move = 'moveAssured',
})
oldCallback = turtle.getMoveCallback()
turtle.setMoveCallback(move)

View File

@@ -75,7 +75,7 @@ end
turtle.run(function()
turtle.reset()
turtle.setPolicy(turtle.policies.digOnly)
turtle.set({ digPolicy = 'dig' })
local s, m = pcall(function()
repeat

View File

@@ -49,7 +49,7 @@ equip('right', 'plethora:sensor', 'plethora:module:3')
local sensor = device['plethora:sensor']
turtle.setMovementStrategy('goto')
turtle.setPolicy(turtle.policies.attack)
turtle.set({ attackPolicy = 'attack' })
local function findChests()
if chest then

View File

@@ -62,7 +62,7 @@ shell.openForegroundTab('spawner.lua %s')]], table.concat({ ... }, ' ')))
end
turtle.setMovementStrategy('goto')
turtle.setPolicy(turtle.policies.attack)
turtle.set({ attackPolicy = 'attack' })
local function dropOff()
local inv = turtle.getSummedInventory()

View File

@@ -759,7 +759,10 @@ local tasks = {
local s, m = turtle.run(function()
turtle.reset()
turtle.addFeatures('crafting')
turtle.setPolicy("digAttack")
turtle.set({
attackPolicy = 'attack',
digPolicy = 'dig',
})
while not turtle.isAborted() do
print('fuel: ' .. turtle.getFuelLevel())

View File

@@ -517,7 +517,7 @@ local function fellTree(pt)
desperateRefuel(FUEL_BASE + 100)
turtle.clearMoveCallback()
turtle.setPolicy("attack")
turtle.set({ attackPolicy = "attack" })
return true
end
@@ -752,7 +752,7 @@ local tasks = {
local s, m = turtle.run(function()
turtle.addFeatures('level', 'crafting')
turtle.setPolicy("attack")
turtle.set({ attackPolicy = "attack" })
while not turtle.isAborted() do
print('fuel: ' .. turtle.getFuelLevel())

View File

@@ -87,43 +87,47 @@ local function run(member, point)
end
local function dropOff()
if chestPoint then
local topPoint = Point.copy(chestPoint)
topPoint.y = topPoint.y + 2
turtle.gotoY(topPoint.y)
while not turtle._goto(topPoint) do
os.sleep(.5)
end
-- drop off
local box = Point.makeBox(
{ x = chestPoint.x - 3, y = chestPoint.y + 3, z = chestPoint.z - 3 },
{ x = chestPoint.x + 3, y = chestPoint.y, z = chestPoint.z + 3 }
)
turtle.setMovementStrategy('pathing')
turtle.setPathingBox(Point.normalizeBox(box))
turtle.setPolicy('none')
while not turtle.moveAgainst(chestPoint) do
os.sleep(.5)
end
emptySlots({ }, chestPoint)
turtle.pathfind(Point.above(topPoint))
turtle.setMovementStrategy('goto')
turtle.setPolicy('turtleSafe')
else
turtle.gotoY(spt.y)
turtle._goto(spt)
emptySlots({ }, Point.above(spt))
-- go to 2 above chest
local topPoint = Point.copy(chestPoint)
topPoint.y = topPoint.y + 2
turtle.gotoY(topPoint.y)
while not turtle._goto(topPoint) do
os.sleep(.5)
end
-- path to chest
local box = Point.makeBox(
{ x = chestPoint.x - 3, y = chestPoint.y + 3, z = chestPoint.z - 3 },
{ x = chestPoint.x + 3, y = chestPoint.y, z = chestPoint.z + 3 }
)
turtle.set({
movementStrategy = 'pathing',
pathingBox = Point.normalizeBox(box),
digPolicy = 'digNone',
})
while not turtle.moveAgainst(chestPoint) do
os.sleep(.5)
end
emptySlots({ }, chestPoint)
-- path to 3 above chest
turtle.pathfind(Point.above(topPoint))
turtle.set({
movementStrategy = 'goto',
digPolicy = 'turtleSafe',
})
end
if turtle then
turtles[member.id] = turtle
turtle.reset()
turtle.setPolicy('turtleSafe')
turtle.setMovementStrategy('goto')
turtle.setPoint(point)
turtle.set({
attackPolicy = 'attack',
digPolicy = 'turtleSafe',
movementStrategy = 'goto',
point = point,
})
repeat
local pt = getNextPoint(turtle)
@@ -160,7 +164,7 @@ local function run(member, point)
while not turtle._goto(Point.above(spt)) do
os.sleep(.5)
end
turtle.setPolicy('digOnly')
turtle.set({ digPolicy = 'dig' })
turtle._goto(spt)
else
turtle.gotoY(spt.y)
@@ -220,7 +224,10 @@ local page = UI.Page {
function page.info:draw()
self:clear()
self:write(2, 1, 'Turtles: ' .. Util.size(turtles))
self:write(20, 1, 'Queue: ' .. Util.size(queue))
if not chestPoint then
self:write(16, 1, 'No chest')
end
self:write(28, 1, 'Queue: ' .. Util.size(queue))
end
function page:scan()

View File

@@ -626,9 +626,11 @@ Event.addRoutine(function()
Util.writeTable(PROGRESS_FILE, mining)
end
turtle.setPolicy(turtle.policies.digAttack)
turtle.setDigPolicy(turtle.digPolicies.turtleSafe)
turtle.setMovementStrategy('goto')
turtle.set({
attackPolicy = 'attack',
digPolicy = 'turtleSafe',
movementStrategy = 'goto',
})
status('mining')
Event.onTerminate(function()

View File

@@ -622,8 +622,10 @@ end
turtle.run(function()
turtle.reset()
turtle.setPolicy(turtle.policies.digAttack)
turtle.setDigPolicy(turtle.digPolicies.turtleSafe)
turtle.set({
attackPolicy = 'attack',
digPolicy = 'turtleSafe',
})
unload()
status('mining')