feat: Enhance home position management with auto-setting functionality when GPS is available
This commit is contained in:
57
turtle.lua
57
turtle.lua
@@ -82,19 +82,28 @@ end
|
||||
-- Set home position (server-authoritative via wireless)
|
||||
local function setHome()
|
||||
print("Setting home position...")
|
||||
if not updatePosition() then
|
||||
print("Failed to get GPS position for home")
|
||||
return false
|
||||
|
||||
-- If we don't have current position, try to get it
|
||||
-- But don't block if we already have it
|
||||
if not state.position then
|
||||
if not updatePosition() then
|
||||
print("Failed to get GPS position for home")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- Set locally immediately
|
||||
state.homePosition = state.position
|
||||
state.homePosition = {
|
||||
x = state.position.x,
|
||||
y = state.position.y,
|
||||
z = state.position.z
|
||||
}
|
||||
|
||||
-- Send to server via wireless (fire and forget)
|
||||
modem.transmit(CHANNEL_SEND, CHANNEL_RECEIVE, {
|
||||
type = "set_home",
|
||||
turtleID = os.getComputerID(),
|
||||
position = state.position
|
||||
position = state.homePosition
|
||||
})
|
||||
|
||||
print("✅ Home set at:", textutils.serialize(state.homePosition))
|
||||
@@ -569,7 +578,24 @@ local commands = {
|
||||
explore = function()
|
||||
print("Explore command received")
|
||||
if not state.homePosition then
|
||||
return false, "Home not set! Use setHome first"
|
||||
-- Auto-set home at current position if we have GPS
|
||||
if state.position then
|
||||
print("Auto-setting home at current position")
|
||||
state.homePosition = {
|
||||
x = state.position.x,
|
||||
y = state.position.y,
|
||||
z = state.position.z
|
||||
}
|
||||
-- Sync to server
|
||||
modem.transmit(CHANNEL_SEND, CHANNEL_RECEIVE, {
|
||||
type = "set_home",
|
||||
turtleID = os.getComputerID(),
|
||||
position = state.homePosition
|
||||
})
|
||||
print("✅ Home auto-set at:", textutils.serialize(state.homePosition))
|
||||
else
|
||||
return false, "Home not set and no GPS available! Use setHome first"
|
||||
end
|
||||
end
|
||||
if isTooFarFromHome() then
|
||||
return false, "Already at max distance from home"
|
||||
@@ -583,7 +609,24 @@ local commands = {
|
||||
mine = function()
|
||||
print("Mine command received")
|
||||
if not state.homePosition then
|
||||
return false, "Home not set! Use setHome first"
|
||||
-- Auto-set home at current position if we have GPS
|
||||
if state.position then
|
||||
print("Auto-setting home at current position")
|
||||
state.homePosition = {
|
||||
x = state.position.x,
|
||||
y = state.position.y,
|
||||
z = state.position.z
|
||||
}
|
||||
-- Sync to server
|
||||
modem.transmit(CHANNEL_SEND, CHANNEL_RECEIVE, {
|
||||
type = "set_home",
|
||||
turtleID = os.getComputerID(),
|
||||
position = state.homePosition
|
||||
})
|
||||
print("✅ Home auto-set at:", textutils.serialize(state.homePosition))
|
||||
else
|
||||
return false, "Home not set and no GPS available! Use setHome first"
|
||||
end
|
||||
end
|
||||
if isTooFarFromHome() then
|
||||
return false, "Already at max distance from home"
|
||||
|
||||
Reference in New Issue
Block a user