mirror of
https://github.com/mrSkortch/MissionScriptingTools.git
synced 2026-07-19 10:17:18 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b5d905fd6e | |||
| 94629d2cfd | |||
| 4922d756d5 | |||
| 67f2c5f983 | |||
| 9c3c67817b | |||
| debded08f4 | |||
| 52555f73f7 | |||
| effa8eb5b1 | |||
| b5c7b16500 | |||
| de420ca158 | |||
| 240b8a3abb |
@@ -35,7 +35,7 @@ mist = {}
|
||||
-- don't change these
|
||||
mist.majorVersion = 4
|
||||
mist.minorVersion = 5
|
||||
mist.build = 128
|
||||
mist.build = 121
|
||||
|
||||
-- forward declaration of log shorthand
|
||||
local log
|
||||
@@ -97,6 +97,57 @@ do -- the main scope
|
||||
mist.DBs.missionData.countries = {}
|
||||
end
|
||||
|
||||
mist.DBs.zonesByName = {}
|
||||
mist.DBs.zonesByNum = {}
|
||||
|
||||
|
||||
if env.mission.triggers and env.mission.triggers.zones then
|
||||
for zone_ind, zone_data in pairs(env.mission.triggers.zones) do
|
||||
if type(zone_data) == 'table' then
|
||||
local zone = mist.utils.deepCopy(zone_data)
|
||||
--log:warn(zone)
|
||||
zone.point = {} -- point is used by SSE
|
||||
zone.point.x = zone_data.x
|
||||
zone.point.y = land.getHeight({x = zone_data.x, y = zone_data.y})
|
||||
zone.point.z = zone_data.y
|
||||
zone.properties = {}
|
||||
if zone_data.properties then
|
||||
for propInd, prop in pairs(zone_data.properties) do
|
||||
if prop.value and tostring(prop.value) ~= "" then
|
||||
zone.properties[prop.key] = prop.value
|
||||
end
|
||||
end
|
||||
end
|
||||
if zone.verticies then -- trust but verify
|
||||
local r = 0
|
||||
for i = 1, #zone.verticies do
|
||||
local dist = mist.utils.get2DDist(zone.point, zone.verticies[i])
|
||||
if dist > r then
|
||||
r = mist.utils.deepCopy(dist)
|
||||
end
|
||||
end
|
||||
zone.radius = r
|
||||
|
||||
end
|
||||
if zone.linkUnit then
|
||||
local uRef = mist.DBs.unitsByName[zone.linkUnit]
|
||||
if zone.verticies then
|
||||
local offset = {}
|
||||
for i = 1, #zone.verticies do
|
||||
table.insert(offset, {dist = mist.utils.get2DDist(uRef.point, zone.verticies[i]), heading = mist.getHeadingPoints(uRef.point, zone.verticies[i]) + uRef.heading})
|
||||
end
|
||||
zone.offset = offset
|
||||
else
|
||||
zone.offset = {dist = mist.utils.get2DDist(uRef.point, zone.point), heading = mist.getHeadingPoints(uRef.point, zone.point) + uRef.heading}
|
||||
end
|
||||
end
|
||||
|
||||
mist.DBs.zonesByName[zone_data.name] = zone
|
||||
mist.DBs.zonesByNum[#mist.DBs.zonesByNum + 1] = mist.utils.deepCopy(zone) --[[deepcopy so that the zone in zones_by_name and the zone in
|
||||
zones_by_num se are different objects.. don't want them linked.]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mist.DBs.drawingByName = {}
|
||||
mist.DBs.drawingIndexed = {}
|
||||
@@ -695,6 +746,7 @@ do -- the main scope
|
||||
["FARP"] = "farps",
|
||||
["Fueltank"] = "fueltank_cargo",
|
||||
["Gate"] = "gate",
|
||||
["FARP Fuel Depot"] = "gsm rus",
|
||||
["Armed house"] = "home1_a",
|
||||
["FARP Command Post"] = "kp-ug",
|
||||
["Watch Tower Armed"] = "ohr-vyshka",
|
||||
@@ -703,6 +755,7 @@ do -- the main scope
|
||||
["Pipes big"] = "pipes_big_cargo",
|
||||
["Oil platform"] = "plavbaza",
|
||||
["Tetrapod"] = "tetrapod_cargo",
|
||||
["Fuel tank"] = "toplivo",
|
||||
["Trunks long"] = "trunks_long_cargo",
|
||||
["Trunks small"] = "trunks_small_cargo",
|
||||
["Passenger liner"] = "yastrebow",
|
||||
@@ -789,59 +842,6 @@ do -- the main scope
|
||||
end
|
||||
end
|
||||
|
||||
mist.DBs.zonesByName = {}
|
||||
mist.DBs.zonesByNum = {}
|
||||
|
||||
if env.mission.triggers and env.mission.triggers.zones then
|
||||
for zone_ind, zone_data in pairs(env.mission.triggers.zones) do
|
||||
if type(zone_data) == 'table' then
|
||||
local zone = mist.utils.deepCopy(zone_data)
|
||||
--log:warn(zone)
|
||||
zone.point = {} -- point is used by SSE
|
||||
zone.point.x = zone_data.x
|
||||
zone.point.y = land.getHeight({x = zone_data.x, y = zone_data.y})
|
||||
zone.point.z = zone_data.y
|
||||
zone.properties = {}
|
||||
if zone_data.properties then
|
||||
for propInd, prop in pairs(zone_data.properties) do
|
||||
if prop.value and tostring(prop.value) ~= "" then
|
||||
zone.properties[prop.key] = prop.value
|
||||
end
|
||||
end
|
||||
end
|
||||
if zone.verticies then -- trust but verify
|
||||
local r = 0
|
||||
for i = 1, #zone.verticies do
|
||||
local dist = mist.utils.get2DDist(zone.point, zone.verticies[i])
|
||||
if dist > r then
|
||||
r = mist.utils.deepCopy(dist)
|
||||
end
|
||||
end
|
||||
zone.radius = r
|
||||
|
||||
end
|
||||
if zone.linkUnit then
|
||||
local uRef = mist.DBs.unitsByName[zone.linkUnit]
|
||||
if uRef then
|
||||
if zone.verticies then
|
||||
local offset = {}
|
||||
for i = 1, #zone.verticies do
|
||||
table.insert(offset, {dist = mist.utils.get2DDist(uRef.point, zone.verticies[i]), heading = mist.getHeadingPoints(uRef.point, zone.verticies[i]) + uRef.heading})
|
||||
end
|
||||
zone.offset = offset
|
||||
else
|
||||
zone.offset = {dist = mist.utils.get2DDist(uRef.point, zone.point), heading = mist.getHeadingPoints(uRef.point, zone.point) + uRef.heading}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mist.DBs.zonesByName[zone_data.name] = zone
|
||||
mist.DBs.zonesByNum[#mist.DBs.zonesByNum + 1] = mist.utils.deepCopy(zone) --[[deepcopy so that the zone in zones_by_name and the zone in
|
||||
zones_by_num se are different objects.. don't want them linked.]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--DynDBs
|
||||
mist.DBs.MEunits = mist.utils.deepCopy(mist.DBs.units)
|
||||
mist.DBs.MEunitsByName = mist.utils.deepCopy(mist.DBs.unitsByName)
|
||||
@@ -1072,12 +1072,6 @@ do -- the main scope
|
||||
|
||||
newTable.units[unitId].type = unitData:getTypeName()
|
||||
newTable.units[unitId].unitId = tonumber(unitData:getID())
|
||||
|
||||
local pName = unitData:getPlayerName()
|
||||
--log:warn("'$1'", pName)
|
||||
if (pName and pName ~= "") and not mist.DBs.MEunitsByName[newTable.units[unitId].unitName] then
|
||||
newTable.dynamicSlot = timer.getTime()
|
||||
end
|
||||
|
||||
|
||||
newTable.units[unitId].groupName = newTable.groupName
|
||||
@@ -1098,11 +1092,7 @@ do -- the main scope
|
||||
mistAddedObjects[index] = nil
|
||||
end
|
||||
if found == false then
|
||||
if newTable.dynamicSlot then
|
||||
newTable.units[unitId].skill = "Client"
|
||||
else
|
||||
newTable.units[unitId].skill = "High"
|
||||
end
|
||||
newTable.units[unitId].skill = "High"
|
||||
newTable.units[unitId].alt_type = "BARO"
|
||||
end
|
||||
if newTable.units[unitId].alt_type == "RADIO" then -- raw postition MSL was grabbed for group, but spawn is AGL, so re-offset it
|
||||
@@ -1160,12 +1150,10 @@ do -- the main scope
|
||||
end
|
||||
end
|
||||
end
|
||||
--dbLog:warn(newTable)
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', newTable}, timer.getAbsTime() ..'Group.lua')
|
||||
newTable.timeAdded = timer.getAbsTime() -- only on the dynGroupsAdded table. For other reference, see start time
|
||||
--mist.debug.dumpDBs()
|
||||
--end
|
||||
--dbLog:warn(newTable)
|
||||
--dbLog:info('endDbUpdate')
|
||||
return newTable
|
||||
end
|
||||
@@ -1257,12 +1245,8 @@ do -- the main scope
|
||||
if stillExists == true and (updated == true or not mist.DBs.groupsByName[name]) then
|
||||
--dbLog:info('Get Table')
|
||||
local dbData = dbUpdate(name, gData.type, staticGroupName)
|
||||
if dbData and type(dbData) == 'table' then
|
||||
if dbData.name then
|
||||
writeGroups[#writeGroups+1] = {data = dbData, isUpdated = updated}
|
||||
else
|
||||
dbLog:warn("dbUpdate failed to populate data: $1 $2 $3", name, gData.type, gData)
|
||||
end
|
||||
if dbData and type(dbData) == 'table' then
|
||||
writeGroups[#writeGroups+1] = {data = dbData, isUpdated = updated}
|
||||
end
|
||||
end
|
||||
-- Work done, so remove
|
||||
@@ -1282,11 +1266,6 @@ do -- the main scope
|
||||
--dbLog:info(newTable)
|
||||
|
||||
local state = 0
|
||||
if not newTable.name then
|
||||
dbLog:warn("Failed to add to database; sufficent data missing $1", newTable)
|
||||
return false
|
||||
end
|
||||
|
||||
if updateChecker[newTable.name] then
|
||||
dbLog:warn("Failed to add to database: $1. Stopped at state: $2", newTable.name, updateChecker[newTable.name])
|
||||
return false
|
||||
@@ -1362,13 +1341,6 @@ do -- the main scope
|
||||
--dbLog:info('byId')
|
||||
mist.DBs.unitsById[tonumber(newUnitData.unitId)] = ldeepCopy(newUnitData)
|
||||
end
|
||||
|
||||
if newTable.dynamicSlot then
|
||||
mist.DBs.humansByName[newTable.units[1].unitName] = ldeepCopy(newUnitData)
|
||||
if newUnitData.unitId then
|
||||
mist.DBs.humansById[newTable.units[1].unitId] = ldeepCopy(newUnitData)
|
||||
end
|
||||
end
|
||||
mist.DBs.unitsByName[newUnitData.unitName] = ldeepCopy(newUnitData)
|
||||
end
|
||||
-- this is a really annoying DB to populate. Gotta create new tables in case its missing
|
||||
@@ -1411,9 +1383,6 @@ do -- the main scope
|
||||
--dbLog:info('add to dynGroups')
|
||||
mist.DBs.dynGroupsAdded[#mist.DBs.dynGroupsAdded + 1] = ldeepCopy(newTable)
|
||||
--dbLog:info('clear entry')
|
||||
|
||||
|
||||
|
||||
updateChecker[newTable.name] = nil
|
||||
--dbLog:info('return')
|
||||
return true
|
||||
@@ -1443,8 +1412,7 @@ do -- the main scope
|
||||
if i > 0 then
|
||||
--dbLog:info('updateDBTables: $1', #writeGroups)
|
||||
|
||||
for x = i, 1, -1 do
|
||||
--dbLog:info(x)
|
||||
for x = 1, i do
|
||||
local res = writeDBTables(writeGroups[x])
|
||||
if res and res == true then
|
||||
--dbLog:info('result: complete')
|
||||
@@ -1454,7 +1422,6 @@ do -- the main scope
|
||||
end
|
||||
end
|
||||
if x%savesPerRun == 0 then
|
||||
--dbLog:info("yield")
|
||||
coroutine.yield()
|
||||
end
|
||||
if timer.getTime() > lastUpdateTime then
|
||||
@@ -1469,15 +1436,14 @@ do -- the main scope
|
||||
-- dont need to add units spawned in at the start of the mission if mist is loaded in init line
|
||||
if event.id == world.event.S_EVENT_BIRTH and timer.getTime0() < timer.getAbsTime() then
|
||||
|
||||
if Object.getCategory(event.initiator) == 1 then
|
||||
if Object.getCategory(event.initiator) == 1 and not Unit.getPlayerName(event.initiator) then -- simple player check, will need to later check to see if unit was spawned with a player in a flight
|
||||
--log:info('Object is a Unit')
|
||||
local g = Unit.getGroup(event.initiator)
|
||||
if g and event.initiator:getPlayerName() ~= "" and not mist.DBs.MEunitsByName[event.initiator:getName()] then
|
||||
if Unit.getGroup(event.initiator) then
|
||||
-- log:info(Unit.getGroup(event.initiator):getName())
|
||||
local gName = g:getName()
|
||||
if not tempSpawnedGroups[gName] then
|
||||
--log:warn('addedTo tempSpawnedGroups: $1', gName)
|
||||
tempSpawnedGroups[gName] = {type = 'group', gp = g}
|
||||
local g = Unit.getGroup(event.initiator)
|
||||
if not tempSpawnedGroups[g:getName()] then
|
||||
--log:info('added')
|
||||
tempSpawnedGroups[g:getName()] = {type = 'group', gp = g}
|
||||
tempSpawnGroupsCounter = tempSpawnGroupsCounter + 1
|
||||
end
|
||||
else
|
||||
@@ -1525,7 +1491,7 @@ do -- the main scope
|
||||
task.t = timer.getTime() + task.rep --schedule next run
|
||||
local err, errmsg = pcall(task.f, unpack(task.vars, 1, table.maxn(task.vars)))
|
||||
if not err then
|
||||
log:error('Error in scheduled function: $1', errmsg)
|
||||
log:error('Error in scheduled function: $1' .. errmsg)
|
||||
end
|
||||
--scheduledTasks[i].f(unpack(scheduledTasks[i].vars, 1, table.maxn(scheduledTasks[i].vars))) -- do the task
|
||||
i = i + 1
|
||||
@@ -1551,63 +1517,53 @@ do -- the main scope
|
||||
id = tostring(original_id) .. ' #' .. tostring(id_ind)
|
||||
id_ind = id_ind + 1
|
||||
end
|
||||
local valid
|
||||
|
||||
if mist.DBs.aliveUnits and mist.DBs.aliveUnits[val.object.id_] then
|
||||
--log:info('object found in alive_units')
|
||||
val.objectData = mist.utils.deepCopy(mist.DBs.aliveUnits[val.object.id_])
|
||||
if Object.isExist(val.object) then
|
||||
local pos = Object.getPosition(val.object)
|
||||
if pos then
|
||||
val.objectPos = pos.p
|
||||
end
|
||||
val.objectType = mist.DBs.aliveUnits[val.object.id_].category
|
||||
--[[if mist.DBs.activeHumans[Unit.getName(val.object)] then
|
||||
--trigger.action.outText('remove via death: ' .. Unit.getName(val.object),20)
|
||||
mist.DBs.activeHumans[Unit.getName(val.object)] = nil
|
||||
end]]
|
||||
valid = true
|
||||
local pos = Object.getPosition(val.object)
|
||||
if pos then
|
||||
val.objectPos = pos.p
|
||||
end
|
||||
val.objectType = mist.DBs.aliveUnits[val.object.id_].category
|
||||
--[[if mist.DBs.activeHumans[Unit.getName(val.object)] then
|
||||
--trigger.action.outText('remove via death: ' .. Unit.getName(val.object),20)
|
||||
mist.DBs.activeHumans[Unit.getName(val.object)] = nil
|
||||
end]]
|
||||
elseif mist.DBs.removedAliveUnits and mist.DBs.removedAliveUnits[val.object.id_] then -- it didn't exist in alive_units, check old_alive_units
|
||||
--log:info('object found in old_alive_units')
|
||||
val.objectData = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_])
|
||||
if Object.isExist(val.object) then
|
||||
local pos = Object.getPosition(val.object)
|
||||
if pos then
|
||||
val.objectPos = pos.p
|
||||
end
|
||||
val.objectType = mist.DBs.removedAliveUnits[val.object.id_].category
|
||||
valid = true
|
||||
local pos = Object.getPosition(val.object)
|
||||
if pos then
|
||||
val.objectPos = pos.p
|
||||
end
|
||||
val.objectType = mist.DBs.removedAliveUnits[val.object.id_].category
|
||||
|
||||
else --attempt to determine if static object...
|
||||
--log:info('object not found in alive units or old alive units')
|
||||
if Object.isExist(val.object) then
|
||||
local pos = Object.getPosition(val.object)
|
||||
if pos then
|
||||
local static_found = false
|
||||
for ind, static in pairs(mist.DBs.unitsByCat.static) do
|
||||
if ((pos.p.x - static.point.x)^2 + (pos.p.z - static.point.y)^2)^0.5 < 0.1 then --really, it should be zero...
|
||||
--log:info('correlated dead static object to position')
|
||||
val.objectData = static
|
||||
val.objectPos = pos.p
|
||||
val.objectType = 'static'
|
||||
static_found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not static_found then
|
||||
local pos = Object.getPosition(val.object)
|
||||
if pos then
|
||||
local static_found = false
|
||||
for ind, static in pairs(mist.DBs.unitsByCat.static) do
|
||||
if ((pos.p.x - static.point.x)^2 + (pos.p.z - static.point.y)^2)^0.5 < 0.1 then --really, it should be zero...
|
||||
--log:info('correlated dead static object to position')
|
||||
val.objectData = static
|
||||
val.objectPos = pos.p
|
||||
val.objectType = 'building'
|
||||
val.typeName = Object.getTypeName(val.object)
|
||||
val.objectType = 'static'
|
||||
static_found = true
|
||||
break
|
||||
end
|
||||
else
|
||||
val.objectType = 'unknown'
|
||||
end
|
||||
valid = true
|
||||
if not static_found then
|
||||
val.objectPos = pos.p
|
||||
val.objectType = 'building'
|
||||
val.typeName = Object.getTypeName(val.object)
|
||||
end
|
||||
else
|
||||
val.objectType = 'unknown'
|
||||
end
|
||||
end
|
||||
if valid then
|
||||
mist.DBs.deadObjects[id] = val
|
||||
end
|
||||
mist.DBs.deadObjects[id] = val
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1777,7 +1733,7 @@ do -- the main scope
|
||||
function mist.dynAddStatic(n)
|
||||
|
||||
local newObj = mist.utils.deepCopy(n)
|
||||
--log:warn(newObj)
|
||||
log:warn(newObj)
|
||||
if newObj.units and newObj.units[1] then -- if its mist format
|
||||
for entry, val in pairs(newObj.units[1]) do
|
||||
if newObj[entry] and newObj[entry] ~= val or not newObj[entry] then
|
||||
@@ -2061,7 +2017,7 @@ do -- the main scope
|
||||
|
||||
end
|
||||
end
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, newGroup.name ..'.lua')
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, 'newGroupPushedToAddGroup.lua')
|
||||
--log:warn(newGroup)
|
||||
-- sanitize table
|
||||
newGroup.groupName = nil
|
||||
@@ -3602,7 +3558,7 @@ function mist.getUnitsInMovingZones(unit_names, zone_unit_names, radius, zone_ty
|
||||
end
|
||||
|
||||
function mist.getUnitsLOS(unitset1, altoffset1, unitset2, altoffset2, radius)
|
||||
--log:info("$1, $2, $3, $4, $5", unitset1, altoffset1, unitset2, altoffset2, radius)
|
||||
log:info("$1, $2, $3, $4, $5", unitset1, altoffset1, unitset2, altoffset2, radius)
|
||||
radius = radius or math.huge
|
||||
local unit_info1 = {}
|
||||
local unit_info2 = {}
|
||||
@@ -3610,25 +3566,21 @@ function mist.getUnitsLOS(unitset1, altoffset1, unitset2, altoffset2, radius)
|
||||
-- get the positions all in one step, saves execution time.
|
||||
for unitset1_ind = 1, #unitset1 do
|
||||
local unit1 = Unit.getByName(unitset1[unitset1_ind])
|
||||
if unit1 then
|
||||
local lCat = Object.getCategory(unit1)
|
||||
if ((lCat == 1 and unit1:isActive()) or lCat ~= 1) and unit1:isExist() == true then
|
||||
unit_info1[#unit_info1 + 1] = {}
|
||||
unit_info1[#unit_info1].unit = unit1
|
||||
unit_info1[#unit_info1].pos = unit1:getPosition().p
|
||||
end
|
||||
local lCat = Object.getCategory(unit1)
|
||||
if unit1 and ((lCat == 1 and unit1:isActive()) or lCat ~= 1) and unit:isExist() == true then
|
||||
unit_info1[#unit_info1 + 1] = {}
|
||||
unit_info1[#unit_info1].unit = unit1
|
||||
unit_info1[#unit_info1].pos = unit1:getPosition().p
|
||||
end
|
||||
end
|
||||
|
||||
for unitset2_ind = 1, #unitset2 do
|
||||
local unit2 = Unit.getByName(unitset2[unitset2_ind])
|
||||
if unit2 then
|
||||
local lCat = Object.getCategory(unit2)
|
||||
if ((lCat == 1 and unit2:isActive()) or lCat ~= 1) and unit2:isExist() == true then
|
||||
unit_info2[#unit_info2 + 1] = {}
|
||||
unit_info2[#unit_info2].unit = unit2
|
||||
unit_info2[#unit_info2].pos = unit2:getPosition().p
|
||||
end
|
||||
local lCat = Object.getCategory(unit2)
|
||||
if unit2 and ((lCat == 1 and unit2:isActive()) or lCat ~= 1) and unit:isExist() == true then
|
||||
unit_info2[#unit_info2 + 1] = {}
|
||||
unit_info2[#unit_info2].unit = unit2
|
||||
unit_info2[#unit_info2].pos = unit2:getPosition().p
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4058,14 +4010,13 @@ do -- group functions scope
|
||||
|
||||
if Group.getByName(gpName) and Group.getByName(gpName):isExist() == true then
|
||||
local newGroup = Group.getByName(gpName)
|
||||
local newData = mist.utils.deepCopy(dbData)
|
||||
local newData = {}
|
||||
newData.name = gpName
|
||||
newData.groupId = tonumber(newGroup:getID())
|
||||
newData.category = newGroup:getCategory()
|
||||
newData.groupName = gpName
|
||||
newData.hidden = dbData.hidden
|
||||
|
||||
|
||||
|
||||
if newData.category == 2 then
|
||||
newData.category = 'vehicle'
|
||||
elseif newData.category == 3 then
|
||||
@@ -4837,9 +4788,6 @@ do -- group functions scope
|
||||
highNum = secondNum
|
||||
end
|
||||
local total = 1
|
||||
if highNum > 50 then
|
||||
return math.random(lowNum, highNum)
|
||||
end
|
||||
if math.abs(highNum - lowNum + 1) < 50 then -- if total values is less than 50
|
||||
total = math.modf(50/math.abs(highNum - lowNum + 1)) -- make x copies required to be above 50
|
||||
end
|
||||
@@ -5243,8 +5191,7 @@ do -- mist.util scope
|
||||
|
||||
function mist.utils.getHeadingPoints(point1, point2, north) -- sick of writing this out.
|
||||
if north then
|
||||
local p1 = mist.utils.makeVec3(point1)
|
||||
return mist.utils.getDir(mist.vec.sub(mist.utils.makeVec3(point2), p1), p1)
|
||||
return mist.utils.getDir(mist.vec.sub(mist.utils.makeVec3(point2), mist.utils.makeVec3(point1)), (mist.utils.makeVec3(point1)))
|
||||
else
|
||||
return mist.utils.getDir(mist.vec.sub(mist.utils.makeVec3(point2), mist.utils.makeVec3(point1)))
|
||||
end
|
||||
@@ -5888,8 +5835,8 @@ do -- mist.debug scope
|
||||
log:alert('insufficient libraries to run mist.debug.dump_G, you must disable the sanitization of the io and lfs libraries in ./Scripts/MissionScripting.lua')
|
||||
--trigger.action.outText(errmsg, 10)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Write debug data to file.
|
||||
-- This function requires you to disable script sanitization
|
||||
-- in $DCS_ROOT\Scripts\MissionScripting.lua to access lfs and io
|
||||
@@ -7704,10 +7651,7 @@ do
|
||||
--log:warn(s)
|
||||
if type(s) == 'table' then
|
||||
local mType = s.markType
|
||||
--log:echo(s)
|
||||
|
||||
if mType == 'panel' then
|
||||
local markScope = s.markScope or "all"
|
||||
if mType == 'panel' then
|
||||
if markScope == 'coa' then
|
||||
trigger.action.markToCoalition(s.markId, s.text, s.pos, s.markFor, s.readOnly)
|
||||
elseif markScope == 'group' then
|
||||
@@ -7765,15 +7709,10 @@ do
|
||||
|
||||
local function validateColor(val)
|
||||
if type(val) == 'table' then
|
||||
for i = 1, 4 do
|
||||
if val[i] then
|
||||
if type(val[i]) == 'number' and val[i] > 1 then
|
||||
val[i] = val[i]/255 -- convert RGB values from 0-255 to 0-1 equivilent.
|
||||
end
|
||||
else
|
||||
val[i] = 0.8
|
||||
log:warn("index $1 of color to mist.marker.add was missing, defaulted to 0.8", i)
|
||||
end
|
||||
for i = 1, #val do
|
||||
if type(val[i]) == 'number' and val[i] > 1 then
|
||||
val[i] = val[i]/255 -- convert RGB values from 0-255 to 0-1 equivilent.
|
||||
end
|
||||
end
|
||||
elseif type(val) == 'string' then
|
||||
val = mist.utils.hexToRGB(val)
|
||||
@@ -7814,7 +7753,7 @@ do
|
||||
--log:info('create maker DB: $1', e.idx)
|
||||
mist.DBs.markList[e.idx] = {time = e.time, pos = e.pos, groupId = e.groupId, mType = 'panel', text = e.text, markId = e.idx, coalition = e.coalition}
|
||||
if e.unit then
|
||||
mist.DBs.markList[e.idx].unit = e.initiator:getName()
|
||||
mist.DBs.markList[e.idx].unit = e.intiator:getName()
|
||||
end
|
||||
--log:info(mist.marker.list[e.idx])
|
||||
end
|
||||
@@ -7837,7 +7776,7 @@ do
|
||||
else
|
||||
for mEntry, mData in pairs(mist.DBs.markList) do
|
||||
if id == mData.name or id == mData.id then
|
||||
return mData.markId
|
||||
return mData.id
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -7847,16 +7786,11 @@ do
|
||||
|
||||
|
||||
local function removeMark(id)
|
||||
--log:info("Removing Mark: $1", id)
|
||||
--log:info("Removing Mark: $1", id
|
||||
local removed = false
|
||||
if type(id) == 'table' then
|
||||
for ind, val in pairs(id) do
|
||||
local r
|
||||
if type(val) == "table" and val.markId then
|
||||
r = val.markId
|
||||
else
|
||||
r = getMarkId(val)
|
||||
end
|
||||
local r = getMarkId(val)
|
||||
if r then
|
||||
trigger.action.removeMark(r)
|
||||
mist.DBs.markList[r] = nil
|
||||
@@ -7866,11 +7800,9 @@ do
|
||||
|
||||
else
|
||||
local r = getMarkId(id)
|
||||
if r then
|
||||
trigger.action.removeMark(r)
|
||||
mist.DBs.markList[r] = nil
|
||||
removed = true
|
||||
end
|
||||
trigger.action.removeMark(r)
|
||||
mist.DBs.markList[r] = nil
|
||||
removed = true
|
||||
end
|
||||
return removed
|
||||
end
|
||||
@@ -7992,7 +7924,6 @@ do
|
||||
|
||||
if markForCoa then
|
||||
if type(markForCoa) == 'string' then
|
||||
--log:warn("coa is string")
|
||||
if tonumber(markForCoa) then
|
||||
coa = coas[tonumber(markForCoa)]
|
||||
markScope = 'coa'
|
||||
@@ -8007,10 +7938,11 @@ do
|
||||
end
|
||||
elseif type(markForCoa) == 'number' and markForCoa >=-1 and markForCoa <= #coas then
|
||||
coa = markForCoa
|
||||
--log:warn("coa is number")
|
||||
markScope = 'coa'
|
||||
markScore = 'coa'
|
||||
end
|
||||
markFor = coa
|
||||
|
||||
|
||||
|
||||
elseif markFor then
|
||||
if type(markFor) == 'number' then -- groupId
|
||||
if mist.DBs.groupsById[markFor] then
|
||||
@@ -8119,7 +8051,7 @@ do
|
||||
end
|
||||
for i = 1, #markForTable do
|
||||
local newId = iterate()
|
||||
local data = {markId = newId, text = text, pos = pos[i], markScope = markScope, markFor = markForTable[i], markType = 'panel', name = name, readOnly = readOnly, time = timer.getTime()}
|
||||
local data = {markId = newId, text = text, pos = pos[i], markFor = markForTable[i], markType = 'panel', name = name, readOnly = readOnly, time = timer.getTime()}
|
||||
mist.DBs.markList[newId] = data
|
||||
table.insert(list, data)
|
||||
|
||||
@@ -8243,7 +8175,6 @@ do
|
||||
end
|
||||
|
||||
function mist.marker.remove(id)
|
||||
|
||||
return removeMark(id)
|
||||
end
|
||||
|
||||
@@ -8775,13 +8706,6 @@ do -- group tasks scope
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
function mist.insertTaskToWP(wp, task)
|
||||
if not wp.task then
|
||||
wp.task = {["id"] = "ComboTask", ["params"] = {tasks = {}}}
|
||||
end
|
||||
table.insert(wp.task.params.tasks, task)
|
||||
end
|
||||
|
||||
function mist.ground.patrol(gpData, pType, form, speed)
|
||||
local vars = {}
|
||||
@@ -9041,8 +8965,8 @@ do -- group tasks scope
|
||||
minR = mist.utils.get2DDist(avg, zone[i])
|
||||
end
|
||||
end
|
||||
--log:warn('minR: $1', minR)
|
||||
--log:warn('Radius: $1', radius)
|
||||
--log:warn('minR: $1', minR)
|
||||
local lSpawnPos = {}
|
||||
for j = 1, 100 do
|
||||
newCoord = mist.getRandPointInCircle(avg, radius)
|
||||
@@ -9274,7 +9198,7 @@ do -- group tasks scope
|
||||
function mist.groupIsDead(groupName) -- copy more or less from on station
|
||||
local gp = Group.getByName(groupName)
|
||||
if gp then
|
||||
if #gp:getUnits() > 0 and gp:isExist() == true then
|
||||
if #gp:getUnits() > 0 or gp:isExist() == true then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
+133
-209
@@ -35,7 +35,7 @@ mist = {}
|
||||
-- don't change these
|
||||
mist.majorVersion = 4
|
||||
mist.minorVersion = 5
|
||||
mist.build = 128
|
||||
mist.build = 121
|
||||
|
||||
-- forward declaration of log shorthand
|
||||
local log
|
||||
@@ -97,6 +97,57 @@ do -- the main scope
|
||||
mist.DBs.missionData.countries = {}
|
||||
end
|
||||
|
||||
mist.DBs.zonesByName = {}
|
||||
mist.DBs.zonesByNum = {}
|
||||
|
||||
|
||||
if env.mission.triggers and env.mission.triggers.zones then
|
||||
for zone_ind, zone_data in pairs(env.mission.triggers.zones) do
|
||||
if type(zone_data) == 'table' then
|
||||
local zone = mist.utils.deepCopy(zone_data)
|
||||
--log:warn(zone)
|
||||
zone.point = {} -- point is used by SSE
|
||||
zone.point.x = zone_data.x
|
||||
zone.point.y = land.getHeight({x = zone_data.x, y = zone_data.y})
|
||||
zone.point.z = zone_data.y
|
||||
zone.properties = {}
|
||||
if zone_data.properties then
|
||||
for propInd, prop in pairs(zone_data.properties) do
|
||||
if prop.value and tostring(prop.value) ~= "" then
|
||||
zone.properties[prop.key] = prop.value
|
||||
end
|
||||
end
|
||||
end
|
||||
if zone.verticies then -- trust but verify
|
||||
local r = 0
|
||||
for i = 1, #zone.verticies do
|
||||
local dist = mist.utils.get2DDist(zone.point, zone.verticies[i])
|
||||
if dist > r then
|
||||
r = mist.utils.deepCopy(dist)
|
||||
end
|
||||
end
|
||||
zone.radius = r
|
||||
|
||||
end
|
||||
if zone.linkUnit then
|
||||
local uRef = mist.DBs.unitsByName[zone.linkUnit]
|
||||
if zone.verticies then
|
||||
local offset = {}
|
||||
for i = 1, #zone.verticies do
|
||||
table.insert(offset, {dist = mist.utils.get2DDist(uRef.point, zone.verticies[i]), heading = mist.getHeadingPoints(uRef.point, zone.verticies[i]) + uRef.heading})
|
||||
end
|
||||
zone.offset = offset
|
||||
else
|
||||
zone.offset = {dist = mist.utils.get2DDist(uRef.point, zone.point), heading = mist.getHeadingPoints(uRef.point, zone.point) + uRef.heading}
|
||||
end
|
||||
end
|
||||
|
||||
mist.DBs.zonesByName[zone_data.name] = zone
|
||||
mist.DBs.zonesByNum[#mist.DBs.zonesByNum + 1] = mist.utils.deepCopy(zone) --[[deepcopy so that the zone in zones_by_name and the zone in
|
||||
zones_by_num se are different objects.. don't want them linked.]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mist.DBs.drawingByName = {}
|
||||
mist.DBs.drawingIndexed = {}
|
||||
@@ -695,6 +746,7 @@ do -- the main scope
|
||||
["FARP"] = "farps",
|
||||
["Fueltank"] = "fueltank_cargo",
|
||||
["Gate"] = "gate",
|
||||
["FARP Fuel Depot"] = "gsm rus",
|
||||
["Armed house"] = "home1_a",
|
||||
["FARP Command Post"] = "kp-ug",
|
||||
["Watch Tower Armed"] = "ohr-vyshka",
|
||||
@@ -703,6 +755,7 @@ do -- the main scope
|
||||
["Pipes big"] = "pipes_big_cargo",
|
||||
["Oil platform"] = "plavbaza",
|
||||
["Tetrapod"] = "tetrapod_cargo",
|
||||
["Fuel tank"] = "toplivo",
|
||||
["Trunks long"] = "trunks_long_cargo",
|
||||
["Trunks small"] = "trunks_small_cargo",
|
||||
["Passenger liner"] = "yastrebow",
|
||||
@@ -789,59 +842,6 @@ do -- the main scope
|
||||
end
|
||||
end
|
||||
|
||||
mist.DBs.zonesByName = {}
|
||||
mist.DBs.zonesByNum = {}
|
||||
|
||||
if env.mission.triggers and env.mission.triggers.zones then
|
||||
for zone_ind, zone_data in pairs(env.mission.triggers.zones) do
|
||||
if type(zone_data) == 'table' then
|
||||
local zone = mist.utils.deepCopy(zone_data)
|
||||
--log:warn(zone)
|
||||
zone.point = {} -- point is used by SSE
|
||||
zone.point.x = zone_data.x
|
||||
zone.point.y = land.getHeight({x = zone_data.x, y = zone_data.y})
|
||||
zone.point.z = zone_data.y
|
||||
zone.properties = {}
|
||||
if zone_data.properties then
|
||||
for propInd, prop in pairs(zone_data.properties) do
|
||||
if prop.value and tostring(prop.value) ~= "" then
|
||||
zone.properties[prop.key] = prop.value
|
||||
end
|
||||
end
|
||||
end
|
||||
if zone.verticies then -- trust but verify
|
||||
local r = 0
|
||||
for i = 1, #zone.verticies do
|
||||
local dist = mist.utils.get2DDist(zone.point, zone.verticies[i])
|
||||
if dist > r then
|
||||
r = mist.utils.deepCopy(dist)
|
||||
end
|
||||
end
|
||||
zone.radius = r
|
||||
|
||||
end
|
||||
if zone.linkUnit then
|
||||
local uRef = mist.DBs.unitsByName[zone.linkUnit]
|
||||
if uRef then
|
||||
if zone.verticies then
|
||||
local offset = {}
|
||||
for i = 1, #zone.verticies do
|
||||
table.insert(offset, {dist = mist.utils.get2DDist(uRef.point, zone.verticies[i]), heading = mist.getHeadingPoints(uRef.point, zone.verticies[i]) + uRef.heading})
|
||||
end
|
||||
zone.offset = offset
|
||||
else
|
||||
zone.offset = {dist = mist.utils.get2DDist(uRef.point, zone.point), heading = mist.getHeadingPoints(uRef.point, zone.point) + uRef.heading}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mist.DBs.zonesByName[zone_data.name] = zone
|
||||
mist.DBs.zonesByNum[#mist.DBs.zonesByNum + 1] = mist.utils.deepCopy(zone) --[[deepcopy so that the zone in zones_by_name and the zone in
|
||||
zones_by_num se are different objects.. don't want them linked.]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--DynDBs
|
||||
mist.DBs.MEunits = mist.utils.deepCopy(mist.DBs.units)
|
||||
mist.DBs.MEunitsByName = mist.utils.deepCopy(mist.DBs.unitsByName)
|
||||
@@ -1072,12 +1072,6 @@ do -- the main scope
|
||||
|
||||
newTable.units[unitId].type = unitData:getTypeName()
|
||||
newTable.units[unitId].unitId = tonumber(unitData:getID())
|
||||
|
||||
local pName = unitData:getPlayerName()
|
||||
--log:warn("'$1'", pName)
|
||||
if (pName and pName ~= "") and not mist.DBs.MEunitsByName[newTable.units[unitId].unitName] then
|
||||
newTable.dynamicSlot = timer.getTime()
|
||||
end
|
||||
|
||||
|
||||
newTable.units[unitId].groupName = newTable.groupName
|
||||
@@ -1098,11 +1092,7 @@ do -- the main scope
|
||||
mistAddedObjects[index] = nil
|
||||
end
|
||||
if found == false then
|
||||
if newTable.dynamicSlot then
|
||||
newTable.units[unitId].skill = "Client"
|
||||
else
|
||||
newTable.units[unitId].skill = "High"
|
||||
end
|
||||
newTable.units[unitId].skill = "High"
|
||||
newTable.units[unitId].alt_type = "BARO"
|
||||
end
|
||||
if newTable.units[unitId].alt_type == "RADIO" then -- raw postition MSL was grabbed for group, but spawn is AGL, so re-offset it
|
||||
@@ -1160,12 +1150,10 @@ do -- the main scope
|
||||
end
|
||||
end
|
||||
end
|
||||
--dbLog:warn(newTable)
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', newTable}, timer.getAbsTime() ..'Group.lua')
|
||||
newTable.timeAdded = timer.getAbsTime() -- only on the dynGroupsAdded table. For other reference, see start time
|
||||
--mist.debug.dumpDBs()
|
||||
--end
|
||||
--dbLog:warn(newTable)
|
||||
--dbLog:info('endDbUpdate')
|
||||
return newTable
|
||||
end
|
||||
@@ -1257,12 +1245,8 @@ do -- the main scope
|
||||
if stillExists == true and (updated == true or not mist.DBs.groupsByName[name]) then
|
||||
--dbLog:info('Get Table')
|
||||
local dbData = dbUpdate(name, gData.type, staticGroupName)
|
||||
if dbData and type(dbData) == 'table' then
|
||||
if dbData.name then
|
||||
writeGroups[#writeGroups+1] = {data = dbData, isUpdated = updated}
|
||||
else
|
||||
dbLog:warn("dbUpdate failed to populate data: $1 $2 $3", name, gData.type, gData)
|
||||
end
|
||||
if dbData and type(dbData) == 'table' then
|
||||
writeGroups[#writeGroups+1] = {data = dbData, isUpdated = updated}
|
||||
end
|
||||
end
|
||||
-- Work done, so remove
|
||||
@@ -1282,11 +1266,6 @@ do -- the main scope
|
||||
--dbLog:info(newTable)
|
||||
|
||||
local state = 0
|
||||
if not newTable.name then
|
||||
dbLog:warn("Failed to add to database; sufficent data missing $1", newTable)
|
||||
return false
|
||||
end
|
||||
|
||||
if updateChecker[newTable.name] then
|
||||
dbLog:warn("Failed to add to database: $1. Stopped at state: $2", newTable.name, updateChecker[newTable.name])
|
||||
return false
|
||||
@@ -1362,13 +1341,6 @@ do -- the main scope
|
||||
--dbLog:info('byId')
|
||||
mist.DBs.unitsById[tonumber(newUnitData.unitId)] = ldeepCopy(newUnitData)
|
||||
end
|
||||
|
||||
if newTable.dynamicSlot then
|
||||
mist.DBs.humansByName[newTable.units[1].unitName] = ldeepCopy(newUnitData)
|
||||
if newUnitData.unitId then
|
||||
mist.DBs.humansById[newTable.units[1].unitId] = ldeepCopy(newUnitData)
|
||||
end
|
||||
end
|
||||
mist.DBs.unitsByName[newUnitData.unitName] = ldeepCopy(newUnitData)
|
||||
end
|
||||
-- this is a really annoying DB to populate. Gotta create new tables in case its missing
|
||||
@@ -1411,9 +1383,6 @@ do -- the main scope
|
||||
--dbLog:info('add to dynGroups')
|
||||
mist.DBs.dynGroupsAdded[#mist.DBs.dynGroupsAdded + 1] = ldeepCopy(newTable)
|
||||
--dbLog:info('clear entry')
|
||||
|
||||
|
||||
|
||||
updateChecker[newTable.name] = nil
|
||||
--dbLog:info('return')
|
||||
return true
|
||||
@@ -1443,8 +1412,7 @@ do -- the main scope
|
||||
if i > 0 then
|
||||
--dbLog:info('updateDBTables: $1', #writeGroups)
|
||||
|
||||
for x = i, 1, -1 do
|
||||
--dbLog:info(x)
|
||||
for x = 1, i do
|
||||
local res = writeDBTables(writeGroups[x])
|
||||
if res and res == true then
|
||||
--dbLog:info('result: complete')
|
||||
@@ -1454,7 +1422,6 @@ do -- the main scope
|
||||
end
|
||||
end
|
||||
if x%savesPerRun == 0 then
|
||||
--dbLog:info("yield")
|
||||
coroutine.yield()
|
||||
end
|
||||
if timer.getTime() > lastUpdateTime then
|
||||
@@ -1469,15 +1436,14 @@ do -- the main scope
|
||||
-- dont need to add units spawned in at the start of the mission if mist is loaded in init line
|
||||
if event.id == world.event.S_EVENT_BIRTH and timer.getTime0() < timer.getAbsTime() then
|
||||
|
||||
if Object.getCategory(event.initiator) == 1 then
|
||||
if Object.getCategory(event.initiator) == 1 and not Unit.getPlayerName(event.initiator) then -- simple player check, will need to later check to see if unit was spawned with a player in a flight
|
||||
--log:info('Object is a Unit')
|
||||
local g = Unit.getGroup(event.initiator)
|
||||
if g and event.initiator:getPlayerName() ~= "" and not mist.DBs.MEunitsByName[event.initiator:getName()] then
|
||||
if Unit.getGroup(event.initiator) then
|
||||
-- log:info(Unit.getGroup(event.initiator):getName())
|
||||
local gName = g:getName()
|
||||
if not tempSpawnedGroups[gName] then
|
||||
--log:warn('addedTo tempSpawnedGroups: $1', gName)
|
||||
tempSpawnedGroups[gName] = {type = 'group', gp = g}
|
||||
local g = Unit.getGroup(event.initiator)
|
||||
if not tempSpawnedGroups[g:getName()] then
|
||||
--log:info('added')
|
||||
tempSpawnedGroups[g:getName()] = {type = 'group', gp = g}
|
||||
tempSpawnGroupsCounter = tempSpawnGroupsCounter + 1
|
||||
end
|
||||
else
|
||||
@@ -1525,7 +1491,7 @@ do -- the main scope
|
||||
task.t = timer.getTime() + task.rep --schedule next run
|
||||
local err, errmsg = pcall(task.f, unpack(task.vars, 1, table.maxn(task.vars)))
|
||||
if not err then
|
||||
log:error('Error in scheduled function: $1', errmsg)
|
||||
log:error('Error in scheduled function: $1' .. errmsg)
|
||||
end
|
||||
--scheduledTasks[i].f(unpack(scheduledTasks[i].vars, 1, table.maxn(scheduledTasks[i].vars))) -- do the task
|
||||
i = i + 1
|
||||
@@ -1551,63 +1517,53 @@ do -- the main scope
|
||||
id = tostring(original_id) .. ' #' .. tostring(id_ind)
|
||||
id_ind = id_ind + 1
|
||||
end
|
||||
local valid
|
||||
|
||||
if mist.DBs.aliveUnits and mist.DBs.aliveUnits[val.object.id_] then
|
||||
--log:info('object found in alive_units')
|
||||
val.objectData = mist.utils.deepCopy(mist.DBs.aliveUnits[val.object.id_])
|
||||
if Object.isExist(val.object) then
|
||||
local pos = Object.getPosition(val.object)
|
||||
if pos then
|
||||
val.objectPos = pos.p
|
||||
end
|
||||
val.objectType = mist.DBs.aliveUnits[val.object.id_].category
|
||||
--[[if mist.DBs.activeHumans[Unit.getName(val.object)] then
|
||||
--trigger.action.outText('remove via death: ' .. Unit.getName(val.object),20)
|
||||
mist.DBs.activeHumans[Unit.getName(val.object)] = nil
|
||||
end]]
|
||||
valid = true
|
||||
local pos = Object.getPosition(val.object)
|
||||
if pos then
|
||||
val.objectPos = pos.p
|
||||
end
|
||||
val.objectType = mist.DBs.aliveUnits[val.object.id_].category
|
||||
--[[if mist.DBs.activeHumans[Unit.getName(val.object)] then
|
||||
--trigger.action.outText('remove via death: ' .. Unit.getName(val.object),20)
|
||||
mist.DBs.activeHumans[Unit.getName(val.object)] = nil
|
||||
end]]
|
||||
elseif mist.DBs.removedAliveUnits and mist.DBs.removedAliveUnits[val.object.id_] then -- it didn't exist in alive_units, check old_alive_units
|
||||
--log:info('object found in old_alive_units')
|
||||
val.objectData = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_])
|
||||
if Object.isExist(val.object) then
|
||||
local pos = Object.getPosition(val.object)
|
||||
if pos then
|
||||
val.objectPos = pos.p
|
||||
end
|
||||
val.objectType = mist.DBs.removedAliveUnits[val.object.id_].category
|
||||
valid = true
|
||||
local pos = Object.getPosition(val.object)
|
||||
if pos then
|
||||
val.objectPos = pos.p
|
||||
end
|
||||
val.objectType = mist.DBs.removedAliveUnits[val.object.id_].category
|
||||
|
||||
else --attempt to determine if static object...
|
||||
--log:info('object not found in alive units or old alive units')
|
||||
if Object.isExist(val.object) then
|
||||
local pos = Object.getPosition(val.object)
|
||||
if pos then
|
||||
local static_found = false
|
||||
for ind, static in pairs(mist.DBs.unitsByCat.static) do
|
||||
if ((pos.p.x - static.point.x)^2 + (pos.p.z - static.point.y)^2)^0.5 < 0.1 then --really, it should be zero...
|
||||
--log:info('correlated dead static object to position')
|
||||
val.objectData = static
|
||||
val.objectPos = pos.p
|
||||
val.objectType = 'static'
|
||||
static_found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not static_found then
|
||||
local pos = Object.getPosition(val.object)
|
||||
if pos then
|
||||
local static_found = false
|
||||
for ind, static in pairs(mist.DBs.unitsByCat.static) do
|
||||
if ((pos.p.x - static.point.x)^2 + (pos.p.z - static.point.y)^2)^0.5 < 0.1 then --really, it should be zero...
|
||||
--log:info('correlated dead static object to position')
|
||||
val.objectData = static
|
||||
val.objectPos = pos.p
|
||||
val.objectType = 'building'
|
||||
val.typeName = Object.getTypeName(val.object)
|
||||
val.objectType = 'static'
|
||||
static_found = true
|
||||
break
|
||||
end
|
||||
else
|
||||
val.objectType = 'unknown'
|
||||
end
|
||||
valid = true
|
||||
if not static_found then
|
||||
val.objectPos = pos.p
|
||||
val.objectType = 'building'
|
||||
val.typeName = Object.getTypeName(val.object)
|
||||
end
|
||||
else
|
||||
val.objectType = 'unknown'
|
||||
end
|
||||
end
|
||||
if valid then
|
||||
mist.DBs.deadObjects[id] = val
|
||||
end
|
||||
mist.DBs.deadObjects[id] = val
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1777,7 +1733,7 @@ do -- the main scope
|
||||
function mist.dynAddStatic(n)
|
||||
|
||||
local newObj = mist.utils.deepCopy(n)
|
||||
--log:warn(newObj)
|
||||
log:warn(newObj)
|
||||
if newObj.units and newObj.units[1] then -- if its mist format
|
||||
for entry, val in pairs(newObj.units[1]) do
|
||||
if newObj[entry] and newObj[entry] ~= val or not newObj[entry] then
|
||||
@@ -2061,7 +2017,7 @@ do -- the main scope
|
||||
|
||||
end
|
||||
end
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, newGroup.name ..'.lua')
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, 'newGroupPushedToAddGroup.lua')
|
||||
--log:warn(newGroup)
|
||||
-- sanitize table
|
||||
newGroup.groupName = nil
|
||||
@@ -3602,7 +3558,7 @@ function mist.getUnitsInMovingZones(unit_names, zone_unit_names, radius, zone_ty
|
||||
end
|
||||
|
||||
function mist.getUnitsLOS(unitset1, altoffset1, unitset2, altoffset2, radius)
|
||||
--log:info("$1, $2, $3, $4, $5", unitset1, altoffset1, unitset2, altoffset2, radius)
|
||||
log:info("$1, $2, $3, $4, $5", unitset1, altoffset1, unitset2, altoffset2, radius)
|
||||
radius = radius or math.huge
|
||||
local unit_info1 = {}
|
||||
local unit_info2 = {}
|
||||
@@ -3610,25 +3566,21 @@ function mist.getUnitsLOS(unitset1, altoffset1, unitset2, altoffset2, radius)
|
||||
-- get the positions all in one step, saves execution time.
|
||||
for unitset1_ind = 1, #unitset1 do
|
||||
local unit1 = Unit.getByName(unitset1[unitset1_ind])
|
||||
if unit1 then
|
||||
local lCat = Object.getCategory(unit1)
|
||||
if ((lCat == 1 and unit1:isActive()) or lCat ~= 1) and unit1:isExist() == true then
|
||||
unit_info1[#unit_info1 + 1] = {}
|
||||
unit_info1[#unit_info1].unit = unit1
|
||||
unit_info1[#unit_info1].pos = unit1:getPosition().p
|
||||
end
|
||||
local lCat = Object.getCategory(unit1)
|
||||
if unit1 and ((lCat == 1 and unit1:isActive()) or lCat ~= 1) and unit:isExist() == true then
|
||||
unit_info1[#unit_info1 + 1] = {}
|
||||
unit_info1[#unit_info1].unit = unit1
|
||||
unit_info1[#unit_info1].pos = unit1:getPosition().p
|
||||
end
|
||||
end
|
||||
|
||||
for unitset2_ind = 1, #unitset2 do
|
||||
local unit2 = Unit.getByName(unitset2[unitset2_ind])
|
||||
if unit2 then
|
||||
local lCat = Object.getCategory(unit2)
|
||||
if ((lCat == 1 and unit2:isActive()) or lCat ~= 1) and unit2:isExist() == true then
|
||||
unit_info2[#unit_info2 + 1] = {}
|
||||
unit_info2[#unit_info2].unit = unit2
|
||||
unit_info2[#unit_info2].pos = unit2:getPosition().p
|
||||
end
|
||||
local lCat = Object.getCategory(unit2)
|
||||
if unit2 and ((lCat == 1 and unit2:isActive()) or lCat ~= 1) and unit:isExist() == true then
|
||||
unit_info2[#unit_info2 + 1] = {}
|
||||
unit_info2[#unit_info2].unit = unit2
|
||||
unit_info2[#unit_info2].pos = unit2:getPosition().p
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4058,14 +4010,13 @@ do -- group functions scope
|
||||
|
||||
if Group.getByName(gpName) and Group.getByName(gpName):isExist() == true then
|
||||
local newGroup = Group.getByName(gpName)
|
||||
local newData = mist.utils.deepCopy(dbData)
|
||||
local newData = {}
|
||||
newData.name = gpName
|
||||
newData.groupId = tonumber(newGroup:getID())
|
||||
newData.category = newGroup:getCategory()
|
||||
newData.groupName = gpName
|
||||
newData.hidden = dbData.hidden
|
||||
|
||||
|
||||
|
||||
if newData.category == 2 then
|
||||
newData.category = 'vehicle'
|
||||
elseif newData.category == 3 then
|
||||
@@ -4837,9 +4788,6 @@ do -- group functions scope
|
||||
highNum = secondNum
|
||||
end
|
||||
local total = 1
|
||||
if highNum > 50 then
|
||||
return math.random(lowNum, highNum)
|
||||
end
|
||||
if math.abs(highNum - lowNum + 1) < 50 then -- if total values is less than 50
|
||||
total = math.modf(50/math.abs(highNum - lowNum + 1)) -- make x copies required to be above 50
|
||||
end
|
||||
@@ -5243,8 +5191,7 @@ do -- mist.util scope
|
||||
|
||||
function mist.utils.getHeadingPoints(point1, point2, north) -- sick of writing this out.
|
||||
if north then
|
||||
local p1 = mist.utils.makeVec3(point1)
|
||||
return mist.utils.getDir(mist.vec.sub(mist.utils.makeVec3(point2), p1), p1)
|
||||
return mist.utils.getDir(mist.vec.sub(mist.utils.makeVec3(point2), mist.utils.makeVec3(point1)), (mist.utils.makeVec3(point1)))
|
||||
else
|
||||
return mist.utils.getDir(mist.vec.sub(mist.utils.makeVec3(point2), mist.utils.makeVec3(point1)))
|
||||
end
|
||||
@@ -5888,8 +5835,8 @@ do -- mist.debug scope
|
||||
log:alert('insufficient libraries to run mist.debug.dump_G, you must disable the sanitization of the io and lfs libraries in ./Scripts/MissionScripting.lua')
|
||||
--trigger.action.outText(errmsg, 10)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--- Write debug data to file.
|
||||
-- This function requires you to disable script sanitization
|
||||
-- in $DCS_ROOT\Scripts\MissionScripting.lua to access lfs and io
|
||||
@@ -7704,10 +7651,7 @@ do
|
||||
--log:warn(s)
|
||||
if type(s) == 'table' then
|
||||
local mType = s.markType
|
||||
--log:echo(s)
|
||||
|
||||
if mType == 'panel' then
|
||||
local markScope = s.markScope or "all"
|
||||
if mType == 'panel' then
|
||||
if markScope == 'coa' then
|
||||
trigger.action.markToCoalition(s.markId, s.text, s.pos, s.markFor, s.readOnly)
|
||||
elseif markScope == 'group' then
|
||||
@@ -7765,15 +7709,10 @@ do
|
||||
|
||||
local function validateColor(val)
|
||||
if type(val) == 'table' then
|
||||
for i = 1, 4 do
|
||||
if val[i] then
|
||||
if type(val[i]) == 'number' and val[i] > 1 then
|
||||
val[i] = val[i]/255 -- convert RGB values from 0-255 to 0-1 equivilent.
|
||||
end
|
||||
else
|
||||
val[i] = 0.8
|
||||
log:warn("index $1 of color to mist.marker.add was missing, defaulted to 0.8", i)
|
||||
end
|
||||
for i = 1, #val do
|
||||
if type(val[i]) == 'number' and val[i] > 1 then
|
||||
val[i] = val[i]/255 -- convert RGB values from 0-255 to 0-1 equivilent.
|
||||
end
|
||||
end
|
||||
elseif type(val) == 'string' then
|
||||
val = mist.utils.hexToRGB(val)
|
||||
@@ -7814,7 +7753,7 @@ do
|
||||
--log:info('create maker DB: $1', e.idx)
|
||||
mist.DBs.markList[e.idx] = {time = e.time, pos = e.pos, groupId = e.groupId, mType = 'panel', text = e.text, markId = e.idx, coalition = e.coalition}
|
||||
if e.unit then
|
||||
mist.DBs.markList[e.idx].unit = e.initiator:getName()
|
||||
mist.DBs.markList[e.idx].unit = e.intiator:getName()
|
||||
end
|
||||
--log:info(mist.marker.list[e.idx])
|
||||
end
|
||||
@@ -7837,7 +7776,7 @@ do
|
||||
else
|
||||
for mEntry, mData in pairs(mist.DBs.markList) do
|
||||
if id == mData.name or id == mData.id then
|
||||
return mData.markId
|
||||
return mData.id
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -7847,16 +7786,11 @@ do
|
||||
|
||||
|
||||
local function removeMark(id)
|
||||
--log:info("Removing Mark: $1", id)
|
||||
--log:info("Removing Mark: $1", id
|
||||
local removed = false
|
||||
if type(id) == 'table' then
|
||||
for ind, val in pairs(id) do
|
||||
local r
|
||||
if type(val) == "table" and val.markId then
|
||||
r = val.markId
|
||||
else
|
||||
r = getMarkId(val)
|
||||
end
|
||||
local r = getMarkId(val)
|
||||
if r then
|
||||
trigger.action.removeMark(r)
|
||||
mist.DBs.markList[r] = nil
|
||||
@@ -7866,11 +7800,9 @@ do
|
||||
|
||||
else
|
||||
local r = getMarkId(id)
|
||||
if r then
|
||||
trigger.action.removeMark(r)
|
||||
mist.DBs.markList[r] = nil
|
||||
removed = true
|
||||
end
|
||||
trigger.action.removeMark(r)
|
||||
mist.DBs.markList[r] = nil
|
||||
removed = true
|
||||
end
|
||||
return removed
|
||||
end
|
||||
@@ -7992,7 +7924,6 @@ do
|
||||
|
||||
if markForCoa then
|
||||
if type(markForCoa) == 'string' then
|
||||
--log:warn("coa is string")
|
||||
if tonumber(markForCoa) then
|
||||
coa = coas[tonumber(markForCoa)]
|
||||
markScope = 'coa'
|
||||
@@ -8007,10 +7938,11 @@ do
|
||||
end
|
||||
elseif type(markForCoa) == 'number' and markForCoa >=-1 and markForCoa <= #coas then
|
||||
coa = markForCoa
|
||||
--log:warn("coa is number")
|
||||
markScope = 'coa'
|
||||
markScore = 'coa'
|
||||
end
|
||||
markFor = coa
|
||||
|
||||
|
||||
|
||||
elseif markFor then
|
||||
if type(markFor) == 'number' then -- groupId
|
||||
if mist.DBs.groupsById[markFor] then
|
||||
@@ -8119,7 +8051,7 @@ do
|
||||
end
|
||||
for i = 1, #markForTable do
|
||||
local newId = iterate()
|
||||
local data = {markId = newId, text = text, pos = pos[i], markScope = markScope, markFor = markForTable[i], markType = 'panel', name = name, readOnly = readOnly, time = timer.getTime()}
|
||||
local data = {markId = newId, text = text, pos = pos[i], markFor = markForTable[i], markType = 'panel', name = name, readOnly = readOnly, time = timer.getTime()}
|
||||
mist.DBs.markList[newId] = data
|
||||
table.insert(list, data)
|
||||
|
||||
@@ -8243,7 +8175,6 @@ do
|
||||
end
|
||||
|
||||
function mist.marker.remove(id)
|
||||
|
||||
return removeMark(id)
|
||||
end
|
||||
|
||||
@@ -8775,13 +8706,6 @@ do -- group tasks scope
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
function mist.insertTaskToWP(wp, task)
|
||||
if not wp.task then
|
||||
wp.task = {["id"] = "ComboTask", ["params"] = {tasks = {}}}
|
||||
end
|
||||
table.insert(wp.task.params.tasks, task)
|
||||
end
|
||||
|
||||
function mist.ground.patrol(gpData, pType, form, speed)
|
||||
local vars = {}
|
||||
@@ -9041,8 +8965,8 @@ do -- group tasks scope
|
||||
minR = mist.utils.get2DDist(avg, zone[i])
|
||||
end
|
||||
end
|
||||
--log:warn('minR: $1', minR)
|
||||
--log:warn('Radius: $1', radius)
|
||||
--log:warn('minR: $1', minR)
|
||||
local lSpawnPos = {}
|
||||
for j = 1, 100 do
|
||||
newCoord = mist.getRandPointInCircle(avg, radius)
|
||||
@@ -9274,7 +9198,7 @@ do -- group tasks scope
|
||||
function mist.groupIsDead(groupName) -- copy more or less from on station
|
||||
local gp = Group.getByName(groupName)
|
||||
if gp then
|
||||
if #gp:getUnits() > 0 and gp:isExist() == true then
|
||||
if #gp:getUnits() > 0 or gp:isExist() == true then
|
||||
return false
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user