From 0c69b555df123dfcc249c53a873378081c916eae Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Thu, 19 Feb 2026 21:21:09 -0500 Subject: [PATCH] feat: Enhance home position management with auto-setting functionality when GPS is available --- turtle.lua | 57 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/turtle.lua b/turtle.lua index 71b5789..3b7332a 100644 --- a/turtle.lua +++ b/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"