Compare commits

...

7 Commits

Author SHA1 Message Date
mrSkortch 52555f73f7 Merge pull request #30 from mrSkortch/development
rev 74
2016-09-20 02:18:34 -06:00
mrSkortch 9ff6be9311 rev 74
Minor fix to mist.getCurrentGroupData.
2016-09-20 02:16:13 -06:00
mrSkortch effa8eb5b1 Merge pull request #29 from mrSkortch/development
Assorted fixes
2016-07-11 15:46:43 -06:00
mrSkortch 7171a8f483 Assorted fixes
-fixed mist.time.getDate to account for changes made to the mission file
format related to how the mission start time and date are saved. Also
added in code to correctly account for leap years.

- fixed issue in DB updating checking the incorrect value

- fixed mist.getUnitSkill. Slightly reworked how the function got the
data.
2016-07-10 20:57:27 -06:00
mrSkortch b5c7b16500 Merge pull request #28 from mrSkortch/development
4.3 Hotfix-1
2016-06-01 01:05:05 -06:00
mrSkortch 4ff3d57d66 actual commit
Fixed an oops
2016-06-01 01:03:20 -06:00
mrSkortch 9dfd4929ea v71
Fixed a bug with flagFuncs to stop assigning the unitTableDef if the
corresponding units entry was invalid.
2016-06-01 01:02:31 -06:00
3 changed files with 214 additions and 108 deletions
+91 -54
View File
@@ -35,7 +35,7 @@ mist = {}
-- don't change these
mist.majorVersion = 4
mist.minorVersion = 3
mist.build = 71
mist.build = 74
-- forward declaration of log shorthand
local log
@@ -289,7 +289,7 @@ do -- the main scope
['Focus'] = 4,
['Darkstar'] = 5,
},
['TANKER'] = {
['TANKER'] = {
['Texaco'] = 1,
['Arco'] = 2,
['Shell'] = 3,
@@ -809,18 +809,21 @@ do -- the main scope
-- first check group level properties, groupId, countryId, coalition
dbLog:info('Found in DBs, check if updated')
local dbTable = mist.DBs.groupsByName[name]
local _u
dbLog:info(dbTable)
if gType ~= 'static' then
dbLog:info('Not static')
local _g = Group.getByName(name)
_u = _g:getUnit(1)
if dbTable.groupId ~= _g:getID() or _u:getCountry() ~= dbTable.countryId or _u:getCoalition() ~= coalition.side[string.upper(dbTable.coaltionId)] then
local _u = _g:getUnit(1)
if dbTable.groupId ~= tonumber(_g:getID()) or _u:getCountry() ~= dbTable.countryId or _u:getCoalition() ~= dbTable.coaltionId then
dbLog:info('Group Data mismatch')
updated = true
else
dbLog:info('No Mismatch')
end
end
end
dbLog:info('Updated: $1', updated)
if updated == false and gType ~= 'static' then -- time to check units
dbLog:info('No Group Mismatch, Check Units')
for index, uObject in pairs(Group.getByName(name):getUnits()) do
@@ -828,7 +831,7 @@ do -- the main scope
if mist.DBs.unitsByName[uObject:getName()] then
dbLog:info('UnitByName table exists')
local uTable = mist.DBs.unitsByName[uObject:getName()]
if uObject:getID() ~= uTable.unitId or uObject:getTypeName() ~= uTable.type then
if tonumber(uObject:getID()) ~= uTable.unitId or uObject:getTypeName() ~= uTable.type then
dbLog:info('Unit Data mismatch')
updated = true
break
@@ -1693,10 +1696,11 @@ do
-- @tparam string unitName unit name
-- @return skill of the unit
function mist.getUnitSkill(unitName)
if Unit.getByName(unitName) and Unit.getByName(unitName):isExist() == true then
local lunit = Unit.getByName(unitName)
for name, data in pairs(mist.DBs.unitsByName) do
if name == unitName and data.type == lunit:getTypeName() and data.unitId == lunit:getID() and data.skill then
if mist.DBs.unitsByName[unitName] then
if Unit.getByName(unitName) then
local lunit = Unit.getByName(unitName)
local data = mist.DBs.unitsByName[unitName]
if data.unitName == unitName and data.type == lunit:getTypeName() and data.unitId == tonumber(lunit:getID()) and data.skill then
return data.skill
end
end
@@ -2128,6 +2132,7 @@ do
-- @treturn table @{UnitNameTable}
function mist.makeUnitTable(tbl)
--Assumption: will be passed a table of strings, sequential
log:info(tbl)
local units_by_name = {}
local l_munits = mist.DBs.units --local reference for faster execution
@@ -2624,8 +2629,8 @@ function mist.getUnitsInMovingZones(unit_names, zone_unit_names, radius, zone_ty
end
function mist.getUnitsLOS(unitset1, altoffset1, unitset2, altoffset2, radius)
log:info("$1, $2, $3, $4, $5", unitset1, altoffset1, unitset2, altoffset2, radius)
radius = radius or math.huge
local unit_info1 = {}
local unit_info2 = {}
@@ -2950,19 +2955,26 @@ do -- group functions scope
local newUnits = newGroup:getUnits()
for unitNum, unitData in pairs(newGroup:getUnits()) do
newData.units[unitNum] = {}
newData.units[unitNum].unitId = tonumber(unitData:getID())
newData.units[unitNum].point = unitData.point
local uName = unitData:getName()
if mist.DBs.unitsByName[uName] and unitData:getTypeName() == mist.DBs.unitsByName[uName].type and mist.DBs.unitsByName[uName].unitId == tonumber(unitData:getID()) then -- If old data matches most of new data
newData.units[unitNum] = mist.utils.deepCopy(mist.DBs.unitsByName[uName])
else
newData.units[unitNum].unitId = tonumber(unitData:getID())
newData.units[unitNum].type = unitData:getTypeName()
newData.units[unitNum].skill = mist.getUnitSkill(uName)
newData.country = string.lower(country.name[unitData:getCountry()])
newData.units[unitNum].callsign = unitData:getCallsign()
newData.units[unitNum].unitName = uName
end
newData.units[unitNum].x = unitData:getPosition().p.x
newData.units[unitNum].y = unitData:getPosition().p.z
newData.units[unitNum].type = unitData:getTypeName()
newData.units[unitNum].skill = mist.getUnitSkill(unitData:getName())
-- get velocity needed
newData.units[unitNum].unitName = unitData:getName()
newData.units[unitNum].heading = mist.getHeading(unitData, true) -- added to DBs
newData.units[unitNum].point = {x = newData.units[unitNum].x, y = newData.units[unitNum].y}
newData.units[unitNum].heading = mist.getHeading(unitData, true) -- added to DBs
newData.units[unitNum].alt = unitData:getPosition().p.y
newData.country = string.lower(country.name[unitData:getCountry()])
newData.units[unitNum].callsign = unitData:getCallsign()
newData.units[unitNum].speed = mist.vec.mag(unitData:getVelocity())
end
return newData
@@ -3574,7 +3586,7 @@ do -- group functions scope
s1 = string.lower(s1)
s2 = string.lower(s2)
end
log:info('Comparing: $1 and $2', s1, s2)
if s1 == s2 then
return true
else
@@ -4522,7 +4534,9 @@ unitTableDef = table or nil
end
if (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
units = mist.makeUnitTable(unitTableDef)
if unitTableDef then
units = mist.makeUnitTable(unitTableDef)
end
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
@@ -4592,9 +4606,11 @@ unitTableDef = table or nil
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)
if unitTableDef then
units = mist.makeUnitTable(unitTableDef)
end
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
@@ -4666,11 +4682,16 @@ unitTableDef = table or nil
end
if (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
units = mist.makeUnitTable(unitTableDef)
if unitTableDef then
units = mist.makeUnitTable(unitTableDef)
end
end
if (zone_units.processed and zone_units.processed < mist.getLastDBUpdateTime()) or not zone_units.processed then -- run unit table short cuts
zone_units = mist.makeUnitTable(zUnitTableDef)
if zUnitTableDef then
zone_units = mist.makeUnitTable(zUnitTableDef)
end
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
@@ -4745,11 +4766,15 @@ toggle = boolean or nil
end
if (unitset1.processed and unitset1.processed < mist.getLastDBUpdateTime()) or not unitset1.processed then -- run unit table short cuts
unitset1 = mist.makeUnitTable(unitTableDef1)
if unitTableDef1 then
unitset1 = mist.makeUnitTable(unitTableDef1)
end
end
if (unitset2.processed and unitset2.processed < mist.getLastDBUpdateTime()) or not unitset2.processed then -- run unit table short cuts
unitset2 = mist.makeUnitTable(unitTableDef2)
if unitTableDef2 then
unitset2 = mist.makeUnitTable(unitTableDef2)
end
end
@@ -5801,34 +5826,45 @@ do -- mist.time scope
-- first val returns with the month as a string
-- 2nd val defins if it should be written the American way or the wrong way.
function mist.time.getDate(convert)
local cal = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} -- starts at june. 2011. 2012 is leap year, sigh. add a simple check for leap year
local cal = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} --
local date = {}
date.d = 0
date.m = 6
date.y = 2011
local start = 0
if not env.mission.date then -- Not likely to happen. Resaving mission auto updates this to remove it.
date.d = 0
date.m = 6
date.y = 2011
else
date.d = env.mission.date.Day
date.m = env.mission.date.Month
date.y = env.mission.date.Year
end
local start = 86400
local timeInSec = mist.utils.round(timer.getAbsTime())
if convert and type(convert) == 'number' then
timeInSec = convert
end
while start < timeInSec do
if date.d == cal[date.m] then
--if y % 4 >= 0 and i == 2 then -- for leap year. DCS doesnt do leapyear, but I am keeping the code dormant because maybe with WW2 the mission year may become relevant
--else
date.m = date.m + 1
date.d = 0
--end
if timeInSec > 86400 then
while start < timeInSec do
if date.d >= cal[date.m] then
if date.m == 2 and date.d == 28 then -- HOLY COW we can edit years now. Gotta re-add this!
if date.y % 4 == 0 and date.y % 100 == 0 and date.y % 400 ~= 0 or date.y % 4 > 0 then
date.m = date.m + 1
date.d = 0
end
--date.d = 29
else
date.m = date.m + 1
date.d = 0
end
end
if date.m == 13 then
date.m = 1
date.y = date.y + 1
end
date.d = date.d + 1
start = start + 86400
end
if date.m == 13 then
date.m = 1
date.y = date.y + 1
end
date.d = date.d + 1
start = start + 86400
end
return date
end
@@ -5998,6 +6034,7 @@ do -- group tasks scope
-- function mist.ground.buildPath() end -- ????
function mist.ground.patrolRoute(vars)
log:info('patrol')
local tempRoute = {}
local useRoute = {}
local gpData = vars.gpData
@@ -6088,9 +6125,9 @@ do -- group tasks scope
},
},
}
useRoute[#useRoute].task = tempTask
log:info(useRoute)
mist.goRoute(gpData, useRoute)
return
+91 -54
View File
@@ -35,7 +35,7 @@ mist = {}
-- don't change these
mist.majorVersion = 4
mist.minorVersion = 3
mist.build = 71
mist.build = 74
-- forward declaration of log shorthand
local log
@@ -289,7 +289,7 @@ do -- the main scope
['Focus'] = 4,
['Darkstar'] = 5,
},
['TANKER'] = {
['TANKER'] = {
['Texaco'] = 1,
['Arco'] = 2,
['Shell'] = 3,
@@ -809,18 +809,21 @@ do -- the main scope
-- first check group level properties, groupId, countryId, coalition
dbLog:info('Found in DBs, check if updated')
local dbTable = mist.DBs.groupsByName[name]
local _u
dbLog:info(dbTable)
if gType ~= 'static' then
dbLog:info('Not static')
local _g = Group.getByName(name)
_u = _g:getUnit(1)
if dbTable.groupId ~= _g:getID() or _u:getCountry() ~= dbTable.countryId or _u:getCoalition() ~= coalition.side[string.upper(dbTable.coaltionId)] then
local _u = _g:getUnit(1)
if dbTable.groupId ~= tonumber(_g:getID()) or _u:getCountry() ~= dbTable.countryId or _u:getCoalition() ~= dbTable.coaltionId then
dbLog:info('Group Data mismatch')
updated = true
else
dbLog:info('No Mismatch')
end
end
end
dbLog:info('Updated: $1', updated)
if updated == false and gType ~= 'static' then -- time to check units
dbLog:info('No Group Mismatch, Check Units')
for index, uObject in pairs(Group.getByName(name):getUnits()) do
@@ -828,7 +831,7 @@ do -- the main scope
if mist.DBs.unitsByName[uObject:getName()] then
dbLog:info('UnitByName table exists')
local uTable = mist.DBs.unitsByName[uObject:getName()]
if uObject:getID() ~= uTable.unitId or uObject:getTypeName() ~= uTable.type then
if tonumber(uObject:getID()) ~= uTable.unitId or uObject:getTypeName() ~= uTable.type then
dbLog:info('Unit Data mismatch')
updated = true
break
@@ -1693,10 +1696,11 @@ do
-- @tparam string unitName unit name
-- @return skill of the unit
function mist.getUnitSkill(unitName)
if Unit.getByName(unitName) and Unit.getByName(unitName):isExist() == true then
local lunit = Unit.getByName(unitName)
for name, data in pairs(mist.DBs.unitsByName) do
if name == unitName and data.type == lunit:getTypeName() and data.unitId == lunit:getID() and data.skill then
if mist.DBs.unitsByName[unitName] then
if Unit.getByName(unitName) then
local lunit = Unit.getByName(unitName)
local data = mist.DBs.unitsByName[unitName]
if data.unitName == unitName and data.type == lunit:getTypeName() and data.unitId == tonumber(lunit:getID()) and data.skill then
return data.skill
end
end
@@ -2128,6 +2132,7 @@ do
-- @treturn table @{UnitNameTable}
function mist.makeUnitTable(tbl)
--Assumption: will be passed a table of strings, sequential
log:info(tbl)
local units_by_name = {}
local l_munits = mist.DBs.units --local reference for faster execution
@@ -2624,8 +2629,8 @@ function mist.getUnitsInMovingZones(unit_names, zone_unit_names, radius, zone_ty
end
function mist.getUnitsLOS(unitset1, altoffset1, unitset2, altoffset2, radius)
log:info("$1, $2, $3, $4, $5", unitset1, altoffset1, unitset2, altoffset2, radius)
radius = radius or math.huge
local unit_info1 = {}
local unit_info2 = {}
@@ -2950,19 +2955,26 @@ do -- group functions scope
local newUnits = newGroup:getUnits()
for unitNum, unitData in pairs(newGroup:getUnits()) do
newData.units[unitNum] = {}
newData.units[unitNum].unitId = tonumber(unitData:getID())
newData.units[unitNum].point = unitData.point
local uName = unitData:getName()
if mist.DBs.unitsByName[uName] and unitData:getTypeName() == mist.DBs.unitsByName[uName].type and mist.DBs.unitsByName[uName].unitId == tonumber(unitData:getID()) then -- If old data matches most of new data
newData.units[unitNum] = mist.utils.deepCopy(mist.DBs.unitsByName[uName])
else
newData.units[unitNum].unitId = tonumber(unitData:getID())
newData.units[unitNum].type = unitData:getTypeName()
newData.units[unitNum].skill = mist.getUnitSkill(uName)
newData.country = string.lower(country.name[unitData:getCountry()])
newData.units[unitNum].callsign = unitData:getCallsign()
newData.units[unitNum].unitName = uName
end
newData.units[unitNum].x = unitData:getPosition().p.x
newData.units[unitNum].y = unitData:getPosition().p.z
newData.units[unitNum].type = unitData:getTypeName()
newData.units[unitNum].skill = mist.getUnitSkill(unitData:getName())
-- get velocity needed
newData.units[unitNum].unitName = unitData:getName()
newData.units[unitNum].heading = mist.getHeading(unitData, true) -- added to DBs
newData.units[unitNum].point = {x = newData.units[unitNum].x, y = newData.units[unitNum].y}
newData.units[unitNum].heading = mist.getHeading(unitData, true) -- added to DBs
newData.units[unitNum].alt = unitData:getPosition().p.y
newData.country = string.lower(country.name[unitData:getCountry()])
newData.units[unitNum].callsign = unitData:getCallsign()
newData.units[unitNum].speed = mist.vec.mag(unitData:getVelocity())
end
return newData
@@ -3574,7 +3586,7 @@ do -- group functions scope
s1 = string.lower(s1)
s2 = string.lower(s2)
end
log:info('Comparing: $1 and $2', s1, s2)
if s1 == s2 then
return true
else
@@ -4522,7 +4534,9 @@ unitTableDef = table or nil
end
if (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
units = mist.makeUnitTable(unitTableDef)
if unitTableDef then
units = mist.makeUnitTable(unitTableDef)
end
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
@@ -4592,9 +4606,11 @@ unitTableDef = table or nil
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)
if unitTableDef then
units = mist.makeUnitTable(unitTableDef)
end
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
@@ -4666,11 +4682,16 @@ unitTableDef = table or nil
end
if (units.processed and units.processed < mist.getLastDBUpdateTime()) or not units.processed then -- run unit table short cuts
units = mist.makeUnitTable(unitTableDef)
if unitTableDef then
units = mist.makeUnitTable(unitTableDef)
end
end
if (zone_units.processed and zone_units.processed < mist.getLastDBUpdateTime()) or not zone_units.processed then -- run unit table short cuts
zone_units = mist.makeUnitTable(zUnitTableDef)
if zUnitTableDef then
zone_units = mist.makeUnitTable(zUnitTableDef)
end
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
@@ -4745,11 +4766,15 @@ toggle = boolean or nil
end
if (unitset1.processed and unitset1.processed < mist.getLastDBUpdateTime()) or not unitset1.processed then -- run unit table short cuts
unitset1 = mist.makeUnitTable(unitTableDef1)
if unitTableDef1 then
unitset1 = mist.makeUnitTable(unitTableDef1)
end
end
if (unitset2.processed and unitset2.processed < mist.getLastDBUpdateTime()) or not unitset2.processed then -- run unit table short cuts
unitset2 = mist.makeUnitTable(unitTableDef2)
if unitTableDef2 then
unitset2 = mist.makeUnitTable(unitTableDef2)
end
end
@@ -5801,34 +5826,45 @@ do -- mist.time scope
-- first val returns with the month as a string
-- 2nd val defins if it should be written the American way or the wrong way.
function mist.time.getDate(convert)
local cal = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} -- starts at june. 2011. 2012 is leap year, sigh. add a simple check for leap year
local cal = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} --
local date = {}
date.d = 0
date.m = 6
date.y = 2011
local start = 0
if not env.mission.date then -- Not likely to happen. Resaving mission auto updates this to remove it.
date.d = 0
date.m = 6
date.y = 2011
else
date.d = env.mission.date.Day
date.m = env.mission.date.Month
date.y = env.mission.date.Year
end
local start = 86400
local timeInSec = mist.utils.round(timer.getAbsTime())
if convert and type(convert) == 'number' then
timeInSec = convert
end
while start < timeInSec do
if date.d == cal[date.m] then
--if y % 4 >= 0 and i == 2 then -- for leap year. DCS doesnt do leapyear, but I am keeping the code dormant because maybe with WW2 the mission year may become relevant
--else
date.m = date.m + 1
date.d = 0
--end
if timeInSec > 86400 then
while start < timeInSec do
if date.d >= cal[date.m] then
if date.m == 2 and date.d == 28 then -- HOLY COW we can edit years now. Gotta re-add this!
if date.y % 4 == 0 and date.y % 100 == 0 and date.y % 400 ~= 0 or date.y % 4 > 0 then
date.m = date.m + 1
date.d = 0
end
--date.d = 29
else
date.m = date.m + 1
date.d = 0
end
end
if date.m == 13 then
date.m = 1
date.y = date.y + 1
end
date.d = date.d + 1
start = start + 86400
end
if date.m == 13 then
date.m = 1
date.y = date.y + 1
end
date.d = date.d + 1
start = start + 86400
end
return date
end
@@ -5998,6 +6034,7 @@ do -- group tasks scope
-- function mist.ground.buildPath() end -- ????
function mist.ground.patrolRoute(vars)
log:info('patrol')
local tempRoute = {}
local useRoute = {}
local gpData = vars.gpData
@@ -6088,9 +6125,9 @@ do -- group tasks scope
},
},
}
useRoute[#useRoute].task = tempTask
log:info(useRoute)
mist.goRoute(gpData, useRoute)
return
+32
View File
@@ -1,3 +1,35 @@
v74
-fixed mist.getCurrentGroupData to return more data
v73
-fixed mist.time.getDate to account for changes made to the mission file format related to how the mission start time and date are saved. Also added in code to correctly account for leap years.
- fixed issue in DB updating checking the incorrect value
- fixed mist.getUnitSkill. Slightly reworked how the function got the data.
v72
fixed bug with flagFuncs to correctly check and assign unitTableDef entries.
v71
added shapename DB entry
dynAddStatic will now add a shapename if the object type matches a shapename DB entry
v70
Added assorted error checking on a few functions
v69
- Updated mission used to create DBs. There should no longer be any unit
names that are the same as group names.
Dynamically generated names will now be indexed accordingly to their
category. Used to be just a single counter shared between all.
Several changes and fixes to dynAddStatic
-Fixed function wasn't working when given certain params.
-fixed country checker to better account for country names with spaces.
This fix was applied to dynAdd but not dynAddStatic, I corrected this.
-Optimized it slightly. Trimmed the fat of some of the code.
v68
-DB refactor-start
v66
-Added default setting for logger if no value present
-Added documentation for logger