feat(inferium-harvester): improve printed messages + fuel management at start
This commit is contained in:
parent
9dd106763e
commit
a4a33d1eef
@ -3,7 +3,7 @@ local utils = require('libs/utils')
|
|||||||
local turtleUtils = require('libs/turtle-utils')
|
local turtleUtils = require('libs/turtle-utils')
|
||||||
local config = require('config/harvesting')
|
local config = require('config/harvesting')
|
||||||
|
|
||||||
local VERSION = "2.0.0"
|
local VERSION = "2.2.0"
|
||||||
local INFERIUM_SERVER = 'inferium.com'
|
local INFERIUM_SERVER = 'inferium.com'
|
||||||
local IDLE_TIME = 2
|
local IDLE_TIME = 2
|
||||||
local WAIT_ITEM_IDLE_TIME = 5
|
local WAIT_ITEM_IDLE_TIME = 5
|
||||||
@ -44,10 +44,8 @@ local function getIndexedCount(t)
|
|||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
local function assertEnoughFuel()
|
local function hasEnoughFuel()
|
||||||
if turtle.getFuelLevel() < MIN_FUEL_NEEDED then
|
return turtle.getFuelLevel() >= MIN_FUEL_NEEDED
|
||||||
error('Not enough fuel')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function retrieveChestFuelOrientation()
|
local function retrieveChestFuelOrientation()
|
||||||
@ -100,6 +98,7 @@ end
|
|||||||
|
|
||||||
-- Implementations
|
-- Implementations
|
||||||
local function retrieveHomePositionProcedure()
|
local function retrieveHomePositionProcedure()
|
||||||
|
print("> retrieving the home position")
|
||||||
if turtleUtils.getInventory('bottom') then
|
if turtleUtils.getInventory('bottom') then
|
||||||
retrieveChestFuelOrientation()
|
retrieveChestFuelOrientation()
|
||||||
return
|
return
|
||||||
@ -143,6 +142,7 @@ local function retrieveHomePositionProcedure()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function dropAllProcedure()
|
local function dropAllProcedure()
|
||||||
|
print('> drop all')
|
||||||
for i=1, 16, 1 do
|
for i=1, 16, 1 do
|
||||||
local count = turtle.getItemCount(i)
|
local count = turtle.getItemCount(i)
|
||||||
|
|
||||||
@ -157,6 +157,7 @@ local function dropAllProcedure()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function refuelProcedure()
|
local function refuelProcedure()
|
||||||
|
print('> refuel')
|
||||||
local refuelOk, refuelErr = turtleUtils.refuelWithBuffer('bottom', 'front', MIN_FUEL_NEEDED, IDLE_TIME)
|
local refuelOk, refuelErr = turtleUtils.refuelWithBuffer('bottom', 'front', MIN_FUEL_NEEDED, IDLE_TIME)
|
||||||
|
|
||||||
if not refuelOk then
|
if not refuelOk then
|
||||||
@ -221,6 +222,8 @@ local function forward()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function harvestProcedure()
|
local function harvestProcedure()
|
||||||
|
print('> harvest')
|
||||||
|
|
||||||
for i=1, config.length, 1 do
|
for i=1, config.length, 1 do
|
||||||
harvestDown(i)
|
harvestDown(i)
|
||||||
|
|
||||||
@ -242,6 +245,7 @@ end
|
|||||||
local function retrieveLocalPlan()
|
local function retrieveLocalPlan()
|
||||||
goToHarvestPoint()
|
goToHarvestPoint()
|
||||||
|
|
||||||
|
print('> retrieve the local plan')
|
||||||
localPlan = {}
|
localPlan = {}
|
||||||
|
|
||||||
for i=1, config.length, 1 do
|
for i=1, config.length, 1 do
|
||||||
@ -267,6 +271,7 @@ local function retrieveLocalPlan()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function fetchRemotePlan()
|
local function fetchRemotePlan()
|
||||||
|
print('> fetch remote plan')
|
||||||
local message = { type = 'getplan', payload = { computerId = os.getComputerID() } }
|
local message = { type = 'getplan', payload = { computerId = os.getComputerID() } }
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
@ -276,6 +281,7 @@ local function fetchRemotePlan()
|
|||||||
previouslyFetchedRemotePlan = replyMessage.payload
|
previouslyFetchedRemotePlan = replyMessage.payload
|
||||||
return replyMessage.payload
|
return replyMessage.payload
|
||||||
elseif previouslyFetchedRemotePlan then
|
elseif previouslyFetchedRemotePlan then
|
||||||
|
print('> failed to fetch remote plan, use the previous one instead')
|
||||||
return previouslyFetchedRemotePlan
|
return previouslyFetchedRemotePlan
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -286,7 +292,8 @@ end
|
|||||||
local function removeSeeds(seeds)
|
local function removeSeeds(seeds)
|
||||||
goToHarvestPoint()
|
goToHarvestPoint()
|
||||||
|
|
||||||
local stateSeeds = seeds
|
print('> remove old seeds')
|
||||||
|
local stateSeeds = seeds -- warning: do not mutate the data (only the ref)
|
||||||
|
|
||||||
for i=1, config.length, 1 do
|
for i=1, config.length, 1 do
|
||||||
local ok, block = turtle.inspectDown()
|
local ok, block = turtle.inspectDown()
|
||||||
@ -324,6 +331,7 @@ local function removeSeeds(seeds)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function retrieveSeeds(seeds)
|
local function retrieveSeeds(seeds)
|
||||||
|
print('> retrieve seeds from inventory')
|
||||||
local seedRetrieved = false
|
local seedRetrieved = false
|
||||||
local seedsCount = getIndexedCount(seeds)
|
local seedsCount = getIndexedCount(seeds)
|
||||||
|
|
||||||
@ -358,6 +366,8 @@ end
|
|||||||
local function replantSeeds()
|
local function replantSeeds()
|
||||||
goToHarvestPoint()
|
goToHarvestPoint()
|
||||||
|
|
||||||
|
print('> replant seeds')
|
||||||
|
|
||||||
for i=1, config.length, 1 do
|
for i=1, config.length, 1 do
|
||||||
local ok, block = turtle.inspectDown()
|
local ok, block = turtle.inspectDown()
|
||||||
|
|
||||||
@ -419,21 +429,34 @@ local function replantProcedure()
|
|||||||
localPlan = {}
|
localPlan = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function resetTerminal()
|
||||||
|
term.clear()
|
||||||
|
term.setCursorPos(1, 1)
|
||||||
|
end
|
||||||
|
|
||||||
-- Main procedure
|
-- Main procedure
|
||||||
local function main()
|
local function main()
|
||||||
net.openRednet()
|
net.openRednet()
|
||||||
|
|
||||||
print("Starting Trap's inferium harvester v" .. VERSION)
|
print("Starting Trap's inferium harvester v" .. VERSION)
|
||||||
|
|
||||||
turtleUtils.refuelAllFromInventory()
|
if not hasEnoughFuel() then
|
||||||
assertEnoughFuel()
|
turtleUtils.refuelAllFromInventory()
|
||||||
|
end
|
||||||
|
|
||||||
|
if not hasEnoughFuel() then
|
||||||
|
error('Not enough fuel', 0)
|
||||||
|
end
|
||||||
|
|
||||||
print("> retrieving home position")
|
|
||||||
retrieveHomePositionProcedure()
|
retrieveHomePositionProcedure()
|
||||||
|
|
||||||
print("> start the harvesting process")
|
local cycleNumber = 1
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
|
resetTerminal()
|
||||||
|
print('> Starting cycle ' .. tostring(cycleNumber))
|
||||||
|
print()
|
||||||
|
|
||||||
dropAllProcedure()
|
dropAllProcedure()
|
||||||
refuelProcedure()
|
refuelProcedure()
|
||||||
|
|
||||||
@ -442,6 +465,8 @@ local function main()
|
|||||||
goToHarvestPoint()
|
goToHarvestPoint()
|
||||||
harvestProcedure()
|
harvestProcedure()
|
||||||
goBackToHome()
|
goBackToHome()
|
||||||
|
|
||||||
|
cycleNumber = cycleNumber + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
net.closeRednet()
|
net.closeRednet()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user