Formatting and typos (#1652)

* Formatting and typo fixes.

General formatting and typo fixes.

* Update STTS.lua

Keep class table on separate lines.
This commit is contained in:
TommyC81 2021-12-04 21:49:47 +04:00 committed by GitHub
parent 2ba5215036
commit 32deb160ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 2095 additions and 2260 deletions

View File

@ -11,7 +11,7 @@
-- --
-- DCS itself provides a lot of enumerators for various things. See [Enumerators](https://wiki.hoggitworld.com/view/Category:Enumerators) on Hoggit. -- DCS itself provides a lot of enumerators for various things. See [Enumerators](https://wiki.hoggitworld.com/view/Category:Enumerators) on Hoggit.
-- --
-- Other Moose classe also have enumerators. For example, the AIRBASE class has enumerators for airbase names. -- Other Moose classes also have enumerators. For example, the AIRBASE class has enumerators for airbase names.
-- --
-- @module ENUMS -- @module ENUMS
-- @image MOOSE.JPG -- @image MOOSE.JPG
@ -30,7 +30,7 @@ ENUMS = {}
-- @type ENUMS.ROE -- @type ENUMS.ROE
-- @field #number WeaponFree AI will engage any enemy group it detects. Target prioritization is based based on the threat of the target. -- @field #number WeaponFree AI will engage any enemy group it detects. Target prioritization is based based on the threat of the target.
-- @field #number OpenFireWeaponFree AI will engage any enemy group it detects, but will prioritize targets specified in the groups tasking. -- @field #number OpenFireWeaponFree AI will engage any enemy group it detects, but will prioritize targets specified in the groups tasking.
-- @field #number OpenFire AI will engage only targets specified in its taskings. -- @field #number OpenFire AI will engage only targets specified in its tasking.
-- @field #number ReturnFire AI will only engage threats that shoot first. -- @field #number ReturnFire AI will only engage threats that shoot first.
-- @field #number WeaponHold AI will hold fire under all circumstances. -- @field #number WeaponHold AI will hold fire under all circumstances.
ENUMS.ROE = { ENUMS.ROE = {
@ -67,7 +67,7 @@ ENUMS.AlarmState = {
Red = 2, Red = 2,
} }
--- Weapon types. See the [Weapon Flag](https://wiki.hoggitworld.com/view/DCS_enum_weapon_flag) enumerotor on hoggit wiki. --- Weapon types. See the [Weapon Flag](https://wiki.hoggitworld.com/view/DCS_enum_weapon_flag) enumerator on Hoggit wiki.
-- @type ENUMS.WeaponFlag -- @type ENUMS.WeaponFlag
ENUMS.WeaponFlag={ ENUMS.WeaponFlag={
-- Bombs -- Bombs
@ -111,7 +111,7 @@ ENUMS.WeaponFlag={
-- --
-- Bombs -- Bombs
GuidedBomb = 14, -- (LGB + TvGB + SNSGB) GuidedBomb = 14, -- (LGB + TvGB + SNSGB)
AnyUnguidedBomb = 2147485680, -- (HeBomb + Penetrator + NapalmBomb + FAEBomb + ClusterBomb + Dispencer + CandleBomb + ParachuteBomb) AnyUnguidedBomb = 2147485680, -- (HeBomb + Penetrator + NapalmBomb + FAEBomb + ClusterBomb + Dispenser + CandleBomb + ParachuteBomb)
AnyBomb = 2147485694, -- (GuidedBomb + AnyUnguidedBomb) AnyBomb = 2147485694, -- (GuidedBomb + AnyUnguidedBomb)
--- Rockets --- Rockets
AnyRocket = 30720, -- LightRocket + MarkerRocket + CandleRocket + HeavyRocket AnyRocket = 30720, -- LightRocket + MarkerRocket + CandleRocket + HeavyRocket
@ -173,7 +173,7 @@ ENUMS.MissionTask={
TRANSPORT="Transport", TRANSPORT="Transport",
} }
--- Formations (new). See the [Formations](https://wiki.hoggitworld.com/view/DCS_enum_formation) on hoggit wiki. --- Formations (new). See the [Formations](https://wiki.hoggitworld.com/view/DCS_enum_formation) on Hoggit wiki.
-- @type ENUMS.Formation -- @type ENUMS.Formation
ENUMS.Formation={} ENUMS.Formation={}
ENUMS.Formation.FixedWing={} ENUMS.Formation.FixedWing={}
@ -244,7 +244,7 @@ ENUMS.Formation.Vehicle.Cone="Cone"
ENUMS.Formation.Vehicle.Diamond="Diamond" ENUMS.Formation.Vehicle.Diamond="Diamond"
--- Formations (old). The old format is a simplified version of the new formation enums, which allow more sophisticated settings. --- Formations (old). The old format is a simplified version of the new formation enums, which allow more sophisticated settings.
-- See the [Formations](https://wiki.hoggitworld.com/view/DCS_enum_formation) on hoggit wiki. -- See the [Formations](https://wiki.hoggitworld.com/view/DCS_enum_formation) on Hoggit wiki.
-- @type ENUMS.FormationOld -- @type ENUMS.FormationOld
ENUMS.FormationOld={} ENUMS.FormationOld={}
ENUMS.FormationOld.FixedWing={} ENUMS.FormationOld.FixedWing={}

View File

@ -9,7 +9,6 @@
-- @module Utilities.PROFILER -- @module Utilities.PROFILER
-- @image MOOSE.JPG -- @image MOOSE.JPG
--- PROFILER class. --- PROFILER class.
-- @type PROFILER -- @type PROFILER
-- @field #string ClassName Name of the class. -- @field #string ClassName Name of the class.
@ -25,7 +24,6 @@
-- @field #number ThreshTtot Total time threshold. Only write output if total function CPU time is more than this value. -- @field #number ThreshTtot Total time threshold. Only write output if total function CPU time is more than this value.
-- @field #string fileNamePrefix Output file name prefix, e.g. "MooseProfiler". -- @field #string fileNamePrefix Output file name prefix, e.g. "MooseProfiler".
-- @field #string fileNameSuffix Output file name prefix, e.g. "txt" -- @field #string fileNameSuffix Output file name prefix, e.g. "txt"
--- *The emperor counsels simplicity. First principles. Of each particular thing, ask: What is it in itself, in its own constitution? What is its causal nature? * --- *The emperor counsels simplicity. First principles. Of each particular thing, ask: What is it in itself, in its own constitution? What is its causal nature? *
-- --
-- === -- ===
@ -35,12 +33,11 @@
-- # The PROFILER Concept -- # The PROFILER Concept
-- --
-- Profile your lua code. This tells you, which functions are called very often and which consume most real time. -- Profile your lua code. This tells you, which functions are called very often and which consume most real time.
-- With this information you can optimize the perfomance of your code. -- With this information you can optimize the performance of your code.
-- --
-- # Prerequisites -- # Prerequisites
-- --
-- The modules **os** and **lfs** need to be desanizied. -- The modules **os** and **lfs** need to be de-sanitized.
--
-- --
-- # Start -- # Start
-- --
@ -122,15 +119,15 @@ function PROFILER.Start(Delay, Duration)
-- Check if os, io and lfs are available. -- Check if os, io and lfs are available.
local go = true local go = true
if not os then if not os then
env.error("ERROR: Profiler needs os to be desanitized!") env.error( "ERROR: Profiler needs os to be de-sanitized!" )
go = false go = false
end end
if not io then if not io then
env.error("ERROR: Profiler needs io to be desanitized!") env.error( "ERROR: Profiler needs io to be de-sanitized!" )
go = false go = false
end end
if not lfs then if not lfs then
env.error("ERROR: Profiler needs lfs to be desanitized!") env.error( "ERROR: Profiler needs lfs to be de-sanitized!" )
go = false go = false
end end
if not go then if not go then
@ -161,7 +158,6 @@ function PROFILER.Start(Delay, Duration)
env.info( string.format( "- Output file \"%s\" in CSV format", PROFILER.getfilename( "csv" ) ) ) env.info( string.format( "- Output file \"%s\" in CSV format", PROFILER.getfilename( "csv" ) ) )
env.info( '###############################################################################' ) env.info( '###############################################################################' )
-- Message on screen -- Message on screen
local duration = Duration or 600 local duration = Duration or 600
trigger.action.outText( "### Profiler running ###", duration ) trigger.action.outText( "### Profiler running ###", duration )
@ -191,7 +187,6 @@ function PROFILER.Stop(Delay)
-- Remove hook. -- Remove hook.
debug.sethook() debug.sethook()
-- Run time game. -- Run time game.
local runTimeGame = timer.getTime() - PROFILER.TstartGame local runTimeGame = timer.getTime() - PROFILER.TstartGame
@ -337,7 +332,6 @@ function PROFILER.printCSV(data, runTimeGame)
g:close() g:close()
end end
--- Write info to output file. --- Write info to output file.
-- @param #string ext Extension. -- @param #string ext Extension.
-- @return #string File name. -- @return #string File name.
@ -385,25 +379,20 @@ function PROFILER.showInfo(runTimeGame, runTimeOS)
local tforgen = nil -- #PROFILER.Data local tforgen = nil -- #PROFILER.Data
local tpairs = nil -- #PROFILER.Data local tpairs = nil -- #PROFILER.Data
for func, count in pairs( PROFILER.Counters ) do for func, count in pairs( PROFILER.Counters ) do
local s, src, line, tm = PROFILER.getData( func ) local s, src, line, tm = PROFILER.getData( func )
if PROFILER.logUnknown == true then if PROFILER.logUnknown == true then
if s==nil then s="<Unknown>" end if s == nil then
s = "<Unknown>"
end
end end
if s ~= nil then if s ~= nil then
-- Profile data. -- Profile data.
local T= local T = { func = s, src = src, line = line, count = count, tm = tm } -- #PROFILER.Data
{ func=s,
src=src,
line=line,
count=count,
tm=tm,
} --#PROFILER.Data
-- Collect special cases. Somehow, e.g. "_copy" appears multiple times so we try to gather all data. -- Collect special cases. Somehow, e.g. "_copy" appears multiple times so we try to gather all data.
if s == "_copy" then if s == "_copy" then
@ -473,7 +462,9 @@ function PROFILER.showInfo(runTimeGame, runTimeOS)
env.info( "##############################################################################" ) env.info( "##############################################################################" )
-- Sort by total time. -- Sort by total time.
table.sort(t, function(a,b) return a.tm>b.tm end) table.sort( t, function( a, b )
return a.tm > b.tm
end )
-- Write data. -- Write data.
PROFILER._flog( f, "" ) PROFILER._flog( f, "" )
@ -500,7 +491,9 @@ function PROFILER.showInfo(runTimeGame, runTimeOS)
PROFILER.showTable( t, f, runTimeGame ) PROFILER.showTable( t, f, runTimeGame )
-- Sort by number of calls. -- Sort by number of calls.
table.sort(t, function(a,b) return a.tm/a.count>b.tm/b.count end) table.sort( t, function( a, b )
return a.tm / a.count > b.tm / b.count
end )
-- Detailed data. -- Detailed data.
PROFILER._flog( f, "" ) PROFILER._flog( f, "" )
@ -513,7 +506,9 @@ function PROFILER.showInfo(runTimeGame, runTimeOS)
PROFILER.showTable( t, f, runTimeGame ) PROFILER.showTable( t, f, runTimeGame )
-- Sort by number of calls. -- Sort by number of calls.
table.sort(t, function(a,b) return a.count>b.count end) table.sort( t, function( a, b )
return a.count > b.count
end )
-- Detailed data. -- Detailed data.
PROFILER._flog( f, "" ) PROFILER._flog( f, "" )
@ -536,4 +531,3 @@ function PROFILER.showInfo(runTimeGame, runTimeOS)
-- Print csv file. -- Print csv file.
PROFILER.printCSV( t, runTimeGame ) PROFILER.printCSV( t, runTimeGame )
end end

View File

@ -1,7 +1,6 @@
--- Various routines --- Various routines
-- @module routines -- @module routines
-- @image MOOSE.JPG -- @image MOOSE.JPG
env.setErrorMessageBoxEnabled( false ) env.setErrorMessageBoxEnabled( false )
--- Extract of MIST functions. --- Extract of MIST functions.
@ -9,7 +8,6 @@ env.setErrorMessageBoxEnabled(false)
routines = {} routines = {}
-- don't change these -- don't change these
routines.majorVersion = 3 routines.majorVersion = 3
routines.minorVersion = 3 routines.minorVersion = 3
@ -46,7 +44,6 @@ routines.utils.deepCopy = function(object)
return objectreturn return objectreturn
end end
-- porting in Slmod's serialize_slmod2 -- porting in Slmod's serialize_slmod2
routines.utils.oneLineSerialize = function( tbl ) -- serialization of a table all on a single line, no comments, made to replace old get_table_string function routines.utils.oneLineSerialize = function( tbl ) -- serialization of a table all on a single line, no comments, made to replace old get_table_string function
@ -142,7 +139,6 @@ routines.utils.basicSerialize = function(s)
end end
end end
routines.utils.toDegree = function( angle ) routines.utils.toDegree = function( angle )
return angle * 180 / math.pi return angle * 180 / math.pi
end end
@ -252,10 +248,6 @@ function routines.utils.get3DDist(point1, point2)
return routines.vec.mag( { x = point1.x - point2.x, y = point1.y - point2.y, z = point1.z - point2.z } ) return routines.vec.mag( { x = point1.x - point2.x, y = point1.y - point2.y, z = point1.z - point2.z } )
end end
-- 3D Vector manipulation -- 3D Vector manipulation
routines.vec = {} routines.vec = {}
@ -295,16 +287,12 @@ routines.vec.rotateVec2 = function(vec2, theta)
end end
--------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------
-- acc- the accuracy of each easting/northing. 0, 1, 2, 3, 4, or 5. -- acc- the accuracy of each easting/northing. 0, 1, 2, 3, 4, or 5.
routines.tostringMGRS = function( MGRS, acc ) routines.tostringMGRS = function( MGRS, acc )
if acc == 0 then if acc == 0 then
return MGRS.UTMZone .. ' ' .. MGRS.MGRSDigraph return MGRS.UTMZone .. ' ' .. MGRS.MGRSDigraph
else else
return MGRS.UTMZone .. ' ' .. MGRS.MGRSDigraph .. ' ' .. string.format('%0' .. acc .. 'd', routines.utils.round(MGRS.Easting/(10^(5-acc)), 0)) return MGRS.UTMZone .. ' ' .. MGRS.MGRSDigraph .. ' ' .. string.format( '%0' .. acc .. 'd', routines.utils.round( MGRS.Easting / (10 ^ (5 - acc)), 0 ) ) .. ' ' .. string.format( '%0' .. acc .. 'd', routines.utils.round( MGRS.Northing / (10 ^ (5 - acc)), 0 ) )
.. ' ' .. string.format('%0' .. acc .. 'd', routines.utils.round(MGRS.Northing/(10^(5-acc)), 0))
end end
end end
@ -366,8 +354,7 @@ routines.tostringLL = function(lat, lon, acc, DMS)
secFrmtStr = '%0' .. width .. '.' .. acc .. 'f' secFrmtStr = '%0' .. width .. '.' .. acc .. 'f'
end end
return string.format('%02d', latDeg) .. ' ' .. string.format('%02d', latMin) .. '\' ' .. string.format(secFrmtStr, latSec) .. '"' .. latHemi .. ' ' return string.format( '%02d', latDeg ) .. ' ' .. string.format( '%02d', latMin ) .. '\' ' .. string.format( secFrmtStr, latSec ) .. '"' .. latHemi .. ' ' .. string.format( '%02d', lonDeg ) .. ' ' .. string.format( '%02d', lonMin ) .. '\' ' .. string.format( secFrmtStr, lonSec ) .. '"' .. lonHemi
.. string.format('%02d', lonDeg) .. ' ' .. string.format('%02d', lonMin) .. '\' ' .. string.format(secFrmtStr, lonSec) .. '"' .. lonHemi
else -- degrees, decimal minutes. else -- degrees, decimal minutes.
latMin = routines.utils.round( latMin, acc ) latMin = routines.utils.round( latMin, acc )
@ -391,8 +378,7 @@ routines.tostringLL = function(lat, lon, acc, DMS)
minFrmtStr = '%0' .. width .. '.' .. acc .. 'f' minFrmtStr = '%0' .. width .. '.' .. acc .. 'f'
end end
return string.format('%02d', latDeg) .. ' ' .. string.format(minFrmtStr, latMin) .. '\'' .. latHemi .. ' ' return string.format( '%02d', latDeg ) .. ' ' .. string.format( minFrmtStr, latMin ) .. '\'' .. latHemi .. ' ' .. string.format( '%02d', lonDeg ) .. ' ' .. string.format( minFrmtStr, lonMin ) .. '\'' .. lonHemi
.. string.format('%02d', lonDeg) .. ' ' .. string.format(minFrmtStr, lonMin) .. '\'' .. lonHemi
end end
end end
@ -433,7 +419,6 @@ routines.getNorthCorrection = function(point) --gets the correction needed for
return math.atan2( north_posit.z - point.z, north_posit.x - point.x ) return math.atan2( north_posit.z - point.z, north_posit.x - point.x )
end end
do do
local idNum = 0 local idNum = 0
@ -489,14 +474,7 @@ function routines.getRandPointInCircle(point, radius, innerRadius)
end end
routines.goRoute = function( group, path ) routines.goRoute = function( group, path )
local misTask = { local misTask = { id = 'Mission', params = { route = { points = routines.utils.deepCopy( path ) } } }
id = 'Mission',
params = {
route = {
points = routines.utils.deepCopy(path),
},
},
}
if type( group ) == 'string' then if type( group ) == 'string' then
group = Group.getByName( group ) group = Group.getByName( group )
end end
@ -510,7 +488,6 @@ routines.goRoute = function(group, path)
return false return false
end end
-- Useful atomic functions from mist, ported. -- Useful atomic functions from mist, ported.
routines.ground = {} routines.ground = {}
@ -569,9 +546,7 @@ routines.ground.buildWP = function(point, overRideForm, overRideSpeed)
end end
wp.type = 'Turning Point' wp.type = 'Turning Point'
return wp return wp
end end
routines.fixedWing.buildWP = function( point, WPtype, speed, alt, altType ) routines.fixedWing.buildWP = function( point, WPtype, speed, alt, altType )
@ -702,7 +677,6 @@ routines.groupToRandomPoint = function(vars)
local headingDegrees = vars.headingDegrees local headingDegrees = vars.headingDegrees
local speed = vars.speed or routines.utils.kmphToMps( 20 ) local speed = vars.speed or routines.utils.kmphToMps( 20 )
local useRoads local useRoads
if not vars.disableRoads then if not vars.disableRoads then
useRoads = true useRoads = true
@ -729,7 +703,6 @@ routines.groupToRandomPoint = function(vars)
offset.z = routines.utils.round( math.cos( heading + (math.pi / 2) ) * 50 + rndCoord.y, 3 ) offset.z = routines.utils.round( math.cos( heading + (math.pi / 2) ) * 50 + rndCoord.y, 3 )
path[#path + 1] = routines.ground.buildWP( posStart, form, speed ) path[#path + 1] = routines.ground.buildWP( posStart, form, speed )
if useRoads == true and ((point.x - posStart.x) ^ 2 + (point.z - posStart.z) ^ 2) ^ 0.5 > radius * 1.3 then if useRoads == true and ((point.x - posStart.x) ^ 2 + (point.z - posStart.z) ^ 2) ^ 0.5 > radius * 1.3 then
path[#path + 1] = routines.ground.buildWP( { ['x'] = posStart.x + 11, ['z'] = posStart.z + 11 }, 'off_road', speed ) path[#path + 1] = routines.ground.buildWP( { ['x'] = posStart.x + 11, ['z'] = posStart.z + 11 }, 'off_road', speed )
path[#path + 1] = routines.ground.buildWP( posStart, 'on_road', speed ) path[#path + 1] = routines.ground.buildWP( posStart, 'on_road', speed )
@ -742,8 +715,6 @@ routines.groupToRandomPoint = function(vars)
path[#path + 1] = routines.ground.buildWP( rndCoord, form, speed ) path[#path + 1] = routines.ground.buildWP( rndCoord, form, speed )
routines.goRoute( group, path ) routines.goRoute( group, path )
return
end end
routines.groupRandomDistSelf = function( gpData, dist, form, heading, speed ) routines.groupRandomDistSelf = function( gpData, dist, form, heading, speed )
@ -752,8 +723,6 @@ routines.groupRandomDistSelf = function(gpData, dist, form, heading, speed)
fakeZone.radius = dist or math.random( 300, 1000 ) fakeZone.radius = dist or math.random( 300, 1000 )
fakeZone.point = { x = pos.x, y, pos.y, z = pos.z } fakeZone.point = { x = pos.x, y, pos.y, z = pos.z }
routines.groupToRandomZone( gpData, fakeZone, form, heading, speed ) routines.groupToRandomZone( gpData, fakeZone, form, heading, speed )
return
end end
routines.groupToRandomZone = function( gpData, zone, form, heading, speed ) routines.groupToRandomZone = function( gpData, zone, form, heading, speed )
@ -780,8 +749,6 @@ routines.groupToRandomZone = function(gpData, zone, form, heading, speed)
vars.point = routines.utils.zoneToVec3( zone ) vars.point = routines.utils.zoneToVec3( zone )
routines.groupToRandomPoint( vars ) routines.groupToRandomPoint( vars )
return
end end
routines.isTerrainValid = function( coord, terrainTypes ) -- vec2/3 and enum or table of acceptable terrain types routines.isTerrainValid = function( coord, terrainTypes ) -- vec2/3 and enum or table of acceptable terrain types
@ -829,11 +796,8 @@ routines.groupToPoint = function(gpData, point, form, heading, speed, useRoads)
vars.disableRoads = useRoads vars.disableRoads = useRoads
vars.point = routines.utils.zoneToVec3( point ) vars.point = routines.utils.zoneToVec3( point )
routines.groupToRandomPoint( vars ) routines.groupToRandomPoint( vars )
return
end end
routines.getLeadPos = function( group ) routines.getLeadPos = function( group )
if type( group ) == 'string' then -- group name if type( group ) == 'string' then -- group name
group = Group.getByName( group ) group = Group.getByName( group )
@ -934,7 +898,6 @@ routines.getBRString = function(vars)
end end
end end
-- Returns the Vec3 coordinates of the average position of the concentration of units most in the heading direction. -- Returns the Vec3 coordinates of the average position of the concentration of units most in the heading direction.
--[[ vars for routines.getLeadingPos: --[[ vars for routines.getLeadingPos:
vars.units - table of unit names vars.units - table of unit names
@ -992,7 +955,6 @@ routines.getLeadingPos = function(vars)
end end
end end
--[[ vars for routines.getLeadingMGRSString: --[[ vars for routines.getLeadingMGRSString:
vars.units - table of unit names vars.units - table of unit names
vars.heading - direction vars.heading - direction
@ -1026,8 +988,6 @@ routines.getLeadingLLString = function(vars)
end end
end end
--[[ vars for routines.getLeadingBRString: --[[ vars for routines.getLeadingBRString:
vars.units - table of unit names vars.units - table of unit names
vars.heading - direction, number vars.heading - direction, number
@ -1083,11 +1043,7 @@ routines.msgMGRS = function(vars)
newText = text .. s newText = text .. s
end end
routines.message.add{ routines.message.add { text = newText, displayTime = displayTime, msgFor = msgFor }
text = newText,
displayTime = displayTime,
msgFor = msgFor
}
end end
--[[ vars for routines.msgLL --[[ vars for routines.msgLL
@ -1114,15 +1070,10 @@ routines.msgLL = function(vars)
newText = text .. s newText = text .. s
end end
routines.message.add{ routines.message.add { text = newText, displayTime = displayTime, msgFor = msgFor }
text = newText,
displayTime = displayTime,
msgFor = msgFor
}
end end
--[[ --[[
vars.units- table of unit names (NOT unitNameTable- maybe this should change). vars.units- table of unit names (NOT unitNameTable- maybe this should change).
vars.ref - vec3 ref point, maybe overload for vec2 as well? vars.ref - vec3 ref point, maybe overload for vec2 as well?
@ -1149,15 +1100,10 @@ routines.msgBR = function(vars)
newText = text .. s newText = text .. s
end end
routines.message.add{ routines.message.add { text = newText, displayTime = displayTime, msgFor = msgFor }
text = newText,
displayTime = displayTime,
msgFor = msgFor
}
end end
-------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------
-- basically, just sub-types of routines.msgBR... saves folks the work of getting the ref point. -- basically, just sub-types of routines.msgBR... saves folks the work of getting the ref point.
--[[ --[[
@ -1228,14 +1174,9 @@ routines.msgLeadingMGRS = function(vars)
newText = text .. s newText = text .. s
end end
routines.message.add{ routines.message.add { text = newText, displayTime = displayTime, msgFor = msgFor }
text = newText,
displayTime = displayTime,
msgFor = msgFor
}
end end
--[[ vars for routines.msgLeadingLL: --[[ vars for routines.msgLeadingLL:
vars.units - table of unit names vars.units - table of unit names
vars.heading - direction, number vars.heading - direction, number
@ -1266,12 +1207,7 @@ routines.msgLeadingLL = function(vars)
newText = text .. s newText = text .. s
end end
routines.message.add{ routines.message.add { text = newText, displayTime = displayTime, msgFor = msgFor }
text = newText,
displayTime = displayTime,
msgFor = msgFor
}
end end
--[[ --[[
@ -1306,23 +1242,22 @@ routines.msgLeadingBR = function(vars)
newText = text .. s newText = text .. s
end end
routines.message.add{ routines.message.add { text = newText, displayTime = displayTime, msgFor = msgFor }
text = newText,
displayTime = displayTime,
msgFor = msgFor
}
end end
function spairs( t, order ) function spairs( t, order )
-- collect the keys -- collect the keys
local keys = {} local keys = {}
for k in pairs(t) do keys[#keys+1] = k end for k in pairs( t ) do
keys[#keys + 1] = k
end
-- if order function given, sort by it by passing the table and keys a, b, -- if order function given, sort by it by passing the table and keys a, b,
-- otherwise just sort the keys -- otherwise just sort the keys
if order then if order then
table.sort(keys, function(a,b) return order(t, a, b) end) table.sort( keys, function( a, b )
return order( t, a, b )
end )
else else
table.sort( keys ) table.sort( keys )
end end
@ -1337,7 +1272,6 @@ function spairs(t, order)
end end
end end
function routines.IsPartOfGroupInZones( CargoGroup, LandingZones ) function routines.IsPartOfGroupInZones( CargoGroup, LandingZones )
-- trace.f() -- trace.f()
@ -1359,8 +1293,6 @@ function routines.IsPartOfGroupInZones( CargoGroup, LandingZones )
return CurrentZoneID return CurrentZoneID
end end
function routines.IsUnitInZones( TransportUnit, LandingZones ) function routines.IsUnitInZones( TransportUnit, LandingZones )
-- trace.f("", "routines.IsUnitInZones" ) -- trace.f("", "routines.IsUnitInZones" )
@ -1441,7 +1373,6 @@ function routines.IsUnitNearZonesRadius( TransportUnit, LandingZones, ZoneRadius
end end
end end
function routines.IsStaticInZones( TransportStatic, LandingZones ) function routines.IsStaticInZones( TransportStatic, LandingZones )
-- trace.f() -- trace.f()
@ -1474,7 +1405,6 @@ function routines.IsStaticInZones( TransportStatic, LandingZones )
return TransportZoneResult return TransportZoneResult
end end
function routines.IsUnitInRadius( CargoUnit, ReferencePosition, Radius ) function routines.IsUnitInRadius( CargoUnit, ReferencePosition, Radius )
-- trace.f() -- trace.f()
@ -1517,7 +1447,6 @@ function routines.IsPartOfGroupInRadius( CargoGroup, ReferencePosition, Radius )
return Valid return Valid
end end
function routines.ValidateString( Variable, VariableName, Valid ) function routines.ValidateString( Variable, VariableName, Valid )
-- trace.f() -- trace.f()
@ -1546,7 +1475,6 @@ function routines.ValidateNumber( Variable, VariableName, Valid )
-- trace.r( "", "", { Valid } ) -- trace.r( "", "", { Valid } )
return Valid return Valid
end end
function routines.ValidateGroup( Variable, VariableName, Valid ) function routines.ValidateGroup( Variable, VariableName, Valid )
@ -1672,7 +1600,6 @@ end
routines.ground.patrolRoute = function( vars ) routines.ground.patrolRoute = function( vars )
local tempRoute = {} local tempRoute = {}
local useRoute = {} local useRoute = {}
local gpData = vars.gpData local gpData = vars.gpData
@ -1698,7 +1625,6 @@ routines.ground.patrolRoute = function(vars)
routeProvided = true routeProvided = true
end end
local overRideSpeed = vars.speed or 'default' local overRideSpeed = vars.speed or 'default'
local pType = vars.pType local pType = vars.pType
local offRoadForm = vars.offRoadForm or 'default' local offRoadForm = vars.offRoadForm or 'default'
@ -1707,7 +1633,6 @@ routines.ground.patrolRoute = function(vars)
if routeProvided == false and #tempRoute > 0 then if routeProvided == false and #tempRoute > 0 then
local posStart = routines.getLeadPos( gpData ) local posStart = routines.getLeadPos( gpData )
useRoute[#useRoute + 1] = routines.ground.buildWP( posStart, offRoadForm, overRideSpeed ) useRoute[#useRoute + 1] = routines.ground.buildWP( posStart, offRoadForm, overRideSpeed )
for i = 1, #tempRoute do for i = 1, #tempRoute do
local tempForm = tempRoute[i].action local tempForm = tempRoute[i].action
@ -1729,7 +1654,6 @@ routines.ground.patrolRoute = function(vars)
tempSpeed = overRideSpeed tempSpeed = overRideSpeed
end end
useRoute[#useRoute + 1] = routines.ground.buildWP( tempRoute[i], tempForm, tempSpeed ) useRoute[#useRoute + 1] = routines.ground.buildWP( tempRoute[i], tempForm, tempSpeed )
end end
@ -1751,24 +1675,10 @@ routines.ground.patrolRoute = function(vars)
cTask3[#cTask3 + 1] = routines.utils.oneLineSerialize( newPatrol ) cTask3[#cTask3 + 1] = routines.utils.oneLineSerialize( newPatrol )
cTask3[#cTask3 + 1] = ')' cTask3[#cTask3 + 1] = ')'
cTask3 = table.concat( cTask3 ) cTask3 = table.concat( cTask3 )
local tempTask = { local tempTask = { id = 'WrappedAction', params = { action = { id = 'Script', params = { command = cTask3 } } } }
id = 'WrappedAction',
params = {
action = {
id = 'Script',
params = {
command = cTask3,
},
},
},
}
useRoute[#useRoute].task = tempTask useRoute[#useRoute].task = tempTask
routines.goRoute( gpData, useRoute ) routines.goRoute( gpData, useRoute )
return
end end
routines.ground.patrol = function( gpData, pType, form, speed ) routines.ground.patrol = function( gpData, pType, form, speed )
@ -1785,8 +1695,6 @@ routines.ground.patrol = function(gpData, pType, form, speed)
vars.speed = speed vars.speed = speed
routines.ground.patrolRoute( vars ) routines.ground.patrolRoute( vars )
return
end end
function routines.GetUnitHeight( CheckUnit ) function routines.GetUnitHeight( CheckUnit )
@ -1803,11 +1711,8 @@ function routines.GetUnitHeight( CheckUnit )
-- trace.f( "routines", "Unit Height = " .. UnitHeight - LandHeight ) -- trace.f( "routines", "Unit Height = " .. UnitHeight - LandHeight )
return UnitHeight - LandHeight return UnitHeight - LandHeight
end end
Su34Status = { status = {} } Su34Status = { status = {} }
boardMsgRed = { statusMsg = "" } boardMsgRed = { statusMsg = "" }
boardMsgAll = { timeMsg = "" } boardMsgAll = { timeMsg = "" }
@ -1815,7 +1720,6 @@ SpawnSettings = {}
Su34MenuPath = {} Su34MenuPath = {}
Su34Menus = 0 Su34Menus = 0
function Su34AttackCarlVinson( groupName ) function Su34AttackCarlVinson( groupName )
-- trace.menu("", "Su34AttackCarlVinson") -- trace.menu("", "Su34AttackCarlVinson")
local groupSu34 = Group.getByName( groupName ) local groupSu34 = Group.getByName( groupName )
@ -1982,7 +1886,6 @@ function Su34OverviewStatus()
boardMsgRed.statusMsg = msg boardMsgRed.statusMsg = msg
end end
function UpdateBoardMsg() function UpdateBoardMsg()
-- trace.f() -- trace.f()
Su34OverviewStatus() Su34OverviewStatus()
@ -2007,63 +1910,22 @@ function Su34Menu(groupName)
-- env.info(( 'Su34Menu(' .. groupName .. ')' )) -- env.info(( 'Su34Menu(' .. groupName .. ')' ))
local groupSu34 = Group.getByName( groupName ) local groupSu34 = Group.getByName( groupName )
if Su34Status.status[groupName] == 1 or if Su34Status.status[groupName] == 1 or Su34Status.status[groupName] == 2 or Su34Status.status[groupName] == 3 or Su34Status.status[groupName] == 4 or Su34Status.status[groupName] == 5 then
Su34Status.status[groupName] == 2 or
Su34Status.status[groupName] == 3 or
Su34Status.status[groupName] == 4 or
Su34Status.status[groupName] == 5 then
if Su34MenuPath[groupName] == nil then if Su34MenuPath[groupName] == nil then
if planeMenuPath == nil then if planeMenuPath == nil then
planeMenuPath = missionCommands.addSubMenuForCoalition( planeMenuPath = missionCommands.addSubMenuForCoalition( coalition.side.RED, "SU-34 anti-ship flights", nil )
coalition.side.RED,
"SU-34 anti-ship flights",
nil
)
end end
Su34MenuPath[groupName] = missionCommands.addSubMenuForCoalition( Su34MenuPath[groupName] = missionCommands.addSubMenuForCoalition( coalition.side.RED, "Flight " .. groupName, planeMenuPath )
coalition.side.RED,
"Flight " .. groupName,
planeMenuPath
)
missionCommands.addCommandForCoalition( missionCommands.addCommandForCoalition( coalition.side.RED, "Attack carrier Carl Vinson", Su34MenuPath[groupName], Su34AttackCarlVinson, groupName )
coalition.side.RED,
"Attack carrier Carl Vinson",
Su34MenuPath[groupName],
Su34AttackCarlVinson,
groupName
)
missionCommands.addCommandForCoalition( missionCommands.addCommandForCoalition( coalition.side.RED, "Attack ships in the west", Su34MenuPath[groupName], Su34AttackWest, groupName )
coalition.side.RED,
"Attack ships in the west",
Su34MenuPath[groupName],
Su34AttackWest,
groupName
)
missionCommands.addCommandForCoalition( missionCommands.addCommandForCoalition( coalition.side.RED, "Attack ships in the north", Su34MenuPath[groupName], Su34AttackNorth, groupName )
coalition.side.RED,
"Attack ships in the north",
Su34MenuPath[groupName],
Su34AttackNorth,
groupName
)
missionCommands.addCommandForCoalition( missionCommands.addCommandForCoalition( coalition.side.RED, "Hold position and await instructions", Su34MenuPath[groupName], Su34Orbit, groupName )
coalition.side.RED,
"Hold position and await instructions",
Su34MenuPath[groupName],
Su34Orbit,
groupName
)
missionCommands.addCommandForCoalition( missionCommands.addCommandForCoalition( coalition.side.RED, "Report status", Su34MenuPath[groupName], Su34OverviewStatus )
coalition.side.RED,
"Report status",
Su34MenuPath[groupName],
Su34OverviewStatus
)
end end
else else
if Su34MenuPath[groupName] then if Su34MenuPath[groupName] then
@ -2207,32 +2069,23 @@ function EscortCarrier ( CarrierGroup, EscortPrefix, EscortLastWayPoint, EscortE
EscortMission.units[u].unitId = nil EscortMission.units[u].unitId = nil
end end
EscortMission.route.points[1].task = {
EscortMission.route.points[1].task = { id = "ComboTask", id = "ComboTask",
params = params = {
{ tasks = {
tasks = [1] = {
{
[1] =
{
enabled = true, enabled = true,
auto = false, auto = false,
id = "Escort", id = "Escort",
number = 1, number = 1,
params = params = {
{
lastWptIndexFlagChangedManually = false, lastWptIndexFlagChangedManually = false,
groupId = CarrierGroup:getID(), groupId = CarrierGroup:getID(),
lastWptIndex = nil, lastWptIndex = nil,
lastWptIndexFlag = false, lastWptIndexFlag = false,
engagementDistMax = EscortEngagementDistanceMax, engagementDistMax = EscortEngagementDistanceMax,
targetTypes = EscortTargetTypes, targetTypes = EscortTargetTypes,
pos = pos = { y = 20, x = 20, z = 0 } -- end of ["pos"]
{
y = 20,
x = 20,
z = 0,
} -- end of ["pos"]
} -- end of ["params"] } -- end of ["params"]
} -- end of [1] } -- end of [1]
} -- end of ["tasks"] } -- end of ["tasks"]
@ -2325,7 +2178,6 @@ function getCarrierHeight( CarrierGroup )
else else
return 999999 return 999999
end end
end end
function GetUnitHeight( CheckUnit ) function GetUnitHeight( CheckUnit )
@ -2340,16 +2192,13 @@ function GetUnitHeight( CheckUnit )
-- env.info(( 'CarrierHeight: LandHeight = ' .. LandHeight .. ' CarrierHeight = ' .. CarrierHeight )) -- env.info(( 'CarrierHeight: LandHeight = ' .. LandHeight .. ' CarrierHeight = ' .. CarrierHeight ))
return UnitHeight - LandHeight return UnitHeight - LandHeight
end end
_MusicTable = {} _MusicTable = {}
_MusicTable.Files = {} _MusicTable.Files = {}
_MusicTable.Queue = {} _MusicTable.Queue = {}
_MusicTable.FileCnt = 0 _MusicTable.FileCnt = 0
function MusicRegister( SndRef, SndFile, SndTime ) function MusicRegister( SndRef, SndFile, SndTime )
-- trace.f() -- trace.f()
@ -2357,7 +2206,6 @@ function MusicRegister( SndRef, SndFile, SndTime )
env.info( ('MusicRegister: SndFile = ' .. SndFile) ) env.info( ('MusicRegister: SndFile = ' .. SndFile) )
env.info( ('MusicRegister: SndTime = ' .. SndTime) ) env.info( ('MusicRegister: SndTime = ' .. SndTime) )
_MusicTable.FileCnt = _MusicTable.FileCnt + 1 _MusicTable.FileCnt = _MusicTable.FileCnt + 1
_MusicTable.Files[_MusicTable.FileCnt] = {} _MusicTable.Files[_MusicTable.FileCnt] = {}
@ -2368,7 +2216,6 @@ function MusicRegister( SndRef, SndFile, SndTime )
if not _MusicTable.Function then if not _MusicTable.Function then
_MusicTable.Function = routines.scheduleFunction( MusicScheduler, {}, timer.getTime() + 10, 10 ) _MusicTable.Function = routines.scheduleFunction( MusicScheduler, {}, timer.getTime() + 10, 10 )
end end
end end
function MusicToPlayer( SndRef, PlayerName, SndContinue ) function MusicToPlayer( SndRef, PlayerName, SndContinue )
@ -2391,7 +2238,6 @@ function MusicToPlayer( SndRef, PlayerName, SndContinue )
end end
-- env.info(( 'MusicToPlayer: end' )) -- env.info(( 'MusicToPlayer: end' ))
end end
function MusicToGroup( SndRef, SndGroup, SndContinue ) function MusicToGroup( SndRef, SndGroup, SndContinue )
@ -2494,9 +2340,6 @@ function MusicScheduler()
end end
end end
end end
end end
env.info( ('Init: Scripts Loaded v1.1') ) env.info( ('Init: Scripts Loaded v1.1') )

View File

@ -1,21 +1,18 @@
--- **Utilities** DCS Simple Text-To-Speech (STTS). --- **Utilities** DCS Simple Text-To-Speech (STTS).
-- --
-- --
--
-- @module Utils.STTS -- @module Utils.STTS
-- @image MOOSE.JPG -- @image MOOSE.JPG
--- [DCS Enum world](https://wiki.hoggitworld.com/view/DCS_enum_world) --- [DCS Enum world](https://wiki.hoggitworld.com/view/DCS_enum_world)
-- @type STTS -- @type STTS
-- @field #string DIRECTORY Path of the SRS directory. -- @field #string DIRECTORY Path of the SRS directory.
--- Simple Text-To-Speech --- Simple Text-To-Speech
-- --
-- Version 0.4 - Compatible with SRS version 1.9.6.0+ -- Version 0.4 - Compatible with SRS version 1.9.6.0+
-- --
-- # DCS Modification Required -- # DCS Modification Required
-- --
-- You will need to edit MissionScripting.lua in DCS World/Scripts/MissionScripting.lua and remove the sanitisation. -- You will need to edit MissionScripting.lua in DCS World/Scripts/MissionScripting.lua and remove the sanitization.
-- To do this remove all the code below the comment - the line starts "local function sanitizeModule(name)" -- To do this remove all the code below the comment - the line starts "local function sanitizeModule(name)"
-- Do this without DCS running to allow mission scripts to use os functions. -- Do this without DCS running to allow mission scripts to use os functions.
-- --
@ -23,7 +20,7 @@
-- --
-- # USAGE: -- # USAGE:
-- --
-- Add this script into the mission as a DO SCRIPT or DO SCRIPT FROM FILE to initialise it -- Add this script into the mission as a DO SCRIPT or DO SCRIPT FROM FILE to initialize it
-- Make sure to edit the STTS.SRS_PORT and STTS.DIRECTORY to the correct values before adding to the mission. -- Make sure to edit the STTS.SRS_PORT and STTS.DIRECTORY to the correct values before adding to the mission.
-- Then its as simple as calling the correct function in LUA as a DO SCRIPT or in your own scripts. -- Then its as simple as calling the correct function in LUA as a DO SCRIPT or in your own scripts.
-- --
@ -80,7 +77,7 @@ STTS={
DIRECTORY = "", DIRECTORY = "",
SRS_PORT = 5002, SRS_PORT = 5002,
GOOGLE_CREDENTIALS = "C:\\Users\\Ciaran\\Downloads\\googletts.json", GOOGLE_CREDENTIALS = "C:\\Users\\Ciaran\\Downloads\\googletts.json",
EXECUTABLE="DCS-SR-ExternalAudio.exe", EXECUTABLE = "DCS-SR-ExternalAudio.exe"
} }
--- FULL Path to the FOLDER containing DCS-SR-ExternalAudio.exe - EDIT TO CORRECT FOLDER --- FULL Path to the FOLDER containing DCS-SR-ExternalAudio.exe - EDIT TO CORRECT FOLDER
@ -95,7 +92,6 @@ STTS.GOOGLE_CREDENTIALS = "C:\\Users\\Ciaran\\Downloads\\googletts.json"
--- DONT CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING --- DONT CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING
STTS.EXECUTABLE = "DCS-SR-ExternalAudio.exe" STTS.EXECUTABLE = "DCS-SR-ExternalAudio.exe"
--- Function for UUID. --- Function for UUID.
function STTS.uuid() function STTS.uuid()
local random = math.random local random = math.random
@ -112,7 +108,11 @@ end
function STTS.round( x, n ) function STTS.round( x, n )
n = math.pow( 10, n or 0 ) n = math.pow( 10, n or 0 )
x = x * n x = x * n
if x >= 0 then x = math.floor(x + 0.5) else x = math.ceil(x - 0.5) end if x >= 0 then
x = math.floor( x + 0.5 )
else
x = math.ceil( x - 0.5 )
end
return x / n return x / n
end end
@ -170,7 +170,6 @@ function STTS.TextToSpeech(message, freqs, modulations, volume, name, coalition,
volume = 1 volume = 1
speed = 1 speed = 1
message = message:gsub( "\"", "\\\"" ) message = message:gsub( "\"", "\\\"" )
local cmd = string.format( "start /min \"\" /d \"%s\" /b \"%s\" -f %s -m %s -c %s -p %s -n \"%s\" -h", STTS.DIRECTORY, STTS.EXECUTABLE, freqs or "305", modulations or "AM", coalition, STTS.SRS_PORT, name ) local cmd = string.format( "start /min \"\" /d \"%s\" /b \"%s\" -f %s -m %s -c %s -p %s -n \"%s\" -h", STTS.DIRECTORY, STTS.EXECUTABLE, freqs or "305", modulations or "AM", coalition, STTS.SRS_PORT, name )
@ -237,8 +236,7 @@ end
-- @param #string volume Volume, e.g. "0.5". -- @param #string volume Volume, e.g. "0.5".
function STTS.PlayMP3( pathToMP3, freqs, modulations, volume, name, coalition, point ) function STTS.PlayMP3( pathToMP3, freqs, modulations, volume, name, coalition, point )
local cmd = string.format("start \"\" /d \"%s\" /b /min \"%s\" -i \"%s\" -f %s -m %s -c %s -p %s -n \"%s\" -v %s -h", local cmd = string.format( "start \"\" /d \"%s\" /b /min \"%s\" -i \"%s\" -f %s -m %s -c %s -p %s -n \"%s\" -v %s -h", STTS.DIRECTORY, STTS.EXECUTABLE, pathToMP3, freqs or "305", modulations or "AM", coalition or "0", STTS.SRS_PORT, name or "ROBOT", volume or "1" )
STTS.DIRECTORY, STTS.EXECUTABLE, pathToMP3, freqs or "305", modulations or "AM", coalition or "0", STTS.SRS_PORT, name or "ROBOT", volume or "1")
if point and type( point ) == "table" and point.x then if point and type( point ) == "table" and point.x then
local lat, lon, alt = coord.LOtoLL( point ) local lat, lon, alt = coord.LOtoLL( point )