Merged several PRs

Merged several Pull Requests. Unified the build number.
This commit is contained in:
mrSkortch 2020-06-22 03:22:18 -06:00
parent 50ddf1f337
commit f15b4428d0
2 changed files with 143 additions and 79 deletions

View File

@ -35,13 +35,13 @@ mist = {}
-- don't change these -- don't change these
mist.majorVersion = 4 mist.majorVersion = 4
mist.minorVersion = 4 mist.minorVersion = 4
mist.build = 83 mist.build = 85
-- forward declaration of log shorthand -- forward declaration of log shorthand
local log local log
local mistSettings = { local mistSettings = {
errorPopup = false, -- errors printed by mist logger will create popup warning you errorPopup = true, -- errors printed by mist logger will create popup warning you
warnPopup = false, warnPopup = false,
infoPopup = false, infoPopup = false,
logLevel = 'warn', logLevel = 'warn',
@ -1204,7 +1204,7 @@ do -- the main scope
if mist.nextUnitId > 6900 and mist.nextUnitId < 30000 then if mist.nextUnitId > 6900 and mist.nextUnitId < 30000 then
mist.nextUnitId = 30000 mist.nextUnitId = 30000
end end
return mist.nextUnitId return mist.utils.deepCopy(mist.nextUnitId)
end end
--- Returns next group id. --- Returns next group id.
@ -1214,7 +1214,7 @@ do -- the main scope
if mist.nextGroupId > 6900 and mist.nextGroupId < 30000 then if mist.nextGroupId > 6900 and mist.nextGroupId < 30000 then
mist.nextGroupId = 30000 mist.nextGroupId = 30000
end end
return mist.nextGroupId return mist.utils.deepCopy(mist.nextGroupId)
end end
--- Returns timestamp of last database update. --- Returns timestamp of last database update.
@ -1227,7 +1227,7 @@ do -- the main scope
-- @todo write good docs -- @todo write good docs
-- @tparam table staticObj table containing data needed for the object creation -- @tparam table staticObj table containing data needed for the object creation
function mist.dynAddStatic(newObj) function mist.dynAddStatic(newObj)
log:info(newObj)
if newObj.units and newObj.units[1] then -- if its mist format if newObj.units and newObj.units[1] then -- if its mist format
for entry, val in pairs(newObj.units[1]) do for entry, val in pairs(newObj.units[1]) do
if newObj[entry] and newObj[entry] ~= val or not newObj[entry] then if newObj[entry] and newObj[entry] ~= val or not newObj[entry] then
@ -1272,6 +1272,7 @@ do -- the main scope
newObj.unitId = mistUnitId newObj.unitId = mistUnitId
end end
newObj.name = newObj.unitName
if newObj.clone or not newObj.name then if newObj.clone or not newObj.name then
mistDynAddIndex[' static '] = mistDynAddIndex[' static '] + 1 mistDynAddIndex[' static '] = mistDynAddIndex[' static '] + 1
newObj.name = (newCountry .. ' static ' .. mistDynAddIndex[' static ']) newObj.name = (newCountry .. ' static ' .. mistDynAddIndex[' static '])
@ -1305,7 +1306,7 @@ do -- the main scope
mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newObj) mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newObj)
if newObj.x and newObj.y and newObj.type and type(newObj.x) == 'number' and type(newObj.y) == 'number' and type(newObj.type) == 'string' then if newObj.x and newObj.y and newObj.type and type(newObj.x) == 'number' and type(newObj.y) == 'number' and type(newObj.type) == 'string' then
--log:info('addStaticObject') log:info(newObj)
coalition.addStaticObject(country.id[newCountry], newObj) coalition.addStaticObject(country.id[newCountry], newObj)
return newObj return newObj
@ -1467,12 +1468,14 @@ do -- the main scope
mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newGroup.units[unitIndex]) mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newGroup.units[unitIndex])
end end
mistAddedGroups[#mistAddedGroups + 1] = mist.utils.deepCopy(newGroup) mistAddedGroups[#mistAddedGroups + 1] = mist.utils.deepCopy(newGroup)
if newGroup.route then
if newGroup.route and not newGroup.route.points then if newGroup.route and not newGroup.route.points then
if not newGroup.route.points and newGroup.route[1] then if newGroup.route[1] then
local copyRoute = newGroup.route local copyRoute = mist.utils.deepCopy(newGroup.route)
newGroup.route = {} newGroup.route = {}
newGroup.route.points = copyRoute newGroup.route.points = copyRoute
end end
end
else -- if aircraft and no route assigned. make a quick and stupid route so AI doesnt RTB immediately else -- if aircraft and no route assigned. make a quick and stupid route so AI doesnt RTB immediately
if newCat == 'AIRPLANE' or newCat == 'HELICOPTER' then if newCat == 'AIRPLANE' or newCat == 'HELICOPTER' then
newGroup.route = {} newGroup.route = {}
@ -1484,7 +1487,7 @@ do -- the main scope
--mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, 'newGroup.lua') --mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, 'newGroup.lua')
--log:warn(newGroup)
-- sanitize table -- sanitize table
newGroup.groupName = nil newGroup.groupName = nil
newGroup.clone = nil newGroup.clone = nil
@ -3159,11 +3162,16 @@ do -- group functions scope
log:warn("Couldn't find payload for group: $1", groupIdent) log:warn("Couldn't find payload for group: $1", groupIdent)
return return
end
function mist.getValidRandomPoint(vars)
end end
function mist.teleportToPoint(vars) -- main teleport function that all of teleport/respawn functions call function mist.teleportToPoint(vars) -- main teleport function that all of teleport/respawn functions call
log:info(vars)
local point = vars.point local point = vars.point
log:info(point)
local gpName local gpName
if vars.gpName then if vars.gpName then
gpName = vars.gpName gpName = vars.gpName
@ -3176,12 +3184,7 @@ do -- group functions scope
local action = vars.action local action = vars.action
local disperse = vars.disperse or false local disperse = vars.disperse or false
local maxDisp = vars.maxDisp local maxDisp = vars.maxDisp or 200
if not vars.maxDisp then
maxDisp = 200
else
maxDisp = vars.maxDisp
end
local radius = vars.radius or 0 local radius = vars.radius or 0
local innerRadius = vars.innerRadius local innerRadius = vars.innerRadius
@ -3211,18 +3214,31 @@ do -- group functions scope
--log:info('get Randomized Point') --log:info('get Randomized Point')
local diff = {x = 0, y = 0} local diff = {x = 0, y = 0}
local newCoord, origCoord local newCoord, origCoord
if point and radius >= 0 then
local valid = false
local validTerrain local validTerrain = {'LAND', 'ROAD', 'SHALLOW_WATER', 'WATER', 'RUNWAY'}
if string.lower(newGroupData.category) == 'ship' then if string.lower(newGroupData.category) == 'ship' then
validTerrain = {'SHALLOW_WATER' , 'WATER'} validTerrain = {'SHALLOW_WATER' , 'WATER'}
elseif string.lower(newGroupData.category) == 'vehicle' then elseif string.lower(newGroupData.category) == 'vehicle' then
validTerrain = {'LAND', 'ROAD'} validTerrain = {'LAND', 'ROAD'}
else
validTerrain = {'LAND', 'ROAD', 'SHALLOW_WATER', 'WATER', 'RUNWAY'}
end end
local offsets = {}
if point and radius >= 0 then
local valid = false
-- new thoughts
-- Get AVG position of group and max radius distance to that avg point, otherwise use disperse data to get zone area to check
if disperse then
else
end
--
---- old
for i = 1, 100 do for i = 1, 100 do
newCoord = mist.getRandPointInCircle(point, radius, innerRadius) newCoord = mist.getRandPointInCircle(point, radius, innerRadius)
if mist.isTerrainValid(newCoord, validTerrain) then if mist.isTerrainValid(newCoord, validTerrain) then
@ -3245,15 +3261,28 @@ do -- group functions scope
end end
--log:info(point) --log:info(point)
for unitNum, unitData in pairs(newGroupData.units) do for unitNum, unitData in pairs(newGroupData.units) do
log:info(unitNum)
if disperse then if disperse then
local unitCoord
if maxDisp and type(maxDisp) == 'number' and unitNum ~= 1 then if maxDisp and type(maxDisp) == 'number' and unitNum ~= 1 then
newCoord = mist.getRandPointInCircle(origCoord, maxDisp) for i = 1, 100 do
unitCoord = mist.getRandPointInCircle(origCoord, maxDisp)
if mist.isTerrainValid(unitCoord, validTerrain) == true then
log:warn('Index: $1, Itered: $2. AT: $3', unitNum, i, unitCoord)
break
end
end
--else --else
--newCoord = mist.getRandPointInCircle(zone.point, zone.radius) --newCoord = mist.getRandPointInCircle(zone.point, zone.radius)
end end
if unitNum == 1 then
newGroupData.units[unitNum].x = newCoord.x unitCoord = mist.utils.deepCopy(newCoord)
newGroupData.units[unitNum].y = newCoord.y end
if unitCoord then
newGroupData.units[unitNum].x = unitCoord.x
newGroupData.units[unitNum].y = unitCoord.y
end
else else
newGroupData.units[unitNum].x = unitData.x + diff.x newGroupData.units[unitNum].x = unitData.x + diff.x
newGroupData.units[unitNum].y = unitData.y + diff.y newGroupData.units[unitNum].y = unitData.y + diff.y
@ -4329,6 +4358,8 @@ function mist.utils.oneLineSerialize(tbl)
end end
tbl_str[#tbl_str + 1] = '}' tbl_str[#tbl_str + 1] = '}'
return table.concat(tbl_str) return table.concat(tbl_str)
else
return mist.utils.basicSerialize(tbl)
end end
end end
@ -6137,7 +6168,7 @@ do -- mist.time scope
-- if number or table the time is converted into mil tim -- if number or table the time is converted into mil tim
function mist.time.convertToSec(timeTable) function mist.time.convertToSec(timeTable)
timeInSec = 0 local timeInSec = 0
if timeTable and type(timeTable) == 'number' then if timeTable and type(timeTable) == 'number' then
timeInSec = timeTable timeInSec = timeTable
elseif timeTable and type(timeTable) == 'table' and (timeTable.d or timeTable.h or timeTable.m or timeTable.s) then elseif timeTable and type(timeTable) == 'table' and (timeTable.d or timeTable.h or timeTable.m or timeTable.s) then
@ -6912,6 +6943,7 @@ do -- group tasks scope
end end
for validIndex, validData in pairs(typeConverted) do for validIndex, validData in pairs(typeConverted) do
if land.getSurfaceType(coord) == land.SurfaceType[validData] then if land.getSurfaceType(coord) == land.SurfaceType[validData] then
log:info('Surface is : $1', validData)
return true return true
end end
end end

View File

@ -35,13 +35,13 @@ mist = {}
-- don't change these -- don't change these
mist.majorVersion = 4 mist.majorVersion = 4
mist.minorVersion = 4 mist.minorVersion = 4
mist.build = 83 mist.build = 85
-- forward declaration of log shorthand -- forward declaration of log shorthand
local log local log
local mistSettings = { local mistSettings = {
errorPopup = false, -- errors printed by mist logger will create popup warning you errorPopup = true, -- errors printed by mist logger will create popup warning you
warnPopup = false, warnPopup = false,
infoPopup = false, infoPopup = false,
logLevel = 'warn', logLevel = 'warn',
@ -1204,7 +1204,7 @@ do -- the main scope
if mist.nextUnitId > 6900 and mist.nextUnitId < 30000 then if mist.nextUnitId > 6900 and mist.nextUnitId < 30000 then
mist.nextUnitId = 30000 mist.nextUnitId = 30000
end end
return mist.nextUnitId return mist.utils.deepCopy(mist.nextUnitId)
end end
--- Returns next group id. --- Returns next group id.
@ -1214,7 +1214,7 @@ do -- the main scope
if mist.nextGroupId > 6900 and mist.nextGroupId < 30000 then if mist.nextGroupId > 6900 and mist.nextGroupId < 30000 then
mist.nextGroupId = 30000 mist.nextGroupId = 30000
end end
return mist.nextGroupId return mist.utils.deepCopy(mist.nextGroupId)
end end
--- Returns timestamp of last database update. --- Returns timestamp of last database update.
@ -1227,7 +1227,7 @@ do -- the main scope
-- @todo write good docs -- @todo write good docs
-- @tparam table staticObj table containing data needed for the object creation -- @tparam table staticObj table containing data needed for the object creation
function mist.dynAddStatic(newObj) function mist.dynAddStatic(newObj)
log:info(newObj)
if newObj.units and newObj.units[1] then -- if its mist format if newObj.units and newObj.units[1] then -- if its mist format
for entry, val in pairs(newObj.units[1]) do for entry, val in pairs(newObj.units[1]) do
if newObj[entry] and newObj[entry] ~= val or not newObj[entry] then if newObj[entry] and newObj[entry] ~= val or not newObj[entry] then
@ -1272,6 +1272,7 @@ do -- the main scope
newObj.unitId = mistUnitId newObj.unitId = mistUnitId
end end
newObj.name = newObj.unitName
if newObj.clone or not newObj.name then if newObj.clone or not newObj.name then
mistDynAddIndex[' static '] = mistDynAddIndex[' static '] + 1 mistDynAddIndex[' static '] = mistDynAddIndex[' static '] + 1
newObj.name = (newCountry .. ' static ' .. mistDynAddIndex[' static ']) newObj.name = (newCountry .. ' static ' .. mistDynAddIndex[' static '])
@ -1305,7 +1306,7 @@ do -- the main scope
mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newObj) mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newObj)
if newObj.x and newObj.y and newObj.type and type(newObj.x) == 'number' and type(newObj.y) == 'number' and type(newObj.type) == 'string' then if newObj.x and newObj.y and newObj.type and type(newObj.x) == 'number' and type(newObj.y) == 'number' and type(newObj.type) == 'string' then
--log:info('addStaticObject') log:info(newObj)
coalition.addStaticObject(country.id[newCountry], newObj) coalition.addStaticObject(country.id[newCountry], newObj)
return newObj return newObj
@ -1467,12 +1468,14 @@ do -- the main scope
mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newGroup.units[unitIndex]) mistAddedObjects[#mistAddedObjects + 1] = mist.utils.deepCopy(newGroup.units[unitIndex])
end end
mistAddedGroups[#mistAddedGroups + 1] = mist.utils.deepCopy(newGroup) mistAddedGroups[#mistAddedGroups + 1] = mist.utils.deepCopy(newGroup)
if newGroup.route then
if newGroup.route and not newGroup.route.points then if newGroup.route and not newGroup.route.points then
if not newGroup.route.points and newGroup.route[1] then if newGroup.route[1] then
local copyRoute = newGroup.route local copyRoute = mist.utils.deepCopy(newGroup.route)
newGroup.route = {} newGroup.route = {}
newGroup.route.points = copyRoute newGroup.route.points = copyRoute
end end
end
else -- if aircraft and no route assigned. make a quick and stupid route so AI doesnt RTB immediately else -- if aircraft and no route assigned. make a quick and stupid route so AI doesnt RTB immediately
if newCat == 'AIRPLANE' or newCat == 'HELICOPTER' then if newCat == 'AIRPLANE' or newCat == 'HELICOPTER' then
newGroup.route = {} newGroup.route = {}
@ -1484,7 +1487,7 @@ do -- the main scope
--mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, 'newGroup.lua') --mist.debug.writeData(mist.utils.serialize,{'msg', newGroup}, 'newGroup.lua')
--log:warn(newGroup)
-- sanitize table -- sanitize table
newGroup.groupName = nil newGroup.groupName = nil
newGroup.clone = nil newGroup.clone = nil
@ -3159,11 +3162,16 @@ do -- group functions scope
log:warn("Couldn't find payload for group: $1", groupIdent) log:warn("Couldn't find payload for group: $1", groupIdent)
return return
end
function mist.getValidRandomPoint(vars)
end end
function mist.teleportToPoint(vars) -- main teleport function that all of teleport/respawn functions call function mist.teleportToPoint(vars) -- main teleport function that all of teleport/respawn functions call
log:info(vars)
local point = vars.point local point = vars.point
log:info(point)
local gpName local gpName
if vars.gpName then if vars.gpName then
gpName = vars.gpName gpName = vars.gpName
@ -3176,12 +3184,7 @@ do -- group functions scope
local action = vars.action local action = vars.action
local disperse = vars.disperse or false local disperse = vars.disperse or false
local maxDisp = vars.maxDisp local maxDisp = vars.maxDisp or 200
if not vars.maxDisp then
maxDisp = 200
else
maxDisp = vars.maxDisp
end
local radius = vars.radius or 0 local radius = vars.radius or 0
local innerRadius = vars.innerRadius local innerRadius = vars.innerRadius
@ -3211,18 +3214,31 @@ do -- group functions scope
--log:info('get Randomized Point') --log:info('get Randomized Point')
local diff = {x = 0, y = 0} local diff = {x = 0, y = 0}
local newCoord, origCoord local newCoord, origCoord
if point and radius >= 0 then
local valid = false
local validTerrain local validTerrain = {'LAND', 'ROAD', 'SHALLOW_WATER', 'WATER', 'RUNWAY'}
if string.lower(newGroupData.category) == 'ship' then if string.lower(newGroupData.category) == 'ship' then
validTerrain = {'SHALLOW_WATER' , 'WATER'} validTerrain = {'SHALLOW_WATER' , 'WATER'}
elseif string.lower(newGroupData.category) == 'vehicle' then elseif string.lower(newGroupData.category) == 'vehicle' then
validTerrain = {'LAND', 'ROAD'} validTerrain = {'LAND', 'ROAD'}
else
validTerrain = {'LAND', 'ROAD', 'SHALLOW_WATER', 'WATER', 'RUNWAY'}
end end
local offsets = {}
if point and radius >= 0 then
local valid = false
-- new thoughts
-- Get AVG position of group and max radius distance to that avg point, otherwise use disperse data to get zone area to check
if disperse then
else
end
--
---- old
for i = 1, 100 do for i = 1, 100 do
newCoord = mist.getRandPointInCircle(point, radius, innerRadius) newCoord = mist.getRandPointInCircle(point, radius, innerRadius)
if mist.isTerrainValid(newCoord, validTerrain) then if mist.isTerrainValid(newCoord, validTerrain) then
@ -3245,15 +3261,28 @@ do -- group functions scope
end end
--log:info(point) --log:info(point)
for unitNum, unitData in pairs(newGroupData.units) do for unitNum, unitData in pairs(newGroupData.units) do
log:info(unitNum)
if disperse then if disperse then
local unitCoord
if maxDisp and type(maxDisp) == 'number' and unitNum ~= 1 then if maxDisp and type(maxDisp) == 'number' and unitNum ~= 1 then
newCoord = mist.getRandPointInCircle(origCoord, maxDisp) for i = 1, 100 do
unitCoord = mist.getRandPointInCircle(origCoord, maxDisp)
if mist.isTerrainValid(unitCoord, validTerrain) == true then
log:warn('Index: $1, Itered: $2. AT: $3', unitNum, i, unitCoord)
break
end
end
--else --else
--newCoord = mist.getRandPointInCircle(zone.point, zone.radius) --newCoord = mist.getRandPointInCircle(zone.point, zone.radius)
end end
if unitNum == 1 then
newGroupData.units[unitNum].x = newCoord.x unitCoord = mist.utils.deepCopy(newCoord)
newGroupData.units[unitNum].y = newCoord.y end
if unitCoord then
newGroupData.units[unitNum].x = unitCoord.x
newGroupData.units[unitNum].y = unitCoord.y
end
else else
newGroupData.units[unitNum].x = unitData.x + diff.x newGroupData.units[unitNum].x = unitData.x + diff.x
newGroupData.units[unitNum].y = unitData.y + diff.y newGroupData.units[unitNum].y = unitData.y + diff.y
@ -4323,12 +4352,14 @@ function mist.utils.oneLineSerialize(tbl)
tbl_str[#tbl_str + 1] = mist.utils.oneLineSerialize(val) tbl_str[#tbl_str + 1] = mist.utils.oneLineSerialize(val)
tbl_str[#tbl_str + 1] = ', ' --I think this is right, I just added it tbl_str[#tbl_str + 1] = ', ' --I think this is right, I just added it
else else
log:war('Unable to serialize value type $1 at index $2', mist.utils.basicSerialize(type(val)), tostring(ind)) log:warn('Unable to serialize value type $1 at index $2', mist.utils.basicSerialize(type(val)), tostring(ind))
end end
end end
tbl_str[#tbl_str + 1] = '}' tbl_str[#tbl_str + 1] = '}'
return table.concat(tbl_str) return table.concat(tbl_str)
else
return mist.utils.basicSerialize(tbl)
end end
end end
@ -6137,7 +6168,7 @@ do -- mist.time scope
-- if number or table the time is converted into mil tim -- if number or table the time is converted into mil tim
function mist.time.convertToSec(timeTable) function mist.time.convertToSec(timeTable)
timeInSec = 0 local timeInSec = 0
if timeTable and type(timeTable) == 'number' then if timeTable and type(timeTable) == 'number' then
timeInSec = timeTable timeInSec = timeTable
elseif timeTable and type(timeTable) == 'table' and (timeTable.d or timeTable.h or timeTable.m or timeTable.s) then elseif timeTable and type(timeTable) == 'table' and (timeTable.d or timeTable.h or timeTable.m or timeTable.s) then
@ -6912,6 +6943,7 @@ do -- group tasks scope
end end
for validIndex, validData in pairs(typeConverted) do for validIndex, validData in pairs(typeConverted) do
if land.getSurfaceType(coord) == land.SurfaceType[validData] then if land.getSurfaceType(coord) == land.SurfaceType[validData] then
log:info('Surface is : $1', validData)
return true return true
end end
end end