mirror of
https://github.com/mrSkortch/MissionScriptingTools.git
synced 2025-08-15 10:47:23 +00:00
Moar slight changes
Some minor fixes to code implemented last update 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.
This commit is contained in:
parent
3386d0daa5
commit
f96edc14bd
128
mist.lua
128
mist.lua
@ -35,7 +35,7 @@ mist = {}
|
|||||||
-- don't change these
|
-- don't change these
|
||||||
mist.majorVersion = 4
|
mist.majorVersion = 4
|
||||||
mist.minorVersion = 2
|
mist.minorVersion = 2
|
||||||
mist.build = 68
|
mist.build = 69
|
||||||
|
|
||||||
-- forward declaration of log shorthand
|
-- forward declaration of log shorthand
|
||||||
local log
|
local log
|
||||||
@ -53,12 +53,11 @@ do -- the main scope
|
|||||||
local lastUpdateTime = 0
|
local lastUpdateTime = 0
|
||||||
|
|
||||||
local updateAliveUnitsCounter = 0
|
local updateAliveUnitsCounter = 0
|
||||||
local writeDbTableCounter = 0
|
local updateTenthSecond = 0
|
||||||
local checkSpawnEventsCounter = 0
|
|
||||||
|
|
||||||
local mistGpId = 7000
|
local mistGpId = 7000
|
||||||
local mistUnitId = 7000
|
local mistUnitId = 7000
|
||||||
local mistDynAddIndex = 1
|
local mistDynAddIndex = {[' air '] = 0, [' hel '] = 0, [' gnd '] = 0, [' bld '] = 0, [' static '] = 0, [' shp '] = 0}
|
||||||
|
|
||||||
local scheduledTasks = {}
|
local scheduledTasks = {}
|
||||||
local taskId = 0
|
local taskId = 0
|
||||||
@ -703,7 +702,7 @@ do -- the main scope
|
|||||||
-- this function then checks DBs to see if data has changed
|
-- this function then checks DBs to see if data has changed
|
||||||
]]
|
]]
|
||||||
local function checkSpawnedEventsNew()
|
local function checkSpawnedEventsNew()
|
||||||
if tempSpawnedGroupsCounter > 0 then
|
if tempSpawnGroupsCounter > 0 then
|
||||||
--[[local updatesPerRun = math.ceil(#tempSpawnedGroupsCounter/20)
|
--[[local updatesPerRun = math.ceil(#tempSpawnedGroupsCounter/20)
|
||||||
if updatesPerRun < 5 then
|
if updatesPerRun < 5 then
|
||||||
updatesPerRun = 5
|
updatesPerRun = 5
|
||||||
@ -753,7 +752,7 @@ do -- the main scope
|
|||||||
end
|
end
|
||||||
-- Work done, so remove
|
-- Work done, so remove
|
||||||
tempSpawnedGroups[name] = nil
|
tempSpawnedGroups[name] = nil
|
||||||
tempSpawnedGroupsCounter = tempSpawnedGroupsCounter - 1
|
tempSpawnGroupsCounter = tempSpawnGroupsCounter - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -876,26 +875,26 @@ do -- the main scope
|
|||||||
-- dont need to add units spawned in at the start of the mission if mist is loaded in init line
|
-- dont need to add units spawned in at the start of the mission if mist is loaded in init line
|
||||||
if event.id == world.event.S_EVENT_BIRTH and timer.getTime0() < timer.getAbsTime() then
|
if event.id == world.event.S_EVENT_BIRTH and timer.getTime0() < timer.getAbsTime() then
|
||||||
dbLog:info('unitSpawnEvent')
|
dbLog:info('unitSpawnEvent')
|
||||||
if not Unit.getPlayerName(event.initiator) then -- simple player check, will need to later check to see if unit was spawned with a player in a flight
|
|
||||||
table.insert(tempSpawnedUnits,(event.initiator))
|
--table.insert(tempSpawnedUnits,(event.initiator))
|
||||||
-------
|
-------
|
||||||
-- New functionality below.
|
-- New functionality below.
|
||||||
-------
|
-------
|
||||||
if Object.getCategory(event.initiator) == 1 then
|
if Object.getCategory(event.initiator) == 1 and not Unit.getPlayerName(event.initiator) then -- simple player check, will need to later check to see if unit was spawned with a player in a flight
|
||||||
dbLog:info('Object is a Unit')
|
dbLog:info('Object is a Unit')
|
||||||
dbLog:info(Unit.getGroup(event.initiator):getName())
|
dbLog:info(Unit.getGroup(event.initiator):getName())
|
||||||
if not tempSpawnedGroups[Unit.getGroup(event.initiator):getName()] then
|
if not tempSpawnedGroups[Unit.getGroup(event.initiator):getName()] then
|
||||||
dbLog:info('added')
|
dbLog:info('added')
|
||||||
tempSpawnedGroups[Unit.getGroup(event.initiator):getName()] = 'group'
|
tempSpawnedGroups[Unit.getGroup(event.initiator):getName()] = 'group'
|
||||||
tempSpawnedGroupsCounter = tempSpawnGroupsCounter + 1
|
tempSpawnGroupsCounter = tempSpawnGroupsCounter + 1
|
||||||
end
|
|
||||||
elseif Object.getCategory(event.initiator) == 3 or Object.getCategory(event.initiator) == 6 then
|
|
||||||
dbLog:info('Object is Static')
|
|
||||||
tempSpawnedGroups[StaticObject.getName(event.initiator)] = 'static'
|
|
||||||
tempSpawnedGroupsCounter = tempSpawnGroupsCounter + 1
|
|
||||||
end
|
end
|
||||||
|
elseif Object.getCategory(event.initiator) == 3 or Object.getCategory(event.initiator) == 6 then
|
||||||
|
dbLog:info('Object is Static')
|
||||||
|
tempSpawnedGroups[StaticObject.getName(event.initiator)] = 'static'
|
||||||
|
tempSpawnGroupsCounter = tempSpawnGroupsCounter + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1118,62 +1117,37 @@ do -- the main scope
|
|||||||
--- Spawns a static object to the game world.
|
--- Spawns a static object to the game world.
|
||||||
-- @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(staticObj)
|
function mist.dynAddStatic(newObj)
|
||||||
local newObj = {}
|
|
||||||
newObj.groupId = staticObj.groupId
|
|
||||||
newObj.category = staticObj.category
|
|
||||||
newObj.type = staticObj.type
|
|
||||||
newObj.unitId = staticObj.unitId
|
|
||||||
newObj.y = staticObj.y
|
|
||||||
newObj.x = staticObj.x
|
|
||||||
newObj.heading = staticObj.heading
|
|
||||||
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
|
|
||||||
newObj.mass = staticObj.mass
|
|
||||||
newObj.categoryStatic = staticObj.categoryStatic
|
|
||||||
if staticObj.units then -- if its mist format
|
|
||||||
newObj.groupId = staticObj.units[1].groupId
|
|
||||||
newObj.category = staticObj.units[1].category
|
|
||||||
newObj.type = staticObj.units[1].type
|
|
||||||
newObj.unitId = staticObj.units[1].unitId
|
|
||||||
newObj.y = staticObj.units[1].y
|
|
||||||
newObj.x = staticObj.units[1].x
|
|
||||||
newObj.heading = staticObj.units[1].heading
|
|
||||||
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
|
|
||||||
|
|
||||||
if not newObj.country then
|
if newObj.units and newObj.units[1] then -- if its mist format
|
||||||
return false
|
for entry, val in pairs(newObj.units[1]) do
|
||||||
|
if newObj[entry] and newObj[entry] ~= val or not newObj[entry] then
|
||||||
|
newObj[entry] = val
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
--log:info(newObj)
|
||||||
local newCountry = newObj.country
|
|
||||||
|
local cntry = newObj.country
|
||||||
if newObj.countryId then
|
if newObj.countryId then
|
||||||
newCountry = newObj.countryId
|
cntry = newObj.countryId
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local newCountry = ''
|
||||||
|
|
||||||
for countryId, countryName in pairs(country.name) do
|
for countryId, countryName in pairs(country.name) do
|
||||||
if type(newObj.country) == 'string' then
|
if type(cntry) == 'string' then
|
||||||
if tostring(countryName) == string.upper(newObj.country) then
|
cntry = cntry:gsub("%s+", "_")
|
||||||
|
if tostring(countryName) == string.upper(cntry) then
|
||||||
newCountry = countryName
|
newCountry = countryName
|
||||||
end
|
end
|
||||||
elseif type(newObj.country) == 'number' then
|
elseif type(cntry) == 'number' then
|
||||||
if countryId == newObj.country then
|
if countryId == cntry then
|
||||||
newCountry = countryName
|
newCountry = countryName
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if newObj.clone or not newObj.groupId then
|
if newObj.clone or not newObj.groupId then
|
||||||
mistGpId = mistGpId + 1
|
mistGpId = mistGpId + 1
|
||||||
newObj.groupId = mistGpId
|
newObj.groupId = mistGpId
|
||||||
@ -1185,8 +1159,8 @@ do -- the main scope
|
|||||||
end
|
end
|
||||||
|
|
||||||
if newObj.clone or not newObj.name then
|
if newObj.clone or not newObj.name then
|
||||||
mistDynAddIndex = mistDynAddIndex + 1
|
mistDynAddIndex[' static '] = mistDynAddIndex[' static '] + 1
|
||||||
newObj.name = (country.name[newCountry] .. ' static ' .. mistDynAddIndex)
|
newObj.name = (country.name[cntry] .. ' static ' .. mistDynAddIndex[' static '])
|
||||||
end
|
end
|
||||||
|
|
||||||
if not newObj.dead then
|
if not newObj.dead then
|
||||||
@ -1196,7 +1170,7 @@ do -- the main scope
|
|||||||
if not newObj.heading then
|
if not newObj.heading then
|
||||||
newObj.heading = math.random(360)
|
newObj.heading = math.random(360)
|
||||||
end
|
end
|
||||||
|
|
||||||
if newObj.categoryStatic then
|
if newObj.categoryStatic then
|
||||||
newObj.category = newObj.categoryStatic
|
newObj.category = newObj.categoryStatic
|
||||||
end
|
end
|
||||||
@ -1205,6 +1179,7 @@ do -- the main scope
|
|||||||
end
|
end
|
||||||
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')
|
||||||
coalition.addStaticObject(country.id[newCountry], newObj)
|
coalition.addStaticObject(country.id[newCountry], newObj)
|
||||||
|
|
||||||
return newObj
|
return newObj
|
||||||
@ -1275,7 +1250,7 @@ do -- the main scope
|
|||||||
typeName = ' bld '
|
typeName = ' bld '
|
||||||
end
|
end
|
||||||
if newGroup.clone or not newGroup.groupId then
|
if newGroup.clone or not newGroup.groupId then
|
||||||
mistDynAddIndex = mistDynAddIndex + 1
|
mistDynAddIndex[typeName] = mistDynAddIndex[typeName] + 1
|
||||||
mistGpId = mistGpId + 1
|
mistGpId = mistGpId + 1
|
||||||
newGroup.groupId = mistGpId
|
newGroup.groupId = mistGpId
|
||||||
end
|
end
|
||||||
@ -1288,7 +1263,7 @@ do -- the main scope
|
|||||||
end
|
end
|
||||||
|
|
||||||
if newGroup.clone and mist.DBs.groupsByName[newGroup.name] or not newGroup.name then
|
if newGroup.clone and mist.DBs.groupsByName[newGroup.name] or not newGroup.name then
|
||||||
newGroup.name = tostring(tostring(country.name[cntry]) .. tostring(typeName) .. mistDynAddIndex)
|
newGroup.name = tostring(tostring(country.name[cntry]) .. tostring(typeName) .. mistDynAddIndex[typeName])
|
||||||
end
|
end
|
||||||
|
|
||||||
if not newGroup.hidden then
|
if not newGroup.hidden then
|
||||||
@ -2944,7 +2919,7 @@ do -- group functions scope
|
|||||||
newData.units[unitNum].shape_name = unitData.shape_name
|
newData.units[unitNum].shape_name = unitData.shape_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
--log:info(newData)
|
||||||
return newData
|
return newData
|
||||||
else
|
else
|
||||||
log:error('$1 not found in MIST database', gpName)
|
log:error('$1 not found in MIST database', gpName)
|
||||||
@ -3077,7 +3052,8 @@ do -- group functions scope
|
|||||||
action = 'tele'
|
action = 'tele'
|
||||||
newGroupData = vars.groupData
|
newGroupData = vars.groupData
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--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 then
|
if point then
|
||||||
@ -3161,6 +3137,7 @@ do -- group functions scope
|
|||||||
end
|
end
|
||||||
--mist.debug.writeData(mist.utils.serialize,{'teleportToPoint', newGroupData}, 'newGroupData.lua')
|
--mist.debug.writeData(mist.utils.serialize,{'teleportToPoint', newGroupData}, 'newGroupData.lua')
|
||||||
if string.lower(newGroupData.category) == 'static' then
|
if string.lower(newGroupData.category) == 'static' then
|
||||||
|
--log:info(newGroupData)
|
||||||
return mist.dynAddStatic(newGroupData)
|
return mist.dynAddStatic(newGroupData)
|
||||||
end
|
end
|
||||||
return mist.dynAdd(newGroupData)
|
return mist.dynAdd(newGroupData)
|
||||||
@ -3193,7 +3170,7 @@ do -- group functions scope
|
|||||||
end
|
end
|
||||||
|
|
||||||
function mist.cloneInZone(gpName, zone, disperse, maxDisp)
|
function mist.cloneInZone(gpName, zone, disperse, maxDisp)
|
||||||
|
--log:info('cloneInZone')
|
||||||
if type(gpName) == 'table' then
|
if type(gpName) == 'table' then
|
||||||
gpName = gpName:getName()
|
gpName = gpName:getName()
|
||||||
else
|
else
|
||||||
@ -3212,6 +3189,7 @@ do -- group functions scope
|
|||||||
vars.radius = zone.radius
|
vars.radius = zone.radius
|
||||||
vars.disperse = disperse
|
vars.disperse = disperse
|
||||||
vars.maxDisp = maxDisp
|
vars.maxDisp = maxDisp
|
||||||
|
--log:info('do teleport')
|
||||||
return mist.teleportToPoint(vars)
|
return mist.teleportToPoint(vars)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user