mirror of
https://github.com/mrSkortch/MissionScriptingTools.git
synced 2025-08-15 10:47:23 +00:00
v115
CHANGED: default unitId and groupId values to start at 70000 instead of 7000 ADDED: linkUnit to database entries ADDED: linkOffset to database entries ADDED: mist.DBs.const.nato table for phonetic conversion of letters CHANGED: mist.getUnitPlayload to return an empty table if nothing found CHANGE: mist.getGroupPayload to return an empty table if nothing found FIXED: mist.getLeadPos to check if leader object is accessible and will iterate whole table to find the first one that is accessible FIXED: mist.groupIsDead to only call Group.getByName once FIXED: mist.Logger:setLevel to default to warning level. FIXED: mist.Logger:setLevel to use string.lower in case where one forgets that the formatting.
This commit is contained in:
parent
2c54802861
commit
0c37aaaa09
110
mist.lua
110
mist.lua
@ -35,7 +35,7 @@ mist = {}
|
|||||||
-- don't change these
|
-- don't change these
|
||||||
mist.majorVersion = 4
|
mist.majorVersion = 4
|
||||||
mist.minorVersion = 5
|
mist.minorVersion = 5
|
||||||
mist.build = 113
|
mist.build = 115
|
||||||
|
|
||||||
-- forward declaration of log shorthand
|
-- forward declaration of log shorthand
|
||||||
local log
|
local log
|
||||||
@ -64,8 +64,8 @@ do -- the main scope
|
|||||||
local updateAliveUnitsCounter = 0
|
local updateAliveUnitsCounter = 0
|
||||||
local updateTenthSecond = 0
|
local updateTenthSecond = 0
|
||||||
|
|
||||||
local mistGpId = 7000
|
local mistGpId = 70000
|
||||||
local mistUnitId = 7000
|
local mistUnitId = 70000
|
||||||
local mistDynAddIndex = {[' air '] = 0, [' hel '] = 0, [' gnd '] = 0, [' bld '] = 0, [' static '] = 0, [' shp '] = 0}
|
local mistDynAddIndex = {[' air '] = 0, [' hel '] = 0, [' gnd '] = 0, [' bld '] = 0, [' static '] = 0, [' shp '] = 0}
|
||||||
|
|
||||||
local scheduledTasks = {}
|
local scheduledTasks = {}
|
||||||
@ -339,7 +339,7 @@ do -- the main scope
|
|||||||
|
|
||||||
units_tbl[unit_num].groupName = groupName
|
units_tbl[unit_num].groupName = groupName
|
||||||
units_tbl[unit_num].groupId = group_data.groupId
|
units_tbl[unit_num].groupId = group_data.groupId
|
||||||
|
units_tbl[unit_num].linkUnit = unit_data.linkUnit
|
||||||
if unit_data.AddPropAircraft then
|
if unit_data.AddPropAircraft then
|
||||||
units_tbl[unit_num].AddPropAircraft = unit_data.AddPropAircraft
|
units_tbl[unit_num].AddPropAircraft = unit_data.AddPropAircraft
|
||||||
end
|
end
|
||||||
@ -347,7 +347,13 @@ do -- the main scope
|
|||||||
if category == 'static' then
|
if category == 'static' then
|
||||||
units_tbl[unit_num].categoryStatic = unit_data.category
|
units_tbl[unit_num].categoryStatic = unit_data.category
|
||||||
units_tbl[unit_num].shape_name = unit_data.shape_name
|
units_tbl[unit_num].shape_name = unit_data.shape_name
|
||||||
units_tbl[unit_num].linkUnit = unit_data.linkUnit
|
if group_data.linkOffset then
|
||||||
|
if group_data.route and group_data.route.points and group_data.route.points[1] and group_data.route.points[1].linkUnit then
|
||||||
|
units_tbl[unit_num].linkUnit = group_data.route.points[1].linkUnit
|
||||||
|
end
|
||||||
|
units_tbl[unit_num].offset = unit_data.offsets
|
||||||
|
end
|
||||||
|
|
||||||
if unit_data.mass then
|
if unit_data.mass then
|
||||||
units_tbl[unit_num].mass = unit_data.mass
|
units_tbl[unit_num].mass = unit_data.mass
|
||||||
end
|
end
|
||||||
@ -395,6 +401,36 @@ do -- the main scope
|
|||||||
|
|
||||||
mist.DBs.const = {}
|
mist.DBs.const = {}
|
||||||
|
|
||||||
|
mist.DBs.const.nato = {
|
||||||
|
a = "alpha",
|
||||||
|
b = "bravo",
|
||||||
|
c = "charlie",
|
||||||
|
d = "delta",
|
||||||
|
e = "echo",
|
||||||
|
f = "foxtrot",
|
||||||
|
g = "golf",
|
||||||
|
h = "hotel",
|
||||||
|
i = "india",
|
||||||
|
j = "juliett",
|
||||||
|
k = "kilo",
|
||||||
|
l = "lima",
|
||||||
|
m = "mike",
|
||||||
|
n = "november",
|
||||||
|
o = "oscar",
|
||||||
|
p = "papa",
|
||||||
|
q = "quebec",
|
||||||
|
r = "romeo",
|
||||||
|
s = "sierra",
|
||||||
|
t = "tango",
|
||||||
|
u = "uniform",
|
||||||
|
v = "victor",
|
||||||
|
w = "whiskey",
|
||||||
|
x = "xray",
|
||||||
|
y = "yankee",
|
||||||
|
z = "zulu",
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
-- not accessible by SSE, must use static list :-/
|
-- not accessible by SSE, must use static list :-/
|
||||||
mist.DBs.const.callsigns = {
|
mist.DBs.const.callsigns = {
|
||||||
['NATO'] = {
|
['NATO'] = {
|
||||||
@ -1153,10 +1189,10 @@ do -- the main scope
|
|||||||
savesPerRun = 5
|
savesPerRun = 5
|
||||||
end
|
end
|
||||||
if i > 0 then
|
if i > 0 then
|
||||||
--dbLog:info('updateDBTables')
|
-- dbLog:info('updateDBTables')
|
||||||
local ldeepCopy = mist.utils.deepCopy
|
local ldeepCopy = mist.utils.deepCopy
|
||||||
for x = 1, i do
|
for x = 1, i do
|
||||||
--dbLog:info(writeGroups[x])
|
-- dbLog:info(writeGroups[x])
|
||||||
local newTable = writeGroups[x].data
|
local newTable = writeGroups[x].data
|
||||||
local updated = writeGroups[x].isUpdated
|
local updated = writeGroups[x].isUpdated
|
||||||
local mistCategory
|
local mistCategory
|
||||||
@ -1295,8 +1331,9 @@ do -- the main scope
|
|||||||
local function doScheduledFunctions()
|
local function doScheduledFunctions()
|
||||||
local i = 1
|
local i = 1
|
||||||
while i <= #scheduledTasks do
|
while i <= #scheduledTasks do
|
||||||
|
local refTime = timer.getTime()
|
||||||
if not scheduledTasks[i].rep then -- not a repeated process
|
if not scheduledTasks[i].rep then -- not a repeated process
|
||||||
if scheduledTasks[i].t <= timer.getTime() then
|
if scheduledTasks[i].t <= refTime then
|
||||||
local task = scheduledTasks[i] -- local reference
|
local task = scheduledTasks[i] -- local reference
|
||||||
table.remove(scheduledTasks, i)
|
table.remove(scheduledTasks, i)
|
||||||
local err, errmsg = pcall(task.f, unpack(task.vars, 1, table.maxn(task.vars)))
|
local err, errmsg = pcall(task.f, unpack(task.vars, 1, table.maxn(task.vars)))
|
||||||
@ -1308,9 +1345,9 @@ do -- the main scope
|
|||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if scheduledTasks[i].st and scheduledTasks[i].st <= timer.getTime() then --if a stoptime was specified, and the stop time exceeded
|
if scheduledTasks[i].st and scheduledTasks[i].st <= refTime then --if a stoptime was specified, and the stop time exceeded
|
||||||
table.remove(scheduledTasks, i) -- stop time exceeded, do not execute, do not increment i
|
table.remove(scheduledTasks, i) -- stop time exceeded, do not execute, do not increment i
|
||||||
elseif scheduledTasks[i].t <= timer.getTime() then
|
elseif scheduledTasks[i].t <= refTime then
|
||||||
local task = scheduledTasks[i] -- local reference
|
local task = scheduledTasks[i] -- local reference
|
||||||
task.t = timer.getTime() + task.rep --schedule next run
|
task.t = timer.getTime() + task.rep --schedule next run
|
||||||
local err, errmsg = pcall(task.f, unpack(task.vars, 1, table.maxn(task.vars)))
|
local err, errmsg = pcall(task.f, unpack(task.vars, 1, table.maxn(task.vars)))
|
||||||
@ -3962,8 +3999,15 @@ do -- group functions scope
|
|||||||
unitId = mist.DBs.MEunitsByName[unitIdent].unitId
|
unitId = mist.DBs.MEunitsByName[unitIdent].unitId
|
||||||
else
|
else
|
||||||
log:error("Unit not found in mist.DBs.MEunitsByName: $1", unitIdent)
|
log:error("Unit not found in mist.DBs.MEunitsByName: $1", unitIdent)
|
||||||
|
return {}
|
||||||
end
|
end
|
||||||
|
elseif type(unitIdent) == "number" and not mist.DBs.MEunitsById[unitIdent] then
|
||||||
|
log:error("Unit not found in mist.DBs.MEunitsBId: $1", unitIdent)
|
||||||
|
return {}
|
||||||
end
|
end
|
||||||
|
local ref = mist.DBs.MEunitsById[unitId]
|
||||||
|
|
||||||
|
if ref then
|
||||||
local gpId = mist.DBs.MEunitsById[unitId].groupId
|
local gpId = mist.DBs.MEunitsById[unitId].groupId
|
||||||
|
|
||||||
if gpId and unitId then
|
if gpId and unitId then
|
||||||
@ -3990,12 +4034,13 @@ do -- group functions scope
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
log:error('Need string or number. Got: $1', type(unitIdent))
|
log:error('Need string or number. Got: $1', type(unitIdent))
|
||||||
return false
|
return {}
|
||||||
end
|
end
|
||||||
log:warn("Couldn't find payload for unit: $1", unitIdent)
|
log:warn("Couldn't find payload for unit: $1", unitIdent)
|
||||||
return
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function mist.getGroupPayload(groupIdent)
|
function mist.getGroupPayload(groupIdent)
|
||||||
@ -4005,6 +4050,7 @@ do -- group functions scope
|
|||||||
gpId = mist.DBs.MEgroupsByName[groupIdent].groupId
|
gpId = mist.DBs.MEgroupsByName[groupIdent].groupId
|
||||||
else
|
else
|
||||||
log:error('$1 not found in mist.DBs.MEgroupsByName', groupIdent)
|
log:error('$1 not found in mist.DBs.MEgroupsByName', groupIdent)
|
||||||
|
return {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -4034,10 +4080,10 @@ do -- group functions scope
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
log:error('Need string or number. Got: $1', type(groupIdent))
|
log:error('Need string or number. Got: $1', type(groupIdent))
|
||||||
return false
|
return {}
|
||||||
end
|
end
|
||||||
log:warn("Couldn't find payload for group: $1", groupIdent)
|
log:warn("Couldn't find payload for group: $1", groupIdent)
|
||||||
return
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function mist.getGroupTable(groupIdent)
|
function mist.getGroupTable(groupIdent)
|
||||||
@ -8855,30 +8901,36 @@ do -- group tasks scope
|
|||||||
end
|
end
|
||||||
|
|
||||||
function mist.getLeadPos(group)
|
function mist.getLeadPos(group)
|
||||||
|
local gObj
|
||||||
if type(group) == 'string' then -- group name
|
if type(group) == 'string' then -- group name
|
||||||
group = Group.getByName(group)
|
gObj = Group.getByName(group)
|
||||||
|
elseif type(group) == "table" then
|
||||||
|
gObj = group
|
||||||
end
|
end
|
||||||
|
|
||||||
local units = group:getUnits()
|
if gObj then
|
||||||
|
local units = gObj:getUnits()
|
||||||
|
|
||||||
local leader = units[1]
|
local leader = units[1]
|
||||||
if Unit.getLife(leader) == 0 or not Unit.isExist(leader) then -- SHOULD be good, but if there is a bug, this code future-proofs it then.
|
if leader then
|
||||||
local lowestInd = math.huge
|
if Unit.isExist(leader) then
|
||||||
for ind, unit in pairs(units) do
|
return leader:getPoint()
|
||||||
if Unit.isExist(unit) and ind < lowestInd then
|
elseif #units > 1 then
|
||||||
lowestInd = ind
|
for i = 2, #units do
|
||||||
return unit:getPosition().p
|
if Unit.isExist(units[i]) then
|
||||||
|
return units[i]:getPoint()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if leader and Unit.isExist(leader) then -- maybe a little too paranoid now...
|
log:error("Group passed to mist.getLeadPos might be dead: $1", group)
|
||||||
return leader:getPosition().p
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function mist.groupIsDead(groupName) -- copy more or less from on station
|
function mist.groupIsDead(groupName) -- copy more or less from on station
|
||||||
if Group.getByName(groupName) then
|
|
||||||
local gp = Group.getByName(groupName)
|
local gp = Group.getByName(groupName)
|
||||||
|
if gp then
|
||||||
if #gp:getUnits() > 0 or gp:isExist() == true then
|
if #gp:getUnits() > 0 or gp:isExist() == true then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -9016,10 +9068,10 @@ do -- mist.Logger scope
|
|||||||
-- @usage -- log everything
|
-- @usage -- log everything
|
||||||
--myLogger:setLevel(3)
|
--myLogger:setLevel(3)
|
||||||
function mist.Logger:setLevel(level)
|
function mist.Logger:setLevel(level)
|
||||||
if not level then
|
|
||||||
self.level = 2
|
self.level = 2
|
||||||
else
|
if level then
|
||||||
if type(level) == 'string' then
|
if type(level) == 'string' then
|
||||||
|
level = string.lower(level)
|
||||||
if level == 'none' or level == 'off' then
|
if level == 'none' or level == 'off' then
|
||||||
self.level = 0
|
self.level = 0
|
||||||
elseif level == 'error' then
|
elseif level == 'error' then
|
||||||
@ -9031,8 +9083,6 @@ do -- mist.Logger scope
|
|||||||
end
|
end
|
||||||
elseif type(level) == 'number' then
|
elseif type(level) == 'number' then
|
||||||
self.level = level
|
self.level = level
|
||||||
else
|
|
||||||
self.level = 2
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
9187
mist_4_5_113.lua
9187
mist_4_5_113.lua
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user