Fixed the botched merge

There was a conflict on merging lukrop's commit. I've fixed it and made
some other changes.

-Retabulated entire file. Fans of terrible drink from the 90s rejoice.
-Moved the mist init message back to the end of file and into the old
format.
-Commented out several of the new log:info statements that replaced old
commented out print statements.
This commit is contained in:
mrSkortch 2016-01-18 04:33:36 -07:00
parent e312ec70c3
commit b40a919bb0

780
mist.lua
View File

@ -35,7 +35,7 @@ mist = {}
-- don't change these -- don't change these
mist.majorVersion = 4 mist.majorVersion = 4
mist.minorVersion = 1 mist.minorVersion = 1
mist.build = 61 mist.build = 63
-- forward declaration of log shorthand -- forward declaration of log shorthand
local log local log
@ -368,7 +368,7 @@ do -- the main scope
mist.DBs.unitsByCat[unit_data.category] = mist.DBs.unitsByCat[unit_data.category] or {} -- future-proofing against new categories... mist.DBs.unitsByCat[unit_data.category] = mist.DBs.unitsByCat[unit_data.category] or {} -- future-proofing against new categories...
table.insert(mist.DBs.unitsByCat[unit_data.category], mist.utils.deepCopy(unit_data)) table.insert(mist.DBs.unitsByCat[unit_data.category], mist.utils.deepCopy(unit_data))
log:info('inserting $1', unit_data.unitName) --log:info('inserting $1', unit_data.unitName)
table.insert(mist.DBs.unitsByNum, mist.utils.deepCopy(unit_data)) table.insert(mist.DBs.unitsByNum, mist.utils.deepCopy(unit_data))
if unit_data.skill and (unit_data.skill == "Client" or unit_data.skill == "Player") then if unit_data.skill and (unit_data.skill == "Client" or unit_data.skill == "Player") then
@ -405,13 +405,13 @@ do -- the main scope
local original_key = key --only for duplicate runtime IDs. local original_key = key --only for duplicate runtime IDs.
local key_ind = 1 local key_ind = 1
while mist.DBs.deadObjects[key] do while mist.DBs.deadObjects[key] do
log:warn('duplicate runtime id of previously dead object key: $1', key) --log:warn('duplicate runtime id of previously dead object key: $1', key)
key = tostring(original_key) .. ' #' .. tostring(key_ind) key = tostring(original_key) .. ' #' .. tostring(key_ind)
key_ind = key_ind + 1 key_ind = key_ind + 1
end end
if mist.DBs.aliveUnits and mist.DBs.aliveUnits[val.object.id_] then if mist.DBs.aliveUnits and mist.DBs.aliveUnits[val.object.id_] then
log:info('object found in alive_units') --log:info('object found in alive_units')
val.objectData = mist.utils.deepCopy(mist.DBs.aliveUnits[val.object.id_]) val.objectData = mist.utils.deepCopy(mist.DBs.aliveUnits[val.object.id_])
local pos = Object.getPosition(val.object) local pos = Object.getPosition(val.object)
if pos then if pos then
@ -420,7 +420,7 @@ do -- the main scope
val.objectType = mist.DBs.aliveUnits[val.object.id_].category val.objectType = mist.DBs.aliveUnits[val.object.id_].category
elseif mist.DBs.removedAliveUnits and mist.DBs.removedAliveUnits[val.object.id_] then -- it didn't exist in alive_units, check old_alive_units elseif mist.DBs.removedAliveUnits and mist.DBs.removedAliveUnits[val.object.id_] then -- it didn't exist in alive_units, check old_alive_units
log:info('object found in old_alive_units') --log:info('object found in old_alive_units')
val.objectData = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_]) val.objectData = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_])
local pos = Object.getPosition(val.object) local pos = Object.getPosition(val.object)
if pos then if pos then
@ -429,13 +429,13 @@ do -- the main scope
val.objectType = mist.DBs.removedAliveUnits[val.object.id_].category val.objectType = mist.DBs.removedAliveUnits[val.object.id_].category
else --attempt to determine if static object... else --attempt to determine if static object...
log:info('object not found in alive units or old alive units') --log:info('object not found in alive units or old alive units')
local pos = Object.getPosition(val.object) local pos = Object.getPosition(val.object)
if pos then if pos then
local static_found = false local static_found = false
for ind, static in pairs(mist.DBs.unitsByCat.static) do for ind, static in pairs(mist.DBs.unitsByCat.static) do
if ((pos.p.x - static.point.x)^2 + (pos.p.z - static.point.y)^2)^0.5 < 0.1 then --really, it should be zero... if ((pos.p.x - static.point.x)^2 + (pos.p.z - static.point.y)^2)^0.5 < 0.1 then --really, it should be zero...
log:info('correlated dead static object to position') --log:info('correlated dead static object to position')
val.objectData = static val.objectData = static
val.objectPos = pos.p val.objectPos = pos.p
val.objectType = 'static' val.objectType = 'static'
@ -881,13 +881,13 @@ do -- the main scope
local original_id = id --only for duplicate runtime IDs. local original_id = id --only for duplicate runtime IDs.
local id_ind = 1 local id_ind = 1
while mist.DBs.deadObjects[id] do while mist.DBs.deadObjects[id] do
log:info('duplicate runtime id of previously dead object id: $1', id) --log:info('duplicate runtime id of previously dead object id: $1', id)
id = tostring(original_id) .. ' #' .. tostring(id_ind) id = tostring(original_id) .. ' #' .. tostring(id_ind)
id_ind = id_ind + 1 id_ind = id_ind + 1
end end
if mist.DBs.aliveUnits and mist.DBs.aliveUnits[val.object.id_] then if mist.DBs.aliveUnits and mist.DBs.aliveUnits[val.object.id_] then
log:info('object found in alive_units') --log:info('object found in alive_units')
val.objectData = mist.utils.deepCopy(mist.DBs.aliveUnits[val.object.id_]) val.objectData = mist.utils.deepCopy(mist.DBs.aliveUnits[val.object.id_])
local pos = Object.getPosition(val.object) local pos = Object.getPosition(val.object)
if pos then if pos then
@ -899,7 +899,7 @@ do -- the main scope
mist.DBs.activeHumans[Unit.getName(val.object)] = nil mist.DBs.activeHumans[Unit.getName(val.object)] = nil
end]] end]]
elseif mist.DBs.removedAliveUnits and mist.DBs.removedAliveUnits[val.object.id_] then -- it didn't exist in alive_units, check old_alive_units elseif mist.DBs.removedAliveUnits and mist.DBs.removedAliveUnits[val.object.id_] then -- it didn't exist in alive_units, check old_alive_units
log:info('object found in old_alive_units') --log:info('object found in old_alive_units')
val.objectData = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_]) val.objectData = mist.utils.deepCopy(mist.DBs.removedAliveUnits[val.object.id_])
local pos = Object.getPosition(val.object) local pos = Object.getPosition(val.object)
if pos then if pos then
@ -908,13 +908,13 @@ do -- the main scope
val.objectType = mist.DBs.removedAliveUnits[val.object.id_].category val.objectType = mist.DBs.removedAliveUnits[val.object.id_].category
else --attempt to determine if static object... else --attempt to determine if static object...
log:info('object not found in alive units or old alive units') --log:info('object not found in alive units or old alive units')
local pos = Object.getPosition(val.object) local pos = Object.getPosition(val.object)
if pos then if pos then
local static_found = false local static_found = false
for ind, static in pairs(mist.DBs.unitsByCat.static) do for ind, static in pairs(mist.DBs.unitsByCat.static) do
if ((pos.p.x - static.point.x)^2 + (pos.p.z - static.point.y)^2)^0.5 < 0.1 then --really, it should be zero... if ((pos.p.x - static.point.x)^2 + (pos.p.z - static.point.y)^2)^0.5 < 0.1 then --really, it should be zero...
log:info('correlated dead static object to position') --log:info('correlated dead static object to position')
val.objectData = static val.objectData = static
val.objectPos = pos.p val.objectPos = pos.p
val.objectType = 'static' val.objectType = 'static'
@ -931,7 +931,6 @@ do -- the main scope
end end
end end
mist.DBs.deadObjects[id] = val mist.DBs.deadObjects[id] = val
end end
end end
end end
@ -979,8 +978,8 @@ do -- the main scope
-- call main the first time therafter it reschedules itself. -- call main the first time therafter it reschedules itself.
mist.main() mist.main()
--log:msg('MIST version $1.$2.$3 loaded', mist.majorVersion, mist.minorVersion, mist.build)
log:msg('MIST version $1.$2.$3 loaded', mist.majorVersion, mist.minorVersion, mist.build) return
end end
--- The main function. --- The main function.
@ -4085,10 +4084,12 @@ do -- mist.debug scope
f:write(fcn(unpack(fcnVars, 1, table.maxn(fcnVars)))) f:write(fcn(unpack(fcnVars, 1, table.maxn(fcnVars))))
f:close() f:close()
log:info('Wrote debug data to $1', fdir) log:info('Wrote debug data to $1', fdir)
--trigger.action.outText(errmsg, 10) local errmsg = 'mist.debug.writeData wrote data to ' .. fdir
trigger.action.outText(errmsg, 10)
else else
log:alert('insufficient libraries to run mist.debug.dump_G, you must disable the sanitization of the io and lfs libraries in ./Scripts/MissionScripting.lua') local errmsg = 'Error: insufficient libraries to run mist.debug.writeData, you must disable the sanitization of the io and lfs libraries in ./Scripts/MissionScripting.lua'
--trigger.action.outText(errmsg, 10) log:alert(errmsg)
trigger.action.outText(errmsg, 10)
end end
end end
@ -6593,747 +6594,4 @@ end
-- initialize mist -- initialize mist
mist.init() mist.init()
-- vim: sw=2:ts=2
<<<<<<< HEAD
mist.respawnInZone = function(gpName, zone, disperse, maxDisp)
if type(gpName) == 'table' and gpName:getName() then
gpName = gpName:getName()
elseif type(gpName) == 'table' and gpName[1]:getName() then
gpName = math.random(#gpName)
else
gpName = tostring(gpName)
end
if type(zone) == 'string' then
zone = trigger.misc.getZone(zone)
elseif type(zone) == 'table' and not zone.radius then
zone = trigger.misc.getZone(zone[math.random(1, #zone)])
end
local vars = {}
vars.gpName = gpName
vars.action = 'respawn'
vars.point = zone.point
vars.radius = zone.radius
vars.disperse = disperse
vars.maxDisp = maxDisp
return mist.teleportToPoint(vars)
end
mist.cloneInZone = function(gpName, zone, disperse, maxDisp)
if type(gpName) == 'table' then
gpName = gpName:getName()
else
gpName = tostring(gpName)
end
if type(zone) == 'string' then
zone = trigger.misc.getZone(zone)
elseif type(zone) == 'table' and not zone.radius then
zone = trigger.misc.getZone(zone[math.random(1, #zone)])
end
local vars = {}
vars.gpName = gpName
vars.action = 'clone'
vars.point = zone.point
vars.radius = zone.radius
vars.disperse = disperse
vars.maxDisp = maxDisp
return mist.teleportToPoint(vars)
end
mist.teleportInZone = function(gpName, zone, disperse, maxDisp) -- groupName, zoneName or table of Zone Names, keepForm is a boolean
if type(gpName) == 'table' and gpName:getName() then
gpName = gpName:getName()
else
gpName = tostring(gpName)
end
if type(zone) == 'string' then
zone = trigger.misc.getZone(zone)
elseif type(zone) == 'table' and not zone.radius then
zone = trigger.misc.getZone(zone[math.random(1, #zone)])
end
local vars = {}
vars.gpName = gpName
vars.action = 'tele'
vars.point = zone.point
vars.radius = zone.radius
vars.disperse = disperse
vars.maxDisp = maxDisp
return mist.teleportToPoint(vars)
end
mist.respawnGroup = function(gpName, task)
local vars = {}
vars.gpName = gpName
vars.action = 'respawn'
if task and type(task) ~= 'number' then
vars.route = mist.getGroupRoute(gpName, 'task')
end
local newGroup = mist.teleportToPoint(vars)
if task and type(task) == 'number' then
local newRoute = mist.getGroupRoute(gpName, 'task')
mist.scheduleFunction(mist.goRoute, {newGroup, newRoute}, timer.getTime() + task)
end
return newGroup
end
mist.cloneGroup = function(gpName, task)
local vars = {}
vars.gpName = gpName
vars.action = 'clone'
if task and type(task) ~= 'number' then
vars.route = mist.getGroupRoute(gpName, 'task')
end
local newGroup = mist.teleportToPoint(vars)
if task and type(task) == 'number' then
local newRoute = mist.getGroupRoute(gpName, 'task')
mist.scheduleFunction(mist.goRoute, {newGroup, newRoute}, timer.getTime() + task)
end
return newGroup
end
mist.teleportGroup = function(gpName, task)
local vars = {}
vars.gpName = gpName
vars.action = 'teleport'
if task and type(task) ~= 'number' then
vars.route = mist.getGroupRoute(gpName, 'task')
end
local newGroup = mist.teleportToPoint(vars)
if task and type(task) == 'number' then
local newRoute = mist.getGroupRoute(gpName, 'task')
mist.scheduleFunction(mist.goRoute, {newGroup, newRoute}, timer.getTime() + task)
end
return newGroup
end
mist.spawnRandomizedGroup = function(groupName, vars) -- need to debug
if Group.getByName(groupName) and Group.getByName(groupName):isExist() == true then
local gpData = mist.getGroupData(groupName)
gpData.units = mist.randomizeGroupOrder(gpData.units, vars)
gpData.route = mist.getGroupRoute(groupName, 'task')
mist.dynAdd(gpData)
end
return true
end
mist.randomizeNumTable = function(vars)
local newTable = {}
local excludeIndex = {}
local randomTable = {}
if vars and vars.exclude and type(vars.exclude) == 'table' then
for index, data in pairs(vars.exclude) do
excludeIndex[data] = true
end
end
local low, hi, size
if vars.size then
size = vars.size
end
if vars and vars.lowerLimit and type(vars.lowerLimit) == 'number' then
low = mist.utils.round(vars.lowerLimit)
else
low = 1
end
if vars and vars.upperLimit and type(vars.upperLimit) == 'number' then
hi = mist.utils.round(vars.upperLimit)
else
hi = size
end
local choices = {}
-- add to exclude list and create list of what to randomize
for i = 1, size do
if not (i >= low and i <= hi) then
excludeIndex[i] = true
end
if not excludeIndex[i] then
table.insert(choices, i)
else
newTable[i] = i
end
end
for ind, num in pairs(choices) do
local found = false
local x = 0
while found == false do
x = mist.random(size) -- get random number from list
local addNew = true
for index, _ in pairs(excludeIndex) do
if index == x then
addNew = false
break
end
end
if addNew == true then
excludeIndex[x] = true
found = true
end
excludeIndex[x] = true
end
newTable[num] = x
end
--[[
for i = 1, #newTable do
env.info(newTable[i])
end
]]
return newTable
end
mist.randomizeGroupOrder = function(passedUnits, vars)
-- figure out what to exclude, and send data to other func
local units = passedUnits
if passedUnits.units then
units = passUnits.units
end
local exclude = {}
local excludeNum = {}
if vars and vars.excludeType and type(vars.excludeType) == 'table' then
exclude = vars.excludeType
end
if vars and vars.excludeNum and type(vars.excludeNum) == 'table' then
excludeNum = vars.excludeNum
end
local low, hi
if vars and vars.lowerLimit and type(vars.lowerLimit) == 'number' then
low = mist.utils.round(vars.lowerLimit)
else
low = 1
end
if vars and vars.upperLimit and type(vars.upperLimit) == 'number' then
hi = mist.utils.round(vars.upperLimit)
else
hi = #units
end
local excludeNum = {}
for unitIndex, unitData in pairs(units) do
if unitIndex >= low and unitIndex <= hi then -- if within range
local found = false
if #exclude > 0 then
for excludeType, index in pairs(exclude) do -- check if excluded
if mist.stringMatch(excludeType, unitData.type) then -- if excluded
excludeNum[unitIndex] = unitIndex
found = true
end
end
end
else -- unitIndex is either to low, or to high: added to exclude list
excludeNum[unitIndex] = unitId
end
end
local newGroup = {}
local newOrder = mist.randomizeNumTable({exclude = excludeNum, size = #units})
for unitIndex, unitData in pairs(units) do
for i = 1, #newOrder do
if newOrder[i] == unitIndex then
newGroup[i] = mist.utils.deepCopy(units[i]) -- gets all of the unit data
newGroup[i].type = mist.utils.deepCopy(unitData.type)
newGroup[i].skill = mist.utils.deepCopy(unitData.skill)
newGroup[i].unitName = mist.utils.deepCopy(unitData.unitName)
newGroup[i].unitIndex = mist.utils.deepCopy(unitData.unitIndex) -- replaces the units data with a new type
end
end
end
return newGroup
end
mist.ground.patrolRoute = function(vars)
local tempRoute = {}
local useRoute = {}
local gpData = vars.gpData
if type(gpData) == 'string' then
gpData = Group.getByName(gpData)
end
local useGroupRoute
if not vars.useGroupRoute then
useGroupRoute = vars.gpData
else
useGroupRoute = vars.useGroupRoute
end
local routeProvided = false
if not vars.route then
if useGroupRoute then
tempRoute = mist.getGroupRoute(useGroupRoute)
end
else
useRoute = vars.route
local posStart = mist.getLeadPos(gpData)
useRoute[1] = mist.ground.buildWP(posStart, useRoute[1].action, useRoute[1].speed)
routeProvided = true
end
local overRideSpeed = vars.speed or 'default'
local pType = vars.pType
local offRoadForm = vars.offRoadForm or 'default'
local onRoadForm = vars.onRoadForm or 'default'
if routeProvided == false and #tempRoute > 0 then
local posStart = mist.getLeadPos(gpData)
useRoute[#useRoute + 1] = mist.ground.buildWP(posStart, offRoadForm, overRideSpeed)
for i = 1, #tempRoute do
local tempForm = tempRoute[i].action
local tempSpeed = tempRoute[i].speed
if offRoadForm == 'default' then
tempForm = tempRoute[i].action
end
if onRoadForm == 'default' then
onRoadForm = 'On Road'
end
if (string.lower(tempRoute[i].action) == 'on road' or string.lower(tempRoute[i].action) == 'onroad' or string.lower(tempRoute[i].action) == 'on_road') then
tempForm = onRoadForm
else
tempForm = offRoadForm
end
if type(overRideSpeed) == 'number' then
tempSpeed = overRideSpeed
end
useRoute[#useRoute + 1] = mist.ground.buildWP(tempRoute[i], tempForm, tempSpeed)
end
if pType and string.lower(pType) == 'doubleback' then
local curRoute = mist.utils.deepCopy(useRoute)
for i = #curRoute, 2, -1 do
useRoute[#useRoute + 1] = mist.ground.buildWP(curRoute[i], curRoute[i].action, curRoute[i].speed)
end
end
useRoute[1].action = useRoute[#useRoute].action -- make it so the first WP matches the last WP
end
local cTask3 = {}
local newPatrol = {}
newPatrol.route = useRoute
newPatrol.gpData = gpData:getName()
cTask3[#cTask3 + 1] = 'mist.ground.patrolRoute('
cTask3[#cTask3 + 1] = mist.utils.oneLineSerialize(newPatrol)
cTask3[#cTask3 + 1] = ')'
cTask3 = table.concat(cTask3)
local tempTask = {
id = 'WrappedAction',
params = {
action = {
id = 'Script',
params = {
command = cTask3,
},
},
},
}
useRoute[#useRoute].task = tempTask
mist.goRoute(gpData, useRoute)
return
end
mist.ground.patrol = function(gpData, pType, form, speed)
local vars = {}
if type(gpData) == 'table' and gpData:getName() then
gpData = gpData:getName()
end
vars.useGroupRoute = gpData
vars.gpData = gpData
vars.pType = pType
vars.offRoadForm = form
vars.speed = speed
mist.ground.patrolRoute(vars)
return
end
mist.random = function(firstNum, secondNum) -- no support for decimals
local lowNum, highNum
if not secondNum then
highNum = firstNum
lowNum = 1
else
lowNum = firstNum
highNum = secondNum
end
local total = 1
if math.abs(highNum - lowNum + 1) < 50 then -- if total values is less than 50
total = math.modf(50/math.abs(highNum - lowNum + 1)) -- make x copies required to be above 50
end
local choices = {}
for i = 1, total do -- iterate required number of times
for x = lowNum, highNum do -- iterate between the range
choices[#choices +1] = x -- add each entry to a table
end
end
local rtnVal = math.random(#choices) -- will now do a math.random of at least 50 choices
for i = 1, 10 do
rtnVal = math.random(#choices) -- iterate a few times for giggles
end
return choices[rtnVal]
end
mist.stringMatch = function(s1, s2, bool)
local exclude = {'%-', '%(', '%)', '%_', '%[', '%]', '%.', '%#', '% ', '%{', '%}', '%$', '%%', '%?', '%+', '%^'}
if type(s1) == 'string' and type(s2) == 'string' then
for i , str in pairs(exclude) do
s1 = string.gsub(s1, str, '')
s2 = string.gsub(s2, str, '')
end
if not bool then
s1 = string.lower(s1)
s2 = string.lower(s2)
end
if s1 == s2 then
return true
else
return false
end
else
env.info('mist.stringMatch; Either the first or second variable were not a string')
return false
end
end
mist.matchString = mist.stringMatch -- both commands work because order out type of I
mist.time = {}
-- returns a string for specified military time
-- theTime is optional
-- if present current time in mil time is returned
-- if number or table the time is converted into mil tim
mist.time.convertToSec = function(timeTable)
timeInSec = 0
if timeTable and type(timeTable) == 'number' then
timeInSec = timeTable
elseif timeTable and type(timeTable) == 'table' and (timeTable.d or timeTable.h or timeTable.m or timeTable.s) then
if timeTable.d and type(timeTable.d) == 'number' then
timeInSec = timeInSec + (timeTable.d*86400)
end
if timeTable.h and type(timeTable.h) == 'number' then
timeInSec = timeInSec + (timeTable.h*3600)
end
if timeTable.m and type(timeTable.m) == 'number' then
timeInSec = timeInSec + (timeTable.m*60)
end
if timeTable.s and type(timeTable.s) == 'number' then
timeInSec = timeInSec + timeTable.s
end
end
return timeInSec
end
mist.time.getDHMS = function(timeInSec)
if timeInSec and type(timeInSec) == 'number' then
local tbl = {d = 0, h = 0, m = 0, s = 0}
if timeInSec > 86400 then
while timeInSec > 86400 do
tbl.d = tbl.d + 1
timeInSec = timeInSec - 86400
end
end
if timeInSec > 3600 then
while timeInSec > 3600 do
tbl.h = tbl.h + 1
timeInSec = timeInSec - 3600
end
end
if timeInSec > 60 then
while timeInSec > 60 do
tbl.m = tbl.m + 1
timeInSec = timeInSec - 60
end
end
tbl.s = timeInSec
return tbl
else
env.info('mist.time.getDHMS didnt recieve number')
return
end
end
mist.getMilString = function(theTime)
local timeInSec = 0
if theTime then
timeInSec = mist.time.convertToSec(theTime)
else
timeInSec = mist.utils.round(timer.getAbsTime(), 0)
end
local DHMS = mist.time.getDHMS(timeInSec)
return tostring(string.format('%02d', DHMS.h) .. string.format('%02d',DHMS.m))
end
mist.getClockString = function(theTime, hour)
local timeInSec = 0
if theTime then
timeInSec = mist.time.convertToSec(theTime)
else
timeInSec = mist.utils.round(timer.getAbsTime(), 0)
end
local DHMS = mist.time.getDHMS(timeInSec)
if hour then
if DHMS.h > 12 then
DHMS.h = DHMS.h - 12
return tostring(string.format('%02d', DHMS.h) .. ':' .. string.format('%02d',DHMS.m) .. ':' .. string.format('%02d',DHMS.s) .. ' PM')
else
return tostring(string.format('%02d', DHMS.h) .. ':' .. string.format('%02d',DHMS.m) .. ':' .. string.format('%02d',DHMS.s) .. ' AM')
end
else
return tostring(string.format('%02d', DHMS.h) .. ':' .. string.format('%02d',DHMS.m) .. ':' .. string.format('%02d',DHMS.s))
end
end
-- returns the date in string format
-- both variables optional
-- first val returns with the month as a string
-- 2nd val defins if it should be written the American way or the wrong way.
mist.time.getDate = function(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 date = {}
date.d = 0
date.m = 6
date.y = 2011
local start = 0
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
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
mist.time.relativeToStart = function(time)
if type(time) == 'number' then
return time - timer.getTime0()
end
end
mist.getDateString = function(rtnType, murica, oTime) -- returns date based on time
local word = {'January', 'Feburary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' } -- 'etc
local curTime = 0
if oTime then
curTime = oTime
else
curTime = mist.utils.round(timer.getAbsTime())
end
local tbl = mist.time.getDate(curTime)
if rtnType then
if murica then
return tostring(word[tbl.m] .. ' ' .. tbl.d .. ' ' .. tbl.y)
else
return tostring(tbl.d .. ' ' .. word[tbl.m] .. ' ' .. tbl.y)
end
else
if murica then
return tostring(tbl.m .. '.' .. tbl.d .. '.' .. tbl.y)
else
return tostring(tbl.d .. '.' .. tbl.m .. '.' .. tbl.y)
end
end
end
--WIP
mist.time.milToGame = function(milString, rtnType) --converts a military time. By default returns the abosolute time that event would occur. With optional value it returns how many seconds from time of call till that time.
local curTime = mist.utils.round(timer.getAbsTime())
local milTimeInSec = 0
if milString and type(milString) == 'string' and string.len(milString) >= 4 then
local hr = tonumber(string.sub(milString, 1, 2))
local mi = tonumber(string.sub(milString, 3))
milTimeInSec = milTimeInSec + (mi*60) + (hr*3600)
elseif milString and type(milString) == 'table' and (milString.d or milString.h or milString.m or milString.s) then
milTimeInSec = mist.time.convertToSec(milString)
end
local startTime = timer.getTime0()
local daysOffset = 0
if startTime > 86400 then
daysOffset = mist.utils.round(startTime/86400)
if daysOffset > 0 then
milTimeInSec = milTimeInSec *daysOffset
end
end
if curTime > milTimeInSec then
milTimeInSec = milTimeInSec + 86400
end
if rtnType then
milTimeInSec = milTimeInSec - startTime
end
return milTimeInSec
end
mist.DBs.const = {}
--[[
['LAND'] = 1,
['SHALLOW_WATER'] = 2,
['WATER'] = 3,
['ROAD'] = 4,
['RUNWAY'] = 5
]]
--[[mist.DBs.const.ME_SSE_terms = {
['ME'] = {
['vehicle'] = {'GROUND', 'GROUND_UNIT'},
['plane'] = {'AIRPLANE'},
},
['SSE'] = {
},
}]]
mist.DBs.const.callsigns = { -- not accessible by SSE, must use static list :-/
['NATO'] = {
['rules'] = {
['groupLimit'] = 9,
},
['AWACS'] = {
['Overlord'] = 1,
['Magic'] = 2,
['Wizard'] = 3,
['Focus'] = 4,
['Darkstar'] = 5,
},
['TANKER'] = {
['Texaco'] = 1,
['Arco'] = 2,
['Shell'] = 3,
},
['JTAC'] = {
['Axeman'] = 1,
['Darknight'] = 2,
['Warrior'] = 3,
['Pointer'] = 4,
['Eyeball'] = 5,
['Moonbeam'] = 6,
['Whiplash'] = 7,
['Finger'] = 8,
['Pinpoint'] = 9,
['Ferret'] = 10,
['Shaba'] = 11,
['Playboy'] = 12,
['Hammer'] = 13,
['Jaguar'] = 14,
['Deathstar'] = 15,
['Anvil'] = 16,
['Firefly'] = 17,
['Mantis'] = 18,
['Badger'] = 19,
},
['aircraft'] = {
['Enfield'] = 1,
['Springfield'] = 2,
['Uzi'] = 3,
['Colt'] = 4,
['Dodge'] = 5,
['Ford'] = 6,
['Chevy'] = 7,
['Pontiac'] = 8,
},
['unique'] = {
['A10'] = {
['Hawg'] = 9,
['Boar'] = 10,
['Pig'] = 11,
['Tusk'] = 12,
['rules'] = {
['canUseAircraft'] = true,
['appliesTo'] = {
'A-10C',
'A-10A',
},
},
},
},
},
}
--[[ scope:
{
units = {...}, -- unit names.
coa = {...}, -- coa names
countries = {...}, -- country names
CA = {...}, -- looks just like coa.
unitTypes = { red = {}, blue = {}, all = {}, Russia = {},}
}
scope examples:
{ units = { 'Hawg11', 'Hawg12' }, CA = {'blue'} }
{ countries = {'Georgia'}, unitTypes = {blue = {'A-10C', 'A-10A'}}}
{ coa = {'all'}}
{unitTypes = { blue = {'A-10C'}}}
]]
end
mist.main()
env.info(('Mist version ' .. mist.majorVersion .. '.' .. mist.minorVersion .. '.' .. mist.build .. ' loaded.')) env.info(('Mist version ' .. mist.majorVersion .. '.' .. mist.minorVersion .. '.' .. mist.build .. ' loaded.'))
=======
>>>>>>> origin/development