spawning aircraft with AGL WP DB entry fix

Fixed a issue where altitude was not correctly saved for aircraft
altitude set to AGL

Added Mark panel stuff. Currently WIP.
Fixed typos in function names where Celsius was spelled wrong:
mist.utils.kelvinToCelsius
mist.utils.FahreneitToCelsius
mist.utils.celsiusToFahrenheit

mist logger now defined in mistSettings.logLevel for easy access.
This commit is contained in:
mrSkortch 2017-08-25 00:22:18 -06:00
parent 4f4b890339
commit acbdb0561b

256
mist.lua
View File

@ -35,7 +35,7 @@ mist = {}
-- don't change these -- don't change these
mist.majorVersion = 4 mist.majorVersion = 4
mist.minorVersion = 4 mist.minorVersion = 4
mist.build = 80 mist.build = 81
-- forward declaration of log shorthand -- forward declaration of log shorthand
local log local log
@ -44,6 +44,7 @@ local mistSettings = {
errorPopup = false, -- errors printed by mist logger will create popup warning you errorPopup = false, -- errors printed by mist logger will create popup warning you
warnPopup = false, warnPopup = false,
infoPopup = false, infoPopup = false,
logLevel = 'info',
} }
do -- the main scope do -- the main scope
@ -731,6 +732,9 @@ do -- the main scope
newTable.units[unitId].skill = "High" newTable.units[unitId].skill = "High"
newTable.units[unitId].alt_type = "BARO" newTable.units[unitId].alt_type = "BARO"
end end
if newTable.units[unitId].alt_type == "RADIO" then -- raw postition MSL was grabbed for group, but spawn is AGL, so re-offset it
newTable.units[unitId].alt = (newTable.units[unitId].alt - land.getHeight({x = newTable.units[unitId].x, y = newTable.units[unitId].y}))
end
end end
end end
@ -1130,13 +1134,13 @@ do -- the main scope
-- @function mist.init -- @function mist.init
function mist.init() function mist.init()
-- create logger -- create logger
mist.log = mist.Logger:new("MIST") mist.log = mist.Logger:new("MIST", mistSettings.logLevel)
dbLog = mist.Logger:new('MISTDB', 'warning') dbLog = mist.Logger:new('MISTDB', 'warning')
log = mist.log -- log shorthand log = mist.log -- log shorthand
-- set warning log level, showing only -- set warning log level, showing only
-- warnings and errors -- warnings and errors
log:setLevel("warning") --log:setLevel("warning")
log:info("initializing databases") log:info("initializing databases")
initDBs() initDBs()
@ -1469,6 +1473,12 @@ do -- the main scope
newGroup.route = {} newGroup.route = {}
newGroup.route.points = copyRoute newGroup.route.points = copyRoute
end end
else -- if aircraft and no route assigned. make a quick and stupid route so AI doesnt RTB immediately
if newCat == 'AIRPLANE' or newCat == 'HELICOPTER' then
newGroup.route = {}
newGroup.route.points = {}
newGroup.route.points[1] = {}
end
end end
newGroup.country = newCountry newGroup.country = newCountry
@ -2520,7 +2530,7 @@ function mist.getUnitsInPolygon(unit_names, polyZone, max_alt)
local units = {} local units = {}
for i = 1, #unit_names do for i = 1, #unit_names do
units[#units + 1] = Unit.getByName(unitNames[i]) units[#units + 1] = Unit.getByName(unit_names[i])
end end
local inZoneUnits = {} local inZoneUnits = {}
@ -3201,7 +3211,7 @@ do -- group functions scope
--log:info('get Randomized Point') --log:info('get Randomized Point')
local diff = {x = 0, y = 0} local diff = {x = 0, y = 0}
local newCoord, origCoord local newCoord, origCoord
if point then if point and radius > 0 then
local valid = false local valid = false
local validTerrain local validTerrain
@ -3252,8 +3262,11 @@ do -- group functions scope
if (newGroupData.category == 'plane' or newGroupData.category == 'helicopter') then if (newGroupData.category == 'plane' or newGroupData.category == 'helicopter') then
if point.z and point.y > 0 and point.y > land.getHeight({newGroupData.units[unitNum].x, newGroupData.units[unitNum].y}) + 10 then if point.z and point.y > 0 and point.y > land.getHeight({newGroupData.units[unitNum].x, newGroupData.units[unitNum].y}) + 10 then
newGroupData.units[unitNum].alt = point.y newGroupData.units[unitNum].alt = point.y
log:info('far enough from ground')
else else
if newGroupData.category == 'plane' then if newGroupData.category == 'plane' then
log:info('setNewAlt')
newGroupData.units[unitNum].alt = land.getHeight({newGroupData.units[unitNum].x, newGroupData.units[unitNum].y}) + math.random(300, 9000) newGroupData.units[unitNum].alt = land.getHeight({newGroupData.units[unitNum].x, newGroupData.units[unitNum].y}) + math.random(300, 9000)
else else
newGroupData.units[unitNum].alt = land.getHeight({newGroupData.units[unitNum].x, newGroupData.units[unitNum].y}) + math.random(200, 3000) newGroupData.units[unitNum].alt = land.getHeight({newGroupData.units[unitNum].x, newGroupData.units[unitNum].y}) + math.random(200, 3000)
@ -3280,6 +3293,7 @@ do -- group functions scope
if route then if route then
newGroupData.route = route newGroupData.route = route
end end
log:info(newGroupData)
--mist.debug.writeData(mist.utils.serialize,{'teleportToPoint', newGroupData}, 'newGroupData.lua') --mist.debug.writeData(mist.utils.serialize,{'teleportToPoint', newGroupData}, 'newGroupData.lua')
if string.lower(newGroupData.category) == 'static' then if string.lower(newGroupData.category) == 'static' then
--log:info(newGroupData) --log:info(newGroupData)
@ -3707,15 +3721,15 @@ do -- mist.util scope
return kmph/3.6 return kmph/3.6
end end
function mist.utils.kelvinToCelcius(t) function mist.utils.kelvinToCelsius(t)
return t - 273.15 return t - 273.15
end end
function mist.utils.FahrenheitToCelcius(f) function mist.utils.FahrenheitToCelsius(f)
return (f - 32) * (5/9) return (f - 32) * (5/9)
end end
function mist.utils.celciusToFahrenheit(c) function mist.utils.celsiusToFahrenheit(c)
return c*(9/5)+32 return c*(9/5)+32
end end
@ -3791,19 +3805,19 @@ do -- mist.util scope
-- Temperature -- Temperature
elseif t1 == 'f' or t1 == 'fahrenheit' then elseif t1 == 'f' or t1 == 'fahrenheit' then
if t2 == 'c' or t2 == 'celcius' then if t2 == 'c' or t2 == 'celsius' then
return (val - 32) * (5/9) return (val - 32) * (5/9)
elseif t2 == 'k' or t2 == 'kelvin' then elseif t2 == 'k' or t2 == 'kelvin' then
return (val + 459.67) * (5/9) return (val + 459.67) * (5/9)
end end
elseif t1 == 'c' or t1 == 'celcius' then elseif t1 == 'c' or t1 == 'celsius' then
if t2 == 'f' or t2 == 'fahrenheit' then if t2 == 'f' or t2 == 'fahrenheit' then
return val*(9/5)+32 return val*(9/5)+32
elseif t2 == 'k' or t2 == 'kelvin' then elseif t2 == 'k' or t2 == 'kelvin' then
return val + 273.15 return val + 273.15
end end
elseif t1 == 'k' or t1 == 'kelvin' then elseif t1 == 'k' or t1 == 'kelvin' then
if t2 == 'c' or t2 == 'celcius' then if t2 == 'c' or t2 == 'celsius' then
return val - 273.15 return val - 273.15
elseif t2 == 'f' or t2 == 'fahrenheit' then elseif t2 == 'f' or t2 == 'fahrenheit' then
return ((val*(9/5))-459.67) return ((val*(9/5))-459.67)
@ -4191,9 +4205,12 @@ function mist.utils.serialize(name, value, level)
local function serializeToTbl(name, value, level) local function serializeToTbl(name, value, level)
local var_str_tbl = {} local var_str_tbl = {}
if level == nil then level = "" end if level == nil then
if level ~= "" then level = level.." " end level = ""
end
if level ~= "" then
level = level..""
end
table.insert(var_str_tbl, level .. name .. " = ") table.insert(var_str_tbl, level .. name .. " = ")
if type(value) == "number" or type(value) == "string" or type(value) == "boolean" then if type(value) == "number" or type(value) == "string" or type(value) == "boolean" then
@ -4208,7 +4225,6 @@ function mist.utils.serialize(name, value, level)
else else
key = string.format("[%q]", k) key = string.format("[%q]", k)
end end
table.insert(var_str_tbl, mist.utils.serialize(key, v, level.." ")) table.insert(var_str_tbl, mist.utils.serialize(key, v, level.." "))
end end
@ -5902,7 +5918,213 @@ do -- mist.demos scope
end end
end end
do
--[[ stuff for marker panels
marker.add() add marker. Point of these functions is to simplify process and to store all mark panels added.
-- generates Id if not specified or if multiple marks created.
-- makes marks for countries by creating a mark for each client group in the country
-- can create multiple marks if needed for groups and countries.
-- adds marks to table for parsing and removing
-- Uses similar structure as messages. Big differences is it doesn't only mark to groups.
If to All, then mark is for All
if to coa mark is to coa
if to specific units, mark is to group
--------
STUFF TO Check
--------
If mark added to a group before a client joins slot is synced.
Mark made for cliet A in Slot A. Client A leaves, Client B joins in slot A. What do they see?
May need to automate process...
]]
local typeBase = {
['Mi-8MT'] = {'Mi-8MTV2', 'Mi-8MTV', 'Mi-8'},
['MiG-21Bis'] = {'Mig-21'},
['MiG-15bis'] = {'Mig-15'},
['FW-190D9'] = {'FW-190'},
['Bf-109K-4'] = {'Bf-109'},
}
local mId = 1337
mist.marker = {}
mist.marker.list = {}
local function markSpamFilter(recList, spamBlockOn)
for id, name in pairs(recList) do
if name == spamBlockOn then
log:info('already on recList')
return recList
end
end
log:info('add to recList')
table.insert(recList, spamBlockOn)
return recList
end
local function iterate()
mId = mId + 1
return mId
end
function mist.marker.add(pos, text, markFor, id)
log:warn('markerFunc')
log:info('Pos: $1, Text: $2, markFor: $3, id: $4', pos, text, markFor, id)
if not id then
else
end
local markType = 'all'
local markForTable = {}
if pos then
pos = mist.utils.makeVec3(pos)
end
if text and type(text) ~= string then
text = tostring(text)
else
text = ''
end
if markFor then
if type(markFor) == 'number' then -- groupId
if mist.DBs.groupsById[markFor] then
markType = 'group'
end
elseif type(markFor) == 'string' then -- groupName
if mist.DBs.groupsByName[markFor] then
markType = 'group'
markFor = mist.DBs.groupsByName[markFor].groupId
end
elseif type(markFor) == 'table' then -- multiple groupName, country, coalition, all
markType = 'table'
log:info(markFor)
for forIndex, forData in pairs(markFor) do -- need to rethink this part and organization. Gotta be a more logical way to send messages to coa, groups, or all.
log:info(forIndex)
log:info(forData)
for list, listData in pairs(forData) do
log:info(listData)
forIndex = string.lower(forIndex)
if type(listData) == 'string' then
listData = string.lower(listData)
end
if listData == 'all' then
markType = 'all'
break
elseif (forIndex == 'coa' or forIndex == 'ca') then -- mark for coa or CA.
for name, index in pairs (coalition.side) do
if listData == string.lower(name) then
markType = 'coalition'
end
end
elseif (forIndex == 'countries' and string.lower(clientData.country) == listData) or (forIndex == 'units' and string.lower(clientData.unitName) == listData) then
markForTable = markSpamFilter(markForTable, clientData.groupId)
elseif forIndex == 'unittypes' then -- mark to group
-- iterate play units
for clientId, clientData in pairs(mist.DBs.humansById) do
for typeId, typeData in pairs(listData) do
log:info(typeData)
local found = false
if list == 'all' or clientData.coalition and type(clientData.coalition) == 'string' and mist.stringMatch(clientData.coalition, list) then
if mist.matchString(typeData, clientData.type) then
found = true
else
-- check other known names for aircraft
end
end
if found == true then
markForTable = markSpamFilter(markForTable, clientData.groupId) -- sends info to other function to see if client is already recieving the current message.
end
--[[for clientDataEntry, clientDataVal in pairs(clientData) do
if type(clientDataVal) == 'string' then
if mist.matchString(list, clientDataVal) == true or list == 'all' then
local sString = typeData
for rName, pTbl in pairs(typeBase) do -- just a quick check to see if the user may have meant something and got the specific type of the unit wrong
for pIndex, pName in pairs(pTbl) do
if mist.stringMatch(sString, pName) then
sString = rName
end
end
end
if mist.stringMatch(sString, clientData.type) then
found = true
markForTable = markSpamFilter(markForTable, clientData.groupId) -- sends info oto other function to see if client is already recieving the current message.
--table.insert(newMsgFor, clientId)
end
end
end
if found == true then -- shouldn't this be elsewhere too?
break
end
end]]
end
end
end
end
end
end
else
markType = 'all'
end
if markType ~= 'table' then
local newId = iterate()
local data = {markId = newId, text = text, pos = pos, markType = markType, markFor = markFor}
-- create marks
if markType == 'coa' then
trigger.action.markToCoalition(newId, text, pos, markFor)
elseif markType == 'group' then
trigger.action.markToGroup(newId, text, pos, markFor)
else
trigger.action.markToAll(iterate(), text, pos)
end
table.insert(mist.marker.list, data) -- add to the DB
else
if #markForTable > 0 then
log:info('iterate')
for i = 1, #markForTable do
local newId = iterate()
local data = {markId = newId, text = text, pos = pos, markFor = markFor}
log:info(data)
table.insert(mist.marker.list, data)
trigger.action.markToGroup(newId, text, pos, markForTable[i])
end
end
end
end
function mist.marker.remove(id)
for i, data in pairs(mist.marker.list) do
if id == data.markId then
trigger.action.removeMark(id)
end
end
end
function mist.marker.get(id)
end
function mist.marker.coords(pos, cType, markFor, id) -- wrapper function to just display coordinates of a specific format at location
end
end
--- Time conversion functions. --- Time conversion functions.
-- @section mist.time -- @section mist.time
do -- mist.time scope do -- mist.time scope
@ -6796,7 +7018,6 @@ end
-- @tfield[opt] boolean toggle switch the flag to false if required -- @tfield[opt] boolean toggle switch the flag to false if required
-- conditions are not met. Default: false. -- conditions are not met. Default: false.
-- @tfield[opt] table unitTableDef -- @tfield[opt] table unitTableDef
--- Logger class. --- Logger class.
-- @type mist.Logger -- @type mist.Logger
do -- mist.Logger scope do -- mist.Logger scope
@ -6878,7 +7099,7 @@ do -- mist.Logger scope
--- Sets the level of verbosity for this logger. --- Sets the level of verbosity for this logger.
-- @tparam[opt] number|string level the log level defines which messages -- @tparam[opt] number|string level the log level defines which messages
-- will be logged and which will be omitted. Log level 3 beeing the most verbose -- will be logged and which will be omitted. Log level 3 beeing the most verbose
-- and 0 disabling all output. This can also be a string. Allowed strings are: -- and 0 disabling all output. This can also[ be a string. Allowed strings are:
-- "none" (0), "error" (1), "warning" (2) and "info" (3). -- "none" (0), "error" (1), "warning" (2) and "info" (3).
-- @usage myLogger:setLevel("info") -- @usage myLogger:setLevel("info")
-- @usage -- log everything -- @usage -- log everything
@ -7023,6 +7244,7 @@ do -- mist.Logger scope
end end
-- initialize mist -- initialize mist
mist.init() mist.init()
env.info(('Mist version ' .. mist.majorVersion .. '.' .. mist.minorVersion .. '.' .. mist.build .. ' loaded.')) env.info(('Mist version ' .. mist.majorVersion .. '.' .. mist.minorVersion .. '.' .. mist.build .. ' loaded.'))