mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Got now back a good version working with CARGO now as a separate object.
- Sling load working but dealing with the DCS bugs. - Normal CARGO pickup and deployment is working now, but needs to be further optimized...
This commit is contained in:
@@ -25,6 +25,91 @@ routines.build = 22
|
||||
-- Utils- conversion, Lua utils, etc.
|
||||
routines.utils = {}
|
||||
|
||||
--from http://lua-users.org/wiki/CopyTable
|
||||
routines.utils.deepCopy = function(object)
|
||||
local lookup_table = {}
|
||||
local function _copy(object)
|
||||
if type(object) ~= "table" then
|
||||
return object
|
||||
elseif lookup_table[object] then
|
||||
return lookup_table[object]
|
||||
end
|
||||
local new_table = {}
|
||||
lookup_table[object] = new_table
|
||||
for index, value in pairs(object) do
|
||||
new_table[_copy(index)] = _copy(value)
|
||||
end
|
||||
return setmetatable(new_table, getmetatable(object))
|
||||
end
|
||||
local objectreturn = _copy(object)
|
||||
return objectreturn
|
||||
end
|
||||
|
||||
|
||||
-- porting in Slmod's serialize_slmod2
|
||||
routines.utils.oneLineSerialize = function(tbl) -- serialization of a table all on a single line, no comments, made to replace old get_table_string function
|
||||
if type(tbl) == 'table' then --function only works for tables!
|
||||
|
||||
local tbl_str = {}
|
||||
|
||||
tbl_str[#tbl_str + 1] = '{'
|
||||
|
||||
for ind,val in pairs(tbl) do -- serialize its fields
|
||||
if type(ind) == "number" then
|
||||
tbl_str[#tbl_str + 1] = '['
|
||||
tbl_str[#tbl_str + 1] = tostring(ind)
|
||||
tbl_str[#tbl_str + 1] = ']='
|
||||
else --must be a string
|
||||
tbl_str[#tbl_str + 1] = '['
|
||||
tbl_str[#tbl_str + 1] = routines.utils.basicSerialize(ind)
|
||||
tbl_str[#tbl_str + 1] = ']='
|
||||
end
|
||||
|
||||
if ((type(val) == 'number') or (type(val) == 'boolean')) then
|
||||
tbl_str[#tbl_str + 1] = tostring(val)
|
||||
tbl_str[#tbl_str + 1] = ','
|
||||
elseif type(val) == 'string' then
|
||||
tbl_str[#tbl_str + 1] = routines.utils.basicSerialize(val)
|
||||
tbl_str[#tbl_str + 1] = ','
|
||||
elseif type(val) == 'nil' then -- won't ever happen, right?
|
||||
tbl_str[#tbl_str + 1] = 'nil,'
|
||||
elseif type(val) == 'table' then
|
||||
if ind == "__index" then
|
||||
tbl_str[#tbl_str + 1] = "__index"
|
||||
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
|
||||
else
|
||||
tbl_str[#tbl_str + 1] = routines.utils.oneLineSerialize(val)
|
||||
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
|
||||
end
|
||||
elseif type(val) == 'function' then
|
||||
tbl_str[#tbl_str + 1] = "function " .. tostring(ind)
|
||||
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
|
||||
else
|
||||
env.info('unable to serialize value type ' .. routines.utils.basicSerialize(type(val)) .. ' at index ' .. tostring(ind))
|
||||
env.info( debug.traceback() )
|
||||
end
|
||||
|
||||
end
|
||||
tbl_str[#tbl_str + 1] = '}'
|
||||
return table.concat(tbl_str)
|
||||
else
|
||||
return tostring(tbl)
|
||||
end
|
||||
end
|
||||
|
||||
--porting in Slmod's "safestring" basic serialize
|
||||
routines.utils.basicSerialize = function(s)
|
||||
if s == nil then
|
||||
return "\"\""
|
||||
else
|
||||
if ((type(s) == 'number') or (type(s) == 'boolean') or (type(s) == 'function') or (type(s) == 'table') or (type(s) == 'userdata') ) then
|
||||
return tostring(s)
|
||||
elseif type(s) == 'string' then
|
||||
s = string.format('%q', s)
|
||||
return s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
routines.utils.toDegree = function(angle)
|
||||
@@ -137,91 +222,6 @@ function routines.utils.get3DDist(point1, point2)
|
||||
end
|
||||
|
||||
|
||||
--from http://lua-users.org/wiki/CopyTable
|
||||
routines.utils.deepCopy = function(object)
|
||||
local lookup_table = {}
|
||||
local function _copy(object)
|
||||
if type(object) ~= "table" then
|
||||
return object
|
||||
elseif lookup_table[object] then
|
||||
return lookup_table[object]
|
||||
end
|
||||
local new_table = {}
|
||||
lookup_table[object] = new_table
|
||||
for index, value in pairs(object) do
|
||||
new_table[_copy(index)] = _copy(value)
|
||||
end
|
||||
return setmetatable(new_table, getmetatable(object))
|
||||
end
|
||||
local objectreturn = _copy(object)
|
||||
return objectreturn
|
||||
end
|
||||
|
||||
|
||||
-- porting in Slmod's serialize_slmod2
|
||||
routines.utils.oneLineSerialize = function(tbl) -- serialization of a table all on a single line, no comments, made to replace old get_table_string function
|
||||
if type(tbl) == 'table' then --function only works for tables!
|
||||
|
||||
local tbl_str = {}
|
||||
|
||||
tbl_str[#tbl_str + 1] = '{'
|
||||
|
||||
for ind,val in pairs(tbl) do -- serialize its fields
|
||||
if type(ind) == "number" then
|
||||
tbl_str[#tbl_str + 1] = '['
|
||||
tbl_str[#tbl_str + 1] = tostring(ind)
|
||||
tbl_str[#tbl_str + 1] = ']='
|
||||
else --must be a string
|
||||
tbl_str[#tbl_str + 1] = '['
|
||||
tbl_str[#tbl_str + 1] = routines.utils.basicSerialize(ind)
|
||||
tbl_str[#tbl_str + 1] = ']='
|
||||
end
|
||||
|
||||
if ((type(val) == 'number') or (type(val) == 'boolean')) then
|
||||
tbl_str[#tbl_str + 1] = tostring(val)
|
||||
tbl_str[#tbl_str + 1] = ','
|
||||
elseif type(val) == 'string' then
|
||||
tbl_str[#tbl_str + 1] = routines.utils.basicSerialize(val)
|
||||
tbl_str[#tbl_str + 1] = ','
|
||||
elseif type(val) == 'nil' then -- won't ever happen, right?
|
||||
tbl_str[#tbl_str + 1] = 'nil,'
|
||||
elseif type(val) == 'table' then
|
||||
if ind == "__index" then
|
||||
tbl_str[#tbl_str + 1] = "__index"
|
||||
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
|
||||
else
|
||||
tbl_str[#tbl_str + 1] = routines.utils.oneLineSerialize(val)
|
||||
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
|
||||
end
|
||||
elseif type(val) == 'function' then
|
||||
tbl_str[#tbl_str + 1] = "function " .. tostring(ind)
|
||||
tbl_str[#tbl_str + 1] = ',' --I think this is right, I just added it
|
||||
else
|
||||
env.info('unable to serialize value type ' .. routines.utils.basicSerialize(type(val)) .. ' at index ' .. tostring(ind))
|
||||
env.info( debug.traceback() )
|
||||
end
|
||||
|
||||
end
|
||||
tbl_str[#tbl_str + 1] = '}'
|
||||
return table.concat(tbl_str)
|
||||
else
|
||||
return tostring(tbl)
|
||||
end
|
||||
end
|
||||
|
||||
--porting in Slmod's "safestring" basic serialize
|
||||
routines.utils.basicSerialize = function(s)
|
||||
if s == nil then
|
||||
return "\"\""
|
||||
else
|
||||
if ((type(s) == 'number') or (type(s) == 'boolean') or (type(s) == 'function') or (type(s) == 'table') or (type(s) == 'userdata') ) then
|
||||
return tostring(s)
|
||||
elseif type(s) == 'string' then
|
||||
s = string.format('%q', s)
|
||||
return s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- From http://lua-users.org/wiki/SimpleRound
|
||||
-- use negative idp for rounding ahead of decimal place, positive for rounding after decimal place
|
||||
@@ -280,6 +280,9 @@ routines.vec.rotateVec2 = function(vec2, theta)
|
||||
end
|
||||
---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
-- acc- the accuracy of each easting/northing. 0, 1, 2, 3, 4, or 5.
|
||||
routines.tostringMGRS = function(MGRS, acc)
|
||||
if acc == 0 then
|
||||
@@ -1829,6 +1832,23 @@ routines.ground.patrol = function(gpData, pType, form, speed)
|
||||
return
|
||||
end
|
||||
|
||||
function routines.GetUnitHeight( CheckUnit )
|
||||
trace.f( "routines" )
|
||||
|
||||
local UnitPoint = CheckUnit:getPoint()
|
||||
local UnitPosition = { x = UnitPoint.x, y = UnitPoint.z }
|
||||
local UnitHeight = UnitPoint.y
|
||||
|
||||
local LandHeight = land.getHeight( UnitPosition )
|
||||
|
||||
--env.info(( 'CarrierHeight: LandHeight = ' .. LandHeight .. ' CarrierHeight = ' .. CarrierHeight ))
|
||||
|
||||
trace.f( "routines", "Unit Height = " .. UnitHeight - LandHeight )
|
||||
|
||||
return UnitHeight - LandHeight
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
Su34Status = { status = {} }
|
||||
@@ -2362,7 +2382,7 @@ trace.f()
|
||||
|
||||
--env.info(( 'CarrierHeight: LandHeight = ' .. LandHeight .. ' CarrierHeight = ' .. CarrierHeight ))
|
||||
|
||||
return CarrierHeight - LandHeight
|
||||
return UnitHeight - LandHeight
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user