neural flying
This commit is contained in:
@@ -351,18 +351,6 @@ function Storage:import(source, slot, count, item)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- is this item in some chest
|
|
||||||
if self.cache[key] then
|
|
||||||
for node, adapter in self:onlineAdapters() do
|
|
||||||
if count <= 0 then
|
|
||||||
return total
|
|
||||||
end
|
|
||||||
if adapter.cache and adapter.cache[key] and not node.lock then
|
|
||||||
insert(adapter)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not itemDB:get(item) then
|
if not itemDB:get(item) then
|
||||||
if item.displayName then
|
if item.displayName then
|
||||||
-- this item already has metadata
|
-- this item already has metadata
|
||||||
@@ -377,6 +365,18 @@ function Storage:import(source, slot, count, item)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- is this item in some chest
|
||||||
|
if self.cache[key] then
|
||||||
|
for node, adapter in self:onlineAdapters() do
|
||||||
|
if count <= 0 then
|
||||||
|
return total
|
||||||
|
end
|
||||||
|
if adapter.cache and adapter.cache[key] and not node.lock then
|
||||||
|
insert(adapter)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- high to low priority
|
-- high to low priority
|
||||||
for remote in self:onlineAdapters() do
|
for remote in self:onlineAdapters() do
|
||||||
if count <= 0 then
|
if count <= 0 then
|
||||||
|
|||||||
@@ -1,78 +1,97 @@
|
|||||||
_G.requireInjector(_ENV)
|
_G.requireInjector(_ENV)
|
||||||
|
|
||||||
local ni = require('neural.interface')
|
local Config = require('config')
|
||||||
local GPS = require('gps')
|
local GPS = require('gps')
|
||||||
|
local ni = _G.device.neuralInterface
|
||||||
|
|
||||||
local strength = .315
|
local os = _G.os
|
||||||
local delay = .1
|
local parallel = _G.parallel
|
||||||
|
|
||||||
while ni.getMetaOwner().health < 26 do
|
local id = ni.getID()
|
||||||
print('health: ' .. ni.getMetaOwner().health)
|
local config = Config.load('flight', { })
|
||||||
os.sleep(1)
|
|
||||||
|
local args = { ... }
|
||||||
|
if args[1] == 'wp' then
|
||||||
|
local pt = GPS.locate()
|
||||||
|
config[args[2]] = pt
|
||||||
|
Config.update('flight', config)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
ni.launch(0, 270, 1.5)
|
local wp = config[args[1]]
|
||||||
os.sleep(.25)
|
if not wp then
|
||||||
|
error('invalid wp')
|
||||||
|
end
|
||||||
|
|
||||||
local pt
|
local pt = GPS.locate()
|
||||||
|
|
||||||
local function fly()
|
local function descend()
|
||||||
for i = 1, 100 do
|
print('descending to ' .. wp.y)
|
||||||
os.sleep(1)
|
repeat
|
||||||
if pt then
|
local meta = ni.getMetaByID(id)
|
||||||
print(pt.y)
|
if meta.motionY < 0 then
|
||||||
print(strength)
|
ni.launch(0, -90, math.min(4, meta.motionY / -0.5))
|
||||||
end
|
end
|
||||||
end
|
print(math.abs(wp.y - pt.y))
|
||||||
|
until math.abs(wp.y - pt.y) < 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local function gps()
|
local function gps()
|
||||||
local lastY = 12
|
|
||||||
while true do
|
while true do
|
||||||
pt = GPS.locate()
|
local lpt = GPS.locate()
|
||||||
if pt then
|
if lpt then
|
||||||
local d = math.abs(lastY - pt.y)
|
pt = lpt
|
||||||
|
|
||||||
-- force required to get to lvl 12
|
|
||||||
|
|
||||||
local motionY = ni.getMetaOwner().motionY
|
|
||||||
-- print('y: ' .. pt.y)
|
|
||||||
if pt.y < 12 then
|
|
||||||
if pt.y > lastY then
|
|
||||||
--strength = strength + .001
|
|
||||||
else
|
|
||||||
strength = strength + .02 * d
|
|
||||||
end
|
|
||||||
elseif pt.y > 12 then
|
|
||||||
if pt.y > lastY then
|
|
||||||
strength = strength - .02 * d
|
|
||||||
else
|
|
||||||
--strength = strength - .001
|
|
||||||
end
|
|
||||||
end
|
|
||||||
lastY = pt.y
|
|
||||||
|
|
||||||
-- force required to offset motion
|
|
||||||
local om = (motionY - 0.138) / 0.8
|
|
||||||
|
|
||||||
ni.launch(0, 270, strength-motionY)
|
|
||||||
-- print('strength: ' .. strength)
|
|
||||||
os.sleep(delay)
|
|
||||||
end
|
end
|
||||||
|
os.sleep(.1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parallel.waitForAny(fly, gps)
|
local function yap(x, y, z)
|
||||||
|
local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
|
||||||
|
local yaw = math.atan2(-(x - .5), z - .5)
|
||||||
|
|
||||||
repeat
|
return math.deg(yaw), math.deg(pitch)
|
||||||
ni.launch(0, 270, .25)
|
|
||||||
os.sleep(.1)
|
|
||||||
until not ni.getMetaOwner().isAirborne
|
|
||||||
|
|
||||||
print('descending')
|
|
||||||
for i = 1, 50 do
|
|
||||||
ni.launch(0, 270, .2)
|
|
||||||
os.sleep(.1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ni.look(180, 0)
|
local function distance(a, b)
|
||||||
|
return math.sqrt(
|
||||||
|
math.pow(a.x - b.x, 2) +
|
||||||
|
math.pow(a.z - b.z, 2))
|
||||||
|
end
|
||||||
|
|
||||||
|
local function hover()
|
||||||
|
repeat
|
||||||
|
local meta = ni.getMetaByID(id)
|
||||||
|
local pitch = 295
|
||||||
|
local yaw = yap(wp.x - pt.x, wp.y, wp.z - pt.z)
|
||||||
|
|
||||||
|
if pt.y < wp.y + 16 and meta.motionY < 0 then
|
||||||
|
ni.launch(yaw, pitch, math.min(4, math.min(4, -meta.motionY * math.abs(pt.y - (wp.y + 16)) / 2)))
|
||||||
|
end
|
||||||
|
|
||||||
|
until distance(wp, pt) < 2
|
||||||
|
end
|
||||||
|
|
||||||
|
local function launch()
|
||||||
|
ni.launch(0, 270, 3)
|
||||||
|
|
||||||
|
repeat
|
||||||
|
local meta = ni.getMetaByID(id)
|
||||||
|
until meta.motionY < 0
|
||||||
|
|
||||||
|
hover()
|
||||||
|
|
||||||
|
descend()
|
||||||
|
end
|
||||||
|
|
||||||
|
local s, m = pcall(parallel.waitForAny, launch, gps)
|
||||||
|
|
||||||
|
if not s then
|
||||||
|
_G.printError(m)
|
||||||
|
end
|
||||||
|
|
||||||
|
--s, m = pcall(parallel.waitForAny, descend, gps)
|
||||||
|
|
||||||
|
if not s then
|
||||||
|
error(m)
|
||||||
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user