mirror of
https://github.com/mrSkortch/MissionScriptingTools.git
synced 2025-08-15 10:47:23 +00:00
spawnsByBase and other fixes
ADDED: mist.DBs.spawnsByBase table that lists each airbase or unit that has an aircraft set to spawn on it. MODIFIED: DB to contain the starting helipadId or airdromeId for each unit MODIFIED: mist.getCurrentGroupData to use an empty table so it doesn't error if nothing is found MODIFIED: mist.getCurrentGroupData to only call getPosition once. MODIFIED: mist.getGroupTable to add country and category values to the table returned so it can be directly used in mist.dynAdd without having to dd those vlaue sback.
This commit is contained in:
parent
2e6f77452c
commit
ab55753487
76
mist.lua
76
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 = 118
|
mist.build = 119
|
||||||
|
|
||||||
-- forward declaration of log shorthand
|
-- forward declaration of log shorthand
|
||||||
local log
|
local log
|
||||||
@ -227,6 +227,16 @@ do -- the main scope
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local abRef = {units = {}, airbase = {}}
|
||||||
|
for ind, val in pairs(world.getAirbases()) do
|
||||||
|
local cat = "airbase"
|
||||||
|
if Airbase.getDesc(val).category > 0 then
|
||||||
|
cat = "units"
|
||||||
|
end
|
||||||
|
abRef[cat][tonumber(val:getID())] = {name = val:getName()}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
mist.DBs.navPoints = {}
|
mist.DBs.navPoints = {}
|
||||||
mist.DBs.units = {}
|
mist.DBs.units = {}
|
||||||
@ -286,7 +296,18 @@ do -- the main scope
|
|||||||
mist.DBs.units[coa_name][countryName][category] = {}
|
mist.DBs.units[coa_name][countryName][category] = {}
|
||||||
|
|
||||||
for group_num, group_data in pairs(obj_cat_data.group) do
|
for group_num, group_data in pairs(obj_cat_data.group) do
|
||||||
|
local helipadId
|
||||||
|
local airdromeId
|
||||||
|
|
||||||
|
if group_data.route and group_data.route.points and group_data.route.points[1] then
|
||||||
|
if group_data.route.points[1].airdromeId then
|
||||||
|
airdromeId = group_data.route.points[1].airdromeId
|
||||||
|
--table.insert(abRef.airbase[group_data.route.points[1].airdromeId], group_data.groupId)
|
||||||
|
elseif group_data.route.points[1].helipadId then
|
||||||
|
helipadId = group_data.route.points[1].helipadId
|
||||||
|
--table.insert(abRef.units[group_data.route.points[1].helipadId], group_data.groupId)
|
||||||
|
end
|
||||||
|
end
|
||||||
if group_data and group_data.units and type(group_data.units) == 'table' then --making sure again- this is a valid group
|
if group_data and group_data.units and type(group_data.units) == 'table' then --making sure again- this is a valid group
|
||||||
|
|
||||||
mist.DBs.units[coa_name][countryName][category][group_num] = {}
|
mist.DBs.units[coa_name][countryName][category][group_num] = {}
|
||||||
@ -351,6 +372,12 @@ do -- the main scope
|
|||||||
units_tbl[unit_num].hardpoint_racks = unit_data.hardpoint_racks
|
units_tbl[unit_num].hardpoint_racks = unit_data.hardpoint_racks
|
||||||
units_tbl[unit_num].psi = unit_data.psi
|
units_tbl[unit_num].psi = unit_data.psi
|
||||||
|
|
||||||
|
if helipadId then
|
||||||
|
units_tbl[unit_num].helipadId = mist.utils.deepCopy(helipadId)
|
||||||
|
end
|
||||||
|
if airdromeId then
|
||||||
|
units_tbl[unit_num].airdromeId = mist.utils.deepCopy(airdromeId)
|
||||||
|
end
|
||||||
|
|
||||||
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
|
||||||
@ -752,6 +779,10 @@ do -- the main scope
|
|||||||
-- end
|
-- end
|
||||||
|
|
||||||
--Build DBs
|
--Build DBs
|
||||||
|
|
||||||
|
--dbLog:echo(abRef)
|
||||||
|
mist.DBs.spawnsByBase = {}
|
||||||
|
|
||||||
for coa_name, coa_data in pairs(mist.DBs.units) do
|
for coa_name, coa_data in pairs(mist.DBs.units) do
|
||||||
for cntry_name, cntry_data in pairs(coa_data) do
|
for cntry_name, cntry_data in pairs(coa_data) do
|
||||||
for category_name, category_data in pairs(cntry_data) do
|
for category_name, category_data in pairs(cntry_data) do
|
||||||
@ -781,6 +812,21 @@ do -- the main scope
|
|||||||
-- mist.DBs.activeHumans[unit_data.unitName].playerName = Unit.getByName(unit_data.unitName):getPlayerName()
|
-- mist.DBs.activeHumans[unit_data.unitName].playerName = Unit.getByName(unit_data.unitName):getPlayerName()
|
||||||
--end
|
--end
|
||||||
end
|
end
|
||||||
|
if unit_data.airdromeId then
|
||||||
|
--log:echo(unit_data.airdromeId)
|
||||||
|
--log:echo(abRef.airbase[unit_data.airdromeId])
|
||||||
|
if not mist.DBs.spawnsByBase[abRef.airbase[unit_data.airdromeId].name] then
|
||||||
|
mist.DBs.spawnsByBase[abRef.airbase[unit_data.airdromeId].name] = {}
|
||||||
|
end
|
||||||
|
table.insert(mist.DBs.spawnsByBase[abRef.airbase[unit_data.airdromeId].name], unit_data.unitName)
|
||||||
|
end
|
||||||
|
if unit_data.helipadId then
|
||||||
|
if not mist.DBs.spawnsByBase[abRef.units[unit_data.helipadId].name] then
|
||||||
|
mist.DBs.spawnsByBase[abRef.units[unit_data.helipadId].name] = {}
|
||||||
|
end
|
||||||
|
table.insert(mist.DBs.spawnsByBase[abRef.units[unit_data.helipadId].name], unit_data.unitName)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -3953,7 +3999,7 @@ do -- group functions scope
|
|||||||
|
|
||||||
--- Returns group data table of give group.
|
--- Returns group data table of give group.
|
||||||
function mist.getCurrentGroupData(gpName)
|
function mist.getCurrentGroupData(gpName)
|
||||||
local dbData = mist.getGroupData(gpName)
|
local dbData = mist.getGroupData(gpName) or {}
|
||||||
|
|
||||||
if Group.getByName(gpName) and Group.getByName(gpName):isExist() == true then
|
if Group.getByName(gpName) and Group.getByName(gpName):isExist() == true then
|
||||||
local newGroup = Group.getByName(gpName)
|
local newGroup = Group.getByName(gpName)
|
||||||
@ -3989,23 +4035,24 @@ do -- group functions scope
|
|||||||
newData.units[unitNum].callsign = unitData:getCallsign()
|
newData.units[unitNum].callsign = unitData:getCallsign()
|
||||||
newData.units[unitNum].unitName = uName
|
newData.units[unitNum].unitName = uName
|
||||||
end
|
end
|
||||||
|
local pos = unitData:getPosition()
|
||||||
newData.units[unitNum].x = unitData:getPosition().p.x
|
newData.units[unitNum].x = pos.p.x
|
||||||
newData.units[unitNum].y = unitData:getPosition().p.z
|
newData.units[unitNum].y = pos.p.z
|
||||||
newData.units[unitNum].point = {x = newData.units[unitNum].x, y = newData.units[unitNum].y}
|
newData.units[unitNum].point = {x = newData.units[unitNum].x, y = newData.units[unitNum].y}
|
||||||
newData.units[unitNum].heading = mist.getHeading(unitData, true) -- added to DBs
|
newData.units[unitNum].heading = math.atan2(pos.x.z, pos.x.x)
|
||||||
newData.units[unitNum].alt = unitData:getPosition().p.y
|
newData.units[unitNum].alt = pos.p.y
|
||||||
newData.units[unitNum].speed = mist.vec.mag(unitData:getVelocity())
|
newData.units[unitNum].speed = mist.vec.mag(unitData:getVelocity())
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return newData
|
return newData
|
||||||
elseif StaticObject.getByName(gpName) and StaticObject.getByName(gpName):isExist() == true then
|
elseif StaticObject.getByName(gpName) and StaticObject.getByName(gpName):isExist() == true and dbData.units then
|
||||||
local staticObj = StaticObject.getByName(gpName)
|
local staticObj = StaticObject.getByName(gpName)
|
||||||
dbData.units[1].x = staticObj:getPosition().p.x
|
local pos =staticObj:getPosition()
|
||||||
dbData.units[1].y = staticObj:getPosition().p.z
|
dbData.units[1].x = pos.p.x
|
||||||
dbData.units[1].alt = staticObj:getPosition().p.y
|
dbData.units[1].y = pos.p.z
|
||||||
dbData.units[1].heading = mist.getHeading(staticObj, true)
|
dbData.units[1].alt = pos.p.y
|
||||||
|
dbData.units[1].heading = math.atan2(pos.x.z, pos.x.x)
|
||||||
|
|
||||||
return dbData
|
return dbData
|
||||||
end
|
end
|
||||||
@ -4199,7 +4246,10 @@ do -- group functions scope
|
|||||||
if ((type(obj_cat_data) == 'table') and obj_cat_data.group and (type(obj_cat_data.group) == 'table') and (#obj_cat_data.group > 0)) then --there's a group!
|
if ((type(obj_cat_data) == 'table') and obj_cat_data.group and (type(obj_cat_data.group) == 'table') and (#obj_cat_data.group > 0)) then --there's a group!
|
||||||
for group_num, group_data in pairs(obj_cat_data.group) do
|
for group_num, group_data in pairs(obj_cat_data.group) do
|
||||||
if group_data and group_data.groupId == gpId then
|
if group_data and group_data.groupId == gpId then
|
||||||
return group_data
|
local gp = mist.utils.deepCopy(group_data)
|
||||||
|
gp.category = obj_cat_name
|
||||||
|
gp.country = cntry_data.id
|
||||||
|
return gp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -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 = 118
|
mist.build = 119
|
||||||
|
|
||||||
-- forward declaration of log shorthand
|
-- forward declaration of log shorthand
|
||||||
local log
|
local log
|
||||||
@ -227,6 +227,16 @@ do -- the main scope
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local abRef = {units = {}, airbase = {}}
|
||||||
|
for ind, val in pairs(world.getAirbases()) do
|
||||||
|
local cat = "airbase"
|
||||||
|
if Airbase.getDesc(val).category > 0 then
|
||||||
|
cat = "units"
|
||||||
|
end
|
||||||
|
abRef[cat][tonumber(val:getID())] = {name = val:getName()}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
mist.DBs.navPoints = {}
|
mist.DBs.navPoints = {}
|
||||||
mist.DBs.units = {}
|
mist.DBs.units = {}
|
||||||
@ -286,7 +296,18 @@ do -- the main scope
|
|||||||
mist.DBs.units[coa_name][countryName][category] = {}
|
mist.DBs.units[coa_name][countryName][category] = {}
|
||||||
|
|
||||||
for group_num, group_data in pairs(obj_cat_data.group) do
|
for group_num, group_data in pairs(obj_cat_data.group) do
|
||||||
|
local helipadId
|
||||||
|
local airdromeId
|
||||||
|
|
||||||
|
if group_data.route and group_data.route.points and group_data.route.points[1] then
|
||||||
|
if group_data.route.points[1].airdromeId then
|
||||||
|
airdromeId = group_data.route.points[1].airdromeId
|
||||||
|
--table.insert(abRef.airbase[group_data.route.points[1].airdromeId], group_data.groupId)
|
||||||
|
elseif group_data.route.points[1].helipadId then
|
||||||
|
helipadId = group_data.route.points[1].helipadId
|
||||||
|
--table.insert(abRef.units[group_data.route.points[1].helipadId], group_data.groupId)
|
||||||
|
end
|
||||||
|
end
|
||||||
if group_data and group_data.units and type(group_data.units) == 'table' then --making sure again- this is a valid group
|
if group_data and group_data.units and type(group_data.units) == 'table' then --making sure again- this is a valid group
|
||||||
|
|
||||||
mist.DBs.units[coa_name][countryName][category][group_num] = {}
|
mist.DBs.units[coa_name][countryName][category][group_num] = {}
|
||||||
@ -351,6 +372,12 @@ do -- the main scope
|
|||||||
units_tbl[unit_num].hardpoint_racks = unit_data.hardpoint_racks
|
units_tbl[unit_num].hardpoint_racks = unit_data.hardpoint_racks
|
||||||
units_tbl[unit_num].psi = unit_data.psi
|
units_tbl[unit_num].psi = unit_data.psi
|
||||||
|
|
||||||
|
if helipadId then
|
||||||
|
units_tbl[unit_num].helipadId = mist.utils.deepCopy(helipadId)
|
||||||
|
end
|
||||||
|
if airdromeId then
|
||||||
|
units_tbl[unit_num].airdromeId = mist.utils.deepCopy(airdromeId)
|
||||||
|
end
|
||||||
|
|
||||||
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
|
||||||
@ -752,6 +779,10 @@ do -- the main scope
|
|||||||
-- end
|
-- end
|
||||||
|
|
||||||
--Build DBs
|
--Build DBs
|
||||||
|
|
||||||
|
--dbLog:echo(abRef)
|
||||||
|
mist.DBs.spawnsByBase = {}
|
||||||
|
|
||||||
for coa_name, coa_data in pairs(mist.DBs.units) do
|
for coa_name, coa_data in pairs(mist.DBs.units) do
|
||||||
for cntry_name, cntry_data in pairs(coa_data) do
|
for cntry_name, cntry_data in pairs(coa_data) do
|
||||||
for category_name, category_data in pairs(cntry_data) do
|
for category_name, category_data in pairs(cntry_data) do
|
||||||
@ -781,6 +812,21 @@ do -- the main scope
|
|||||||
-- mist.DBs.activeHumans[unit_data.unitName].playerName = Unit.getByName(unit_data.unitName):getPlayerName()
|
-- mist.DBs.activeHumans[unit_data.unitName].playerName = Unit.getByName(unit_data.unitName):getPlayerName()
|
||||||
--end
|
--end
|
||||||
end
|
end
|
||||||
|
if unit_data.airdromeId then
|
||||||
|
--log:echo(unit_data.airdromeId)
|
||||||
|
--log:echo(abRef.airbase[unit_data.airdromeId])
|
||||||
|
if not mist.DBs.spawnsByBase[abRef.airbase[unit_data.airdromeId].name] then
|
||||||
|
mist.DBs.spawnsByBase[abRef.airbase[unit_data.airdromeId].name] = {}
|
||||||
|
end
|
||||||
|
table.insert(mist.DBs.spawnsByBase[abRef.airbase[unit_data.airdromeId].name], unit_data.unitName)
|
||||||
|
end
|
||||||
|
if unit_data.helipadId then
|
||||||
|
if not mist.DBs.spawnsByBase[abRef.units[unit_data.helipadId].name] then
|
||||||
|
mist.DBs.spawnsByBase[abRef.units[unit_data.helipadId].name] = {}
|
||||||
|
end
|
||||||
|
table.insert(mist.DBs.spawnsByBase[abRef.units[unit_data.helipadId].name], unit_data.unitName)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -3953,7 +3999,7 @@ do -- group functions scope
|
|||||||
|
|
||||||
--- Returns group data table of give group.
|
--- Returns group data table of give group.
|
||||||
function mist.getCurrentGroupData(gpName)
|
function mist.getCurrentGroupData(gpName)
|
||||||
local dbData = mist.getGroupData(gpName)
|
local dbData = mist.getGroupData(gpName) or {}
|
||||||
|
|
||||||
if Group.getByName(gpName) and Group.getByName(gpName):isExist() == true then
|
if Group.getByName(gpName) and Group.getByName(gpName):isExist() == true then
|
||||||
local newGroup = Group.getByName(gpName)
|
local newGroup = Group.getByName(gpName)
|
||||||
@ -3989,23 +4035,24 @@ do -- group functions scope
|
|||||||
newData.units[unitNum].callsign = unitData:getCallsign()
|
newData.units[unitNum].callsign = unitData:getCallsign()
|
||||||
newData.units[unitNum].unitName = uName
|
newData.units[unitNum].unitName = uName
|
||||||
end
|
end
|
||||||
|
local pos = unitData:getPosition()
|
||||||
newData.units[unitNum].x = unitData:getPosition().p.x
|
newData.units[unitNum].x = pos.p.x
|
||||||
newData.units[unitNum].y = unitData:getPosition().p.z
|
newData.units[unitNum].y = pos.p.z
|
||||||
newData.units[unitNum].point = {x = newData.units[unitNum].x, y = newData.units[unitNum].y}
|
newData.units[unitNum].point = {x = newData.units[unitNum].x, y = newData.units[unitNum].y}
|
||||||
newData.units[unitNum].heading = mist.getHeading(unitData, true) -- added to DBs
|
newData.units[unitNum].heading = math.atan2(pos.x.z, pos.x.x)
|
||||||
newData.units[unitNum].alt = unitData:getPosition().p.y
|
newData.units[unitNum].alt = pos.p.y
|
||||||
newData.units[unitNum].speed = mist.vec.mag(unitData:getVelocity())
|
newData.units[unitNum].speed = mist.vec.mag(unitData:getVelocity())
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return newData
|
return newData
|
||||||
elseif StaticObject.getByName(gpName) and StaticObject.getByName(gpName):isExist() == true then
|
elseif StaticObject.getByName(gpName) and StaticObject.getByName(gpName):isExist() == true and dbData.units then
|
||||||
local staticObj = StaticObject.getByName(gpName)
|
local staticObj = StaticObject.getByName(gpName)
|
||||||
dbData.units[1].x = staticObj:getPosition().p.x
|
local pos =staticObj:getPosition()
|
||||||
dbData.units[1].y = staticObj:getPosition().p.z
|
dbData.units[1].x = pos.p.x
|
||||||
dbData.units[1].alt = staticObj:getPosition().p.y
|
dbData.units[1].y = pos.p.z
|
||||||
dbData.units[1].heading = mist.getHeading(staticObj, true)
|
dbData.units[1].alt = pos.p.y
|
||||||
|
dbData.units[1].heading = math.atan2(pos.x.z, pos.x.x)
|
||||||
|
|
||||||
return dbData
|
return dbData
|
||||||
end
|
end
|
||||||
@ -4199,7 +4246,10 @@ do -- group functions scope
|
|||||||
if ((type(obj_cat_data) == 'table') and obj_cat_data.group and (type(obj_cat_data.group) == 'table') and (#obj_cat_data.group > 0)) then --there's a group!
|
if ((type(obj_cat_data) == 'table') and obj_cat_data.group and (type(obj_cat_data.group) == 'table') and (#obj_cat_data.group > 0)) then --there's a group!
|
||||||
for group_num, group_data in pairs(obj_cat_data.group) do
|
for group_num, group_data in pairs(obj_cat_data.group) do
|
||||||
if group_data and group_data.groupId == gpId then
|
if group_data and group_data.groupId == gpId then
|
||||||
return group_data
|
local gp = mist.utils.deepCopy(group_data)
|
||||||
|
gp.category = obj_cat_name
|
||||||
|
gp.country = cntry_data.id
|
||||||
|
return gp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user