mirror of
https://github.com/mrSkortch/MissionScriptingTools.git
synced 2026-07-21 13:13:23 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bc1aeb0875 | |||
| 69190060e5 | |||
| 9bfeca1495 | |||
| 5af7e9d7b4 | |||
| d9f5f24632 | |||
| 838855ed2b | |||
| 71de3f5b53 | |||
| 40100072a8 | |||
| d636f64cbd | |||
| ee76538575 |
Binary file not shown.
@@ -14,8 +14,8 @@ mist = {}
|
|||||||
|
|
||||||
-- don't change these
|
-- don't change these
|
||||||
mist.majorVersion = 4
|
mist.majorVersion = 4
|
||||||
mist.minorVersion = 0
|
mist.minorVersion = 1
|
||||||
mist.build = 55
|
mist.build = 61
|
||||||
|
|
||||||
--------------------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------------------
|
||||||
-- the main area
|
-- the main area
|
||||||
@@ -241,7 +241,7 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--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
|
newTable['timeAdded'] = timer.getAbsTime() -- only on the dynGroupsAdded table. For other reference, see start time
|
||||||
--mist.debug.dumpDBs()
|
--mist.debug.dumpDBs()
|
||||||
--end
|
--end
|
||||||
@@ -254,6 +254,7 @@ do
|
|||||||
local function checkSpawnedEvents()
|
local function checkSpawnedEvents()
|
||||||
if #tempSpawnedUnits > 0 then
|
if #tempSpawnedUnits > 0 then
|
||||||
local groupsToAdd = {}
|
local groupsToAdd = {}
|
||||||
|
local added = false
|
||||||
local ltemp = tempSpawnedUnits
|
local ltemp = tempSpawnedUnits
|
||||||
local ltable = table
|
local ltable = table
|
||||||
|
|
||||||
@@ -265,7 +266,7 @@ do
|
|||||||
local spawnedObj = ltemp[x]
|
local spawnedObj = ltemp[x]
|
||||||
if spawnedObj and spawnedObj:isExist() then
|
if spawnedObj and spawnedObj:isExist() then
|
||||||
local found = false
|
local found = false
|
||||||
for index, name in pairs(groupsToAdd) do
|
for name, val in pairs(groupsToAdd) do
|
||||||
if spawnedObj:getCategory() == 1 then -- normal groups
|
if spawnedObj:getCategory() == 1 then -- normal groups
|
||||||
if mist.stringMatch(spawnedObj:getGroup():getName(), name) == true then
|
if mist.stringMatch(spawnedObj:getGroup():getName(), name) == true then
|
||||||
found = true
|
found = true
|
||||||
@@ -280,26 +281,37 @@ do
|
|||||||
end
|
end
|
||||||
-- for some reason cargo objects are returning as category == 6.
|
-- for some reason cargo objects are returning as category == 6.
|
||||||
if found == false then
|
if found == false then
|
||||||
|
added = true
|
||||||
if spawnedObj:getCategory() == 1 then -- normal groups
|
if spawnedObj:getCategory() == 1 then -- normal groups
|
||||||
groupsToAdd[#groupsToAdd + 1] = spawnedObj:getGroup():getName()
|
groupsToAdd[spawnedObj:getGroup():getName()] = true
|
||||||
elseif spawnedObj:getCategory() == 3 or spawnedObj:getCategory() == 6 then -- static objects
|
elseif spawnedObj:getCategory() == 3 or spawnedObj:getCategory() == 6 then -- static objects
|
||||||
groupsToAdd[#groupsToAdd + 1] = spawnedObj:getName()
|
groupsToAdd[spawnedObj:getName()] = true
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
table.remove(ltemp, x)
|
table.remove(ltemp, x)
|
||||||
if x%updatesPerRun == 0 then
|
if x%updatesPerRun == 0 then
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if added == true then
|
||||||
if #groupsToAdd > 0 then
|
for groupName, val in pairs(groupsToAdd) do
|
||||||
for groupId, groupName in pairs(groupsToAdd) do
|
local dataChanged = false
|
||||||
if not mist.DBs.groupsByName[groupName] or mist.DBs.groupsByName[groupName] and mist.DBs.groupsByName[groupName].startTime + 10 < timer.getAbsTime() then
|
if mist.DBs.groupsByName[groupName] then
|
||||||
|
for _index, data in pairs(mist.DBs.groupsByName[groupName]) do
|
||||||
|
if data.unitName ~= spawnedObj:getName() and data.unitId ~= spawnedObj:getID() and data.type ~= spawnedObj:getTypeName() then
|
||||||
|
dataChanged = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if dataChanged == false then
|
||||||
|
groupsToAdd[groupName] = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if groupsToAdd[groupName] == true or not mist.DBs.groupsByName[groupName] then
|
||||||
writeGroups[#writeGroups + 1] = dbUpdate(groupName)
|
writeGroups[#writeGroups + 1] = dbUpdate(groupName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -309,6 +321,7 @@ do
|
|||||||
|
|
||||||
|
|
||||||
local function updateDBTables()
|
local function updateDBTables()
|
||||||
|
|
||||||
local i = 0
|
local i = 0
|
||||||
for index, newTable in pairs(writeGroups) do
|
for index, newTable in pairs(writeGroups) do
|
||||||
i = i + 1
|
i = i + 1
|
||||||
@@ -492,6 +505,7 @@ do
|
|||||||
newObj.name = staticObj.name
|
newObj.name = staticObj.name
|
||||||
newObj.dead = staticObj.dead
|
newObj.dead = staticObj.dead
|
||||||
newObj.country = staticObj.country
|
newObj.country = staticObj.country
|
||||||
|
newObj.countryId = staticObj.countryId
|
||||||
newObj.clone = staticObj.clone
|
newObj.clone = staticObj.clone
|
||||||
newObj.shape_name = staticObj.shape_name
|
newObj.shape_name = staticObj.shape_name
|
||||||
newObj.canCargo = staticObj.canCargo
|
newObj.canCargo = staticObj.canCargo
|
||||||
@@ -508,21 +522,22 @@ do
|
|||||||
newObj.name = staticObj.units[1].name
|
newObj.name = staticObj.units[1].name
|
||||||
newObj.dead = staticObj.units[1].dead
|
newObj.dead = staticObj.units[1].dead
|
||||||
newObj.country = staticObj.units[1].country
|
newObj.country = staticObj.units[1].country
|
||||||
|
newObj.countryId = staticObj.units[1].countryId
|
||||||
newObj.shape_name = staticObj.units[1].shape_name
|
newObj.shape_name = staticObj.units[1].shape_name
|
||||||
newObj.canCargo = staticObj.units[1].canCargo
|
newObj.canCargo = staticObj.units[1].canCargo
|
||||||
newObj.mass = staticObj.units[1].mass
|
newObj.mass = staticObj.units[1].mass
|
||||||
newObj.categoryStatic = staticObj.units[1].categoryStatic
|
newObj.categoryStatic = staticObj.units[1].categoryStatic
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
newObj.country = staticObj.country
|
|
||||||
|
|
||||||
if not newObj.country then
|
if not newObj.country then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local newCountry
|
local newCountry = newObj.country
|
||||||
for countryName, countryId in pairs(country.id) do
|
if newObj.countryId then
|
||||||
|
newCountry = newObj.countryId
|
||||||
|
end
|
||||||
|
for countryId, countryName in pairs(country.name) do
|
||||||
if type(newObj.country) == 'string' then
|
if type(newObj.country) == 'string' then
|
||||||
if tostring(countryName) == string.upper(newObj.country) then
|
if tostring(countryName) == string.upper(newObj.country) then
|
||||||
newCountry = countryName
|
newCountry = countryName
|
||||||
@@ -546,7 +561,7 @@ do
|
|||||||
|
|
||||||
if newObj.clone or not newObj.name then
|
if newObj.clone or not newObj.name then
|
||||||
mistDynAddIndex = mistDynAddIndex + 1
|
mistDynAddIndex = mistDynAddIndex + 1
|
||||||
newObj.name = (newCountry .. ' static ' .. mistDynAddIndex)
|
newObj.name = (country.name[newCountry] .. ' static ' .. mistDynAddIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not newObj.dead then
|
if not newObj.dead then
|
||||||
@@ -577,13 +592,19 @@ do
|
|||||||
--
|
--
|
||||||
|
|
||||||
|
|
||||||
--env.info('dynAdd')
|
|
||||||
|
--mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, 'newGroupOrig.lua')
|
||||||
local cntry = newGroup.country
|
local cntry = newGroup.country
|
||||||
|
if newGroup.countryId then
|
||||||
|
cntry = newGroup.countryId
|
||||||
|
end
|
||||||
|
|
||||||
local groupType = newGroup.category
|
local groupType = newGroup.category
|
||||||
local newCountry = ''
|
local newCountry = ''
|
||||||
-- validate data
|
-- validate data
|
||||||
for countryName, countryId in pairs(country.id) do
|
for countryId, countryName in pairs(country.name) do
|
||||||
if type(cntry) == 'string' then
|
if type(cntry) == 'string' then
|
||||||
|
cntry = cntry:gsub("%s+", "_")
|
||||||
if tostring(countryName) == string.upper(cntry) then
|
if tostring(countryName) == string.upper(cntry) then
|
||||||
newCountry = countryName
|
newCountry = countryName
|
||||||
end
|
end
|
||||||
@@ -616,7 +637,6 @@ do
|
|||||||
newCat = 'AIRPLANE'
|
newCat = 'AIRPLANE'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local typeName
|
local typeName
|
||||||
if newCat == 'GROUND_UNIT' then
|
if newCat == 'GROUND_UNIT' then
|
||||||
typeName = ' gnd '
|
typeName = ' gnd '
|
||||||
@@ -629,7 +649,6 @@ do
|
|||||||
elseif newCat == 'BUILDING' then
|
elseif newCat == 'BUILDING' then
|
||||||
typeName = ' bld '
|
typeName = ' bld '
|
||||||
end
|
end
|
||||||
|
|
||||||
if newGroup.clone or not newGroup.groupId then
|
if newGroup.clone or not newGroup.groupId then
|
||||||
mistDynAddIndex = mistDynAddIndex + 1
|
mistDynAddIndex = mistDynAddIndex + 1
|
||||||
mistGpId = mistGpId + 1
|
mistGpId = mistGpId + 1
|
||||||
@@ -644,7 +663,7 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
if newGroup.clone and mist.DBs.groupsByName[newGroup.name] or not newGroup.name then
|
if newGroup.clone and mist.DBs.groupsByName[newGroup.name] or not newGroup.name then
|
||||||
newGroup['name'] = tostring(tostring(cntry) .. tostring(typeName) .. mistDynAddIndex)
|
newGroup['name'] = tostring(tostring(country.name[cntry]) .. tostring(typeName) .. mistDynAddIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not newGroup.hidden then
|
if not newGroup.hidden then
|
||||||
@@ -662,8 +681,9 @@ do
|
|||||||
newGroup.start_time = 0
|
newGroup.start_time = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for unitIndex, unitData in pairs(newGroup.units) do
|
|
||||||
|
|
||||||
|
|
||||||
|
for unitIndex, unitData in pairs(newGroup.units) do
|
||||||
local originalName = newGroup.units[unitIndex].unitName or newGroup.units[unitIndex].name
|
local originalName = newGroup.units[unitIndex].unitName or newGroup.units[unitIndex].name
|
||||||
if newGroup.clone or not unitData.unitId then
|
if newGroup.clone or not unitData.unitId then
|
||||||
mistUnitId = mistUnitId + 1
|
mistUnitId = mistUnitId + 1
|
||||||
@@ -720,7 +740,6 @@ do
|
|||||||
mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newGroup.units[unitIndex])
|
mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newGroup.units[unitIndex])
|
||||||
end
|
end
|
||||||
mistAddedGroups[#mistAddedGroups + 1] = mist.utils.deepCopy(newGroup)
|
mistAddedGroups[#mistAddedGroups + 1] = mist.utils.deepCopy(newGroup)
|
||||||
|
|
||||||
if newGroup.route and not newGroup.route.points then
|
if newGroup.route and not newGroup.route.points then
|
||||||
if not newGroup.route.points and newGroup.route[1] then
|
if not newGroup.route.points and newGroup.route[1] then
|
||||||
local copyRoute = newGroup.route
|
local copyRoute = newGroup.route
|
||||||
@@ -916,7 +935,9 @@ end
|
|||||||
|
|
||||||
function mist.utils.makeVec3(Vec2, y)
|
function mist.utils.makeVec3(Vec2, y)
|
||||||
if not Vec2.z then
|
if not Vec2.z then
|
||||||
if not y then
|
if Vec2.alt and not y then
|
||||||
|
y = Vec2.alt
|
||||||
|
elseif not y then
|
||||||
y = 0
|
y = 0
|
||||||
end
|
end
|
||||||
return {x = Vec2.x, y = y, z = Vec2.y}
|
return {x = Vec2.x, y = y, z = Vec2.y}
|
||||||
@@ -956,7 +977,9 @@ end
|
|||||||
-- gets heading-error corrected direction from point along vector vec.
|
-- gets heading-error corrected direction from point along vector vec.
|
||||||
function mist.utils.getDir(vec, point)
|
function mist.utils.getDir(vec, point)
|
||||||
local dir = math.atan2(vec.z, vec.x)
|
local dir = math.atan2(vec.z, vec.x)
|
||||||
|
if point then
|
||||||
dir = dir + mist.getNorthCorrection(point)
|
dir = dir + mist.getNorthCorrection(point)
|
||||||
|
end
|
||||||
if dir < 0 then
|
if dir < 0 then
|
||||||
dir = dir + 2*math.pi -- put dir in range of 0 to 2*pi
|
dir = dir + 2*math.pi -- put dir in range of 0 to 2*pi
|
||||||
end
|
end
|
||||||
@@ -975,7 +998,35 @@ function mist.utils.get3DDist(point1, point2)
|
|||||||
return mist.vec.mag({x = point1.x - point2.x, y = point1.y - point2.y, z = point1.z - point2.z})
|
return mist.vec.mag({x = point1.x - point2.x, y = point1.y - point2.y, z = point1.z - point2.z})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mist.utils.vecToWP(vec)
|
||||||
|
local newWP = {}
|
||||||
|
newWP.x = vec.x
|
||||||
|
newWP.y = vec.y
|
||||||
|
if vec.z then
|
||||||
|
newWP.alt = vec.y
|
||||||
|
newWP.y = vec.z
|
||||||
|
else
|
||||||
|
newWP.alt = land.getHeight({x = vec.x, y = vec.y})
|
||||||
|
end
|
||||||
|
return newWP
|
||||||
|
end
|
||||||
|
|
||||||
|
function mist.utils.unitToWP(pUnit)
|
||||||
|
local unit = mist.utils.deepCopy(pUnit)
|
||||||
|
if type(unit) == 'string' then
|
||||||
|
if Unit.getByName(unit) then
|
||||||
|
unit = Unit.getByName(unit)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if unit:isExist() == true then
|
||||||
|
local new = mist.utils.vecToWP(unit:getPosition().p)
|
||||||
|
new.speed = mist.vec.mag(unit:getVelocity())
|
||||||
|
new.alt_type = "BARO"
|
||||||
|
|
||||||
|
return new
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1005,6 +1056,15 @@ mist.utils.round = function(num, idp)
|
|||||||
return math.floor(num * mult + 0.5) / mult
|
return math.floor(num * mult + 0.5) / mult
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mist.utils.roundTbl = function(tbl, idp)
|
||||||
|
for id, val in pairs(tbl) do
|
||||||
|
if type(val) == 'number' then
|
||||||
|
tbl[id] = mist.utils.round(val, idp)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return tbl
|
||||||
|
end
|
||||||
|
|
||||||
-- porting in Slmod's dostring
|
-- porting in Slmod's dostring
|
||||||
mist.utils.dostring = function(s)
|
mist.utils.dostring = function(s)
|
||||||
local f, err = loadstring(s)
|
local f, err = loadstring(s)
|
||||||
@@ -1521,7 +1581,8 @@ mist.tostringBR = function(az, dist, alt, metric)
|
|||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
mist.getNorthCorrection = function(point) --gets the correction needed for true north
|
mist.getNorthCorrection = function(gPoint) --gets the correction needed for true north
|
||||||
|
local point = mist.utils.deepCopy(gPoint)
|
||||||
if not point.z then --Vec2; convert to Vec3
|
if not point.z then --Vec2; convert to Vec3
|
||||||
point.z = point.y
|
point.z = point.y
|
||||||
point.y = 0
|
point.y = 0
|
||||||
@@ -2034,6 +2095,10 @@ for coa_name, coa_data in pairs(mist.DBs.units) do
|
|||||||
if unit_data.skill and (unit_data.skill == "Client" or unit_data.skill == "Player") then
|
if unit_data.skill and (unit_data.skill == "Client" or unit_data.skill == "Player") then
|
||||||
mist.DBs.humansByName[unit_data.unitName] = mist.utils.deepCopy(unit_data)
|
mist.DBs.humansByName[unit_data.unitName] = mist.utils.deepCopy(unit_data)
|
||||||
mist.DBs.humansById[unit_data.unitId] = mist.utils.deepCopy(unit_data)
|
mist.DBs.humansById[unit_data.unitId] = mist.utils.deepCopy(unit_data)
|
||||||
|
--if Unit.getByName(unit_data.unitName) then
|
||||||
|
-- mist.DBs.activeHumans[unit_data.unitName] = mist.utils.deepCopy(unit_data)
|
||||||
|
-- mist.DBs.activeHumans[unit_data.unitName].playerName = Unit.getByName(unit_data.unitName):getPlayerName()
|
||||||
|
--end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -2158,7 +2223,10 @@ do
|
|||||||
val['objectPos'] = pos.p
|
val['objectPos'] = pos.p
|
||||||
end
|
end
|
||||||
val['objectType'] = mist.DBs.aliveUnits[val.object.id_].category
|
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
|
elseif mist.DBs.removedAliveUnits and mist.DBs.removedAliveUnits[val.object.id_] then -- it didn't exist in alive_units, check old_alive_units
|
||||||
--print('object found in old_alive_units')
|
--print('object found in old_alive_units')
|
||||||
val['objectData'] = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_])
|
val['objectData'] = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_])
|
||||||
@@ -2200,22 +2268,22 @@ do
|
|||||||
|
|
||||||
mist.addEventHandler(addDeadObject)
|
mist.addEventHandler(addDeadObject)
|
||||||
|
|
||||||
|
--[[
|
||||||
--[[local function addClientsToActive(event)
|
local function addClientsToActive(event)
|
||||||
if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT then
|
if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT or event.id == world.event.S_EVENT_BIRTH then
|
||||||
if not mist.DBs.activeHumans[Unit.getName(event.initiator)] then
|
env.info(mist.utils.tableShow(event))
|
||||||
local newU = mist.utils.deepCopy(mist.DBs.unitsByName[Unit.getName(event.initiator)])
|
|
||||||
if Unit.getPlayerName(event.initiator) then
|
if Unit.getPlayerName(event.initiator) then
|
||||||
|
env.info(Unit.getPlayerName(event.initiator))
|
||||||
|
local newU = mist.utils.deepCopy(mist.DBs.unitsByName[Unit.getName(event.initiator)])
|
||||||
newU.playerName = Unit.getPlayerName(event.initiator)
|
newU.playerName = Unit.getPlayerName(event.initiator)
|
||||||
end
|
|
||||||
mist.DBs.activeHumans[Unit.getName(event.initiator)] = newU
|
mist.DBs.activeHumans[Unit.getName(event.initiator)] = newU
|
||||||
|
--trigger.action.outText('added: ' .. Unit.getName(event.initiator), 20)
|
||||||
end
|
end
|
||||||
elseif event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT or event.id == world.event.S_EVENT_DEATH then
|
elseif event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT and event.initiator then
|
||||||
if mist.DBs.activeHumans[Unit.getName(event.initiator)] then
|
if mist.DBs.activeHumans[Unit.getName(event.initiator)] then
|
||||||
mist.DBs.activeHumans[Unit.getName(event.initiator)] = nil
|
mist.DBs.activeHumans[Unit.getName(event.initiator)] = nil
|
||||||
|
-- trigger.action.outText('removed via control: ' .. Unit.getName(event.initiator), 20)
|
||||||
end
|
end
|
||||||
elseif event.id == world.event.S_EVENT_BIRTH then -- do client check
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -3054,6 +3122,7 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
|||||||
interval = {'number', 'nil'},
|
interval = {'number', 'nil'},
|
||||||
toggle = {'boolean', 'nil'},
|
toggle = {'boolean', 'nil'},
|
||||||
unitTableDef = {'table', 'nil'},
|
unitTableDef = {'table', 'nil'},
|
||||||
|
zUnitTableDef = {'table', 'nil'},
|
||||||
}
|
}
|
||||||
|
|
||||||
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_in_moving_zones', type_tbl, vars)
|
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_in_moving_zones', type_tbl, vars)
|
||||||
@@ -3068,15 +3137,24 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
|||||||
local interval = vars.interval or 1
|
local interval = vars.interval or 1
|
||||||
local toggle = vars.toggle or nil
|
local toggle = vars.toggle or nil
|
||||||
local unitTableDef = vars.unitTableDef
|
local unitTableDef = vars.unitTableDef
|
||||||
|
local zUnitTableDef = vars.zUnitTableDef
|
||||||
|
|
||||||
if not units.processed then
|
if not units.processed then
|
||||||
unitTableDef = mist.utils.deepCopy(units)
|
unitTableDef = mist.utils.deepCopy(units)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not zone_units.processed then
|
||||||
|
zUnitTableDef = mist.utils.deepCopy(zone_units)
|
||||||
|
end
|
||||||
|
|
||||||
if (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
|
if (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
|
||||||
units = mist.makeUnitTable(unitTableDef)
|
units = mist.makeUnitTable(unitTableDef)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (zone_units.processed and zone_units.processed < mist.getLastDBUpdateTime()) or not zone_units.processed then -- run unit table short cuts
|
||||||
|
zone_units = mist.makeUnitTable(zUnitTableDef)
|
||||||
|
end
|
||||||
|
|
||||||
if stopflag == -1 or (type(trigger.misc.getUserFlag(stopflag)) == 'number' and trigger.misc.getUserFlag(stopflag) == 0) or (type(trigger.misc.getUserFlag(stopflag)) == 'boolean' and trigger.misc.getUserFlag(stopflag) == false) then
|
if stopflag == -1 or (type(trigger.misc.getUserFlag(stopflag)) == 'number' and trigger.misc.getUserFlag(stopflag) == 0) or (type(trigger.misc.getUserFlag(stopflag)) == 'boolean' and trigger.misc.getUserFlag(stopflag) == false) then
|
||||||
|
|
||||||
local in_zone_units = mist.getUnitsInMovingZones(units, zone_units, radius, zone_type)
|
local in_zone_units = mist.getUnitsInMovingZones(units, zone_units, radius, zone_type)
|
||||||
@@ -3088,7 +3166,7 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
|||||||
end
|
end
|
||||||
-- do another check in case stopflag was set true by this function
|
-- do another check in case stopflag was set true by this function
|
||||||
if (type(trigger.misc.getUserFlag(stopflag)) == 'number' and trigger.misc.getUserFlag(stopflag) == 0) or (type(trigger.misc.getUserFlag(stopflag)) == 'boolean' and trigger.misc.getUserFlag(stopflag) == false) then
|
if (type(trigger.misc.getUserFlag(stopflag)) == 'number' and trigger.misc.getUserFlag(stopflag) == 0) or (type(trigger.misc.getUserFlag(stopflag)) == 'boolean' and trigger.misc.getUserFlag(stopflag) == false) then
|
||||||
mist.scheduleFunction(mist.flagFunc.units_in_moving_zones, {{units = units, zone_units = zone_units, radius = radius, flag = flag, stopflag = stopflag, zone_type = zone_type, req_num = req_num, interval = interval, toggle = toggle}}, timer.getTime() + interval)
|
mist.scheduleFunction(mist.flagFunc.units_in_moving_zones, {{units = units, zone_units = zone_units, radius = radius, flag = flag, stopflag = stopflag, zone_type = zone_type, req_num = req_num, interval = interval, toggle = toggle, unitTableDef = unitTableDef, zUnitTableDef = zUnitTableDef}}, timer.getTime() + interval)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -3199,11 +3277,11 @@ toggle = boolean or nil
|
|||||||
end
|
end
|
||||||
|
|
||||||
if (unitset1.processed and unitset1.processed < mist.getLastDBUpdateTime()) or not unitset1.processed then -- run unit table short cuts
|
if (unitset1.processed and unitset1.processed < mist.getLastDBUpdateTime()) or not unitset1.processed then -- run unit table short cuts
|
||||||
units = mist.makeUnitTable(unitTableDef1)
|
unitset1 = mist.makeUnitTable(unitTableDef1)
|
||||||
end
|
end
|
||||||
|
|
||||||
if (unitset2.processed and unitset2.processed < mist.getLastDBUpdateTime()) or not unitset2.processed then -- run unit table short cuts
|
if (unitset2.processed and unitset2.processed < mist.getLastDBUpdateTime()) or not unitset2.processed then -- run unit table short cuts
|
||||||
units = mist.makeUnitTable(unitTableDef2)
|
unitset2 = mist.makeUnitTable(unitTableDef2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -3392,6 +3470,21 @@ mist.flagFunc.group_alive_more_than = function(vars)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mist.getAvgPoint = function(points)
|
||||||
|
local avgX, avgY, avgZ, totNum = 0, 0, 0, 0
|
||||||
|
for i = 1, #points do
|
||||||
|
local nPoint = mist.utils.makeVec3(points[i])
|
||||||
|
if nPoint.z then
|
||||||
|
avgX = avgX + nPoint.x
|
||||||
|
avgY = avgY + nPoint.y
|
||||||
|
avgZ = avgZ + nPoint.z
|
||||||
|
totNum = totNum + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if totNum ~= 0 then
|
||||||
|
return {x = avgX/totNum, y = avgY/totNum, z = avgZ/totNum}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--Gets the average position of a group of units (by name)
|
--Gets the average position of a group of units (by name)
|
||||||
@@ -3919,7 +4012,7 @@ mist.groupRandomDistSelf = function(gpData, dist, form, heading, speed)
|
|||||||
local pos = mist.getLeadPos(gpData)
|
local pos = mist.getLeadPos(gpData)
|
||||||
local fakeZone = {}
|
local fakeZone = {}
|
||||||
fakeZone.radius = dist or math.random(300, 1000)
|
fakeZone.radius = dist or math.random(300, 1000)
|
||||||
fakeZone.point = {x = pos.x, y, pos.y, z = pos.z}
|
fakeZone.point = {x = pos.x, y = pos.y, z = pos.z}
|
||||||
mist.groupToRandomZone(gpData, fakeZone, form, heading, speed)
|
mist.groupToRandomZone(gpData, fakeZone, form, heading, speed)
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -4080,6 +4173,7 @@ do
|
|||||||
local caSlots = false
|
local caSlots = false
|
||||||
local caMSGtoGroup = false
|
local caMSGtoGroup = false
|
||||||
|
|
||||||
|
if env.mission.groundControl then -- just to be sure?
|
||||||
for index, value in pairs(env.mission.groundControl) do
|
for index, value in pairs(env.mission.groundControl) do
|
||||||
if type(value) == 'table' then
|
if type(value) == 'table' then
|
||||||
for roleName, roleVal in pairs(value) do
|
for roleName, roleVal in pairs(value) do
|
||||||
@@ -4097,6 +4191,7 @@ do
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function mistdisplayV5()
|
local function mistdisplayV5()
|
||||||
--[[thoughts to improve upon
|
--[[thoughts to improve upon
|
||||||
@@ -4193,7 +4288,6 @@ do
|
|||||||
end
|
end
|
||||||
if msgTableText['BLUE'] then
|
if msgTableText['BLUE'] then
|
||||||
trigger.action.outTextForCoalition(coalition.side.BLUE, table.concat(msgTableText['BLUE'].text), msgTableText['BLUE'].displayTime, true)
|
trigger.action.outTextForCoalition(coalition.side.BLUE, table.concat(msgTableText['BLUE'].text), msgTableText['BLUE'].displayTime, true)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -4339,8 +4433,6 @@ do
|
|||||||
if string.lower(forIndex) == 'coa' or string.lower(forIndex) == 'ca' then
|
if string.lower(forIndex) == 'coa' or string.lower(forIndex) == 'ca' then
|
||||||
if listData == string.lower(coaData) or listData == 'all' then
|
if listData == string.lower(coaData) or listData == 'all' then
|
||||||
newMsgFor = msgSpamFilter(newMsgFor, coaData)
|
newMsgFor = msgSpamFilter(newMsgFor, coaData)
|
||||||
--table.insert(newMsgFor, coaData)
|
|
||||||
-- added redca or blueca to list
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -5279,7 +5371,6 @@ mist.teleportToPoint = function(vars) -- main teleport function that all of tele
|
|||||||
if string.lower(newGroupData.category) == 'static' then
|
if string.lower(newGroupData.category) == 'static' then
|
||||||
return mist.dynAddStatic(newGroupData)
|
return mist.dynAddStatic(newGroupData)
|
||||||
end
|
end
|
||||||
|
|
||||||
return mist.dynAdd(newGroupData)
|
return mist.dynAdd(newGroupData)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ mist = {}
|
|||||||
|
|
||||||
-- don't change these
|
-- don't change these
|
||||||
mist.majorVersion = 4
|
mist.majorVersion = 4
|
||||||
mist.minorVersion = 0
|
mist.minorVersion = 1
|
||||||
mist.build = 55
|
mist.build = 61
|
||||||
|
|
||||||
--------------------------------------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------------------------------------
|
||||||
-- the main area
|
-- the main area
|
||||||
@@ -241,7 +241,7 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--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
|
newTable['timeAdded'] = timer.getAbsTime() -- only on the dynGroupsAdded table. For other reference, see start time
|
||||||
--mist.debug.dumpDBs()
|
--mist.debug.dumpDBs()
|
||||||
--end
|
--end
|
||||||
@@ -254,6 +254,7 @@ do
|
|||||||
local function checkSpawnedEvents()
|
local function checkSpawnedEvents()
|
||||||
if #tempSpawnedUnits > 0 then
|
if #tempSpawnedUnits > 0 then
|
||||||
local groupsToAdd = {}
|
local groupsToAdd = {}
|
||||||
|
local added = false
|
||||||
local ltemp = tempSpawnedUnits
|
local ltemp = tempSpawnedUnits
|
||||||
local ltable = table
|
local ltable = table
|
||||||
|
|
||||||
@@ -265,7 +266,7 @@ do
|
|||||||
local spawnedObj = ltemp[x]
|
local spawnedObj = ltemp[x]
|
||||||
if spawnedObj and spawnedObj:isExist() then
|
if spawnedObj and spawnedObj:isExist() then
|
||||||
local found = false
|
local found = false
|
||||||
for index, name in pairs(groupsToAdd) do
|
for name, val in pairs(groupsToAdd) do
|
||||||
if spawnedObj:getCategory() == 1 then -- normal groups
|
if spawnedObj:getCategory() == 1 then -- normal groups
|
||||||
if mist.stringMatch(spawnedObj:getGroup():getName(), name) == true then
|
if mist.stringMatch(spawnedObj:getGroup():getName(), name) == true then
|
||||||
found = true
|
found = true
|
||||||
@@ -280,26 +281,37 @@ do
|
|||||||
end
|
end
|
||||||
-- for some reason cargo objects are returning as category == 6.
|
-- for some reason cargo objects are returning as category == 6.
|
||||||
if found == false then
|
if found == false then
|
||||||
|
added = true
|
||||||
if spawnedObj:getCategory() == 1 then -- normal groups
|
if spawnedObj:getCategory() == 1 then -- normal groups
|
||||||
groupsToAdd[#groupsToAdd + 1] = spawnedObj:getGroup():getName()
|
groupsToAdd[spawnedObj:getGroup():getName()] = true
|
||||||
elseif spawnedObj:getCategory() == 3 or spawnedObj:getCategory() == 6 then -- static objects
|
elseif spawnedObj:getCategory() == 3 or spawnedObj:getCategory() == 6 then -- static objects
|
||||||
groupsToAdd[#groupsToAdd + 1] = spawnedObj:getName()
|
groupsToAdd[spawnedObj:getName()] = true
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
table.remove(ltemp, x)
|
table.remove(ltemp, x)
|
||||||
if x%updatesPerRun == 0 then
|
if x%updatesPerRun == 0 then
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if added == true then
|
||||||
if #groupsToAdd > 0 then
|
for groupName, val in pairs(groupsToAdd) do
|
||||||
for groupId, groupName in pairs(groupsToAdd) do
|
local dataChanged = false
|
||||||
if not mist.DBs.groupsByName[groupName] or mist.DBs.groupsByName[groupName] and mist.DBs.groupsByName[groupName].startTime + 10 < timer.getAbsTime() then
|
if mist.DBs.groupsByName[groupName] then
|
||||||
|
for _index, data in pairs(mist.DBs.groupsByName[groupName]) do
|
||||||
|
if data.unitName ~= spawnedObj:getName() and data.unitId ~= spawnedObj:getID() and data.type ~= spawnedObj:getTypeName() then
|
||||||
|
dataChanged = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if dataChanged == false then
|
||||||
|
groupsToAdd[groupName] = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if groupsToAdd[groupName] == true or not mist.DBs.groupsByName[groupName] then
|
||||||
writeGroups[#writeGroups + 1] = dbUpdate(groupName)
|
writeGroups[#writeGroups + 1] = dbUpdate(groupName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -309,6 +321,7 @@ do
|
|||||||
|
|
||||||
|
|
||||||
local function updateDBTables()
|
local function updateDBTables()
|
||||||
|
|
||||||
local i = 0
|
local i = 0
|
||||||
for index, newTable in pairs(writeGroups) do
|
for index, newTable in pairs(writeGroups) do
|
||||||
i = i + 1
|
i = i + 1
|
||||||
@@ -492,6 +505,7 @@ do
|
|||||||
newObj.name = staticObj.name
|
newObj.name = staticObj.name
|
||||||
newObj.dead = staticObj.dead
|
newObj.dead = staticObj.dead
|
||||||
newObj.country = staticObj.country
|
newObj.country = staticObj.country
|
||||||
|
newObj.countryId = staticObj.countryId
|
||||||
newObj.clone = staticObj.clone
|
newObj.clone = staticObj.clone
|
||||||
newObj.shape_name = staticObj.shape_name
|
newObj.shape_name = staticObj.shape_name
|
||||||
newObj.canCargo = staticObj.canCargo
|
newObj.canCargo = staticObj.canCargo
|
||||||
@@ -508,21 +522,22 @@ do
|
|||||||
newObj.name = staticObj.units[1].name
|
newObj.name = staticObj.units[1].name
|
||||||
newObj.dead = staticObj.units[1].dead
|
newObj.dead = staticObj.units[1].dead
|
||||||
newObj.country = staticObj.units[1].country
|
newObj.country = staticObj.units[1].country
|
||||||
|
newObj.countryId = staticObj.units[1].countryId
|
||||||
newObj.shape_name = staticObj.units[1].shape_name
|
newObj.shape_name = staticObj.units[1].shape_name
|
||||||
newObj.canCargo = staticObj.units[1].canCargo
|
newObj.canCargo = staticObj.units[1].canCargo
|
||||||
newObj.mass = staticObj.units[1].mass
|
newObj.mass = staticObj.units[1].mass
|
||||||
newObj.categoryStatic = staticObj.units[1].categoryStatic
|
newObj.categoryStatic = staticObj.units[1].categoryStatic
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
newObj.country = staticObj.country
|
|
||||||
|
|
||||||
if not newObj.country then
|
if not newObj.country then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local newCountry
|
local newCountry = newObj.country
|
||||||
for countryName, countryId in pairs(country.id) do
|
if newObj.countryId then
|
||||||
|
newCountry = newObj.countryId
|
||||||
|
end
|
||||||
|
for countryId, countryName in pairs(country.name) do
|
||||||
if type(newObj.country) == 'string' then
|
if type(newObj.country) == 'string' then
|
||||||
if tostring(countryName) == string.upper(newObj.country) then
|
if tostring(countryName) == string.upper(newObj.country) then
|
||||||
newCountry = countryName
|
newCountry = countryName
|
||||||
@@ -546,7 +561,7 @@ do
|
|||||||
|
|
||||||
if newObj.clone or not newObj.name then
|
if newObj.clone or not newObj.name then
|
||||||
mistDynAddIndex = mistDynAddIndex + 1
|
mistDynAddIndex = mistDynAddIndex + 1
|
||||||
newObj.name = (newCountry .. ' static ' .. mistDynAddIndex)
|
newObj.name = (country.name[newCountry] .. ' static ' .. mistDynAddIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not newObj.dead then
|
if not newObj.dead then
|
||||||
@@ -577,13 +592,19 @@ do
|
|||||||
--
|
--
|
||||||
|
|
||||||
|
|
||||||
--env.info('dynAdd')
|
|
||||||
|
--mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, 'newGroupOrig.lua')
|
||||||
local cntry = newGroup.country
|
local cntry = newGroup.country
|
||||||
|
if newGroup.countryId then
|
||||||
|
cntry = newGroup.countryId
|
||||||
|
end
|
||||||
|
|
||||||
local groupType = newGroup.category
|
local groupType = newGroup.category
|
||||||
local newCountry = ''
|
local newCountry = ''
|
||||||
-- validate data
|
-- validate data
|
||||||
for countryName, countryId in pairs(country.id) do
|
for countryId, countryName in pairs(country.name) do
|
||||||
if type(cntry) == 'string' then
|
if type(cntry) == 'string' then
|
||||||
|
cntry = cntry:gsub("%s+", "_")
|
||||||
if tostring(countryName) == string.upper(cntry) then
|
if tostring(countryName) == string.upper(cntry) then
|
||||||
newCountry = countryName
|
newCountry = countryName
|
||||||
end
|
end
|
||||||
@@ -616,7 +637,6 @@ do
|
|||||||
newCat = 'AIRPLANE'
|
newCat = 'AIRPLANE'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local typeName
|
local typeName
|
||||||
if newCat == 'GROUND_UNIT' then
|
if newCat == 'GROUND_UNIT' then
|
||||||
typeName = ' gnd '
|
typeName = ' gnd '
|
||||||
@@ -629,7 +649,6 @@ do
|
|||||||
elseif newCat == 'BUILDING' then
|
elseif newCat == 'BUILDING' then
|
||||||
typeName = ' bld '
|
typeName = ' bld '
|
||||||
end
|
end
|
||||||
|
|
||||||
if newGroup.clone or not newGroup.groupId then
|
if newGroup.clone or not newGroup.groupId then
|
||||||
mistDynAddIndex = mistDynAddIndex + 1
|
mistDynAddIndex = mistDynAddIndex + 1
|
||||||
mistGpId = mistGpId + 1
|
mistGpId = mistGpId + 1
|
||||||
@@ -644,7 +663,7 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
if newGroup.clone and mist.DBs.groupsByName[newGroup.name] or not newGroup.name then
|
if newGroup.clone and mist.DBs.groupsByName[newGroup.name] or not newGroup.name then
|
||||||
newGroup['name'] = tostring(tostring(cntry) .. tostring(typeName) .. mistDynAddIndex)
|
newGroup['name'] = tostring(tostring(country.name[cntry]) .. tostring(typeName) .. mistDynAddIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not newGroup.hidden then
|
if not newGroup.hidden then
|
||||||
@@ -662,8 +681,9 @@ do
|
|||||||
newGroup.start_time = 0
|
newGroup.start_time = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for unitIndex, unitData in pairs(newGroup.units) do
|
|
||||||
|
|
||||||
|
|
||||||
|
for unitIndex, unitData in pairs(newGroup.units) do
|
||||||
local originalName = newGroup.units[unitIndex].unitName or newGroup.units[unitIndex].name
|
local originalName = newGroup.units[unitIndex].unitName or newGroup.units[unitIndex].name
|
||||||
if newGroup.clone or not unitData.unitId then
|
if newGroup.clone or not unitData.unitId then
|
||||||
mistUnitId = mistUnitId + 1
|
mistUnitId = mistUnitId + 1
|
||||||
@@ -720,7 +740,6 @@ do
|
|||||||
mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newGroup.units[unitIndex])
|
mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newGroup.units[unitIndex])
|
||||||
end
|
end
|
||||||
mistAddedGroups[#mistAddedGroups + 1] = mist.utils.deepCopy(newGroup)
|
mistAddedGroups[#mistAddedGroups + 1] = mist.utils.deepCopy(newGroup)
|
||||||
|
|
||||||
if newGroup.route and not newGroup.route.points then
|
if newGroup.route and not newGroup.route.points then
|
||||||
if not newGroup.route.points and newGroup.route[1] then
|
if not newGroup.route.points and newGroup.route[1] then
|
||||||
local copyRoute = newGroup.route
|
local copyRoute = newGroup.route
|
||||||
@@ -916,7 +935,9 @@ end
|
|||||||
|
|
||||||
function mist.utils.makeVec3(Vec2, y)
|
function mist.utils.makeVec3(Vec2, y)
|
||||||
if not Vec2.z then
|
if not Vec2.z then
|
||||||
if not y then
|
if Vec2.alt and not y then
|
||||||
|
y = Vec2.alt
|
||||||
|
elseif not y then
|
||||||
y = 0
|
y = 0
|
||||||
end
|
end
|
||||||
return {x = Vec2.x, y = y, z = Vec2.y}
|
return {x = Vec2.x, y = y, z = Vec2.y}
|
||||||
@@ -956,7 +977,9 @@ end
|
|||||||
-- gets heading-error corrected direction from point along vector vec.
|
-- gets heading-error corrected direction from point along vector vec.
|
||||||
function mist.utils.getDir(vec, point)
|
function mist.utils.getDir(vec, point)
|
||||||
local dir = math.atan2(vec.z, vec.x)
|
local dir = math.atan2(vec.z, vec.x)
|
||||||
|
if point then
|
||||||
dir = dir + mist.getNorthCorrection(point)
|
dir = dir + mist.getNorthCorrection(point)
|
||||||
|
end
|
||||||
if dir < 0 then
|
if dir < 0 then
|
||||||
dir = dir + 2*math.pi -- put dir in range of 0 to 2*pi
|
dir = dir + 2*math.pi -- put dir in range of 0 to 2*pi
|
||||||
end
|
end
|
||||||
@@ -975,7 +998,35 @@ function mist.utils.get3DDist(point1, point2)
|
|||||||
return mist.vec.mag({x = point1.x - point2.x, y = point1.y - point2.y, z = point1.z - point2.z})
|
return mist.vec.mag({x = point1.x - point2.x, y = point1.y - point2.y, z = point1.z - point2.z})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function mist.utils.vecToWP(vec)
|
||||||
|
local newWP = {}
|
||||||
|
newWP.x = vec.x
|
||||||
|
newWP.y = vec.y
|
||||||
|
if vec.z then
|
||||||
|
newWP.alt = vec.y
|
||||||
|
newWP.y = vec.z
|
||||||
|
else
|
||||||
|
newWP.alt = land.getHeight({x = vec.x, y = vec.y})
|
||||||
|
end
|
||||||
|
return newWP
|
||||||
|
end
|
||||||
|
|
||||||
|
function mist.utils.unitToWP(pUnit)
|
||||||
|
local unit = mist.utils.deepCopy(pUnit)
|
||||||
|
if type(unit) == 'string' then
|
||||||
|
if Unit.getByName(unit) then
|
||||||
|
unit = Unit.getByName(unit)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if unit:isExist() == true then
|
||||||
|
local new = mist.utils.vecToWP(unit:getPosition().p)
|
||||||
|
new.speed = mist.vec.mag(unit:getVelocity())
|
||||||
|
new.alt_type = "BARO"
|
||||||
|
|
||||||
|
return new
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1005,6 +1056,15 @@ mist.utils.round = function(num, idp)
|
|||||||
return math.floor(num * mult + 0.5) / mult
|
return math.floor(num * mult + 0.5) / mult
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mist.utils.roundTbl = function(tbl, idp)
|
||||||
|
for id, val in pairs(tbl) do
|
||||||
|
if type(val) == 'number' then
|
||||||
|
tbl[id] = mist.utils.round(val, idp)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return tbl
|
||||||
|
end
|
||||||
|
|
||||||
-- porting in Slmod's dostring
|
-- porting in Slmod's dostring
|
||||||
mist.utils.dostring = function(s)
|
mist.utils.dostring = function(s)
|
||||||
local f, err = loadstring(s)
|
local f, err = loadstring(s)
|
||||||
@@ -1521,7 +1581,8 @@ mist.tostringBR = function(az, dist, alt, metric)
|
|||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
||||||
mist.getNorthCorrection = function(point) --gets the correction needed for true north
|
mist.getNorthCorrection = function(gPoint) --gets the correction needed for true north
|
||||||
|
local point = mist.utils.deepCopy(gPoint)
|
||||||
if not point.z then --Vec2; convert to Vec3
|
if not point.z then --Vec2; convert to Vec3
|
||||||
point.z = point.y
|
point.z = point.y
|
||||||
point.y = 0
|
point.y = 0
|
||||||
@@ -2034,6 +2095,10 @@ for coa_name, coa_data in pairs(mist.DBs.units) do
|
|||||||
if unit_data.skill and (unit_data.skill == "Client" or unit_data.skill == "Player") then
|
if unit_data.skill and (unit_data.skill == "Client" or unit_data.skill == "Player") then
|
||||||
mist.DBs.humansByName[unit_data.unitName] = mist.utils.deepCopy(unit_data)
|
mist.DBs.humansByName[unit_data.unitName] = mist.utils.deepCopy(unit_data)
|
||||||
mist.DBs.humansById[unit_data.unitId] = mist.utils.deepCopy(unit_data)
|
mist.DBs.humansById[unit_data.unitId] = mist.utils.deepCopy(unit_data)
|
||||||
|
--if Unit.getByName(unit_data.unitName) then
|
||||||
|
-- mist.DBs.activeHumans[unit_data.unitName] = mist.utils.deepCopy(unit_data)
|
||||||
|
-- mist.DBs.activeHumans[unit_data.unitName].playerName = Unit.getByName(unit_data.unitName):getPlayerName()
|
||||||
|
--end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -2158,7 +2223,10 @@ do
|
|||||||
val['objectPos'] = pos.p
|
val['objectPos'] = pos.p
|
||||||
end
|
end
|
||||||
val['objectType'] = mist.DBs.aliveUnits[val.object.id_].category
|
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
|
elseif mist.DBs.removedAliveUnits and mist.DBs.removedAliveUnits[val.object.id_] then -- it didn't exist in alive_units, check old_alive_units
|
||||||
--print('object found in old_alive_units')
|
--print('object found in old_alive_units')
|
||||||
val['objectData'] = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_])
|
val['objectData'] = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_])
|
||||||
@@ -2200,22 +2268,22 @@ do
|
|||||||
|
|
||||||
mist.addEventHandler(addDeadObject)
|
mist.addEventHandler(addDeadObject)
|
||||||
|
|
||||||
|
--[[
|
||||||
--[[local function addClientsToActive(event)
|
local function addClientsToActive(event)
|
||||||
if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT then
|
if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT or event.id == world.event.S_EVENT_BIRTH then
|
||||||
if not mist.DBs.activeHumans[Unit.getName(event.initiator)] then
|
env.info(mist.utils.tableShow(event))
|
||||||
local newU = mist.utils.deepCopy(mist.DBs.unitsByName[Unit.getName(event.initiator)])
|
|
||||||
if Unit.getPlayerName(event.initiator) then
|
if Unit.getPlayerName(event.initiator) then
|
||||||
|
env.info(Unit.getPlayerName(event.initiator))
|
||||||
|
local newU = mist.utils.deepCopy(mist.DBs.unitsByName[Unit.getName(event.initiator)])
|
||||||
newU.playerName = Unit.getPlayerName(event.initiator)
|
newU.playerName = Unit.getPlayerName(event.initiator)
|
||||||
end
|
|
||||||
mist.DBs.activeHumans[Unit.getName(event.initiator)] = newU
|
mist.DBs.activeHumans[Unit.getName(event.initiator)] = newU
|
||||||
|
--trigger.action.outText('added: ' .. Unit.getName(event.initiator), 20)
|
||||||
end
|
end
|
||||||
elseif event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT or event.id == world.event.S_EVENT_DEATH then
|
elseif event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT and event.initiator then
|
||||||
if mist.DBs.activeHumans[Unit.getName(event.initiator)] then
|
if mist.DBs.activeHumans[Unit.getName(event.initiator)] then
|
||||||
mist.DBs.activeHumans[Unit.getName(event.initiator)] = nil
|
mist.DBs.activeHumans[Unit.getName(event.initiator)] = nil
|
||||||
|
-- trigger.action.outText('removed via control: ' .. Unit.getName(event.initiator), 20)
|
||||||
end
|
end
|
||||||
elseif event.id == world.event.S_EVENT_BIRTH then -- do client check
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -3054,6 +3122,7 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
|||||||
interval = {'number', 'nil'},
|
interval = {'number', 'nil'},
|
||||||
toggle = {'boolean', 'nil'},
|
toggle = {'boolean', 'nil'},
|
||||||
unitTableDef = {'table', 'nil'},
|
unitTableDef = {'table', 'nil'},
|
||||||
|
zUnitTableDef = {'table', 'nil'},
|
||||||
}
|
}
|
||||||
|
|
||||||
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_in_moving_zones', type_tbl, vars)
|
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_in_moving_zones', type_tbl, vars)
|
||||||
@@ -3068,15 +3137,24 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
|||||||
local interval = vars.interval or 1
|
local interval = vars.interval or 1
|
||||||
local toggle = vars.toggle or nil
|
local toggle = vars.toggle or nil
|
||||||
local unitTableDef = vars.unitTableDef
|
local unitTableDef = vars.unitTableDef
|
||||||
|
local zUnitTableDef = vars.zUnitTableDef
|
||||||
|
|
||||||
if not units.processed then
|
if not units.processed then
|
||||||
unitTableDef = mist.utils.deepCopy(units)
|
unitTableDef = mist.utils.deepCopy(units)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not zone_units.processed then
|
||||||
|
zUnitTableDef = mist.utils.deepCopy(zone_units)
|
||||||
|
end
|
||||||
|
|
||||||
if (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
|
if (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
|
||||||
units = mist.makeUnitTable(unitTableDef)
|
units = mist.makeUnitTable(unitTableDef)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (zone_units.processed and zone_units.processed < mist.getLastDBUpdateTime()) or not zone_units.processed then -- run unit table short cuts
|
||||||
|
zone_units = mist.makeUnitTable(zUnitTableDef)
|
||||||
|
end
|
||||||
|
|
||||||
if stopflag == -1 or (type(trigger.misc.getUserFlag(stopflag)) == 'number' and trigger.misc.getUserFlag(stopflag) == 0) or (type(trigger.misc.getUserFlag(stopflag)) == 'boolean' and trigger.misc.getUserFlag(stopflag) == false) then
|
if stopflag == -1 or (type(trigger.misc.getUserFlag(stopflag)) == 'number' and trigger.misc.getUserFlag(stopflag) == 0) or (type(trigger.misc.getUserFlag(stopflag)) == 'boolean' and trigger.misc.getUserFlag(stopflag) == false) then
|
||||||
|
|
||||||
local in_zone_units = mist.getUnitsInMovingZones(units, zone_units, radius, zone_type)
|
local in_zone_units = mist.getUnitsInMovingZones(units, zone_units, radius, zone_type)
|
||||||
@@ -3088,7 +3166,7 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
|||||||
end
|
end
|
||||||
-- do another check in case stopflag was set true by this function
|
-- do another check in case stopflag was set true by this function
|
||||||
if (type(trigger.misc.getUserFlag(stopflag)) == 'number' and trigger.misc.getUserFlag(stopflag) == 0) or (type(trigger.misc.getUserFlag(stopflag)) == 'boolean' and trigger.misc.getUserFlag(stopflag) == false) then
|
if (type(trigger.misc.getUserFlag(stopflag)) == 'number' and trigger.misc.getUserFlag(stopflag) == 0) or (type(trigger.misc.getUserFlag(stopflag)) == 'boolean' and trigger.misc.getUserFlag(stopflag) == false) then
|
||||||
mist.scheduleFunction(mist.flagFunc.units_in_moving_zones, {{units = units, zone_units = zone_units, radius = radius, flag = flag, stopflag = stopflag, zone_type = zone_type, req_num = req_num, interval = interval, toggle = toggle}}, timer.getTime() + interval)
|
mist.scheduleFunction(mist.flagFunc.units_in_moving_zones, {{units = units, zone_units = zone_units, radius = radius, flag = flag, stopflag = stopflag, zone_type = zone_type, req_num = req_num, interval = interval, toggle = toggle, unitTableDef = unitTableDef, zUnitTableDef = zUnitTableDef}}, timer.getTime() + interval)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -3199,11 +3277,11 @@ toggle = boolean or nil
|
|||||||
end
|
end
|
||||||
|
|
||||||
if (unitset1.processed and unitset1.processed < mist.getLastDBUpdateTime()) or not unitset1.processed then -- run unit table short cuts
|
if (unitset1.processed and unitset1.processed < mist.getLastDBUpdateTime()) or not unitset1.processed then -- run unit table short cuts
|
||||||
units = mist.makeUnitTable(unitTableDef1)
|
unitset1 = mist.makeUnitTable(unitTableDef1)
|
||||||
end
|
end
|
||||||
|
|
||||||
if (unitset2.processed and unitset2.processed < mist.getLastDBUpdateTime()) or not unitset2.processed then -- run unit table short cuts
|
if (unitset2.processed and unitset2.processed < mist.getLastDBUpdateTime()) or not unitset2.processed then -- run unit table short cuts
|
||||||
units = mist.makeUnitTable(unitTableDef2)
|
unitset2 = mist.makeUnitTable(unitTableDef2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -3392,6 +3470,21 @@ mist.flagFunc.group_alive_more_than = function(vars)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mist.getAvgPoint = function(points)
|
||||||
|
local avgX, avgY, avgZ, totNum = 0, 0, 0, 0
|
||||||
|
for i = 1, #points do
|
||||||
|
local nPoint = mist.utils.makeVec3(points[i])
|
||||||
|
if nPoint.z then
|
||||||
|
avgX = avgX + nPoint.x
|
||||||
|
avgY = avgY + nPoint.y
|
||||||
|
avgZ = avgZ + nPoint.z
|
||||||
|
totNum = totNum + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if totNum ~= 0 then
|
||||||
|
return {x = avgX/totNum, y = avgY/totNum, z = avgZ/totNum}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--Gets the average position of a group of units (by name)
|
--Gets the average position of a group of units (by name)
|
||||||
@@ -3919,7 +4012,7 @@ mist.groupRandomDistSelf = function(gpData, dist, form, heading, speed)
|
|||||||
local pos = mist.getLeadPos(gpData)
|
local pos = mist.getLeadPos(gpData)
|
||||||
local fakeZone = {}
|
local fakeZone = {}
|
||||||
fakeZone.radius = dist or math.random(300, 1000)
|
fakeZone.radius = dist or math.random(300, 1000)
|
||||||
fakeZone.point = {x = pos.x, y, pos.y, z = pos.z}
|
fakeZone.point = {x = pos.x, y = pos.y, z = pos.z}
|
||||||
mist.groupToRandomZone(gpData, fakeZone, form, heading, speed)
|
mist.groupToRandomZone(gpData, fakeZone, form, heading, speed)
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -4080,6 +4173,7 @@ do
|
|||||||
local caSlots = false
|
local caSlots = false
|
||||||
local caMSGtoGroup = false
|
local caMSGtoGroup = false
|
||||||
|
|
||||||
|
if env.mission.groundControl then -- just to be sure?
|
||||||
for index, value in pairs(env.mission.groundControl) do
|
for index, value in pairs(env.mission.groundControl) do
|
||||||
if type(value) == 'table' then
|
if type(value) == 'table' then
|
||||||
for roleName, roleVal in pairs(value) do
|
for roleName, roleVal in pairs(value) do
|
||||||
@@ -4097,6 +4191,7 @@ do
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function mistdisplayV5()
|
local function mistdisplayV5()
|
||||||
--[[thoughts to improve upon
|
--[[thoughts to improve upon
|
||||||
@@ -4193,7 +4288,6 @@ do
|
|||||||
end
|
end
|
||||||
if msgTableText['BLUE'] then
|
if msgTableText['BLUE'] then
|
||||||
trigger.action.outTextForCoalition(coalition.side.BLUE, table.concat(msgTableText['BLUE'].text), msgTableText['BLUE'].displayTime, true)
|
trigger.action.outTextForCoalition(coalition.side.BLUE, table.concat(msgTableText['BLUE'].text), msgTableText['BLUE'].displayTime, true)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -4339,8 +4433,6 @@ do
|
|||||||
if string.lower(forIndex) == 'coa' or string.lower(forIndex) == 'ca' then
|
if string.lower(forIndex) == 'coa' or string.lower(forIndex) == 'ca' then
|
||||||
if listData == string.lower(coaData) or listData == 'all' then
|
if listData == string.lower(coaData) or listData == 'all' then
|
||||||
newMsgFor = msgSpamFilter(newMsgFor, coaData)
|
newMsgFor = msgSpamFilter(newMsgFor, coaData)
|
||||||
--table.insert(newMsgFor, coaData)
|
|
||||||
-- added redca or blueca to list
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -5279,7 +5371,6 @@ mist.teleportToPoint = function(vars) -- main teleport function that all of tele
|
|||||||
if string.lower(newGroupData.category) == 'static' then
|
if string.lower(newGroupData.category) == 'static' then
|
||||||
return mist.dynAddStatic(newGroupData)
|
return mist.dynAddStatic(newGroupData)
|
||||||
end
|
end
|
||||||
|
|
||||||
return mist.dynAdd(newGroupData)
|
return mist.dynAdd(newGroupData)
|
||||||
|
|
||||||
end
|
end
|
||||||
Binary file not shown.
@@ -1,3 +1,40 @@
|
|||||||
|
v61 - 4.1 release
|
||||||
|
-Fixed locality issue with unitToWP
|
||||||
|
|
||||||
|
v60
|
||||||
|
-Fixed issue with country names in the editor not matching enum country
|
||||||
|
name values. For example "Best Korea" could not match with "BEST_KOREA".
|
||||||
|
Thanks lukrop of this fix
|
||||||
|
-Fixed locality issue with mist.getNorthCorrection
|
||||||
|
-Added function mist.utils.unitToWP
|
||||||
|
-added function mist.utils.vecToWP
|
||||||
|
|
||||||
|
Both of these functions deal with creating a WP table from the passed
|
||||||
|
values. unitToWP also returns a speed variable based on the current
|
||||||
|
velocity of the unit
|
||||||
|
|
||||||
|
v59
|
||||||
|
-removed the new 3rd variable from mist.utils.getDir and just made the 2nd variable optional instead
|
||||||
|
-Added check to DB update functions to only update if data from the group has changed from what is currently in the DB. This fixes an issue I had where some data was lost if you spawned a group normally after mission start and then used a respawn, clone, or teleport function on said group
|
||||||
|
-fixed issue with dynAdd functions naming a group with the country ID insead of country name
|
||||||
|
-added mist.getAvgPoint(). Function is similar to mist.getAvgPos except it uses raw vec2/3 coordinates instead of units
|
||||||
|
-added mist.utils.roundTbl() Has the same input values as mist.utils.round except it accepts a table and it rounds all numbers in the first level of the table to the passed percision.
|
||||||
|
|
||||||
|
v58
|
||||||
|
-added optional variable to mist.utils.getDir() If present this function will return the "raw" heading, this is useful in assigning the heading variable within a task.
|
||||||
|
-mist.utils.makeVec3 now supports being given a table in WP format. Specifically it now coverts a table {x, y, alt) to vec3
|
||||||
|
|
||||||
|
|
||||||
|
v57
|
||||||
|
-fixed bug with groupRandomDistSelf improperly declaring the y variable
|
||||||
|
-fixed flagFunc.units_in_moving_zones not checking for a unitNameTable for the zone_units
|
||||||
|
-fixed bug in flagFunc.units_LOS when given a unitNameTable for both entries.
|
||||||
|
|
||||||
|
v56
|
||||||
|
-fixed bug with dynAdd and dynAddStatic not recognizing new countries in dcs 1.5
|
||||||
|
|
||||||
|
v55
|
||||||
|
- Release v4
|
||||||
v54
|
v54
|
||||||
-added a check when adding unitTypes for messages to figure out the correct in-game unit name for a given unit. For example the Mi-8 helicopter is always displayed as 'Mi-8MTV2', however its actual in game name is 'Mi-8MT', this feature allows for you to list 'Mi-8MTV2', 'Mi-8MTV', or 'Mi-8' to get messages sent to the Mi-8. Shortcut also works for the relevant aircraft 'Mig-21', 'Mig-15', 'FW-190', and 'Bf-109'.
|
-added a check when adding unitTypes for messages to figure out the correct in-game unit name for a given unit. For example the Mi-8 helicopter is always displayed as 'Mi-8MTV2', however its actual in game name is 'Mi-8MT', this feature allows for you to list 'Mi-8MTV2', 'Mi-8MTV', or 'Mi-8' to get messages sent to the Mi-8. Shortcut also works for the relevant aircraft 'Mig-21', 'Mig-15', 'FW-190', and 'Bf-109'.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user