mirror of
https://github.com/mrSkortch/MissionScriptingTools.git
synced 2026-07-18 22:54:58 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bc1aeb0875 | |||
| 69190060e5 | |||
| 9bfeca1495 | |||
| 5af7e9d7b4 | |||
| d9f5f24632 | |||
| 838855ed2b | |||
| 71de3f5b53 | |||
| 40100072a8 | |||
| d636f64cbd | |||
| ee76538575 | |||
| a8b7e5eb6c | |||
| 6c2b091e94 | |||
| 5e40137af4 | |||
| 8dfd4ec355 | |||
| 065c28a697 | |||
| 4ff458534f | |||
| 29c93002fa | |||
| 2f02c4041c | |||
| 9486c56d4b | |||
| 278216aabb | |||
| 60d83c3bc3 | |||
| 08e4cb6334 |
Binary file not shown.
@@ -1,4 +1,11 @@
|
||||
--[[
|
||||
Links:
|
||||
|
||||
ED Forum Thread: http://forums.eagle.ru/showthread.php?t=98616
|
||||
|
||||
Github
|
||||
Development: https://github.com/mrSkortch/MissionScriptingTools/tree/development
|
||||
Official Release: https://github.com/mrSkortch/MissionScriptingTools/tree/master
|
||||
|
||||
]]
|
||||
|
||||
@@ -6,11 +13,9 @@
|
||||
mist = {}
|
||||
|
||||
-- don't change these
|
||||
mist.majorVersion = 3
|
||||
mist.minorVersion = 7
|
||||
mist.build = 48
|
||||
|
||||
|
||||
mist.majorVersion = 4
|
||||
mist.minorVersion = 1
|
||||
mist.build = 61
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------
|
||||
-- the main area
|
||||
@@ -21,6 +26,7 @@ do
|
||||
local mistAddedObjects = {} -- mist.dynAdd unit data added here
|
||||
local mistAddedGroups = {} -- mist.dynAdd groupdata added here
|
||||
local writeGroups = {}
|
||||
local lastUpdateTime = 0
|
||||
|
||||
local function update_alive_units() -- coroutine function
|
||||
local lalive_units = mist.DBs.aliveUnits -- local references for faster execution
|
||||
@@ -235,7 +241,7 @@ do
|
||||
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
|
||||
--mist.debug.dumpDBs()
|
||||
--end
|
||||
@@ -248,6 +254,7 @@ do
|
||||
local function checkSpawnedEvents()
|
||||
if #tempSpawnedUnits > 0 then
|
||||
local groupsToAdd = {}
|
||||
local added = false
|
||||
local ltemp = tempSpawnedUnits
|
||||
local ltable = table
|
||||
|
||||
@@ -259,7 +266,7 @@ do
|
||||
local spawnedObj = ltemp[x]
|
||||
if spawnedObj and spawnedObj:isExist() then
|
||||
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 mist.stringMatch(spawnedObj:getGroup():getName(), name) == true then
|
||||
found = true
|
||||
@@ -274,26 +281,37 @@ do
|
||||
end
|
||||
-- for some reason cargo objects are returning as category == 6.
|
||||
if found == false then
|
||||
added = true
|
||||
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
|
||||
groupsToAdd[#groupsToAdd + 1] = spawnedObj:getName()
|
||||
groupsToAdd[spawnedObj:getName()] = true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
table.remove(ltemp, x)
|
||||
if x%updatesPerRun == 0 then
|
||||
coroutine.yield()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
if #groupsToAdd > 0 then
|
||||
for groupId, groupName in pairs(groupsToAdd) do
|
||||
if not mist.DBs.groupsByName[groupName] or mist.DBs.groupsByName[groupName] and mist.DBs.groupsByName[groupName].startTime + 10 < timer.getAbsTime() then
|
||||
|
||||
if added == true then
|
||||
for groupName, val in pairs(groupsToAdd) do
|
||||
local dataChanged = false
|
||||
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)
|
||||
end
|
||||
end
|
||||
@@ -303,6 +321,7 @@ do
|
||||
|
||||
|
||||
local function updateDBTables()
|
||||
|
||||
local i = 0
|
||||
for index, newTable in pairs(writeGroups) do
|
||||
i = i + 1
|
||||
@@ -369,6 +388,9 @@ do
|
||||
coroutine.yield()
|
||||
end
|
||||
end
|
||||
if timer.getTime() > lastUpdateTime then
|
||||
lastUpdateTime = timer.getTime()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -438,6 +460,7 @@ do
|
||||
local mistUnitId = 7000
|
||||
local mistDynAddIndex = 1
|
||||
|
||||
|
||||
mist.nextGroupId = 1
|
||||
mist.nextUnitId = 1
|
||||
|
||||
@@ -457,6 +480,10 @@ do
|
||||
return mist.nextGroupId
|
||||
end
|
||||
|
||||
mist.getLastDBUpdateTime = function()
|
||||
return lastUpdateTime
|
||||
end
|
||||
|
||||
local function groupSpawned(event)
|
||||
if event.id == world.event.S_EVENT_BIRTH and timer.getTime0() < timer.getAbsTime()then -- dont need to add units spawned in at the start of the mission if mist is loaded in init line
|
||||
table.insert(tempSpawnedUnits,(event.initiator))
|
||||
@@ -478,6 +505,7 @@ do
|
||||
newObj.name = staticObj.name
|
||||
newObj.dead = staticObj.dead
|
||||
newObj.country = staticObj.country
|
||||
newObj.countryId = staticObj.countryId
|
||||
newObj.clone = staticObj.clone
|
||||
newObj.shape_name = staticObj.shape_name
|
||||
newObj.canCargo = staticObj.canCargo
|
||||
@@ -494,21 +522,22 @@ do
|
||||
newObj.name = staticObj.units[1].name
|
||||
newObj.dead = staticObj.units[1].dead
|
||||
newObj.country = staticObj.units[1].country
|
||||
newObj.countryId = staticObj.units[1].countryId
|
||||
newObj.shape_name = staticObj.units[1].shape_name
|
||||
newObj.canCargo = staticObj.units[1].canCargo
|
||||
newObj.mass = staticObj.units[1].mass
|
||||
newObj.categoryStatic = staticObj.units[1].categoryStatic
|
||||
end
|
||||
|
||||
|
||||
newObj.country = staticObj.country
|
||||
|
||||
if not newObj.country then
|
||||
return false
|
||||
end
|
||||
|
||||
local newCountry
|
||||
for countryName, countryId in pairs(country.id) do
|
||||
local newCountry = newObj.country
|
||||
if newObj.countryId then
|
||||
newCountry = newObj.countryId
|
||||
end
|
||||
for countryId, countryName in pairs(country.name) do
|
||||
if type(newObj.country) == 'string' then
|
||||
if tostring(countryName) == string.upper(newObj.country) then
|
||||
newCountry = countryName
|
||||
@@ -532,7 +561,7 @@ do
|
||||
|
||||
if newObj.clone or not newObj.name then
|
||||
mistDynAddIndex = mistDynAddIndex + 1
|
||||
newObj.name = (newCountry .. ' static ' .. mistDynAddIndex)
|
||||
newObj.name = (country.name[newCountry] .. ' static ' .. mistDynAddIndex)
|
||||
end
|
||||
|
||||
if not newObj.dead then
|
||||
@@ -563,13 +592,19 @@ do
|
||||
--
|
||||
|
||||
|
||||
--env.info('dynAdd')
|
||||
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, 'newGroupOrig.lua')
|
||||
local cntry = newGroup.country
|
||||
if newGroup.countryId then
|
||||
cntry = newGroup.countryId
|
||||
end
|
||||
|
||||
local groupType = newGroup.category
|
||||
local newCountry = ''
|
||||
-- validate data
|
||||
for countryName, countryId in pairs(country.id) do
|
||||
for countryId, countryName in pairs(country.name) do
|
||||
if type(cntry) == 'string' then
|
||||
cntry = cntry:gsub("%s+", "_")
|
||||
if tostring(countryName) == string.upper(cntry) then
|
||||
newCountry = countryName
|
||||
end
|
||||
@@ -602,7 +637,6 @@ do
|
||||
newCat = 'AIRPLANE'
|
||||
end
|
||||
end
|
||||
|
||||
local typeName
|
||||
if newCat == 'GROUND_UNIT' then
|
||||
typeName = ' gnd '
|
||||
@@ -615,7 +649,6 @@ do
|
||||
elseif newCat == 'BUILDING' then
|
||||
typeName = ' bld '
|
||||
end
|
||||
|
||||
if newGroup.clone or not newGroup.groupId then
|
||||
mistDynAddIndex = mistDynAddIndex + 1
|
||||
mistGpId = mistGpId + 1
|
||||
@@ -630,7 +663,7 @@ do
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
if not newGroup.hidden then
|
||||
@@ -648,8 +681,9 @@ do
|
||||
newGroup.start_time = 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for unitIndex, unitData in pairs(newGroup.units) do
|
||||
|
||||
local originalName = newGroup.units[unitIndex].unitName or newGroup.units[unitIndex].name
|
||||
if newGroup.clone or not unitData.unitId then
|
||||
mistUnitId = mistUnitId + 1
|
||||
@@ -706,7 +740,6 @@ do
|
||||
mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newGroup.units[unitIndex])
|
||||
end
|
||||
mistAddedGroups[#mistAddedGroups + 1] = mist.utils.deepCopy(newGroup)
|
||||
|
||||
if newGroup.route and not newGroup.route.points then
|
||||
if not newGroup.route.points and newGroup.route[1] then
|
||||
local copyRoute = newGroup.route
|
||||
@@ -902,7 +935,9 @@ end
|
||||
|
||||
function mist.utils.makeVec3(Vec2, y)
|
||||
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
|
||||
end
|
||||
return {x = Vec2.x, y = y, z = Vec2.y}
|
||||
@@ -942,7 +977,9 @@ end
|
||||
-- gets heading-error corrected direction from point along vector vec.
|
||||
function mist.utils.getDir(vec, point)
|
||||
local dir = math.atan2(vec.z, vec.x)
|
||||
dir = dir + mist.getNorthCorrection(point)
|
||||
if point then
|
||||
dir = dir + mist.getNorthCorrection(point)
|
||||
end
|
||||
if dir < 0 then
|
||||
dir = dir + 2*math.pi -- put dir in range of 0 to 2*pi
|
||||
end
|
||||
@@ -961,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})
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -991,6 +1056,15 @@ mist.utils.round = function(num, idp)
|
||||
return math.floor(num * mult + 0.5) / mult
|
||||
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
|
||||
mist.utils.dostring = function(s)
|
||||
local f, err = loadstring(s)
|
||||
@@ -1507,7 +1581,8 @@ mist.tostringBR = function(az, dist, alt, metric)
|
||||
return s
|
||||
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
|
||||
point.z = point.y
|
||||
point.y = 0
|
||||
@@ -1871,7 +1946,11 @@ for coa_name, coa_data in pairs(env.mission.coalition) do
|
||||
if group_data and group_data.units and type(group_data.units) == 'table' then --making sure again- this is a valid group
|
||||
|
||||
mist.DBs.units[coa_name][countryName][category][group_num] = {}
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["groupName"] = group_data.name
|
||||
local groupName = group_data.name
|
||||
if env.mission.version > 7 then
|
||||
groupName = env.getValueDictByKey(groupName)
|
||||
end
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["groupName"] = groupName
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["groupId"] = group_data.groupId
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["category"] = category
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["coalition"] = coa_name
|
||||
@@ -1888,13 +1967,15 @@ for coa_name, coa_data in pairs(env.mission.coalition) do
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["frequency"] = group_data.frequency
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["modulation"] = group_data.modulation
|
||||
|
||||
|
||||
|
||||
for unit_num, unit_data in pairs(group_data.units) do
|
||||
local units_tbl = mist.DBs.units[coa_name][countryName][category][group_num]["units"] --pointer to the units table for this group
|
||||
|
||||
units_tbl[unit_num] = {}
|
||||
units_tbl[unit_num]["unitName"] = unit_data.name
|
||||
if env.mission.version > 7 then
|
||||
units_tbl[unit_num]["unitName"] = env.getValueDictByKey(unit_data.name)
|
||||
else
|
||||
units_tbl[unit_num]["unitName"] = unit_data.name
|
||||
end
|
||||
units_tbl[unit_num]["type"] = unit_data.type
|
||||
units_tbl[unit_num]["skill"] = unit_data.skill --will be nil for statics
|
||||
units_tbl[unit_num]["unitId"] = unit_data.unitId
|
||||
@@ -1924,7 +2005,7 @@ for coa_name, coa_data in pairs(env.mission.coalition) do
|
||||
units_tbl[unit_num]["psi"] = unit_data.psi
|
||||
|
||||
|
||||
units_tbl[unit_num]["groupName"] = group_data.name
|
||||
units_tbl[unit_num]["groupName"] = groupName
|
||||
units_tbl[unit_num]["groupId"] = group_data.groupId
|
||||
|
||||
if unit_data.AddPropAircraft then
|
||||
@@ -1973,6 +2054,7 @@ mist.DBs.humansByName = {}
|
||||
mist.DBs.humansById = {}
|
||||
|
||||
mist.DBs.dynGroupsAdded = {} -- will be filled by mist.dbUpdate from dynamically spawned groups
|
||||
mist.DBs.activeHumans = {}
|
||||
|
||||
mist.DBs.aliveUnits = {} -- will be filled in by the "update_alive_units" coroutine in mist.main.
|
||||
|
||||
@@ -2013,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
|
||||
mist.DBs.humansByName[unit_data.unitName] = 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
|
||||
@@ -2137,7 +2223,10 @@ do
|
||||
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
|
||||
--print('object found in old_alive_units')
|
||||
val['objectData'] = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_])
|
||||
@@ -2179,6 +2268,26 @@ do
|
||||
|
||||
mist.addEventHandler(addDeadObject)
|
||||
|
||||
--[[
|
||||
local function addClientsToActive(event)
|
||||
if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT or event.id == world.event.S_EVENT_BIRTH then
|
||||
env.info(mist.utils.tableShow(event))
|
||||
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)
|
||||
mist.DBs.activeHumans[Unit.getName(event.initiator)] = newU
|
||||
--trigger.action.outText('added: ' .. Unit.getName(event.initiator), 20)
|
||||
end
|
||||
elseif event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT and event.initiator then
|
||||
if mist.DBs.activeHumans[Unit.getName(event.initiator)] then
|
||||
mist.DBs.activeHumans[Unit.getName(event.initiator)] = nil
|
||||
-- trigger.action.outText('removed via control: ' .. Unit.getName(event.initiator), 20)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mist.addEventHandler(addClientsToActive)]]
|
||||
end
|
||||
|
||||
|
||||
@@ -2557,7 +2666,7 @@ Country names to be used in [c] and [-c] short-cuts:
|
||||
end
|
||||
|
||||
|
||||
units_tbl['processed'] = true --add the processed flag
|
||||
units_tbl['processed'] = timer.getTime() --add the processed flag
|
||||
return units_tbl
|
||||
end
|
||||
|
||||
@@ -2637,7 +2746,7 @@ initial_number
|
||||
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 (#mist.getDeadMapObjsInZones(zones) - initial_number) >= req_num and trigger.misc.getUserFlag(flag) == false then
|
||||
if (#mist.getDeadMapObjsInZones(zones) - initial_number) >= req_num and trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
return
|
||||
else
|
||||
@@ -2680,7 +2789,7 @@ initial_number
|
||||
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 (#mist.getDeadMapObjsInPolygonZone(zone) - initial_number) >= req_num and trigger.misc.getUserFlag(flag) == false then
|
||||
if (#mist.getDeadMapObjsInPolygonZone(zone) - initial_number) >= req_num and trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
return
|
||||
else
|
||||
@@ -2756,6 +2865,7 @@ maxalt = number or nil,
|
||||
interval = number or nil,
|
||||
req_num = number or nil
|
||||
toggle = boolean or nil
|
||||
unitTableDef = table or nil
|
||||
]]
|
||||
-- type_tbl
|
||||
local type_tbl = {
|
||||
@@ -2767,6 +2877,7 @@ toggle = boolean or nil
|
||||
interval = {'number', 'nil'},
|
||||
[{'req_num', 'reqnum'}] = {'number', 'nil'},
|
||||
toggle = {'boolean', 'nil'},
|
||||
unitTableDef = {'table', 'nil'},
|
||||
}
|
||||
|
||||
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_in_polygon', type_tbl, vars)
|
||||
@@ -2779,14 +2890,17 @@ toggle = boolean or nil
|
||||
local maxalt = vars.maxalt or vars.alt
|
||||
local req_num = vars.req_num or vars.reqnum or 1
|
||||
local toggle = vars.toggle or nil
|
||||
local unitTableDef = vars.unitTableDef
|
||||
|
||||
|
||||
if not units.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(units)
|
||||
--mist.debug.writeData(mist.utils.serialize,{'vars', vars}, 'vars.txt')
|
||||
if not units.processed then
|
||||
unitTableDef = mist.utils.deepCopy(units)
|
||||
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 (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(unitTableDef)
|
||||
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) == 0) then
|
||||
local num_in_zone = 0
|
||||
for i = 1, #units do
|
||||
local unit = Unit.getByName(units[i])
|
||||
@@ -2794,7 +2908,7 @@ toggle = boolean or nil
|
||||
local pos = unit:getPosition().p
|
||||
if mist.pointInPolygon(pos, zone, maxalt) then
|
||||
num_in_zone = num_in_zone + 1
|
||||
if num_in_zone >= req_num and trigger.misc.getUserFlag(flag) == false then
|
||||
if num_in_zone >= req_num and trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
break
|
||||
end
|
||||
@@ -2802,13 +2916,11 @@ toggle = boolean or nil
|
||||
end
|
||||
end
|
||||
if toggle and (num_in_zone < req_num) and trigger.misc.getUserFlag(flag) > 0 then
|
||||
|
||||
trigger.action.setUserFlag(flag, false)
|
||||
end
|
||||
-- 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
|
||||
|
||||
mist.scheduleFunction(mist.flagFunc.units_in_polygon, {{units = units, zone = zone, flag = flag, stopflag = stopflag, interval = interval, req_num = req_num, maxalt = maxalt, toggle = toggle}}, timer.getTime() + interval)
|
||||
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) == 0) then
|
||||
mist.scheduleFunction(mist.flagFunc.units_in_polygon, {{units = units, zone = zone, flag = flag, stopflag = stopflag, interval = interval, req_num = req_num, maxalt = maxalt, toggle = toggle, unitTableDef = unitTableDef}}, timer.getTime() + interval)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2894,6 +3006,7 @@ function mist.flagFunc.units_in_zones(vars)
|
||||
[{'req_num', 'reqnum'}] = {'number', 'nil'},
|
||||
interval = {'number', 'nil'},
|
||||
toggle = {'boolean', 'nil'},
|
||||
unitTableDef = {'table', 'nil'},
|
||||
}
|
||||
|
||||
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_in_zones', type_tbl, vars)
|
||||
@@ -2906,22 +3019,28 @@ function mist.flagFunc.units_in_zones(vars)
|
||||
local req_num = vars.req_num or vars.reqnum or 1
|
||||
local interval = vars.interval or 1
|
||||
local toggle = vars.toggle or nil
|
||||
local unitTableDef = vars.unitTableDef
|
||||
|
||||
if not units.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(units)
|
||||
if not units.processed then
|
||||
unitTableDef = mist.utils.deepCopy(units)
|
||||
end
|
||||
|
||||
if (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(unitTableDef)
|
||||
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
|
||||
|
||||
local in_zone_units = mist.getUnitsInZones(units, zones, zone_type)
|
||||
|
||||
if #in_zone_units >= req_num and trigger.misc.getUserFlag(flag) == false then
|
||||
if #in_zone_units >= req_num and trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
elseif #in_zone_units < req_num and toggle then
|
||||
trigger.action.setUserFlag(flag, false)
|
||||
end
|
||||
-- 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
|
||||
mist.scheduleFunction(mist.flagFunc.units_in_zones, {{units = units, zones = zones, 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_zones, {{units = units, zones = zones, flag = flag, stopflag = stopflag, zone_type = zone_type, req_num = req_num, interval = interval, toggle = toggle, unitTableDef = unitTableDef}}, timer.getTime() + interval)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3002,6 +3121,8 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
||||
[{'req_num', 'reqnum'}] = {'number', 'nil'},
|
||||
interval = {'number', 'nil'},
|
||||
toggle = {'boolean', 'nil'},
|
||||
unitTableDef = {'table', 'nil'},
|
||||
zUnitTableDef = {'table', 'nil'},
|
||||
}
|
||||
|
||||
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_in_moving_zones', type_tbl, vars)
|
||||
@@ -3015,27 +3136,37 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
||||
local req_num = vars.req_num or vars.reqnum or 1
|
||||
local interval = vars.interval or 1
|
||||
local toggle = vars.toggle or nil
|
||||
local unitTableDef = vars.unitTableDef
|
||||
local zUnitTableDef = vars.zUnitTableDef
|
||||
|
||||
if not units.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(units)
|
||||
if not units.processed then
|
||||
unitTableDef = mist.utils.deepCopy(units)
|
||||
end
|
||||
|
||||
if not zone_units.processed then -- run unit table short cuts
|
||||
zone_units = mist.makeUnitTable(zone_units)
|
||||
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
|
||||
units = mist.makeUnitTable(unitTableDef)
|
||||
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
|
||||
|
||||
local in_zone_units = mist.getUnitsInMovingZones(units, zone_units, radius, zone_type)
|
||||
|
||||
if #in_zone_units >= req_num and trigger.misc.getUserFlag(flag) == false then
|
||||
if #in_zone_units >= req_num and trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
elseif #in_zone_units < req_num and toggle then
|
||||
trigger.action.setUserFlag(flag, false)
|
||||
end
|
||||
-- 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
|
||||
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
|
||||
|
||||
@@ -3051,7 +3182,7 @@ mist.getUnitsLOS = function(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
|
||||
if unit1 and unit1:isActive() == true then
|
||||
unit_info1[#unit_info1 + 1] = {}
|
||||
unit_info1[#unit_info1]["unit"] = unit1
|
||||
unit_info1[#unit_info1]["pos"] = unit1:getPosition().p
|
||||
@@ -3060,7 +3191,7 @@ mist.getUnitsLOS = function(unitset1, altoffset1, unitset2, altoffset2, radius)
|
||||
|
||||
for unitset2_ind = 1, #unitset2 do
|
||||
local unit2 = Unit.getByName(unitset2[unitset2_ind])
|
||||
if unit2 then
|
||||
if unit2 and unit2:isActive() == true then
|
||||
unit_info2[#unit_info2 + 1] = {}
|
||||
unit_info2[#unit_info2]["unit"] = unit2
|
||||
unit_info2[#unit_info2]["pos"] = unit2:getPosition().p
|
||||
@@ -3118,6 +3249,8 @@ toggle = boolean or nil
|
||||
interval = {'number', 'nil'},
|
||||
radius = {'number', 'nil'},
|
||||
toggle = {'boolean', 'nil'},
|
||||
unitTableDef1 = {'table', 'nil'},
|
||||
unitTableDef2 = {'table', 'nil'},
|
||||
}
|
||||
|
||||
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_LOS', type_tbl, vars)
|
||||
@@ -3132,28 +3265,38 @@ toggle = boolean or nil
|
||||
local radius = vars.radius or math.huge
|
||||
local req_num = vars.req_num or vars.reqnum or 1
|
||||
local toggle = vars.toggle or nil
|
||||
local unitTableDef1 = vars.unitTableDef1
|
||||
local unitTableDef2 = vars.unitTableDef2
|
||||
|
||||
|
||||
if not unitset1.processed then -- run unit table short cuts
|
||||
unitset1 = mist.makeUnitTable(unitset1)
|
||||
if not unitset1.processed then
|
||||
unitTableDef1 = mist.utils.deepCopy(unitset1)
|
||||
end
|
||||
|
||||
if not unitset2.processed then -- run unit table short cuts
|
||||
unitset2 = mist.makeUnitTable(unitset2)
|
||||
if not unitset2.processed then
|
||||
unitTableDef2 = mist.utils.deepCopy(unitset2)
|
||||
end
|
||||
|
||||
if (unitset1.processed and unitset1.processed < mist.getLastDBUpdateTime()) or not unitset1.processed then -- run unit table short cuts
|
||||
unitset1 = mist.makeUnitTable(unitTableDef1)
|
||||
end
|
||||
|
||||
if (unitset2.processed and unitset2.processed < mist.getLastDBUpdateTime()) or not unitset2.processed then -- run unit table short cuts
|
||||
unitset2 = mist.makeUnitTable(unitTableDef2)
|
||||
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
|
||||
|
||||
local unitLOSdata = mist.getUnitsLOS(unitset1, altoffset1, unitset2, altoffset2, radius)
|
||||
|
||||
if #unitLOSdata >= req_num and trigger.misc.getUserFlag(flag) == false then
|
||||
if #unitLOSdata >= req_num and trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
elseif #unitLOSdata < req_num and toggle then
|
||||
trigger.action.setUserFlag(flag, false)
|
||||
end
|
||||
-- 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
|
||||
mist.scheduleFunction(mist.flagFunc.units_LOS, {{unitset1 = unitset1, altoffset1 = altoffset1, unitset2 = unitset2, altoffset2 = altoffset2, flag = flag, stopflag = stopflag, radius = radius, req_num = req_num, interval = interval, toggle = toggle}}, timer.getTime() + interval)
|
||||
mist.scheduleFunction(mist.flagFunc.units_LOS, {{unitset1 = unitset1, altoffset1 = altoffset1, unitset2 = unitset2, altoffset2 = altoffset2, flag = flag, stopflag = stopflag, radius = radius, req_num = req_num, interval = interval, toggle = toggle, unitTableDef1 = unitTableDef1, unitTableDef2 = unitTableDef2}}, timer.getTime() + interval)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3186,7 +3329,7 @@ stopFlag
|
||||
|
||||
|
||||
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 Group.getByName(groupName) and Group.getByName(groupName):isExist() == true then
|
||||
if Group.getByName(groupName) and Group.getByName(groupName):isExist() == true and #Group.getByName(groupName):getUnits() > 0 then
|
||||
if trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
end
|
||||
@@ -3223,7 +3366,7 @@ mist.flagFunc.group_dead = function(vars)
|
||||
|
||||
|
||||
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 Group.getByName(groupName) and Group.getByName(groupName):isExist() == false or not Group.getByName(groupName) then
|
||||
if (Group.getByName(groupName) and Group.getByName(groupName):isExist() == false) or (Group.getByName(groupName) and #Group.getByName(groupName):getUnits() < 1) or not Group.getByName(groupName) then
|
||||
if trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
end
|
||||
@@ -3327,20 +3470,41 @@ mist.flagFunc.group_alive_more_than = function(vars)
|
||||
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)
|
||||
mist.getAvgPos = function(unitNames)
|
||||
local avgX, avgY, avgZ, totNum = 0, 0, 0, 0
|
||||
for i = 1, #unitNames do
|
||||
local unit = Unit.getByName(unitNames[i])
|
||||
local unit
|
||||
if Unit.getByName(unitNames[i]) then
|
||||
unit = Unit.getByName(unitNames[i])
|
||||
elseif StaticObject.getByName(unitNames[i]) then
|
||||
unit = StaticObject.getByName(unitNames[i])
|
||||
end
|
||||
if unit then
|
||||
|
||||
local pos = unit:getPosition().p
|
||||
avgX = avgX + pos.x
|
||||
avgY = avgY + pos.y
|
||||
avgZ = avgZ + pos.z
|
||||
totNum = totNum + 1
|
||||
if pos then -- you never know O.o
|
||||
avgX = avgX + pos.x
|
||||
avgY = avgY + pos.y
|
||||
avgZ = avgZ + pos.z
|
||||
totNum = totNum + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
if totNum ~= 0 then
|
||||
@@ -3500,10 +3664,13 @@ mist.goRoute = function(group, path)
|
||||
if type(group) == 'string' then
|
||||
group = Group.getByName(group)
|
||||
end
|
||||
local groupCon = group:getController()
|
||||
if groupCon then
|
||||
groupCon:setTask(misTask)
|
||||
return true
|
||||
local groupCon = nil
|
||||
if group then
|
||||
groupCon = group:getController()
|
||||
if groupCon then
|
||||
groupCon:setTask(misTask)
|
||||
return true
|
||||
end
|
||||
end
|
||||
--Controller.setTask(groupCon, misTask)
|
||||
return false
|
||||
@@ -3845,7 +4012,7 @@ mist.groupRandomDistSelf = function(gpData, dist, form, heading, speed)
|
||||
local pos = mist.getLeadPos(gpData)
|
||||
local fakeZone = {}
|
||||
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)
|
||||
|
||||
return
|
||||
@@ -4003,6 +4170,37 @@ do
|
||||
local displayActive = false
|
||||
local displayFuncId = 0
|
||||
|
||||
local caSlots = false
|
||||
local caMSGtoGroup = false
|
||||
|
||||
if env.mission.groundControl then -- just to be sure?
|
||||
for index, value in pairs(env.mission.groundControl) do
|
||||
if type(value) == 'table' then
|
||||
for roleName, roleVal in pairs(value) do
|
||||
for rIndex, rVal in pairs(roleVal) do
|
||||
if rIndex == 'red' or rIndex == 'blue' then
|
||||
if env.mission.groundControl[index][roleName][rIndex] > 0 then
|
||||
caSlots = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif type(value) == 'boolean' and value == true then
|
||||
caSlots = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function mistdisplayV5()
|
||||
--[[thoughts to improve upon
|
||||
event handler based activeClients table.
|
||||
display messages only when there is an update
|
||||
possibly co-routine it.
|
||||
]]
|
||||
end
|
||||
|
||||
local function mistdisplayV4()
|
||||
local activeClients = {}
|
||||
|
||||
@@ -4011,6 +4209,10 @@ do
|
||||
activeClients[clientData.groupId] = clientData.groupName
|
||||
end
|
||||
end
|
||||
|
||||
--[[if caSlots == true and caMSGtoGroup == true then
|
||||
|
||||
end]]
|
||||
|
||||
|
||||
if #messageList > 0 then
|
||||
@@ -4050,7 +4252,7 @@ do
|
||||
msgTableText[recData] = {}
|
||||
msgTableText[recData].text = {}
|
||||
if recData == 'RED' or recData == 'BLUE' then
|
||||
msgTableText[recData].text[1] = '---------------- Combined Arms Message: \n'
|
||||
msgTableText[recData].text[1] = '-------Combined Arms Message-------- \n'
|
||||
end
|
||||
msgTableText[recData].text[#msgTableText[recData].text + 1] = messageData.text
|
||||
msgTableText[recData].displayTime = messageData.displayTime - messageData.displayedFor
|
||||
@@ -4079,17 +4281,19 @@ do
|
||||
end
|
||||
------- new display
|
||||
|
||||
|
||||
if msgTableText['RED'] then
|
||||
trigger.action.outTextForCoalition(coalition.side.RED, table.concat(msgTableText['RED'].text), msgTableText['RED'].displayTime)
|
||||
end
|
||||
if msgTableText['BLUE'] then
|
||||
trigger.action.outTextForCoalition(coalition.side.BLUE, table.concat(msgTableText['BLUE'].text), msgTableText['BLUE'].displayTime)
|
||||
if caSlots == true and caMSGtoGroup == false then
|
||||
if msgTableText['RED'] then
|
||||
trigger.action.outTextForCoalition(coalition.side.RED, table.concat(msgTableText['RED'].text), msgTableText['RED'].displayTime, true)
|
||||
|
||||
end
|
||||
if msgTableText['BLUE'] then
|
||||
trigger.action.outTextForCoalition(coalition.side.BLUE, table.concat(msgTableText['BLUE'].text), msgTableText['BLUE'].displayTime, true)
|
||||
end
|
||||
end
|
||||
|
||||
for index, msgData in pairs(msgTableText) do
|
||||
if type(index) == 'number' then -- its a groupNumber
|
||||
trigger.action.outTextForGroup(index, table.concat(msgData.text), msgData.displayTime)
|
||||
trigger.action.outTextForGroup(index, table.concat(msgData.text), msgData.displayTime, true)
|
||||
end
|
||||
end
|
||||
--- new audio
|
||||
@@ -4100,6 +4304,7 @@ do
|
||||
trigger.action.outSoundForCoalition(coalition.side.BLUE, msgTableSound['BLUE'])
|
||||
end
|
||||
|
||||
|
||||
for index, file in pairs(msgTableSound) do
|
||||
if type(index) == 'number' then -- its a groupNumber
|
||||
trigger.action.outSoundForGroup(index, file)
|
||||
@@ -4111,6 +4316,22 @@ do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local typeBase = {
|
||||
['Mi-8MT'] = {'Mi-8MTV2', 'Mi-8MTV', 'Mi-8'},
|
||||
['MiG-21Bis'] = {'Mig-21'},
|
||||
['MiG-15bis'] = {'Mig-15'},
|
||||
['FW-190D9'] = {'FW-190'},
|
||||
['Bf-109K-4'] = {'Bf-109'},
|
||||
}
|
||||
|
||||
--[[mist.setCAGroupMSG = function(val)
|
||||
if type(val) == 'boolean' then
|
||||
caMSGtoGroup = val
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end]]
|
||||
|
||||
mist.message = {
|
||||
|
||||
@@ -4176,18 +4397,26 @@ do
|
||||
if type(listData) == 'string' then
|
||||
listData = string.lower(listData)
|
||||
end
|
||||
if forIndex == 'coa' and (listData == string.lower(clientData.coalition) or listData == 'all') or forIndex == 'countries' and string.lower(clientData.country) == listData or forIndex == 'units' and string.lower(clientData.unitName) == listData then --
|
||||
newMsgFor = msgSpamFilter(newMsgFor, clientId) -- so units dont get the same message twice if complex rules are given
|
||||
if (forIndex == 'coa' and (listData == string.lower(clientData.coalition) or listData == 'all')) or (forIndex == 'countries' and string.lower(clientData.country) == listData) or (forIndex == 'units' and string.lower(clientData.unitName) == listData) then --
|
||||
newMsgFor = msgSpamFilter(newMsgFor, clientData.groupId) -- so units dont get the same message twice if complex rules are given
|
||||
--table.insert(newMsgFor, clientId)
|
||||
elseif forIndex == 'unittypes' then
|
||||
for typeId, typeData in pairs(listData) do
|
||||
local found = false
|
||||
for clientDataEntry, clientDataVal in pairs(clientData) do
|
||||
if type(clientDataVal) == 'string' then
|
||||
if string.lower(list) == string.lower(clientDataVal) or list == 'all' then
|
||||
if typeData == clientData.type then
|
||||
if mist.matchString(list, clientDataVal) == true or list == 'all' then
|
||||
local sString = typeData
|
||||
for rName, pTbl in pairs(typeBase) do -- just a quick check to see if the user may have meant something and got the specific type of the unit wrong
|
||||
for pIndex, pName in pairs(pTbl) do
|
||||
if mist.stringMatch(sString, pName) then
|
||||
sString = rName
|
||||
end
|
||||
end
|
||||
end
|
||||
if sString == clientData.type then
|
||||
found = true
|
||||
newMsgFor = msgSpamFilter(newMsgFor, clientId) -- sends info oto other function to see if client is already recieving the current message.
|
||||
newMsgFor = msgSpamFilter(newMsgFor, clientData.groupId) -- sends info oto other function to see if client is already recieving the current message.
|
||||
--table.insert(newMsgFor, clientId)
|
||||
end
|
||||
end
|
||||
@@ -4204,8 +4433,6 @@ do
|
||||
if string.lower(forIndex) == 'coa' or string.lower(forIndex) == 'ca' then
|
||||
if listData == string.lower(coaData) or listData == 'all' then
|
||||
newMsgFor = msgSpamFilter(newMsgFor, coaData)
|
||||
--table.insert(newMsgFor, coaData)
|
||||
-- added redca or blueca to list
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4241,7 +4468,7 @@ do
|
||||
messageID = messageID + 1
|
||||
new.messageID = messageID
|
||||
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', new}, 'newMsg.txt')
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', new}, 'newMsg.lua')
|
||||
|
||||
|
||||
messageList[#messageList + 1] = new
|
||||
@@ -5109,11 +5336,15 @@ mist.teleportToPoint = function(vars) -- main teleport function that all of tele
|
||||
newGroupData.units[unitNum]["y"] = unitData.y + diff.y
|
||||
end
|
||||
if point then
|
||||
if (newGroupData.category == 'plane' or newGroupData.category == 'helicopter') and point.z then
|
||||
if point.y > 0 and point.y > land.getHeight({newGroupData.units[unitNum]["x"], newGroupData.units[unitNum]["y"]}) + 10 then
|
||||
if (newGroupData.category == 'plane' or newGroupData.category == 'helicopter') then
|
||||
if point.z and point.y > 0 and point.y > land.getHeight({newGroupData.units[unitNum]["x"], newGroupData.units[unitNum]["y"]}) + 10 then
|
||||
newGroupData.units[unitNum]["alt"] = point.y
|
||||
else
|
||||
newGroupData.units[unitNum]["alt"] = land.getHeight({newGroupData.units[unitNum]["x"], newGroupData.units[unitNum]["y"]}) + 300
|
||||
if newGroupData.category == 'plane' then
|
||||
newGroupData.units[unitNum]["alt"] = land.getHeight({newGroupData.units[unitNum]["x"], newGroupData.units[unitNum]["y"]}) + math.random(300, 9000)
|
||||
else
|
||||
newGroupData.units[unitNum]["alt"] = land.getHeight({newGroupData.units[unitNum]["x"], newGroupData.units[unitNum]["y"]}) + math.random(200, 3000)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5140,7 +5371,6 @@ mist.teleportToPoint = function(vars) -- main teleport function that all of tele
|
||||
if string.lower(newGroupData.category) == 'static' then
|
||||
return mist.dynAddStatic(newGroupData)
|
||||
end
|
||||
|
||||
return mist.dynAdd(newGroupData)
|
||||
|
||||
end
|
||||
|
||||
+333
-103
@@ -1,4 +1,11 @@
|
||||
--[[
|
||||
Links:
|
||||
|
||||
ED Forum Thread: http://forums.eagle.ru/showthread.php?t=98616
|
||||
|
||||
Github
|
||||
Development: https://github.com/mrSkortch/MissionScriptingTools/tree/development
|
||||
Official Release: https://github.com/mrSkortch/MissionScriptingTools/tree/master
|
||||
|
||||
]]
|
||||
|
||||
@@ -6,11 +13,9 @@
|
||||
mist = {}
|
||||
|
||||
-- don't change these
|
||||
mist.majorVersion = 3
|
||||
mist.minorVersion = 7
|
||||
mist.build = 48
|
||||
|
||||
|
||||
mist.majorVersion = 4
|
||||
mist.minorVersion = 1
|
||||
mist.build = 61
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------
|
||||
-- the main area
|
||||
@@ -21,6 +26,7 @@ do
|
||||
local mistAddedObjects = {} -- mist.dynAdd unit data added here
|
||||
local mistAddedGroups = {} -- mist.dynAdd groupdata added here
|
||||
local writeGroups = {}
|
||||
local lastUpdateTime = 0
|
||||
|
||||
local function update_alive_units() -- coroutine function
|
||||
local lalive_units = mist.DBs.aliveUnits -- local references for faster execution
|
||||
@@ -235,7 +241,7 @@ do
|
||||
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
|
||||
--mist.debug.dumpDBs()
|
||||
--end
|
||||
@@ -248,6 +254,7 @@ do
|
||||
local function checkSpawnedEvents()
|
||||
if #tempSpawnedUnits > 0 then
|
||||
local groupsToAdd = {}
|
||||
local added = false
|
||||
local ltemp = tempSpawnedUnits
|
||||
local ltable = table
|
||||
|
||||
@@ -259,7 +266,7 @@ do
|
||||
local spawnedObj = ltemp[x]
|
||||
if spawnedObj and spawnedObj:isExist() then
|
||||
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 mist.stringMatch(spawnedObj:getGroup():getName(), name) == true then
|
||||
found = true
|
||||
@@ -274,26 +281,37 @@ do
|
||||
end
|
||||
-- for some reason cargo objects are returning as category == 6.
|
||||
if found == false then
|
||||
added = true
|
||||
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
|
||||
groupsToAdd[#groupsToAdd + 1] = spawnedObj:getName()
|
||||
groupsToAdd[spawnedObj:getName()] = true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
table.remove(ltemp, x)
|
||||
if x%updatesPerRun == 0 then
|
||||
coroutine.yield()
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
if #groupsToAdd > 0 then
|
||||
for groupId, groupName in pairs(groupsToAdd) do
|
||||
if not mist.DBs.groupsByName[groupName] or mist.DBs.groupsByName[groupName] and mist.DBs.groupsByName[groupName].startTime + 10 < timer.getAbsTime() then
|
||||
|
||||
if added == true then
|
||||
for groupName, val in pairs(groupsToAdd) do
|
||||
local dataChanged = false
|
||||
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)
|
||||
end
|
||||
end
|
||||
@@ -303,6 +321,7 @@ do
|
||||
|
||||
|
||||
local function updateDBTables()
|
||||
|
||||
local i = 0
|
||||
for index, newTable in pairs(writeGroups) do
|
||||
i = i + 1
|
||||
@@ -369,6 +388,9 @@ do
|
||||
coroutine.yield()
|
||||
end
|
||||
end
|
||||
if timer.getTime() > lastUpdateTime then
|
||||
lastUpdateTime = timer.getTime()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -438,6 +460,7 @@ do
|
||||
local mistUnitId = 7000
|
||||
local mistDynAddIndex = 1
|
||||
|
||||
|
||||
mist.nextGroupId = 1
|
||||
mist.nextUnitId = 1
|
||||
|
||||
@@ -457,6 +480,10 @@ do
|
||||
return mist.nextGroupId
|
||||
end
|
||||
|
||||
mist.getLastDBUpdateTime = function()
|
||||
return lastUpdateTime
|
||||
end
|
||||
|
||||
local function groupSpawned(event)
|
||||
if event.id == world.event.S_EVENT_BIRTH and timer.getTime0() < timer.getAbsTime()then -- dont need to add units spawned in at the start of the mission if mist is loaded in init line
|
||||
table.insert(tempSpawnedUnits,(event.initiator))
|
||||
@@ -478,6 +505,7 @@ do
|
||||
newObj.name = staticObj.name
|
||||
newObj.dead = staticObj.dead
|
||||
newObj.country = staticObj.country
|
||||
newObj.countryId = staticObj.countryId
|
||||
newObj.clone = staticObj.clone
|
||||
newObj.shape_name = staticObj.shape_name
|
||||
newObj.canCargo = staticObj.canCargo
|
||||
@@ -494,21 +522,22 @@ do
|
||||
newObj.name = staticObj.units[1].name
|
||||
newObj.dead = staticObj.units[1].dead
|
||||
newObj.country = staticObj.units[1].country
|
||||
newObj.countryId = staticObj.units[1].countryId
|
||||
newObj.shape_name = staticObj.units[1].shape_name
|
||||
newObj.canCargo = staticObj.units[1].canCargo
|
||||
newObj.mass = staticObj.units[1].mass
|
||||
newObj.categoryStatic = staticObj.units[1].categoryStatic
|
||||
end
|
||||
|
||||
|
||||
newObj.country = staticObj.country
|
||||
|
||||
if not newObj.country then
|
||||
return false
|
||||
end
|
||||
|
||||
local newCountry
|
||||
for countryName, countryId in pairs(country.id) do
|
||||
local newCountry = newObj.country
|
||||
if newObj.countryId then
|
||||
newCountry = newObj.countryId
|
||||
end
|
||||
for countryId, countryName in pairs(country.name) do
|
||||
if type(newObj.country) == 'string' then
|
||||
if tostring(countryName) == string.upper(newObj.country) then
|
||||
newCountry = countryName
|
||||
@@ -532,7 +561,7 @@ do
|
||||
|
||||
if newObj.clone or not newObj.name then
|
||||
mistDynAddIndex = mistDynAddIndex + 1
|
||||
newObj.name = (newCountry .. ' static ' .. mistDynAddIndex)
|
||||
newObj.name = (country.name[newCountry] .. ' static ' .. mistDynAddIndex)
|
||||
end
|
||||
|
||||
if not newObj.dead then
|
||||
@@ -563,13 +592,19 @@ do
|
||||
--
|
||||
|
||||
|
||||
--env.info('dynAdd')
|
||||
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, 'newGroupOrig.lua')
|
||||
local cntry = newGroup.country
|
||||
if newGroup.countryId then
|
||||
cntry = newGroup.countryId
|
||||
end
|
||||
|
||||
local groupType = newGroup.category
|
||||
local newCountry = ''
|
||||
-- validate data
|
||||
for countryName, countryId in pairs(country.id) do
|
||||
for countryId, countryName in pairs(country.name) do
|
||||
if type(cntry) == 'string' then
|
||||
cntry = cntry:gsub("%s+", "_")
|
||||
if tostring(countryName) == string.upper(cntry) then
|
||||
newCountry = countryName
|
||||
end
|
||||
@@ -602,7 +637,6 @@ do
|
||||
newCat = 'AIRPLANE'
|
||||
end
|
||||
end
|
||||
|
||||
local typeName
|
||||
if newCat == 'GROUND_UNIT' then
|
||||
typeName = ' gnd '
|
||||
@@ -615,7 +649,6 @@ do
|
||||
elseif newCat == 'BUILDING' then
|
||||
typeName = ' bld '
|
||||
end
|
||||
|
||||
if newGroup.clone or not newGroup.groupId then
|
||||
mistDynAddIndex = mistDynAddIndex + 1
|
||||
mistGpId = mistGpId + 1
|
||||
@@ -630,7 +663,7 @@ do
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
if not newGroup.hidden then
|
||||
@@ -648,8 +681,9 @@ do
|
||||
newGroup.start_time = 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for unitIndex, unitData in pairs(newGroup.units) do
|
||||
|
||||
local originalName = newGroup.units[unitIndex].unitName or newGroup.units[unitIndex].name
|
||||
if newGroup.clone or not unitData.unitId then
|
||||
mistUnitId = mistUnitId + 1
|
||||
@@ -706,7 +740,6 @@ do
|
||||
mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newGroup.units[unitIndex])
|
||||
end
|
||||
mistAddedGroups[#mistAddedGroups + 1] = mist.utils.deepCopy(newGroup)
|
||||
|
||||
if newGroup.route and not newGroup.route.points then
|
||||
if not newGroup.route.points and newGroup.route[1] then
|
||||
local copyRoute = newGroup.route
|
||||
@@ -902,7 +935,9 @@ end
|
||||
|
||||
function mist.utils.makeVec3(Vec2, y)
|
||||
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
|
||||
end
|
||||
return {x = Vec2.x, y = y, z = Vec2.y}
|
||||
@@ -942,7 +977,9 @@ end
|
||||
-- gets heading-error corrected direction from point along vector vec.
|
||||
function mist.utils.getDir(vec, point)
|
||||
local dir = math.atan2(vec.z, vec.x)
|
||||
dir = dir + mist.getNorthCorrection(point)
|
||||
if point then
|
||||
dir = dir + mist.getNorthCorrection(point)
|
||||
end
|
||||
if dir < 0 then
|
||||
dir = dir + 2*math.pi -- put dir in range of 0 to 2*pi
|
||||
end
|
||||
@@ -961,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})
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -991,6 +1056,15 @@ mist.utils.round = function(num, idp)
|
||||
return math.floor(num * mult + 0.5) / mult
|
||||
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
|
||||
mist.utils.dostring = function(s)
|
||||
local f, err = loadstring(s)
|
||||
@@ -1507,7 +1581,8 @@ mist.tostringBR = function(az, dist, alt, metric)
|
||||
return s
|
||||
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
|
||||
point.z = point.y
|
||||
point.y = 0
|
||||
@@ -1871,7 +1946,11 @@ for coa_name, coa_data in pairs(env.mission.coalition) do
|
||||
if group_data and group_data.units and type(group_data.units) == 'table' then --making sure again- this is a valid group
|
||||
|
||||
mist.DBs.units[coa_name][countryName][category][group_num] = {}
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["groupName"] = group_data.name
|
||||
local groupName = group_data.name
|
||||
if env.mission.version > 7 then
|
||||
groupName = env.getValueDictByKey(groupName)
|
||||
end
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["groupName"] = groupName
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["groupId"] = group_data.groupId
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["category"] = category
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["coalition"] = coa_name
|
||||
@@ -1888,13 +1967,15 @@ for coa_name, coa_data in pairs(env.mission.coalition) do
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["frequency"] = group_data.frequency
|
||||
mist.DBs.units[coa_name][countryName][category][group_num]["modulation"] = group_data.modulation
|
||||
|
||||
|
||||
|
||||
for unit_num, unit_data in pairs(group_data.units) do
|
||||
local units_tbl = mist.DBs.units[coa_name][countryName][category][group_num]["units"] --pointer to the units table for this group
|
||||
|
||||
units_tbl[unit_num] = {}
|
||||
units_tbl[unit_num]["unitName"] = unit_data.name
|
||||
if env.mission.version > 7 then
|
||||
units_tbl[unit_num]["unitName"] = env.getValueDictByKey(unit_data.name)
|
||||
else
|
||||
units_tbl[unit_num]["unitName"] = unit_data.name
|
||||
end
|
||||
units_tbl[unit_num]["type"] = unit_data.type
|
||||
units_tbl[unit_num]["skill"] = unit_data.skill --will be nil for statics
|
||||
units_tbl[unit_num]["unitId"] = unit_data.unitId
|
||||
@@ -1924,7 +2005,7 @@ for coa_name, coa_data in pairs(env.mission.coalition) do
|
||||
units_tbl[unit_num]["psi"] = unit_data.psi
|
||||
|
||||
|
||||
units_tbl[unit_num]["groupName"] = group_data.name
|
||||
units_tbl[unit_num]["groupName"] = groupName
|
||||
units_tbl[unit_num]["groupId"] = group_data.groupId
|
||||
|
||||
if unit_data.AddPropAircraft then
|
||||
@@ -1973,6 +2054,7 @@ mist.DBs.humansByName = {}
|
||||
mist.DBs.humansById = {}
|
||||
|
||||
mist.DBs.dynGroupsAdded = {} -- will be filled by mist.dbUpdate from dynamically spawned groups
|
||||
mist.DBs.activeHumans = {}
|
||||
|
||||
mist.DBs.aliveUnits = {} -- will be filled in by the "update_alive_units" coroutine in mist.main.
|
||||
|
||||
@@ -2013,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
|
||||
mist.DBs.humansByName[unit_data.unitName] = 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
|
||||
@@ -2137,7 +2223,10 @@ do
|
||||
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
|
||||
--print('object found in old_alive_units')
|
||||
val['objectData'] = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_])
|
||||
@@ -2179,6 +2268,26 @@ do
|
||||
|
||||
mist.addEventHandler(addDeadObject)
|
||||
|
||||
--[[
|
||||
local function addClientsToActive(event)
|
||||
if event.id == world.event.S_EVENT_PLAYER_ENTER_UNIT or event.id == world.event.S_EVENT_BIRTH then
|
||||
env.info(mist.utils.tableShow(event))
|
||||
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)
|
||||
mist.DBs.activeHumans[Unit.getName(event.initiator)] = newU
|
||||
--trigger.action.outText('added: ' .. Unit.getName(event.initiator), 20)
|
||||
end
|
||||
elseif event.id == world.event.S_EVENT_PLAYER_LEAVE_UNIT and event.initiator then
|
||||
if mist.DBs.activeHumans[Unit.getName(event.initiator)] then
|
||||
mist.DBs.activeHumans[Unit.getName(event.initiator)] = nil
|
||||
-- trigger.action.outText('removed via control: ' .. Unit.getName(event.initiator), 20)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mist.addEventHandler(addClientsToActive)]]
|
||||
end
|
||||
|
||||
|
||||
@@ -2557,7 +2666,7 @@ Country names to be used in [c] and [-c] short-cuts:
|
||||
end
|
||||
|
||||
|
||||
units_tbl['processed'] = true --add the processed flag
|
||||
units_tbl['processed'] = timer.getTime() --add the processed flag
|
||||
return units_tbl
|
||||
end
|
||||
|
||||
@@ -2637,7 +2746,7 @@ initial_number
|
||||
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 (#mist.getDeadMapObjsInZones(zones) - initial_number) >= req_num and trigger.misc.getUserFlag(flag) == false then
|
||||
if (#mist.getDeadMapObjsInZones(zones) - initial_number) >= req_num and trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
return
|
||||
else
|
||||
@@ -2680,7 +2789,7 @@ initial_number
|
||||
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 (#mist.getDeadMapObjsInPolygonZone(zone) - initial_number) >= req_num and trigger.misc.getUserFlag(flag) == false then
|
||||
if (#mist.getDeadMapObjsInPolygonZone(zone) - initial_number) >= req_num and trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
return
|
||||
else
|
||||
@@ -2756,6 +2865,7 @@ maxalt = number or nil,
|
||||
interval = number or nil,
|
||||
req_num = number or nil
|
||||
toggle = boolean or nil
|
||||
unitTableDef = table or nil
|
||||
]]
|
||||
-- type_tbl
|
||||
local type_tbl = {
|
||||
@@ -2767,6 +2877,7 @@ toggle = boolean or nil
|
||||
interval = {'number', 'nil'},
|
||||
[{'req_num', 'reqnum'}] = {'number', 'nil'},
|
||||
toggle = {'boolean', 'nil'},
|
||||
unitTableDef = {'table', 'nil'},
|
||||
}
|
||||
|
||||
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_in_polygon', type_tbl, vars)
|
||||
@@ -2779,14 +2890,17 @@ toggle = boolean or nil
|
||||
local maxalt = vars.maxalt or vars.alt
|
||||
local req_num = vars.req_num or vars.reqnum or 1
|
||||
local toggle = vars.toggle or nil
|
||||
local unitTableDef = vars.unitTableDef
|
||||
|
||||
|
||||
if not units.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(units)
|
||||
--mist.debug.writeData(mist.utils.serialize,{'vars', vars}, 'vars.txt')
|
||||
if not units.processed then
|
||||
unitTableDef = mist.utils.deepCopy(units)
|
||||
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 (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(unitTableDef)
|
||||
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) == 0) then
|
||||
local num_in_zone = 0
|
||||
for i = 1, #units do
|
||||
local unit = Unit.getByName(units[i])
|
||||
@@ -2794,7 +2908,7 @@ toggle = boolean or nil
|
||||
local pos = unit:getPosition().p
|
||||
if mist.pointInPolygon(pos, zone, maxalt) then
|
||||
num_in_zone = num_in_zone + 1
|
||||
if num_in_zone >= req_num and trigger.misc.getUserFlag(flag) == false then
|
||||
if num_in_zone >= req_num and trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
break
|
||||
end
|
||||
@@ -2802,13 +2916,11 @@ toggle = boolean or nil
|
||||
end
|
||||
end
|
||||
if toggle and (num_in_zone < req_num) and trigger.misc.getUserFlag(flag) > 0 then
|
||||
|
||||
trigger.action.setUserFlag(flag, false)
|
||||
end
|
||||
-- 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
|
||||
|
||||
mist.scheduleFunction(mist.flagFunc.units_in_polygon, {{units = units, zone = zone, flag = flag, stopflag = stopflag, interval = interval, req_num = req_num, maxalt = maxalt, toggle = toggle}}, timer.getTime() + interval)
|
||||
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) == 0) then
|
||||
mist.scheduleFunction(mist.flagFunc.units_in_polygon, {{units = units, zone = zone, flag = flag, stopflag = stopflag, interval = interval, req_num = req_num, maxalt = maxalt, toggle = toggle, unitTableDef = unitTableDef}}, timer.getTime() + interval)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2894,6 +3006,7 @@ function mist.flagFunc.units_in_zones(vars)
|
||||
[{'req_num', 'reqnum'}] = {'number', 'nil'},
|
||||
interval = {'number', 'nil'},
|
||||
toggle = {'boolean', 'nil'},
|
||||
unitTableDef = {'table', 'nil'},
|
||||
}
|
||||
|
||||
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_in_zones', type_tbl, vars)
|
||||
@@ -2906,22 +3019,28 @@ function mist.flagFunc.units_in_zones(vars)
|
||||
local req_num = vars.req_num or vars.reqnum or 1
|
||||
local interval = vars.interval or 1
|
||||
local toggle = vars.toggle or nil
|
||||
local unitTableDef = vars.unitTableDef
|
||||
|
||||
if not units.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(units)
|
||||
if not units.processed then
|
||||
unitTableDef = mist.utils.deepCopy(units)
|
||||
end
|
||||
|
||||
if (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(unitTableDef)
|
||||
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
|
||||
|
||||
local in_zone_units = mist.getUnitsInZones(units, zones, zone_type)
|
||||
|
||||
if #in_zone_units >= req_num and trigger.misc.getUserFlag(flag) == false then
|
||||
if #in_zone_units >= req_num and trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
elseif #in_zone_units < req_num and toggle then
|
||||
trigger.action.setUserFlag(flag, false)
|
||||
end
|
||||
-- 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
|
||||
mist.scheduleFunction(mist.flagFunc.units_in_zones, {{units = units, zones = zones, 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_zones, {{units = units, zones = zones, flag = flag, stopflag = stopflag, zone_type = zone_type, req_num = req_num, interval = interval, toggle = toggle, unitTableDef = unitTableDef}}, timer.getTime() + interval)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3002,6 +3121,8 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
||||
[{'req_num', 'reqnum'}] = {'number', 'nil'},
|
||||
interval = {'number', 'nil'},
|
||||
toggle = {'boolean', 'nil'},
|
||||
unitTableDef = {'table', 'nil'},
|
||||
zUnitTableDef = {'table', 'nil'},
|
||||
}
|
||||
|
||||
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_in_moving_zones', type_tbl, vars)
|
||||
@@ -3015,27 +3136,37 @@ function mist.flagFunc.units_in_moving_zones(vars)
|
||||
local req_num = vars.req_num or vars.reqnum or 1
|
||||
local interval = vars.interval or 1
|
||||
local toggle = vars.toggle or nil
|
||||
local unitTableDef = vars.unitTableDef
|
||||
local zUnitTableDef = vars.zUnitTableDef
|
||||
|
||||
if not units.processed then -- run unit table short cuts
|
||||
units = mist.makeUnitTable(units)
|
||||
if not units.processed then
|
||||
unitTableDef = mist.utils.deepCopy(units)
|
||||
end
|
||||
|
||||
if not zone_units.processed then -- run unit table short cuts
|
||||
zone_units = mist.makeUnitTable(zone_units)
|
||||
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
|
||||
units = mist.makeUnitTable(unitTableDef)
|
||||
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
|
||||
|
||||
local in_zone_units = mist.getUnitsInMovingZones(units, zone_units, radius, zone_type)
|
||||
|
||||
if #in_zone_units >= req_num and trigger.misc.getUserFlag(flag) == false then
|
||||
if #in_zone_units >= req_num and trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
elseif #in_zone_units < req_num and toggle then
|
||||
trigger.action.setUserFlag(flag, false)
|
||||
end
|
||||
-- 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
|
||||
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
|
||||
|
||||
@@ -3051,7 +3182,7 @@ mist.getUnitsLOS = function(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
|
||||
if unit1 and unit1:isActive() == true then
|
||||
unit_info1[#unit_info1 + 1] = {}
|
||||
unit_info1[#unit_info1]["unit"] = unit1
|
||||
unit_info1[#unit_info1]["pos"] = unit1:getPosition().p
|
||||
@@ -3060,7 +3191,7 @@ mist.getUnitsLOS = function(unitset1, altoffset1, unitset2, altoffset2, radius)
|
||||
|
||||
for unitset2_ind = 1, #unitset2 do
|
||||
local unit2 = Unit.getByName(unitset2[unitset2_ind])
|
||||
if unit2 then
|
||||
if unit2 and unit2:isActive() == true then
|
||||
unit_info2[#unit_info2 + 1] = {}
|
||||
unit_info2[#unit_info2]["unit"] = unit2
|
||||
unit_info2[#unit_info2]["pos"] = unit2:getPosition().p
|
||||
@@ -3118,6 +3249,8 @@ toggle = boolean or nil
|
||||
interval = {'number', 'nil'},
|
||||
radius = {'number', 'nil'},
|
||||
toggle = {'boolean', 'nil'},
|
||||
unitTableDef1 = {'table', 'nil'},
|
||||
unitTableDef2 = {'table', 'nil'},
|
||||
}
|
||||
|
||||
local err, errmsg = mist.utils.typeCheck('mist.flagFunc.units_LOS', type_tbl, vars)
|
||||
@@ -3132,28 +3265,38 @@ toggle = boolean or nil
|
||||
local radius = vars.radius or math.huge
|
||||
local req_num = vars.req_num or vars.reqnum or 1
|
||||
local toggle = vars.toggle or nil
|
||||
local unitTableDef1 = vars.unitTableDef1
|
||||
local unitTableDef2 = vars.unitTableDef2
|
||||
|
||||
|
||||
if not unitset1.processed then -- run unit table short cuts
|
||||
unitset1 = mist.makeUnitTable(unitset1)
|
||||
if not unitset1.processed then
|
||||
unitTableDef1 = mist.utils.deepCopy(unitset1)
|
||||
end
|
||||
|
||||
if not unitset2.processed then -- run unit table short cuts
|
||||
unitset2 = mist.makeUnitTable(unitset2)
|
||||
if not unitset2.processed then
|
||||
unitTableDef2 = mist.utils.deepCopy(unitset2)
|
||||
end
|
||||
|
||||
if (unitset1.processed and unitset1.processed < mist.getLastDBUpdateTime()) or not unitset1.processed then -- run unit table short cuts
|
||||
unitset1 = mist.makeUnitTable(unitTableDef1)
|
||||
end
|
||||
|
||||
if (unitset2.processed and unitset2.processed < mist.getLastDBUpdateTime()) or not unitset2.processed then -- run unit table short cuts
|
||||
unitset2 = mist.makeUnitTable(unitTableDef2)
|
||||
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
|
||||
|
||||
local unitLOSdata = mist.getUnitsLOS(unitset1, altoffset1, unitset2, altoffset2, radius)
|
||||
|
||||
if #unitLOSdata >= req_num and trigger.misc.getUserFlag(flag) == false then
|
||||
if #unitLOSdata >= req_num and trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
elseif #unitLOSdata < req_num and toggle then
|
||||
trigger.action.setUserFlag(flag, false)
|
||||
end
|
||||
-- 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
|
||||
mist.scheduleFunction(mist.flagFunc.units_LOS, {{unitset1 = unitset1, altoffset1 = altoffset1, unitset2 = unitset2, altoffset2 = altoffset2, flag = flag, stopflag = stopflag, radius = radius, req_num = req_num, interval = interval, toggle = toggle}}, timer.getTime() + interval)
|
||||
mist.scheduleFunction(mist.flagFunc.units_LOS, {{unitset1 = unitset1, altoffset1 = altoffset1, unitset2 = unitset2, altoffset2 = altoffset2, flag = flag, stopflag = stopflag, radius = radius, req_num = req_num, interval = interval, toggle = toggle, unitTableDef1 = unitTableDef1, unitTableDef2 = unitTableDef2}}, timer.getTime() + interval)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3186,7 +3329,7 @@ stopFlag
|
||||
|
||||
|
||||
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 Group.getByName(groupName) and Group.getByName(groupName):isExist() == true then
|
||||
if Group.getByName(groupName) and Group.getByName(groupName):isExist() == true and #Group.getByName(groupName):getUnits() > 0 then
|
||||
if trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
end
|
||||
@@ -3223,7 +3366,7 @@ mist.flagFunc.group_dead = function(vars)
|
||||
|
||||
|
||||
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 Group.getByName(groupName) and Group.getByName(groupName):isExist() == false or not Group.getByName(groupName) then
|
||||
if (Group.getByName(groupName) and Group.getByName(groupName):isExist() == false) or (Group.getByName(groupName) and #Group.getByName(groupName):getUnits() < 1) or not Group.getByName(groupName) then
|
||||
if trigger.misc.getUserFlag(flag) == 0 then
|
||||
trigger.action.setUserFlag(flag, true)
|
||||
end
|
||||
@@ -3327,20 +3470,41 @@ mist.flagFunc.group_alive_more_than = function(vars)
|
||||
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)
|
||||
mist.getAvgPos = function(unitNames)
|
||||
local avgX, avgY, avgZ, totNum = 0, 0, 0, 0
|
||||
for i = 1, #unitNames do
|
||||
local unit = Unit.getByName(unitNames[i])
|
||||
local unit
|
||||
if Unit.getByName(unitNames[i]) then
|
||||
unit = Unit.getByName(unitNames[i])
|
||||
elseif StaticObject.getByName(unitNames[i]) then
|
||||
unit = StaticObject.getByName(unitNames[i])
|
||||
end
|
||||
if unit then
|
||||
|
||||
local pos = unit:getPosition().p
|
||||
avgX = avgX + pos.x
|
||||
avgY = avgY + pos.y
|
||||
avgZ = avgZ + pos.z
|
||||
totNum = totNum + 1
|
||||
if pos then -- you never know O.o
|
||||
avgX = avgX + pos.x
|
||||
avgY = avgY + pos.y
|
||||
avgZ = avgZ + pos.z
|
||||
totNum = totNum + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
if totNum ~= 0 then
|
||||
@@ -3500,10 +3664,13 @@ mist.goRoute = function(group, path)
|
||||
if type(group) == 'string' then
|
||||
group = Group.getByName(group)
|
||||
end
|
||||
local groupCon = group:getController()
|
||||
if groupCon then
|
||||
groupCon:setTask(misTask)
|
||||
return true
|
||||
local groupCon = nil
|
||||
if group then
|
||||
groupCon = group:getController()
|
||||
if groupCon then
|
||||
groupCon:setTask(misTask)
|
||||
return true
|
||||
end
|
||||
end
|
||||
--Controller.setTask(groupCon, misTask)
|
||||
return false
|
||||
@@ -3845,7 +4012,7 @@ mist.groupRandomDistSelf = function(gpData, dist, form, heading, speed)
|
||||
local pos = mist.getLeadPos(gpData)
|
||||
local fakeZone = {}
|
||||
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)
|
||||
|
||||
return
|
||||
@@ -4003,6 +4170,37 @@ do
|
||||
local displayActive = false
|
||||
local displayFuncId = 0
|
||||
|
||||
local caSlots = false
|
||||
local caMSGtoGroup = false
|
||||
|
||||
if env.mission.groundControl then -- just to be sure?
|
||||
for index, value in pairs(env.mission.groundControl) do
|
||||
if type(value) == 'table' then
|
||||
for roleName, roleVal in pairs(value) do
|
||||
for rIndex, rVal in pairs(roleVal) do
|
||||
if rIndex == 'red' or rIndex == 'blue' then
|
||||
if env.mission.groundControl[index][roleName][rIndex] > 0 then
|
||||
caSlots = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif type(value) == 'boolean' and value == true then
|
||||
caSlots = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function mistdisplayV5()
|
||||
--[[thoughts to improve upon
|
||||
event handler based activeClients table.
|
||||
display messages only when there is an update
|
||||
possibly co-routine it.
|
||||
]]
|
||||
end
|
||||
|
||||
local function mistdisplayV4()
|
||||
local activeClients = {}
|
||||
|
||||
@@ -4011,6 +4209,10 @@ do
|
||||
activeClients[clientData.groupId] = clientData.groupName
|
||||
end
|
||||
end
|
||||
|
||||
--[[if caSlots == true and caMSGtoGroup == true then
|
||||
|
||||
end]]
|
||||
|
||||
|
||||
if #messageList > 0 then
|
||||
@@ -4050,7 +4252,7 @@ do
|
||||
msgTableText[recData] = {}
|
||||
msgTableText[recData].text = {}
|
||||
if recData == 'RED' or recData == 'BLUE' then
|
||||
msgTableText[recData].text[1] = '---------------- Combined Arms Message: \n'
|
||||
msgTableText[recData].text[1] = '-------Combined Arms Message-------- \n'
|
||||
end
|
||||
msgTableText[recData].text[#msgTableText[recData].text + 1] = messageData.text
|
||||
msgTableText[recData].displayTime = messageData.displayTime - messageData.displayedFor
|
||||
@@ -4079,17 +4281,19 @@ do
|
||||
end
|
||||
------- new display
|
||||
|
||||
|
||||
if msgTableText['RED'] then
|
||||
trigger.action.outTextForCoalition(coalition.side.RED, table.concat(msgTableText['RED'].text), msgTableText['RED'].displayTime)
|
||||
end
|
||||
if msgTableText['BLUE'] then
|
||||
trigger.action.outTextForCoalition(coalition.side.BLUE, table.concat(msgTableText['BLUE'].text), msgTableText['BLUE'].displayTime)
|
||||
if caSlots == true and caMSGtoGroup == false then
|
||||
if msgTableText['RED'] then
|
||||
trigger.action.outTextForCoalition(coalition.side.RED, table.concat(msgTableText['RED'].text), msgTableText['RED'].displayTime, true)
|
||||
|
||||
end
|
||||
if msgTableText['BLUE'] then
|
||||
trigger.action.outTextForCoalition(coalition.side.BLUE, table.concat(msgTableText['BLUE'].text), msgTableText['BLUE'].displayTime, true)
|
||||
end
|
||||
end
|
||||
|
||||
for index, msgData in pairs(msgTableText) do
|
||||
if type(index) == 'number' then -- its a groupNumber
|
||||
trigger.action.outTextForGroup(index, table.concat(msgData.text), msgData.displayTime)
|
||||
trigger.action.outTextForGroup(index, table.concat(msgData.text), msgData.displayTime, true)
|
||||
end
|
||||
end
|
||||
--- new audio
|
||||
@@ -4100,6 +4304,7 @@ do
|
||||
trigger.action.outSoundForCoalition(coalition.side.BLUE, msgTableSound['BLUE'])
|
||||
end
|
||||
|
||||
|
||||
for index, file in pairs(msgTableSound) do
|
||||
if type(index) == 'number' then -- its a groupNumber
|
||||
trigger.action.outSoundForGroup(index, file)
|
||||
@@ -4111,6 +4316,22 @@ do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local typeBase = {
|
||||
['Mi-8MT'] = {'Mi-8MTV2', 'Mi-8MTV', 'Mi-8'},
|
||||
['MiG-21Bis'] = {'Mig-21'},
|
||||
['MiG-15bis'] = {'Mig-15'},
|
||||
['FW-190D9'] = {'FW-190'},
|
||||
['Bf-109K-4'] = {'Bf-109'},
|
||||
}
|
||||
|
||||
--[[mist.setCAGroupMSG = function(val)
|
||||
if type(val) == 'boolean' then
|
||||
caMSGtoGroup = val
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end]]
|
||||
|
||||
mist.message = {
|
||||
|
||||
@@ -4176,18 +4397,26 @@ do
|
||||
if type(listData) == 'string' then
|
||||
listData = string.lower(listData)
|
||||
end
|
||||
if forIndex == 'coa' and (listData == string.lower(clientData.coalition) or listData == 'all') or forIndex == 'countries' and string.lower(clientData.country) == listData or forIndex == 'units' and string.lower(clientData.unitName) == listData then --
|
||||
newMsgFor = msgSpamFilter(newMsgFor, clientId) -- so units dont get the same message twice if complex rules are given
|
||||
if (forIndex == 'coa' and (listData == string.lower(clientData.coalition) or listData == 'all')) or (forIndex == 'countries' and string.lower(clientData.country) == listData) or (forIndex == 'units' and string.lower(clientData.unitName) == listData) then --
|
||||
newMsgFor = msgSpamFilter(newMsgFor, clientData.groupId) -- so units dont get the same message twice if complex rules are given
|
||||
--table.insert(newMsgFor, clientId)
|
||||
elseif forIndex == 'unittypes' then
|
||||
for typeId, typeData in pairs(listData) do
|
||||
local found = false
|
||||
for clientDataEntry, clientDataVal in pairs(clientData) do
|
||||
if type(clientDataVal) == 'string' then
|
||||
if string.lower(list) == string.lower(clientDataVal) or list == 'all' then
|
||||
if typeData == clientData.type then
|
||||
if mist.matchString(list, clientDataVal) == true or list == 'all' then
|
||||
local sString = typeData
|
||||
for rName, pTbl in pairs(typeBase) do -- just a quick check to see if the user may have meant something and got the specific type of the unit wrong
|
||||
for pIndex, pName in pairs(pTbl) do
|
||||
if mist.stringMatch(sString, pName) then
|
||||
sString = rName
|
||||
end
|
||||
end
|
||||
end
|
||||
if sString == clientData.type then
|
||||
found = true
|
||||
newMsgFor = msgSpamFilter(newMsgFor, clientId) -- sends info oto other function to see if client is already recieving the current message.
|
||||
newMsgFor = msgSpamFilter(newMsgFor, clientData.groupId) -- sends info oto other function to see if client is already recieving the current message.
|
||||
--table.insert(newMsgFor, clientId)
|
||||
end
|
||||
end
|
||||
@@ -4204,8 +4433,6 @@ do
|
||||
if string.lower(forIndex) == 'coa' or string.lower(forIndex) == 'ca' then
|
||||
if listData == string.lower(coaData) or listData == 'all' then
|
||||
newMsgFor = msgSpamFilter(newMsgFor, coaData)
|
||||
--table.insert(newMsgFor, coaData)
|
||||
-- added redca or blueca to list
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4241,7 +4468,7 @@ do
|
||||
messageID = messageID + 1
|
||||
new.messageID = messageID
|
||||
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', new}, 'newMsg.txt')
|
||||
--mist.debug.writeData(mist.utils.serialize,{'msg', new}, 'newMsg.lua')
|
||||
|
||||
|
||||
messageList[#messageList + 1] = new
|
||||
@@ -5109,11 +5336,15 @@ mist.teleportToPoint = function(vars) -- main teleport function that all of tele
|
||||
newGroupData.units[unitNum]["y"] = unitData.y + diff.y
|
||||
end
|
||||
if point then
|
||||
if (newGroupData.category == 'plane' or newGroupData.category == 'helicopter') and point.z then
|
||||
if point.y > 0 and point.y > land.getHeight({newGroupData.units[unitNum]["x"], newGroupData.units[unitNum]["y"]}) + 10 then
|
||||
if (newGroupData.category == 'plane' or newGroupData.category == 'helicopter') then
|
||||
if point.z and point.y > 0 and point.y > land.getHeight({newGroupData.units[unitNum]["x"], newGroupData.units[unitNum]["y"]}) + 10 then
|
||||
newGroupData.units[unitNum]["alt"] = point.y
|
||||
else
|
||||
newGroupData.units[unitNum]["alt"] = land.getHeight({newGroupData.units[unitNum]["x"], newGroupData.units[unitNum]["y"]}) + 300
|
||||
if newGroupData.category == 'plane' then
|
||||
newGroupData.units[unitNum]["alt"] = land.getHeight({newGroupData.units[unitNum]["x"], newGroupData.units[unitNum]["y"]}) + math.random(300, 9000)
|
||||
else
|
||||
newGroupData.units[unitNum]["alt"] = land.getHeight({newGroupData.units[unitNum]["x"], newGroupData.units[unitNum]["y"]}) + math.random(200, 3000)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5140,7 +5371,6 @@ mist.teleportToPoint = function(vars) -- main teleport function that all of tele
|
||||
if string.lower(newGroupData.category) == 'static' then
|
||||
return mist.dynAddStatic(newGroupData)
|
||||
end
|
||||
|
||||
return mist.dynAdd(newGroupData)
|
||||
|
||||
end
|
||||
Binary file not shown.
@@ -1,3 +1,67 @@
|
||||
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
|
||||
-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'.
|
||||
|
||||
v53
|
||||
-added mist.getAvgPos now accepts static objects in addition to units.
|
||||
-made DB creation check the mission editor version for no paticular reason
|
||||
-added mist.getLastDBUpdateTime which returns the most recent time the DB update function has run.
|
||||
-changed mist.makeUnitTable processed entry to return the time it was processed instead of a boolean value.
|
||||
-Changed teleport/respawn/clone functions to spawn aircraft at random altitudes instead of constants if the point given is vec2/not specified.
|
||||
-Fixed FlagFuncs will now recognize units added in dynamically. Note this only applies if you send it unitTableNames identifier and not the table that the function creates.
|
||||
-Added variable to all flagfuncs. unitTableDef is the original definition used for units.
|
||||
-Fixed all getUserFlag checks to compare with numerical value instead of boolean
|
||||
|
||||
v52
|
||||
-Fixed check in mist.getUnitsLOS to verify units are active in a mission
|
||||
-Fixed check in mist.goRoute to verify both the group and controller are valid before assigning the route
|
||||
|
||||
v51
|
||||
-Fixed bug with message system
|
||||
-Added a check to the message system so combined arms messages wont be sent if CA slots are not in a mission.
|
||||
|
||||
v50
|
||||
-something got deleted from v49 so this fixed it.
|
||||
|
||||
v49
|
||||
-fixed flagFuncs.group_dead and group_alive issue caused via a DCS bug.
|
||||
|
||||
v48
|
||||
-added support for cargo objects within dynAdd and DB scripts
|
||||
-DBs added entries for static objects
|
||||
|
||||
Reference in New Issue
Block a user