mirror of
https://github.com/mrSkortch/MissionScriptingTools.git
synced 2025-08-15 10:47:23 +00:00
Sync with upstream
Merge upstream branch 'upstream/master'
This commit is contained in:
commit
e1c5516a8e
BIN
Mist guide.pdf
BIN
Mist guide.pdf
Binary file not shown.
9
mist.lua
9
mist.lua
@ -34,8 +34,8 @@ mist = {}
|
||||
|
||||
-- don't change these
|
||||
mist.majorVersion = 4
|
||||
mist.minorVersion = 0
|
||||
mist.build = 60
|
||||
mist.minorVersion = 1
|
||||
mist.build = 61
|
||||
|
||||
-- forward declaration of log shorthand
|
||||
local log
|
||||
@ -3322,9 +3322,10 @@ do -- mist.util scope
|
||||
--- Creates a waypoint from a unit.
|
||||
-- This function also considers the units speed.
|
||||
-- The alt_type of this waypoint is set to "BARO".
|
||||
-- @tparam Unit unit Unit whose position and speed will be used.
|
||||
-- @tparam Unit pUnit Unit whose position and speed will be used.
|
||||
-- @treturn Waypoint new waypoint.
|
||||
function mist.utils.unitToWP(unit)
|
||||
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)
|
||||
|
||||
@ -14,8 +14,8 @@ mist = {}
|
||||
|
||||
-- don't change these
|
||||
mist.majorVersion = 4
|
||||
mist.minorVersion = 0
|
||||
mist.build = 57
|
||||
mist.minorVersion = 1
|
||||
mist.build = 61
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------
|
||||
-- the main area
|
||||
@ -241,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
|
||||
@ -254,6 +254,7 @@ do
|
||||
local function checkSpawnedEvents()
|
||||
if #tempSpawnedUnits > 0 then
|
||||
local groupsToAdd = {}
|
||||
local added = false
|
||||
local ltemp = tempSpawnedUnits
|
||||
local ltable = table
|
||||
|
||||
@ -265,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
|
||||
@ -280,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
|
||||
@ -309,6 +321,7 @@ do
|
||||
|
||||
|
||||
local function updateDBTables()
|
||||
|
||||
local i = 0
|
||||
for index, newTable in pairs(writeGroups) do
|
||||
i = i + 1
|
||||
@ -548,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
|
||||
@ -591,6 +604,7 @@ do
|
||||
-- validate data
|
||||
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
|
||||
@ -649,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
|
||||
@ -921,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}
|
||||
@ -961,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
|
||||
@ -980,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
|
||||
|
||||
|
||||
|
||||
@ -1010,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)
|
||||
@ -1526,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
|
||||
@ -3414,6 +3470,21 @@ 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)
|
||||
Binary file not shown.
@ -1,3 +1,18 @@
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user