feat: Enhance home position management with auto-setting functionality when GPS is available

This commit is contained in:
MayaTheShy
2026-02-19 21:21:09 -05:00
parent 0d2fe5b8b1
commit 0c69b555df

View File

@@ -82,19 +82,28 @@ end
-- Set home position (server-authoritative via wireless) -- Set home position (server-authoritative via wireless)
local function setHome() local function setHome()
print("Setting home position...") print("Setting home position...")
if not updatePosition() then
print("Failed to get GPS position for home") -- If we don't have current position, try to get it
return false -- 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 end
-- Set locally immediately -- 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) -- Send to server via wireless (fire and forget)
modem.transmit(CHANNEL_SEND, CHANNEL_RECEIVE, { modem.transmit(CHANNEL_SEND, CHANNEL_RECEIVE, {
type = "set_home", type = "set_home",
turtleID = os.getComputerID(), turtleID = os.getComputerID(),
position = state.position position = state.homePosition
}) })
print("✅ Home set at:", textutils.serialize(state.homePosition)) print("✅ Home set at:", textutils.serialize(state.homePosition))
@@ -569,7 +578,24 @@ local commands = {
explore = function() explore = function()
print("Explore command received") print("Explore command received")
if not state.homePosition then 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 end
if isTooFarFromHome() then if isTooFarFromHome() then
return false, "Already at max distance from home" return false, "Already at max distance from home"
@@ -583,7 +609,24 @@ local commands = {
mine = function() mine = function()
print("Mine command received") print("Mine command received")
if not state.homePosition then 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 end
if isTooFarFromHome() then if isTooFarFromHome() then
return false, "Already at max distance from home" return false, "Already at max distance from home"